akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
 
using namespace std;
 
#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
 
template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }
 
typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int solve(string& s, string& t){
  int L = s.size();
  int M = t.size();
  int dp[101][101][31] = {};
  REP(i, M){
    REP(j, L)if(s[j] == t[i]){
      for(int k = 1; i - k * j >= 0 && k <= 100; k++){
        dp[i][k][j] += (j >= 1) ? dp[i - k][k][j - 1] : 1;
      }
    }
  }
  /*
  FOR(k, 1, 11){
    printf("interval = %d\n", k);
    REP(i, M){
      printf("i = %d c = %c: ", i, t[i]);
      REP(j, L) printf("%d ", dp[i][k][j]);
      putchar('\n');
    }
  }
  */
  int ans = 0;
  REP(i, M)REP(k, 101) ans += dp[i][k][L - 1];
  return ans;
}
 
int main(){
  int N;
  cin>>N;
  string s;
  cin>>s;
  int ans = 0;
  REP(i, N){
    string t; cin>>t;
    if(solve(s, t)) ans++;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 4396
import numpy as np
import itertools
n, m, x = map(int, input().split())
a = np.dot([i for i in itertools.product([0, 1], repeat = n)],
           [list(map(int, input().split())) for _ in range(n)])
b = np.prod(a[:, 1:(m + 1)] >= x, axis = 1, dtype = bool)
print(min(a[:, 0][b]) if b.sum() else '-1')

Measured memory_bytes: 28132
#include<bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main() {
int N;
  cin >>N;
  if(N<1000) {
cout << "ABC" << endl;
  }
else {
cout << "ABD" << endl;
}
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<string>
#include<vector>
using namespace std;

int main(void) {
	string s;
	cin >> s;
	s[5] = ' ';
	s[13] = ' ';
	cout << s;
	return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
n,k=map(int,input().split())
l=[0]*10**5
for i in range(n):
    a,b=map(int,input().split())
    l[a-1]+=b
s=0
for i in range(10**5):
    if s+l[i]>=k:print(i+1);break
    else: s+=l[i]

Measured memory_bytes: 5748
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    if (a==1 || b==1 || c==1 || d==1) {
        if (a==4 || b==4 || c==4 || d==4) {
            if (a==7 || b==7 || c==7 || d==7) {
                if (a==9 || b==9 || c==9 || d==9) {
                    cout<<"YES"<<endl;
                    return 0;
                }
            }
        }
    }
    cout<<"NO"<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	Scanner sc = new Scanner(System.in);
	final int MOD = 1000000007;
	final int MAX = Integer.MAX_VALUE;
	final long LMAX = Long.MAX_VALUE;
	final int LEN = 0;

	char ca[];
	int n;
	void doIt() {
		n = sc.nextInt();
		String  s = sc.next();
		ca = s.toCharArray();
		int cnt = 0;
		for(int i = 0; i < 1000; i++) {
			int num = i;
			char[] c = new char[3];
			c[0] = (char)(num / 100 + '0');
			num %= 100;
			c[1] = (char)(num / 10 + '0');
			num %= 10;
			c[2] = (char)(num + '0');
			if(ok(c))cnt++;
		}
		System.out.println(cnt);
	}

	boolean ok(char[] c) {
		int i = 0;
		for(int j = 0; j < n; j++) {
			if(ca[j] == c[i]) {
				i++;
				if(i == 3)break;
			}
		}
		return (i == 3)?true:false;
	}
	
	public static void main(String[] args) {
		new Main().doIt();
	}
}


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

// iterator
#define REP(i,from, to) for(lli i=from;i<to;i++)
#define REPE(i,from, to) for(lli i=from;i<=to;i++)
#define REP_R(i,from, to) for(lli i=from;i>to;i--)
#define REPE_R(i,from, to) for(lli i=from;i>=to;i--)
#define REPIT(it,container) for(auto it = container.begin(); it != container.end(); it++)
#define REPIT_R(it,container) for(auto it = container.rbegin(); it != container.rend(); it++)

// input
#define cin1(x)             cin >> x
#define cin2(x, y)          cin >> x >> y
#define cin3(x, y, z)       cin >> x >> y >> z
#define ncin1(n, x)         REP(i, 0, n) {cin1(x[i]);}
#define ncin2(n, x, y)      REP(i, 0, n) {cin2(x[i], y[i]);}
#define ncin3(n, x, y, z)   REP(i, 0, n) {cin3(x[i], y[i], z[i]);}

// output
#define cout1(x)         cout << #x << ": " << x << endl;
#define cout2(x, y)      cout << #x << ": " << x << ", " << #y << ": " << y << endl;
#define cout3(x, y, z)   cout << #x << ": " << x << ", " << #y << ": " << y << ", " << #z << ": " << z << endl;;
#define ncout1(n, x)     REP(i, 0, n) {cout << #x << "[" << i << "]: "<< x[i] << endl;}

#define coutp(p)         cout << #p << ":" <<  " (" << p.first << ", " << p.second << ")" << endl;

// sort
#define sort_r(x, y)        sort(x, y, greater<lli>()); // 降順(5,4,3,,,)

#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

typedef long long int lli;
typedef pair<lli, lli> P;
typedef tuple<lli, lli, lli> tup;
typedef vector<lli> vlli;

int main() {
    lli n;
    cin1(n);
    lli a[n];
    ncin1(n,a);
    REP(i,0,n) {
        a[i] *= 2;
    }
    sort(a,a+n);
    lli max_n = a[n-1];

    auto it = lower_bound(a,a+n,max_n/2);
    lli cand1 = *it;
    if (cand1 == max_n)
        cand1 = *(it-1);

    REP(i,0,n) {
        a[i] = -a[i];
    }
    sort(a,a+n);
    it = lower_bound(a,a+n,(-max_n)/2);
    lli cand2 = -*it;
    //cout2(cand1, cand2);
    if (cand1 - max_n/2 < max_n/2 - cand2)
        cout << max_n/2 << " " << cand1/2 << endl;
    else
        cout << max_n/2 << " " << cand2/2 << endl;

}


Measured memory_bytes: 1024
#include<iostream>
using namespace std;
int main()
{
  int n,x,y,b,p,q1[366],q2;
  cin>>n;
  for(int i=0; i<n; i++){
    cin>>x>>y>>b>>p;
    q1[i]=x*b+y*p;
    if(b>=5 && p>=2){
      q1[i]=(x*b+y*p)*8/10;
    }else{
      if(b>=5){
	q2=(x*b+y*2)*8/10;
      }else if(p>=2){
	q2=(x*5+y*p)*8/10;
      }else{
	q2=(x*5+y*2)*8/10;
      }
      if(q1[i]>q2){
	q1[i]=q2; 
      }
    }
  }
  for(int i=0; i<n; i++){
    cout<<q1[i]<<'\n';
  }
  return 0; 
}



Measured memory_bytes: 3108
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    vector<int> kouho6;
    vector<int> kouho9;
    int mir=0;
    for(int i =0;mir <=100000;i++){
        mir = pow(6,i);
        kouho6.push_back(mir);
    }
    mir =0;
    for(int i =0;mir <=100000;i++){
        mir = pow(9,i);
        kouho9.push_back(mir);
    }

    reverse(kouho6.begin(),kouho6.end());
    reverse(kouho9.begin(),kouho9.end());
    int ans =n;
    for(int i =0;i<=n;i++){
        int ans6=0;
        int ans9=0;
        int a = i;
        int ia = n-i;
        while(true){
            if(a<6){
                ans6 += a;
                break;
            }
            ans6 += a%6;
            a /= 6;
        }
        while(true){
            if(ia<9){
                ans9 += ia;
                break;
            }
            ans9 += ia%9;
            ia /= 9;
        }
        // cout<<ans6<<"   "<<ans9<<endl;
        ans = min(ans,ans6+ans9);
    }
    cout<<ans<<endl;
}

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

#define SIZE 2000000

int myatoi(const char* p)
{
  int n;
  while (*p!='\n') {
    n = n*10+*p-'0';
    p++;
  }
  return n;
}

int main() {
  int A[SIZE];
  int H=0;
  int i, l, largest, tmp;
  char com[21];
  do {
    fgets(com, 20, stdin);
    if (com[0] == 'i') {
      A[++H] = atoi(com+7);
      for (i=H; i>1 && A[i/2]<A[i];i/=2) {
        tmp = A[i/2];
        A[i/2] = A[i];
        A[i] = tmp;
      }

    } else if (com[1]=='x') { // extract
      printf("%d\n", A[1]);
      A[1] = A[H];
      i = 1;
      while (1) {
        l = i*2;
        largest = i;
        if (l < H && A[l] > A[i])        largest = l;
        if (l+1 < H && A[l+1] > A[largest])  largest = l+1;
        if (largest == i) break;
        tmp = A[i];
        A[i] = A[largest];
        A[largest] = tmp;
        i = largest;
      }
      H--;
    }
  } while (com[2]!='d');
  return 0;
}


Measured memory_bytes: 5588
n = gets.to_i
a = gets.chomp.split
a_index = []
n.times do |i|
    a_index << [a[i].to_i, i+1]
end

a_index.sort!
n.times do |i|
    print a_index[i][1]
    if i != n-1
        print " "
    else
        print "\n"
    end
end

Measured memory_bytes: 17668
#include <iostream>
using namespace std;
int N, K;
int d[100];
int A[100][100];

bool doHave(int sunuke){
    for (int i = 0; i < K; i++) {
        for (int j = 0; j < d[i]; j++) {
            if( A[i][j] == sunuke ) return true;
        }
    }
    return false;
}

int main() {

    cin >> N >> K;


    for (int i = 0; i < K; i++) {
        cin >> d[i];
        for (int j = 0; j < d[i]; j++) {
            cin >> A[i][j];
        }
    }

    int ans = 0;
    for (int i = 1; i <= N; i++) {
        if(!(doHave(i))) ans++;
    }
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3632
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, a, b) for (int i = a; i < (b); i++)
#define FOR(i, n) for (int i = n; i >= 0; i--)
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define ll long long
#define SIZE 100001
#define MOD 1000000007
#define INF 100000000
using namespace std;

int main()
{
    int n;
    cin >> n;

    int a[100001];

    REP(i, n) cin >> a[i];

    int down = 0, up = 0, cnt = 0; 
    REP(i, n-1){
        if(a[i] < a[i+1]) up++;
        else if(a[i] > a[i+1]) down++;
                if(down > 0 && up > 0){
            cnt++;
            down = 0;
            up = 0;
        }

    }

    cout << cnt + 1 << endl;



    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
int vis[10];
int main(){
    std::ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    int n;
    cin>>n;
    int d1=0,d2=0;
    int d;
    int nn=1;
    for(int i=1;i<n;i++) nn*=i;
    for(int i=0;i<n;i++){
        cin>>d;
        int num=0;
        for(int j=1;j<d;j++){
            if(vis[j]==0) num++;
        }
        d1+=nn*num;
        vis[d]=1;
        if(i!=n-1)
            nn/=(n-i-1);
    }
    memset(vis,0,sizeof(vis));
    nn=1;
    for(int i=1;i<n;i++) nn*=i;
    for(int i=0;i<n;i++){
        cin>>d;
        int num=0;
        for(int j=1;j<d;j++){
            if(vis[j]==0) num++;
        }
        d2+=nn*num;
        vis[d]=1;
        if(i!=n-1)
            nn/=(n-i-1);
    }
    //cout<<d1<<' '<<d2<<endl;
    cout<<abs(d1-d2)<<endl;
    return 0;
}


Measured memory_bytes: 256
x,y=map(int,input().split())
a=[0]*3
a[0]=[1,3,5,7,8,10,12]
a[1]=[4,6,9,11]
a[2]=[2]

for i in range(3):
    if x in a[i]:
        if y in a[i]:
            print("Yes")
            exit()
print("No")

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

int main () {
	int N, pre, now, mem, mempre;
	cin >> N;
	pre = 0;
	mem = 0;
	for (int i=0; i<N; ++i) {
		cin >> now;
		if (now == pre+1) {
			pre = now;
		} else {
			if (mem == 0) {
				mem = now;
				mempre = pre;
			} else if (mem == -1) {
				cout << "NO" << endl;
				exit(0);
			} else {
				if (mem == pre+1 && now == mempre+1) {
					mem = -1;
				} else {
					cout << "NO" << endl;
					exit(0);
				}
			}
			++pre;
		}
	}
	cout << "YES" << endl;
}


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

int test() {
    // input
    string S;
    cin >> S;
    const ll BIT_0 = (1<<0);
    const ll BIT_1 = (1<<1);
    const ll BIT_2 = (1<<2);
    
    // calculation
    ll A = S[0] - '0', B = S[1] - '0', C = S[2] - '0', D = S[3] - '0';
    ll bit = 1, res;
    bool flag_A, flag_B, flag_C;
    for (ll i = 0; i < (bit<<3); ++i) {
        res = A;
        flag_A = BIT_0 & i, flag_B = BIT_1 & i, flag_C = BIT_2 & i;
        res = res + (flag_A ? B: -B);
        res = res + (flag_B ? C: -C);
        res = res + (flag_C ? D: -D);
        if (res == 7) break;
    }
    
    cout << A << (flag_A ? '+': '-') << B << (flag_B ? '+': '-') << C << (flag_C ? '+': '-') << D << "=7" << "\n";
    
    return 0;
}

int main() {
    string S;
    cin >> S;
    
    ll BIT = (1<<3), sum;  // 2^3
    for (ll i = 0; i < BIT; ++i) {
        string res; res += S[0];
        sum = S[0] - '0';
        
        // +: 1, -: 0 とする
        // 0 ~ 2 のビットを全探索
        for (ll j = 0; j < 3; ++j) {
            if (i & 1<<j) {
                sum += S[j+1] - '0';
                res += '+';
                res += S[j+1];
            } else {
                sum -= S[j+1] - '0';
                res += '-';
                res += S[j+1];
            }
        }
        
        if (sum == 7) {
            cout << res << "=7" << "\n";
            return 0;
        }
    }
    
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#define MOD 1000000007
typedef long long ll;
using namespace std;

#define mkp make_pair

#define MAX_N 200020
ll inv[MAX_N+10],fac[MAX_N+10],ifac[MAX_N+10];

void setComb(){
  inv[0]=1;inv[1]=1;fac[1]=1;ifac[1]=1;fac[0]=1;ifac[0]=1;
  for(int i=2;i<MAX_N;i++){
    inv[i]=(-MOD/i)*inv[MOD%i]%MOD;
    fac[i]=fac[i-1]*i%MOD;
    ifac[i]=ifac[i-1]*inv[i]%MOD;

    inv[i]=(inv[i]+MOD)%MOD;
    fac[i]=(fac[i]+MOD)%MOD;
    ifac[i]=(ifac[i]+MOD)%MOD;
  }
  return;
}

ll comb(ll n,ll k){
  if(n<k||n<0||k<0) return 0;
  else return ((fac[n]*ifac[k]%MOD*ifac[n-k]%MOD+MOD)%MOD);
}

ll hcomb(ll n,ll r){
  if(n==0&&r==0) return 1;
  else if(n<0||r<0) return 0;
  else return comb(n+r-1,r-1);
}

ll H,W;
int N;
vector<ll> R,C;

ll dp[3030];

void add(ll &a,ll b){
  a=(a+b)%MOD;
}

void mul(ll &a,ll b){
  a=a*b%MOD;
}

int main(){
  cin>>H>>W>>N;
  R.resize(N);
  C.resize(N);
  for(int i=0;i<N;i++) cin>>R[i]>>C[i];

  vector<pair<ll,ll>> v;
  for(int i=0;i<N;i++) v.push_back(mkp(R[i],C[i]));
  sort(v.begin(),v.end());

  setComb();

  for(int i=0;i<N;i++){
    int r=v[i].first;
    int c=v[i].second;
    dp[i]=comb(r+c-2,r-1);
    for(int j=0;j<i;j++){
      int a=v[j].first;
      int b=v[j].second;
      if(r<a||c<b) continue;

      ll p=comb(r-a+c-b,r-a);
      mul(p,dp[j]);
      add(dp[i],MOD-p);
    }
  }

  ll ans=comb(H+W-2,H-1);
  for(int i=0;i<N;i++){
    int r=v[i].first;
    int c=v[i].second;
    ll res=dp[i];
    ll x=comb(H-r+W-c,H-r);
    mul(res,comb(H-r+W-c,H-r));
    add(ans,MOD-res);
  }
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 5120
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <stdbool.h>
typedef long long LL;
typedef long double Lf;
#define Rep(i,a,n)for(LL i=(LL)(a);i<(LL)(n);i++)
#define rep(i,n)Rep(i,0,n)
#define Repp(i,l,r,k)for(LL i=(l);i<(r);i+=(k))
#define Ma(x,y) ((x)>(y)?(x):(y))
#define mi(x,y) ((x)<(y)?(x):(y))
#define MOD 1000000007//998244353,1000000007,1000000009 
int upi(const void* a, const void* b) { return*(int*)a<*(int*)b ? -1 : *(int*)a> * (int*)b ? 1 : 0; }
int downi(const void* a, const void* b) { return*(int*)a<*(int*)b ? 1 : *(int*)a> * (int*)b ? -1 : 0; }
void sortupi(int* a, int n) { qsort(a, n, sizeof(int), upi); } //1,2,3,4,...
void sortdowni(int* a, int n) { qsort(a, n, sizeof(int), downi); }
int upLL(const void* a, const void* b) { return*(LL*)a<*(LL*)b ? -1 : *(LL*)a> * (LL*)b ? 1 : 0; }
int downLL(const void* a, const void* b) { return*(LL*)a<*(LL*)b ? 1 : *(LL*)a> * (LL*)b ? -1 : 0; }
void sortupLL(LL* a, int n) { qsort(a, n, sizeof(LL), upLL); }
void sortdownLL(LL* a, int n) { qsort(a, n, sizeof(LL), downLL); }
int cmp_char(const void* a, const void* b) { return *(char*)a - *(char*)b; } // a,b,c,d
int cmp_str(const void* a, const void* b) { return strcmp(*(const char**)a, *(const char**)b); } // aaa,aab
LL gcd(LL p, LL q) { while (q) { LL t = p % q; p = q; q = t; }return p; }
LL modpow(LL a, LL n, int m) { LL x = 1; for (a %= m; n; n /= 2)n & 1 ? x = x * a % m : 0, a = a * a % m; return x; }
#define invmodpow(b,p)modpow(b,p-2,p)// a/b≡a*b^{-1}(mod p)...return b^{-1}(mod p)
typedef struct fac { LL n, exp; }F;
LL fact(LL n,F*a){LL x,i,j,c=0;x=n;for(i=2;i*i<=x;i++){for(j=1;x%i==0;j++)x/=i;if(j>1){a[c].n=i;a[c++].exp=j-1;}}if(x-1){a[c].n=x;a[c++].exp=1;}return c;}
//snippet

#define N 1009

int main() {
	int n, a[N], ans=0;
	scanf("%d", &n);
	Rep(i,1,n+1)scanf("%d", a + i);

	Rep(i, 1, n + 1)if (i % 2 && a[i] % 2)ans++;
	printf("%d", ans);

	return 0;
}

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

#define lfs cout<<fixed<<setprecision(10)
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define test cout<<"test"<<endl;
#define fi first
#define se second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = (n); i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = (m) - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T>
void chmin(T &a,T b){if(a>b)a=b;}
template<typename T>
void chmax(T &a,T b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void pmod(ll &a,ll b,ll c){a=(b+c)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void qmod(ll &a,ll b,ll c){a=(b*c)%MOD;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>&v,ll n){if(n!=0)cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,0,-1,0,1,1,-1,-1};
vector<ll>dy={0,1,0,-1,1,-1,1,-1};
template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}
vector<ll>z_algorithm(vector<ll>s){
  ll n = s.size();
  vector<ll>ret(n,0);
  ret[0] = n;
  ll p = 1,len = 0;
  while(p < n){
    while(p+len < n && s[len] == s[p+len])len++;
    ret[p] = len;
    if(len == 0){p++; continue;}
    ll k = 1;
    while(p+k < n && k+ret[k] < len)ret[p+k] = ret[k], k++;
    p += k, len -= k;
  }
  return ret;
}
int main(){
  ll res=0,buf=0;
  bool judge = true;
  ll n;cin>>n;
  vector<ll>a(n);
  vector<ll>b(n);
  rep(i,0,n)cin>>a[i];
  rep(i,0,n)cin>>b[i];
  vector<ll>s;
  rep(i,0,n)s.PB(a[i]^a[(i+1)%n]);
  rep(i,0,2*n)s.PB(b[i%n]^b[(i+1)%n]);
  auto v=z_algorithm(s);
  vector<P>ret;
  rep(i,0,n){
    if(v[i+n]>=n)ret.EB((n-i)%n,a[0]^b[i]);
  }
  sort(ALL(ret));
  rep(i,0,ret.size())cout<<ret[i].fi spa ret[i].se<<endl;
  return 0;
}

Measured memory_bytes: 24216
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int H,N,a,b;
  cin>>H>>N;
  vector<pair<int,int>> magic;
  vector<int> spell(H+1,1e9);
  for(int i=0;i<N;++i)
  {
    cin>>a>>b;
    magic.push_back({a,b});
  }
  spell[0]=0;
  for(int h=1;h<=H;++h)
  {
    for(int i=0;i<N;++i)
    {
      int x=magic[i].first,y=magic[i].second;
      spell[h]=min((spell[max(0,h-x)]+y),spell[h]);
    }
  }
  cout<<spell[H]<<endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int sx = sc.nextInt();
		int sy = sc.nextInt();
		int tx = sc.nextInt();
		int ty = sc.nextInt();
		int dx = tx - sx;
		int dy = ty - sy;
		StringBuilder sb = new StringBuilder();
		for(int i = 0 ; i < dx ; i++) {
			sb.append("R");
		}
		for(int i = 0 ; i < dy ; i++) {
			sb.append("U");
		}
		for(int i = 0 ; i < dx ; i++) {
			sb.append("L");
		}
		for(int i = 0 ; i < dy ; i++) {
			sb.append("D");
		}
		sb.append("D");
		for(int i = 0 ; i < dx + 1 ; i++) {
			sb.append("R");
		}
		for(int i = 0 ; i < dy + 1 ; i++) {
			sb.append("U");
		}
		sb.append("LU");

		for(int i = 0 ; i < dx + 1 ; i++) {
			sb.append("L");
		}
		for(int i = 0 ; i < dy + 1 ; i++) {
			sb.append("D");
		}
		sb.append("R");
		System.out.println(sb.toString());
	}
}


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

int N,K;
vector<int> V;

int main()
{
    scanf("%d%d",&N,&K);
    if(N % 2 == 0)
    {
        for(int i = 0; i < K; i++)
        {
            if(i != 0)printf(" ");
            printf("%d",i == 0 ? N / 2 : N);
        }
        printf("\n");
        return 0;
    }

    for(int i = 0; i < K; i++)V.push_back((N + 1) / 2);

    for(int i = 0; i < K / 2; i++)
    {
        if(V[V.size() - 1] == 1)V.pop_back();
        else
        {
            V[V.size() - 1]--;
            while(V.size() != K)V.push_back(N);
        }
    }
    for(int i = 0; i < V.size(); i++)
    {
        if(i != 0)printf(" ");
        printf("%d",V[i]);
    }
    printf("\n");
    return 0;
}



Measured memory_bytes: 3568
#include<iostream>

int main(){
    int A,B;
    int count = 0;
    std::cin >> A >> B;

    for(int i = A ; i <= B; i++){
        int num = i;
        if(num/10000 == num % 10){
            if((num/1000%10) == num/10%10) count++;
        }
    }
    std::cout << count << "\n";
}

Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<numeric> //xとyの最大公約数は__gcd(x,y),xとyの最小公倍数は(x*y)/__gcd
typedef long long ll;
#define rep(i,n) for(ll i=0; i<n; i++)
#define vll vector<ll>
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
using namespace std;

int main(){
  int n,x,ans=0;
  cin >> n >> x;
  vi l(n);
  rep(i,n){
    cin >> l[i];
  }
  vi d(n+1);
  d[0] = 0;
  rep(i,n+1){
    if(d[i] <= x){
      d[i+1] = d[i] + l[i];
      ans++;
    }else{
      break;
    }
  }
  cout << ans;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    char S[50];
    gets(S);

    if(S[0]=='S')
    {
        printf("Cloudy\n");
    }

   else if(S[0]=='R')
    {
        printf("Sunny\n");
    }

    else if(S[0]=='C')
    {
        printf("Rainy\n");
    }
}

Measured memory_bytes: 128
extern crate proconio;
use proconio::input;

fn main() {
    input! {
        n: usize,
        k: usize,
        a: [i64; n],
    }
    for i in k..n {
        println!("{}", if a[i - k] < a[i] { "Yes" } else { "No" });
    }
}


Measured memory_bytes: 5632
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define F first
#define S second
#define forn(i, n) for (int i = 0; i < (int)n; i++)
#define pb push_back
#define fastIO ios::sync_with_stdio(0), cin.tie(0);
#define endl '\n'
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> pii;
int n, m;
bool ok(int i, int j) {
    return i >= 0 && i < n && j >= 0 && j < m;
}
int main() {
#ifdef LOCAL
    // freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
#else
    fastIO;
#endif

    cin >> n >> m;
    char mat[n][m];
    forn(i, n) {
        string s;
        cin >> s;
        forn(j, sz(s)) {
            mat[i][j] = s[j];
        }
    }
    forn(i, n) {
        forn(j, m) {
            int cnt = 0;
            if (mat[i][j] == '.') {
                for (int x = -1; x <= 1; x++) {
                    for (int y = -1; y <= 1; y++) {
                        if (ok(i + x, j + y) && mat[i + x][j + y] == '#') {
                            cnt++;
                        }
                    }
                }
                mat[i][j] = cnt + '0';
            }
        }
    }
    forn(i, n) {
        forn(j, m) {
            cout << mat[i][j];
        }
        cout << endl;
    }
    return 0;
}

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

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

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

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout<<setprecision(32);

	int n, h, w;
	cin>>h>>w>>n;
	map<pair<int, int>, int> mp;
	for(int i = 0; i < n; i++){
		int x, y;
		cin>>x>>y;
		x--; y--;
		mp[{x, y}]++;
		for(int k = 0; k < 8; k++){
			int nx = x + dx[k];
			int ny = y + dy[k];
			if(nx >= 0 && nx < h && ny >= 0 && ny < w)mp[{nx, ny}]++;
		}
	}
	ll tot = 0;
	vector<ll> cnt(10, 0);
	for(auto pp : mp){
		int x = pp.first.first;
		int y = pp.first.second;
		if(x > 0 && x + 1 < h && y > 0 && y + 1 < w){
			cnt[pp.second]++;
			tot++;
		}
	}
	cnt[0] = (h - 2)*1LL*(w - 2) - tot;
	for(auto &x : cnt){
		cout<<x<<'\n';
	}

	return 0;
}

Measured memory_bytes: 56576
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int n,i,j;
	int a,b,data[100001];
	int min,ban;
	while(1){
		for(i=1;i<=100000;i++) data[i]=0;
		cin>>n;
		if(n==0) break;
		for(i=0;i<n;i++){
			cin>>b;
			for(j=0;j<8;j++){
				cin>>a;
				if(j%2==0) data[b]+=a*60;
				else data[b]+=a;
			}
		}
		for(i=0;i<2;i++){
			min=100000000;
			for(j=1;j<=100000;j++){
				if(data[j]!=0 && min>data[j]) {
					ban=j;
					min=data[j];
				}
			}
			cout<<ban<<endl;
			data[ban]=0;
		}
		for(i=0;i<2;i++){
			min=0;
			for(j=1;j<=100000;j++){
				if(data[j]!=0 && min<data[j]) {
					ban=j;
					min=data[j];
				}
			}
			data[ban]=0;
		}
		cout<<ban<<endl;
	}
	return 0;
}

Measured memory_bytes: 3468
#include <iostream>
#include <vector>
#include <iomanip>
#include <stack>
#include <array>
#include <deque>
#include <forward_list>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iterator>
#include <string>
#include <cstring>
#include <fstream>
#include <random>
#include <time.h>
#include <complex>
#include <cmath>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n;i>0;i--)
#define arep(a,i,n) for(int i=(a);i<(n);i++)
#define SORT(v) sort((v).begin(),(v).end())
#define TEMP(type,x,y) do {temp temp=x,x=y,y=temp}while(0)
const ll INF = (1LL << 50);

int main() {

	int N;
	ll M;
	cin >> N >> M;

	int ans = 1;
	for (int A = 1; A*A < M; A++) {//約数のペアのうち、片方を列挙する
		if (M%A != 0) continue;//Mの約数でないならば処理をしない
		int B = M / A;//もう片方の約数

		if ((ll)A*N <= M) ans = max(ans, A);
		if ((ll)B*N <= M) ans = max(ans, B);
	}

	cout << ans << endl;

	return 0;

}

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

public class Main
{
	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
		for(;;)
		{
			int N = sc.nextInt();
			if (N == 0) break;
			
			boolean[][] ok = new boolean[N][31];
			for (int i = 0; i < N; i++)
			{
				int f = sc.nextInt();
				for (int j = 0; j < f; j++)
				{
					int d = sc.nextInt();
					ok[i][d] = true;
				}
			}
			
			long[] map = new long[N];
			long all = 0;
			for (int i = 0; i < N; i++)
			{
				all |= (map[i] = 1L << i);
			}
			
			int day = -1;
			for (int d = 1; d <= 30; d++)
			{
				for (int n1 = 0; n1 < N; n1++)
				{
					for (int n2 = 0; n2 < N; n2++)
					{
						if (n1 == n2) continue;
						if (ok[n1][d] && ok[n2][d])
						{
							map[n1] = map[n2] = (map[n1] | map[n2]);
							if (map[n1] == all)
							{
								day = d;
							}
						}
					}
				}
				if (day != -1) break;
			}
			System.out.println(day);
		}
	}
}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
#define int long long
using namespace std;
int32_t main() {

    int n,i,max1,ans=0;
    cin >> n;
    int arr[n];
    for(i=0;i<n;i++)
        cin >> arr[i];
    max1=arr[0];
    for(i=1;i<n;i++)
    {
        if(arr[i]<max1)
            ans=ans+max1-arr[i];
        else
            max1=max(max1,arr[i]);
    }
    cout << ans;

}


Measured memory_bytes: 5148
#include <math.h>
#include <stdio.h>
#include <algorithm>
using namespace std;

int main() {
    double x1, x2, x3, x4, y1, y2, y3, y4, ansx, ansy;
    int    q;
    scanf("%d", &q);

    for (int i = 0; i < q; i++) {
        scanf("%lf %lf %lf %lf %lf %lf %lf %lf", &x1, &y1, &x2, &y2, &x3, &y3,
              &x4, &y4);
        ansx = ((x2 - x1) * (y3 * (x4 - x3) + x3 * (y3 - y4)) -
                (x4 - x3) * (y1 * (x2 - x1) + x1 * (y1 - y2))) /
               ((y2 - y1) * (x4 - x3) - (y4 - y3) * (x2 - x1));
        if (x1 != x2) {
            ansy = ((y2 - y1) * ansx + y1 * (x2 - x1) + x1 * (y1 - y2)) /
                   (x2 - x1);
        } else {
            ansy = ((y4 - y3) * ansx + y3 * (x4 - x3) + x3 * (y3 - y4)) /
                   (x4 - x3);
        }
        printf("%.10lf %.10lf\n", ansx, ansy);
    }

    return 0;
}



Measured memory_bytes: 2736
#include <algorithm>
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;

using namespace std;

bool sub(int m, int d) {
  if (d < 10) {
    return false;
  }
  int d10 = d / 10;
  int d1 = d % 10;
  if (d10 < 2 || d1 < 2) {
    return false;
  }
  return m == (d10 * d1);
}

int main() {
  int m, d;
  cin >> m >> d;
  long count = 0;

  for (int month = 1; month <= m; month++) {
    for (int day = 2; day <= d; day++) {
      if (sub(month, day)) {
        count++;
      }
    }
  }
  cout << count << endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int nn = 1<<n;

        int[] d = new int[nn];
        Arrays.fill(d, Integer.MAX_VALUE);
        boolean[] v = new boolean[nn];

        ArrayList<K> keys = new ArrayList<>();
        for(int i=0; i<m; i++) {
            int a = sc.nextInt();
            int b = sc.nextInt();
            int mask = 0;
            for(int j=0; j<b; j++) {
                mask |= 1 << (sc.nextInt()-1);
            }
            keys.add(new K(a, mask));
        }
        Collections.sort(keys);

        int amask = 0;
        for(K k : keys) {
            amask |= k.mask;
        }
        if(amask != nn-1) {
            System.out.println(-1);
            return;
        }


        PriorityQueue<P> q = new PriorityQueue<>();
        q.add(new P(0, 0));
        d[0] = 0;
        while(!q.isEmpty()) {
            P p = q.poll();
            v[p.i] = true;
            for(K k : keys) {
                int next = p.i | k.mask;
                int nd = p.d + k.a;
                if(!v[next] && nd < d[next]) {
                    d[next] = nd;
                    q.add(new P(next, nd));
                }
            }
        }

        int res = d[nn-1];
        if(res == Integer.MAX_VALUE) {
            res = -1;
        }
        System.out.println(res);
    }

    static class P implements Comparable<P> {
        int i;
        int d;
        public P(int i, int d) {
            this.i = i;
            this.d = d;
        }
        @Override public int compareTo(P o) {
            return d - o.d;
        }
    }

    static class K implements Comparable<K>{
        int a;
        int mask;
        public K(int a, int mask) {
            this.a = a;
            this.mask = mask;
        }

        @Override public int compareTo(K o) {
            return a - o.a;
        }
    }

}




Measured memory_bytes: 34120
#include <bits/stdc++.h>
using namespace std;
string str[101];
int n,idx=0;

int cal(char ch,int a,int b){
  if(ch=='*') return a*b;
  return a+b;
}

int get_cnt(string a){
  int res=0;
  while(a[res]=='.')res++;
  return res;
}

int dfs(){
  int cnt=get_cnt(str[idx]);
  char ch=str[idx][cnt];
  if(isdigit(ch))return str[idx++][cnt]-'0';
  int res =(ch=='*');
  idx++;
  while(idx<n&&get_cnt(str[idx])>=cnt+1)res=cal(ch,res,dfs());
  return res;
}

int main(){
  while(cin>>n,n){
    for(int i=0;i<n;i++) cin>>str[i];
    idx=0;
    cout <<dfs()<<endl;
  }
  return 0;
}

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

const int INF = 1001001001;

int main(){
    int n;
    cin>>n;
    vector<int> vec1(n);
    int temp;
    int count=0;
    double sn = sqrt(n);
    for (int i = 1; i < sn; i++){
        for (int j = i; j < sn; j++){
            for (int k = j; k < sn; k++){
                temp=i*i+j*j+k*k+i*j+j*k+i*k;
                if(i<=j&&j<=k){
                    if(temp<=n){
                        if(i==j&&j==k){
                            vec1[temp-1]++;
                        }else if(i==j||j==k||k==i){
                            vec1[temp-1]+=3;
                        }else{
                            vec1[temp-1]+=6;
                        }
                    }
                }

            }
        }
    }
    rep(i,n)cout<<vec1[i]<<endl;

    return 0;
}


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

using namespace std;

typedef long long ll;

const int MAX_N = 1e5 + 5;

int N;
int a[MAX_N];
bool ok[MAX_N];

int main()
{
  //freopen("in.txt", "r", stdin);
  cin >> N;
  for (int i = 0; i < N; ++i) scanf("%d", &a[i]);
  for (int i = 0; i < N; ++i) if (a[i] != i + 1) ok[i] = true;
  int ans = 0, cnt = !ok[0] ? 1 : 0;
  ok[N] = true;
  for (int i = 0; i < N; ++i) {
    if (!ok[i + 1]) ++cnt;
    else {ans += (cnt + 1) / 2; cnt = !ok[i + 1] ? 1 : 0;}
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 768
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		if(n <= 111)System.out.println("111");
		else if(n > 111 && n <= 222)System.out.println("222");
		else if(n > 222 && n <= 333)System.out.println("333");
		else if(n > 333 && n <= 444)System.out.println("444");
		else if(n > 444 && n <= 555)System.out.println("555");
		else if(n > 555 && n <= 666)System.out.println("666");
		else if(n > 666 && n <= 777)System.out.println("777");
		else if(n > 777 && n <= 888)System.out.println("888");
		else if(n > 888 && n <= 999)System.out.println("999");
	}
}

Measured memory_bytes: 23636
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,z,w,a[2010];
    cin>>n>>z>>w;
    for(int i=1;i<=n;i++) cin>>a[i];
    if(n==1) cout<<abs(a[n]-w)<<endl;
    else cout<<max(abs(a[n]-a[n-1]),abs(a[n]-w))<<endl;
    return 0; 
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
R, G, B, N = map(int, input().split())
ans = 0

for r in range(N + 1):
  for g in range(N + 1):
    if ((N - r*R - g*G) % B == 0 and (N - r*R - g*G) / B >= 0):
      ans += 1

print(ans)


Measured memory_bytes: 42652
import sys

L, R = list(map(int, input().split()))

yy = 2019

d = 2019

if R > L+2019:
    R = L+2019

for i in range(L,R):
    im = i % yy

    for j in range(i+1, R+1):
        jm = j % yy

        if im * jm % yy <= d:
            d = im * jm % yy

print(d)


Measured memory_bytes: 3060
//#include "bits/stdc++.h"

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<complex>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

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

	int N;
	cin >> N;

	cout << (N+999)/1000*1000-N << endl;

	return 0;
}

Measured memory_bytes: 3608
#include<iostream>
#include<vector>
#include<queue>
#include<set>
// #include<unordered_set>
using namespace std;
typedef pair<int, int> pii;
int main(){
  int n, m;
  std::cin >> n >> m;
  vector<vector<pii> > g(n);
  set<pii> s;
  for (int i = 0; i < m; i++) {
    int a, b, c;
    std::cin >> a >> b >> c;
    a--, b--;
    g[a].push_back(pii(b, c));
    g[b].push_back(pii(a, c));
  }
  priority_queue<pii, vector<pii>, greater<pii> > que;

  for (int i = 0; i < n; i++) {
    vector<int> cost(n, 1e9);
    vector<int> parent(n, -1);
    que.push(pii(0, i));
    while(not que.empty()){
      int v = que.top().second;
      int c = que.top().first;
      que.pop();
      for (int i = 0; i < g[v].size(); i++) {
        int to = g[v][i].first;
        if(cost[to] > c + g[v][i].second){
          cost[to] = c + g[v][i].second;
          que.push(pii(cost[to], to));
          parent[to] = v;
        }
      }
    }
    for (int j = 0; j < n; j++) {
      if(i == j)continue;
      s.insert(pii(j, parent[j]));
      s.insert(pii(parent[j], j));
    }
  }
  std::cout << m - s.size()/2 << std::endl;
  return 0;
}


Measured memory_bytes: 384
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <algorithm>
#include <functional>
#include <utility>
#include <numeric>
#include <set>

using namespace std;
using ll = long long;

typedef pair<ll, ll> P;

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


// LRUD
const int dx[4] = {-1, 1, 0, 0};
const int dy[4] = {0, 0, -1, 1};
// const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
// const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

vector<vector<int> > vvi;
vector<vector<vector<int> > > vvvi;

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

int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }

int main(int argc, char**argv){
    int n;
    cin >> n;
    vector<int> h(n);
    for (int i = 0; i < n; i++){
        cin >> h[i];
    }

    int ans = 0;
    // int min = *std::min_element(h.begin(), h.end());
    // ans += min;
    // cout << "min: " << min << endl;

    vector<int> f(n, 0);
    while (true){
        int i;
        for (i = 0; i < n; i++){
            if (h[i] != f[i]) break;
        }
        if (i == n){
            cout << ans << endl;
            return 0;
        }

        int l_idx = 0;
        while (h[l_idx] == f[l_idx]) l_idx++;
        int r_idx = l_idx;
        while (l_idx < n && r_idx < n){
            while (h[r_idx] > f[r_idx]) r_idx++;
            for (int i = l_idx; i < r_idx; i++){
                f[i]++;
            }
            ans++;

            while (h[l_idx] == f[l_idx]) l_idx++;
            r_idx = l_idx;
        }
    }

    return 0;
}


















Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
ll GetDigit(ll num){ return log10(num)+1; } //numの桁数を求める

int main()
{
    int a,b,c;
    cin >> a >> b >> c;
    if(2*b == a+c) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 3600
N, M = map(int, input().split())
A = [0] * N
B = [0] * N
for i in range(N):
    A[i], B[i] = map(int, input().split())
A, B = zip(*sorted(zip(A, B)))

n = 0
ans = 0
i = 0

while n != M:
    if n + B[i] > M:
        ans += (M - n) * A[i]
        n = M
    else:
        ans += A[i] * B[i]
        n += B[i]
    i += 1
print(ans)

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

using namespace std;
#define deb(x) cout << #x << ": " << x << endl
#define fo(i, n) for (ll i = 0; i < n; i++)
#define fkn(i, k, n) for (i = k; i < n; i++)
#define ll long long
#define F first;
#define S second;
#define PB(x) push_back(x);
#define MP(x,y) make_pair(x,y);
typedef vector<ll> vll;

bool powerOfTwo(ll x)
{
    return !(x & (x - 1));
}


int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); 
    ll a;
    cin>>a;
    ll x = a*a;
    cout << a + (x * a)+x <<endl;
    
    
   
}




Measured memory_bytes: 3588
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <utility>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;

#define INF_LL (ll)1e18
#define INF (int)1e9
#define REP(i, n) for(int i = 0;i < (n);i++)
#define FOR(i, a, b) for(int i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
using ll = long long;
using PII = pair<int, int>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}


int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a, b;
	cin >> a >> b;
	cout << (a+b+1)/2 << endl;
}


Measured memory_bytes: 256
import math
# from decimal import Decimal

a, b, h, m = map(int, input().split())

minutes = h * 60 + m
# print(minutes)
min_needle_angle = minutes * 6
hour_needle_angle = minutes * 0.5

# print(min_needle_angle)

# これはなくても良さそう cos0とcos-720は値が一緒だからわざわざ整数値に直さなくてもいい
# if min_needle_angle > 360:
#     min_needle_angle %= 360 # /じゃなく% n周して余ったところを渡せばいい

# angle = max(min_needle_angle, hour_needle_angle) - min(min_needle_angle, hour_needle_angle)
angle = abs(min_needle_angle - hour_needle_angle)

# if angle > 180:
#     # angle -= 180 # angleから180を引かない
#     angle = 360 - angle # 360からangleを引く
# print(angle, 360 - angle)

angle = min(angle, 360 - angle) #こっちの方がわかりやすいかも

# print(a**2, b ** 2, 2 * a * b)
# angle = float(angle)
# cosc = Decimal(math.cos(f'{angle:.10f}'))
# cosc = round(math.cos(angle), 9)

# これを1/2乗する
# c_nijou =  a ** 2 + b ** 2 - 2 * a * b * math.cos(angle)
# print(math.radians(angle))
# print(math.cos(math.radians(angle)))
c_nijou =  a ** 2 + b ** 2 - 2 * a * b * math.cos(math.radians(angle))

print((c_nijou)**0.5)

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

int main(void){
  int n;
  scanf("%d", &n);
  int i, j, k;
  int *a = (int *)malloc(n * sizeof(int));
  int max = 0, min;
  for(i=0; i<n; i++){
    scanf("%d", a+i);
    if(max < a[i])
      max = a[i];
    if(i==0)
      min = a[0];
    else if(a[i] < min)
      min = a[i];
  }

  if(min != 1){
    printf("-1\n");
    return 0;
  }
  
  int count = 0;

  j = 0;
  k = 0;
  for(i=1; i<=max; i++){
    while(a[j] != i && j < n)
      j++;
    while(k<j){
      a[k] = 0;
      k++;
    }
    if(j == n)
      break;
    j++;
    k++;
  }

  for(i=j; i<n; i++)
    a[i] = 0;
  
  for(i=0; i<n; i++)
    if(a[i] == 0)
      count++;

  printf("%d\n", count);
  
  return 0;
  
}


Measured memory_bytes: 896
//Giorgi Kldiashvili

#include <bits/stdc++.h>

#define M 1000000007ll
#define ll long long
#define MIN(x, y) ((x) < (y) ? (x) : (y))
#define MAX(x, y) ((x) < (y) ? (y) : (x))

using namespace std;

const int N = 300020;

int n, last;
ll answer, A, B, a[N], S[N][2][2];
bool fix[N];
int C[N];

int main()
{
  scanf("%d %lld %lld", &n, &A, &B);
  if(A > B) swap(A, B);
  for(int i = 1; i <= n; ++ i)
    scanf("%lld", &a[i]);
  a[0] = -1e18;
  S[1][0][0] = S[1][1][0] = 1;
  for(int i = 1; i < n; ++ i)
    if(a[i + 1] - a[i] >= A)
      fix[i] = true;
  last = 0;
  for(int i = 1; i <= n; ++ i)
  {
    C[i] = last;
    if(!fix[i - 1])
      last = i - 1;
  }
  for(int i = 2; i <= n; ++ i)
  {
    if(a[i] - A < a[i - 2])
      return printf("0"), 0;
    if(a[i] - A >= a[i - 1])
      S[i][0][0] = (S[i - 1][0][0] + S[i - 1][0][1]) % M;
    if(a[i] - B >= a[i - 1])
      S[i][1][1] = (S[i - 1][1][1] + S[i - 1][1][0]) % M;
    int l, r;
    l = 0; r = i - 1;
    while(l < r)
    {
      int mid = l + r - 1 >> 1;
      if(a[mid] + B <= a[i])
        l = mid + 1;
      else
        r = mid;
    }
    if(l == i)
      l --;
    if(C[i] < l)
      S[i][1][0] = (S[l][0][1] + S[l][0][0]) % M;
    S[i][0][1] = (S[i - 1][1][0] + S[i - 1][1][1]) % M;
  }

  for(int i = 0; i < 2; ++ i)
    for(int j = 0; j < 2; ++ j)
      answer = (answer + S[n][i][j]) % M;

  cout << answer << endl;

}


Measured memory_bytes: 7424
#include<stdio.h>
int N, x, max;
char c;
int main(){
  scanf("%d\n", &N);
  c=getchar();
  while(c!=10){
    if(c=='I'){
      if(++x>max){max=x;}
    }else{
      x--;
    }
    c=getchar();
  }
  printf("%d\n", max);
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <cmath>

using namespace std;

bool xcmp(pair<long long int, long long int> a, pair<long long int, long long int> b) {
    if(a.first!=b.first) {
        return a.first < b.first;
    }
    return a.second < b.second;
}

bool ycmp(pair<long long int, long long int> a, pair<long long int, long long int> b) {
    if(a.second!=b.second) {
        return a.second < b.second;
    }
    return a.first < b.first;
}

int main() {
    int K, N;
    cin >> N >> K;
    vector<pair<long long int, long long int> > xy(N);
    for(int n=0; n<N; n++) {
        cin >> xy[n].first >> xy[n].second;
    }
    
    sort(xy.begin(), xy.end(), xcmp);

    long long int ans=1e9;
    ans *= ans;
    ans *= 5;
    for(int i=0; i<N; i++) {
        for(int j=i+K-1; j<N; j++) {
            vector<long long int> y;
            long long int tmpx = abs(xy[j].first-xy[i].first);
            for(int k=i; k<=j; k++) {
                y.push_back(xy[k].second);
            }
            sort(y.begin(), y.end());
            long long int tmpy;
            for(int k=0; k+K-1<y.size(); k++) {
                tmpy = abs(y[k]-y[k+K-1]);
                if(ans > tmpx*tmpy) {
                    ans = tmpx*tmpy;
                }
            }
        }
    }
    
    cout << ans << endl;

    return 0;
    
}

Measured memory_bytes: 256
def count_bit(x):
    res = 0
    while x > 0:
        res += x % 2
        x //= 2
    return res


n, m = map(int, input().split())
k = [0] * m
for i in range(m):
    x = list(map(int, input().split()))
    k[i] = sum(map(lambda l: 2**(l-1), x[1:]))
p = list(map(int, input().split()))

res = 0
for b in range(2**n):
    for i in range(m):
        x = b & k[i]
        if count_bit(x) % 2 != p[i]:
            break
    else:
        res += 1
print(res)

Measured memory_bytes: 3064