akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

int cnt[50];

signed main()
{
    int N,M; cin>>N>>M;
    REP(i,M){
        int a,b; cin>>a>>b;
        a--,b--;
        cnt[a]++; 
        cnt[b]++;
    }
    REP(i,N) cout<<cnt[i]<<endl;
 
}


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

int main(void) {
    int A, B; cin >> A >> B;
    int max = -999999;

    if (A + B > max){
        max = A + B;
    }
    if (A - B > max){
        max = A - B;
    }
    if (A * B > max){
        max = A * B;
    }

    cout << max << 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 erep(i,n) for(int i = 0;i<=n;i++)
#define rep1(i,n) for(int i = 1;i<n;i++)
#define erep1(i,n) for(int i = 1;i<=n;i++)
typedef long long ll;
#define int long long
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstring vector<string>
#define vdouble vector<double>
#define vll vector<ll>:
#define vbool vector<bool>
#define INF 100000000000000009
#define MOD 1000000007
using P = pair<int,int>;
signed main(){
  int n;
  cin >> n;
  vector<P> road(n);
  rep(i,n){
    int a,b;
    cin >> a >> b;
    road[i].first = a+b;
    road[i].second = a-b;
  }
  sort(road.begin(),road.end());
  int cur = -INF;
  int ans = 0;
  //rep(i,n) cout << road[i][0] << " " << road[i][1] << endl;
  rep(i,n){
    if(cur <= road[i].second){
      ans++;
      cur = road[i].first;
    }
  }
  cout << ans << endl;
}


      
    
  
  
  
  
  
  



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

using ll = long long;

const int INF = 1001001001;
const ll INF_LL = 1001001001001001001LL;

int main(void){
  string s; cin >> s;

  int find_A,find_Z_last;  
  rep(i,s.size())
    if(s[i] == 'A'){      
      find_A = i;
      break;
    }  
  for(int i = s.size()-1;i>=0;--i)
    if(s[i] == 'Z'){
      find_Z_last = i;
      break;
    }

  int ans = find_Z_last-find_A+1;
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 3756
import sys

readline = sys.stdin.readline

def main():
    while True:
        n, k = map(int, readline().split())
        if n == 0 and k == 0:
            return
        a = []
        for _ in range(n):
            a.append(int(readline()))

        base = sum(a[:k])
        subsum = [base]
        for i in range(k,n):
            base += a[i]
            base -= a[i-k]
            subsum.append(base)

        print(max(subsum))


if __name__ == "__main__":
    main()



Measured memory_bytes: 11700
#include<iostream>

using namespace std;

main(){
  int a,b;
  cin>> a>>b;
  if(a==1) a +=100;
  if(b ==1) b+=100;
  if(a == b) cout<<"Draw"<<endl;
  else if (a>b) cout<<"Alice"<<endl;
  else cout<<"Bob"<<endl;
  return 0;
}

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

int main() {
    int N;
    cin >> N;
    vector<int> a(N);
    rep(i, N) {
        cin >> a.at(i);
    }

    vector<int> pressNum(N, 0);  // index -> ボタン番号; value -> 押した回数

    int count = 0;
    int current = 0;
    rep(i, N) {
        if (current == 1) break;          // ボタン2の時に終了(0-index)
        int nextNum = a.at(current) - 1;  // 次のボタン位置(0-index)
        current = nextNum;
        count++;
    }

    int ans = (count == N) ? -1 : count;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1024
long n,k;long fun(long n, long x){if(n==0)return(x<=0?0:1);long p=(1LL<<n)-1;if(x<=2*p)return fun(n-1,x-1);return p+1+fun(n-1,x-1-2*p);}
main(){scanf("%ld%ld",&n,&k);printf("%ld\n",fun(n,k));}

Measured memory_bytes: 128
#include<cstdio>
#include<iostream>
#include<cstring>
#define MN 100005
using namespace std;
char s[MN],t[MN];
int sa[MN],sb[MN],la,lb;
bool check(int x,int y){
    if(x>y) swap(x,y);
    return (y-x)%3;
}
int main()
{
    scanf("%s",s+1);
    scanf("%s",t+1);
    la=strlen(s+1); lb=strlen(t+1);
    for(int i=1;i<=la;i++)
        if(s[i]=='A') sa[i]=sa[i-1]+2;
        else sa[i]=sa[i-1]+1;
    for(int i=1;i<=lb;i++)
        if(t[i]=='A') sb[i]=sb[i-1]+2;
        else sb[i]=sb[i-1]+1;
    int T; scanf("%d",&T);
    while(T--){
        int xa,xb,ya,yb;
        scanf("%d%d%d%d",&xa,&xb,&ya,&yb);
        if(!check(sa[xb]-sa[xa-1],sb[yb]-sb[ya-1])) puts("YES");
        else puts("NO");
    }
    return 0;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
const LL INF = 0x3f3f3f3f3f3f3f3fLL;
int solve(int i, auto &arr, auto &dp) {
    if (~dp[i]) return dp[i];
    int minV = 1;
    for (auto &v : arr)
        if (i - v >= 0)
            minV = min(minV, solve(i - v, arr, dp));
    return dp[i] = !minV;
}
void marmot0814() {
    int n, k; cin >> n >> k;
    vector<int> arr(n);
    for (auto &v : arr)
        cin >> v;
    vector<int> dp(k + 1, -1); dp[0] = 0;
    if (solve(k, arr, dp))
        cout << "First\n";
    else
        cout << "Second\n";
}
int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int t = 1, kase = 0; // cin >> t;
    while (t--) {
        // cout << "Case #" << ++kase << ":";
        marmot0814();
    }
}

Measured memory_bytes: 11396
#include <bits/stdc++.h>
using namespace std;
long long ceil1(long long a,long long b)
{
	if(a % b == 0)
		return a / b;
	else
		return a / b + 1;
}
 
void solve(int n)
{
	long long a = 1, b = 1;
	for(long long i = 0; i < n; i++)
	{
		long long x , y;
		cin >> x >> y;
		long long temp = max (ceil1(a,x),ceil1(b,y));
		a = temp * x;
		b = temp * y;
	}
	cout << a+b;
	return;
}
int main() {
	int n;
	cin >> n;
	solve(n);
}

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

#define ln                '\n'
#define all(dat)           dat.begin(), dat.end()
#define loop(i, to)        for (int i = 0; i < to; ++i)
#define cont(i, to)        for (int i = 1; i <= to; ++i)
#define circ(i, fm, to)    for (int i = fm; i <= to; ++i)
#define foreach(i, dat)    for (__typeof(dat.begin()) i = dat.begin(); i != dat.end(); ++i)

typedef long long          num;

using namespace std;

template<int mod>
struct modulo {
	int w;
	operator int&() { return w; }
	
	modulo() {}
	modulo(int w) { this->w = w; fix(); }
	void inline fix() { w %= mod; if (w < 0) w += mod; }
	modulo inline fix(int w) const { w %= mod; if (w < 0) w += mod; return w; }
	
	modulo inline operator + (modulo b) { modulo r = *this; r += b; return r; }
	modulo& operator += (modulo b) { if ((w += b.w) >= mod) w -= mod; return *this; }
	modulo inline operator - (modulo b) { modulo r = *this; r -= b; return r; }
	modulo& operator -= (modulo b) { if ((w -= b.w) < 0) w -= mod; return *this; }
	modulo inline operator * (modulo b) { modulo r = *this; r *= b; return r; }
	modulo& operator *= (modulo b) { w = (num) w * b.w % mod; return *this; }
	modulo inline operator / (modulo b) { modulo r = *this; r /= b; return r; }
	modulo& operator /= (modulo b) { w = (num) w * b.inv() % mod; return *this; }
	
	modulo inline inv() const {
		int a = w, m = mod, u = 0, v = 1, t;
		for (; a != 0; t = m / a, m -= t * a, swap(a, m), u -= t * v, swap(u, v));
		return fix(u);
	}
	
	modulo inline pow(int p) const {
		if (!w)  return 0;
		modulo a = *this, r = 1;
		for (; p > 0; a *= a, p >>= 1) if (p & 1) r *= a;
		return r;
	}
};
typedef modulo<998244353> rem;

const int nsz = int(2e5);
rem n, m, k, fac[nsz + 5], ifc[nsz + 5], ans;

void inline init() {
	fac[0] = ifc[0] = 1;
	cont (i, n) {
		fac[i] = fac[i - 1] * rem(i);
		ifc[i] = fac[i].inv();
	}
}

rem inline C(int n, int m) { return fac[n] * ifc[m] * ifc[n - m]; }

rem inline f(int n, int k) { return C(n - 1, k) * m * (m - rem(1)).pow(n - k - 1); }

int main() {
	scanf("%d%d%d", &n, &m, &k);
	if (m == 1) {
		printf("%d\n", k == n - rem(1));
		return 0;
	}
	init();
	circ (i, 0, int(k)) {
		ans += f(n, i);
	}
	printf("%d\n", ans);
}


Measured memory_bytes: 5388
#include<cstdio>
#include<cctype>

int main(){
    char ch;
    
    while(1){
        scanf("%c", &ch);
        if ( isalpha(ch) ){
            if ( islower(ch) ) printf("%c", toupper(ch));
            else printf("%c", tolower(ch));
        } else printf("%c", ch);
        
        if ( ch == '\n' ) break;
    }
    
    return 0;
}


Measured memory_bytes: 2692
//! 尺卂乃卂.卂ﾌ乇乇ㄒ
#include<bits/stdc++.h>
//#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
//Using namespace __gnu_pbds;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> Ordered_set;

#define ll              long long
#define int             long long
#define ld             long double
#define pb              push_back
#define pii             pair<int,int>
#define vi              vector<int>
#define vii             vector<vi>
#define vip            vector<pii>
#define mii             map<int,int>
#define mip             map<pair<int,int>,int>
#define mic             map<char,int> 
#define all(v)          v.begin(),v.end()  
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define lb(x)           (x&(-x))
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define w(x)            int x; cin>>x; while(x--)
#define itr(it,v)          for(auto it:v)
#define show(arr,n)     for(int i=0;i<n;i++) cout<<arr[i]<<" "; cout<<"\n";
#define fi(i,n)         for(int i=0;i<n;i++)
#define fir(i,k,n)       for(int i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ff               first 
#define ss               second
#define deb(x) cout << #x << "=" << x << endl
#define FIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define check(x) (x && cout<<"Yes\n")||(cout<<"No\n");
#define fin(s)          freopen(s,"r",stdin);  
#define fout(s)         freopen(s,"w",stdout);

const ld pi = 3.141592653589793238462643383279502884;
const int xd[]={-1,0,1,0};
const int yd[]={0,-1,0,1};
int XX[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
int YY[] = { -1, 0,  1, -1, 1, -1, 0, 1 };

int expo(int a,int b,int m);
int mmi(int a,int m);
void ipgraph(int m);

const int N=5*(1e5)+10;
vii adj(N);
int a[N];

void  solve(){

}
int32_t main()
{
    FIO
    int l,r,x; cin>>l>>r>>x;
  	int c=x;
  int p=0;
  while(c<=r){
    if(c>=l) p++;
  	c+=x;
  }
  cout<<p<<"\n";
    return 0;

}

void ipgraph(int m){
    int i, u, v;
    while(m--){
          cin>>u>>v;
         u--, v--;
    adj[u].pb(v);
    adj[v].pb(u);
    }
}
int expo(int a,int b,int m){
    if(b==0) return 1;
    if(b==1) return a;
    int val=(expo(a,b/2,m)*expo(a,b/2,m))%m;
    if(b & 1) return (val*a)%m;
    else return val;
}
int mmi(int a,int m){
    return expo(a,m-2,m);
}

Measured memory_bytes: 15052
#include <iostream>
#include <vector>

using namespace std;
int main(void){
  int n;
  int d[10][7] = {
    {1,1,1,1,1,1,0}, // 0
    {0,1,1,0,0,0,0}, // 1
    {1,1,0,1,1,0,1}, // 2 
    {1,1,1,1,0,0,1}, // 3
    {0,1,1,0,0,1,1}, // 4
    {1,0,1,1,0,1,1}, // 5
    {1,0,1,1,1,1,1}, // 6
    {1,1,1,0,0,1,0}, // 7
    {1,1,1,1,1,1,1}, // 8
    {1,1,1,1,0,1,1}  // 9
  };
  while(cin>>n,n>=0){
    int l[7] = {0};
    while(n--){
      int num;
      cin>>num;
      for(int i = 6 ; i >= 0 ; i --){
	cout<<(l[i]==d[num][i]?0:1);
	l[i]=d[num][i];
      }
      cout<<endl;
    }
  }
}

Measured memory_bytes: 1160
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
typedef long long int ll;
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) for (unsigned int i=0;i<(n);i++)
#define EREP(i,n) for (int i=1;i<=(n);i++)
#define ALL(a) (a).begin(),(a).end()
//#define EVEL 1

#ifdef EVEL
#define DEB(X) cout << #X << ":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const int MOD =  1000000007 ;
const int INF = 2000000000;

    int A,B,C;
    // (X)=G*2-R
int main(){
    cin>>A>>B;
    C=A-B;

    cout<<(C<0?0:C);
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
 
int main(){
    string p, s;
    cin >> p >> s;     // p:ring, s:string for search
    p = p + p;
    bool flag = false;
    for(int i=0; i<p.size()-s.size(); i++){
        string t = p.substr(i, s.size());
        if(t==s){
            flag = true;
            break;
        }
    }
    if(flag) cout<<"Yes"<<endl;
    else     cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 3216
use std::io::BufRead;
fn main() {
    let stdin = std::io::stdin();
    let mut lock = stdin.lock();
    let mut abc = String::new();
    let _ = lock.read_line(&mut abc);
    let abc = abc
        .trim()
        .split_whitespace()
        .map(|n| n.parse::<u32>().unwrap())
        .collect::<Vec<_>>();
    println!(
        "{}",
        if solve(abc[0], abc[1], abc[2]) {
            "YES"
        } else {
            "NO"
        }
    );
}

fn solve(a: u32, b: u32, c: u32) -> bool {
    let mut history: Vec<bool> = Vec::with_capacity(b as usize);
    let mut current = a % b;
    for _ in 0..b as usize {
        history.push(false);
    }
    loop {
        if current == c {
            return true;
        }
        if history[current as usize] {
            return false;
        } else {
            history[current as usize] = true;
            current = (current + a) % b;
        }
    }
}


Measured memory_bytes: 4352
#include <iostream>

using namespace std;

int main() {
    int n;
    cin >> n;
    int F[n + 1];

    F[0] = F[1] = 1;
    for (int i = 2; i <= n; i++) {
        F[i] = F[i - 1] + F[i - 2];
    }
    cout << F[n] << endl;
    return 0;
}


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

int main(){
   ll n,k;cin>>n>>k;
   ll ans=0;
   while(n){ans++;n/=k;}
   cout<<ans;
}

Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;

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

long long int lcm(long long int a, long long int b){
	return a * b / gcd(a,b);
}

int main(){
	int a[3], m[3], p[3] = {1,1,1}, c[3] = {0};
	while(1){
		memset(c,0,sizeof(c));
		cin >> a[0] >> m[0] >> a[1] >> m[1] >> a[2] >> m[2];
		if(!a[0])break;
		for(int i=0;i<3;i++){
			do{
			p[i] = a[i] * p[i] % m[i];
			c[i] += 1;
			}while(p[i] != 1);
		}
		cout << lcm(lcm(c[0],c[1]),c[2]) << endl;
	}
	return 0;
}

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

int main() {
  ios::sync_with_stdio(0); cin.tie(0);
  int x[5];
  for(int i = 0; i < 5; ++i) {
    cin >> x[i];
    if(x[i] == 0) {
      cout << i + 1 << '\n';
      return 0;
    }
  }
}

Measured memory_bytes: 3608
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
#define INF 2147483647
#define LINF 9223372036854775807
#define MOD 1000000007
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
//typedef long long int ll;
 

signed main(){
   
   string s;
   cin>>s;
   int sco=0,tco=0;
   int ans=s.size();
   for(int i=0;i<s.size();i++){
       if(s[i]=='S'){
           sco++;
       }
       else{
           tco++;
           if(i+1==s.size() || s[i+1]=='S' || tco==sco){
               ans-=min(sco,tco)*2;
               if(s[i+1]=='S'){
                   sco-=tco;
                   tco=0;
               }
               if(tco==sco || sco<0){
                   sco=0;
                   tco=0;
               }
           }
       }
   }
   cout<<ans<<endl;
   
}

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

using ll = long long;

const ll INF = 1LL << 62;

void chmax(ll& a, ll b) {
	a = max(a, b);
}

int main() {
	ll n, k;
	cin >> n >> k;
	vector<int> p(n);
	vector<ll> c(n);

	for (int i = 0; i < n; i++) {
		cin >> p[i];
		p[i]--;
	}
	for (int i = 0; i < n; i++) {
		cin >> c[i];
	}



	ll ans = -INF;


	for (int i = 0; i < n; i++) {
		int pos = i;
		int loop_cnt = 0;
		ll loop_sum = 0;

		vector<ll> sums(5005, -INF);

		while (1) {
			pos = p[pos];
			loop_cnt++;
			loop_sum += c[pos];
			sums[loop_cnt] = loop_sum;
			if (pos == i || loop_cnt == k) {
				break;
			}
		}

		chmax(ans, *max_element(sums.begin(), sums.end()));
		
		if (k <= loop_cnt || sums[loop_cnt] <= 0) {
			continue;
		}
		else {
			chmax(ans, k / loop_cnt * sums[loop_cnt] + *max_element(sums.begin(), sums.begin() + (k % loop_cnt + 1)));
            chmax(ans, (k / loop_cnt - 1) * sums[loop_cnt] + *max_element(sums.begin(), sums.end()));
		}
	}

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

Measured memory_bytes: 3704
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using VI = vector<int>;
using VVI = vector<VI>;

int n, m;
VVI G(710, VI(710, 1));
VI col(710, 0);

bool dfs(int v, int c) {
  col[v] = c;
  for (int i = 0; i < n; i++) {
    if (not G[v][i]) continue;
    if (col[i] == c) return false;
    if (col[i] == 0 and not dfs(i, -c)) return false;
  }
  return true;
}

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    G[i][i] = 0;
  }
  for (int i = 0; i < m; i++) {
    int a, b; cin >> a >> b;
    a--; b--;
    G[a][b] = G[b][a] = 0;
  }

  int c = 1;
  for (int i = 0; i < n; i++) {
    if (col[i] == 0) {
      if (not dfs(i, c)) {
        cout << -1 << '\n';
        return 0;
      }
      c++;
    }
  }

  VI a;
  for (int i = 1; i < c; i++) {
    int t = 0;
    for (int j = 0; j < n; j++) {
      t += col[j] == i;
      t -= col[j] == -i;
    }
    a.push_back(abs(t));
  }

  int an = a.size();
  vector< vector<bool> > dp(an + 1, vector<bool>(2 * n + 10));
  dp[0][n + 5] = true;
  for (int i = 0; i < an; i++) {
    for (int j = 0; j < 2 * n + 10; j++) {
      if (not dp[i][j]) continue;
      if (j + a[i] < 2 * n + 10) {
        dp[i + 1][j + a[i]] = true;
      }
      if (j - a[i] >= 0) {
        dp[i + 1][j - a[i]] = true;
      }
    }
  }

  int mind;
  for (int i = 0; i < n + 1; i++) {
    if (dp[an][n + 5 + i] or dp[an][n + 5 - i]) {
      mind = i;
      break;
    }
  }

  int x = (n + mind) / 2, y = (n - mind) / 2;
  int res = x * (x - 1) / 2 + y * (y - 1) / 2;
  cout << res << '\n';
  return 0;
}

Measured memory_bytes: 2432
#include <stdio.h>
int main()
{
  int n,m;
  scanf("%d %d",&n,&m);
  int sum =0;
  int x;
  for(int i=0;i<m;i++)
  {
    scanf("%d",&x);
    sum+=x;
  }
  if(n-sum>=0) printf("%d\n",n-sum);
	else printf("-1\n");
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

#define DEBUG(x) cout<<#x<<": "<<x<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

#define CHMIN(a, b) a=min((a), (b))
#define CHMAX(a, b) a=max((a), (b))

const ll MOD=1000000007ll;
// const ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

ll sum[1333];
bool abit[1252525][43], sum_bit[43];

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, k;
	ll a[1333];
	cin>>n>>k;
	REP(i, n){
		cin>>a[i];
		sum[i+1]=sum[i]+a[i];
	}
	int cnt=0;
	REP(i, n-1){
		FOR(j, i+1, n){
			ll tmp=sum[j+1]-sum[i];
			int ind=42;
			while(tmp>0){
				abit[cnt][ind]=tmp&1;
				tmp/=2;
				--ind;
			}
			++cnt;
		}
	}
	vi x;
	REP(i, cnt){
		x.push_back(i);
	}
	REP(i, 43){
		int cnt2=0;
		vi y;
		for(auto &xx : x){
			if(abit[xx][i]){
				++cnt2;
				y.push_back(xx);
			}
		}
		if(cnt2>=k){
			sum_bit[i]=true;
			x.erase(ALL(x));
			for(auto &yy : y){
				x.push_back(yy);
			}
		}
	}
	ll ans=0;
	REP(i, 43){
		ans*=2;
		if(sum_bit[i]){
			++ans;
		}
	}
	cout<<ans<<'\n';
	return 0;
}


Measured memory_bytes: 25712
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>
#include <bitset>
#include <cstdint>

using namespace std;
using lli = long long int;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

i64 m, k;
int main() {
  cin >> m >> k;

  if (m == 1 && k == 0) { cout << "0 0 1 1\n"; return 0; }

  i64 x = 1ll << m;

  if (x <= k) { cout << -1 << '\n'; return 0; }

  i64 y = 0;
  for (i64 i = 0; i < x; ++i) if (i != k) y ^= i;

  if (y != k) { cout << -1 << '\n'; return 0; }

  for (i64 i = 0; i < x; ++i) if (i != k) cout << i << ' ';
  cout << k << ' ';
  for (i64 i = x - 1; i >= 0; --i) if (i != k) cout << i << ' ';
  cout << k << '\n';
  return 0;
}


Measured memory_bytes: 1792
/*
    Problem 92
    https://onlinejudge.u-aizu.ac.jp/problems/1193
*/
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
int H;
int W = 5;
vector<vector<int>> pazzle(MAX, vector<int>(W));
/* function */
void init() {
    for (int i = 0; i < MAX; i++) for (int j = 0; j < W; j++)
        pazzle[i][j] = 0;
}
void input() {
    for (int i = 0; i < H; i++) for (int j = 0; j < W; j++)
        cin >> pazzle[i][j];
}
int deleteStone() {
    int ret = 0;
    for (int h = 0; h < H; h++) {
        for (int l = 0; l < W;) {
            int r = l + 1;
            for (; r < W && pazzle[h][l] == pazzle[h][r]; r++);
            if (r - l >= 3) {
                ret += pazzle[h][l] * (r - l);
                for (; l < r; l++) pazzle[h][l] = 0;
            }
            l = r;
        }
    }
    return ret;
}
void moveStone() {
    for (int w = 0; w < W; w++) {
        vector<int> tmp(H, 0);
        int len = 0;
        for (int h = H-1; h >= 0; h--)
            if (pazzle[h][w] != 0) tmp[len++] = pazzle[h][w];
        for (int h = H-1; h >= 0; h--)
            pazzle[h][w] = tmp[H-1-h];
    }
}
void solve() {
    init();
    input();
    int totalScore = 0;
    while (1) {
        int score = deleteStone();
        if (score == 0) break;
        totalScore += score;
        moveStone();
    }
    cout << totalScore << '\n';
}
/* main */
int main(){
    while (1) {
        cin >> H;
        if (H == 0) return 0;
        solve();
    }
}


Measured memory_bytes: 3136
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  int w,h,n;
  cin >> w >> h >> n;
  int x,y,a;
  int x0 = 0;
  int y0 = 0;
  REP(i,n){
    cin >> x >> y >> a;
    if(a==1) x0 = max(x0,x);
    if(a==2) w = min(w,x);
    if(a==3) y0 = max(y0,y);
    if(a==4) h = min(h,y);
  }
  cout << max(0,w-x0)*max(0,h-y0) << endl;
  
}

Measured memory_bytes: 256
class UnionFind:
    def __init__(self, n):
        self.n = n
        # 最初はすべての根が自分自身である
        self.parent = [-1 for i in range(n)]

    def root(self, x):
        if self.parent[x] < 0:
            return x
        self.parent[x] = self.root(self.parent[x])
        return self.parent[x]

    def size(self, x):
        return -self.parent[self.root(x)]

    def connect(self, x, y):
        x = self.root(x)
        y = self.root(y)
        if x == y:
            return
        if self.size(x) < self.size(y):
            x, y = y, x
        self.parent[x] += self.parent[y]
        self.parent[y] = x

N, M = map(int,input().split())
AB = []
ans = [0 for i in range(M+1)]
for i in range(M):
    AB.append(list(map(int,input().split())))

uni = UnionFind(N)
ans[M] = N * (N - 1) // 2
for i in range(M-1, 0, -1):
    a,b = AB[i]
    a-=1
    b-=1
    if uni.root(a) == uni.root(b):
        ans[i] = ans[i+1]
    else:
        ans[i] = ans[i+1] - uni.size(a) * uni.size(b)
        uni.connect(a,b)

for i in range(1,M+1):
    print(ans[i])


Measured memory_bytes: 109292
n = int(input())
a = list(map(int, input().split()))
ans = 0
b = []

while True:
    b[:] = map(lambda i: i%2, a)
    if sum(b) == 0:
        ans += 1
        a[:] = map(lambda i: i//2, a)
    else:
        break
print(ans)

Measured memory_bytes: 9168
# -*- coding: utf-8 -*-
s = list(input())

tmp = []
ans = 0
for i in range(len(s)):
    if len(tmp) > 0 and tmp[-1] == '0' and s[i] == '1':
        tmp.pop()
        ans += 2
    elif len(tmp) > 0 and tmp[-1] == '1' and s[i] == '0':
        tmp.pop()
        ans += 2
    else:
        tmp.append(s[i])
print(ans)


Measured memory_bytes: 4652
# coding: utf-8
H,N=map(int,input().split())
AB=[[0,0]]
for i in range(N):
    AB.append(list(map(int,input().split())))

INF=10**9

dp=[[INF for i in range(H+1)] for j in range(N+1)]

for i in range(N+1):
    dp[i][0]=0


for i in range(1,N+1):
    for j in range(1,H+1):
        dp[i][j]=min(dp[i-1][j],dp[i][max(j-AB[i][0],0)] + AB[i][1])
        #print(dp[i-1][j],dp[i-1][max(j-AB[i][0],0)] + AB[i][1],dp[i][max(j-AB[i][0],0)] + AB[i][1])
        


print(dp[N][H])


Measured memory_bytes: 125404
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

const int N = 1e6 + 5;

int n, m;
int a[N];

int32_t main()
{
	IOS;
	cin >> n >> m;
	int sum = 0;
	for(int i = 1; i <= m; i++)
	{
		int x;
		cin >> x;
		sum += x;
		if(sum > n)
		{
			cout << -1;
			return 0;
		}
	}
	cout << n - sum;
	return 0;
}

Measured memory_bytes: 3616
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ARC076
{
    public class C
    {
        private const long Mod = 1000000000 + 7;
        private long Factorial(int x)
        {
            long result = 1;
            while (x > 0)
            {
                result *= x;
                result %= Mod;
                x--;
            }
            return result;
        }
        private void Run()
        {
            var input = Console.ReadLine().Trim().Split();
            var N = int.Parse(input[0]);
            var M = int.Parse(input[1]);

            long result;
            var max = Math.Max(N, M);
            var min = Math.Min(N, M);
            if (min + 1 == max)
            {
                result = (Factorial(M) * Factorial(N) % Mod);
            }
            else if (min == max)
            {
                result = (Factorial(M) * Factorial(N) * 2 % Mod);
            }
            else { result = 0; }
            Console.WriteLine(result);
        }

        public static void Main()
        {
            var old = Console.Out;
            using (var writer = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false })
            {
                Console.SetOut(writer);
                new C().Run();
                Console.Out.Flush();
                Console.SetOut(old);
            }
        }
    }
}


Measured memory_bytes: 11092
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int X = sc.nextInt();
		int ans = 1;
		for(int b=2;b<X;b++) {
			for(int p=2;(int)Math.pow(b,p)<=X;p++) {
				if(ans <= Math.pow(b,p)) {
					ans = (int) Math.pow(b,p);
				}
			}
		}
		System.out.println(ans);
	}

}

Measured memory_bytes: 23252
#include <iostream>
using namespace std;
int main(void){
    int t,n;
    for(int i=0;i<4;i++){
        cin >>t>>n;
        if(t==1){
            cout <<6000*n<<endl;
        }
        else if(t==2){
            cout <<4000*n<<endl;
        }
        else if(t==3){
            cout <<3000*n<<endl;
        }
        else if(t==4){
            cout <<2000*n<<endl;
        }
    }
}


Measured memory_bytes: 3088
#include<stdio.h>
#include<math.h>
const int e[40]={0,1,1,2,2,2,3,3,3,3,4,4,4,4,4,5,5,5,5,5,
                 5,6,6,6,6,6,6,6,7,7,7,7,7,7,7,7,8,8,8,8};
int main(void)
{
  int i,x;
  long long a=0,N;
  x=scanf("%lld",&N)-1;
  while(N%2==0){x++;N/=2;}
  a+=e[x];
  for(i=3;i<=(int)sqrt(N);i+=2)
  {
    x=0;while(!(N%i))x++,N/=i;
    a+=e[x];
  }
  if(N>1)a++;
  return printf("%lld\n",a),0;
}

Measured memory_bytes: 2152
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,a,b) for(int i=(a);i<(b);++i)

template<class T> inline void chmin(T& a, T b) {if (a > b) a = b;}
template<class T> inline void chmax(T& a, T b) {if (a < b) a = b;}

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  rep(i,N) cin >> a[i];
  cout << N+N-2 << endl;
  if (*max_element(a.begin(),a.end()) >= abs(*min_element(a.begin(),a.end()))) {
    auto ix = max_element(a.begin(),a.end());
    rep(i,N){if (ix-a.begin()+1!=i+1)
      cout << ix-a.begin()+1 << ' ' << i+1 << endl;
    }
    rep2(i,1,N) {
      cout << i << ' ' << i+1 << endl;
    }
  }
  else {
    auto ix = min_element(a.begin(),a.end());
    rep(i,N){if (ix-a.begin()+1!=i+1)
      cout << ix-a.begin()+1 << ' ' << i+1 << endl;
    }
    for (int i=N;i>1;i--) {
      cout << i << ' ' << i-1 << endl;
    }
  }

} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define RST(i,n) memset(i,n,sizeof i)
#define sz(a) (int)a.size()
#define B_E(a) a.begin(),a.end()
#define pb push_back
#define pob pop_back
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);

const ll MaxN=1e5+5;
const ll MOD=1000000007;
const ll INF=ll(1e15);

int main(){
	IOS();
	ll a,b,c;
	cin>>a>>b>>c;
	if(a==b){
		cout<<c<<endl;
	}
	else if(b==c){
		cout<<a<<endl;
	}
	else{
		cout<<b<<endl;
	}
}

Measured memory_bytes: 256
from collections import Counter
h, w, n = map(int, input().split())
c = []
for k in range(n):
    i, j = map(lambda x: int(x) - 1,input().split())
    for l in range(3):
        for m in range(3):
            p = i - l
            o = j - m 
            if p < 0 or p > h - 3: continue
            if o < 0 or o > w - 3: continue
            c.append((p, o))

c = Counter(Counter(c).values())
print((h - 2) * (w - 2) - sum(c.values()))
for i in range(1, 10):
    print(c[i])

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

int main(){
  bool a=false,b=false,c=false,d=false;
  for(int i=0;i<4;i++){
    int A;
    cin >> A;
    if(A==1){
      a=true;
    }
    if(A==4){
      b=true;
    }
    if(A==7){
      c=true;
    }
    if(A==9){
      d=true;
    }
  }
  if(a && b && c && d){
    cout << "YES" << endl;
  }
  else{
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 3560
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

constexpr ll infl = 10000000000000007LL;
constexpr int inf = 1000000007;

int main() {
    string s;
    cin >> s;
    if (string(s.size(), s.front()) == s) {
        cout << 0 << endl;
    } else {
        int ans = inf;
        for (char c : s) {
            string t(s);
            for (int i = s.size() - 1; i >= 1; --i) {
                int len = 0;
                for (int j = 0; j < i; ++j) {
                    if (t[j] == c || t[j + 1] == c) {
                        t[j] = c;
                        ++len;
                    }
                }

                if (len == i) {
                    ans = min(ans, (int)s.size() - len);
                    break;
                }
            }
        }
        cout << ans << endl;
    }
    return 0;
}

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

namespace B
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var a = new int[n];
            for(int i=0;i<n;i++)
            {
                a[i] = int.Parse(Console.ReadLine())-1;
            }
            var ans = 0;
            var isLightUpable = false;
            var LightingNo = 0;

            while(!isLightUpable && ans <= n)
            {
                ans++;
                LightingNo = a[LightingNo];
                if(LightingNo == 1)
                {
                    isLightUpable = true;
                }
            }
            
            Console.WriteLine(isLightUpable? ans : -1);
        }
    }
}


Measured memory_bytes: 13280
#include <bits/stdc++.h>
#define rep(i,n) for(int64_t i=0;i < (int64_t)(n);i++)
#define invrep(i,n) for(int64_t i=n-1;i >= 0;i--)
#define _GLIBCXX_DEBUG
using namespace std;

//////全探索したいときに開けよ////////
vector<vector<int>> fspattern;
vector<int> fspattern_draft;
int fspcnt = 0;

void setfspattern_core(int floor,int number,int degree){
  if(floor==degree){
    fspattern.at(fspcnt) = fspattern_draft;
    fspcnt++;
  }else{
    rep(i,number){
      fspattern_draft.at(floor) = i;
      setfspattern_core(floor+1,number,degree);
    }
  }
}

void setfspattern(int number,int degree){
  fspcnt = 0;
  int64_t array_num = 1;
  rep(i,degree){
    array_num *= number;
  }
  fspattern = vector<vector<int>>(array_num,vector<int>(degree));
  fspattern_draft = vector<int>(degree);
  setfspattern_core(0,number,degree);
}

//////nCrのmodを求めたいときに開けよ/////////
//int64_t univMod = 1000000007;
//int64_t factnum = 100000
//vector<int64_t> modfact(factnum);
//vector<int64_t> modinvfact(factnum);

/*void setmodfact(){
  for(int i=0;i<factnum;i++){
    if(i == 0){
      modfact.at(i) = 1;
    }else{
      modfact.at(i) = (modfact.at(i-1)*i)%univMod;
    }
  }
}

int64_t calcmodpower(int64_t a,int64_t n){
  int64_t res = 1;
  while(n != 0){
    if(n & 1){
      res = (res * a) % univMod;
    }
    a = (a*a) % univMod;
    n = n >> 1;
  }
  return res;
}

int64_t calcinverse(int64_t n){
	return calcmodpower(n,univMod-2);
}

void setmodinvfact(){
  for(int i=0;i<factnum;i++){
    if(i==0){
      modinvfact.at(i) = 1;
    }else{
      modinvfact.at(i) = calcmodpower(modfact.at(i),univMod-2);
    }
  }
}*/


/*
int64_t calcGCD(int64_t a,int64_t b){
	int64_t p = a;
	int64_t q = b;
	int64_t c = a%b;
	while(c != 0){
		p = q;
		q = c;
		c = p%q;
	}
	return q;
}
*/
bool cmp(pair<int64_t,int64_t> a,pair<int64_t,int64_t> b){
  if(a.first != b.first){
    return a.first < b.first;
  }else{
    return a.second > b.second;
  }
}


int main(){
  int64_t n,m;
  cin >> n >> m;
  vector<pair<int64_t,int64_t>> p(n);
  rep(i,n){
    cin >> p[i].first >> p[i].second;
  }
  sort(p.begin(),p.end());
  int64_t wow = 0;
  priority_queue<int64_t> que;
  int64_t res = 0;
  for(int64_t d=1;d <= m;d++){
    while(wow < n && p[wow].first <= d){
      que.push(p[wow].second);
      wow++;
    }
    if(!que.empty()){
      res += que.top();
      que.pop();
    }
  }
  cout << res << endl;
}

Measured memory_bytes: 2936
open Printf
open Scanf
open BatPervasives

(*open Core*)


(*let map2 f a1 a2 = Array.of_list (List.map2 f (Array.to_list a1) (Array.to_list a2))*)

let count (s1, s2) =
  let count_array s =
    let toi x = int_of_char x - int_of_char 'a' in
    let a = BatArray.create (toi 'z' + 1) 0 in
    BatString.iter (fun x -> a.(toi x) <- 1) s;
    a in
  let a1 = count_array s1 in
  let a2 = count_array s2 in
  let b = BatArray.map2 (fun a b ->
      match (a, b) with
      | (1, 1) -> 1
      | _ -> 0
    ) a1 a2 in
  BatArray.fold_left (+) 0 b

let split_string s i length =
  let s1 = String.sub s 0 i in
  let s2 = String.sub s i (length - i) in
  (s1, s2)

let main =
  let (length, s) = scanf "%d\n%s" (fun a b -> (a, b)) in
  let rec iter i v =
    match i with
    | i when i = length -> v
    | i -> iter (i + 1) (max (count (split_string s i length)) v) in
  let init = count (split_string s 1 length) in
  printf "%d\n" (iter 2 init)




Measured memory_bytes: 768
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF (1<<30)
#define LINF (1LL<<60)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
typedef unsigned long long int ull;
typedef long long lint;
 
int main(void){
    int N;
    cin >> N;
    int A[N];
    rep(i,N) cin >> A[i];
    int ans=INF;
    for(int i=-100;i<=100;i++){
        int count=0;
        rep(j,N) count+=pow(A[j]-i,2);
        ans=min(ans,count);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
// エラストテネスの篩
const int NMAX = 1e+6+1;
int prime[NMAX];
void Sieve(){
  rep(i,NMAX) prime[i] = true;
  prime[0] = prime[1] = false;
  for(int i=2;i<NMAX;++i){
    if(prime[i]){
      int j = i*2;;
      while(j<=NMAX){
	prime[j] = false;
	j += i;
      }
    }
  }
}

int main()
{
 
  int n;cin >> n;
  Sieve();
  while(1){
    if(prime[n]){
      cout << n << "\n";
      break;
    }
    n++;
  }
  return 0;
}


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

struct UF {
    int n;
    vector<int> par;
    UF(int _n) : n(_n) {
        for(int i = 0; i < n; i++) par.push_back(i);
    }
    int find(int a){
        if(a != par[a]) par[a] = find(par[a]);
        return par[a];
    }
    bool join(int a, int b){
        a = find(a);
        b = find(b);
        par[a] = b;
        return (a != b);
    }
};


int main(){
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	string s;
	cin >> s;
	int n = (int)s.size();
	s = "a" + s + "a";
	vector<int> diffs(n+1);
	for(int i = 0; i <= n; i++){
		diffs[i] += (s[i+1] - 'a');
		diffs[i] -= (s[i] - 'a');
	}
	UF uf(n+1);
	for(int i = 0; i <= n; i++) uf.join(i, n-i);
	int x;
	cin >> x;
	for(int i = 0; i < x; i++){
		int l, r;
		cin >> l >> r;
		l--;
		uf.join(l, r);
	}
	vector<int> tot(n+1, 0);
	for(int i = 0; i <= n; i++) tot[uf.find(i)] += diffs[i];
	for(int i = 0; i <= n; i++){
		if(tot[i] % 26 != 0){
			cout << "NO" << '\n';
			return 0;
		}
	}
	cout << "YES" << '\n';
}

Measured memory_bytes: 1640
#include<stdio.h>
int MAX(int a,int b){return a<b?b:a;}
int main(){
  int n,a,b,c,e,f,g,i,m;
  while(scanf("%d",&n),n){
    int d[100010]={};
    while(n--){
      scanf("%d:%d:%d %d:%d:%d",&a,&b,&c,&e,&f,&g);
      d[a*3600+b*60+c]++;
      d[e*3600+f*60+g]--;
    }
    for(i=m=0;i<86420;i++)m=MAX(m,d[i+1]+=d[i]);
    printf("%d\n",m);
  }
  return 0;
}

Measured memory_bytes: 996
import java.util.*;
public class Main 
{
	public static void main(String[] args) 
	{
		Scanner stdIn = new Scanner(System.in);
		while(stdIn.hasNext())
		{
			int n = stdIn.nextInt();
			if(n == 0)
			{
				break;
			}
			int y = stdIn.nextInt();
			int ans = 0;
			double max = 0;
			while(n-- != 0)
			{
				int b = stdIn.nextInt();
				int r = stdIn.nextInt();
				int t = stdIn.nextInt();
				double sum = 1;
				if(t == 1)
				{
					sum = 1 + y * r / 100.0;
				}
				else
				{
					sum = Math.pow(1 + r / 100.0, y);
				}
				if(sum > max)
				{
					ans = b;
					max = sum;
				}
			}
			System.out.println(ans);
		}
	}
}

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

const vector<int> dx{1, 0, -1, 0};
const vector<int> dy{0, 1, 0, -1};

int main()
{

    int h, w;
    cin >> h >> w;
    vector<vector<char>> grid(h, vector<char>(w, '0'));
    int sharpcnt = 0;
    for (int i = 0; i < h; i++)
    {
        for(int j = 0; j < w; j++){
            cin >> grid[i][j];
            if(grid[i][j]=='#'){
                sharpcnt++;
            }
        }
    }

    //

    vector<vector<int>> dist(h, vector<int>(w, 1e9));
    dist[0][0] = 0;

    queue<pair<int, int>> que;
    que.push({0, 0});
    while(!que.empty()){
        pair<int, int> temp = que.front();
        que.pop();
        if(temp.first==h-1 && temp.second==w-1){
            break;
        }
        for(int i = 0; i < 4; i++){
            int ny = temp.first + dy[i];
            int nx = temp.second + dx[i];
            if(0<=nx && 0<=ny && nx<=w-1 && ny<=h-1 && grid[ny][nx]!='#' && dist[ny][nx]==1e9){
                que.push({ny, nx});
                dist[ny][nx] = dist[temp.first][temp.second] + 1;
            }
        }
    }
    if(dist[h - 1][w - 1]==1e9){
        cout << -1 << endl;
    }else{
        cout << h * w - sharpcnt - dist[h - 1][w - 1] - 1 << endl;
    }
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Arrays;
public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		while(scan.hasNext()){
			int n = scan.nextInt();
			int m = scan.nextInt();
			if(n == 0 && m == 0){
				break;
			}
			int sumA = 0;
			int[] cardA = new int[n];
			int[] cardB = new int[m];
			int sumB = 0;
			for(int i = 0;i < n;i++){
				cardA[i] = scan.nextInt();
				sumA += cardA[i];
			}
			for(int i = 0;i < m;i++){
				cardB[i] = scan.nextInt();
				sumB += cardB[i];
			}
			if((sumA+sumB)%2 != 0){
				System.out.println(-1);
				continue;
			}
			Arrays.sort(cardA);
			Arrays.sort(cardB);
			boolean fl = true;
			int sum = sumA - sumB;
			for(int i = 0;i < n;i++){
				for(int j = 0;j < m;j++){
					if(sum == 2*(cardA[i]-cardB[j])){
						fl = false;
						System.out.println(cardA[i] + " " + cardB[j]);
						break;
					}
				}
				if(!fl){
					break;
				}
			}
			if(fl){
				System.out.println(-1);
			}
		}
	}
}

Measured memory_bytes: 21044
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
const int mod=1e9+7;

void solve(){
	char a,b;
	cin>>a>>b;
	if(a=='H'){
		cout<<b;
	}
	else{
		cout<<((b=='H')?'D':'H');
	}
}

int main(){
int test=1;
// cin>>test;
while(test--){
	solve();
	cout<<endl;
}

return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
#define dbg(x) cerr << #x << ": " << x << endl
int main() {
  ll n, m;
  cin >> n >> m;
  vector<int> a(m), b(m);
  rep(i, m) {
    int na, nb;
    cin >> na >> nb;
    na--, nb--;
    a[i] = na;
    b[i] = nb;
  }
  vector<vector<int>> V(n);
  rep(j, n) V[j].push_back(j);
  vector<int> idx(n);
  rep(j, n) idx[j] = j;

  ll cnt =
    n * (n - 1) / 2;    // take care not to be overflow
  vector<ll> ans;
  ans.push_back(cnt);

  reverse(all(a));
  reverse(all(b));

  rep(i, m - 1) {
    int aj = idx[a[i]], bj = idx[b[i]];
    if(aj == bj) {
      ans.push_back(cnt);
      continue;
    }

    ll sza = (ll)V[aj].size(), szb = (ll)V[bj].size();
    cnt -= sza * szb;
    ans.push_back(cnt);

    if(sza < szb) swap(aj, bj);
    for(auto x : V[bj]) {
      V[aj].push_back(x);
      idx[x] = aj;
    }
    V[bj].clear();
  }

  reverse(all(ans));
  rep(i, m) printf("%lld\n", ans[i]);
  return 0;
}


Measured memory_bytes: 12916
n=range(input())
a=[map(int,raw_input().split()) for i in n]
s=[0]*len(n)
for i in [0,1,2]:
	for j in n:
		for k in n:
			if j!=k and a[j][i]==a[k][i]:break
		else:s[j]+=a[j][i]
for i in s:print i

Measured memory_bytes: 4224
#include <bits/stdc++.h>
using namespace std;
template < typename T > std::string to_string( const T& n ){
	std::ostringstream stm ;
	stm << n ;
	return stm.str() ;
}


int main(void){
	int n;
	cin >> n;
	int S[14];
	int H[14];
	int C[14];
	int D[14];
	for(int i = 1; i < 14; i++){
		S[i] = 0;
		H[i] = 0;
		C[i] = 0;
		D[i] = 0;
	}
	for(int i = 0; i < n; i++){
		string m;
		int t;
		cin >> m >> t;
		if(m =="S")S[t] = 1;
		if(m =="H")H[t] = 1;
		if(m =="C")C[t] = 1;
		if(m =="D")D[t] = 1;
	}
	for(int i = 1; i < 14; i++){
		if(S[i] == 0)cout << "S "+ to_string(i)+"\n";
	}
	for(int i = 1; i < 14; i++){
		if(H[i] == 0)cout << "H "+ to_string(i)+"\n";
	}
	for(int i = 1; i < 14; i++){
		if(C[i] == 0)cout << "C "+ to_string(i)+"\n";
	}
	for(int i = 1; i < 14; i++){
		if(D[i] == 0)cout << "D "+ to_string(i)+"\n";
	}
	return 0;
}


Measured memory_bytes: 3136
#include <stdio.h>
#include <string.h>
#include <ctype.h>

int main(void)
{
	char s[80];
	int i, len, a;
	
	gets(s);
	
	len = strlen(s);
	
	for(i = 0;i < len;i++){
		
		a = islower(s[i]);
		
		if(a != 0){
			s[i] = toupper(s[i]);
		}
	}
	printf("%s\n", s);
	
	return 0;
}

Measured memory_bytes: 524
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;
int main(void){
    // Here your code !
    
    int i = 0;
    string s;
    cin >> s;
    
    const string goal = "CODEFESTIVAL2016";
    
    cout << count_if(s.begin(),s.end(),[&](const char & c ){ return goal[i++] != c; }) << endl; 
    
    
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

int main() {
	int n, m, x;
	cin >> n >> m >> x;
	vector<int> a(m);
	rep(i, m) cin >> a[i];

	int cos_sum1 = 0;
	for (int pos = x; pos <= n; pos++) {
		rep(i, m)
			if (pos == a[i]) cos_sum1++;
	}

	int cos_sum2 = 0;
	for (int pos = x; pos >= 0; pos--) {
		rep(i, m)
			if (pos == a[i]) cos_sum2++;
	}

	int ans = min(cos_sum1, cos_sum2);
	cout << ans << endl;
	return 0;
}

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

#define max 6

//qsort(d, n, sizeof(int), up_comp);
int up_comp(const void *a, const void *b){return *(int*)a - *(int*)b;}
int down_comp(const void *a, const void *b){return *(int*)b - *(int*)a;}

int main()
{
    int i, j=0;
    char n[max];
    
   
    
    scanf("%s", n);
    

    if (n[2]==n[3]&&n[4]==n[5])
        printf("Yes");
    else
        printf("No");

    return 0;
}



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

using namespace std;


void _accepcted_by_one_hit_()
{
    #ifdef NTMA
        freopen("abc.inp", "r", stdin);
        freopen("abc.out", "w", stdout);
    #endif
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
}

int main()
{	
	_accepcted_by_one_hit_();
    string s; cin >> s;
    if (s == "AAA" || s == "BBB") cout << "No\n";
    else cout << "Yes";
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
const ll INF = 1LL<<60;
const ll MOD = 1e9+7;


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int m; cin>>m;
    ll csum = 0;
    ll dsum = 0;
    rep(i,m){
        ll d,c;cin>>d>>c;
        csum += c;
        dsum += d*c;
    }
    cout<<csum+(dsum-1)/9-1<<endl;
    return 0;
}

Measured memory_bytes: 256