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

const int Maxn = 1 << 18;
const int Maxm = 100005;
const int Maxd = 9;

int n;
int V[Maxn], W[Maxn];
int q;
int qv[Maxm], ql[Maxm];
vector <int> quer[Maxn];
int res[Maxm];
vector <int> seq;
int best[Maxm];

int Gen(int lvl, int lft, int has, bool tk)
{
    if (lvl >= seq.size()) {
        if (tk) has += best[lft];
        return has;
    } else {
        int res = Gen(lvl + 1, lft, has, tk);
        if (W[seq[lvl]] <= lft)
            res = max(res, Gen(lvl + 1, lft - W[seq[lvl]], has + V[seq[lvl]], tk));
        return res;
    }
}

void genBest(int lvl, int w, int has)
{
    if (w >= Maxm) return;
    if (lvl >= seq.size()) best[w] = max(best[w], has);
    else {
        genBest(lvl + 1, w, has);
        genBest(lvl + 1, w + W[seq[lvl]], has + V[seq[lvl]]);
    }
}

void Traverse(int v)
{
    if (v > n) return;
    seq.push_back(v);
    if (seq.size() < Maxd)
        for (int i = 0; i < quer[v].size(); i++) {
            int ind = quer[v][i];
            res[ind] = Gen(0, ql[ind], 0, false);
        }
    else {
        if (seq.size() == Maxd) {
            fill(best, best + Maxm, 0);
            genBest(0, 0, 0);
            for (int i = 1; i < Maxm; i++)
                best[i] = max(best[i], best[i - 1]);
        }
        for (int i = 0; i < quer[v].size(); i++) {
            int ind = quer[v][i];
            res[ind] = Gen(Maxd, ql[ind], 0, true);
        }
    }
    Traverse(2 * v);
    Traverse(2 * v + 1);
    seq.pop_back();
}

int main()
{
    scanf("%d", &n);
    for (int i = 1; i <= n; i++)
        scanf("%d %d", &V[i], &W[i]);
    scanf("%d", &q);
    for (int i = 1; i <= q; i++) {
        scanf("%d %d", &qv[i], &ql[i]);
        quer[qv[i]].push_back(i);
    }
    Traverse(1);
    for (int i = 1; i <= q; i++)
        printf("%d\n", res[i]);
    return 0;
}


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

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; ++ i) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  if (n & 1) {
    int k = n / 2;
    if (a[k] != a[k - 1] && a[k] != a[k + 1]) {
      cout << 1 << endl;
    } else {
      cout << 0 << endl;
    }
  } else {
    int k = n / 2;
    if (a[k] != a[k - 1]) {
      cout << a[k] - a[k - 1] << endl;
    } else {
      cout << 0 << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 640
height, width = gets.split(" ").map(&:to_i)
boards = []
height.times do
  boards << gets.chomp.split("")
end
original_number_boards = Array.new(height) { Array.new(width, -1) }
boards.each_with_index do |row, index_1|
  row.each_with_index do |cell, index_2|
    if cell == "#"
      original_number_boards[index_1][index_2] = -2
    end
  end
end

ans = 0
0.upto(height - 1).each do |h_index|
  0.upto(width - 1).each do |w_index|
    number_boards = Marshal.load(Marshal.dump(original_number_boards))
    if number_boards[h_index][w_index] == -2
      next
    else
      number_boards[h_index][w_index] = 0
      queue = [[h_index, w_index]]
    end
    tmp = 0
    until queue.empty?
      current_h, current_w = queue.shift
      current_step = number_boards[current_h][current_w]
    
      if current_h > 0 && number_boards[current_h - 1][current_w] == -1
        number_boards[current_h - 1][current_w] = current_step + 1
        queue << [current_h - 1, current_w]
      end
    
      if current_h < height - 1 && number_boards[current_h + 1][current_w] == -1
        number_boards[current_h + 1][current_w] = current_step + 1
        queue << [current_h + 1, current_w]
      end
    
      if current_w > 0 && number_boards[current_h][current_w - 1] == -1
        number_boards[current_h][current_w - 1] = current_step + 1
        queue << [current_h, current_w - 1]
      end
    
      if current_w < width - 1 && number_boards[current_h][current_w + 1] == -1
        number_boards[current_h][current_w + 1] = current_step + 1
        queue << [current_h, current_w + 1]
      end
      tmp = current_step
    end
    ans = tmp if tmp > ans
  end
end
puts ans


Measured memory_bytes: 2428
N = int(input())
AB = [[int(_) for _ in input().split()] for _ in range(N)]
A = sorted([a for a, b in AB])
B = sorted([b for a, b in AB])

ans = B[N // 2] + B[(N - 1) // 2] - (A[N // 2] + A[(N - 1) // 2])
if N % 2:
    ans //= 2
ans += 1
print(ans)


Measured memory_bytes: 47676
a = int(input())
b = int(input())
c = int(input())
x = int(input())

cnt = 0
for i in range (0, a+1):
    for j in range (0, b+1):
        for k in range (0, c+1):
            if 500 * i + 100 * j + 50 * k == x:
                cnt = cnt + 1
print(cnt)

Measured memory_bytes: 3064
s=input()
if len(s)>9 and len(s)<5:
    print("NO")
else:
    x=["AKIHABARA","AKIHABAR","AKIHABRA","AKIHABR",
      "AKIHBARA","AKIHBAR","AKIHBRA","AKIHBR",
       "KIHABARA","KIHABAR","KIHABRA","KIHABR",
      "KIHBARA","KIHBAR","KIHBRA","KIHBR"]
    if s in x:
        print("YES")
    else:
        print("NO")

Measured memory_bytes: 38256
#include <iostream>
#include <map>

int main()
{
    char b;
    std::cin >> b;

    std::map<char, char> mcc;
    mcc['A'] = 'T';
    mcc['T'] = 'A';
    mcc['C'] = 'G';
    mcc['G'] = 'C';

    std::cout << mcc[b] << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<string>
using namespace std;
int main()
{
	string g;
	int x,i,k[26]={0},sum=1;
	cin>>g;
	x=g.length();
	for(i=0;i<x;i++)
	{
		k[g[i]-'a']++;
	}
	for(i=0;i<26;i++)
	{
		if(k[i]%2==1)
		{
			sum=0;
			break;
		}
	}
	if(sum==1)printf("Yes");
	else printf("No");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
 int k,x;
 int min, max;
 cin >> k >> x;
  
  if( (x - k +1) >= -1000000){
    min = x - k + 1;
  }
  else{
     min = -1000000; 
  }
  
  if( (x + k -1) <= 1000000){
     max = x + k - 1;
  }
  else{
     max = 1000000;
  }
  
  for( int i = min; i < max; i++){
    cout << i << ' ';
  }
  cout << max;
}

Measured memory_bytes: 256
#include <stdio.h>
int main()
{
    char s[110];
    scanf("%s", s);
    for (int i = 0; s[i] != '\0'; i++)
    {
        switch (s[i])
        {
        case 'R':
            if (i % 2 == 1)
            {
                printf("No\n");
                return 0;
            }
            break;
        case 'L':
            if (i % 2 == 0)
            {
                printf("No\n");
                return 0;
            }
            break;
        default:
            break;
        }
    }
    printf("Yes\n");
    return 0;
}

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

using namespace std;
typedef long long int LL;
typedef long long int ll;
typedef pair<long long int, long long int> pii;
typedef pair<double, double> pdd;

#define SORT(c) sort((c).begin(),(c).end())
#define BACKSORT(c) sort((c).begin(),(c).end(),std::greater<LL>())
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SP << " " <<

LL mod = 1000000007;

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

  LL N;
  cin >> N;
  vector<LL> s(N);
  REP(i,N){
    cin >> s[i];
  }

  LL ans = 0;

  FOR(i,1,N){
    LL st = 0;
    LL gl = N - 1;
    LL sum = 0;
    REP(j,N){
      st += i;
      gl -= i;
      if(st*2>=(N-1)&&(N-1)%i==0){
        break;
      }
      if (gl<=i){
        break;
      }

      sum += s[st] + s[gl];
      if(ans<sum){
        ans = sum;
      }
    }
  }

  cout << ans << endl;
}

// 0 5
// 2 7
// 4 9
// 6 11

// 03
// 25
// 47

// A +B


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define fo(i, x, y) for(int i = x, _b = y; i <= _b; i ++)
#define ff(i, x, y) for(int i = x, _b = y; i <  _b; i ++)
#define fd(i, x, y) for(int i = x, _b = y; i >= _b; i --)
#define ll long long
#define pp printf
#define hh pp("\n")
using namespace std;

const int N = 2e5 + 5;

int a3[13];

int n, m;
char s[N];

const int M = 531441;
struct nod {
	int p[M], w[N];
} a[2]; int o;

int t[3], nt[3];
int c[3][M];
int p[M];

int main() {
	a3[0] = 1; fo(i, 1, 12) a3[i] = a3[i - 1] * 3;
	scanf("%d", &n);
	scanf("%s", s + 1); m = strlen(s + 1);
	fo(i, 1, n) {
		fo(j, 0, 2)	t[j] = j;
		fo(j, 0, 2) ff(k, 0, a3[i - 1]) c[j][k] = j;
		a[!o].w[0] = a3[i] - 1;
		fo(j, 1, m) {
			char ch = s[j];
			if(ch == 'S') {
				swap(t[1], t[2]);
			} else {
				int lc[3];
				fo(k, 0, 2) lc[k] = c[t[k]][a[o].w[j - 1]];
				fo(k, 0, 2) c[t[k]][a[o].w[j - 1]] = lc[(k + 2) % 3];
			}
			a[!o].w[j] = a[o].w[j] + a3[i - 1] * c[t[2]][a[o].w[j]];
		}
		fo(j, 0, 2) ff(k, 0, a3[i - 1]) {
			a[!o].p[c[t[j]][k] * a3[i - 1] + k] = j * a3[i - 1] + a[o].p[k];
		}
		o = !o;
	}
	ff(j, 0, a3[n]) pp("%d ", a[o].p[j]); hh;
}

Measured memory_bytes: 10620
#include <iostream>
#include <cstring>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <math.h>
#include <string>
using namespace std;

int main()
{
    int n;
    cin >> n;
    if(n<1000){
        cout << "ABC";
    }else{
        cout << "ABD";
    }
    
    return 0;
}

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

int main() {
	int n;
  cin >> n;
  int a;
  a = n % 1000;
  int c;
  c = 1000 - a;
  if (c == 1000) {
    cout << '0';
  } else {
    cout << c;
  }
	return 0;
}

Measured memory_bytes: 3604
int main()
{

    int W,H,x,y,r;
    scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
   
    if(x>=r&&y>=r&&x+r<=W&&y+r<=H){
        printf("Yes\n");}
    else{
        printf("No\n");}
    
    return 0;
}

Measured memory_bytes: 584
#include<bits/stdc++.h>
constexpr long long INFL = 1LL << 60;
constexpr int INF = 1 << 30;

using namespace std;

using ll = long long;
using P = tuple<int, int>;
using iarr = valarray<int>;

int main()
{
    int N;
    cin >> N;
    vector<int> A(N+1), B(N);
    for(int i = 0; i < N+1; ++i) cin >> A[i];
    for(int i = 0; i < N; ++i) cin >> B[i];

    ll cnt = 0;
    for(int i = 0; i < N+1; ++i){
        if(A[i] - B[i] > 0){
            cnt += B[i];
        }else{
            cnt += A[i];
            B[i] -= A[i];
            if(A[i+1] - B[i] > 0){
                cnt += B[i];
                A[i+1] -= B[i];
            }else{
                cnt += A[i+1];
                A[i+1] = 0;
            }
        }
    }

    cout << cnt << endl;

    return 0;
}



Measured memory_bytes: 1024
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main(){
    char s[11];
    scanf("%s",s);
    int n=0;
    for(int i=0;i<12;i++){
        if(s[i]!='\0') n++;
        else break;
    }
    
    int a[n];
    for(int i=0;i<n;i++){
        a[i]=(int)(s[i])-'0';
    }
    int min=1000;
    int error;
    for(int i=0;i<n-2;i++){
        error=abs(753-(100*a[i]+10*a[i+1]+a[i+2]));
        if(min>error){
            min=error;
        }
    }
    printf("%d\n",min);
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<vector>
#define ll long long
#define MAX 1000003
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define endl "\n"
using namespace std;

int main(){
	IOS;
	int n; cin>>n;
	vector<int> a(n+1),b(n);
	for(int i=0;i<=n;i++){
		cin>>a[i];
	}
	for(int i=0;i<n;i++){
		cin>>b[i];
	}	
	ll kills=0;
	for(int i=0;i<n;i++){
		if(a[i]+a[i+1]>b[i]){
			kills+=b[i];
			if(a[i]>b[i])
				a[i]-=b[i];
			else {
				a[i+1]=a[i+1]-(b[i]-a[i]);
			}
		}

		else {
			kills+=a[i]+a[i+1];
			a[i]=a[i+1]=0;
		}
	}
	cout<<kills<<endl;
return 0;
}

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

//typedef
//------------------------------------------
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define PB push_back
#define MP make_pair
#define SORT(c) sort((c).begin(),(c).end())
#define COUT(x) cout<<x<<endl

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

//constant
//--------------------------------------------
const double PI = acos(-1.0);
const LL MOD = 1e9 + 7;
const ULL INF= 1e20;

//function
//--------------------------------------------
LL gcd(LL, LL);
bool isEven(LL);
void coutY();
void coutN();

int main() {
	int a[4];
  REP(i,4)cin>>a[i];
  COUT(min(a[0],a[1])+min(a[2],a[3]));
}

LL gcd(LL a, LL b) {
	if (a == 0 || b == 0)return 0;
	if (a < b)swap(a, b);
	if (a % b == 0)return b;
	else gcd(b, a % b);
}
bool isEven(LL a) {
	return !((bool)(a % 2));
}
void coutY() {
	cout << "Yes" << endl;
	return;
}
void coutN() {
	cout << "No" << endl;
	return;
}


Measured memory_bytes: 256
import copy
N,M=map(int,input().split())
linkedBulb=[[] for i in range(N)]#各スイッチごとにつながってる電球
for i in range(M):
    S=[int(_) for _ in input().split()]
    for n,s in enumerate(S):
        if n==0:continue
        else:
            linkedBulb[s-1].append(i)
s=[1-int(i) for i in input().split()]
ans=0
for bit in range(2**N):
    start=copy.deepcopy(s)
    for j in range(N):
        if (bit>>j)&1:
            for todo in linkedBulb[j]:
                start[todo]=1-start[todo]
    if all(start):ans+=1
print(ans)


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

long	GCM(long A, long B) {
	while (B!=0) {
		A %=B;
		swap(A, B);
	}
	return A;
}

int	main() {
	int N;
	cin >>N;
	long T;
	cin >>T;
	for (int i=1; i<N; i++) {
		long TT;
		cin >>TT;
		T *= TT/GCM(T, TT);
	}
	cout <<T <<endl;
	return 0;
};


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

int n,k,s,t,x;
vector<int>e[100005];
int main(){
    scanf("%d",&n);
    //if(n==3)printf("Yes\n3\n2 1 2\n2 3 1\n2 2 3");else printf("No");
    t=n<<3|1;s=sqrt(t);if(s*s!=t){printf("No");return 0;}
    ++s;if(s&1){printf("No");return 0;}k=s>>1;
    for(int i=1;i<k;i++)for(int j=i+1;j<=k;j++)e[i].push_back(++x),e[j].push_back(x);
    printf("Yes\n%d",k);
    for(int i=1;i<=k;i++){
        printf("\n%d",e[i].size());
        for(int j=0;j<e[i].size();j++)printf(" %d",e[i][j]);
    }
    return 0;
}

Measured memory_bytes: 4608
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <map>
#include <vector>
using namespace std;
#define LL long long
const int N = 1e5+55;
int num[N];
int s[N];

struct node
{
	int val,num;
}b[5];

bool cmp(int a,int b)
{
	return num[a]>num[b];
}
int cnt=0;
int n;

void f(vector<int> a)
{
	for(int i=1;i<=1e5;i++){
		num[i]=0;
		s[i]=i;
	}

	for(int i=0;i<a.size();i++){
		num[a[i]]++;
	}
	sort(s+1,s+1+100000,cmp);
	b[++cnt].val=s[1];
	b[cnt].num=num[s[1]];
	b[++cnt].val=s[2];
	b[cnt].num=num[s[2]];
}

int main()
{
	scanf("%d",&n);
	vector<int> a,bb;
	for(int i=1;i<=n;i++){
		int x;scanf("%d",&x);
		if(i&1) a.push_back(x);
		else bb.push_back(x);
	}
	f(a);f(bb);
	int ans=0;
	for(int i=1;i<=2;i++){
		for(int j=3;j<=4;j++){
			if(b[i].val!=b[j].val){
				ans=max(ans,b[i].num+b[j].num);
			}
		}
	}
	printf("%d\n",n-ans);



}


Measured memory_bytes: 1660
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    int n; cin >> n;
    int cnt = 0, res = 0, cur, mini = n + 1;
    for (int i = 0; i < n; ++i) {
        cin >> cur;
        cnt += (cur < mini);
        mini = min(mini, cur);
    }
    cout << cnt << '\n';
    return 0;
}

Measured memory_bytes: 256
/***********************************************************************


    __       ____ ____   ___                 _  __  __           __   
   / /      |  _ \___ \ / _ \               | |/ _|/ _|          \ \  
  / /_____  | |_) |__) | | | |_      ___   _| | |_| |_ ____  _____\ \ 
 < <______| |  _ <|__ <| | | \ \ /\ / / | | | |  _|  _|_  / |______> >
  \ \       | |_) |__) | |_| |\ V  V /| |_| | | | | |  / /        / / 
   \_\      |____/____/ \___/  \_/\_/  \__,_|_|_| |_| /___|      /_/  
                                                                      
                                                                      

************************************************************************/

#include <bits/stdc++.h>

#define loop(i, a, b) for (int i = a; i < b; i++)
#define wh(x) \
    int x;    \
    cin >> x; \
    while (x--)
#define mkar(arr, n) \
    int arr[n];      \
    loop(i, 0, n) { cin >> arr[i]; }
#define print_ar(arr, n)                     \
    loop(i, 0, n) { cout << arr[i] << " "; } \
    cout << endl;
#define pii pair<int, int>
#define mci map<char, int>
#define endl "\n"
#define ll long long
#define ull unsigned long long
#define pb push_back
#define FIO                           \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL)
#define slow(x) this_thread::sleep_for(chrono::milliseconds(x));
#define setbitmsb(x) (int)log2(x)
#define setbitlsb(x) (int)log2(x & -x)
#define OJ                            \
    freopen("input.txt", "r", stdin); \
    freopen("output.txt", "w", stdout)

using namespace std;

void setBit(ull &num, int ind)
{
    num |= (1ULL << ind);
}
void unsetBit(ull &num, int ind)
{
    num &= (~(1ULL << ind));
}

int main()
{
    // FIO;
    // OJ;
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    int sum = 0;
    if (k >= a)
    {
        sum += a;
        k = k - a;
        if (k >= b)
        {
            sum += 0;
            k = k - b;
            if (k >= c)
            {
                sum -= c;
                k = k - c;
            }
            else
            {
                sum -= k;
            }
        }
        else
        {
            sum += (0);
        }
    }
    else
    {
        sum += k;
    }
    cout << sum << endl;
    return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;

#define x first
#define y second
#define pb push_back
#define eb emplace_back
#define rep(i,a,b) for(auto i=(a); i<(b); ++i)
#define REP(i,n) rep(i,0,n)
#define all(v) (v).begin(), (v).end()
#define rs resize
#define DBG(x) cerr << __LINE__ << ": " << #x << " = " << (x) << endl

const ld PI = acos(-1.0);
template<class T> using min_queue =
priority_queue<T, vector<T>, greater<T>>;
template<class T> int sz(const T &x) {
    return (int) x.size(); // copy the ampersand(&)!
}

template<class T> ostream& operator<<(ostream &os, vector<T> &v) {
    os << "\n[";
    for(T &x : v) os << x << ',';
    return os << "]\n";
}

struct pairhash {
    public:
    template<typename T1, typename T2>
    size_t operator()(const pair<T1, T2> &p) const {
        size_t lhs = hash<T1>()(p.x);
        size_t rhs = hash<T2>()(p.y);
        return lhs ^ (rhs+0x9e3779b9+(lhs<<6)+(lhs>>2));
    }
};



void run() {
	ll n;
	cin >> n;
	vi A1(n, 0), A2(n, 0);
	bool has1 = false;
	string s;
	cin >> s;
	for (ll i = 0; i < n; i++) {
		if (s[i] == '1') {
			A1[i] = 0; A2[i] = 0;
		} else if (s[i] == '2') {
			has1 = true;
			A1[i] = 1;
		} else {
			A1[i] = 0; A2[i] = 1;
		}
	}

	ll r1 = 0, r2 = 0;
	for (ll i = 0; i < n; i++) {
		if (((~(n-1))&i) == 0) {
			//cout << i << endl;
			//cout << n-1 << endl;
			//cout << ((~(n-1))&i) << endl;
			r1 ^= A1[i];
			r2 ^= A2[i];
		}
	}
	if (has1) {
		cout << r1 << endl;
	} else {
		if (r1 == 1) {
			cout << 1 << endl;
		} else {
			cout << 2*r2 << endl;
		}
	}

}

signed main() {
    // DON'T MIX "scanf" and "cin"!
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout << fixed << setprecision(20);
    run();
    return 0;
}


Measured memory_bytes: 17564
#include<cstdio>
#include<iostream>
#include<vector>
#include<set>
#include<queue>
#include<algorithm>
#include<utility>
using namespace std;
long long int a[100009],c[100009],ans;
vector<int> b,p;
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	for(int i=0;i<n;i++){
		b.push_back(a[(i+1)%n]-a[i]);
		p.push_back(a[(i+1)%n]-a[i]);
	}
	sort(p.begin(),p.end(),greater<int>());
	int ma=p[0];
	for(int i=0;i<n;i++){
		if( ( ma - b[i] ) % n != 0){cout<<"NO"<<endl;return 0;}
		else c[i] = ( ma - b[i] ) / n ;
		//cout<<i<<":"<<c[i]<<endl;
		ans+=c[i];
	}
	if(ans==0){
		if((a[0]*2)%(n*(n+1))==0)cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
		return 0;
	}
	if(ans != ma) cout<<"NO"<<endl;
	else{
		int check=a[0];
		check-=c[0]*n;
		for(int i=1;i<n;i++){
			check-=c[i]*(n-i);
		}
		if(check==0) cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
	return 0;
}

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

#define EPS 1e-7

int w,h;
char map[60][12];
char visited[60][12];
int okflag;

typedef struct {
	double x;
	int num;
} zyusin_t;

typedef struct {
	int min,max;
} range_t;

zyusin_t shindan_the_block(int x,int y);

void get_the_zyusin(range_t* range,zyusin_t* zyusin,int x,int y,char block) {
	if(x<0 || x>=w || y<0 || y>=h)return;
	if(visited[y][x] || map[y][x]!=block || !okflag)return;
	visited[y][x]=1;
	zyusin->x+=x+0.5;
	zyusin->num++;
	get_the_zyusin(range,zyusin,x-1,y,block);
	get_the_zyusin(range,zyusin,x+1,y,block);
	get_the_zyusin(range,zyusin,x,y-1,block);
	get_the_zyusin(range,zyusin,x,y+1,block);
	if(y>0 && map[y-1][x]!='.' && map[y-1][x]!=block && !visited[y-1][x]) {
		zyusin_t upzyusin;
		upzyusin=shindan_the_block(x,y-1);
		zyusin->x+=upzyusin.x*upzyusin.num;
		zyusin->num+=upzyusin.num;
	}
	if(y<h-1) {
		if(map[y+1][x]!='.' && map[y+1][x]!=map[y][x]) {
			if(x<range->min)range->min=x;
			if(range->max<x)range->max=x;
		}
	} else {
		if(x<range->min)range->min=x;
		if(range->max<x)range->max=x;
	}
}

zyusin_t shindan_the_block(int x,int y) {
	zyusin_t zyusin={0,1};
	range_t range;
	if(map[y][x]=='.')return zyusin;
	if(!okflag)return zyusin;
	zyusin.x=0;
	zyusin.num=0;
	range.min=range.max=x;
	get_the_zyusin(&range,&zyusin,x,y,map[y][x]);
	zyusin.x/=zyusin.num;
	if(zyusin.x<range.min+EPS || range.max+1<zyusin.x+EPS)okflag=0;
	return zyusin;
}

int main(void) {
	int i;
	while(scanf("%d%d",&w,&h)==2 && w!=0 && h!=0) {
		for(i=0;i<h;i++)scanf("%s",map[i]);
		memset(visited,0,sizeof(visited));
		okflag=1;
		for(i=0;i<w;i++) {
			if(map[h-1][i]!='.') {
				shindan_the_block(i,h-1);
				break;
			}
		}
		puts(okflag?"STABLE":"UNSTABLE");
	}
	return 0;
}

Measured memory_bytes: 600
import sys
input = sys.stdin.readline


class Node:
    def __init__(self, val):
        self.val = val
        self.next = None
        self.parent = None


class Stack:
    def __init__(self):
        self.head = Node(None)
        self.top = self.head

    def push(self, node: Node):
        if self.top == self.head:
            self.head.next = node
            node.parent = self.head
            self.top = node
        else:
            self.top.next = node
            node.parent = self.top
            self.top = node

    def pop(self):
        if self.top == self.head:
            return None
        else:
            _tmp = self.top
            self.top = self.top.parent
            self.top.next = None
            return _tmp


ops = input().strip().split()

stack = Stack()

for op in ops:
    if op == "+":
        _a = stack.pop().val
        _b = stack.pop().val
        stack.push(Node(_a + _b))
    elif op == "-":
        _a = stack.pop().val
        _b = stack.pop().val
        stack.push(Node(_b - _a))
    elif op == "*":
        _a = stack.pop().val
        _b = stack.pop().val
        stack.push(Node(_a * _b))
    else:
        stack.push(Node(int(op)))

print(stack.pop().val)



Measured memory_bytes: 5612
#include <iostream>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
using namespace std;
int main()
{
    char x[4];
    cin>>x;
    if(strcmp(x,"BBB")==0||strcmp(x,"AAA")==0)
        cout<<"No";
    else
        cout<<"Yes";
return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll z=1000000007,n;
ll mini(ll x,ll y)
{
	if(x<y)
		return x;
	else
		return y;
}
int main()
{
	ll k;
	cin>>n>>k;
	std::vector<ll> h(n);
	for (int i = 0; i < n; ++i)
	{
		cin>>h[i];
	}
	std::vector<ll> dp(n,pow(10,17));
	dp[n-1]=0;
	dp[n-2]=fabs(h[n-1]-h[n-2]);
	for (int i = n-3; i >=0 ; --i)
	{
		ll j=i+1;
		while(j<=i+k && j<=n-1)
		{
			dp[i]=mini(dp[i],dp[j]+fabs(h[j]-h[i]));
			++j;
		}
	}
	
	cout<<dp[0]<<"\n";
}

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

using namespace std;

int main(){
  int a, b, c, x, y, need_a, need_b;
  cin >> a >> b >> c >> x >> y;
  
  int min = 1000000000;
  int maxc = max(x, y)*2;
  for(int i=0;i<=maxc;i++){
    need_a = x - i/2;
    need_b = y - i/2;
    if(need_a<0)need_a=0;
    if(need_b<0)need_b=0;
    int price = need_a*a + need_b * b + i *c;
    if(price < min)min = price;
  }
  //cout << need_a << " " << need_b << endl;
  cout << min << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include<cstdlib>
#include<queue>
#include<set>
#include<vector>
#include<string>
#include<algorithm>
#include<sstream>
#include<cmath>
#include<stack>
#include<map>
#include<cstdio>
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
#define mp make_pair
#define pb push_back
#define P pair<int,int>
#define ll __int64
int h,r;
int main(){
cin>>h>>r;
if(h+r>0)cout<<1;
else if(h+r<0)cout<<-1;
else cout<<0;
cout<<endl;
	return 0;
}



Measured memory_bytes: 3100
#include <iostream>

using namespace std;

int main()
{
	int box[3];

	cin >> box[0] >> box[1] >> box[2];

	for(int i = 1; i < 3; i++){
		int j = i;
		while(1 <= j && box[j - 1] > box[j]){
			int tmp = box[j];
			box[j] = box[j - 1];
			box[j - 1] = tmp;
			j--;
		}
	}

	cout << box[0] << " " << box[1] << " " << box[2] << endl;;

	return 0;
}


Measured memory_bytes: 3116
// Charan Sriramula

#include<bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long int ll;

const ll lg=14;
const ll N=1e5+5;
const ll INF=1e9;
const ll mod=1e9+7;
const double PI = 3.14159265358979323846;

#define ints(n) scanf("%d",&n)
#define intp(n) printf("%d\n",n)
#define longs(n) scanf("%lld",&n)
#define longp(n) printf("%lld\n",n)

#define f first
#define s second
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define mp(x,y) make_pair(x,y)
#define GCD(a,b) __gcd((a),(b))
#define all(v) v.begin(),v.end()
#define bits(x) __builtin_popcount(x)
#define LCM(a,b) ((a)*(b))/GCD((a),(b))
#define ms(dp,val) memset(dp,val,sizeof(dp))
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
template<typename T> T power(T x,T y,ll m){T ans=1;while(y>0){if(y&1LL) ans=(ans*x)%m;y>>=1LL;x=(x*x)%m;}return ans%m;}

stack<ll> topo;
vector<ll> g[N];
ll n,m,u,v,vis[N],dis[N];

void DFS(ll cur)
{
  vis[cur]=1;
  for(auto i:g[cur])
  {
    if(vis[i]){continue;}
    DFS(i);
  }
  topo.push(cur);
}

int main()
{
  cin>>n>>m;
  while(m--)
  {
    cin>>u>>v;
    g[u].pb(v);
  }
  for(ll i=1;i<=n;i++)
  {
    dis[i]=-INF;
    if(vis[i]){continue;}
    DFS(i);
  }
  while(topo.size())
  {
    ll cur=topo.top();
    topo.pop();
    if(dis[cur]==-INF){dis[cur]=0;}
    for(auto i:g[cur]){dis[i]=max(dis[i],dis[cur]+1);}
  }
  ll maxi=0;
  for(ll i=1;i<=n;i++){maxi=max(maxi,dis[i]);}
  cout<<maxi<<endl;
}


Measured memory_bytes: 10112
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
inline int read()
{
	int x;char c;
	while((c=getchar())<'0'||c>'9');
	for(x=c-'0';(c=getchar())>='0'&&c<='9';)x=x*10+c-'0';
	return x;
}
#define MN 100000
int r[MN+5],t[MN+5],a[MN+5],s[MN+5],sl,sr,f[MN+5];
vector<int> v[MN+5];
bool cmp(int x,int y){return a[x]<a[y];}
int gf(int k){return f[k]?f[k]=gf(f[k]):k;}
int main()
{
	int x,k,q,i,j,ss=0;
	x=read();k=read();
	for(i=1;i<=k;++i)r[i]=read();
	q=read();
	for(i=1;i<=q;++i)
	{
		t[i]=read();a[i]=read();s[i]=i;
		v[upper_bound(r+1,r+k+1,t[i])-r-1].push_back(i);
	}
	sort(s+(sl=1),s+(sr=q)+1,cmp);
	for(i=0;i<v[0].size();++i)t[v[0][i]]=max(a[v[0][i]]-t[v[0][i]],0);
	for(i=1;i<=k;++i)
		if(i&1)
		{
			ss-=r[i]-r[i-1];
			if(a[s[sl]]+ss<=0)
			{
				for(j=sl;j<=sr&&a[s[j]]+ss<=0;++j);
				a[s[--j]]=-ss;
				while(sl<j)f[s[sl++]]=s[j];
			}
			for(j=0;j<v[i].size();++j)
				t[v[i][j]]=min(a[gf(v[i][j])]+ss+t[v[i][j]]-r[i],x);
		}
		else
		{
			ss+=r[i]-r[i-1];
			if(a[s[sr]]+ss>=x)
			{
				for(j=sr;j>=sl&&a[s[j]]+ss>=x;--j);
				a[s[++j]]=x-ss;
				while(sr>j)f[s[sr--]]=s[j];
			}
			for(j=0;j<v[i].size();++j)
				t[v[i][j]]=max(a[gf(v[i][j])]+ss-t[v[i][j]]+r[i],0);
		}
	for(i=1;i<=q;++i)printf("%d\n",t[i]);
}

Measured memory_bytes: 7168
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

class Main{
    static List<Integer> edges[];
    static List<Integer> edge = new ArrayList<>();
    static boolean[] isLeaf;

    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        // 小さい順に挿入
        int n = scan.nextInt();
        edges = new ArrayList[n];
        for(int i=0;i<n;++i)edges[i]=new ArrayList<>();
        for(int i=0;i<n-1;++i){
            int v = scan.nextInt()-1;
            int u = scan.nextInt()-1;
            edges[v].add(u);edges[u].add(v);
        }
        isLeaf = new boolean[n];
        for(int i=0;i<n;++i)if(edges[i].size()==1)isLeaf[i]=true;
        for(int i=0;i<n;++i){
            if(isLeaf[i])continue;
            int cnt = 0;
            for(int u : edges[i])if(!isLeaf[u])++cnt;
            if(cnt<=1)edge.add(i);
            if(cnt>2){
                System.out.println(-1);
                return;
            }
        }
        List<Integer> ans = new ArrayList<>();
        if(edge.size()==2){
            for(int v : edge){
                List<Integer> list = new ArrayList<>();
                list.add(0);
                int bef=-1;
                int u = v;
                boolean flag=true;
                while(flag){
                    list.add(edges[u].size()-2);
                    flag=false;
                    for(int w :edges[u])if(!isLeaf[w]&&w!=bef){
                        flag=true;bef=u;u=w;break;
                    }
                }
                list.add(0);
                if(ans.size()==0)ans=list;
                else{
                    for(int i=0;i<ans.size();++i){
                        if(ans.get(i)==list.get(i))continue;
                        else if(ans.get(i)> list.get(i))ans=list;
                        break;
                    }
                }
            }
        }else{
            ans = new ArrayList<>();
            ans.add(0);
            if(edge.size()>0)ans.add(edges[edge.get(0)].size()-2);
            ans.add(0);
        }



        List<Integer> res = new ArrayList<>();
        int num = 1;
        for(int k : ans){
            for(int i=0;i<k;++i)res.add(1+num++);
            res.add(num++ -k);
        }
        for(int k : res)System.out.print(k+" ");
        System.out.println();

    }
}

Measured memory_bytes: 103660
import numpy as np
import copy


def bw(cell):
    if(cell=='.'):
        return(0)
    else:
        return(1)

def getBin(number, total):
    return bin(number)[2:].zfill(total)

para_line = list(map(int,input().split(' ')))
board = np.zeros((para_line[0],para_line[1]))
for n in range(para_line[0]):
    board[n] = np.array(list(map(bw,list(input()))))

fil_h_num = [list(map(int, getBin(i, para_line[0]))) for i in range(2**para_line[0])]

fil_h = []

for i in fil_h_num:
    fil_h.append(list(map(bool,i)))

fil_w_num = [list(map(int, getBin(i, para_line[1]))) for i in range(2**para_line[1])]

fil_w = []

for i in fil_w_num:
    fil_w.append(list(map(bool,i)))

cnt = 0

for f in fil_h:
    now_board = copy.deepcopy(board[f])
    for w in fil_w:
        if(int(np.sum(now_board[:,w]))==para_line[2]):
            cnt += 1
print(cnt)


Measured memory_bytes: 27284
#include<stdio.h>
#include<string.h>
#define LEN 100005

/* プロセスを表す構造体 */
typedef struct pp {
  char name[100];
  int t;
} P;

P Q[LEN];
int head, tail, n;

void enqueue(P x) {
  Q[tail] = x;
  tail = (tail + 1) % LEN;
}

P dequeue() {
  P x = Q[head];
  head = (head + 1) % LEN;
  return x;
}

int min(int a, int b) { return a < b ? a : b; }  /* 最小値を返す */

int main() {
  int elaps = 0, c;
  int i, q;
  P u;
  scanf("%d %d", &n, &q);

  /* 全てのプロセスをキューに順番に追加する */
  for ( i = 1; i <= n; i++ ) {
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }
  head = 1; tail = n + 1;

  /* シミュレーション */
  while ( head != tail ) {
    u = dequeue();
    c = min(q, u.t);  /* q または必要な時間 u.t だけ処理を行う */
    u.t -= c;  /* 残りの必要時間を計算 */
    elaps += c;  /* 経過時間を計算 */
    if ( u.t > 0 ) enqueue(u);  /* 処理が完了していなければキューに追加 */
    else printf("%s %d\n", u.name, elaps);
  }

  return 0;
}


Measured memory_bytes: 12756
import java.util.Scanner;

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

            long mod = (long) (1e9 + 7);

            long[] dp = new long[S + 1];
            dp[S] = 1;
            for (int sum = S; sum >= 0; sum--) {
                for (int add = 3; sum + add <= S; add++) {
                    if (dp[sum + add] <= 0) {
                        continue;
                    }
                    dp[sum] += dp[sum + add];
                    dp[sum] %= mod;
                }
            }

            System.out.println(dp[0]);
        }
    }
}


Measured memory_bytes: 27264
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>
using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)
#define eprintf(...) fprintf(stderr, __VA_ARGS__)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) {
    for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }
    putchar('\n');
}

int N;
VI G[100111];
int par[100111];
int state[100111];

void MAIN() {
    scanf("%d", &N);
    REP (i, N-1) {
	int x, y;
	scanf("%d%d", &x, &y);
	G[x].push_back(y);
	G[y].push_back(x);
    }

    if (N <= 1) {
	puts("0");
    } else if (N == 2) {
	puts("1");
    } else {
	int ans = N;

	VI ord;
	ord.reserve(N);

	REP (_, 2) {
	    if (_ == 0) {
		ord.push_back(0);
		REP (__, 2) {
		    ord[0] = ord.back();
		    ord.resize(1);
		    par[ord[0]] = -1;
		    REP (i_, N) {
			int v = ord[i_];
			EACH (e, G[v]) if (*e != par[v]) {
			    par[*e] = v;
			    ord.push_back(*e);
			}
		    }
		}
	    } else {
		ord[0] = ord.back();
		ord.resize(1);
		par[ord[0]] = -1;
		REP (i_, N) {
		    int v = ord[i_];
		    EACH (e, G[v]) if (*e != par[v]) {
			par[*e] = v;
			ord.push_back(*e);
		    }
		}
	    }

	    int tmp = 1;
	    REP (i_, N) {
		int v = ord[N-1-i_];
		int c = G[v].size();
		if (par[v] != -1) c--;
		int s[4] = {};
		EACH (e, G[v]) if (*e != par[v]) {
		    s[state[*e]]++;
		}

		if (G[v].size() == 1u) {
		    state[v] = 0;
		} else if (s[0] >= 2) {
		    tmp += s[0] - 1;
		    state[v] = 1;
		} else {
		    state[v] = (s[1] > 0);
		}
	    }
	    amin(ans, tmp);
	}

	printf("%d\n", ans);
    }
}

int main() {
    int TC = 1;
//    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}



Measured memory_bytes: 7424
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <set>
#include <iomanip>
#include <stdio.h>
#include <sstream>
#include <string>
using namespace std;
int main(void){
    long long int h, w;
    cin>>h>>w;
    if(h==1||w==1){
        cout<<1<<endl;
    }else if((h*w)%2==0){
        cout<<h*w/2<<endl;
    }else{
        cout<<h*w/2 +1<<endl;
    }
}


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

int N,sum=0;
int main(){
    cin >> N;
    long long ans=0;
    for(int i=1;i<=N;i++){
        long long t=N/i;
        ans+=(t*(t+1)/2)*i;
        //for(int j=1;j<=N;j++){
        //if(i%j==0){
        //    sum+=i;
        //    }
        //}
    }
    cout << ans << endl;
}

Measured memory_bytes: 3616
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
	public static void main(String[]args) {
		try(Scanner scan = new Scanner(System.in)){
			long mod = (long)1e9+7;
			int N = scan.nextInt();
			int M = scan.nextInt();
			int[]a = new int[M];
			int[]s = new int [N];
			for(int i = 0;i<M;i++) {
				a[i] = scan.nextInt();
				s[a[i]-1]++;
			}
			ArrayList<Integer>sb = new ArrayList<Integer>();
			
			for(int i = 0;i<N-1;i++) {
				if(s[i]==1&&s[i+1]==1) {
					System.out.println(0);
					System.exit(0);
				}
			}
			
			int count = 1;
			for(int i = 0;i<N;i++) {
				if(s[i]==1&&count!=0) {
					sb.add(count-1);
					count=0;
				}else if(s[i]==0) {
					count++;
				}
				if(i==N-1) {
					sb.add(count-1);
				}
			}
			COMinit();
			long goukei = 1;
			
			for(Integer i:sb) {
				//System.out.println(i);
				if(i==0)continue;
				int k = i/2;
				long sum = 0;
				for(int j = 0;j<=k;j++) {
					sum = (sum+COM(i-j,j))%mod;
					//System.out.println(COM(i-j,j));
				}
				
				goukei = (goukei*sum)%mod;
			}
			//System.out.println();
			System.out.println(goukei);
			
			
			
			
		}
		
		
	}
	
	
	//拡張ユークリッドでの逆元の求め方でnCkをつくる、前処理必須。
	
	static  int MAX = 510000;
	static  int MOD = 1000000007;

	 static long[] fac = new long[MAX]; 
	 static long[] finv = new long[MAX]; 
	 static long[] inv = new long[MAX]; 

	// テーブルを作る前処理
	static 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;
	    }
	}

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

}


Measured memory_bytes: 71440
/* topological_sort_DFS.cpp

    verified: AOJ GRL_4_B Topological Sort
    http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_4_B&lang=ja
*/

#include <bits/stdc++.h>
using namespace std;

struct Edge {
    int to;
};
using Graph = vector<vector<Edge>>;

/* topo_sort(G): グラフG をトポロジカルソート
    返り値: トポロジカルソートされた頂点番号
    計算量: O(|E|+|V|)
    返り値のサイズがグラフより小さければ閉路が存在する
    （大きなグラフではスタックオーバーフローの可能性があるので、dfsではなくbfsの方が良い）
 */
vector<int> topo_sort(const Graph &G) {  // bfs
    int n = (int)G.size();
    vector<int> ans(n);

    vector<int> ind(n);            // ind[i]: 頂点iに入る辺の数(次数)
    for (int i = 0; i < n; i++) {  // 次数を数えておく
        for (auto e : G[i]) {
            ind[e.to]++;
        }
    }
    queue<int> que;
    for (int i = 0; i < n; i++) {  // 次数が0の点をキューに入れる
        if (ind[i] == 0) {
            que.push(i);
        }
    }
    while (!que.empty()) {  // 幅優先探索
        int now = que.front();

        que.pop();
        for (auto e : G[now]) {
            ind[e.to]--;
            if (ind[e.to] == 0) {
                que.push(e.to);
                ans[e.to] = now + 1;
            }
        }
    }
    return ans;
}

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

    int N, M;
    cin >> N >> M;
    int V = N;
    int E = N - 1 + M;
    vector<int> s(E), t(E);
    for (int i = 0; i < E; i++) {
        cin >> s.at(i) >> t.at(i);
        s[i]--, t[i]--;
    }

    Graph G(V);
    for (int i = 0; i < E; i++) {
        G[s[i]].push_back({t[i]});
    }
    vector<int> ans = topo_sort(G);

    for (auto i : ans) {
        cout << i << endl;
    }

    return 0;
}


Measured memory_bytes: 7416
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll MOD = 1e9+7;

#define vec     vector<int>
#define vecll   vector<ll>
#define vec2    vector<vector<int>>
#define vec2ll  vector<vector<ll>>
#define vpair   vector<pair<int, int>>
#define vpairll vector<pair<ll, ll>>

#define rep(i,n)         for(int i=(int)0; i<(int)n; i++)
#define REP(i,m,n)       for(int i=(int)m; i<(int)n; i++)
#define arr(var, n)      vec var(n); rep(i,n){cin >> var[i];}
#define arrll(var, n)    vecll var(n); rep(i,n){cin >> var[i];}
#define all(var)         (var).begin(), (var).end()
#define sortall(var)     sort(all(var))
#define mpair(v1, v2)    make_pair(v1, v2);
#define prt(var)         cout << var << "\n"
#define prtd(n, var)     cout << fixed << setprecision(n) << var << "\n"
#define prt2(v1, v2)     cout << v1 << " " << v2 << "\n"
#define prt3(v1, v2, v3) cout << v1 << " " << v2 << " " << v3 << "\n"
#define prtall(var)      rep(i,var.size()){cout << var[i] << " ";} cout << "\n"

//----------------------------------------------------------------

int main(void) {
  string s;
  cin >> s;

  int a=0, b=0;
  rep(i,s.size()){
    if(s[i]=='0') a++;
    else b++;
  }

  prt(2*min(a,b));

}


Measured memory_bytes: 512
#include <stdio.h>

int main(void) {
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    if(a >= b && a >= c) {
        a *= 10;
    } else if(b > a && b > c) {
        b *= 10;
    } else {
        c *= 10;
    }
    printf("%d\n", a + b + c);
    return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
    public static int MAX = 100000;
    public static boolean isPrime(int num){
        if(num < 2)
            return false;
        if(num == 2)
            return true;
        if(num % 2 ==0)
            return false;
        for(int i = 3;i * i <= num;i += 2){
            if(num % i == 0)
                return false;
        }
        return true;
    }
    public static void main(String[] args) {
        int n;
        int count = 0;
        int[] A = new int[MAX];
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        for(int i = 0;i < n;i ++)
            A[i] = sc.nextInt();
        for(int j = 0;j < n;j ++){
            boolean flag = isPrime(A[j]);
            if(flag)
                count ++;
        }
        System.out.println(count);
    }
}


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

//////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////// ここからコピペ ////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////

// N*M型行列
template<typename T = int64_t>
class Matrix {
private:
	class RowVector {
	private:
		std::vector<T> container_;
	
	public:
		RowVector(const int column_size)
			: container_(column_size){}
		T& operator[](const int c) { return container_[c]; }
	};

	std::vector<RowVector> container_;

public:
	const int N, M;
	Matrix(const int row_size, const int column_size)
		: N(row_size), M(column_size), container_(row_size, RowVector(column_size)){}
	Matrix(Matrix<T>&& mat)
		: N(mat.N), M(mat.M), container_(std::move(mat.container_)){}
	Matrix(Matrix<T>& mat)
		: N(mat.N), M(mat.M), container_(mat.container_){}
	RowVector& operator[](const int r) { return container_[r]; }

	Matrix<T> operator+(Matrix<T>& mat)
	{
		Matrix<T> ret{*this};
		for (int r_i{}; r_i < N; r_i++)
			for (int c_i{}; c_i < M; c_i++)
				ret[r_i][c_i] += mat[r_i][c_i];
		return std::move(ret);
	}
	Matrix<T> operator-(Matrix<T>& mat)
	{
		Matrix<T> ret{*this};
		for (int r_i{}; r_i < N; r_i++)
			for (int c_i{}; c_i < M; c_i++)
				ret[r_i][c_i] -= mat[r_i][c_i];
		return std::move(ret);
	}
	Matrix<T> operator*(Matrix<T>& mat)
	{
		Matrix<T> ret(this->N, mat.M);
		for (int r_i{}; r_i < this->N; r_i++)
			for (int c_i{}; c_i < mat.M; c_i++)
				for (int l_i{}; l_i < this->M; l_i++)
					ret[r_i][c_i] += (*this)[r_i][l_i] * mat[l_i][c_i];
		return std::move(ret);
	}
	std::vector<T> operator*(std::vector<T>& vec)
	{
		std::vector<T> ret(N);
		for (int r_i{}; r_i < N; r_i++)
			for (int c_i{}; c_i < M; c_i++)
				ret[r_i] += (*this)[r_i][c_i] * vec[c_i];
		return std::move(ret);
	}
};

//////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////// ここまでコピペ ////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=3035
int main()
{
	int n, m, l;
	scanf("%d%d%d", &n, &m, &l);
	Matrix<> A(n, m), B(m, l);
	for (int i{}; i < n; i++)
		for (int j{}; j < m; j++)
			scanf("%lld", &A[i][j]);
	for (int i{}; i < m; i++)
		for (int j{}; j < l; j++)
			scanf("%lld", &B[i][j]);
	Matrix<> C(A * B);
	for (int i{}; i < n; i++)
		for (int j{}; j < l; j++)
			printf("%lld%c", C[i][j], j == l - 1? '\n': ' ');
	return 0;
}


Measured memory_bytes: 3372
#include <bits/stdc++.h>
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end() 
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define INF 1000000000
using namespace std;
typedef long long ll;

int main() {
    string SL[4] = {"Sunny", "Cloudy", "Rainy", "Sunny"};
    string s;
    cin >> s;

    REP(i, 3){
        if(SL[i] == s) cout << SL[i+1] << endl;
    }
}

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

using namespace std;

#define ll long long 

int const N = 1e5 + 20;
int const INF = 1e9 + 7;

ll t, memo[N][5], k;
 


int main(){
	
	cin>>t;
	
	cin>>memo[0][0]>>memo[0][1]>>memo[0][2];
	
	for(int i = 1; i < t; ++i){
		for(int j: {0, 1, 2}){
			cin>>k;
			memo[i][j] = max(memo[i-1][(j+1)%3] + k, memo[i-1][(j+2)%3] + k);
		}
	}
	
	cout<<max(max(memo[t-1][0], memo[t-1][1]), memo[t-1][2]);
	return 0;
}


Measured memory_bytes: 7476
package main

import (
	"bufio"
	"fmt"
	"os"
)

const (
	NO  = "No"
	YES = "Yes"
)

func lib_TernaryOPString(ok bool, v1, v2 string) string {
	if ok {
		return v1
	}
	return v2
}
func main() {
	scanner := bufio.NewScanner(os.Stdin)
	const initialBufSize = 4096
	const maxBufSize = 1000000
	scanner.Buffer(make([]byte, initialBufSize), maxBufSize)
	scanner.Split(bufio.ScanWords)
	var S string
	scanner.Scan()
	S = scanner.Text()
	var T string
	scanner.Scan()
	T = scanner.Text()
	fmt.Println(solve(S, T))
}
func solve(S string, T string) string {
	return lib_TernaryOPString(S == T[:len(T)-1], YES, NO)
}


Measured memory_bytes: 1760
'use strict'
process.stdin.resume()
process.stdin.setEncoding('utf8')
process.stdin.on('data', function hoge(input) {
  var resu = input.split(' ').map(Number)
  resu.sort(
    function(a, b) {
      return (a < b ? -1 : 1)
    }
  )
  console.log(resu.join(" "))
  return resu
})

Measured memory_bytes: 15484
# -*- coding: utf-8 -*-
import math
K = int(input())

N = 50
As = [N-1 for _ in range(N)]
ind = 0

modk = K % 50
L = K // 50
base = 49 + L - modk

ans = []

if modk != 0:
    for i in range(N):
        if i >= N - modk:
            ans.append(base + N + 1)
        else:
            ans.append(base)
    # for i in range(0,modk,1):
    #     ans.append(base + N + 1)
    # for i in range(modk,N,1):
    #     ans.append(base)
else:
    for i in range(N):
        ans.append(49 + L)
# for k in range(K):
#     for i in range(N):
#         As[i] -= 1
#     As[ind] += N + 1
#     ind += 1
#     ind = ind % N
# print(N)
# print(*As)
print(N)
print(*ans)


Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int s[100010]={0},a[100010]={0},b[100010]={0};
int main()
{
    int n,i,x,y,xx,yy;
    cin >> n;
    x=y=xx=yy=0;
    for(i=0;i<n;i++)
    {
        cin >> s[i];
        if(i%2==0){
            a[s[i]]++;
            if(a[s[i]]>x)
            {
                x=a[s[i]];
                xx=s[i];
            }
        }
        else{
            b[s[i]]++;
            if(b[s[i]]>y)
            {
                y=b[s[i]];
                yy=s[i];
            }
        }
    }
    int m;
    if(xx==yy)
    {
        if(x+y==n)
            m=n/2;
        else
        {
            int x1,y1;
            x1=y1=0;
            for(i=0;i<n;i++)
            {
                if(i%2==0){
                    if(a[s[i]]>x1 && s[i]!=xx){
                        x1=a[s[i]];
                    }
                }
                else{
                    if(b[s[i]]>y1 && s[i]!=yy){
                        y1=b[s[i]];
                    }
                }
            }
            m=n-x-y1;
            if(n-x1-y<m)
                m=n-x1-y;
        }
    }
    else
        m=n-x-y;
    cout << m << endl;
    return 0;
}


Measured memory_bytes: 1408