akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <climits>
#include <complex>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <vector>

// using
using namespace std;

// typedef
typedef long long ll;

// define
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define UNIQ(c) unique(ALL(c))
#define FOR(i, a, b, c) for (int i = (int)(a); i < (int)(b); i += (int)(c))
#define REP(i, n) FOR(i, 0, n, 1)
#define RFOR(i, a, b, c) for (int i = (int)(a); i >= (int)(b); i -= (int)(c))
#define RREP(i, n) RFOR(i, n, 0, 1)

// functions
int ceil(int a, int b) {
    return (a + b - 1) / b;
}
int round(int a, int b) {
    return (a + b / 2) / b;
}
int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
template <class T> bool amax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> bool amin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

// main
int main() {
    int N;
    string S;
    cin >> N >> S;
    int res = 0;
    FOR(i, 1, N, 1) {
        if (S[i] == 'E') {
            res++;
        }
    };
    int cnt = res;
    FOR(i, 1, N, 1) {
        if (S[i] == 'E') {
            cnt--;
        }
        if (S[i - 1] == 'W') {
            cnt++;
        }
        amin(res, cnt);
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 900
#include <iostream>

int main(){
  int x, y, r, W, H;
  std::cin >> W >> H >> x >> y >> r;
  if(x >= r && x + r <= W && y >= r && y + r <= H){
    std::cout << "Yes" << std::endl;
}
  else std::cout << "No" << std::endl;
}



Measured memory_bytes: 3080
#define _CRT_SECURE_NO_WARNINGS
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#include <stack>
#include <array>
#include <fstream>
#include <deque>
#include <bitset>
#include <complex>
using namespace std;
#define REP(i,n) for(int (i) = 0;(i) < (n) ; ++(i))
#define REPS(a,i,n) for(int (i) = (a) ; (i) < (n) ; ++(i))
#define REVERSE(i,n) for(int (i) = n-1;(i) >= 0 ; --i)
#define ALL(c) (c).begin() , (c).end()
#define EACH(it,c) for(auto(it,(c).begin());it != (c).end();)
#define cx real()
#define cy imag()
#define px first
#define py second
#define LL long long
#define int LL
#define inf  (1LL << 60)
#define mod 1000000007
#define QUICK_CIN ios::sync_with_stdio(false); cin.tie(0);
#define lower lower_bound
#define upper upper_bound
#define ZERO(c,n) memset(&c[0],0,sizeof(int)*n)
#define ZERO2(c,n) memset(&c[0][0],0,sizeof(int)*n
#define pl(a) cout << ""#a": " << a << endl;
#ifdef _DEBUG
#define debug_io fstream cin("input.txt");ofstream cout("output.txt");
#else
#define debug_io ;
#endif
#define debug_input debug_io
#define pb(a) push_back(a)
template<class T>void scan(vector<T>& a, int n, istream& cin)
{
	T c; REP(i, n) { cin >> c; a.push_back(c); }
}
using vs = vector<string>; using vi = vector<int>; using pii = pair<int, int>;
using psi = pair<string, int>; using vvi = vector<vi>; using pss = pair<string, string>;
template<class T>bool valid(T x, T w) { return 0 <= x&&x < w; }
int dx[4] = { 1, -1, 0, 0 }; int dy[4] = { 0, 0, 1, -1 };
//-----------------------------------------------------------------------------------------------
//-----------------------------------------------------------------------------------------------
//-----------------------------------------------------------------------------------------------


int func(int a,int b)
{
	int na(0),nb(0);

	while (a) {
		a /= 10;
		na++;
	}
	while (b) {
		b /= 10;
		nb++;
	}

	return max(na, nb);
}

signed main()
{
	QUICK_CIN;
	//debug_input;

	int n;
	cin >> n;

	int min_d = inf;

	for (int i = 1; i*i <= n; ++i) {
		if (n % i == 0) {
			min_d = min(min_d, func(i, n / i));
		}
	}

	cout << min_d << endl;

	return 0;
}

Measured memory_bytes: 256
def main():
    import sys
    readline = sys.stdin.readline

    n, w = map(int, readline().split())

    dp = [[0] * (w + 1) for _ in range(n + 1)]

    for i in range(1, n + 1):  # i個目の品物を選ぶかどうか決めた後の価値の総和の最大値,1-indexed
        wi, vi = map(int, readline().split())
        for j in range(wi):
            dp[i][j] = dp[i - 1][j]
        for j in range(wi, w + 1):
            dp[i][j] = max(
                dp[i - 1][j],  # i-1にすることにdebugで気づいた
                dp[i - 1][j - wi] + vi
            )

    print(max(dp[n]))


if __name__ == '__main__':
    main()


Measured memory_bytes: 119152
from collections import deque

N, M = map(int, input().split())
g = [[] for i in range(N)]
for i in range(M):
    A, B = map(int, input().split())
    g[A-1].append(B)
    g[B-1].append(A)

ans = [-1] * N
ans[0] = 0
d = deque([1])
while len(d) != 0:
    now = d[0]
    d.popleft()
    for i in g[now-1]:
        if ans[i-1] != -1:
            continue
        ans[i-1] = now
        d.append(i)

if -1 in ans:
    print('No')
else:
    print('Yes')
    for i in ans[1:]:
        print(i)


Measured memory_bytes: 98844
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
	int n,a[100000];
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	int i=0,c=0;	
	while(i<n){
		if(a[i]-a[i+1]<0){
			while(a[i]-a[i+1]<=0){
				i++;
			}
			c++;
		}
	else if(a[i]-a[i+1]>0){
			while(a[i]-a[i+1]>=0){
				i++;
			}
			c++;
		}	
		i++;
			

	}
	cout<<c<<endl;
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int mod=1e9+7;
map<int,int>d;
inline int read()
{
    char ch=getchar();
    int x=0,q=1;
    while(ch>'9' || ch<'0')q=ch==45?-1:q,ch=getchar();
    while(ch>='0' && ch<='9')x=(x<<1)+(x<<3)+(ch^'0'),ch=getchar();
    return x*q;
}
inline int solve(int x)
{
    if(d[x]!=0)
        return d[x];
    else
    return d[x]=((solve(x/2)+solve((x-1)/2)+solve((x-2)/2)))%mod;
}
signed main()
{
    d[0]=1; 
    d[1]=2;
    int n;
    n=read(); 
    int ans=solve(n);
    printf("%lld\n",ans);
    return 0;
}

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

#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<")"<< endl
#define BINARY(x) static_cast<bitset<16> >(x)

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

#define in_range(x, y, w, h) (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;
const int INF = 1e9;
typedef pair<int, int> PII;
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};

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

    string ans = "Positive";
    if (A <= 0 && B >= 0) ans = "Zero";
    else {
        int nega_cnt = 0;
        if (A < 0) nega_cnt = -A;
        if (B < 0) nega_cnt += (-B - 1);
        if (nega_cnt % 2) ans = "Negative";
    }

    cout << ans << endl;
}



Measured memory_bytes: 256
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
import copy

def dfs(y,x):
    if x<0 or x>=w or y<0 or y>=h:
        return
    if li[y][x] == 0:
        return
    if li[y][x] == 1:
        li[y][x] = 0
    dfs(y,x+1)
    dfs(y,x-1)
    dfs(y+1,x)
    dfs(y-1,x)
    dfs(y+1,x+1)
    dfs(y+1,x-1)
    dfs(y-1,x+1)
    dfs(y-1,x-1)
while True:
    w,h = map(int,input().split())
    if w == 0 and h == 0:
        break
    li = []
    for i in range(h):
        c = list(map(int,input().split()))
        li.append(c)
    cnt = 0
    for i in range(h):
        for j in range(w):
            if li[i][j] == 1:
                dfs(i,j)
                cnt += 1
    print(cnt)


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

int main() {
  int a,b,k; cin>>a>>b>>k;
  int count=0;
  int n=min(a,b);
  for (int i = n; 1<=i; i--) {
    if (a%i==0 && b%i==0) {
      count++;
      if (count==k) {
        cout<<i<<endl;
        return 0;
      }
    }
  }
  return 0;
}


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

signed main() {
	string s, t;
	cin >> s >> t;
	vector<int> table(26, -1), rtable(26, -1);
	bool ok = true;
	rep(i, s.size()) {
		int p = s[i] - 'a';
		int q = t[i] - 'a';
		if(table[p] < 0 && rtable[q] < 0) {
			table[p] = q;
			rtable[q] = p;
		}
		else if(table[p] != q || rtable[q] != p) {
			ok = false;
		}
	}
	if(ok) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

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

int cmp(const void* x, const void* y) {
	int a = *(const int*)x, b = *(const int*)y;
	return a < b ? -1 : a > b;
}

int ookikunaihou(int a, int b) {
	return a <= b ? a : b;
}

#define MAX (1 << 19) /* 524288 */

#define INF 1010101010

int ki_all[MAX * 2 - 1];
int ki[MAX * 2 - 1];

void ki_init(void) {
	int i;
	for (i = 0; i < MAX * 2 - 1; i++) {
		ki_all[i] = INF;
		ki[i] = INF;
	}
}

void ki_update_i(int idx, int qmin, int qmax, int smin, int smax, int value) {
	if (qmax <= smin || smax <= qmin) { /* クエリがセグメントから完全に外れている */
		/* nop */
	} else if (qmin <= smin && smax <= qmax) { /* セグメントがクエリに完全に含まれる */
		ki_all[idx] = ookikunaihou(ki_all[idx], value);
	} else {
		int smid = smin + (smax - smin) / 2;
		int lidx = idx * 2 + 1, ridx = idx * 2 + 2;
		int left, right;
		ki_all[lidx] = ookikunaihou(ki_all[idx], ki_all[lidx]);
		ki_all[ridx] = ookikunaihou(ki_all[idx], ki_all[ridx]);
		ki_all[idx] = INF;
		ki_update_i(lidx, qmin, qmax, smin, smid, value);
		ki_update_i(ridx, qmin, qmax, smid, smax, value);
		left = ookikunaihou(ki[lidx], ki_all[lidx]);
		right = ookikunaihou(ki[ridx], ki_all[ridx]);
		ki[idx] = ookikunaihou(left, right);
	}
}

void ki_update(int min, int max, int value) {
	ki_update_i(0, min, max, 0, MAX, value);
}

int ki_get_i(int idx, int qmin, int qmax, int smin, int smax) {
	if (qmax <= smin || smax <= qmin) { /* クエリがセグメントから完全に外れている */
		return INF;
	} else if (qmin <= smin && smax <= qmax) { /* セグメントがクエリに完全に含まれる */
		return ookikunaihou(ki[idx], ki_all[idx]);
	} else {
		int smid = smin + (smax - smin) / 2;
		int left = ki_get_i(idx * 2 + 1, qmin, qmax, smin, smid);
		int right = ki_get_i(idx * 2 + 2, qmin, qmax, smid, smax);
		return ookikunaihou(ookikunaihou(left, right), ki_all[idx]);
	}
}

int ki_get(int min, int max) {
	return ki_get_i(0, min, max, 0, MAX);
}

int N, Q;
int S[271828], T[271828], X[271828];
int D[271828];

int za_count;
int za[MAX];

/* target以下の最大の添字を求める */
int za_get(int target) {
	int yes = 0, no = za_count - 1;
	if (za[za_count - 1] <= target) return za_count - 1;
	while (yes + 1 < no) {
		int mid = yes + (no - yes) / 2;
		if (za[mid] <= target) yes = mid; else no = mid;
	}
	return yes;
}

int main(void) {
	int i;
	if (scanf("%d%d", &N, &Q) != 2) return 1;
	for (i = 0; i < N; i++) {
		if (scanf("%d%d%d", &S[i], &T[i], &X[i]) != 3) return 1;
	}
	for (i = 0; i < Q; i++) {
		if (scanf("%d", &D[i]) != 1) return 1;
	}

	for (i = 0; i < N; i++) {
		za[i * 2 + 0] = S[i] - X[i];
		za[i * 2 + 1] = T[i] - X[i];
	}
	za[N * 2] = 0;
	qsort(za, N * 2 + 1, sizeof(*za), cmp);
	za_count = 1;
	for (i = 1; i < N * 2 + 1; i++) {
		if (za[za_count - 1] != za[i]) {
			za[za_count++] = za[i];
		}
	}

	ki_init();
	for (i = 0; i < N; i++) {
		int sidx = za_get(S[i] - X[i]);
		int tidx = za_get(T[i] - X[i]);
		ki_update(sidx, tidx, X[i]);
	}
	for(i = 0; i < Q; i++) {
		int idx = za_get(D[i]);
		int answer = ki_get(idx, idx + 1);
		printf("%d\n", answer < INF ? answer : -1);
	}

	return 0;
}


/*

その時刻に出発したらaffectされる、という中で最小の座標を求める

*/


Measured memory_bytes: 16352
#include <iostream>
#include <stdio.h>
#include <algorithm>

using namespace std;

int main()
{
    int N, K, X, Y;
    cin >> N >> K >> X >> Y;

    int sum = 0;
    sum = min(X * N, K * X + (N - K) * Y);
    

    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<limits.h>
#include<queue>
#include<string>
using namespace std;

int main(){
	int n,i,j;
	cin >> n;
	bool A[n][n];
	
	for (i=0;i<n;i++){
		for (j=0;j<n;j++){
			A[i][j]=0;
		}
	}
	
	for (i=0;i<n;i++){
		int id,deg,dam;
		cin >> id >> deg;
		for (j=0;j<deg;j++){
			cin >> dam;
			A[i][dam-1]=1;
		}
	}
	
	for(i=0;i<n;i++){
		for (j=0;j<n-1;j++){
			cout << A[i][j] <<" ";
		}
		cout << A[i][n-1] <<endl;
	}
	
	return 0;
}

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

using namespace std;

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

int main()
{
	int k;
	int a, b, c;
	int n,ans;

	cin >> k;

	ans = 0;
	for(a=1 ;a <= k ; ++a)
	{
		for (b = 1;b <= k; ++b)
		{
			for (c = 1;c <= k; ++c)
			{
				n = gcd(a, b);
				ans += gcd(n, c);

			}
		}
	}

	cout << ans << endl;

	return(0);
}


Measured memory_bytes: 3572
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>

#define lpsbd(i, s, b, d) for(size_t i = (s); i < (b); i+=(d))
#define lpsb(i, s, b) for(size_t i = (s); i < (b); i++)
#define lpn(i, n) for(size_t i = 0; i < (n); i++)
#define fa(i, x) for(auto &i: x)
#define vcd(t, n, d) vector<t>(n, d)
#define vc(t, n) vector<t>(n)
#define all(x) (x).begin(), (x).end()

using namespace std;
using ll = long long;

const ll MOD = 1000000007;

int main(void)
{
    int N;
    cin >> N;
    int D;
    int dn[13] = {0};
    dn[0] = 1;
    lpn(i, N)
    {
        cin >> D;
        dn[D]++;
    }
    if (dn[0] >= 2 || dn[12] >= 2)
    {
        cout << 0 << endl;
        return 0;
    }
    vector<int> opt;
    opt.push_back(0);
    opt.push_back(24);
    if (dn[12]) opt.push_back(12);
    bool lr = true;
    lpsb(i, 1, 12)
    {
        switch (dn[i])
        {
        case 1:
            opt.push_back((lr ? i : 24 - i));
            lr = !lr;
            break;

        case 2:
            opt.push_back(i);
            opt.push_back(24 - i);
        case 0:
            break;

        default:
            cout << 0 << endl;
            return 0;
        }
    }
    int ans = 24;
    sort(all(opt));
    for (int i = opt.size()-1; i >= 1; i--) ans = min(ans, opt[i] - opt[i-1]);
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

class Main {

	static class Comb implements Comparable<Comb> {
		private int[] array;
		private int dec; //十進数

		//コンストラクタ
		public Comb(int[] a) {
			array = new int[a.length];
			for (int i = 0; i < array.length; i++) {
				array[i] = a[i];
				dec += Math.pow(2, array[i]); //十進数にする
			}
		}

		public int[] getArray() { return array; }

		public int getDec() { return dec;	}

		@Override
		public int compareTo(Comb c) { //比較の標準を作る
			return this.dec - c.getDec();
		}
	}

	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			//入力と配列準備
			sc.nextInt();
			int tLen = sc.nextInt();
			ArrayList<Integer> list = new ArrayList<Integer>();
			for (int i = 0; i < tLen; i++) {
				list.add(sc.nextInt());
			}
			System.out.println("0:");
			//--------------------------------------------------------
			ArrayList<Comb> arrayC = new ArrayList<Comb>();
			ArrayList<int[]> array = combination(tLen - 1);
			for (int[] arrayi : array) {
				int[] arrayNum = new int[arrayi.length];
				for (int i=0; i<arrayi.length; i++) arrayNum[i]=list.get(arrayi[i]);
				arrayC.add(new Comb(arrayNum));
			}
			Collections.sort(arrayC);
			for (Comb c : arrayC) {
				System.out.print(c.getDec() + ":");
				for (int i : c.getArray()) {
					System.out.print(" " + i);
				}
				System.out.print('\n');
			}
		}
	}

	static ArrayList<int[]> combination(int numbers) {
		ArrayList<int[]> a = new ArrayList<int[]>();
		for (int i = 1; i <= numbers + 1; i++) 	a.addAll(nCr(numbers, i));
		return a;
	}

	//組み合わせを配列に保存
	static ArrayList<int[]> nCr(int numbers, int target){  //0～numbersから選べる、何個取る
		ArrayList<int[]> list = new ArrayList<int[]>();
		int[] keep = new int[target];
		int[] finalt = new int[target];
		for (int i=0; i<target; i++) {
			keep[i] = 0 + i;  //最初の組み合わせを作成
			finalt[i] = numbers + (i - target) + 1;  //最後の組み合わせを作成
		}
		int[] k = new int[target];
		System.arraycopy(keep,0,k,0,target);
		list.add(k);
		while (!Arrays.equals(keep, finalt)) { //最後の組み合わせではない場合
			if (keep[target-1] != numbers) {  //最後の桁がnumbersではない場合
				keep[target-1]++;
				k = new int[target];
				System.arraycopy(keep,0,k,0,target);
				list.add(k);
			} else {
				int now = target-2;
				while (now > 0) {
					if (keep[now+1] - keep[now] == 1) now--; //右の桁-1はnowの最大値
					else break;
				}
				keep[now]++;
				for (int i=now+1; i<target; i++) {
					keep[i] = keep[i-1]+1;
				}
				k = new int[target];
				System.arraycopy(keep,0,k,0,target);
				list.add(k);
			}
		}
		return list;
	}
}


Measured memory_bytes: 205084
n = int(input())
points = list(map(int, input().split()))

sum = 0
for i in points:
  sum += i

mean = sum/len(points)
if mean%2 != 0:
    mean = int(round(mean,0))

ans = 0
for i in points:
  ans += (i - mean)**2

print(ans)

Measured memory_bytes: 8884
#define _GLIBCXX_DEBUG
#include <iostream>
#include <string>
#include <vector>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <bitset>
#include <map>

using namespace std;

int main(){

    int N;
    cin >> N;

    int old_H = 0;
    for (int i = 0; i < N; i++){
        int H;
        cin >> H;
        if(H < old_H){
            cout << "No" << endl;
            break;
        }else if (H == old_H){
            // old_H = H;
        }else if (H > old_H){
            old_H = H - 1;
        }

        if (i == N-1){
            cout << "Yes" << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define print(x)cout<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int main() {
  int n;
  cin>>n;
  vl a(n);
  map<ll,ll> mp;
  rep(i,n){
    cin>>a[i];
    mp[a[i]]++;
  }
  ll sum = 0;
  for(auto it:mp){
    sum += it.se*(it.se-1)/2;
  }
  rep(i,n){
    ll x = mp[a[i]]*(mp[a[i]]-1)/2;
    ll y = (mp[a[i]]-1)*(mp[a[i]]-2)/2;
    if(y<0)cout<<0<<endl;
    else{
      cout<<sum-x+y<<endl;
    }    
  }

  return 0;
}

Measured memory_bytes: 11008
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll
#define INF 1e16
#define mod 1000000007
int main(){
    ll n;
    cin>>n;
    ll a,x,y;
    vector< vector<P> > g(n);
    // cout<<n<<" "<<a<<endl;
    rep(i,n){
        cin>>a;
        rep(j,a){
            cin>>x>>y;
            x--;
            g[i].push_back({x,y});

        }
    }
    ll cnt = 0;
    ll ans = 0;
    // cout<<(1<<n)<<endl;
    for(int i=0;i< (1<<n);i++){
        ll dp[16] = {-1};
        cnt = 0;
        rep(j,n) if((1<<j) & i) {
            cnt++;
            dp[j] = 1;
        } else {
            dp[j] = 0;
        }
        bool flg = true;
        // cout<<i<<"ss"<<endl;
        rep(j,n){
            if((1<<j) & i){
                for(auto p:g[j]){
                    // cout<<dp[p.fi]<<" "<<p.se<<endl;
                    if(p.se == dp[p.fi]) continue;
                    else flg = false;
                }
            } 
        }
        if(flg) maxch(ans,cnt);
    }
    cout<<ans<<endl;
return 0;}

Measured memory_bytes: 256
N = int(input())
A1, A2 = [list(map(int, input().split())) for _ in range(2)]

ans = 0
sum = 0
for n in range(0, N):
    for i in range(0, n + 1):
        sum += A1[i]
    for j in range(n, N):
        sum += A2[j]
    if ans < sum:
        ans = sum
    sum = 0

print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long  ll;
typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef double ld;
typedef complex<ld> Point;
const ll INF = mod * mod;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
const ld eps = 1e-6;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;

ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	while (b) {
		ll r = a % b; a = b; b = r;
	}
	return a;
}

ll lcd(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

//左側と右側の累積和
vector<ll> le[1 << 17], ri[1 << 17];
void solve() {
	int n;
	cin >> n;
	vector<ll> s(n);
	rep(i, n)cin >> s[i];
	rep1(i, n - 1) {
		ll d = (n - 1) / i;
		le[i].resize(d+1);
		ri[i].resize(d + 1);
		rep(j, d) {
			le[i][j + 1] = le[i][j] + s[i*j];
			ri[i][j + 1] = ri[i][j] + s[n - 1 - i * j];
		}
	}
	ll ans = -INF;
	rep1(i, n-1) {

		for (int j = 0; j <= n - 1; j+= i) {
			int a = n - 1 - j;
			if (a <= 1)continue;
			int b = a - i;
			if (b <= 0||b>=a)continue;
			if (b%i == 0) {
				ll d = b / i; d++;
				if (d*i + b < n - 1)continue;
			}
			ll sum = 0;
			ll l = (n - 1 - b - 1) / i;
			sum += le[i][l + 1];
			ll r = (n - 1 - a) / i + 1;
			sum += ri[i][r];
			//cout << a<<" " << b << " "<<sum<<endl;
			ans = max(ans, sum);
		}
	}
	cout << ans << endl;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	solve();
	//stop
	return 0;
}


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

int main(void)
{
	int M[12];
	int N[12];
	int L;
	while(cin >> L){
		if(!L) break;
		for(int i=0; i<12; i++){
			cin >> M[i] >> N[i];
		}
		int month = 0;
		int sum=0;
		for(;month<12; month++){
			sum+=M[month]-N[month];
			if(sum>=L) break;
		}
		if(month!=12) cout << month + 1 << endl;
		else cout << "NA" << endl;
	}
	return 0;
}

Measured memory_bytes: 0
N, M = map(int,input().split())
E = []
for i in range(N+1):
    E.append([])
for _ in range(M):
    a, b = map(int,input().split())
    E[a].append(b)
    E[b].append(a)

ORD = [0] * (N+1)
LOW = [0] * (N+1)
used = [False] * (N+1)
bridge = []

def dfs(idx, k, parent):
    global E,ORD,LOW,used,bridge
    used[idx] = True
    ORD[idx] = k
    LOW[idx] = k
    for to in E[idx]:
        if not used[to]:
            k = dfs(to, k+1, idx)
            LOW[idx] = min(LOW[idx], LOW[to])
            if ORD[idx] < LOW[to]:
                bridge.append(sorted([idx,to]))
        elif to != parent:
            LOW[idx] = min(LOW[idx], ORD[to])
    return k

dfs(1, 1, 0)
print(len(bridge))

#print(bridge)
#print(ORD)
#print(LOW)
#print(used)
#print(E)

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

int main(void)
{
  int n;
  int a, b, c;
  int i;
  int temp;
  cin >> n;
  for(i = 0; i < n; i++){
    cin >> a >> b >> c;
    if(a < b){
      temp = a;
      a = b; 
      b = temp;
    }
    if(a < c){
      temp = a;
      a = c;
      c = temp;
    }
    
    if(a*a == b*b + c*c){
      cout << "YES" << endl;
    }else{
      cout << "NO" << endl;
    }
  }

  return 0;
}

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

#define REP(i, n) for(int i = 0;i < n;i++)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define ll long long
const ll mod = 1e9+7;


int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n, m;
	cin >> n >> m;
	vector<vector<char>> a(n, vector<char>(n));
	vector<vector<char>> b(m, vector<char>(m));
	REP(i, n){
		REP(j, n){ cin >> a[i][j]; }
	}
	REP(i, m){
		REP(j, m){ cin >> b[i][j]; }
	}
	REP(i, n-m+1){
		REP(j, n-m+1){
			bool match = true;
			REP(k, m){
				REP(l, m){
					if (a[i+k][j+l]!=b[k][l]){
						match = false;
						break;
					}
				}
				if (!match){ break; }
			}
			if (match){ cout << "Yes" << endl; return 0; }
		}
	}
	cout << "No" << endl;
}


Measured memory_bytes: 256
n = int(input())

#n以下の素数列挙(O(n log(n))
def primes(n):
    ass = []
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    for i in range(len(is_prime)):
        if is_prime[i] and i % 5 == 1:
            ass.append(i)
    return ass

prime_list = primes(55555)
#print(prime_list)
#print(len(prime_list))
ans = []
for i in range(n):
    ans.append(prime_list[i])
print(*ans)

Measured memory_bytes: 65676
n, k = map(int, input().split())
s = input()

if s[0] == 'L' and s[n-1] == 'L':
    s = 'R' + s
    cnt = 0
    for i in range(n):
        if s[i] == 'R' and s[i+1] == 'L':
            cnt += 1
    if cnt <= k:
        print(n-1)
    elif cnt == k+1:
        print(n-1)
    else:
        print(n-2*(cnt-1)-1+2*k)

elif s[0] == 'L' and s[n-1] == 'R':
    s = 'R' + s + 'L'
    cnt = 0
    for i in range(n+1):
        if s[i] == 'R' and s[i+1] == 'L':
            cnt += 1
    if cnt <= k:
        print(n-1)
    elif cnt == k+1:
        print(n-1)
    elif cnt == k+2:
        print(n-2)
    else:
        print(n-2*(cnt-2)-2+2*k)

elif s[0] == 'R' and s[n-1] == 'L':
    cnt = 0
    for i in range(n-1):
        if s[i] == 'R' and s[i+1] == 'L':
            cnt += 1
    if cnt <= k:
        print(n-1)
    else:
        print(n-2*cnt+2*k)

elif s[0] == 'R' and s[n-1] == 'R':
    s = s + 'L'
    cnt = 0
    for i in range(n):
        if s[i] == 'R' and s[i+1] == 'L':
            cnt += 1
    if cnt <= k:
        print(n-1)
    elif cnt == k+1:
        print(n-1)
    else:
        print(n-2*(cnt-1)-1+2*k)

Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
const int INF=1001001000;
const int mINF=-1001001000;
const ll LINF=10100100100100100;
int main(){
    int n;cin >> n;
    string s;cin >> s;
    int q;cin >> q;
    vector<set<int>> a(26);
    for(int i=0;i<n;i++){
        int c=s[i]-'a';
        a[c].insert(i);
    }
    vector<int> ans(q);
    for(int i=0;i<q;i++){
        int num;cin >> num;
        if(num==1){
            int j;
            char cc;
            cin >> j >> cc;
            j--;
            int c=cc-'a';
            a[s[j]-'a'].erase(j);
            s[j]=cc;
            a[c].insert(j);
        }
        else{
            int l,r;cin >> l >> r;
            l--;
            int cnt=0;
            for(int j=0;j<26;j++){
                auto itr=a[j].lower_bound(l);
                if(itr!=a[j].end()&&*itr<r) cnt++;
            }
            cout << cnt << endl;
        }
    }
    return 0;
}

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

int main()
{
	int x, y;
	cin >> x >> y;

	if (y >= 2*x && y%2 == 0 && 4*x >= y)
		cout << "Yes\n";
	else
		cout << "No\n";
	return 0;
}

Measured memory_bytes: 3632
import java.util.*


fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)

    var N: Long
    N = sc.nextLong()
    val A = Array((N).toInt()){0L}
    for (i in 0 until N) {
        A[(i).toInt()] = sc.nextLong()
    }
    solve(N, A)
}

fun solve(N: Long, A: Array<Long>) {
    val s = HashSet<Long>()

    A.forEach {
        if (s.contains(it)) {
            s.remove(it)
        } else {
            s.add(it)
        }
    }

    println(s.size)
}



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

int main()
{
  long long n, sum;
  cin >> n;
  sum = 0;
  for(int i = 1; i <= n; i++)
  {
    for(int j = 1; j <= n; j++)
    {
      for(int k = 1; k <= n; k++)
      {
        sum += gcd(gcd(i, j), k);
      }
    }
  }
  cout << sum;
  return 0;
}



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

"""
input:
4 5
4 2
5 2
2 1
8 3

output:
13
"""

import sys
from collections import namedtuple


# def solve():
#     for i, item in enumerate(item_list, 1):
#         for cp in range(1, real_cp + 1):
#             # capacity allows putting in, calculate value
#             if item.w <= cp:
#                 values[i][cp] = max(values[i - 1][cp], values[i - 1][cp - item.w] + item.v)
#             # can't put in, skip current item
#             else:
#                 values[i][cp] = values[i - 1][cp]
#
#     return values[c_items][real_cp]


def solve_2():
    dp = [0] * (real_cp + 1)
    for item in item_list:
        v, w = item.v, item.w
        for cp in range(real_cp - w, -1, -1):
            dp[cp + w] = max(dp[cp + w], dp[cp] + v)

    return dp.pop()


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    c_items, real_cp = map(int, _input[0].split())
    items = map(lambda x: x.split(), _input[1:])

    Item = namedtuple('Item', ('v', 'w'))
    item_list = [Item(int(v), int(w)) for v, w in items]

    # values = [[0] * (real_cp + 1) for _ in range(c_items + 1)]
    print(solve_2())

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

int main(void){
	int num[27];
	for(int i=0; i<27; i++){
		num[i] = 0;
	}

	char w;
	while(cin >> w){
		if(w >= 'a' && w <= 'z'){
			w -= 'a' - 'A';
		}
		if(w >= 'A' && w <= 'Z'){
			num[w-'A']++;
		}
	}

	for(int i=0; i<26; i++){
		printf("%c : %d\n", 'a'+i, num[i]);
	}

	return 0;
}

Measured memory_bytes: 1124
#include <iostream>
#include <algorithm>
#include <vector>
#include <tuple>
using namespace std;

int main(){
    int A,B,T;
    cin>>A>>B>>T;
    int ans=0;
    for(int t=0;t<=T;t+=A){
        if(!t) continue;
        ans+=B;
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<ll, ll>pll;
int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    string s;
    cin >> s;
    s[1] == 'R' ? s[1] = 'B' : s[1] = 'R';
    cout << s;
    return 0;
}


Measured memory_bytes: 3600
#include <iostream>
#include <algorithm>
#include <vector>
#include <string.h>

#define MAX(x, y)	(((x) > (y))? (x) : (y))
#define ABS(x)		(((x) < 0)? (-1*(x)) : (x))
#define REPI(x,y)	for (i=(x);i<(y);i++)
#define REPJ(x,y)	for (j=(x);i<(y);i++)
#define MEMCLR(X)	memset((X),0,sizeof((X)))

using namespace std;

int N,A,B,S = 0,w;
char k;
int main() {
	int i;

	cin >> N >> A >> B ;
	REPI(1,N+1) {
		w = i;
		k = 0;
		while (w != 0) {
			k += w % 10;
			w/=10;
		} 
		if (A <= k && k <= B) S+=i;
	}
	
	cout << S;

	return 0;
}


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

using namespace std;

char sir[1000009];
vector < string > v;

bool cmpLength (string &s1, string &s2)
{
    return s1.length () > s2.length ();
}

const int maxCntNodes = 1100009, sigma = 26;
long long ans = 0;
int N, cntNodes = 1;
int son[maxCntNodes][sigma], cnt[maxCntNodes][sigma], f[sigma];

int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

scanf ("%d\n", &N);
v.resize (N);
for (int i=0; i<N; i++)
    scanf ("%s", sir),
    v[i] = sir;
sort (v.begin (), v.end (), cmpLength);
for (auto s : v)
{
    reverse (s.begin (), s.end ());
//    printf ("%s\n", s.c_str ());
    int leftChars = 0;
    for (auto &c : s)
        c -= 'a', f[c] ++, leftChars ++;
    int q = 1;
    for (auto c : s)
    {
        if (leftChars == 1)
        {
            ans += cnt[q][c], f[c] --;
            break;
        }
        if (son[q][c] == 0)
            son[q][c] = ++cntNodes;
        for (int i=0; i<sigma; i++)
            if (f[i] > 0)
                cnt[q][i] ++;
        f[c] --, leftChars --, q = son[q][c];
    }
}
printf ("%lld\n", ans);
return 0;
}


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

int main()
{
    string s;
    cin >> s;
    int A_index = -1, Z_index = -1;
    for (int i = 0; i < s.size(); i++)
    {
        if (A_index == -1 && s[i] == 'A')
        {
            A_index = i;
        }
        else if (s[i] == 'Z')
        {
            Z_index = i;
        }
    }

    cout << Z_index - A_index + 1 << endl;

    return 0;
}

Measured memory_bytes: 640
inlist = input().split()
a1, a2 = (int(x) for x in inlist)

# a = input()
# a = int(a)

if a1 <a2:
    print("a < b")

if a1 >a2:
    print("a > b")

if a1 ==a2:
    print("a == b")



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

public class Main {

   public static void main(String[] args) {
   
      Scanner sc = new Scanner(System.in);
      
      int N = sc.nextInt();
      int[] L = new int[N];
      for(int i=0;i<N;i++) {
         L[i] = sc.nextInt();
      }
      Arrays.sort(L);
      int ans = 0;
      for(int i=0;i<N-2;i++) {
         for(int j=i+1;j<N-1;j++) {
            int ij = L[i]+L[j];
            int w = j+1;
            while(w < N && L[w] < ij) {
               ans++;
               w++;
            }
         }
      }
      
      System.out.println(ans);
   }
}

Measured memory_bytes: 29108
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	vector<int>v(n);
	for(int i=0;i<n;i++){
		cin>>v[i];
	}	
	sort(v.begin(),v.end());
	for(int i=0;i<n-1;i++){
		if(v[i]==v[i+1]){
			return cout<<"NO"<<endl,0;
		}
	}
	cout<<"YES"<<endl;
	return 0;
}


Measured memory_bytes: 4004
#include <bits/stdc++.h>
 
using namespace std;
 
#define all(x) x.begin(), x.end()
 
typedef long long ll;
typedef long double ld;
 
const int N = 123456;
const int M = 1234567;
 
int a[2222], b[2222];
ll bst[1111], c[2222];
bool has_a_cycle[1111];
 
int main(int argc, char const *argv[])
{
	
	#ifdef Cyborg101
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif	
 
	cin.sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
 
	int n, m;
	cin >> n >> m;
 
	for(int i = 0; i < m; ++i){
		cin >> a[i] >> b[i] >> c[i];
		c[i] = -c[i];
	}
 
	//const ll inf = 1e18;
	#define inf (1ll << 62)
 
 
	for(int i = 0; i <= n; ++i)
		bst[i] = inf;
 
	bst[1] = 0;
 
	for(int i = 0; i < m; ++i){
		for(int j = 0; j < m; ++j){
 
			if(bst[a[j]] == inf) continue;
 
			if(bst[a[j]] + c[j] < bst[b[j]])
				bst[b[j]] = bst[a[j]] + c[j];
		}
	}
 
	for(int i = 0; i < m; ++i){
		for(int j = 0; j < m; ++j){
 
			if(bst[a[j]] == inf) continue;
 
			if(bst[a[j]] + c[j] < bst[b[j]]){
				bst[b[j]] = bst[a[j]] + c[j];		
				has_a_cycle[b[j]] = true;
			}
 
			if(has_a_cycle[a[j]])
				has_a_cycle[b[j]] = true;
		}
	}
 
	if(has_a_cycle[n])
		cout << "inf" << endl;
	else
		cout << -bst[n] << endl;
 
	return 0;				
}

Measured memory_bytes: 384
n = int(input())
a = list(map(int, input().split()))

ans = 0
t = 400
while t < 3201:
  for i in a:
    if i >= t-400 and i < t:
      ans += 1
      break
  t += 400

s = 0
for i in a:
  if i >= 3200: s += 1

if ans == 0: print(1, s)
else: print(ans, ans+s)

Measured memory_bytes: 9080
n,m,k = map(int,input().split())
a_list = list(map(int,input().split()))
b_list = list(map(int,input().split()))
sum_a = [a_list[0]]
sum_b = [b_list[0]]
for i in range(1,n):
  sum_a.append(sum_a[-1] + a_list[i])
  
for i in range(1,m):
  sum_b.append(sum_b[-1] + b_list[i])
import bisect
result = [0]
for i in range(n):
  border = k - sum_a[i]
  if border < 0:
    break
  index = bisect.bisect_right(sum_b, border)
  result.append(i+1+index)
  
for i in range(m):
  border = k - sum_b[i]
  if border < 0:
    break
  index = bisect.bisect_right(sum_a, border)
  result.append(i+1+index)
print(max(result))

Measured memory_bytes: 59556
#include<iostream>
using namespace std;
int n; 

int isPrime(int x) {
  if (x < 2) return 0;
  else if (x == 2) return 1;
  if ( x % 2 == 0) return 0;
  for (int i = 3; i * i <= x; i+=2 ) {
    if (x % i == 0) return 0;
  }
  return 1;

}

int main()
{
  int x[100000];
  int ans = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> x[i];
    if (isPrime(x[i])) ans++;
  }
  cout << ans << endl;
  return 0;
}
 
 

Measured memory_bytes: 3068
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S,T,U;
  int A,B;
  cin >> S >> T >> A >> B >> U;
  
  if(S == U){
    
    cout << A - 1 << " " << B << endl;
    
  }
  
  else if(T == U){
    
    cout << A << " " << B - 1 << endl;
    
  }
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iomanip>
#include <math.h>
#include <unistd.h>
#include <stdio.h>
#define rep(i,x) for(ll i = 0;i<x;i++)
#define all(a) (a).begin(),(a).end()
#define vecin(a) rep(i,a.size())cin >> a[i]
#define vecout(a) rep(i,a.size()){cout << a[i];cout << (i == a.size() - 1 ? "\n":" ");}
using ll = long long;
using ld = long double;
using namespace std;
using dou = double;
const ll inf = 2147483647;
const ll INF = 1LL << 60;
const ld pi = 3.14159265358;
const ll mod = 1000000007LL;
typedef pair<ll,ll> P;
using graph = vector<vector<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;}
template<class T> inline bool change(T a,T b){if(a > b){swap(a,b);return true;}return false;}
ll gcd(ll a,ll b){
    if(a < b)swap(a,b);
    if(a % b == 0)return b;
    else return gcd(b,a%b);
}
//素数判定O(sqrt(N))
bool isp(ll n){
    bool res = true;
    if(n == 1)return false;
    else{
        for(ll i = 2;i * i <= n;i++){
            if(n % i == 0){
                res = false;
                break;
            }
        }
        return res;
    }
}
const ll cmax = 1000000;
ll fac[cmax], finv[cmax], inv[cmax];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < cmax; 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 nCk(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;
}
//nのm乗をMODで割ったあまりO(logN)
ll modpow(ll n,ll m,ll MOD){
    ll res = 1;
    while(m){
        if(m & 1)res = (res * n) % MOD;
        m >>= 1;
        n *= n;
        n %= MOD;
    }
    return res;
}

//printf("%.10f\n", N);
/*  vector<ll> vec = {1,2,5,6,8,9,10};
    cout << binary_search(all(vec),5) << endl; -> true*/
/*
    vector<ll> vec = {1,2,5,6,8,9,10};
    auto n = upper_bound(all(vec),4);
    cout << *n << endl; -> 5*/

//    cout << fixed << setprecision(15);
ll N;
void out(vector<ll> q){
    rep(i,N){
        if(q[i] == 1)cout << "S";
        else cout << "W";
    }
    cout << "\n";
    return;
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll N,ans = 1;
    cin >> N;
    for(ll i = 1;i <= N;i++){
        ans *= i;
        ans %= mod;
    }
    cout << ans << endl;
}

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

// macro
#define rep(i,n) for(i=0;i<n;i++)
#define ll long long
#define all(v) v.begin(), v.end()

// code starts
int main()
{
  int rad,n;cin>>rad>>n;
  while(rad!=0||n!=0)
  {
    vector<int> l(n);
    vector<int> r(n);
    vector<int> h(n);
    int i,j;
    rep(i,n)cin>>l[i]>>r[i]>>h[i];
    rep(i,n)
    {
      l[i]+=20;
      r[i]+=20;
    }
    vector<int> maxh(20*2,0);
    rep(i,n)
    {
      rep(j,20*2)
      {
        if(j<l[i]||j>=r[i])continue;
        maxh[j]=max(maxh[j],h[i]);
      }
    }
    double ans=100.0;
    for(i=20-rad;i<=20+rad;i++)
    {
      int useh;
      if(i==20-rad)useh=maxh[i];
      else if(i==20+rad)useh=maxh[i-1];
      else useh=min(maxh[i-1],maxh[i]);
      int x=i-20;
      double kans=useh+rad-sqrt(rad*rad-x*x);
      ans=min(ans,kans);
    }
    cout<<fixed<<setprecision(10)<<ans<<endl;
    cin>>rad>>n;
  }
}



Measured memory_bytes: 3284
#include <iostream>
#include<math.h>
using namespace std;
int main() {
	 int e;
	cin >> e;

	while (e!=0) {
		int min = e;
		for (int z = 0; z <= 100; z++) {
			for (int y = 0; y <= 1000; y++) {
				int z2 = z * z,y2=y*y;
				int z3 = z2 * z;
				int x = e - y2 - z3;
				if (x < 0)break;
				int a = x + y + z;
				if (a < min)min = a;
			}
		}
		cout << min << endl;
		cin >> e;
	}
}


Measured memory_bytes: 3060
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_C main
#include "bits/stdc++.h"
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
using psi = pair<string, int>;
// functions

#endif


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


    int N;  cin >> N;
    vi T(N), A(N); REP(i, N) cin >> T[i] >> A[i];
    vl dp(N + MGN, 0);
    // dp[i] : T[i]*dp[i] number of votes that Tk got
    //         A[i]*dp[i] numger of votes that Ao got

    dp[0] = 1;
    FOR(i,1,N) {
        //T[i]*dp[i] >= T[i-1]*dp[i-1]
        //A[i]*dp[i] >= A[i-1]*dp[i-1]
        dp[i] = max((T[i - 1] * dp[i - 1] + T[i] - 1) / T[i]
                  , (A[i - 1] * dp[i - 1] + A[i] - 1) / A[i]);
    }

    ll ans = (T[N - 1] + A[N - 1])*dp[N - 1];
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
B = set(A)
C = list(B)
k = len(C)
if N%3==0:
    if k==3 and C[0]^C[1]==C[2] and A.count(C[0])==A.count(C[1]) and A.count(C[0])==A.count(C[2]):
        print("Yes")
    elif k==2:
        C = sorted(C)
        if C[0]==0 and A.count(C[0])==N//3:
            print("Yes")
        else:
            print("No")
    elif k==1 and C[0] == 0:
        print("Yes")
    else:
        print("No")
else:
    if k==1 and C[0] ==0:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 60784
N,x=map(int,input().split())
*A,=map(int,input().split())
A = [0] + A
ans = 0
for i,a in enumerate(A):
    if a>x:
        ans += a-x
        A[i] = x
for i in range(1,N+1):
    ans += max(0,A[i-1]+A[i]-x)
    A[i] -= max(0,A[i]+A[i-1]-x)
print(ans)

Measured memory_bytes: 14060
#include <stdio.h> 
int main (){
	int i ;
	scanf("%d", &i);
	if(1 == i){
		printf("1\n");
	}else if(2 <= i && i < 4){
		printf("2\n");
	}else if(4 <= i&&i < 8){
		printf("4\n");
	} else if(8 <= i&&i < 16){
		printf("8\n");
	} else if(16 <= i&&i < 32){
		printf("16\n");
	} else if(32 <= i&&i < 64){
		printf("32\n");
	} else if(64 <= i){
		printf("64\n");
	} 
	return 0;
}	

Measured memory_bytes: 128
def main():
    n = int(input())
    A = list(map(int, input().split()))
    A.sort()
    m = A.pop()
    B = [[a, abs(a - (m / 2))] for a in A]
    B.sort(key = lambda x: x[1])
    print('{} {}'. format(m, B[0][0]))

if __name__ == '__main__':
    main()


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

int main() {
  int n,i = 1;
  cin >> n;
  while(i*2 <= n) i *= 2;
  cout << i << endl;
}

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

using namespace std;

#define int long long
#define all(v) begin(v), end(v)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for(int i = (int)(s); i < (int)(n); i++)
#define min(...) min({__VA_ARGS__})
#define max(...) max({__VA_ARGS__})

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

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

  string s;
  cin >> s;
  reverse(all(s));
  string t[] = {"resare", "esare", "remaerd", "maerd"};
  int i = 0;
  while(i < s.size()) {
    int idx = -1;
    rep(j, 4) if(s.substr(i, t[j].size()) == t[j]) idx = j;
    if(~idx) {
      i += t[idx].size();
    } else {
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;

  return 0;
}


Measured memory_bytes: 512
fun main(args : Array<String>) {
    val N = readLine()?.toInt() ?: return
    val S = readLine() ?: return
    val subString1 = S.substring(0, N / 2)
    val subString2 = S.substring(N / 2, N)

    if (subString1 == subString2) {
        print("Yes")
    } else {
        print("No")
    }
}

Measured memory_bytes: 31608
import sys
sys.setrecursionlimit(10**9)

MOD = 10**9 + 7
n, k = map(int, input().split())
graph = [[] for _ in range(n)]
k_inv = pow(k, MOD - 2, MOD)
for _ in range(n - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    graph[a].append(b)
    graph[b].append(a)


def dfs(v, v_p):
    # 子部分木の塗り方の場合の数
    if v_p == -1:  # root
        c = k - 1
    else:
        c = k - 2

    cnt = 1
    i = 0
    for v_next in graph[v]:
        if v_next == v_p:
            continue
        cnt *= max(0, c - i)
        cnt %= MOD
        cnt *= dfs(v_next, v)
        cnt %= MOD
        i += 1
    return cnt


ans = dfs(0, -1) * k % MOD
print(ans)


Measured memory_bytes: 92404