akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n, k, c;
    cin >> n >> k >> c;
    string s;
    cin >> s;
    s = "x" + s;
    map<int,int> m;
    int cnt = 0, last;
    for(int i = 1; i <= n; i++)
    {
        if(s[i]=='o')
        {
            m[i]++;
            last = i;
            cnt++;
            i = i + c;
        }
    }
    for(int i = n; i >0; i--)
    {
        if(s[i] == 'o')
        {
            last = i;
            break;
        }
    }
//    cout << "cnt = " << cnt << endl;
    if(cnt > k)
        return 0;
//    cout << "last =" << last << endl;
    for(int i = last; i >= 0; i--)
    {
        if(s[i] == 'o')
        {
            m[i]++;
            i = i -c;
        }
    }
    for(auto it = m.begin(); it != m.end(); it++)
    {
        if(it->second==2)
            cout << it->first << endl;
    }
    return 0;
}


Measured memory_bytes: 11072
n = int(input())
xyh = [list(map(int, input().split())) for _ in range(n)]

# 高度が0ではない任意の点を1つ定める
sx, sy, sh = sorted(xyh, key=lambda x: x[-1])[-1]

# 全探索
for cx in range(101):
    for cy in range(101):
        H = abs(sx - cx) + abs(sy - cy) + sh
        for x, y, h in xyh:            
            if max(H - abs(x - cx) - abs(y - cy), 0) != h:
                break
        else:
            ans = cx, cy, H
print(*ans)

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

#define REP(i, n) for(int i = 0; i < (int)(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++)

static const int MAX_N = 2000;

//int n, m, k[MAX_N];
//int kk[MAX_N * MAX_N];


int main () {
    int n, s;
    cin >> n >> s;
    
    vector<int> Zs(n + 1);

    for (int i = 0; i <= n; i++) {
        Zs[i] = 1000 * i;
    }

    for (int x = 0; x <= n; x++) {
        for(int y = 0; y <= n; y++) {
            int z = s - 10000*x - 5000*y;
            if ( x + y <= n && z == Zs[n - x - y]) {
                cout << x << " " << y << " " << n - x - y << endl;
                exit(0);
            }
        }
    }

    cout << -1 << " " << -1 << " " << -1 << endl;

    return 0;
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
int main(){
    long h,w;
    cin>>h>>w;
    vector<string> c(h);
    for(int i = 0; i<h; i++)
        cin>>c[i];
    for(int i = 0; i < 2*h; i++){
        for(int j =0; j<w; j++){
            cout<<c[i/2][j];
        }
        cout<<endl;
    }
}

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

int main(int argc, char const *argv[])
{
	int n;
	cin>>n;
	int a,ans=10000000;
	for (int i = 0; i < n; ++i)
	{
		cin>>a;
		int cnt=0;
		while (a%2==0)
		{
			++cnt;
			a/=2;
		}
		ans=min(ans,cnt);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int N;
  cin >> N;
  vector<pair<string, int>> v;
  for (int i = 0; i < N; ++i) {
    string s;
    int t;
    cin >> s >> t;
    v.push_back({s, t});
  }
  string X;
  cin >> X;
  
  bool flag = false;
  int ans = 0;
  for (auto& e : v) {
    if (e.first == X) {
      flag = true;
      continue;
    }
    if (flag) {
      ans += e.second;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
	int N, H, W;
	cin >> N >> H >> W;

	int count = 0;
	for (int i = 0; i < N; i++) {
		int a, b;
		cin >> a >> b;
		if (a >= H && b >= W) {
			count++;
		}
	}

	cout << count <<endl;
}


Measured memory_bytes: 256
// luogu-judger-enable-o2
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline int read(){
	int ans=0,f=1;char chr=getchar();
	while(!isdigit(chr)){if(chr=='-')f=-1;chr=getchar();}
	while(isdigit(chr)) {ans=(ans<<3)+(ans<<1)+chr-48;chr=getchar();}
	return ans*f;
}const int M = 2005;
int n,m,Q,s[2005][2005],v[2005][2005],sx,sy,tx,ty,ans;
int dx[]={0,1,0,-1},
	dy[]={1,0,-1,0};
char a[2005][2005];
void dfs(int x,int y){
	v[x][y]=1;
	for(int i=0;i<4;i++){
		int fx=x+dx[i],fy=y+dy[i];
		if(v[fx][fy]||fx<sx||fx>tx||fy<sy||fy>ty||a[fx][fy]=='0') continue;
		dfs(fx,fy);
	}
}
inline void BF(){
	while(Q--){
		memset(v,0,sizeof(v));ans=0;
		sx=read(),sy=read(),tx=read(),ty=read();
		for(int i=sx;i<=tx;i++)
			for(int j=sy;j<=ty;j++)
				if(!v[i][j]&&a[i][j]=='1') ans++,dfs(i,j);
		printf("%d\n",ans);
	}
}int s1[M][M],s2[M][M],s3[M][M];
inline void Solve(){
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			a[i][j]=(a[i][j]=='1');
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			s1[i][j]=a[i][j]+s1[i-1][j]+s1[i][j-1]-s1[i-1][j-1],
			s2[i][j]=(a[i][j]&&a[i+1][j])+s2[i-1][j]+s2[i][j-1]-s2[i-1][j-1],
			s3[i][j]=(a[i][j]&&a[i][j+1])+s3[i-1][j]+s3[i][j-1]-s3[i-1][j-1];
	while(Q--){
		sx=read(),sy=read(),tx=read(),ty=read();
		int V=s1[tx][ty]-s1[sx-1][ty]-s1[tx][sy-1]+s1[sx-1][sy-1];
		int E=s2[tx-1][ty]-s2[tx-1][sy-1]-s2[sx-1][ty]+s2[sx-1][sy-1]
			 +s3[tx][ty-1]-s3[sx-1][ty-1]-s3[tx][sy-1]+s3[sx-1][sy-1];
//		cout<<V<<" "<<E<<endl;
		printf("%d\n",V-E);
	}
	
}
int main(){
//	freopen("wang.in","r",stdin);
//	freopen("wang.out","w",stdout);
	n=read(),m=read(),Q=read();
	for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)cin>>a[i][j];
//	BF();
	Solve();
	return 0;
}


Measured memory_bytes: 52992
#include <bits/stdc++.h> 
using namespace std; 
  
int main() 
{ 
int N;
string msg = "YES";
scanf("%d",&N);
int A[N];
for(int i = 0; i< N ; i++){
  scanf("%d",&A[i]);
}
sort(A,A+N);

for(int j = 0;j<N;j++){
  if(A[j]==A[j+1]){
    msg = "NO";
    continue;
  }
}
printf(msg.c_str());
  
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char[] a = sc.nextLine().toCharArray();
        char[] b = sc.nextLine().toCharArray();
        char[] c = sc.nextLine().toCharArray();
        sc.close();

        String out = "" + a[0] + b[1] + c[2];
        System.out.println(out);
    }
}


Measured memory_bytes: 23764
#include <cmath>

#include <iostream>
#include <algorithm>

#define SIZE 100000
#define INF  1000000010

typedef long long ll;

ll N, A, B;
ll h[SIZE];

bool enough(ll T) {
    ll other = B*T;
    ll magic = 0;
    for (int i=0; i<N; ++i) {
        if (h[i] > other) {
            magic += (h[i] - other) / (A - B);
            if ( (h[i] - other) % (A - B) ) ++magic;
        }
    }
    return magic <= T;
}

int main() {
    std::cin >> N >> A >> B;
    for (int i=0; i<N; ++i) std::cin >> h[i];
    ll ub = INF, lb = 0;
    while (ub - lb > 1) {
        ll mid = (ub + lb) / 2;
        if (enough(mid)) {
            ub = mid;
        } else {
            lb = mid;
        }
    }
    std::cout << ub << std::endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main() {
  string S, T;
  cin >> S >> T;
  int U = 0;
  for (int i = 0; i < 3; i++) {
    if (S.at(i) == T.at(i)) {U++;}
  }
  cout << U << endl;
}

Measured memory_bytes: 3604
import java.util.*;

public class Main {


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

        int n = sc.nextInt();
        int m = sc.nextInt();

        long array[] = new long[m];

        for (int i = 0; i < m; i++) {
            array[i] = sc.nextLong();
        }

        int sum = 0;

        for (int i = 0; i < m; i++) {
            sum += array[i];
        }

        if(n - sum < 0) {
            System.out.println("-1");
        } else {
            System.out.println(n - sum);
        }

        sc.close();
    }

}

Measured memory_bytes: 46572
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  	int n;
  	cin>>n;
	map<int,int>res;
  	int a=0,b=0,c=0,d=0,e=0;
  	for(int j=2; j<=n; j++){
      int m=j;
		for(int i=2; i*i<=m; i++){
			while(m%i==0){
				res[i]++;
				m/=i;
			}
		}	
		if(m!=1)res[m]++;
    }
  for(int i=2; i<=n; i++){
    if(res[i]>=74){
      a++;
    }
    if(res[i]>=24){
      b++;
    }
    if(res[i]>=14){
      c++;
    }
    if(res[i]>=4){
      d++;
    }
    if(res[i]>=2){
      e++;
    }
  }
  int ans=a+b*(e-1)+c*(d-1)+d*(d-1)*(e-2)/2;
  cout<<ans<<endl;
}


Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;
use std::cmp::min;

const INF: i64 = 1_i64 << 60;

fn func10(arg: &mut i64) {
    if *arg % 10 != 0 {
        *arg += 10 - *arg % 10
    }
}

fn main() {
    let mut vec: [i64; 5] = [0; 5];
    for i in 0..5 {
        vec[i] = read();
    }

    let mut ans = INF;
    for i in 0..5 {
        for j in 0..5 {
            if i == j {
                continue;
            }
            for k in 0..5 {
                if k == i || k == j {
                    continue;
                }
                for l in 0..5 {
                    if l == i || l == j || l == k {
                        continue;
                    }
                    for m in 0..5 {
                        if m == i || m == j || m == k || m == l {
                            continue;
                        }
                        let mut res = vec[i];
                        func10(&mut res);
                        res += vec[j];
                        func10(&mut res);
                        res += vec[k];
                        func10(&mut res);
                        res += vec[l];
                        func10(&mut res);
                        res += vec[m];
                        ans = min(ans, res);
                    }
                }
            }
        }
    }

    println!("{}", ans);
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;++A)
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////
ll N;
set<string> st;

ll i, j, k;
int main(){
    scanf("%lld", &N);
    fornum(i,0,N){
        string s;
        cin >> s;
        st.insert(s);
    }
    printf("%d\n", st.size());

    return 0;
}

Measured memory_bytes: 19384
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
#define REP(i,n) for (lint i = 0; i < (n); i++)
#define REP1(i,n) for (lint i = 1; i < (n); i++)

int N, M;

int main(void){
    cin >> N >> M;
    (N == M) ? cout << "Yes" << endl : cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	C
# CreatedDate:  2020-09-04 15:20:21 +0900
# LastModified: 2020-09-04 15:31:03 +0900
#


import os
import sys
# import numpy as np
# import pandas as pd
from collections import Counter


def main():
    _ = int(input())
    a = list(map(int, input().split()))
    a_cnt = [[key, val] for key, val in Counter(a).items() if val >= 2]
    if len(a_cnt) == 0:
        print(0)
        return
    a_cnt.sort(key=lambda x: x[0], reverse=True)
    if a_cnt[0][1] >= 4:
        print(a_cnt[0][0]**2)
    elif len(a_cnt) == 1:
        print(0)
    else:
        print(a_cnt[0][0]*a_cnt[1][0])


if __name__ == "__main__":
    main()


Measured memory_bytes: 22252
#include<bits/stdc++.h>
 
#define ll long long int
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define INF 0x3f3f3f3f
#define show(x) cerr<<#x<<" : "<<x<<'\n';
#define yogeshk972() cerr<<"\nTime Taken : "<<(float)(clock()-time_p)/CLOCKS_PER_SEC<<"\n";
clock_t time_p=clock();

using namespace std;
const int N=1e6+1, mod= 1e9+7;

pair<int,int> merge(pair<int,int> a,pair<int,int> b){
	if( a.xx> b.xx ) swap(a,b);
	if( a.yy==-1||b.yy==-1 || b.xx > a.yy ){
		return {0,-1};
	}
	return { b.xx, min(a.yy,b.yy) };
}

signed main(){
	ios_base::sync_with_stdio(0);	cin.tie(0);
	
	int n;
	cin>>n;
	
	set<pair<int,int>> st;
	set<int> st2;
	vector<pair<int,int>> v,p(n);
	
	for(int i=0;i<n;i++){
		int x,y;
		cin>>x>>y;
		p[i]={x,y};
	}
	
	sort(p.begin(),p.end());
	vector<pair<int,int>> l(n),r(n);
	l[0]=p[0]; r[n-1]=p[n-1];
	
	for(int i=1;i<n;i++){
		l[i]=merge(l[i-1],p[i]);
	}
	
	for(int i=n-2;i>=0;i--){
		r[i]=merge(p[i],r[i+1]);
	}

	int res=0;
	for(int i=0;i<n-1;i++){
		res=max(res, (l[i].yy-l[i].xx +1 )+ (r[i+1].yy-r[i+1].xx+1 ) );
		if(i){
			pair<int,int> pp=merge(l[i-1],r[i+1]);
			res=max(res, (pp.yy-pp.xx+1) + (p[i].yy-p[i].xx+1) );
		}
	}
	cout<<res;
	
    yogeshk972();
}


Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include <set>
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
int n, m, q;
int a[51], b[51], c[51], d[51];
int v[11];
 
int main() {
    int N;
    cin >> N;
    int* nums = new int[N];
    rep(i, 0, N){
        cin >> nums[i];
    }
    long long min = 2000001;
    rep(i, -100, 101){
        long long cost = 0;
        rep(j, 0, N){
            cost += (nums[j] - i) * (nums[j] - i);
        }
        if (min > cost){
            min = cost;
        }
    }
    cout << min << endl;
    return 0;
}


Measured memory_bytes: 256
n, k = map(int, input().split())
a = list(map(int, input().split()))

ans = n - k + 1
i1 = -1
for i in range(n):
    if a[i] == 1:
        i1 = i
        break
for i in range(max(i1 - k + 1, 0), i1 + 1):
    ans = min(ans, (i + k - 2) // (k - 1) + (n - i - 2) // (k - 1) + 1)

print(ans)

Measured memory_bytes: 52604
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace Tasks
{
    public class C
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var N = Scanner.Scan<int>();
            var A = Scanner.ScanEnumerable<int>().ToArray();
            var distinct = A.Distinct().Count();
            Console.WriteLine(N == distinct ? "YES" : "NO");
        }

        public static class Scanner
        {
            private static Queue<string> queue = new Queue<string>();
            public static T Next<T>()
            {
                if (!queue.Any()) foreach (var item in Console.ReadLine().Trim().Split(" ")) queue.Enqueue(item);
                return (T)Convert.ChangeType(queue.Dequeue(), typeof(T));
            }
            public static T Scan<T>() => Next<T>();
            public static (T1, T2) Scan<T1, T2>() => (Next<T1>(), Next<T2>());
            public static (T1, T2, T3) Scan<T1, T2, T3>() => (Next<T1>(), Next<T2>(), Next<T3>());
            public static (T1, T2, T3, T4) Scan<T1, T2, T3, T4>() => (Next<T1>(), Next<T2>(), Next<T3>(), Next<T4>());
            public static (T1, T2, T3, T4, T5) Scan<T1, T2, T3, T4, T5>() => (Next<T1>(), Next<T2>(), Next<T3>(), Next<T4>(), Next<T5>());
            public static IEnumerable<T> ScanEnumerable<T>() => Console.ReadLine().Trim().Split(" ").Select(x => (T)Convert.ChangeType(x, typeof(T)));
        }
    }
}


Measured memory_bytes: 56820
#pragma GCC optimize "-O3"
#pragma GCC target ("avx")
#define _USE_MATH_DEFINES
#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf (1ll<<60)
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v),greater<int>())
signed gcd(int a, int b){return b?gcd(b,a%b):a;}
signed lcm(int a, int b){return a*b/gcd(a,b);}

using namespace std;

const int mod=1e9+7;

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
    int a,b,c;
    cin >> a >> b >> c;
    cout << min(b/a,c) << endl;
}


Measured memory_bytes: 256
a,b,c=map(int,input().split())
if a<b<c:
	print(a+b)
elif a<c<b:
	print(a+c)
elif b<a<c:
	print(b+a)
elif b<c<a:
	print(b+c)
elif c<a<b:
	print(c+a)
else:
	print(c+b)

Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define nl "\n"
#define pb push_back
#define sp " "
typedef long long ll;

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    long long mn=1e18+3;
    long long n  , k;
    
    cin >> n >>k;
    
    long long  das=n/k;
    n=n-(das*k);
    mn=min(mn,n);
    while(true){
        n=abs(n-k);
        if(n<mn)mn=n;
        else break;
    }
    cout<<mn<<nl;
}


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

#define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) do{}while(0)
#endif






ll l, n, n1;
vector<ll> x;

int main(){
	cin >> l >> n;
	n1 = n+1;
	
	x.resize(n1*2+1);
	rep(i,n){
		cin >> x[i+1];
		x[i+1+n1] = x[i+1] + l;
	}
	x[0] = 0;
	x[n1] = l;
	x[n1*2] = l*2;
	
	// 片方に何歩か歩いてから振動するように歩く
	
	/* 
	  1  3  5  7  9 10  8  6  4  2
	.  .  .  .  .  *  .  .  .  .  .
	*/
	ll summax = 0;
	for ( int rep = 0; rep <= 1; rep++ ){
		if ( rep == 1 ){
			// 左右を逆転して調べる
			reverse(x.begin(),x.end());
			for ( auto &e : x )
				e = 2*l - e;
		}
		
		
		int x0 = n1;
		int l = x0;
		int r = x0;
		
		ll lsum = 0;
		ll rsum = 0;
		for ( int i = 0; i < n; i++ ){
			if ( i%2 == 0 ){
				r++;
			}
			else {
				l--;
			}
			lsum += x[x0]-x[l];
			rsum += x[r]-x[x0];
		}
		
		bool r_even = (n%2==0); // rsumが偶数
		
		for ( int i = 0; ; i++ ){
			ll msum = (x[x0+i]-x[x0]) * (n-i);
			eprintf( "%d : %lld, r=%lld m=%lld l=%lld\n", i, rsum+msum+lsum, rsum, msum, lsum );
			chmax( summax, lsum+msum+rsum );
			if ( i == n-1 )
				break;
			
			lsum -= x[x0]-x[l];
			
			if ( r_even ){
				r++;
				l++;
			}
			r_even = !r_even;
			
			rsum -= (x[x0+i+1]-x[x0+i]) * (n-i);
			rsum += x[r]-x[x0+i+1];
		}
	}
	
	cout << summax << endl;
	
	
	return 0;
}




Measured memory_bytes: 6416
import java.util.*;

public class Main {
    private static final int MOD = (int) (1e9+7);

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int rows = scanner.nextInt();
        int columns = scanner.nextInt();
        char[][] grid = new char[rows][columns];
        for(int i = 0; i< rows; ++i){
            grid[i] =scanner.next().toCharArray();
        }
        int[][] dp = new int[rows][columns];
        dp[0][0] = 1;
        for(int i = 0; i< rows; ++i){
            for(int j = 0; j< columns; ++j){
                if(i>0) dp[i][j] += dp[i-1][j];
                if(j>0) dp[i][j] += dp[i][j-1];
                if(grid[i][j]=='#') dp[i][j]=0;
                dp[i][j]%=MOD;
            }
        }
        System.out.println(dp[rows -1][columns -1]);
    }
}


Measured memory_bytes: 49488
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#include <queue>
#include <climits>
#include <utility>
typedef long long ll;
using namespace std;

int main(void){
  int n, i, j;
  int head, tail;
  string s;
  cin >> n;

  int cnt[10][10] = {};

  for(i=1;i<=n;i++){
    s = to_string(i);
    head = s[0] - '0';
    tail = s[s.size()-1] - '0';

    cnt[head][tail]++;
  }

  int ans = 0;
  for(i=1;i<=9;i++){
    for(j=1;j<=9;j++){
      ans += cnt[i][j] * cnt[j][i];
    }
  }

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define two(a) (1<<(a))
#define LINF (1ll<<61)
#define EPS (1e-14)
#define Lshift(a,b) ((a)<<(b))
#define Rshift(a,b) ((a)>>(b))
#define rep(a,b) for(a=0 ; a<b ; a++)
#define xrep(a,b,c) for(a=b ; a<c ; a++)
#define INF (1<<29)
#define sz(a) int(a.size())
#define mset(x) memset(x, 0, sizeof(x))
#define swap(a,b) ( (a^=b) , (b^=a) , (a^=b) )
#define GET(x) (mark[x>>5]>>(x&31)&1)
#define SET(x) (mark[x>>5]|=1<<(x&31))
#define maxL (10000000>>5)+1
#define mod 1000000007
#define vi vector<int>
#define pii pair<int, int>
#define mii map<int, int>
#define si set<int>
#define pb push_back
typedef long long ll;
using namespace std;


int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    vector<ll> pos;
    vector<ll> neg;
    int n, k;
    cin >> n >> k;
    int i;
    rep(i, n) {
        int in;
        cin >> in;
        if (in < 0) { neg.pb(in); }
        else { pos.pb(in); }
    }
    sort(neg.begin(), neg.end());
    reverse(neg.begin(), neg.end());
    sort(pos.begin(), pos.end());
    ll ans(1);
    if (k % 2 == 1 && sz(pos) == 0) {
        rep(i, k) { ans = ans * neg[i] % mod; }
    } else {
        reverse(pos.begin(), pos.end());
        reverse(neg.begin(), neg.end());
        int pidx(0);
        int nidx(0);
        while(k) {
            if (pidx + 2 <= sz(pos) && nidx + 2 <= sz(neg) && k >= 2) {
                long long pp = pos[pidx] * pos[pidx+1];
                long long nn = neg[nidx] * neg[nidx+1];
                if (nn > pp) {
                    nn %= mod;
                    ans = ans * nn % mod;
                    nidx += 2;
                    k -= 2;
                } else {
                    ans = ans * pos[pidx] % mod;
                    pidx++;
                    k--;
                }
            } else if (k >= 2 && nidx + 2 <= sz(neg)) {
                long long nn = neg[nidx] * neg[nidx+1];
                nn %= mod;
                ans = ans * nn % mod;
                nidx += 2;
                k -= 2;
            } else if (pidx < sz(pos)) {
                ans = ans * pos[pidx++] % mod;
                k--;
            } else {
                ans = ans * neg[nidx++] % mod;
                k--;
            }
        }
    }
    if (ans < 0) ans += mod;
    cout << ans % mod << endl;
}


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

typedef long long ll;
const int mod = 1e9 + 7;

int main() {
	int n, m; cin >> n >> m;
	vector<ll>x(n), y(m); for (auto&& xx : x)cin >> xx; for (auto&& yy : y)cin >> yy;
	sort(x.begin(), x.end()); sort(y.begin(), y.end());

	ll a = 0, b = 0;
	for (ll i = 0; i < n; i++)a -= x[i] * (n - 1 - i - i);
	for (ll i = 0; i < m; i++)b -= y[i] * (m - 1 - i - i);
	cout << (a % mod) * (b % mod) % mod << endl;

	return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>

int main() {
        int N, M, A, sum = 0;
        int i;
        scanf("%d %d", &N, &M);

        for(i = 0; i < M; i++) {
                scanf("%d", &A);
                sum += A;
        }

        printf("%d\n", N - sum >= 0 ? N - sum : -1);

        return 0;
}


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

#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

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

    constexpr auto M = 998244353L;

    int64_t n = s.size();

    vector<int64_t> dp(2 * n);
    dp[0] = 1;

    for (auto a :
         s | transformed([](char c) { return c - '0'; }) | indexed(0)) {
        auto i = a.index();
        auto b = a.value();

        vector<int64_t> next(dp.size());
        for (auto j : irange(0L, 2 * n)) {
            int64_t remain = i + 2;
            int64_t blue = j + b;
            int64_t red = remain - blue;

            if (blue == 0) {
                next[0] += dp[j];
            } else if (red == 0) {
                next[blue - 1] += dp[j];
            } else {
                next[blue] += dp[j];
                next[blue - 1] += dp[j];
            }

            next[blue] %= M;
            next[blue - 1] %= M;
        }

        dp = std::move(next);
    }

    for (auto i : irange(0L, n)) {
        vector<int64_t> next(dp.size());
        for (auto j : irange(0L, 2 * n)) {
            int64_t remain = n - i;
            int64_t blue = j;
            int64_t red = remain - blue;

            if (blue == 0) {
                next[0] += dp[j];
            } else if (red == 0) {
                next[blue - 1] += dp[j];
            } else {
                next[blue] += dp[j];
                next[blue - 1] += dp[j];
            }

            next[blue] %= M;
            next[blue - 1] %= M;
        }

        dp = std::move(next);
    }

    std::cout << dp[0] << std::endl;
}

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

int main()
{
    int n, k;
    cin >> n >> k;
    vector<int> P(n);
    rep(i, n) cin >> P[i];
    sort(P.begin(), P.end());
    ll ans = 0;
    rep(i, k) ans += P[i];

    cout << ans << endl;
}

Measured memory_bytes: 3568
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,f,e) for(int (i)=(f); (i)<(e); (i)++)
#define repr(i,e,f) for(int (i)=(e-1); (i)>=(f); (i)--)

const ll MOD = 1e9+7;
const int INF = (int)1e9+7;

// vector<tuple<long,long>> items; // (value, weight)
// auto item = items[i];
// long v = get<0>(item);
// long w = get<1>(item);
// long v, w;
//   for( int i = 0; i < N; i++ ){
//     cin >> v >> w;
//     items.push_back( make_tuple(v, w) ); // item : (value, weight)
//   }

deque<int> G[2010];
int K[2010];

int main(){
    int N,X,Y;
    cin >> N >> X >> Y;

    rep(i,1,N){
        G[i].push_back(i+1);
        G[i+1].push_back(i);
    }
    G[X].push_back(Y);
    G[Y].push_back(X);
    
    // rep(i,1,N+1){
    //     cout << i << " : ";
    //     for(auto j : G[i]){
    //         cout << j << " ";
    //     }
    //     cout << endl;
    // }

    rep(i,1,N+1){
        vector<int> dist(N+1,-1);
        queue<int> que;

        dist[i] = 0;
        for(int j=i-1; j=0; j--){
            dist[j] = INF;
        }
        que.push(i);

        while (!que.empty()) {
            int v = que.front(); // キューから先頭頂点を取り出す
            que.pop();

            // v から辿れる頂点をすべて調べる
            for (int nv : G[v]) {
                if (dist[nv] != -1) continue; // すでに発見済みの頂点は探索しない
                // 新たな白色頂点 nv について距離情報を更新してキューに追加する
                dist[nv] = dist[v] + 1;
                que.push(nv);
            }
        }

        rep(v,i,N+1){
            K[dist[v]] += 1;
        }
    }

    rep(k,1,N){
        cout << K[k] << endl;
    }
    

    return 0;
}

Measured memory_bytes: 1664
def A():
    xyz=list(map(int,input().split()))
    xyz[0],xyz[1]=xyz[1],xyz[0]
    xyz[0],xyz[2]=xyz[2],xyz[0]
    
    print(str(xyz[0])+" "+str(xyz[1])+" "+str(xyz[2]))

    
if __name__=='__main__':
    A()


Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
const int N=105;
char a[N],b[N];
int main (){
	int n;scanf ("%d",&n);
	scanf ("%s",a+1);
	scanf ("%s",b+1);
	for (int l=n;l>=1;l--){
		bool flag=true;
		for (int i=n-l+1,j=1;j<=l;i++,j++){
			if (a[i]!=b[j]) {flag=false;break;}
		}
		if (flag){printf ("%d",n+n-l);return 0;}
	}
	printf ("%d",n+n);
	return 0;
}

Measured memory_bytes: 256
/*
title:

url:
*/

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <functional>
#include <queue>
#include <limits>
#include <string>
#include <utility>
#include <cstring>
#include <map>
#include <cmath>
#include <iterator>

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define INF 1000000007

typedef pair<int, int> pint;
typedef long long ll;

int main()
{
    int N;
    cin >> N;
    bool is_same[N];
    fill(is_same, is_same + N, false);
    rep(i, N)
    {
        int tmp;
        cin >> tmp;
        tmp--;
        if (i == tmp)
        {
            is_same[i] = true;
        }
    }

    int ans = 0;
    rep(i, N)
    {
        if (is_same[i])
        {
            ans++;
            if (i + 1 < N && is_same[i + 1])
            {
                is_same[i + 1] = false;
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 384
n = int(input())
lt = 0
lx = 0
ly = 0
for i in range(n):
    t, x, y = [int(i) for i in input().split()]
    dt = abs(lt-t)
    dx = abs(lx-x)
    dy = abs(ly-y)
    if not(dt >= dx + dy and dt % 2 == (dx + dy) % 2):
        print("No")
        exit()
    lt = t
    lx = x
    ly = y
print("Yes")

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

struct Card{
  char suit;
  int value;
};

int main(void){
    int N;
    char input[3];
    struct Card *deck, *deck2, forSwap;
    int i, j;
    char order[9][4];
    int count[9] = {0};
    int tmp;
    bool stable = true;
    int mini;
    
    cin >> N;
    deck = new struct Card[N];
    deck2 = new struct Card[N];
    
    for(i = 0; i < N; i++){
        cin >> input;
        deck[i].suit = deck2[i].suit = input[0];
        deck[i].value = deck2[i].value = input[1] - '0';
        tmp = deck[i].value - 1;
        order[tmp][count[tmp]] = deck[i].suit;
        count[tmp]++;
        
//        cout << deck[i].suit << deck[i].value << " ";
    }
    
    for(i = 0; i < N; i++){
        for(j = N - 1; i < j; j--){
            if(deck[j].value < deck[j - 1].value){
                forSwap = deck[j];
                deck[j] = deck[j -1];
                deck[j -1] = forSwap;
            }
        }
    }
    
    j = 0;
    for(i = 0; i < N; i++){
        if(i) cout << " ";
        cout << deck[i].suit << deck[i].value;
        tmp = deck[i].value - 1;
        if(1 < count[tmp]){
            if(order[tmp][j] != deck[i].suit) stable = false;
//            cout << order[tmp][j] << deck[i].suit << j;
//            cout << deck[i].value << " ";
            j++;
            if(j == count[tmp]) j = 0;
        }
    }
    cout << endl;
    if(stable) cout << "Stable";
    else cout << "Not stable";
    cout << endl;
    
    for(i = 0; i < N; i++){
        mini = i;
        for(j = i; j < N; j++){
            if(deck2[j].value < deck2[mini].value) mini = j;
        }
        
        forSwap = deck2[mini];
        deck2[mini] = deck2[i];
        deck2[i] = forSwap;
    }
    
    j = 0;
    stable = true;
    for(i = 0; i < N; i++){
        if(i) cout << " ";
        cout << deck2[i].suit << deck2[i].value;
        tmp = deck2[i].value - 1;
        if(1 < count[tmp]){
            if(order[tmp][j] != deck2[i].suit) stable = false;
//            cout << deck2[i].value << " ";
            j++;
            if(j == count[tmp]) j = 0;
        }
    }
    cout << endl;
    if(stable) cout << "Stable";
    else cout << "Not stable";
    cout << endl;
    
    delete [] deck;
    deck = 0;
    delete [] deck2;
    deck2 = 0;
    return 0;
}

Measured memory_bytes: 3068
from math import *

n = int(input())
a = [int(input()) for _ in range(5)]

ans = ceil(n / a[0])
min = 0
for i in range(1, 5):
  if a[i] >= a[min]:
    ans += 1
  else:
    ans = ceil(n / a[i]) + i
    min = i

print(ans)

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

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
            var A = input[0];
            var B = input[1];

            Console.WriteLine(A * B - (A + B - 1));
        }
    }
}

Measured memory_bytes: 13396
#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>
#define rep(i,n) for (long long i=0; i < (n); ++i)
#define rep2(i,n,m) for(long long i=n;i<=m;i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
const ll INF=1e18 ;
inline void chmax(ll& a,ll b){a=max(a,b);}
inline void chmin(ll& a,ll b){a=min(a,b);}
int main(){
  int n,a,b;
  cin>> n>> a>>b ;
  
  if(abs(a-b)%2==1)
  cout <<"Borys"<<endl ;
  
  else
   cout<<"Alice"<<endl; 
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;


public class Main {
	public static void main(String[] args){

		Scanner sc = new Scanner(System.in);

        int N = Integer.parseInt(sc.next());	//N人
        int[] xs = new int[N];
        for(int i = 0; i < N; i++) {

        	xs[i] = Integer.parseInt(sc.next());
        }
        quick_sort(xs, 0, xs.length-1);

        int sum = 0;
        int current = 0;
        boolean flg = true;
        for(int i = xs[0]; i <= xs[N-1]; i++) {
        	for(int j = 0; j < N; j++) {
        		int pos = (xs[j]-i) * (xs[j]-i);
        		current += pos;
        	}
        	if (current < sum || flg) {
        		sum = current;
        		flg = false;
        	}
        	current = 0;
        }
        System.out.println(sum);
	}


	static void quick_sort(int[] d, int left, int right) {
        if (left>=right) {
            return;
        }
        int p = d[(left+right)/2];
        int l = left, r = right, tmp;
        while(l<=r) {
            while(d[l] < p) { l++; }
            while(d[r] > p) { r--; }
            if (l<=r) {
                tmp = d[l]; d[l] = d[r]; d[r] = tmp;
                l++; r--;
            }
        }
        quick_sort(d, left, r);  // ピボットより左側をクイックソート
        quick_sort(d, l, right); // ピボットより右側をクイックソート
    }
}

Measured memory_bytes: 21076
#include <stdio.h>
#include <iostream>
#include <set>
using namespace std;
int main(){
    int k;
    string c,temp;
    set<string> s;
    set<string>::iterator u;
    cin>>c>>k;
    for(int i=0;i<c.size();i++){
        temp.clear();
        for(int j=i;j<i+k&&j<c.size();j++){
            temp+=c[j];
            s.insert(temp);
        }
    }
    u=s.begin();
    k--;
    for(int i=0;i<k;i++)u++;
    cout<<*u<<endl;
}

Measured memory_bytes: 1664
#include <iostream>
using namespace std;
 
int main() {
    int y=700;
    string S;
    
    cin >> S;
    
    if(S[0]=='o') y += 100;
    if(S[1]=='o') y += 100;
    if(S[2]=='o') y += 100;
    
    cout << y << endl;
    return 0;
}

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

int main()
{
    int A, B, C, X;
    cin >> A >> B >> C >> X;
    int res = 0;
    for(int a = 0; a <= A; a++)
    {
        for(int b = 0; b <= B; b++)
        {
            for(int c = 0; c <= C; c++)
            {
                int total = 500*a + 100*b + 50*c;
                if(total == X)
                {
                    res++;
                } 
            }
        }
    }

    cout << res << endl;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define ss second
#define ff first
#define mp make_pair
using namespace std;

int main() {
   ll n,i,cnt=0,x,y;
   cin>>n;
   ll a[n];
   for(i=0;i<n;i++){
       cin>>a[i];
   }
   sort(a,a+n);
   x=a[(n/2)-1];
   y=a[n/2];
   if(y-x>=0){
       cout<<y-x;
   }
   else{
       cout<<0;
   }
    
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif

// $ cp-batch RedScarf | diff RedScarf.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address RedScarf.cpp && ./a.out

/*

 6/21/2020

 5:21-

 */

const int MAX_N=1e6+1;
int A[MAX_N];
int N;

void solve() {
  int xorb=0;
  REP(i,N) xorb^=A[i];
  REP(i,N) cout<<(xorb^A[i])<<" ";
  cout<<endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout<<setprecision(12)<<fixed;

  cin>>N;
  REP(i,N) cin>>A[i];
  solve();

  return 0;
}


Measured memory_bytes: 4396
fn main(){
  let mut buf = String::new();
  std::io::stdin().read_line(&mut buf).expect("failed to read");
  let x: u32 = buf.trim().parse().unwrap();

  let mut i: u32 = 1;

  loop {
    if 360 * i % x == 0 {
      println!("{}", 360 * i / x);
      break;
    } else {
      i += 1;
    }
  }            
}


Measured memory_bytes: 2080
package main

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

const (
	initialBufSize = 1e4
	maxBufSize     = 1e6 + 7
)

var buf []byte = make([]byte, maxBufSize)
var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(buf, maxBufSize)
}

func main() {
	S := nextLine()
	var ans int
	an := make([]int, len(S)+1)
	for i := 0; i < len(S); i++ {
		if S[i] == '<' {
			an[i+1] = an[i] + 1
		}

	}
	for i := 0; i < len(S); i++ {
		if S[len(S)-i-1] == '>' && an[len(S)-i] >= an[len(S)-i-1] {
			an[len(S)-1-i] = an[len(S)-i] + 1
		}
	}
	for _, v := range an {
		ans += v
	}
	fmt.Println(ans)
}

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

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func abs(a int) int {
	if a > 0 {
		return a
	} else {
		return -a
	}
}

func pow(p, q int) int {
	res := p
	if q == 0 {
		return 1
	}
	for i := 0; i < q-1; i++ {
		res *= p
	}
	return res
}

func MinOf(vars ...int) int {
	min := vars[0]
	for _, i := range vars {
		if min > i {
			min = i
		}
	}
	return min
}

func MaxOf(vars ...int) int {
	max := vars[0]
	for _, i := range vars {
		if max < i {
			max = i
		}
	}
	return max
}

func gcdof2numbers(a int, b int) int {
	if b == 0 {
		return a
	}
	return gcdof2numbers(b, a%b)
}

func lcmof2numbers(a int, b int) int {
	return a / gcdof2numbers(a, b) * b
}

// マイナスの場合は考慮していない
func fuctorial(a int) int {
	if a == 1 || a == 0 {
		return 1
	} else {
		return fuctorial(a-1) * a
	}
}

func NextPermutation(x sort.Interface) bool {
	n := x.Len() - 1
	if n < 1 {
		return false
	}
	j := n - 1
	for ; !x.Less(j, j+1); j-- {
		if j == 0 {
			return false
		}
	}
	l := n
	for !x.Less(j, l) {
		l--
	}
	x.Swap(j, l)
	for k, l := j+1, n; k < l; {
		x.Swap(k, l)
		k++
		l--
	}
	return true
}

// 素因数分解したmapを返す
func primeFuctorize(n int) map[int]int {
	pf := map[int]int{}
	for i := 2; i*i <= n; i++ {
		for n%i == 0 {
			pf[i]++
			n /= i
		}
	}
	if n != 1 {
		pf[n]++
	}
	return pf
}


Measured memory_bytes: 6944
#include <stdio.h>

int main(void)
{
	int i;
	char str[1000];

	while (1) {
		int ans = 0;
		scanf("%s", str, 1000);
		if (str[0] == '0') {
			break;
		}
		for (i = 0; str[i] != '\0'; i++) {
			int num = str[i] - '0';
			ans += num;
		}
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 536
/*#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <array>
#include <vector>
#include <deque>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <unordered_map>
#include <unordered_set>
*/

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

// #define int long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define FOR(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define SORT(c) sort((c).begin(),(c).end())

typedef long long ll;
const ll INF = LLONG_MAX - 100;
const ll mod = 2e9 + 7;
const int MAX_N = 5e5 + 5;
int dx[] = { -1LL,0,1LL,0 }, dy[] = { 0,1LL,0,-1LL };
vector<ll> prime;

ll inv[MAX_N], fac[MAX_N];

template <class T = ll> T in() { T x; cin >> x; return (x); }
inline ll GCD(ll a, ll b) { ll c; while (b != 0) { c = a % b; a = b; b = c; }return a; }
inline ll LCM(ll a, ll b) { return a * b / GCD(a, b); }
inline ll POW(ll a, ll b) { ll c = 1LL; while (b > 0) { if (b & 1LL) { c = a * c%mod; }a = a * a%mod; b >>= 1LL; }return c; }
inline void _nCr() { fac[0] = 1LL; for (int i = 1LL; i < MAX_N; i++) { fac[i] = fac[i - 1LL] * i%mod; }for (int i = 0; i < MAX_N; i++) { inv[i] = POW(fac[i], mod - 2); } }
inline ll nCr(ll n, ll r) { return (fac[n] * inv[r] % mod)*inv[n - r] % mod; }
inline void PRI(ll n) { bool a[n + 1LL]; for (int i = 0; i < n + 1LL; i++) { a[i] = 1LL; }for (int i = 2; i < n + 1LL; i++) { if (a[i]) { prime.pb(i); ll b = i; while (b <= n) { a[b] = 0; b += i; } } } }

typedef pair<int, pair<int, int>> edge;

class UnionFind {
private:
	vector<int> par;
public:
	UnionFind(int N) { par = vector<int>(N, -1LL); }
	int find(int x);
	ll size(int x);
	void unite(int x, int y);
	bool same(int x, int y);
};



class Kruskal {
private:
	UnionFind *uf;
	vector<edge> e;
public:
	vector<edge> mst;
	Kruskal(int N) { uf = new UnionFind(N); }
	void add(int x, int y, ll z);
	void run();
};



//----UnionFind-------------------------------
int UnionFind::find(int x) {
	if (par[x] < 0) return x;
	else return par[x] = find(par[x]);
}

ll UnionFind::size(int x) {
	return -par[find(x)];
}

void UnionFind::unite(int x, int y) {
	x = find(x);
	y = find(y);

	//大きい方に小さい方をくっ付ける
	if (size(x) < size(y)) swap(x, y);
	par[x] += par[y];
	par[y] = x;
}

bool UnionFind::same(int x, int y) {
	x = find(x);
	y = find(y);
	return x == y;
}



//----Kruskal-------------------------------
void Kruskal::add(int x, int y, ll z) {
	//x < y
	if (x > y) swap(x, y);
	e.push_back({ z,{x,y} });
}

void Kruskal::run() {
	sort(e.begin(), e.end());
	e.erase(unique(e.begin(), e.end()), e.end());
	for (auto x : e) {
		if (uf->same(x.second.first, x.second.second)) {
			continue;
		}
		else {
			mst.push_back(x);
			uf->unite(x.second.first, x.second.second);
		}
	}
}

signed main() {
	ll n;cin >> n;
	ll a[n],b[n];
	REP (i,n) cin >> a[i] >> b[i];
	ll sum = 0;
	for (int i = n-1;i >= 0;i--) {
		if ((sum + a[i]) % b[i] != 0) {sum += b[i] - (sum + a[i]) % b[i];}
	}
	cout << sum << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define FOR(v, a, b) for(int v = (a); v < (b); ++v)
#define FORE(v, a, b) for(int v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define UNWORDS(vec, str) for(int i = 0; i < (vec).size(); ++i) cout << (i ? str : "") << (vec)[i]
#define UNLINES(vec) for(int i = 0; i < (vec).size(); ++i) cout << (vec)[i] << endl
#define RS resize
#define CLR clear
#define PB push_back
#define ALL(x) (x).begin(), (x).end()
using namespace std;

int dir[5] = {0,1,0,-1,0};

int field[14][14];

int rec(int x, int y){
	
	field[x][y] = 0;
	
	REP(i, 4){
		if(field[x + dir[i]][y + dir[i + 1]] == 1){
			rec(x + dir[i], y + dir[i + 1]);
		}
	}
	
	return 1;
}

int main(){
	
	vector< string > lines;
	string str;
	int cnt;
	
	while(cin >> str){
		lines.PB(str);
	}
	
	REP(i, lines.size() / 12){
		cnt = 0;
		FORE(j, 1, 12){
			FORE(k, 1, 12){
				field[j][k] = lines[j - 1 + i * 12][k - 1] - '0';
			}
		}
		
		FORE(j, 1, 12){
			FORE(k, 1, 12){
				if(field[j][k] == 1){
					cnt += rec(j, k);
				}
			}
		}
		cout << cnt << endl;
	}
	
	return 0;
}

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

using namespace std;

int main(void){
    long long N,M;
    cin>>N>>M;
    vector<long long>A(N);
    vector<long long>B(N);
    for(int i=0;i<N;i++){
        cin>>A[i]>>B[i];
    }
    vector<pair<long long,long long>> drink;
    for(int i=0;i<N;i++){
        drink.push_back(make_pair(A[i],B[i]));
    }
    sort(drink.begin(),drink.end());
    long long ans=0;
    for(auto x:drink){
        if(M>0){
            ans+=x.first*min(M,x.second);
            M=M-min(M,x.second);
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3956
#include <bits/stdc++.h>
// #define int ll

typedef long long ll;

using namespace std;

inline int read() {
	int x = 0, f = 1; char c = getchar();
	while (!isdigit(c)) {
		if (c == '-') f = -1;
		c = getchar();
	}
	while (isdigit(c)) {
		x = x * 10 + c - '0';
		c = getchar();
	}
	return x * f;
}

signed main() {
	int n=read(),last=n%10;
	if(last==2||last==4||last==5||last==7||last==9)puts("hon");
	else if(last==3)puts("bon");
	else puts("pon");
	return 0;
}


Measured memory_bytes: 3580
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <queue>
#include <list>
#include <stack>
#include <math.h>
#include <map>
#include <unordered_map>
#include <set>
using namespace std;

#define ll long long
#define ull unsigned long long

#define	max	998244353//1000000007

ll gcd(ll a, ll b) {
	if (a < b)
		swap(a, b);
	while (ll r = a % b)
		a = b, b = r;
	return b;
}

class mod
{
public:
	ll val;

	mod(ll v)
	{
		val = v % max;
	}

	mod()
	{
		val = 0;
	}

	void operator -=(const mod &v)
	{
		val -= v.val;

		if (val < 0)
			val += max;
	}

	void operator +=(const mod &v)
	{
		if (val + v.val >= max)
			val -= max;
		val += v.val;
	}

	void operator +=(ll &v)
	{
		if (val + v >= max)
			val -= max;
		val += v;
	}

	void operator *=(const mod &v)
	{
		val *= v.val;
		val %= max;
	}

	void operator *=(ll &v)
	{
		val *= v;
		val %= max;
	}

	ll modinv(ll a)
	{
		ll b = max, u = 1, v = 0;
		while (b)
		{
			ll t = a / b;
			a -= t * b; swap(a, b);
			u -= t * v; swap(u, v);
		}
		u %= max;
		if (u < 0)
			u += max;
		return u;
	}

	void operator /=(const mod &v)
	{
		val *= modinv(v.val);
		val %= max;
	}

	void operator /=(ll &v)
	{
		val *= modinv(v);
		val %= max;
	}
};

struct p
{
	ll a;
	int b;
	int c;
};

inline int func(int a, int b)
{
	if (a > b)
		return a - b;
	else
		return b - a;
}

ll r = 0;
int tar = 0;
ll cur = 1;

bool solve(int head, int keta)
{
	if (keta == 0)
	{
		tar--;
		if (tar == 0)
		{
			r = 0;
			r += head;
			cur *= 10;
			return true;
		}
		return false;
	}

	if (head == 9)
	{
		if (solve(8, keta - 1))
		{
			r += head * cur;
			cur *= 10;
			return true;
		}
		
		if (solve(9, keta - 1))
		{
			r += head * cur;
			cur *= 10;
			return true;
		}
		return false;
	}
	else if (head == 0)
	{
		if (solve(0, keta - 1))
		{
			r += head * cur;
			cur *= 10;
			return true;
		}

		if (solve(1, keta - 1))
		{
			r += head * cur;
			cur *= 10;
			return true;
		}
		return false;
	}
	else
	{
		if (solve(head - 1, keta - 1))
		{
			r += head * cur;
			cur *= 10;
			return true;
		}

		if (solve(head, keta - 1))
		{
			r += head * cur;
			cur *= 10;
			return true;
		}

		if (solve(head + 1, keta - 1))
		{
			r += head * cur;
			cur *= 10;
			return true;
		}
		return false;
	}
}

int main()
{
	int x, y, z;
	cin >> x >> y >> z;
	printf("%d %d %d", z, x, y);

	return 0;
}


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

int main()
{
    int a1, a2, a3;
    cin >> a1 >> a2 >> a3;
    if(a1 + a2 + a3 >= 22) {
        cout << "bust";
    }
    else {
        cout << "win";
    }
    
    return 0;
}


Measured memory_bytes: 256