akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<float.h>
#include<cfloat>
#include<string>
#include<ctype.h>
#include<algorithm>
#include<errno.h>
#include<cerrno>
#include<assert.h>
#include<cassert> 
#include<map>
#include<memory.h>
#include<cctype>
#include<ctype.h>
#include<math.h>
#include<vector> 
#include<cstdio> 
#include<set>
#include<string.h>
#include<stdio.h>
#include<new>
#include<memory>
#include<cmath>
#include<queue>
#include<cstring>
#define ll long long
#define fo(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define br break
#define ct continue
#define pb push_back
#define pi 3.141592653589793238462643383279502884197169
#define F first
#define S second
#define em empty()
#define vei vector<int>
#define ves vector<string>
#define qui queue<int> 
#define qu queue
using namespace std;
int main()
{int n;
 cin>>n;
 if(n<1200){
 cout<<"ABC"<<endl;}
 else{
 cout<<"ARC"<<endl;} 
 return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define SHIFT_LEFT(n) (1LL<<((ll)n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;
ll mod_div(ll a,ll b){
  ll tmp=MOD-2,c=b,ret=1;
  while(tmp>0){
    if(tmp&1){
      ret*=c;ret%=MOD;
    }
    c*=c;c%=MOD;tmp>>=1;
  }
  return a*ret%MOD;
}
 
#define MAX_K 200100
vector<ll> kaijo(MAX_K);
ll combination(ll n, ll r){
  if(n<r||n<0||r<0)
    return 0;
  if(kaijo[0]!=1){
    kaijo[0]=1;
    for(ll i=1;i<MAX_K;i++)kaijo[i]=(kaijo[i-1]*i)%MOD;
  }
  ll ret=kaijo[n];
  long long tmp = (kaijo[r] * kaijo[n-r]) % MOD;
  return mod_div(ret,tmp);
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n,k;
  cin>>n>>k;
  vi A(n);
  for(auto &a:A)cin>>a;
  sort(ALL(A));
  ll minx = 0;
  for(int i = 0;i < n;i++){
    minx += (combination(n-i-1,k-1)*((A[i]+MOD)%MOD))%MOD;
    minx %=MOD;
  }
  reverse(ALL(A));
  ll maxx = 0;
  for(int i = 0;i < n;i++){
    maxx += (combination(n-i-1,k-1)*((A[i]+MOD)%MOD))%MOD;
    maxx %= MOD;
  }
  cout<<(MOD+maxx-minx)%MOD<<endl;
  return 0;
}


Measured memory_bytes: 2560
n=int(input())
s=input()
dp=[0]*n
buf=[0]*10
c=0
for i in range(n-1,-1,-1):
    if buf[int(s[i])]==0:
        dp[i]=c
        c+=1
        buf[int(s[i])]=1
    else:
        dp[i]=c
ten=[[] for i in range(10)]
for i in range(n):
    ten[int(s[i])].append(i)
buf=[0]*10
count=0
for i in range(n):
    if buf[int(s[i])]==0:
        for j in range(10):
            for h in range(len(ten[j])):
                if ten[j][h]>i:
                    count+=dp[ten[j][h]]
                    break
        buf[int(s[i])]=1
print(count)
        

Measured memory_bytes: 40688
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextString() string {
	sc.Scan()
	return sc.Text()
}

func maxLenPoint(B []int, length int) (int, int, int) {
	maxlen := 0
	var diff int
	var v1, v2 int
	for i := len(B) - 1; i > 0; i-- {
		diff = B[i] - B[i-1]
		if diff > maxlen {
			maxlen = diff
			v1 = i - 1 //low
			v2 = i     //high
		}
	}

	// circle check
	diff = length + B[0] - B[len(B)-1]
	if diff > maxlen {
		maxlen = diff
		v1 = 0
		v2 = len(B)
	}

	return maxlen, v1, v2

}

func main() {
	var K, N int
	var A []int

	fmt.Scan(&K, &N)

	sc.Split(bufio.ScanWords)

	A = make([]int, N)
	for i := 0; i < N; i++ {
		A[i], _ = strconv.Atoi(nextString())
	}

	l, _, _ := maxLenPoint(A, K)
	fmt.Println(K - l)

}


Measured memory_bytes: 3840
#include <iostream>
using namespace std;
int n,a[101],r;
int main()
{ cin>>n;
  for(int i=1;i<=n;i++)
    cin>>a[i];
  for(int i=1;i<n;i++)
  { if(a[i]==a[i+1] && i!=n-1)
       r++,a[i+1]=a[i+2]+1;
    else if(a[i]==a[i+1] && i==n-1)
       r++;
  }
  cout<<r;
  return 0;
}


Measured memory_bytes: 256
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <stdint.h>
#include <string.h>

int main(void) {
	uint32_t a, b, c;
	uint32_t k;
	uint32_t *max = &a;

	scanf("%"PRIu32" %"PRIu32" %"PRIu32"\n%"PRIu32, &a, &b, &c, &k);

	if (*max < b) {
		max = &b;
	}
	if (*max < c) {
		max = &c;
	}

	for (uint32_t count = 0; count < k; count++) {
		*max *= 2;
	}

	printf("%"PRIu32, a + b + c);

	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define sz(x) ((int)(x).size())
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
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;
  string A, B, C;
  cin >> A >> B >> C;

  int ans = 0;
  rep(i, N) {
    set<char> s;
    s.insert(A[i]);
    s.insert(B[i]);
    s.insert(C[i]);

    ans += sz(s) - 1;
  }

  cout << ans << endl;
}

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

using namespace std;
typedef long long  ll;
#define rep(i,s,n)for(ll i = s;i<n;i++)

int main() {
	bool S[26];
	char c[26]; cin >> c;
	rep(i, 0, 26) {
		S[i] = false;
	}

	rep(i, 0, 26) {
		if (c[i] == '\0') break;

		if (S[c[i] - 'a']) {
			cout << "no" << endl;
			return 0;
		}

		S[c[i] - 'a'] = true;
	}
	cout << "yes" << endl;
}

Measured memory_bytes: 256
l = input()

mod = 10**9+7


dplow = [0]*len(l)
dp2 = [0]*len(l)

dplow[0] = 1
dp2[0] = 2

for i in range(1,len(l)):
    dplow[i] += dplow[i-1]*3%mod
    if l[i] == "1":
        dplow[i] += dp2[i-1]%mod
        dp2[i] += dp2[i-1]*2%mod
    else:
        dp2[i] += dp2[i-1] %mod

print((dplow[-1]+dp2[-1])%mod)

Measured memory_bytes: 11116
e,s=gets;h=gets.split.map(&:to_i).sort.chunk{|e|e}.map{|k,v|s||=k;[e=k,v.size]}.to_h;print h[s]==s*2+1-e&&(s+1..e).all?{|x|h[x].to_i>1}?:P: :Imp,:ossible

Measured memory_bytes: 1916
#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 < (n); ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define show(x) cout << #x << " = " << (x) << endl;
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl;
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = 1<<30;
const ll INFLL = 1LL<<60;
//cout << fixed << setprecision(10);

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

ll x[55];
ll dp[55][55][2555];

int main () {
  ll n, a;
  cin >> n >> a;
  rep(i,n) cin >> x[i];
  
  dp[0][0][0] = 1;
  rep(i,n) {
    rep(j,n) {
      rep(k,2500) {
        if (dp[i][j][k] == 0) continue;
        dp[i+1][j][k] += dp[i][j][k];
        dp[i+1][j+1][k+x[i]] += dp[i][j][k];
      }
    }
  }

  ll ans = 0;
  for (int i = 1; i <= n; ++i) {
    ans += dp[n][i][i*a];
  }

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

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

using namespace std;

int main()
{
    int x[5], answer;
    for (int i = 0; i < 5; i++)
    {
        cin >> x[i];
        if (x[i] != i + 1)
            answer = i + 1;
    }
    cout << answer << endl;
}


Measured memory_bytes: 3548
/*
*  Author: windystreet
*  Date  : 2018-12-09 14:14:49
*  Motto : Think twice, code once.
*/
#include<bits/stdc++.h>

using namespace std;

#define X first
#define Y second
#define eps  1e-5
#define gcd __gcd
#define pb push_back
#define PI acos(-1.0)
#define lowbit(x) (x)&(-x)
#define bug printf("!!!!!\n");
#define mem(x,y) memset(x,y,sizeof(x))

typedef long long LL;
typedef long double LD;
typedef pair<int,int> pii;
typedef unsigned long long uLL;

const int maxn = 1e5+7;
const int INF  = 1<<30;
const int mod  = 1e9+7;

void solve(){
	int n;
    scanf("%d",&n);
    printf("Christmas");
    for(int i=0;i<25-n;i++){
    	printf(" Eve");
    }
    
    return;
}

int main()
{
//    freopen("F:\\in.txt","r",stdin);
//    freopen("out.txt","w",stdout);
//    ios::sync_with_stdio(false);
    int t = 1;
    //scanf("%d",&t);
    while(t--){
    //    printf("Case %d: ",cas++);
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b,c;
  c =0;
  cin >> a >> b;
  for (int i = a;i <= b;i++){
   	int n = i%10;
    int o = i/10%10;
    int m = i/10000%10;
    int l = i/1000%10;
    if (n == m && o == l)c++;
  }
  cout << c << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <map>
#include <queue>
using ll = long long;
using namespace std;
int N, tmp;
string s, t;
int main(void)
{
    cin >> s;
    cout << count(s.begin(), s.end(), '2') << endl;
    return 0;
}

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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define UB upper_bound
#define LB lower_bound
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

LL n, a[100000];
LL sum[100000];

int main() {
	cin >> n;
	inc(i, n) { cin >> a[i]; }
	
	sort(a, a + n);
	
	sum[0] = a[0];
	incID(i, 1, n) {
		sum[i] = sum[i - 1] + a[i];
	}
	
	int ans = n;
	dec(i, n - 1) {
		if(sum[i] * 2 < a[i + 1]) { ans = n - 1 - i; break; }
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 1792
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <deque>
#include <iostream>
#include <iomanip>
#include <locale>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int INT_MAX_SQRT = sqrt(INT_MAX);
int pwi(int x, int p) {
    if (p == 0) return 1;
    if (p == 1) return x;
    int tmp = pwi(x, p / 2);
    if (tmp > INT_MAX_SQRT) return 0;  // overflow
    if (p % 2 == 0)
        return tmp * tmp;
    else
        return tmp * tmp * x;
}

long LONG_MAX_SQRT = sqrt(LONG_MAX);
long pwl(long x, long p) {
    if (p == 0) return 1;
    if (p == 1) return x;
    long tmp = pwl(x, p / 2);
    if (tmp > LONG_MAX_SQRT) return 0;  // overflow
    if (p % 2 == 0)
        return tmp * tmp;
    else
        return tmp * tmp * x;
}

map<long, long> factorization(long N) {
    map<long, long> res;
    long SQRT_N = ceil(sqrt(N));
    for (long i = 2; i < SQRT_N; i++) {
        while (N % i == 0) {
            if (res.find(i) == res.end()) {
                res[i] = 1;
            } else {
                res[i] += 1;
            }
            N /= i;
        }
    }
    if (N > SQRT_N) res[N] = 1;
    return res;
}

void debug_vec(string name, vector<int> vec) {
    cout << name << endl;
    for (auto e: vec) cout << e << endl;
}

void debug_vec(string name, vector<long> vec) {
    cout << name << endl;
    for (auto e: vec) cout << e << endl;
}

void debug_mat(string name, vector<vector<long>> mat) {
    cout << name << endl;
    for (auto vec: mat) {
        for (auto e: vec) cout << e << "   ";
        cout << endl;
    }
}

int main() {
    int D;
    cin >> D;
    int I = 26;

    vector<int> C(I);
    for (int i = 0; i < I; i++) cin >> C[i];

    vector<vector<long>> S(D, vector<long>(I));
    for (int d = 0; d < D; d++) {
        for (int i = 0; i < I; i++) {
            cin >> S[d][i];
        }
    }

    vector<int> L(I, 1);
    for (int d = 0; d < D; d++) {
        for (int i = 0; i < I; i++) {
            long loss = 0;
            for (int j = 0; j < I; j++) {
                if (i != j) loss += L[j] * C[j];
            }
            S[d][i] -= loss;
        }
        int ind = distance(S[d].begin(), max_element(S[d].begin(), S[d].end()));
        cout << ind + 1 << endl;
        for (int i = 0; i < I; i++) L[i]++;
        L[ind] = 1;
    }

    return 0;
}


Measured memory_bytes: 3820
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
  
int main(void){
    ll h, w;
    
    cin >> h >> w;
    
    ll ans = ((h/2) * (w/2))*2;
    //cout << (h/2)*2 << " " << (w/2)*2 << endl;
    //cout << ans << endl;
    if(h%2 == 1) ans += w/2;
    //cout << ans << endl;
    if(w%2 == 1) ans += h/2;
    //cout << ans << endl;

    if((h%2 == 1) && (w%2 == 1)) ans += 1;
    //cout << h%2 << " " << w%2 << endl;

    if((h==1) || (w==1)) ans = 1;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<sstream>
#include<string>
#include<string.h>
#include<cmath>
#include<stack>
#include<vector>
#include<map>
#define E (2.71828182)
#define PI (3.1415926535898)
#define	mem(a,b)	memset(a,b,sizeof(a))
#define	_max(a,b,c)	(max(a,b)>c?max(a,b):c)
#define mod	1000000007
#include<set>
#define gc getchar
#define debug(a) cout << "*" << a << "*" << endl
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<float, int> P;
const int N = 200000;
const long long  MAX_V = 5005, INF = 2147483647, MOD = 998244353;
#include <iostream>
using namespace std;
int gt[9], a[9], b[9], n;
bool judge(int a[])
{
	for (int i = 0; i < n; i++)
		if (a[i] != gt[i])	return false;
	return true;
}
int main()
{
	while (~scanf("%d", &n))
	{
		int f1 = 0, f2 = 0, ct = 1;
		for (int i = 0; i < n; i++)	gt[i] = i + 1;
		for (int i = 0; i < n; i++)	scanf("%d", &a[i]);
		for (int i = 0; i < n; i++)	scanf("%d", &b[i]);
		do
		{
			if (judge(a))	f1 = ct;
			if (judge(b))	f2 = ct;
			ct++;
		}while (next_permutation(gt, gt + n) && (!f1 || !f2));
		printf("%d\n", abs(f1 - f2));
	}
}


Measured memory_bytes: 256
# -*- coding:utf-8 -*-
"""解き方
[入力例1]
4 3
1 2
2 3
1 4

道路\都市 | 1 | 2 | 3 | 4
           ○   ○ 
               ○   ○
           ○           ○

[出力例1]
2
2
1
1
"""
def solve():
    N, M = list(map(int, input().split()))
    road_cnt = [0 for i in range(N)]

    for i in range(M):
        a, b = list(map(int, input().split()))
        a, b = a-1, b-1

        road_cnt[a] += 1
        road_cnt[b] += 1
    
    for cnt in road_cnt:
        print(cnt)


if __name__ == "__main__":
    solve()


Measured memory_bytes: 3060
s = list(input())
n = len(s)
u = int((n-1)/2)

s01 = s[:u]
s02 = s[-u:]

s1 = s01[:u]
s2 = s01[-u:]
s3 = s02[:u]
s4 = s02[-u:]

ms = 'Yes'
for t1,t2,t3,t4 in zip(s1,s2,s3,s4):
  if not (t1==t2 and t2 == t3 and t3== t4):
    ms = 'No'
    break
    
print(ms)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define mod 1000000007
using namespace  std ;
typedef long long ll ;
typedef vector<int>vi ;
//typedef vector<l>vl ;
typedef vector<ll>vll ;
typedef vector<vector<ll> >vvl ;
typedef pair<int,int> pii ;
typedef pair<ll,ll> pll ;
typedef vector<pll>vpll;
typedef vector<string>vstr;
void READ(vll &v, ll n)
{
    ll a ;
    for(ll i=0 ; i<n ; i=i+1)
    {
        cin>>a ;
        v.pb(a) ;
    }
}
void PRINT(vll &v, ll n)
{
    ll a ;
    for(ll i=0 ; i<n ; i=i+1)
    {
        cout<<v[i]<<" " ;
    }
    cout<<"\n" ;
}
ll n,m,k;
vll v;
ll dp[100005][3];
ll solve(ll i , ll j)
{
    if(i<m || i==0)
    {
        return(!j);
    }
    if(dp[i][j]!=-1)
    {
        return(dp[i][j]);
    }
    ll ans = 3;
    for(ll b = 0 ; b<n ; b=b+1)
    {
        if(i>=v[b])
        {
            ans = solve(i-v[b],!j);
        }
        if(ans==j)
        {
            break;
        }
    }
    dp[i][j] = ans;
    return(ans);
}
int main()
{
    ios_base::sync_with_stdio(false);//this and next two lines for cin cout TLE handling
    cin.tie(NULL);
    cout.tie(NULL);
    std::cout.unsetf ( std::ios::floatfield );//this and next line for floating precision upto 6
    std::cout.precision(6);
    ll a,b,c,d,e,x,i,j,t,y,w;
    double p,q,r,u,s ;
    string str = "",str1 = "" ;
    /*char ch,chr ;
    ll a1=0,a2=0,b1=0,b2=0 ;*/
    cin>>n>>k;
    READ(v,n);
    m = *min_element(all(v));
    memset(dp,-1,sizeof(dp));
    a = solve(k,0);
    //cout<<a;
    if(a)
    {
    	cout<<"Second";
	}
	else
	{
		cout<<"First";
	}
}

Measured memory_bytes: 5760
#include<bits/stdc++.h>
#define ll long long
#define fi first
#define se second
using namespace std;

const ll MOD=10000;
string a,b;
int m;
ll dp[502][2][500][11][3][2];

inline ll solve(string s){
  int n=(int)s.length();
  for(int i=0;i<n+1;i++)
    for(int j=0;j<2;j++)
      for(int k=0;k<m;k++)
        for(int l=0;l<11;l++)
          for(int mm=0;mm<3;mm++)
            for(int o=0;o<2;o++)
              dp[i][j][k][l][mm][o]=0;
  dp[0][0][0][0][0][0]=1;
  for(int i=0;i<n;i++){
    for(int j=0;j<2;j++){
      for(int k=0;k<m;k++){
        for(int l=0;l<11;l++){
          for(int mm=0;mm<3;mm++){
            for(int o=0;o<2;o++){
              int lim=j?9:s[i]-'0';
              int pre=l-1;
              for(int d=0;d<lim+1;d++){
                if(d==0 && o==0){
                  (dp[i+1][j || d<lim][(10*k+d)%m][0][0][0]+=dp[i][j][k][l][mm][o])%=MOD;
                  continue;
                }
                if(pre==-1){
                  (dp[i+1][j || d<lim][(10*k+d)%m][d+1][0][1]+=dp[i][j][k][l][mm][o])%=MOD;
                  continue;
                }
                if(pre<d && mm!=1){
                  (dp[i+1][j || d<lim][(10*k+d)%m][d+1][1][1]+=dp[i][j][k][l][mm][o])%=MOD;
                }
                if(pre>d && mm!=2){
                  (dp[i+1][j || d<lim][(10*k+d)%m][d+1][2][1]+=dp[i][j][k][l][mm][o])%=MOD;
                }
              }
            }
          }
        }
      }
    }
  }
  ll ans=0;
  for(int i=0;i<2;i++)for(int j=1;j<11;j++)for(int k=0;k<3;k++){
    (ans+=dp[n][i][0][j][k][1])%=MOD;
  }
  return ans;
}

inline string min1(string s){
  int n=(int)s.length();
  for(int i=n-1;i>=0;i--){
    int now=s[i]-'0';
    if(now-1<0){
      s[i]='9';
    }else{
      s[i]='0'+now-1;
      break;
    }
  }
  for(int i=0;i<n;i++){
    if(s=="0")break;
    if(s[i]=='0')s=s.substr(1,s.length()-1);
    else break;
  }
  return s;
}
                   
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(10);
  cout<<fixed;
#ifdef LOCAL_DEFINE
    freopen("in", "r", stdin); 
    freopen("out","w",stdout);
#endif
  ll ansa,ansb;
  cin>>a>>b>>m;
  a=min1(a);
  ansb=solve(b);
  ansa=solve(a);
  cout<<(ansb+MOD-ansa)%MOD<<"\n";
#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
  return 0;
}

Measured memory_bytes: 261524
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtTest.AGC_Challenge
{
    class _016_C
    {
        static void Main(string[] args)
        {
            Method(args);
        }

        static void Method(string[] args)
        {
            int[] HWhw = ReadInts();
            int H = HWhw[0];
            int W = HWhw[1];
            int h = HWhw[2];
            int w = HWhw[3];

            if (H % h == 0 && W % w == 0)
            {
                WriteLine("No");
                return;
            }

            bool rev = false;
            if (W % w == 0)
            {
                int tmp = H;
                int tmp2 = h;
                H = W;
                h = w;
                W = tmp;
                w = tmp2;
                rev = true;
            }

            int[] sums = new int[W];
            for (int i = 0; w - 1 + i * w < W; i++)
            {
                sums[w - 1 + i * w] = -(i + 1);
            }

            for(int i = 0; W - 1 - i * w >= 0; i++)
            {
                sums[W - 1 - i * w] = i + 1;
            }

            for (int i = W - 2; i >= 0; i--)
            {
                if (sums[i] == 0) sums[i] = sums[i + 1];
            }

            WriteLine("Yes");

            if (rev)
            {
                for (int i = 0; i < W; i++)
                {
                    for (int j = 0; j < H; j++)
                    {
                        if (i > 0) Write(sums[i] - sums[i - 1]);
                        else Write(sums[i]);
                        if (j < H - 1) Write(" ");
                    }
                    WriteLine();
                }
            }
            else
            {
                for (int i = 0; i < H; i++)
                {
                    for (int j = 0; j < W; j++)
                    {
                        if (j > 0) Write(sums[j] - sums[j - 1]);
                        else Write(sums[j]);
                        if (j < W - 1) Write(" ");
                    }
                    WriteLine();
                }
            }
        }

        private static string Read() { return ReadLine(); }
        private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 16336
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <sstream>
#include <set>
#include <tuple>
#include <algorithm>
#include <memory>
#include <numeric>
#include <queue>
#include <functional>
#include <cmath>
#include <cstring>
#include <map>
#include <unordered_map>

using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;

const ll INF = 1LL << 60;

vector<ll> h_dp;
map<P, ll> f_dp;

ll h(const ll l)
{
	if (l < 1) return 1;
	if (h_dp[l] != -1) return h_dp[l];

	h_dp[l] = 2 * h(l - 1) + 3;
	return h_dp[l];
}


ll f(const ll l, const ll x)
{
	if (l <= 0) return (x > 0 ? 1 : 0);
	
	const auto& itr = f_dp.find(P(l, x));
	if (itr != f_dp.end())
	{
		return itr->second;
	}

	ll ans = 0;
	if (x <= 1 + h(l - 1))
	{
		ans = f(l - 1, x - 1);
	}
	else
	{
		ans = f(l - 1, h(l - 1)) + 1 + f(l - 1, x - 2 - h(l - 1));
	}

	f_dp.emplace(P(l, x), ans);
	return ans;
}


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

	ll N, X;

	cin >> N >> X;

	h_dp = vector<ll>(N + 1, -1);

	cout << f(N, X) << endl;
	//system("pause");
}


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

bool SortXPos(pair<int, int> pos1, pair<int, int> pos2) { return pos1.first < pos2.first ? true : false; }
bool SortYPos(pair<int, int> pos1, pair<int, int> pos2) { return pos1.second < pos2.second ? true : false; }

int main(void)
{
	int num;
	while(cin>>num)
	{
		if(num == 0)
			break;
		vector<pair<int, int> > pos(num);
		pos[0].first= 0; pos[0].second= 0;

		for(int i= 1 ; i < num; i++)
		{
			int base, action;
			cin>>base>>action;

			switch(action)
			{
			case 0:
				pos[i].first= pos[base].first-1;
				pos[i].second= pos[base].second;
				break;
			case 1:
				pos[i].first= pos[base].first;
				pos[i].second= pos[base].second-1;
				break;
			case 2:
				pos[i].first= pos[base].first+1;
				pos[i].second= pos[base].second;
				break;
			case 3:
				pos[i].first= pos[base].first;
				pos[i].second= pos[base].second+1;
				break;
			}
		}

		sort(pos.begin(), pos.end(), SortXPos);
		int xlength= pos[num-1].first-pos[0].first+1;
		sort(pos.begin(), pos.end(), SortYPos);
		int ylength= pos[num-1].second-pos[0].second+1;

		cout<<xlength<<' '<<ylength<<endl;
	}
	return 0;
}

Measured memory_bytes: 3108
n=int(input())
listP=list(map(int,input().split()))
ans=0
for i in range(1,n-1):
  if listP[i-1]<listP[i]<listP[i+1] or listP[i-1]>listP[i]>listP[i+1]:
    ans+=1
print(ans)      

Measured memory_bytes: 3060
N = int(input())
S = []
for i in range(N):
    S.append(input())
M = int(input())
T = []
for j in range(M):
    T.append(input())

maxmoney = 0
maxword = "aaaaa"
for i in range(N):
    money = 0
    for j in range(N):
        if S[i]==S[j]:
            money = money + 1
    for j in range(M):
        if S[i] == T[j]:
            money = money - 1
    if money > maxmoney:
        maxmoney = money
        maxword = S[i]
print(maxmoney)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e15;

#include <math.h>
#define PI 3.14159265358979323846264338327950L
const int mxN = 2e2;

int main() {
    string s, t;
    cin >> s >> t;
    int mn = 10000000;
    for (int i = 0; i < (int)s.length() && i + (int)t.length() < (int) s.length()+1; i++) {
        int cnt = 0;
        for (int j = i, k = 0; k < (int)t.length(); j++, k++) {
            if (s[j] != t[k]) cnt++;
        }
        mn = min(mn, cnt);
    }
    cout << mn;
    return 0;
}

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

int main()
{
    int a, b;
    cin >> a >> b;
    if (a % 2 == 0 || b % 2 == 0)
    {
        cout << "Even" << endl;
    }
    else
    {
        cout << "Odd" << endl;
    }
}

Measured memory_bytes: 256
n=int(input())
a=[int(n) for n in input().split()]
ch=[]

for i in range(n):
  ch.append([a[i], i+1])
ch.sort()
for i in range(n):
  if i==n-1:
    print(ch[i][1])
  else:
    print(ch[i][1], end=" ")

Measured memory_bytes: 21440
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define SUB(a, b) a = (a+mod-b)%mod
#define MUL(a, b) a = (a * b) % mod
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define fi first
#define se second
typedef pair<int,int> P;
typedef pair<int, P> PP;
typedef pair<P, int> Pi;
typedef vector<int> vi;
typedef deque<int> dq;
const int inf = 1e9+7;
const int INF = 1e18+7;

const int mod = 1e9+7;
class FermatCombination{
private:
	vector<int> fac, inv;
	int Pow(int x, int n){
		if(n < 0)n += mod-1;
		int ans = 1;
		while(n > 0){
			if(n & 1)ans = (ans*x)%mod;
			x = (x*x)%mod;
			n >>= 1;
		}
		return ans;
	}
	void Factrial(int n){
		fac[0] = inv[0] = 1;
		for(int i = 1;i <= n;i++){
			fac[i] = (fac[i-1]*i)%mod;
			inv[i] = Pow(fac[i], mod-2);
		}
	}
public:
	void init(int n){	//nCk
		fac.resize(n+1);
		inv.resize(n+1);
		Factrial(n);
	}
	int comb(int n, int k){
		if(n < k)return 0;
		if(k == 0)return 1;
		int tmp = (fac[n]*inv[k])%mod;
		return (tmp*inv[n-k])%mod;
	}
};

FermatCombination C;
signed main(){
	C.init(200005);
	int h, w, a, b, ans = 0;
	scanf("%lld%lld%lld%lld", &h, &w, &a, &b);
	repi(i,b,w){
		int d = h-a-1;
		int tmp1 = C.comb(i+d, d);
		int tmp2 = C.comb(a-1+w-i-1, a-1);
		ADD(ans, (tmp1*tmp2)%mod);
	}
	printf("%lld\n", ans);
	return 0;
}







Measured memory_bytes: 3328
#include<iostream>
#include<algorithm>

using namespace std;
int main()
{
    int A, B, C, X, Y;
    cin >> A >> B >> C >> X >> Y;
  	int val=0;

    if(A > C*2){
        val= C*2*X;
        if(X<Y){
            if(B > C*2){
                val+= (Y-X)*C*2;
            }
            else{
                val+= (Y-X)*B;
            }
        }
    }
    else if(B > C*2){
        val= C*2*Y;
        if(Y<X){
            if(A > C*2){
                val+= (X-Y)*C*2;
            }
            else{
                val+= (X-Y)*A;
            }
        }
    }
    else if(A+B > C*2){
        if(X > Y){
            val = C*2*Y;
            val += A*(X-Y);
        }
        else{
            val = C*2*X;
            val += B*(Y-X);
        } 
    }
    else{
        val= A*X + B*Y;
    }
    cout << val << endl;
    return 0;
}

Measured memory_bytes: 256
n=int(input())
i=0
j=n-1
print(i)
a=input()
print(j)
b=input()
while 1:
    if j-i<2:
        print(i)
        _=input()
        print(j)
        if input()!='Vacant':
            print('助けてくれ～～～')
    k=(j-i)//2+i
    print(k)
    c=input()
    if(k-i)%2and a==c or not(k-i)%2and a!=c:
        j=k
    else:
        a=c
        i=k

Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define INF LLONG_MAX/10
#define rep(i,n) for(int i=0;i<n;i++)
#define krep(i,k,n,m) for(int i=k;i<n;i+=m)
#define erep(i,k,n) for(int i=k;i<n;i++)
#define mod 1000000007
//最大公約数
int gcd(int s,int b){
    if(b==0)return s;
    return gcd(b,s%b);
}
signed main(){
    int n;
    cin>>n;
    if(n%2==1){
        cout<<0<<endl;
    }
    else{
        n=n/2;
        int ans=0;
        while(1){
            ans+=n/5;
            n=n/5;
            if(n==0){
                break;
            }
        }
        cout<<ans<<endl;
    }
}



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

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

    string x;
    int ans = 0;
    for (auto c: s) {
        if (x.size() > 0 && x.back() != c) {
            x.pop_back();
            ans += 2;
        } else {
            x.push_back(c);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include<stdio.h>
#include<math.h>
int main(){
double a,b,c,d,e,f,x,y,i,j;
int g,h;
while(scanf("%lf %lf %lf %lf %lf %lf\n",&a,&b,&c,&d,&e,&f)!=EOF){
y=(c*d-a*f)/(b*d-a*e);
x=(e*c-b*f)/(a*e-b*d);
if(x>=0){
x=x*1000+0.5;
}
else{
x=x*1000-0.5;
}
if(y>=0){
y=y*1000+0.5;
}
else{
y=y*1000-0.5;
}
g=x,h=y;
i=g,j=h;
x=i/1000,y=j/1000;
printf("%.3lf %.3lf\n",x,y);
}
return 0;
}


Measured memory_bytes: 2032
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>

using namespace std;

class go{
public:
	int num;
	int times;
	go(int x, int y){num = x; times = y;}
};

bool mysort(const go& a1, const go& a2){
	if(a1.times > a2.times){
		return true;
	}else if(a1.times < a2.times){
		return false;
	}else{
		if(a1.num < a2.num){
			return true;
		}else{
			return false;
		}
	}
}

int main(void){
	int x,y;
	while(cin >> x >> y){
		if((x|y) == 0) break;
		bool op[x][y];
		char tmp;
		vector<go> v;
		for(int i=0;i<x;i++){
			for(int j=0;j<y;j++){
				cin >> tmp;
				op[i][j] = tmp - '0';
			}
		}
		for(int i=0;i<y;i++){
			tmp = 0;
			for(int j=0;j<x;j++){
				if(op[j][i]) tmp++;
			}
			v.push_back(go(i,tmp));
		}
		sort(v.begin(), v.end(), mysort);
		for(int i=0;i<y-1;i++){
			cout << v[i].num + 1<< " ";
		}
		cout << v[y-1].num + 1 << endl;
	}

}

Measured memory_bytes: 1004
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
using namespace std;
 
int main(){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if(a+b < c+d)cout << "Right";
    else if(a+b==c+d) cout << "Balanced";
    else cout << "Left";
}

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

int main(){
    int n,mi=1e9,p,ans=0;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>p;
        if(p<mi)ans++,mi=p;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define N 505
inline int read(){
    int x=0,f=1;
    char c=getchar();
    while(c<'0'||c>'9'){
        if(c=='-')f=-1;
        c=getchar();
    }
    while(c>='0'&&c<='9'){
        x=(x<<3)+(x<<1)+c-'0';
        c=getchar();
    }
    return x*f;
}
int a[N][N],n,ans,p[N*N],vis[N][N];
const int d[4][2]={{0,1},{1,0},{-1,0},{0,-1}};
inline bool check(int x,int y){
	return x>=1&&y>=1&&x<=n&&y<=n;
}
void dfs(int x,int y){
	for(int i=0;i<4;++i){
		int nx=x+d[i][0],ny=y+d[i][1];
		if(check(nx,ny)&&a[nx][ny]>a[x][y]+(!vis[x][y])){
			a[nx][ny]=a[x][y]+(!vis[x][y]);
			dfs(nx,ny);
		}
	}
}
int main(){
	n=read();
	for(int i=1;i<=n*n;++i){
		p[i]=read();
	}
	for(int i=1;i<=n;++i){
		for(int j=1;j<=n;++j){
			a[i][j]=min(min(n-i,i-1),min(n-j,j-1));
		}
	}
	for(int i=1;i<=n*n;++i){
		int x=(p[i]-1)/n+1,y=(p[i]-1)%n+1;
		ans+=a[x][y];
		vis[x][y]=1;
		for(int k=0;k<4;++k){
			int nx=x+d[k][0],ny=y+d[k][1];
			if(check(nx,ny)&&a[nx][ny]>a[x][y]){
				a[nx][ny]=a[x][y],dfs(nx,ny);
			}
		}
	}
	printf("%d\n",ans);
	return 0;
}


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

#define name ""
#define ini freopen(name".inp","r",stdin); freopen(name".out","w",stdout)
#define foe(it,c) for (__typeof(c.begin()) it = c.begin(); it != c.end(); it++)
#define long long long 
#define db double 
#define pii pair <int, int>
#define pll pair <long, long>
#define all(c) c.begin(), c.end()
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

const int INF = 1e9+7;
const int MOD = 1e9+7;
const int dx[4] = {0,0,-1,1};
const int dy[4] = {-1,1,0,0};

int main()
{
  fastio;
  int a, b, c; cin >> a >> b >> c;
  cout << c << ' ' << a << ' ' << b;
  return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long A = sc.nextInt();
		long B = sc.nextInt();
		
		if((A+B)%2!=0) {
			System.out.println("IMPOSSIBLE");
			return;
		}
		if(A==B) {
			System.out.println(1);
			return;
		}
		System.out.println((A+B)/2);
		
	}
}



Measured memory_bytes: 23124
import java.util.Scanner;

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

        while (true) {
            try {
                String s = sc.nextLine();
                if (s.equals(".")) break;
                System.out.println(search(s, 0, '.', '.', 0) == s.length()-1 ? "yes" : "no");
            } catch (Exception e) {
                break;
            }
        }
        sc.close();
    }

    private static int search(String s, int i, char shape, char opp, int depth) {
        for (; i<s.length()-1; ++i) {
            char c = s.charAt(i);
            if (opp == '.') {
                if (c == ')' || c == ']') return s.length()+10;
            }
            if (c == opp) return s.length()+10;
            else if (c == '(') i = search(s, i+1, ')', ']', depth+1);
            else if (c == '[') i = search(s, i+1, ']', ')', depth+1);
            else if (c == shape) return i;
        }
        return i + depth;
    }
}



Measured memory_bytes: 42336
import java.lang.Math;
import java.util.Arrays;
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int board[][] = new int[2][N];
        for (int i = 0; i < 2; i++) {
            for (int j = 0; j < N; j++) {
                board[i][j] = sc.nextInt();
            }
        }

        // 上は左側からの累積和, 下は右側からの累積和を取っておく
        int sumUp[] = new int[N];
        sumUp[0] = board[0][0];
        for (int i = 1; i < N; i++) {
            sumUp[i] = sumUp[i-1] + board[0][i];
        }
        int sumDown[] = new int[N];
        sumDown[N-1] = board[1][N-1];
        for (int i = N-2; i >= 0; i--) {
            sumDown[i] = sumDown[i+1] + board[1][i];
        }

        int answer = 0;
        for (int i = 0; i < N; i++) {
            answer = Math.max(answer, (sumUp[i] + sumDown[i]));
        }

        System.out.println(answer);
    }
}


Measured memory_bytes: 21844
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;

#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

#[allow(dead_code)]
fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}


fn print_vec(v: &Vec<Vec<usize>>){
    for row in v{
        println!("{:?}", row);
    }
}

fn main(){
    let line: Vec<usize> = read_as_vec();
    let (n, m, q)= (line[0], line[1], line[2]);

    let mut table: Vec<Vec<usize>> = vec![vec![0;n];n];

    for _ in 0..m{
        let line: Vec<usize> = read_as_vec();
        table[line[0]-1][line[1]-1] += 1;
    }
    let mut cul_sum: Vec<Vec<usize>> = vec![vec![0;n];n];

    cul_sum[0][0] = table[0][0];
    for i in 1..n{
        cul_sum[i][0] = table[i][0] + cul_sum[i-1][0];
        cul_sum[0][i] = table[0][i] + cul_sum[0][i-1];
    }



    for i in 1..n{
        for j in 1..n{
            cul_sum[i][j] = cul_sum[i][j-1] + cul_sum[i-1][j] +
                table[i][j] - cul_sum[i-1][j-1];
        }
    }
    //print_vec(&cul_sum);
    for _ in 0..q{
        let line: Vec<usize> = read_as_vec();
        let (s, e) = (line[0]-1, line[1]-1);

        if s == 0{
            let ans = cul_sum[e][e];
            println!("{}", ans);
        }else{
            let ans = cul_sum[e][e] + cul_sum[s-1][s-1] - cul_sum[s-1][e] - cul_sum[e][s-1];
            println!("{}", ans);
        }
    }

}


Measured memory_bytes: 9084
#include<iostream>
using namespace std;
int main()
{
	long long n,m,max; 
	cin>>n>>m>>max;
    if(max>n)
	{ 
	max=max-n;
	n=0;
		if(max>m)
		{
			max=max-m;
			m=0;
		}
		else {
				m=m-max;
				max=0;
			}
	}
	else n=n-max;
	cout<<n<<" "<<m;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
long long num[200000+50];
int main ()
{
	long long n;
	while(scanf("%lld",&n)!=EOF)
	{
		long long i,sn=0,k;
		for(i=0;i<n;i++)
		{
			scanf("%lld",&num[i]);
			sn+=num[i];			
		}
		k=fabs(sn-2*num[0]);
		for(i=0;i<n-1;i++)
		{
			sn-=2*num[i];
			//printf("sn=%lld\n",sn);
			if(k>fabs(sn))
				k=fabs(sn);
			//printf("k=%lld\n",k);

		}	
		if(k<0)
			k*=-1;
		printf("%lld\n",k);
	} 
}

Measured memory_bytes: 1664
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)(((n)>>(m))&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
ll gcd(ll p,ll q){
	while(q){
		ll t=p%q;
		p=q;
		q=t;
	}
	return p;
}
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)

ll a[100010];
ll dp1[100010],dp2[100010];
ll n;
int main(){
	scanf("%lld",&n);
	rep(i,0,n)scanf("%lld",a+i);
	dp1[0]=0;
	dp2[0]=0;
	rep(i,1,n+1){
		dp1[i]=gcd(dp1[i-1],a[i-1]);
		dp2[i]=gcd(dp2[i-1],a[n-i]);
	}
	ll ans=max(dp1[n-1],dp2[n-1]);
	rep(i,1,n-1)ans=max(ans,gcd(dp1[i],dp2[n-1-i]));
	printf("%lld",ans);
}

Measured memory_bytes: 2560
from collections import deque

h, w = map(int, input().split())

area = [[] for _ in range(h+2)]

for i in range(h+2):
    if i == 0 or i == h+1:
        area[i] = ['#'] * (w+2)
    else:
        area[i] = list(input())
        area[i].insert(0, '#')
        area[i].append('#')

def bfs(i, j):
    distance_matrix = [[1000 for _ in range(w+2)] for _ in range(h+2)]
    distance_matrix[i][j] = 0
    move = [[-1,0],[1,0],[0,-1],[0,1]]
    d = deque()
    d.append([i, j])
    max_distance = 0
    while len(d) > 0:
        x, y = d.popleft()
        for q, v in move:
            if area[x+q][y+v] =='.' and distance_matrix[x+q][y+v] == 1000:
                d.append([x+q,y+v])
                distance = distance_matrix[x][y] + 1
                distance_matrix[x+q][y+v] = distance
                if distance > max_distance:
                    max_distance = distance
    return max_distance

max_distance = 0
for i in range(1, h+1):
    for j in range(1, w+1):
        if area[i][j] == '#':
            continue
        else:
            distance = bfs(i, j)
            if distance > max_distance:
                max_distance = distance


print(max_distance)



Measured memory_bytes: 3316
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
#define P pair<int,int>
const int MOD=1e9+7;
const int INF=2e9;
 
 
int main() {
    ios_base::sync_with_stdio(false);
 
    string o,e; 
    cin >> o >> e;
    string ans;
    rep(i,e.size()) {
        ans.push_back(o[i]);
        ans.push_back(e[i]);
    }
    if (o.size()>e.size()) ans.push_back(o[o.size()-1]);
    cout << ans << endl;
 
    return 0;   
}

Measured memory_bytes: 256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "iomanip"
#include "cmath"

using namespace std;

const long long int MOD = 1000000007;

long long int N, M, K, H, W, L, R;


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

	cin >> H >> W;
	vector<vector<int>>edge(10, vector<int>(10, 100000));
	for (int i = 0; i < 10; i++) {
		for (int j = 0; j < 10; j++) {
			cin >> edge[i][j];
		}
	}
	for (int k = 0; k < 10; k++) {
		for (int i = 0; i < 10; i++) {
			for (int j = 0; j < 10; j++) {
				edge[i][j] = min(edge[i][j], edge[i][k] + edge[k][j]);
			}
		}
	}
	vector<int>num(10);
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			cin >> K;
			if (K != -1) {
				num[K]++;
			}
		}
	}
	for (int i = 0; i < 10; i++) {
		M += edge[i][1] * num[i];
	}
	cout << M << endl;
	return 0;
}


Measured memory_bytes: 256
//#include <cstdio>
#include <iomanip>    // setw 控制输出间隔函数
#include <iostream>   // cin, cout, abs
#include <algorithm>  // max, min, swap, sort
#include <cmath>      // pow
#include <cstring>    // strlen
#include <set>        // set 集合
#include <stack>      // stack 栈
#include <queue>      // queue 队列
#include <string>     // string 字(yang)符(rou)串, substr
#include <map>
#include <fstream>
using namespace std;
int main()
{
    //freopen("aaa.in", "r", stdin);
    //freopen("aaa.out", "w", stdout);
    string h;
    cin >> h;
    string f = h;
    for( int i = 0; i < h.size(); i++)
        h[i] = f[h.size() - i - 1];
    for( int i = 0; i < h.size(); i++)
    {
        if( h[i] == 'b') h[i] = 'd';
        else if( h[i] == 'd') h[i] = 'b';
        else if( h[i] == 'p') h[i] = 'q';
        else if( h[i] == 'q') h[i] = 'p';
    }
    if( h == f) printf("Yes\n");
    else printf("No\n");
    //fclose(stdin);
    //fclose(stdout);
    return 0;
}


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

int main() {
  int n;
  string s;
  cin>>n>>s;
  int e[300005],w[300005];
  
  e[0]=0;
  for (int i=0; i<s.size(); i++) {
    e[i+1]=e[i]+(s[i]=='E' ? 1 : 0);
    w[i+1]=w[i]+(s[i]=='W' ? 1 : 0);
  }
  int ans=1e9,sum;
  for (int i=0; i<s.size(); i++) {
    sum=w[i]+e[n]-e[i+1];
    ans=min(ans,sum);
  }
  cout<<ans<<endl;     
  return 0;
}



Measured memory_bytes: 2948
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }

using Weight = int;
struct Edge {
	int s; //source
	int d; //destination
	Weight w; //weight
	Edge(int s, int d, Weight w = 1) : s(s), d(d), w(w) {};
	bool operator<(const Edge &e)const { return w < e.w; }
};
using Edges = vector<Edge>;
using Graph = vector<Edges>;
using Array = vector<Weight>;
using Matrix = vector<Array>;

enum { WHITE, GRAY, BLACK };
vector<int> dijkstra(const Graph &g, int s, vector<Weight> &dist) {
	using State = tuple<Weight, int, int>; //?§?????????????????°?????????? ??? ???
	priority_queue<State, vector<State>, greater<State>> PQ;
	int n = g.size();
	vector<int> color(n, WHITE);
	vector<int> prev(n, -1);
	dist.assign(n, INF);
	dist[s] = 0; PQ.emplace(0, s, -1); color[s] = GRAY; //?§????
	while (PQ.size()) {
		Weight d; int v, u;
		tie(d, v, u) = PQ.top(); PQ.pop(); //dist???????°???¨??????State???????????????
		if (dist[v] < d)continue; //?????§???????????§???????????°??????
		color[v] = BLACK;
		prev[v] = u;
		for (auto &e : g[v]) { //??£??\????????????????????¨????????????		
			if (color[e.d] == BLACK)continue; //??¢?´¢????????????
			if (dist[e.d] > dist[v] + e.w) {
				dist[e.d] = dist[v] + e.w;
				PQ.emplace(dist[e.d], e.d, v);
				color[e.d] = GRAY;
			}
		}
	}
	return prev;
}

//??¨?????´???
Edge diameter(const Graph &g, int s = 0) {
	vector<Weight> dist;
	dijkstra(g, s, dist);
	int n = g.size(), u = -1, v = -1;
	for (int i = 0; i < n; i++) if (dist[i] != INF && (u == -1 || dist[i] > dist[u])) u = i;
	dijkstra(g, u, dist);
	for (int i = 0; i < n; i++) if (dist[i] != INF && (v == -1 || dist[i] > dist[v])) v = i;
	Weight d = dist[v];
	if (u > v) swap(u, v);
	return Edge(u, v, d);
}

signed main() {
	int n; cin >> n;
	Graph g(n);
	rep(i, 0, n-1) {
		int s, t, w; cin >> s >> t >> w;
		g[s].emplace_back(s, t, w);
		g[t].emplace_back(t, s, w);
	}
	Edge e = diameter(g);
	vector<Weight> dist1, dist2;
	dijkstra(g, e.s, dist1);
	dijkstra(g, e.d, dist2);
	rep(i, 0, n) {
		cout << max(dist1[i], dist2[i]) << endl;
	}
	return 0;
}

Measured memory_bytes: 3928