akhauriyash/Code-Regression huggingface dataset:
import java.io.*;
import java.util.*;
import static java.lang.System.out;

public class Main {
    static MyReader in = new MyReader();

    public static void main(String[] args) {
        int N = in.i();
        int[] a = new int[N * 3];
        for (int i = 0; i < a.length; i++) {
            a[i] = in.i();
        }
        int[][] dp = new int[N + 1][3];
        for (int i = 0; i < N; i++) {
            dp[i + 1][0] = a[i * 3] + Math.max(dp[i][1], dp[i][2]);
            dp[i + 1][1] = a[i * 3 + 1] + Math.max(dp[i][0], dp[i][2]);
            dp[i + 1][2] = a[i * 3 + 2] + Math.max(dp[i][0], dp[i][1]);
        }
        out.println(Math.max(dp[N][0], Math.max(dp[N][1], dp[N][2])));
    }
}

class MyReader extends BufferedReader {
    char[] cbuf = new char[1024];
    int head = 0;
    int tail = 0;

    MyReader() {
        super(new InputStreamReader(System.in));
    }

    char next() {
        if (head == tail) {
            try {
                tail = super.read(cbuf, 0, cbuf.length);
            } catch (IOException e) {
                e.printStackTrace();
            }
            head = 0;
        }
        return cbuf[head++];
    }

    void back() {
        head--;
    }

    boolean minus() {
        boolean minus;
        while (true) {
            char c = next();
            if (!isDelimiter(c)) {
                if (!(minus = c == '-')) back();
                return minus;
            }
        }
    }

    void skip() {
        while (isDelimiter(next()));
        back();
    }

    char[] s(int N) {
        char[] cbuf = new char[N];
        read(cbuf, 0, N);
        return cbuf;
    }

    public int read(char[] cbuf, int off, int len) {
        skip();
        int i;
        for (i = 0; i < cbuf.length; i++) {
            char c = next();
            if (isDelimiter(c)) {
                break;
            }
            cbuf[i] = c;
        }
        return i;
    }

    boolean isDelimiter(char c) {
        return c == ' ' || c == '\n' || c == '\r';
    }

    int i() {
        boolean minus = minus();
        int n = 0;
        while (true) {
            int k = next() - '0';
            if (k < 0 || 9 < k) break;
            n = 10 * n + k;
        }
        return minus ? -n : n;
    }

    int[] ii(final int N) {
        int[] a = new int[N];
        for (int j = 0; j < a.length; j++) a[j] = i();
        return a;
    }

    long l() {
        boolean minus = minus();
        long n = 0;
        while (true) {
            int k = next() - '0';
            if (k < 0 || 9 < k) break;
            n = 10 * n + k;
        }
        return minus ? -n : n;
    }
}


Measured memory_bytes: 40216
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,next=1;
    int a[100000];
    cin >> n;
    for(int i=0; i< n; i++){
        cin >> a[i];
    }
    for(int i=0; i< n; i++){
        next = a[next-1];
        if(next==2){
            cout << i+1<< endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
    
}

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

int n,k;
ll a[1005];
ll sum[1005];
vector<ll> vec;
bool flag[2000005];

int main(void){
    scanf("%d%d",&n,&k);
    for(int i=0;i<n;i++){
        scanf("%lld",&a[i]);
        sum[i+1]+=sum[i];
        sum[i+1]+=a[i];
    }
    for(int i=0;i<n;i++){
        for(int j=i;j<n;j++){
            ll vo=sum[j+1]-sum[i];
            vec.push_back(vo);
        }
    }
    ll ans=0;
    for(ll i=50;i>=0;i--){
        int cnt=0;
        for(int j=0;j<vec.size();j++){
            if(!flag[j]){
                if((ll)(vec[j]>>i) & 1LL){
                    cnt++;
                    //printf("%lld\n",vec[j]);
                }
            }
        }
        if(cnt>=k){
            ans+=1LL<<i;
        }
        //printf("%lld %d %d %lld\n",i,k,cnt,ans);
        for(int j=0;j<vec.size();j++){
            if((ll)(vec[j]>>i) & 1LL){
            }else{
                if(cnt>=k){
                    flag[j]=true;
                }
            }
        }
    }
    printf("%lld\n",ans);
    return 0;
}

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

int main() {
    vector<int> vec(3);
    for (int i=0;i<3;i++){
        cin>>vec.at(i);
    }
    sort(vec.begin(),vec.end());
    cout<<vec.at(0)<<" "<<vec.at(1)<<" "<<vec.at(2)<<endl;
}


Measured memory_bytes: 3100
import std.stdio, std.conv, std.string;
import std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }

int DEBUG_LEVEL = 0;
void print()(){ writeln(""); }
void print(T, A ...)(T t, lazy A a){ write(t), print(a); }
void print(int level, T, A ...)(T t, lazy A a){ if(level <= DEBUG_LEVEL) print(t, a); }

void main(string[] args){
	if(args.length > 1 && args[1] == "-debug"){
		if(args.length > 2 && args[2].isNumeric) DEBUG_LEVEL = args[2].to!int;
		else DEBUG_LEVEL = 1;
	}
	
	long a = read.to!long;
	long b = read.to!long;
	long c = read.to!long;
	
	if(a == b && b == c) "Yes".writeln;
	else "No".writeln;
	
}

Measured memory_bytes: 256
N=6
#A=[3,14,159,2,6,53]
#B=[58,9,79,323,84,6]
#C=[2643,383,2,79,50,288]
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))

D=[0]*N
E=[0]*N

A=list(sorted(A,reverse=True))
B=list(sorted(B,reverse=True))
C=list(sorted(C,reverse=True))

u=N-1
d=N-1
c=0
while(True):
    if A[u] < B[d]:
        c+=1
        u-=1
    else:
        D[d]=c
        d-=1
    if(-1==u or -1==d):
        for i in range(d,-1,-1):
            D[i]=c
        break
u=0
d=0
c=0
while(True):
    if B[u] < C[d]:
        c+=1
        d+=1
    else:
        E[u]=c
        u+=1
    if(N==u or N==d):
        for i in range(u,N):
            E[i]=c
        break

s=0
for i in range(N):
    s+=D[i]*E[i]


print(s)

Measured memory_bytes: 25396
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;
int read()
{
	char ch=getchar();int f=0,x=1;
	while(ch<'0'||ch>'9'){if(ch=='-') x=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){f=(f<<1)+(f<<3)+ch-'0';ch=getchar();}
	return f*x;
}
char s[15];
int num[55];
int main()
{
	scanf("%s",s+1);
	for(int i=1;i<=4;i++)
	{
		num[s[i]-'A'+1]++;
	}
	int temp=0;
	for(int i=1;i<=26;i++)
	{
		if(num[i]!=2&&num[i]!=0)
		{
			puts("No");
			return 0;
		}
	}
	puts("Yes");
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <stdio.h>
#include <map>
#include <set>
#include <algorithm>

using namespace std;

int main()
{
  vector<int> a(3);
  cin >> a[0] >> a[1] >> a[2];

  sort(a.begin(), a.end());

  cout << abs(a[1] - a[0]) + abs(a[2] - a[1]) << endl;
}

Measured memory_bytes: 256
/*
ID: barish21
LANG: C++14
TASK: test
*/

/****Author: Barish Namazov****/
#include <bits/stdc++.h>

using namespace std;

/***TEMPLATE***/
#define intt long long

#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

#define F first
#define S second
#define pb push_back

#define IO ios_base::sync_with_stdio(false);cin.tie();

const intt max1 = 11;
const intt max2 = 102;
const intt max3 = 1003;
const intt max4 = 10004;
const intt maxx = 100005;
const intt max6 = 1000006;
const intt max7 = 10000007;
const intt lg2 = 7;
const intt lg3 = 10;
const intt lg4 = 13;
const intt lg5 = 17;
const intt lg6 = 20;
const intt lg7 = 24;
const intt lg8 = 27;
const intt lg9 = 30;
const intt lg18 = 60;
const intt INF = 2LL * 1000000000;
/***************/

/***Additional Functions***/
intt powmod(intt a,intt b,intt mod){intt res=1;a%=mod;assert(b>=0);for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
intt gcd(intt a, intt b) { while(b) b ^= a ^= b ^= a %= b; return a;}
intt lcm(intt a,intt b){return a*b/gcd(a,b);}
intt is_prime(intt n){if(n==1)return 0;if(n==2)return 1;if(n%2==0)return 0;for(intt i=3;i<=sqrt(n);i+=2)if(n%i==0)return 0;return 1;}
intt is_integer(double n){if(floor(n)==ceil(n))return 1;return 0;}

intt sto_int(string s){stringstream ss(s);intt n;ss>>n;return n;}
string to_string(intt n){stringstream ss;ss<<n;string s=ss.str();return s;}
/**************************/

intt arr[maxx];
int main() {
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    //ofstream fout ("test.out");
    //ifstream fin ("test.in");
    IO;
    intt n, k, ok = 0;
    cin >> n >> k;
    for (intt i = 1; i <= n; i++) {
        cin >> arr[i]; if (arr[i] >= k) ok = 1;
    }
    if (!ok)
        return cout << "IMPOSSIBLE" << endl, 0;
    intt g = arr[1];
    for (intt i = 2; i <= n; i++)
        g = gcd (g, arr[i]);
    if (k % g == 0)
        cout << "POSSIBLE" << endl;
    else
        cout << "IMPOSSIBLE" << endl;
    return 0;
}


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

using namespace std;

using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using vvvll = vector<vector<vector<ll>>>;
using vvvvll = vector<vector<vector<vector<ll>>>>;
using pl4 = pair<ll,ll>;
using str = string;
using vpl4 = vector<pair<ll,ll>>;

#define sz size()
#define be begin()
#define en end()
#define fi first
#define se second
#define pb push_back
#define mp make_pair

#define llin(x) ll(x);cin >> (x);
#define stin(x) str(x);cin >> (x);
#define vllin(x,n) vll(x)(n);FOR(i,0,n-1){cin >> (x)[i];}
#define vllin2(a,b,n) vll(a)(n);vll(b)(n);FOR(i,0,n-1){cin >> (a)[i] >> (b)[i];}
#define vllin3(a,b,c,n) vll(a)(n);vll(b)(n);vll(c)(n);FOR(i,0,n-1){cin >> (a)[i] >> (b)[i] >> (c)[i];}
#define vlling(x,n) (x).assign(n,0);FOR(i,0,n-1){cin >> (x)[i];}
#define vlling2(a,b,n) (a).assign(n,0);(b).assign(n,0);FOR(i,0,n-1){cin >> (a)[i] >> (b)[i];}
#define vlling3(a,b,c,n) (a).assign(n,0);(b).assign(n,0);(c).assign(n,0);FOR(i,0,n-1){cin >> (a)[i] >> (b)[i] >> (c)[i];}
#define vpl4in(x,n) vpl4(x)((n),mp(0,0));FOR(i,0,n-1){cin >> x[i].fi >> x[i].se;}
#define FOR(i,a,b) for(ll i=a;i<=b;i++)
#define rFOR(i,b,a) for(ll i=a;i>=b;i--)
#define SORT(x) sort(x.be,x.en)
#define rSORT(x) sort(x.rbegin(),x.rend())
#define say(x) cout << (x);
#define sal(x) cout << (x) << endl;
#define says(x) cout << (x) << (' ');
#define sas cout << (' ');
#define sayR(x) cout << fixed << setprecision(10) << (x);
#define salR(x) cout << fixed << setprecision(10) << (x) << endl;
#define yn(a) cout << ((a) ? "yes" : "no") << endl;
#define Yn(a) cout << ((a) ? "Yes" : "No") << endl;
#define YN(a) cout << ((a) ? "YES" : "NO") << endl;
#define Imp(a) cout << ((a) ? "Possible" : "Impossible") << endl;
#define IMP(a) cout << ((a) ? "POSSIBLE" : "IMPOSSIBLE") << endl;

ll MOD = 1000000007;

signed main()
{
    llin(n);
    vvll a(n,vll(n,0));
    FOR(i,0,n-1){
        FOR(j,0,n-2){
            cin >>a[i][j];
        }
    }
    vll k(n,0);
    ll o=0;
    ll c=0;
    ll s=0;
    ll q=0;
    vll w(n,0);
    vvll l(1000000,vll(0,0));
    ll r=0;
    ll i=0;
    FOR(i,0,n-1){
        l[0].pb(i);
    }
    while(true){
        c=0;
        q=0;
        FOR(j,0,n-1){
            if(k[j]<n-1){
                q=1;
                w[j]=0;
            }
        }
        if(q==0) break;
        r=l[s].sz;
    FOR(t,0,r-1){
        i=l[s][t];
        o=a[i][k[i]]-1;
        if(w[i]==0&&w[o]==0&&a[o][k[o]]==i+1){
            c=1;
            k[i]++;
            k[o]++;
            w[i]=w[o]=1;
            l[s+1].pb(i);
            l[s+1].pb(o);
        }
    }
    if(c==0){
        sal(-1)
        return 0;
    }
    s++;
    }
    sal(s)
}

Measured memory_bytes: 47104
#include <bits/stdc++.h>
using namespace std;
int i,j,k,count1=0,count2=0;
void ABC164();

int main(){
    ABC164();
}

void ABC164(){
    int n;
    cin>>n;
    vector<string> s(n);
    for(i=0;i<n;i++){
        cin>>s[i];
    }
    sort(s.begin(),s.end());
    count1=1;
    for(i=0;i<n-1;i++){
        if(s[i]!=s[i+1])count1++;
    }
    cout<<count1<<endl;
}


Measured memory_bytes: 9588
n, m = [int(i) for i in input().split(' ')]
c_list = []
for i in range(m):
    c_list.append([int(i) for i in input().split(' ')])
number = [-1 for i in range(n)]
for line in c_list:
    if number[line[0] - 1] == -1:
        number[line[0] - 1] = line[1]
    else:
        if number[line[0] - 1] == line[1]:
            continue
        else:
            print("-1")
            break
else:
    if number[0] == 0:
        if len(number) != 1:
            print("-1")
        else:
            print("0")
    else:
        for i, index in enumerate(number):
            if index == -1:
                if i == 0 and len(number) != 1:
                    index = 1
                else:
                    index = 0
            print(index, end="")

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

int main()
{
    int n;
    cin >> n;
    vector<int> c(8, 0);
    int b = 0;
    vector<int> a(n);
    for(int i = 0; i < n; i++) {
        int a;
        cin >> a;
        if(a < 400) c[0] = 1;
        else if(a < 800) c[1] = 1;
        else if(a < 1200) c[2] = 1;
        else if(a < 1600) c[3] = 1;
        else if(a < 2000) c[4] = 1;
        else if(a < 2400) c[5] = 1;
        else if(a < 2800) c[6] = 1;
        else if(a < 3200) c[7] = 1;
        else b++;
    }
    int sum = 0;
    for(int i = 0; i < 8; i++) sum += c[i];
    cout << (sum == 0 ? 1 : sum )<< " " << sum + b << endl;
    return 0;
}

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

using namespace std;
using ll = long long;
const int INF = 1000000000;

int main() {
  string s, t;
  cin >> s >> t;
  int m = INF;
  for (int i = 0; i <= s.size() - t.size(); i++) {
    int cnt = 0;
    for (int j = 0; j < t.size(); j++) {
      if (s[j + i] != t[j]) {
        cnt++;
      }
    }
    m = min(m, cnt);
  }
  cout << m << endl;
  return 0;
}


Measured memory_bytes: 3628
#include <stdio.h>
typedef long long ll;
using namespace std;

int main(void) {
  ll i, j, k, a, b, n, m, v;
  scanf("%lld", &n);
  ll cnt[100000][2];
  for(i = 0; i < 100000; ++i) cnt[i][0] = cnt[i][1] = 0;
  for(i = 0; i < n; ++i) {
    scanf("%lld", &v);
    cnt[v - 1][i & 1]++;
  }
  ll max0 = 0, max1 = 0, max01 = 0, max11 = 0, m1, m0;
  for(i = 0; i < 100000; ++i) {
    if(max0 < cnt[i][0]) max01 = max0, max0 = cnt[i][0], m0 = i;
    else if(max01 < cnt[i][0]) max01 = cnt[i][0];
    if(max1 < cnt[i][1]) max11 = max1, max1 = cnt[i][1], m1 = i;
    else if(max11 < cnt[i][1]) max11 = cnt[i][1];
  }
  if(m0 == m1) {
    printf("%lld", max0 + max11 > max1 + max01 ? n - (max0 + max11) : n - (max1 + max01));
  } else {
    printf("%lld", n - (max0 + max1));
  }
  return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1e9 + 7;
const int inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;
#define fast() ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)

// dp[i][j] := i個目まで見たとき、重さがj以下のときの価値の最大値
int N, W, weight[1 << 17], value[1 << 17];
ll dp[111][1 << 17];

int main()
{
    cin >> N >> W;
    for (int i = 0; i < N; i++)
    {
        cin >> weight[i + 1] >> value[i + 1];
    }

    for (int i = 1; i <= N; i++)
    {
        for (int j = 0; j <= W; j++)
        {
            if (j - weight[i] < 0)
                dp[i][j] = dp[i - 1][j];
            else
                dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - weight[i]] + value[i]);
        }
    }

    cout << dp[N][W] << endl;
}

Measured memory_bytes: 105472
#include <stdio.h>

int main (void){
  
  int A, B, C, X;
  
  scanf("%d", &A);
  scanf("%d", &B);
  scanf("%d", &C);
  scanf("%d", &X);
  
  int i, j, k;
  
  int count=0;
  
  for (i=0; i<=A; i++){
   for (j=0; j<=B; j++){
     for (k=0; k<=C; k++){
       
      if ( 500*i + 100*j + 50*k == X)
      { count = count + 1;}
       
     }
   }
  }
  
  printf("%d", count);
  
  return 0;
}

Measured memory_bytes: 1712
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define rando mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define fi first
#define se second
#define debug(x) cerr << " - " << #x << ": " << x << endl;
#define debugs(x, y) cerr << " - " << #x << ": " << x << " " << #y << ": " << y << endl;
#define debugii(x) cerr << " - " << #x << ": " << x.fi<<","<<x.se << endl;
#define sep() cerr << "--------------------" << endl;
#define all(x) (x).begin(),(x).end()
#define sz(x) (ll)x.size()
#define ld long double
#define ll long long
//#define int ll
#define ii pair<int,int>
#define v vector<int>
#define vii vector<ii>
#define vv vector<vector<int> >
#define mp make_pair
#define INF 1000000000
#define pb push_back
#define EPS 1e-9
const int MOD = 1000000007; // 998244353
char grid[21][21];
int xs[4]={-1,1,0,0};
int ys[4]={0,0,1,-1};
int tab[21][21][21][21];
int32_t main(){
    boost;
    int h,w;
    cin>>h>>w;
    for (int i = 0; i < h; ++i)
        for (int j = 0; j < w; ++j)
            for (int x = 0; x < h; ++x)
                for (int y = 0; y < w; ++y)
                    tab[i][j][x][y]=INF;
    for (int i = 0; i < h; ++i)
        for (int j = 0; j < w; ++j)
            cin>>grid[i][j];
    for (int i = 0; i < h; ++i)
        for (int j = 0; j < w; ++j)
        {
            if(grid[i][j]=='#')continue;
            tab[i][j][i][j]=0;
            for (int z = 0; z < 4; ++z)
            {
                int x=i+xs[z],y=j+ys[z];
                if(x<0||x>=h||y<0||y>=w||grid[x][y]=='#')continue;
                tab[i][j][x][y]=1;
                tab[x][y][i][j]=1;
            }
        }
    for (int kx = 0; kx < h; ++kx)
        for (int ky = 0; ky < w; ++ky)
            for (int i = 0; i < h; ++i)
                for (int j = 0; j < w; ++j)
                    for (int x = 0; x < h; ++x)
                        for (int y = 0; y < w; ++y)
                            if(tab[i][j][kx][ky]<INF && tab[kx][ky][x][y]<INF)
                                tab[i][j][x][y]=min(tab[i][j][x][y],tab[i][j][kx][ky]+tab[kx][ky][x][y]);
    int ans=0;
    for (int i = 0; i < h; ++i)
        for (int j = 0; j < w; ++j)
            for (int x = 0; x < h; ++x)
                for (int y = 0; y < w; ++y)
                    if(tab[i][j][x][y]<INF)
                        ans=max(ans,tab[i][j][x][y]);
    cout<<ans;
    return 0;
}
//long long
//array bounds
//special cases
//binary search

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

using ll = long long;

int main() {
    ll N, K, Asum = 0;
    cin >> N >> K;
    vector<ll> A(N), F(N);
    //B[i]: A>iが何人いるか
    rep(i, N) {
        cin >> A[i];
        Asum += A[i];
    }
    rep(i, N) cin >> F[i];
    if (Asum <= K) {
        cout << 0 << endl;
        return 0;
    }
    sort(A.begin(), A.end());
    sort(F.begin(), F.end());
    ll x = 0;
    ll amax = 1e18, amin = 0;
    while (amax > amin + 1) {
        ll a = (amax + amin) / 2;
        x = 0;
        rep(i, N) {
            ll y = A[N - 1 - i] - a / F[i];
            if (y > 0) x += y;
        }
        if (x <= K) amax = a;
        else amin = a;
    }
    cout << amax << endl;
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};



int main(){
    int a,b,c;cin >> a >> b >> c;
    cout << max(0,c-(a-b)) << endl;
    return 0;
}


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

#define int         long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define f           first
#define s          second
#define sz(x)       (int)x.size()
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define rep0(a,n)  for(int i=0;i<n;i++)cin>>a[i]
#define si(x)       cin>>x
#define sii(x,y)    cin>>x>>y
#define siii(x,y,z) cin>>x>>y>>z
#define ahell   998244353
#define hell 1000000007
#define N 1000001
#define fl 1.0000000000
//#define mod 998244353
#define cntbit(a) __builtin_popcountl(a)
#define ios ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;

main()
{
  ios
int n,m,i;
int j;
int u,v,q;
int test=1;
//si(test);

while(test--)
{
    cin>>n;
    int a[n][3];

    for(i=0;i<n;i++)
        {
            for(j=0;j<3;j++)
                cin>>a[i][j];
        }

    int dp[n][3];

    dp[0][0]=a[0][0];
    dp[0][1]=a[0][1];
    dp[0][2]=a[0][2];

    for(i=1;i<n;i++)
    {

       for(j=0;j<3;j++)
       {
            int id1=(j+1)%3,id2=(j+2)%3;
            dp[i][j]=a[i][j]+max(dp[i-1][id1],dp[i-1][id2]);

       }
    }

   int t=max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
   cout<<t;
}

}


Measured memory_bytes: 8232
#include "bits/stdc++.h"
#define MAXN 100009
#define INF 1000000007
#define mp(x,y) make_pair(x,y)
#define all(v) v.begin(),v.end()
#define pb(x) push_back(x)
#define wr cout<<"----------------"<<endl;
#define ppb() pop_back()
#define tr(ii,c) for(__typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++)
#define ff first
#define ss second
#define my_little_dodge 46
#define debug(x)  cerr<< #x <<" = "<< x<<endl;
using namespace std;

typedef long long ll;
typedef pair<int,int> PII;
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
int xx[MAXN],yy[MAXN],ata[MAXN],p[MAXN];
bool cmp1(int x,int y){
	return (xx[x]<xx[y]);
}
bool cmp2(int x,int y){
	return (yy[x]<yy[y]);
}
int tap(int x){
	if(x==ata[x])
		return x;
	return ata[x]=tap(ata[x]);	
}
bool merge(int x,int y){
	if((x=tap(x))==(y=tap(y)))
		return 0;
	ata[y]=x;return 1;	
}
int main(){
    //~ freopen("file.in", "r", stdin);
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d%d",xx+i,yy+i);
		p[i]=i;ata[i]=i;
	}
	vector<pair<int,PII> >edges;
	sort(p+1,p+n+1,cmp1);
	for(int i=1;i<n;i++)
		edges.pb(mp(xx[p[i+1]]-xx[p[i]],mp(p[i],p[i+1])));
	sort(p+1,p+n+1,cmp2);
	for(int i=1;i<n;i++)
		edges.pb(mp(yy[p[i+1]]-yy[p[i]],mp(p[i],p[i+1])));
	sort(all(edges));
	int ans=0;
	tr(it,edges)
		if(merge(it->ss.ff,it->ss.ss))
			ans+=it->ff;
	printf("%d\n",ans);	
	return 0;
}


Measured memory_bytes: 6260
class Node
  attr_accessor :state, :depth, :path_cost
  attr_reader :parent

  def initialize(state, parent)
    @state = state
    @parent = parent
    @depth = parent.nil? ? 0 : parent.depth + 1
  end

  def goal?(limit, max)
    nums.size == limit && sum == max
  end

  def bad_end?(limit, max)
    nums.length > limit || sum > max
  end

  def nums
    parent.nil? ? [state] : parent.nums << state
  end

  def sum
    nums.inject(:+)
  end
end

STDIN.read.split("\n").each do |line|
  limit, max = line.split.map(&:to_i)

  next if limit == 0 && max == 0

  goals = []
  10.times do |i|
    init_node = Node.new(i, nil)
    queue = [init_node]
    black_list = [init_node.nums.sort]

    loop do
      break if queue.empty?

      elem = queue.shift

      goals << elem if elem.goal?(limit, max)

      next if elem.bad_end?(limit, max)

      10.times do |j|
        next if elem.nums.include?(j)
        new_node = Node.new(j, elem)
        new_nums = new_node.nums.sort
        next if black_list.include?(new_nums)
        black_list << new_nums
        queue << new_node
      end
    end
  end

  puts goals.map { |e| e.nums.sort }.uniq.size
end

Measured memory_bytes: 10936
n, d = map(int, input().split())

points = []

for _ in range(n):
    points.append(list(map(int, input().split())))

def distance(a, b):
    dist = 0

    for a, b in zip(a, b):
        dist += (a - b) ** 2

    if dist == 0:
        return False

    return int(dist ** 0.5) ** 2 == dist

count = 0

for pa in points:
    for pb in points:
        if distance(pa, pb):
            count += 1

print(count // 2)

Measured memory_bytes: 9460
import java.io.*;
public class Main {
	public static void main(String[] args)throws IOException{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		String str=br.readLine();
		if(str.equals("a")||str.equals("i")||str.equals("u")||str.equals("e")||str.equals("o")){
			System.out.println("vowel");
		}
		else System.out.println("consonant");
	}
}

Measured memory_bytes: 8148
#include <iostream>
#include <vector>
#include <cstring>

using namespace std;

#define MAX_T 1000001

bool table[MAX_T];
vector<int> prime;

void init() {
    memset(table, 1, sizeof(table));
    table[0] = table[1] = false;
    for (int i = 2; i < MAX_T; i++) {
        if (table[i]) {
            prime.push_back(i);
            for (int j = i + i; j < MAX_T; j+=i) {
                table[j] = false;
            }
        }
    }
}

int main() {
    int a, d, n;
    init();
    while (cin >> a >> d >> n) {
        if (a == 0 && d == 0 && n == 0) break;
        int p = 0;
        for (int i = 0; ; i++) {
            if (table[a + d*i]) {
                p++;
            }
            if (p == n) {
                cout << a + d*i << endl;
                break;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 0
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define PI 3.141592
#define LL_INF 9000000000000000000
#define LL_MINF -9000000000000000000
#define INT_INF 2000000000
#define INT_MINF -2000000000
#define all(a) (a).begin(), (a).end()
#define fi first
#define se second
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

int main(){
    int N, M;
    cin >> N >> M;
    map<int,int> count;
    for(int i = 0; i < M; i++){
        int a, b;
        cin >> a >> b;
        count[a]++;
        count[b]++;
    }
    for(int i = 1; i <= N; i++){
        cout << count[i] << endl;
    }
}


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

using namespace std;

int main()
{
	string s;
	cin >> s;
	string r;
	for (auto&& si : s)
		if (r.empty() || r.back() != si)
			r += si;
	cout << r.size() - 1 << endl;
	return 0;
}


Measured memory_bytes: 640
// +build ignore
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
	"strings"
)

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []byte {
	return []byte(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

func gcd(x, y int) int {
	if x%y != 0 {
		return gcd(y, x%y)
	}
	return y
}

func run(input io.Reader, output io.Writer) int {
	sc := NewScanner()
	a := sc.nextRuneSlice()
	b := sc.nextRuneSlice()
	c := sc.nextRuneSlice()

	abc := fmt.Sprintf("%c%c%c\n", a[0], b[0], c[0])

	fmt.Println(strings.ToUpper(abc))

	return 0
}

func main() {
	os.Exit(run(os.Stdin, os.Stdout))
}


Measured memory_bytes: 640
def waru(x):
  ret_val=0
  while x>0:
    if x%2:
      break
    else:
      x//=2
      ret_val+=1
  return ret_val

N=int(input())
check_val=0
ans=1
for i in range(1,N+1):
  temp=waru(i)
  if check_val<temp:
    check_val=temp
    ans=i
print(ans)


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(long long i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,n-1,0)
#define RREPS(i,n) RFOR(i,n,1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
const int INF=1e18;
const int MOD=1e9+7;
int divup(int x,int y){
    if(x%y==0)return x/y;
    else return x/y+1;
}

signed main(){
    int n,x,y;cin>>n>>x>>y;
    map<int,int>co;
    REPS(i,n-1)for(int j=i+1;j<=n;j++){
        int dist=min({j-i,abs(x-i)+abs(y-j)+1,abs(x-j)+abs(y-i)+1});
        co[dist]++;
    }
    REPS(i,n-1)cout<<co[i]<<endl;
}

Measured memory_bytes: 384
#include <iostream>

using namespace std;

int h, w;
char c[105][105];
bool delx[105], dely[105];

int main(void)
{
	cin >> h >> w;
	for(int y = 1; y <= h; y++){
		for(int x = 1; x <= w; x++){
			cin >> c[x][y];
		}
	}
	
	for(int y = 1; y <= h; y++){
		bool flag = false;
		for(int x = 1; x <= w; x++){
			if(c[x][y] == '#'){
				flag = true;
				break;
			}
		}
		if(!flag) dely[y] = true;
	}
	
	for(int x = 1; x <= w; x++){
		bool flag = false;
		for(int y = 1; y <= h; y++){
			if(c[x][y] == '#'){
				flag = true;
				break;
			}
		}
		if(!flag) delx[x] = true;
	}
	
	for(int y = 1; y <= h; y++){
		if(dely[y]) continue;
		for(int x = 1; x <= w; x++){
			if(delx[x]) continue;
			cout << c[x][y];
		}
		cout << endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
## coding: UTF-8
import math
A, B, H, M = map(int,input().split())

A_theta = H * 30 + M * 0.5
B_theta = M * 6

A_zahyou = [A * math.sin(math.radians(A_theta)) , A * math.cos(math.radians(A_theta)) ]
B_zahyou = [B * math.sin(math.radians(B_theta)) , B * math.cos(math.radians(B_theta)) ]
#print(A_zahyou, B_zahyou)

dist_2 = (A_zahyou[0] - B_zahyou[0]) ** 2 + (A_zahyou[1] - B_zahyou[1]) ** 2
dist = math.sqrt(dist_2)
print(dist)
#sin30 = math.sin(math.radians(30))
#print(sin30)

Measured memory_bytes: 62560
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	ll N,C,K;
	cin >> N >> C >> K;
	vector<ll> T(N);
	for(int i=0;i<N;++i){
		cin >> T[i];
	}
	sort(T.begin(),T.end());
	ll res = 0;
	int i=0;
	ll t = 0;ll ct = 0;
	while(i<N){
		t = T[i++]+K;
		ct = 1;
		while(ct < C && i<N && T[i] <= t){
			++i;++ct;
		}
		++res;
	}
	cout << res << endl;
	return 0;
}

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

int main() {
	string a,b;
	while(cin>>a>>b){
		string s=a+b;
		stringstream geek(s);
		int n;
		geek>>n;
		int c=sqrt(n);
		if(c*c==n){
			printf("Yes\n");
		}
		else{
			printf("No\n");
			
		}
		//int n=(int)s;
		//int m=n%10;
	
		
		
		
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
#define FOR(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)
#define rep(i,n) FOR(i,0,n-1)
#define int long long

int s[200005];

signed main(){
	
	int n,m,x;cin>>n>>m>>x;
	
	int l = 0,r = 0;
	rep(i,m)
	{
		int a;cin>>a;
		if(a<x) l++;
		else r++;
	}
	
	
	cout << min(r,l) << endl;
}

//cout << ans << endl;

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD=1000000007;

int main() {
    string S; cin>>S;
    ll ans=0;
    for(int bit=0;bit<(1<<(S.size()-1));bit++){
        ll bubunwa=0;
        for(int i=0;i<S.size();i++) {
            bubunwa=bubunwa*10+S[i]-'0';
            if (bit & (1 << (S.size()-1-i-1))) {
                ans+=bubunwa;
                bubunwa=0;
            }
        }
        ans+=bubunwa;
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>

using namespace std;

int main() {
    long NUM = 1000000;
    long n;
	long counter = 0;
	bool primeNum[NUM + 10];

	long i, ii, j, len = NUM + 10;
	
	primeNum[0] = primeNum[1] = false;
	for (i = 2; i < len; i++) primeNum[i] = true;
	
	ii = 4;
    for(i = 2; ii < NUM;) {
        if (primeNum[i]) {
            for (j = ii; j < NUM; j += i) {
                primeNum[j] = false;
            }
        }
        
        i++;
        ii = i * i;
    }
    
    while (scanf("%ld", &n) != EOF) {
        counter = 0;
        
        for (i = 0; i <= n; i++) {
            if (primeNum[i]) counter++;
        }
        
        printf("%ld\n", counter);
    }

    return 0;
}

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

int main() {
	int n;
	cin >> n;
	string s;
	cin >> s;
	int c =0;
	for(int i=1;i<n;i++){
		if(s[i]=='E')c++;
	}
	int ans = c;
	for(int i=1;i<n;i++){
		if(s[i]=='E')c--;
		if(s[i-1]=='W')c++;
		ans = min(ans,c);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 900
W, H, N = list(map(int,input().split()))
l, r, u, d = 0, W, H, 0
for _ in range(N):
    x, y, a = list(map(int,input().split()))
    if a==1: l = max(l,x)
    if a==2: r = min(r,x)
    if a==3: d = max(d,y)
    if a==4: u = min(u,y)
print(max(0,r-l)*max(0,u-d))

Measured memory_bytes: 3064
while True:
   m, f, r = [int(i) for i in input().split()]
 
   if m == f == r == -1:
      break
   total = m + f
   if m == -1 or f == -1 or total < 30:
      print("F")
   
   elif total < 50 and r < 50:
      print("D")

   elif r >= 50 or total < 65:
      print("C")
   
   elif total < 80:
      print("B")

   else:
      print("A")

Measured memory_bytes: 7724
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <list>
#include <set>
#include <stack>
#include <cctype>
#include <cmath>
#include <bitset>

using namespace std;

/* typedef */
typedef long long ll;

/* constant */
const int INF = 1 << 30;
const int NIL = -1;
const int MAX = 100000;
const int mod = 1000000007;
const double pi = 3.141592653589;

/* global variables */
vector<int> parent(MAX), prenum(MAX), lowest(MAX);
vector< vector<int> > Adj(MAX);
vector<bool> visited(MAX, false);
int N;
int timer;

/* function */
void dfs(int cur, int prev);
void art_points();

/* main */
int main() {
    int m;
    cin >> N >> m;
    for (int i = 0; i < m; i++) {
        int v, u;
        cin >> v >> u;
        Adj[v].push_back(u);
        Adj[u].push_back(v);
    }

    art_points();

}

void dfs(int cur, int prev) {
    // after visited node cur
    prenum[cur] = lowest[cur] = timer;
    timer++;
    visited[cur] = true;

    int next;
    for (int i = 0; i < Adj[cur].size(); i++) {
        next = Adj[cur][i];
        if ( !visited[next] ) {
            // before visiting next node
            parent[next] = cur;
            dfs(next, cur);
            // after visiting next node
            lowest[cur] = min(lowest[cur], lowest[next]);
        }
        else if (next != prev) {
            // Edge(cur, next) is Back-Edge
            lowest[cur] = min(lowest[cur], prenum[next]);
        }
    }
}

void art_points() {
    timer = 1;
    // calculate lowest
    dfs(0, -1); // 0 == root

    set<int> ap;
    int child_of_root = 0;
    for (int i = 1; i < N; i++) {
        int p = parent[i];
        if (p == 0) child_of_root++;
        else if (prenum[p] <= lowest[i]) ap.insert(p);
    }
    if (child_of_root >= 2) ap.insert(0);
    for (auto it = ap.begin(); it != ap.end(); it++) {
        cout << *it << '\n';
    }
}


Measured memory_bytes: 7808
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define mem(x,y)		(x*)malloc(sizeof(x)*(y));

int main()
{
	int i,j;
	for(i = 0;i < 3;i++)
	{
		int in[3],out[3];
		for(j = 0;j < 3;j++)
		{
			scanf("%d",&in[j]);
		}
		for(j = 0;j < 3;j++)
		{
			scanf("%d",&out[j]);
			out[j] -= in[j];
		}
		for(j = 2;j >= 0;j--)
		{
			if(out[j] < 0)
			{
				out[j]+=60;
				out[j-1]--;
			}
		}
		printf("%d %d %d\n",out[0],out[1],out[2]);
	}
	return 0;
}

Measured memory_bytes: 0
//
// Created by Akifumi Ohata on 2017/09/30.
//


#include<iostream>
#include <vector>
#include <numeric>
#include <math.h>
#include <cmath>

using namespace std;

using ll =  long long ;

int main() {

    int A, B,C;

    cin >> A >> B >> C;


    std::vector<int> array(3,0);


    array[0]=A+B;
    array[1]=B+C;
    array[2]=C+A;


    std::vector<int>::iterator iter = std::min_element(array.begin(), array.end());
    size_t index = static_cast<size_t>(std::distance(array.begin(), iter));

    cout<< array[index] << endl;

    return 0;

}

Measured memory_bytes: 888
using System;

public class Hello
{
    public static void Main()
    {
        var a = new int[6];
        for (int i = 0; i < 6; i++) a[i] = int.Parse(Console.ReadLine().Trim());
        Console.WriteLine(a[4] - a[0] > a[5] ? ":(" : "Yay!");
    }
}

Measured memory_bytes: 11092
#include <stdio.h>

int main(void){

	int h, w;
	int i, j;

	while(1){
		scanf("%d %d ", &h, &w);	/* H??¨W?????\??? */

		if(h==0&&w==0)break;		/* H??¨W????????????0??????????????¢?????????????????? */
		for(i=0;i<h;i++){			/* ???H?????????????????? */
			for(j=0;j<w;j++){		/* ?¨?W?????????????????? */
				if((i%2==0&&j%2==0)||(i%2==1&&j%2==1)){		/* ??¶??°??? ?\???°??? ??¶??°??? ?\???°????????´????????? */
					printf("#");	/* if??§???????????????????????????#????????? */

				}else{
					printf(".");	/* if??§??????????????????????????????????????? */
				}
			}
			printf("\n");
		}
		printf("\n");
	}

	return 0;
}

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

void __print(int x) {cerr << x;};void __print(long x) {cerr << x;};void __print(long long x) {cerr << x;};void __print(unsigned x) {cerr << x;};void __print(unsigned long x) {cerr << x;};void __print(unsigned long long x) {cerr << x;};void __print(float x) {cerr << x;};void __print(double x) {cerr << x;};void __print(long double x) {cerr << x;};void __print(char x) {cerr << '\'' << x << '\'';};void __print(const char *x) {cerr << '\"' << x << '\"';};void __print(const string &x) {cerr << '\"' << x << '\"';};void __print(bool x) {cerr << (x ? "true" : "false");}

#define int             long long
#define setbits(x)      __builtin_popcountll(x)
#define zerobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define endl             '\n'
#define pb              push_back
#define all(x)          x.begin(),x.end()
int powmod(int a,int b) {int res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
int string_to_int(string s){int ans = 0;int p=1;for(int i=s.size()-1;i>=0;i--){ans += (s[i]-'0')*p;p *= 10;}return ans;}

//DEBUGGING-LINES
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr <<'}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i);cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

void t_c_c()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
/*#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif*/
		int arr[4] = {0};
	int tc; cin >> tc;
	while(tc--){
		string s; cin >> s;
		if(s=="AC") arr[0]++;
		if(s=="WA") arr[1]++;
		if(s=="TLE") arr[2]++;
		if(s=="RE") arr[3]++;
	}
	cout << "AC x " << arr[0] << endl;
	cout << "WA x " << arr[1] << endl;
	cout << "TLE x " << arr[2] << endl;
	cout << "RE x " << arr[3] << endl;
}

int32_t main()
{
	t_c_c();
	return 0;
}


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

# define rep(i, n) for(int(i)=0;(i)<(n);(i)++)
# define reps(i, n) for(int(i)=1;(i)<=(n);(i)++)
# define rrep(i, n) for(int i=((int)(n)); i>0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>=0; --i)
# define ALL(v) v.begin(), v.end()
template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<typename T> void dump(T e){std::cout << e << std::endl;}
template<typename T> void dump(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void dump(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ dump(v); } }
template <typename T>
void dump_stack(std::stack<T>& stack) {
  std::stack<T> temp;
  while (!stack.empty()) {
    T top = stack.top(); stack.pop();
    std::cout << top << " ";
    temp.push(top);
  }
  std::cout << endl;
  while (!temp.empty()) {
    T top = temp.top(); temp.pop();
    stack.push(top);
  }
}
template <typename T>
void dump_queue(std::queue<T>& queue) {
  std::queue<T> temp;
  while (!queue.empty()) {
    T top = queue.front(); queue.pop();
    std::cout << top << " ";
    temp.push(top);
  }
  std::cout << endl;
  while (!temp.empty()) {
    T top = temp.front(); temp.pop();
    queue.push(top);
  }
}

typedef long long ll;



int main() {
  ll n; cin>>n;
  vector<ll> a(n);
  rep(i,n) cin>>a[i];
  
  vector<ll>ans;
  rep(i,a.size()){
    if(i==0) continue;
    if(a[i-1] > a[i]){
      ans.push_back(a[i-1]-a[i]);
      a[i] +=a[i-1]-a[i];
    }
  }
  ll r=0;
  bool b = ans.empty();
  if (b==false) {
    rep(i,ans.size()) r += ans[i];
  }
  cout << r << endl;
}


Measured memory_bytes: 6752
//#pragma GCC optimize("O-fast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
//#pragma comment(linker, "/STACK:367077216")

#include <iostream>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef long double ld;

#define pii pair<int, int>
#define F first
#define S second
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define pop pop_back

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	string s1, s2;
	cin >> s1 >> s2;
	s1 += s2[(int)s2.size() - 1];
	cout << ((s1 == s2) ? "Yes" : "No");
	return 0;
}

Measured memory_bytes: 3644
fun main(){
    val (x, y) = readLine()!!.split(" ").map { it.toInt() }
    val min = x * 2
    val max = x * 4
    if (y % 2 == 0 && y >= min && y <= max){
        println("Yes")
    } else {
        println("No")
    }
}

Measured memory_bytes: 36416
#include <bits/stdc++.h>
 
#define rep(i,n) for(ll i=0;i<n;++i)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()

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

const ll MOD  = 1e9 + 7;
const ll LINF = 1LL << 62;
const int INF = 1e9 + 7;

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

    string s;
    cin >> s;

    vector<ll> back(1);
    back[0] = 0;
    ll ans = 0;
    ll cnt = 0;

    rep(i, n){
        if(s[i] == '0'){
            cnt++;
            while(s[i] == '0')i++;
            back.push_back(i);
            if(cnt > k){
                back.erase(back.begin());
                cnt = k;
            }
        }
        ll len = i - back.front() + 1;
        if(i == n)len--;
        ans = max(ans, len);
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 3904
while 1:
    try:
        p=[0]*100
        while 1:
            a,b=map(int,raw_input().split())
            if a==0:
                break
            p[a-1]+=1
            p[b-1]+=1
        if p[0]%2==p[1]%2==1 and sum(filter(lambda x:x%2==1,p[2:]))==0:
            print 'OK'
        else:
            print 'NG'
    except:
        break

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

int main(void){
	int a, b, c;
	cin >> a >> b;
	if(b<10) c = 10*a+b;
	else if(b<100) c = 100*a+b;
	else if(b==100) c = 1000*a+b;
	for(int i=0; i<=316; i++){
		if(i*i==c){
		cout << "Yes" << endl;
		return 0;
		}
	}
	cout << "No" << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <list>
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;

typedef pair <long long, long long>  pii;

const int MAXN = 500 + 5, MAXC = 30 + 3;
long long a, b;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> a >> b;
    long long c = b - a;
    long long d = (c * (c - 1) / 2);
    cout << d - a;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <queue>
#include <vector>
#define LL long long
using namespace std;
const int MAXN = 2 * 1e5 + 5;
char s[MAXN];
int n, ans;
int main() {
	scanf("%s", s + 1);
	n = strlen(s + 1);
	for(int i = 1; i <= n; i ++) {
		ans += s[i] - '0';
	}
	if(ans % 9 == 0) printf("Yes");
	else {
		printf("No");
	}
	return 0;
}

Measured memory_bytes: 1920
#include <bits/stdc++.h>
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define IFOR(i, m, n) for(int i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
const int MOD = 1000000007;
/* テンプレートここまで */

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

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

  vector<int> h(N);

  REP(i,N){
    cin >> h[i];
  }

  vector<ll> dp(N, INF);
  dp[0] = 0;

  REP(i, N-1){
    chmin(dp[i+1], dp[i] + abs(h[i] - h[i+1]));
    chmin(dp[i+2], dp[i] + abs(h[i] - h[i+2]));
  }

  cout << dp[N-1] << endl;

}


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

import sys
import os

for s in sys.stdin:
    A = list(map(int, s.split(',')))
    A.sort()
    #print(A)

    if (A[0] == A[1] == A[2] == A[3]) or (A[1] == A[2] == A[3] == A[4]):
        print('four card')

    # full house
    elif (A[0] == A[1] == A[2]) and (A[3] == A[4]):
        print('full house')
    elif (A[0] == A[1]) and (A[2] == A[3] == A[4]):
        print('full house')

    # straight
    elif A[0] == A[1] - 1 == A[2] - 2 == A[3] - 3 == A[4] - 4:
        print('straight')
    elif A[1] == 10 and A[2] == 11 and A[3] == 12 and A[4] == 13 and A[0] == 1:
        print('straight')

    # three card
    elif (A[0] == A[1] == A[2]) or (A[1] == A[2] == A[3]) or (A[2] == A[3] == A[4]):
        print('three card')

    # two pair
    elif ((A[0] == A[1]) and (A[2] == A[3])) or ((A[0] == A[1]) and (A[3] == A[4])) or ((A[1] == A[2]) and (A[3] == A[4])):
        print('two pair')

    # one pair
    elif (A[0] == A[1]) or (A[1] == A[2]) or (A[2] == A[3]) or (A[3] == A[4]):
        print('one pair')

    else:
        print('null')

Measured memory_bytes: 7616
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

int main() {
    int n, k;
    cin >> n >> k;
    vec p(n);
    rep(i, n) cin >> p[i];

    vector<double> q(n);
    rep(i, n) {
        q[i] = p[i]+1;
        q[i] /= 2;
    }

    vector<double> s(n+1);
    s[0] = 0;
    rep(i, n) s[i+1] = s[i] + q[i];

    double res = -1;

    for (int i = 0; i + k <= n; i++) {
        res = max(res, s[i+k] - s[i]);
    }

    cout << fixed << setprecision(10) << res << endl;
    return 0;
}

Measured memory_bytes: 4096