akhauriyash/Code-Regression huggingface dataset:
#include <iostream>

using namespace std;

int main(){
    /*
    "... It can be shown that the objective is always achievable regardless of the values of the integers x and y."
    wait, did anyone talked about a proof? :P
    well, its simple. there are three possibilities.
    x < y:
        press the button A until achiving Y
    x = y:
        no action is needed
    x > y:
        lets press the button B. now we have -x < y. head to the first possibility.
    */

    // I think this code could be smaller, with a proof.

    int x, y;
    cin >> x >> y;

    if (x < 0 and y < 0) {
        if (x < y){
            cout << y - x << endl;
        } else if (x == y){
            cout << 0 << endl;
        } else {
            cout << 1 + (0 - y - (0 - x)) + 1 << endl;
        }
    } else if (x < 0 and y == 0){
        cout << 0 - x << endl;
    } else if (x < 0 and y > 0){ // Sorry Shayan. I saw the test cases!
        if (0 - x < y){
            cout << 1 + (y - (0 - x)) << endl;
        } else if (0 - x == y){
            cout << 1 << endl;
        } else {
            cout << (0 - y) - x + 1 << endl;
        }
    } else if (x == 0 and y < 0){
        cout << (0 - y) + 1 << endl;
    } else if (x == 0 and y == 0){
        cout << 0 << endl;
    } else if (x == 0 and y > 0){
        cout << y << endl;
    } else if (x > 0 and y < 0){
        if (0 - x < y){
            cout << 1 + (y + x) << endl;
        } else if (0 - x == y){
            cout << 1 << endl;
        } else {
            cout << (0 - y) - x + 1 << endl;
        }
    } else if (x > 0 and y == 0){
        cout << 1 + x << endl;
    } else {
        if (x < y){
            cout << y - x << endl;
        } else if (x == y){
            cout << 0 << endl;
        } else {
            cout << 1 + (x - y) + 1 << endl; // Sorry Shayan :)
        }
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define LL unsigned long long
#define st first
#define nd second
#define endl '\n'
using namespace std;
const int N=1e5+5;
int n,m;
LL x[N],y[N],mod=1e9+7;
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin>>n>>m;
	for(int i=0;i<n;++i)
		cin>>x[i];
	for(int i=0;i<m;++i) 
		cin>>y[i];
	LL xtotal=0,ytotal=0,lastx=0,lasty=0;
	for(int i=1;i<n;++i) {
		xtotal=(xtotal+lastx+(x[i]-x[i-1])*i)%mod;
		lastx=(lastx+(x[i]-x[i-1])*i)%mod;
	}
	for(int i=1;i<m;++i) {
		ytotal=(ytotal+lasty+(y[i]-y[i-1])*i)%mod;
		lasty=(lasty+(y[i]-y[i-1])*i)%mod;
	}
	cout<<(xtotal*ytotal)%mod<<endl;
}

Measured memory_bytes: 1792
class Dice:

    def __init__(self):
        self._top = 1
        self._front = 2
        self._side = 3
        self._sum = 1

    def to_north(self):
        tmp = self._top
        self._top = self._front
        self._front = 7 - tmp 
        self._sum += self._top

    def to_east(self):
        tmp = self._top
        self._top = 7 - self._side
        self._side = tmp
        self._sum += self._top

    def to_west(self):
        tmp = self._top
        self._top = self._side
        self._side = 7 - tmp
        self._sum += self._top

    def to_south(self):
        tmp = self._top
        self._top = 7 - self._front
        self._front = tmp
        self._sum += self._top

    def to_right(self):
        tmp = self._front
        self._front = self._side
        self._side = 7 - tmp
        self._sum += self._top

    def to_left(self):
        tmp = self._front
        self._front = 7 - self._side
        self._side = tmp
        self._sum += self._top

    def get_sum(self):
        return self._sum

if __name__ == '__main__':
    d = ['North', 'East', 'South', 'West', 'Right', 'Left']

    while True:
        dice = Dice()
        n = input()
        if n == 0:
            break

        for i in xrange(n):
            t = raw_input()
            if t == d[0]:
                dice.to_north() 
            elif t == d[1]:
                dice.to_east()
            elif t == d[2]:
                dice.to_south()
            elif t == d[3]:
                dice.to_west()
            elif t == d[4]:
                dice.to_right()
            elif t == d[5]:
                dice.to_left()

        print(dice.get_sum())

Measured memory_bytes: 4316
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <string>
#include <set>
#define INF 100000000000
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define LOOP(i,N) for(int i=0;i<N;i++)
#define LOOP1(i,N) for(int i=1;i<=N;i++)
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;
#define int long long
/* define/include */

signed main(){
  int S;
  cin >> S;
  int A=S/1000;
  int B=(S/100)%10;
  int C=(S/10)%10;
  int D=S%10;
  int V[4]={S/1000,(S/100)%10,(S/10)%10,S%10};
  for(int i=0;i<(1<<4);i++){
    //000 ~ 100
    int s=V[0];
    // cout << i << ":" << s << endl;
    for(int j=0;j<3;j++){
      if(i & (1<<j)){
        // j桁目のtrue
        s+=V[j+1];
        // cout << "." << j << "+:" << s << endl;
      }else{
        s-=V[j+1];
        // cout << "." << j << "-:" << s << endl;
      }
    }if(s==7){
      cout << V[0];
      for(int j=0;j<3;j++){
        if(i & (1<<j)) cout << "+" << V[j+1];
        else          cout << "-" << V[j+1];
      }
      cout << "=7";
      return 0;
    }
  }
  cout << "Err";
  return 0;
}


Measured memory_bytes: 256
N = int(input())
a = list(map(int,input().split()))

ans = 2*10**9
allsum = sum(a)
snukesum = 0

for n in range(1,N):
  snukesum += a[n-1]
  ans_candidate = abs(2*snukesum- allsum)
  if ans > ans_candidate:
    ans = ans_candidate
    
print(ans)


Measured memory_bytes: 23792
using System;

namespace B___Christmas_Eve_Eve
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var p = new int[n];
            var sum = 0;
            var max = 0;
            for(var i=0; i<n; i++)
            {
                p[i]=int.Parse(Console.ReadLine());
                sum += p[i];
                max = Math.Max(max, p[i]);
            }
            Console.WriteLine((sum - max) + (max / 2));
        }
    }
}

Measured memory_bytes: 11092
n = int(input())
li = list(map(int,input().split()))
cnt = 0
li.sort()
if len(set(li)) == 1:
        cnt = 0
elif li[int(n/2 - 1)] == li[int(n/2)]:
        cnt = 0
else:
        cnt = li[int(n/2)] - li[int(n/2 -1)]
print(cnt)

Measured memory_bytes: 14004
#include <iostream>

using namespace std;

int main()
{
    long int N, K;
    cin >> N >> K;

    long int ans = 0;
    long int i;
    for (i = K; i <= N + 1; i++) {
        long int tmp = (i * i - i)/2;
        long int min = tmp;
        long int max = i * N - tmp;



        ans += (max - min + 1);

        if (ans >= 1000000007) {
            long int mod = ans % 1000000007;
            ans = mod;
        }


    }

    cout << ans;

    return 0;
}

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

vector<int> forintinput(int n) {
	vector<int> x;
	for(int i = 0;i < n;i++){
		int ia;
		cin >> ia;
		x.push_back(ia);
	}
	return x;
}
int main(){
	int a,b,c,k;
	cin >> a >> b >> c >> k;
	if(k <= a) cout << k << endl;
	else if(k <= a + b) cout << a << endl;
	else cout << a - (k - a - b) << endl;
	return 0;
}

Measured memory_bytes: 3632
/*
 * Problem Description: Partition
 * Category: Sort
 * Author: Khan
 * Date: 19th October, 2017
 */

#include <stdio.h>

#define MAXN 100000

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

int partition(int A[], int p, int r)
{
    int x, t;
    x = A[r];
    int i = p - 1;
    for (int j = p; j < r; ++j)
        if(A[j] <= x)
        {
            i++;
            swap(&A[i], &A[j]);
        }
    swap(&A[i + 1], &A[r]);
    return (i + 1);
}

int main(int argc, char const *argv[])
{
    //freopen("sample.txt", "r", stdin);
    int n, A[MAXN];
    scanf("%d", &n);
    for (int i = 0; i < n; ++i)
        scanf("%d", &A[i]);
    int q = partition(A, 0, n - 1);
    for (int i = 0; i < n; ++i)
    {
        if(i)
            printf(" ");
        if(i == q)
            printf("[");
        printf("%d", A[i]);
        if(i == q)
            printf("]");
    }
    printf("\n");
    return 0;
}

Measured memory_bytes: 3100
from collections import deque
h,w = map(int, input().split())
s = [list('#'+input()+'#') for i in range(h)]
s = [['#']*(w+2)]+s+[['#']*(w+2)]
z=0
for i in s:
  z += i.count('.')
ans = [[-1]*(w+2) for i in range(h+2)]
m = [[0,1],[0,-1],[1,0],[-1,0]]
ans[1][1] = 1
d = deque([[1,1]])
while len(d):
  x,y = d.popleft()
  for i,j in m:
    a,b = x+i,y+j
    if s[a][b] == '.' and ans[a][b] == -1:
      d.append([a,b])
      ans[a][b] = ans[x][y]+1
if ans[h][w] == -1:
  print(-1)
else:
  print(z-ans[h][w])

Measured memory_bytes: 9520
#include<stdio.h>
int main(){
char s[5];
int i,j,c,b[5],k,ans=1,l;
while(1){
for(i=0;i<4;i++){
scanf("%c",&s[i]);
}
scanf("\n");
for(i=0;i<4;i++){
b[i]=s[i]-'0';
}
if(b[0]==0 && b[1]==0 && b[2]==0 && b[3]==0){
break;
}
else if(b[0]==b[1] && b[1]==b[2] && b[2]==b[3]){
printf("NA\n");
}
else if(b[0]==6 && b[1]==1 && b[2]==7 && b[3]==4){
printf("0\n");
}
else{
while(1){
for(i=0;i<4;i++){
for(j=i+1;j<4;j++){
if(b[i]>b[j]){
k=b[i];
b[i]=b[j];
b[j]=k;
}
}
}
l=b[3]*1000+b[2]*100+b[1]*10+b[0];
c=b[0]*1000+b[1]*100+b[2]*10+b[3];
if(l-c==6174){
printf("%d\n",ans);
ans=1;
break;
}
else{
k=l-c;
for(i=0;i<4;i++){
b[i]=k%10;
k=k/10;
}
ans++;
}
}
}
}
return 0;
}


Measured memory_bytes: 2036
//
//  main.cpp
//  no.2
//
//  Created by MacBook_Virgo on 2015/04/23.
//  Copyright (c) 2015??´MacBook_Virgo. All rights reserved.
//
/*http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_7_B????§£???????????????
*/

#include <iostream>
using namespace std;
int main(int argc, const char * argv[]) {
    int n,x;
    while(cin >> n >>x,(n!=0)||(x!=0)){
       int answer = 0;
        for(int a = 1;a<=n;a++){
            for(int b = a+1;b <=n;b++){
                for(int c=b+1;c <=n;c++){
                    if(x == a+b+c){answer++;
                    }
                }
            }
        }
        cout << answer << endl;
    }
    return 0;
}

Measured memory_bytes: 1160
import java.util.Scanner;

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

        System.out.printf("%d %d %.5f\n",a/b,a%b,(double)a/b);
        }finally{
            scanner.close();
        }
    }
    
}


Measured memory_bytes: 26620
N=int(input())
F=[[0 for i in range(10)]for i in range(N)]
for i in range(N):
    st=input().split()
    indexnum=0
    for j in range(10):
            tmp=True
            if int(st[indexnum]):
                tmp=True
            else:
                tmp=False
            F[i][j]=tmp
            indexnum+=1
P=[[0 for i in range(11)] for i in range(N)]
for i in range(N):
    st=input().split()
    for j in range(10):
        P[i][j]=int(st[j])
xmax=-1e+10
for t in range(1,1024):
    a=[0 for i in range(10)]
    s=t
    for i in range(10):
       a[i]=(s%2)
       s=(s-a[i])//2
    x=0
    for i in range(N):
        c=0
        for j in range(10):
            if F[i][j] and a[j]==1:
                c+=1
        x+=P[i][c]
    if xmax<x:
        xmax=x
print(xmax)





Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <iomanip>
#include <map>
#include <cstdlib>
using namespace std;
int main()
{
    int a, b, c, d, x, y;
    cin >> a >> b >> c >> d;
    x = min(a, b);
    y = min(c, d);
    cout << x + y << endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
a_list = list(map(int, input().split()))

flag = 0
node_sum = 0
now_node = 0
max_node = [1]
for i in range(1, n+1):
    max_node.append((max_node[i-1]-a_list[i-1])*2)
# print(max_node)

for d, a in enumerate(reversed(a_list)):
    d = n-d
    max_now = max_node[d]
    if (now_node+1)//2 + a > max_now:
        flag = 1
        break
    elif now_node + a > max_now:
        now_node = max_now
    else:
        now_node += a
    node_sum += now_node
    # print(f"{d} {now_node}")

if flag == 1:
    print(-1)
else:
    print(node_sum)


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

int main() {
  long long n, k;
  cin >> n >> k;

  long long ans = 0;
  for ( long long b = k+1; b <= n; b++ ) {
    ans += (n/b) * (b-k);
    ans += ( (n%b) >= k ) ? (n%b) - (k-1) : 0;
  }
  if ( k == 0 ) { ans = n*n; }

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3604
#include<iostream>
#include <stdio.h>
#include <string>
#include <string.h>
#include <algorithm>
#include <functional>
#include <vector>
#include <math.h>

using namespace std;
int main()
{
	int N;
	cin >> N;

	int temp = 0;
	bool flag = false;

	for (int i = 0; i < 50; i++) {
		for (int j = 0; j < 50; j++) {
			temp = N - 4 * i - 7 * j;
			if (temp == 0) {
				flag = true;
			}
		}

	}

	if (flag == true) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}


	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
  int x,y,d;

  scanf("%d%d",&x,&y);
  if(x>y)
    {
      while(1)
        {
          d = x % y;
          if(d==0)break;
          x = y;
          y = d;
        }
      printf("%d\n",y);
    }
  else
    {
      while(1)
        {
          d = y % x;
          if(d==0)break;
          y = x;
          x = d;
        }
      printf("%d\n",x);
    }

    return 0;
}



Measured memory_bytes: 2100
#include <stdio.h>

void print_grade(int m, int t, int r)
{
    int sum = m + t;

    if (m == -1 || t == -1) //中間（m）期末（t）どちらかの試験を受けていなければF。
    {
        puts("F");
    }
    else if (sum >= 80) //80点以上でA。
    {
        puts("A");
    }
    else if (65 <= sum && sum < 80) //65点以上、80点未満でB。
    {
        puts("B");
    }
    else if (50 <= sum && sum < 65) //50点以上、65点未満でC。
    {
        puts("C");
    }
    else if (30 <= sum && sum < 50) //30点以上、50点未満でD。ただし再試験（r）が50点以上の場合はC。
    {
        if (r >= 50)
        {
            puts("C");
        }
        else
        {
            puts("D");
        }
    }
    else //30点未満でF。
    {
        puts("F");
    }
}
int main(void)
{
    int m, t, r;
    int sum;

    while (1)
    {
        scanf("%d %d %d", &m, &t, &r);
        if (m == -1 && t == -1 && r == -1) //全て-1の時終了。
        {
            break;
        }

        print_grade(m, t, r); //成績を表示
    }

    return 0;
}


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

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

Measured memory_bytes: 3596
import bisect

def _input(n):
    return [int(raw_input()) for i in xrange(n)]

# Wrapper for built-in function
def lower_bound(arr, target):
    return bisect.bisect_right(arr, target)


def LIS(arr, n):
    L = [0] * n

    L[0] = arr[0]
    length = 1

    for i in xrange(1, n):
        if L[length - 1] < arr[i]:
            L[length] = arr[i]#L.append(A[i])
            length += 1
        else:
            if L[lower_bound(L[:length], arr[i])-1 if lower_bound(L[:length], arr[i])-1 > 0 else 0] \
                    != arr[i]: # Fix common item - Dont insert common item and zero Problem
                L[lower_bound(L[:length], arr[i])] = arr[i]
    return length, L

#=========================================================
def main():

    n = int(raw_input())
    arr = _input(n)
    print LIS(arr, n)[0]#, LIS(arr, n)[1]#, arr

if __name__ == "__main__":
    main()

Measured memory_bytes: 11220
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
inline int read(){
	int f=1,ans=0;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){ans=ans*10+c-'0';c=getchar();}
	return f*ans;
}
const int MAXN=101;
int n,a[MAXN],maxn,num[MAXN];
void wrong(){printf("Impossible\n");exit(0);}
int main(){
	n=read();
	for(int i=1;i<=n;i++) a[i]=read(),num[a[i]]++,maxn=max(maxn,a[i]);
	int minn=(maxn+1)/2+1;
	if(maxn%2==1) if(num[minn-1]!=2) wrong();
	if(maxn%2==0&&num[minn-1]!=1) wrong();
	for(int i=1;i<minn-1;i++) if(num[i]) wrong();
	for(int i=minn;i<=maxn;i++) if(num[i]<2) wrong();
	printf("Possible\n"); 
}


Measured memory_bytes: 256
from sys import stdin, stdout
input = stdin.readline
print = stdout.write
n, m, k = map(int, input().split())
a = [0] + list(map(int, input().split()))
b = [0] + list(map(int, input().split()))
for i in range(1, n + 1):
    a[i] += a[i - 1]
for i in range(1, m + 1):
    b[i] += b[i - 1]
i, j, z = 0, m, 0
while i <= n and a[i] <= k:
    while b[j] > k - a[i]:
        j -= 1
    z = max(z, i + j)
    i += 1
print(str(z))

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

typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007;

ll f(ll b,ll n){
    if(n<b) return n;
    else return f(b,n/b)+(n%b);
}

int main(){
    
    ll N,S;cin>>N>>S;
    if(N<S) cout<<-1<<endl;
    else if(N==S) cout<<N+1<<endl;
    else if(N<=3&&S==1) cout<<N<<endl;
    else{
        ll sma=-1,div;
        for(ll i=2;i<=sqrt(N);i++){
        ll M=N/i+1;
            if(N%M+(i-1)>=S&&(N%M-S)%(i-1)==0&&i-1<=S){
                sma=M;
                div=i;
            }
        }
        for(ll i=2;i<=sqrt(N);i++){
            if(f(i,N)==S){
                if(sma==-1) sma=i;
                else sma=min(sma,i);
            }
        }
        if(sma<=sqrt(N)) cout<<sma<<endl;
        else{
            ll ans=sma+(N%sma+(div-1)-S)/(div-1);
            cout<<ans<<endl;
        }
    }
}


Measured memory_bytes: 256
//const int N=1e5;
#define INF 1e9
#include <bits/stdc++.h>
using namespace std;

#define ll long long

void sol() {
	int x; cin >> x;
	bool ok = false;
	if (x >= 30)
		ok = true;
	if (ok)
		cout << "Yes\n";
	else
		cout << "No\n";

}

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

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int t = 1;
	//cin >> t;
	while (t--) {
		sol();
	}

	return 0;
}

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

int main() {
    string s;
    int k,ans=0;
    cin >> s;
    k = s.length();
    for (int i=0; i<k; i++){
        if (s.at(i) == 'o') ans ++;
    }
    if (15-k+ans > 7){
        cout << "YES" << endl;
    }
    else{
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define fi first
#define se second
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;

int main(){
    ll N,M,K;
    cin >> N >> M >> K;
    vector<ll> A(N), B(M), SA(N+1), SB(M+1);
    rep(i,N){
        cin >> A[i];
    }
    rep(i,N){
        SA[i+1] = SA[i] + A[i];
    }
    rep(i,M){
        cin >> B[i];
    }
    rep(i,M){
        SB[i+1] = SB[i] + B[i];
    }
    ll ans = 0;
    rep(i,N+1){
        ll sum = SA[i];
        if(sum > K) continue;
        ll cap = K - sum;
        ll id = upper_bound(SB.begin(), SB.end(), cap) - SB.begin();
        id--;
        cmax(ans, i+id);
    }
    cout << ans << endl;
    /*
    ll sum = 0;
    ll ind1 = 0;
    while(ind1 < N && sum + A[ind1] <= K){
        sum += A[ind1];
        ind1++;
    }
    ll ind2 = 0;
    while(ind2 < M && sum + B[ind2] <= K) {
        sum += B[ind2];
        ind2++;
    }
    ll ans = ind1 + ind2;
    for(ll i = ind1-1;i>=0;i--){
        sum -= A[i];
        while(ind2 < M && sum + B[ind2] <= K){
            sum += B[ind2];
            ind2++;
        }
        ind1--;
        //cout << ans << " " << sum << endl;
        cmax(ans, ll(ind1+ind2));
    }
    cout << ans << endl;*/
}

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

using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define REP(i, l, n) for(int i=(l), i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back

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

char alpha[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};

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

int main(){
    ll h, w; cin >> h >> w;
    vector<string> lis(h);
    vector<vector<ll> > flag(h, vector<ll>(w, 0));
    vector<vector<ll> > tree(h*w+1);
    REP(i, 0, h){
        cin >> lis[i];
    }
    REP(i, 0, h){
        REP(l, 0, w){
            ll x = i, y = l;
            flag[x][y] = 1;
            REP(j, 0, 4){
                ll nx = x + dx[j], ny = y + dy[j];
                if(nx >= 0 && ny >= 0 && nx < h && ny < w && flag[nx][ny] == 0){
                    if((lis[x][y] == '.' && lis[nx][ny] == '#') || (lis[x][y] == '#' && lis[nx][ny] == '.')){
                        tree[w*x+y+1].pb(w*nx+ny+1);
                        tree[w*nx+ny+1].pb(w*x+y+1);
                    }
                }
            }
        }
    }
    vector<ll> flag1(h*w+1, 0);
    queue<ll> q;
    ll ans = 0;
    REP(i, 1, h*w+1){
        if(flag1[i] != 0){continue;}
        ll bc = 0;
        ll wc = 0;
        q.push(i);
        flag1[i]++;
        while(!q.empty()){
            ll now = q.front();
            ll xx = (now-1)/w;
            ll yy = (now-1) % w;
            if(lis[xx][yy] == '.'){
                wc++;
            }else{
                bc++;
            }
            q.pop();
            flag1[now]++;
            REP(i, 0, tree[now].size()){
                ll next = tree[now][i];
                if(flag1[next] == 0){
                    q.push(next);
                    flag1[next]++;
                }
            }
        }
        ans += bc * wc;
    }
    cout << ans << endl;
}

Measured memory_bytes: 17168
# include "bits/stdc++.h"

using namespace std;

#define endl "\n"
typedef long long int ll;

inline void fastio(){ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);}
inline void setPrecision(int n){cout.precision(n);}

ll INF = 1e10;
int MOD = 1e9+7;

int main(){
	fastio();
	int n,k; cin>>n>>k;
	vector<int> v(n+1),w(n+1);
	int mxv = 0;
	for(int i=1;i<=n;++i){
		cin>>w[i]>>v[i];
		mxv += v[i];
	}
	vector<vector<ll>> dp(2, vector<ll>(mxv+1, 1e18));
	dp[0][0] = 0;
	dp[1][0] = 0;
	for(int i=1;i<=n;++i){
		for(int j=0;j<=mxv;++j){
			dp[i%2][j] = min(dp[i%2][j],dp[(i-1)%2][j]);
			if(j>=v[i]) dp[i%2][j] = min(dp[i%2][j], dp[(i-1)%2][j-v[i]] + w[i]);
		}
	}
	for(int i=mxv;i>=0;--i)
		if(dp[n%2][i] <= k){
			cout<<i; break;
		}
    return 0;
}

Measured memory_bytes: 5568
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#define rep(i, n) for(int i=0;i<n;i++)
using namespace std;
int main(){
	int long long a, b, k;
	cin>>a>>b>>k;
	if(a>=k)
		cout<<a-k<<" "<<b<<endl;
	else if(a+b>=k)
		cout<<0<<" "<<a+b-k<<endl;
	else
		cout<<0<<" "<<0;
	return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//#define int ll
//const ll mod = 1000000007;

string s;
int n, k;
int a, b, c;
string ans;

signed main() {
    cin >> s;
    string ss[3] = {"Sunny", "Cloudy", "Rainy"};
    for (int i = 0; i < 3; i++) {
        if (ss[i] == s) {
            ans = ss[(i + 1) % 3];
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define SSTR( x ) static_cast< std::ostringstream & >( \
        ( std::ostringstream() << std::dec << x ) ).str()
#define ALL(s) (s).begin(), (s).end()
using namespace std;
typedef long long unsigned int llu;
typedef long long ll;

long int pop(vector<long int>& A){
  int ind = A.size()-1;
  long int r = A[ind];
  A.pop_back();
  return r;
}

int main (){
  string S;
  vector<long int>  s;
  while (cin >> S){
    if(S == "+"){
      long int a = pop(s);
      long int b = pop(s);
      s.push_back(a+b);
    }else if(S == "-"){
      long int a = pop(s);
      long int b = pop(s);
      s.push_back(b-a);
    }else if(S == "*"){
      long int a = pop(s);
      long int b = pop(s);
      s.push_back(a*b);
    }
    else{
      int i = 0;
      sscanf(S.c_str(),"%d",&i);
      s.push_back(i);
    }

  }

  cout <<  pop(s) << endl;
  return 0;
}



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

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

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

struct Sieve {
  vector<int> p;

  Sieve(int n) : p(n) {
    p[1] = -1;
    for (ll i = 2; i <= n; ++i) {
      if (p[i] != 0) continue;
      p[i] = i;
      for (ll j = 2 * i; j <= n; j += i) {
        p[j] = i;
      }
    }
  }

  map<int, int> fact(int x) {
    map<int, int> mp;
    while (p[x] != -1) {
      ++mp[p[x]];
      x /= p[x];
    }
    return mp;
  }

  vector<P> factList(int x) {
    auto mp = fact(x);
    vector<P> f;
    for (auto p : mp) {
      f.push_back({p.first, p.second});
    }
    return f;
  }
};

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

  Sieve s(n);
  ll ans = 0;
  for (int i = 1; i <= n; ++i) {
    // auto fact = s.factList(i);
    auto fact = s.fact(i);
    ll now = 1;
    for (auto p : fact) now *= p.second + 1;
    ans += (ll)i * now;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 42344
#include<iostream>
#include<math.h>
using namespace std;
typedef long long ll;

int main(){
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    #endif
    
    int n; cin >> n;
    ll  a[n];
    ll temp,value=1;
    ll limit=pow(10,18);
    int zero=0;
    for(int i=0;i<n;i++){
        cin >> a[i];
        if(a[i]==0) zero++;
    }
    if (zero>0) {
        cout << 0 << "\n";
        return 0;
    }


    for(int i=0;i<n;i++){
        //cout << value << " " << temp <<" \n";
        temp=a[i];
        double fraction=limit/value;
        if( temp<=fraction){
            value*=temp;
        }
        else {
            value=-1;
            break;
        }
    }

    cout << value<< "\n";
     
    return 0;
}

Measured memory_bytes: 4388
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <algorithm>
#define MP make_pair
using ll = long long;
using namespace std;

int main()
{
  string s;
  cin >> s;
  ll sn = 0;
  for(int i=0; i < s.length(); i++){
    ll si = s[i] - '0';
    sn += si;
  }
  ll ss = stoi(s);
  if(ss % sn == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}


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

using namespace std;

int i,n,j,k,ans;
bool yes;
char s[1007][1007];
char b[1007][1007];

int main() {
	scanf("%d",&n);
	for (i=0 ; i<n ; i++) {
		scanf("%s",s[i]);
	}
	
	for (i=0 ; i<n ; i++) {
		yes = true;
		
		for (j=0 ; j<n ; j++) {
			for (k=0 ; k<n ; k++) {
				int x = (i+j) % n;
				int y = k % n;
				b[x][y] = s[j][k];
			}
		}
		
		for (j=0 ; j<n ; j++) {
			for (k=0 ; k<n ; k++) {
				if (b[j][k] != b[k][j]) yes = false;
			}
		}
		if (yes) ans += n;
	}
	
	printf("%d\n",ans);
}


Measured memory_bytes: 896
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <queue>
#include <cmath>
#include <map>
#include <set>
#include <deque>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int mod = 1e9+7;
const int inf = 1<<30;
typedef pair<int, int> P;


int main() {
  int n; cin >> n;
  vector<P> tasks;
  rep(i, n) {
    int a, b; cin >> a >> b;
    tasks.emplace_back(b, a);
  }
  sort(tasks.begin(), tasks.end());
  int sum = 0;
  bool ok = true;
  for(auto v : tasks) {
    sum += v.second;
    if(sum > v.first) {
      ok = false;
      break;
    }
  }
  if(ok) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 2420
#include<bits/stdc++.h>
#define lowbit(x) (x&-x)
#define mem(a,b) memset(a,b,sizeof(a))
#define  For(i,a,b) for(int i=a,i##E=b;i<=i##E;++i)
#define rFor(i,a,b) for(int i=a,i##E=b;i>=i##E;--i)
using namespace std;
typedef long long LL;
const int N=16;
const int inf=0x3f3f3f3f;
template<typename T>inline bool chkmin(T &a,const T &b){return a>b?a=b,1:0;}
template<typename T>inline bool chkmax(T &a,const T &b){return a<b?a=b,1:0;}
template<typename T>inline void read(T &x)
{
	x=0;int _f(0);char ch=getchar();
	while(!isdigit(ch))_f|=(ch=='-'),ch=getchar();
	while( isdigit(ch))x=x*10+ch-'0',ch=getchar();
	x=_f?-x:x;
}
inline void file()
{
#ifndef ONLINE_JUDGE
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
#endif
}
int n,m,tot,dp[N][1<<N],ans;
int c[N],w[N][1<<N],can[1<<N];
int q[1<<N],cnt;
int main()
{
	int x,y,z;
	read(n),read(m);
	For(i,1,m)
	{
		read(x),read(y),read(z);
		c[x]|=(1<<(y-1)),w[x][1<<(y-1)]=z;
		c[y]|=(1<<(x-1)),w[y][1<<(x-1)]=z;
		ans+=z;
	}
	For(i,1,n)
	{
		cnt=0;
		for(int x=c[i];x;x=(x-1)&c[i])
			q[++cnt]=x;
		rFor(j,cnt,1)
		{
			int x=q[j];
			w[i][x]=w[i][x^lowbit(x)]+w[i][lowbit(x)];
		}
	}
	mem(dp,-inf);
	dp[1][1]=0;
	tot=(1<<n)-1;
	For(x,1,tot)
	{
		For(u,1,n)
			if(x&(1<<(u-1)))
				can[x]+=w[u][x&c[u]];
		can[x]>>=1;
	}
	For(x,1,tot)
		if(x&1)
		For(u,1,n)
		if(dp[u][x]>=0){
			int bx=tot^x,f=1<<(u-1);
			for(int sm=bx;sm;sm=(sm-1)&bx)
				chkmax(dp[u][x|sm],dp[u][x]+can[sm|f]);
			For(v,1,n)
				if(c[u]&(1<<(v-1))&&!(x&(1<<(v-1))))
					chkmax(dp[v][x|(1<<(v-1))],dp[u][x]+w[v][f]);
		}
	printf("%d\n",ans-dp[n][tot]);
	return 0;
}


Measured memory_bytes: 7808
#include <bits/stdc++.h>
#define MAX (ll)(1e5)
#define MOD (ll)(1e9 + 7)
#define INF (ll)(1e18 + 3)
#define PI (double)(3.14159265)

using namespace std;
using ll = long long;
using ld = long double;

int main () {
	string st;
	cin >> st;
	int ans = 0;
	if (st == "SUN") {
		ans = 7;
	}
	else if (st == "MON") {
		ans = 6;
	}
	else if (st == "TUE") {
		ans = 5;
	}
	else if (st == "WED") {
		ans = 4;
	}
	else if (st == "THU") {
		ans = 3;
	}
	else if (st == "FRI") {
		ans = 2;
	}
	else if (st == "SAT") {
		ans = 1;
	}
	cout << ans << "\n";
}
	


Measured memory_bytes: 256
s = input()

if s == 'SUN':
    print(7)
elif s == 'MON':
    print(6)
elif s == 'TUE':
    print(5)
elif s == 'WED':
    print(4)
elif s == 'THU':
    print(3)
elif s == 'FRI':
    print(2)
elif s == 'SAT':
    print(1)


Measured memory_bytes: 2940
#include<iostream>
#include<cstdio>
using namespace std;
int a,b,c,d,x,y;
int main()
{
	cin>>a>>b>>c>>d;
	x=c-a;y=d-b;
	cout<<c-y<<" "<<d+x<<" ";
	cout<<c-x-y<<" "<<d+x-y<<" ";
	return 0;
} 

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<string>

#define NMAX (10000+10)
#define YES 0
#define NO 1

using namespace std;

int main(void){

	int huriko[NMAX*20]={YES};
	int cnt=0;
	long long primenum[NMAX];

	huriko[0]=NO,huriko[1]=NO;
	primenum[0]=0;
	for(int i=2;cnt<NMAX-5;i++){
		if(huriko[i]==YES){
			cnt++;
			primenum[cnt]=primenum[cnt-1]+i;
			for(int j=i+i;j<NMAX*20;j+=i){
				huriko[j]=NO;
			}
		}
	}

	int n;

	while(1){
		cin>>n;
		if(n==0) break;
		else cout<<primenum[n]<<endl;
	}

	return 0;
}

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

int main() {
  string S;
  cin >>S;
  bool s = false;
  for (int i =0;i<2;i++){
    if(S.at(i) != S.at(i+1)){      
      s = true;
      break;
    }
    }
  if(s){
    cout <<"Yes"<<endl;
  }
  else{
    cout <<"No"<<endl;
  }
  }














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

const int N = 20;

int n, k;
int* dp[1 << N + 1], pool[(1 << N + 1) * (N + 2)], *p = pool;

void alloc() {
	for (int i = 1; i < 1 << n + 1; ++i) {
		int len = std::__lg(i);
		dp[i] = p, p += 1 << n - len + 1;
	}
}

int main() {
	std::ios::sync_with_stdio(0), std::cin.tie(0);
	std::cin >> n >> k, alloc();
	for (int i = 0; i <= n; ++i) {
		std::string s; std::cin >> s;
		for (int j = 0; j < 1 << i; ++j)
			if (s[j] == '1') dp[1][1 << i | j] = 1;
	}
	for (int i = 1; i < 1 << n + 1; ++i) {
		int len = std::__lg(i);
		for (int j = 1; j < 1 << n - len + 1; ++j) if (dp[i][j]) {
			int j_len = std::__lg(j), k_len;
			if (j & j + 1) {
				k_len = std::__lg(j ^ ~(-1 << j_len + 1));
				dp[i << 1 | 0][j & ~(-1 << k_len) | 1 << k_len] += dp[i][j];
			}
			if (j & j - 1) {
				k_len = std::__lg(j ^ 1 << j_len);
				dp[i << 1 | 1][j & ~(-1 << k_len) | 1 << k_len] += dp[i][j];
			}
		}
	}
	std::string ans = "";
	for (int i = 2; i < 1 << n + 1; ++i) {
		int len = std::__lg(i), sum = 0;
		for (int j = 1; j < 1 << n - len + 1; ++j) sum += dp[i][j];
		if (sum >= k) {
			std::string s;
			for (int t = len - 1; ~t; --t)
				s += char(i >> t & 1 | '0');
			if (len > ans.size()) ans = s;
		}
	}
	std::cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 190908
import scala.io.StdIn.readLine

object Main {
  def revP(l:List[String],stack:List[Int]):Int =  {
    l match {
      case Nil => stack(0)
      case hd::tl =>
        val stack2 =
          if(hd!="+" && hd!="-" && hd!="*") hd.toInt::stack
          else {
            val x::y::tail = stack
            if(hd=="+") (y+x)::tail
            else if(hd=="-") (y-x)::tail
            else if(hd=="*") (y*x)::tail
            else Nil
          }
        revP(tl,stack2)
    }
  }

  def main(args:Array[String]) = {
    val l = readLine.split(" ").toList
    println(revP(l,Nil))
  }
}

Measured memory_bytes: 43664
x=y=k=j=0
gets
s=gets.chomp
s.size.times{|i|
	if s[i]=='('
		j+=1
	else
		j-=1
		x=[x,j].min
	end
	if s[s.size-1-i]==')'
		k+=1
	else
		k-=1
		y=[y,k].min
	end
}
puts '('*-x+s+')'*-y

Measured memory_bytes: 1788
////////////////////////////////////////////
///                                      ///
///         Template ver. 1 rapel        ///
/// Fear is Temporary, Regret is Forever ///
///          Must Try and Get AC         ///
///                                      ///
////////////////////////////////////////////
#include <stdio.h>
#include <iostream>
#include <sstream>
#include <iomanip>

#include <algorithm>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <utility>

#include <math.h>
#include <complex>

#include <assert.h>
#include <time.h>
//#include <chrono>
//#include <random>

#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <bitset>

#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define PF push_front
#define POB pop_back
#define POF pop_front
#define endl '\n'
using namespace std;

typedef long long LL;
typedef unsigned long long ULL;

void desperate_optimization(int precision){
  	ios_base::sync_with_stdio(false);
  	cin.tie(0);
  	cout.tie(0);
  	cout.setf(ios::fixed);
  	cout.setf(ios::showpoint);
  	cout.precision(precision);
}

const int N = 1e5;
int arr[N + 5];
vector<int> lst[N + 5];
int tot = 0;
int depth[N + 5];
int n, k;

void dfs(int idx) {
	depth[idx] = 0;
	for(auto x: lst[idx]) {
		dfs(x);
		depth[idx] = max(depth[idx], depth[x] + 1);
	}
//	cout<<"IDX "<<idx<<" "<<depth[idx]<<endl;
	if(depth[idx] == k - 1 && arr[idx] != 1 && idx != 1) {
		depth[idx] = -1;
		tot++;
	}
}

void hora(int tc) {
	cin>>n>>k;
	for(int i = 1;i <= n;i++) {
		cin>>arr[i];
		if(i != 1) lst[arr[i]].PB(i);
	}
	if(arr[1] != 1) tot++;
	dfs(1);
	cout<<tot<<endl;
}

int main(){
	desperate_optimization(10);
	int ntc = 1;
	//cin>>ntc;
	for(int tc = 1;tc <= ntc;tc++) hora(tc);
	return 0;
}




Measured memory_bytes: 11264
#include <bits/stdc++.h>
using namespace std;
const int inf=1000000;
int n,k,c;
string s;
int main(){
	cin>>n>>k>>c>>s;
	vector<int> g1(k),g2(k);
	{
		int lst=-inf;
		int p=0;
		for(int i=0;i<n&&p<k;++i){
			if(s[i]=='o'&&i>lst+c){
				g1[p++]=i;
				lst=i;
			}
		}
	}
	{
		int lst=inf;
		int p=k-1;
		for(int i=n-1;i>=0&&p>=0;--i){
			if(s[i]=='o'&&i<lst-c){
				g2[p--]=i;
				lst=i;
			}
		}
	}
	for(int i=0;i<k;++i){
		if(g1[i]==g2[i]){
			cout<<g1[i]+1<<'\n';
		}
	}
	return 0;
} 

Measured memory_bytes: 3332
N = int(input())
T,A = map(int,input().split())
H = list(input().split())
H = list(map(int,H))

sa = 100000000000
index = 0

for i in range(N):
	kion = T - H[i]*0.006
	if(abs(A-kion)<sa):
		sa = abs(A-kion)
		index = i+1

print(index)

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main(){
    int N;
    cin>>N;
    int a[N];
    for(int i=0; i<N; i++)cin>>a[i];
    sort(a,a+N);
    int alice=0, bob=0;
    for(int i=1; i<=N; i+=2){
        alice+=a[N-i];
        bob += a[N-i-1];
    }
    cout<<alice-bob<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
// #include <boost/multiprecision/cpp_int.hpp> 

#define gc getchar//_unlocked
#define pc putchar//_unlocked
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define pp pair<int,int>
#define ppl pair<ll,ll>
#define bigint boost::multiprecision::cpp_int
#define finp ios_base::sync_with_stdio(0);cin.tie(0);
#define bc __builtin_popcountll
#define afor(i,a,b) for(int i=a;i<=b;++i)
#define bfor(i,a,b) for(int i=a;i>=b;--i)
#define vi vector<int>
#define vpp vector<pp>
#define vll vector<ll>
#define fr first
#define se second

using namespace std;
using namespace __gnu_pbds;

char putnb[20];
void putn(ll n) {if(!n)pc('0');if(n<0)pc('-'),n=0-n;int pi=0;while(n)putnb[pi++]=(n%10)+'0',n/=10;while(pi)pc(putnb[--pi]);}
void sci(int *x) {register char c = gc();*x = 0;for(; (c<48)||(c>57);c = gc());for(; (c>47)&&(c<58);c = gc())*x = (int)((((*x)<<1) + ((*x)<<3)) + c - 48);}
void scll(ll *x)  {register char c = gc();*x = 0;for(; (c<48)||(c>57);c = gc());for(; (c>47)&&(c<58);c = gc())*x =  (ll)((((*x)<<1) + ((*x)<<3)) + c - 48);}
ll fp(ll a,ll b,ll c) {if(b==0)return 1%c; if(b==1)return a%c; ll ret=fp(a,b/2,c); ret=(ret*ret)%c; if(b&1)ret=(ret*a)%c; return ret;}

const ll mod=1e9 +7;
const ll mod2=1999999973;
const ll inf=1e18;
const int infs=1e9 + 1000;
const int N=100000;
const long double PI = acos(-1);

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;


ld ldp[N+5];

ld c2(ll n)
{
  if(!n)return 0;
  return ((ld)n * ((n<=N)?ldp[n]:log2(n)));
}
ld calc(ppl a)
{
  return (c2(a.first) - c2(a.second) - c2(a.first - a.second));
}
bool cmp(ppl a,ppl b)
{
  return calc(a) < calc(b);
}
vector<ppl> vv;

ll arr[N+5];
int main()
{
  finp;
  afor(i,1,N)
  {
    ldp[i] = log2(i);
  }

  ll n;
  cin>>n;
  afor(i,1,n)cin>>arr[i];
  sort(arr+1,arr+n+1);
  set<ll> s;

  s.insert(arr[1]);

  afor(i,2,n)
  {
    auto xx = s.lower_bound(arr[i]/2);

    auto x1 = xx;
    afor(j,1,2)
    {
      if(x1 == s.end())break;
      vv.pb({arr[i],*x1});
      x1++;
    }
    auto x2 = xx;
    afor(j,1,2)
    {
      if(x2 == s.begin())break;
      x2--;
      vv.pb({arr[i],*x2});
    }
    s.insert(arr[i]);
  }

  sort(vv.begin(),vv.end(),cmp);

  cout<<vv.back().fr<<" "<<vv.back().se;
return 0;
}

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

int main(){
  string S,answer;
  cin >> S;
  for(int i = 0;i < S.size();i++) {
    if(S.at(i)=='1'){
      answer+='1';
    }
    if(S.at(i)=='0'){
      answer+='0';
    }
        if(S.at(i)=='B'){
      if(answer.size()>0)
        answer.pop_back();
        }
    }
  cout<<answer<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i=0;i<int(n);++i)
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
int INF=numeric_limits<int>::max();
// for(int j=0;j<N;++j) {

int main(void) {
  int n;cin>>n;
  int a[n+10];
  ll x[n+10];
  ll sum_a=0;
  REP(i,n) {
    cin>>a[i];
    sum_a+=a[i];
  }

  for(int i=1;i<(n-1)/2+1;++i) {
    sum_a-=2*a[2*i-1];
  }
  x[0] = sum_a;
  cout << x[0] << " ";
  for(int i=1;i<n;++i) {
    x[i]=2*a[i-1]-x[i-1];
    cout << x[i] << " ";
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 2432
n=gets.to_i
s=?.+(gets.chomp)+?.
e=w=0
dp_e=[]
dp_w=[]
s.chars.each{|c|
  if c== ?E
    e+=1
  elsif c==?W
    w+=1
  end
  dp_e<<e
  dp_w<<w
}
puts 1.upto(n).map{|i|
  dp_w[i-1]+e-dp_e[i]
}.min

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

long long n, x, t, a[100001];
int main(){
	cin >> n >> x;
	for(int i = 1; i <= n; i++) cin >> a[i];
	for(int i = 1; i <= n; i++){
		if((a[i-1]+a[i]) > x){
			t += a[i-1]+a[i]-x;
			a[i] = x-a[i-1];
		}
	}
	cout << t;
}

Measured memory_bytes: 1024
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author silviase
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        AAirportBus solver = new AAirportBus();
        solver.solve(1, in, out);
        out.close();
    }

    static class AAirportBus {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 乗る人数
            int n = in.nextInt();
            // 乗せられる人数
            int c = in.nextInt();
            // 待てる時間
            int k = in.nextInt();
            int[] t = new int[n];
            for (int i = 0; i < n; i++) {
                t[i] = in.nextInt();
            }

            Arrays.sort(t);

            // out.println(Arrays.toString(t));

            int cnt = 0;
            int got = 0;
            long time = t[0] + k;
            while (got < n) {
                int ninzu = 0;
                cnt++;
                while (t[got] <= time) {
                    ninzu++;
                    got++;
                    if (got == n) {
                        out.println(cnt);
                        return;
                    }
                    if (ninzu == c) {
                        break;
                    }
                }
                // out.println(time + " " + got);
                time = t[got] + k;
            }


        }

    }
}



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

int main(){
    ll n;
    cin >> n;
    
    if((n % 2) == 1){
        cout << 0 << endl;
        return 0;
    }

    ll mul5 = 10;
    ll cnt = 0;
    while(mul5 <= n){
        cnt += n / mul5;
        // cout << n << " " << mul5 << " " << cnt << endl;
        mul5 *= 5;
    }
    cout << cnt << endl;

    return 0;
} 

Measured memory_bytes: 256
from collections import deque

n=int(input())
a=list(map(int,input().split()))

b=deque()
l=len(a)
if l%2==0:
    for i in range(l):
        if i%2!=0:
            b.appendleft(a[i])
        else:
            b.append(a[i])
else:
    for i in range(l):
        if i%2!=0:
            b.append(a[i])
        else:
            b.appendleft(a[i])
print(*b)

Measured memory_bytes: 25536
#include <iostream>
#include <cmath>
#include <algorithm>
#include <set>
#include <vector>
using namespace std;
int main() {
    int N; cin >> N;
    set<int> S;
    for (int i = 0; i < N; ++i) {
        int a; cin >> a; S.insert(a);
    }
    printf("%d\n", S.size());
}


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

struct Crop {
    string name;
    double efficiency;
};

int main() {
    while (true) {
        int n;
        cin >> n;
        if (n == 0) {
            break;
        }
        Crop* crops = new Crop [n];
        for (int i = 0; i < n; i++) {
            string l;
            int p, a, b, c, d, e, f, s, m;
            cin >> l >> p >> a >> b >> c >> d >> e >> f >> s >> m;
            crops[i].name = l;
            int time = a + b + c, sale = 0;
            for (int j = 0; j < m; j++) {
                time += d + e;
                sale += f * s;
            }
            crops[i].efficiency = (double) (sale - p) / time;
        }
        for (int i = 0; i < n - 1; i++) {
            for (int j = 0; j < n - 1 - i; j++) {
                if (crops[j].efficiency < crops[j + 1].efficiency
                    || (crops[j].efficiency == crops[j + 1].efficiency && crops[j].name > crops[j + 1].name)) {
                    Crop temp = crops[j];
                    crops[j] = crops[j + 1];
                    crops[j + 1] = temp;
                }
            }
        }
        for (int i = 0; i < n; i++) {
            cout << crops[i].name << endl;
        }
        cout << "#" << endl;
        delete[] crops;
    }
}

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

int main(){

     long long a,b,c;
    if(scanf("%llu %llu %llu",&a,&b,&c)!=3){};
    
    if(c-a-b>0){
        if(4*a*b<(c-a-b)*(c-a-b)){
        printf("Yes");
        }else{
            printf("No");
        }
    }else{
        printf("No");
    }

    return 0;
}

Measured memory_bytes: 128
import itertools
import bisect

lis = list(itertools.product('7530',repeat = 9))
int_lis = list(map(int,map(''.join,lis)))
str_lis = list(map(str,int_lis[:-16]))
lis = []
for s in str_lis:
    if ('7' in s) and ('5' in s) and ('3' in s) and ('0' not in s) :
        lis.append(int(s))
print(bisect.bisect_right(sorted(lis),int(input())))


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

using namespace std;

#define ll long long
#define ld long double
#define P pair<ll, ll>

#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

#define all(v) v.begin(), v.end()

#define sortAl(v) sort(all(v))
#define sortAlr(v)          \
  sort(v.begin(), v.end()); \
  reverse(v.begin(), v.end())

#define cout(n) cout << fixed << setprecision(n)

#define rep(i, n) for (ll i = 0; i < n; i++)
#define REP(i, n) for (ll i = 1; i < n; i++)

template <class T>
inline void chmax(T &a, T b) {
  a = std::max(a, b);
}
template <class T>
inline void chmin(T &a, T b) {
  a = std::min(a, b);
}

#define mod (ll)(1e9 + 7)
#define INF LLONG_MAX

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

  ll n, m;
  cin >> n >> m;

  vector<bitset<10>> lights(m);
  vector<ll> onoff(m);
  rep(i, m) {
    int cnt;
    cin >> cnt;
    rep(k, cnt) {
      ll a;
      cin >> a;
      lights[i][a - 1] = 1;
    }
  }
  rep(i, m) {
    ll a;
    cin >> a;
    onoff[i] = a;
  }

  ll sum = 0;
  rep(s, 1ll << n) {
    bitset<10> sw(s);
    rep(i, m) {
      auto tmp = sw & lights[i];
      if (tmp.count() % 2 != onoff[i]) {
        goto fail;
      }
    }
    sum++;
  fail:
    0;
  }

  cout << sum << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
// Welcome to my source code!

int main() {
    int n;
    cin >> n;
    int a[n];
    for (int i = 0; i < n; i++) cin >> a[i];
    sort(a, a+n);
    int t, cnt, ans;
    for (int i = 0; i < n;) {
        t = a[i], cnt = 0;
        while (i < n && a[i] == t) cnt++, i++;
        ans += cnt % 2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
N = gets.to_i
A = gets.chomp.split(" ").map(&:to_i)

def search_half(a, n)
  a_s = a[n]
  a_i = a.bsearch_index{|x| x >= a_s / 2}
  if a_i == 0 then
    [a[a_i], a_s - a[a_i]]
  else
    if (2 * a[a_i] - a_s).abs < (2 * a[a_i-1] - a_s).abs then
      [a[a_i], a_s - a[a_i]]
    else
      [a[a_i-1], a_s - a[a_i-1]]
    end
  end
end


wk = 0
al = A.map{|a| wk += a; wk}
wk = 0
ar = A.reverse.map{|a| wk += a; wk}
ans = 10 ** 9
1.upto(N-3){|n|
  al_a = search_half(al, n)
  ar_a = search_half(ar, N-n-2)
  l = al_a + ar_a
  wk = l.max - l.min
  ans = wk if ans > wk
}

puts ans


Measured memory_bytes: 26372