akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

#define DUMP(x) std::cout << (#x) << " = " << (x) << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define ALL(r) r.begin(), r.end()

using ll = std::int64_t;
using vint = std::vector<int>;
using pint = std::pair<int, int>;

constexpr std::int32_t INF = 1001001001;

constexpr int mod = 1000000007;
class mint {
private:
    std::int64_t m_x;
public:
    mint(std::int64_t m_x = 0) : m_x(m_x% mod) {}
    std::int64_t get() { return m_x; }
    mint& operator+=(const mint a) {
        if ((m_x += a.m_x) >= mod) m_x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((m_x += mod - a.m_x) >= mod) m_x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (m_x *= a.m_x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }

    mint pow(const std::int64_t t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }
    // for prime mod
    mint inv() const {
        return pow(mod - 2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res /= a;
    }
};

mint dp[105][6][6][6];

constexpr int A = 0;
constexpr int C = 1;
constexpr int G = 2;
constexpr int T = 3;

void Main() {
    int n;
    cin >> n;

    dp[0][T][T][T] = 1;
    rep(i, n) {
        rep(j, 4) {
            rep(k, 4) {
                rep(l, 4) {
                    rep(m, 4) {
                        if (          k == A && l == G && m == C)continue;
                        if (j == A &&           l == G && m == C)continue;
                        if (          k == G && l == A && m == C)continue;
                        if (          k == A && l == C && m == G)continue;
                        if (j == A && k == G &&           m == C)continue;

                        dp[i + 1][k][l][m] += dp[i][j][k][l];
                    }
                }
            }

        }
    }

    mint ans = 0;
    rep(x, 4) {
        rep(y, 4) {
            rep(z, 4) {
                ans += dp[n][x][y][z];
            }
        }
    }
    cout << ans.get() << endl;
}

int main() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


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

using namespace std;

typedef vector<int> int_vec;

int main()
{
    int n;
    cin >> n;
    int_vec S;
    for (int i = 0; i < n; ++i) {
        int x;
        cin >> x;
        S.push_back(x);
    }

    int q;
    cin >> q;
    int_vec T;
    for (int j = 0; j < q; ++j) {
        int x;
        cin >> x;
        T.push_back(x);
    }

    int c = 0;
    for (int_vec::iterator y = T.begin(); y != T.end(); ++y) {
        for (int_vec::iterator x = S.begin(); x != S.end(); ++x) {
            if (*x == *y) {
                c++;
                break;
            }
        }
    }
    cout << c << endl;
}

Measured memory_bytes: 3216
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<time.h>
#include<set>
#include<map>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i>b;i--)
#define vint vector<int> 
#define vvint vector<vint>
#define ct(a) cout<<a<<endl
#define tget(a,b) get<a>(b)
using namespace std;
typedef long long ll;
const ll INF = 1e17;
const int MOD = 1e9 + 7;
ll lim;
ll N, W[100], V[100];
ll dp[101][100001];
int main(void) {
	cin >> N>>lim;
	FOR(i, 0, N)cin >> W[i] >> V[i];
	
	FOR(i, 0, N) {
		for (ll k = 0; k <=lim; k++) {
			if (k < W[i]) {
				dp[i + 1][k] = dp[i][k];
			}
			else {
				dp[i + 1][k] = max(dp[i][k], dp[i][k - W[i]] + V[i]);
			}
		}
	}
	ll ans = 0;
	FOR(i, 0, lim+1)if (dp[N][i] > ans&&dp[N][i]!=INF)ans = dp[N][i];
	ct(ans);
	return 0;
}

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

using namespace std;
long long int n,k=0,a[500000];
int main()
{
        cin >> n;
        for (int i=1; i<=n; i++)
        {
                cin >> a[i];
        }
        for (int i=1; i<n; i++)
        {
                if(a[i]==i)
                {
                        swap(a[i],a[i+1]);
                        k++;
                }
        }
        if(a[n]==n)
                k++;
        cout << k;
        return 0;
}


Measured memory_bytes: 1024
#include <algorithm>
#include <cmath>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define loop(i, x, n) for (int i = (x); i < (n); i++)
#define all(v) (v).begin(), (v).end()
#define int long long
using namespace std;
const int MOD = 1e9 + 7;
const int INF = 1e9;
template<typename T> void cmax(T &a, T b) { a = max(a, b); }
template<typename T> void cmin(T &a, T b) { a = min(a, b); }

signed main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  sort(all(a));
  deque<int> b;
  b.push_back(a.back());
  b.push_front(a[0]);

  int turn = 0;
  int high = n - 2;
  int low = 1;
  int num = 2;

  while (num < n - 1) {
    int f = turn % 4;
    if (f == 0) {
      b.push_back(a[low]);
      low++;
    } else if (f == 1) {
      b.push_front(a[high]);
      high--;
    } else if (f == 2) {
      b.push_back(a[high]);
      high--;
    } else {
      b.push_front(a[low]);
      low++;
    }
    turn++;
    num++;
  }

  int ans = 0;
  for (auto itr = b.begin(); itr < b.end() - 1; itr++) {
    // cout << *itr << ' ' << *(itr + 1) << endl;
    ans += abs(*itr - *(itr + 1));
  }
  if (3 <= n) {
    int left = abs(b.front() - a[low]);
    int right = abs(b.back() - a[low]);
    ans += max(left, right);
  }

  turn = 0;
  high = n - 2;
  low = 1;
  num = 2;

  deque<int> c;
  c.push_back(a[0]);
  c.push_front(a.back());

  while (num < n - 1) {
    int f = turn % 4;
    if (f == 0) {
      b.push_back(a[high]);
      high--;
    } else if (f == 1) {
      b.push_front(a[low]);
      low++;
    } else if (f == 2) {
      b.push_back(a[low]);
      low++;
    } else {
      b.push_front(a[high]);
      high--;
    }
    turn++;
    num++;
  }
  int sum = 0;
  for (auto itr = c.begin(); itr < c.end() - 1; itr++) {
    // cout << *itr << ' ' << *(itr + 1) << endl;
    sum += abs(*itr - *(itr + 1));
  }
  if (3 <= n) {
    int left = abs(c.front() - a[low]);
    int right = abs(c.back() - a[low]);
    sum += max(left, right);
  }

  cout << max(ans, sum) << endl;
  return 0;
}


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,M;
vector<pair<int,int>> EE[1010101];
vector<int> G[2020202];
vector<int> GI[2020202];
int did[101010];
vector<int> E[1010101];
int id;
int dist[1010101];
int distg[1010101];

void dfs(int cur,int x) {
	if(did[cur]==x) return;
	did[cur]=x;
	G[id].push_back(cur);
	GI[cur].push_back(id);
	FORR(r,E[cur]) dfs(r,x);
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>M;
	FOR(i,M) {
		cin>>x>>y>>r;
		EE[r].push_back({x-1,y-1});
	}
	MINUS(did);
	FOR(i,1010100) if(EE[i].size()) {
		vector<int> V;
		FORR(e,EE[i]) {
			E[e.first].push_back(e.second);
			E[e.second].push_back(e.first);
			V.push_back(e.first);
			V.push_back(e.second);
		}
		
		FORR(r,V) if(did[r]!=i) {
			dfs(r,i);
			id++;
		}
		FORR(e,EE[i]) {
			E[e.first].clear();
			E[e.second].clear();
		}
	}
	
	memset(dist,0x3f,sizeof(dist));
	memset(distg,0x3f,sizeof(dist));
	dist[0]=0;
	vector<int> V;
	V.push_back(0);
	
	FOR(i,1010101) {
		if(V.empty()) break;
		vector<int> V2;
		FORR(r,V) {
			FORR(gi,GI[r]){
				if(distg[gi]>i) {
					distg[gi]=i;
					FORR(g,G[gi]) V2.push_back(g);
				}
			}
		}
		sort(ALL(V2));
		V2.erase(unique(ALL(V2)),V2.end());
		V.clear();
		FORR(r,V2) if(dist[r]>i+1) {
			dist[r]=i+1;
			V.push_back(r);
		}
	}
	
	if(dist[N-1]>0x3f0000) dist[N-1]=-1;
	cout<<dist[N-1]<<endl;
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}


Measured memory_bytes: 171256
#include <iostream>
#include <vector>
#include <cstring>

using namespace std;

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

int board[7][7][7], cnt[7][7];

int main() {
	int n, m, p;
	while (cin >> n >> m >> p, n) {
		vector<int> ix(p + 1), iy(p + 1);
		for (int i = 1; i <= p; ++i) cin >> ix[i] >> iy[i];
		memset(board, -1, sizeof(board));
		memset(cnt, 0, sizeof(cnt));
		int flag = -1;
		int i;
		for (i = 1; i <= p; ++i) {
			int color = i & 1;
			int x = ix[i], y = iy[i];
			--x, --y;
			int z = cnt[x][y]++;
			board[x][y][z] = color;
			for (int j = 0; j < 13; ++j) {
				int tmp = 1;
				int nx = x + dx[j], ny = y + dy[j], nz = z + dz[j];
				while (0 <= nx && nx < n && 0 <= ny && ny < n && 0 <= nz && nz < n) {
					if (board[nx][ny][nz] == color) tmp++;
					else break;
					nx += dx[j], ny += dy[j], nz += dz[j];
				}
				nx = x - dx[j], ny = y - dy[j], nz = z - dz[j];
				while (0 <= nx && nx < n && 0 <= ny && ny < n && 0 <= nz && nz < n) {
					if (board[nx][ny][nz] == color) tmp++;
					else break;
					nx -= dx[j], ny -= dy[j], nz -= dz[j];
				}
				if (tmp >= m) {
					flag = color;
					goto output;
				}
			}
		}
	output:
		if (flag == 1) cout << "Black " << i;
		else if (flag == 0) cout << "White " << i;
		else cout << "Draw";
		cout << endl;
	}

	return 0;
}


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

int main(){
    ios_base::sync_with_stdio(false);
    float x, y; cin >> x >> y;
    float a = y / 2 - x;
    float b = x - a;
    if ((b == 0 && a == 0 )|| b < 0 || a < 0) cout << "No" << "\n";
    else if (b == floor(b) && a == floor(a)) cout << "Yes" << "\n";
    else cout << "No" << "\n";
}

Measured memory_bytes: 3780
import re
import sys
from itertools import product

import numpy as np

sys.setrecursionlimit(200000)


def input():
    return sys.stdin.readline()[:-1]


def ii(t: type = int):
    return t(input())


def il(t: type = int):
    return list(map(t, input().split()))


def imi(N: int, t: type = int):
    return [ii(t) for _ in range(N)]


def iml(N: int, t: type = int):
    return [il(t) for _ in range(N)]


def solve():
    S = ii(str)
    a = 0
    b = 0
    for i, s in enumerate(S):
        if i % 2 == 0:
            if s == "0":
                a += 1
            else:
                b += 1
        else:
            if s == "0":
                b += 1
            else:
                a += 1
    return min(a, b)


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

Measured memory_bytes: 12636
#include<bits/stdc++.h>
using namespace std;
const int N=200005;
char s[N];
int main(){
	scanf("%s",s+1);
	int ans=0,n=strlen(s+1);
	for (int i=1;i<=n;){
		if (s[i]!=s[i+1])i++,ans++;
		else if (!s[i+2])ans++,i+=3;
		else i+=3,ans+=2;
	}
	printf("%d\n",ans);	
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
const LL mod=998244353;
const LL LINF=1LL<<62;
const int INF=1<<30;
int dx[]={1,0,-1,0,1,-1,1,-1};
int dy[]={0,1,0,-1,1,-1,-1,1};

int main(){
    int n,k,c;cin >> n >> k >> c;
    string s;cin >> s;
    vector<int> L(n+1,0), R(n+1,0);
    int l = -INF;
    for (int i = 0; i < n; i++) {
        int t = L[i];
        L[i+1] = t;
        if(s[i] == 'o'){
            if(l + c < i){
                chmax(L[i+1], t + 1);
                l = i;
            }
        }
    }
    int r = INF;
    for (int i = n-1; i >= 0; i--) {
        int t = R[i+1];
        R[i] = t;
        if(s[i] == 'o'){
            if(r - c > i){
                chmax(R[i], t + 1);
                r = i;
            }
        }
    }
    vector<int> ans;
    for (int i = 0; i < n; i++) {
        if(L[i] + R[i + 1] < k){
            ans.pb(i + 1);
        }
    }
    for (int i = 0; i < ans.size(); i++) {
        cout<< ans[i] << endl;
    }
    return 0;
}



Measured memory_bytes: 4216
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define INF 1000000007
#define MAX 11
typedef pair<int,int> int_pair;

int main(void){
    string a;
    int s[MAX];
    cin >> a;
    ll ans = 0;
    int n = a.size();
    for(int i=0;i<n;i++) s[i] = a[i]-'0';
    for(int bit=0;bit<(1<<(n-1));bit++){
        int cnt = 0;
        ans += s[n-1];
        for(int i=n-2;i>=0;i--){
            if(bit & (1<<i))
                cnt ++;
            else
                cnt = 0;
            ans += s[i]*pow(10,cnt);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-


def main():
    n, m, q = map(int, input().split())
    summed = [[0 for _ in range(n + 1)] for _ in range(n + 1)]

    for _ in range(m):
        li, ri = map(int, input().split())
        summed[li][ri] += 1

    for i in range(1, n + 1):
        for j in range(1, n + 1):
            summed[i][j] += summed[i - 1][j]
            summed[i][j] += summed[i][j - 1]
            summed[i][j] -= summed[i - 1][j - 1]

    ans = list()

    for _ in range(q):
        pi, qi = map(int, input().split())
        count = summed[qi][qi] - summed[pi - 1][qi] - summed[qi][pi - 1] + summed[pi - 1][pi - 1]
        ans.append(count)

    print('\n'.join(map(str, ans)))


if __name__ == '__main__':
    main()


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

using namespace std;

#define pb push_back
#define sz(a) ((int)a.size())
#define mp make_pair
#define fi first
#define se second

const int maxn = 1e5 + 5;

const int maxv = 1e9;

int T, tc;
int n;
long long a[maxn];

int main() {
//	freopen("inp.txt", "r", stdin);
    
   	cin >> n;
   	long long ans = 0;
   	for (int i = 0; i < n; i++) {
   		int x;
		cin >> x;
		a[x]++;   	
		ans += x;
	}
	
	int q;
	cin >> q;
	for (int i = 0; i < q; i++) {
		int x, y;
		cin >> x >> y;
		a[y] += a[x];
		ans -= a[x] * x;
		ans += a[x] * y;
		a[x] = 0;
		printf("%lld\n", ans);
	}
    
    return 0;
}

Measured memory_bytes: 4480
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;

int main()
{
    int N; LLONG W;
    cin >> N >> W;
    vector<LLONG> ws(N), vs(N);
    for (int i = 0; i < N; ++i)
    {
        cin >> ws[i] >> vs[i];
    }
    map<int, multiset<LLONG>> plusWeight2ValuesMap;
    for (int i = 0; i < N; ++i)
    {
        plusWeight2ValuesMap[ws[i] - ws.front()].insert(vs[i]);
    }
    vector<LLONG> nums(4);
    for (int i = 0; i < 4; ++i)
    {
        nums[i] = plusWeight2ValuesMap[i].size();
    }
    map<int, vector<LLONG>> plusWeight2SumsMap;
    for (int i = 0; i < 4; ++i)
    {
        plusWeight2SumsMap[i].push_back(0);
        LLONG sum = 0;
        auto itr = plusWeight2ValuesMap[i].rbegin();
        for (auto itr = plusWeight2ValuesMap[i].rbegin();
            itr != plusWeight2ValuesMap[i].rend(); ++itr)
        {
            sum += *itr;
            plusWeight2SumsMap[i].push_back(sum);
        }
    }
    LLONG w1 = ws.front();
    LLONG maxValue = 0;
    for (LLONG n0 = 0; n0 <= nums[0]; ++n0)
        for (LLONG n1 = 0; n1 <= nums[1]; ++n1)
            for (LLONG n2 = 0; n2 <= nums[2]; ++n2)
                for (LLONG n3 = 0; n3 <= nums[3]; ++n3)
                {
                    LLONG w = w1 * (n0 + n1 + n2 + n3)
                        + n1 + n2 * 2 + n3 * 3;
                    if (w <= W)
                    {
                        maxValue = max(maxValue,
                            plusWeight2SumsMap[0][n0]
                            + plusWeight2SumsMap[1][n1]
                            + plusWeight2SumsMap[2][n2]
                            + plusWeight2SumsMap[3][n3]);
                    }
                }
    cout << maxValue << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
#include<complex>
#include<random>
#include<ctime>
#include<set>
using namespace std;
#define SAY_YES cout<<"YES"<<endl;
#define SAY_Yes cout<<"Yes"<<endl;
#define SAY_NO cout<<"NO"<<endl;
#define SAY_No cout<<"No"<<endl;
#define IFYES(TRUE_OR_FALSE) if(TRUE_OR_FALSE){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;} 
#define IFYes(TRUE_OR_FALSE) if(TRUE_OR_FALSE){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;} 
#define IFyes(TRUE_OR_FALSE) if(TRUE_OR_FALSE){cout<<"yes"<<endl;}else{cout<<"no"<<endl;} 

const long long int mod=1000000007;
const long long int INF=99999999999999999;



long long int N,M,K,A[1100050]={},pl=0,zero=0,mi=0,tmp=0,res=0;
long long int dp[1000020]={},dp2[1000020]={};
vector<long long int> minus_num,plus_num;
string str;
map<string,long long int>mp;
int main() {
	cout << fixed << setprecision(18);
    cin>>str;
    for(int i=0;i<str.length();i++){
        A[str.length()-i-1]=str[i]-'0';
		dp[i]=INF;
		dp2[i]=INF;
    }
	//dpはより大きなお金を払う状態
	dp[0]=10-A[0];
	dp2[0]=A[0];

	for(int i=1;i<str.length();i++){
		
		dp[i]=min(dp[i-1]+9-A[i],dp2[i-1]+10-A[i]);
		if(A[i]!=9){dp2[i]=min(dp[i-1]+A[i]+1,dp2[i-1]+A[i]);}
		else{dp2[i]=dp2[i-1]+A[i];}
		tmp=i;
		
    	//cout<<dp[i]<<" "<<dp2[i]<<endl;
    }
	
    cout<<min(dp[str.length()-1]+1,dp2[str.length()-1])<<endl;
} 


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

bool agreed(vector<int> &sums,int x){
	bool p = true;
	for(int i =1;i<sums.size();i++){
		if(sums[i] < x){
			p = false;
			break;
		}
	}
	return p;
}

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

	int n,m,x; cin >> n >> m >> x;
	vector<vector<int>> books(n);
	//books[i][0] gives price and remaining grip of algo
	for(int i =0;i<n;i++){
		books[i].resize(m+1);
		for(int j =0;j<m+1;j++){
			cin >> books[i][j];
		}
	}
	int cost=13e5;
	for(int k = 0;k<pow(2,n);k++){
		
		vector<int>sums;sums.assign(m+1,0);
		int amount =0;
		for(int j =0;j<n;j++){
			if(k & 1<<j){
				amount += books[j][0];
				for(int i =1;i<=m;i++){
					sums[i]+=books[j][i];
				}

			}
		}
		if(agreed(sums,x)){
			cost = min(cost,amount);
		}
	}

	if(cost==13e5){
		cout << -1;
	}
	else{
		cout << cost;
	}
	
}


Measured memory_bytes: 4092
import sys
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

N = int(input())
uvw = [ tuple(map(int,input().split())) for i in range(N-1) ]

dic = {}
color = [0]*N
dist = {}
root = [0]*N

for i in range(N):
    dic[i+1] = []
for n in range(N-1):
    i = uvw[n][0]
    j = uvw[n][1]
    dic[i].append(j)
    dic[j].append(i)
    root[i-1] += 1
    root[j-1] += 1
    #color[(i,j)] = 0
    dist[(i,j)] = uvw[n][2]
    dist[(j,i)] = uvw[n][2]
root_node = root.index(1)+1
#ma = max(root)
def rec(now_node, now_dist):
    if now_dist%2==1:
        color[now_node-1] = 1
    tg_list = dic[now_node][:]
    for elem in tg_list:
        dic[elem].remove(now_node)
        rec(elem, now_dist + dist[(elem,now_node)])
rec(root_node,0)
#print(ma)
for n in range(N):
    #i = ab[n][0]
    #j = ab[n][1]
    print(color[n])


Measured memory_bytes: 158412
#![allow(unused, non_snake_case, dead_code, non_upper_case_globals)]
use {
    proconio::{marker::*, *},
    std::{cmp::*, collections::*, mem::*},
};

#[fastout]
fn main() {
    input! {//
        n:usize,
      mut  c:Chars,
    }

    // rw をなくす
    let mut lr = 0;
    let mut lw = 0;
    let mut rw = 0;
    let mut rr = 0;
    for &x in c.iter() {
        if x == 'W' {
            rw += 1;
        } else {
            rr += 1;
        }
    }

    let mut ans = min(rw, rr);
    for i in 0..n {
        if c[i] == 'W' {
            lw += 1;
            rw -= 1;
        } else {
            lr += 1;
            rr -= 1;
        }
        ans = min(ans, max(lw, rr));
    }
    println!("{}", ans);
}
const INF: i64 = 1 << 60;


Measured memory_bytes: 3100
#include <bits/stdc++.h>
 
typedef long long ll;

using namespace std;
using Graph = vector<vector<int>>;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define COUT(a) cout << (a) << endl;
#define ENDL(a) cout << endl;

const unsigned int BIT_FLAG_0 = (1 << 0); // 0000 0000 0000 0001
const unsigned int BIT_FLAG_1 = (1 << 1); // 0000 0000 0000 0010
const unsigned int BIT_FLAG_2 = (1 << 2); // 0000 0000 0000 0100
const unsigned int BIT_FLAG_3 = (1 << 3); // 0000 0000 0000 1000
const unsigned int BIT_FLAG_4 = (1 << 4); // 0000 0000 0001 0000
const unsigned int BIT_FLAG_5 = (1 << 5); // 0000 0000 0010 0000
const unsigned int BIT_FLAG_6 = (1 << 6); // 0000 0000 0100 0000
const unsigned int BIT_FLAG_7 = (1 << 7); // 0000 0000 1000 0000
const unsigned int BIT_FLAG_8 = (1 << 8); // 0000 0001 0000 0000
const unsigned int BIT_FLAG_9 = (1 << 9); // 0000 0010 0000 0000
const unsigned int BIT_FLAG_10 = (1 << 10); // 0000 0100 0000 0000
const unsigned int BIT_FLAG_11 = (1 << 11); // 0000 1000 0000 0000

const double PI=3.14159265358979323846; // or M_PI


void Main() {
    ll n;
    string in_s;
    vector<string> s;

    cin >> n;
    REP(i, n) {
        cin >> in_s;
        s.push_back(in_s);
    }

    set<string> s2(s.begin(), s.end());
    COUT(s2.size());
}

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

/*
4 3
1 2 3 4
1 3
2 3
2 4
*/

Measured memory_bytes: 24980
#include "bits/stdc++.h"
using namespace std;

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

const int INF = 1000000007;

int main(void){
	int x1,y1,x2,y2;
	cin>>x1>>y1>>x2>>y2;

	int A,B;
	int x3,y3,x4,y4;
	A = x2 - x1;
	B = y2 - y1;
	x3 = x2 - B; y3 = y2 + A;
	x4 = x1 - B; y4 = y1 + A;

	printf("%d %d %d %d\n", x3, y3, x4, y4);
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>    
//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//using namespace __gnu_pbds; 
#define fastio() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pb  push_back
#define show(x) cout<<(#x)<<" : "<<x<<endl;
#define ll  long long
#define ld  long double
#define fill(a,val) memset(a,val,sizeof(a))
#define mp  make_pair
#define ff  first
#define ss  second
#define pii pair<ll,ll>
#define sq(x) ((x)*(x))
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define endl "\n"
#define int long long
#define rep(a,b) for(ll a=0;a<b;a++)
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
const ll MOD     = 1000*1000*1000+7;
const ll INF     = 1ll*1000*1000*1000*1000*1000*1000 + 7;
const ll MOD2    = 998244353;
const ll N       = 1000 * 100 + 10;
const ll N2      = 70;
const ld PI  = 3.141592653589793;
//template<class T>using onset=tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);} 
ll power(ll x,ll y,ll p = LLONG_MAX ){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
ll lcm(ll a , ll b){return (a*b)/gcd(a,b);}
void solve(){
  #ifndef ONLINE_JUDGE    
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
  #endif
}
signed main()
{
    fastio();
    //cout<<fixed<<setprecision(20);
    //CHECK for LONG LONG and LONG DOUBLE
    //*comment for all except cc/cf
    ll h,w,k;
    cin>>h>>w>>k; 
    char c[h][w];
    ll s=0;
    rep(i,h){
     rep(j,w){
       cin>>c[i][j];
       if(c[i][j]=='#'){
         s++;
       }
     }
    }
    ll n=h+w,res=0;
    for(ll i=0;i<(1<<n);i++){
     ll cnt=0;
     rep(j,h){
       if(i&(1<<j)){
        rep(o,w){
          if(c[j][o]=='#'){
            cnt++;
          }
        }
       }
     }
     rep(j,w){
      if(i&(1<<(j+h))){
        rep(u,h){
          if(!(i&(1<<u))){
            if(c[u][j]=='#'){
              cnt++;
            }
          }
        }
      }
     }
     if((s-cnt)==k){
       res++; 
     }
    }
    cout<<res<<endl; 
    
    //printclock;
    return 0;
}
    

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

int main(){
    int n;
    float tmp, ans;
    string k;
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> tmp;
        cin >> k;

        if(k == "JPY"){
            ans += tmp;
        }
        else{
            tmp *= 380000;
            ans += tmp;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES 
#include<iomanip> 
#include<cmath>  
#include<iostream>
#include<fstream>
#include<vector>
#include<algorithm>
#include<numeric>
#include<bitset>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<queue>
#include<deque>
#include<stack>
using namespace std;
typedef long long ll;
#define repi(i,a,b) for(ll i = (ll)(a) ; i < (ll)(b) ; i++)
#define repd(i,a,b) for(ll i = (ll)(a) ; i > (ll)(b) ; i--)
#define rd(x) cin >> x
#define wr(x)  cout << x
#define wrln(x) cout << x << endl

const ll mod = 1000000000 + 7;
ll N;
vector<ll> bits;
ll dp[100][3];

int main() {
	dp[0][0] = dp[0][1] = 1;
	dp[0][2] = 0;
	rd(N);

	if (N == 1) {
		wrln(2);
		return 0;
	}

	while (N) {
		bits.push_back(N & 1);
		N >>= 1;
	}

	repi(i, 1, bits.size()) {
		if (bits[bits.size() - 1 - i]) {
			dp[i][0] = dp[i - 1][0];
			dp[i][1] = dp[i - 1][0] + dp[i - 1][1];
			dp[i][2] = dp[i - 1][1] * 2 + dp[i - 1][2] * 3;
		}
		else {
			dp[i][0] = dp[i - 1][0] + dp[i - 1][1];
			dp[i][1] = dp[i - 1][1];
			dp[i][2] = dp[i - 1][1] + dp[i - 1][2] * 3;
		}
		repi(j, 0, 3) dp[i][j] %= mod;
	}

	wrln((dp[bits.size() - 1][0] + dp[bits.size() - 1][1] + dp[bits.size() - 1][2]) % mod);

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#pragma once
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef long double lb;
#define int long long
#define double long double
typedef pair<int,int> P;
const ll INF = 1e16;
const int MOD = 1000000007;
const double EPS = 1e-10;
const double PI = 3.141592653589793;
template<class T> inline bool chmin(T& a, T b){if(a>b){a = b;return 1;}return 0;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a = b;return 1;}return 0;}
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 


////////////////////////////////////////////////////////////////////
///////////////////////___modpow___////////////////////
ll modpow(ll a,  ll n, const ll &MOD = MOD){
  ll ret = n == 0 ? 1 : modpow(a, n/2, MOD);
  (ret *= ret) %= MOD;
  if(n%2)((ret *= a) %= MOD);
  return ret;
}


////////////////////////////////////////////////////////////////////

char c;
signed main(){
  cin>>c;
  cout << (char)(c+1) << endl;
}




Measured memory_bytes: 256
function main(arg) {
    var num1 = arg.split(/\s+/g)[0];
    var num2 = arg.split(/\s+/g)[1];
    var seki = num1*num2;
    if(num1<10&&num2<10&&num1>0&&num2>0){
    	console.log(seki);
    }else{
    	console.log(-1);
    }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 21064
#![allow(unused_imports)]
use proconio::{input, fastout};
use proconio::marker::*;

#[fastout]
fn main() {
    input! {
	a: usize,
    b: usize,
    }
  	let ans = match a + b {
      3 => 3,
      4 => 2,
      _ => 1
  };
  println!("{}", ans);
}


Measured memory_bytes: 2200
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextLong()
    val t = sc.nextLong()
    val tn = (0 until n).map { sc.next().toLong() }
    println(problem060c(n, t, tn))
}

fun problem060c(n: Long, t: Long, tn: List<Long>): Long {
    var sum = 0L
    var currentT = 0L
    for (i in tn.indices) {
        if (i >= tn.size - 1) {
            sum += t
            continue
        }
        val tiNext = tn[i + 1]
        if (currentT + t > tiNext) {
            sum += tiNext - currentT
            currentT = tiNext
        } else if(currentT + t <= tiNext) {
            sum += t
            currentT = tiNext
        }
    }
    return sum
}

Measured memory_bytes: 58232
N = int(input())
A = list(map(int, input().split()))

buka = {}
for a in A:
  if a in buka:
    buka[a] += 1
  else:
    buka[a] = 1

for i in range(N+1)[1:]:
  if i in buka:
    print(buka[i])
  else:
    print(0)

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

int main() {
  int n;cin>>n;
  
  map<string,int> mp;
  vector<long long > kai;
  long long ans=0;
  for (int i=0;i<n;i++) {
    string s;
    cin>>s;
    sort(s.begin(),s.end());
    mp[s]++;
  }
  
  for (auto& p : mp) {
    int q = p.second;
    ans += (long long)q*(q-1)/2;
  }
  
  cout<<ans<<endl;
    
}

Measured memory_bytes: 11136
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<memory>
#include<functional>
#include<set>
 
using namespace std;
 
#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define F(i,j,k) fill(i[0],i[0]+j*j,k)
#define P(p) cout<<(p)<<endl;
#define INF 1<<25
 
typedef long long ll;

int dy[8]={1,1,1,0,0,-1,-1,-1};
int dx[8]={-1,0,1,-1,1,-1,0,1};
struct S{
	int a,b,c;
};
bool asc(const S& left,const S& right){
	return left.c > right.c;
}

int W,N;
int v[1001],w[1001];
int dp[1001][1001];

int main(){
	int cnt=1;
	char tmp;
	while(cin>>W){
		if(W==0)break;
		cin>>N;
		rep(i,N)cin>>v[i]>>tmp>>w[i];
		REP(i,1,N+1){
			rep(j,W+1){
				if(w[i-1]<=j)
					dp[i][j]=max(dp[i-1][j],dp[i-1][j-w[i-1]]+v[i-1]);
				else 
					dp[i][j]=dp[i-1][j];
			}
		}
		int ans_v=0,ans_w=0;
		rep(i,W+1){
			if(dp[N][i]>ans_v){
				ans_v=dp[N][i];
				ans_w=i;
			}
		}
		cout<<"Case "<<cnt<<":"<<endl;
		cout<<ans_v<<endl;
		cout<<ans_w<<endl;
		cnt++;
	}
	return 0;
}

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

int n;
int a[100005];
int main()
{
    scanf("%d", &n);
    int k = 0;
    for(int i = 1; i <= n ; ++i)
        scanf("%d", &a[i]);
    for(int i = 1; i < n ; ++i){
        if(a[i] == i){
            ++k;
            int aux = a[i];
            a[i] = a[i + 1];
            a[i + 1] = aux;
        }
    }
    if(a[n] == n) ++k;
    printf("%d", k);
    return 0;
}


Measured memory_bytes: 640
#pragma warning(disable:4786)
#pragma warning(disable:4996)
#include<list>
#include<bitset>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<functional>
#include<string>
#include<cstring>
#include<cstdlib>
#include<queue>
#include<utility>
#include<fstream>
#include<sstream>
#include<cmath>
#include<stack>
#include<assert.h>
using namespace std;

#define MEM(a, b) memset(a, (b), sizeof(a))
#define CLR(a) memset(a, 0, sizeof(a))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define ABS(X) ( (X) > 0 ? (X) : ( -(X) ) )
#define S(X) ( (X) * (X) )
#define SZ(V) (int )V.size()
#define FORN(i, n) for(i = 0; i < n; i++)
#define FORAB(i, a, b) for(i = a; i <= b; i++)
#define ALL(V) V.begin(), V.end()
#define IN(A, B, C)  ((B) <= (A) && (A) <= (C))

typedef pair<int,int> PII;
typedef pair<double, double> PDD;
typedef vector<int> VI;
typedef vector<PII > VP;

#define AIN(A, B, C) assert(IN(A, B, C))

//typedef int LL;
typedef long long int LL;
//typedef __int64 LL;

int main()
{
	LL n, a, b, c, d;
	scanf("%lld %lld %lld %lld %lld ", &n, &a, &b, &c, &d);
	if (a > b) swap(a, b);


	LL D = b - a;
	for (int i = 0; i <= n - 1; i++) {
		int j = n - 1 - i;

		LL diff = i * c - j * c;
		LL high = i * (d - c);
		LL low = j * (d - c);

		if (diff - low <= D && D <= diff + high) {
			printf("YES\n");
			return 0;
		}
	}

	printf("NO\n");
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int N;
vector<long long> A;
vector<map<long long, long long>> memo;
long long f(int p, long long q) {
	if (p == N) return 0;
	if (memo[p].count(q)) return memo[p][q];
	auto x = A[p];
	long long r = 1LL<<61;
	if (q <= 0 && q+x > 0) r = min(r, f(p+1, q+x));
	if (q >= 0 && q+x < 0) r = min(r, f(p+1, q+x));
	if (q <= 0) r = min(r, f(p+1, 1) + abs(q+x - 1));
	if (q >= 0) r = min(r, f(p+1, -1) + abs(q+x + 1));
	return memo[p][q] = r;
}
int main() {
	cin >> N;
	A.resize(N);
	for (auto& x : A) cin >> x;
	memo.resize(N);
	cout << f(0, 0) << endl;
}


Measured memory_bytes: 36224
from collections import Counter
from functools import reduce
# import statistics
import bisect
import copy
import fractions
import math
import pprint
import random
import sys
import time
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def MI(): return map(int, sys.stdin.readline().split())
def II(): return int(sys.stdin.readline())
def IS(): return input()
def C(x): return Counter(x)
def GCD_LIST(numbers):
    return reduce(fractions.gcd, numbers)
def LCM_LIST(numbers):
    return reduce(LCM, numbers)
def LCM(m, n):
    return (m * n // fractions.gcd(m, n))
def unite(x, y):
    # それぞれのノードの根を求める
    x = root(x)
    y = root(y)
    if x == y:
        return
    # node[x]の根をyに変更する
    node[x] = y
def same(x,y): return bool(root(x) == root(y))
def root(x):
    if node[x] == x:  # xが根の場合
        return x
    else:
        node[x] = root(node[x])  # 経路圧縮
        return node[x]
def dfs(v):
    # ノードに訪れた
    visited[v] = True
    for v2 in range(n):
        if graph[v][v2] == False:  # そもそもvとv2が辺でつながっていない
            continue
        if visited[v2] == True:  # もう見た
            continue
        dfs(v2)

n = II()
t = [II() for _ in range(n)]
print(LCM_LIST(t))



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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    std::vector<int> v(n);
    for(int i = 0; i < n; i++)
        cin>>v[i];
    std::vector<int> dp(n);
    dp[n-1] = 0;
    dp[n-2] = abs(v[n-2] - v[n-1]);
    for(int i = n-3; i >= 0; i--){
        dp[i] = min(abs(v[i]-v[i+1]) + dp[i+1], abs(v[i]-v[i+2]) + dp[i+2]);
        //cout<<dp[i]<<"\n";
    }
    cout<<dp[0]<<"\n";
}

Measured memory_bytes: 1024
/*
* Author. Silviase(@silviasetitech)
* For AtCoder
*/

import java.util.*;
import java.lang.*;
import java.math.*;


public class Main {
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        
        int n = sc.nextInt();
        int variety = sc.nextInt();
        int[] k = new int[n];
        int[] preference = new int[variety];
        int ans = 0;
        for (int i = 0; i < n; i++) {
            k[i] = sc.nextInt();
            for (int j = 0; j < k[i]; j++) {
                int tmp = sc.nextInt();
                preference[tmp-1]++;
            }
        }
        for (int i = 0; i < variety; i++) {
            if (preference[i] == n) {
                ans++;
            } 
        }
        System.out.println(ans);
        sc.close();
    }
    private static int gcd(int m, int n) {
        if(m < n) {
            return gcd(n, m);
        }
        if(n == 0){
            return m;
        } 
        return gcd(n, m % n);
    }
}

Measured memory_bytes: 23892
#include <algorithm>
#include <iostream>
#include <set>
#include <vector>
#include <cmath>
#include <utility>
#include <numeric>
#include <string>

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;

#define all(a) (a).begin(), (a).end()
#define rep(i, n) for (int i=0;(i)<(n);(i)++)
#define repi(i, n) for (int i=0;(i)<=(n);(i)++)
#define repr(i, n) for (int i=n;(i)>=0;(i)--)
#define print(x) (cout<<x<<endl)
#define MOD 1000000007

int main() {
    int n; cin>>n;
    string upper; cin>>upper;
    string lower; cin>>lower;

    int p=0;
    ll ans=1;
    bool last_port=false;
    while (p<n) {
        bool port = (upper[p]==lower[p]);
        if (p==0) {
            ans *= (port ? 3 : 6);
        } else {
            if (last_port) ans=(ans*2)%MOD;
            else if (not port) ans=(ans*3)%MOD;
        }
        last_port = port;
        p += (last_port ? 1 : 2);
    }
    print(ans);
}

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

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<29;

int n;
int W, H;
int compress(int *x1, int *x2, int w) {
  vector<int> xs;
  REP(i, n) {
    for (int d=-1;d<=1;++d) {
      int xx1 = x1[i]+d, xx2 = x2[i] + d;
      if (0<=xx1&&xx1<w) xs.push_back(xx1);
      if (0<=xx2&&xx2<w) xs.push_back(xx2);
    }
  }
  sort(ALL(xs));
  xs.erase(unique(ALL(xs)), xs.end());
  REP(i, n) {
    x1[i] = find(ALL(xs), x1[i]) - xs.begin();
    x2[i] = find(ALL(xs), x2[i]) - xs.begin();
  }
  return xs.size();
}

int main() {
  while(cin >> W>>H,W||H) {
    cin >> n;
    int x1[n], y1[n], x2[n], y2[n];
    REP(i, n) {
      cin >> x1[i] >> y1[i]>>x2[i]>>y2[i];
      x2[i]--;y2[i]--;
    }
    W = compress(x1, x2, W);
    H = compress(y1,y2,H);
    bool ba[W][H];
    memset(ba,0,sizeof(ba));
    REP(i, n) {
      for(int x=x1[i]; x<=x2[i]; ++x)
        for(int y=y1[i]; y<=y2[i]; ++y)
          ba[x][y] = 1;
    }
    int ans = 0;
    typedef pair<int,int> pii;
    int dx[] = {0,1,0,-1};
    int dy[] = {1,0,-1,0};
    REP(y, H) {
      REP(x, W) {
        if (ba[x][y]) continue;
        ans++;

        queue<pii> Q;
        Q.push(pii(x,y));
        while(!Q.empty()) {
          int nx = Q.front().first;
          int ny = Q.front().second;
          Q.pop();
          REP(k,4) {
            int xx = nx + dx[k];
            int yy = ny + dy[k];
            if (xx<0||xx>=W||yy<0||yy>=H) continue;
            if (ba[xx][yy]) continue;
            ba[xx][yy] = 1;
            Q.push(pii(xx,yy));
          }
        }
      }
    }
    cout << ans << endl;;
  }
}

Measured memory_bytes: 2624
#include <cstdio>

int main() {
    long n, k;
    for (;;) {
        long a[100002] = {};
        scanf("%ld %ld", &n, &k);
        if (n == 0)
            return 0;
        for (long i = 0; i < n; i++) {
            scanf(" %ld", &a[i]);
        }
        long max = -2147483648;
        for (long i = 0; i < n - k; i++) {
            long result = 0;
            for (long l=i; l<i+k; l++)
                result += a[l];
            if (result > max)
                max = result;
        }
        printf("%ld\n", max);
    }
}

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

A = list(map(int,input().split()))

dic = {}
lis = []


for i in A:

    if i in dic:
        dic[i] += 1
    else:
        dic[i] = 1
        lis.append(i)

lis.sort()
lis.reverse()

L = 0
S = 0

for i in lis:

    if L != 0 and S != 0:
        break

    if dic[i] >= 4:

        L = max(L,i)
        S = max(S,i)

    elif dic[i] >= 2 and L == 0:

        L = i

    elif dic[i] >= 2 and S == 0:

        S = i

print (L*S)


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

int main() {
    int n;
    cin >> n;
    vector<pair<int,int>> a(n);
    for(int i = 0; i < n; i++) {
        int x,y;
        cin >> x >> y;
        a[i].first=y;
        a[i].second=x;
    }
    sort(a.begin(),a.end());
    ll sum=0;
    for(int i = 0; i < n; i++) {
        sum += a[i].second;
        if(sum>a[i].first){
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;

    return 0;
}

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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  while(1) {
    c -= b;
    if(c<=0) {
      cout << "Yes" <<endl;
      break;
    }
    a -= d;
    if(a<=0) {
      cout << "No" <<endl;
      break;
    }
  }

  return 0;
}

Measured memory_bytes: 3636
#include <stdio.h>

int main() {

	char c[5];

	scanf("%s",c);

	if (c[0] == 'a' || c[0] == 'i' || c[0] == 'u' || c[0] == 'e' || c[0] == 'o') { printf("vowel\n"); }
	else { printf("consonant\n"); }

	return 0;
}

Measured memory_bytes: 128
from collections import defaultdict

N=int(input())
S=input()
INF=int(1e9+7)
dict=defaultdict(int)
for i in S:
    dict[i]+=1
l=list(dict.values())
ans=1
for i in l:
    ans*=(i+1)
    ans%=INF
print(ans-1)


Measured memory_bytes: 40048
#include <bits/stdc++.h>
using namespace std;
 #define MAX 1000000000005
 #define ll long long int
 int main()
 {    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
   ll t;
        long long int m,sum=1,k=0,i,d=0,j,sum1=0,sum2=0,sum3=0,l,kk,sum4=0,sum5=0,sum6=0,c=0,x,y,q;
         ll n;
           cin>>n;
         string s;
           while(n)
           { n--;
             s.push_back('a'+(n%26));
              n/=26;
           }
            reverse(s.begin(),s.end());
              cout<<s<<endl;
    }


Measured memory_bytes: 3664
#include <cstdio>
#include <iostream>
#include <string>
#include <algorithm>
#include <cstring>
#include <utility>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <bitset>
#include <stack>
#include <deque>
using namespace std;
typedef pair<int, int> pii;
typedef pair<int, pii> pip;
typedef long long LL;
const int MAXN = 1234;
const LL MOD = (LL)1e9 + 7;
int r[MAXN * MAXN], c[MAXN * MAXN];
int mz[MAXN][MAXN];
bool used[MAXN * MAXN];
int cnt[MAXN * MAXN];

int main() {
    int N, M;
    scanf("%d %d", &N, &M);
    bool ans = true;
    for (int i = 0; i < N; i++) {
        int tmp;
        scanf("%d", &tmp);
        if (r[tmp]) ans = false;
        r[tmp] = 1;
        for (int j = 0; j < M; j++) mz[i][j] = tmp;
    }
    for (int i = 0; i < M; i++) {
        int tmp;
        scanf("%d", &tmp);
        if (c[tmp])
           ans = false;
        c[tmp] = 1;
        for (int j = 0; j < N; j++) {
            if (mz[j][i] == tmp) used[tmp] = 1;
            mz[j][i] = min(mz[j][i], tmp);
        }
    }
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < M; j++) {
            int cur = mz[i][j];
            cnt[cur]++;
        }
    }
    LL sum = 1, pool = 0;
    for (int i = 1; i <= N * M; i++) {
        //printf("i = %d cnt = %d\n", i, cnt[i]);
        if (!used[i]) {
           if (cnt[i]) sum *= cnt[i];
           else pool++;
           sum %= MOD;
        }
        cnt[i]--;
        if (pool < cnt[i]) ans = false;
        for (int j = 0; j < cnt[i]; j++) {
            sum *= pool;
            pool--;
            sum %= MOD;
        }
    }
    if (!ans) sum = 0;
    printf("%lld\n", sum);
    return 0;
}


Measured memory_bytes: 14592
#include<bits/stdc++.h>
using namespace std;
int a[100];
int main(){
	int N, ans = 0;
	scanf("%d", &N);
	for(int i = 0; i < N; i += 1) scanf("%d", a + i);
	for(int i = 1; i < N; i += 1)
		if(a[i] == a[i - 1])
			a[i] = 200, ans += 1;
	printf("%d\n", ans);
} 

Measured memory_bytes: 256
from collections import Counter
n = int(input())
nmax = 10**6+10
eratos = [0 for i in range(nmax+1)]
prime = []
cnt = 2
while True:
  while cnt <= nmax and eratos[cnt]:
    cnt += 1
  if cnt > nmax:
    break
  eratos[cnt] = 1
  prime.append(cnt)
  for i in range(cnt**2,nmax+1,cnt):
    eratos[i] = 1
pr = []
for i in prime:
  while n%i == 0:
    n //= i
    pr.append(i)
if n > 1:
  pr.append(n)
c = Counter(pr)
ans = 0
for i in c.values():
  for j in range(10):
    if i < j*(j+1)//2:
      ans += j-1
      break
print(ans)

Measured memory_bytes: 147772
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        Map<String, Integer> map = new HashMap<>();
        String[] s = new String[n];
        for (int i = 0; i < n; i++) {
            s[i] = sc.next();
        }

        long cnt = 0;
        for (int i = 0; i < n; i++) {
            char[] c = s[i].toCharArray();
            Arrays.sort(c);
            String str = new String(c);
            if (!map.containsKey(str)) {
                map.put(str, 1);
            } else {
                int cmb = map.get(str);
                cnt += cmb;
                map.put(str, cmb + 1);
            }
        }
        System.out.println(cnt);
    }

}


Measured memory_bytes: 52888
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
main()
{
    int n;
    cin>>n;
    vector<double> v(n);
    rep(i,n)cin>>v[i];
    sort(begin(v),end(v));
    rep(i,n-1)
    {
        double mid=(v[0]+v[1])/2;
        v[1]=mid;
        v.erase(begin(v));
    }
    printf( "%lf\n",v[0]);
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#define MAXN 100000
using namespace std;
typedef long long LL;
vector<int> G[MAXN+5];
int N,d[MAXN+5];
LL a[MAXN+5],maxval[MAXN+5];
bool DFS(int u,int fa)
{
	LL sum=0;
	bool Enter=false;
	for(int i=0;i<(int)G[u].size();i++)
	{
		int v=G[u][i];
		if(v==fa)
			continue;
		Enter=true;
		if(DFS(v,u)==false)
			return false;
		sum+=a[v];
		maxval[u]=max(maxval[u],a[v]);
	}
	if(Enter==false)
	{
		maxval[u]=a[u];
		return true;
	}
	if(2LL*a[u]<sum||a[u]>sum||a[u]<maxval[u])
		return false;
	a[u]=2*a[u]-sum;
	return true;
}
int main()
{
//	freopen("tree.in","r",stdin);
//	freopen("tree.out","w",stdout);
	scanf("%d",&N);
	for(int i=1;i<=N;i++)
		scanf("%lld",&a[i]);
	int u,v;
	for(int i=1;i<N;i++)
	{
		scanf("%d %d",&u,&v);
		G[u].push_back(v);
		G[v].push_back(u);
		d[u]++,d[v]++;
	}
	if(N==2)
	{
		if(a[1]!=a[2])
			printf("NO\n");
		else
			printf("YES\n");
		return 0;
	}
	int rt;
	for(int i=1;i<=N;i++)
		if(d[i]>=2)
		{
			rt=i;
			break;
		}
	if(DFS(rt,-1)==false||a[rt]!=0)
		printf("NO\n");
	else
		printf("YES\n");
	return 0;
}

Measured memory_bytes: 14336
#include <stdio.h>

int n, m, x, c[13], a[13][13], s, r = -1, l[13];

void d(int i) {
    if (i > n) {
        for (int j = 1; j <= m; j++) if (l[j] < x) return;
        if (r < 0 || s < r) r = s;
        return;
    }
    s += c[i];
    for (int j = 1; j <= m; j++) l[j] += a[i][j];
    d(i + 1);
    s -= c[i];
    for (int j = 1; j <= m; j++) l[j] -= a[i][j];
    d(i + 1);
}

int main() {
    scanf("%d %d %d", &n, &m, &x);
    for (int i = 1; i <= n; i++) {
        scanf("%d", &c[i]);
        for (int j = 1; j <= m; j++) scanf("%d", &a[i][j]);
    }
    d(1);
    printf("%d", r);
    return 0;
}


Measured memory_bytes: 1728