akhauriyash/Code-Regression huggingface dataset:
import java.lang.reflect.Array;
import java.util.*;
import java.lang.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int x = sc.nextInt();
        int m[] = new int[n];
        for (int i = 0; i < n; i++) {
            m[i] = sc.nextInt();
        }
        Arrays.sort(m);
        int sum[] = new int[n];
        sum[0] = m[0];
        for (int i = 1; i < n; i++) {
            sum[i] = sum[i - 1] + m[i];
        }

        int dounut = 0;
        if (x >= sum[n - 1]) {
            dounut = n + (x - sum[n - 1]) / sum[0];
        } else {
            for (int i = 0; i < n; i++) {
                if (m[i] > x) {
                    dounut = i - 1;
                    break;
                }
            }
        }
        System.out.println(dounut);
    }
}

Measured memory_bytes: 21844
import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.util.StringTokenizer;


         class FastReader
        {
            BufferedReader br;
            StringTokenizer st;

            public FastReader()
            {
                br = new BufferedReader(new
                        InputStreamReader(System.in));
            }

            String next()
            {
                while (st == null || !st.hasMoreElements())
                {
                    try
                    {
                        st = new StringTokenizer(br.readLine());
                    }
                    catch (IOException  e)
                    {
                        e.printStackTrace();
                    }
                }
                return st.nextToken();
            }

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

            long nextLong()
            {
                return Long.parseLong(next());
            }

            double nextDouble()
            {
                return Double.parseDouble(next());
            }

            String nextLine()
            {
                String str = "";
                try
                {
                    str = br.readLine();
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
                return str;
            }
        }

public class Main {

    public static void main(String[] args) {
        FastReader fastReader = new FastReader();
        filter( fastReader.nextInt(), fastReader.next() );

    }

    private static void filter(int reach, String s) {

        int len = s.length();
        if( len <= reach ){
            System.out.println(s);
        }else{
            System.out.println( s.substring(0, reach ) + "..." );
        }

    }
}


Measured memory_bytes: 36528
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <math.h>
using namespace std;
 
int main(){
	long long n, k;
	cin >> n >> k;
	vector<int> p(n);
	int counta = 0;
	int countb = 0;
	for(int i=0;i<n;i++){
		cin >> p.at(i);
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			if(p.at(i) > p.at(j)){
				counta++;
			}
		}
	}
	for(int i=0;i<n;i++){
		for(int j=i+1;j<n;j++){
			if(p.at(i) > p.at(j)){
				countb++;
			}
		}
	}
	long long int ans1 = (k*(k-1)/2)%1000000007;
	long long int ans2 = (counta * ans1);
	long long int ans3 = (countb*k)%1000000007;
	long long int ans = (ans2 + ans3)%1000000007;
	cout << ans << endl;
	return 0;
}

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

string str;

int main() {
  cin >> str;
  int cntA = 0;//1010...
  int cntB = 0;//0101...

  for(int i = 0; i < (int)str.size(); i = i + 2){
    if(str[i] == '0') cntA++;
    else cntB++;
  }
  
  for(int i = 1; i < (int)str.size(); i = i + 2){
    if(str[i] == '1') cntA++;
    else cntB++;
  }
  
  if (cntA < cntB) cout << cntA << endl;
  else cout << cntB << endl;

}

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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

int main()
{
    int n;
    string s;
    cin >> n >> s;
    if (n % 2 == 1)
        OP("No");
    else
    {
        if (s.substr(0, n / 2) == s.substr(n / 2))
            OP("Yes");
        else
            OP("No");
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<climits>
#include<map>
#include<string>
#include<functional>
#include<iomanip>
#include<deque>
#include<random>
#include<set>
#include<bitset>
#include<cassert>

using namespace std;
typedef long long ll;
typedef double lldo;
#define mp make_pair
#define pub push_back
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
ll gcd(ll a, ll b) { if (a % b == 0) { return b; } else  return gcd(b, a % b); }
ll lcm(ll a, ll b) { if (a == 0) { return b; }return a / gcd(a, b) * b; }
template<class T>ll LBI(vector<T>& ar, T in) { return lower_bound(ar.begin(), ar.end(), in) - ar.begin(); }
template<class T>ll UBI(vector<T>& ar, T in) { return upper_bound(ar.begin(), ar.end(), in) - ar.begin(); }

ll x;

int main() {
	cin >> x;
	for (int i = 1;; i++) {
		if (!((x * i) % 360)) {
			cout << i << endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 3632
// AOJ 2060 Tetrahedra
// 2018.3.23 bal4u

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0, c = getchar_unlocked();
	do n = 10*n + (c & 0xf), c = getchar_unlocked(); while (c >= '0');
	return n;
}

#define HASHSIZ  2000003
long long hash[HASHSIZ+2];

int insert(long long a)
{
	int i = a % HASHSIZ;
	while (hash[i]) {
		if (a == hash[i]) return 1;
		if (++i == HASHSIZ) i = 0;
	}
	hash[i] = a;
	return 0;
}

long long max;
int a[16], a2[16], n;

int check(int i, int j, int k)
{
	int s = a[i] + a[j] + a[k];
	int z = a[i];
	if (z < a[j]) z = a[j];
	if (z < a[k]) z = a[k];
	return (z<<1) >= s;
}

void calc(int i, int j, int k, int p, int q, int r)
{
	long long V;
	long long hash;
	long long A, B, C, P, Q, R;

	hash = a[i]; hash = (hash << 6) + a[j];
	hash = (hash << 6) + a[k];	hash = (hash << 6) + a[p];
	hash = (hash << 6) + a[q]; 	hash = (hash << 6) + a[r];
	if (insert(hash)) return;

	A = a2[i], B = a2[j], C = a2[k], P = a2[p], Q = a2[q], R = a2[r];
	V = A*R*(-A+B+C+P+Q-R) + B*Q*(A-B+C+P-Q+R) + C*P*(A+B-C-P+Q+R)
		- B*C*R - A*C*Q -A*B*P - P*Q*R;
	if (V > max) max = V;
}

int cmp(int *a, int *b) { return *a - *b; }

int main()
{
	int i, j, k, p, q, r;
	while (n = in()) {
		memset(hash, 0, sizeof(hash));

		for (i = 0; i < n; i++) a[i] = in();
		qsort(a, n, sizeof(int), cmp);
		for (i = n-1; ; i--) if (a[i] < a[i-1]+a[i-2]) break;
		n = i+1;

		for (i = 0; i < n; i++) a2[i] = a[i]*a[i];

		max = 0;
		for (i = 0; i < n; i++) for (j = i+1; j < n; j++) for (k = j+1; k < n; k++) {
			if (check(i, j, k)) continue;
			for (p = 0; p < n; p++) {
			if (p == i || p == j || p == k || check(i, j, p)) continue;
			for (q = 0; q < n; q++) {
			if (q == i || q == j || q == k || q == p || check(i, k, q)) continue;
			for (r = 0; r < n; r++) {
			if (r == i || r == j || r == k || r == q || r == p || check(j, k, r)) continue;
			calc(i, j, k, p, q, r);
		}}}}
		printf("%.10lf\n", sqrt((double)max/144));
	}
	return 0;
}



Measured memory_bytes: 17352
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  string o, e;
  cin >> o >> e;
  for(int i=0; i<o.length()+e.length(); i++){
    if(i%2==0) cout << o.substr(i/2,1);
    else cout << e.substr(i/2,1);
  }
  cout << endl;
  return 0;
}


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

using namespace std;

//#define int long long
#define sz(a) (int) (a).size()
#define all(a) (a).begin(), (a).end()

const int maxn = 1e5 + 10;

vector<int> g[maxn];
int dp[maxn];
int ans = 0;

void dfs(int v) {
    dp[v] = 1;
    for (auto u : g[v]) {
        if (!dp[u]) {
            dfs(u);
        }
        dp[v] = max(dp[u] + 1, dp[v]);
        ans = max(ans, dp[v]);
    }
}

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

    int n, m;
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        int u, v;
        cin >> u >> v;
        g[u].push_back(v);
    }
    for (int i = 1; i <= n; i++) {
        if (!dp[i]) dfs(i);
    }
    cout << ans - 1 << "\n";

    return 0;
}


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

typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1e9+7;
#define rep(i,N) for(ll i=0; i<(N); i++)

ll N;
ll ans;
bool over_flow(ll a,ll b){
  ll p=a*b;
  if(p<0){
    return 1;
  }
  else if(p/a==b){
    return 0;
  }else{
    return 1;
  }
}
ll pw(ll x,ll y){
    ll ret=1;
    for(ll i=0; i<y; i++){
       if(over_flow(ret,x)) return 0;
       ret*=x;
    }
    return ret;
}

int main(){

cin.tie(0);
ios::sync_with_stdio(false);

cin>>N;
if(N%2){
	cout<<0<<endl;
	return 0;
}
/*f[0]*2*4*6*8*10...
f[1]*3*5*7*9*11... */
//2*(1*2*3*4*5...)

N/=2;
rep(i,30){
	if(i==0) continue;
	if(pw(5,i)==0) continue;
	ans+=N/pw(5,i);
}

cout<<ans<<endl;

}
	


Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
	int a,b,c,d,cnt=0;
	scanf("%d%d%d",&a,&b,&c);
	for (d=a;d<=b;d++){
		if(c%d==0){
			cnt++;
		}
	}
	printf("%d\n",cnt);
	
	return 0;
}


Measured memory_bytes: 2104
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i<(n);++i)
using namespace std;
int main(){
	int n;cin>>n;
	float x,ans=0;
	string u;
	rep(i,n){
		cin>>x>>u;
		ans+=(u[0]=='J'?x:380000*x);
	}
	cout<<ans<<endl;
}

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

int main() {
  ll n;
  cin >> n;
  ll ans = 1e18;
  for (ll i = 1; i*i <= n; ++i) {
    if (n%i != 0) continue;
    ll j = n/i;
    ans = min(ans, i+j-2);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
  string s;
  cin>>s;
  int l=0,r=s.length()-1;
  bool flage=true;
  while(l<r){
    if(s[l]!=s[r])flage=false;
    l++,r--;
  }
  if(!flage){
    cout<<"No";
    return 0;
  }
  
  flage=true;
  l=0,r=(s.length()-1)/2-1;
  while(l<r){
    if(s[l]!=s[r])flage=false;
    l++,r--;
  }
  if(!flage){
    cout<<"No";
    return 0;
  }
  
  
  flage=true;
  l=(s.length()+1)/2,r=s.length()-1;
  while(l<r){
    if(s[l]!=s[r])flage=false;
    l++,r--;
  }
  if(!flage){
    cout<<"No";
    return 0;
  }
  cout<<"Yes";
}

Measured memory_bytes: 256
#include<stdio.h>

int main ()
{
	int n=10;

	long long int r,d,x;

	scanf("%lld %lld %lld", &r, &d, &x);

	while (n--)
	{
		x = r*x - d;
		printf("%lld\n",x);
	}

	return 0;
}


Measured memory_bytes: 128
# coding: utf-8

def main():
    N = int(input())
    a_s = map(int, input().split())

    ds = [a - i - 1 for i, a in enumerate(a_s)]
    pz = False
    t = 0
    for d in ds:
        if d == 0:
            if pz:
                pz = False
            else:
                t += 1
                pz = True
        else:
            pz = False
    return t


print(main())


Measured memory_bytes: 13880
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <stdbool.h>
#define LL long long
#define DB double
#define INF 1145141919810364364
#define PI 3.14159265358979
#define MIN(x,y) ((x)<(y)?(x):(y))
#define MAX(x,y) ((x)<(y)?(y):(x))
#define FOR(i,a,n) for(i=a;i<n;i++)
#define rep(i,n) FOR(i,0,n)
#define MOD 1000000007
//#define MOD 998244353
#define ERR 0.00000001
#define NUM 400010

void swap(LL* a,LL* b){LL tmp=*a;*a=*b;*b=tmp;}
void YN(int a){if(a==1)printf("Yes\n");if(a==0)printf("No\n");}
LL lpow(LL a,LL n){LL ans=pow(a,n)*10;if(ans%10<5)return ans/10;return ans/10+1;}
LL dup(LL a,LL d){if(a%d==0)return a/d;else return a/d+1;}
LL GCD(LL a,LL b){LL c=1,tmp=MAX(a,b);b=MIN(a,b);a=tmp;while(c!=0){c=a%b;a=b;b=c;}return a;}
LL LCM(LL a,LL b){return a*b/GCD(a,b);}
int lcmp(const void* a,const void* b){if(*(LL*)a>*(LL*)b)return 1;if(*(LL*)a<*(LL*)b)return -1;return 0;}
int lcmpr(const void* a,const void* b){if(*(LL*)a>*(LL*)b)return -1;if(*(LL*)a<*(LL*)b)return 1;return 0;}
int ccmp(const void* a,const void* b){return *(char*)a-*(char*)b;}
int ccmpr(const void* a,const void* b){return *(char*)b-*(char*)a;}
int scmp(const void* a,const void* b){return strcmp((char*)a,(char*)b);}
int scmpr(const void* a,const void* b){return strcmp((char*)b,(char*)a);}
LL mod(LL a,LL m){if(a<0)return a%m+m;else return a%m;}
LL DIV(LL a,LL d){LL m=MOD,x=1,y=0,k;while(m){k=d/m;d-=k*m;swap(&m,&d);x-=k*y;swap(&x,&y);}return mod(a*mod(x,MOD),MOD);}
LL FAC(LL a){LL i,ans=1;FOR(i,1,a+1){ans*=i;if(MOD>0&&ans>MOD)ans%=MOD;}return ans;}
LL POW(LL a,LL n){LL ans=1;while(n>0){if(n&1)ans=ans*a%MOD;a=a*a%MOD;n>>=1;}return ans;}
LL fact[NUM],finv[NUM],inv[NUM];
void comi(){LL i;fact[0]=fact[1]=1;finv[0]=finv[1]=1;inv[1]=1;FOR(i,2,NUM){fact[i]=fact[i-1]*i%MOD;inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;finv[i]=finv[i-1]*inv[i]%MOD;}}
LL com(LL n,LL k){if(n<k||n<0||k<0)return 0;return fact[n]*(finv[k]*finv[n-k]%MOD)%MOD;}

int main(){
  comi();
  LL n,k,i,ans=0;
  scanf("%lld%lld",&n,&k);
  ans=com(n*2-1,n-1);
  FOR(i,k+1,n)ans=mod(ans-com(n,i)*com(n-1,i),MOD);

  printf("%lld\n",ans);
	return 0;
}


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

int main()
{
  int N;
  int A[205];

  cin >> N;
  for(int i = 0; i < 2 * N; i++) cin >> A[i];
  
  sort(A, A + 2 * N);
  
  int ans = 0;
  for(int i = 0; i < N; i++) {
    ans += min(A[i * 2], A[i * 2 + 1]);
  }
  
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

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


Measured memory_bytes: 2704
#include <stdio.h>
#define black 1
#define white 0
#define BIG 2000000000

int n,c[100][100], A[100], color[100];

void Keiro() {
    int i, min, u, v;
    
    for (i = 0; i < n; ++i) {
        color[i]  = white;
        A[i] = BIG;
    }
    
    A[0] = 0;
    
    while(1) {
        min = BIG;
        
        u = -1;
        for(i = 0; i < n; i++) {
            if (min > A[i] && color[i] != black) {
                u = i;
                min = A[i];
            }
        }
        if (u == -1) break;
        
        color[u] = black;
        for (v = 0; v < n; ++v) {
            if (color[v] != black) {
                if (A[v] > A[u] + c[u][v]) {
                    A[v] = A[u] + c[u][v];
                }
            }
        }
        
    }
    
}
int main() {
    int i, j, k, a, b;
    scanf("%d", &n);
    
    for (i = 0; i < n; ++i){
        for (j = 0; j < n; ++j) {
            c[i][j] = BIG;

        }
    }
    for (i = 0; i < n; ++i) {
        scanf("%d %d", &a, &k);
        for (j = 0; j < k; ++j) {
            scanf("%d %d", &a, &b);
            c[i][a] = b;
        }
    }
    Keiro();
    
    for (i = 0; i < n; ++i) {
        printf("%d %d\n", i, A[i]);
    }

    return 0;
}

Measured memory_bytes: 1780
N = list(input())
n_1 = int(N[-1])

hon = [2,4,5,7,9]
pon = [0,1,6,8]
bon = [3]

if n_1 in hon:
    print('hon')
elif n_1 in pon:
    print('pon')
else:
    print('bon')


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

double a, b;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> a >> b;
	for(double i = 1; i <= (double)3000; i++)
		if(floor(i * 0.08) == a && floor(i * 0.1) == b){
			cout << i << "\n";
			return 0;
		}
	cout << "-1\n";
	return 0;
}

Measured memory_bytes: 256
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 x = sc.nextInt();
		int[] a = new int[n];

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

		Arrays.sort(a);

		int ans = 0;
		for (int i = 0; i < a.length; i++) {
			x -= a[i];
			if (x < 0)
				break;
			ans++;
		}

		System.out.println(x > 0 ? --ans : ans);
		sc.close();
	}

}


Measured memory_bytes: 21716
#include<stdio.h>
#include<string.h>
int main()
{
    char s[11],t[12],n[11];
    gets(s);
    gets(t);
    int i,d=0,lenS,lenT;
    lenS=strlen(s);
    lenT=strlen(t);
    for(i=0;i<(lenT-1);i++)
    {
        n[i]=t[i];
    }
    for(i=0;i<lenS;i++)
    {
        if(s[i]==n[i]){
            d++;
        }

    }
    if(d==lenS) printf("Yes\n");
    else printf("No\n");
    return 0;

}

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

int main()
{
	int H, W, Ch, Cw, Dh, Dw;
	cin >> H >> W >> Ch >> Cw >> Dh >> Dw;
	Ch--;
	Cw--;
	Dh--;
	Dw--;
	vector<string> S( H );
	for( int i = 0; i < H; i++ ) {
		cin >> S[i];
	}

	typedef tuple<int, int, int> T;
	const int INF = INT32_MAX / 2;
	vector<vector<int>> dist( H, vector<int>( W, INF ) );
	dist[Ch][Cw] = 0;
	priority_queue<T, vector<T>, greater<T>> que;
	que.push( T( 0, Ch, Cw ) );
	int dirv[4] = { 1, -1, 0, 0 };
	int dirh[4] = { 0, 0, 1, -1 };
	while( !que.empty() ) {
		int d, y, x;
		tie( d, y, x ) = que.top();
		que.pop();
		if( dist[y][x] < d ) continue;
		if( y == Dh && x == Dw ) break;
		for( int i = 0; i < 4; i++ ) {
			int ny = y + dirv[i];
			int nx = x + dirh[i];
			if( ny < 0 || ny >= H || nx < 0 || nx >= W ) continue;
			if( S[ny][nx] == '#' ) continue;
			if( dist[ny][nx] > d ) {
				que.push( T( d, ny, nx ) );
				dist[ny][nx] = d;
			}
		}
		int sty = y - 2;
		int endy = y + 2;
		int stx = x - 2;
		int endx = x + 2;
		for( int i = sty; i <= endy; i++ ) {
			for( int j = stx; j <= endx; j++ ) {
				if( i < 0 || i >= H || j < 0 || j >= W ) continue;
				if( S[i][j] == '#' ) continue;
				if( dist[i][j] > d + 1 ) {
					que.push( T( d + 1, i, j ) );
					dist[i][j] = d + 1;
				}
			}
		}
	}
	int ans = dist[Dh][Dw];
	if( ans == INF ) ans = -1;

	cout << ans << endl;
}


Measured memory_bytes: 9520
#if !defined(__clang__) && defined(__GNUC__)
#include <bits/stdc++.h>
#else
#include <cstdlib>
#include <climits>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#endif //  !defined(__clang__) && defined(__GNUG__)
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/math/common_factor_rt.hpp>

using namespace std;

int main()
{

    std::string S;
    std::cin >> S;

    int64_t w;
    std::cin >> w;

    for (size_t i = 0; i < S.size(); i += w) {
        std::cout << S[i];
    }
    std::cout << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
using namespace std;
typedef long long LL;

LL dp[1000005][10][2] = {0};
string s;
LL n,ans = 0x3f3f3f3f3f3f3f3f;

int main(){
	memset(dp,0x3f,sizeof(dp));
	cin >> s; n = s.length(); s = ' ' + s;
	dp[0][1][1] = 1; dp[0][0][0] = 0;
	for(LL i = 1;i <= n;i ++){
		for(LL j = 0;j <= 9;j ++){
			for(LL k = 0;k <= 9;k ++){
				if(j < s[i] - '0') dp[i][j][0] = min(dp[i][j][0],dp[i - 1][k][1] + (10 + j - (s[i] - '0')) % 10 + j);
				else dp[i][j][0] = min(dp[i][j][0],dp[i - 1][k][0] + (10 + j - (s[i] - '0')) % 10 + j);
				if(j - 1 < s[i] - '0') dp[i][j][1] = min(dp[i][j][1],dp[i - 1][k][1] + (19 + j - (s[i] - '0')) % 10 + j);
				else dp[i][j][1] = min(dp[i][j][1],dp[i - 1][k][0] + (19 + j - (s[i] - '0')) % 10 + j);
			}
		}
	}
	for(LL j = 0;j <= 9;j ++) ans = min(ans,dp[n][j][0]);
	cout << ans << endl;
	return 0;
}
//

Measured memory_bytes: 158596
#include <iostream>

using namespace std;
void swap(int &a, int &b);

int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	if (b < a)
		swap(a, b);
	if (c < b)
		swap(b, c);
	if (b < a)
		swap(a, b);
	cout << a << " " << b << " " << c << endl;

	return 0;
}

void swap(int &a, int &b)
{
	int temp = a;
	a = b;
	b = temp;
	return;
}




Measured memory_bytes: 3084
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < n; ++i)
using ll = long long;
const ll MOD = 1000000007;//998244353;
const int INF = 10000;
int A[1000][1000];
int main() {
   ios::sync_with_stdio(false);
   cin.tie(0);
   int h, w; cin >> h >> w;
   rep(i,h){
      rep(j,w){
         char c; cin >> c;
         A[i][j] = c=='#' ? 0 : INF;
      }
   }
   rep(i,h){
      rep(j,w-1){
         A[i][j+1] = min(A[i][j]+1, A[i][j+1]);
         A[i][w-j-2] = min(A[i][w-j-1]+1, A[i][w-j-2]);
      }
   }
   rep(j,w){
      rep(i,h-1){
         A[i+1][j] = min(A[i][j]+1, A[i+1][j]);
         A[h-i-2][j] = min(A[h-i-1][j]+1, A[h-i-2][j]);
      }
   }
   int ans = 0;
   rep(i,h)rep(j,w)ans = max(ans, A[i][j]);
   cout << ans << endl;
}

Measured memory_bytes: 7544
#include <iostream>
#include <string>
#include <stdio.h>
#include <string.h>
#include <cmath>
#include <vector>
#include <algorithm>
#include <cstdio>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define int long long
using namespace std;

signed main() {
    int n;
    int rr = 0, bb = 0;
    string s;
    cin >> n;
    cin >> s;
    for (int i = 0; i < n; i++) {
        if (s[i] == 'R'){
            rr++;
        } else if (s[i] == 'B') {
            bb++;
        }
    }
    if (rr > bb) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


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

using namespace std;

const int MOD = 1e9 + 7;

const int maxn = 3e5 + 5;
long long fact_my[maxn], inv_my[maxn];
long long pow_mod(long long b, int p) {
    long long res = 1;
    long long pow = b;
    while (p > 0) {
        if ((p & 1) != 0) res *= pow, res %= MOD;
        pow = pow * pow;
        pow %= MOD;
        p >>= 1;
    }

    return res;
}
long long C(int n, int k) {
    return (((fact_my[n] * inv_my[k]) % MOD) * inv_my[n - k]) % MOD;

}

int main() {
    int H, W, A, B;
    fact_my[0] = inv_my[0] = 1;
    for (int i = 1; i <= maxn; ++i) {
        fact_my[i] = (fact_my[i - 1] * i) % MOD;
        inv_my[i] = (pow_mod(fact_my[i], MOD - 2)) % MOD;
    }
    scanf("%d%d%d%d", &H, &W, &A, &B);
    H--, W--, A--, B--;
    long long res = 0;
    for (int i = 0; i < W - B; ++i) {
        res += ((C(H - A + B + 1 + i, B + 1 + i) - C(H - A + B + i, B + i) + 3LL * MOD) % MOD) * C(A + W - B - i - 1, A);
        res %= MOD;

    }
    printf("%lld\n", res);
    return 0;
}


Measured memory_bytes: 4992
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <math.h>
#include <limits.h>
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) > (b) ? (b) : (a))
#define abs(x) ((x) > 0 ? (x) : -(x))
#define MOD (ll)1000000007 //10^9 + 7
#define endl printf("\n")
typedef long long ll;
#define MAX_N (1 << 17)

int
main(int argc, char *argv[])
{
  int n;
  char s[2][53];
  scanf("%d", &n);
  scanf("%s", s[0]);
  scanf("%s", s[1]);

  int i, f;
  ll ans = 1;
  if (s[0][0] == s[1][0]) {
    i = 1; f = 0;
    ans *= 3;
  } else {
    i = 2; f = 1;
    ans *= 6;
  }

  while (i < n) {
    if (f) {
      if (s[0][i] != s[1][i]) {
	ans *= (ll)3;
	ans %= MOD;
	i += 2;
	f = 1;
      } else {
	i += 1;
	f = 0;
      }
    } else {
      if (s[0][i] != s[1][i]) {
	ans *= (ll)2;
	ans %= MOD;
	i += 2;
	f = 1;
      } else {
	ans *= (ll)2;
	ans %= MOD;
	i += 1;
	f = 0;
      }
    }
  }

  printf("%lld\n", ans);

  return 0;
}
	


Measured memory_bytes: 128
def main(argv)
  (a, b) = gets.chomp.split(' ').map(&:to_i)
  
  if a <= 9 and b <= 9 then
    puts (a * b).to_s
  else
    puts -1.to_s
  end
end

if self.to_s == 'main' then
  main(ARGV)
end

Measured memory_bytes: 1788
n,k=map(int,input().split())
d=list(map(int,input().split()))
a=[]
for i in range(10):
    sum=0
    for x in d:
        if x==i:
            break
        else:
            sum+=1
    if sum==k:
        a.append(i)
a=set(a)
for i in range(n,10*n+1):
    b=[]
    x=len(str(i))
    y=str(i)
    for j in range(x):
        b.append(int(y[j]))
    b=set(b)
    if a>=b:
        print(i)
        break

Measured memory_bytes: 3064
N, K = map(int,input().split())
sumn = 0
for i in range(K, N + 2):
    n = i*(i-1)//2
    l = N*(N+1)//2 - (N - i)*(N - i + 1)//2
    sumn += l - n + 1
    sumn = sumn%(10**9+7)
print(sumn)

Measured memory_bytes: 9192
#include <stdio.h>
#include <math.h>
int isprime(int);

int main(){
  int i, count=0, n, x;
  scanf("%d", &n);
  for(i = 0; i < n; i++){
    scanf("%d", &x);
    if(isprime(x) == 0) count++;
    else continue;
  }
  printf("%d\n", count);
  return 0;
}

int isprime(int x){
  int i=3;
  if(x == 2) return 0;
  
  if(x < 2 || x % 2 == 0)return 1;
  
  while(i <= sqrt(x)){
    if (x % i == 0) return 1;
    i = i + 2;
      }
  return 0;
}

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

typedef unsigned long long ull;

ull f(ull h){
	if(h == 1) return 1;
	
	return f(h/2)*2 + 1;
}

int main(){
	ull h;
	cin >> h;
	
	cout << f(h) <<endl;;
	
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
using ll = long long;
using P = pair<ll,int>;
using PP = pair<int,pair<int,int>>;
using T = tuple<string,int,int>;
const ll INF = 1LL<<60;

int main(){
  int n,k; cin >> n >> k;
  double ans = 0;
  for(int i = 1; i <= n; i++){
    double p = 1.0 / n;
    int now = i;
    while(now < k){
      now *= 2;
      p /= 2;
    }
    ans += p;
  }
  printf("%.15f\n", ans);
  return 0;
}


Measured memory_bytes: 256
import Control.Applicative ((<$>), (<*>))
import Control.Monad (replicateM, unless)

import Data.Vector.Unboxed (Vector, (!), (//))
import qualified Data.Vector.Unboxed as V

import Control.Monad.State

main :: IO ()
main = do
  [n, m] <- map read <$> words <$> getLine
  unless (n == 0 && m == 0) $ do
    solve n <$> replicateM n (read <$> getLine) <*> replicateM m (read <$> getLine) >>= print
    main

solve :: Int -> [Int] -> [Int] -> Int
solve n mp ds = evalState (f ds) (0, 0)
  where f :: [Int] -> State (Int, Int) Int
        f (x:xs) = do
          (p, ct) <- get
          let y = p + x
          if y >= n - 1 then return (ct + 1)
          else do
            let z = mpv ! y + y
            if z >= n - 1 then return (ct + 1)
            else do
              put (z, ct + 1)
              f xs
        mpv = V.fromList mp



Measured memory_bytes: 6080
k = int(input())

n = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

print(n[k-1])


Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <array>
#include <deque>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <complex>
#include <bitset>
#include <functional>

using namespace std;
using ll=long long int;

int main() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        a[i] = s[i] - '0';
    }

    set<int> ca[3];
    for (int i = 0; i < n; ++i) {
        for (int j = 2; j >= 1; --j) {
            for (auto &e: ca[j-1]) ca[j].insert(e*10 + a[i]);
        }
        ca[0].insert(a[i]);
    }


    cout << ca[2].size() << endl;


    return 0;
}


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

const int INF = 1 << 29;
using ll = long long int;
#define all(x) (x).begin(),(x).end()
#define rep(i,N) for(ll i = 0; i < (ll)N; ++i)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)


int main() {
	int n;
	cin >> n;
	string s;
	cin >> s;
	int c = 0;
	const string find_word("ABC");
	string::size_type pos = s.find(find_word);
	while (pos != string::npos) {
		++c;
		pos = s.find(find_word, pos + find_word.length());
	}

	cout << c << endl;
}

Measured memory_bytes: 3204
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define ALL(v) (v).begin(), (v).end()
#define SP cout << fixed << setprecision(10)
const int INF = (int)1e9;
const int MOD = (int)1e9 + 7;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

int n, c, x;
int d[30][39];
int t[3][30];

int main(void) {
    // code

    cin >> n >> c;
    REP(i, c) REP(j, c) cin >> d[i][j];
    REP(i, n) REP(j, n) cin >> x, t[(i + j) % 3][x - 1]++;

    int res = 1 << 30;
    REP(i, c) REP(j, c) if (i != j) REP(k, c) if (i != k && j != k) {
        int tt = 0;
        REP(l, c) tt += d[l][i] * t[0][l];
        REP(l, c) tt += d[l][j] * t[1][l];
        REP(l, c) tt += d[l][k] * t[2][l];
        if (tt < res)
            res = tt;
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define Repr(i, n, a) for (int i = (n); i >= (a); i--)
#define rep(i, n) Rep(i, 0, n)
#define repr(i, n) Repr(i, n, 0)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

int calc(int NUM, string s)
{
    int num[4];
    rep(i, 4)
    {
        int n = NUM % 10;
        num[3 - i] = n;
        NUM /= 10;
    }
    stack<int> st;
    rep(i, s.size())
    {
        if (s[i] == 'a')
            st.push(num[0]);
        if (s[i] == 'b')
            st.push(num[1]);
        if (s[i] == 'c')
            st.push(num[2]);
        if (s[i] == 'd')
            st.push(num[3]);
        if (s[i] == '+')
        {
            int a = st.top();
            st.pop();
            int b = st.top();
            st.pop();
            st.push(a | b);
        }
        if (s[i] == '*')
        {
            int a = st.top();
            st.pop();
            int b = st.top();
            st.pop();
            st.push(a & b);
        }
        if (s[i] == '^')
        {
            int a = st.top();
            st.pop();
            int b = st.top();
            st.pop();
            st.push(a ^ b);
        }
    }
    return st.top();
}

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

    string S;
    while (1)
    {
        cin >> S;
        if (S == ".")
            break;
        reverse(all(S));
        int P;
        cin >> P;
        int pass = calc(P, S);
        int cnt = 0;
        rep(i, 10000) if (calc(i, S) == pass) cnt++;
        cout << pass << " " << cnt << endl;
    }
}


Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod = 1000000007;
const int INF = 1001001001;

template<class Type>
Type modpow(Type a, Type n, Type mod)
{
	Type res = 1;
	while (0 < n) {
		if (n & 1) {
			res = res * a % mod;
		}
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

template<class Type>
Type gcd(Type x, Type y)
{
	Type r;
	if (x < y) swap(x, y);

	while (0 < y) {
		r = x % y;
		x = y;
		y = r;
	}
	return x;
}

template<class Type>
Type lcm(Type x, Type y)
{
	return x * y / gcd(x, y);
}

template<class Type>
bool is_prime(Type x)
{
	if (x == 2) return true;
	if (x < 2 || x % 2 == 0) return false;

	for (Type i = 3; i <= sqrt(x); i += 2) {
		if (x % i == 0) return false;
	}
	return true;
}

template<class Type>
vector<bool> eratos(Type n)
{
	vector<bool> isPrime(n + 1, true);
	isPrime[0] = isPrime[1] = false;
	for (Type i = 2; i <= n; i++) {
		if (isPrime[i]) {
			Type j = i + i;
			while (j <= n) {
				isPrime[j] = false;
				j = j + i;
			}
		}
	}
	return isPrime;
}

bool binary_search_judge(vector<int> a, int index, int key)
{
	if (key <= a[index]) return true;
	else return false;
}

int binary_search(vector<int> a, int key)
{
	int ng = -1;
	int ok = a.size();
	while (1 < abs(ng - ok)) {
		int mid = (ng + ok) / 2;
		if (binary_search_judge(a, mid, key)) ok = mid;
		else ng = mid;
	}
	return a[ok] == key;
}

int main()
{
	int n;
	cin >> n;
	string x;
	vector<pair<string, int>> playlist(n);
	for (int i = 0; i < n; i++) {
		string s;
		int t;
		cin >> s >> t;
		playlist[i] = make_pair(s, t);
	}
	cin >> x;

	int ans = 0;
	bool is_sleep = false;
	for (int i = 0; i < n; i++) {
		if (is_sleep) ans += playlist[i].second;
		if (playlist[i].first == x) is_sleep = true;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
import std.stdio : writeln, write, stdin;
import std.array;
import std.range;
import std.algorithm : max;


void main(){
	int n = next!int();
	for(int i=0; i<n; ++i){
		readln;
		
		bool[8][8] map;
		for(int y=0; y<8; ++y){
			string str = next!string();
			for(int x=0; x<8; ++x){
				map[y][x] = str[x]=='1';
			}
		}
		int X = next!int() -1;
		int Y = next!int() -1;
		
		int[2][] queue;
		queue ~= [X, Y];
		while(queue.length > 0){
			auto p = queue.front;
			queue.popFront;
			
			int x_ = p[0];
			int y_ = p[1];
			if(map[y_][x_]){
				map[y_][x_] = false;
				for(int x = x_-3; x <= x_+3; ++x){
					if(0<=x && x<8){
						if(map[y_][x]){
							queue ~= [x, y_];
						}
					}
				}
				for(int y = y_-3; y <= y_+3; ++y){
					if(0<=y && y<8){
						if(map[y][x_]){
							queue ~= [x_, y];
						}
					}
				}
			}
		}
		
		writeln("Data ", i+1, ":");
		for(int y=0; y<8; ++y){
			for(int x=0; x<8; ++x){
				write(map[y][x] ? 1 : 0);
			}
			write('\n');
		}
	}
}

import std.stdio : readln, chomp;
import std.conv : to;
import std.string : split;
shared string[] input;
shared string delim = " ";
T next(T)()
in
{
	assert(hasNext());
}
out
{
	input.popFront;
}
body
{
	return input.front.to!T;
}

void next(T)(ref T v){
	v = next!T();
}

bool hasNext(){
	if(input.length > 0){
		return true;
	}
	
	string str = readln;
	if(str.length > 0){
		input ~= str.chomp.split(delim);
		return true;
	}else{
		return false;
	}
}


void dbg(T...)(T vs)
{
	import std.stdio : stderr;
	foreach(v; vs)
		stderr.write(v.to!string ~ " ");
	stderr.write("\n");
}

T clone(T)(T v){
	T v_;
	static if(isInputRange!(T)){
		foreach(ite; v){
			v_ ~= ite.clone;
		}
	}else{
		v_ = v;
	}
	
	return v_;
}

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

int main(){
    int N;
    cin>>N;
    set<int> dic;
    vector<int> A(N);
    for(int i=0; i<N; i++) cin>>A[i];

    for(int i=0; i<N; i++){
        if(!dic.count(A[i])) dic.insert(A[i]);
    }

    int ans;

    ans = ((int)dic.size()%2==0 ? (int)dic.size()-1 : (int)dic.size());

    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 5376
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
 
const double EPS = 1e-10;
const ll INF = 100000000;
const ll MOD = 1000000007;

ll n;
ll c[3];
bool saw[301][301][301];
double dp[301][301][301];

void dfs(int a1, int a2, int a3) {
    if (saw[a1][a2][a3]) return;
    if (a3 > 0) {
        dfs(a1, a2, a3-1);
        dp[a1][a2][a3] += dp[a1][a2][a3-1]*a3;
    }
    if (a2 > 0) {
        dfs(a1, a2-1, a3+1);
        dp[a1][a2][a3] += dp[a1][a2-1][a3+1]*a2;
    }
    if (a1 > 0) {
        dfs(a1-1, a2+1, a3);
        dp[a1][a2][a3] += dp[a1-1][a2+1][a3]*a1;
    }
    dp[a1][a2][a3] += n;
    dp[a1][a2][a3] /= (a1 + a2 + a3);
    saw[a1][a2][a3] = true;
}

int main() {
    cin >> n;
    rep(i,n) {
        int a; cin >> a;
        c[a-1]++;
    }
    saw[0][0][0] = true;
    dfs(c[2], c[1], c[0]);
    printf("%.10f\n", dp[c[2]][c[1]][c[0]]);
}



Measured memory_bytes: 239872
/**
 *   @FileName	a.cpp
 *   @Author	kanpurin
 *   @Created	2020.08.16 16:53:00
**/

#include "bits/stdc++.h" 
using namespace std; 
typedef long long ll;

int n;
vector<vector<int>> g;
int dfs(int v, int p = -1) {
    vector<int> cnt(3,0);
    for(int u : g[v]) {
        if (p == u) continue;
        cnt[dfs(u,v)+1]++;
    }
    if (cnt[1] >= 2) return 1;
    if (cnt[2] >= 1) return 1;
    if (cnt[1] == 1) return -1;
    return 0;
}
int main() {
    cin >> n;
    g.resize(n);
    for (int i = 0; i < n-1; i++) {
        int a,b;cin >> a >> b;
        a--;b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    int ans = dfs(0);
    if (ans != -1) {
        puts("First");
    }
    else {
        puts("Second");
    }
    return 0;
}

Measured memory_bytes: 8796
n,m = map(int,input().split())

ll=[]
rr =[]
for i in range(m):
	l,r = map(int,input().split())
	ll.append(l)
	rr.append(r)

an = min(rr)-max(ll)+1
if an >0:
	print(an)
else:
	print(0)

Measured memory_bytes: 10996
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <algorithm>
#include <typeinfo>
#define _USE_MATH_DEFINES
#include <cmath>

using namespace std;

int main(){

    string s;
    int m;

    while(true){
        cin >> s;
        if(s=="-"){
            break;
        }
        cin >> m;
        vector<int> h(m);

        for(int i=0; i<m; i++){
            cin >> h[i];
        }

        for(int i=0; i<m; i++){
            string tmp = s.substr(0,h[i]);
            s.erase(0,h[i]);
            s += tmp;
        }

        cout << s << endl;
    }

    return 0;
}



Measured memory_bytes: 3156
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
using ll = long long;
int main(){
  ll n,a,b;
  cin>>n>>a>>b;
  ll p = n/(a+b);
  ll pa =n%(a+b);
  ll ans =0;
  if (pa<=a){
     ans = a*p+(n-p*(a+b));
  }else{
     ans = a*(p+1);
  }
  cout << ans;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	char moji[11] = { 0 };
	char kekka[11] = { 0 };
	int i;
	int j=0;

	scanf("%s", moji);

	for (i = 0;i < 10;i++)
	{
		if (moji[i] == '0')
		{
			kekka[j] = '0';
			j = j + 1;
		}
		else if (moji[i] == '1')
		{
			kekka[j] = '1';
			j = j + 1;
		}
		else if (moji[i] == 'B')
		{
			if (j != 0)
			{
				j = j - 1;
				kekka[j] = '\0';

			}
			
		}
	}
	printf("%s", kekka);

}

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

int main()
{
	int a1,b1,a2,b2,k;
	cin>>a1>>b1>>a2>>b2>>k;
	
	int a=a2-a1,b=b2-b1;
	int t=a*60+b;
	cout<<t-k<<endl;
	return 0;
}

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

int main() 
{
    int r, c;                                       //r * c行列

    cin >> r >> c;

    long long Sheet[r+1][c+1];                      //初めから合計値を格納する場所を設ける

    for( int i = 0; i <= r; i++ )                   //全て0で初期化
        for( int j = 0; j <= c; j++ )
            Sheet[i][j] = 0;

    for( int i = 0; i < r; i++ )                    //合計値を  格納する場所を除いて、入力値を保存
        for( int j = 0; j < c; j++ )                //入力ついでに合計も計算
        {
            cin >> Sheet[i][j];
            Sheet[i][c] += Sheet[i][j];             //行の合計値を格納(cは列の最後)
            Sheet[r][j] += Sheet[i][j];             //列の合計値を格納(rは行の最後)

            if( j + 1 == c )                        //jはcまで回らない(j<r)のでj+1
                Sheet[r][c] += Sheet[i][c];         //合計の合計値を格納
        }
    
    for( int i = 0; i <= r; i++ )                   //出力
    {
        for( int j = 0; j <= c; j++ )
        {
            if( j == c )                            //最後の空白を省く
                cout << Sheet[i][j];
            else
                cout << Sheet[i][j] << " ";
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3128
#include <bits/stdc++.h>
//#define int long long

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

#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e18;
const int MOD = 1e9 + 7;

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

    string s;
    cin >> s;

    string t = "";
    REP(i, s.size()){
        if(s[i] != 'x') t = t + s[i];
    }
    string revt = t;
    reverse(all(revt));
    if(revt != t){
        cout << "-1" << endl;
        return 0;
    }

    if(t.size() % 2 == 0){
        int ans = 0;
        int l = 0, r = s.size() - 1;
        REP(i, t.size() / 2){
            int cnt1 = 0, cnt2 = 0;
            while(s[l] != t[i]) cnt1++, l++;
            while(s[r] != t[i]) cnt2++, r--;
            ans += abs(cnt1 - cnt2);
            l++, r--;
        }
        cout << ans << endl;
    }else{
        int ans = 0;
        int l = 0, r = s.size() - 1;
        REP(i, t.size() / 2 + 1){
            int cnt1 = 0, cnt2 = 0;
            while(s[l] != t[i]) cnt1++, l++;
            while(s[r] != t[i]) cnt2++, r--;
            ans += abs(cnt1 - cnt2);
            l++, r--;
        }
        cout << ans << endl;
    }
}


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

int main() {
  int n;
  string s;
  cin >> n >> s;
  int result = 0;
  int i;
  for (i = 1; i < n; i++) {
    if (s.at(i) != s.at(i - 1)) {
      result++;
      i++;
    }
  }
  cout << result << endl;
  return 0;
}



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

int main(){
	int i,j,k,n,m,l,f,x,y,z; string s;
	int d, g;
	cin >> d >> g;
	vector<int> p(d), c(d);
	rep(i, d) cin >> p[i] >> c[i];

	f = 1e8;
	for(i = 0; i < 1 << d; i++){
		int score = 0;
		int count = 0;

		for(j = 0; j < d; j++){
			if(i >> j & 1){
				score += (j+1) * p[j] * 100 + c[j];
				count += p[j];
			}
		}

		for(j = d-1; j >= 0; j--){
			for(k = 0; k < p[j]; k++){
				if((~i >> j & 1) && score < g){
					score += (j+1) * 100;
					count++;
				}
			}
		}

		if(score >= g){
			f = min(f, count);
		}
	}

	cout << f << endl;
}	

Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<unordered_map>
#include<set>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<queue>
#include<stack>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef long double ld;
#define mp make_pair
#define pb push_back

#define rep(i, N) for(ll i = 0; i < N; i++)
#define repa(i, a, N) for(ll i = a; i < N; i++)
#define repr(i, N) for(ll i = N-1; i >= 0; i--)

#define drep(i, N, j, M) rep(i, N) rep(j, M)
#define trep(i, N, j, M, k, L) rep(i, N) rep(j, M) rep(k, L)

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

// const ll mod = 1e9 + 7;
const ll mod = 998244353;

const ll LLMAX = numeric_limits<long long>::max();

void No() {
	cout << "No" << endl;
}

void Yes() {
	cout << "Yes" << endl;
}

ll id(char c) {
	return c - 'a';
}

template<class t, class u>
ostream& operator<<(ostream& os, const pair<t, u>& p) {
	return os << "{" << p.first << "," << p.second << "}";
}

template<class t> ostream& operator<<(ostream& os, const vector<t>& v) {
	os << "{";
	for (auto e : v)os << e << ",";
	return os << "}";
}

int main() {
	ll A, B;
	cin >> A >> B;
	ll ans = 0;

	ans = max(ans, (A - 2 * B));

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

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

using namespace std;

int div_cnt(int temp,int cnt){
    if (temp % 2 == 1)
        return cnt;
    else{
        temp /= 2;
        cnt++;
        return div_cnt(temp, cnt);
    }
}

int main(void)
{
    int n;
    cin >> n;
    vector<int> a(n);
    int sum = 0;

    for (int i = 0; i < n; i++){
        cin >> a.at(i);
        int temp = a.at(i);
        int cnt = 0;
        sum += div_cnt(temp, cnt);
    }

    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.PrintWriter
val pw = PrintWriter(System.out)

fun main(args : Array<String>) {
    func()
    pw.flush()
}

fun func() {
    val a = next()
    val b = next()

    if (a.length > b.length) {
        println("GREATER")
        return
    }

    if (b.length > a.length) {
        println("LESS")
        return
    }

    for (i in 0 until a.length) {
        if (a[i].toInt() > b[i].toInt()) {
            println("GREATER")
            return
        }
        if (b[i].toInt() > a[i].toInt()) {
            println("LESS")
            return
        }
    }

    println("EQUAL")
}

fun next() = readLine()!!

fun println(value : Any) {
    pw.println(value)
}

Measured memory_bytes: 33564
#include <iostream>
#include<vector>
#include<unordered_map>
using namespace std;

int main() {
	// your code goes here
	int n;
	cin>>n;
	vector<int>vec(n+2,0);
	for(int i=1;i<=n;i++)
	cin>>vec[i];
	unordered_map<int,int>mp;
	for(int i=1;i<=n;i++)
	mp[i+vec[i]]++;
	long long count=0;
	for(int i=1;i<=n;i++)
	count+=mp[i-vec[i]];
	cout<<count;
	return 0;
}

Measured memory_bytes: 18200
#include<stdio.h>
#include<string.h>
int main(void)
{
	char s[3];
	int i,len,cnt;
	scanf("%s",&s);
	len=strlen(s);
	cnt=0;
	for(i=0;i<len;i++){
		if(s[i]=='1'){
				cnt++;
		}
	}
	printf("%d\n",cnt);
	return 0;
}

		

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define faster  ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define ull unsigned long long
#define pb push_back
const double PI = acos(-1.0);
using namespace std;

int main()
{
    faster

    int a,b;
    cin>>a>>b;

    a=a+b;

    if(a==3)
        cout<<3<<endl;
    else if(a==4)
        cout<<2<<endl;
    else if(a==5)
        cout<<1<<endl;




    return 0;
}


Measured memory_bytes: 256
import numpy as np
N = int(input())
A = list(map(int,input().split()))
x = np.array([0]*N)
sum_A = sum(A)
odd_A = sum(A[0::2])
x[0] = int(odd_A - sum_A/2)
for i in range(1,N):
    x[i] = A[i-1] - x[i-1]
x *= 2
print(*x)

Measured memory_bytes: 23116
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;

struct Graph {
    struct Vertex { int n, a; };
    struct Edge { int i, n; };
    Graph(int n, int m) : v(n, { -1, 0 }), e(m), n(n), m(0) {}
    void add_edge(int i, int j) {
        e[m] = { j, v[i].n };
        v[i].n = m;
        m++;
    }
    void dfs(int i, int p) {
        v[i].a = 1;
        vv++;
        for (int j = v[i].n; j >= 0; j = e[j].n) {
            Edge& o = e[j];
            ee++;
            if (v[o.i].a) continue;
            dfs(o.i, i);
        }
    }
    vector<Vertex> v;
    vector<Edge> e;
    int n, m;
    int64_t vv, ee;
};

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

    int n, m;
    cin >> n >> m;

    Graph g(n, m * 2);
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        a--; b--;

        g.add_edge(a, b);
        g.add_edge(b, a);
    }

    int64_t k;

    g.ee = g.vv = 0;
    g.dfs(0, -1);
    g.ee /= 2;
    k = n - g.vv;
    int64_t r0 = g.vv * (g.vv - 1) / 2 - g.ee + k * (k - 1) / 2 - (m - g.ee);

    g.ee = g.vv = 0;
    g.dfs(1, -1);
    g.ee /= 2;
    k = n - g.vv;
    int64_t r1 = g.vv * (g.vv - 1) / 2 - g.ee + k * (k - 1) / 2 - (m - g.ee);

    cout << max(r0, r1) << endl;

    return 0;
}

Measured memory_bytes: 3712
#include <iostream>
#include <cstring>
#define MOD 1000000007
using namespace std;

int h,w;

int main(void){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>h>>w;
	for (int i = 0; i < h; ++i){
		string arr;
		cin>>arr;
		cout<<arr<<endl<<arr<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 256