akhauriyash/Code-Regression huggingface dataset:
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

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

    static class TaskD {
        public void solve(int testNumber, InputReader in, PrintWriter out) {

            int h = in.nextInt();
            int w = in.nextInt();

            int n = in.nextInt();
            int[] a = new int[n];

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

            int[][] ans = new int[h][w];

            int i = 0;
            int j = 0;

            boolean[][] vis = new boolean[h][w];

            int cur = 0;
            int tot = 0;
            int tt = h * w;

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

            for (int idx = 0; tot < tt; idx = (idx + 1) % 4, i += dx[idx], j += dy[idx]) {

                while (i >= 0 && j >= 0 && i < h && j < w && !vis[i][j]) {
                    vis[i][j] = true;
                    ans[i][j] = cur + 1;
                    a[cur]--;
                    tot++;
                    if (a[cur] == 0) cur++;
                    i += dx[idx];
                    j += dy[idx];
                }

                //roll_back
                i -= dx[idx];
                j -= dy[idx];

            }


            for (int ii = 0; ii < h; ++ii)
                for (int jj = 0; jj < w; ++jj)
                    out.print(ans[ii][jj] + (jj == w - 1 ? "\n" : " "));

        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 23764
#include <iostream>

using namespace std;
int main(){
    int n; cin >> n;
    n %= 10;
    if(n==3){
        cout << "bon" << endl;
    }else if(n==0 || n==1 || n==6 || n==8){
        cout << "pon" << endl;
    }else{
        cout << "hon" << endl; 
    }
}

Measured memory_bytes: 3636
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int n,x,y,ans[2005];
int main()
{
	scanf("%d%d%d",&n,&x,&y);
	for(int i=1;i<=n;i++)
	  for(int j=i+1;j<=n;j++)
	    ans[min(j-i,min(abs(i-x)+abs(j-y)+1,abs(i-y)+abs(j-x)+1))]++;
	for(int i=1;i<n;i++)printf("%d\n",ans[i]);
	return 0;
}

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

public class Main{
	public static void main(String[] args)throws IOException{
		InputStreamReader isr = new InputStreamReader(System.in);
		BufferedReader reader = new BufferedReader(isr);
		String string;
		int n;
		
		while((string = reader.readLine()) != null){
			n = Integer.parseInt(string);
			if(n == 0) break;
			
			String[] cake = reader.readLine().split(" ");
			int peace = 0;
			for(int i = 0; i < cake.length; i++)
				peace += Integer.parseInt(cake[i]);
			
			System.out.println(peace / (n - 1));
		}
		reader.readLine();
	}
}

Measured memory_bytes: 31792
#include <bits/stdc++.h>
using namespace std;
// Collecting Balls (Easy Version)
int main() {
  int N, K, s = 0;
  cin >> N >> K;

  for (int i = 0; i < N; i++) {
    int x;
    cin >> x;

    if (x <= K / 2) {
      s += x;
    } else {
      s += K - x;
    }
  }

  cout << s * 2 << endl;
}

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

int main() {
  int w, a, b;
  cin >> w >> a >> b;
  if(abs(a - b) <= w){
    cout << "0" << endl;
  }else{
    cout << abs(a - b) - w << endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<ctime>
#include<cmath>
#include<utility>
#include<cstdlib>
#include<bitset>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<iomanip>
using namespace std;                       

#define ll long long
#define pb push_back
#define mp make_pair

#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

const ll M = 1e9 + 7;

ll fastpo(ll a, ll x){
    if(x == 0) return 1ll;
    if(x == 1) return a;
    ll y = fastpo(a, x/2);
    if(x%2 == 0){
        return y*y;
    }
    return y*y*a;
}

ll inv(ll a, ll M){
    return fastpo(a, M-2);
}

ll gcdExtended(ll a, ll b, ll *x, ll *y) 
{ 
    if (a == 0) 
    { 
        *x = 0, *y = 1; 
        return b; 
    } 
  
    ll x1, y1; 
    ll gcd = gcdExtended(b%a, a, &x1, &y1); 
  
    *x = y1 - (b/a) * x1; 
    *y = x1; 
  
    return gcd; 
}

ll modInverse(ll a, ll m) 
{ 
    ll x, y; 
    ll g = gcdExtended(a, m, &x, &y); 
    if (g != 1) 
        return -1; 
    else
    { 
        ll res = (x%m + m) % m; 
        return res;
    } 
}


ll gcd(ll a, ll b){
    if(a == 0){
        return b;
    }
    return gcd(b%a, a);
}

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

int main(){
//    clock_t time_req;
//     time_req = clock();
    int n;
    cin>>n;
    vector<ll> a(n);
    vector<ll> cnt(1e5 + 6, 0);
    ll sum = 0;
    for(int i=0; i<n; i++){
        cin>>a[i];
        cnt[a[i]]++;
        sum += a[i];
    }
    int q;
    cin>>q;
    for(int i=0; i<q; i++){
        ll b, c;
        cin>>b>>c;
        ll j = cnt[b];
        cnt[b] = 0;
        cnt[c] += j;
        sum -= (j*b);
        sum += (j*c);
        cout<<sum<<endl;
    }
    // time_req = clock()-time_req;
    // cout<<"Time taken: "<<(float)time_req/CLOCKS_PER_SEC<<"s"<<endl;
    return 0;
}

Measured memory_bytes: 4760
#include<stdio.h>
int main(void){
int n,max=-1000001,min=1000001;
long long sum=0;
scanf("%d",&n);
if(0<n&&n<=10000){
int i,number;
for(i=0;i<n;i++){
if(scanf("%d",&number)==1){
if(-1000000>number||number>1000000)
return 0;
sum+=number;
if(max<number)
max=number;
if(min>number)
min=number;
}}
printf("%d %d %ld\n",min,max,sum);
}
return 0;
}

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

int main(){
    string a, b;
    cin >> a >> b;

    /*if(a == b){
        printf("EQUAL\n");
        return 0;
    }*/

    if(a.size() < b.size()){
        printf("LESS\n");
    }
    else if(a.size() > b.size()){
        printf("GREATER\n");
    }
    else{
        for(long long i = 0; i < a.size(); i++){
            if(a[i] > b[i]){
                printf("GREATER\n");
                return 0;
            }
            else if(a[i] < b[i]){
                printf("LESS\n");
                return 0;
            }
        }
        printf("EQUAL\n");
    }
    return 0;
}

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

#define range(i, l, r) for (int i = (int)l; i < (int)(r); ++(i))
#define rrange(i, l, r) for (int i = ((int)(r) - 1); i >= (int)l; --(i))

#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
#define rwhole(f,x,...) ([&](decltype((x)) whole) { return (f)(rbegin(whole), rend(whole), ## __VA_ARGS__); })(x)

#define debug(x) cerr << "(" << __LINE__ << ")" << #x << ": " << (x) << endl

using int32 = int;
using int64 = long long;

const int mod     = 1e9 + 7;
const int32 inf   = 1001001001;
const int64 infll = 1001001001001001001ll;

const int dx[] = {0, -1, 1, 0, -1, 1, -1, 1}, dy[] = {-1, 0, 0, 1, -1, -1, 1, 1};
const string YES = "YES", NO = "NO", Yes = "Yes", No = "No", yes = "yes", no = "no";

struct IoSetup { IoSetup(){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(16); cerr << fixed << setprecision(16); } } iosetup;

template <typename T = int64> T input() { T x; cin >> x; return x; }

template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { range(i, 0, v.size()) { os << v[i] << (i + 1 != v.size() ? " " : ""); } return os; } 
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }
template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << p.fs << " " << p.sc; return os; }
template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.fs >> p.sc; return is; }

template <typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template <typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

void solver() {
  int K = input(), X = input();

  vector< int > ans;
  range(i, X - K + 1, X + K) {
    ans.emplace_back(i);
  }

  cout << ans << endl;
}

signed main(int argc, char *argv[]) {
  solver();
}


Measured memory_bytes: 256
import numpy as np
n,a=map(int,input().split())
s=np.full(n*1000+1,a+1)
s[0]=0
for i in range(n):
    w,v=map(int,input().split())
    s[v:]=np.minimum(s[v:],s[:-v]+w)
print(np.max(np.where(s<=a)))

Measured memory_bytes: 14892
#include "bits/stdc++.h"
using namespace std;
#define int long long
int mod=1e9+7;

signed main(){
  string t;
  cin>>t;
  string s;
  int ans=0;
  while(cin>>s){
    if(s=="END_OF_TEXT")break;
    for(int i=0;i<s.size();i++){
      if(s[i]>='A'&&s[i]<='Z')s[i]-='A'-'a';
    }
    if(s==t)ans++;
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 3124
n=int(input())
num_list1=list(map(str,input().split()))
num_list2=[]
input_list=[]

for k in num_list1:
    num_list2.append(k)
    input_list.append(k)


def bubble(num_list):
    i=0
    flag=True
    while flag:
        flag=False
        for j in range(len(num_list)-1,i,-1):
            if int(num_list[j-1][1])>int(num_list[j][1]):
                tmp=num_list[j-1]
                num_list[j-1]=num_list[j]
                num_list[j]=tmp
                flag=True
    return num_list 

def select(num_list):
    for i in range(0,len(num_list)):
        min=i
        for j in range(min+1,len(num_list)):
            if int(num_list[min][1])>int(num_list[j][1]):
                min=j
        tmp=num_list[i]
        num_list[i]=num_list[min]
        num_list[min]=tmp
    return num_list



def stable(input_list,output_list):
    for i in range(0,len(input_list)):
        for j in range(i+1,len(output_list)):
            for k in range(0,len(output_list)):
                for l in range(k+1,len(output_list)):
                    if input_list[i][1]==input_list[j][1] and input_list[i]==output_list[l] and input_list[j]==output_list[k]:
                        return "Not stable"
    return "Stable"

bubble=bubble(num_list1)
select=select(num_list2)


print(" ".join(bubble))
print(stable(input_list,bubble))
print(" ".join(select))
print(stable(input_list,select))


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

long long N, W, w[100], v[100], dp[101][100001];

long long solve(long long nleft, long long wleft)
{
    if (nleft < 0LL) return 0LL;
    if (!dp[nleft][wleft]) 
    {
        dp[nleft][wleft] = solve(nleft - 1LL, wleft);
        if (wleft - w[nleft] >= 0LL)
            dp[nleft][wleft] = max(solve(nleft - 1LL, wleft), v[nleft] + solve(nleft - 1LL, wleft - w[nleft]));
    }
    return dp[nleft][wleft];
}

int main()
{
    scanf("%lld %lld", &N, &W);
    for (int i = 0; i < N; i++)
    {
        scanf("%lld %lld", w + i, v + i);
    }
    printf("%lld\n", solve(N,W));
    return 0;
}


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

int main()
{
    int a, b;
    cin >> a >> b;
    rep(i, 2000)
    {
        if (i * 8 / 100 == a && i * 10 / 100 == b)
        {
            cout << i << endl;
            return 0;
        }
    }
    cout << "-1" << endl;
    return 0;
}

Measured memory_bytes: 3596
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <complex>
#include <math.h>
#include <ctype.h>
using namespace std;
double a,b,c,d,e,f,x,y;
int main(){
	while(cin>>a>>b>>c>>d>>e>>f){
	x=(c*e-b*f)/(a*e-b*d);
	y=(a*f-c*d)/(a*e-b*d);
	printf("%.3lf", x+1-1);
	cout<<" ";
	printf("%.3lf\n", y+1-1);
	}
return 0;}


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

 int main()
 {
     int n,x,flag=0;
     cin>>n;
     while(n){
        if(n%10==9){flag=1;}
        n/=10;
     }
    if(flag==1){cout<<"Yes"<<endl;}
    else {cout<<"No"<<endl;}
 }


Measured memory_bytes: 3620
#include <bits/stdc++.h>
    
using namespace std;
    
#define endl "\n"
#define ll unsigned long long
#define int long long int
#define pii pair <int, int>
#define pdd pair< double, double>
#define piii pair < pii, int > 
#define pll pair<ll, ll >
#define vi vector <int >
#define vvi vector < vi > 
#define vii vector < pii >
#define viii vector < piii >
#define vll vector <ll >
#define umap unordered_map
#define pb push_back
#define pq priority_queue
#define forn(i, n) for(int i = 0; i < (int)n; i++)
#define rep(i,b,c) for(int i = (int)b; i < (int)c; i++)
#define double long double
#define a first
#define b second

int32_t main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);

    int n, m, k;
    cin >> n >> m;
    vi arr(m);
    vvi a(m);
    vi ax(m);
    forn(i, m){
        cin >> arr[i] >> k;
        a[i].resize(k);
        ax[i] = 0;
        forn(j, k){
            cin >> a[i][j];
            ax[i] = ax[i]|(1 << a[i][j]);
        }
    }

    vi dp((1 << n + 1) + 5);
    dp[0] = 0;
    for(int i = 2; i < (1 << n + 1) + 3; i++){
        dp[i] = INT_MAX;
        forn(j, m){
            if(!(i&ax[j])) continue;
            int aux = i;
            for(auto z:a[j]){
                if(aux&(1 << z)){
                    aux = aux^(1 << z);
                }
            }
            dp[i] = min(dp[i], arr[j] + dp[aux]);
        }
    }
    int bitmask = 0;

    rep(i, 1, n + 1){
        bitmask = bitmask|(1 << i);
    }   
    if(dp[bitmask] >=INT_MAX){
        cout << -1 << endl;
    }else{
        cout << dp[bitmask] << endl;
    }


    return 0;
}


Measured memory_bytes: 512
N=int(input())
S=input()
A=[0]*(N+1)
B=[0]*(N+1)
for i in range(N):
    if S[i]=="W":
        A[i+1]=A[i]+1
    else:
        A[i+1]=A[i]
for i in range(N,0,-1):
    if S[i-1]=="E":
        B[i-1]=B[i]+1
    else:
        B[i-1]=B[i]
ans=10**19
for i in range(N):
    ans=min(ans,A[i]+B[i+1])
print(ans)


Measured memory_bytes: 45796
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
using namespace std;

int main(){
    int n=0,m=0,p=0,Asum=0,Nsum=0;
    string s;
    map<int,int>  res;
    set<int>      solved;
    cin >> n>>m ;
    while(m--){
        cin >> p >> s;
        if(s == "WA"){
            res[p]++;
        }else{
            // AC
            if(solved.count(p) == 0){
                // First AC
                solved.insert(p);
                Nsum+=res[p];
            }
        }
    }

    cout << solved.size() << " " << Nsum<< endl;
    return 0;
}


Measured memory_bytes: 9600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxx = 1e5 + 7;
int n;
ll k;
ll a[maxx];
ll ans, sum;

void Init() {
	cin >> n >> k;
	for(int i = 1; i <= n; i++) cin >> a[i];
}

void Solve() {
	for(int bit = 60; bit >= 0; bit--) {
		ll dd = 1ll << bit;
		int cnt1 = 0, cnt0 = 0;
		for(int i = 1; i <= n; i++) {
			if(a[i] & dd) cnt1++;
			else cnt0++;
		}
		if(cnt0 >= cnt1) {
			if(ans + dd <= k) ans += dd;
			else ans += 0ll << bit;
		}
		else ans += 0ll << bit;
	}
	for(int i = 1; i <= n; i++) sum += ans ^ a[i];
	cout << sum << endl;
}

int main() {
	Init();
	Solve();
	return 0;
}

Measured memory_bytes: 1024
S=input()
def heisei(S):
    while True:
        if int(S[0:4])<2019:
            return 'Heisei'
        if int(S[0:4])==2019 and int(S[5:7])<4:
            return 'Heisei'
        if int(S[5:7])==4 and int(S[8:10])<=30:
            return 'Heisei'
        return 'TBD'
    
print(heisei(S))
            

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
typedef long long llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define print(a) cout << a << endl;


int main(){
    int n;
    cin >> n;
    if( n==3 or n==5 or n==7) cout << "YES" << endl;
    else cout << "NO" << endl;
}

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

using namespace std;

int main(int argc, char const *argv[]) {
	int n,temp;
	std::vector<int> a;
	std::cin >> n;
	for (size_t i = 0; i < n; i++) {
		std::cin >> temp;
		a.push_back(temp);
	}
	for (size_t i = 0; i*2 < n; i++) {
		std::cout << a[n-1-i*2] << " ";
	}
	temp = n % 2;
	for (size_t i = 0; temp+i*2 < n; i++) {
		std::cout << a[temp+i*2] << " ";
	}
	std::cout << '\n';
	return 0;
}


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

int main() {
    int N,num,ind_a,ind_b,ans = 0;
    cin >> N;
    num = N / 2 + 1;
    vector<int> card(N),alice(num,0),bob(num,0);

    for (int i = 0; i < N; ++i)
    {
        cin >> card.at(i);
    };
    
    for (int i = 0; i < num; ++i)
    {
        ind_a = 0;
        ind_b = 0;

        for (int j = 0; j < N; ++j)
        {
            if (card.at(j)> alice.at(i)){
                alice.at(i) = card.at(j);
                ind_a = j;
            }
        }
        card.at(ind_a) = 0;

        for (int j = 0; j < N; ++j)
        {
            if (card.at(j)> bob.at(i)){
                bob.at(i) = card.at(j);
                ind_b = j;
            }
        }
        card.at(ind_b) = 0;
    }

    for (int i = 0; i < num; ++i){
        ans += alice.at(i)-bob.at(i);
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
int main()
{
	int n;
	while(std::cin>>n,n){
		n = 1000-n;
		int ans = 0;
		while(n>=500){
			n-=500; ans++;
		}
		while(n>=100){
			n-=100; ans++;
		}
		while(n>=50){
			n-=50; ans++;
		}
		while(n>=10){
			n-=10; ans++;
		}
		while(n>=5){
			n-=5; ans++;
		}
		ans += n;
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
#include <cmath>
#include <climits>
#include <vector>

typedef long long ll;

using namespace std;

int main(void) {
    int a, b, c; cin >> a >> b >> c;
    int ans = min(a, b) + min(max(a, b), c);
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <bits/stdc++.h>
#define ll long long
using namespace std;
void put(int x){
	if(x<0) {
		putchar('-');
		x*=-1;
	}
	if(x==0) {
		putchar('0');
	}
	int num=0;
	char c[15];
	while(x) {
		c[++num]=(x%10)+48;
		x/=10;
	}
	while(num) {
		putchar(c[num--]);
	}
	putchar('\n');
}
inline void in(int &x){
	char ch=getchar();
	int flag=1;
	while(!(ch>='0'&&ch<='9')) {
		if(ch=='-')
			flag*=-1;
		ch=getchar();
	}
	x=ch-'0';
	ch=getchar();
	while(ch>='0'&&ch<='9') {
		x=((x<<3)+(x<<1))+ch-'0';
		ch=getchar();
	}
	x*=flag;
}
int n,a[105],ans=1000000000;
int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	in(n);for(int i=1;i<=n;i++)in(a[i]);
	for(int i=-100;i<=100;i++){
		int sum=0;
		for(int j=1;j<=n;j++)
		sum+=(a[j]-i)*(a[j]-i);
		ans=min(ans,sum);
	}
	printf("%d\n",ans);
	return 0;
}


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

using namespace std;

int main() {
  static std::bitset<1000000001> bits{};
  int n;
  std::cin >> n;
  for (int i = 0; i < n; i++) {
    int a;
    std::cin >> a;
    bits[a] = bits[a] ^ 1;
  }
  std::cout << bits.count() << std::endl;
  return 0;
}


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

#define watch(x) cerr << (#x) << ": " << (x) << endl
#define int long long



int32_t main() {
    
    string s; cin >> s;
    int n = s.length();

    vector<int> a;
    char prev = s[0];
    a.push_back(1);
    for(int i = 1; i < n; ++i) {
        if(s[i] == prev) {
            a[a.size()-1]++;
        } else {
            a.push_back(1);
            prev = s[i];
        }
    }

    int ans = 0;
    while((int)a.size() > 1) {
        ans += 2*min(a[0], a[1]);
        if(a[0] > a[1]) {
            int d = a[0]-a[1];
            a.erase(a.begin());
            a.erase(a.begin());
            if(!a.empty()) a[0] += d;
        } else {
            a[1] -= a[0];
            a.erase(a.begin());
        }
    }

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


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

#define rep(i, n) for(int i=0;i<(int)n;i++)
#define rep2(i, s, n) for(int i=(s);i<(int)n;i++)
int INF=1e9+7;

ll gcd(ll m,ll n) {
  if(m%n==0) return n;
  return gcd(n,m%n);
}

int main() {
  ll A,B;
  cin >> A >> B;
  if(A<B) swap(A,B);
  ll g=gcd(A,B);
  int ans=1;
  ll num=g;
  for(ll i=2;i*i<=g;i++) {
    if(num%i==0) {
      while(num%i==0) num/=i;
      ans++;
    }
  }
  if(num>1) ans++;
  cout << ans << endl;
}

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

int main(){
  vector<int> n(4);
  int x;
  cin >> x;
  for(int i=0;i<4;i++){
    n.at(3-i)=(x%10);
    x/=10;
  }
  for(int i=0;i<(1<<3);i++){
    bitset<3> b(i);
    int sum=n.at(0);
    string ope="";
    for(int j=0;j<3;j++){
      if(b.test(j)){
        sum+=n.at(j+1);
        ope+="+";
      }else{
        sum-=n.at(j+1);
        ope+="-";
      }
    }
    if(sum==7){
      cout << n.at(0);
      for(int j=0;j<3;j++){
        cout << ope.at(j) << n.at(j+1);
      }
      cout << "=7" << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 256
<?php

class scan {
    private $arr = [];
    private $count = 0;
    private $pointer = 0;
    public function next() {
        if($this->pointer >= $this->count) {
            $str = trim(fgets(STDIN));
            $this->arr = explode(' ', $str);
            $this->count = count($this->arr);
            $this->pointer = 0;
        }
        $result = $this->arr[$this->pointer];
        $this->pointer++;
        return $result;
    }
    public function hasNext() {
        return $this->pointer < $this->count;
    }
    public function nextInt() {
        return (int)$this->next();
    }
    public function nextDouble() {
        return (double)$this->next();
    }
}

$sc = new scan();
$n = $sc->nextInt();
$m = $sc->nextInt();
$sum = 0;
for ($i=0;$i<$n;$i++) {
    $a[] = $sc->nextInt();
    $sum += $a[$i];
}

rsort($a);
if ($a[$m - 1] < (1/(4*$m)*$sum)) {
    echo "No";
} else {
    echo "Yes";
}

Measured memory_bytes: 4728
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        Main m = new Main(sc);
        m.show(m.solve());
        sc.close();
    }
    
	//フィールド
    Scanner sc;
    String S;
    String answer;
    
    //入力
    Main(Scanner sc) {
        this.sc = sc;
        S = sc.next();
    }
    
    //解答処理
    private String solve() {
        
        if (S.length() == 2) {
        	answer = S;
        } else if(S.length() == 3) {
        	String[] str = S.split("");
        	answer = str[2] + str[1] + str[0] ;
        }
        
        return answer;
    }
    
    //出力
    public void show(String answer) {
        System.out.println(answer);
    }
}


Measured memory_bytes: 39192
main=interact$unlines.f.lines
f(_:l)=[ "AC x "++show(sum[1|"AC"<-l])
       , "WA x "++show(sum[1|"WA"<-l])
       , "TLE x "++show(sum[1|"TLE"<-l])
       , "RE x "++show(sum[1|"RE"<-l])
       ]

Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

vl factor(ll n) {
  vl res;
  for(ll i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      res.push_back(i);
      if(i != n && i != n / i) res.push_back(n / i);
    }
  }
  return res;
}

int main() {
  ll n;
  cin >> n;
  vi a(n + 1);
  rep(i, n) cin >> a[i + 1];
  vl ans;
  for(ll i = n; i >= 1; i--) {
    if(a[i] == 0) continue;
    ans.push_back(i);
    auto f = factor(i);
    for(auto v : f) a[v] = !a[v];
  }
  sort(all(ans));
  cout << ans.size() << endl;
  rep(i, ans.size()) cout << ans[i] << (i == ans.size() - 1 ? '\n' : ' ');
}

Measured memory_bytes: 2932
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int INF=1001001001;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
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; }
 
int main(){
    ll N,K; cin >> N >> K;
    ll ans;
    
    ans=N%K;
    if (abs(ans-K)<ans){
        ans=abs(ans-K);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
# coding: utf-8
# Your code here!

n = int(input())
num_list = list(map(int, input().split()))
sum=1

if 0 in num_list:
    print(0)
    exit()

for i in num_list:
    
    if i==0:
        print(0)
        exit()
    i=str(i)
    sum=str(sum)
    
    if len(i)+len(sum)>21:
        print(-1)
        exit()
    i=int(i)
    sum=int(sum)
    sum=sum*i
    if sum>10**18:
        print(-1)
        exit()
print(sum)

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

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, start, end) for(int i = start; i < end; i++)
#define all(x) (x).begin(), (x).end()
#define debug(x) cout << (x) << endl;
#define MAX 999999999

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

typedef long long ll;

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

    int n;
    cin >> n;

    vector<int> nums(n);
    int cnt[3] = {0};
    rep(i, n){
        cin >> nums[i];
        if(nums[i] % 4 == 0) cnt[0] ++;
        else if(nums[i] % 2 == 0) cnt[1] ++;
        else { cnt[2] ++; }
    }

    if(cnt[0] > 0) cnt[0] ++;

    if(cnt[0] - cnt[2] - (cnt[1] % 2) >= 0){
       cout << "Yes" << "\n";
    }else{
        cout << "No" << "\n";
    }

}


Measured memory_bytes: 640
/*
  #問題：
  


  #分析：
  #オブジェクト：
  
  #条件：
  

  #要求：
  

  #解法：
  
*/

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
#include <initializer_list>
#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define uLL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;


const unsigned int BIT_FLAG_0 = (1<<0);
const unsigned int BIT_FLAG_1 = (1<<1);
const unsigned int BIT_FLAG_2 = (1<<2);
const unsigned int BIT_FLAG_3 = (1<<3);
const unsigned int BIT_FLAG_4 = (1<<4);
const unsigned int BIT_FLAG_5 = (1<<5);
const unsigned int BIT_FLAG_6 = (1<<6);
const unsigned int BIT_FLAG_7 = (1<<7);


#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
namespace mp = boost::multiprecision;

using Bint = mp::cpp_int;



int main(void){
  int H,W,h,w;
  cin>>H>>W;
  cin>>h>>w;
  cout<<(H-h)*(W-w)<<endl;
  return 0;
}



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

int main(){
  int d, n, num;
  cin >> d >> n;
  if(d==0){
    num=n;
    if(n==100)num+=num/100;
  }else if(d==1){
    num=n*100;
    if(n==100)num+=num/100;
  }else{
    num=n*10000;
    if(n==100)num+=num/100;
  }
  cout << num << endl;
  return 0;
}

Measured memory_bytes: 3644
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
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<VL> VVL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main() {
    int a, b;
    cin >> a >> b;
    cout << (a - 1) * (b - 1) << endl;

    return 0;
}

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

using namespace std;
#define BUF (200005)
#define ll long long 
#define INF (100000000000000)

ll n;
ll a[BUF];
ll s[BUF];


ll minmax4(ll a,ll b,ll c,ll d){
	ll mn,mx;
	mn = min(a,b);
	mn = min(mn,c);
	mn = min(mn,d);

	mx = max(a,b);
	mx = max(mx,c);
	mx = max(mx,d);

	return mx-mn;
}

void print4(ll a, ll b, ll c, ll d){
	cout << a << " " << b << " " << c << " " << d << "\n";
}

int main(void){
	cin >> n;
	for(ll i=1;i<=n;i++){
		cin >> a[i];
		s[i] = s[i-1] + a[i];
	}

	ll L,R;
	ll l=1,r=3;
	ll ans = INF;
	for(ll i=2;i<n-1;i++){
		L=s[i];
		R=s[n]-s[i];

		while(abs(2*s[l]-L) > abs(2*s[l+1]-L)){
			if( (l+1)==i) break;
			l++;
		}

		if(r<i+1)r=i+1;
		while(abs(2*(s[r]-L)-R) > abs(2*(s[r+1]-L)-R)){
			if( (r+1)==n) break;
			r++;
		}
		ans = min(ans, minmax4(s[l], L-s[l], s[r]-L, s[n]-s[r]) );	
	}

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


Measured memory_bytes: 3328
/*@author hussein zayed ;
    ___  ___
   |\  \|\  \
   \ \  \_\  \
    \ \   ___ \USSEIN
     \ \  \\ \ \
      \ \__\\ \_\
       \|__| \|__|
****************************************
*/

#include <bits/stdc++.h>
using namespace std;
#define fr for(int i=0;i<n;++i)
#define fr1 for(int i=1;i<=n;++i)
#define cinA for(int i=0;i<n;++i){cin>>arr[i];}
#define cinA1 for(int i=1;i<=n;++i){cin>>arr[i];}
#define coutA for(int i=0;i<n;++i){cout<<arr[i]<<" ";}
#define ll long long
#define lnarray sizeof(arr)/sizeof(*arr)
#define vi vector<int>
#define vs vector<string>
void Fast()
{
    ios_base :: sync_with_stdio( 0 ) ;
    cin.tie( 0 ) ;
    cout.tie( 0 ) ;
}
inline int RD()
{
    int i ;
    cin>>i;
    return i;
}

inline float RF()
{
    float i ;
    cin>>i;
    return i;
}

inline double RDO()
{
    double i ;
    cin>>i;
    return i;
}

inline string RS()
{
    string i ;
    cin>>i;
    return i;
}

inline ll RLL()
{
    ll i ;
    cin>>i;
    return i;
}

ll sumSet(ll n)
{
    return (1ll*n*(n+1))/2;
}


bool isPrime(int n)
{
    if(n==1)
        return false;
    for(int i=2; i*i<=n; ++i)
    {
        if(n%i==0)
            return false;
    }
    return true;
}
int sumDigit(int n){
int sum =0;
  while (n != 0)
    {
        sum+= + n % 10;
        n = n / 10;
    }
    return sum;
}

ll power2(int n){
  ll ans=(1<<n);
  return ans;
}

ll sumpow2(ll n){
 ll sum=(n*(n+1)*(2*n-1))/6;
 return sum;
}
const int MX=3e5+100;
int n,arr[MX],cm[MX];
int Left,Right,add;
bool can(int x){
 for(int i=1,j=x;j<=n;++i,++j){
  if(cm[j]-cm[i-1]+add>=x){
  Left=i,Right=j;
   return true;}
 }
 return false;
}
bool checkP(int n){
 vector<int>vr;
 while(n!=0){
 int a=n%10;
  n/=10;
 vr.push_back(a);}
 if(vr[0]==vr[4]&&vr[1]==vr[3])
 return true;
 return false;
}
int main(){
    Fast();
//freopen("output.txt" , "w" , stdout);
//freopen("wall.in" , "r" , stdin);
 int arr[5][5];
   for(int i=1;i<=3;i++){
    for(int j=1;j<=3;j++){
    cin>>arr[i][j];}}
    
if(arr[1][2]-arr[1][1]==arr[2][2]-arr[2][1]&&arr[3][2]-arr[3][1]==arr[2][2]-arr[2][1]&&arr[1][3]-arr[1][2]==arr[2][3]-arr[2][2]&&arr[3][3]-arr[3][2]==arr[2][3]-arr[2][2])
   cout<<"Yes";
else
  cout<<"No";
 }


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

#define int long long

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

int N;
struct edge {
    int to, cap, rev;
};
vector<edge> G[102];
bool used[102];

void add_edge(int from, int to, int cap) {
    G[from].push_back((edge) {to, cap, G[to].size()});
    G[to].push_back((edge) {from, 0, G[from].size() - 1});
}

int dfs(int v, int t, int f) {
    if (v == t) {
        return f;
    }
    used[v] = true;
    for (int i = 0; i < G[v].size(); i++) {
        edge &e = G[v][i];
        if (!used[e.to] && e.cap > 0) {
            int d = dfs(e.to, t, min(f, e.cap));
            if (d > 0) {
                e.cap -= d;
                G[e.to][e.rev].cap += d;
                return d;
            }
        }
    }
    return 0;
}

int max_flow(int s, int t) {
    int flow = 0;
    for (;; ) {
        memset(used, 0, sizeof(used));
        int f = dfs(s, t, 1e14);
        if (f == 0) {
            return flow;
        }
        flow += f;
    }
}

signed main() {
    cin >> N;
    int sum = 0;
    for (int i = 1; i <= N; i++) {
        for (int j = i + 1; j <= N; j++) {
            if (j % i == 0) {
                add_edge(i, j, 1e14);
            }
        }
    }
    for (int i = 1; i <= N; i++) {
        int a;
        cin >> a;
        if (a > 0) {
            add_edge(i, 100, a);
            sum += a;
        } else {
            add_edge(0, i, -a);
        }
    }
    cout << sum - max_flow(0, 100);
    return 0;
}


Measured memory_bytes: 256
def Gcd(a, b):#ユークリッド互除法
	return Gcd(b, a % b) if b else a

N,M = map(int,input().split())
S = input()
T = input()

#最小公倍数
p = (N * M) // Gcd(N, M)
re = p

for i in range(0,p,max((p//N),(p//M))):
	#交差点
	if i % (p//N) == 0 and i % (p//M) == 0:
		#異なる文字
		if S[i // (p//N)] != T[i // (p//M)]:
			re = -1
			break
print(re)

Measured memory_bytes: 3316
W, H, N = map(int, input().split())
xyalist = [tuple(map(int, input().split())) for _ in range(N)]
points = [[0, 0], [W, H]]
for x, y, a in xyalist:
    if a == 1:
        if x > points[0][0]:
            points[0][0] = x
    elif a == 2:
        if x < points[1][0]:
            points[1][0] = x
    elif a == 3:
        if y > points[0][1]:
            points[0][1] = y
    elif a == 4:
        if y < points[1][1]:
            points[1][1] = y
area = -1
if (points[1][0] - points[0][0]) > 0 and (points[1][1] - points[0][1]) > 0:
    area = (points[1][0] - points[0][0]) * (points[1][1] - points[0][1])

print(area if area > 0 else 0)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
long long n, a, b, k, p = 998244353, z;
int f[1000020];
int v[1000020];
int C(int n, int m) {
	return (long long)f[n] * v[m] % p * v[n - m] % p;
}
int main() {
	cin >> n >> a >> b >> k;
	f[0] = v[0] = v[1] = 1;
	for (int i = 2; i <= 1000000; i++) {
		v[i] = (long long)v[p % i] * (p - p / i) % p;
	}
	for (int i = 1; i <= 1000000; i++) {
		f[i] = (long long)f[i - 1] * i % p;
		v[i] = (long long)v[i - 1] * v[i] % p;
	}
	for (int i = 0; i <= n; i++) {
		int j = (k - a * i) / b;
		if (0 <= j && j <= n && i * a + j * b == k) {
			z = (z + (long long)C(n, i) * C(n, j)) % p;
		}
	}
	cout << z << endl;
	return 0;
}

Measured memory_bytes: 8064
n = int(input())
if n < 10:
    print(n)
elif n < 100:
    print(9)
elif n < 1000:
    print(9+(n-99))
elif n < 10000:
    print(9+900)
elif n < 100000:
    print(909+(n-9999))
else:
    print(90909)

Measured memory_bytes: 2940
#include <stdio.h>

int main() {

  int a[30] = {0};
  int i,b,c;

  for(i=0; i<28 ; i++) {
    scanf("%d" , &b);
    a[b-1] = 1;
  }

  for(i=0; i<30;i++) {
    if(a[i] == 0) {
      printf("%d\n" ,i+1);
    }
  }

  return 0;

}

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

int main() {
  vector<queue<char>> v(3);

  string s;
  cin >> s;
  for (char c : s) v[0].push(c);

  cin >> s;
  for (char c : s) v[1].push(c);

  cin >> s;
  for (char c : s) v[2].push(c);

  char c = 'a';
  while (true)
  {
    char i = c - 'a';
    if (v[i].empty())
    {
      putchar(toupper(c));
      return 0;
    }

    c = v[i].front(); v[i].pop();
  }
}


Measured memory_bytes: 3616
#include<stdio.h>

int BinarySearch(int key,int n,int *array){
    int left=0,mid,right=n;
    while(left < right){
        mid = (left + right) / 2;
        if(array[mid] == key){
          return mid;  
        } else if(key < array[mid]){
            right = mid;
        } else{
            left = mid + 1;
        }
    }
    return -1;
}

int main(){
    int n,q,c=0,cnt=0;;
    scanf("%d",&n);
    int s[n+1];
    for(int i = 0;i < n;i++) scanf("%d",&s[i]);
    scanf("%d",&q);
    int t[q];
    for(int i = 0;i < q;i++) scanf("%d",&t[i]);

    
    for(int i = 0;i < q;i++) if(BinarySearch(t[i],n,s) != -1)  cnt++;
        
    printf("%d\n",cnt);
    
}



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

typedef long long int ll;
#define deb(x) cout << #x << " " << x << endl;
#define debtwo(x,y) cout << #x << " " << x << ", " << #y << " " << y << endl;
#define mod 1000000000000000000

int main() {
    string s;
    cin >> s;
    int res = 0;
    for (int i = 0; i < s.length(); i++) {
        int r = 0;
        while (i < s.length() && s[i] == 'R') {
            r++;
            i++;
        }
        res = max(res, r);
    }
    cout << res;
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define mod 1000000007
#define ALL(v) (v).begin(),(v).end()
#define vi vector<int>
#define vll vector<ll>
#define vpii vector<pair<int,int>>
typedef long long ll;

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

int n,ans;

main()
{
        cin>>n;
        int k=200;
        rep(i,n)
        {
                int a;
                cin>>a;
                ans+=a;
                if(a%10!=0)k=min(k,a);
        }
        cout<<(ans%10!=0?ans:(k==200?0:ans-k))<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Arrays;
import java.util.Collections;
 
class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        boolean b = false;
        for(int i = 1; i < 10; i++){
            if(a % i == 0 && a / i <= 9){
                b = true;
            }
        }
        if(b){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 22996
unittest
{
	assert( [ "2 700", "3 500", "5 800" ].parse.expand.solve == 3 );
	assert( [ "2 2000", "3 500", "5 800" ].parse.expand.solve == 7 );
	assert( [ "2 400", "3 500", "5 800" ].parse.expand.solve == 2 );
	assert( [ "5 25000", "20 1000", "40 1000", "50 1000", "30 1000", "1 1000" ].parse.expand.solve == 66 );
}



import std.algorithm;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto dg = input.front.split.to!( long[] );

	auto upcs = new long[ 3 ][ dg[ 0 ] ];
	foreach( i, ref upc; upcs )
	{
		input.popFront;
		upc = ( ( i + 1 ) * 100 ) ~ input.front.split.to!( long[] );
	}
	
	return tuple( dg[ 1 ], upcs );
}

long solve( in long g, in long[ 3 ][] upcs )
{
	auto ts = new long[ upcs.length ];
	foreach( i, upc; upcs )
	{
		auto rc = calc( g, upc[ 0 ], upc[ 1 ], upc[ 2 ] );
		auto upcs_r = upcs[ 0 .. i ] ~ upcs[ i + 1 .. $ ];
		
		// 目標点数に達した
		if( rc[ 0 ] <= 0 )
		{
			ts[ i ] = rc[ 1 ];
			continue;
		}
		
		// 目標点数に達してないけどもう問題がないので打ち切る
		if( upcs_r.length <= 0 )
		{
			ts[ i ] = long.max;
			continue;
		}
		
		// まだ残ってる
		ts[ i ] = rc[ 1 ] + solve( rc[ 0 ], upcs_r );
	}
	
	return ts.reduce!( min );
}

auto calc( in long g, in long u, in long p, in long c )
{
	// 全問解かなくても足りる場合
	if( g <= u * ( p - 1 ) )
	{
		return tuple( 0L, cast( long ) ceil( cast( real ) g / u ) );
	}
	
	// 全問解くと足りる場合
	if( g <= u * p + c )
	{
		return tuple( 0L, cast( long ) p );
	}
	
	// 全問解いても足りない場合
	return tuple( cast( long ) g - ( u * p + c ), cast( long ) p );
}


Measured memory_bytes: 1276
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main()
{
    int n,b,f,r,v;
    int count[4][3][10]={0};
    scanf("%d",&n);
    for (int i = 0; i < n; i++)
    {
        scanf("%d%d%d%d",&b,&f,&r,&v);
        if(count[b-1][f-1][r-1]+v<0){
            count[b-1][f-1][r-1]=0;
        }else if(count[b-1][f-1][r-1]+v>9){
            count[b-1][f-1][r-1]=9;
        }else{
            count[b-1][f-1][r-1]+=v;
        }
    }
    for (int i = 0; i < 4; i++)
    {
        for (int j = 0; j < 3; j++)
        {
            for (int k = 0; k < 10; k++)
            {
                printf(" %d",count[i][j][k]);
            }
            printf("\n");
        }
        if(i!=3)printf("####################\n");
        
    }
}


Measured memory_bytes: 3244
#include <cstdio>
#include <vector>
#include <algorithm>

int main() {
  size_t N;
  scanf("%zu", &N);

  std::vector<int> a(N);
  for (auto& ai: a) scanf("%d", &ai);

  std::sort(a.rbegin(), a.rend());

  int res = 0;
  for (size_t i = 0; i < N; ++i) {
    if (i % 2 == 0) {
      res += a[i];
    } else {
      res -= a[i];
    }
  }
  printf("%d\n", res);
}

Measured memory_bytes: 256
def f(x):
    x = str(x)
    if x[0]==x[4] and x[1]==x[3]:
        return True
    else:
        return False
a,b = map(int,input().split())
cnt=0
for i in range(a,b+1):
    cnt += 1 if f(i) else 0
print(cnt)


Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <utility>
#include <queue>
#include <algorithm>
#define llint long long
#define mod 998244353
#define inf 1e18

using namespace std;
typedef pair<llint, llint> P;

llint n;
llint a[100005], b[100005];
llint need[100005], sneed[100005];
bool used[100005];
P p[100005];

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> a[i];
	for(int i = 1; i <= n; i++) cin >> b[i];
	
	for(int i = 1; i <= n; i++){
		p[i] = make_pair(b[i], a[i]);
	}
	sort(p+1, p+n+1);
	
	sort(a+1, a+n+1);
	sort(b+1, b+n+1);
	
	for(int i = 1; i <= n; i++){
		if(a[i] > b[i]){
			cout << "No" << endl;
			return 0;
		}
	}
	
	for(int i = 1; i <= n; i++) a[i] = p[i].second;
	for(int i = 1; i <= n; i++){
		need[i] = lower_bound(b+1, b+n+1, a[i]) - b;
		sneed[i] = need[i];
	}
	sort(sneed+1, sneed+n+1);
	
	for(int i = 1; i <= n; i++){
		if(i != sneed[i]){
			cout << "Yes" << endl;
			return 0;
		}
	}
	
	//for(int i = 1; i <= n; i++)  cout << need[i] << " "; cout << endl;
	
	int cnt = 0;
	for(int i = 1; i <= n; i++){
		if(used[i]) continue;
		cnt++;
		int v = i;
		do{
			used[v] = true;
			v = need[v];
		}while(!used[v]);
	}
	if(cnt == 1){
		cout << "No" << endl;
	}
	else cout << "Yes" << endl;
	
	return 0;
}

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

#define INFTY 10000000

int n,u,k;
int s,d,v,TTL;
int M[101][101],D[101];

void bfs( int s ){
  
  queue <int> Q;
  for( int i = 1; i <= n; i++ ) D[i] = INFTY;

  D[s] = 1;
  Q.push(s);
     
  while( !Q.empty() ){
    u = Q.front(); Q.pop();
    for( int l = 1; l <= n; l++ ){
      if( M[u][l] == 0 ) continue;
      if( D[l] != INFTY ) continue;
      D[l] = D[u] + 1;
      // cout << "l" << " " << l << " " <<  "D[l]" << " " << D[l] << " " <<
      // 	"D[u]" << " " << D[u] << endl;
      Q.push(l);

     
    }

  }
  if ( D[d] > TTL ){
    cout << "NA" << endl;
    return;
  }else{
    cout << D[d] << endl;
    //	cout << "TTL" << " " << TTL << endl;
    return;
  }
  
 
}

int main(){
  cin >> n;
  for( int i = 1; i <= n; i++ ){
    cin >> u;
    cin >> k;
    for( int j = 0; j < k; j++ ){
      int v;
      cin >> v;
      M[u][v] = 1;
    }
  }
    
  int p; cin >> p; 
  for( int i = 0; i < p; i++ ){
  cin >> s >> d >> TTL;
  bfs(s);
  }

  return 0;
}

Measured memory_bytes: 1240
#include <bits/stdc++.h>
using namespace std;
int a[4][13];
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		char c;
		int in;
		cin>>c>>in;
		if(c=='S')a[0][in-1]=1;
		else if(c=='H')a[1][in-1]=1;
		else if(c=='C')a[2][in-1]=1;
		else a[3][in-1]=1;
	}
	for(int i=0;i<4;i++){
		for(int j=0;j<13;j++){
			if(a[0][j]==0&&i==0){
				cout<<"S "<<j+1<<endl;
			}
			if(a[1][j]==0&&i==1){
				cout<<"H "<<j+1<<endl;
			}	
			if(a[2][j]==0&&i==2){
				cout<<"C "<<j+1<<endl;
			}
			if(a[3][j]==0&&i==3){
				cout<<"D "<<j+1<<endl;
			}
		}
	}
}



Measured memory_bytes: 3088