akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <queue>
#include <algorithm>
using namespace std;

int main() {
	int n, q, time;
	string name;
	// queue
	queue<pair<string, int> > Q;
	// input
	cin >> n >> q;

	// add all the processes into the queue
	for (int i=0; i<n; ++i) {
		cin >> name >> time;
		Q.push(make_pair(name, time));
	}

	pair<string, int> u;
	int elaps = 0, a;

	while (!Q.empty()) {
		u = Q.front(); Q.pop();
		a = min(u.second, q);
		u.second -= a;
		elaps += a;
		if (u.second > 0) {
			Q.push(u);
		} else {
			cout << u.first << " " << elaps << endl;
		}
	}
	return 0;
}




Measured memory_bytes: 6236
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
bool compare(pair<long long int,long int> a,pair<long long int,long int> b)
{
    return a.second<b.second;
}
int main()
{
    string a;
    cin>>a;
    bool temp=0;
    for(long int i=0;i<a.length()-1;i++)
    {
        if(a[i]==a[i+1])
        {
            temp=1;
            break ;
        }
    }
    if(temp)
    cout<<"Bad"<<endl;
    else
    cout<<"Good";
}

Measured memory_bytes: 256
#include  <iostream>
#include  <stdio.h>
#include <algorithm>
using namespace std;
#include <vector>
#define rep(i,n) for (int i = 0; i < (n) ; i++)
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define ll long long
#define ull unsigned long long
#define vint vector<int>
#define vll vector<ll>

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

#include <math.h>
/*
int standerd = int(pow(10.0,9.0)) + 7;
*/
string ans_Yes = "Yes"; 
string ans_No = "No"; 
string ans_yes = "yes"; 
string ans_no = "no"; 
 
ll N;
ll M;
ll K;
class UnionFind {
public:
    vector<int> parent; // parent[i]:iの親の番号　(例) parent[3] = 2 : 3の親が2
    vector<int> cnt;
    UnionFind(int N){ //最初は全てが根であるとして初期化
        for(int node_i = 0; node_i < N; node_i++){
            int parent_i = node_i;
            parent.push_back(parent_i);
            cnt.push_back(1);
        }
    }
    int getRoot(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (parent[x] == x) return x;
        return parent[x] = getRoot(parent[x]);
    }
    int getCnt(int x){
        return cnt[getRoot(x)];
    }
    void unite(int x, int y) { // xとyの木を併合
        int rx = getRoot(x); //xの根をrx
        int ry = getRoot(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        parent[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
        cnt[ry]+=cnt[rx];
    }
    bool isSameRoot(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = getRoot(x);
        int ry = getRoot(y);
        return rx == ry;
    }
};

int main(){
    cin >> N >> M >> K;
    UnionFind union_find(N);
    vint chain[N];

    int A,B;
    rep(ni,N){
        chain[ni].push_back(ni);
    }


    rep(mi,M){
        cin >> A;
        cin >> B;
        A--;
        B--;
        union_find.unite(A,B);
        chain[A].push_back(B);
        chain[B].push_back(A);
    }

    rep(ki,K){
        cin >> A;
        cin >> B;
        A--;
        B--;
        if(union_find.isSameRoot(A,B)){
            chain[A].push_back(B);
            chain[B].push_back(A);
        }
    }
    rep(ni,N){
        cout << ( union_find.getCnt(ni)-chain[ni].size() );
        cout << " ";
    }

}

Measured memory_bytes: 9460
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long
typedef pair<int, int> P;

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int W, H;
    cin >> W >> H;
    vector<P> pq;
    rep(i, W) {int p; cin >> p; pq.push_back({p, 0LL});}
    rep(i, H) {int q; cin >> q; pq.push_back({q, 1LL});}

    sort(pq.begin(), pq.end());
    int a = W + 1, b = H + 1;
    int ans = 0;
    rep(i, W + H) {
        if (pq[i].second == 0) {ans += b * pq[i].first; a--;}
        else {ans += a * pq[i].first; b--;}
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 6384
import java.util.Scanner;
public class Main {
 
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
 
		int  A = sc.nextInt();
		int  P = sc.nextInt();
		
		int D = (3 * A + P) / 2;
			System.out.println(D);
		
	}
} 

Measured memory_bytes: 22868
import sys, re
from math import ceil, floor, sqrt, pi, factorial, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left
from functools import reduce
from decimal import Decimal, getcontext
# input = sys.stdin.readline 
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_list(N): return [s_list() for _ in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    n, k = i_map()
    num_list = i_list()

    for _ in range(k):
        if num_list.count(n) == n:
            break
        tmp_list = [0] * (n+1)
        for j in range(n):
            l = max(0, j - num_list[j])
            r = min(j + num_list[j]+ 1, n)
            tmp_list[l] += 1
            tmp_list[r] -= 1
        for j in range(n):
            tmp_list[j+1] += tmp_list[j]
        num_list = deepcopy(tmp_list)
        
    print(*num_list[:n])

if __name__ == '__main__':
    main()


Measured memory_bytes: 180932
N,M = [int(x) for x in input().split(' ')]
AB = {}
for i in range(N):
  a,b = [int(x) for x in input().split(' ')]
  if a in AB:
    AB[a] += b
  else:
    AB[a] = b
    
dc = sorted(AB.items())

c = 0
m = M
for s in dc:
  price, stock = s
  if stock >= m:
    c += price * m
    break
  else:
    c += stock * price
    m -= stock
    
print(c)
    

Measured memory_bytes: 23008
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cassert>
#include <algorithm>
#include <vector>
using namespace std;

typedef long long LL;
const int INF = 100000000;
const int MAXN = 111111 * 2;
int val[MAXN], l[MAXN], r[MAXN], odd[MAXN];
int n, K;
vector<int> adj[MAXN];

inline bool dfs(int u, int fa) {
//cout << u << " -------- " << fa << endl;
	if (val[u] == INF) {
		l[u] = -INF, r[u] = INF;
		odd[u] = -1;
	} else {
		l[u] = r[u] = val[u];
		odd[u] = val[u] & 1;
	}
	for (int i = 0; i < adj[u].size(); ++i) {
	int v = adj[u][i];
//cout << "e: " << u << " " << v << endl;
		if (v != fa) {
			if (!dfs(v, u)) {
				return false;
			}
			int ll = l[v] - 1, rr = r[v] + 1;
			int o = odd[v] == -1 ? -1 : odd[v] ^ 1;
			l[u] = max(l[u], ll);
			r[u] = min(r[u], rr);
			if (l[u] > r[u]) {
				return false;
			}
			if (o == -1) {
				continue;
			}
			if (odd[u] == -1) {
				odd[u] = o;
			} else {
				if (o != odd[u]) {
					return false;
				}
			}
//cout << l[u] << " " << r[u] << " " << odd[u] << " " << o << endl;
			if (odd[u] != -1) {
				int t1 = l[u], t2 = min(l[u] + 1, r[u]);
				if (((t1 % 2) + 2) % 2 != odd[u] && ((t2 % 2) + 2) % 2 != odd[u]) {
// << "asdf" << endl;
					return false;
				}
			}
		}
	}
//cout << u << " " << l[u] << " " << r[u] << " " << odd[u] << endl;
	return true;
}

inline bool check_in(int x, int l, int r, int o) {
	if (x < l || x > r) {
		return false;
	}
	return o == -1 || ((x % 2) + 2) % 2 == o;
}

inline void solve(int u, int fa) {
//cout << u << " " << fa << " " << val[u] << endl;
	for (int i = 0; i < adj[u].size(); ++i) {
		int v = adj[u][i];
		if (v == fa) {
			continue;
		}
		int t1 = val[u] - 1, t2 = t1 + 2;
		if (check_in(t1, l[v], r[v], odd[v])) {
			val[v] = t1;
		} else {
			if (check_in(t2, l[v], r[v], odd[v])) {
				val[v] = t2;
			} else {
				assert(false);
			}
		}
		solve(v, u);
	}	
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	
	cin >> n;
	for (int i = 1; i <= n; ++i) {
		adj[i].clear();
		val[i] = INF;
	}
	for (int i = 1; i < n; ++i) {
		int u, v;
		cin >> u >> v;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	cin >> K;
	for (int i = 1; i <= n; ++i) {
		int u, value; 
		cin >> u >> value;
		val[u] = value;
	}
	
	if (!dfs(1, 0)) {
		cout << "No" << endl;
		return 0;
	} else {
		if (odd[1] == -1 || ((l[1] % 2) + 2) % 2 == odd[1]) {
			val[1] = l[1];
		} else {
			val[1] = l[1] + 1;
		}
		solve(1, 0);
		
		cout << "Yes" << endl;
		for (int i = 1; i <= n; ++i) {
			cout << val[i] << endl;
		}
	} 
}

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

from collections import deque
b1 = deque([])
b2 = deque([])

for i in range(N):
    if i % 2 == 0:
        b1.append(A[i])
    else:
        b2.appendleft(A[i])
print(*(list(b1)+list(b2)))

Measured memory_bytes: 101588
import java.util.Scanner;
import java.util.Set;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Queue;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();

        Room[] room = new Room[n + 1];
        for (int i = 0; i < room.length; i++) {
            room[i] = new Room(i);
        }

        for (int i = 0; i < m; i++) {
            int from = sc.nextInt();
            int to   = sc.nextInt();

            room[from].addRoom(to);
            room[to].addRoom(from);
        }

        room[1].sign = 1;

        mark(room);
        // 大文字かっい！！
        System.out.println("Yes");
        for (int i = 2; i < room.length; i++) {
            System.out.println(room[i].sign);
        }
    }

    private static void mark(Room[] room) {
        Queue<Room> queue = new LinkedList<>();

        queue.add(room[1]);

        while (!queue.isEmpty()) {
            Room r = queue.poll();

            for (Integer roomNo : r.rooms) {
                if (room[roomNo.intValue()].sign == -1) {
                    room[roomNo.intValue()].sign = r.no;
                    queue.add(room[roomNo.intValue()]);
                }
            }
        }
    }
}

class Room {
    /** 部屋番号 */
    public int no;
    /** 繋がっている部屋 */
    public Set<Integer> rooms;
    /** 繋がっている部屋の数 */
    public int size = 0;
    /** 最適な移動部屋 */
    public int sign = -1;

    public Room(int no) {
        this.no = no;
        this.rooms = new HashSet<Integer>();
    }

    public void addRoom(int no) {
        rooms.add(Integer.valueOf(no));
    }
}

Measured memory_bytes: 95044
#include<stdio.h>

int main(){
  int month, day, cout;
  while(scanf("%d%d", &month, &day), month+day){
    cout=0;
    if(month==1){
      cout += day;
    }else if(month==2){
      cout += 31+day;
    }else if(month==3){
      cout += 60+day;
    }else if(month==4){
      cout += 91+day;
    }else if(month==5){
      cout += 121+day;
    }else if(month==6){
      cout += 152+day;
    }else if(month==7){
      cout += 182+day;
    }else if(month==8){
      cout += 213+day;
    }else if(month==9){
      cout += 244+day;
    }else if(month==10){
      cout += 274+day;
    }else if(month==11){
      cout += 305+day;
    }else if(month==12){
      cout += 335+day;
    }
    if(cout%7==5){
      printf("Monday\n");
    }else if(cout%7==6){
      printf("Tuesday\n");
    }else if(cout%7==0){
      printf("Wednesday\n");
    }else if(cout%7==1){
      printf("Thursday\n");
    }else if(cout%7==2){
      printf("Friday\n");
    }else if(cout%7==3){
      printf("Saturday\n");
    }else if(cout%7==4){
      printf("Sunday\n");
    }
  }
  return 0;
}

Measured memory_bytes: 584
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;

const int mx=200010;
const ll mod=1e9+7;
ld ans=0;

ll w,h,x,y;

int main(){
  cin >> w >> h >> x >> y;

  cout << w*h/2.0 << " " << (2*x==w&&2*y==h?1:0) << endl;
  return 0;
}

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

int main() {
  int N, A, B, C, D;
  string S;
  cin >> N >> A >> B >> C >> D >> S, A--, B--, C--, D--;
  auto f = [&](int l, int r, string T) {
    return ((int) S.substr(l, r - l + 1).find(T) != -1) ? true : false;
  };
  if (f(A, C, "##") || f(B, D, "##") || (D < C && !f(B - 1, D + 1, "..."))) cout << "No" << "\n";
  else cout << "Yes" << "\n";
}

Measured memory_bytes: 3724
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a[]={1,1,1,2,1,2,1,5,2,2,1,5,1,2,1,14,1,5,1,5,2,2,1,15,2,2,5,4,1,4,1,51};
	int k;
	cin>>k;
	cout<<a[k-1]<<"\n";
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
long double pi = 2 * acos(0.0);
const ll mod = 1e9 + 7;

void solve() {
    ll n, m, k;
    cin >> n >> m >> k;
    ll a[n + 1] = {0}, b[m + 1] = {0};
    for(ll i = 1; i <= n; i++) {
        cin >> a[i];
        a[i] += a[i - 1];
    }
    for(ll i = 1; i <= m; i++) {
        cin >> b[i];
        b[i] += b[i - 1];
    }
    ll ans = 0, i = 0, j = 0, pb = m;
    for( ; i <= n && j >= 0; i++) {
        for(j = pb; j >= 0; j--) {
            if(a[i] + b[j] <= k) break;
        }
        ans = max(ans, i + j);
        pb = j;
    }
    cout << ans;
}

int main() {
    ios_base :: sync_with_stdio(false); 
    cin.tie(nullptr);   
    ll t = 1;
    //cin >> t;
    while(t--) {
        solve();
    }
    return 0;
}


Measured memory_bytes: 6752
#include <bits/stdc++.h>
#define INF 1e9
#define endl '\n'
#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 FORE(i, a, b) for (int i = (a), e = (b); i < e; ++i)
#define RFORE(i, a, b) for (int i = (b)-1, e = (a); i >= e; --i)
#define ALL(x) (x).begin(), (x).end()
#define SORT(c) sort((c).begin(), (c).end())
#define SORTR(c) sort((c).begin(), (c).end(), greater<int>())
using namespace std;
typedef long long ll;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int N;
    cin >> N;
    vector<int> t(N);
    vector<int> x(N);
    vector<int> y(N);
    for (int i = 0; i < N; i++) {
        cin >> t.at(i) >> x.at(i) >> y.at(i);
    }
    int tmp_t = 0;
    int tmp_x = 0;
    int tmp_y = 0;
    FOR(i, 0, N) {
        int t_diff = t.at(i) - tmp_t;
        int dist   = abs(x.at(i) - tmp_x) + abs(y.at(i) - tmp_y);
        if (((t_diff % 2) != (dist % 2)) || (t_diff < dist)) {
            cout << "No" << endl;
            exit(0);
        }
        tmp_t = t.at(i);
        tmp_x = x.at(i);
        tmp_y = y.at(i);
    }
    cout << "Yes" << endl;
}


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

using namespace std;

int main(){
 int A, B;
 cin >> A >> B;
 if(A >= 6 && A <= 12)
   B /= 2;
 else if(A <= 5)
   B = 0;
 cout << B << "\n";
 return 0;
}


Measured memory_bytes: 256
// C - Snuke Festival
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(int)(n);++i)

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

	int N; cin>>N;
	vector<int> A(N, 0), B(N, 0), C(N, 0);
	rep(i, N) cin>>A[i];
	rep(i, N) cin>>B[i];
	rep(i, N) cin>>C[i];
	sort(all(A));
	sort(all(C));
	int64_t ans = 0;
	for(int b:B){
		int ia = lower_bound(all(A), b) - A.begin();
		int ic = C.end() - upper_bound(all(C), b);
		ans += (int64_t)ia * ic;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 4500
#include <stdio.h>

int main(void)
{
	int a, b, c;

	scanf("%d", &a);
	scanf("%d", &b);
	scanf("%d", &c);

		if ((a < b) && (b < c))
		{
			printf("Yes\n");
		}

		else
		{
			printf("No\n");
		}
	
	return 0;

}


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

def main():

    X, Y, Z = map(int, input().split())

    X, Y = change(X, Y)
    X, Z = change(X, Z)

    print(X, Y ,Z)

def change(a, b):
    num = a
    a = b
    b = num

    return(a, b)

if __name__ == "__main__":
    main()

Measured memory_bytes: 9092
D[13][3]={{1,0,0},{0,1,0},{0,0,1},{1,1,0},{1,0,1},{0,1,1},{1,-1,0},{1,0,-1},{0,1,-1},{1,1,1},{-1,1,1},{1,-1,1},{1,1,-1}};
M[9][9][9],q[2];main(n,m,p,I,x,y,z,j,c,d,J){for(;scanf("%d%d%d",&n,&m,&p),n;){
	for(memset(M,I=0,sizeof(M)),c=1;I++<p;c*=-1){
		for(scanf("%d%d",&x,&y),z=1;;z++)if(!M[x][y][z]){M[x][y][z]=c;break;}
		for(d=0;d<13;d++){
			for(j=0;j<2;j++)for(J=2*j-1,q[j]=J;;q[j]+=J)if(M[x+D[d][0]*q[j]][y+D[d][1]*q[j]][z+D[d][2]*q[j]]!=c)break;
			if(q[1]-q[0]-1>=m){printf(c==1?"Black %d\n":"White %d\n",I);goto next;}
		}
	}
	puts("Draw");
next:
	for(;I++<p;)scanf("%d%d",&x,&y);
}exit(0);}

Measured memory_bytes: 608
#include <iostream>
#include <vector>
#include <map>
#define rep(i, n) for(i = 0; i < n; i++)
using namespace std;

int n;
int a[200001];

bool check(int x) {
	map<int, int> str;	//(桁の位置(0-indexed), 桁の値(0～x-1)). (pos, 0)以外を記録.
	int i;
	
	for (i = 1; i < n; i++) {
		if (a[i] > a[i - 1]) continue;
		while (!str.empty() && str.rbegin()->first >= a[i]) str.erase(str.rbegin()->first);
		str[a[i] - 1]++;
		
		int cur = a[i] - 1;
		while (str[cur] >= x) {
			str[cur] = 0;
			cur--;
			str[cur]++;
			if (cur < 0) { return false; }
		}
	}
	return true;
}

int main() {
	int i;
	
	cin >> n;
	a[0] = 0;
	rep(i, n) cin >> a[i + 1];
	n++;
	
	//check(1)を呼び出すと,桁上がりの処理がO(A_i)回行われる可能性があるので、答え=1かの判定は先にやる
	bool ok1 = true;
	for (i = 1; i < n; i++) if (a[i] <= a[i - 1]) ok1 = false;
	if (ok1) { cout << 1 << endl; return 0; }
	
	//2分探索
	int st = 1, ed = n, mid;	//xxxooo, (st, ed]
	while (ed - st >= 2) {
		mid = (st + ed) / 2;
		if (check(mid)) ed = mid;
		else st = mid;
	}
	cout << ed << endl;
	return 0;
}

Measured memory_bytes: 1024
from math import ceil,log
N=int(input())
A=[int(i) for i in input().split()]
def f(A):
    dp=[0]*16
    L=[0]*N
    for i in range(16):
        dp[i]=i
    for n in range(N-2,-1,-1):
        ndp=[0]*16
        nx=ceil(log(A[n]/A[n+1])/log(4)) #A
        for x in range(16):
            dx=nx+x
            if dx <=15:
                #print(max(0,dx))
                ndp[x]=dp[max(0,dx)]+x
            else:
                ndp[x]=dp[15]+x+(N-1-n)*(dx-15)
        dp=ndp
        L[n]=dp[0]
    return L

K=f(A)+[0]
L=[0]+f(A[::-1])[::-1]
ans=10**22
for i in range(N+1):
    ans=min(ans,i+2*L[i]+2*K[i])
print(ans)

Measured memory_bytes: 124984
import sys
sys.setrecursionlimit(100000)

def check(x, y, flag):
	farm[x][y] = "$"
	if farm[x + 1][y] == flag : check(x + 1, y, flag)
	if farm[x - 1][y] == flag : check(x - 1, y, flag)
	if farm[x][y + 1] == flag : check(x, y + 1, flag)
	if farm[x][y - 1] == flag : check(x, y - 1, flag)
	return 1

while True:
	h,w = map(int, raw_input().split())
	if h == 0 and w == 0 : break

	farm = []
	farm.append(list("$" * (w + 2)))
	for i in range(0, h):
		farm.append(list("$" + raw_input() + "$"))
	farm.append(list("$" * (w + 2)))
	
	count = 0
	for i in range(0, h):
		for j in range(0, w):
			if farm[i + 1][j + 1] != "$":
				count += check(i + 1, j + 1, farm[i + 1][j + 1])
				
	print count

Measured memory_bytes: 14260
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef pair<ll, ll> P;
ll Mod = 1000000007;
ll dis[100005];
bool OK[100005];
vector<P> R[100005];

void DFS(ll a) {
  for (int i = 0; i < R[a].size(); i++) {
    if (!OK[R[a][i].first]) {
      OK[R[a][i].first] = true;
      dis[R[a][i].first] = dis[a] + R[a][i].second;
      DFS(R[a][i].first);
    }
  }
  return ;
}

int main() {
  ll N;
  cin >> N;
  
  for (int i = 0; i < N-1; i++) {
    ll u,v,w;
    cin >> u >> v >> w;
    u--;
    v--;
    R[u].push_back(make_pair(v,w));
    R[v].push_back(make_pair(u,w));
  }
  dis[0] = 0;
  DFS(0);
  for (int i = 0; i < N; i++) {
    cout << dis[i] % 2 << endl;
  }
  return 0;
}

Measured memory_bytes: 10240
import sys
from fractions import gcd
from collections import defaultdict
from collections import deque
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return list(map(int, sys.stdin.readline().split()))
def II(): return int(sys.stdin.readline())
def LS(): return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]

def main():
    n, m = LI()
    g = [[] for i in range(3*(n+1))]
    for i in range(m):
        u, v = LI()
        g[u].append(v + n + 1)
        g[u + n + 1].append(v + 2*(n + 1))
        g[u + 2*(n + 1)].append(v)

    s, t = LI()

    Q = deque([s])
    searched = [0 for i in range(3*(n+1))]
    searched[s] = 1
    depth = [0 for i in range(3*(n+1))]
    while len(Q) != 0:
        v = Q.popleft()
        for i in g[v]:
            if i == t:
                depth[i] = depth[v] + 1
                print(depth[i]//3)
                return
            if searched[i] == 0:
                depth[i] = depth[v] + 1
                Q.append(i)
                searched[i] = 1
    print(-1)


if __name__ == "__main__":
    main()

Measured memory_bytes: 121888
R, G, B, N = map(int, input().split())
answer = 0
# Rr + Gg + Bb = N ( 0 <= r, 0 <= g, 0 <= b)

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

print(answer)

Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
#define inf          0x3f3f3f3f
#define go(a,b,c)    for(int a=b;a<=c;a++)
#define gov(a,b)     for(int a=0;a<b.size();a++)
#define rgo(a,b,c)   for(int a=b;a>=c;a--)
#define sf(a)        scanf("%d",&a)
#define sff(a,b)     scanf("%d%d",&a,&b)
#define sfff(a,b,c)  scanf("%d%d%d",&a,&b,&c)
#define eps          1e-9
#define ft           first
#define sd           second
#define prt(a)       printf("%d\n",a)
#define prn(i,n,a)   printf("%d%c",a,i==n?'\n':' ')
#define pb           push_back
typedef long long LL;
typedef pair<int,int> pii;
typedef set<int> si;
typedef vector<int> vi;
typedef map<int,int> mii;
typedef double db;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
const int maxn=5e5+10;
const LL mod=1e9+7;
LL fsp(LL a,LL b)
{
	LL ans=1;
	while(b)
	{
		if(b&1)ans=ans*a%mod;
		a=a*a%mod;
		b>>=1;
	}
	return ans%mod;
}
int read()
{
	int f=0,x=0;
	char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch<='9'&&ch>='0'){x=x*10+ch-'0';ch=getchar();}
	return f*x;
}
//=======================================================
int q,n,d,a[maxn],dis[maxn];
LL c[maxn];
void work()
{
	
	go(i,1,n)sf(a[i]);
	int now=d;
	dis[0]=d;
	go(i,1,n)
	{
		if(a[i]<now*2)now=abs(now-a[i]);
		dis[i]=now;
	}
	c[n]=1;
	rgo(i,n-1,1)
	{
		if(a[i+1]>=2*c[i+1])c[i]=c[i+1];
		else c[i]=c[i+1]+a[i+1];
		//if(c[i]>1e9)c[i]=1e9;
	}
	sf(q);
	while(q--)
	{
		int x;
		sf(x);
		if(dis[x-1]>=c[x])puts("YES");
		else puts("NO");
	}
	
	
}
int main()
{
	while(~sff(n,d))
	{
		work();
	}
	return 0;
}

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

char S[204];

bool even(int len) {
    for(int i = 0; i < len; ++i) {
        int j = len + i;
        if(S[i] != S[j]) return false;
    }
    return true;
}

int main()
{
    scanf("%s", S);
    int N = strlen(S);
    int p = (N%2) ? N/2 : N/2 - 1;
    for(int len = p; len > 0; --len) 
        if(even(len)) { cout << 2*len << endl; break; }
    
    return 0;
}

Measured memory_bytes: 256
N,MOD=int(input()),10**9+7
memo = [{} for i in range(N+1)]
def ok(last4):
  for i in range(4):
    t = list(last4)
    if i >= 1:
      t[i-1], t[i] = t[i], t[i-1]
    if ''.join(t).count('AGC') >= 1:
      return False
  return True

def dfs(cur, last3):
  if last3 in memo[cur]:
    return memo[cur][last3]
  if cur == N:
    return 1
  ret = 0
  for c in 'ACGT':
    if ok(last3 + c):
      ret = (ret + dfs(cur + 1, last3[1:] + c)) % MOD
  memo[cur][last3] = ret
  return ret

print(dfs(0, 'TTT'))

Measured memory_bytes: 3872
r,c = map(int,input().split(' '))
arr = [[0 for i in range(c+1)] for i in range(r+1)]

for i in range(r):
    row = list(map(int,input().split(' ')))
    for j in range(c):
        arr[i][j] = row[j]

for i in range(r):
    for j in range(c):
        arr[i][-1] += arr[i][j]
for i in range(c):
    for j in range(r):
        arr[-1][i] += arr[j][i]
        
if c == 1:
    for i in range(r):
        arr[-1][-1] += arr[i][0]
elif r == 1:
    for i in range(c):
        arr[-1][-1] += arr[0][i]
else:
    for i in range(r):
        arr[-1][-1] += arr[i][-1]
    
for i in range(r+1):
    for j in range(c):
        print(arr[i][j],end = ' ')
    print(arr[i][-1])

Measured memory_bytes: 8428
#include <iostream>
#include <vector>
#include <queue>
using namespace std;

struct Relation {
  int x, y, z;
};

int main() {
  int n, m;
  cin >> n >> m;
  vector<Relation> xyz(m);
  for (auto& r : xyz) {
    cin >> r.x >> r.y >> r.z;
  }

  vector<bool> visited(n);
  vector<vector<int>> to(n);
  for (auto& r : xyz) {
    int x = r.x - 1;
    int y = r.y - 1;
    to[x].push_back(y);
    to[y].push_back(x);
  }

  int cost = 0;
  for (int i = 0; i < n; ++i) {
    if (visited[i])
      continue;
    
    ++cost;
    queue<int> q;
    q.push(i);
    while (!q.empty()) {
      int j = q.front();
      q.pop();
      for (int k : to[j]) {
        if (visited[k])
          continue;
        visited[k] = true;
        q.push(k);
      }
    }
  }
  cout << cost << "\n";

  return 0;
}


Measured memory_bytes: 7672
#include <iostream>
#include <string>
#include <vector>

#define rep(i,n) for (int i = 0; i < (n); ++i)

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

int main() {
  int A, B, C;
  cin >> A >> B >> C;

  if (A <= C && C <= B) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 256
sx, sy, tx, ty = map(int, input().split())
xf, xb, yf, yb = 'R', 'L', 'U', 'D'
dx = abs(tx - sx)
dy = abs(ty - sy)

if tx < sx:
  xf, xb = 'L', 'R'
if ty < sy:
  yf, yb = 'D', 'U'

s = ""
if dx == 0:
  s += yf*dy
  s += xf
  s += yb*dy
  s += xb
  s += xb
  s += yf*dy
  s += xf
  s += yf
  s += xf*2
  s += yb*(dy+2)
  s += xb*2
  s *= yb
elif dy == 0:
  s += xf*dx
  s += yb
  s += xb*dx
  s += yf
  s += yf
  s += xf*dx
  s += yb
  s += xf
  s += yb*2
  s += xb(dx+2)
  s += yf*2
  s += xf
else:
  s += yf*dy
  s += xf*dx
  s += yb*dy
  s += xb*dx
  s += xb
  s += yf*(dy+1)
  s += xf*(dx+1)
  s += yb
  s += xf
  s += yb*(dy+1)
  s += xb*(dx+1)
  s += yf

print(s)

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

#define rep(i,n) for(int i=0; i<(n); i++);
using namespace std;
vector<double> v;

int main(){
    int N;
    double sum;

    cin >> N;
    v.resize(N);

    for(int i=0; i<N; i++) cin >> v[i];
    sort(v.begin(), v.end());

    sum = v[0];
    for(int i=1; i<N; i++){
        sum = (sum + v[i])/2.0;
    }

    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include<vector>
#include <algorithm>
#include<cstdlib>
#include<set>
#include<math.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define rep(i,n) for(ll i=0;i<n;i++)

int main()
{
	ll a, b, k;
	cin >> a >> b >> k;
	if (k <= a)
	{
		cout << a - k << " " << b << "\n";
	}
	else
	{
		if (k <= a + b)
		{
			cout << '0' << " " << a + b - k << "\n";
		}
		else cout << 0 << " " << 0 << "\n";
	}
	return 0;
}

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

#define ll long long //data types used often, but you don't want to type them time by time
#define ull unsigned long long
#define ui unsigned int
#define mod 1000000007
#define inf 100000000000010
#define us unsigned short
#define IOS ios_base::sync_with_stdio(0); //to synchronize the input of cin and scanf
#define INF LONG_MAX
#define PI 3.1415926535897932384626
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define rep(x,j,n)for(int x=j;x<n;x++)
#define all(x) (x).begin(), (x).end()

typedef vector<pair<ll,ll>> vpi;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll,ll> pi;

bool prime(ll n)
{
    if(n<=1)return false;
    if(n<=3)return true;
    if(n%2==0||n%3==0)return false;
    for(ll i=5;i*i<=n;i+=6)
    {
        if(n%i==0||n%(i+2)==0)return false;
    }
    return true;
}

ll modexp(ll a,ll b,ll m)
{
    ll r=1;
    a=a%m;
    while(b>0)
    {
        if(b&1)r=(r*a)%m;
        b = b>>1;
        a=(a*a)%m;
    }
    return r%m;
}

struct CustomCompare
{
    bool operator()(const int& lhs, const int& rhs)
    {
        return lhs < rhs;
    }
};

bool comp(pair<ll, pi>a,pair<ll,pi>b)
{
    if(a.se.fi==b.se.fi)return a.se.se>b.se.se;
    return a.se.fi>b.se.fi;
}

ll builtin_popcount(ll x)
{
    ll cnt = 0;
    for(ll i=60;i>=0;i--)
    {
        if((1LL<<i)&x)cnt++;
    }
    return cnt;
}


int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
ll x; cin>>x;
cout<<360/__gcd(x,360LL)<<endl;
return 0;
}
/*
50 25
39 99 70 24 49 13 86 43 88 74 45 92 72 71 90 32 19 76 84 46 63 15 87 1 39 58 17 65 99 43 83 29 64 67 100 14 17 100 81 26 45 40 95 94 86 2 89 57 52 91 45
1221 360 459 651 958 584 345 181 536 116 1310 403 669 1044 1281 711 222 280 1255 257 811 409 698 74 838
*/


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

int compare(const void *a,const void *b){
  return *(int*)b-*(int*)a;
}

int main(){
  int n;
  scanf("%d",&n);
  int a[200];
  int i;
  for(i=0;i<n;++i) scanf("%d",&a[i]);
  qsort(a,n,4,compare);
  
  
  int ans = 0;
  
  for(i=0;i<n;++i){
    if(i%2==0) ans += a[i];
    else ans -= a[i];
  }
  
  printf("%d\n",ans);
}


Measured memory_bytes: 1728
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>

#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

#include <stdexcept>

using namespace std;

// type alias
using ll = long long;
using ull = unsigned long long;

ll MOD = 1000000007LL;

//conversion
//------------------------------------------
inline int toint(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class t> inline string tostring(t x) { ostringstream sout; sout << x; return sout.str(); }

//debug
#define DUMP(x)  cerr << #x << " = " << (x) << endl
#define DEBUG(x) cerr << #x << " = " << (x) << " (l" << __line__ << ")" << " " << __file__ << endl

ll get_lis_length(const vector<ll>& seq, bool strictly = true, bool ascending = true)
{

	vector<ll> min_last_seq_elem;
	using iter_type = decltype(min_last_seq_elem.begin());
	auto get_iter = [&strictly, &ascending](iter_type begin, iter_type end, ll elem)
	{
		if (strictly)
		{
			if(ascending)
				return upper_bound(begin, end, elem, less<ll>());
			else
				return upper_bound(begin, end, elem, greater<ll>());
		}
		else
		{
			if (ascending)
				return lower_bound(begin, end, elem, less<ll>());
			else
				return lower_bound(begin, end, elem, greater<ll>());
		}
	};

	for (auto& elem : seq)
	{
		auto iter = get_iter(min_last_seq_elem.begin(), min_last_seq_elem.end(), elem);
		if (iter == min_last_seq_elem.end())
			min_last_seq_elem.emplace_back(elem);
		else
			*iter = elem;
	}

	return min_last_seq_elem.size();
}

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

	ll N;
	cin >> N;

	vector<ll> vs(N);
	for (ll i = 0; i < N; ++i)
	{
		cin >> vs[i];
	}

	cout << get_lis_length(vs, true, false) << endl;

	return 0;
}


Measured memory_bytes: 2168
import java.util.*;
public class Main{
	public static void main(String args[]){
		
		Scanner ob = new Scanner(System.in);
		long N = ob.nextLong();
		long sum = 0;
		
		for(long i = 1; i <= N; i++){
			if((i % 3 != 0) && (i % 5 != 0)){
				sum += i;
				//System.out.println("i: " + i);
				//System.out.println("Sum: " + sum);	
			}
			else{
				continue;
			}
		}
		System.out.println(sum);
	}
}


Measured memory_bytes: 35824
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		
		String[] S = new String[n];
		int x = 0;
		
		for(int i = 0; i < n; i++) {
			S[i] = sc.next();
			if(i > 0 && S[i].length() < S[i - 1].length()) {
				x = i;
			}
		}
		
		String temp = S[0];
		S[0] = S[x];
		S[x] = temp;
		String ans = "";
		
		for(int i = 0; i < S[0].length(); i++) {
			int count = 0;
			for(int j = 1; j < n; j++) {
				int y = S[j].indexOf(S[0].substring(i, i + 1));
				if(y >= 0) {
					S[j] = S[j].substring(0, y) + S[j].substring(y + 1, S[j].length());
					count++;
				}

			}
			if(count == n - 1) {
				ans += S[0].substring(i, i + 1);
			}
		}

		String[] ans1 = ans.split("");
		Arrays.sort(ans1);
		for(String i : ans1) {
			System.out.print(i);
		}
	}
}


Measured memory_bytes: 25684
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <bitset>
#include <fstream>
#include <cmath>
#include <ctime>
using namespace std;
typedef long long ll;

int check(string, string);

int main()
{
	string s1, s2;

	while(cin >> s1 >> s2)
	{
		int res = 0;
		if(s1.size() < s2.size()) swap(s1, s2);

		for(int i = 0; i < s1.size(); i++)
			res = max(res, check(s1.substr(i, s1.size()), s2));

		for(int i = 0; i < s2.size(); i++)
			res = max(res, check(s2.substr(s2.size()-1-i, s2.size()), s1));

		cout << res << endl;
	}
}

int check(string s1, string s2)
{
	int res = 0, sn = 0;
	for(int i = 0; i < min(s1.size(), s2.size()); i++){
		if(s1[i] == s2[i])	sn++;
		else				sn = 0;

		res = max(res, sn);
	}
	return res;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define PII pair<LL,LL>
#define FOR(i,a,b) for (LL i=(a);i<=(b);++i)
#define ROF(i,b,a) for (LL i=(b);i>=(a);--i)
typedef long long LL;
inline LL read(){
	LL x=0,f=1; char ch=getchar();
	while (ch<'0'||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	while (ch>='0'&&ch<='9') { x=x*10+ch-'0'; ch=getchar(); }
	return x*f;
}

const LL MAXN=350005,Mo=1000000007;
LL n,m,a,b,c,d;
int main(){
	a=read(); b=read(); c=read(); d=read(); n=read();
	if (a*8<d) d=a*8;
	if (b*4<d) d=b*4;
	if (c*2<d) d=c*2;
	if (a*4<c) c=a*4;
	if (b*2<c) c=b*2;
	if (n&1) cout<<n/2*d+c<<endl; else cout<<n/2*d<<endl;
	return 0;
}

/*
*/


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
typedef long long ll; 
using namespace std;
ll n,k,h[200100],cnt;
int main(){
    cin>>n>>k;
    for(int i=0;i<n;i++){
        cin>>h[i];
    }
    sort(h,h+n);
    for(int i=0;i<n-k;i++){
        cnt+=h[i];
    }
    cout<<cnt<<endl;
}

Measured memory_bytes: 1792
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintStream;

class Main {

    public static void main(String[] args) throws IOException {
        doit(args, System.in, System.out);
    }

    static void doit(String[] args, InputStream in, PrintStream out)
            throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        String line = null;
        while ((line = reader.readLine()) != null && !line.isEmpty()) {
            int n = 0;
            for (String word : line.split("[ .]")) {
                if (word.length() != 3 && word.length() != 4) {
                    continue;
                }
                n = ('t' - word.charAt(0) + 26) % 26;
                String s = decrypt(word, n);
                if (s.matches("the|this|that")) {
                    break;
                }
            }
            String result = decrypt(line, n);
            out.println(result);
        }
    }

    static String decrypt(String s, int n) {
        StringBuilder sb = new StringBuilder();
        for (char ch : s.toCharArray()) {
            if (ch >= 'a' && ch <= 'z') {
                ch = (char) ('a' + (ch - 'a' + n) % 26);
            }
            sb.append(ch);
        }
        return sb.toString();
    }
}

Measured memory_bytes: 9344
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long llu;
vector<pair<int,int>> vp;
pair<int,int> pp;
vector<ll> vv,vv1;
map<int,int> mp;
int mat[502][502];
int main()
{
   int n;
   cin>>n;
   int a[n],b[n],c[n],dp1[n],dp2[n],dp3[n];
   for(int i=0; i<n; i++){
        cin>>a[i]>>b[i]>>c[i];
   }
   dp1[0] = a[0],dp2[0] = b[0],dp3[0] = c[0];
   for(int i=1; i<n; i++){
        dp1[i] = a[i] + max(dp2[i-1],dp3[i-1]);
        dp2[i] = b[i] + max(dp1[i-1],dp3[i-1]);
        dp3[i] = c[i] + max(dp1[i-1],dp2[i-1]);
   }
   cout<<max(dp1[n-1],max(dp2[n-1],dp3[n-1]))<<"\n";

}


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

int arr[1000001];
int c=0,terA,terB;

void swap(int &a,int &b) {
	int t=a;
	a=b;
	b=t;
}

void cek(int x) {
	if(c==0) {
		c++;
		terA=x;
		return;
	} else if(c==1) {
		c++;
		terB=x;
		if(terB>terA) swap(terA,terB);
		return;
	} else {
		if(x>terB) {
			terB=x;
			if(terB>terA) {
				swap(terA,terB);
			}
		}
	}
}

int main() {
	int a;
	cin>>a;
	for(int i=0;i<a;i++) {
		cin>>arr[i];
		cek(arr[i]);
	}
	for(int i=0;i<a;i++) {
		if(arr[i]!=terA) cout<<terA;
		else cout<<terB;
		cout<<endl;
	}
}

Measured memory_bytes: 2432
import itertools
N,M = input().split()
N = int(N)
M = int(M)
line_list = []
for i in range(M):
    line = input().split()
    new_list=[]
    for l in line:
        new_list.append(int(l))
    new_list.pop(0)
    line_list.append(new_list)
old_p_list = input().split()
p_list = []
for p in old_p_list:
    p_list.append(int(p))

A = []
for n in range(N):
    A.append([True,False])
pattern_list = list(itertools.product(*A))
pattern_num = 0
for pattern in pattern_list:
    ok_flug = 1
    for i, line in enumerate(line_list):
            on_num = 0
            for l in line:
                if pattern[l-1]:
                    on_num += 1
            if on_num%2 != p_list[i]:
                ok_flug = 0
    if ok_flug == 1:
        pattern_num += 1
print(pattern_num)


Measured memory_bytes: 3316
import java.util.Scanner;

public class Main {
    
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        final int N = sc.nextInt();
        final int X = sc.nextInt();
        final int T = sc.nextInt();
        
        System.out.println((N + X - 1) / X * T);
    }
}


Measured memory_bytes: 35660
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(obj) (obj).begin(),(obj).end()
typedef long long llong;

llong gcd(llong a,llong b){
    if(b==0) return a;
    return gcd(b,a%b);
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  llong x,m=1;
  cin>>n;
  for(int i=0;i<n;i++){
      cin>>x;
      llong j=gcd(m,x);
      m/=j;
      m*=x;
  }
  cout<<m<<endl;
  return 0;
}


Measured memory_bytes: 256
[n, a, b] = [int(i) for i in input().split()]
mod = 1000000007

def factorial(n,m):
    #0〜(2 * 10 ^ 5)!のリスト
    f = [1,1]
    for i in range(2,n+1):
        f.append(f[-1]*i % m)
    #modにおける逆元のリスト
    g = [1]
    for i in range(n):
        g.append(pow(f[i+1],m-2,m))
    return f,g

f, g = factorial(2*10**5+1,mod)

div_a = g[a]
"""
for i in range(n,n-a-1,-1):
    div_a *= i
    div_a %= mod
"""
for i in range(1,a+1):
    div_a *= n - i + 1
    div_a %= mod


div_b = g[b]
for i in range(1,b+1):
    div_b *= n - i + 1
    div_b %= mod


mx = pow(2, n, mod)
mx += mod*3
print((mx - 1 - div_a - div_b)%mod)


Measured memory_bytes: 18924
S = input()
if S[0] != 'A':
  print("WA")
else:
  if 'C' not in S[2:-1] or S[2:-1].count('C') > 1:
    print("WA")
  else:
    i = S.find('C')
    S = S[0:1].lower() + S[1:i] + S[i:i+1].lower() + S[i+1:]
    if S.islower():
      print("AC")
    else:
      print("WA")

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <cmath>
#include <climits>
#include <vector>
#include <cstring>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <unordered_map>
#include <string.h>
#include <iomanip>
using namespace std;
#define int long long
#define ull unsigned long long
#define F first
#define S second
#define nl "\n"
#define ld long double
#define div 1000000007
#define pi 3.14159265358979323846

void solve()
{
    ull n;cin>>n;
    ull t3=(n/3);
    ull t5=(n/5);
    ull t15=n/15;
    ull ans=n*(n+1)/2-(3*t3*(t3+1)/2-(15*t15*(t15+1)/2))-(5*t5*(t5+1)/2-(15*t15*(t15+1)/2))-(15*t15*(t15+1)/2);
    cout<<ans<<nl;
}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    vector<int> v(3);
    for(auto& a:v){
        cin>>a;
    }
    bool f=false;
    for(int i=0;i<3;i++){
        if(v[i%3]+v[(i+1)%3]==v[(i+2)%3]){
            f=true;
        }
    }
    if(f){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
// __builtin_ctz : no of trailing zeros
#define int long long
#define ll long long
#define pp pair<int,int>
#define mod 1000000007
#define trace(x) cerr<<#x<<": "<<x<<" "<<endl
#define trace2(x, y) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z) cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define sa(a,n) for(int i =0 ; i<n ; i++) cin>>a[i]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define scan() int n; cin>>n ; int a[n]; for(int i = 0 ; i<n ; i++) cin>>a[i]
#define print(a,n) for(int i = 0 ; i < n ; i++) cout<<a[i]<<' '
using namespace std;
int max(int x, int y)
{
    return x>y ? x : y;
}
int min(int x, int y)
{
    return x<y ? x : y;
}
void _(int&a , int b)
{
    a=(a%mod+b%mod)%mod;
    a=(a+mod)%mod;
}
ll cl(ll a,ll b)
{
    return (a/b)+(!(!(a%b)));
}
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n;cin >> n;ll d=n%10;
    if(d==3)cout << "bon";
    else if(d==0 or d==1 or d==6 or d==8)cout << "pon";
    else cout << "hon";
    }

Measured memory_bytes: 3648
#include<bits/stdc++.h>
#include<numeric>
using namespace std;
#define ll  long long
#define mp make_pair
#define fi first
#define se second
#define pii pair<ll,ll>
#define pb push_back
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define what_is(x) cerr << #x << " is " << x << endl;
#define mod 1000000007
ll int dp[1001];
void prime()
{
    for(int i=1;i<=1000;i++)
    dp[i]=1;
    dp[1]=0;
    for(int i=2;i<=1000;i++)
    {
        if(dp[i])
        for(int j=i*i;j<=1000;j+=i)
        {
            dp[j]=0;
        }
    }
    // for(int i=1;i<=20;i++)
    // what_is(dp[i]);
}
ll int e(ll int n,ll int p)
{
    ll int ans=0,x=p;
    while((n/x)>0)
    {
        ans += n/x;
        x *=p;
    }
    // what_is(ans);
    return ans ;
}
int main()
{
    ll int n;
    ll int total=1;
    cin >> n;
    prime();
    for(int i=1;i<=n;i++)
    {
        if(dp[i])
        total = total*(e(n,i)+1);
        total %=mod;
    }
    cout << total ;
}

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

int a[31][200001], sum[200001];

int main()
{
  int N, C;
  cin >> N >> C;

  for(int i = 0; i < N; i++){
    int s, t, c;
    cin >> s >> t >> c;
    a[c][s*2]++;
    a[c][t*2]--;
  }

  for(int i = 1; i <= C; i++){
    for(int j = 2; j <= 200000; j++){
      if(a[i][j] > 0){
        a[i][j-1] = a[i][j];
        a[i][j] = 0;
      }
    }
  }

  int ans = 0;
  for(int i = 1; i <= 200000; i++){
    sum[i] = sum[i-1];
    for(int j = 1; j <= C; j++){
      sum[i] += a[j][i-1];
    }
    ans = max(ans, sum[i]);
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 24448
#include <bits/stdc++.h>
#include <vector>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,a,b)for(int i=(int)(a);(i)<(int)(b);i++)

typedef unsigned long long ull;
typedef long long ll;

const int INF = 1001001001;
const ll MOD = 1e9 + 7;

using namespace std;
using P = pair<int,int>;

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

int main() {
  ll n; cin >> n;
  ll a[n]; ll s[n+1] = {0};
  rep(i, n) {
      cin >> a[i];
      s[i+1] = s[i] + a[i];
  }

  ll min_diff = 20000000000;
  rep(i, n) {
      if (s[n]-s[i] == s[i]) 
      {
          cout << 0 << endl;
          return 0;
      }
      min_diff = min(min_diff, abs(s[n] - s[i] - s[i]));
  }
  cout << min_diff << endl;
  
  return 0;
}

Measured memory_bytes: 3328
n, m = map(int, input().split())
h = list(map(int, input().split()))
good = [True] * n
for _ in range(m):
    a, b = map(int, input().split())
    if h[a-1] < h[b-1]:
        good[a-1] = False
    elif h[a-1] > h[b-1]:
        good[b-1] = False
    else:
        good[a-1] = False
        good[b-1] = False
print(sum(good))


Measured memory_bytes: 20112
#include <vector>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <cstdlib>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0;i<n;i++)
#define SORT(c) sort((c).begin(),(c).end())

string ans;
int num;

void zeroPlusOneMinus(int operand, int zeroOrOne) {
  if(zeroOrOne == 0) {
    num += operand;
    ans += "+" + to_string(operand);
  } else {
    num -= operand;
    ans += "-" + to_string(operand);
  }
}

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

  string s;
  cin >> s;

  REP(i, 2) {
    REP(j, 2) {
      REP(k, 2) {
        ans = s.substr(0, 1);
        num = stoi(s.substr(0, 1));

        zeroPlusOneMinus(stoi(s.substr(1, 1)), i);
        zeroPlusOneMinus(stoi(s.substr(2, 1)), j);
        zeroPlusOneMinus(stoi(s.substr(3, 1)), k);

        if(num == 7) {
          cout << ans + "=7";
          return 0;
        }
      }
    }
  }
}


Measured memory_bytes: 256