akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
long long const MX = 2e5 + 2, MOD = 1e9 + 7;
long long c[MX], p[MX];
int main()
{
    long long t = 1;
//    cin>>t;
    while(t--){
        long long n , k;
        cin>>n>>k;
        long long mx = -1e9 - 1;
        for(long long i = 0; i < n; i++) cin>>p[i],p[i]--;
        for(long long i = 0; i < n; i++){
            cin>>c[i];
            mx = max(mx, c[i]);
        }
        if(mx <= 0) {
            cout<<mx;
            continue;
        }
        mx = -1e15;
        for(long long i = 0; i < n; i++){
            long long cntp = 0, sum = 0, x = i;
            while(true){
                sum += c[p[x]];
                x = p[x];
                cntp++;
                if(x == i) break;
            }
//            long long l = k, ans = 0;
//                ans += max(0ll, sum) * ((long long)k/cntp);
//                l = k % cntp;
//            mx = max(mx, ans);
//            for(long long j = 0; j < cntp; j++){
//                if(j == l) break;
//                ans = ans + c[p[x]];
//                x = p[x];
//                mx = max(mx, ans);
//            }
            long long cnt = 0, path = 0;
            x = i;
            while(true){
                cnt++;
                path += c[x];
                if(cnt > k) break;
                int num = (k - cnt)/cntp;
                long long score = path + max(0ll, sum)*num;
                mx = max(mx, score);
                x = p[x];
                if(x == i) break;
            }
        }
        cout<<mx;
    }
}




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

int main(){
    int a,b,c,d;
    c = d = 0;
    cin >> a >> b;
    for(int i = 0;i < b;i++){
        cin >> c;
        d = d + c;
    }
    if(d > a){
        cout << -1 << endl;
    }else{
        cout << a - d <<endl;
    }
}

Measured memory_bytes: 3632
import sys
N = int(input())
s = [0] * N
for n in range(N):
    s[n] = int(input())
total = sum(s)

ans = total
s_copy = s.copy()
while ans % 10 == 0:
    ans -= min(s_copy)
    if ans == 0:
        print(ans)
        sys.exit()
    del s_copy[s_copy.index(min(s_copy))]

ans_2 = total
while ans_2 % 10 == 0:
    for item in sorted(s):
        if item % 10 != 0:
            ans_2 -= item
            break
print(max(ans, ans_2))

Measured memory_bytes: 3064
using System;

class Shinobu {
  static void Main() {
    int[] a = new int[10];
    for (int i = 0; i < 10; i++) {
      a[i] = int.Parse(Console.ReadLine());
    }

    Array.Sort(a);
    Array.Reverse(a);
    for (int i = 0; i < 3; i++) {
      Console.WriteLine(a[i]);
    }
  }
}

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

using namespace std;

map<int,int> col;
map<int,int> raw;
int ans[500][500];
char least[500][500];
int main()
{
    int n,m,k;

    cin >> n >> m >> k;


    for (int i = 0 ; i < n ; i++){
        for (int j = 0 ; j < m ; j++){
            cin >> least[i][j];
            if (least[i][j] == '#'){
                col[j]++;
                raw[i]++;
            }
        }
    }





    int cont = 0;

    for (int i = 0 ; i < n ; i++){
        if (raw[i])cont++;
        else continue;
        bool ok = true;
        for (int j = 0 ; j < m ; j++){
            if (least[i][j] == '.'){
                ans[i][j] = cont;
            }
            else {
                if (ok){
                    ok = false;
                    ans[i][j] = cont;
                }
                else {
                    cont++;
                    ans[i][j] = cont;
                }
            }
        }
    }




    for (int i = 0 ; i < m ; i++){
        bool ok = true;
        int mark = 0;
        for (int j = 0 ; j < n ; j++){
            if (ans[j][i] != 0){
                mark = ans[j][i];

            }
            ans[j][i] = mark;
        }


        mark = 0;
        for (int j = n - 1 ; j >= 0 ; j--){
            if (ans[j][i] != 0){
                mark = ans[j][i];

            }
            ans[j][i] = mark;
        }
    }

    for (int i = 0 ; i < n ; i++){
        for (int j = 0 ; j < m ; j++){
            cout << ans[i][j] << " ";
        }
        cout << "\n";
    }

    return 0;
}


Measured memory_bytes: 1536
#include<cstdio>
#include <iostream>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
#include<functional>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<numeric>

using namespace std;
typedef long long ll;
typedef pair<int, int> Pr;

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

	if (A + B >= 10) {
		cout << "error" << endl;
	}
	else
		cout << A + B << endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#include <list>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T, typename S>
ostream& operator<<(ostream& os, pair<T, S> a) {
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for (auto x : v) os << x << ' ';
    return os;
}
void debug() {
    cerr << '\n';
}
template <typename H, typename... T>
void debug(H a, T... b) {
    cerr << a;
    if (sizeof...(b)) cerr << ", ";
    debug(b...);
}
bool dp[82][82][80*80*2];
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int h, w;
    int a[81][81]={}, b[81][81]={};
    cin >> h >> w;
    rep(i,h)rep(j,w)cin >> a[i][j];
    rep(i,h)rep(j,w)cin >> b[i][j];
    dp[1][0][0] = true;
    dp[0][1][0] = true;
    auto ok = [&](int i, int j){
        return 0<=i and i < h and 0<=j and j < w;
    };
    rep(i,h+1)rep(j,w+1)rep(k,80*(i+1+j+1)+1){
        if(dp[i][j][k]){
            if(ok(i,j-1)){
                int t = abs(a[i][j-1]-b[i][j-1]);
                show(i,j,t);
                dp[i+1][j][k+t] = dp[i+1][j][abs(k-t)] = true;
            }
            if(ok(i-1,j)){
                int s = abs(a[i-1][j]-b[i-1][j]);
                show(i,j,s);
                dp[i][j+1][k+s] = dp[i][j+1][abs(k-s)] = true;
            }
        }
    }
    int ans = 0;
    while(1){
        if(dp[h][w][ans]){
            cout << ans << endl;
            return 0;
        }
        ans++;
    }
}

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

int main()
{
    ll n, i, j, p, x, a[20009], b[20009];
    cin >> n;
    for(i = 0; i < n; i++)
        a[i] = i+1;
    for(i = n-1; i >= 0; i--)
        b[i] = n-i;


    for(i = 0; i < n; i++)
    {
        cin >> p;
        a[p-1] += i;
        for(j = p-1; j < n; j++)
        {
            a[j] += n;
            b[j] -= n;
        }
    }

    x = 1 - b[n-1];
    for(i = 0; i < n; i++)
    {
        a[i] += x;
        b[i] += x;
    }

    for(i = 0; i < n; i++)
        cout << a[i] << " ";
    cout << "\n";
    for(i = 0; i < n; i++)
        cout << b[i] << " ";
}


Measured memory_bytes: 3904
#include <iostream>

using namespace std;

int main()
{
    auto check = [](int p, int q) {
        const auto squareNorm = p * p + q * q;
        // enumerate all natural numbers
        for (int n = 0;; ++n) {
            // if <m, n> . <x, y> = <p, q> then (m^2 + n^2) * (x^2 + y^2) = p^2 + q^2
            // so, if n^2 > p^2 + q^2 then (x^2 + y^2) < 1. there is no such integers.
            if (n * n > squareNorm) {
                break;
            }
            for (int m = 0; m <= n; ++m) {
                if (m * m > squareNorm) {
                    break;
                }
                // m^2 + n^2 > 0
                if (n * n + m * m <= 0) {
                    continue;
                }
                auto f = [p, q](int n_, int m_) {
                    // trivial solution
                    if ((n_ ==  1 && m_ ==  0) ||
                        (n_ ==  0 && m_ ==  1) ||
                        (n_ == -1 && m_ ==  0) ||
                        (n_ ==  0 && m_ == -1) ||
                        (n_ ==  p && m_ ==  q) ||
                        (n_ == -q && m_ ==  p) ||
                        (n_ == -p && m_ == -q) ||
                        (n_ ==  q && m_ == -p)) {
                        return false;
                    }
                    // is divisor?
                    // note: this equation can derive by solving Ginkgo multiplication definition
                    return (n_ * p + m_ * q) % (n_ * n_ + m_ * m_) == 0 &&
                           (n_ * q - m_ * p) % (n_ * n_ + m_ * m_) == 0;
                };
                if (f(n, m) || f(n, -m) || f(-n, m) || f(-n, -m)) {
                    return false;
                }
            }
        }
        return true;
    };

    int N;
    cin >> N;
    for (int i = 0; i < N; ++i) {
        int n, m;
        cin >> n >> m;
        cout << (check(n, m) ? 'P' : 'C') << endl;
    }
}


Measured memory_bytes: 2976
#include <cstdio>
#include <cstdlib>

int main(){
    int w,a,b;
    scanf("%d %d %d",&w,&a,&b);
    if(abs(a - b) > w){
        printf("%d\n",abs(a - b) - w);
    }else if(abs(a - b) <= w){
        printf("0\n");
    }

    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<cmath>
#include<cstdio>
#include<algorithm>
using namespace std;
const int maxv = 10010;
int V,E;
int par[maxv], rank[maxv];
void init(int n){
	for(int i = 0; i < n; i++){
		par[i] = i;
		rank[i] = 0;
	}
}
int find(int x){
	if(par[x]==x) return par[x];
	return par[x]=find(par[x]);
}
void unite(int x, int y){
	x = find(x);
	y = find(y);
	if(x == y) return;
	if(rank[x] > rank[y]) par[y] = x;
	else par[x] = y;
	if(rank[x] == rank[y]) rank[x]++;
}
bool same(int x, int y){
	return find(x) == find(y);
}
struct edge{
	int u,v;
	double cost;
}es[maxv*maxv];
bool cmp(const edge & e1, const edge & e2){
	return e1.cost > e2.cost;
}
struct position{
	double x,y;
}pos[maxv];
int main(){
	while(cin>>V>>E){
		for(int i = 0; i < V; i++){
			cin>>pos[i].x>>pos[i].y;
		}
		for(int i = 0; i < E; i++){
			cin>>es[i].u>>es[i].v;
			es[i].cost=sqrt((pos[es[i].u-1].x-pos[es[i].v-1].x)*(pos[es[i].u-1].x-pos[es[i].v-1].x)+(pos[es[i].u-1].y-pos[es[i].v-1].y)*(pos[es[i].u-1].y-pos[es[i].v-1].y));
		}
		sort(es,es+E,cmp);
		init(V);
		double res = 0,sum=0;
		for(int i = 0; i < E; i++){
			edge e = es[i];
			//cout<<e.cost<<endl;
			sum+=e.cost;
			if(!same(e.u, e.v)){
				unite(e.u, e.v);
				res+=e.cost;
			}
		}
		printf("%.3lf\n",sum-res);
	//	cout<<sum-res<<endl;
	}
}

Measured memory_bytes: 1940
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<functional>
#include <random>
#include<iostream>
#include<iomanip>
using namespace std;

int N, A, x[50];

long long num_[51][100000];

long long selection(int card, int pt) {

	if (num_[card][pt+2500] >= 0) {
		return num_[card][pt + 2500];

	}

	if (card == 0 && pt != 0) {
		num_[card][pt + 2500] = 0;
		return num_[card][pt + 2500];
	}
	if (card == 0 && pt == 0) {
		num_[card][pt + 2500] = 1;
		return num_[card][pt + 2500];
	}
	long long ret=0;
	/*x[card - 1]を取るとき*/
	ret += selection(card - 1, pt - x[card - 1]);
	/*取らないとき*/
	ret += selection(card - 1, pt);

	num_[card][pt + 2500] = ret;
	return num_[card][pt + 2500];
}


int main() {
	cin >> N >> A;
	for (int i = 0; i < N; i++) {
		cin >> x[i];
		x[i] -= A;
	}
	for (int i = 0; i <= N; i++) {
		for (int j = 0; j < 10000; j++) {
			num_[i][j] = -1;
		}
	}

	cout << selection(N, 0) - 1; //「何も選ばない」を抜く。

}

Measured memory_bytes: 37504
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <math.h>
#include <stack>
#include <climits>
#include <bitset>
#include <utility>


using namespace std;
typedef long long ll;

//最小公倍数
ll gcd(ll x, ll y) {
  ll tmp = 0;
  if (x < y){
    tmp=x;
    x=y;
    y=tmp;
  }
  while (y > 0) {
    ll r = x % y;
    x = y;
    y = r;
  }
  return x;
}

//最大公倍数
ll lcm(ll x,ll y){
  return x/gcd(x,y)*y;
}

//階乗
ll kaijo(ll k){
    ll sum = 1;
    for (ll i = 1; i <= k; ++i)
    {
        sum *= i;
        sum%=1000000000+7;
    }
    return sum;
}

//for(int i = ; i < ; i++){}

ll lmax(ll s,ll t){
  if(s>t){
    return s;
  }
  else{
    return t;
  }
}

ll lmin(ll s,ll t){
  if(s<t){
    return s;
  }
  else{
    return t;
  }
}
// ここから開始

int main(){
  char c;
  cin>>c;
  if(c=='a'||c=='e'||c=='i'||c=='o'||c=='u') cout<<"vowel"<<endl;
  else cout<<"consonant"<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cstdio>
#include <set>
#include <algorithm>

using namespace std;

int main(){
	int N, M, K, L;
	while(cin >> N >> M >> K >> L, N){
		vector< pair<int, string> > vp;
		for(int i=0;i<N;i++){
			string str; int d;
			cin >> str >> d;
			vp.push_back(make_pair(-d, str));
		}
		sort(vp.begin(), vp.end());
		set<string> S;
		for(int i=0;i<M;i++){
			string str;
			cin >> str;
			S.insert(str);
		}
		vector<int> rank;
		for(int i=0;i<N;i++)
			if(S.count(vp[i].second)) rank.push_back(i);
		int l = 0, h = min(M, K)+1;
		while(h-l>1){
			int mid = (l+h)/2;
			int lest = mid;
			int against = K-mid;
			long long vote = 0;
			for(int i=0;i<mid;i++){
				if(rank[i] <= against) against++;
				else {
					vote += -vp[against].first + vp[rank[i]].first + (vp[against].second < vp[rank[i]].second);
				}
			}
			if(vote > L) h = mid;
			else         l = mid;
		}
		cout << l << endl;
	}
}

Measured memory_bytes: 10000
#include<iostream>
#include<string>
using namespace std;
int main(){
  string S;
  cin >> S;
  int ans=0;
  if(S[0] == 'R'){
    if(S[1] == 'R'){
      if(S[2] == 'R') ans=3;
      else ans=2;
    }else{
      ans=1;
    }
  }else{
    if(S[1] == 'R'){
      if(S[2] == 'R') ans=2;
      else ans=1;
    }else{
      if(S[2] == 'R') ans=1;
      else ans=0;
    } 
  }
  cout << ans << endl;
}

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

int main(){
	long long N, M;
	cin >> N >> M;
	if(N == 1){
		cout << M << endl;
		return 0;
	}

	long long maxi = 1;
	for(long long i = 1; i * i <= M; i++){
		if(M%i == 0){
			if(M/i >= N){
				maxi = max(maxi, i);
			}
			if(i>=N){
				maxi = max(maxi, M/i);
			}
		}
	}
	cout << maxi << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
using namespace std;
const int N=1e5+5;
typedef long long LL;

priority_queue<int,vector<int>,greater<int> >q[N],aq;

int root[N],cost[N],st[N];

int find(int x){
	return root[x]==x?x:root[x]=find(root[x]);
}

int main(){
	int n,m;
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++){
		scanf("%d",&cost[i]);
		root[i]=i;
	}
	for(int i=1;i<=m;i++){
		int a,b;
		scanf("%d%d",&a,&b);
		int t1=find(a),t2=find(b);
		if(t1!=t2)
			root[t1]=root[t2];
	}
	int cnt=0;
	for(int i=0;i<n;i++){
		if(root[i]==i)
			st[++cnt]=i;
	}
	for(int i=0;i<n;i++){
		int t1=find(i);
		q[t1].push(cost[i]);
	}
	if(cnt==1){
		puts("0");
		return 0;
	}
	LL ans=0;
	for(int i=1;i<=cnt;i++){
		int t1=st[i];
		ans+=q[t1].top();
		q[t1].pop();
		while(!q[t1].empty()){
			aq.push(q[t1].top());
			q[t1].pop();
		}
	}
	int sum=cnt-2;
	bool flag=true;
	while(sum--){
		if(aq.empty()){
			flag=false;
			break;
		}
		ans+=aq.top();
		aq.pop();
	}
	if(flag)
		printf("%lld\n",ans);
	else
		puts("Impossible");
}

Measured memory_bytes: 7680
def updiv(x,y):
    if x % y == 0:
        return x // y
    else:
        return x // y + 1

def want(K):

    for i in range(N):

        num = 0
        kai = N * K + i
        
        for j in range(N):
            num += max(0 , updiv( a[j] + kai - (N-1) , N + 1))

        #print (kai,num)
        if num <= kai:
            return kai

    return None

N = int(input())

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

l = -1
r = sum(a)

while r-l != 1:

    m = (l+r)//2

    ind = want(m)

    if ind == None:
        l = m
    else:
        r = m

    #print (l,r)

print (want(r))


Measured memory_bytes: 40304
N,M=map(int,input().split())
A=[0 for k in range(N)]
B=[0 for k in range(M)]
for i in range(N):
    A[i]=input()
for i in range(M):
    B[i]=input()
L=N-M
mark=0
import sys
for k in range(L+1):
    for l in range(L+1):
        count=0
        for i in range(M):    
            for j in range(M):
                if B[i][j]==A[i+k][j+l]:
                    count+=1
                else:
                    break
        if mark==0 and count==M**2:
            print("Yes")
            mark=1
            sys.exit()
if mark==0:
    print("No")

        

Measured memory_bytes: 3064
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 6)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")
al = "abcdefghijklmnopqrstuvwxyz"
AL = al.upper()

n = k()
d = [l() for i in range(n)]

for i in d:
  if i[0] == i[1]:
    cnt += 1
  else:
    cnt = 0
  if cnt == 3:
    print("Yes")
    sys.exit()

print("No")

Measured memory_bytes: 10512
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    s=input()
    if s[0]!=s[-1]:
        if len(s)%2==0:
            print('Second')
        else:
            print('First')
    else:
        if len(s)%2==0:
            print('First')
        else:
            print('Second')

if __name__ == '__main__':
    main()


Measured memory_bytes: 39024
#include <bits/stdc++.h>
#define rep(i,l,r)for(int i=(l);i<(r);i++)
const int INF = 2147483647;//int max
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;
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() {
    map<string,ll> m;
    ll n;
    cin >> n;
    rep(i,0,n){
        string s;
        cin >> s;
        m[s]++;
    }
    cout << m.size() << endl;
    return 0;
}

Measured memory_bytes: 19224
#include <cstdio>
#include <algorithm>
using namespace std;
int main(){
	int n;
	scanf("%d", &n);
	int a[n];
	for(int i = 0; i < n; i++){
		scanf("%d", &a[i]);
	}
	int cn4 = 0;
	int cn2 = 0;
	for(int i = 0; i < n; i++){
		if(a[i] % 4 == 0){
			cn4++;
		}else if(a[i] % 2 == 0){
			cn2++;
		}
	}
	int left = (n-1) - cn4*2;
	if(left <= 0){
		printf("Yes\n");
	}else if(left <= cn2 - 1){
		printf("Yes\n");
	}else{
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)  //  repマクロ
#define leng(n) (int)(log10(n)+1)  //  桁数
using namespace std;

signed main() {
  int a, b, c, d, e;
  cin >> a >> b >> c >> d >> e;
  vector<int> min1(5);
  min1[0] = a%10;
  min1[1] = b%10;
  min1[2] = c%10;
  min1[3] = d%10;
  min1[4] = e%10;
  int min5 = 10;
  rep(i, 5) {
    if (min1[i] != 0 && min1[i]<min5) min5 = min1[i];
  }
  cout << 10*((a-1)/10) + 10*((b-1)/10) + 10*((c-1)/10) + 10*((d-1)/10) + 10*((e-1)/10) + 50 - (10-min5) << endl;
}


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

#define rep(n) for(int i=0;i<n;i++)
#define repp(j, n) for(int j=0;j<n;j++)
#define reppp(i, m, n) for(int i=m;i<n;i++)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define debug(x) cerr << #x << ": " << x << endl

using namespace std;

typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pii;

int main() {
    ll N,C;
    cin >> N >> C;
    vector<Pll> sushi(N+2, Pll(0, 0));
    reppp(i, 1, N+1) cin >> sushi[i].first >> sushi[i].second;
    sushi[N+1].first = C;
    sushi[N+1].second = 0;

    vector<ll> asc(N+2, 0), asc_max(N+2, INT_MIN), desc(N+2, 0), desc_max(N+2, INT_MIN);
    reppp(i, 1, N+1){
        asc[i] = asc[i-1] + sushi[i].second - (sushi[i].first - sushi[i-1].first);
        asc_max[i] = max(asc[i], asc_max[i-1]);
    }
    asc[N+1] = asc[N];
    asc_max[N+1] = asc_max[N];
    for(int i=N;i>=1;i--){
        desc[i] = desc[i+1] + sushi[i].second - (sushi[i+1].first - sushi[i].first);
        desc_max[i] = max(desc[i], desc_max[i+1]);
    }
    desc[0] = desc[1];
    desc_max[0] = desc_max[1];

    ll ans = 0LL;
    repp(i, N+2){
        ll tmp = asc[i];
        ll d = (i < N+1?desc_max[i+1]:0);
        if(d > sushi[i].first) tmp += - sushi[i].first + d;
        ans = max(ans, tmp);

        tmp = desc[i];
        d = (i!=0?asc_max[i-1]:0);
        if(d > C-sushi[i].first) tmp += - (C-sushi[i].first) + d;
        ans = max(ans, tmp);
    }
    cout << ans << endl;
}

Measured memory_bytes: 4992
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] num = new int[n];

		for (int i = 0; i < n; i++) {
			num[i] = sc.nextInt();
		}

		int max = num[0];
		int min = num[0];
		long sum = 0;

		for (int a : num) {
			if (a > max) {
				max = a;
			}
			if (a < min) {
				min = a;
			}
			sum += a;
		}
		System.out.println(min + " " + max + " " + sum);
		sc.close();
	}

}



Measured memory_bytes: 41212
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	private BufferedReader br;
	private int n;
	
	public static void main(String[] args)throws IOException {
		// TODO Auto-generated method stub
		new Main().start();
	}
	public void start()throws IOException{
		br=new BufferedReader(new InputStreamReader(System.in));
		n=Integer.parseInt(br.readLine());
		if(n<=999){
			System.out.println("ABC");
		}
		else{
			System.out.println("ABD");
		}
	}

}


Measured memory_bytes: 23380
#include<iostream>
using namespace std;
#define Int long long
#include<bits/stdc++.h>
int main(){
  Int x,y,a,b,c;
  cin>>x>>y>>a>>b>>c;
  vector<Int>red(a);
  vector<Int>gr(b);
  vector<Int>col(c);
  for(Int i=0;i<a;i++)
    cin>>red[i];
  for(Int i=0;i<b;i++)
    cin>>gr[i];
  for(Int i=0;i<c;i++)
    cin>>col[i];
  sort(red.rbegin(),red.rend());
  sort(gr.rbegin(),gr.rend());
  sort(col.rbegin(),col.rend());
  vector<Int>fin(x+y);
  for(Int i=0;i<x;i++)
    fin[i]=red[i];
  for(Int i=0;i<y;i++)
    fin[x+i]=gr[i];
  Int sum=0;
  for(Int i=0;i<x+y;i++)
    sum+=fin[i];
  sort(fin.rbegin(),fin.rend());
  Int l=0,j=x+y-1;
  while(l<c and j>=0){
    Int dif=col[l]-fin[j];
    if(dif>0){
      sum+=dif;
      l++;
      j--;
    }
    else
      break;
  }
  cout<<sum;
  return 0;
}

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

int main() {
  while (true) {
    int h, w;
    cin >> h >> w;
    if (h == 0 && w == 0) {
      break;
    }
    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        if (i % 2 == j % 2) {
          cout << "#";
        }
        else {
          cout << ".";
        }
      }
      cout << endl;
    }
    cout << endl;
  }
}



Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
int main() {
    ios::sync_with_stdio(false);

    string s; cin >> s;
    int ans = 0;
    for (int i = 0; i < s.size(); i++)
        if (s[i] == '2')
            ans++;
    cout << ans << endl;
    
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<int, int> pp;
double PI=acos(-1);
int const N = 5e5 + 10,M=5e6+10, oo = 1e9;
const int mod = oo+7;
const ll  OO = 3e18;

int n,aa[N];
pp dp[N];
pp rec(int u){
    if(dp[u].first!=-1)return dp[u];
    int mx1=-1,mx2=0;
    for(int i=20;i>-1;i--){
        if((u>>i)&1){
            pp r=rec((1<<i)^u);
            int mx=aa[r.first],mn=aa[r.second];
            if(mx1==-1){
                mx1=r.first,mx2=r.second;
                continue;
            }
            if(mx>aa[mx1]&&r.first!=mx2){
                mx2=mx1;
                mx1=r.first;
            }else if(mx>aa[mx2]&&r.first!=mx1)mx2=r.first;
            if(mn>aa[mx2]&&r.second!=mx1)mx2=r.second;
        }
    }
    if(aa[u]>aa[mx1]){
        mx2=mx1;
        mx1=u;
    }else if(aa[u]>aa[mx2])mx2=u;
    return dp[u]={mx1,mx2};
}
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin>>n;
    n=(1<<n);
    for(int i=0;i<n;i++)cin>>aa[i],dp[i].first=-1;
    if(aa[0]>aa[1])dp[1]={0,1};else dp[1]={1,0};
    for(int i=2;i<n;i++){
        if(bitset<25>(i).count()==1){
            if(aa[i]>aa[0])dp[i].first=i;
            else dp[i]={0,i};
            continue;
        }
        rec(i);
    }
    cout<<aa[0]+aa[1]<<endl;
    for(int i=2,mx=aa[0]+aa[1],mx1=max(aa[0],aa[1]),mx2=min(aa[0],aa[1]);i<n;i++){
        if(aa[i]>mx1){
            mx2=mx1;
            mx1=aa[i];
        }else if(aa[i]>mx2)mx2=aa[i];
        if(bitset<25>(i+1).count()==1)mx=max(mx,mx1+mx2);
        mx=max(mx,aa[0]+aa[i]);
        mx=max(mx,aa[dp[i].first]+aa[dp[i].second]);
//        cout<<aa[dp[i].first]<<' '<<aa[dp[i].second]<<' '<<mx<<endl;
    cout<<mx<<endl;
    }
    return 0;
}



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

typedef pair<int, int> P;	// first: 終わらせる時間、second: 所要時間

int main() {
	int n;
	cin >> n;
	
	vector<P> p(n);
	for (int i = 0; i < n; i++) {
		cin >> p[i].first;
		p[i].second = i + 1;
	}
	sort(p.begin(), p.end());
	
	for (int i = 0; i < n; ++i) {
		cout << p[i].second << ' ';
	}
}



Measured memory_bytes: 1536
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
using std::endl;
using std::cin;
using std::cout;
using std::vector;
using std::pair;
using std::string;

//for(int32_t i = 0; i < N; i++)

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

    int32_t count = 0;
    for (int32_t i = 0; i < N.length(); i++) {
        if (N.substr(i,1) == "2") {
            count++;
        }
    }

    cout << count << endl;


    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>

using namespace std;

#define ll long long

int N, M, buff, ans=0;
vector<int> X, diff;

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

    for(int i = 0; i < M; i++) {
        cin >> buff;
        X.push_back(buff);
    }
    
    sort(X.begin(), X.end());
    
    // for(int i = 0; i < M; i++) cout << X[i] << " ";
    // cout << endl;

    for(int i = 0; i < M-1; i++)
        diff.push_back(X[i+1] - X[i]);

    sort(diff.begin(), diff.end());
    reverse(diff.begin(), diff.end());

    // for(int i = 0; i < M-1; i++) cout << diff[i] << " ";
    //     cout << endl;

    for(int i = N-1; i < M-1; i++)
        ans += diff[i];

    cout << ans << endl;
}


Measured memory_bytes: 1400
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
using System.Text;//テキストの高速出力に必要
class Program
{
	static void Main()
	{
		int n = int.Parse(Console.ReadLine());
		long[] numsa = Array.ConvertAll(Console.ReadLine().Split(' '),long.Parse);
    long[] numsb = Array.ConvertAll(Console.ReadLine().Split(' '),long.Parse);
		long answer = 0;

    for(int i = 0; i < n; i++)
    {
      if(numsa[i] >= numsb[i])
      {
        answer += numsb[i];
      }else
      {
        answer += numsa[i];
        numsb[i] -= numsa[i];

        if(numsa[i+1] >= numsb[i])
        {
          answer += numsb[i];
          numsa[i+1] -= numsb[i];
        }else
        {
          answer += numsa[i+1];
          numsa[i+1] = 0;
        }
      }
    }

		Console.WriteLine(answer);
	}
}

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

template<typename T>
struct Die {
	T s[6];
	T &left() { return (s[0]); }
	T &right() { return (s[1]); }
	T &front() { return (s[2]); }
	T &back() { return (s[3]); }
	T &bottom() { return (s[4]); }
	T &top() { return (s[5]); }

	Die(T l, T r, T f, T b, T d, T u) {
		tie(s[0], s[1], s[2], s[3], s[4], s[5]) = tie(l, r, f, b, d, u);
	}
	
	void roll(char c) {
		string S = "ENWS";
		int indexes[4][4] = {
			{1, 5, 0, 4},
			{3, 5, 2, 4},
			{0, 5, 1, 4},
			{2, 5, 3, 4}
		};
		for (int i = 0; i < 4; i++) {
			if (c != S[i]) continue;
			T temp = s[indexes[i][0]];
			s[indexes[i][0]] = s[indexes[i][1]];
			s[indexes[i][1]] = s[indexes[i][2]];
			s[indexes[i][2]] = s[indexes[i][3]];
			s[indexes[i][3]] = temp;
		}
	}
};

int main() {
	int u, f, r, l, b, d;
	string S;
	cin >> u >> f >> r >> l >> b >> d;
	Die<int> dice(l, r, f, b, d, u);

	cin >> S;
	for (int i = 0; i < S.size(); i++) {
		dice.roll(S[i]);
	}
	cout << dice.top() << endl;
	return (0);
}



Measured memory_bytes: 3212
/* author: Mohammad Sheraj */
/* Clang++17 launch.json for debugger */
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
// char buf[10]; fgets(buf, 10, stdin);
// Use long long instead of long
// cout<<"Case #"<<t<<": "<<answer<<endl;
///////////////////////////////////////////////////////////////

#include <iostream>
#include <vector>
#include <string>
#include <tuple>
#include <stack>
#include <queue> //includes priority_queue
#include <deque>
#include <unordered_set>
#include <unordered_map>
#include <set> //sorts by value
#include <map> //sorts by key
#include <algorithm> //max/min //lower_bound/upper_bound //binary_search //reverse //transform
#include <math.h> //ceil/floor

using namespace std;
///////////////////////////////////////////////////////////////////////


int main() {
    // freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
    // int T;
    // cin>>T;
    // for(int test=1;test<=T;test++) {
    // }
    int N;
    cin>>N;
    cout<<(1000-N%1000)%1000;
}

Measured memory_bytes: 3128
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define N 20010
#define mo 1000000007ll
int f[N];
int n,k;
ll qp(ll x,ll y){
	if(y<0)return 1;
	ll r=1;
	for(;y;y>>=1,x=x*x%mo)
		if(y&1)r=r*x%mo;
	return r;
}
signed main(){
	cin>>n>>k;
	f[0]=1;
	for(int i=1;i<n;i++){
		for(int j=i;j;j--){
			f[j]=(f[j+1]+f[j-1]);
			if(f[j]>=mo)f[j]-=mo;
		}
		f[0]=f[1];
	}
	cout<<f[n-k]*qp(2,n-k-1)%mo;
}

Measured memory_bytes: 256
n = int(input())
a1 = list(map(int,input().split()))
a2 = list(map(int,input().split()))
max_candy = 0
for down in range(n):
    candy = sum(a1[0:down+1])+sum(a2[down:n+1])
    if candy > max_candy:
        max_candy = candy
print(max_candy)

Measured memory_bytes: 3060
#include<stdio.h>
#include<string.h>
long long a,b,i,srx,sry;
long long zzh;
long long max(long long x,long long y)
{
    if(x>y)
    return x;
    return y;
}
long long min(long long x,long long y)
{
    if(x>y)
    return y;
    return x;
}
int main()
{
    scanf("%d%d",&srx,&sry);
    a=max(sry,srx);
    b=min(srx,sry);
    long long r;
    while(b>0)
    {r=a%b;
    a=b;
    b=r;}
    zzh=srx*sry/a;
    printf("%lld",zzh);
    return 0;
}

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

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: 3608
#include<iostream>
#include<cstdio>
using namespace std;
int n,a,b;
int myabs(int x)
{
	if(x<0)return -x;return x;
}
int main()
{
	scanf("%d%d%d",&n,&a,&b);
	printf((myabs(a-b)&1)?"Borys":"Alice");
	return 0;
} 

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

ans=0
MOD=10**9+7

cnt=[0]*(K+1)
for x in reversed(range(1,K+1)):
    cnt_tmp = pow(K//x,N,MOD)#xの倍数のみで作れるlen=Nの数列の総数
    t=1
    while (t+1)*x<=K:
        t+=1
        cnt_tmp -= cnt[x*t] #cnt_tmpのうち,gcd=2x,3x...になるものを除く

    cnt[x]=cnt_tmp
    ans += x*cnt_tmp
    ans%=MOD
print((ans+MOD)%MOD)


Measured memory_bytes: 11108
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define INF 1145141919
int dy[] = {0, 0, 1, -1};
int dx[] = {1, -1, 0, 0};
int ny, nx;
typedef long long int ll;
using namespace std;

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

ll lcm(ll m, ll n)
{
    if ((0 == m) || (0 == n))
        return 0;
    return ((m / gcd(m, n)) * n);
}

ll llpow(ll x, ll y)
{
    ll ans = 1;
    REP(i, y)
    ans *= x;
    return ans;
}

int ctoi(char c)
{
    if (c >= '0' && c <= '9')
    {
        return c - '0';
    }
    return 0;
}
////////////////////////////////////////////////////////////////////
int main()
{
    int a,p; cin >> a >> p;

    cout << int((a*3+p)/2) << endl;

    return 0;

}


Measured memory_bytes: 256
import math
def PrimeNum(a):
	x=math.sqrt(a)
	x=int(x)
	tmp=1
	if a==1:
		tmp=0
	elif a==2:
		tmp==1
	elif a>3 and a<9:
		for i in range(2,a):
			st=a%i
			if st==0:
				tmp=0
				break
	
	else:
		for i in range(2,x+1):
			st=a%i
			if st == 0:
				tmp=0
				break
	#print("::::",a,x,st,tmp)
		
	#if tmp==1:print("・・")

	return tmp	
	
n=int(input())
p=[]
att=0
for i in range(n):
	p.append(int(input()))
	att+=PrimeNum(p[i])
	
print(att)



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

int main() {
	string S;
	int min = 1000;
	cin >> S;
	for (int i = 0; i < S.size() - 2; i++) {
		int x = abs(753 - stoi(S.substr(i, 3)));
		if (min > x) min = x;
	}
	cout << min << endl;
}


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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

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

signed main() {
#ifdef _DEBUG
  freopen("in" , "r", stdin );
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  string s; cin >> s;
  int n = s.size();
  deque<int> v;
  for (int i = 0; i < n; i++) {
    if (s[i] != 'x') v.push_back(i);
  }
  int m = v.size();
  bool palin = 1;
  for (int i = 0; i < m / 2; i++) {
    if (s[v[i]] != s[v[m - i - 1]]) {
      palin = 0;
      break;
    }
  }
  if (!palin) {
    cout << -1 << '\n';
    return 0;
  }
  int ans = 0;
  v.push_front(-1); v.push_back(n); m += 2;
  for (int i = 0; i < (m - 1) / 2; i++) {
    int r = m - i - 1;
    int a = v[i + 1] - v[i];
    int b = v[r] - v[r - 1];
    ans += abs(a - b);
  }
  cout << ans << '\n';
}


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

int main()
{
    int a;
    cin >> a;
    if (a == 25)
        cout << "Christmas" << endl;
    else if (a == 24)
        cout << "Christmas Eve" << endl;
    else if (a == 23)
        cout << "Christmas Eve Eve" << endl;
    else
        cout << "Christmas Eve Eve Eve" << endl;

    return 0;
}

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

using namespace std;

int main()	{

	int n, m, temp, amax;
	int a[1000];

	while (true)	{

		scanf("%d %d", &n, &m);

		if (n == 0)	break;

		amax = -1;

		for (int i = 0; i <= n-1; i++)	{
			
			cin >> temp;

			a[i] = temp;
		}

		for (int i = 0; i <= n-1; i++)	{
			for (int j = 0; j <= n-1; j++)	{
				
				if (i == j)	{
					continue;
				}

				if (a[i] + a[j] <= m)	{
					amax = max(amax, a[i] + a[j]);
				}
			}
		}

		if (amax == -1)	{
			printf("NONE\n");
		} else	{
			printf("%d\n", amax);
		}
	}

	return 0;
}


Measured memory_bytes: 3112
#include<bits/stdc++.h>
using namespace std;
#define int long long
char s[16];
int month[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
bool leap_year(int y){
    return !(y%400)||((y%100)&&!(y%4));
}
char ret[32];
string mayan_to_ad(){
    int b,ka,t,w,ki;
    int y,m,d;
    sscanf(s,"%lld.%lld.%lld.%lld.%lld",&b,&ka,&t,&w,&ki);
    int dki=b*20*20*18*20+ka*20*18*20+t*18*20+w*20+ki;
    if(dki<=10){
        y=2012;
        m=12;
        d=21+dki;
    }
    else{
        dki-=10;
        for(int yy=2013;;yy++){
            for(int mm=1;mm<=12;mm++){
                int tmp=(leap_year(yy)&&mm==2);
                for(int dd=1;dd<=month[mm]+tmp;dd++){
                    dki--;
                    if(dki==0){
                        y=yy;m=mm;d=dd;
                        goto end;
                    }
                }
            }
        }
    }
    end:;

    sprintf(ret,"%lld.%lld.%lld",y,m,d);
    return ret;
}
string ad_to_mayan(){
    int y,m,d,b,ka,t,w,ki;
    int leap=0;
    sscanf(s,"%lld.%lld.%lld",&y,&m,&d);
    for(int i=2013;i<y;i++)if(leap_year(i))leap++;
    if(leap_year(y)&&m>2)leap++;
    int dy=365*max(0ll,y-2013)+leap;
    if(y>2012){
        dy+=10;
        for(int i=1;i<=m;i++){
            if(i==m)dy+=d;
            else dy+=month[i];
        }
    }
    else dy=d-21;
    dy%=20*20*20*18*13;
    b=dy/(20*20*20*18);dy%=20*20*20*18;
    ka=dy/(20*18*20);dy%=20*18*20;
    t=dy/(18*20);dy%=18*20;
    w=dy/20;dy%=20;
    ki=dy;
    sprintf(ret,"%lld.%lld.%lld.%lld.%lld",b,ka,t,w,ki);
    return ret;
}
signed main(){
    while(cin>>s,s[0]!='#'){
        int cnt=0;
        for(int i=0;s[i];i++)if(s[i]=='.')cnt++;
        string ans;
        if(cnt==2)ans=ad_to_mayan();
        else ans=mayan_to_ad();
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 1264
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <set>
#include <utility>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <cstdio>
#include <map>

using namespace std;

using ll = long long;
using P = pair<ll,ll>;

#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = ((ll)(x) - 1); i >= 0; i--)

#define vi vector<int>
#define vvi vector<vi>

#define _upgrade ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(x) (x).begin(), (x).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define chmin(x,y) (x=min(x,y))
#define chmax(x,y) (x=max(x,y))

//ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};

const ll mod = 1e9 + 7;
const ll IMF = 1LL<<29;
const double PI = 3.14159265358979323846;


// ***************************CODE**********************//



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

        for(int i = 0; i < (1 << 4); i++){
                string ans;
                ans += s[0];
                int num = (int)(s[0] - '0');

                for(int j = 1; j < 4; j++){
                        if(i & (1 << j)){
                                ans += '+';
                                num += (int)(s[j] - '0');
                        }
                        else{
                                ans += '-';
                                num -= (int)(s[j] - '0');
                        }
                        ans += s[j];
                }

                if(num == 7){
                        ans += "=7";
                        cout << ans << endl;
                        return 0;
                }
        }
}






Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
using namespace std;
typedef long long ll;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

#define EPS (1e-7)
#define INF (1e15)
#define PI (acos(-1))
#define MOD 1000000007

#define REP(i,n) for(int i=0;i<n;i++)
#define REPS(i,f,n) for(int i=(f);i<(n);i++)
#define EACH(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)

#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define arrdump(n,a) for(int i=0;i<n;i++) {cout<<((i>0)? " ":"")<<a[i];}cout<<"\n";


typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int dy4[]={0, 0, 1, -1};
int dx4[]={1, -1, 0, 0};
int dx8[]={0, 0, 1, -1, 1, 1, -1, -1};
int dy8[]={1, -1, 0, 0, 1, -1, -1, 1};

// https://atcoder.jp/contests/abc079/tasks/abc079_c

string abcd;
string OP;

static bool dfs(int sum, string op) {
    if (op.length() == 3) {
        OP = op;
        return sum == 7;
    }

    if (dfs(sum+(abcd[op.length()+1]-'0'), op+"+")) return true;
    if (dfs(sum-(abcd[op.length()+1]-'0'), op+"-")) return true;
    return false;
}

int main() {
    cin >> abcd;
    if (dfs(abcd[0]-'0', "")) {
        printf("%c%c%c%c%c%c%c=7\n", abcd[0], OP[0], abcd[1], OP[1], abcd[2], OP[2], abcd[3]);
    }

    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


class data
{
    public int input;
    public int position;

};
namespace ConsoleApplication3
{
    class Program
    {

        static void Main(string[] args)
        {
            string temp;
            int number;
            int result = 0;
            int[] input;
            temp = Console.ReadLine();
            number = int.Parse(temp);
            input = new int[number];


            for (int i = 0; i < number; i++)
            {
                temp = Console.ReadLine();
                input[i] = int.Parse(temp);
            }

            int bottom = 1000000000, top, diff;
            diff = 1 - bottom;
            bool direction = false;
            for (int i = 1; i < number; i++)
            {
                if (input[i] - input[i - 1] > 0)
                {
                    if (bottom > input[i - 1])
                        bottom = input[i - 1];
                    top = input[i];
                    if (top - bottom > diff)
                        diff = top - bottom;
                }else if(input[i] - input[i - 1] == 0)
                {
                    if(diff < 0)
                        diff = 0;

                }else{
                    direction = false;
                    if(diff < input[i] - input[i -1])
                        diff = input[i] - input[i -1];
                }


            }


            Console.WriteLine("{0}", diff);
        }
    }
}



Measured memory_bytes: 20328
#include<stdio.h>
int main()
{
    int a,b,c,max,mid;
    scanf("%d%d%d",&a,&b,&c);
    if(a>=1&&a<=10000&&b>=1&&b<=10000&&c>=1&&c<=10000)
    {
        if(a<b&&a<c)
        {
            max=a;
            if(b<c)
            {
                mid=b;
            }
            else
            {
                mid=c;
            }
        }

        else if(b<a&&b<c)
        {
            max=b;
            if(a<c)
            {
                mid=a;
            }
            else
            {
                mid=c;
            }
        }

       else if(c<b&&c<a)
        {
            max=c;
            if(b<a)
            {
                mid=b;
            }
            else
            {
                mid=a;
            }
        }
        else if(a==b&&a==c&&b==c)
		{
			max=a;
			mid=a;
		}
		else if(a==b&&a!=c)
		{
			if(a<c)
			{
				max=a;
				mid=a;
			}
			else
			{
				max=c;
				mid=a;
			}
		}
	else if(b==c&&b!=a)
		{
			if(b<a)
			{
				max=b;
				mid=b;
			}
			else
			{
				max=a;
				mid=b;
			}
		}
     else if(a==c&&a!=b)
		{
			if(b<a)
			{
				max=b;
				mid=a;
			}
			else
			{
				max=a;
				mid=a;
			}
		}
		printf("%d\n",max+mid);
    }
    return 0;
}

Measured memory_bytes: 128
import java.util.*;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int A = Integer.parseInt(sc.next());
        int B = Integer.parseInt(sc.next());
        int count = 0;
        for(int i=A; i<=B; i++) {
            int num = i;
            int a = num % 10;
            num /= 10;
            int b = num % 10;
            num /= 10;
            int c = num % 10;
            num /= 10;
            int d = num % 10;
            num /= 10;
            int e = num;
            if(a == e && b == d) count++;
        }
        System.out.println(count);
    } 
}

Measured memory_bytes: 21844
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
#include<complex>
using namespace std;

int main() {
	long long int n=700,m,a,b,c,d,e;
	long double z,w;
	string str,str2,str3;
	char ch;
	long long int x[130]={};
	cout << fixed << setprecision(10);
	cin>>a>>b;
	a%=500;
	if(a<=b){cout<<"Yes";}
	else{cout<<"No";}





	cout<<endl;
} 


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int divi(int n){
  int c=0;
 while (n %2 != 1 ){
   c++;
   n /=2;
 }
  return c;
}

int main(){
 int N;
  cin >>N;
  vector<pair<int,int>>vec(N);
  for (int i=0;i <N; i++){
    int f;
   cin >> f;
    vec.at(i).first = f;
    vec.at(i).second =divi (f) ;
  }
  int sum=0;
  for (int i=0;i <N; i++){
    sum +=vec.at(i).second;
  }
  cout << sum << endl;
}

Measured memory_bytes: 384
/*Author- Soumak Poddar*/

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

#define ll long long int
#define sll signed long long int
#define ull unsigned long long int
#define um unordered_map
#define us unordered_set
#define mm multimap
#define mp make_pair
#define pb push_back
#define M 1000000007

bool comp(pair<int,int> a,pair<int,int> b)
{
   return a.second<b.second;
}

void solve();
int main()
{
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   cout.tie(NULL);

   #ifndef ONLINE_JUDGE
      freopen("input.txt", "r", stdin);
      freopen("error.txt", "w", stderr);
      freopen("output.txt", "w", stdout);
   #endif
   
   int t=1;
   // cin>>t;
   while(t--)
   {
      solve();
      cout<<"\n";
   }
   cerr<<"Time Taken : "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<endl;
   return 0;
}
void solve()
{
   int l,r,d;
   cin>>l>>r>>d;
   int c=0;
   for(int i=l;i<=r;i++)
   {
      if(i%d==0)
         c++;
   }
   cout<<c;
}

Measured memory_bytes: 3796
import sys
input=sys.stdin.readline
n,m=map(int,input().split())
b=[]
for i in range(m):
    b.append(int(input()))
a=set(b)
dp=[0]*(n+1)
dp[0]=1
if 1 in a:
    dp[1]=0
else:
    dp[1]=1
for i in range(2,n+1):
    if i in a:
        dp[i]=0
    else:
        dp[i]=dp[i-1]+dp[i-2]
print(dp[n]%1000000007)

Measured memory_bytes: 470392
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <climits>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int d;
    cin >> d;
    cout << "Christmas";
    REP(i, 25 - d) cout << " Eve";
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 10**6
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

x,y=map(int,input().split())
a=(2*x-y)//3
b=(2*y-x)//3
if a!=(2*x-y)/3 or b!=(2*y-x)/3:
    print(0)
else:
    print(cmb(a+b,a,mod))

Measured memory_bytes: 122120