akhauriyash/Code-Regression huggingface dataset:
#ifdef __APPLE__
#include "bits:stdc++.h"
#else
#include <bits/stdc++.h>
#endif

#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (LL I = 0; I < (N); ++I)
#define REPP(I, A, B) for (LL I = (A); I < (B); ++I)
#define RI(X) scanf("%lld", &(X))
#define RII(X, Y) scanf("%lld%lld", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%lld%lld%lld", &(X), &(Y), &(Z))
#define DRI(X) LL (X); scanf("%lld", &X)
#define DRII(X, Y) LL X, Y; scanf("%lld%lld", &X, &Y)
#define DRIII(X, Y, Z) LL X, Y, Z; scanf("%lld%lld%lld", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define PII pair<int,int>
#define VI vector<int>
#define VPII vector<pair<int,int> >
#define PLL pair<long long,long long>
#define VPLL vector<pair<long long,long long> >
#define F first
#define S second
typedef long long LL;
using namespace std;

LL C[(int)2.5e5],A[(int)2.5e5];

LL has[(int)2.5e5]={0},mod=1000000007;

LL inv(LL n){
    LL ans=1;
    for(LL p=mod-2,cur=n;p;p>>=1){
        if(p&1)ans=cur*ans%mod;
        cur=cur*cur%mod;
    }return ans;
}
int main(){
    DRI(n);
    fill(has,has+n+1,-1);
    LL l,r;
    REP(i,n+1){
        RI(A[i]);
        if(has[A[i]]!=-1){
            l=has[A[i]],r=n-i;
        }
        has[A[i]]=i;
    }
    LL C=n*(n+1)/2%mod,lr=l+r;
    printf("%lld\n%lld\n",n,((C-lr)%mod+mod)%mod);
    REPP(i,3,n+2){
        C=C*(n-i+2)%mod*inv(i)%mod;
        lr=lr*(l+r-i+2)%mod*inv(i-1)%mod;
        printf("%lld\n",(C-lr+mod)%mod);
    }
    
    
    
    
}

Measured memory_bytes: 4096
#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>
using namespace std;
   
  
   
int main(){
   
    int n; 
    int r[1000],w[1000];
    int sum_r=0,sum_w=0,idx=0;
	bool dp[1001][1000]={};
    while(scanf("%d",&n),n){
         
        sum_r=sum_w=idx=0;
        for(int i=0;i<n;i++){
            scanf("%d %d",&r[i],&w[i]);
            sum_r+=r[i];
            sum_w+=w[i];
            if(r[idx]<r[i]) idx=i;
        }
  
        int r0=r[idx],r=sum_r-r0;
        w[idx]=0;
 
        if(r0 <= r){
            cout<<sum_r+sum_w<<endl;
        }else{
  
            int res=2*r0;
            //vector<vector<bool> > dp(1001,vector<bool>(1000,false));
  
			fill(&dp[0][0],&dp[1001][0],false);
            dp[0][0]=true;
            for(int i=0;i<n;i++){
                for(int j=0;j<1000;j++){
                    if(dp[i][j]){
                        dp[i+1][j]=true; 
                        if(j+w[i]<1000)
                            dp[i+1][j+w[i]]=true; 
                    }
                }
            }
  
            int opt=r0-r;
            while(!dp[n][opt]) opt--;
  
            res+=sum_w-opt;
            printf("%d\n",res);
  
  
  
        }
          
          
    }
}

Measured memory_bytes: 2228
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int main(){
    string s;
    cin >> s;
    int n = s.size();
 
    ll ans = 0;
    for (int bit = 0; bit < 1<<(n - 1); bit++){
        ll temp = 0;
        for (int i = 0; i < n; i++){
            temp *= 10;
            temp += (s[i] - '0');
            if (bit & (1<<i) || i == n - 1){
                ans += temp;
                temp = 0;
            }
        }
    }
 
    cout << ans << endl;
 
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<vector<int>> vvi;

ll gcd(ll a,ll b){
  if (a%b==0) return(b);
  else return(gcd(b,a%b));
}
ll lcm(ll a,ll b){
  return a*b/gcd(a,b);
}

vector<int> bfs(vvi L,int S){
  vector<int> v(L.size(),-1);
  v[S]=0;
  queue<int> q;
  q.push(S);
  while(!q.empty()){
    int a=q.front();
    q.pop();
    for(int x:L[a]){
      if (v[x]==-1){
        v[x]=v[a]+1;
        q.push(x);
      }
    }
  }
  return v;
}

void initialize(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}
/////////////////////////////////////////

int main(){
  initialize();
  string S;
  cin >> S;
  int d[4];
  rep(i,4) d[i]=0;
  char a[4]={'N','W','S','E'};
  for(char c:S){
    rep(i,4){
      if(c==a[i]) d[i]++; 
    }
  }
  bool f=(d[0]+d[2]==0 or d[0]*d[2]>0) and (d[1]+d[3]==0 or d[1]*d[3]>0);
  cout << (f?"Yes":"No") << endl;
  return 0;
}


Measured memory_bytes: 256
open Scanf
open Printf

let rec f i x s =
	if 0 <> x then 
		let ss = "Case "^(string_of_int i)^": "^(string_of_int x)^"\n" in
		let c = read_int() in
		s^f (i+1) c ss
	else
		s;;

let ptc =
	let c = read_int() in
	let s = "" in
	f 1 c s;;

printf "%s" ptc;;

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

signed main() {
  string S; cin >> S;
  map<char,int> m;
  for(auto c : S) m[c]++;
  if(m.size()!=2) {puts("No"); return 0;}
  for(auto c : m) if(c.second != 2) {puts("No"); return 0;}
  puts("Yes");
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>

using namespace std;

int main(void){
    int a, b;

    cin >> a >> b;

    if(b % a == 0){
        cout << a + b << endl;
    }
    else{
        cout << b - a << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define COUT(x) cout<<(x)<<endl
#define dump(x)  cout << #x << " = " << (x) << endl;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
using M = map<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int, vector<int>, greater<int>>;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main() {
  int n; cin >> n;
  vector<int> a(4, 0);
  int i = 0;
  while(n > 0) {
    a[i++] = n%10;
    n/=10;
  }
  reverse(a.begin(),a.end());

  REP(bit, 1<<3) {
    string t;
    int res = a[0];
    REP(i,3) {
      if (bit >> i & 1) { t.push_back('+'); res+=a[i+1]; }
      else { t.push_back('-'); res-=a[i+1]; }
    }
    if (res == 7) {
      cout << a[0] << t[0] << a[1] << t[1] << a[2] << t[2] << a[3] << "=" << 7 << endl;
      return 0;
    }
  }
  return 0;
}

Measured memory_bytes: 256
from collections import deque
n=int(input())
v=[0 for i in range(n-1)]
u=[0 for i in range(n-1)]
w=[0 for i in range(n-1)]
da=[[] for i in range(n)]
for i in range(n-1):
  u[i],v[i],w[i]=map(int,input().split())
  da[u[i]-1].append(i)
  da[v[i]-1].append(i)
  u[i]-=1
  v[i]-=1
que=[0]
co=0
ans=[-1 for i in range(n)]
di=[0 for i in range(n)]
ans[0]=0
while co<n:
  x=que.pop()
  if di[x]%2==0:
    ans[x]=0
  else:
    ans[x]=1
  for i in da[x]:
    if ans[u[i]]<0:
      di[u[i]]=di[x]+w[i]
      que.append(u[i])
    if ans[v[i]]<0:
      di[v[i]]=di[x]+w[i]
      que.append(v[i])
  co+=1
for i in ans:
  print(i)
  
  

Measured memory_bytes: 36704
#include<iostream>
#include<cstdio>
#include<set>
#include<algorithm>
#define mk make_pair
using namespace std;
int X,Y,Z,n;
long long fro[101010];
struct evol
{
	int a,b,c;
}a[101010];
bool cmp(evol u,evol v){ return u.b-u.a<v.b-v.a;}
set<pair<int,int> > s;
int main()
{
	scanf("%d%d%d",&X,&Y,&Z);
	n=X+Y+Z;
	for(int i=1;i<=n;i++)
	scanf("%d%d%d",&a[i].a,&a[i].b,&a[i].c);
	sort(a+1,a+n+1,cmp);
	long long ans=0;
	for(int i=1;i<=X;i++)
	{
		s.insert(mk(a[i].c-a[i].a,i));
		ans+=a[i].a;
	}fro[X]=ans;
	for(int i=X+1;i<=n-Y;i++)
	{
		pair<int,int> x=mk(a[i].c-a[i].a,i),y=(*--s.end());
		if(x<y)
		{
			ans+=a[i].a+y.first;
			s.insert(x);
			s.erase(--s.end());
		}
		else ans+=a[i].c;
		fro[i]=ans;
	}
	s.clear();
	ans=0;
	for(int i=n;i>n-Y;i--)
	{
		s.insert(mk(a[i].c-a[i].b,i));
		ans+=a[i].b;
	}
	long long res=ans+fro[n-Y];
	for(int i=n-Y;i>X;i--)
	{
		pair<int,int> x=mk(a[i].c-a[i].b,i),y=(*--s.end());
		if(x<y)
		{
			ans+=a[i].b+y.first;
			s.insert(x);
			s.erase(--s.end());
		}
		else ans+=a[i].c;
		res=max(res,ans+fro[i-1]);
	}
	printf("%lld\n",res);
	return 0;
}
			
	
	

Measured memory_bytes: 5888
def sum_of_multiples(N, n):
    num_of_multiples = N//n
    sum_of_multiples = (n+n*num_of_multiples)*num_of_multiples//2
    return sum_of_multiples


def main(N=None):
    if not N:
        N = int(input())
    sum_all = N*(N+1)//2
    sum_multiples_of_three = sum_of_multiples(N, 3)
    sum_multiples_of_five = sum_of_multiples(N, 5)
    sum_multiples_of_fifteen = sum_of_multiples(N, 15)
    ans = sum_all - sum_multiples_of_three - \
        sum_multiples_of_five + sum_multiples_of_fifteen
    print(ans)
    return ans


if __name__ == "__main__":
  main()


Measured memory_bytes: 9196
#coding:utf-8

n = int(input())
xl = input().split()

listx = []
for i in xl:
  yy = int(i)
  listx.append(yy)
  
def hp(a,b):
  goh = 0
  for i in a:
    hp = (i - b)**2
    goh += hp
    
  return goh

xmax = max(listx)
xmin = min(listx)
listhp = []
for p in range(xmin,xmax + 1):
  hq = hp(listx,p)
  listhp.append(hq)
  
ans = min(listhp)
print("{}".format(ans))

Measured memory_bytes: 3064
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scanf("%d", &n)
	a := make([]int, n)
	approved := true
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &a[i])
		if a[i]%2 == 0 && (a[i]%3 != 0 && a[i]%5 != 0) {
			approved = false
		}
	}

	if approved {
		fmt.Println("APPROVED")
	} else {
		fmt.Println("DENIED")
	}
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;

bool is_integer(double x){
  double r;
  return 0==std::modf(x,&r);
}

int main() {
  int N,D,ans=0;
  cin>>N>>D;
  vector<vector<int>> X(N,vector<int>(D));
  rep(i,N)rep(j,D)cin>>X[i][j];
  rep(i,N)for(int j=i+1;j<N;j++){
      double L=0;
      rep(k,D){
        double p=pow(X[i][k]-X[j][k],2);
        L+=p;
      }
      double q=pow(L,0.5);
      if(is_integer(q))ans++;
  }
  cout << ans<<endl;
  return 0;
}

Measured memory_bytes: 4024
#include <bits/stdc++.h>
// #include <atcoder/all>
#define ll long long int
#define ld long double
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i, n) for (ll i = 1; i < (ll)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;

long long GCD(long long a, long long b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}

vector<pair<ll, ll> > prime_factorize(ll N) {
    vector<pair<ll, ll> > res;
    for (ll a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        ll ex = 0; // 指数

        // 割れる限り割り続ける
        while (N % a == 0) {
            ++ex;
            N /= a;
        }

        // その結果を push
        res.push_back({a, ex});
    }

    // 最後に残った数について
    if (N != 1) res.push_back({N, 1});
    return res;
}
// using namespace atcoder;
void Main()
{
    ll A, B;
    cin >> A >> B;

    ll gcd = GCD(A, B);
    auto primes = prime_factorize(gcd);
    put(primes.size() + 1);
}
signed main(){ Main();return 0;}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 10000000000000000

int main(){
	
	int N;
	cin>>N;
	
	vector<pair<long long,long long>> A(N);
	for(int i=0;i<N;i++){
		cin>>A[i].first;
		A[i].second = i;
	}
	
	sort(A.rbegin(),A.rend());
	
	vector<vector<long long>> dp(N+1,vector<long long>(N+1,-Inf));
	dp[0][0] = 0;
	
	for(int i=0;i<N;i++){
		for(int j=0;j<=N;j++){
			if(dp[i][j]==-Inf)continue;
			long long mini = j;
			long long maxi = N-1-i+j;
			
			dp[i+1][j] = max(dp[i+1][j],dp[i][j]+abs(maxi-A[i].second)*A[i].first);
			dp[i+1][j+1] = max(dp[i+1][j+1],dp[i][j] + abs(mini-A[i].second)*A[i].first);
		}
	}
	
	long long ans = 0;
	for(int i=0;i<=N;i++){
		ans = max(ans,dp.back()[i]);
	}
	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 34668
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <cstring>

void merge(int *A, char *S, int left, int mid, int right){
    int i, j;
    int n1 = mid - left;
    int n2 = right - mid;
    int L[n1+1];
    int R[n2+1];
    char Ls[n1+1];
    char Rs[n2+1];
    for(i=0;i<n1;i++)L[i]=A[left+i];
    for(i=0;i<n2;i++)R[i]=A[mid+i];
    for(i=0;i<n1;i++)Ls[i]=S[left+i];
    for(i=0;i<n2;i++)Rs[i]=S[mid+i];
    L[n1] = INT_MAX;
    R[n2] = INT_MAX;
    Ls[n1] = CHAR_MAX;
    Rs[n2] = CHAR_MAX;
    i = 0;
    j = 0;
    for(int k=left;k<right;k++){
        if(L[i]<=R[j]){
            A[k] = L[i];
            S[k] = Ls[i];
            i++;
        }else{
            A[k] = R[j];
            S[k] = Rs[j];
            j++;
        }
    }
}

void mergeSort(int *A, char *S, int left, int right){
    if(left+1>=right)return;
    int mid = (left + right)/2;
    mergeSort(A, S, left, mid);
    mergeSort(A, S, mid, right);
    merge(A, S, left, mid, right);
}

int partition(int *a, char *s, int p, int r){
    int x = a[r];
    char y = s[r];
    int i = p - 1;
    int tmp1;
    char tmp2;
    for(int j=p;j<r;j++){
        if(a[j]<=x){
            i++;
            tmp1 = a[j];
            a[j] = a[i];
            a[i] = tmp1;
            tmp2 = s[j];
            s[j] = s[i];
            s[i] = tmp2;
        }
    }
    a[r] = a[i+1];
    a[i+1] = x;
    s[r] = s[i+1];
    s[i+1] = y;
    return i + 1;
}

void quickSort(int *a, char *s, int p, int r){
    if(p>=r)return;
    int q = partition(a, s, p, r);
    quickSort(a, s, p, q-1);
    quickSort(a, s, q+1, r);
}

int main(){
    int i, n, p;
    char c;
    scanf("%d",&n);
    int a[n];
    char s[n+1];
    int a_[n];
    char s_[n+1];
    char tmp[2];
    for(i=0;i<n;i++){
        while((c = getchar())=='\n');
        s[i] = c;
        s_[i] = c;
        scanf("%s",tmp);
        a[i] = atoi(tmp);
        a_[i] = a[i];
    }
    s[n] = '\0';
    s_[n] = '\0';
    quickSort(a, s, 0, n-1);
    mergeSort(a_,s_,0,n);
    if(strcmp(s,s_)==0)printf("Stable\n");
    else printf("Not stable\n");
    for(i=0;i<n;i++){
        printf("%c %d\n",s[i],a[i]);
    }
    return 0;
}



Measured memory_bytes: 4052
N, K = map(int, input().split())
a_list = list(map(int, input().split()))
sum_list = []

for i in range(N):
    for j in range(i, N):
        sum_list.append(sum(a_list[i:j+1]))
ans = 0
count = 0
tmp = []
for i in range(40, -1, -1):
    for s in sum_list:
        check_num = 1 << i
        logical_and = check_num & s

        if logical_and != 0:
            count += 1

    if count >= K:
        ans += 1 << i
        tmp = [x for x in sum_list if (1 << i) & x != 0]
        sum_list = tmp[:]
    count = 0
print(ans)



Measured memory_bytes: 24748
package main

import (
	"fmt"
	"sort"
)

func main() {
	var N, M, sum int
	fmt.Scan(&N, &M)
	An := make([]int, N)
	for i := range An {
		fmt.Scan(&An[i])
		sum += An[i]
	}
	sort.Sort(sort.Reverse(sort.IntSlice(An)))
	if An[M-1]*4*M >= sum {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


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

// Shrotening
#define fst first
#define snd second
#define pb push_back
#define mp std::make_pair

// Loop
#define FOR(i,a,b) for(auto i=(a);i<(b);++i)
#define RFOR(i,a,b) for(auto i=(a);i>=(b);--i)

#define REP(i,a) for(long i=0;i<(a);++i)
#define RREP(i,a) for(long i=(a);i>=0;--i)

#define EACH(i,a) for(auto (i)=(a).begin(),_END=(a).end();i!=_END;++i)
#define REACH(i,a) for(auto (i)=(a).rbegin(),_END=(a).rend();i!=_END;++i)

//Algorithm
#define ALL(a) (a).begin(), a.end()
#define RALL(a) (a).rbegin(), a.rend()
#define EXIST(a,x) ((a).find(x)!=(a).end())
#define SORT(a) std::sort((a).begin(), (a).end())
#define UNIQUE(a) std::sort((a).begin(), a.end()), a.erase(std::unique((a).begin(), a.end()), a.end());
#define SUM(a) std::accumulate((a).begin(), (a).end(), 0);

#define fcout(n) std::cout << std::fixed << std::setprecision((n))

//Setting
#define OPT std::cin.tie(0);std::ios::sync_with_stdio(false);

//debug message
bool debug = true;
#define MSG(s)   if(debug){std::cout << s << std::endl;}
#define DEBUG(x) if(debug){std::cout << "debug(" << #x << "): " << x << std::endl;}

//alias
typedef long long LL;
typedef std::pair<int,int> PII;

typedef std::vector<char> VC;
typedef std::vector<int>  VI;
typedef std::vector<long> VL;
typedef std::vector<long long> VLL;
typedef std::vector<PII> VPII;

typedef std::vector< VC > VC2;
typedef std::vector< VI > VI2;
typedef std::vector< VL > VL2;
typedef std::vector< VLL > VLL2;

int a, b;
int main() {
    std::cin >> a >> b;
    if(a+b == 15) {
        std::cout << "+" << std::endl;
    } else if(a*b == 15) {
        std::cout << "*" << std::endl;
    } else {
        std::cout << "x" << std::endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <iterator>

using namespace std;

int main(){
	
	int n, r, p, c;
	
	vector<int> v1, v2;
	
	while(true){
		cin >> n >> r;
		if(n == 0 && r == 0){
			break;
		}
		for(int i = 1; i <= n; i++){
			v1.push_back(i);
		}
		for(int loop = 0; loop < r; loop++){
			cin >> p >> c;
			p--;
			copy(v1.end() - p - c, v1.end() - p, back_inserter(v2));
			v1.erase(v1.end() - p - c, v1.end() - p);
			copy(v2.begin(), v2.end(), back_inserter(v1));
			v2.erase(v2.begin(), v2.end());
			/*
			for(int i = 0; i < v1.size(); i++){
				printf("%d ", v1.at(i));
			}
			printf("\n");
			*/
		}
		printf("%d\n", v1.back());
		v1.erase(v1.begin(), v1.end());
	}
	
	return 0;
}

Measured memory_bytes: 1200
#include "bits/stdc++.h"
using namespace std;

int main(void){
  int in=0,l=0;
  string s;
  vector<int>v[101];

 while(getline(cin,s)){
  if(s=="PP")break; for(int i=0;i<=s.size();i++){
	  if(s[i]==',' || i==s.size())v[l].push_back(in),in=0;else if(s[i]!=',')in*=10,in+=s[i]-'0';}l++;
  }

  int dp[101][101];

  fill(dp[0],dp[101],0);
   dp[0][0]=v[0][0];

  for(int i=1;i<l;i++){
    for(int j=0;j<v[i].size();j++){
      dp[i][j]=dp[i-1][j]+v[i][j];
      if(i<=l/2 && j)dp[i][j]=max(dp[i][j],dp[i-1][j-1]+v[i][j]);
      if(i>l/2)dp[i][j]=max(dp[i][j],dp[i-1][j+1]+v[i][j]);
    }
  }
  cout << dp[l-1][0] << endl;

  return 0;
}

Measured memory_bytes: 3016
#include <stdio.h>
#include <iostream>
#include <vector>
#include <list>
#include <cmath>
#include <fstream>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <iterator>
#include <cstdlib>
#include <sstream>

using namespace std;

#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) (EQ((a).real(),(b).real()) && EQ((a).imag(),(b).imag()))

typedef complex<double> P;
typedef long long ll;

const int MAX_SIZE = 10000;


class table{
public:
	int a;
	int b;
	int c;
	int check;

	bool operator<(const table &t)const{
		return t.check < (this->check);
	}
};

int main(){

	int a,b,c,N;
	while(cin >> a >> b >> c && !(a == 0 && b == 0 && c == 0)){
	vector<table> v;
	cin >> N;
	int check[10000];
	fill(check,check+10000,2);
	for(int i = 0; i < N; i++){
		table t;
		cin >> t.a >> t.b >> t.c >> t.check;
		v.push_back(t);
	}
	sort(v.begin(),v.end());
	for(int i = 0; i < v.size(); i++){
		if(v[i].check == 1){
			check[v[i].a] = 1;
			check[v[i].b] = 1;
			check[v[i].c] = 1;
		}
		else{
			if(check[v[i].a]==1 && check[v[i].b]==1 && check[v[i].c]==2){
				check[v[i].c] = 0;
			}
			else if(check[v[i].a]==1 && check[v[i].b]==2 && check[v[i].c]==1){
				check[v[i].b] = 0;
			}
			else if(check[v[i].a]==2 && check[v[i].b]==1 && check[v[i].c]==1){
				check[v[i].a] = 0;
			}
		}
	}

	for(int i = 1; i <= a + b+ c; i++){
		cout << check[i] << endl;
	}
	}


	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin>>s;
  int m=0;
  int c=0;
  for(int i=0;i<s.size();i++){
    if(s.at(i)=='A'||s.at(i)=='C'||s.at(i)=='G'||s.at(i)=='T')
      c++;
    else
      c=0;
    m=max(m,c);
  }
  cout<<m<<endl;
}

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

int main(){

  string A,B; cin >> A >> B;

  if(A.size() > B.size())cout << "GREATER" << endl;
  else if(A.size() < B.size())cout << "LESS" << endl;
  else{//A.size() == B.size()

    for(int i = 0;i < B.size();i++){
      if(A[i] > B[i]){
        cout << "GREATER" << endl;
        return 0;
      }
      if(B[i] > A[i]){
        cout << "LESS" << endl;
        return 0;
      }
    }

    cout << "EQUAL" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdio.h>
#include <algorithm>
using namespace std;
#define ll long long
#define r(i,n) for(int i=0;i<n;i++)
#define rn(i,n) for(int i=1;i<=n;i++)

int main(){
  ll n,k,cnt=0,cnt1=0;
  cin>>n>>k;
  if(k%2==0){
    for(int i=1;i<=n;i++){
      if(i%k==0)cnt++;
      else if(i%k==k/2)cnt1++;
    }
    cnt=cnt*cnt*cnt+cnt1*cnt1*cnt1;
  }else{
    for(int i=1;i<=n;i++){
      if(i%k==0)cnt++;
    }
    cnt=cnt*cnt*cnt;
  }


  cout<<cnt<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/indexed.hpp>

using namespace std;
using namespace boost::adaptors;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;
using boost::irange;
constexpr ll MOD = 0x1fffffffffffff;

int main()
{
  random_device rd;
  mt19937 mt(rd());
  uniform_int_distribution<ll> dis(257, 612);
  ll base = dis(mt);
  ll n;
  cin>>n;
  string s;
  cin>>s;
  vector<vector<tuple<ll, ll>>> vs(n+1);
  vector<bool> ok(n+1);
  for(ll i : irange(0l, n)) {
    ll h = 0;
    for (ll j : irange(0l, n)) {
      if (i+j >= n) break;
      h *= base;
      h += s[i+j];
      h %= MOD;
      vs[j+1].emplace_back(h, i);
    }
  }
  for (auto&& s : index(vs)) {
    boost::sort(s.value());
    ll old = -1;
    ll oldi = 0;
    for (auto& t : s.value()) {
      ll h, i;
      tie(h, i) = t;
      if (old == h) {
        if (oldi + s.index() <= i) ok[s.index()] = true;
      } else {
        old = h;
        oldi = i;
      }
    }
  }
  int mx = 0;
  for (auto&& p : index(ok)) {
    if (p.value()) mx = p.index();
  }
  cout<<mx<<endl;
  return 0;
}


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

using ll = long long;
#define int long long
using P = pair<int, int>;

#define LOG(variable) cout << #variable":\t" << (variable) << endl
#define LOGCON(i, container) for(int (i) = 0; (i) < (container).size(); ++(i)) cout << (i) << ":\t" << (container)[(i)] << endl
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(i, r, n) for (int i = (r); i < (n); ++i)
#define REPR(i, n) for(int i = (n); i >= 0; --i) // from n to 0
#define REPRS(i, n, r) for(int i = (n); i >= (r); --i) // from n to r
#define REPOBJ(itr, obj) for(auto itr = (obj).begin(); itr != (obj).end() ; ++itr)
#define REPROBJ(itr, obj) for(auto itr = (obj).rbegin(), e = (obj).rend(); itr != e; ++itr)
#define COUTB(x) cout << (x) << "\n"
#define COUTS(x) cout << (x) << " "
#define PB push_back
#define SORT(obj) sort((obj).begin(), (obj).end())
#define SORTR(obj) sort((obj).begin(), (obj).end(), greater<>())
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define PI (acos(-1))
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%MOD+MOD)%MOD){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += MOD-a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= MOD; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime MOD
  mint inv() const { return pow(MOD-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
template<typename T = int>
T in() {T a; cin >> a; return a;}
/***** MAIN *****/
signed main() {
  int n, a, b, c, d;
  cin >> n >> a >> b >> c >> d;
  --a; --b; --c; --d;
  string s; cin >> s;
  if(c < d) {
    REPS(i,a,d-1) {
      if(s[i] == '#' && s[i+1] == '#') {
        cout << "No" << endl;
        return 0;
      }
    }
    cout << "Yes" << endl;
    return 0;
  }

  REPS(i,a,c-1) {
    if(s[i] == '#' && s[i+1] == '#') {
      cout << "No" << endl;
      return 0;
    }
  }

  REPS(i,b,d+1) {
    if(s[i-1] == '.' && s[i] == '.' && s[i+1] == '.') {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}
/***** MAIN *****/


Measured memory_bytes: 640
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 10**6
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )
x,y=map(int,input().split())
if x>2*y or y>2*x or (2*x-y)%3!=0 or (2*y-x)%3!=0:
    print(0)
    exit()
print(cmb((x+y)//3,(2*x-y)//3,mod))

Measured memory_bytes: 122016
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-6;
const double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}

int main(){
	int a;scanf("%d",&a);
	int o1=0;
	int o2=0;
	int o4=0;
	for(int i=0;i<a;i++){
		int p;scanf("%d",&p);
		if(p%4==0)o4++;
		else if(p%2==0)o2++;
		else o1++;
	}
	bool ok=false;
	if(o2==0){
		if(o1<=o4+1)ok=true;
	}else{
		if(o1<=o4)ok=true;
	}
	if(ok)printf("Yes\n");else printf("No\n");
}
//14141222

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <vector>
using namespace std;

int main(){
    int N;
    cin >> N;
    int l[N];
    int max_l = 0;
    int sum = 0;
    for(int i = 0; i < N; i++){
        cin >> l[i];
        max_l = max(max_l, l[i]);
        sum += l[i];
    }
    sum -= max_l;
    if(max_l < sum){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    
    }
    return 0;
}

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

int main() {
  char c;
  cin >> c;
  if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u')
    cout << "vowel" << endl;
  else
    cout << "consonant" << endl;

  return 0;
}


Measured memory_bytes: 256
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())


N = I()
CSF = [tuple(MI()) for i_ in range(N-1)]

for i in range(N):
    time = 0
    for j in range(i,N-1):
        c,s,f = CSF[j]
        if time < s:
            time = s
        else:
            time = s+f*((time-s+f-1)//f)
        time += c
    print(time)


Measured memory_bytes: 72048
/* Headers */
#include <unordered_map>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <climits>
#include <cstdio>
#include <cctype>
#include <vector>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#define FOR(i,a,b,c) for(int i=(a);i<=(b);i+=(c))
#define ROF(i,a,b,c) for(int i=(a);i>=(b);i-=(c))
#define FORL(i,a,b,c) for(long long i=(a);i<=(b);i+=(c))
#define ROFL(i,a,b,c) for(long long i=(a);i>=(b);i-=(c))
#define FORR(i,a,b,c) for(register int i=(a);i<=(b);i+=(c))
#define ROFR(i,a,b,c) for(register int i=(a);i>=(b);i-=(c))
#define RevEdge(x) x^1
#define lowbit(x) x&(-x)
#define LeftChild(x) x<<1
#define RightChild(x) (x<<1)+1
#define CLOSE_IN() fclose(stdin);
#define CLOSE_OUT() fclose(stdout);
#define FILE_IN(x) freopen(x,"r",stdin);
#define FILE_OUT(x) freopen(x,"w",stdout);
#define IOS(x) std::ios::sync_with_stdio(x)
#define Dividing() printf("-----------------------------------\n");
namespace FastIO {
#define gc() (iS == iT ? (iT = (iS = ibuff) + fread(ibuff, 1, SIZ, stdin), (iS == iT ? EOF : *iS++)) : *iS++)
    const int SIZ = 1 << 21 | 1;
    char* iS, * iT, ibuff[SIZ], obuff[SIZ], * oS = obuff, * oT = oS + SIZ - 1, fu[110], cc;
    int fr;
    inline void out() {
        fwrite(obuff, 1, oS - obuff, stdout);
        oS = obuff;
    }
    template<class Type>
    inline void read(Type& x) {
        x = 0;
        Type y = 1;
        for (cc = gc(); (cc > '9' || cc < '0') && cc != '-'; cc = gc());
        cc == '-' ? y = -1 : x = (cc & 15);
        for (cc = gc(); cc >= '0' && cc <= '9'; cc = gc())
            x = x * 10 + (cc & 15);
        x *= y;
    }
    template<class Type>
    inline void print(Type x, char text = '\n') {
        if (x < 0)
            * oS++ = '-', x *= -1;
        if (x == 0)
            * oS++ = '0';
        while (x)
            fu[++fr] = x % 10 + '0', x /= 10;
        while (fr);
            * oS++ = fu[fr--];
        * oS++ = text;
        out();
    }
    inline void prints(char x[], char text = '\n') {
        for (register int i = 0; x[i]; ++i)
            * oS++ = x[i];
        * oS++ = text;
        out();
    }
}
using namespace FastIO;
template<typename T>
inline T max(T a, T b) {return (a > b) ? a : b;}
template<typename T>
inline T min(T a, T b) {return (a > b) ? b : a;}
/* definitions */
#define ll long long
const int MAXN = 3e5 + 10, mod = 1e9 + 7;
ll n, dp[MAXN][3][3], ans;
char s[MAXN];
/* functions */
int main(int argc, char *argv[]) {
    /*FILE_IN("data.in");*/ scanf("%s", s + 1);
    n = strlen(s + 1), dp[0][0][0] = 1;
    FOR(i, 1, n, 1)
        FOR(j, 0, 2, 1)
            FOR(k, 0, 2, 1) {
                if(s[i] != '0') {
                    if(k) (dp[i][j][k - 1] += dp[i - 1][j][k]) %= mod;
                    else (dp[i][min(j + 1, 2)][k] += dp[i - 1][j][k]) %= mod;
                } if(s[i] != '1') {
                    if(k == 2) (dp[i][j][1] += dp[i - 1][j][k]) %= mod;
                    else (dp[i][j][k + 1] += dp[i - 1][j][k]) %= mod;
                }
            }
    FOR(i, 0, 2, 1) FOR(j, 0, i, 1) (ans += dp[n][i][j]) %= mod;
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 25172
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
// Hey! 僕の提出を見てくれてありがとう.
// ロボ子さん可愛いぞ！！！！！君もV沼にはまろう↓
// https://www.youtube.com/channel/UCDqI2jOz0weumE8s7paEk6g
using namespace std;
namespace mp = boost::multiprecision;
// 任意長整数型
using bint = mp::cpp_int;
// 仮数部長が32の浮動小数点数型
using real32 = mp::number<mp::cpp_dec_float<32>>;
// 仮数部長が1024の浮動小数点数型
using real1024 = mp::number<mp::cpp_dec_float<1024>>;
// ついでに有理数型
using rat = boost::rational<bint>;
using ll = long long;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}//a,bの最大公約数(gcd)を求める
ll lcm(ll a,ll b){return abs(a*b)/gcd(a,b);}//a,bの最小公倍数(lcm)を求める
vector<ll> enum_div(ll n){vector<ll> ret;for(int i=1 ; i*i<=n ; i++){if(n%i == 0){ret.push_back(i);if(i!=1 && i*i!=n)ret.push_back(n/i);}}ret.push_back(n);return ret;}
//↑nの約数を求める
vector<bool> IsPrime; void sieve(size_t max){if(max+1 > IsPrime.size())IsPrime.resize(max+1,true);IsPrime[0] = false;IsPrime[1] = false;for(size_t i=2; i*i<=max; ++i)if(IsPrime[i])for(size_t j=2; i*j<=max; ++j)IsPrime[i*j] = false;}
//↑エラトステネスの篩で素数を求める
#define roundup(divisor,dividend) (divisor + (dividend - 1)) / dividend //切り上げ割り算
#define all(x) (x).begin(),(x).end() //xの初めから終わりまでのポインタ
#define size_t ll //size_tは自動でllに変換される
#define pb(x) push_back(x)
#define pri_queue priority_queue //優先度付きキュー
#define syo(x) fixed << setprecision(x) //iostreamで小数をx桁表示
//sortを降順にする時は greater<型>()

void solve(long long N){
	string a = to_string(N);
	int ans = 0;
	for (int i = 0; i < 4; i++) {
		if(a[i] == '2')ans++;
	}
	cout << ans << endl;
}

int main(){
    long long N;
  scanf("%lld",&N);
    solve(N);
    return 0;
}


Measured memory_bytes: 3740
#include<bits/stdc++.h>
#define ll long long int 
#define double /*long*/ double
#define endl '\n'
#define vll vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define vppll vector<pair<pll,pll>>
#define mp make_pair
#define pb push_back
#define mapll map<ll,ll>
#define fir first
#define sec second
#define _cin ios_base::sync_with_stdio(0);  cin.tie(0);
#define fo(i,b) for(i=0;i<b;i++)
#define repa(i,a,b) for(i=a;i<b;i++)
#define repb(i,a,b) for(i=a;i>=b;i--)
#define all(x) (x).begin(), (x).end()
#define s(v) v.size()
const long long int MAX = (ll)(1e18+1);
const long long int MIN = (ll)(-1e18-1);
const long long int mod = (ll)(1e9+7);
using namespace std;

ll max(ll a,ll b,ll c) {return max(max(a, b), c);}
ll min(ll a,ll b,ll c) { return min(min(a, b), c);}
ll max(ll a,ll b) {return (a>b) ? a : b;}
ll min(ll a,ll b) {return (a<b) ? a : b;}
ll power(ll a, ll n) {ll p = 1;while (n > 0) {if(n%2) {p = p * a;} n >>= 1; a *= a;} return p;}
ll power_mod(ll a, ll n, ll mod_){ ll p=1; while(n){ if(n%2){ p=(p*a)%mod_;} n/=2; a=(a*a)%mod_;} return p%mod_;}
                                                 /*Code Begins*/


int main(){
    _cin;
    // cout << setprecision(15);
    ll mn = MAX, mx = MIN;
    ll n, t, m, k, i, j,  sum=0,  prev, flag=0, cnt=0;
    ll x=0, y=0, fx, tot=0, l , r;
    int TC=1;
    // cin >> TC;
while(TC--){
    cin >> n;
    string s;
    cin >> s;
    ll dp[n+2][n+2];
    vll pr(n+2,0);
    fo(i,n+2) {
        fo(j,n+2) dp[i][j]=-1;
        // cout << endl;
    }
    dp[1][1]=1;
    pr[0]=0;
    pr[1]=1;
    repa(l,2,n+1){
        repa(i,1,l+1){
            if(s[l-2]=='<') {
                dp[l][i] = pr[i-1]%mod;
            }else{
                dp[l][i] = (pr[l-1] +mod - pr[i-1])%mod;
            }
        }
        pr[0]=0;
        repa(i,1,l+1) pr[i] = (pr[i-1] + dp[l][i])%mod;
        // pr[l+1]=pr[l];
    }
    ll ans=0;
    repa(i,1,n+1) ans = (ans + dp[n][i])%mod;
    cout << ans << endl;
    // repa(i,1,n+1) {
    //     repa(j,1,n+1) cout << dp[i][j] << ' ';
    //     cout << endl;
    // }



}
    return 0;
}


Measured memory_bytes: 70656
/**
 *      purpose : AGC 5 A
 *      author  : kyomukyomupurin
 *      created : 2018-11-21 20:59:43
**/

#include <bits/stdc++.h>
using namespace std;
typedef int64_t int64;
#define print(x) cout << (x) << '\n'

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    string x; cin >> x;
    stack<char> s;

    for (int i = 0; i < (int) x.size(); ++i){
        if (x[i] == 'S'){
            s.push(x[i]);
        }
        else if ((x[i] == 'T' && s.empty()) || (x[i] == 'T' && s.top() == 'T')){
            s.push(x[i]);
        }
        else if (x[i] == 'T' && s.top() == 'S'){
            s.pop();
        }
    }
    print(s.size());
    
    return 0;
}

Measured memory_bytes: 720
from collections import defaultdict, Counter

n = int(input())
a = list(map(int, input().split()))
ans = [0] * n
dic = defaultdict(int)
for i in range(n):
    dic[a[i]] += 1

sum = 0
for v in dic.values():
    sum += v * (v - 1) / 2
    
for i in range(n):
    print(int(sum - (dic[a[i]] - 1)))

Measured memory_bytes: 26908
N, K = map(int, raw_input().split())
D = raw_input().split()

while True:
	flag = True
	for i in range(0, len(str(N))):
		if str(N)[i] in D:
			flag = False
			break
	if flag:
		print N
		break
	else:
		N = N + 1

Measured memory_bytes: 2692
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

var (
	readString func() string
	readBytes  func() []byte
	stdout     *bufio.Writer
)

func init() {
	readString, readBytes = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Bytes()
	}
	return f1, f2
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

func eprintf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(os.Stderr, f, args...)
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func min64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func max64(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func abs64(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func gcd64(a, b int64) int64 {
	if b == 0 {
		return a
	}
	return gcd64(b, a%b)
}

// readString() string
// readInt() int
// readInt64() int64
// readFloat64() float64

// -----------------------------------------------------------------------------

func main() {
	defer stdout.Flush()
	N := readInt()
	M := readInt()
	G := make([][]int, N)
	for i := 0; i < M; i++ {
		x := readInt() - 1
		y := readInt() - 1
		G[x] = append(G[x], y)
	}

	H := make([]int, N)
	for i := range H {
		H[i] = -1
	}
	var ans int
	for i := range G {
		ans = max(ans, dfs(H, G, i))
	}
	println(ans)
}

func dfs(H []int, G [][]int, i int) int {
	if 0 <= H[i] {
		return H[i]
	}
	if len(G[i]) == 0 {
		H[i] = 0
		return 0
	}
	var ans int
	for _, j := range G[i] {
		ans = max(ans, dfs(H, G, j))
	}
	H[i] = ans + 1
	return H[i]
}

// -----------------------------------------------------------------------------


Measured memory_bytes: 21376
# D - Sum of Divisors

n = int(input())

# n以下の1の倍数 ... n個, それぞれk倍して加算 ... n * (n+1) // 2
# n以下のmの倍数 ... n//m個, それぞれk倍して加算 ... m * (n // m) * (n // m + 1) // 2

s = sum(m * (n // m) * (n // m + 1) // 2 for m in range(1, n + 1))
print(s)


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

const int N = 2 * 1e5 + 1;
vector<vector<int>> graph(N);
vector<bool> checked(N);

int dfs(int x) {
	stack<int> s;
	s.push(x);
	int visited = 0;
	checked[x] = true;
	while (!s.empty()) {
		visited++;
		int node = s.top();
		s.pop();
		for (int i : graph[node]) {
			if (!checked[i]) {
				s.push(i);
				checked[i] = true;
			}
		}
	}
	return visited;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, m;
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		graph[a].push_back(b);
		graph[b].push_back(a);
	}
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		if (!checked[i]) {
			ans = max(ans, dfs(i));
		}
	}
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 15052
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

int main() {
  int n, m;

  while(cin >> n >> m, n+m) {
    VI v;
    REP(i, m) v.PB(0);

    REP(i, n) {
      REP(j, m) {
	bool q;
	cin >> q;
	if(q) v[j]++;
      }
    }

    int point;
    REP(i, m) {
      int max = -1;
      REP(j, m) {
      if(max < v[j]) {
	max = v[j];
	point = j;
      }
      }
      v[point] = -1;
      cout << point+1;
      if(i+1 != m) cout << ' ';
      else cout << endl;
    }
    v.clear();
  }
}

Measured memory_bytes: 1220
import java.util.Scanner

object Main extends App { 
  val sc = new Scanner(System.in)
  val N, W = sc.nextInt()
  val items= (for (i <- 1 to N) yield (sc.nextInt, sc.nextInt)).toArray

  type Item = (Int,Int)

  class DP(num:Int, wgt:Int, items:Array[Item]) {
    val memo = Array.fill(wgt+1)(0)
    override def toString:String = (for (e <- memo) yield f" $e%2d").foldLeft("")(_ + _)
    def solver():Int = {
      for (i <- 1 to num; j <- wgt to 0 by -1) {
        val (v, w) = items(i-1)
        if (j >= w) {
          val v0 = memo(j)
          val v1 = memo(j-w) + v
          memo(j)= v0 max v1
        }
      }
      memo(wgt)
    }
  }
  
  val dp = new DP(N, W, items)

  println(dp.solver())
}


Measured memory_bytes: 47492
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define repp(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
//小数点以下　cout << fixed << setprecision(10) << num << endl;
//桁数はlog10(mid)でやれ　log(mid)/log(10)はWA
const int INF = 1001001001;
int main(){
    int n; cin >> n;
    rep(i,50001){
        if(int(i*1.08)==n){
            cout << i << endl;
            return 0;
        }
    }
    cout << ":(" << endl;
}


Measured memory_bytes: 256
s=input()
ans=0
for i in range(len(s)):
	ct=0
	for j in range(i,len(s)):
		if s[j]=="A" or s[j]=="C" or s[j]=="T" or s[j]=="G":
			ct+=1
		else:
			break
	ans=max(ct,ans)

print(ans)

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

int main(){
	int A, B;
	cin >> A >> B;
	for(int n=1;n<=200000;n++) {
		int a = (n * 0.08) / 1;
		int b = (n * 0.1) / 1;
		if(a == A and b == B) {
			cout << n << endl;
			return 0;
		}
	}
	cout << -1 << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
	
	int a,b;
	scanf("%d%d",&a,&b);
	int d,r;
	double f;
	d=a/b; r=a%b; f=(double)a/(double)b;
	printf("%d %d %f\n",d,r,f);
	
	return 0;
}


Measured memory_bytes: 2120
#include<stdio.h>
#include<stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root = NIL;

Node treeMinimum(Node x){
  while(x->left!=NIL)x=x->left;
  return x;
}

Node treeSearch(Node u, int k){
  Node i=u;
  while(i!=NIL){
    if(i->key==k)return i;
    else if(i->key<k)i=i->right;
    else i=i->left;
    
  }
  return NIL;
}

Node treeSuccessor(Node x){
  if(x->right!=NIL)return treeMinimum(x->right);
  Node y=x->parent;
  while(y!=NIL&&x==y->right){
    x=y;
    y=y->parent;
  }
  return y;
}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y
  if(z->left==NIL||z->right==NIL)y=z;
  else y=treeSuccessor(z);
  
  if(y->left!=NIL)x=y->left;
  else x=y->right;

  if(x!=NIL)x->parent=y->parent;
  
  if(y->parent==NIL)root=x;
  else if(y==y->parent->left)y->parent->left=x;
  else y->parent->right=x;

  if(y!=z)z->key=y->key;
  
}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x!=NIL){
    y=x;
    if(z->key<x->key)x=x->left;
    else x=x->right;
  }
  z->parent=y;
  if(y==NIL)root=z;
  else if(z->key<y->key)y->left=z;
  else y->right=z;
  
}

void inorder(Node u){
  if(u==NIL)return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}

void preorder(Node u){
  if(u==NIL)return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}

Measured memory_bytes: 19364
#include<stdio.h>
char a[100010];
int main(){
    int s=0;
    char b;
    scanf("%s",a);
    b=a[0];
    for(int i=1;a[i]!='\0';i++){
        if(a[i]!=b){
            s++;
            b=a[i];
        }
    }
    printf("%d",s);
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	static final int MAX = 100;
	static final long INF = (1L << 32);
	static int n;
	static long[][]d = new long[MAX][MAX];
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		n = scan.nextInt();
		int q = scan.nextInt();
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < n; j++) {
				if(i != j) d[i][j] = INF;
			}
		}
		for(int i = 0; i < q; i++) {
			int u = scan.nextInt();
			int v = scan.nextInt();
			int c = scan.nextInt();
			d[u][v] = c;
		}
		scan.close();
		warshallFloyd();
		boolean negative = false;
		for(int i = 0; i < n; i++){
			if(d[i][i] < 0) negative = true;
		}
		if(negative) {
			System.out.println("NEGATIVE CYCLE");
		}else {
			for(int i = 0; i < n; i++) {
				for(int j = 0; j < n; j++) {
					if(j == n - 1) {
						if(d[i][j] == INF) System.out.println("INF");
						else System.out.println(d[i][j]);
					}
					else {
						if(d[i][j] == INF) System.out.print("INF ");
						else System.out.print(d[i][j] + " ");
					}
				}
			}
		}
	}
	static void warshallFloyd() {
		for(int k = 0; k < n; k++) {
			for(int i = 0; i < n; i++) {
				if(d[i][k] == INF) continue;
				for(int j = 0; j < n; j++) {
					if(d[k][j] == INF) continue;
					d[i][j] = Math.min(d[i][j], d[i][k] + d[k][j]);
				}
			}
		}
	}
}


Measured memory_bytes: 58656
#include <bits/stdc++.h>
#include <boost/range/adaptor/reversed.hpp>
#include <boost/range/algorithm/sort.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using boost::irange;
using boost::sort;
using boost::adaptors::reversed;

int main() {
    int k;
    cin >> k;
    long ans = 0;
    for (int a = 1; a <= k; a++) {
        for (int b = 1; b <= k; b++) {
            for (int c = 1; c <= k; c++) {
                ans += gcd(gcd(a, b), c);
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
string b="CODEFESTIVAL2016";
int main()
{
    string a;
    cin>>a;
    int i,counter;
    counter=0;
    for(i=0;i<a.size();i++)
    {
        if(a[i]!=b[i])counter++;
    }
    cout<<counter<<endl;
    //不换行就等着WA吧！
    return 0;
}

Measured memory_bytes: 256