akhauriyash/Code-Regression huggingface dataset:
# copy from https://atcoder.jp/contests/abc138/submissions/15674047

import sys
import heapq
import math


def input():
    return sys.stdin.readline().rstrip()


def main():
    N, Q = map(int, input().split())
    tree = [[] for _ in range(N)]

    for _ in range(N - 1):
        a, b = map(lambda x: int(x) - 1, input().split())
        tree[a].append(b)
        tree[b].append(a)

    counter = [0] * N

    for _ in range(Q):
        p, x = map(int, input().split())
        counter[p - 1] += x

    visited = set()
    stack = [0]
    while stack:  # 深さ優先
        i = stack.pop()
        visited.add(i)
        for j in tree[i]:
            if not j in visited:  # 逆方向回るの防止
                counter[j] += counter[i]
                stack.append(j)
    print(*counter)


if __name__ == "__main__":
    main()


Measured memory_bytes: 144772
N, X, Y = map(int, input().split())

ans = [0]*N

for i in range(1, X):
    for j in range(i+1, N+1):
        ans[min(j-i, X-i+1+abs(Y-j))] += 1

for i in range(X, Y):
    for j in range(i+1, N+1):
        ans[min(j-i,i-X+1+abs(Y-j))] += 1

for i in range(Y, N):
    for j in range(i+1, N+1):
        ans[j-i] += 1

for i in range(1, N):
    print(ans[i])


Measured memory_bytes: 46940
//
#include <vector>
#include <set>
#include <map>
#include <array>
#include <iostream>
#include <algorithm>
#include <numeric>
#include <bitset>
#include <cstdio>
#include <cstdint>
#include <cmath>
//
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);++i)
inline void yes(bool cond) { cond ? puts("Yes") : puts("No"); }
template<typename Type> inline void chmin(Type& a, Type b) { if (a > b) a = b; }
template<typename Type> inline void chmax(Type& a, Type b) { if (a < b) a = b; }
template<typename Type> inline void sort(Type& arr) { std::sort(arr.begin(), arr.end()); }
template<typename Type> inline Type nth(vector<Type>& arr, size_t pos) { std::nth_element(arr.begin(), arr.begin() + pos, arr.end()); return arr[pos]; }
constexpr ll BIGP = 1000000007L;
constexpr ll INF_I = std::numeric_limits<ll>::max();
constexpr ld INF_F = std::numeric_limits<float>::infinity();
constexpr ld PI = 3.14159265358979323846L;
//
int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    ll N, K;
    cin >> N;
    int count[4] = {};
    rep(i, N)
    {
        string S;
        cin >> S;
        if(S=="AC") ++count[0];
        else if (S == "WA") ++count[1];
        else if (S == "TLE") ++count[2];
        else if (S == "RE") ++count[3];
    }

    cout << "AC x " << count[0] << endl;
    cout << "WA x " << count[1] << endl;
    cout << "TLE x " << count[2] << endl;
    cout << "RE x " << count[3] << endl;
    return 0;
}

Measured memory_bytes: 3192
#include <stdio.h>
#include <string.h>

int main(void)
{
	int len;
	int i, j, k;
	char str[128];
	
	while (fgets(str, 128, stdin) != NULL){
		len = strlen(str);
		for (i = 0; i < len; i++){
			if (str[i] == '@'){
				i++;
				for (k = 0; k < str[i] - '0'; k++){
					printf("%c", str[i + 1]);
				}
				i++;
			}
			else {
				printf("%c", str[i]);
			}
		}
//		printf("\n");
	}
	
	return (0);
}

Measured memory_bytes: 912
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        final Scanner sc = new Scanner(System.in);

        final int N = sc.nextInt();

        for (int x = 1; x <= 9; x++) {
            for (int y = 1; y <= 9; y++) {
                if (x * y == N) {
                    System.out.println("Yes");
                    return;
                }
            }
        }

        System.out.println("No");
    }
}


Measured memory_bytes: 23892
//#include "pch.h"
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>

#include <vector>
#include <set>
#include <map>
#include <iostream>
#include <utility>
#include <queue>
#include <algorithm>
#include <functional>
#include <string>

#define ll long long
#define fri(n) for(i=0;i<(n);i++)
#define frj(n) for(j=0;j<(n);i++)
#define min(p,q) ((p)<(q)?(p):(q))
#define max(p,q) ((p)>(q)?(p):(q))
#define swap(p,q) r=(p);(p)=(q);(q)=r
#define INF 1000000000000000000//10^18
#define INFINT 2000000001//2*10^9+1
#define MOD 1000000007
#define MODANOTHER 998244353
#define PI acos(-1)

using namespace std;




int main(void)
{
	//変数の宣言
	int n,m,c;
	int b[30];
	int a[30][30];

	//よく使う変数
	int i,j,k,l;
	int flag=0;
	int ans=0;
	int count=0;
	int temp,temp1,temp2;
	int max,min;
	int len;
	int sum=0;
	int ok,ng;



	//データの読み込み


	scanf("%d %d %d",&n,&m,&c);
//	scanf_s("%d %d %d",&n,&m,&c);

	for(i=0;i<m;i++){
		scanf("%d",&b[i]);
//		scanf_s("%d",&b[i]);
	}

	for(i=0;i<n;i++){
		for(j=0;j<m;j++){
			scanf("%d",&a[i][j]);
//			scanf_s("%d",&a[i][j]);
		}		
	}

	//	printf("nは%dです\n", n);
	//	printf("データの読み込み終了\n");
	//実際の処理

	for(i=0;i<n;i++){
		temp=c;
		for(j=0;j<m;j++){
			temp=temp+a[i][j]*b[j];
		}
		if(temp>0)ans++;
	}

	//	printf("計算部分終了\n");

	//出力


	printf("%d",ans);


	//	printf("結果の出力終了\n");


	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <utility>
#include <deque>
#include <stack>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<ll> vl;
typedef queue<int> qi;
typedef queue<ll> ql;
typedef pair<ll,ll> pll;
typedef pair<int,ll> pil;
typedef pair<ll,int> pli;
#define rep(i,n) for (ll i=0;i<n;i++)
#define mp make_pair
#define pb push_back
#define pf push_front
#define F first
#define S second
#define INF 200000009
#define I_Love_CHYY ios::sync_with_stdio
#define true false
vector<ll> v0,v1,v2,v3;
ll s0[105],s1[105],s2[105],s3[105];
ll n0,n1,n2,n3,n,w,w1,ans=0;
int main(){
	#define all(x) x.begin()+1,x.end()
	I_Love_CHYY(true);
	cin>>n>>w;int tmp;
	cin>>w1>>tmp;
	v0.pb(0),v1.pb(0),v2.pb(0),v3.pb(0);
	v0.pb(tmp);
	rep(i,n-1){
		int x,y;cin>>x>>y;
		switch (x-w1){
			case 0:v0.pb(y);break;
			case 1:v1.pb(y);break;
			case 2:v2.pb(y);break;
			case 3:v3.pb(y);break;
		}
	}
	n0=v0.size();n1=v1.size();n2=v2.size();n3=v3.size();
	sort(all(v0)),sort(all(v1)),sort(all(v2)),sort(all(v3));
	reverse(all(v0)),reverse(all(v1)),reverse(all(v2)),reverse(all(v3));
	for (ll i=1;i<n0;++i) s0[i]=s0[i-1]+v0[i];
	for (ll i=1;i<n1;++i) s1[i]=s1[i-1]+v1[i];
	for (ll i=1;i<n2;++i) s2[i]=s2[i-1]+v2[i];
	for (ll i=1;i<n3;++i) s3[i]=s3[i-1]+v3[i];
	rep(i0,n0) rep(i1,n1) rep(i2,n2) rep(i3,n3){
		if (w1*(i0+i1+i2+i3)+i1+i2*2+i3*3>w) break;
		ans=max(ans,s0[i0]+s1[i1]+s2[i2]+s3[i3]);
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
char mat[1001][1001]; ll dp[1001][1001];
int h,w; 
int main() {
    int i,j,sum;
	cin>>h>>w;
	for(i=1;i<=h;i++){
	    for(j=1;j<=w;j++){
	        cin>>mat[i][j];
	    }
	}
	dp[0][1]=1;
	for(i=1;i<=h;i++){
	    for(j=1;j<=w;j++){
	        if(mat[i][j]=='.')
	            dp[i][j]=(dp[i][j-1]+dp[i-1][j])%1000000007;
	    }
	}
	cout<<dp[h][w];
}


Measured memory_bytes: 9088
#include <bits/stdc++.h>
#define err(args...) {}
#ifdef DEBUG
#include "_debug.cpp"
#endif
using namespace std;
using ll = long long;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int m;
    cin >> m;
    cout << 2 * 24 - m << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/


int main(){
    int a, b, c; cin >> a >> b >> c;

    bool flg = false;
    for(int k=1; k<=b; k++) if(k*a%b == c) flg = true;

    if(flg) cout << "YES" << endl;
    else cout << "NO" << endl;
}

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

using namespace std;
using ll = long long;

const string MINUSINF = "-";

ll match[10] = {2, 5, 5, 4, 5, 6, 3, 7, 6};
string dp[10010];

void chmax(string &a, string b) {
  if (a == MINUSINF)
    a = b;
  else if (a.size() < b.size())
    a = b;
  else if (a.size() == b.size()) {
    if (a < b)
      a = b;
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, M;
  cin >> N >> M;
  vector<int> A(M);
  for (int i = 0; i < M; i++)
    cin >> A[i];
  for (int i = 0; i < 10010; i++)
    dp[i] = MINUSINF;

  dp[0] = "";
  for (int i = 0; i <= N; i++) {
    if (dp[i] == MINUSINF)
      continue;
    for (auto a : A)
      chmax(dp[i + match[a - 1]], dp[i] + char('0' + a));
  }
  cout << dp[N] << endl;
}


Measured memory_bytes: 43776
#include <bits/stdc++.h>
using namespace std;
typedef   long long ll;
typedef   unsigned long long ull ;
typedef   double dll ;
#define   mp make_pair
#define   pb push_back
#define   ff first 
#define   ss second
#define   IOS ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define   endl "\n" 
#define   pll pair<ll, ll>
#define   all(x) x.begin(), x.end()
#define   vll vector<ll> 

int main()
{
    IOS
    ll n;
    cin>>n;
    ll x=1000;
    if(n<=1000) cout<<1000-n<<endl;
    else
    {
        while(x<n)
        {
            x=x+1000;
        }
        cout<<x-n<<endl;
    }
    return 0;
}

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

using namespace std;

typedef long long ll;

const int N = 1000010;

ll gcd(ll a , ll b){
	return !b ? a: gcd(b,a%b);
}

int n;
ll A[N],B[N];
ll res = 0;
int main() {
	//freopen("input.txt","r",stdin);
	scanf("%d",&n);
	for (int i = 1; i <= n; ++i){
		scanf("%lld%lld",&A[i],&B[i]);
	}
	for (int i = n ; i >= 1; --i){
		A[i] += res;
		if(A[i]%B[i] == 0)
			continue;
		ll nxt = (A[i]+B[i])/B[i] * B[i];
		res += nxt  - A[i];
	}
	printf("%lld\n", res);
	return 0;
} 

Measured memory_bytes: 1920
#include <iostream>
#include <string>

using namespace std;

string s, t;
int n, m;

int main()
{
	cin >> s;
	cin >> t;
	char ch;

	n = s.length();
	m = t.length();

	for (int i = 0; i < n; ++i)
		for (int j = i + 1; j < n; ++j)
			if (s[i] > s[j])
			{
				ch = s[i];
				s[i] = s[j];
				s[j] = ch;
			}

	for (int i = 0; i < m; ++i)
		for (int j = i + 1; j < m; ++j)
			if (t[i] < t[j])
			{
				ch = t[i];
				t[i] = t[j];
				t[j] = ch;
			}

	if (s < t)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
import java.text.DecimalFormat;
import java.util.stream.LongStream;
import java.util.stream.IntStream;
import java.io.*;
import java.util.*;

public class Main {

    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);

        AtCoder problem = new AtCoder(sc);
        problem.solve(out);

        out.flush();
    }

}

class AtCoder {

    double T, X;

    AtCoder(FastScanner sc) {
        T = sc.nextDouble();
        X = sc.nextDouble();
    }

    void solve(PrintWriter out) {
        out.println(T / X);
    }

}

// https://qiita.com/p_shiki37/items/a0f6aac33bf60f5f65e4
class FastScanner {

    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        if (hasNextByte()) {
            return buffer[ptr++];
        } else {
            return -1;
        }
    }

    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
            ptr++;
        }
        return hasNextByte();
    }

    public String next() {
        if (!hasNext()) {
            throw new NoSuchElementException();
        }
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext()) {
            throw new NoSuchElementException();
        }
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) {
            throw new NumberFormatException();
        }
        return (int) nl;
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}


Measured memory_bytes: 21460
N, M = map(int, input().split(' '))
A_n = list(map(int, input().split(' ')))
count = 0
total = sum(A_n)
A_sort = sorted(A_n, reverse=True)
for a in A_sort:
    # print(a/total)
    if a/total >= 1/4/M:
        count += 1
    else:
        break
if count >= M:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 9136
n,m = map(int, input().split())
sub_list = [list(input().split()) for _ in range(m)]

penalty_list = [0]*n #問題ごとのACが出るまでのペナルティ数
result_list = [0]*n #問題ごとの最終的にACが出たかどうかのリスト

for i in range(m):
  if sub_list[i][1] =='AC':
    result_list[int(sub_list[i][0]) -1] = 1
  else:
    if result_list[int(sub_list[i][0]) -1] == 0:
      penalty_list[int(sub_list[i][0]) -1] += 1

ac_count = 0
wa_count = 0
for i in range(n):
  if result_list[i] == 1:
    ac_count += 1
    wa_count += penalty_list[i]

print(f'{ac_count} {wa_count}')


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

using namespace std;

namespace abreto {

typedef vector<int> vi;
typedef pair<int,int> pii;
#define fi first
#define se second
#define pb push_back

typedef long long int ll;

const int maxn = 1 << 10;

int X, Y, Z, K;
ll A[maxn], B[maxn], C[maxn];

struct state
{
    int ia, ib, ic; /* reversed, indexed from 0 */
    ll sum;
    state() : ia(0), ib(0), ic(0) { }
    state(int a, int b, int c) : ia(a), ib(b), ic(c)
    {
        if (ia >= X) return;
        if (ib >= Y) return;
        if (ic >= Z) return;
        assert(ia < X); assert(ib < Y); assert(ic < Z);
        sum = A[ia] + B[ib] + C[ic];
    }
    bool operator<(const state &os) const { return sum < os.sum; }
};

map<ll, bool> vis;

void push(priority_queue<state> &q, state s)
{
    if (s.ia >= X) return;
    if (s.ib >= Y) return;
    if (s.ic >= Z) return;
    ll hash = (s.ia - 1) * (int) 1e6 + (s.ib - 1) * (int) 1e3 + (s.ic - 1);
    if (vis.find(hash) != vis.end()) return;
    q.push(s);
    vis[hash] = true;
}

void main(void)
{
    cin >> X >> Y >> Z >> K;
    for (int i = 0; i < X; i++) cin >> A[i]; sort(A, A + X, greater<ll>());
    for (int i = 0; i < Y; i++) cin >> B[i]; sort(B, B + Y, greater<ll>());
    for (int i = 0; i < Z; i++) cin >> C[i]; sort(C, C + Z, greater<ll>());
    priority_queue<state> q;
    q.push(state(0, 0, 0));
    while (K--)
    {
        assert( !q.empty() );
        state u = q.top(); q.pop();
        cout << u.sum << '\n';
        push(q, state(u.ia + 1, u.ib, u.ic));
        push(q, state(u.ia, u.ib + 1, u.ic));
        push(q, state(u.ia, u.ib, u.ic + 1));
    }
}

}

int main(void)
{
    cin.sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    abreto::main();
    return 0;
}


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

using namespace std;

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

    vector<int> H;
    for(int i=0; i<N; i++){
        int t;
        cin >> t;
        H.push_back(t);
    }

    int cnt = 0;
    int max = 0;
    for(int i=0; i<N-1; i++){
        if(H[i] >= H[i+1]) cnt++;
        else{
            max = std::max(max, cnt);
            cnt = 0;
        }
        if(i == N-2) max = std::max(max, cnt);
    }

    cout << max;

    return 0;

}

Measured memory_bytes: 892
from functools import reduce
import operator
MOD = 10**9+7
mprod = lambda it: reduce(lambda x,y: (x*y)%MOD,it,1)
nprod = lambda it: reduce(lambda x,y: (x*y),it,1)


from fractions import Fraction

def solve(A,K):
    N = len(A)
    if N == K:
        return mprod(A)

    if all(v <= 0 for v in A) and K%2 == 1:
        A.sort()
        return mprod(A[-K:])

    A.sort(key=lambda x: abs(x))

    if A[-K] == 0:
        return 0

    parity = sum(v < 0 for v in A[-K:])%2
    if parity == 0:
        return mprod(A[-K:])

    rp = N-K
    while rp < N and A[rp] < 0:
        rp += 1

    rn = N-K
    while rn < N and A[rn] > 0:
        rn += 1


    lp = N-K-1
    while lp >= 0 and A[lp] < 0:
        lp -= 1

    ln = N-K-1
    while ln >= 0 and A[ln] > 0:
        ln -= 1

    if rp < N and ln >= 0:
        r1 = Fraction(-A[ln],A[rp])
    else:
        r1 = 0
    if rn < N and lp >= 0:
        r2 = Fraction(-A[lp],A[rn])
    else:
        r2 = 0
    if r1 > r2:
        return (mprod(A[-K:])*A[ln]*pow(A[rp],-1,MOD))%MOD
    else:
        return (mprod(A[-K:])*A[lp]*pow(A[rn],-1,MOD))%MOD

from itertools import combinations
def naive(A,K):
    return max(nprod(p) for p in combinations(A,K))%MOD


if __name__ == '__main__':
    N,K = map(int,input().split())
    A = list(map(int,input().split()))
    
    print(solve(A,K)%MOD)

    # from random import randrange

    # N = 9
    # K = 8
    # for _ in range(100000):
    #     A = [randrange(-8,8) for _ in range(N)]
    #     if solve(A.copy(),K) != naive(A.copy(), K):
    #         print(A, solve(A.copy(),K),naive(A.copy(), K) )

Measured memory_bytes: 33112
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main(){
  ll h, w, n, x, y;
  in3(h, w, n);
  ll a = 0;
  vector<ll> c(n);
  rep(i, n)
    in(c[i]);
  vector<vector<ll>> d(h, vector<ll> (w));
  x = y = 0;
  rep(i, n){
    rep(j, c[i]){
      d[y][x] = i + 1;
      if(a == 0 && x == w - 1){
        y++;
        a++;
      }
      else if(a == 1 && x == 0){
        y++;
        a--;
      }
      else if(a == 0)
        x++;
      else
        x--;
    }
  }
  rep(i, h){
    rep(j, w){
      out(d[i][j]);
      hina;
    }
    memi;
  }
}


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

#define rep(i,n) for(int i = 0; i < n; i++)
#define REP(i,n) for(int i = 1; i < n; i++)
#define repll(i,n) for(ll i = 0; i < n; i++)
#define REPll(i,n) for(ll i = 1; i < n; i++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define yesorno(a) printf(a ? "yes\n" : "no\n")
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define YESorNO(a) printf(a ? "YES\n" : "NO\n") 
#define endl "\n"
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll a, const ll b){return ((a)+(b)-1)/b;}


signed main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int n, u, v;
  cin >> n >> u >> v;
  u--; v--;
  vii tree(n);
  rep(i,n-1){
    int a, b;
    cin >> a >> b;
    a--; b--;
    tree[b].push_back(a);
    tree[a].push_back(b);
  }
  vi dt(n,-1), da(n, -1);
  dt[u] = 0; da[v] = 0;
  queue<int> qt, qa;
  qt.push(u); qa.push(v);
  while(!qt.empty()){
    int now = qt.front(); qt.pop();
    for(int &next : tree[now]){
      if(dt[next] != -1) continue;
      qt.push(next);
      dt[next] = dt[now] + 1;
    }
  }
  while(!qa.empty()){
    int now = qa.front(); qa.pop();
    for(int &next : tree[now]){
      if(da[next] != -1) continue;
      qa.push(next);
      da[next] = da[now] + 1;
    }
  }
  int ans = -inf;
  rep(i,n){
    if(da[i] <= dt[i]) continue;
    ans = max(da[i], ans);
  }
  ans--;
  cout << ans << endl;
}

Measured memory_bytes: 6656
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define ll long long
#define imfor(i, n) for(int i = 0; i < n; i++)
using namespace std;
ll MOD = 1000000007;

int main() {
    int n;
    cin >> n;
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        if (1 <= i && i <= 9) {
            ans++;
        }
        else if (100 <= i && i <= 999) {
            ans++;
        }
        else if (10000 <= i && i <= 99999) {
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, begin, end) for (int i = begin; i < (int)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main()
{
    int H, W, h, w;
    cin >> H >> W >> h >> w;
    int ans = H * W - h * W - (H - h) * w;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include"math.h"
#include <cstdio> 
#include <iostream>
#include<vector>
#include<queue>
#include<algorithm>
#include<string.h>
#include <sstream>  
#include <string>
//continue 只管for、while，不看if，不管多少if都直接无视,continue 表示终止本次（本轮）循环。当代码执行到continue时，本轮循环终止，进入下一轮循环，具有过滤功能。
using namespace std;
const int N = 8;
int row[N] = {0};
int col[N] = {0};
int dpos[2 * N - 1] = {0};
int dneg[2 * N - 1] = {0};
int X[N][N] = {0};
int num;
void printBoard(){
	for(int i = 0;i < N;i++){
		for(int j = 0;j < N;j++){
			if(X[i][j] && row[i] != j) return;
		}
	}
	for(int i = 0;i < N;i++){
		for(int j = 0;j < N;j++){
			if(row[i] == j) cout << 'Q';
			else cout << '.';
		}
		cout << endl;
	}
}
void recursive(int i){
	if(i == N){
		printBoard();
		return;
	}
	for(int j = 0;j < N;j++){
		if(col[j] || dpos[i + j] || dneg[i - j + (N - 1)]) continue;
		row[i] = j;
		col[j] = 1;
		dpos[i + j] = 1;
		dneg[i - j + (N - 1)] = 1;
		recursive(i + 1);
		row[i] = col[j] = dpos[i + j] = dneg[i - j + (N - 1)] = 0;
	}
}
int main(){
	int x,y;
	cin >> num;
	getchar();
	for(int i = 1;i<=num;i++){
		cin >> x >> y;
		getchar();
		X[x][y] = 1;
	}
	recursive(0);
}



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

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

    ll n,k,a,b;

    // while(cin>>n>>k){
        cin>>n>>k;
        ll v[100010];
        int l=-1;
        for(int i=1;i<=100005;i++) v[i]=0;
        
        for(int i=0;i<n;i++){
            cin>>a>>b;
            v[a] += b;
            if(l<=a)l=a;
        }

        ll count = 0;
        int ans;
        for(int i=1;i<=l;i++){
            count += v[i];
            if(count >= k){
                ans = i;
                break;
            }
        }
        cout<<ans<<endl;
    // }

    return 0;
 
}

Measured memory_bytes: 1024
"""
言い換えると次のことをすればよい
初期値をl = [], s = 0 として
'1 a b': lにaを追加、sにbを足す
'2': 中央値のインデックスより大きい要素の和-～～より小さい要素の和+sを出力
(要素が仮に昇順にソートされているなら、要素数をkとして、
sum(l[(k+1)//2:]) - sum(l[:k//2]) + s　を出力、xとしてはl[(k-1)//2]を出力
"""
import heapq

less = []
greater = []
s = 0
sum_ = 0
q = int(input())
def query(n):
  global s, sum_
  if n[0] == "1":
    c, a, b = map(int, n.split())
    s += b
    if len(less) == len(greater):
      if not greater or a <= greater[0]:
        heapq.heappush(less, -a)
        sum_ -= a
      else:
        r = heapq.heappushpop(greater, a)
        heapq.heappush(less, -r)
        sum_ += a - 2*r
    else:
      if a >= -less[0]:
        heapq.heappush(greater, a)
        sum_ += a
      else:
        r = -heapq.heappushpop(less, -a)
        heapq.heappush(greater, r)
        sum_ += 2*r - a
  else:
    res = sum_
    if len(less) > len(greater):
      res -= less[0]
    res += s
    print(-less[0], res)
    
for _ in range(q):
  k = input()
  query(k)

Measured memory_bytes: 11128
const MOD = 10^9+7

function solve()
    N = parse(Int,readline())
    A = parse.(Int,split(readline()))
    ans = 0
    for i in 0:60
        cnt1 = 0
        for j in 1:N
            (A[j]>>i&1==1) && (cnt1+=1)
        end
        ans += mod((N-cnt1)cnt1,MOD) * mod(2^i,MOD)
        ans %= MOD
    end
    println(ans)
end
solve()

Measured memory_bytes: 203072
#include <bits/stdc++.h>
#define vi vector<int>
#define ll long long int
#define vll vector<long long int>
#define vpi vector<pair<ll,ll>>
#define all(x) (x).begin(), (x).end()
#define rep(i,a,b) for(int i=a ; i<b ; ++i)
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;

int main() {
    IOS;
    int l,r,d; cin >> l>>r>>d;
    int cnt = 0;
    for(int i=l;i<=r;++i) if(i%d==0) cnt++;
    cout << cnt;
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h> 
using namespace std; 
int main(){ 
    int N, M, C;
    cin >> N >> M >> C;
    vector<int> B(M), A(M);
    int ans = 0, cnt = 0;
    
    for ( int i = 0; i < M; i++) cin >> B.at(i);
    for ( int i = 0; i < N; i++) {
        for ( int j = 0;  j < M; j++) {
        cin >> A.at(j);
        cnt += A.at(j) * B.at(j);
            }
        cnt += C;
        if(cnt > 0) ans++;
        cnt = 0;
        }
		cout << ans <<endl;	
		}

Measured memory_bytes: 256
//
//  main.cpp
//  CPP
//
//  Created by chemistrae on 02/12/2018.
//  Copyright © 2018 chemistrae. All rights reserved.
//

#include <iostream>
#include <algorithm>

using namespace std;

int n, h, w;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    
    
    cin >> n >> h >> w;
    
    int ret = 0;
    
    for (int i=0; i<n; i++) {
        int a, b;
        cin >> a >> b;
        //cout << a/h << ' ' << b/w << '\n';
        //cout << min(h/a, w/b) << '\n';
        ret += min(a/h, b/w);
    }
    
    cout << ret << '\n';
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//関数
const long INF=1000000000000;

//main関数
int main() {
    //入力
    string S;
    cin>>S;
    
    //計算
    long N=S.size();
    
    bool waitingForC =false;
    long a=0,bc=0,ans=0;
    for(int i=0;i<N;i++){
        if(waitingForC){
            if(S.at(i)=='C'){
                bc++;
                ans+=a;
                waitingForC=false;
            }else if(S.at(i)=='B'){
                a=0;
                bc=0;
                waitingForC=true;
            }else{
                a=1;
                bc=0;
                waitingForC=false;
            }
        }else{
            if(S.at(i)=='C'){
                a=0;
                bc=0;
                waitingForC=false;
            }else if(S.at(i)=='B'){
                waitingForC=true;
            }else{
                a++;
                waitingForC=false;
            }
            
        }
        
       // cout<<" a "<<a<<"  bc "<<bc<<"  ans "<<ans<<"  waithngForC "<<waitingForC<<endl;
    }
    
    
    
    //出力
    cout<<ans<<endl;
}

Measured memory_bytes: 640
#include<iostream>

using namespace std;

int main() {
	
	double weight;
	
	while( cin >> weight ) {
	
	if(weight <= 48.00)
		cout << "light fly\n";
	
	else if (weight <= 51.00)
		cout << "fly\n";
	
	else if (weight <= 54.00)
		cout << "bantam\n";
		
	else if (weight <= 57.00)
		cout << "feather\n";
		
	else if (weight <= 60.00)
		cout << "light\n";
		
	else if (weight <= 64.00)
		cout << "light welter\n";
		
	else if (weight <= 69.00)
		cout << "welter\n";
		
	else if (weight <= 75.00)
		cout << "light middle\n";
		
	else if (weight <= 81.00)
		cout << "middle\n";
		
	else if (weight <= 91.00)
		cout << "light heavy\n";
		
	else
		cout << "heavy\n";
		
	}
	return 0;
}



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

#define ll long long

int const MOD = 1e9 + 7;

int n, m;
char grid[1001][1001];
ll dp[1001][1001];

ll pound(int x, int y)
{
    if (dp[y][x] != -1)
        return dp[y][x];
        
    ll a = 0;
    if (x < m)
        if (grid[y][x + 1] != '#')
            a = pound(x + 1, y);
            
    ll b = 0;
    if (y < n)
        if (grid[y + 1][x] != '#')
            b = pound(x, y + 1);
            
    return dp[y][x] = (a % MOD + b % MOD) % MOD;
}

int main()
{
    cin >> n >> m;
    
    for (int i = 0; i < n; ++i)
    {
        for (int j = 0; j < m; ++j)
        {
            cin >> grid[i][j];
            dp[i][j] = -1;
        }
    }
            
    dp[n - 1][m - 1] = 1;
            
    cout << pound(0, 0);
    
    return 0;
}


Measured memory_bytes: 9088
/******************************************
* NICK : nikhilsinghh59 *
******************************************/
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define watch(x) cout << (#x) << " is " << (x) << endl
#define endl "\n"

#define PB push_back
#define F first
#define S second
#define all(c) (c).begin(),(c).end()
const int M = 1e9+7;

ll calc(ll a , ll b) {
	if(b==0) return 1;

	if(b%2==0) {
		return calc((a*a)%M , b/2);
	}
	else {
		return (a*calc((a*a)%M , b/2))%M;
	}
}

int main()
{   
    //#ifndef ONLINE_JUDGE
    // for getting input from input.txt
    //freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    //freopen("output.txt", "w", stdout);
    //#endif

    ll n , a  , b;
    cin >> n >> a >> b;

    ll val = (calc(2 , n) - 1 + M)%M;

    // calc a! and b!
    ll ar[200005];
    ar[0]=1;
    for(ll i=1 ; i<=200001; i++) {
    	ar[i] = (ar[i-1]*i)%M;
    }

    // n-r+1
    ll v1 = 1;
    for(ll i=n; i>=n-a+1 ; i--) {
    	v1 = (v1*i)%M;
    }
    ll v2=1;
    for(ll i=n ; i>=n-b+1; i--) {
    	v2 = (v2*i)%M;
    }

    ll va = (v1*calc(ar[a] , M-2))%M;
    ll vb = (v2 * calc(ar[b] , M-2))%M;

    ll ans = (val - va +M)%M;
    ans = (ans - vb + M)%M;

    cout << ans;
}

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

using namespace std;

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

int n;
set < int > s;

int gcd(int x, int y) {
	return !y ? x : gcd(y, x % y);
}

int main() {

	scanf("%d", &n);

	int sum = 0;

	for(int i = 2; i <= 30000 and s.size() + 1 < n; i++) {
		if(i % 2 == 0 or i % 3 == 0) {
			s.insert(i);
			sum += i;
		}
	}

	assert(s.size() == n - 1);

	for(int i = 2; i <= 30000; i++) {
		if(!s.count(i) and (sum + i) % 2 == 0 and (sum + i) % 3 == 0 and gcd(sum, i) != 1) {
			s.insert(i);
			break;
		}
	}

	assert(s.size() == n);

	for(auto x : s)
		printf("%d ", x);

	puts("");

    return 0;

}



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

public class Main {

	@SuppressWarnings("resource")
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int a[] = new int[n];

		for (int i = 0; i < n; i++) {
			a[i] = scanner.nextInt();
		}
		Arrays.sort(a);

		int al = 0;
		int bo = 0;
		for (int i = a.length - 1; i >= 0; i--) {
			if ((a.length - 1) % 2 == i % 2)
				al += a[i];
			else
				bo += a[i];
		}

		System.out.println(al - bo);

	}
}


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


int main () {

    int n; cin >> n;
    string s;
    map<string, int> mp; 

     mp["AC"] = 0;
     mp["WA"] = 0;
     mp["TLE"] = 0;
     mp["RE"] = 0;
    for(int i = 0; i < n; i++) {
        cin >> s;
        mp[s]++;
    }

    cout <<  "AC x " << mp["AC"] << endl 
         <<  "WA x " << mp["WA"] << endl 
         <<  "TLE x " <<mp["TLE"]<< endl
         <<  "RE x " << mp["RE"] << endl;
    return 0;
}

Measured memory_bytes: 3632
(eval-when (:compile-toplevel :load-toplevel :execute)
  (defparameter OPT
    #+swank '(optimize (speed 3) (safety 2))
    #-swank '(optimize (speed 3) (safety 0) (debug 0)))
  #+swank (progn (ql:quickload '(:cl-debug-print))))
#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)

(deftype int32 () '(signed-byte 32))
(deftype int64 () '(signed-byte 64))
(deftype int5 () '(unsigned-byte 5))

;;macros
(defmacro println (n)
  `(format t "~a~%" ,n))
(defmacro vint-out (vec)
  `(progn
     (rep i (length ,vec)
          (princ (vref ,vec i))
          (princ " "))
     (fresh-line)))

(defmacro aif (test-form then-form &optional else-form)
  `(let ((it ,test-form))
     (if it ,then-form ,else-form)))

;;vector
(defmacro vec (type &optional (num 100) (val 0))
  (let* ((g (gensym)))
    `(let* ((,g ,num))
       (make-array ,g :element-type ',type :initial-element ,val
                   :adjustable nil :fill-pointer ,g))))

(defmacro double-vec (type &optional (dim1 100) (dim2 100) (val 0))
  `(make-array '(,dim1 ,dim2) :element-type ',type :initial-element ,val))

(defmacro vint (&optional (num 0) (val 0))
  `(vec int32 ,num ,val))

(defmacro double-vec (type &optional (dim1 100) (dim2 100) (val 0))
  `(make-array '(,dim1 ,dim2) :element-type ',type :initial-element ,val))

(defmacro vref (vector pos &optional value)
  (let ((g (gensym)))
    `(let ((,g ,value))
       (if ,g
           (setf (aref ,vector ,pos) ,g)
           (aref ,vector ,pos)))))

(defmacro chvar (sym comp predicate)
  (let ((g (gensym)))
    `(let ((,g ,comp))
       (if (or (null ,sym) (not (funcall ,predicate ,sym ,g)))
           (setf ,sym ,g)))))

(defmacro chmax (sym comp &optional (predicate #'>))
  `(chvar ,sym ,comp ,predicate))

(defmacro chmin (sym comp &optional (predicate #'<))
  `(chvar ,sym ,comp ,predicate))

(defmacro defchangef (name op default-val)
  `(defmacro ,name (var &optional (val ,default-val))
     `(setq ,var (,',op ,val ,var))))
(defmacro read-str ()
  `(write-to-string (read)))

;;本体
(defvar n (read))
(defvar m (read))


(defun main()
  (println
   (aif (reduce #'intersection
                (loop for i below n
                   collect (loop for j below (read)
                              collect (read))))
        (length it)
        0)))

#-swank(main)


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

int main() {
  int A,B,C,D,N;
  string S;
  cin >> N >> A >> B >> C >> D;
  cin >> S;
  int ng = 0;
  int wall = 0;
  int r = 0;
  int ov = 0;
  if (D>C) {
    for (int i=A-1;i<C;++i ) {
	  if (S[i] == '#') {
    	  if (wall == 1) {
            ng = 1;
            break;
          }
          wall = 1;
      } else {
        wall = 0;
      }
    }
    wall = 0;
    if (ng==0) {
      for (int i=B-1;i<D;++i ) {
	    if (S[i] == '#') {
    	  if (wall == 1) {
            ng = 1;
            break;
          }
          wall = 1;
        } else {
          wall = 0;
        }
      }
    }
  } else {
    ov = 1;
    int dd = D+1;
    if (D==N) {
      dd = D;
    }
    for (int i=B-2;i<dd;++i ) {
	  if (S[i] == '#') {
        if (ov!=2) ov = 0;
        r = 0;
        if (wall == 1) {
          ng = 1;
          break;
        }
        wall = 1;
      } else {
        ++r;
        if (r>2) ov = 2;
        wall = 0;
      }
    }
    if (ov==0) {
      ng = 1;
    }
    if (ng==0) {
      for (int i=A-1;i<C;++i ) {
	    if (S[i] == '#') {
    	  if (wall == 1) {
            ng = 1;
            break;
          }
          wall = 1;
        } else {
          wall = 0;
        }
      }
    }
  }
  if (ng==0) {
	  cout << "Yes" << endl;
  } else {
	  cout << "No" << endl;
  }
    
  return 0;
}
  

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvec;
typedef vector<vector<bool>> vveb;
typedef vector<vector<string>> vves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pb push_back
#define pp pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
//const int64 INF = 1LL << 58;
#define dame { puts("-1"); return 0;}
#define YES { cout << "YES" << endl; return 0; }
#define NO { cout << "NO" << endl; return 0; }
#define Yes { cout << "Yes" << endl; return 0; }
#define No { cout << "No" << endl; return 0; }
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};


int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
    ll l, r;
    cin >> l >> r;
    ll kosuu = r-l+1;
    if(kosuu>2018){cout << 0 << endl; return 0;}
    else{
        vi a(kosuu);
        rep(i,kosuu){
            a[i] = (l+i)%2019;
        }
        int mn = 2020;
        rep(i,a.size()-1){
            repk(j,i+1,a.size()){
                mn = min(mn,(a[i]*a[j])%2019);
            }
        }
        cout << mn <<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
int main() {
	int n;
	std::cin >> n;
	std::vector<std::string>v;
	for (int i = 0;i < n;++i) {
		int a, b, c;
		std::cin >> a >> b >> c;
		int max = std::max(a, std::max(b, c));
		if (a*a + b*b + c*c == max*max * 2) {
			v.push_back("YES");
		}
		else {
			v.push_back("NO");
		}
	}
	for (int i = 0;n > i;++i) {
		std::cout << v[i] << std::endl;
	}
	return 0;
}

Measured memory_bytes: 1252
import java.util.Scanner;

public class Main {
	public void change() {

	}
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n[] = new int[3];
        n[0] = sc.nextInt();
        n[1] = sc.nextInt();
        n[2] = sc.nextInt();
        int change = 0;
       if(n[0] > n[1]) {
    	   change = n[0];
    	   n[0] = n[1];
    	   n[1] = change;
       }
       if(n[1] > n[2]) {
    	   change = n[1];
    	   n[1] = n[2];
    	   n[2] = change;
       }
       if(n[0] > n[1]) {
    	   change = n[0];
    	   n[0] = n[1];
    	   n[1] = change;
       }
       System.out.printf("%d %d %d\n", n[0], n[1], n[2]);
    }
}


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

using namespace std;
using ll = long long int;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define rep(i, N) for (ll i = 0; i < (N); i++)
#define FOR(i, a, b) for (ll i = (a), i < (N): i++)
#define all(A) (A).begin(), (A).end()

int main(){
    int N;
    cin >> N;
    int A[N];
    int B[N];
    rep(i, N) cin >> A[i];
    rep(i, N) cin >> B[i];

    rep(i, N - 1) A[i + 1] += A[i];
    for (int i = N - 1; i > 0; i--) {
        B[i - 1] += B[i];
    }
    int ans = 0;
    rep(i, N) ans= max(ans, A[i] + B[i]);
    
    cout << ans << endl;

    return 0;
}


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

int main() {
  char in;
  cin >> in;
  if (isupper(in)) {
    cout << 'A' << endl;
  } else {
    { cout << 'a' << endl; }
  }
  return 0;
}

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

using _i64 = int64_t;
using _u64 = uint64_t;
using _f64 = double;

#define endl "\n"

#define _for(i, start, end) for(_i64 i = (_i64)start; i < (_i64)end; ++i)
#define _rep(i, number) _for(i, 0, number)
#define _foreach(e, data) for(auto& e : data)
#define _all(data) data.begin(), data.end()

template<typename type>
_i64 _size(const type& data) { return static_cast<_i64>(data.size()); }
template<typename type, size_t size>
_i64 _size(const type (&)[size]) { return static_cast<_i64>(size); }

enum _flag : bool { able = true, disable = false };

struct _time {
    _time(_flag flag) { check = flag; if(!check) { return; } gettime(start); }
    ~_time() {
        if(!check) { return; }; gettime(end);
        _i64 elapse = chrono::duration_cast<chrono::milliseconds>(end - start).count();
        cout << endl << "Time: " << elapse << " ms" << endl;
    }
    private:
    using _timer = chrono::time_point<chrono::system_clock>;
    _timer start, end; bool check;
    void gettime(_timer& time) { time = chrono::system_clock::now(); }
};

struct _ini { _ini() { ios::sync_with_stdio(false); cin.tie(nullptr); } } _ini;

int main() {
    {
        _time time(disable);
        stack<_i64> vehicle; _i64 quere;
        while(cin >> quere) {
            if(quere == 0) { cout << vehicle.top() << endl; vehicle.pop(); }
            else { vehicle.push(quere); }
        }
    }
    return 0;
}


Measured memory_bytes: 3188
//============================================================================
// Name        : atcoder.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
using namespace std;
string str;
long long A[26];
int main(){
	cin>>str;
char B[26];
	B[0]='a';B[1]='b';B[2]='c';B[3]='d';B[4]='e';B[5]='f';B[6]='g';B[7]='h';B[8]='i';B[9]='j';B[10]='k';B[11]='l';B[12]='m';
	B[13]='n';B[14]='o';B[15]='p';B[16]='q';B[17]='r';B[18]='s';B[19]='t';B[20]='u';B[21]='v';B[22]='w';B[23]='x';B[24]='y';B[25]='z';
	for(int i=0;i<str.size();i++){
		if(str[i]=='a')A[0]+=1;
		if(str[i]=='b')A[1]+=1;
		if(str[i]=='c')A[2]+=1;
		if(str[i]=='d')A[3]+=1;
		if(str[i]=='e')A[4]+=1;
		if(str[i]=='f')A[5]+=1;
		if(str[i]=='g')A[6]+=1;
		if(str[i]=='h')A[7]+=1;
		if(str[i]=='i')A[8]+=1;
		if(str[i]=='j')A[9]+=1;
		if(str[i]=='k')A[10]+=1;
		if(str[i]=='l')A[11]+=1;
		if(str[i]=='m')A[12]+=1;
		if(str[i]=='n')A[13]+=1;
		if(str[i]=='o')A[14]+=1;
		if(str[i]=='p')A[15]+=1;
		if(str[i]=='q')A[16]+=1;
		if(str[i]=='r')A[17]+=1;
		if(str[i]=='s')A[18]+=1;
		if(str[i]=='t')A[19]+=1;
		if(str[i]=='u')A[20]+=1;
		if(str[i]=='v')A[21]+=1;
		if(str[i]=='w')A[22]+=1;
		if(str[i]=='x')A[23]+=1;
		if(str[i]=='y')A[24]+=1;
		if(str[i]=='z')A[25]+=1;
	}
	int S=0;
	for(int i=0;i<25;i++){
		if(A[i]==0){
			if(S==0){
				cout<<B[i]<<endl;
			}S+=1;
		}
	}

	if(A[25]>0 && S==0){
		cout<<"None"<<endl;
	}else if(A[25]==0 && S==0){
		cout<<B[25]<<endl;
	}


	return 0;
}



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

int main(){
    string s;
    cin>>s;
    int year,month,day;
    year=stoi(s.substr(0,4));
    month=stoi(s.substr(5,2));
    day=stoi(s.substr(8,2));

    int HeiseiFlag=1;

    if(year>=2020){
        HeiseiFlag=0;
    }else if(year==2019&&month>=5){
        HeiseiFlag=0;
    }

    if(HeiseiFlag==1){
        cout<<"Heisei"<<endl;
    }else{
        cout<<"TBD"<<endl;
    }
    return(0);
}

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

typedef struct {
	char goku[32];
	int page;
} goku_t;

int qsort_comp(const void* x,const void* y) {
	const goku_t* a=(const goku_t*)x;
	const goku_t* b=(const goku_t*)y;
	int strcmp_result;
	strcmp_result=strcmp(a->goku,b->goku);
	if(strcmp_result)return strcmp_result;
	if((a->page)>(b->page))return 1;
	if((a->page)<(b->page))return -1;
	return 0;
}

int goku_num;
goku_t gokulist[100];

int main(void) {
	int i;
	for(goku_num=0;
		scanf("%s%d",
			gokulist[goku_num].goku,&gokulist[goku_num].page)==2;
		goku_num++);
	if(goku_num<=0)return 0;
	qsort(gokulist,goku_num,sizeof(goku_t),qsort_comp);
	printf("%s\n%d",gokulist[0].goku,gokulist[0].page);
	for(i=1;i<goku_num;i++) {
		if(strcmp(gokulist[i-1].goku,gokulist[i].goku)==0) {
			printf(" %d",gokulist[i].page);
		} else {
			printf("\n%s\n%d",gokulist[i].goku,gokulist[i].page);
		}
	}
	putchar('\n');
	return 0;
}

Measured memory_bytes: 0
from collections import defaultdict
n=int(input())
a=list(map(int,input().split()))
a.sort()
m=max(a)
x=[1 for i in range(m+1)]
for p in a:
    if m//p:
        for k in range(2,m//p+1):
            x[p*k]=-1

ans=0
dic=defaultdict(int)
for i in a:
    dic[i]+=1

for p in a:
    if x[p]==1 and dic[p]==1: ans+=1
print(ans)

Measured memory_bytes: 168388
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <map>
#include <numeric>
#include <random>
#include <queue>
#include <deque>
#include <tuple>
#include <iomanip>

using namespace std;

typedef long long ll;

const ll MOD = 1000000007;
const ll MAX = 300000;

ll fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++){
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

// 二項係数計算
ll COM(ll n, ll k){
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll FAC(ll n){
  return fac[n];
}

ll modinv(ll a, ll m) {
  ll b = m, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    a -= t * b; swap(a, b);
    u -= t * v; swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}

ll RepeatSquaring(ll N, ll P, ll M){
  if(P==0) return 1;
  if(P%2==0){
    ll t = RepeatSquaring(N, P/2, M);
    return t*t % M;
  }
  return N * RepeatSquaring(N, P-1, M) % M;
}

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

  COMinit();

  ll N,A,B,C;
  cin>>N>>A>>B>>C;
  ll ABinv=modinv(A+B,MOD);
  ll ans=0ll;
  ll p1=A*ABinv%MOD;
  ll p2=B*ABinv%MOD;

  for(int i=0;i<N;i++){
    ans+=RepeatSquaring(p1,N,MOD)*RepeatSquaring(p2,i,MOD)%MOD*COM(N+i-1,N-1)%MOD*(N+i)%MOD;
    ans%=MOD;
    ans+=RepeatSquaring(p2,N,MOD)*RepeatSquaring(p1,i,MOD)%MOD*COM(N+i-1,N-1)%MOD*(N+i)%MOD;
    ans%=MOD;
  }
  cout<<ans*100%MOD*(modinv(100-C,MOD))%MOD<<endl;
}


Measured memory_bytes: 7296
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main(){
  string s;
  cin>>s;
  ll len = s.length();
  if(s[len - 1] == 's')
    cout<<(s+"es")<<endl;
  else
    cout<<(s+"s")<<endl;
}

Measured memory_bytes: 3600
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> 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; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    long double w, h, x, y;
    cin >> w >> h >> x >> y;
    long double ans = w * h / 2;
    cout << fixed << setprecision(12) << ans << " ";
    if(x*2 == w && y*2 == h) cout << "1" << endl;
    else cout << "0" << endl;
    return 0;
}


Measured memory_bytes: 3772
{-# LANGUAGE BangPatterns #-}
import Control.Applicative ((<$>))
import Data.Array (listArray, (!))
import Data.List (sort)

main :: IO ()
main = do
    [n,m] <- getInts
    cs <- getInts
    print $ solve n m $ sort cs

getInts :: IO [Int]
getInts = map read . words <$> getLine

solve :: Int -> Int -> [Int] -> Int
solve n m cs = table (n,m-1)
    where
        idx (!x,!y) = x + y*(n+1)
        xdi i = let x = i`mod`(n+1)
                    y = i`div`(n+1)
                 in x `seq` y `seq` (x,y)
        table = (listArray (0,idx (n,m-1)) (map (f.xdi) [0..idx (n,m-1)]) !) . idx
        f (!x,0) = x
        f (!x,!y) = if c > x then table (x,y-1)
                             else let res1 = table (x,y-1)
                                      res2 = table (x-c,y) + 1
                                   in res1 `seq` res2 `seq` min res1 res2
            where c = cs !! y

Measured memory_bytes: 123288