akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define ALL(n) begin(n),end(n)
const int INF=1000000000;

using Graph=vector<vector<int>>;

int n;
vector<int> d;

void Dijkstra(const Graph &G){
    // 暫定の最短距離，頂点番号
    priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> que;
    que.emplace(d[0],0);

    // 距離を確定すべき頂点がなくなるまで続ける
    while(!que.empty()){
        pair<int,int> p=que.top();
        que.pop();
        int v=p.second;
        
        // 最短距離より大きい場合は無視
        if(d[v]<p.first) continue;

        REP(i,n){
            // 辺(v,i)がなければ無視
            if(G[v][i]==INF) continue;

            // 辺(v,i)を採用して距離が短くなるならば，暫定的に採用
            if(d[i]>d[v]+G[v][i]){
                d[i]=d[v]+G[v][i];
                que.emplace(d[i],i);
            }
        }
    }
}

int main(){
    cin>>n;

    // グラフの受け取り
    Graph G(n,vector<int>(n));
    REP(i,n){
        int u,k;
        cin>>u>>k;
        G[u].assign(n,INF);
        REP(j,k){
            int v,c;
            cin>>v>>c;
            G[u][v]=c;
        }
    }

    // d[i]=(無限大) で初期化
    d.assign(n,INF);
    d[0]=0;

    Dijkstra(G);

    REP(i,n){
        cout<<i<<" "<<d[i]<<endl;
    }
}


Measured memory_bytes: 3212
#include <algorithm>
#include <vector>
#include <cmath>
#include <tuple>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <queue>
#include <numeric>
#include <iostream>

using namespace std;


int main() {

    int N, M, C;
    cin >> N >> M >> C;

    int cnt = 0;

    vector<int> bs;
    for (int i = 0; i < M; i++) {
        int B;
        cin >> B;
        bs.push_back(B);
    }

    for (int i = 0; i < N; i++) {

        int sum = C;
        int A;
        for (int j = 0; j < M; j++) {
            cin >> A;
            sum += (A * bs[j]);
        }

        if (sum > 0) {
            cnt += 1;
        }
    }

    cout << cnt << "\n";

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
  int n,m;
  while(  cin >> n >> m,n+m){
    int ninki[1001] = {0},p[1001] = {0};
    for(int i = 0 ; i < n ; i++ ){
      for(int j = 0 ; j < m ; j++ ){
	int t;
	cin >> t; 
	ninki[j] += t; 
	if(i == 0)p[j] = j+1;
      }
    }

    for(int i = 0 ; i < m  ; i++ ){
      for(int j = m-1 ; j > i ; j-- ){
	if(ninki[j-1] < ninki[j]){
	  swap(ninki[j-1],ninki[j]);
	  swap(p[j-1],p[j]);
	}
      }
    }
    for(int i = 0 ; i < m  ; i++ ){
      if(i == 0)cout << p[i];
      else cout <<" "<< p[i];
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 1168
#include<bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define REPR(i,n) for(int i=n-1;i>=0;i--)
#define FORR(i,n,m) for(int i=n-1;i>=m;i--)
#define ARR(array) for(int i=0;i<array.size();i++)
#define all(in) (in).begin(),(in).end()
#define ALL(in,K) (in),(in)+(K)

#define INF 1e18
#define MOD 1000000007
#define SIZE 10005
#define PI 	3.14159265358979323846

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; } //最大公約数
ll lcm(ll a, ll b) { return a/gcd(a, b)*b; } //最小公倍数

ll input(){
  ll a;
  cin >> a;
  return a;
}

int main(){
  string s;
  cin >> s;
  int ans=0;
  REP(i,3)if(s.at(i)=='1')ans++;
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <functional>
#include <cstdio>
#include <climits>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int main() {
    int a, b;
    cin >> a >> b;
    if (b < a) {
        cout << a - 1 << endl;
    } else {
        cout << a << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
  int n,m;
  cin >> n >> m;
  int h[n];
  rep(i,n)cin >> h[i];
  vector<vector<int>> k(n,vector<int>(1,-1));
  rep(i,m){
    int a,b;
    cin >> a >> b;
    a--;
    b--;
    k[a].push_back(b);
    k[b].push_back(a);
  }
  int ans=0;
  rep(i,n){
    int q=h[i];
    int t=0;
    for(int w: k[i]){
      if(w==-1)continue;
      if(h[w]>=q){
        t=1;
        break;
      }
    }
    if(t==0)ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 9808
#include <stdio.h>
#include <math.h>

typedef struct{
	double x;
	double y;
}point;

void kock(int n, point a,point b)
{
	point s, t, u;
	double x;
	
	x=M_PI*60/180;
	if(n == 0){
		return;
	}
// p1, p2 から s, t, u を計算

	s.x=(2*a.x+1*b.x)/3;
	s.y=(2*a.y+1*b.y)/3;
	t.x=(1*a.x+2*b.x)/3;
	t.y=(1*a.y+2*b.y)/3;
	u.x=(t.x-s.x)*cos(x)-(t.y-s.y)*sin(x)+s.x;
	u.y=(t.x-s.x)*sin(x)+(t.y-s.y)*cos(x)+s.y;
	
	kock(n-1, a, s);
	printf("%f %f\n",s.x,s.y);
	kock(n-1, s, u);
	printf("%f %f\n",u.x,u.y);
	kock(n-1, u, t);
	printf("%f %f\n",t.x,t.y);
	kock(n-1, t, b);
}

int main(void)
{
	point a, b;
	int n;
	
	scanf("%d",&n);
	a.x=0;
	a.y=0;
	b.x=100;
	b.y=0;
	
	printf("%f %f\n",a.x,a.y);
	kock(n,a,b);
	printf("%f %f\n",b.x,b.y);
	
	return 0;
}


Measured memory_bytes: 2048
#include <bits/stdc++.h>
#include <string>
using namespace std;
#define ll long long
#define endl "\n"
#define print_array(name,n) for(ll o=0;o<n;o++) cout<<name[o]<<" "
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define inf 2e18
#define pll pair<ll,ll>
#define pii pair<int,int>
bool sortbysecond(const pair<int,int> &a,const pair<int,int> &b){
	return (a.ss>b.ss);
}
 
ll gcd(ll a,ll b){ if(b==0) return a; return gcd(b,a%b) ;} 

template <typename T>
string NumberTostring(T Number )
{
	ostringstream ss;
	ss<<Number;
	return ss.str();
}
 

 
int main()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
 	ll n,k;
 	cin>>n>>k;
 	vector<ll> vec(n);
 	ll mx = 0;
 	for(int i=0;i<n;i++){
 		cin>>vec[i];
 		if(mx<vec[i]){
 			mx = vec[i];
 		}
 	}   
 	ll low = 1;
 	ll high = mx;
 	ll ans = 0;
 	while(low<=high){
 		ll mid =  (high+low)/2;
 		ll temp = 0;
 		for(int i=0;i<n;i++){
 			if(vec[i]<=mid){
 				continue;
 			}
 			temp += (vec[i] + mid-1)/mid - 1;
 			
 		}
 		// cout<<mid<<" "<<temp<<endl;
 		if(temp<=k){
 			high = mid-1;
 			ans = mid;
 		}
 		else{
 			low = mid+1;
 		}
 	}
 	cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 4732
#include <iostream>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <deque>
#include <queue>

using namespace std;
typedef long long ll;

ll dp[100005];
ll h[100005];
int main(){
    int N, K;
    cin >> N >> K;
    for(int i = 1; i <= N; i++) cin >> h[i];

    for(int i = 2; i <= N; i++){
        if(i > K){
            for(int j = i-K; j <= i-1; j++){
                if(j == i-K) dp[i] = dp[j]+abs(h[i]-h[j]);
                dp[i] = min(dp[i], dp[j]+abs(h[i]-h[j]));
            }
        } else {
            for(int j = 1; j <= i-1; j++){
                if(j==1) dp[i] = dp[j]+abs(h[i]-h[j]);
                dp[i] = min(dp[i], dp[j]+abs(h[i]-h[j]));
            }
        }
    }

    cout << dp[N] << endl;
}



Measured memory_bytes: 1792
#include<cstdio>
#include<cmath>
#define int long long
int min(int a,int b){return a<b?a:b;}
signed main(){
    long long a,b,n;scanf("%lld%lld%lld",&a,&b,&n);
    printf("%lld\n",(int)floor(a*min(b-1,n)*1.0/b)-a*(int)floor(min(b-1,n)*1.0/b));
    return 0;
}

Measured memory_bytes: 2212
#include<bits/stdc++.h>
using namespace std;
#define ll long long
vector<vector<ll>>dp;
ll f(vector<ll>&A,int i,int j)
{
    if(i>j)
        return 0;
    if(i==j)return A[i];
    if(dp[i][j]!=-1)
        return dp[i][j];
    dp[i][j]=max(A[i]+min(f(A,i+1,j-1),f(A,i+2,j)),A[j]+min(f(A,i+1,j-1),f(A,i,j-2)));
    return dp[i][j];
}
int main()
{
    int n;
    cin>>n;
    vector<ll>A(n);
    long long total=0;
    for(ll &i:A){
        cin>>i;
        total+=i;
    }
    dp.resize(n+1,vector<ll>(n+1,-1));
    cout<<f(A,0,n-1)+f(A,0,n-1)-total;
}

Measured memory_bytes: 70912
def kakeru(i):
    for a in range(K+1):
        if i*2**a >= K:
            return a

N, K = map(int, input().split())
result = 0

for i in range(1,N+1):
    x = kakeru(i) if i < K else 0
    pulas = (1/N)*((0.5)**x) if x > 0 else 1/N
    result += pulas

print(result)


Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>

#define MOD (1000000007)

using namespace std;

typedef long long ll;
typedef pair<ll, ll> tup;
const int MAX = 510000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


int main() {
    COMinit();

    ll N, K;
    cin >> N >> K;

    ll ret = 0;
    for(ll i = K; i <= N+1; i++) {

        ll minv = ((i % MOD) * ((i-1) % MOD) / 2) % MOD;
        ll maxv = ((i % MOD) * (((2* N-i)%MOD)+1)/2) % MOD;
        //cout << maxv << "," << minv << ":" << maxv-minv<<endl;
        ret = ret % MOD + (maxv-minv + MOD + 1) % MOD;
        ret %= MOD;
    }

    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 15560
#include <bits/stdc++.h>

#define reps(v, f, l) for (int v = (f), v##_ = (l); v < v##_; ++v)
#define rep(v, n) reps(v, 0, n)
#define lep(v, n) reps(v, 1, n + 1)

using namespace std;

typedef long long int lint;

static inline int in(){ int x; scanf("%d", &x); return x; }
static inline lint inl(){ lint x; scanf("%lld", &x); return x; }
template<typename T> void show(T& a, char del='\n', char last='\n'){ rep(i, a.size() - 1) cout << a[i] << del; cout << a[a.size() - 1] << last; }

struct Info {
  int weight;
  int time;
  int from;
  Info() : time(-1) {}
  Info(int w, int t, int f) : weight(w), time(t), from(f) {}
};

Info dp[1 << 16][16];
int main()
{
  int n = in();
  vector<int> ids;
  vector<int> dist;
  vector<int> weight;

  rep(i, n){
    ids.push_back(in());
    dist.push_back(in());
    weight.push_back(in());
  }
  rep(i, n){
    dp[1 << i][i] = Info(weight[i], 0, -1);
  }
  rep(state, 1 << n){
    rep(last, n){
      Info& src = dp[state][last];
      if (src.time == -1) continue;
      rep(next, n){
        if (state & (1 << next)) continue;
        Info& dst = dp[state | (1 << next)][next];
        int t = src.time + abs(dist[last] - dist[next]) * src.weight;
        if (dst.time == -1 || dst.time > t){
          dst = Info(src.weight + weight[next], t, last);
        }
      }
    }
  }
  int id = 0;
  int state = (1 << n) - 1;
  Info& best = dp[state][id];
  rep(i, n){
    if (best.time > dp[state][i].time){
      best = dp[(1 << n) - 1][i];
      id = i;
    }
  }
  vector<int> ans;
  while (1){
    ans.push_back(ids[id]);
    if (best.from == -1) break;
    state &= ~(1 << id);
    id = best.from;
    best = dp[state][id];
  }
  reverse(ans.begin(), ans.end());
  show(ans, ' ');
  return 0;
}

Measured memory_bytes: 13508
#include <iostream>
#include <cstdio>
#include <cstring>
#include <set>
#include <vector>
#include <map>
#include <algorithm>
#define N 100005
#define Abs(a) ((a)<0?-(a):(a))
using namespace std;
struct P{
	int x,y;
	P(){}
	P(int a,int b){x=a;y=b;}
}a[N];
bool operator <(P a,P b){
	if(a.y!=b.y) return a.y<b.y;
	return a.x<b.x;
}
int n,S,T,fa[N],id,L[N],R[N],tot[N];
map<int,int> mp[2];
set<P> s[N<<1];
vector<int> sum[N<<1];
vector<P> b[N<<1];
int add(int op,int k,int val){
	for(int S=sum[op].size();k<=S;k+=k&-k) sum[op][k-1]+=val;
}
int find(int op,int k){
	int ans=0;
	for(int S=sum[op].size();k;k-=k&-k) ans+=sum[op][k-1];
	return ans;
}
bool cmp(P a,P b){
	return a.x<b.x;
}
int find(int k){
	if(fa[k]!=k) fa[k]=find(fa[k]);
	return fa[k];
}
void merge(int x,int y){
	x=find(x);
	y=find(y);
	fa[x]=y;
}
int main(){
	scanf("%d%d%d",&n,&S,&T);
	for(int i=1;i<=n;i++) scanf("%d%d",&a[i].x,&a[i].y),fa[i]=i;
	int dis=Abs(a[S].x-a[T].x)+Abs(a[S].y-a[T].y);
	int sx=a[S].x,sy=a[S].y;
	sort(a+1,a+n+1,cmp);
	for(int i=1;i<=n;i++) if(a[i].x==sx&&a[i].y==sy) S=i;
	for(int i=1;i<=n;i++){
		if(mp[0].find(a[i].x+a[i].y)==mp[0].end()) mp[0][a[i].x+a[i].y]=++id;
		if(mp[1].find(a[i].x-a[i].y)==mp[1].end()) mp[1][a[i].x-a[i].y]=++id;
		int X=mp[0][a[i].x+a[i].y],Y=mp[1][a[i].x-a[i].y];
		sum[X].push_back(0);
		sum[Y].push_back(0);
		b[X].push_back(P(-i,a[i].y));
		b[Y].push_back(P(i,a[i].y));
	}
	for(int i=1;i<=id;i++) sort(b[i].begin(),b[i].end());
	for(int i=1;i<=id;i++){
		for(int p=0,S=b[i].size();p<S;p++){
			if(b[i][p].x<0) L[-b[i][p].x]=p+1;
			else R[b[i][p].x]=p+1;
		}
	}
	/*for(int i=1;i<=n;i++){
		for(int p=i-1;p;p--) if(Abs(a[i].x-a[p].x)+Abs(a[i].y-a[p].y)==dis) cout<<i<<" "<<p<<endl,tot[i]--;
	}*/
	set<P>::iterator t,t1;
	for(int i=1;i<=n;i++){
		int X=mp[0][a[i].x+a[i].y],Y=mp[1][a[i].x-a[i].y];
		int dx=a[i].x+a[i].y-dis,dy=a[i].x-a[i].y-dis;
		if(mp[0].find(dx)!=mp[0].end()&&s[mp[0][dx]].size()){
			dx=mp[0][dx];
			for(t=s[dx].begin();t!=s[dx].end();++t){
				if((*t).y>a[i].y) break;
				merge((*t).x,i);
			}
			if(t!=s[dx].begin()){
				t1=s[dx].begin();
				if((*t).y>a[i].y) --t;
				if(t!=t1){
					++t1;
					for(;t1!=t;) s[dx].erase(t1++);
				}
			}
			int lst=lower_bound(b[dx].begin(),b[dx].end(),a[i])-b[dx].begin();
			tot[i]+=find(dx,lst);
		}
		if(mp[1].find(dy)!=mp[1].end()&&s[mp[1][dy]].size()){
			dy=mp[1][dy];
			t=s[dy].end();--t;
			t1=t;
			for(;;--t){
				if((*t).y<a[i].y) break;
				merge((*t).x,i);
				if(t==s[dy].begin()) break;
			}
			if(t!=t1){
				if((*t).y<a[i].y) ++t;
				if(t!=t1){
					--t1;
					for(;t1!=t;) s[dy].erase(t1--);
				}
			}
			int lst=upper_bound(b[dy].begin(),b[dy].end(),a[i])-b[dy].begin()+1;
			if(lst<=sum[dy].size()){
				if(b[dy][lst-1].y==a[i].y) lst++;
				tot[i]+=find(dy,sum[dy].size())-find(dy,lst-1);
			}
		}
		s[X].insert(P(i,a[i].y));
		s[Y].insert(P(i,a[i].y));
		add(X,L[i],1);
		add(Y,R[i],1);
	}
	long long ans=0;
	for(int i=1;i<=n;i++) if(find(i)==find(S)) ans+=tot[i];
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 49280
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
char a[10001];
int n;
bool x;
int main(){
	scanf("%s",a+1);
	int l=strlen(a+1);
	for(int i=1;i<=l;i++)
		if(a[i]=='C'){
			n=i;
			x=true;
			break;
		}
	if(!x){
		printf("No\n");
		return ~~(0-0);
	}
	for(int i=n+1;i<=l;i++)
		if(a[i]=='F'){
			printf("Yes\n");
			return ~~(0-0);
		}
	printf("No\n");
	return ~~(0-0);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N,S;
    cin >> N >> S;
    int count = 0;
    for(int i = 0;i <= N;++i)
    {
        for(int j = i;j <= N;++j)
        {
            for(int k = j;k <= N;++k)
            {   
                if(i + k + j == S)
                {
                    if(i == k && k == j)
                        count++;
                    else if(i == k || k == j || i == j)
                        count += 3;
                    else
                        count += 6;
                }
            }
        }
    }
    std::cout << count << endl;
}


Measured memory_bytes: 256
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container, std.format;
static import std.ascii;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
// dfmt on

void main()
{
    auto S = sread();
    bool n, w, s, e;
    foreach (c; S)
    {
        n = n || c == 'N';
        w = w || c == 'W';
        s = s || c == 'S';
        e = e || c == 'E';
    }
    writeln(((n == s) && (w == e)) ? "Yes" : "No");
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ALL(obj) obj.begin(),obj.end()
#define pb(obj) push_back(obj)
#define REP(i,N) for(ll i=0;i<N;i++)
typedef long long ll;
ll const MOD=1000000007;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,p,count=0;
    bool flag=false;
    cin>>N;
    vector<int>sub;
    for(int i=0;count<N;i++){
        p=5*i+2;
        flag=true;
        for(int j=2;j<=sqrt(p);j++){
            if(p%j==0){flag=false;break;}
        }
        if(flag){sub.pb(p);count++;}
    }
    for(int i=0;i<N;i++){
        cout<<sub[i]<<" ";
    }
    cout<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;

int main() {
  int N;
  cin >> N;
  if (N%10 == 7 || (N/10)%10 == 7 || (N/100)%10 == 7) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }

}

Measured memory_bytes: 3572
#include <iostream>
using namespace std;


int main()
{
	int a;
	cin >> a;
	int temp;
	temp = a;
	int add = 0;
	do {
		add += temp % 10;
		temp /= 10;
	} while (temp);
	if (!(a % add)) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;

//const double PI = acos(-1);
using ll = long long;
using ull = unsigned long long;
const int inf = 2e9;
const ll INF = 2e18;
const ll MOD = 1e9+7;

#define REP(i,n) for (int i = 0; i < (n); i++)
#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second

template<class T>
struct Fenwick {
    int N;
    vector<T> seg;
    Fenwick(int N) : N(N) {
        seg.resize(N+1);
        fill_n(begin(seg), N+1, 0);
    }
    /// i番目の要素にxを追加する
    void add(int i, T x) {
        i++;
        while (i <= N) {
            seg[i] += x;
            i += i & -i;
        }
    }
    /// [0, i)のsum
    T sum(int i) {
        T s{0};
        while (i > 0) {
            s += seg[i];
            i -= i & -i;
        }
        return s;
    }
    /// [a, b)のsum
    T sum(int a, int b) {
        return sum(b) - sum(a);
    }
};

ll n, k;
ll a[200010];
ll b[200010];
ll c[200010];

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);

  cin >> n >> k;

  REP(i,n) {
    cin >> a[i];
    if (i!=0)
      a[i] += a[i-1];
  }

  vector<pair<ll,int>> v;
  REP(i,n) {
    b[i] = a[i]-k*(ll)(i+1);
    v.pb({b[i],i});
  }

  sort(v.begin(),v.end());

  int cnt = 1;
  REP(i,n) {
    if (i==0) {
      c[v[i].se] = cnt;
    } else if (v[i].fi == v[i-1].fi) {
      c[v[i].se] = cnt;
    } else {
      c[v[i].se] = ++cnt;
    }
  }

//  REP(i,n) cout << a[i] << " ";
//  cout << endl;
//  REP(i,n) cout << b[i] << " ";
//  cout << endl;
//  REP(i,n) cout << c[i] << " ";
//  cout << endl;

  Fenwick<ll> BIT(cnt+1);
  ll ans = 0;

  REP(i,n) {
    if (b[i] >= 0) ans++;
    ans += BIT.sum(c[i]+1);
    BIT.add(c[i],1LL);
  }

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 10476
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define Sort(a) sort(a.begin(), a.end())
const int INF = 1<<30;
const ll MOD = 1000000007;

int main(void) {

    string s, t; cin >> s >> t;
    cout << t + s << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;

// GCD, LCM
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main()
{
    int A,B,C,D;
    cin>>A>>B>>C>>D;


    while(1){
        C-=B;
        if(C<=0){
            cout<<"Yes"<<endl;
            return 0;
        }

        A-=D;
        if(A<=0){
            cout<<"No"<<endl;
            return 0;
        }
    }

    return 0;
}

Measured memory_bytes: 3592
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <deque>
#include <numeric>
#include <sstream>
#include <iomanip>
using lint = long long;

int main()
{
    lint n;
    scanf("%lld", &n);

    std::deque<lint> q;

    for (int i = 0; i < n; ++i)
    {
        lint a;
        scanf("%lld", &a);

        q.push_back(a);
    }

    std::sort(q.begin(), q.end());

    lint front, back;
    lint left, right;
    lint ans = 0;

    front = q.front();
    q.pop_front();
    back = q.back();
    q.pop_back();

    left = front;
    right = back;

    ans += abs(right - left);

    for (int i = 0; i < n - 2; ++i)
    {
        front = q.front();
        back = q.back();

        if (left < right)
        {
            lint lb = abs(left - back);
            lint rf = abs(right - front);
            if (lb > rf)
            {
                ans += lb;
                left = back;
                q.pop_back();
            }
            else
            {
                ans += rf;
                right = front;
                q.pop_front();
            }
        }
        else
        {
            lint lf = abs(left - front);
            lint rb = abs(right - back);
            if (rb > lf)
            {
                ans += rb;
                right = back;
                q.pop_back();
            }
            else
            {
                ans += lf;
                left = front;
                q.pop_front();
            }
        }
    }

    printf("%lld", ans);

    return 0;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
int main(){
	int x[7];
	bool q=true;
	for(int i=0;i<6;i++){
		cin>>x[i];
	}
	if(x[4]-x[0]>x[5])q=false;
	if(q==true) cout<<"Yay!";
	else cout<<":(";
	cout<<"\n";
	return 0;
}

Measured memory_bytes: 3684
#include <bits/stdc++.h>
using namespace std;

int main()
{
	string S;
	int w;
	cin >> S >> w;
	int n = S.size();
	for (int i = 0; i < n; i += w) {
		cout << S[i];
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 256
#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>

#define FASTIO
#define ALL(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i < (r); ++i)

#ifdef FASTIO
#define scanf abacaba
#define printf abacaba
#endif

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

using namespace std;


/*
ll pw(ll a, ll b) {
	ll ans = 1; while (b) {
		while (!(b & 1)) b >>= 1, a = (a * a) % MOD;
		ans = (ans * a) % MOD, --b;
	} return ans;
}
*/
const ll MOD = 1e9 + 7;

string s;
int sm[210000];
int nx[3];
int go[210000][3];
ll dp[210000];

int main() {
#ifdef FASTIO
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#endif
	int fl = 0;
	cin >> s;
	for (int i = 0; i + 1 < s.size(); ++i) {
		if (s[i] == s[i + 1]) {
			fl = 1;
			break;
		}
	}
	if (!fl) {
		cout << 1 << "\n";
		return 0;
	}
	int n = s.size();
	sm[n] = 0;
	for (int i = n - 1; i >= 0; --i) {
		if (s[i] == 'a')
			sm[i] = sm[i + 1] + 1;
		else
			sm[i] = sm[i + 1] - 1;
		sm[i] = (sm[i] + 3) % 3;
	}
	for (int i = 0; i < 3; ++i)
		nx[i] = -1;
	int lst = n;
	for (int i = n - 1; i >= 0; --i) {
		if (lst > i + 1 && s[i + 1] == s[i]) {
			while (lst > i + 1) {
				nx[sm[lst]] = lst;
				--lst;
			}
		}
		if (s[i] == 'a') {
			go[i][0] = i + 1;
			go[i][1] = nx[(sm[i] + 1) % 3];
		}
		else {
			go[i][1] = i + 1;
			go[i][0] = nx[(sm[i] + 2) % 3];
		}
	}
	dp[0] = 1;
	for (int i = 0; i < s.size(); ++i) {
		for (int j = 0; j < 2; ++j)
			if (go[i][j] != -1)
				dp[go[i][j]] = (dp[go[i][j]] + dp[i]) % MOD;
	}
	ll ans = 0;
	for (int i = 1; i <= n; ++i) {
		if (sm[i] == 0)
			ans = (ans + dp[i]) % MOD;
	}
	cout << ans << "\n";
	return 0;
}




Measured memory_bytes: 4096
n,k = map(int,input().split())
ro, sc ,pa = map(int,input().split())
a = input()
dict = {'r':'p', 's':'r', 'p': 's'}
scores = {'r':ro,'s':sc,'p':pa}
can_lelect = 'rsp'
select = ['' for _ in range(n)]
cant = [[] for _ in range(n)]
left = 0
cur = k
for i in range(k):
    need = dict[a[i]]
    select[i] = need
while cur < n:
    need_cur = dict[a[cur]]
    need_left = dict[a[left]]
    if select[left] == '':
        select[left] = need_left
    if need_cur == select[left] :
        if select[left] != need_left:
            cant[left].append(need_cur)
            for v in can_lelect:
                if v not in cant[left]:
                    select[left] = v
                    break
            select[cur] = need_cur
        else:
            cant[cur].append(need_cur)
            for v in can_lelect:
                if  v not in cant[cur]:
                    select[cur] = v
                    break
    else:
        select[cur] = need_cur
    left+=1
    cur +=1
total = 0
for i in range(n):
    c = select[i]
    if c == dict[a[i]]:
        total+=scores[c]
print(total)

Measured memory_bytes: 13044
#include <bits/stdc++.h>
using namespace std;

int main() {
    string a,b,c;
    cin >> a >> b >> c;
    if(a[a.length()-1]==b[0] && c[0]==b[b.length()-1]){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;

int D, A[10];
const int MAX_DATA = 100000;
bool owata[MAX_DATA];

bool dfs(int n,int a,int b)
{
	if(n==10)
	{
		return true;
	}

	if(A[n]>a){
	if(dfs(n+1,A[n],b))
	{
		return true;
	}
	}

	if(A[n]>b){
	if(dfs(n+1,a,A[n]))
	{
		return true;
	}
	}

	return false;

}

int main(){
	cin>>D;
	for(int i=1;i<=D;i++){
		for(int j=0;j<10;j++){
			cin>>A[j];
		}

		owata[i] = dfs(0, 0, 0);
	}
	for(int i=1;i<=D;i++)
	{
		cout << (owata[i] ? "YES":"NO") << endl;
	}
}

Measured memory_bytes: 1156
#include <iostream> 
#include <string> 
#include <vector> 
#include <cmath> 
#include <algorithm> 
#include <cstdlib> 
#include <ctime> 
#include <cstdio> 
#include <functional> 
#include <set> 
#include <queue> 
#include <cctype> 
#include <climits> 
#include <stack> 
#include <map> 
#include <cstring> 

using namespace std; 

const long long mod=1e9+7;

int main(){

    int h,w;
    cin>>h>>w;

    vector<string> table(h);
    for(int i=0;i<h;i++) cin>>table[i];

    vector<vector<int> > yoko(h,vector<int>(w,0));
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(table[i][j]=='#') yoko[i][j]++;
            if(j!=0) yoko[i][j]+=yoko[i][j-1];
        }
    }

    vector<vector<int> > tate(w,vector<int>(h,0));
    for(int i=0;i<w;i++){
        for(int j=0;j<h;j++){
            if(table[j][i]=='#') tate[i][j]++;
            if(j!=0) tate[i][j]+=tate[i][j-1];
        }
    }

    int res=0;

    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            int cnt=0;
            if(table[i][j]=='#'){
                continue;
            }

            int yoko_ = upper_bound(yoko[i].begin(),yoko[i].end(),yoko[i][j])
                        - lower_bound(yoko[i].begin(),yoko[i].end(),yoko[i][j]);
            if(yoko[i][j]!=0) yoko_--;
            
            int tate_ = upper_bound(tate[j].begin(),tate[j].end(),tate[j][i])
                        - lower_bound(tate[j].begin(),tate[j].end(),tate[j][i]);
            if(tate[j][i]!=0) tate_--;

            cnt=tate_+yoko_-1;

            res=max(res,cnt);
        }
    }

    cout<<res<<endl;

    return 0;
}

Measured memory_bytes: 37760
#include <stdio.h>
#include <iostream>
#include <vector>
using namespace std;
int dp[2][105];
int can[2][105];
int n;
int pick(int x, int y)
{
    if (x==1&&y==n-1)
    {
        return can[x][y];
    }
    if (dp[x][y]!=-1)return dp[x][y];
    if (x!=1)dp[x][y]=pick(x+1,y);
    if (y+1<n)dp[x][y]=max(dp[x][y],pick(x,y+1));
    dp[x][y]+=can[x][y];
    return dp[x][y];
}
int main()
{
    cin>>n;
    for (int i=0;i<n;i++)
    {
        dp[0][i]=-1;
        dp[1][i]=-1;
        cin>>can[0][i];
    }
    for (int i=0;i<n;i++)
    {
        cin>>can[1][i];
    }
    printf ("%d\n",pick(0,0));
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <map>
#include <numeric>
using namespace std;

const int MOD = 1000000007;
typedef long long ll;


int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long N;
  cin>>N;
  long long K=0;
  for(int i=0;i<N;i++){
    if(i*(i+1)/2==N){
      K=i;
      break;
    }
  }
  if(N==1){
    cout<<"Yes"<<endl;
    cout<<2<<endl;
    cout<<"1 1"<<endl;
    cout<<"1 1"<<endl;
  }else{
    if(K==0){
      cout<<"No"<<endl;
    }else{
      cout<<"Yes"<<endl;
      cout<<K+1<<endl;
      vector<vector<long long> > res(K+1, vector<long long>());
      long long sum = 1;
      for (int k = K; k >= 1; --k) {
        for (int i = 0; i < k; ++i) {
          res[K-k].push_back(sum + i);
          res[K-k + i + 1].push_back(sum + i);
        }
        sum += k;
      }

      for (int i = 0; i < K+1; ++i) {
        cout << res[i].size();
        for (int j = 0; j < res[i].size(); ++j) cout << " " << res[i][j];
        cout << endl;
      }
    }
  }
}


Measured memory_bytes: 3200
/**
 * D - Teleporter
 * https://atcoder.jp/contests/abc167/tasks/abc167_d
 */
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    // 高橋王は正の整数 K が好きです。わがままな高橋王は、町 1 から出発してテレポーターをちょうど K 回使うと、どの町に到着するかが知りたいです。
    // 高橋王のために、これを求めるプログラムを作成してください。
    long long N, K;
    cin >> N >> K;

    vector<long long>A(N);
    // vector<long long>HND(N + 1, 0);
    for (int i = 0; i < N; i++) {
        cin >> A.at(i);
        // HND.at( A.at(i) )++; 
    }

    // 最多出現の値を求める
    /*
    long long maxA = 0;
    long long maxHND = 0;
    for (int i = 0; i < N + 1; i++) {
        if (HND.at(i) > maxHND) {
            maxHND = HND.at(i);
            maxA = i;
        }
    }
    */

    long long place = 1;
    vector<long long>HND(N + 1, 0);
    long long kaisuu = 0;
    for (long long i = 1; i <= K; i++) {
        place = A.at(place - 1);
        kaisuu++;
        if (HND.at(place) == 0) {
            HND.at(place) = kaisuu;
        } else if (HND.at(place) > 0) {
            long long loopcnt = kaisuu - HND.at(place);
            i += ((K - i) / loopcnt) * loopcnt;
            // cout << "koko";
        }
    }
    cout << place << endl;
 

  /*
    long long place = 1;
    long long kaisuu = 0;
    long long maxAkai = 0;
    long long syokai = 0;
    for (long long i = 0; i < K; i++) {
        place = A.at(place - 1);
        if (place == maxA) {
            maxAkai++;
        }
 
        if (maxAkai == 0) {
            syokai++;
        } else if (maxAkai == 1) {
            kaisuu++;
        } else if (maxAkai == 2) {
            i = syokai + ((K - syokai) / kaisuu) * kaisuu;
            maxAkai++;
        }
    }
    cout << place << endl;
    */
    // cout << score << endl;
}
 

Measured memory_bytes: 6428
#include <bits/stdc++.h>
using namespace std;

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair
#define F first
#define S second

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


#define MAX_N 8
i64 N;
i64 A[MAX_N];
i64 P[MAX_N];
i64 Q[MAX_N];

int main() {
  REP(i, MAX_N) {
    A[i] = 0;
    P[i] = 0;
    Q[i] = 0;
  }

  cin >> N;
  REP(i, N) cin >> P[i];
  REP(i, N) cin >> Q[i];

  REPS(i, N) A[i - 1] = i;

  i64 a, b;
  i64 k = 0;
  do {
    bool eq = true;
    REP(i, N) {
      if (P[i] != A[i]) {
        eq = false;
        break;
      }
    }
    if (eq) a = k;

    eq = true;
    REP(i, N) {
      if (Q[i] != A[i]) {
        eq = false;
        break;
      }
    }
    if (eq) b = k;

    k++;
  } while(next_permutation(A, A + N));

  cout << abs(a - b) << endl;

  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main () {
    int data[5],i,avg;
    int sum = 0;
    for (i = 0; i < 5; i++) {
        scanf("%d",&data[i]);
    }
    for (i = 0; i < 5; i++) {
        if(data[i] < 40) {
            data[i] = 40;
        }
        sum = sum + data[i];
    }
    avg = sum / 5;
    printf("%d\n",avg);
}

Measured memory_bytes: 1024
#include<stdio.h>
int main()
{
    int a,b,c,d,e,f,g,h,i;
    for(a=1; a<=9; a++)
    {
        printf("1x%d=%d\n",a,1*a);
    }
    for(b=1; b<=9; b++)
    {
        printf("2x%d=%d\n",b,2*b);
    }
    for(c=1; c<=9; c++)
    {
        printf("3x%d=%d\n",c,3*c);
    }
    for(d=1; d<=9; d++)

    {
        printf("4x%d=%d\n",d,4*d);
    }
    for(e=1; e<=9; e++)

    {
        printf("5x%d=%d\n",e,5*e);
    }
    for(f=1; f<=9; f++)
    {
        printf("6x%d=%d\n",f,6*f);
    }
    for(g=1; g<=9; g++)
    {
        printf("7x%d=%d\n",g,7*g);
    }
    for(h=1; h<=9; h++)
    {
        printf("8x%d=%d\n",h,8*h);
    }
    for(i=1; i<=9; i++)
    {
        printf("9x%d=%d\n",i,9*i);
    }


    return 0;
}



Measured memory_bytes: 2000
import std.algorithm,
       std.string,
       std.array,
       std.range,
       std.stdio,
       std.conv;

void main() {
  int[] nm = readln.chomp.split.to!(int[]);
  int n = nm[0],
      m = nm[1];

  writeln((n - 1) * (m - 1));
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define sc(x) scanf("%lld",&x)
#define pr(x) printf("%lld\n",x)
#define clr(x) memset(x, 0, sizeof(x))
#define all(x) x.begin(), x.end()
typedef pair<ll, ll> pii;
typedef vector< ll > vl;
typedef vector< pii > vpii;

//DONT WASTE YOUR TIME
//prove yourself
//remember....fuck ps&&as hard....show them your are better then them
//Be confident.....dont lose hope.......You can do it.....
//dimaag  khoob h tere meh ....bas concentration ki kami h
//CONCENTRATE
//A,B,C dimaag nhi ...observation h .....zyaada mat sochna unme.....bas observe karna dhyaan se aur implement kar daal jitni jaldi ho sake

//capture it

const ll N= 1e6+55,mod = 1e9+7;

set<ll>s;
int main() {
 	//freopen("task.in","r",stdin);freopen("task.out","w",stdout);
	ll i,j,k,n;
	sc(n);
	while(n--){
		sc(i);
		s.insert(i);
	}	
	j=s.size();
	pr(j);

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define endl "\n"
#define se second
#define ls( s) (s&(-s))
#define ll long long
#define inf 0x3f3f3f3f
#define fast    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int N = 2e5+10;
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
const ll mod =    2019;
int h,w,n;
int xf,yf;
string s,t;
bool go(int cur,int mx,char c1,char c2)
{
	int l=cur,r=cur;
	for(int i=0;i<n;i++)
	{
		if(s[i]==c1)
		l--;
		else if(s[i]==c2)
		r++;
		if((!l)||(r>mx))
		return true;
		if(t[i]==c1)
		r--;
		if(t[i]==c2)
		l++;
		r=max(r,1);
		l=min(l,mx);
	}
	return false;
}
int main()
{  fast
   cin>>h>>w>>n>>xf>>yf;
   cin>>s>>t;
  if(go(xf,h,'U','D')||go(yf,w,'L','R'))cout<<"NO";
  else
  cout<<"YES";
}


Measured memory_bytes: 920
# -*- coding: utf-8 -*-
H, W = map(int, input().split())
 
if H*W %3 ==0:
    print(0)
    exit()
 
diff_list = [W,H]
 
#縦→横
split1 = [W//3, W//3 + 1]
split2 = [H//2, H//2 +1]
 
for w in split1:
    for h in split2:
        temp = [H*w, h*(W-w), (H-h)*(W-w)]
        diff_list.append(abs(max(temp)-min(temp)))
 
#横→縦
if H != W:
    split1 = [H//3, H//3 + 1]
    split2 = [W//2, W//2 + 1]
 
    for h in split1:
        for w in split2:
            temp = [h*W, (H-h)*w, (H-h)*(W-w)]
            diff_list.append(abs(max(temp)-min(temp)))
 
# print(diff_list)
print(min(diff_list))

Measured memory_bytes: 3064
#include<bits/stdc++.h>

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    int x;
    int sum=0;
    int mn=0;
    while(n--)
    {
        cin>>x;
        mn=max(x,mn);
        sum+=x;
    }
    if(sum-mn>mn)cout<<"Yes\n";
    else cout<<"No\n";
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    long long N,A,B;
    cin>>N>>A>>B;
    if (A > B) {
        cout << 0 << endl;
        return 0;
    }
    if (N == 1 && A != B) {
        cout << 0 << endl;
        return 0;
    }
    if (N == 1 && A == B) {
        cout << 1 << endl;
        return 0;
    }
    long long min = (N - 1) * A + B;
    long long max = (N - 1) * B + A;
    cout << max - min + 1 << endl;
    return 0;
}

Measured memory_bytes: 256
#[warn(unused_imports)]
use itertools::*;
use proconio::*;

fn main() {
    input! {
        _: usize,
        s: String,
    }
    let chars: Vec<char> = s.chars().collect();

    let cnt = |c| s.chars().filter(|&x| x == c).count();
    let mut ans = cnt('R') * cnt('G') * cnt('B');

    for i in 0..chars.len() {
        let first = chars[i];
        for j in i + 1..(chars.len() + i + 1) / 2 {
            let second = chars[j];
            if first != second {
                let third = chars[2 * j - i];
                if third != second && first != third {
                    ans -= 1;
                }
            }
        }
    }

    println!("{}", ans);
}


Measured memory_bytes: 2144
def solve():
    N = int(input())
    L = sorted(map(int, input().split()))
    N = len(L)
    if N < 3:
        print(0)
        return
    ans = 0
    for i in range(N-2):
        for j in range(i+1, N-1):
            a = L[i]
            b = L[j]
            if a == b:
                continue
            for k in range(j+1, N):
                c = L[k]
                if a == c or b == c:
                    continue
                if a + b <= c:
                    break
                ans += 1
    print(ans)

solve()

Measured memory_bytes: 69324
#include <iostream>
using namespace std;
bool num[50021];
int main()
{
	int n;
	while(cin >> n)
	{
		num[0]=num[1]=true; for(int i=2;i<=n;i++) num[i]=false;
		int ansup,anslow;
		for(int i=2;i<=50000;i++)
		{
			if(num[i]==false)
			{
				for(int j=i*2;j<=50021;j+=i) num[j]=true;
			}
		}
		for(int j=n+1; ;j++) if(num[j]==false) {ansup=j; break;}
		for(int j=n-1; ;j--) if(num[j]==false) {anslow=j; break;}
		cout << anslow << ' ' << ansup << '\n' ;
	}
}

Measured memory_bytes: 1208
a=[list(map(int,input().split())) for i in range(3)]
n=int(input())
for i in range(n):
    b=int(input())
    for j in range(3):
        for k in range(3):
            if a[j][k]==b:
                a[j][k]=0
 
for i in range(3):
    flag=True
    for j in range(3):
        if a[i][j]!=0:
            flag=False
    if flag:
        print("Yes")
        exit()
 
for i in range(3):
    flag=True
    for j in range(3):
        if a[j][i]!=0:
            flag=False
    if flag:
        print("Yes")
        exit()

flag=True
for i in range(3):
    if a[i][i]!=0:
        flag=False
if flag:
    print("Yes")
    exit()
 
for i in range(3):
    if a[i][2-i]!=0:
        print("No")
        exit()
print("Yes")
exit()

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long int ll;
typedef pair<int,int> P;

#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 1e9;

int main()
{
    int n,l;
    cin>>n>>l;
    int sum = l*n + (n-1)*n/2;
    int res = 1e9;
    int ans = -1;
    for(int i = 0; i < n; i++){
        if(res > abs(l+i)){
            ans = sum-(l+i);
            res = abs(l+i);
        }
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

string str;

int main(void){
    cin >> str;
    int cnt=0;
    int cnt2=0;
    for(int i=0;i<str.size();i++){
        if(i%2==0){
            if(str[i]=='0')cnt++;
            else cnt2++;
        }else{
            if(str[i]=='1')cnt++;
            else cnt2++;
        }
    }
    printf("%d\n",min(cnt,cnt2));
    return 0;
}





Measured memory_bytes: 512
#include<iostream>
using namespace std;

int main(){
    char a,b;
    cin >> a >> b;
    if(a == 'H'){
        cout << b << endl;
    }else{
        if(b == 'H') cout << 'D' << endl;
        if(b == 'D') cout << 'H' << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>

using namespace std;
int main()
{
    int A, B, C, K;
    cin >> A >> B >> C;
    cin >> K;
    
    int max = A;
    int sum = B+C;
    if( max < B){
        max=B;
        sum=A+C;
    }
    if( max < C){
        max=C;
        sum=A+B;
    }

    for(int i=0; i<K; i++){
        max = 2 * max;
    }
    sum+=max;

    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define pb push_back
#define fi first
#define se second
const int maxn=1e5+10;
const int mod=1e9+7;
const int inf=0x3f3f3f3f;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	string a;
	cin>>a;
	bool f=true;
	for(int i=0;i<a.size();i++)
	{
		if((i&1)==1&&a[i]=='R') f=false;
		if((i&1)==0&&a[i]=='L') f=false;
	}
	if(f) cout<<"Yes"<<'\n';
	else cout<<"No"<<'\n';
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;

int main() {
  int N, c;
  cin >> N;
  c = 0;
  int t = N;
  while (t > 0){
    c += t % 10;
    t /= 10;
  }
  if(N % c == 0){
  cout << "Yes" << endl;
  }
  else{
  cout << "No" << endl;
  }
}


Measured memory_bytes: 3544
import sys
import operator

input=sys.stdin.readline

def main():
    n,m = map(int, input().split())
    a = [int(i) for i in input().split()]
    sousa = []
    d = []
    for _ in range(m):
        sousa.append([int(i) for i in input().split()])

    a.sort()
    
    sousa.sort(key=operator.itemgetter(1), reverse = True)

    for i in sousa:
        d.extend([i[1]] * i[0])
        if len(d)>n:
            break

    dIdx = 0
    dLen = len(d)

    for i in range(len(a)):
        if a[i] < d[dIdx]:
            a[i] = d[dIdx]
            dIdx += 1
            if dIdx >= dLen:
                break

    print(sum(a))

if __name__ == "__main__":
    main()


Measured memory_bytes: 80108
#include <bits/stdc++.h>
#include <numeric>
#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())

#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false
#define LL long long
#define Dev 1000000007

// sort(a.begin(), a.end(), std::greater<int>());
using namespace std;

int main()
{
    string a, b, c;
    cin >> a >> b >> c;
    if (*(a.end() - 1) == b[0] && *(b.end() - 1) == c[0])
    {
        cout << "YES" << endl;
    }
    else
    {
        cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      	int a = sc.nextInt();
      	int b = sc.nextInt();
 	    int c = sc.nextInt();
	   	
      	if(a==b){
        	System.out.println(c);
        }else if(b==c){
        	System.out.println(a);
        }else{
        	System.out.println(b);
        }
    }
}

Measured memory_bytes: 35560
#![allow(non_snake_case, unused)]
use std::cmp::*;
use std::collections::*;

pub fn readln() -> String {
    let mut line = String::new();
    ::std::io::stdin()
        .read_line(&mut line)
        .unwrap_or_else(|e| panic!("{}", e));
    line
}
macro_rules! read {
	($($t:tt),*; $n:expr) => {{
		let stdin = ::std::io::stdin();
		let ret = ::std::io::BufRead::lines(stdin.lock()).take($n).map(|line| {
			let line = line.unwrap();
			let mut it = line.split_whitespace();
			_read!(it; $($t),*)
		}).collect::<Vec<_>>();
		ret
	}};
	($($t:tt),*) => {{
		let line = readln();
		let mut it = line.split_whitespace();
		_read!(it; $($t),*)
	}};
}

macro_rules! _read {
	($it:ident; [char]) => {
		_read!($it; String).chars().collect::<Vec<_>>()
	};
	($it:ident; [u8]) => {
		Vec::from(_read!($it; String).into_bytes())
	};
	($it:ident; [$t:ty]) => {
		$it.map(|s| s.parse::<$t>().unwrap_or_else(|e| panic!("{}", e))).collect::<Vec<_>>()
	};
	($it:ident; $t:ty) => {
		$it.next().unwrap_or_else(|| panic!("input mismatch")).parse::<$t>().unwrap_or_else(|e| panic!("{}", e))
	};
	($it:ident; $($t:ty),+) => {
		($(_read!($it; $t)),*)
	};
}

fn main() {
    let n = read!(usize);
    let mut table = vec![vec![2; n]; n];

    for i in 0..n {
        let a = read!(usize);
        for j in 0..a {
            let l = read!([usize]);
            table[i][l[0]-1] = l[1];
        }
    }

    let mut cnt = 0;
    for bit in 0..1 << n {
        let mut hyp = vec![0; n];
        for i in 0..n {
            hyp[i] = (bit >> i) & 1;
        }

        let mut flag = true;
        for r in 0..n {
            if hyp[r] == 0 {
                continue;
            }
            for c in 0..n {
                let acc = table[r][c];
                if acc == 2 {
                    continue;
                }
                let acc_hyp = if hyp[r] == 1 {hyp[c]} else {0};
                if acc != acc_hyp {
                    flag = false;
                }
            }
        }
        //
        if flag {
            cnt = max(cnt, hyp.iter().sum());
        }
    }

    println!("{}", cnt);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
#define int ll
using PII = pair<int, int>;
template <typename T> using V = vector<T>;
template <typename T> using VV = vector<V<T>>;
template <typename T> using VVV = vector<VV<T>>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define PB push_back

const ll INF = (1LL<<60);
const int MOD = 1000000007;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }
template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')';
  return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'[';
  REP(i, a.size()) {out<<a[i];if(i!=a.size()-1)out<<',';}
  out<<']';
  return out;
}

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};

signed main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);

  int n, x;
  cin >> n >> x;
  V<int> v(n);
  REP(i, n) cin >> v[i], v[i] -= x;

  int g = v[0];
  REP(i, n) {
    if(v[i] == 0) continue;
    g = __gcd(g, abs(v[i]));
  }

  cout << g << endl;

  return 0;
}


Measured memory_bytes: 1024