akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

inline ll lcm(ll x,ll y) {
  return x/__gcd(x,y)*y;
}

int prime[10005];
bool check[10005];

void pre(int n) {
  int tot=0;
  for(int i=2;i<=n;i++) {
  	if (!check[i]) prime[++tot]=i;
  	for(int j=1;j<=tot&&i*prime[j]<=n;j++) {
  		check[i*prime[j]]=1;
  		if (i%prime[j]==0) break;
	  }
  }
}

ll ans[505][505],val1[1005],val2[1005];

int main() {
  pre(1e4);
  int n;
  scanf("%d",&n);
  if (n==2) {
  	puts("4 7");
  	puts("23 10");
  	return 0;
  }
  int cnt=1;
  for(int i=1;i<=n;i++)
    for(int j=1;j<=n;j++)
      if ((i+j)&1) {
      	if (!val1[i-j+n]) val1[i-j+n]=prime[++cnt];
      	ans[i][j]=val1[i-j+n];
	  }
  for(int i=1;i<=n;i++)
    for(int j=1;j<=n;j++)
      if ((i+j)&1) {
      	if (!val2[i+j]) val2[i+j]=prime[++cnt];
      	ans[i][j]*=val2[i+j];
	  }
  for(int i=1;i<=n;i++)
    for(int j=1;j<=n;j++)
      if (!((i+j)&1)) {
      	ans[i][j]=1;
      	if (i>1) ans[i][j]=lcm(ans[i][j],ans[i-1][j]);
      	if (i<n) ans[i][j]=lcm(ans[i][j],ans[i+1][j]);
      	if (j>1) ans[i][j]=lcm(ans[i][j],ans[i][j-1]);
      	if (j<n) ans[i][j]=lcm(ans[i][j],ans[i][j+1]);
      	ans[i][j]++;
	  }
  for(int i=1;i<=n;i++) {
    for(int j=1;j<=n;j++) printf("%lld ",ans[i][j]);
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 5120
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<vector>
#include<list>
#include<functional>
#include<algorithm>
#include<string>
#include<cmath>
#include<complex>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

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

	int N, K;
	cin >> N >> K;
	vector<int> l(N);
	REP(i, N) cin >> l[i];
	sort(l.begin(), l.end(), greater<int>());
	int res = 0;
	REP(i, K) res += l[i];
	cout << res << "\n";

	return 0;
}

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
using P = pair<ll, ll>;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
struct edge {
  ll to, cost;
};

int main() {
  ll N; cin >> N;
  vector<ll> A(N); REP(i, N) cin >> A[i];
  const ll MOD = pow(10, 9) + 7;
  ll ans = 0;
  ll res = 0; // カッコの中
  for(int i = N - 1; i >= 1; --i) {
    res += A[i];
    ll tmp2 = res % MOD;
    ll tmp = A[i - 1] * tmp2;
    tmp %= MOD;
    ans += tmp;
    ans %= MOD;
  }
  cout << ans << endl;
}

Measured memory_bytes: 4744
/*     ####   ####  #               ####  #        ##   #    # #    # ###### #####
      #      #    # #              #      #       #  #  ##  ## ##  ## #      #    #
       ####  #    # #               ####  #      #    # # ## # # ## # #####  #    #
           # #  # # #                   # #      ###### #    # #    # #      #####
      #    # #   #  #              #    # #      #    # #    # #    # #      #   #
       ####   ### # ###### #######  ####  ###### #    # #    # #    # ###### #    #

*/

#include<bits/stdc++.h>
using namespace std;

typedef long long int LLi;
typedef long long LL;
typedef vector<LLi> VLL;
typedef vector<string> VS;
typedef vector<pair<LLi, LLi> > VP;


#define For(in) for (LLi i = 0; i < (n); i++)
#define FOR(in) for(LLi i=1; i <= (n); i++)
#define pb push_back
#define sr(v) sort(v.begin(), v.end())
#define rev(v) reverse(v.begin(), v.end())
#define uniq(v) v.erase(unique(v.begin(), v.end()), v.end());
#define exit(); return 0;
#define no "NO"
#define yes "YES"
#define con continue;

LLi max_3(LLi a, LLi b, LLi c)
{
    return max(a,max(b,c));
}
LLi min_3(LLi a, LLi b, LLi c)
{
    return min(a,min(b,c));
}

main()
{
    LLi q,t;
 //    cin>>t;
  //  while(t--)
  //  {
        LLi a=0,b=0,c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,r=0,u=0,w=0,x=0,y=0,z=0;
        LLi aa[1000];
        LLi flag=0, flag1=0, co=0, co1=0, co2=0, co3=0, x1=0, x2=0, y1=0, y2=0, z1=0, z2=0;
        LLi ma=0, mi=100000000;
        LLi mid=0, temp=0, stop=0, start=0;
        double pi= 3.141592653589793;
        double d1=0.0, d2, d3, d4;
        VLL v,v1,v2,v3,v4,v5,v6,v7,v8,v9,v10;
        VS vs, vs1, vs2, vs3, vs4;
        VP vp, vp1,vp2;
        char ch, ch1, ch2;
        string str, str1, str2, str3, str4, str5;
        pair<LLi, LLi> pa;
        list<LLi> li, li1;
        map<LLi, LLi> mp, mp1;
        set<LLi> st;
        map<LLi ,LLi> :: iterator imll;
        VLL :: iterator ivll;
        set<LLi> :: iterator isll;
        VP :: iterator ivp;

        cin>>x>>y;

       
        a = x*4;
        b = x*2;
        if(y<=a && y>=b && y%2==0)
        {
            cout<<"Yes"<<endl;
            
        }
        else cout<<"No"<<endl;





  //   }
    exit()

}


Measured memory_bytes: 3608
//ウンコ
#include<bits/stdc++.h>
#define X first
#define Y second
#define pb emplace_back
#define FOR(i,a,b) for(int (i)=(a);i<(b);++(i))
#define EFOR(i,a,b) for(int (i)=(a);i<=(b);++(i))
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef ll LL;
typedef pii PII;
typedef pll PLL;
template<class T> using vv=vector<vector<T>>;
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
const ll MOD=1e9+7;

int N;
int M;
char field[2145][2145];
int rimos[2145][2145];
int pile[2145][2145];

int main() {
  scanf("%d%d", &N, &M);
  rep(i, N) {
    rep(j, M) {
      scanf(" %c", &field[i][j]);
      if (field[i][j] == '#') rimos[i][j] = 1;
      else rimos[i][j] = 0;
    }
  }

  rrep(i, N) {
    rreps(j, 1, M) {
      rimos[i][j] ^= rimos[i][j-1];
    }
  }

  rreps(i, 1, N) {
    rrep(j, M) {
      rimos[i][j] ^= rimos[i-1][j];
    }
  }

  reps(i, 1, N) {
    reps(j, 1, M) {
      if (rimos[i][j]) pile[i][j] = 0;
      else pile[i][j] = pile[i-1][j] + 1;
    }
  }

  /*reps(i, 1, N) {
    reps(j, 1, M) {
      printf("%01d ", pile[i][j]);
    }puts("");
  }*/

  int ans = max(N, M);
  reps(i, 1, N) {
    deque<pii> deq;
    reps(j, 1, M) {
      int width = 0;
      while (!deq.empty() && deq.back().first >= pile[i][j]) {
        int height = deq.back().first;
        width += deq.back().second;
        ans = max(ans, (height+1)*(width+1));
        deq.pop_back();
      }

      deq.push_back(pii(pile[i][j], width+1));
    }

    int width = 0;
    while (!deq.empty()) {
      int height = deq.back().first;
      width += deq.back().second;
      ans = max(ans, (height+1)*(width+1));
      deq.pop_back();
    }
  }
  printf("%d\n", ans);
}


Measured memory_bytes: 40448
#include <iostream>
using namespace std;
int main(){
  int N;
  cin >> N;
  int max = -1;
  int min = 1001;
  int a[N];
  for(int i = 0; i < N; ++i){
    cin >> a[i];
    if(max < a[i])max = a[i];
    if(min > a[i])min = a[i];
  }
  cout << max - min << endl;
  return 0;
}


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

int main(int argc, char **argv) {
  int n, k, d;
  cin >> n >> k;
  bool disable[10];
  for (int i = 0; i < 10; i++) {
    disable[i] = false;
  }
  for (int i = 0; i < k; i++) {
    cin >> d;
    disable[d] = true;
  }
  int tmp;
  for (;;) {
    tmp = n;
    for (int i = 0; i < 5; i++) {
      if (disable[tmp % 10]) {
        n++;
        break;
      }
      if((tmp /= 10) == 0){
        cout << n;
        return 0;
      }
    }
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cstdlib>
using namespace std;
const int MAXN = 1e8 + 7;
int A[MAXN], N;

int binSearch( int x ) {
    int lb = 0, ub = N;
    while( lb < ub ) {
        int mid = ( ub + lb ) / 2;
        if ( A[mid] == x ) return 1;
        else if ( A[mid] > x ) ub = mid;
        else lb = mid + 1;
    }
    return 0;
}

int main( ) {
    scanf("%d", &N);
    for ( int i = 0; i < N; i++ ) scanf("%d", &A[i]);
    int q, t, cnt = 0;
    scanf("%d", &q);
    for ( int i = 0; i < q; i++ ) {
        scanf("%d", &t);
        if ( binSearch(t) ) cnt++;
    }
    printf("%d\n", cnt);
    return 0;
}



Measured memory_bytes: 3504
S = input()
T = input()
cnt = 0
s = S + S
ans=False
if S==T:
  ans=True
else:
  for i in range(len(S)):
    if s[i]==T[0]:
        for j in range(len(T)):
            if s[i+j]==T[j]:
                cnt +=1
        if (cnt%len(T))==0:
          ans=True
        cnt=0
          
if ans==True:
  print('Yes')
else:
  print('No')



Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)

int main(){
    ll S;
    cin >> S;
    ll x1 = 1e9;
    ll y2 = (S+x1-1)/x1;
    ll x2 = x1*y2 - S;
    cerr << abs(x1*y2 - x2) << endl;
    cout << "0 0 " << x1 << " 1 " << x2 << " " << y2 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <tuple>
#include <stdio.h>
#include <bitset>
#include <limits.h>
#include <complex>
#include <deque>
#include <iomanip>
#include <list>
using namespace std;
#define pi pair<int32,int32>
#define pl pair<int64,int64>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define en cout << endl //セミコロンつけろ
//#define MM 1000000000
//#define MOD MM+7
const int MM = 1e9;
const int MOD = MM+7;
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
// 'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122
template<typename T>
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}
template<typename T>
T LCM(T x,T y){
    T gc = GCD(x,y);
    return x*y/gc;
}
int N,a[100010];
long long f(int s,int N){
    long long ret = 0,sum = 0;
    for(int i = 0; i < N; i++){
        sum += a[i];
        if (sum * s <= 0){
            ret += abs(sum) + 1;
            sum = s;
        }
        s *= -1;
    }
    return ret;
}

int main(){
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> a[i];
    }
    cout << min(f(1,N),f(-1,N)) << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <math.h>
#include <stdlib.h>
#include <stdio.h>

using namespace std;

int main()
{
int N;
int D;
cin >> N >> D;
int a[N];
int b[N];
for(int i=0;i < N;i++)
{
cin >> a[i] >> b[i];
// cout << a[i] << b[i];
}
double dBuf = 0;
  double dBuf1 = 0;
  double dBuf2 = 0;
int counter = 0;
for(int j=0;j < N;j++)
{
dBuf1 = abs(a[j]);
dBuf2 = abs(b[j]);
  
  // cout << dBuf1 <<" "<< dBuf2<<endl;
dBuf = sqrt(dBuf1*dBuf1+dBuf2*dBuf2);

if(dBuf <= D)
{
counter = counter +1;
}
}
cout << counter << endl;
return 0;
}


Measured memory_bytes: 4724
def eratosthenes(n):
 is_p=[1]*n
 p_list=[]

 is_p[0]=0
 is_p[1]=0

 for i in range(2,n):
  if is_p[i]:
   p_list.append(i)
   for j in range(i*i,n,i):
    is_p[j] = 0

 return is_p, p_list

lim=10**5+1
is_p, p_list=eratosthenes(lim)

q=int(input())

'''
b=[0]
for i in range(1,lim+1):
 if is_p[i-1] and is_p[i//2]:
  b.append(b[i-1]+1)
 else:
  b.append(b[i-1])
'''
a = [0] * (10**5+2)
for i in range(3, 10**5+1, 2):
    if is_p[i] and is_p[(i+1)//2]:
        a[i] = 1
for i in range(1, 10**5+1):
    a[i+1] += a[i]

for i in range(q):
 l,r=map(int,input().split())
# print(b[r+1]-b[l])
 print(a[r]-a[l-1])

Measured memory_bytes: 7552
#include <bits/stdc++.h>
#define N 100005
#define M 10000000000
#define endl "\n"
using namespace std;

int m;


int Wt;

int wt[101];

long  long  val[101];


long long  dp[105][N];




long long maxCost(int n, int W)
{


	if (n - 1 < 0)
		return 0;

	if (W == 0)
		return 0;

	if (dp[n][W] != -1)
		return dp[n][W];


	if (wt[n - 1] <= W)
		return dp[n][W] = max(val[n - 1] + maxCost( n - 1, W - wt[n - 1]), maxCost(n - 1, W));
	else return dp[n][W] = maxCost(n - 1, W);


}


int32_t main()
{


	cin >> m >> Wt;


	for (int i = 0; i < m; ++i)
	{
		cin >> wt[i] >> val[i];

	}


	memset(dp, -1, sizeof(dp));



	cout << maxCost(m, Wt) << endl;

}

Measured memory_bytes: 85648
from sys import stdin
def main():
    #入力
    readline=stdin.readline
    N,M=map(int,readline().split())
    x=[0]*M
    y=[0]*M
    for i in range(M):
        x[i],y[i]=map(int,readline().split())

    box=[1]*(N+1)
    flags=[False]*(N+1)
    flags[1]=True

    for i in range(M):
        out=x[i]
        inn=y[i]
        if flags[out]==True and box[out]==1:
            flags[out]=False
            flags[inn]=True
        elif flags[out]==True:
            flags[inn]=True
        box[out]-=1
        box[inn]+=1

    res=0
    for i in range(N+1):
        if flags[i]==True:
            res+=1
    print(res)
        
if __name__=="__main__":
    main()

Measured memory_bytes: 12404
n = int(input())
s = input()

left = 0
right = 0
tmp = 0
tmp_li = []

if s[0] == '(':
    bfr = 0
    tmp = 1
else:
    bfr = 1
    tmp = -1

#bfr = s[0]

for i in range(1,n):
    if bfr == 0:
        if s[i] == '(':
            #tmp_li.append(tmp)
            tmp += 1
        else:
            #tmp -= 1
            tmp_li.append(tmp)
            tmp = -1
            bfr = 1
    else:
        if s[i] == '(':
            #tmp += 1
            tmp_li.append(tmp)
            tmp = 1
            bfr = 0
        else:
            tmp -= 1

tmp_li.append(tmp)
#print(tmp_li)

tmp2_li = []
tmp = 0

for i in range(len(tmp_li)):
    tmp += tmp_li[i]
    if tmp < 0:
        tmp2_li.append(tmp)
        tmp = 0

tmp2_li.append(tmp)

minus = 0
plus = 0

for i in range(len(tmp2_li)):
    if tmp2_li[i] < 0:
        minus += tmp2_li[i]
    else:
        plus += tmp2_li[i]
        
#print(minus,plus)

print('('*(-minus)+s+')'*plus)


Measured memory_bytes: 3064
# -*- coding: utf-8 -*-

n,m=map(int,input().split())
h=list(map(int,input().split()))

ans=[True for _ in range(n)]

for i in range(m):
    a,b=map(int,input().split())
    if h[a-1]>=h[b-1]:
        ans[b-1]=False
    if h[a-1]<=h[b-1]:
        ans[a-1]=False

print(ans.count(True))

Measured memory_bytes: 85032
N=int(input())
A=list(map(int,input().split()))

T={}
for a in A:
    if a in T:
        T[a]+=1
    else:
        T[a]=1

F=True
for x in T:
    F&=(3*T[x]%N==0)

if not F:
    print("No")
    exit()

M=max(T,key=lambda x:T[x])
if 3*T[M]==N:
    x,y,z=list(T.keys())
elif 3*T[M]==2*N:
    x=y=M
    del T[M]
    z=tuple(T.keys())[0]
else:
    x=y=z=M

if x^y==z:
    print("Yes")
else:
    print("No")



Measured memory_bytes: 93500
#include <stdio.h>

int main(void) {
	long long h, w, num=0;
	scanf("%lld %lld", &h, &w);
	if(h==1 || w==1){
		printf("1");
		return 0;
	}
	
	if(h%2==0)
		printf("%lld", h*w/2);
	else
		printf("%lld", (h-1)*w/2+(w+1)/2);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
 
#define mod 1000000007
#define FOR(x,to) for(int x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define long long long
inline int rei(){int x;cin>>x;return x;}
inline long rel(){long x;cin>>x;return x;}
inline string res(){string x;cin>>x;return x;}
//------------------------------------------------------- 
long DP[101*100001];
void Calc(){
	int N = rei();
	int W = rei();
	for(int i=0;i<N;i++){
		for(int j=0;j<=W;j++){
			DP[(i+1)*100001+j] = DP[i*100001+j];
		}
		int w = rei();
		long v = rel();
		for(int j=w;j<=W;j++){
			DP[(i+1)*100001+j] = max(DP[(i+1)*100001+j],DP[i*100001+j-w]+v);
		}
	}
	long ans = 0;
	for(int i=0;i<=W;i++){
		ans = max(ans,DP[N*100001+i]);
	}
	cout << ans << endl;
}
int main(int argc,char** argv){
	ios::sync_with_stdio(false), cin.tie(0);
	cout.tie(0); Calc(); return 0;
}

Measured memory_bytes: 78336
#include<map>
#include<bitset>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<stack>
#define REP(i,x,y) for(ll i=x;i<=y;i++)
typedef long long ll;
using namespace std;
ll const MAX = 200005;
ll const INF = 1000000000000000;

ll b[MAX];
struct query {
	ll l; ll r;
};
query qu[MAX];
ll tree[MAX * 4];
ll n_;

void init(ll n) {
	n_ = 1;
	while (n_ <= n) {
		n_ *= 2;
	}
	REP(i, 1, 2*n_) {
		tree[i] = INF;
	}
}

void update(ll x, ll v) {
	x += n_;
	tree[x] = v;
	while (x > 0) {
		x /= 2;
		tree[x] = min(tree[x*2],tree[x*2+1]);
	}
}

ll val_o(ll a, ll b, ll k, ll l, ll r) {
	if (b <= l || r <= a) {
		return INF;
	}
	else if (a <= l && r <= b) {
		return tree[k];
	}
	else {
		ll ans1 = val_o(a, b, k * 2, l, (l + r) / 2);
		ll ans2 = val_o(a, b, k * 2 + 1, (l + r) / 2, r);
		//cout << ans1 << " " << ans2 << endl;
		return min(ans1, ans2);
	}
}

ll val(ll a, ll b) {
	return val_o(a, b, 1, 0, n_);
}

bool order(query x, query y) {
	return x.l < y.l;
}


int main() {
	ll n;
	cin >> n;
	init(n);
	REP(i, 1, n) {
		cin >> b[i];
	}

	ll cnt = 1;
	update(0, 0);
	ll q;
	cin >> q;
	REP(i, 1, q) {
		cin >> qu[i].l >> qu[i].r;
	}
	sort(qu + 1, qu + 1 + q, order);
	qu[q + 1].l = qu[q + 1].r = -1;
	/*
	REP(i, 0, 2*n_) {
		cout << tree[i] << " ";
	}
	cout << endl;
	*/
	ll black = 0;
	REP(i, 1, n) {
		while (i == qu[cnt].l) {
			ll cur = qu[cnt].l - 1;
			ll next = qu[cnt].r;
			/*
			REP(i, cur, next) {
				cout << tree[i + n_] << " ";
			}
			cout << " ! " << endl;
			*/
			//a[next] = val(cur, next + 1);
			//cout << cur << " " << next << " " <<val(cur, next + 1) << endl;
			ll t = val(cur, next + 1);
			update(next, t);
			cnt++;	

		}
		//a[i] = min(a[i] + (b[i] == 0), a[i - 1] + (b[i] == 1));
		update(i, min(tree[i + n_] + (b[i] == 0), tree[i - 1 + n_] + (b[i] == 1)));
		if (b[i] == 0) {
			black++;
			//a[i]--;
			update(i, tree[i + n_] - 1);
		}/*
		REP(i, 0, n) {
			cout << tree[i+n_] << " ";
		}
		cout << "black= " << black << " i = " << i <<  endl;
		*/
	}
	cout << tree[n+n_] + black << endl;
}

Measured memory_bytes: 11264
#include<map>
#include<queue>
#include<time.h>
#include<limits.h>
#include<cmath>
#include<ostream>
#include<iterator>
#include<set>
#include<stack>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define rep_1(i,m,n) for(int i=m;i<=n;i++)
#define mem(st) memset(st,0,sizeof st)
inline int read()
{
	int num=0, w=0;
	char ch=0;
	while (!isdigit(ch))
	{
		w|=ch=='-';
		ch = getchar();
	}
	while (isdigit(ch))
	{
		num = (num<<3) + (num<<1) + (ch^48);
		ch = getchar();
	}
	return w? -num: num;
}
typedef long long ll;
typedef pair<int,int> pii;
typedef unsigned long long ull;
typedef pair<double,double> pdd;
const int inf = 0x3f3f3f3f;
const int N=2e6+10;
int a[N];
void solve()
{
	int n;
	cin>>n;
	for(int i=1; i<=n; i++)
		cin>>a[i];
	sort(a+1,a+1+n);
	int ans=0;
	for(int i=1; i<=n; i++)
		for(int j=i+1; j<=n; j++)
			if(a[i]!=a[j])
				for(int k=j+1; k<=n; k++)
					if(a[j]!=a[k])
						if(a[i]+a[j]>a[k])
							ans++;
	cout<<ans<<endl;
}
signed main()
{
	int t=1;
	while(t--)
		solve();
	return 0;
}



Measured memory_bytes: 3588
#include<stdio.h>
#include<map>
#include<algorithm>
typedef std::pair<int,int>P;
bool C(P l,P r){return l.first>r.first;}
int main()
{
	int m,n,i,j,x,f;
	while(scanf("%d%d",&n,&m),n)
	{
		P p[100];
		for(i=0;i<n;++i)for(j=0;j<m;++j)scanf("%d",&x),p[j].first+=x,p[j].second=j+1;
		std::stable_sort(p,p+m,C);
		for(f=i=0;i<m;++i)printf("%s%d",f++?" ":"",p[i].second);
		puts("");
	}
	return 0;
}

Measured memory_bytes: 0
import java.util.Scanner;


public class Main 
{

	public static void main(String[] args) 
	{
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();

		int sum =0;
		for(int i=0;i<N;i++)
		{
			int l=sc.nextInt();
			int r=sc.nextInt();
			sum += r-l+1;
		}
		sc.close();
		
		System.out.println(sum);
	

	}

}


Measured memory_bytes: 24156
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;




int main(){
    ll a;
    cin >> a;
    string S;
    cin >> S;
    if(a>=3200){cout<<S<<endl;}
    else cout<<"red"<<endl;

return 0;


}  



Measured memory_bytes: 256
from operator import mul
from functools import reduce

N, M = map(int, input().split())

Nans = 0
Mans = 0

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

if N == 0 or N == 1:
    Nans = 0
else:
    Nans = cmb(N, 2)

if M == 0 or M == 1:
    Mans = 0
else:
    Mans = cmb(M, 2)

print(Nans + Mans)

Measured memory_bytes: 3572
#include <iostream>

constexpr int MOD = 1e9 + 7;

constexpr long long exp(const int &a, const int &b) {
  // Calculate a ** b by binary exponentation
  long long ret  = 1;
  long long base = a;
  int exponent   = b;

  while (exponent) {
    if (exponent & 1) {
      ret *= base;
      ret %= MOD;
    }
    base *= base;
    base %= MOD;
    exponent >>= 1;
  }

  return ret;
}

constexpr long long binomial(const int &n, const int &r) {
  // Calculate binomial(n, r)
  //
  // to do this, we need to calculate these values:
  //  - n * (n-1) * (n-2) * ... * (n-r+1)
  //  - 1/r! (inverse of the r factorial)
  //
  // Calculate n * (n-1) * (n-2) * ... * (n-r+1) using for loop
  long long prod_r = 1;

  for (int i = n - r + 1; i <= n; i++) {
    prod_r *= i;
    prod_r %= MOD;
  }

  // Calculate a! using for loop
  long long r_factorial = 1;

  for (int i = 1; i <= r; i++) {
    r_factorial *= i;
    r_factorial %= MOD;
  }

  // Calculate 1/a! by Fermat's little theorem
  //
  // Fermat's little theorem:
  //   x^(p-2) = 1/x (mod p)
  constexpr int exponent    = MOD - 2;
  long long inv_r_factorial = exp(r_factorial, exponent);

  // Return binomial(n, a)
  return (prod_r * inv_r_factorial) % MOD;
}

int main() {
  // Input
  int n, a, b;
  std::cin >> n >> a >> b;

  // Want to calculate 2 ** n - binomial(n, a) - binomial(n, b) - 1
  //
  // Calculate 2 ** n
  long long two_to_the_n = exp(2, n);

  // Calculate binomial(n, a), binomial(n, b)
  long long binomial_n_a = binomial(n, a);
  long long binomial_n_b = binomial(n, b);

  // Output
  long long ans = (two_to_the_n - binomial_n_a - binomial_n_b - 1) % MOD;

  if (ans < 0)
    std::cout << ans + MOD << std::endl;
  else
    std::cout << ans << std::endl;
}

Measured memory_bytes: 3640
/+ dub.sdl:
    name "A"
    dependency "dcomp" version=">=0.0.2"
+/

import std.algorithm, std.range, std.stdio, std.math, std.conv, core.bitop;

// import dcomp.scanner;
// import dcomp.algorithm;

int n;
struct Edge {
    int to;
    long dist;
}
Edge[][] g;
long md;

T[N] toS(T, int N)(T[N] data){ return data; }

long[2][][] memo;
long[2][] leaf = [[0L, 0L]];
long[2][] dfs(int p) {
    if (g[p].empty) {
        return leaf;
    }
    Edge le = g[p][0], re = g[p][1];
    auto lt = dfs(le.to);
    auto rt = dfs(re.to);
    if (lt.length > rt.length) {
        swap(le, re);
        swap(lt, rt);
    }
    long ld = le.dist, rd = re.dist;
    auto buf = Appender!(long[2][])(memo[p]);
    buf.clear();
    foreach (co; lt) {
        //co[1] + ld + rd + rco[0] <= md
        int idx = binSearch!((i){return co[1]+ld+rd+rt[i][0] > md;})(-1, rt.length.to!int)-1;
        if (idx == -1) continue;
        buf.put([co[0]+ld, rt[idx][1]+rd].toS);
        buf.put([rt[idx][1]+rd, co[0]+ld].toS);
    }
    memo[p] = buf.data;
    sort(memo[p]);
    if (memo[p].empty) return memo[p];
    long ma = 10L^^15;
    int co = 0;
    foreach (e; memo[p]) {
        if (ma <= e[1]) continue;
        ma = min(ma, e[1]);
        memo[p][co] = e;
        co++;
    }
    return memo[p][0..co];
}

//md以下にできるか？
bool solve(long _md) {
    md = _md;
    return !dfs(0).empty;
}

int main() {
    auto sc = new Scanner();
    int n;
    sc.read(n);
    g = new Edge[][](n);
    memo = new long[2][][](n);
    foreach (i; 1..n) {
        int a; long b;
        sc.read(a, b); a--;
        g[a] ~= Edge(i, b);
    }

    writeln(binSearch!solve(-1L, 10L^^12));
    return 0;
}
/* IMPORT /Users/yosupo/Program/dcomp/source/dcomp/scanner.d */
// module dcomp.scanner;

class Scanner {
    import std.stdio : File, readln, stdin;
    import std.conv : to;
    import std.range : front, popFront, array, ElementType;
    import std.array : split;
    import std.traits : isSomeString, isDynamicArray;
    import std.algorithm : map;
    File f;
    this(File f = stdin) {
        this.f = f;
    }
    string[] buf;
    bool succ() {
        while (!buf.length) {
            if (f.eof) return false;
            buf = readln.split;
        }
        return true;
    }
    int read(Args...)(auto ref Args args) {
        foreach (i, ref v; args) {
            if (!succ()) return i;
            alias VT = typeof(v);
            static if (!isSomeString!VT && isDynamicArray!VT) {
                v = buf.map!(to!(ElementType!VT)).array;
                buf.length = 0;
            } else {
                v = buf.front.to!VT;
                buf.popFront();
            }
        }
        return args.length;
    }
}
/* IMPORT /Users/yosupo/Program/dcomp/source/dcomp/algorithm.d */
// module dcomp.algorithm;

//[0,0,0,...,1,1,1]で、初めて1となる場所を探す。pred(l) == 0, pred(r) == 1と仮定
T binSearch(alias pred, T)(T l, T r) {
    while (r-l > 1) {
        T md = (l+r)/2;
        if (!pred(md)) l = md;
        else r = md;
    }
    return r;
}


Measured memory_bytes: 93308
sx, sy, tx, ty = map(int, input().split())

if sx < tx:
    flag1 = -1
else:
    flag1 = 1

if sy < ty:
    flag2 = 1
else:
    flag2 = -1

def print_root(x1, y1, x2, y2):

    if y1 < y2:
        print("U" * (y2 - y1), end = "")
    else:
        print("D" * (y1 - y2), end = "")

    if x1 < x2:
        print("R" * (x2 - x1), end = "")
    else:
        print("L" * (x1 - x2), end = "")
    
print_root(sx, sy, tx, ty)
print_root(tx, ty, sx, sy)

print_root(sx, sy, sx + flag1, sy)
print_root(sx + flag1, sy, tx, ty + flag2)
print_root(tx, ty + flag2, tx, ty)

print_root(tx, ty, tx - flag1, ty)
print_root(tx - flag1, ty, sx, sy - flag2)
print_root(sx, sy - flag2, sx, sy)
print()

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

#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL);
#define eof !cin.eof()
#define pb push_back
#define pf push_front
#define pof pop_front
#define pob pop_back
#define ull unsigned long long
#define ll long long
#define ld long double
#define sz(a) a.size()
#define all(s) s.begin(), s.end()
#define rall(s, n) s, s + n
#define x first
#define y second
#define mp make_pair
#define ub upper_bound
#define lb lower_bound
#define ii pair <int, int>
#define iii pair <int, ii>
#define vi vector <int>
#define vit vector <int> :: iterator
#define vlt vector <ll> :: iterator
#define vl vector <ll> 
#define vii vector <ii>
#define viii vector <iii>
#define vd vector <double>
#define vull vector <ull>
#define vc vector <char>
#define vs vector <string>
#define vvi vector <vector <int>>
#define vvl vector <vector <ll>>
#define EPS 1e-10
#define INF 1000000000
#define mod 1000000007
#define reset(a, nilai) memset(a, nilai, sizeof(a))
#define minof min_element
#define maxof max_element
using namespace std;

string s, t;
int main () {
	IOS;
	
	cin >> s >> t;
	int n_s = sz(s);
	int n_t = sz(t);
	int dp[n_s + 1][n_t + 1];
	for (int i = 0; i <= n_s; i++) {
		for (int j = 0; j <= n_t; j++) {
			if (i == 0 || j == 0) {
				dp[i][j] = 0;
			} else if (s[i - 1] == t[j - 1]) {
				dp[i][j] = dp[i - 1][j - 1] + 1;
			} else {
				dp[i][j] = max(dp[i][j - 1], dp[i - 1][j]);
			}
		}
	}
	int index = dp[n_s][n_t];
	int i = n_s, j = n_t;
	char lcs[index + 1];
	lcs[index] = '\0';
	while (i > 0 && j > 0) {
		if (s[i - 1] == t[j - 1]) {
			lcs[index - 1] = s[i - 1];
			i--; j--; index--;
		} else if (dp[i - 1][j] > dp[i][j - 1]){
			i--;
		} else {
			j--;
		}
	}
	cout << lcs << endl;
	return 0;
}

Measured memory_bytes: 35584
/*
#include <cstdio>
#include <cstring>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
*/
#include <bits/stdc++.h>
#define pb push_back
#define FOR(x,st,n) for(int x = (st); x < (n); ++ x)

using namespace std;


typedef long long ll;
typedef pair<int,int> P;
typedef vector<P> vp;
typedef vector<int> vi;
typedef vector<vi> vvi;
const int N = 1e5 +2;

int score[3];
unordered_map<char,int> mmap;
unordered_map<int , char> rmap;
char tt[N],pre[N];

char win(char c){
    if(c=='r') return 'p';
    if(c=='s') return 'r';
    if(c=='p') return 's';
}

int main(){
    
    int n,k;
    cin>>n>>k;
    FOR(i,0,3) cin>>score[i];
    scanf("%s",tt);
    
    mmap['r']=0;
    mmap['s']=1;
    mmap['p']=2;
    rmap[0] = 'r';
    rmap[1] = 's';
    rmap[2] = 'p';

    ll ret=0;

    FOR(i,0,n){
        if(i<k){
            pre[i] = win(tt[i]);
            //cout<<pre[i]<<" ";
            ret+= score[ mmap[pre[i]] ];
            continue;
        }

        if( win(tt[i]) == pre[i-k] ){ //hit

            if(i+k <n){
                char tmp=win(tt[i+k]);

                FOR(dd,0,3){
                    if(dd == mmap[pre[i-k]] || dd==mmap[tmp]) continue;
                    pre[i] == rmap[dd];
                }
            }

        }else{
            pre[i] = win(tt[i]);
            ret+= score[ mmap[pre[i]] ];
        }
        //cout<<pre[i]<<" ";
    }
    
    cout<<ret<<endl;

    return 0;
}



Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define mem(a) memset(a,0,sizeof(a))
#define dbg(x) cout<<#x<<" = "<<x<<endl
#define ll long long
//不要再爆long long了！！！！！！！！不要再爆long long了！！！！！！！ 

int main()
{
	int a,b;
	cin>>a;
	b=a/__gcd(360,a);
	cout<<b*360/a;
	return 0;
}

Measured memory_bytes: 3564
#include <bits/stdc++.h>
using namespace std;
struct drink
{
	int p;
	int x;
};
int main()
{   
	int n,m,sum;
	cin>>n;
	int t[n+1];
	for(int i=1;i<=n;i++)
	{
		cin>>t[i];
	}
	cin>>m;
	drink d[m];
	for(int i=0;i<m;i++)
	{sum=0;
		cin>>d[i].p>>d[i].x;
		for(int j=1;j<=n;j++)
		{
			if(d[i].p == j)
			{
				sum=sum+d[i].x;
			}
			else
			sum=sum+t[j];
		}
		cout<<sum<<endl;
	}

return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdint>
#include <vector>
#include <unordered_set>
#include <stack>
#include <cassert>

class history {
private:
  const std::vector<std::vector<std::int_fast32_t>>& m_graph;
  std::stack<std::int_fast32_t> m_stack;
  std::unordered_set<std::int_fast32_t> m_unordered_set;

public:
  history(const std::vector<std::vector<std::int_fast32_t>>& graph) :
    m_graph(graph),
    m_stack(),
    m_unordered_set() {
  }

  const std::vector<std::vector<std::int_fast32_t>>& graph() const {
    return this->m_graph;
  }

  std::size_t size() const {
    return this->m_stack.size();
  }

  bool empty() const {
    return this->size() == 0;
  }

  bool full() const {
    return this->size() == this->graph().size();
  }

  std::int_fast32_t pos() const {
    assert(!this->empty());
    return this->m_stack.top();
  }

  void visit(const std::int_fast32_t node) {
    assert(!this->full());
    this->m_stack.push(node);
    this->m_unordered_set.insert(node);
  }

  void back() {
    assert(!this->empty());
    const std::int_fast32_t pos = this->pos();
    this->m_stack.pop();
    this->m_unordered_set.erase(pos);
  }

  bool visited(const std::int_fast32_t node) const {
    return this->m_unordered_set.count(node) > 0;
  }
};

std::int_fast32_t dfs(history& history) {
  assert(!history.empty());

  if (history.full()) return 1;

  std::int_fast32_t result = 0;
  for (const std::int_fast32_t& to : history.graph()[history.pos()]) {
    if (history.visited(to)) continue;
    history.visit(to);
    result += dfs(history);
    history.back();
  }
  return result;
}

int main() {
  std::int_fast32_t n, m;
  std::cin >> n >> m;
  std::vector<std::vector<std::int_fast32_t>> graph(n);
  for (std::int_fast32_t i = 0; i < m; ++i) {
    std::int_fast32_t a, b;
    std::cin >> a >> b;
    graph[a - 1].push_back(b - 1);
    graph[b - 1].push_back(a - 1);
  }

  history history(graph);
  history.visit(0);
  std::cout << dfs(history) << std::endl;

  return 0;
}

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

using namespace std;
const int c = 2e5+1;
int main(void){
    string s, t;
    cin >> s >> t;
    
    int n = (int)s.size();
    map<char,int> mps,mpt;
    
    for (int i = 0; i < n; i++){
        mps[s[i]]++;
        mpt[t[i]]++;
    }
    
    vector<int> num_for_s(c);
    vector<int> num_for_t(c);
    
    for (auto p : mps){
        num_for_s[p.second]++;
    }
    
    for (auto p : mpt){
        num_for_t[p.second]++;
    }
    
    for (int i = 0; i <= c; i++){
        if (num_for_s[i] != num_for_t[i]){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}


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

int main(){
    int x;
    cin >> x;
    vector<bool> isexist(x+10, false);
    isexist[0] = true;
    for(int i = 1; i <= x; i++){
        for(int j = 100; j <= 105; j++){
            if(i-j >= 0 && isexist[i-j]) isexist[i] = true;
        }
    }

    if(isexist[x]) cout << 1 << endl;
    else cout << 0 << endl;
    return 0;
}

Measured memory_bytes: 3596
package main

import (
	"fmt"
	"math"
)

type city struct {
	cityID   int
	visitNum int
}

func main() {
	var n, a, b, c, d, e int
	fmt.Scan(&n, &a, &b, &c, &d, &e)

	min := a
	if min > b {
		min = b
	}
	if min > c {
		min = c
	}
	if min > d {
		min = d
	}
	if min > e {
		min = e
	}

	cal := int(math.Ceil(float64(n) / float64(min)))
	cal += 4
	fmt.Print(cal)

}


Measured memory_bytes: 512
using System.Linq;
using System.Collections.Generic;

public class Hello{
    public static void Main(){
        // Here your code !
        string[] input;
        input = System.Console.ReadLine().Split(' ');
        int[] nums;
        nums = input.ToList().ConvertAll<int>(x => int.Parse(x)).ToArray();

        int N = nums[0];
        int T = nums[1];

        input = System.Console.ReadLine().Split(' ');
        nums = input.ToList().ConvertAll<int>(x => int.Parse(x)).ToArray();
        int[] times = nums;

        long sum = 0;
        for(int i= 1; i <N; i++)
        {
            int current = times[i];
            int before = times[i-1];
            int dif = current - before;
            if (dif > T)
            {
                sum += T;
            }
            else
            {
                sum += dif;
            }
                
        }
        sum +=T;

        System.Console.WriteLine(sum);
    }
}


Measured memory_bytes: 30432
#!/usr/bin/env python3
import sys
import itertools
import collections
from queue import Queue
import functools
import math
INF = 10**9


def solve(N: int, i: int):
    print(N-i+1)
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    i = int(next(tokens))  # type: int
    solve(N, i)


if __name__ == '__main__':
    main()


Measured memory_bytes: 4200
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr long long INFL = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;



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

    string S;
    cin >> S;
    int N=S.size();
    int cou=0;
    rep(i,N-1){
        if(S[i]!=S[i+1]) cou++;
    }
    cout << cou << endl;



}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,m;
    cin >> n;
    vector<long> t(n);
    int i,j;
    long sum=0;
    for(i=0;i<n;i++){
        cin >> t.at(i);
        sum+=t.at(i);
    }
    cin >> m;
    long p,x;
    vector<long> s(m);
    for(i=0;i<m;i++){
        cin>> p >> x;
        s.at(i)=sum-t.at(p-1)+x;
    }
    for(i=0;i<m;i++){
        cout << s.at(i) << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long int a,b,x;
    cin >> a >> b >> x;
    long long int ans = b / x - a / x;
    if(a % x == 0)
    {
        ans++;
    }
    cout << ans;
    
    return 0;
}

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

int main() {
  int a,b,c,x,y;
  cin>>a>>b>>c>>x>>y;

  int ans=1e9;
  for (int i=0; i<=max(2*x,2*y); i++) {
    ans=min(ans,a*max(0,(x-i/2))+b*max(0,(y-i/2))+i*c);
  }
  
  cout <<ans<< endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<math.h>
using namespace std;

int main(){
int n,x;
int count;
while(1){
     count = 0;
     cin >> n >> x;
     if(n == 0 && x == 0){
          break;
     }
     for(int i = 1; i <= n; i++){
          for(int j = 1; j <= n; j++){
               for(int k = 1; k <= n; k++){
                    if(k != i && k != j && i != j && i + j + k == x){
                    count++;
                    }
               }
          }
     }
     count /= 6;
     cout << count << endl;
}
return 0;
}


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

template <class T> inline bool chmax(T& a, T b) {
  if(a < b) {
    a = b;
    return true;
  }
  return false;
}

int main() {
  int N;
  cin >> N;
  vector<int> vs(N * 100 + 1, -1);
  vs[0] = 1;
  int s;
  for(int i = 0; i < N; ++i) {
    cin >> s;
    for(int j = vs.size() - 1; j > 0; --j) {
      auto prev = j - s;
      if(prev >= 0 && vs[prev] > 0) {
        vs[j] = vs[prev];
      }
    }
  }
  int ans = 0;
  for(int i = 0; i < vs.size(); ++i) {
    if(vs[i] > 0) {
      chmax(ans, i % 10 == 0 ? 0 : i);
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<string>
#include<list>
#include<vector>
#include<algorithm>
#include<numeric>
#include<queue>
#include<utility>
#include <map>

using namespace std;

int main(int argc, char const *argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout.tie(0);
    /*
    cin>>x;
    cout<<x<<endl;
    */
    int c,i,j,n,k,m,x,y,z,cnt=0,ans=0;
    double a,b,d;

    cin>>n>>k;

    string kirai[k];

    for(i=0; i<k;i++){
        cin>>kirai[i];
    }

    for(i=n;i<=10*n;i++){
        string s=to_string(i);
        for(j=0;j<k;j++){
            if(s.find(kirai[j]) != -1){
                break;
            }
        }
        if(j==k){
            cout<<i<<endl;
            return 0;
        }
    }   
}

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

typedef long long ll;
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef vector< ll > vl;
typedef vector< vl > vvl;
typedef pair< int, int > pii;
typedef vector< pii > vp;
typedef vector< double > vd;
typedef vector< vd > vvd;
typedef vector< string > vs;

template< class T1, class T2 >
int upmin( T1 &x, T2 v ){
  if( x > v ){
    x = v;
    return 1;
  }
  return 0;
}

template< class T1, class T2 >
int upmax( T1 &x, T2 v ){
  if( x < v ){
    x = v;
    return 1;
  }
  return 0;
}

const int INF = 0x3f3f3f3f;

int N, K, L;
vi P, Q;
vi R, S;

void init(){
  cin >> N >> K >> L;
  P = Q = vi( K );
  for( int i = 0; i < K; ++i )
    cin >> P[ i ] >> Q[ i ], --P[ i ], --Q[ i ];
  R = S = vi( L );
  for( int i = 0; i < L; ++i )
    cin >> R[ i ] >> S[ i ], --R[ i ], --S[ i ];
}

vvi G1, G2;
vi cc1_id, cc2_id;

void dfs( const vvi &g, int u, vi &cc_id ){
  for( int v : g[ u ] )
    if( cc_id[ v ] == -1 )
      cc_id[ v ] = cc_id[ u ],
      dfs( g, v, cc_id );
}

void preprocess(){
  G1 = vvi( N );
  for( int i = 0; i < K; ++i )
    G1[ P[ i ] ].emplace_back( Q[ i ] ),
    G1[ Q[ i ] ].emplace_back( P[ i ] );
  G2 = vvi( N );
  for( int i = 0; i < L; ++i )
    G2[ R[ i ] ].emplace_back( S[ i ] ),
    G2[ S[ i ] ].emplace_back( R[ i ] );
  cc1_id = vi( N, -1 );
  int cc_cnt = -1;
  for( int i = 0; i < N; ++i )
    if( cc1_id[ i ] == -1 )
      cc1_id[ i ] = ++cc_cnt,
      dfs( G1, i, cc1_id );
  cc2_id = vi( N, -1 );
  cc_cnt = -1;
  for( int i = 0; i < N; ++i )
    if( cc2_id[ i ] == -1 )
      cc2_id[ i ] = ++cc_cnt,
      dfs( G2, i, cc2_id );
}

void solve(){
  map< pii, int > cnt;
  map< pii, vi > node;
  for( int i = 0; i < N; ++i )
    ++cnt[ make_pair( cc1_id[ i ], cc2_id[ i ] ) ],
    node[ make_pair( cc1_id[ i ], cc2_id[ i ] ) ].emplace_back( i );
  vi ans( N );
  for( auto it = cnt.begin(); it != cnt.end(); ++it )
    for( auto v : node[ it->first ] )
      ans[ v ] = it->second;
  for( int i = 0; i < N; ++i )
    cout << ans[ i ] << " \n"[ i + 1 == N ];
}

signed main(){
  ios::sync_with_stdio( 0 );
  init();
  preprocess();
  solve();
  return 0;
}


Measured memory_bytes: 48512
import Data.List
import Data.Ord
import Data.Char
import Data.Ratio
import Data.Maybe

main = do
  [n,t] <- map (read::String->Int) . words <$> getLine
  ct <- listToTuple . map (map (read::String->Int)) . map words . lines <$> getContents
  let ans = filter((<=t) .snd) ct
  putStrLn $if ans==[] then "TLE" else (show .fst .minimum)ans
  
listToTuple [] = []
listToTuple ([x1,x2] : xs) = (x1,x2) : listToTuple xs

Measured memory_bytes: 4836
#include <iostream>
#include <vector>
#include <string>
using namespace std;

int main(int argc, char *argv[])
{
	int i;
	int N, M;
	int count = 0;
	int tmp;
	cin >> N;
	cin >> M;
	for (i = 0; i < M; i++) {
		cin >> tmp;
		count += tmp;
	}

	if (N < count)
		cout << -1 << endl;
	else
		cout << N - count << endl;

	return 0;
}

Measured memory_bytes: 3632
n = int(input())
dic = dict()
ans = 0

for i in range(n):
    buf = input()
    seq = [buf[i] for i in range(len(buf))]
    seq.sort()
    bf2 = "".join(seq)
    
    if bf2 not in dic:
        dic[bf2] = 0
    else:
        dic[bf2] += 1
        ans += dic[bf2]

print(ans)

Measured memory_bytes: 17892
#include<bits/stdc++.h>
#define ll long long

using namespace std;

ll ans;
string a;

ll num(ll l,ll r)
{
	ll ret=0;
	for(int i=l;i<=r;i++)
	{
		ret=ret*10+a[i]-'0';
	}
	return ret;
}

int main()
{
	cin>>a;
	ll len=a.size()-1;
	for(ll i=0;i<(1<<len);i++)
	{
		ll tmp=0;
		for(int j=0;j<len;j++)
		{
			if((1<<(j))&i)
			{
				ans+=num(tmp,j);
				tmp=j+1;
			}
		}
		ans+=num(tmp,len);
	}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 256
a = gets.to_i
b = gets.to_i
c = gets.to_i
x = gets.to_i
count = 0
for na in 0..a do
  for nb in 0..b do
    for nc in 0..c do
      count += 1 if 500 * na + 100 * nb + 50 * nc == x
    end
  end
end
puts count


Measured memory_bytes: 1788
L, R = map(int, input().split())
if L + 2019 > R:
  tmp = 10**9
  for l in range(L,R):
    for r in range(l+1, R+1):
      if (l*r)%2019 < tmp:
        tmp = (l*r)%2019
  print(tmp)
else:
  print("0")



Measured memory_bytes: 9036
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#define NOT_ZERO 1
#define MAX(a,b) (a>b?a:b)
#define MAX3(a,b,c) MAX(a,MAX(b,c))
#define MIN(a,b) (a<b?a:b)
#define MIN3(a,b,c) MIN(a, MIN(b,c))
typedef long long ll;
typedef unsigned short int usi;

int cmp(const void *a, const void *b){
    return *(int*)b - *(int*)a;
}

int main()
{
    int n, i, a[100000], b[100000], c[100000];
    ll sum=0;
    int count=0;
    scanf("%d",&n);

    for(i=0; i<n; i++) {
        scanf("%d",a+i);
        sum += a[i];
    }
    for(i=0; i<n; i++) {
        scanf("%d",b+i);
        c[i] = a[i]-b[i];
        if(a[i]<b[i]) {
            a[i] = b[i];
            sum -= b[i];
            count++;
        } else {
            sum -= a[i];
        }
    }
    if(sum>=0) {
        printf("%d",count);
        return 0;
    }

    qsort(c, n, sizeof(int), cmp);

    for(i=0; i<n; i++) {
        sum += c[i];
        count++;
        if(sum>=0)break;
    }

    printf("%d",sum>=0?count:-1);

    return 0;
}


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

int main()
{
    int N;
    cin >> N;
    vector<int> X(N, 0);
    int max_point = -1, min_point = 101;
    for (int i = 0; i < N; i++)
    {
        cin >> X[i];
        max_point = max(max_point, X[i]);
        min_point = min(min_point, X[i]);
    }

    int res = INT32_MAX;
    for (int i = min_point; i <= max_point; i++)
    {
        int tmp = 0;
        for (int j = 0; j < N; j++)
        {
            tmp += (X[j] - i) * (X[j] - i);
        }
        res = min(res, tmp);
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  	string s;
  	cin>>s;
   
  	bool isok = true;
  	if(s.size()%2 != 0)
      cout<<"No";
  	else
    {
      	for(int i=0; i<s.size()-1; i=i+2) {
      		if( s[i] =='h' && s[i+1] =='i' ) {
              continue;
      		}
           else {
             isok = false;
           		break;
           }
    	}
    	if(isok)
          cout<<"Yes";
      	else
          cout<<"No";
    }
  
  	
	return 0;
}

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

int main(void) {
	int flag = 0, i, j;
	char string[255];
	scanf("%s", string);
	
	for(i=0;i<strlen(string);i++){
		if(string[i] == 'C'){
			for(j=i;j<strlen(string);j++){
				if(string[j] == 'F' ){
					flag = 1;
				}
			}
		}
	}
	if(flag == 1){
		printf("Yes");
	}else{
		printf("No");
	}
	
	return 0;
}


Measured memory_bytes: 256
#include<cmath>
#include<bits/stdc++.h>
#define MAX(a,b) (a>b? a:b)
#define MIN(a,b) (a>b? b:a)
#define rep(i,n) for(lint i=0;i<(lint)(n);i++)
#define repr(i,n) for(lint i=(lint)(n);i>0;--i)
#define reps(i,a,b) for(lint i=(lint)(a);i<=(lint)(b);i++)
typedef long long lint;
typedef long double ld;
using namespace std;
const ld PI = acos(-1.0);
const lint MOD = 1000000007;

int main(){
    lint N;
    cin >> N;
    string S;
    cin >> S;
    vector<lint> n(N);
    vector<char> t(N);
    rep(i,N) n[i]=0;
    int cur = 1;
    t[0] = S[0];
    n[0] = 1;
    int pos;
    reps(i,1,N-1) {
        bool flag = false;
        rep(j,cur) if((char)(t[j]) == (char)(S[i])) {
            flag=true;
            pos = j;
        }
        if(flag) {
            n[pos]++;
        }
        else {
            cur++;
            t[cur-1] = S[i];
            n[cur-1] = 1;
        }
    }
    lint sum = 1;
    rep(i,cur) {
        sum *= ((n[i]+1)%MOD);
        sum %= MOD;
    }
    cout << (sum+MOD-1)%MOD << endl;
	return 0;
}

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

int main(){
  int N = 0,Ans = 0;
  cin >> N;
  if(N > 1){
    for(int i = 1;i <= N;i++)
      Ans += i;
    cout << Ans << endl;
  }
  else
    cout << 1 << endl;
  return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
def input(): return sys.stdin.readline().rstrip()

def hantei(S,T):
    anss=0
    for i in range(len(S)):
        if S[i]!=T[i]:
            anss+=1
    return anss

def main():
    S=input()
    T=input()
    ans=10000
    for i in range(len(S)-len(T)+1):
        ans=min(ans,hantei(T,S[i:i+len(T)]))
    print(ans)



if __name__ == '__main__':
    main()

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

int main() {
    string s, t;
    cin >> s >> t;

    bool flag = false;
    for (int i = 0; i < s.length(); i++) {
        s = s.back() + s;
        s.pop_back();
        if (s == t) flag = true;
    }

    cout << (flag ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256