akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define int         long long
#define io ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define mi          map<int,int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define endl        '\n'
#define hell        1000000007
using namespace std;
void solve()
{
    string s;
    cin>>s;
    int n=s.length();
    string t="";
    for(int i=0;i<n;i++)
    {
        if(s[i]=='A')
            t+='0';
        else if(i+1<n && s[i]=='B' && s[i+1]=='C')
            t+='1';
        else if(s[i]=='B')
            t+='2';
        else if(s[i]=='C')
            t+='2';
    }
    int c=0,ans=0;
    for(int i=0;i<t.length();i++)
    {
        if(t[i]=='0')
            c++;
        else if(t[i]=='1')
            ans+=c,i++;
        else
            c=0;
    }
    cout<<ans;
    
}
signed main(){
    io;
    int t=1;
    //cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

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

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

    int n, k; cin >> n >> k;

    int r, s, p; cin >> r >> s >> p;
    vector<int> point(128, 0);
    point['r'] = p;
    point['s'] = r;
    point['p'] = s;

    string t; cin >> t;

    vector<vector<int> > dp(n + 1, vector<int>(3, 0));

    vector<bool> flag(100001, false);

    REP(i, n) REP(j, 3) {
        if (i - k >= 0 && flag[i - k] && t[i] == t[i - k])
            dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
        else {
            dp[i + 1][j] = max(dp[i + 1][j], dp[i][j] + point[t[i]]);
            flag[i] = true;
        }
    }

    int ans = 0;
    REP(i, 3) ans = max(ans, dp[n][i]);
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 5840
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using ll = long long;
#define all(v) v.begin(), v.end()
int main() {

ll  A,B,C,K;
cin >>A>>B>>C>>K;
if(K<=A){
    cout<<K<<endl;
}
else if(K<=(A+B)){

    cout<<A<<endl;
}
else{
    cout<<(2*A+B-K)<<endl;
}


}


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

#define ll long long
#define rep(i,a,n) for(ll i=a;i<=n;i++)
#define rop(i,n) for(ll i=0;i<n;i++)
#define pb push_back
#define pob pop_back
#define pf push_front
#define pis pair<int, string>
#define pof pop_front
#define pii pair<int,int>
#define pll pair<ll, ll>
#define mp make_pair
#define fi first
#define se second
#define endl '\n'

const int dr[]={-1,1,0,0};
const int dc[]={0,0,1,-1};
const int drd[]={-1,-1,1,1};
const int dcd[]={-1,1,-1,1};
const int MOD = 1e9 + 7;
const int INF = 1e9;
const int MAX = 1e5 + 5;
const double phi= acos(-1);


int c,n,m,s,dp[10005][10005];
pii item[10005];
int main()
{
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
//	freopen("input.txt","r",stdin);
//	freopen("output.txt","w",stdout);
	cin>>c>>n>>m;
	rep(i,1,n)
	{
		cin>>item[i].fi>>item[i].se;
	}
//	sort(item+1, item+1+n);
	rep(i,1,n)
	{
		rep(j,1,c)
		{
			if(j<item[i].fi) dp[i][j]=dp[i-1][j];
			else
			{
				dp[i][j]=max(item[i].se+dp[i-1][j-item[i].fi], dp[i-1][j]);
			}
		}
	}
	rep(i,1,m)
	{
		s=c/i;
		cout<<dp[n][s]*i<<endl;
	}
	return 0;
}




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

using namespace std;

int main() {
	int a[3][3], count[3][3];
	int N;

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

	cin >> N;

	vector<int> b(100, 0);
	for (int i = 0; i < N; i++) {
		int n;
		cin >> n;
		b[n] = 1;
	}

	int ans = 0;
	for (int i = 0; i < 3; i++) {
		ans = 0;
		for (int j = 0; j < 3; j++) {
			ans += b[a[i][j]];
		}
		if (ans == 3) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	for (int i = 0; i < 3; i++) {
		ans = 0;
		for (int j = 0; j < 3; j++) {
			ans += b[a[j][i]];
		}
		if (ans == 3) {
			cout << "Yes" << endl;
			return 0;
		}
	}

	ans = 0;
	for (int i = 0; i < 3; i++) {
		ans += b[a[i][i]];
	}
	if (ans == 3) {
		cout << "Yes" << endl;
		return 0;
	}

	ans = 0;
	for (int i = 0; i < 3; i++) {
		ans += b[a[2 - i][i]];
	}
	if (ans == 3) {
		cout << "Yes" << endl;
		return 0;
	}

	cout << "No" << endl;

	return 0;
}

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

using namespace std;

int main(int argc, char **argv)
{
	int n, m, **a, s, t, c, *b;
	
	while(1){
		cin >> n;
		cin >> m;
		if(n == 0 && m == 0){
			break;
		}
		c = 0;
		a = (int **)calloc(n+1, sizeof(int));
		b = (int *)calloc(n+1, sizeof(int));
		for(int i = 0; i <= n; i++){
			a[i] = (int *)calloc(n+1, sizeof(int));
		}
		
		for(int i = 0; i < m; i++){
			cin >> s >> t;
			if(s == 1 || t == 1){
				a[s][t] = a[t][s] = 1;
				b[t] = b[s] = 1;
			} else {
				a[s][t] = a[t][s] = 2;
			}
		}
		
		for(int i = 2; i <= n; i++){
			if(a[1][i] == 1){
				for(int j = 2; j <= n; j++){
					if(a[i][j] == 2 && b[j] == 0){
						b[j] = 1;
					}
				}
			}
		}
		b[1] = 0;
		for(int i = 0; i <= n; i++){
			free(a[i]);
			c += b[i];
		}
		free(a);
		free(b);
		
		cout << c << endl;
	}
	
	return 0;
}

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

vector<int>to[200005],ans;
void dfs(int v,int p=-1){
    for(int u:to[v]){
        if(u==p)continue;
        ans[u]+=ans[v];
        dfs(u,v);
    }
}

int main(){
    int n,q;
    cin>>n>>q;
    rep(i,n-1){
        int a,b; cin>>a>>b;
        a--; b--;
        to[a].push_back(b);
        to[b].push_back(a);
    }
    ans.resize(n);
    rep(i,q){
        int p,x;
        cin>>p>>x;
        p--;
        ans[p]+=x;
    }
    dfs(0);
    rep(i,n)cout<<ans[i]<<" ";
    cout<<endl;
    return 0;
}

Measured memory_bytes: 23424
#include <atcoder/dsu>
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n, q, i, ans[200100]={0}, cnt=0;
    cin >> n >> q;
    atcoder :: dsu d(n);
    for(i=0;i<q;i++){
        int t, u, v;
        cin >> t >> u >> v;
        if(t==0) d.merge(u, v);
        else if(d.same(u, v)){
            ans[cnt]=1;
            cnt++;
        }
        else{
            ans[cnt]=0;
            cnt++;
        }
    }
    for(i=0;i<cnt;i++){
        cout << ans[i] <<endl;
    }
    return 0;
}


Measured memory_bytes: 4596
#include<bits/stdc++.h>
#define ll long long
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
using namespace std;

int main()
{
    ll n;
    cin>>n;
    
    ll a[n+1] = {0};
    ll b[n+1] = {0};
    
    for(ll i=1;i<n;i++) cin>>a[i];
    for(ll i=1;i<=n;i++)    b[i] = 100000000;
    
    for(ll i=1;i<n;i++)
    {
        b[i] = min(b[i],a[i]);
        b[i+1] = min(b[i+1],a[i]);
    }
    
    ll ans = 0;
    for(ll i=1;i<=n;i++)    ans += b[i];
    cout<<ans;
    
    return 0;
}


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

const ll MOD = 1e9 + 7;

ll modPow(ll a, ll x) {
  if (x == 0) return 1;
  if (x == 1) return a;
  ll temp = modPow(a, x / 2);
  ll ans = (temp * temp) % MOD;
  if (x % 2 == 1) ans = (ans * a) % MOD;
  return ans;
}

ll modInv(ll a) {
  return modPow(a, MOD - 2);
}

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

  ll K; cin >> K;
  string S; cin >> S;
  ll N = S.size();
  ll ans = 0;

  ll C = 1;
  ll m25 = 1;
  ll m26 = 1;
  for (ll i = 0; i < K; i++) {
    m26 = (m26 * 26) % MOD;
  }
  ll inv26 = modInv(26);
  for (ll i = N - 1; i < N + K; i++) {
    if (i != N - 1) {
      C = (C * i) % MOD;
      ll temp = i - N + 1;
      C = (C * modInv(temp)) % MOD;

      m26 = (m26 * modInv(26)) % MOD;
      m25 = (m25 * 25) % MOD;
    }

    ll temp1 = (C * m25) % MOD;
    temp1 = (temp1 * m26) % MOD;

    ans = (ans + temp1) % MOD;
  }
  cout << ans << '\n';
  return 0;
}

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

int main() {
	int n;
	cin>>n;
	int arr[n];
	int sum=0;
	for(int i=0;i<n;i++){
		cin>>arr[i];
		sum+=arr[i];
	}
	int sum2=0;
	int mn=INT_MAX;
	for(int i=0;i<n;i++){
		sum2+=arr[i];
		mn=min(mn,abs(sum-2*sum2));
	}
	cout<<mn;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

vector<int> Zalgorithm(const std::string& s){
  int ret = 0;
  int n = s.length();
  std::vector<int> z(n, 0);

  int L = 0, R = 0;
  for(int i=1; i<n; i++){
    if(i>R){
      L = R = i;
      while(R<n && s[R-L] == s[R]) R++;
      z[i] = R-L;
      R--;
    }else{
      int k = i-L;
      if(z[k] < R-i+1){
        z[i] = z[k];
      }else{
        L = i;
        while(R<n && s[R-L] == s[R]) R++;
        z[i] = R-L;
        R--;
      }
    }
  }
  return z;
}

int main(){
  int N;
  cin >> N;
  string S;
  cin >> S;

  int ret = 0;
  rep(i,S.size()){
    string T = S.substr(i);
    vector<int> res = Zalgorithm(T);
    rep(j,res.size()){
      if(res[j]<=j) ret = max(ret, res[j]);
    }
  }

  cout << ret << endl;
  
  return 0;
}


Measured memory_bytes: 384
using System;

class ITP1_7_C{
    static void Main(string[] args){
        string[] snum = new string[2];
        snum = Console.ReadLine().Split(' ');
        int r = int.Parse(snum[0]);
        int c = int.Parse(snum[1]);
        int[][] rxc = new int[r][];
        int[] retu = new int[c+1];
        for(int i=0; i<r; i++){
            rxc[i] = new int[c+1];
            string[] str = Console.ReadLine().Split(' ');
            for(int j=0; j<c; j++){
                rxc[i][j] = int.Parse(str[j]);
                rxc[i][c] += rxc[i][j];
                retu[j] += rxc[i][j];
            }
            retu[c] += rxc[i][c];
        }
        foreach(int[] a in rxc){
            int x=0;
            foreach(int b in a){
                Console.Write(b);
                if(x!=c){
                    Console.Write(" ");
                }
                x++;
            }
            Console.WriteLine();
        }
        int y=0;
        foreach(int d in retu){
            Console.Write(d);
            if(y!=c){
                    Console.Write(" ");
                }
            y++;
        }
        Console.WriteLine();
    }
}


Measured memory_bytes: 17964
# include <stdio.h>
# include <string.h>
# include <stdlib.h>
# include <iostream>
# include <vector>
# include <queue>
# include <stack>
# include <map>
# include <math.h>
# include <algorithm>
using namespace std;
# define pi acos(-1.0)
# define mem(a,b) memset(a,b,sizeof(a))
# define FOR(i,a,n) for(int i=a; i<=n; ++i)
# define FO(i,a,n) for(int i=a; i<n; ++i)
typedef long long LL;
typedef unsigned long long ULL;

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





















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

using namespace std;
typedef long long LL;
int ff[200005] = {};

int f(int x) {
    if (x == 0)return 0;
    if (ff[x]) return ff[x];
    int cnt1 = 0;
    for (int i = 0; i < 20; i++) {
        if (x & (1 << i))cnt1++;
    }
    int i1 = x % cnt1;
    if (i1 == 0) {
        ff[x] = 1;
        return 1;
    }
    return ff[x] = f(i1) + 1;
}
int mmd[200005];
int mod(string a, int b) {
    int d = 0;
    for (int i = 0; i < a.size(); i++) d = (d * 10 + (a[i] - '0')) % b;  //求出余数
    return d;
}

string s;
int ans[200006];
int main() {
    int n;
    cin >> n;
    int p = 0;
    cin >> s;
    int cnt1 = 0;
    for (int i = 0; i < n; ++i) {
        if (s[i] == '1') cnt1++;
    }

    int mmd[3] = {};
    int d = 1;
    if(cnt1 >= 2) {
        for (int i = 0; i < n; ++i) {
            if(s[n - i - 1] == '1'){
                mmd[0] += d;
                mmd[0] %= cnt1 - 1;
            }
            d *= 2;
            d %= cnt1 - 1;
        }
    }

    d = 1;
    if(cnt1 >= 1){
        for (int i = 0; i < n; ++i) {
            if(s[n - i - 1] == '1'){
                mmd[1] += d;
                mmd[1] %= cnt1;
            }
            d *= 2;
            d %= cnt1;
        }
    }

    d = 1;
    for (int i = 0; i < n; ++i) {
        if(s[n - i - 1] == '1'){
            mmd[2] += d;
            mmd[2] %= cnt1 + 1;
        }
        d *= 2;
        d %= cnt1 + 1;
    }

    int d1 = 1;
    int d2 = 1;
    for (int i = 0; i < n; ++i) {
        bool add1 = s[n - i - 1] == '0';
        int md = cnt1 + (add1 ? 1 : -1);
        if(md)ans[n - i - 1] = f((mmd[add1 ? 2: 0] + (add1 ? d1 : -d2) + md) % md) + 1;
        else ans[n - i - 1] = 0;
        d1 *= 2;
        d2 *= 2;
        d1 %= cnt1 + 1;
        if(cnt1 - 1 != 0) d2 %= cnt1 - 1;
    }


    for (int i = 0; i < n; ++i) {
        cout<<ans[i]<<endl;
    }
}

Measured memory_bytes: 4832
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    var a = readLine()!!
    var r = 0
    var rm = 0
    for (i in 0 until n){
        when(a[i]) {
            'I' -> {
                r += 1
                if(r > rm) rm = r
            }
            'D' -> {
                r -= 1
            }
        }
    }
    println(rm)
}

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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

int n, m, R, r[8], INF = 100000 * 200 * 8;

int main() {
	cin >> n >> m >> R;
	inc(i, R) { cin >> r[i]; r[i]--; }
	
	int d[200][200];
	fill(d[0], d[200], INF);
	inc(i, n) { d[i][i] = 0; }
	
	inc(i, m) {
		int a, b, c;
		cin >> a >> b >> c;
		a--; b--;
		d[a][b] = c;
		d[b][a] = c;
	}
	
	inc(k, n) {
	inc(i, n) {
	inc(j, n) {
		setmin(d[i][j], d[i][k] + d[k][j]);
	}
	}
	}
	
	sort(r, r + R);
	int ans = INF;
	do {
		int sum = 0;
		inc(i, R - 1) { sum += d[r[i]][r[i + 1]]; }
		setmin(ans, sum);
	} while(next_permutation(r, r + R));
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define long long long int
using namespace std;

// @author: pashka

int main() {
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    long res = 0;
    for (int i = 1; i <= n; i++) {
        if (i % 3 != 0 && i % 5 != 0) {
            res += i;
        }
    }
    cout << res << "\n";

    return 0;
}

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

using namespace std;
using ll = long long;
using P = pair<int, int>;
#define all(c) (c).begin(), (c).end()
const int INF = 1e9 + 1;
const ll LINF = 1e18 + 1;
const ll MOD = 1e9 + 7;

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

  int n, m;
  cin >> n >> m;
  vector<vector<int>> G(n);
  vector<vector<double>> E(n, vector<double>(n, 0.0));

  for (int i = 0; i < m; ++i) {
    int s, t;
    cin >> s >> t;
    --s;
    --t;
    G[s].push_back(t);
  }

  for (int i = n - 2; i >= 0; --i) {
    double sz = G[i].size();
    for (int j = 0; j <= n - 1; ++j) {
      double sum = 0.0, mx = 0.0;
      for (auto t : G[i]) {
        sum += E[t][j] + 1.0;
        mx = max(mx, E[t][j] + 1.0);
      }
      if (i == j) {
        E[i][j] = sz == 1.0 ? sum : (sum - mx) / (sz - 1.0);
      } else {
        E[i][j] = sum / sz;
      }
    }
  }
  // dump(E);
  cout << setprecision(10) << *min_element(all(E[0])) << endl;
  return 0;
}


Measured memory_bytes: 4224
/*
 * 競技プログラミング用テンプレート
 * by yuma140902
 * 2019/12/08
 * ver 0.2.0
 */
#include <bits/stdc++.h>
using namespace std;
typedef int64_t ll;
typedef tuple<int, int> ii;
typedef tuple<int, int, int> iii;
const int INF = 900000;
const ll INFL = 9000000;

#define vi vector<int>
#define vii vector<vector<int> >
#define vi_def(n) vector<int>((n))
#define vii_def(n,m) vector<vector<int> >((n), vector<int>((m)))
#define vi_def_dflt(n, def) vector<int>((n), (def))
#define vii_def_dflt(n, m, def) vector<vector<int> >((n), vector<int>((m), (def)))

#define rep(i, n) for(int i=0; i < (n); ++i)
#define per(i, n) for(int i=(n)-1; i >= 0; --i)
#define range(i, begin, end) for(int i=(begin); i < (end); ++i)

int X;
int main(){
  cin >> X;
  int n = X;
  for(;;){
    int sqrt = std::sqrt(n);
    bool isPrime = true;
    for(int divisor=2; divisor<=sqrt; ++divisor){
      if(n%divisor == 0) {
        isPrime = false;
        break;
      }
    }
    if(isPrime) {
      cout << n << endl;
      return 0;
    }
    else ++n;
  }
}


Measured memory_bytes: 256
d = int(input())
c_l = list(map(int,input().split()))
s_l = [list(map(int,input().split())) for i in range(d)]

last_l = [-1 for i in range(26)]

def calc_score(contest_num):
  contest_val = s_l[day][contest_num]
  point = contest_val

  temp_last_l = last_l[:]
  temp_last_l[contest_num] = day

  for i in range(26):
    point -= c_l[i] * (day - temp_last_l[i])

  return point

ans = []

point = 0
for day in range(d):
  each_point = 0
  each_contest_num = 0
  for temp_contest_num in range(26):
    temp_point = calc_score(temp_contest_num)
    if temp_point > each_point:
      each_point = temp_point
      each_contest_num = temp_contest_num

  ans.append(each_contest_num + 1)

for i in ans:
  print(i)

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

#define int long long

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int A, B, C;
  cin >> A >> B >> C;

  int ans = min(A+B, C) + B;
  if ( C-(A+B) > 0 ) ans++;
  cout << ans << endl;
  
  
  return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
N = int(input())
mod = 10 ** 9 + 7
e = [[] for _ in range(N + 1)]
for _ in range(N - 1):
  u, v = map(int, input().split())
  e[u].append(v)
  e[v].append(u)

s = [1]
order = []
parent = [0] * (N + 1)
size = [1] * (N + 1)
vis = [0] * (N + 1)
while len(s):
  x = s.pop()
  order.append(x)
  vis[x] = 1
  for y in e[x]:
    if vis[y]: continue
    s.append(y)
    vis[y] = 1
    parent[y] = x

order.reverse()
for y in order[: -1]: size[parent[y]] += size[y]
#print(size)

rev = lambda x: pow(x, mod - 2, mod)
res = rev(2) - rev(pow(2, N, mod))
res %= mod
for y in e[1]:
  res -= rev(pow(2, N - size[y], mod)) * (1 - rev(pow(2, size[y], mod)))
  res %= mod
#print(res)

order.reverse()
for y in order[1: ]:
  t = rev(2) - rev(pow(2, N, mod))
  x = parent[y]
  #print(t)
  for z in e[y]:
    if x == z: continue
    t -= rev(pow(2, N - size[z], mod)) * (1 - rev(pow(2, size[z], mod)))
    t %= mod
  #print(t)
  t -= rev(pow(2, size[y], mod)) * (1 - rev(pow(2, N - size[y], mod)))
  t %= mod
  res += t
  res %= mod
  #print(t)
print(res)

Measured memory_bytes: 129392
#include<vector>
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include <iostream>
#include <algorithm>
#include <map>
#include <cmath>
#include<queue>
#include <sstream>
#include <set>

const long long INF = 1000000007;
using namespace std;
typedef long long llong;

//int isalpha(char ch): ch がアルファベットなら true を返す
//int isdigit(char ch): ch が数字なら true を返す
//int islower(char ch): ch が小文字なら true を返す
//int isupper(char ch): ch が大文字なら true を返す
//int tolower(char ch): ch の小文字を返す
//int toupper(char ch): ch の大文字を返す

//string型
//size()	文字数を返す
//Insert()	（指定した場所に）文字・文字列を挿入する
//erase()	（指定した場所の）文字・文字列を削除する
//clear()	すべての文字を削除する
//substr()	文字列の（指定した）部分文字列を返す
//replace()	（指定した）部分文字列を新しい文字列に置換する
//c_str()変換
//文字列の比較は、<=や==などを使え
//replace関数を使い、簡単に文字列を置換
//リバース関数：reverse(str.begin(), str.end());
//map<type, type> dict;で宣言
//グラフ理論用変数
//vector<vector<llong> > graph(N);

//ソート
//降順sort(v.begin(), v.end(), std::greater<Type>());

//大文字から小文字へんかん
//w[i] = w[i]-'A'+'a';

//vector
//assignメソッド　引数：サイズ、値
//与えられたサイズと値でvectorを初期化する

//queueクラス
//find()次に取り出す値の表示をする。
//pop()値を取り出す。戻り値はなし
//push()キューに値をプッシュする

//priority_queueクラス

//切り上げ
//ceil
//floor

int main(){
    llong N;
    cin >> N;
    vector<llong> A(N,0);
    llong totalA = 0;
    llong totalB = 0;

    for(int i=0; i<N; i++){
        cin >> A[i];
    }
    sort(A.begin(), A.end(), greater<llong>());
    for(int i=0; i<N; i++){
        if(i%2==0){
            totalA += A[i];
        }else{
            totalB += A[i];
        }
    }
    cout << totalA-totalB << endl;
    return 0;
}


Measured memory_bytes: 3192
#include <bits/stdc++.h>
#define rep(i, to) for (int i = 0; i < (to); i++)
#define rrep(i, to) for (int i = to - 1; i >= 0; i--)
#define repf(i, from, to) for (int i = (from); i < (to); i++)
#define all(v) v.begin(), v.end()
#define unless(cond) if (!(cond))
using namespace std;
using ll = long long;
template <typename T>
using V = vector<T>;
template <typename T, typename U>
using P = pair<T, U>;

int main() {
  int n;
  V<int> p;
  V<int> q;

  cin >> n;
  p.resize(n);
  q.resize(n);
  rep(i, n) {
    cin >> p[i];
  }
  rep(i, n) {
    cin >> q[i];
  }

  V<int> perm(n, 0);
  rep(i, n) {
    perm[i] = i + 1;
  }

  bool find_p = false;
  bool find_q = false;
  int a, b;
  int count = 0;
  do {
    count++;
    if(perm == p && !find_p) {
      a = count;
    }
    if(perm == q && !find_q) {
      b = count;
    }
  } while(next_permutation(all(perm)));

  cout << abs(a - b) << endl;
}

Measured memory_bytes: 3632
<?php
list($n, $m, $k) = ints();
$a = ints();
$b = ints();
$cnta[0] = $cntb[0] = 0;
for ($i = 0; $i < $n; ++$i) $cnta[$i + 1] = $cnta[$i] + $a[$i];
for ($i = 0; $i < $m; ++$i) $cntb[$i + 1] = $cntb[$i] + $b[$i];

$max = 0;
for ($i = 0; $i <= $n; ++$i) {
    $t = $cnta[$i];
    if ($t > $k) break;
    elseif ($t === $k) $max = max($max, $i);

    $ok = -1;
    $ng = $m + 1;
    while (abs($ok - $ng) > 1) {
        $mid = intdiv($ok + $ng, 2);
        if ($t + $cntb[$mid] <= $k) $ok = $mid;
        else $ng = $mid;
    }
    if ($ok >= 0) $max = max($max, $i + $ok);
}
echo $max;
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}


Measured memory_bytes: 52396
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String[] s = sc.nextLine().split("");

        int count=0;
        for (int i = 0; i < s.length; i++) {
            if (Integer.parseInt(s[i])==1) {
                count++;
            }
        }
        System.out.println(count);
    }
}

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

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef long long int64;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort(all(x))
#define GSORT(x) sort(all(x), greater<int>())
#define MIN(x) *min_element(all(x))
#define MAX(x) *max_element(all(x))
#define in(x) cin >> x
#define co(x) cout << x
#define el  cout << endl
#define dump(x)  cout << #x << " = " << (x) << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }


int main() {
    int a, b, c;
    cin >> a;
    cin >> b;
    c = 6 - a - b;
    cout << c << endl;


    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fin ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ii pair<int,int>
#define F first
#define S second
#define pb push_back
#define pf push_front
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fore(i,a,b) for(int i = a;i < b; i+= 1)
#define forr(i,a) for(int i = a; i >= 0; i--)
#define fori(i,m) for(auto i = m.begin(); i != m.end(); i++) 
#define w(t) while(t--)
#define sz(s) int(s.size())
#define cls(a,car) memset(a,car,sizeof (a))
#define ff(x) cerr << #x << " is " << x << '\n'
#define FL freopen("in", "r", stdin),freopen("out", "w", stdout);
#define time cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ii> vii;
const int N = 2 * 1e5 + 5;
const ll mod = 1e9 + 7;
const int INF = INT_MAX;
const ll INFCAD  = ll(INT_MAX) * 2 + 1;
const double E = 1e-9;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
// fflush(stdout)
// cout << flush
// a + b = a ^ b + 2 * (a & b) 
vi G[N], dis(N, 1e9), parent(N, -1);
void bfs(int node){
    queue<int> q;
    q.push(node);
    dis[node] = 0;
    while(sz(q)){
        int u = q.front();q.pop();
        for(auto v : G[u]){
            if(dis[v] > dis[u] + 1){
                dis[v] = dis[u] + 1;
                parent[v] = u;
                q.push(v);
            }
        }
    }
}
int main(){
    //FL;
    fin;
    int n, m;
    cin >> n >> m;
    w(m){
        int u, v;
        cin >> u >> v;
        u--;
        v--;
        G[u].pb(v);
        G[v].pb(u);
    }
    bfs(0);
        bool ok = 1;
        fore(i, 1, n)
            if(dis[i] == 1e9)
                ok = 0;
        if(ok){
            cout << "Yes\n";
            fore(i, 1, n)
                cout << parent[i] + 1 << '\n';
        }else cout << "No\n";
    time;
    return 0;
}   

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

typedef long long int ll;
typedef long double ld;

#define rep(i,a,b) for(ll i=a;i<=b;++i)
#define rev(i,a,b) for(ll i=a;i>=b;i--)
#define pll pair<ll,ll>
#define vll vector<ll>
#define sll set<ll>
#define vpll vector<pll>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define ln length()
#define M 1000000007
ll a,b,c,d,n;
int main(){
    ios::sync_with_stdio(false);cin.tie(0);
    cin>>a>>b>>c>>d>>n;
    ll ans = (n/2)*min(min(d,2*c),min(4*b,8*a));
    n=n%2;
    if(n == 1) ans+=min(c,min(2*b,4*a));
    cout<<ans<<'\n';
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
const double pi = 3.14159265358979323846;
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
int main()
{
   speed;
   ll n;
   cin>>n;
  
   ll a[n],sum=0,c=1;
   for(int i=0;i<n;i++)
      cin>>a[i];
   
  sort(a,a+n);
  sum=a[n-1];
  
  if(n>=3){
  for(int i=n-2;i>0;i--)
  {
     if(c+2<=n-1)
       sum+=2*a[i],c+=2;
    
    else if(c+1==n-1)
      sum+=a[i],c++;
     
    if(c==n-1)break;
  }
  }
  
  cout<<sum;
  return 0;
}

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

int main() {
	string s;
	cin >> s;
	for(int i = 0; i < 19; i++){
		if(s[i] == ','){
			cout << " ";
		}else{
			cout << s[i];
		}
	}
	cout << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <iterator>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
#include <time.h>
#include <complex>
#include <cstdint>
using namespace std;
using pii = pair<int, int>;
using ll = long long;
using ld = long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rRep(i,a,b) for(int i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
#define mod 1000000007
typedef long long ll;

/*
unsigned gcd(int a, int b) {
	while (1) {
		if (a < b) swap(a, b);
		if (!b) break;
		a %= b;
	}
	return a;
}


ll comb(int n, int r) {
	if (r * 2 > n) r = n - r;
	uintmax_t dividend = 1;
	uintmax_t divisor = 1;
	for (unsigned int i = 1; i <= r; ++i) {
		dividend *= (n - i + 1);
		divisor *= i;
	}
	return dividend / divisor;
}

int compare_char(const void* left, const void* right) {
	char *left_char = (char *)left;
	char *right_char = (char *)right;

	return strcmp(left_char, right_char);
}
*/


int main(){


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

	//int N, M, *A, *B, i, j, *W, *flag, sum=0, start, end, length, tmp;
	ll i, j, k, l, m, n, len;
	ll C, D, N, M, K, num_R, num_G, num_B, temp;
	ll sum = 0, sum_B = 0, sum_C = 0, max, min, count = 0, Q, W, X, flag=0;
	ll  *A, *B, *H, *ans;



	ll temp1, temp2;



	cin >> N >> M;


	H = (ll *)malloc(sizeof(ll)* N);

	A = (ll *)malloc(sizeof(ll)* M);

	B = (ll *)malloc(sizeof(ll)* M);

	ans = (ll *)malloc(sizeof(ll)* N);



	for (i = 0; i < N; i++)
		cin >> H[i];



	for (i = 0; i < M; i++){
		cin >> A[i] >> B[i];
		A[i]--;
		B[i]--;
	}


	for (i = 0; i < N; i++)
		ans[i] = 1;

	for (i = 0; i < M; i++){
		if (H[A[i]] > H[B[i]]){
			ans[B[i]] = 0;
		}
		else if (H[A[i]] == H[B[i]]){
			ans[A[i]] = 0;
			ans[B[i]] = 0;
		}
		else{
			ans[A[i]] = 0;
		}

	}

	count = 0;
	for (i = 0; i < N; i++)
		count += ans[i];

	cout << count << endl;



}//1 2 3 4 5 6
    

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

using namespace std;
typedef long long ll;
#define rep(i, j, n) for (int i = j; i < n; i++)
#define out(ans) cout << ans << endl;
const long long mod = 1e9 + 7;

int ans=0;
int a[200010];
vector<bool>v(200010,false);

bool check(int x){

  if(v[1]==true)return true;
  if(v[x]==false){
    v[x]=true;
    ans++;
    return check(a[x]);
  }else return false;

  return false;
}

int main(){

  int n;cin>>n;
  rep(i,0,n){
    cin>>a[i];
    a[i]--;
  }

  if(check(a[0]))out(ans)
  else out(-1)


  return 0;
}


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

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

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

const int INF = 1e9;
int n;
ll lcmn = 1;

int main() {
  cin >> n;
  vector<int> a(n);
  
  rep(i, n) {
    cin >> a[i];
    lcmn = lcm(lcmn, a[i]);
  }
  ll bunshi = 0;
  rep(i, n) bunshi += lcmn / a[i];
  double ans = (double)lcmn / (double)bunshi;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
class UnionFind:
	def __init__(self, size):
		self.data = [-1] * size

	def merge(self, x, y):
		x = self.root(x)
		y = self.root(y)
		if x == y: return False

		if self.data[x] < self.data[y]:
			x, y = y, x

		self.data[y] += self.data[x]
		self.data[x] = y
		return True

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

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

def main():
	N, M = map(int, input().split())
	uf = UnionFind(N)
	for i in range(M):
		x, y, z = map(int, input().split())
		uf.merge(x-1, y-1)

	cnt = 0
	for i in range(N):
		if uf.root(i) == i:
			cnt += 1

	print(cnt)

if __name__ == '__main__':
	main()

Measured memory_bytes: 12804
// https://atcoder.jp/contests/abc083/tasks/arc088_b
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)

int main(void) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    int len = s.length(), ans = len;
    FOR(i, 1, s.length()) {
        if (s[i] != s[i - 1]) {
            ans = min(ans, max(i, len - i));
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <set>
#include <sstream>
#include <bitset>
#include <stack>
#include <cstdlib>
#include <utility> //pair

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

typedef long long ll;

using namespace std;

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

    vector<int> a(n);
    FOR(i, 0, n){
        cin >> a[i];
    }

    
    
    int ans;
    if(n==k){
        ans = 1;
    }/*if(k==2){
        ans = (n-k-1)/(k-1) + 1;
    }*/else{
        ans = (n-k-1)/(k-1) + 2;
    }

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


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

int n,k;
ll a[200100],ans;

int main()
{
	scanf("%d%d",&n,&k);
	for (int i=1;i<=n;i++) a[i%k]++;
	ans=a[0]*a[0]*a[0];
	if (k%2==0) ans+=a[k/2]*a[k/2]*a[k/2];
	printf("%lld\n",ans);
	return 0;
}

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

#ifdef DEBUG
#define PRINT(x)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#x<<" = "<<(x)<<endl;
#define PRINTA(a,first,last)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#a<<"["<<(first)<<", "<<(last)<<")"<<endl;\
    for (int i=(first);i<(last);++i){cout<<#a<<"["<<i<<"] = "<<(a)[i]<<endl;}
#define PRINTP(p)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#p<<" = ("<<(p.first)<<", "<<(p.second)<<")"<<endl;
#define PRINTI(a,i)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#a<<"["<<#i<<"] = "<<#a<<"["<<(i)<<"] = "<<(a)[i]<<endl;
#else
#define PRINT(x)
#define PRINTA(a,first,last)
#define PRINTP(p)
#define PRINTI(a,i)
#endif

#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);--i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007

using namespace std;

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

template <class T, class U> void amax(T& x, U y) {if (x < y) x = y;}
template <class T, class U> void amin(T& x, U y) {if (x > y) x = y;}

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

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

    string S;
    cin >> S;
    int N = S.size();
    vector<vector<ll>> dp(N + 1, vector<ll>(13, 0));
    vector<int> r = {1, 10, 9, 12, 3, 4};
    dp[0][0] = 1;
    REP(i, N) {
        if (S[N - 1 - i] == '?') {
            REP(d, 10) {
                REP(j, 13) {
                    dp[i + 1][j] = (dp[i + 1][j] + dp[i][(1300 + j - d * r[i % r.size()]) % 13]) % MOD;
                }
            }
        } else {
            int d = S[N - 1 - i] - '0';
            REP(j, 13) {
                dp[i + 1][j] = dp[i][(1300 + j - d * r[i % r.size()]) % 13];
            }
        }
    }

    /*
    REP(i, N) REP(j, 13) {
        printf("dp[%d][%d] = %lld\n", i + 1, j, dp[i + 1][j]);
    }
    */

    cout << dp[N][5] << endl;
    return 0;
}


Measured memory_bytes: 13648
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(long long i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];cout<<endl;}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
#define yes cout<<"Yes\n"
#define no cout<<"No\n"

signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	map<int,int>ma;
	vi d(20);
	rep(i,3)rep(j,3){
		int a;cin>>a;
		ma[a]=i*3+j+1;
	}
	int n;cin>>n;
	while(n--){
		int a;cin>>a;
		if(ma[a])d[ma[a]-1]=1;
	}
	if(d[0]+d[1]+d[2]==3){yes;return 0;}
	if(d[3]+d[4]+d[5]==3){yes;return 0;}
	if(d[6]+d[7]+d[8]==3){yes;return 0;}
	if(d[0]+d[3]+d[6]==3){yes;return 0;}
	if(d[1]+d[4]+d[7]==3){yes;return 0;}
	if(d[2]+d[5]+d[8]==3){yes;return 0;}
	if(d[0]+d[4]+d[8]==3){yes;return 0;}
	if(d[2]+d[4]+d[6]==3){yes;return 0;}
	no;
}








Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main()
{
	int N;
  	cin >> N;
  	float ots = 0;
  	for (int i = 0; i < N; i++){
    	float x;
      	string u;
      	cin >> x >> u;
      	if (u == "BTC"){
        	ots += x * 380000;
        } else {
        	ots += x;
        }
    }
  	cout << ots << endl;
}

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

typedef int32_t i32;
typedef int64_t i64;

#define ALLOC(size,type) ((type*)calloc((size),sizeof(type)))

#define POS(i, j) (((i) & 1) * (m + 1) + (j))

void run (void) {
  i32 n, m;
  scanf ("%" SCNi32 "%" SCNi32, &n, &m);
  i32 *s = ALLOC (n + m, i32);
  i32 *t = s + n;
  for (i32 i = 0; i < n + m; ++i) {
    scanf ("%" SCNi32, s + i);
  }
  const i32 mod = 1000000007;
  i64 *dp = ALLOC (2 * (m + 1), i64);
  for (i32 i = 0; i <= m; ++i) {
    dp[POS(n, i)] = 1;
  }
  for (i32 i = n - 1; i >= 0; --i) {
    dp[POS(i, m)] = 1;
    for (i32 j = m - 1; j >= 0; --j) {
      dp[POS(i, j)] = (dp[POS(i + 1, j)] + dp[POS(i, j + 1)] + mod - dp[POS(i + 1, j + 1)]) % mod;
      if (s[i] == t[j]) {
        dp[POS(i, j)] += dp[POS(i + 1, j + 1)];
        dp[POS(i, j)] %= mod;
      }
    }
  }
  printf ("%" PRIi64 "\n", dp[POS(0, 0)]);
}

int main (void) {
  run();
  return 0;
}


Measured memory_bytes: 384
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while (true) {
			int x = sc.nextInt();
			int y = sc.nextInt();
			if (x == 0 && y==0) {
				break;
			}
			
			if(y<x) {
				int a=0;
				a=x;
				x=y;
				y=a;
			}
			
			System.out.println(x+" "+y);

		}

	}
}



Measured memory_bytes: 35936
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#define maxn 1005
#define _ 0
using namespace std;
struct nod
{
	int nex,id;
	nod(int a,int b)
	{
		nex=a;
		id=b;
	}
	nod(){}
};
int n,m,tim;
int vis[maxn];
int bel[maxn][maxn][2];
int u[maxn*maxn],v[maxn*maxn];
vector<nod> edge[maxn];
void dfs(int now,int fa,int b,int f)
{
//	cerr<<now<<" "<<fa<<" "<<b<<" "<<f<<endl;
	vis[now]=tim; bel[fa][now][f]=b;
	int len=edge[now].size();
	for(int i=0;i<len;i++)
		if(vis[edge[now][i].nex]!=tim)
			dfs(edge[now][i].nex,fa,b,f);
}
void solve(int now)
{
	tim++; vis[now]=tim;
	int len=edge[now].size();
	for(int i=0;i<len;i++)
		if(vis[edge[now][i].nex]!=tim)
			dfs(edge[now][i].nex,now,edge[now][i].id,0);
 
	reverse(edge[now].begin(),edge[now].end());
 
	tim++; vis[now]=tim;
	for(int i=0;i<len;i++)
		if(vis[edge[now][i].nex]!=tim)
			dfs(edge[now][i].nex,now,edge[now][i].id,1);
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)
	{
		scanf("%d%d",&u[i],&v[i]);
		edge[u[i]].push_back(nod(v[i],i));
	}
	for(int i=1;i<=n;i++)
		solve(i);
	for(int i=1;i<=m;i++)
	{
		if( (bel[v[i]][u[i]][0]!=0) ^ _ ^ (bel[u[i]][v[i]][0]!=i || bel[u[i]][v[i]][1]!=i) )
			printf("diff\n");
		else
			printf("same\n");
	}
}

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

int main(void){
    int n, h[110];
    cin >> n;
    for(int i=0;i<n;++i){
        cin >> h[i];
    }
    int cnt=0;
    while(true){
        int flg=1;
        for(int i=0;i<n;++i){
            if(h[i]!=0) flg=0;
        }
        if(flg) break;
        int max=0;
        for(int i=0;i<n;++i){
            if(h[i]>max){
                max = h[i];
            }
        }
        int prev=-2;
        for(int i=0;i<n;++i){
            if(h[i]==max){
                --h[i];
                if(i!=(prev+1)){
                    ++cnt;
                }
                prev = i;
            }
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define all(v) v.begin(),v.end()

using namespace std;
typedef long long ll;

int H,W;
vector<vector<char> > s;
vector<vector<int> > d;
vector<int> dx = {1, 0, -1, 0};
vector<int> dy = {0, 1, 0, -1};

int bfs(pair<int, int> p){
    
    queue<pair<int, int> > pp;
    pp.push(p);
    
    
    while (pp.size()) {
        int x = pp.front().first;
        int y = pp.front().second;
        if (x == H-1 && y == W-1) {
            break;
        }
        pp.pop();
        
        rep(i,4){
            int nx = x + dx[i];
            int ny = y + dy[i];
            
            if (0<=nx && nx<=H-1 && 0<=ny && ny<=W-1 && d[nx][ny]==-1 && s[nx][ny]=='.') {
                pp.push(pair<int,int>(nx,ny));
                d[nx][ny] = d[x][y]+1;
               
                
            }
            
            
            
        }
        
    }
    
    return d[H-1][W-1];
    
    
}


int main(){
    
    cin >> H >> W;
    s.assign(H, vector<char>(W, '.'));
    d.assign(H, vector<int>(W, -1));
    d[0][0] = 0;
    int white = 0;
    rep(i, H){
        rep(j,W){
            cin >> s[i][j];
            if (s[i][j] == '.') {
                white++;
            }
        }
    }

    int ans = bfs(pair<int, int>(0, 0));
    
    if (ans == -1) {
        cout << -1 << endl;
    }else{
        cout << white-ans-1 << endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <tuple>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

int n;
int a[100100];

bool solve() {
    int two = 0, four = 0, odd = 0;
    for (int i = 0; i < n; i++) {
        if (a[i] % 4 == 0) four++;
        else if (a[i] % 2 == 0) two++;
        else odd++;
    }
    return four >= odd || (odd - four == 1 && two == 0);
}

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

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

    input();
    cout << (solve()?"Yes":"No") << endl;
}


Measured memory_bytes: 640
class MyProcess
  attr_reader :name
  def initialize(name, time)
    @name = name
    @time = time.to_i
  end

  def execute(time)
    @time -= time
    return time if @time >= 0

    @time + time
  end

  def finished?
    @time <= 0
  end
end

n, q = gets.split.map(&:to_i)
queue = n.times.map{ MyProcess.new(*gets.split) }

elapsed = 0
until queue.empty?
  process = queue.shift
  elapsed += process.execute(q)

  if process.finished?
    puts "#{process.name} #{elapsed}"
  else
    queue.push(process)
  end
end

Measured memory_bytes: 14692
#include <stdio.h>

int main(int argc, char *argv[])
{
    int a = 0, b = 0, c = 0;
    int ans = 0;
    fscanf(stdin,"%d %d %d", &a, &b, &c);

    int i = 0;
    for(i=a; i<=b && i<=c; i++) {
        if(c%i==0) {
            ans++;
        }
    }
    printf("%d\n", ans);

    return 0;
}

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

int main() {
    string S;cin>>S;
    int g = 0, p = 0, ans = 0;
    for(int i=0;i<S.size();++i){
        if(S[i]=='g') {
            if(p+1 <= g){
                ++ans;
                ++p;
            } else {
                ++g;
            }
        } else {
            if(p+1 <= g){
                ++p;
            } else {
                --ans;
                ++g;
            }
        }
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
#include <cstdlib> 
#include <math.h>
#include<cstdio>
#include<cstring>
#define FOR(I, A, B) for (ll I = (A); I <= (B); I++)
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fo(i,n) for(ll i=0;i<n;i++)
#define sz(a) ll((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(auto i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define dbg(x) cout << #x << " = " << x << endl
#define dbg2(x,y) cout << #x << " = " << x << ", " << #y << " = " << y << endl
#define dbg3(x,y,z) cout << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << endl
#define dbg4(x,y,z,q) cout << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << ", " << #q << " = " << q << endl
#define scan(char_array) scanf("%[^\n]s",&char_array);

int main(){

	ll n,m;
	cin>>n>>m;
	ll left=1;
	ll right=n-1;
	ll cnt=0;
	if(n%2==1){
	fo(i,m){
		cout<<left<<" "<< right <<endl;
		left++;
		right--;
	}
}
else{
	ll init;
	if((n/2)%2==0) init=n/2-1;
	else init=n/2;
	ll first=1;
	ll total=(init- first)/2;
	ll l,r;
	l=1;
	r=init;
	total=min(total,m);

	fo(i,total){
		cout<<l<<" "<<r<<endl;
		l++;
		r--;

	}
	total=m-total;

	l=init+1;
	r=n-1;
	fo(i,total){
		cout<<l<<" "<<r<<endl;
		l++;
		r--;
	}





}





}


Measured memory_bytes: 3648