akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
 
typedef vector<int> vi; 
typedef pair<int,int> pi;
typedef long long ll;
#define F first 
#define S second 
#define PB push_back 
#define MP make_pair
#define REP(i,a,b) for (int i = a; i <= b; i++)
#define all 1000000007

vector< vector<ll> > tree;
vector< vector<ll> > dp;

ll n;

ll sume1(ll a, ll b){
	ll total = ( (a%all)*(b%all) )%all;
	return total;
}

ll sume2(ll a, ll b){
	
	ll total = ( (a%all) + (b%all) )%all;
	return total;
	
}

void see(ll here, ll father){
	
	ll f = tree[here].size(), counter = 0;
	
	for(ll i = 0; i < f; i++){
		
		if( tree[here][i] != father ){
			see(tree[here][i], here );
			counter++;
			
			dp[here][0] = sume1( dp[here][0] , dp[ tree[here][i] ][0] + dp[ tree[here][i] ][1]  );
			dp[here][1] = sume1( dp[here][1] , dp[ tree[here][i] ][0]   );
		}
		
	}
	
	
}

int main(){
	
	ios::sync_with_stdio(0); cin.tie(0);
	
	cin >> n; 
	
	tree.assign( n+1, vector<ll>(0,0) );
	dp.assign(n+1, vector<ll>(2,1)) ;
	
	ll a,b;
	
	for(ll i = 1; i < n; i++){
		
		cin >> a >> b;
		
		tree[a].PB(b);
		tree[b].PB(a);
		
	}
	
	see(1,0);
	
	
	cout << sume2(dp[1][0], dp[1][1] ) << endl;
	 
	return 0;
}


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

int main(){
  int k,s;
  cin>>k>>s;
  int cnt=0;
  rep(x,k+1)rep(y,k+1){
    int z=s-x-y;
    if(0<=z and z<=k)cnt++;
  }
  cout<<cnt<<endl;
  return 0;
}

Measured memory_bytes: 3612
/* ex5_3
   kento_titech*/
#include<stdio.h>
#define SIZE 101
int main(void){
    int rows,columns,i,j;//rows,columnsはそれぞれ入力する行と列
    int row_mark[SIZE]={0},column_mark[SIZE]={0};//それぞれ黒色の存在する行と列を表す配列
    char grid[SIZE][SIZE];//格子点の多次元配列
    scanf("%d %d",&rows,&columns);
    for(i=0;i<rows;i++){
        for(j=0;j<columns;j++){
            scanf(" %c",&grid[i][j]);
        }
    }
    for(i=0;i<rows;i++){//ある行と列について少なくとも一つ黒色が存在するか
        for(j=0;j<columns;j++){
            if(grid[i][j]=='#'){
                row_mark[i]=1;
                column_mark[j]=1;
            }
        }
    }
    for(i=0;i<rows;i++){
        if(row_mark[i]==1){//i行に黒色が存在するときだけ列を考える
        //continue;
        //}
            for(j=0;j<columns;j++){//j列に黒色が存在するとき座標(i,j)を出力する
                if(column_mark[j]==1){
                    printf("%c",grid[i][j]);
                }
            }printf("\n");
        }
    }
    return 0;
}


Measured memory_bytes: 128
#include <cstdio>
#include <algorithm>

const int MN = 200005;

int N, M, A[MN], Ans;

inline bool check(int pos) {
	int Now = 0;
	for (int i = 1; i <= pos; ++i)
		Now = std::max(Now, A[i] + A[2 * pos - i + 1]);
	for (int i = 1; i <= N - pos; ++i) {
		int v = A[2 * pos + i] + A[2 * N - i + 1];
		if (v < M) return 0;
		Now = std::max(Now, v - M);
	}
	Ans = std::min(Ans, Now);
	return 1;
}

int main() {
	scanf("%d%d", &N, &M), Ans = M;
	for (int i = 1; i <= 2 * N; ++i) scanf("%d", &A[i]);
	std::sort(A + 1, A + 2 * N + 1);
	int l = 0, r = N, mid;
	while (l <= r) {
		mid = (l + r) >> 1;
		if (check(mid)) r = mid - 1;
		else l = mid + 1;
	}
	printf("%d\n", Ans);
	return 0;
}

Measured memory_bytes: 896
primes = [0, 0] + [1] * 150000
for i in range(2, 388):
    if primes[i]:
        for j in range(i*i, 150001, i):
            primes[j] = 0

values = [i for i, v in enumerate(primes) if v]
while True:
    n = int(input())
    if n == 0:
        break
    print(sum(values[:n]))

Measured memory_bytes: 9480
#include <stdio.h>
#include <algorithm>
#include <vector>

int main(int argc, char **argv) {
  int N;
  scanf("%d", &N);

  int64_t total = 0;
  std::vector<int64_t> a(N + 1, 0);
  for (int i = 1; i <= N; ++i) {
    int tmp;
    scanf("%d", &tmp);
    //tmp = (i <= N / 2) ? 1000000000 : -1000000000;

    total += tmp;
    a[i] = a[i - 1] + tmp;
  }

  int64_t min_diff = 200000000000001;
  for (int i = 1; i <= N - 1; ++i) {
    int64_t diff = std::abs(total - 2 * a[i]);
    min_diff = std::min(diff, min_diff);
  }
  printf("%lld\n", min_diff);

  return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<queue>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1001001001;

int main() {
  int A1, A2, A3;
  cin >> A1 >> A2 >> A3;

  string ans;
  if (A1+A2+A3 >= 22) ans = "bust";
  else ans = "win";
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import fractions

s =input().split()
A = int(s[0])
B = int(s[1])
C = int(s[2])
D = int(s[3])

tmp = fractions.gcd(C, D)
CD = (C * D) // tmp
ac = (A-1)//C
bc = B//C
ad = (A-1)//D
bd = B//D
acd = (A-1)//CD
bcd = B//CD

cnt = B - bc - bd + bcd - (A-1) + ac + ad - acd
print(cnt)


Measured memory_bytes: 5076
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=200200;
int i,j,k,n,m,r,c,ch,x[2],y[2],An,Bn,Cn,Dn;
int z[N],d[N];
struct cc {
	int v,q;
	bool operator < (const cc &n) const {
		return v<n.v;
	}
} A[N],B[N],C[N],D[N];
void R(int &x) {
	x=0;ch=getchar();
	while (ch<'0' || '9'<ch) ch=getchar();
	while ('0'<=ch && ch<='9') x=x*10+ch-'0',ch=getchar();
}
void Add(int x,int y,int i) {
	if (x==0) {
		A[++An].v=y;
		A[An].q=i;
		return;
	}
	if (y==c) {
		B[++Bn].v=x;
		B[Bn].q=i;
		return;
	}
	if (x==r) {
		C[++Cn].v=-y;
		C[Cn].q=i;
		return;
	}
	if (y==0) {
		D[++Dn].v=-x;
		D[Dn].q=i;
		return;
	}
}
bool check(int x,int y) {
	return x==0 || x==r || y==0 || y==c;
}
int main() {
	R(r);R(c);R(n);
	for (i=1;i<=n;i++) {
		R(x[0]);R(y[0]);R(x[1]);R(y[1]);
		if (!check(x[0],y[0]) || !check(x[1],y[1])) continue;
		Add(x[0],y[0],i);
		Add(x[1],y[1],i);
	}
	sort(A+1,A+An+1);
	sort(B+1,B+Bn+1);
	sort(C+1,C+Cn+1);
	sort(D+1,D+Dn+1);
	for (i=1;i<=An;i++) {
		if (!z[A[i].q]) d[++m]=A[i].q,z[d[m]]=1;
		else {
			if (d[m]!=A[i].q) return puts("NO"),0;
			m--;z[A[i].q]=0;
		}
	}
	for (i=1;i<=Bn;i++) {
		if (!z[B[i].q]) d[++m]=B[i].q,z[d[m]]=1;
		else {
			if (d[m]!=B[i].q) return puts("NO"),0;
			m--;z[B[i].q]=0;
		}
	}
	for (i=1;i<=Cn;i++) {
		if (!z[C[i].q]) d[++m]=C[i].q,z[d[m]]=1;
		else {
			if (d[m]!=C[i].q) return puts("NO"),0;
			m--;z[C[i].q]=0;
		}
	}
	for (i=1;i<=Dn;i++) {
		if (!z[D[i].q]) d[++m]=D[i].q,z[d[m]]=1;
		else {
			if (d[m]!=D[i].q) return puts("NO"),0;
			m--;z[D[i].q]=0;
		}
	}
	puts("YES");
}

Measured memory_bytes: 5632
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        a: usize,
        p: usize,
    }
    println!("{}", (3 * a + p) / 2);
}


Measured memory_bytes: 4352
#include <iostream>
#include <cmath>
#include <vector>
#include <iomanip>
using namespace std;

int main() {

int n;

cin >> n;

int x,y;

for(x=1;x<=n;++x){
y=x;
if(y%3==0){
cout << " " << x;
}
else{
do{
if(y<1){break;}
if(y%10==3){
cout << " " << x;
break;}
y/=10;
}while(x>=1);
}

}

cout << endl;

}


Measured memory_bytes: 3096
#include<iostream>
#include<string>
#include<cmath>
#include<algorithm>
using namespace std;

struct res{
	string town;
	int score,num;
};

int main(){
	int n;
	res r[100];
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> r[i].town >> r[i].score;
		r[i].num = i+1;
	}
	for(int i = 0; i < n; i++){
		for(int j = n-1; j > i; j--){
			if(r[j].town == r[j-1].town){
				if(r[j].score>r[j-1].score)
					swap(r[j], r[j-1]);
			}
			else if(r[j].town < r[j-1].town)
				swap(r[j], r[j-1]);
		}
	}
	for(int i = 0; i < n; i++)
		cout << r[i].num << '\n';
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << "\n";
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (int i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
const ll MOD = 10007;

template <typename T>
struct Kruskal {
    int v;
    vector<pair<T, pair<int, int>>> e; // {cost, {from, to}}

    Kruskal(int v) : v(v) {}

    struct UnionFind {
        vector<int> par;

        UnionFind(int n): par(n, -1) {}
        void init(int n) { par.assign(n, -1); }

        int root(int x) {
            if (par[x] < 0) return x;
            return par[x] = root(par[x]);
        }

        int issame(int x, int y) {
            return root(x) == root(y);
        }

        bool merge(int x, int y) {
            x = root(x); y = root(y);

            if (x == y) return false;

            // merge by size
            // force size of x to be bigger than that of y
            if (par[x] > par[y]) swap(x, y);
            par[x] += par[y];
            par[y] = x;

            return true;
        }

        int size(int x) {
            return -par[root(x)];
        }
    };

    void add_edge(int s, int t, T w) {
        // Assuming undirected connection
        e.pb({w, {s, t}});
        e.pb({w, {t, s}});
    }

    // return cost of mst
    T operator()() {
        sort(ALL(e));
        UnionFind uf(v);

        T ret = 0;
        for(auto &p: e) {
            int s = p.se.fi, t = p.se.se;
            if (uf.issame(s, t)) continue;

            uf.merge(s, t);
            ret += p.fi;
        }

        return ret;
    }
};

int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(3);

    int n; cin >> n;

    vector<pair<ll, int>> x(n), y(n);
    REP(i, n) {
        ll _x, _y; cin >> _x >> _y;
        x[i] = {_x, i};
        y[i] = {_y, i};
    }

    sort(ALL(x));
    sort(ALL(y));

    Kruskal<ll> g(n);

    REP(i, n - 1) {
        ll cost = x[i + 1].fi - x[i].fi;
        g.add_edge(x[i].second, x[i + 1].second, cost);
    }

    REP(i, n - 1) {
        ll cost = y[i + 1].fi - y[i].fi;
        g.add_edge(y[i].second, y[i + 1].second, cost);
    }

    print(g());

}

Measured memory_bytes: 14756
#include <bits/stdc++.h>
using namespace std;
int a[10];
int get(int x) {
	if (x < 4) return a[x];
  	else return 0;
}

int get1(int x, int y) {
	if (x == 1 && y == 1) return 400000;
  	else return 0;
}
int main() {
	int x = 0;
  	int y = 0;
  	cin >> x >> y;
  	a[1] = 300000;
  	a[2] = 200000;
  	a[3] = 100000;
  	int res = get(x) + get(y);
  	res += get1(x, y);
  	cout << res;
}

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

using namespace std;

typedef pair<int, int> P;
#define int long long
#define ll long long
#define mod 1000000007
#define INF (1LL<<60)


signed main(){

	int X;
	cin >> X;

	if (X == 3LL || X == 5LL || X == 7LL)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;

	return 0;
}


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

typedef long long ll;

using namespace std;

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

    int n; cin >> n;
    vector<ll> a(n + 1);
    ll cumSum[n + 1];
    cumSum[0] = 0;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        cumSum[i] = cumSum[i - 1] + a[i];
    }
    ll ans = 1LL<<60;
    for (int i = 2; i <= n - 2; i++) {
        ll lsum = cumSum[i];
        ll rsum = cumSum[n] - lsum;

        int lb = upper_bound(cumSum, cumSum + i, lsum / 2) - cumSum;
        ll p;
        if (lb == 0 || abs(lsum - 2 * cumSum[lb]) < abs(lsum - 2 * cumSum[lb - 1])) p = cumSum[lb];
        else p = cumSum[lb - 1];
        ll q = lsum - p;

        int rb = upper_bound(cumSum + i, cumSum + n, lsum + rsum / 2) - cumSum;
        ll r;
        if (rb == i || abs(rsum - 2 * (cumSum[rb] - cumSum[i])) < abs(rsum - 2 * (cumSum[rb - 1] - cumSum[i]))) r = cumSum[rb] - cumSum[i];
        else r = cumSum[rb - 1] - cumSum[i];
        ll s = rsum - r;

        ll mx = p;
        ll mn = p;
        for (auto& x : { q, r, s }) {
            mx = max(mx, x);
            mn = min(mn, x);
        }
        ans = min(ans, mx - mn);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3456
#include<stdio.h>
#include<stdlib.h>
#include<stack>
using namespace std;
stack<int> cal;
char s[6];
int main(){
    while(scanf("%s",s)!=EOF){
        if(s[0]=='+'){
            int a=cal.top();
            cal.pop();
            int b=cal.top();
            cal.pop();
            cal.push(a+b);
        }
        else if(s[0]=='*'){
            int a=cal.top();
            cal.pop();
            int b=cal.top();
            cal.pop();
            cal.push(a*b);
        }
        else if(s[0]=='-'){
            int a=cal.top();
            cal.pop();
            int b=cal.top();
            cal.pop();
            cal.push(b-a);
        }
        else cal.push(atoi(s));
    }
    printf("%d\n",cal.top());
    return 0;
}

Measured memory_bytes: 1020
eval'K,*X='+`dd`.split*?,
j=l=1
x,y,*s=X.map &:abs
d=x+y
x,y=y,x if f=x<y
K%2-d%2<0&&p(-1)+exit
d!=K&&(l+=[~-d/K,1].max
l+=1&d-K*l
v=K>(t=K*l-d>>1)?0:t-t=K
a=K-t
2.upto(l){s<<(u=f ?-t:a)<<a-t-u
a+=q=[x+v-a,K].min
t-=K-q})
p l,*s.map{|a|a*=X[j^=1]<=>0.1}+X

Measured memory_bytes: 29848
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner((System.in));
        double w = sc.nextInt();
        double h = sc.nextInt();
        double x = sc.nextInt();
        double y = sc.nextInt();
        double s = 0;
        int cnt = 0;
        
        s = (w * h) / 2;

        if (2 * x == w && 2 * y == h) {
            cnt = 1;
        }

        System.out.println(s+" "+cnt);

		sc.close();
	}
}


Measured memory_bytes: 21844
#include<cstdio>
int prime[1000001]={};
bool is_prime[1000001]={};
	
int sieve(){
	int p=0;
	for(int i=0;i<=1000000;i++)is_prime[i]=true;
	is_prime[0]=is_prime[1]=false;
	for(int i=2;i<=1000000;i++){
		if(is_prime[i]){
			prime[p++]=i;
			for(int j=2*i;j<=1000000;j+=i)is_prime[j]=false;
		}
	}
	return p;
}
	
int main(){
	long long int n,p,ans,anss;
	scanf("%lld%lld",&n,&p);
	ans=1;
	anss=p;
	int x=sieve();
	for(long long int i=0;i<x;i++){
		if(p%prime[i]==0){
			int mode=0;
			for(int j=0;j<n;j++){
				if(p%prime[i]==0){
					p=p/prime[i];
				}else{
					mode=1;
					break;
				}
			}
			if(mode==0)ans=ans*prime[i];
			if(p%prime[i]==0)i--;
		}
	}
	if(n==1)ans=anss;
	printf("%lld\n",ans);
	return 0;
}	

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int,int>;

int solve() {
    int H, W, K;
    cin >> H >> W >> K;
    vector<string> A(H);
    pii s;
    for ( int h = 0; h < H; h++ ) {
        cin >> A[h];
        for ( int w = 0; w < W; w++ ) {
            if ( A[h][w] == 'S' ) s = pii(h,w);
        }
    }
    auto dist = [&](pii& x) {
        return min({x.first, H-1-x.first, x.second, W-1-x.second});
    };
    vector<int> dh = {0, 1, 0, -1}, dw = {1, 0, -1, 0}, hh = {0, 1, 0, 1};
    queue<pii> q;
    q.push(s);
    int m = dist(s);
    int INF = 1e9;
    vector<vector<int>> dk(H,vector<int>(W, INF));
    dk[s.first][s.second] = 0;
    while ( !q.empty() ) {
        auto p = q.front();
        q.pop();
        for ( int i = 0; i < 4; i++ ) {
            int h = p.first + dh[i];
            int w = p.second + dw[i];
            if ( h < 0 || h >= H || w < 0 || w >= W ) continue;
            if ( A[h][w] == '.' && dk[h][w] > dk[p.first][p.second] + 1 && dk[p.first][p.second] < K ) {
                pii u(h,w);
                q.push(u);
                m = min(m, dist(u));
                dk[h][w] = dk[p.first][p.second] + 1;
            }
        }
    }
    int ans = (m + K - 1)/K + 1;
    return ans;
}

int main() {
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 3584
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<string>
#include<map>
#include<vector>
#define rep(i, n) for(int i=0; i<n; i++)
#define rep_one(i, n) for(int i=1; i<n; i++)
using namespace std;
typedef long long ll;

int main(){
    ll n, m, k; cin >> n >> m >> k;
    ll a[n], b[m], as[n+1], bs[m+1], books[n+1];
    rep(i,n) cin >> a[i];
    rep(i,m) cin >> b[i];
    as[0] = 0;
    bs[0] = 0;
    rep_one(i,n+1) as[i] = as[i-1]+a[i-1];
    rep_one(i,m+1) bs[i] = bs[i-1]+b[i-1];
    int limit=m;
    rep(i,n+1){
        while(as[i]+bs[limit]>k){
            if(limit == 0) break;
            limit--;
        }
        if(as[i]+bs[limit]>k && limit==0) books[i] = 0;
        else books[i] = i+limit;
    }
    ll ans = 0;
    rep(i,n+1) if(books[i] > ans) ans = books[i];
    cout << ans << endl;
}


Measured memory_bytes: 11464
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main() {
	//min(a,b)...a,bの小さいほう
	//max(a,b)...     大きいほう
	int a;
	int b;
	int c;
	//int d;
	int e;
	cin >> a >> b >> c;
	//string s;
	//std::cin >> s;
	if (a * b >= c) {
		cout << c << "\n";
	}
	else if(a * b < c){
		cout << a * b << "\n";
	}
	std::cin >> e;
}

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

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

    int n,m; cin >> n >> m;
    vector<ll> h(n); rep(i,n) cin >> h[i];
    vector<bool> isOK(n, true);
    rep(i,m){
        int a,b; cin >> a >> b;
        a--; b--;
        if(h[a] == h[b]) isOK[a] = isOK[b] = false;
        else if(h[a] > h[b]) isOK[b] = false;
        else isOK[a] = false;
    }

    int ans =0;
    rep(i,n) if(isOK[i]) ans++;
    cout << ans << endl;
}

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

int calc(int, int, char);

int main() {
    int a, b;
    char op;
    for (;;) {
        cin >> a >> op >> b;
        if (op == '?')
            return 0;
        cout << calc(a, b, op) << endl;
    }
}

int calc(int a, int b, char op) {
    if (op == '+')
        return a + b;
    if (op == '-')
        return a - b;
    if (op == '*')
        return a * b;
    return a / b;
}



Measured memory_bytes: 3100
import java.util.*;
import java.io.PrintWriter;
import static java.lang.Integer.*;
import static java.lang.Long.*;
import static java.lang.Math.*;
import static java.lang.System.*;

public class Main {
	public static final int MOD = 1000000007;
	public static void main(String[] args) {
		int i,j;
		Scanner sc = new Scanner(in);
		int s = parseInt(sc.next());
		int w = parseInt(sc.next());
		sc.close();
		out.println(s<=w?"unsafe":"safe");
	}
}


Measured memory_bytes: 27016
package main

import(
  "bytes"
	"fmt"
  	"bufio"
  	"os"
  	"strconv"
  	"strings"
)

func arrayToString(A []int, delim string) string {

    var buffer bytes.Buffer
    for i := 0; i < len(A); i++ {
        buffer.WriteString(strconv.Itoa(A[i]))
        if i != len(A)-1 {
            buffer.WriteString(delim)
        }
    }

    return buffer.String()
}

func main(){
  var sc = bufio.NewScanner(os.Stdin)
  sc.Scan()
  num_str := sc.Text()
  numstr := strings.Split(num_str, " ")
  K, _ := strconv.Atoi(numstr[0])//個数
  X, _ := strconv.Atoi(numstr[1])//座標

  var nums1 = []int{}
  var nums2 = []int{}

    
    pul := X + K
  	sub := X - K + 1
  	
  	if K != 1{
      for j := 1; X < pul; j++{
        nums1 = append(nums1, X)
        X++
      } 
      for i := 1; sub < X; i++{
        nums2 = append(nums2, sub)
        sub++
      }
     // nums1 = append(nums1,nums2...)
      fmt.Println(arrayToString(nums2, " "))
    }else{
      fmt.Println(X)
    }
  
  
  
    
}


Measured memory_bytes: 640
// 解説見たやつ
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#define repeat(i, n) for (int i = 0; (i) < (n); ++(i))
#define repeat_from(i, m, n) for (int i = (m); (i) < (n); ++(i))
using namespace std;
template <class T>
void setmax(T &a, T const &b) {
    if (a < b) a = b;
}

template <class T>
void setmin(T &a, T const &b) {
    if (a > b) a = b;
}

template <typename T, typename X>
auto vectors(T a, X x) { return vector<T>(x, a); }

template <typename T, typename X, typename Y, typename... Zs>
auto vectors(T a, X x, Y y, Zs... zs) {
    auto cont = vectors(a, y, zs...);
    return vector<decltype(cont)>(x, cont);
}

int main() {
    int h, w;
    cin >> h >> w;

    map<int, int> s;
    multiset<int> vals;

    repeat(i, w) s[i] = i;
    repeat(i, w) vals.insert(0);

    repeat(i, h) {
        int l, r;
        cin >> l >> r;
        --l;
        auto it = s.lower_bound(l);
        int mr = -1;
        while (it != s.end() && it->first <= r) {
            setmax(mr, it->second);
            int x = it->first - it->second;
            vals.erase(vals.find(x));
            //https://ox8000ffff.hatenadiary.org/entry/20100225/1267201650
            //後置インクリメントはオブジェクトのコピーがeraseの引数になる
            s.erase(it++);
        }
        if (mr != -1 && r < w) {
            vals.insert(r - mr);
            s[r] = mr;
        }
        int ans = -1;
        if (vals.size() > 0) {
            ans = *vals.begin() + (i + 1);
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 22336
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
import time
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

t = time.time()
N, M = MAP()

uv = [LIST() for _ in range(M)]
S, T = MAP()
S = S-1
T = T-1
graph = defaultdict(list)
flag = False
for u, v in uv:
	if v-1 == T:  # T にたどりつける
		flag = True
	graph[v-1].append(u-1)
if not flag:
	print(-1)
	sys.exit(0)
# print(graph)
q = deque([])
q.append((T, 0, "a"))
sirusi = [[] for _ in range(N)]  # "a":3n "b":3n-1 "c":3n-2
count = 0
while q:
	if count >= 3*N+1:  # すべてに印つけおわる
		break
	search, step, state = q.popleft()
	# print(search, step, state)
	if state in sirusi[search]:
		continue
	sirusi[search].append(state)
	count += 1
	# print(search, step, state)
	if search == S and state == "a":
		break

	for node in graph[search]:
		if state == "a":
			q.append((node, step+1, "b"))
		elif state == "b":
			q.append((node, step+1, "c"))
		else:
			q.append((node, step+1, "a"))
# print(sirusi)
if "a" in sirusi[S]:
	print(step//3)
else:
	print(-1)


Measured memory_bytes: 60088
#include<bits/stdc++.h>
using namespace std;
#define db(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<'\n'
const int N = 1e6;
#define ll long long

int main(){
	ios_base::sync_with_stdio(0);
	int a,b,n,W,w,val,T,cas=0;
	cin>>n>>W;
	vector<ll> dp(W+1);
	// max value in same weight
	for(int i=0;i<n;++i) {
		cin>>w>>val;
		for(int weight_already=W-w;weight_already>=0;--weight_already) {
			dp[weight_already+w] = max(dp[weight_already+w], dp[weight_already]+val);
		}
	}
	cout<<dp[W]<<endl;
	return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define REP(i,n) for (ll i = 0; i < n; ++i)
#define REPR(i,n) for (ll i = n-1; i >= 0; --i)
#define FOR(i,m,n) for (int i = m; i < n; ++i)
#define FORR(i,m,n) for (ll i = n-1; i >= m; --i)
#define FORE(x,xs) for (const auto& x : xs)
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()

int A;
string S;

int main() {
    cin >> A >> S;
    if (A >= 3200) cout << S << endl;
    else cout << "red" << endl;
}

Measured memory_bytes: 384
#include<stdio.h>
int main(){
    int i,n,c=0,d,x,y;
    scanf("%d",&n);
    scanf("%d",&d);
    for(i=1;i<=n;i++){
        scanf("%d",&x);
        scanf("%d",&y);
        if((signed long long)x*(signed long long)x+(signed long long)y*(signed long long)y<=(signed long long)d*(signed long long)d){
            c++;
        }
    }
    printf("%d",c);
    return 0;
}

Measured memory_bytes: 1736
#include <bits/stdc++.h>
#define endl '\n';

typedef long long ll;

using namespace std;

const string YES = "";
const string NO  = "";

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

    string s;
    int cnt = 0;

    cin >> s;

    for (int i = 0; i < s.size(); ++i) {
        if (s[i] == '1') cnt++;
    }

    cout << cnt << endl;

    return 0;
}



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

int main(){
  string S;
  cin >> S;
  string K="keyence";
  int a=0;
  for(int i;i<7;i++){
    if (S[i]!=K[i]){
      break;
    }
    a++;
  }
  for(int i;i<7;i++){
    if (S[S.size()-1-i]!=K[6-i]){
      break;
    }
    a++;
  }
  string ans=a>=7?"YES":"NO";
  cout << ans << endl;
}

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

int main(){
    constexpr long MOD = 1000000007;
    auto modinv = [&MOD](unsigned long t, unsigned long a){
        unsigned long ret = t % MOD, n = MOD - 2;
        while(n){
            if(n & 1){
                ret *= a;
                ret %= MOD;
            }
            a *= a;
            a %= MOD;
            n >>= 1;
        }
        return ret;
    };
    unsigned long B, W;
    cin >> B >> W;

    vector<unsigned long> tapi(B), tapu(W);
    tapi[0] = 1;
    tapu[0] = MOD - 1;
    for(unsigned long i = 1, j = W; i != B; ++i, ++j)tapi[i] = modinv(tapi[i - 1] * j, i);
    for(unsigned long i = 1, j = B; i != W; ++i, ++j)tapu[i] = modinv(tapu[i - 1] * j, i);

    unsigned long ans(1), den(500000004);
    for(unsigned long i = 0; i != B + W; ++i){
        cout << ans * den % MOD << endl;
        ans *= 2;
        if(i >= B - 1)ans += tapu[i - B + 1];
        if(i >= W - 1)ans += tapi[i - W + 1];
        ans -= (ans > 2 * MOD) * 2 * MOD;
        ans -= (ans > MOD) * MOD;
        den += MOD * (den & 1);
        den >>= 1;
    }
    return 0;
}


Measured memory_bytes: 3712
//Collecting Balls(Easy mode)
#include <bits/stdc++.h>
using namespace std;
int main ()
{
  int N,K,S;
  cin >> N >> K ;
  S = 0;
  for ( int i=0 ; i<N ; i++ )
  {
    int x,d1,d2;
    cin >> x;
    d1 = 2*x;
    if ( K-x < 0 )
    {
      d2 = 2*(x-K);
    }
    else
    {
      d2 = 2*(K-x);
    }
    if ( d1 < d2 )
    S = S+d1;
    else
    S = S+d2;
  }
  cout << S << endl;
}

Measured memory_bytes: 256
n = input()

alpha = int(n[0])
beta = len(n) - 1

n = int(n)

if n % 2 != 0:
    print('0')
else:
    five = 0
    cnt = 1
    x = 5
    while x <= n:
        five += n // 10  // x
        cnt += 1
        x *= 5

    ans = n // 10 + five
    print(ans)

Measured memory_bytes: 3064
import java.util.Scanner;
public class Main {
	public static void main(String[] args)throws Exception{
		Scanner stdIn=new Scanner(System.in);
		int A=stdIn.nextInt();
		int B=stdIn.nextInt();
		if(A+B>=10)
			System.out.println("error");
		else
			System.out.println(A+B);
	}
}


Measured memory_bytes: 21844
#include<iostream>
#include<vector>
#include<string>
#include<cstring>
#include<algorithm>
#include<map>
#include<set>
#include<cmath>
#include<cassert>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

int main() {
	int N, T;
	cin >> N >> T;
	vector<int> A(N);
	for (int i = 0; i < N; i++)
		cin >> A[i];
	int mini = 1e9+7, maxDiff = -1, ans = 0;
	for (int i = 0; i < N; i++) {
		mini = min(mini, A[i]);
		if (maxDiff < A[i]-mini) {
			maxDiff = A[i]-mini;
			ans = 0;
		}
		if (maxDiff == A[i]-mini) ++ans;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 640
import bisect

def sRaw():
    return input().rstrip("\r")


def iRaw():
    return int(input())


def ssRaw():
    return input().split()


def isRaw():
    return list(map(int, ssRaw()))


INF = 1 << 29

DIV = (10**9) + 7


def mod_inv_prime(a, mod=DIV):
    return pow(a, mod-2, mod)


def ncr(n, r, mod=DIV):
	r = min(r, n-r)
	ret = 1
	for i in range(1, r+1):
		ret = ret * (n-i+1) % mod
		ret = ret * mod_inv(i, mod) % mod
	return ret


def mod_inv(a, b):
    r = a
    w = b
    u = 1
    v = 0
    while w != 0:
        t = r//w
        r -= t*w
        r, w = w, r
        u -= t*v
        u, v = v, u
    return (u % b+b) % b


def CONV_TBL(max, mod=DIV):
    fac, finv, inv = [0]*max, [0]*max, [0]*max
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1
    for i in range(2, max):
        fac[i] = fac[i-1]*i % mod
        inv[i] = mod - inv[mod % i] * (mod//i) % mod
        finv[i] = finv[i-1]*inv[i] % mod

    class CONV:
        def __init__(self):
            pass

        def ncr(self, n, k):
            if(n < k):
                return 0
            if(n < 0 or k < 0):
                return 0
            return fac[n]*(finv[k]*finv[n-k] % mod) % mod
    return CONV()


def main():
    H,W = isRaw()
    if W==1 or H==1:
        return 1
    return (H*W+1)//2


if __name__ == "__main__":
    print(main())


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

int main(){
  int N;
  cin >> N;
  vector<long long> A(100);
  A[0] = 2;
  A[1] = 1;
  for(int i=2;i<=N+1;i++){
    A[i] = A[i-1]+A[i-2];
  }
  cout << A[N] << endl;
}
  
  

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
typedef long long ll;
typedef pair<int, int> P;

int main(){
    string s,t;
    cin >> s;
    cin >> t;
    int alphabet1[26];
    int alphabet2[26];
    for(int i = 0; i < 26; i++){
        alphabet1[i]  = -1;
        alphabet2[i] = -1;

    }
    bool ok = true;
    for(int i = 0; i < s.length();i++){
        int index1,temp1;
        index1 = s[i] - 'a';
        temp1 = t[i] - 'a';
        if(alphabet2[temp1] == -1){
            alphabet2[temp1] = index1;
        }
        if(alphabet1[index1] == -1){
            alphabet1[index1] = temp1;
        }
        if(alphabet2[temp1] != index1 || alphabet1[index1] != temp1){
            ok = false;
            break;
        }
    }
    /*for(int i = 0; i < s.length();i++){
        cout << "unchi" << i+1 << alphabet[i] << endl;
    }*/
    if(ok){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3908
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define m0(x) memset(x,0,sizeof(x))
#define print(x) cout<<x<<endl;
#define pe(x) cout<<x<<" ";
#define lb(v,n) lower_bound(v.begin(), v.end(), n);
#define ub(v,n) upper_bound(v.begin(), v.end(), n);
#define int long long
#define all(x) (x).begin(), (x).end()

using namespace std;

const int MAX = 1010000;
const int MOD = (ll)1000000000 + 7;
const ll INF = 1e17;
const double pi = acos(-1);
const double EPS = 1e-10;

//typedef pair<int, int> P;

vector<int>a, b,am,bm;


signed main() {
	int N; cin >> N;
	a.resize(N); b.resize(N);
	am.resize(N); bm.resize(N);
	REP(i, N)cin >> a[i];
	REP(i, N)cin >> b[i];
	int ans = 0;
	REP(k, 45) {
		int T = 1LL << k;
		//print(T);
		REP(i, N) {
			am[i] = a[i] % (2 * T);
			bm[i] = b[i] % (2 * T);
		}
		//bm[N] = INF;
		VSORT(bm);
		
		int cnt = 0;
		REP(i, N) {
			auto itr = lb(bm, T - am[i]);
			int it = itr - bm.begin();
			itr = lb(bm, 2 * T - am[i]);
			int it2 = itr - bm.begin();
			itr = lb(bm, 3 * T - am[i]);
			int it3 = itr - bm.begin();
			cnt += N - it3;
			cnt += it2 - it;
		}
		if (cnt % 2 == 1) {
			ans += (1LL << k);
		}
	}
	print(ans);
}


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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int main() {
  ll N; cin >> N;

  string S = to_string(N);
  int S_size = S.size();

  vector<int> ans;
  ans.push_back(char_to_int(S[0]) - 1);
  REP(i, S_size - 1) {
    ans.push_back(9);
  }

  vector<int> ans2;
  REP(i, S_size) {
    ans2.push_back(char_to_int(S[i]));
  }

  cout << max(accumulate(all(ans), 0LL), accumulate(all(ans2), 0LL)) << endl;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner scan =new Scanner(System.in);
		while(true){
		int n=scan.nextInt();
		if(n==0)break;
		int []a=new int[n];
		for(int i=0;i<n;i++){
			a[i]=scan.nextInt();
		}
		int m=scan.nextInt();
		int r=a.length-1,l=0,cnt=0;
		while(l<=r){
			int h =(r+l)/2;
			++cnt;
			if(a[h]==m)break;
			if(a[h]<m){
				l=h+1;
			}
			else{
				r=h-1;
			}
		}
		System.out.println(cnt);
	}
	}
}

Measured memory_bytes: 20332
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define vi vector<int>
#define vll vector<long long>
#define FOR(n) for(int i=0;i<n;i++)
#define till(n) for(int i=1;i<=n;i++)
#define mod 1000000007
using namespace std;




int main(){
    //ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

    int n;cin>>n;

    int h[100005];

    ll dp[100005];

    for(int i=1;i<=n;i++)cin >>h[i], dp[i]=-1;
    dp[1] = 0; dp[2] = abs(h[2]-h[1]);

    for(int i=3;i<=n;i++)
        dp[i] = min(dp[i-1] + abs(h[i]-h[i-1]), dp[i-2] + abs(h[i]-h[i-2]));

    cout << dp[n] << endl;

	return 0;
}


Measured memory_bytes: 1408
#include<algorithm>
#include<iostream>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<cmath>
#include<list>
#include<set>
#include<map>

using namespace std;

int main() {
	int N;
	vector<int> D;
	cin >> N;
	for (int i = 0; i < N; ++i) {
		int d;
		cin >> d;
		D.push_back(d);
	}
	int sumXY = 0;
	for (int i = 0; i < N; ++i) {
		for (int j = i + 1; j < N; ++j) {
			sumXY += D[i] * D[j];
		}
	}
	cout << sumXY << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<ll> vi;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define sq(x) ((x)*(x))
#define fo(i,n) for(int i=0;i<n;i++)
#define fp(i,k,n) for(int i=k;i<n;i++)
#define Fo(i,n) for(int i=1;i<=n;i++)
#define all(x) x.begin(),x.end()
#define fi first
#define se second
const double pi = 3.14159265358979323846;
#define uni(c) (c).resize(unique(all(c))-(c).begin())
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL)
//pair <int, int> w[4] = {mp(-1, 0), mp(0, -1), mp(1, 0), mp(0, 1)};   // for matrix movement:
void cp()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif // ONLINE_JUDGE
}

void solve()
{
	ll n; cin >> n;
	ll a[n + 1] = {0};
	for (int i = 1; i <= n; i++)
		cin >> a[i];
	ll dp[n + 1] = {0};
	dp[2] = abs(a[1] - a[2]);
	for (int i = 3; i <= n; i++)
	{
		dp[i] = min(dp[i - 1] + abs(a[i] - a[i - 1]), dp[i - 2] + abs(a[i] - a[i - 2]));
	}
	cout << dp[n];
}
int main()
{
	fast;
	//cp();
	ll t = 1;
	//cin >> t;
	while (t--)
		solve();


	return 0;
}

Measured memory_bytes: 1792
def f(s):
    cnt=0
    for i in range(len(s)):
        if s[i]=="1":
            cnt+=1
    return cnt
n=int(input())
a=[0]*n
x=[0]*n
for i in range(n):
    a[i]=int(input())
    x[i]=[list(map(int,input().split())) for j in range(a[i])]
    for j in range(a[i]):
        x[i][j][0]-=1
#print(x)
b=2**n
s = [bin(i)[2:] for i in range(b)]
for i in range(b):
    s[i]='0'*(n-len(s[i]))+s[i]
    s[i]=s[i][::-1]
ans=0

for i in range(b):
    cnt=0
    z=False
    for j in range(n):
        if s[i][j]=="1":
            for k in range(a[j]):
                if int(s[i][x[j][k][0]])!=x[j][k][1]:
                    z=True
                    break
            if z:
                break
        if j==n-1:
            cnt=f(s[i])
    ans=max(ans,cnt)
print(ans)

Measured memory_bytes: 5428
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;


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


	int x, a, b;
	cin >> x >> a >> b;
	a -= b;
	if (a >= 0) cout << "delicious";
	else if (a < -x) cout << "dangerous";
	else cout << "safe";

	return 0;
}


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

int main() {
  int N, Y;
  scanf("%d %d",&N,&Y);
  bool f=false;
  int x, y, z;
  int x1, y1, z1;
  for (x=0; x<=N; x++) {
    for (y=0; x+y<=N; y++) {
      if ((10000*x+5000*y+1000*(N-x-y))==Y) {
        x1=x;
        y1=y;
        z1=N-x-y;
        f=true;
      }
    }
  }
  if (f==true) {
    printf("%d %d %d\n",x1,y1,z1);
  } else {
    printf("-1 -1 -1\n");
  }
  return 0;
}


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

#define T 1261
#define R 1001

int main()
{
  int N,M,r,q,t[R],n[R],m[R],s[R],i,a,b,c,ans;
  while(cin>>N>>M,N|M){
    cin>>r;
    for(i=0;i<r;i++)cin>>t[i]>>n[i]>>m[i]>>s[i];
    cin>>q;
    while(q-->0){
      cin>>a>>b>>c;
      int time[T]={0};
      for(i=0;i<r;i++){
	if(m[i]!=c)continue;
	time[t[i]] += s[i]==1?1:-1;
      }
      for(i=1;i<T;i++)time[i]+=time[i-1];
      ans=0;
      for(i=a;i<b;i++)ans += time[i]>0;
      cout<<ans<<endl;
    }
  }
}

Measured memory_bytes: 0
MOD = 10 ** 9 + 7


class ModFactorial:
    """
    階乗, 組み合わせ, 順列の計算
    """

    def __init__(self, n, MOD=10 ** 9 + 7):
        """

        :param n: 最大の要素数.
        :param MOD:
        """
        kaijo = [0] * (n + 10)
        gyaku = [0] * (n + 10)

        kaijo[0] = 1
        kaijo[1] = 1
        for i in range(2, len(kaijo)):
            kaijo[i] = (i * kaijo[i - 1]) % MOD
        gyaku[0] = 1
        gyaku[1] = 1
        for i in range(2, len(gyaku)):
            gyaku[i] = pow(kaijo[i], MOD - 2, MOD)
        self.kaijo = kaijo
        self.gyaku = gyaku
        self.MOD = MOD

    def nCm(self, n, m):
        return (self.kaijo[n] * self.gyaku[n - m] * self.gyaku[m]) % self.MOD

    def nPm(self, n, m):
        return (self.kaijo[n] * self.gyaku[n - m]) % self.MOD

    def factorial(self, n):
        return self.kaijo[n]


N, K = [int(_) for _ in input().split()]
modf = ModFactorial(N)

A = [int(_) for _ in input().split()]
A.sort()
i = 1
maxv = 0
for i in range(N):
    if K - 1 <= i:
        maxv += modf.nCm(i, K - 1) * A[i]
        maxv %= MOD
# print(maxv)
A.reverse()
minv=0
for i in range(N):
    if K - 1 <= i:
        minv += modf.nCm(i, K - 1) * A[i]
        minv %= MOD
print((maxv-minv)%MOD)


Measured memory_bytes: 85088
//PLUS ULTRA

#include<bits/stdc++.h>
using namespace std;
     
     
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define pb push_back 
#define mp make_pair
#define forn(i,st,n) for(int i = st; i < n ; i++)
#define nfor(i,st,n) for(int i = st; i >= n ; i--)

typedef long long ll;
typedef pair <int , int> pii;

const int N = 1e5 + 10 , mod =  1000000007;



int main(){
    SPEED;

    int n , k;;

    cin >> k >> n;

    int arr[n];

    forn(i,0,n){
    	cin >> arr[i];

    }

    sort(arr , arr+n);

    int maxi = arr[0] + k - arr[n-1];

    forn(i,0,n-1){
    	if(arr[i+1] - arr[i] > maxi)maxi = arr[i+1] - arr[i];
    }


    cout << k - maxi << endl;

    
    return 0;
}
      
       


Measured memory_bytes: 1024
#include <iostream>
#include <numeric>

using namespace std;
typedef long long ll;

int gcd_3(int a, int b, int c) {
    return gcd(gcd(a, b), c);
}

int main(void) {
    int k;
    cin >> k;
    ll sum=0;
    for (int a = 1; a <= k; a++) {
        for (int b = 1; b <= k; b++) {
            for (int c = 1; c <= k; c++) {
                sum += gcd_3(a, b, c);
            }
        }
    }
    cout << sum;
}

Measured memory_bytes: 3560
#!usr/bin/env python
# -*- coding: utf-8 -*-

while True:
        n = int(raw_input())
        if n == 0:
                break
        list = []
        for i in range(n):
                list.append(int(raw_input()))
        print (sum(list) - max(list) - min(list))/(n-2)

Measured memory_bytes: 6388
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip.split())
def main():
    n = I()
    lst = []
    for _ in range(n):
        st = S()
        st = list(st)
        st.sort()
        lst.append("".join(st))

    ans = 0
    dic = collections.Counter(lst)
    for key,value in dic.items():
        if value >= 2:
            ans += value*(value-1)//2
    print(ans)
main()

Measured memory_bytes: 104788
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define pii pair <ll,ll>
#define vl vector <ll>
#define vp vector <pair<ll,ll>>
#define sort(x) sort(x.begin(), x.end())
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n,i,ans = 0,j,a,b;
    cin>>n;
    ll c[10][10];
    for(i=0;i<10;i++)
        for(j=0;j<10;j++)
            c[i][j] = 0;
    for(i=1;i<=n;i++)
    {
        j = i;
        a = i%10;
        while(j)
        {
            b = j%10;
            j = j/10;
        }
        c[a][b]++;
    }
    for(i=0;i<10;i++)
        for(j=0;j<10;j++)
            ans += c[i][j]*c[j][i];
    cout<<ans;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
typedef pair<lint, lint> P;

signed main(){
	lint N, K; cin >> N >> K;
	vector<lint> x(N), y(N), xa, ya;
	for(int i = 0; i < N; i++) cin >> x[i] >> y[i], xa.push_back(x[i]), ya.push_back(y[i]);
	sort(xa.begin(), xa.end());
	sort(ya.begin(), ya.end());
	lint ans = 5e18;
	for(int i = 0; i < N; i++){
		for(int j = i + 1; j < N; j++){
			for(int k = 0; k < N; k++){
				for(int l = k + 1; l < N; l++){
					lint x1 = xa[i], x2 = xa[j], y1 = ya[k], y2 = ya[l];
					int c = 0;
					for(int m = 0; m < N; m++){
						if(x1 <= x[m] && x[m] <= x2 && y1 <= y[m] && y[m] <= y2) c++;
					}
					if(c >= K) ans = min(ans, (x2 - x1) * (y2 - y1));
				}
			}
		}
	}
	cout << ans << endl;
}

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

int main(){
    int S[13]={0};
    int H[13]={0};
    int C[13]={0};
    int D[13]={0};
    
    unsigned n;
    unsigned char I;
    unsigned J;
    
    cin>>n;
   
   
    while(n--){
        cin>>I>>J;
        switch(I){
            case 'S':
                S[J-1]=1;
                break;
            case 'H':
                H[J-1]=1;
                break;
            case 'C':
                C[J-1]=1;
                break;
            case 'D':
                D[J-1]=1;
            default:
                break;
                
        }
    }
    

    for(int i=0;i<13;++i){
        if(S[i]==0){
            cout<<"S "<<i+1<<endl;
        }
    }
    for(int i=0;i<13;++i){
        if(H[i]==0){
            cout<<"H "<<i+1<<endl;
        }
    }
    for(int i=0;i<13;++i){
        if(C[i]==0){
            cout<<"C "<<i+1<<endl;
        }
    }
    for(int i=0;i<13;++i){
        if(D[i]==0){
            cout<<"D "<<i+1<<endl;
        }
    }
    
    
}



Measured memory_bytes: 3092