akhauriyash/Code-Regression huggingface dataset:
#include  <iostream>
#include  <stdio.h>
#include <algorithm>
#include <map>
#include <math.h>

using namespace std;
#include <vector>
#define rep(i,n) for (ll i = 0; i < (n) ; i++)
#define INF 1e9
#define llINF 1e18
#define base10_4 10000      //1e4
#define base10_5 100000     //1e5
#define base10_6 1000000    //1e6
#define base10_7 10000000   //1e7
#define base10_8 100000000  //1e8
#define base10_9 1000000000 //1e9

#define MOD 1000000007
#define pb push_back
#define ll long long
#define ull unsigned long long
#define vint vector<int>
#define vll vector<ll>

//#include <stack>
//#include <queue>

string ans_Yes = "Yes"; 
string ans_No = "No"; 
string ans_yes = "yes"; 
string ans_no = "no"; 

ll A;
ll B;
ll C;
ll N;
ll M;
ll K;

ll ltmp;
string stmp;
double dtmp;

int main(){

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


    cin >> A;

    ll ans = 1;
    if(A==1) cout << ans << endl;
    else{
        ll cnt = 0;
        ll base = 1;
        while(A>0){
            cnt+=base;
            base*=2;
            A = A/2;
        }

        cout << cnt << endl;



    }
    

}

Measured memory_bytes: 256
def dfs(depth):
    if depth == N:
        ans.append(cal(v))
        return
    for i in range(4):
        v[depth] = i
        dfs(depth+1) 

def cal(v):
    tmp = [0] * 3 
    for i in range(N):
        if v[i] == 0:
            tmp[0] += l[i]
        elif v[i] == 1:
            tmp[1] += l[i]
        elif v[i] == 2:
            tmp[2] += l[i]
    cnt = 0
    if v.count(0) > 1:
        cnt += v.count(0) - 1
    if v.count(1) > 1:
        cnt += v.count(1) - 1
    if v.count(2) > 1:
        cnt += v.count(2) - 1

    if v.count(0) == 0 or v.count(1) == 0 or v.count(2) == 0:
        return float('inf')
    diff = cnt * 10
    for i in range(3):
        diff += abs(A[i]-tmp[i])
    
    return diff
        
    
    

N, *A= map(int, input().split())
l = [int(input()) for _ in range(N)]
v = [-1] * N

ans = []

dfs(0)
print(min(ans))

Measured memory_bytes: 62044
def resolve():
    a, b, k = map(int, input().split())
    for i in range(k):
        if i % 2 == 0:
            if a % 2:
                a -= 1
            next_b = b + a // 2
            a //= 2
            b = next_b
        else:
            if b % 2:
                b -= 1
            next_a = a + b // 2
            b //= 2
            a = next_a
    print(a, b)


if __name__ == "__main__":
    resolve()


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T> using vt = vector<T>;
template<class T> using vvt = vector<vt<T>>;
template<class T> using ttt = tuple<T,T>;
using tii = tuple<int,int>;
using vi = vector<int>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define mt make_tuple
#define ALL(a) (a).begin(),(a).end()
#define FST first
#define SEC second
#define DEB cerr<<"!"<<endl
#define SHOW(a,b) cerr<<(a)<<" "<<(b)<<endl
const int INF = (INT_MAX/2);
const ll LLINF = (LLONG_MAX/2);
const double eps = 1e-8;
//const double PI = M_PI;
inline ll pow(ll x,ll n,ll m){ll r=1;while(n>0){if((n&1)==1)r=r*x%m;x=x*x%m;n>>=1;}return r%m;}
inline ll lcm(ll d1, ll d2){return d1 / __gcd(d1, d2) * d2;}
#define chmax(a,b) a=max(a,b)

/*Coding Space*/
int main(){
  int n; cin >> n;
  priority_queue<long double,vector<long double>,greater<long double>> q;
  rep(i,n){
    long double in; cin >> in;
    q.push(in);
  }
  while(q.size() > 1){
    long double a = q.top(); q.pop();
    long double b = q.top(); q.pop();
    q.push((a+b)/2.0);
  }
  cout << fixed << setprecision(10) << q.top()<< endl;
}


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

using namespace std;

#define _overload3(_1,_2,_3,name,...) name
#define _all1(a) (a).begin(),(a).end()
#define _all2(a,n) (a),(a)+n
#define all(...) _overload3(__VA_ARGS__,_all1,_all2,)(__VA_ARGS__)
#define _rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

#define in(v) cin>>v;
#define out(v) cout<<v<<"\n"

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

  int A[N-1], B[N-1], c[N];
  bool visited[N];
  fill(all(visited, N), false);

  rep(i, N-1) {
    in(A[i]); in(B[i]);
    --A[i]; --B[i];
  }
  int sum = 0;
  rep(i, N) {
    in(c[i]);
    sum += c[i];
  }
  sort(all(c, N));
  reverse(all(c, N));
  out(sum-c[0]);
  visited[A[0]] = visited[B[0]] = true;

  int ans[N];
  ans[A[0]] = c[0];
  ans[B[0]] = c[1];
  rep(i, 1, N-1) {
    rep(j, N-1) {
      if (visited[A[j]] != visited[B[j]]) {
        if (!visited[A[j]])
          ans[A[j]] = c[i+1];
        else
          ans[B[j]] = c[i+1];
        visited[A[j]] = visited[B[j]] = true;
        break;
      }
    }
  }
  rep(i, N) {
    cout << ans[i];
    if (i + 1 != N)
      cout << " ";
  }
  cout << "\n";

  return 0;
}


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

S = [input() for _ in range(N)]

d = {}
for s in S:
    if s in d:
        d[s] += 1
    else:
        d[s] = 1

maxcount = max([d[k] for k in d])
maxlist = list(filter(lambda x: d[x] == maxcount, d))
maxlist = sorted(maxlist)
for m in maxlist:
    print(m)

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

typedef long long ll;

struct Edge {
  int from, to, cost;
  Edge() {}
  Edge(int f, int t) : cost(1), from(f), to(t) {}
  Edge(int f, int t, int c) : from(f), to(t), cost(c) {}
  friend bool operator < (const Edge& lhs, const Edge& rhs) { return lhs.cost < rhs.cost; };
  friend bool operator > (const Edge& lhs, const Edge& rhs) { return rhs < lhs; };
  friend bool operator <= (const Edge& lhs, const Edge& rhs) { return !(lhs > rhs); };
  friend bool operator >= (const Edge& lhs, const Edge& rhs) { return !(lhs < rhs); };
};

typedef vector<vector<Edge>> Graph;
Graph g(100010);

int visit[100010];
int BLACK = 1;
int WHITE = 2;

void dfs(int from, bool black) {
  if (black) {
    visit[from] = BLACK;
  }
  else {
    visit[from] = WHITE;
  }
  for (Edge& e: g[from]) { 
    if (visit[e.to] > 0) continue;
    if (e.cost % 2 == 0) { 
      dfs(e.to, black);
    }
    else {
      dfs(e.to, !black);
    }
  }
}

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n-1; ++i) {
    int u, v, w;
    cin >> u >> v >> w;
    --u; --v;
    g[u].emplace_back(u, v, w);
    g[v].emplace_back(v, u, w);
  }
  dfs(0, true);
  for (int i = 0; i < n; ++i) {
    cout << visit[i]-1 << endl;
  }
}


Measured memory_bytes: 8320
program main;
var s,a,b,c,n : longint;
function gcd(a,b :longint):longint;
var temp : longint;
begin
    repeat
    temp := b;
    b := a mod b;
    a := temp;
    until b = 0;
    gcd := a;
end;
begin
    s := 0;
    readln(n);
    for a := 1 to n do
        for b := 1 to n do
            for c := 1 to n do
                s := s + gcd(gcd(a,b),c);
    writeln(s);
end.

Measured memory_bytes: 1388
#include<stdio.h>
int main()
{
	long long a,b,c;
//	while(1)
//	{
	scanf("%lld %lld %lld",&a,&b,&c);
	if(a == b && b % c == 0)
		printf("1\n");
	else if(a == 0 && b != 0)
		printf("%lld\n",b / c + 1);
	else
		printf("%lld\n",b / c - (a - 1) / c);
//	}
	return 0;
}



Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <set>
using namespace std;

const int MAX = 300000;

int main() {
	int data[MAX+1];
	// make getuyou_doyou_suu
	for(int i=0; i<MAX+1; i++) {
		if (!(i%7 == 6 || i%7 == 1))
		data[i] = 1;
		else data[i] = 0;
	}
	data[0]=1; data[1]=1;
	for(int i=0; i<MAX+1; i++) {
		if (!data[i]) {
			for (int j=i*2; j<MAX+1; j+=i)
				data[j] = 1;
		}
	}
	while (1){
		// input
		int n;
		scanf("%d", &n);
		if (n == 1) break;
		set<int> Ans;
		for(int i = 0; i < n+1; i++)
			if (!data[i] && n % i == 0) {
				Ans.insert(i);
			}
		// output
		set<int>::iterator S=Ans.begin();
		printf("%d:", n);
		while( S != Ans.end()) {
			printf(" %d", *S);
			S++;
		}
		printf("\n");
	}
}

Measured memory_bytes: 2364
#include <bits/stdc++.h>
#ifdef _WIN32
#include "debug.hpp"
#endif
using namespace std;

#define rep(i, N)  for(int i = 0; i < (N); i++)
#define reps(i, N) for(int i = 1; i <= (N); i++)
#define repr(i, N) for(int i = (N) - 1; i >= 0; i--)
#define pub push_back

template<typename T> 
void chmax(T &a, T b){ a = max(a, b); };
template<typename T> 
void chmin(T &a, T b){ a = min(a, b); };

typedef long long ll;
typedef pair<int, int> P;
const int INF = 100000000;
const ll LINF = 10000000000000000;
const int MOD = 1000000007;
const int dx[9] = { 0, 1,  0, -1, 1,  1, -1, -1, 0};
const int dy[9] = { 1, 0, -1,  0, 1, -1, -1,  1, 0};
//--------------------------------------//
int N;
int a[200000];
void solve(){
	ll g = 0;
	reps(i, N - 1)
		g += a[i];
	ll h = a[0];
	ll ans = abs(h - g);
	reps(i, N - 2){
		h += a[i];
		g -= a[i];
		chmin(ans, abs(h - g));
	}
	cout << ans << endl;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> N;
	rep(i, N) {
		cin >> a[i];
	}
		solve();
	return 0;
}


Measured memory_bytes: 1024
/* --- author: dxm --- */
#include<bits/stdc++.h>
using namespace std;

#define INF 1e9
#define Inf 1e18
#define rep(i,n) for(int (i)=0;(i)<n;i++)
#define REP(i,n) for(int (i)=1;(i)<=n;i++)
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define fst first
#define snd second
typedef long long ll;
inline void Fail(){printf("0");exit(0);}

const int maxn=4005;
int n;
int dp[maxn][maxn],sum[maxn][maxn][2],a[maxn],c[maxn],pos[maxn][2],pos1[maxn][2],suf[maxn][maxn][2];
char s[2];

int main(){
	scanf("%d",&n);
	REP(i,2*n){
		scanf("%s%d",s,&a[i]);
		c[i]=s[0]=='W'?0:1;
		pos[a[i]][c[i]]=i;
	}
	REP(i,n)rep(j,2){
		for(int k=pos[i][j]+1;k<=2*n;k++)if(a[k]<i&&c[k]==j)pos1[i][j]++;
	}
	for(int i=2*n;i>=1;i--){
		REP(j,n)rep(k,2)suf[i][j][k]=suf[i+1][j][k];
		for(int j=a[i];j<=n;j++)suf[i][j][c[i]]++;
	}
	rep(i,2*n+1)rep(j,n+1)dp[i][j]=INF;
	dp[0][0]=0;
	rep(i,2*n)rep(j,n+1){
		int cur=dp[i][j];
		if(cur==INF)continue;
		int w=j,b=i-j;
		if(b<0)continue;
		if(w<n)dp[i+1][w+1]=min(dp[i+1][w+1],cur+pos[w+1][0]+pos1[w+1][0]+suf[pos[w+1][0]][b][1]-(i+1));
		if(b<n)dp[i+1][w]=min(dp[i+1][w],cur+pos[b+1][1]+pos1[b+1][1]+suf[pos[b+1][1]][w][0]-(i+1));
	}
	printf("%d",dp[2*n][n]);
	return 0;
}

/*
Input:
-----------------
Output:
*/

Measured memory_bytes: 189952
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    ll i,j,m,n,a,b,l,count=0,t,k;
    cin>>t;
    ll arr[t+10];
    for(i=0;i<t;i++)  cin>>arr[i];

    for(i=0;i<t-2;i++)
    {
        for(k=i+1;k<t-1;k++)
        {

        for(j=k+1;j<t;j++)
        {
            if(arr[i]==arr[k]||arr[i]==arr[j]||arr[k]==arr[j])
            {
                continue;
            }
           else if((arr[i]+arr[k]>arr[j])&&arr[i]+arr[j]>arr[k]&&arr[j]+arr[k]>arr[i])
           {
               //cout<<arr[i]<<" "<<arr[k]<<" "<<arr[j]<<endl;
               count++;
           }
        }

        }
    }
    cout<<count<<endl;






}


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

bool qry(int x , int y){cout << "? " << x - 1 << ' ' << y - 1 << endl; char c; cin >> c; return c == 'Y';}

int main(){
	int A , B; cin >> A >> B;
	if(A <= B) cout << "Impossible" << endl;
	else{
		stack < int > stk;
		for(int i = 1 ; i <= A + B ; ++i) if(stk.empty() || qry(stk.top() , i)) stk.push(i); else stk.pop();
		static char str[4003]; for(int i = 1 ; i <= A + B ; ++i) str[i] = qry(stk.top() , i) + '0';
		cout << "! "; for(int i = 1 ; i <= A + B ; ++i) cout << str[i];
		cout << endl;
	}
	return 0;
}


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

int main() {
    int n;
    cin >> n;
    int longest = 0;
    int sum = 0;
    for (int i = 0; i < n; ++i) {
        int l;
        cin >> l;
        longest = max(longest, l);
        sum += l;
    }
    cout << (2 * longest < sum ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll n,ans,sum,a[200010],mod=1000000007;
ll p(ll x,ll y)
{
    if(y==0)
    {
        return 1;
    }
    ll ret=1;
    if(y%2)
    {
        ret*=x;
    }
    ll tem=p(x,y/2);
    ret*=tem;
    ret%=mod;
    ret*=tem;
    ret%=mod;
    return ret;
}
int main()
{
    scanf("%lld",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%lld",a+i);
        ans+=mod;
        ans-=(a[i]*a[i])%mod;
        sum+=a[i];
        sum%=mod;
    }
    ans+=sum*sum;
    ans%=mod;
    ans*=p(2,mod-2);
    ans%=mod;
    printf("%lld",ans);
}


Measured memory_bytes: 5388
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MX=1e2+5;

bool chk[MX][MX][MX];
int cnt[MX*MX];

void add(int x, int y, int z){
     int sm=x*x+y*y+z*z+x*y+x*z+y*z;
     if(sm<MX*MX && !chk[x][y][z]){
          chk[x][y][z]=1;
          cnt[sm]++;
     }
}

int main(){
     int i, j, k;
     int n;
     cin >> n;
     for(i=1; i<=100; ++i){
          for(j=1; j<=100; ++j){
               for(k=1; k<=100; ++k){
                    add(i, j, k);
               }
          }
     }
     for(i=1; i<=n; ++i){
          cout << cnt[i] << endl;
     }
}


Measured memory_bytes: 4564
N=int(input())
A=list(map(int,input().split()))
a=0
b=0
for num in A:
    if num%2==1:
        a+=1
    elif num%4==0:
        b+=1

if N%2==1:
    if a>b+1:
        print('No')
    else:
        print('Yes')
else:
    if a<=b:
        print('Yes')
    else:
        print('No')

Measured memory_bytes: 20108
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<stack>
#include<vector>
#include<queue>
#include<set>
#include<algorithm>
const int N = 1e9;
const int M = 1e9;
using namespace std;
#define INF 0x3f3f3f3f
#define e  2.718281828459045
#define PI acos(-1)
#define lowbit(x) (x&(-x))
#define memset(x,y) memset(x,y,sizeof(x))
#define ll long long
int book[4];
int main(){
	int a,b;
	cin >> a >> b;
	book[a]=1,book[b]=1;
	for(int i=1;i<=3;i++){
		if(book[i]==0){
			printf("%d\n",i);
			break;
		}
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h> 
#define Rg register 
#define IL inline  
#define Debug cout << " ----- " << endl ;  
using namespace std ; 
const int N = 3e4 + 5 ;  
int n , tot , sum , col[N] , dfn[N] , low[N] , top , sta[N] , pos[N] , block ; 
vector <int> v[N] ; bool In[N] ; 
struct node { int whe , id ; } a[N] ; 
bool cmp ( node A , node B ) { return A.whe < B.whe ; } 
IL void add( Rg int x , Rg int y ) { v[x].push_back(y) ; } 
IL int op ( Rg int x ) { return x % 2 == 0 ? x-1 : x+1 ; }   
IL int Sch ( Rg int Val ) { 
    Rg int l = 1 , r = (n<<1) , mid , Ans = 0 ; 
    if( Val <= a[l].whe ) return l ;  
    if( Val >= a[r].whe ) return r ; 
    while( l <= r ) { 
    	mid = l+r >> 1 ; 
    	if( Val <= a[mid].whe ) Ans = mid , r = mid - 1 ; 
		  else l = mid+1 ;  
	} 
	return Ans ; 
} 
IL void tarjan( Rg int x ) { 
	In[x] = 1 ; dfn[x] = low[x] = ++ tot ; sta[++top] = x ;  
	for(Rg int i=0 ; i<v[x].size(); i++) { 
		int u = v[x][i] ; 
		if( !dfn[u] ) tarjan( u ) , low[x] = min( low[x] , low[u] ) ; 
		  else if( In[u] ) low[x] = min( low[x] , dfn[u] ) ;  
	} 
	if( dfn[x] == low[x] ) { 
	     sum ++ ; int per = sta[top] ;  
	     while( per != x ) 
	         col[per] = sum , In[per] = 0 , per = sta[--top] ; 
		 col[x] = sum , In[x] = 0 , top -- ;  
	} 
} 
void Build( int fro , int x , int y ) { 
    if( x > y ) return ; int l = pos[x] , r = pos[y] ; 
	if( l == r ) { for(Rg int i=x; i<=y; i++) add( fro , op(a[i].id) ) ; return ; } 
	for(Rg int i=x; i<=l*block; i++) add( fro , op(a[i].id) ) ; 
	for(Rg int i=l+1; i<r; i++) add( fro , i+(n<<1) ) ;  
	for(Rg int i=(r-1)*block+1 ; i<=y; i++) add( fro , op(a[i].id) )  ; 
} 
bool check( int H ) { 
    for(Rg int i=1; i<=(n<<1)+pos[n] ; i++) col[i] = dfn[i] = low[i] = 0 ; 
    for(Rg int i=1; i<=(n<<1)+pos[n] ; i++) v[i].clear( ) ; 
    for(Rg int i=1; i<=(n<<1) ; i++) v[(n<<1)+pos[i]].push_back(op(a[i].id)) ; 
    tot = sum = top = 0 ; int l , r ; 
    for(Rg int i=1; i<=(n<<1) ; i++) {  
        l = Sch( a[i].whe-H+1 ) ; r = Sch( a[i].whe+H ) ; 
        Build( a[i].id , l , i-1 ) ; Build( a[i].id , i+1 , r-1 ) ; 
	} 
	for(Rg int i=1; i<=(n<<1); i++) if( !dfn[i] ) tarjan(i) ; 
	for(Rg int i=1; i<=n; i++) if( col[a[i].id] == col[op(a[i].id)] ) return 0 ; 
	return 1 ; 
} 
signed main() { 
    ios::sync_with_stdio(false) ; 
    cin.tie(0) ; cout.tie(0) ; 
    cin >> n ; 
    for(Rg int i=1; i<=n; i++) 
      cin >> a[(i<<1)-1].whe >> a[i<<1].whe , 
       a[(i<<1)-1].id = (i<<1) - 1 , a[i<<1].id = ( i<<1 ) ; 
    sort( a+1 , a+(n<<1)+1 , cmp ) ; 
    block = sqrt( n << 1 ) ; 
    for(Rg int i=1; i<=(n<<1); i++) pos[i] = (i-1)/block+1 ; 
    Rg int l = 1 , r = a[n<<1].whe - a[1].whe , mid , Ans = 0  ;  
    while( l <= r ) { 
    	mid = l+r >> 1 ; 
    	if( check(mid) ) Ans = mid , l = mid+1 ; 
    	  else r = mid-1 ; 
	}  
	cout << Ans << '\n' ;
	return 0 ; 
} 

Measured memory_bytes: 83968
use std::io;

fn main() {
	let mut buf = String::new();
	io::stdin().read_line(&mut buf).expect("error in K");
	let K: u32 = match buf.trim().parse()
	{
		Ok(num) => num,
		Err(_) => panic!("can't parse K"),
	};
	let mut buf = String::new();
	io::stdin().read_line(&mut buf).expect("error in A");
	
	let mut iter = buf.split_whitespace();
	
	let A:u32 = match iter.next().unwrap().parse()
	{
		Ok(num) => num,
		Err(_) => panic!("can't parse A"),
	};
	let B:u32 = match iter.next().unwrap().parse()
	{
		Ok(num) => num,
		Err(_) => panic!("can't parse B"),
	};
	let C = B - A + 1;
	let mut number = 0;
	while number != C{
		if (A + number)%K == 0 {
			println!("OK");
			break;
		}
		number = number + 1;
	}
	if A + number == B + 1 {
		println!("NG");
	}
	//println!("{}, {}, {}", K, A, B);
}

Measured memory_bytes: 2156
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <queue>
#include <bitset>
#include <random>
#include <stack>
#include <deque>
#include <chrono>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef pair<int,int> pii;
#define REP(i, a, b) for (int i = int(a); i <= int(b); i++)
#define REPb(j, d, c) for (int j = int(d); j >= int(c); j--)
#define ff first
#define ss second
#define pb push_back
#define len(x) int((x).size())

int p = 1e9 + 7;
int dp[1001][1001];
bool square_type[1001][1001];

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	//ifstream cin("input.txt");
	//ifstream cin("test.in");
	//ofstream cout("test.out");

	dp[1][1]=1;

	int h,w;
	cin>>h>>w;

	REP(i,1,h)
	{
		string s;
		cin>>s;

		REP(j,1,w)
		{
			if(s[j-1]=='.') square_type[i][j]=1;
			//if(s[j-1]=='#')
		}
	}

	REP(i,1,h)
	{
		REP(j,1,w)
		{
			if(square_type[i][j])
			{
				dp[i][j] += dp[i-1][j];
				dp[i][j] += dp[i][j-1];
				dp[i][j] %= p;
			}
		}
	}

	cout << dp[h][w] << endl;

	return 0;
}

Measured memory_bytes: 5120
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
priority_queue<ll>p,q;
ll n,a[300000],s[100001],t[100001],ans=-(1LL<<60);
int main(void){
 cin>>n;
 for(ll i=0;i<3*n;i++){
  cin>>a[i];
  if(i<n){
   s[0]+=a[i];
   p.push(-a[i]);
  }
  if(n<=i&&i<2*n){
   s[i-n+1]+=a[i]+s[i-n];
   p.push(-a[i]);
   s[i-n+1]+=p.top();
   p.pop();
  }
  if(i>=2*n&&i<3*n){
   t[0]+=a[i];
   q.push(a[i]);
  }
 }
 for(ll i=1;i<=n;i++){
  t[i]+=t[i-1]+a[2*n-i];
  q.push(a[2*n-i]);
  t[i]-=q.top();
  q.pop();
 }
 for(ll i=n;i>=0;i--){
  ans=max(ans,s[i]-t[n-i]);
 }
 cout<<ans<<endl;
}


Measured memory_bytes: 5876
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define SIZE 200005
#define INF 1000000005LL
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

int main(){

    ll n;
    cin >> n;

    vector<ll> data(n);
    vector<ll> sum(n);
    rep(i,0,n){
        ll a;
        cin >> a;
        a%= MOD;
        data[i]=a;
        if(i==0){
            sum[i]=a;
        }else{
            sum[i]=(sum[i-1]+a)%MOD;
        }
    }
    ll ans = 0;
    rep(i,0,n){
        ll kake = (sum[n-1]-sum[i]+MOD)%MOD;
        ans += (data[i]%MOD*kake)%MOD;
    }
    ans%=MOD;
    cout<<ans<<endl;
    

    return 0;
}


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

using namespace std;

string s;
string cm;
int n,k;

int main()
{
	cin >> n >> k;
	cin >> s;
	cm=s[0];
	for(int i=1;i<s.size();i++)
	{
		if(s[i]==cm.back()) continue;
		cm+=s[i];
	}
	int curans=n-cm.size();
	curans=min(n-1,2*k+curans);
	cout << curans << endl;
}

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

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

Node root;

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

Node treeMaximum(Node x)
{
    while (x->right != NIL) x = x->right;
    return x;
}

Node treeSearch(Node x, int k)
{
    if (x == NIL || k == x->key) return x;
    if (k < x->key) return treeSearch(x->left, k);
    else return treeSearch(x->right, k);
}

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

//void treeDelete(Node z){
//  Node y; // node to be deleted
//  Node x; // child of y
//
//
//
//}

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

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

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


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

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

  return EXIT_SUCCESS;
}


Measured memory_bytes: 20532
# from line_profiler import LineProfiler
from collections import deque

def main():
    while(True):
        W, H = map(int, input().split())
        if not W: break
        tx,ty = map(int, input().split())
        kx,ky = map(int, input().split())
        ma = [[False]*(W+2) for _ in range(H+2)]
        for i in range(1,H+1):
            for j,a in enumerate(input().split()):
                ma[i][j+1] = bool(1-int(a))
        que = deque([[tx,ty,kx,ky,0]])
        pas = set()
        ans = "NA"
        while(que):
            tx,ty,kx,ky,c = que.popleft()
            if c > 100: break
            if tx == kx and ty == ky:
                ans = c
                break
            for dx,dy in [[-1,0],[0,-1],[1,0],[0,1]]:
                tdx, tdy = [ dx, dy] if ma[ty+dy][tx+dx] else [0,0]
                kdx, kdy = [-dx,-dy] if ma[ky-dy][kx-dx] else [0,0]
                if (tx+tdx,ty+tdy,kx+kdx,ky+kdy) in pas: continue
                que.append([tx+tdx,ty+tdy,kx+kdx,ky+kdy,c+1])
                pas.add((tx+tdx,ty+tdy,kx+kdx,ky+kdy))
        print(ans)

if __name__ == "__main__":
    # prf = LineProfiler()
    # prf.add_function(main)
    # prf.runcall(main)
    # prf.print_stats()
    main()


Measured memory_bytes: 35196
#include <iostream>

using namespace std;

int main() {
    int n;
    cin >> n;
    double p_o;
    p_o = (double(n) + 1)/(double(n) * 2);
    if(int(n) % 2 == 0){
        cout << 0.5 << endl;
    }else{
        cout << p_o << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph= vector<vector<int>>; 
#define rep(i,n) for (ll i=0; i < (n); ++i)
#define rep2(i,n,m) for(ll i=n;i<=m;i++)
#define rep3(i,n,m) for(ll i=n;i>=m;i--)
#define pb push_back
#define eb emplace_back
#define ppb pop_back
const ll INF=1e18 ;
inline void chmax(ll& a,ll b){a=max(a,b);}
inline void chmin(ll& a,ll b){a=min(a,b);}
int main(){
ll n; cin>> n ;
  
  map<ll,int> ord;  //素因数とオーダーをマップで管理
    for(ll i=2;i*i<n;i++){
        if(n%i==0){
            int res=0;
            while(n%i==0){
                n/=i;
                res++;
            }
            ord[i]=res;
        }
    }
if(n!=1) ord[n]++;
  int ans=0 ; 
   for(auto pr:ord){
     for(int i=1 ;i<10;i++){
        if(i*(i+1)/2>pr.second){
          ans+=i-1 ;
          break ;
        }

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

Measured memory_bytes: 3604
STDIN.gets
alist = []
nums = {}

STDIN.gets.split.each do |a|
  a = a.to_i
  alist << a
  nums[a] ||= 0
  nums[a] += 1
end
  
all = 0
nums.each do |_, v|
  all += (v * (v - 1) / 2)
end
  
alist.each do |a|
  puts all - (nums[a] - 1)
end


Measured memory_bytes: 28676
N,M = map(int,input().split())
ab = [list(map(int,input().split())) for _ in range(N)]
cd = [list(map(int,input().split())) for _ in range(M)]

for i in range(N):
  dist = float("inf")
  ans = 0
  a,b = ab[i][0],ab[i][1]
  
  for j in range(M)[::-1]:
    c,d = cd[j][0],cd[j][1]
    if abs(a-c) + abs(b-d) <= dist:
      dist = abs(a-c) + abs(b-d)
      ans = j + 1
  
  print(ans)

Measured memory_bytes: 9144
#include <bits/stdc++.h>
#define va first
#define vb second
#define lb lower_bound
#define pb push_back
#define all(v) v.begin(),v.end()
#define fio ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;
using ll = long long;
using lf = long double;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

char buf[404][404];
int h, w;
inline int e(int i, int j){
    return (i-1) * w + j;
}
int bz[404*404], wz[404*404];
int rep[404*404];
const int dr[4] = {1,0,-1,0}, dc[4] = {0,1,0,-1};

int f(int x){return x == rep[x] ? x : rep[x] = f(rep[x]);}
void c(int x, int y){
    x = f(x); y = f(y);
    if(x == y) return;
    bz[x] += bz[y];
    wz[x] += wz[y];
    rep[y] = x;
}

int main(){
    fio;
    cin >> h >> w;
    for(int i = 1; i <= h; i++) cin >> buf[i] + 1;
    iota(rep,rep+h*w+1,0);
    for(int i = 1; i <= h; i++){
        for(int j = 1; j <= w; j++){
            if(buf[i][j] == '#') ++bz[e(i,j)];
            else ++wz[e(i,j)];
        }
    }
    for(int i = 1; i <= h; i++){
        for(int j = 1; j <= w; j++){
            for(int d = 0; d < 4; d++){
                int ni = i + dr[d], nj = j + dc[d];
                if(buf[i][j] != buf[ni][nj] && buf[i][j] + buf[ni][nj] == '#' + '.'){
                    c(e(i,j), e(ni,nj));
                }
            }
        }
    }
    ll ans = 0;
    for(int i = 1; i <= h; i++){
        for(int j = 1; j <= w; j++){
            if(f(e(i,j)) == e(i,j)) ans += ll(bz[e(i,j)]) * wz[e(i,j)];
        }
    }
    cout << ans << '\n';
}

Measured memory_bytes: 2304
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template < typename T > using oset = tree < T, null_type, less < T >, rb_tree_tag, tree_order_statistics_node_update >;
// find_by_order(k) (k+1)th largest element
// order_of_key(k) no of elements <=k

typedef long long ll;
typedef long double ld;
#define endl '\n'
#define rep(i,n)  for(ll i = 0; i < (n); ++i)
#define repA(i, a, n)  for(ll i = a; i <= (n); ++i)
#define repD(i, a, n)  for(ll i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (ll)(x).size()
#define ff first
#define ss second
#define pb push_back
typedef vector<ll> vll;
typedef vector<pair<ll,ll>> vpl;
const ld PI = 4*atan((ld)1);
const ll INF = LLONG_MAX;
const ll mod = 1e9+7;

int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    ll tt=1;
        // cin >> tt;
    repA(qq,1,tt){
        ll d,t,s; cin >> d >>t >> s;

        if(t*s>=d){
            cout << "Yes" << endl;
        }else{
            cout << "No";
        }
    }
}


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

#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,b) FOR(i,0,b)
#define PB push_back
using namespace std;

const int Nmax=100000;

vector<int> g[Nmax],rG[Nmax],bct[Nmax];
int idom[Nmax],semi[Nmax],us[Nmax],id[Nmax],rId[Nmax],par[Nmax],mn[Nmax],anc[Nmax];

void AddEdge(int a,int b){
    g[a].PB(b);
    rG[b].PB(a);
}

int Find(int v){
    if(anc[v]==-1)
        return v;
    int a=Find(anc[v]);
    if(id[semi[mn[anc[v]]]]<id[semi[mn[v]]])
        mn[v]=mn[anc[v]];
    return anc[v]=a;
}

void Link(int c,int p){
    anc[c]=p;
}

void Dfs(int v,int p,int& i){
    if(id[v]!=-1)
        return;
    id[v]=i;
    rId[i++]=v;
    par[v]=p;
    for(int c:g[v])
        Dfs(c,v,i);
}

void Calc(int n){
    REP(i,n){
        semi[i]=i;
        id[i]=-1;
        mn[i]=i;
        anc[i]=-1;
    }
    int tmp=0;
    Dfs(0,-1,tmp);
    for(int i=n-1;i>0;i--){
        int w=rId[i];
        for(int v:rG[w]){
            Find(v);
            if(id[semi[mn[v]]]<id[semi[w]])
                semi[w]=semi[mn[v]];
        }
        bct[semi[w]].PB(w);
        for(int v:bct[par[w]]){
            Find(v);
            us[v]=mn[v];
        }
        bct[par[w]].clear();
        Link(w,par[w]);
    }
    FOR(i,1,n){
        int w=rId[i];
        if(semi[w]==semi[us[w]])
            idom[w]=semi[w];
        else
            idom[w]=idom[us[w]];
    }
}

int read(){    int i;    scanf("%d",&i);    return i;}

int main(){
    int n=read(),m=read();
    REP(i,m){
        int s=read()-1,t=read()-1;
        AddEdge(s,t);
    }
    Calc(n);
    int q=read();
    REP(i,q){
        int r=read()-1;
        if(idom[r]==0)
            printf("%d\n",r+1);
        else
            printf("%d\n",idom[r]+1);
    }
}

Measured memory_bytes: 24100
module ABC137

  ! <module>s to import
  use, intrinsic :: iso_fortran_env

  ! require all variables to be explicitly declared
  implicit none

  ! accessibility of <subroutine>s and <function>s in this <module>
  public :: task_B

  ! constants for this <module>
  integer(INT32), parameter, private :: val_coordinate_min_limit = -10000000_INT32
  integer(INT32), parameter, private :: val_coordinate_max_limit =  10000000_INT32

  ! contained <subroutine>s and <function>s are below
  contains

  subroutine task_B (val_width, val_coordinate)

    ! arguments for this <subroutine>
    integer(INT32), intent(in) :: val_width, val_coordinate

    ! variables for this <subroutine>
    integer(INT32) :: val_coordinate_min
    integer(INT32) :: val_coordinate_max

    ! support variables for this <subroutine>
    integer(INT32) :: itr

    ! STEP.01
    ! calculate the range of coordinate where the black stone was set
    val_coordinate_min = val_coordinate - (val_width - 1_INT32)
    val_coordinate_max = val_coordinate + (val_width - 1_INT32)

    ! STEP.02
    ! adjust the range
    if ( val_coordinate_min .lt. val_coordinate_min_limit ) val_coordinate_min = val_coordinate_min_limit
    if ( val_coordinate_max .gt. val_coordinate_max_limit ) val_coordinate_max = val_coordinate_max_limit

    ! STEP.03
    ! output the answer of this task
    write(unit=OUTPUT_UNIT, fmt='(I0)', advance='no') val_coordinate_min

    do itr = val_coordinate_min + 1_INT32, val_coordinate_max, 1_INT32
      write(unit=OUTPUT_UNIT, fmt='(1X,I0)', advance='no') itr
    end do

    write(unit=OUTPUT_UNIT, fmt='(A)', advance='yes') ""

    ! STEP.END
    return

  end subroutine task_B

end module ABC137


program main

  ! <module>s to import
  use, non_intrinsic :: ABC137

  ! require all variables to be explicitly declared
  implicit none

  ! variables for this <program>
  integer(INT32) :: K, X

  ! STEP.01
  ! read out the given data
  read(unit=INPUT_UNIT, fmt=*) K, X

  ! STEP.02
  ! calculate & output the answer of this task
  call task_B (K, X)

end program main

Measured memory_bytes: 640
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define ll long long 

int main() {
  int64_t a, b, c, d;
  cin >> a >> b >> c >> d;
  int64_t ans;
  
  if(a*b <= 0 || c*d <= 0){
    ans = 0;
  }else{
    ans = a*c;
  }
  
  if(a*c > ans) ans = a*c;
  if(a*d > ans) ans = a*d;
  if(b*c > ans) ans = b*c;
  if(b*d > ans) ans = b*d;
  
  cout << ans << endl;

}

Measured memory_bytes: 3632
use std::io;

fn main(){
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    let secs: i32 = buf.trim().parse().unwrap();

    let h: i32 = secs / 3600;
    let m: i32 = (secs % 3600) / 60;
    let s: i32 = secs % 60;

    println!("{}:{}:{}",h,m,s);
}


Measured memory_bytes: 5036
#include<iostream>
#include<vector>
using namespace std;
struct Matrix { vector<vector<long long>>x; };
void resize_(Matrix &a, int H, int W) {
	a.x.resize(H);
	for (int i = 0; i < H; i++)a.x[i].resize(W);
	for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++)a.x[i][j] = 0; }
}
Matrix multiple(Matrix a, Matrix b, long long m) {
	Matrix c; resize_(c, a.x.size(), b.x[0].size());
	for (int i = 0; i < c.x.size(); i++) {
		for (int j = 0; j < c.x[0].size(); j++) {
			for (int k = 0; k < b.x.size(); k++) {
				c.x[i][j] += a.x[i][k] * b.x[k][j];
				c.x[i][j] %= m;
			}
		}
	}
	return c;
}
Matrix power(Matrix a, long long r, long long m) {
	Matrix G[64], H; G[0] = a; int cnt = 0; H = a;
	for (int i = 0; i < 63; i++) {
		G[i + 1] = multiple(G[i], G[i], m);
	}
	for (int i = 0; i < a.x.size(); i++) { for (int j = 0; j < a.x[0].size(); j++) { H.x[i][j] = 0; } }
	for (int i = 0; i < a.x.size(); i++) { H.x[i][i] = 1; }
	for (long long i = 0; i < 63; i++) {
		if ((r / (1LL << i)) % 2 == 0)continue;
		H = multiple(H, G[i], m);
	}
	return H;
}
int main() {
	while (true) {
		long long n, m, a, b, c, t;
		cin >> n >> m >> a >> b >> c >> t;
		if (n == 0 && m == 0 && a == 0 && b == 0 && c == 0 && t == 0)break;
		a %= m; b %= m; c %= m;
		Matrix M1; resize_(M1, n, 1);
		for (int i = 0; i < n; i++) { cin >> M1.x[i][0]; }
		Matrix M2; resize_(M2, n, n);
		for (int i = 0; i < n; i++) {
			if (i > 0)M2.x[i][i - 1] = a;
			M2.x[i][i] = b;
			if (i < n - 1)M2.x[i][i + 1] = c;
		}
		Matrix M3 = power(M2, t, m);
		Matrix M4 = multiple(M3, M1, m);
		for (int i = 0; i < n; i++) { if (i)cout << ' '; cout << M4.x[i][0]; }cout << endl;
	}
	return 0;
}

Measured memory_bytes: 4452
l = [x for x in input()]
l.extend(l)
ch = [ x for x in input()]
txt = "No"
for i in range(len(l)-len(ch)):
    for j in range(len(ch)):
        if l[i+j] != ch[j]:
            break
    else:
        txt ="Yes"
        break
print(txt)


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

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n, k, q;
	cin >> n >> k >> q;
	vector<int> players(n);
	
	for (int i = 0; i < n; i++) {
		players[i] = k - q;
	}

	while (q--) {
		int x; cin >> x;
         x--;
         players[x]++;
	}
	for (int i = 0; i < n; i++) {
		cout << (players[i] <= 0 ? "No\n" : "Yes\n");
	}
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define EXCEPTERROR cout << "-1" << endl;
#define rep(k,nu)    for(int i=k; i<nu;  i++)
#define rep2(k,n)   for(int j=k; j<n;  j++)
#define size_a(array) sizeof(array) / sizeof(array[0])
#define INF 1000000000000 //1e12
#define MOD 10000007 //1e9+7
#define ll long long
#define pb pop_back
template<typename T> inline void chMin(T* a, T* b) {if(*a>*b) *a=*b;}
template<typename T> inline void chMax(T* a, T* b) {if(*a<*b) *a=*b;}
template<typename T> inline int  divUp(T a, T b)   {return ((a+b-1)/b);}
const double PI = acos(-1);
 
int main(){
    int a, b; cin >> a >> b;
    cout << a*b ;
 
    return 0;
}
/*
 
*/

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

using namespace std;
struct du{
    int ap,poz;}viz1[1000005],viz2[1000005];
int cmp(du a, du b){
    return a.ap>b.ap;}

int n,i,x,Max;
int main()
{
    cin>>n;
    for(i=1;i<=n;i++){
        cin>>x;
        if(i%2==0){
            viz1[x].ap++;
            viz1[x].poz = x;
        }
        else
            viz2[x].ap++;
            viz2[x].poz=x;
        Max=max(Max,x);
    }
    sort(viz1+1,viz1+Max+1,cmp);
    sort(viz2+1,viz2+Max+1,cmp);
    if(viz1[1].poz!=viz2[1].poz)
        cout<<n-(viz1[1].ap+viz2[1].ap);
    else
        cout<<n-max(viz1[1].ap+viz2[2].ap,viz1[2].ap+viz2[1].ap);
    return 0;
}


Measured memory_bytes: 5120
def main():
    a, b, c = map(int, input().split())
    k = int(input())
    
    def dfs(a, b, c, k):
        if c > b > a:
            print("Yes")
            exit(0)
        if k == 0:
            return
        dfs(2*a, b, c, k-1)
        dfs(a, 2*b, c, k-1)
        dfs(a, b, 2*c, k-1)
    
    dfs(a, b, c, k)
    print("No")


if __name__ == "__main__":
    main()

Measured memory_bytes: 9168
#include <bits/stdc++.h>
#ifdef __DEBUG__
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
#else
    #define DBG(X)
    #define SAY(X)
#endif

using namespace std;

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

int dx[]={1, 0, -1, 0, 1,-1, 1,-1};
int dy[]={0, 1, 0, -1, 1, 1,-1,-1};
const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);

inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const map<T, S> p) { for (auto el : p) cout << "[" << el.first << ";" << el.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const deque<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const set<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

int N;

struct P
{
    int x,y;
    int i;
    P(int x, int y, int i):x(x),y(y),i(i){}
};


vector<P> Ps;
void input(){
    fast_io();
    cin >> N;
    for (int i = 0; i < N; i++)
    {
        int a,b; cin >> a >> b;
        Ps.emplace_back(a,b,i);
    }
}

vector<vector<pii>> G;


int prim() {
  using Pi = pair< int, int >;
  int total = 0;
  vector< bool > used(G.size(), false);
  priority_queue< Pi, vector< Pi >, greater< Pi > > que;
  que.emplace(0, 0);
  while(!que.empty()) {
    auto p = que.top();
    que.pop();
    if(used[p.second]) continue;
    used[p.second] = true;
    total += p.first;
    for(auto &e : G[p.second]) {
      que.emplace(e.second, e.first);
    }
  }
  return total;
}


int solve(){
    auto cmpX = [](P a, P b){return a.x < b.x;};
    sort(Ps.begin(),Ps.end(),cmpX);
    G.resize(N);
    for (int i = 0; i < N-1; i++)
    {
        int x = Ps[i].i;
        int y = Ps[i+1].i;
        int d = abs(Ps[i+1].x-Ps[i].x);
        G[x].emplace_back(y,d);
        G[y].emplace_back(x,d);
    }

    auto cmpY = [](P a, P b){return a.y < b.y;};
    sort(Ps.begin(),Ps.end(),cmpY);
    for (int i = 0; i < N-1; i++)
    {
        int x = Ps[i].i;
        int y = Ps[i+1].i;
        int d = abs(Ps[i+1].y-Ps[i].y);
        G[x].emplace_back(y,d);
        G[y].emplace_back(x,d);
    }
    int ans = prim();
    cout << ans << endl;    
    return 0;
}   

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

Measured memory_bytes: 13300
def to_do():
    N,M=map(int,input().split())
    day_list=list(map(int,input().split()))
    sum=0
    for i in range(0,M):
        sum=sum+day_list[i]
    if sum>N:
        print(-1)
    if sum<=N:
        print(N-sum)
if  __name__=="__main__":
    to_do()

Measured memory_bytes: 9884
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<memory>
#include<functional>
 
using namespace std;
 
#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define F(i,j,k) fill(i[0],i[0]+j*j,k)
#define P(p) cout<<(p)<<endl;
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define INF 1<<25
#define pb push_back
 
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef pair<int,int> pii;
typedef pair<long,long> pll;
typedef long long ll;
int a[100001];
int main(){
	int n,t_2=0,t_4=0;
	cin>>n;
	rep(i,n){
		cin>>a[i];
		if(a[i]%4==0){
			t_4++;
			continue;
		}
		if(a[i]%2==0)
			t_2++;
	}
	int ne=n,ne_2;
	ne-=t_4;
	ne_2=t_2/2;
	ne-=ne_2;

	int nx=n;
	nx-=t_4;
	nx-=t_2;
/*	if(t_4==1&&ne==2){
		cout<<"Yes"<<endl;
		return 0;
	}*/
	if(nx<=t_4&&(t_2!=1)){
		cout<<"Yes"<<endl;
		return 0;
	}
	if(ne<=t_4+1)
		cout<<"Yes"<<endl;
	else 
		cout<<"No"<<endl;



	return 0;
}


Measured memory_bytes: 640
import java.util.*;

class UF{
	public int[] a;
	public UF(int size){
		Arrays.fill(a=new int[size],-1);
	}
	public int root(int t){
		return a[t]<0?t:(a[t]=root(a[t]));
	}
	public boolean connect(int r,int s){
		r=root(r);
		s=root(s);
		if(r==s)
			return false;
		if(a[r]>a[s]){
			a[s]+=a[r];
			a[r]=s;
		}else{
			a[r]+=a[s];
			a[s]=r;
		}
		return true;
	}
	public boolean isConnected(int a,int b){
		return root(a)==root(b);
	}
	public int groupSize(int t){
		return -a[root(t)];
	}
}

public class Main{
	public static void main(String[] $){
		var s=new Scanner(System.in);

		var n=Integer.parseInt(s.next());
		var q=Integer.parseInt(s.next());

		var uf=new UF(n);

		for(int i=0;i<q;++i){
			var t=Integer.parseInt(s.next());
			var u=Integer.parseInt(s.next());
			var v=Integer.parseInt(s.next());

			if(t==0)
				uf.connect(u,v);
			else
				System.out.println(uf.isConnected(u,v)?1:0);
		}
	}
}


Measured memory_bytes: 67460
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 1e16
#define EPS 1e-9
#define fst first
#define scd second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"
const int MAX=262144;

int mp[MAX*2 - 1];
void setup(){
  rep(i,MAX*2) mp[i]=INF;
  
}

void update(int i,int x){
  i+= MAX-1;
  mp[i]=x;
  while(i>0){
    i=(i-1)/2;
    mp[i]=min(mp[i*2 + 1],mp[i*2 + 2]);
  }
}

int query(int a,int b,int k,int l,int r){
  if(r<=a || b<=l) return INF;
  if(a<=l && r<=b) return mp[k];
  else{
    int vl=query(a,b,k*2 + 1,l,(l+r)/2);
    int vr=query(a,b,k*2 + 2,(l+r)/2,r);
    return min(vl,vr);
  }
}

signed main(){
  cin.tie(0);	
  //ios::sync_with_stdio(false);
  int n,m;
  cin>>n>>m;
  pair<pair<int,int>,int> hen[100000];
  rep(i,m){
    int a,b,c;
    cin>>a>>b>>c;
    hen[i].fst.fst=--a;
    hen[i].fst.scd=--b;
    hen[i].scd=c;
  }
  sort(hen,hen+m);
  setup();
  update(0,0);
  //if(hen[0].fst.fst == 0){
  //update(hen[0].fst.scd,hen[0].scd);
  //}
  rep(i,m){
    int num=query(hen[i].fst.fst,hen[i].fst.scd,0,0,MAX);
    //cout<<hen[i].fst.fst<<" "<<hen[i].fst.scd<<" "<<num<<endl;
    
    update(hen[i].fst.scd,min(num+hen[i].scd,mp[hen[i].fst.scd+MAX-1]));
  }
  int answ=query(n-1,MAX,0,0,MAX);
  if(answ==INF) cout<<-1<<endl;
  else cout<<answ<<endl;
  
  return 0;
}


Measured memory_bytes: 6656
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <unordered_set>
#include <unordered_map>
 
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
static const int INF = 1000010000;
static const int MOD = 1000000007;
 
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define SORT(v) sort(v.begin(), v.end());
#define pb push_back
#define mp make_pair
#define np next_permutation
#define pq priority_queue
 
int dx4[4] = {0,1,0,-1}, dy4[4] = {-1,0,1,0};
//int dx5[5] = {-1,0,0,0,1}, dy5[5] = {0,-1,0,1,0};
//int dx8[8] = {-1,0,1,1,1,0,-1,-1}, dy8[8] = {1,1,1,0,-1,-1,-1,0};
//int dx9[9] = {-1,0,1,1,1,0,-1,-1,0}, dy9[9] = {1,1,1,0,-1,-1,-1,0,0};


int main(){
    int n;
    cin >> n;
    char c;
    bool flag = false;
    REP(i, n){
        cin >> c;
        if(c == 'Y') flag = true;
    }
    if(flag){
        cout << "Four" << endl;
    }else{
        cout << "Three" << endl;
    }
}

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

#define mod 1000000007
#define pll pair<long long,long long>
#define pdd pair<long double,long double>
#define mp make_pair
#define pb push_back
priority_queue<pll,vector<pll>,greater<pll> >pq;

vector<int>arr(100001),dp(100001,0);
int n,k;
int solve(int i){
    if(i>=n)
        return 0;
    if(dp[i]!=0)
        return dp[i];
    if(i+1<n)
        dp[i]=(abs(arr[i+1]-arr[i])+solve(i+1));
    if(i+2<n)
        dp[i]=min(dp[i],abs(arr[i+2]-arr[i])+solve(i+2));
    return dp[i];
}

int main(){
    //int n;
    cin>>n>>k;
    //vector<int>arr(n),dp(n);
    for(int i=0;i<n;i++){
        cin>>arr[i];
    }
    dp[0]=0;
    for(int i=1;i<n;i++){
        dp[i]=abs(arr[i]-arr[i-1])+dp[i-1];
        for(int j=2;j<=k;j++){
            if(i-j>=0)
                dp[i]=min(dp[i],abs(arr[i]-arr[i-j])+dp[i-j]);
        }
    }
    cout<<dp[n-1];
    return 0;
}



Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
const int N=550;

typedef long long ll;
int mp[N][N], dp[N][N];

int main()
{
    memset(dp,0,sizeof(dp));
    int n,m,q,u;
    cin>>n>>m>>q;

    while(m--)
    {
        int a,b;
        cin>>a>>b;
        mp[a][b] ++;
    }

    for(int i=n; i>=1; i--)
        for(int j=1; j<=n; j++)
        {
            dp[i][j] = mp[i][j] + dp[i+1][j] + dp[i][j-1] - dp[i+1][j-1];
            u=dp[i][j];
        }

    while(q--)
    {
        int a,b;
        cin>>a>>b;
        cout<<dp[a][b]<<endl;
    }
    return 0;
}


Measured memory_bytes: 3200
#include <iostream>
#include <bits/stdc++.h>
#include <string>
#include <math.h>
#include <vector>
using namespace std;
int main(){
    int n; cin>>n;
    if(n==1) cout<<"Hello World"<<endl;
    else{
        int a,b;
        cin>>a>>b;
        cout<<a+b<<endl;
    }
    return 0;
}

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

namespace ABC045_B_CardGameForThree
{
    class ABC045_B
    {
        static void Main(string[] args)
        {
            var cards = new List<List<char>>();
            cards.Add(Console.ReadLine().ToList());
            cards.Add(Console.ReadLine().ToList());
            cards.Add(Console.ReadLine().ToList());

            char[] winner = new char[] { 'A', 'B', 'C' };

            int player = 0;
            while (true)
            {
                if (cards[player].Count == 0)
                {
                    Console.WriteLine(winner[player]);
                    return;
                }

                char used = cards[player][0];
                cards[player].RemoveAt(0);

                switch (used)
                {
                    case 'a':
                        player = 0;
                        break;

                    case 'b':
                        player = 1;
                        break;

                    case 'c':
                        player = 2;
                        break;
                }
            }
        }
    }
}


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

int		main(void)
{
    string	a;
	cin >> a;
	int		cnt;
	cnt = 0;
	for (auto &i : a)
	{
		if (i == 'o')
			cnt++;
	}
	cout << 700 + (cnt * 100) << endl;
}

Measured memory_bytes: 256