akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <queue>
#include <string.h>
using namespace std;

int main() {
    int turn = 1;
    char S1[200],S2[200],S3[200];
    queue<int> A,B,C;
    scanf("%s", S1);
    for (int i=0;i<strlen(S1);i++) {
        A.push(S1[i]);
    }
    scanf("%s", S2);
    for (int i=0;i<strlen(S2);i++) {
        B.push(S2[i]);
    }
    scanf("%s", S3);
    for (int i=0;i<strlen(S3);i++) {
        C.push(S3[i]);
    }
    while (true) {
        // Alice's turn
        if (turn == 1) {
            //printf("Alice\n");
            if (A.empty()) {
                cout << "A\n";
                return 0;
            }
            if (A.front()=='b') {
                turn = 2;
            } else if (A.front()=='c') {
                turn = 3;
            }
            A.pop();
            
        } else if (turn == 2) {
            //printf("Bob\n");
            if (B.empty()) {
                cout << "B\n";
                return 0;
            }
            if (B.front()=='a') {
                turn = 1;
            } else if (B.front()=='c') {
                turn = 3;
            }
            B.pop();
            
        } else if (turn == 3) {
            //printf("Charlie\n");
            if (C.empty()) {
                cout << "C\n";
                return 0;
            }
            if (C.front()=='a') {
                turn = 1;
            } else if (C.front()=='b') {
                turn = 2;
            }
            C.pop();
            
        }
    }
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main(){
	
	char kata[19];
	
	scanf("%[^\n]", &kata);
	
	for(int i = 0; i < 19; i++){
		if(kata[i] == ','){
			printf(" ");
		}
		else{
			printf("%c", kata[i]);
		}
		
	}
	return 0;
}

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

int main() {
  while(1) {
    int H,W;
    cin >> H >> W;

    if(H == 0 && W == 0) break;
    for(int a = 0; a < W; a++) {
      printf("#");
    }
    printf("\n");

    for(int b=0+1;b<H-1; b++){
      printf("#");
      for(int c=0+1;c<W-1;c++){
          printf(".");
      }
      printf("#");
      printf("\n");
    }

    for(int d = 0; d < W; d++) {
      printf("#");
    }
    printf("\n");
    printf("\n");
  }

  return 0;
}

Measured memory_bytes: 3064
$num,$tracks = gets.split.map(&:to_i)
$ws = []
for i in 1..$num do
	w = gets.chomp.to_i
	$ws.push(w)
end

def check(p)
	i = 0
	for j in 1..$tracks do
		s = 0
		while s + $ws[i] <= p
			s = s + $ws[i]
			i = i + 1
			if i == $num then
				return $num
			end
		end
	end
	return i
end

def solve()
	left = 0
	right = 100000 * 10000
	while right - left > 1
		mid = (left + right) / 2
		v = check(mid)
		if v >= $num then
			right = mid
		else
			left = mid
		end
	end
	return right
end

ans = solve()
p ans

Measured memory_bytes: 9708
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 

typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
using namespace std;


int main(int argc, char* argv[])
{
    int a,p;
    scanf("%d%d", &a,&p);
    printf("%d\n", (a*3+p)/2);



    return 0;
}


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

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ll long long
#define ull unsigned long long
#define F first
#define S second
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif




int main(void) 
{
	string s; 
	cin >> s; 
	for (int i=0; i<s.size(); i++) 
		cout << "x"; 
	cout << '\n';





 
 
 
	return false;   
}













Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        long[] Hs = new long[N + 1];
        boolean[] t = new boolean[N + 1];
        for (int i = 1; i <= N; i++) {
            Hs[i] = sc.nextLong();
        }
        for (int i = 1; i <= M; i++) {
            int A = sc.nextInt();
            int B = sc.nextInt();
            long ha = Hs[A];
            long hb = Hs[B];
            if (ha < hb) {
                t[A] = true;
            } else if (hb < ha) {
                t[B] = true;
            } else {
                t[A] = true;
                t[B] = true;
            }
        }
        int count = 0;
        for (int i = 1; i <= N; i++) {
            count += t[i] ? 0 : 1;
        }

        System.out.println(count);
    }
}

Measured memory_bytes: 60324
#include <bits/stdc++.h>
using namespace std;
void fast()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
}
int main()
{
    fast();
    int v[]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int k;
    cin>>k;
    cout<<v[k-1];
    return 0;
}


Measured memory_bytes: 256
// Contest.cpp : コンソール アプリケーションのエントリ ポイントを定義します。
//

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <list>
#include <set>
#include <numeric>
#include <map>
#include <math.h>

using namespace std;

int dp[51][51][51];

int main()
{
	int ans=0;
	int a, b, c,x;
	cin >> a >> b >> c >> x;
	for (int i = 0; i <= a; i++) {
		for (int j = 0; j <= b; j++) {
			for (int k = 0; k <= c; k++) {
				if (i*500+j*100+k*50 == x)ans++;
			}
		}
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
using namespace std;
typedef pair<int, int> P;
const int INF = 1e9;

int dp[510], nxt[510];

int main(){
    int n, m;
    cin >> n >> m;
    vector<P> d(m);
    rep(i, 0, m){
        cin >> d[i].first >> d[i].second;
    }
    sort(d.begin(), d.end());
    rep(i, 0, m + 1) dp[i] = INF;
    dp[0] = 0;
    rep(i, 0, n + 1){
        rep(j, 0, m + 1) nxt[j] = dp[j] + 1;
        rep(j, 0, m){
            if(dp[j] >= INF) continue;
            int MIN = i + 1;
            rep(k, j, m){
                if(d[k].second > i + 1) break;
                MIN = min(MIN, d[k].first);
                int cost = dp[j] + 1 + (i + 1 - MIN) * 2;
                // cout << i << ' ' << j << ' ' << k << ' ' << dp[j] << ' ' << cost << endl;
                nxt[k + 1] = min(nxt[k + 1], cost);
            }
        }
        swap(dp, nxt);
    }
    cout << dp[m] << endl;
}   


Measured memory_bytes: 3132
#include<iostream>
using namespace std;
int GCD(int x, int y);
int main(){
  int a,b;
  while(cin >>a>>b){
    cout <<GCD(a,b)<<" "<<a/GCD(a,b)*b<<endl;
  }
  return 0;
}
int GCD(int x, int y){
  if(!y){return x;}
  return GCD(y,x%y);
}

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

int A[100];
int n;
int main () {
  while (cin >> n && n) {
    for (int i=3; i<n+1; ++i) {
      A[0] = 1;
      A[1] = 1;
      A[2] = 2;
      A[i] = A[i-1] + A[i-2] + A[i-3];
    }
    if (n == 1) {
      cout << 1 << endl;
    } else { cout << (((A[n-1] + A[n-2] + A[n-3])/3650) + 1) << endl;
    }
  }
}

Measured memory_bytes: 1164
#include <iostream>
#include <cstdio>
#include <cstdlib>

using namespace std;

int main(void) {

    int _5 = 2, _7 = 1;
    for (int i = 0, n; i < 3; ++i) {
        scanf("%d", &n);
        if (n == 5) { --_5; }
        else if (n ==  7) { --_7; }
    }

    if (_5 || _7)
        printf("NO\n");
    else
        printf("YES\n");

    return 0;
}

Measured memory_bytes: 256
//By Vlgd
#include<bits/stdc++.h>
using namespace std;
int A[100001];
int part(int p,int r){
	int x=A[r];
	int i=p-1;
	for(int j=p;j<r;j++)
		if (A[j]<=x) swap(A[++i],A[j]);
	swap(A[i+1],A[r]);
	return i+1;
}
main(){
	int n;
	scanf("%d",&n);
	for (int i=0;i<n;i++) scanf("%d",&A[i]);
	int p=part(0,n-1);
	for (int i=0;i<n;i++){
		if (i) printf(" ");
		if (i==p) printf("[");
		printf("%d",A[i]);
		if (i==p) printf("]");	
	}
	printf("\n");
}


Measured memory_bytes: 3520
while 1:
  s=input()
  N, K = map(int, s.split(' '))
  if N == 0 and K == 0:
    break
  a = []
  for _ in range(N):
    a.append(int(input()))
  s = [0]
  for i, n in enumerate(a):
    s.append(n + s[i])

  ans = 0
  for i, n in enumerate(s):
    if i - K >= 0:
      ans = max(ans, s[i] - s[i-K])
  print(ans)


Measured memory_bytes: 13316
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,i,a,count=0;
    bool f = true;
    vector<int> bb;
    cin >> n;
    for(i=0;i<n;i++){
        cin >> a;
        bb.push_back(a);
    }
    while(f){
        for(i=0;i<n;i++){
            if(bb[i] % 2 == 0){
                bb[i] /= 2;
            }else{
                f = false;
            }
        }
        if(f)count++;
    }
    
    cout << count << endl;
    
}


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

#define ll long long
int main () {
  ll n, q;
  cin >> n >> q;
  string s;
  cin >> s;
  ll l[q], r[q];
  for (ll i = 0; i < q; i++) {
    cin >> l[i] >> r[i];  
  }
  ll sum[n];
  for (ll i = 0; i < n; i++) {
    sum[i] = 0;  
  }
  for (ll i = 1; i < n; i++) {
    sum[i] = sum[i - 1];
    if (s[i] == 'C' && s[i - 1] == 'A') {
      sum[i]++;  
    }    
  }
  for (ll i = 0; i < q; i++) {
    cout << sum[r[i] - 1] - sum[l[i] - 1] << endl; 
  }
  
}

Measured memory_bytes: 3392
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n=I()
  s,t=LS()

  ans=''
  for i in range(n):
    ans+=s[i]
    ans+=t[i]

  return ans

# main()
print(main())


Measured memory_bytes: 7748
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define sayyes cout<<"Yes"<<endl;
#define sayno cout<<"No"<<endl;
using namespace std;
typedef long long ll;
const double PI=acos(-1);
typedef pair<int,int>P;
const int mod =1e9+7;

int main()
{
    int n;
    cin>>n;
    vector<int> a(n);
    rep(i,n)cin>>a[i];
    vector<int> c(n,0);
    rep(i,n)
    {
        c[a[i]]++;
    }
    ll ans=1;
    if(n%2==0)
    {
        for(int i=1;i<=n-1;i+=2)
        {
            if(c[i]%2!=0)
            {
                cout<<0;
                return 0;
            }
            ans=ans*c[i]%mod;
        }


    }
    else
    {
        if(c[0]!=1)
        {
            cout<<0;
            return 0;
        }
        for(int i=2;i<=n-1;i+=2)
        {
            if(c[i]%2!=0)
            {
                cout<<0;
                return 0;
            }
            ans=ans*c[i]%mod;
        }
        
    }
    
    cout<<ans;

}


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

using namespace std;

#define int long long
#define MP make_pair
#define F first
#define S second
#define pi pair<int,int> 
#define sz(s) ((int)s.size())
#define rep(i,a,b) for (int i = a; i <= (int)b; ++i)

const unsigned mod = 1e9 + 7;
const unsigned N = 5e5 + 4;

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

  int n, k;
  cin >> n >> k;
  int a[n];
  rep(i,0,n-1) cin >> a[i];
  sort(a, a+n);

  int sum = 0;
 	sum = accumulate(a, a+n, sum);
 	const int m = k;
  for (int i = n - 1; k--; --i) {
  	long double x = 1.0 * sum;
  	x /= 4 * m; 
  	if (x > a[i]) return cout << "No" << '\n',0;
  }
  cout << "Yes" << '\n';


  
  assert(numeric_limits<int>::max() >= 1e18);
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using namespace __gnu_cxx;
#define dprint(v) cout << #v"=" << v << endl //;)
#define sz(c) ((int)c.size())
#define zero(v) memset(v, 0, sizeof(v))
#define forall(it,v) for(auto it=v.begin();it!=v.end();++it)
#define mp make_pair
#define ff first
#define ss second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define INF (ll)1e16
#define endl '\n'
#define isin(x,y) ((y).find(x)!=(y).end())
#define forr(i,a,b) for(int i=(a); i<(b); i++)

typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<vll> vvll;

typedef pair<int,int> ii;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n,q;
        string s;
        cin>>n>>q>>s;
        vll po(n);
        forn(i,n-1)if(s[i]=='A'&&s[i+1]=='C')++po[i];
        vll ps(n);
        ps[0]=po[0];
        forn(i,n-1){
            ps[i+1]=ps[i]+po[i+1];
        }
        forn(i,q){
            ll l,r;
            cin>>l>>r;
            --r;--l;
            cout<<ps[r-1]-(l?ps[l-1]:0)<<endl;
        }
	return 0;
}


Measured memory_bytes: 2640
#include <bits/stdc++.h>
#define Maxn 507
#define inf 100007
using namespace std;
int n,p;
char s[Maxn];
int f[Maxn][30];
int main()
{
    scanf("%s",s+1);
    scanf("%d",&p);
    n=strlen(s+1);
    for (int i=n+1;i<=3*n;i++)
        s[i]=s[i-n];
    for (int i=1;i<=3*n;i++)
        for (int j=1;j<=26;j++)
            f[i][j]=inf;
    for (int i=1;i<=26;i++)
        f[1][i]=1;
    f[1][s[1]-'a'+1]=0;
    for (int i=2;i<=3*n;i++)
        for (int k=1;k<=26;k++)
        {
            int tmp=0;
            if (s[i]-'a'+1==k) tmp=0; else tmp=1;
            for (int t=1;t<=26;t++)
                if (k!=t) f[i][k]=min(f[i][k],f[i-1][t]+tmp);
        }
    int ans1=inf,ans2=inf,ans3=inf;
    for (int i=1;i<=26;i++)
    {
        ans1=min(ans1,f[n][i]);
        ans2=min(ans2,f[2*n][i]);
        ans3=min(ans3,f[3*n][i]);
    }
    long long ans=1LL*((p-1)/2)*(ans3-ans1);
    ans+=ans1;
    if (p%2==0) ans+=ans2-ans1;
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 3768
import java.io.*;
import java.util.*;


/**
 * AIZU ONLINE JUDGE
 * 1551
 *  2020/5/10
 */
public class Main {

    PrintStream log = new PrintStream(new OutputStream() { public void write(int b) {} } );
    PrintStream result = System.out;
    Scanner sc = new Scanner(System.in);

    void main() throws IOException {

        int N = sc.nextInt();
        int M = sc.nextInt();

        int[] w = new int[N];
        for(int i = 0; i < M; i++) {
            int a = sc.nextInt();
            int L = sc.nextInt();

            for(int j = 0; j < L; j++) {
                w[(a + j) % N] = 1;
            }
        }

        int[] t = new int[N + 1];
        int s = 0;
        int f = 0;
        int s0 = 0;
        int i;
        for(i = 0; i < N; i++) {
            if (f == 0 && w[i] == 1) {
                s = i;
                f = 1;
            }
            else if (f == 1 && w[i] == 0) {
                f = 0;
                if (s == 0) {
                    s0 = i;
                }
                else {
                    t[i - s]++;
                }
            }
        }
        if (f == 1) {
            t[i - s + s0]++;
        }
        else if (s0 != 0) {
            t[s0]++;
        }

        for(i = N; i > 0; i--) {
            if (t[i] > 0) {
                result.println(i + " " + t[i]);
            }
        }

    }

    public static void main(String[] args) throws IOException {
        new Main().main();
    }


}




Measured memory_bytes: 26572
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <iostream>
#include <string>
#include <tuple>
#include <set>
#include <map>
#include <unordered_map>
#include <complex>
#include <iomanip>
#include <cmath>
#include <tuple>
using namespace std;

int main() {
    string str;
    cin >> str;

    string former = str.substr(0, 2);
    string later = str.substr(2, 2);

    if ("01" <= former && former <= "12") {
        if (later >= "13" || later == "00") {
            cout << "MMYY" << endl;
            return 0;
        } else {
            cout << "AMBIGUOUS" << endl;
            return 0;
        }
    } else {
        if ("01" <= later && later <= "12") {
            cout << "YYMM" << endl;
            return 0;
        } else {
            cout << "NA" << endl;
        }
    }
}


Measured memory_bytes: 256
n, m = map(int, input().split())
h = list(map(int, input().split()))
g = [0] * n
for i in range(m):
    a, b = map(int, input().split())
    if g[a - 1] < h[b - 1]:
        g[a - 1] = h[b - 1]
    if g[b - 1] < h[a - 1]:
        g[b - 1] = h[a - 1]
cnt = 0
for i in range(n):
    if h[i] > g[i]:
        cnt += 1
print(cnt)

Measured memory_bytes: 20008
/* 
	Author: ankrypt
*/


#include <bits/stdc++.h>

using namespace std;

#define MOD 1000000007
#define ll long long int
#define u64 unsigned long long int

string S = "";
ll spaTab[100005][15];

int main() {
	cin >> S;
	int N = S.size();
	spaTab[0][0] = 1;
	for(int i = 0; i < S.size(); i++) {
		for(int j = 0; j < 10; j++) {
			int nxt = S[i] - '0';
	 		if(S[i] == '?') {
	 			nxt = j;
			}
			for(int k = 0; k < 13; k++) {
				int rem = (10 * k + nxt) % 13; 
				spaTab[i + 1][rem] += spaTab[i][k];
				spaTab[i + 1][rem] %= MOD; 
			}
			if(S[i] != '?') {
				break;
			}
		}
	}
	// for(int i = 0; i < N; i++) {
	// 	for(int j = 0; j < 13; j++) {
	// 		cout << spaTab[i][j] << " ";
	// 	}
	// 	cout << "\n";
	// }
	cout << spaTab[N][5];
	
	return 0;
}
/*
	Powered by Buggy Plugin
*/


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

int main(){
    string S;
    cin >> S;
    if(S=="SAT")cout << 1 << endl;
    if(S=="FRI")cout << 2 << endl;
    if(S=="THU")cout << 3 << endl;
    if(S=="WED")cout << 4 << endl;
    if(S=="TUE")cout << 5 << endl;
    if(S=="MON")cout << 6 << endl;
    if(S=="SUN")cout << 7 << endl;
    return 0;
}

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

int main() {
  int N;
  cin>>N;
  vector<int> vec;
  for(int i=0; i<N; i++){
    int a;
    cin>>a;
    vec.push_back(a);
  }
  int i=0;
  int b=1;
  for(; i<N; i++){
    b=vec.at(b-1);
    if(b==2)
      break;
  }
  if(b==2)
    cout<<i+1<<endl;
  else
    cout<<-1<<endl;
}

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

int main() {
  int n, a, b, ans = 0;

  cin >> n >> a >> b;

  for (int i = n; i > 0; i--) {
    int tmp = i, cnt = 0;
    while (tmp >= 10) {
      cnt += tmp % 10;
      tmp /= 10;
      if (cnt > b) break;
    }
    cnt += tmp;
    if (cnt >= a && cnt <= b) ans += i;
  }

  cout << ans;

  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
 
int main(void){
 
void Swap(long long int x[ ], long long int i,long long int j)
{
    long long int temp;
 
    temp = x[i];
    x[i] = x[j];
    x[j] = temp;
}
 
void QSort(long long int x[ ], long long int left, long long int right)
{
    long long int i, j;
    long long int pivot;
 
    i = left;                      
    j = right;                    
 
 pivot = x[(left + right) / 2]; 
 
    while (1) {                    
 
        while (x[i] < pivot)       
            i++;                   
 
        while (pivot < x[j])      
            j--;                  
        if (i >= j)               
            break;                 
 
        Swap(x, i, j);             
        i++;                    
        j--;
    }
 
 
    if (left < i - 1)            
        QSort(x, left, i - 1);   
    if (j + 1 <  right)         
        QSort(x, j + 1, right);  
}
 
long long int a,n,z[200001],p = 0,c = 0;
 
scanf("%ld",&n);
 
z[0] = 0;
for(long long int i = 0; i < n; i++){
scanf("%ld",&a);
z[i+1] = z[i] + a;
if(z[i+1] == 0) p++;
}
 
QSort(z,1,n);
for(long long int i = 1; i < n; i++){
c = 0;
for(long long int j = i+1; j < n+1; j++){
if(z[i] == z[j]) c++;
else break;
}
i += c;
p += c*(c+1)/2;
}
printf("%ld",p);
return 0;
}

Measured memory_bytes: 1792
///mAAria...
#include<bits/stdc++.h>
 
using namespace std;
 
#define int long long
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(v) v.begin(),v.end()
#define ld long double
#define ff first
#define ss second
#define pii pair<int,int>
#define pi 3.1415926535897932384626433832
#define mod 1000000007
#define inf 1000000000

const long double PI = acos(-1);

int powm(int a, int b) {
    int res=1;
    while(b) {
        if(b&1)
            res=(res*a)%mod;
        a=(a*a)%mod;
        b>>=1;
    }
    return res;
}

vector<pii>v;
int sum[100005];

void solve(){
  int n,k;
  cin >> n >> k;

  string s;
  cin >> s;

  int id = 0;
  while(id<n){
    int zero =0, one =0;

    while(id<n && s[id]=='0'){
        zero++;
        id++;
    }

    if(zero)v.push_back({0, zero});

    while(id<n && s[id]=='1' ){
        one++;
        id++;
    }

    if(one)v.push_back({1, one});
  }
    
  int ans = 0;
  sum[1] = v[0].second;

  for(int i = 1;i<(int)v.size();i++){
    sum[i+1]+=sum[i]+v[i].second;
    //cout << sum[i] << endl;
  }
  //for(int i= 1;i<=n;i++)cout << sum[i] << endl;

  for(int i = 1; i<= (int)v.size();i++){
    int t1 = 2*k+i;
    t1 = min<int>(v.size(), t1);
    int t2 = 2*k+i-1;
    t2 = min<int>(v.size(), t2);
    if(v[i-1].first)ans = max(ans, sum[t1] - sum[i-1]);
    else ans = max(ans, sum[t2] - sum[i-1]);

  }
  cout << ans << endl;
} 

signed main() 
{   
    IOS;
    int t = 1;
    //cin >> t;

    for(int i = 1;i<=t;i++){
        solve();
    }
    return 0;
} 

 


Measured memory_bytes: 2880
#include<bits/stdc++.h>
using namespace std;
#define maxn 100005
int a[maxn];
int main(){
	int n;scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",a+i);
		if(a[i]>a[i-1])a[i]--;
		else if(a[i]<a[i-1]){
			puts("No");return 0;
		}
	}
	puts("Yes");
	return 0;
} 

Measured memory_bytes: 640
#include <stdio.h>
#include <string.h>
int main()
{
    int a,b,c,aSpace,extra;
    signed int x;
    scanf("%d", &a);
    scanf("%d", &b);
    scanf("%d", &c);
    aSpace = a-b;
    extra = aSpace - c;
    if(extra >= 0){
       printf("%d\n", 0);
    }else{
        printf("%d\n", extra*-1);
    }
    return 0;
}


Measured memory_bytes: 128
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
int main()
{
	long long int a = 2,b = 1,c,temp;
	int N;
	while(~scanf("%d",&N) && N>=1 && N<= 86 )
	{
		if( N == 1 )	printf("1\n");	
		if( N == 2 )	printf("3\n");
		if( N >= 3 )
		{
			for(int i = 1 ; i <= N - 1 ; i++ )
			{
				c = b + a;
				temp = b;
				b = c;
				a = temp;
			}
			printf("%lld\n",c);
		}
	}
}

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

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

int main() {
  int num;
  int k;
  
  cin >> num >> k;
  
  long long dp[num+k];
  long long h[num+k];
  
  for(int i = 0; i < num; i++) cin >> h[i];
  
  for(int i = 0; i < num+k; i++) dp[i] = 1LL << 60;
  
  dp[0] = 0;
  
  for(int i = 0; i < num; i++){
    for(int j = 1; j <= k; j++){
      chkMin(dp[i + j], dp[i] + abs(h[i] - h[i + j]));
    }
  }
  
  cout << dp[num-1];
}


Measured memory_bytes: 1792
using System;

namespace sample
{
    class sample
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            int result = 0;
            int n = 0;
            for (int i = 0; i < 3; i++)
            {
                if (s[i] == 'R') { n++; }
                else { result = result < n ? n : result; n = 0; }
            }
          	result = result < n ? n : result; n = 0;
            Console.WriteLine(result);
        }
    }
}


Measured memory_bytes: 25840
# 初期入力
import numpy as np
import sys
input = sys.stdin.readline
N = int(input())
V = np.array(list(map(int, input().split())))
C = np.array(list(map(int, input().split())))

#どの宝石を選ぶか全探索
v_c_sum=0
for i in range(N):
    if 0 < V[i] -C[i]:
        v_c_sum +=V[i] - C[i]
print(v_c_sum)

Measured memory_bytes: 12484
#include <bits/stdc++.h>
using namespace std;
template<typename T>
inline T read(T&x){
	x=0;int f=0;char ch=getchar();
	while (ch<'0'||ch>'9') f|=(ch=='-'),ch=getchar();
	while (ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
	return x=f?-x:x;
}
const int N=1e5+10;
struct Node{
	int l,r;
	bool operator<(const Node&rhs)const{
		return r<rhs.r;
	}
}p[N];
int n,m,i,j,pre,cnt;
int main(){
	read(n),read(m);
	for (i=1;i<=m;i++) read(p[i].l),read(p[i].r);
	sort(p+1,p+1+m); 
	for (i=1;i<=m;i++){
		if (p[i].l>=pre){
			pre=p[i].r;
			cnt++;
		}
	}
	printf("%d\n",cnt);
	return 0;
}

Measured memory_bytes: 1024
// .. (Double Dots)

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define irep(i,a) for(auto i = a.begin(); i != a.end(); ++i)
#define nvarep(n,a) int n;cin>>n;vector<int>a(n);rep(i,0,n)cin>>a[i]
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a/__gcd(a, b)*b)
#define range(a) (a).begin(),(a).end() 
#define pb push_back
#define mp make_pair
#define nnn "\n"
#define spa " "
#define cout15(a) printf("%.15f\n",a)
template<class T>inline bool chmin(T& a,T b,bool f){
if(f==1){if(a>b){a=b;return true;}return false;}
else if(f==0){if(a<b){a=b;return true;}return false;}return false;}
typedef pair<int,string> p;
const int inf = 2147483647;//2*10^9
const ll INF = 9223372036854775807;//9*10^18
using graph = vector<vector<int>>;

int main (){
    int n,m;cin>>n>>m;
    graph g(n);
    rep(i,0,m){
        int a,b;cin>>a>>b;
        g[a-1].pb(b-1);
        g[b-1].pb(a-1);
    }
    vector<int>dist(n,-1);
    queue<int>q;
    dist[0]=0;
    q.push(0);
    while(!q.empty()){
        int v = q.front();
        q.pop();
        for(int nv : g[v]){
            if(dist[nv]!=-1)continue;
            dist[nv]=dist[v]+1;
            q.push(nv);
        }
    }
    bool flag = true;
    rep(i,0,n)if(dist[i]==-1)flag=false;
    if(!flag){cout<<"No"<<nnn;return 0;}
    cout<<"Yes"<<nnn;
    rep(i,1,n){
        int mina=inf;
        int ans;
        for(int mi : g[i]){
            mina=min(mina,dist[mi]);
            if(mina==dist[mi])ans=mi;
        }
        cout<<ans+1<<nnn;
    }
    return 0;
}

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

int main () {
    int a, b, c, x;
    cin >> a;
    cin >> b;
    cin >> c;
    cin >> x;
    int count = 0;
    for (int i = 0; i < a+1; i++) {
        for (int j = 0; j < b+1; j++) {
            int ab = i * 500 + j * 100;
            int r = x - ab;
            if (r >= 0 && r % 50 == 0 && r / 50 <= c) {
                count ++;
            }
        }
        /* code */
    }
    cout << count << endl;
    
}

Measured memory_bytes: 256
N = int(input())

a = list(map(int,input().split()))
b = list(map(int,input().split()))

total1 = 0
total2 = 0

for i in range(N):
    if a[i]>b[i]:
        total1 += a[i]-b[i]
    else:
        total2 += (b[i]-a[i])//2

if total1 <=total2:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 80132
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <iostream>
using namespace std;

// s.....0=�{�� 1=����
int n, m, s = 0, c = 0;
char u[256][11] = {}, t[256][11] = {};

int check(int a, int b);

int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%s", &u[i]);
	}
	scanf("%d", &m);
	for (int i = 0; i < m; i++) {
		scanf("%s", &t[i]);
	}

	for (int i = 0; i < m; i++) {
		c = 0;

		for (int j = 0; j < n; j++) {
			if (check(j, i)) {
				c = 1;
				if (s == 0) {
					printf("Opened by %s\n", t[i]);
					s = 1;
					break;
				}
				if (s == 1) {
					printf("Closed by %s\n", t[i]);
					s = 0;
					break;
				}
			}
		}

		if (c == 0) {
			printf("Unknown %s\n", t[i]);
		}
	}
	return 0;
}

int check(int a, int b) {
	for (int i = 0; i < 10; i++) {
		if (u[a][i] != t[b][i])
			return 0;
		if (u[a][i] == t[b][i] && u[a][i] == 0)
			return 1;

	}
	//printf("fadsfasf");
	return 1;
}


Measured memory_bytes: 3212
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll int64_t
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

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

int N,M;
vector<vector<P>> G;
int dp[101010];

int rec(int v){
    if(dp[v]!=INF) return dp[v];

    int res = 0;
    for(auto nv:G[v]) chmax(res,rec(nv.first)+nv.second);
    return dp[v] = res;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin>>N>>M;
    G.assign(N,vector<P>());
    REP(i,M){
        int x,y,z;
        cin>>x>>y>>z;
        G[x].push_back({y,z});
    }
    REP(i,101010) dp[i] = INF;

    int res = 0;
    for(int v=0;v<N;v++) chmax(res,rec(v));
    cout<<res<<endl;

}


Measured memory_bytes: 3632
/* ex3_2
   moka223711 */

#include <stdio.h>

int main(void){
	int num, d = 0;
	scanf("%d", &num);

	// Nを1から9で割って、余りが0かつ商が9以下になっているものを探す
	// 割れるものが見つかったらdを1に変える
	for(int i = 1; i <= 9; i++){
    	if(num % i == 0 && num / i <= 9){
        	d = 1;
			break;
		}
	}
	
	// 上のfor文で1から9で割り切れるものが見つかったときd == 1となっているため
	// if文が実行される、なかったときはelse文の実行
	if(d){
		printf("Yes");
	}
	else{
		printf("No");
	}
  
	return 0;
}


Measured memory_bytes: 128
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

// c++11
#include <array>
#include <tuple>
#include <unordered_map>
#include <unordered_set>

#define mp make_pair
#define mt make_tuple
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

const int INF = 1 << 29;
const double EPS = 1e-9;
const ll MOD = 1000000007;

const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};
string S;
int N;

bool check(){
    int M = S.size();
    if (M % 2 != 0){
        return false;
    }
    if (S.substr(0, M / 2) == S.substr(M / 2)){
        return true;
    }

    return false;
}
int main() {
    cin >> S;
    N = S.size();
    S.pop_back();
    for (int i = N - 2; i >= 0; i--){
        if (check()){
            cout << S.size() << endl;
            return 0;
        }
        S.pop_back();
    }
   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> P;

int main() {
  ll n,a,b;
  cin>>n>>a>>b;
  ll h[100005];
  rep(i,n) cin>>h[i];
  ll l=0,r=1e9;
  while (r-l>1) {
    ll mid=(l+r)/2;
    ll sum=0;
    rep(i,n) sum+=max((h[i]-b*mid+a-b-1)/(a-b),0ll);
    if (sum<=mid) r=mid;
    else l=mid;
  }
  cout<<r<<endl;
  return 0;
}



Measured memory_bytes: 1024
#include<stdio.h>

void trace(int A[], int N){
    int i;
    for (i=0; i < N;i++){
        if(i > 0) printf(" ");
        printf("%d",A[i]);
    }
    printf("\n");
}

void insertionSort(int A[], int N){
    int j,i,v;
    for (i=1;i<N;i++){
        v = A[i];
        j = i-1;
        while(j>=0 && A[j] > v){
            A[j+1] = A[j];
            j--;
        }
        A[j+1] = v;
        trace(A,N);
    }
}

int main(){
    int N, i, j;
    int A[100];
    scanf("%d", &N);
    for (i=0; i<N;i++) scanf("%d",&A[i]);
    
    trace(A,N);
    insertionSort(A,N);
    
    return 0;
}


Measured memory_bytes: 2756
import heapq


def main():
    nvertices, nedges, s = map(int, input().split())
    adj = [[] for i in range(nvertices)]
    for i in range(nedges):
        u, v, w = map(int, input().split())
        adj[u].append((v, w))

    INF = float('inf')
    costs = [INF] * nvertices
    costs[s] = 0
    que = [(0, s)]
    for i in range(1, nvertices):
        que.append((INF, 1))
    while que:
        cost, u = heapq.heappop(que)
        if cost > costs[u]:
            continue
        costs[u] = cost
        for v, w in adj[u]:
            if costs[v] > costs[u] + w:
                costs[v] = costs[u] + w
                heapq.heappush(que, (costs[v], v))

    for i in range(nvertices):
        print(costs[i] if costs[i] < INF else "INF")


main()

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

ll gcd(ll x, ll y)
{
    if(y==0)return x;
    return gcd(y,x%y);
}
// 最大公約数を求める関数
ll lcm(ll x, ll y)
{
    return (x/ gcd(x, y)*y);
}

int main(){
	int n;
	cin>>n;
	ll t[n];
	for(int i=0;i<n;i++){
		cin>>t[i];
	}
	ll res=1;
	res = lcm(t[0],t[1]);
	for(int i=0;i<n;i++){
		res = lcm(res,t[i]);
		//cout<<i<<"回目:"<<res<<endl;
	}
	if(n==1)res = t[0];
	cout<<res<<endl;
}


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

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()

template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll charToBit(char c) {return 1<<(c-'a');}

class SegmentTree {
    int _sz;
    vector<ll> v;
    ll near_pow(ll sz) {
        ll k = 1;
        while(sz>k) k*=2;
        return k;
    }

public:
    SegmentTree(int sz) {
        _sz = near_pow(sz);
        v.resize((2*_sz)-1,0);
        string s; cin >> s;
        REP(i,sz) v[_sz-1+i] = charToBit(s[i]);
        FOR(i,sz,_sz) v[_sz-1+i] = v[_sz+sz-2]; //残りを最後の要素で埋める
        // 葉以外の要素を求める。
        REPR(i,_sz-2) v[i] = v[(2*i)+1] | v[(2*i)+2];

    }
    string lltoStr(ll k) {
        string s;
        REP(i,26) if((1<<i) & k) s.push_back((char)i+'a');
        return s;
    }
    void print() {
        REP(i,v.size()) cerr << i << ": " << lltoStr(v[i]) << endl;
    }
    void update(int key,ll val) {
        // 最下位のノードにアクセス
        key += _sz-1;
        // 最下位のノードを更新
        v[key] = val;
        // 上位ノードの更新
        while(key > 0) {
            key = (key-1)/2;
            v[key] = v[(2*key)+1] | v[(2*key)+2];
        }
        // cerr << "update! key: " << key << " val: " << val << endl;
        // print();
    }
    // 区間[a,b)の要素数を求める。 [l,r)は自分の今いるノードの区間、kは自分の今いるノードのインデックス・
    ll get(int a,int b,int l = 0,int r = -1,int k = 0) {
        // 初期化処理 最初は[l,r) = [0,N)
        if (r<0) r = _sz;

        // if(a==b) return v[_sz-1+a];

        // 欲しい区間と今いるノードの区間が交わらないなら答えに影響のない値を適当に返す
        if ( l >= b || r<= a ) return 0;

        //今いるノードの区間が全て欲しい区間の中だったらそれを答えに使う
        if ( a <= l && r <=  b) return v[k];

        // 今いるノードの区間の一部が欲しい場合は探索を進める。
        // 自分の今いるノードの区間を半分に分けて探索する。
        ll vl = get(a,b,l,(l+r)/2,2*k+1);
        ll vr = get(a,b,(l+r)/2,r,2*k+2);

        return vl | vr;
    }

};
ll count(ll k) {
    int cnt = 0;
    REP(i,26) if((1<<i) & k) cnt++;
    return cnt;
}
void solve() {
    int N;
    cin >> N;
    SegmentTree s(N);
    int Q;
    cin >> Q;
    REP(_,Q) {
        int typ;
        cin >> typ;
        if(typ == 1) {
            int i; char c;
            cin >> i >> c;
            s.update(i-1,charToBit(c));
        }
        if (typ == 2) {
            int l,r;
            cin >> l >> r;
            cout << count(s.get(l-1,r)) << '\n';
        }
    }

}

int main() {
    solve();
    return 0;
}


Measured memory_bytes: 9092
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
typedef vector<ll> vel;
typedef vector<str> ves;
#define REP(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define rep(i, b) REP(i, 0, b)
const ll cd = 1000000007;
const double pi = 3.14159265358979;

int main() {
    ll N, K;
    cin >> N >> K;
    ll count = 0;
    vel sum(N + 2);
    sum[0] = 0;
    rep(i, N + 1) {
        sum[i+1] = sum[i] + i + 1;
    }
    REP(i, K, N+2) {
        ll max, min;
        max = sum[N + 1] - sum[N + 1 - i];
        min = sum[i] - sum[0];
        count += max - min + 1;
        count %= 1000000007;
    }
    cout << count << endl;
}

Measured memory_bytes: 4780
group =[0,1,3,1,2,1,2,1,1,2,1,2,1]

input_lines=raw_input()
input_numbers=input_lines.split()
n=map(int,input_numbers)

if group[n[0]] == group[n[1]]:
    print "Yes"
else:
    print "No"

Measured memory_bytes: 2568
N = input() #N角形
sides_length = input().split()
sides_length = [int(i) for i in sides_length]
sides_total = 0
#定理:一番長い辺が他の N-1辺の長さの合計よりも真に短い場合に限り、条件を満たすN角形が描ける。
for i in range(int(N)):
    sides_total += int(sides_length[i])
sides_max = max(sides_length)
total_Nomax = int(sides_total) - int(sides_max)

if int(sides_max) < int(total_Nomax):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define itrep(x) for(auto it=(x).begin();it!=(x).end();it++) 
#define Sort(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define vi vector<int>
#define INF (int)1e9
#define INFL 1e18
#define MOD 1000000007
#define pb push_back
#define MP make_pair
typedef long long int ll;
typedef std::pair<int,int> P;
int D=1;
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
 
using namespace std;

int chan(char c){
    if(c=='m')return 1000;
    if(c=='c')return 100;
    if(c=='x')return 10;
    if(c=='i')return 1;
}
 
int main(){
    int n;
    cin>>n;
    rep(p,0,n){
        int num[2]={0};
        rep(j,0,2){
            string s;
            cin>>s;
            rep(i,0,s.length()){
                if('0'<=s[i] && s[i]<='9'){
                    num[j]+=(s[i]-'0')*chan(s[i+1]);
                    i++;
                }else {
                    num[j]+=chan(s[i]);
                }
            }
        }
        
        int ans=num[0]+num[1];
        if(ans/1000==1)cout<<'m';
        else if(ans/1000!=0)cout<<ans/1000<<'m';
        ans%=1000;
        
        if(ans/100==1)cout<<'c';
        else if(ans/100!=0)cout<<ans/100<<'c';
        ans%=100;
        
        if(ans/10==1)cout<<'x';
        else if(ans/10!=0)cout<<ans/10<<'x';
        ans%=10;
        if(ans==1)cout<<'i';
        else if(ans!=0)cout<<ans<<'i';
        cout<<endl;
        
    }
    return 0;
}


Measured memory_bytes: 3152
import java.util.*;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		while(true){
			int n = sc.nextInt();
			if(n == 0) break;

			ArrayList<HashSet<Integer>> set = new ArrayList<HashSet<Integer>>();
			boolean[][] flg = new boolean[n][32];

			for(int i=0;i<n;i++){
				set.add(new HashSet<Integer>());
				set.get(i).add(i);

				int m = sc.nextInt();

				for(int j=0;j<m;j++){
					int x = sc.nextInt();
					flg[i][x-1] = true;
				}
			}

			int ans = 0;
			for(;ans<30;ans++){
				HashSet<Integer> tmp = new HashSet<Integer>();
				for(int j=0;j<n;j++){
					if(flg[j][ans]){
						tmp.addAll(set.get(j));
					}
				}
				if(tmp.size() == n) break;

				for(int j=0;j<n;j++){
					if(flg[j][ans]){
						set.get(j).addAll(tmp);
					}
				}
			}

			System.out.println(ans==30 ? -1 : ans+1);
		}
	}
}

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

lint gcd(lint x, lint y) {
  if(x == 0) { return y; }
  else { return gcd(y%x,x); }
}

lint lcm(lint x, lint y) { return x/gcd(x,y)*y; }

lint C(lint n, lint k) {
  if(n == k) { return 1; }
  else if(n < k) { return 0; }
  else if(k == 0) { return 1; }
  else if(k == 1) { return n; }
  else return C(n-1,k-1) + C(n-1,k);
}

lint P(lint n, lint k) {
  if(k == 1) { return n; }
  return (n*(P(n-1,k-1)%1000000007)%1000000007);
}


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

  int cnt=0;
  while(true) {
    if(a < b) { break; }
    b *= 2;
    cnt++;
  }

  while(true) {
    if(b < c) { break; }
    c *= 2;
    cnt++;
  }

  if(cnt <= k) { cout << "Yes" << endl; }
  else { cout << "No" << endl; }
  return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>

using namespace std;

int main(void)
{
	int n;
	int cnt = 0;
	int a[128];

	cin >> n;

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

	bool flag = true;
	for (int i = 0; flag; i++){
		flag = false;
		for (int j = n - 1; j >= i + 1; j--){
			if (a[j] < a[j - 1]){
				swap(a[j], a[j - 1]);
				cnt++;
				flag = true;
			}
		}
	}

	
	for (int i = 0; i < n; i++){
		cout << a[i] << (i + 1 == n ? '\n' : ' ');
	}
	cout << cnt << endl;

	return 0;
}

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

const int INF = (int)2e9;
int N;
vector<int> H;
vector<int> dp;

void input_init(void) {
	cin >> N;
	H.resize(N + 1);
	for (int i = 1; i <= N; ++i)
		cin >> H[i];
	dp.resize(N + 1, INF);
	dp[1] = 0;
	dp[2] = abs(H[2] - H[1]);
}

void solve(void) {
	for (int i = 3; i <= N; ++i) {
		int step1 = abs(H[i] - H[i - 1]) + dp[i - 1];
		int step2 = abs(H[i] - H[i - 2]) + dp[i - 2];
		dp[i] = min(step1, step2);
	}
}

int main(void) {
	input_init();
	solve();
	cout << dp[N] << '\n';
	return 0;
}


Measured memory_bytes: 1024
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        long C = sc.nextLong();
        long[] x = new long[N+1];
        long[] u =new long[N+1];
        for(int i=1;i<=N;i++){
            x[i] = sc.nextLong();
            u[i] = sc.nextLong();
        }
        long[] sum = new long[N+1];
        for(int i=1;i<=N;i++){
            sum[i]=sum[i-1]+u[i];
        }
        long[] clock1 = new long[N+2];
        long[] clock2 = new long[N+2];
        for(int i=1;i<=N;i++){
            clock1[i]=Math.max(clock1[i-1],sum[i]-x[i]);
            clock2[i]=Math.max(clock2[i-1],sum[i]-2*x[i]);
        }
        long[] anti1 = new long[N+2];
        long[] anti2 = new long[N+2];
        for(int i=N;i>=1;i--){
            anti1[i] = Math.max(anti1[i+1],sum[N]-sum[i-1]-(C-x[i]));
            anti2[i] = Math.max(anti2[i+1],sum[N]-sum[i-1]-2*(C-x[i]));
        }
        long ansClock = clock1[N];
        long ansAnti = anti1[1];
        long ansClockFirst = 0;
        for(int i=1;i<=N-1;i++){
            ansClockFirst = Math.max(ansClockFirst,clock2[i]+anti1[i+1]);
        }
        long ansAntiFirst = 0;
        for(int i=N;i>=2;i--){
            ansAntiFirst = Math.max(ansAntiFirst,anti2[i]+clock1[i-1]);
        }
        long ans = Math.max(Math.max(ansClock,ansAnti),Math.max(ansClockFirst,ansAntiFirst));

        System.out.print(ans);
    }
}

Measured memory_bytes: 92640
#include <iostream>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
using namespace std;

struct pos{
    int x;
    int l;
}p[100000];

int main(){

   int n,k,s;

   cin >> n >> k >> s;
   if(k){
       cout << s;
       k--;
       for(int i = 0;i < k;i++){
            cout << " " << s;
       }
       s = (s+1)%1000000000;
       for(int i = 0;i < n-k-1;i++){
            cout << " " << s;
       }
   }
   else{
        s = (s+1)%1000000000;
        for(int i = 0;i < n;i++){
            cout << s;
            if(i!=n-1) cout << " ";
       }
   }
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define meow(args...) fprintf(stderr, args)
typedef unsigned u32;
typedef long long s64;
typedef unsigned long long u64;
template<class T1, class T2> inline bool cmin(T1 &a, const T2 &b) {return b<a?(a=b, true):false;}
template<class T1, class T2> inline bool cmax(T1 &a, const T2 &b) {return a<b?(a=b, true):false;}
template<class Type> Type read() {
	Type a;
	bool b;
	unsigned char c;
	while(c=getchar()-48, (c>9)&(c!=253));
	for(a=(b=c==253)?0:c; (c=getchar()-48)<=9; a=a*10+c);
	return b?-a:a;
}
int (*rd)()=read<int>;
const u32 P=1e9+7;
inline u32 &inc(u32 &a, u32 b) {return (a+=b)<P?a:(a-=P);}
inline u32 &dec(u32 &a, u32 b) {return (a-=b)&0x80000000?(a+=P):a;}
inline u32 sum(u32 a, u32 b) {return (a+=b)<P?a:a-P;}
inline u32 dif(u32 a, u32 b) {return (a-=b)&0x80000000?a+P:a;}
u64 power(u64 a, int b) {
	u64 ans=1;
	for(; b; a=a*a%P, b/=2) if(b&1) ans=ans*a%P;
	return ans;
}

const int N=605;
int a[N], r[N];
u32 dp[2][N][N];
int main() {
	int n;
	u32 (*f)[N]=dp[0], (*g)[N]=dp[1];
	n=2*rd();
	memset(r+1, -1, n*sizeof(int));
	for(int i=0; i<n; ++i) {
		a[i]=rd();
		if(a[i]!=-1) r[a[i]]=i;
	}
	f[0][0]=1;
	for(int i=n, s=0, t=0; i>=1; --i) {
		if(r[i]!=-1) {
			if(a[r[i]^1]!=-1) continue;
			std::swap(f, g);
			memset(f[0], 0, (t+1)*sizeof(u32));
			for(int j=0; j<=s; ++j) memcpy(f[j+1], g[j], (t+1)*sizeof(u32));
			for(int j=0; j<=s; ++j)
				for(int k=1; k<=t; ++k) inc(f[j][k-1], g[j][k]);
			++s;
		} else {
			std::swap(f, g);
			for(int j=0; j<=s; ++j) {
				f[j][0]=0;
				memcpy(f[j]+1, g[j], (t+1)*sizeof(u32));
				for(int k=1; k<=t; ++k) inc(f[j][k-1], g[j][k]);
			}
			for(int j=1; j<=s; ++j)
				for(int k=0; k<=t; ++k)
					if(g[j][k]) f[j-1][k]=(f[j-1][k]+(u64)j*g[j][k])%P;
			++t;
		}
	}
	for(int i=0, m=0; i<n; i+=2)
		if(a[i]==-1&&a[i+1]==-1) f[0][0]=(u64)f[0][0]*(++m)%P;
	printf("%u\n", f[0][0]);
	return 0;
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
#define lowbit(x) x&(-x)
typedef long long ll;
const int maxn = 2e5+3;
ll C[maxn];
int n, h[maxn], a[maxn];
void add(int x, ll d)
{
	while (x<=n)
	{
		C[x] = max(C[x], d);
		x += lowbit(x);
	}
}
ll ma(int x)
{
	ll maxs = 0;
	while (x)
	{
		maxs = max(C[x], maxs);
		x -= lowbit(x);
	}
	return maxs;
}

int main()
{
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i)
		scanf("%d", h+i);
	for (int i = 1; i <= n; ++i)
		scanf("%d", a+i);
	for (int i = 1; i <= n; ++i)
		add(h[i], ma(h[i]-1)+a[i]);
	printf("%lld\n", ma(n));
	return 0;
}
/*
4
3 1 4 2
10 20 30 40

60
*/

Measured memory_bytes: 6764
#include <stdio.h>
#include <iostream>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <string.h>

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

using namespace std;

typedef long long ll;

char S[100000];

int main() {
    cin >> S;
    int result = 0;
    int result2 = 0;
    
    REP(i, 100000) {
        if (S[i] != '0' && S[i] != '1') {
            break;
        }
        if (i % 2 == 0) {
            if (S[i] == '0') {
                result2++;
            } else {
                result++;
            }
        } else {
            if (S[i] == '1') {
                result2++;
            } else {
                result++;
            }
        }
    }
    if (result < result2) {
        cout << result << endl;
    } else {
        cout << result2 << endl;
    }
}


Measured memory_bytes: 384