akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    #define loop(i,a,b) for(i=a;i<b;i++)
    #define rloop(i,a,b) for(i=a;i>=b;i--)
    #define vi vector<int>
    #define vl vector<ll>
    #define vii vector< vector<int> >
    #define vll vector< vector<ll> >
    #define vs vector<string>
    const int inf=1000000001;
    const ll INF=1e16;
    #define MOD 1000000007
    #define mod 1000000009
    #define pi 3.14159265358979323846
     
     
    int main(){
    	ll n,w,i,j,k,l,i2;
    	cin>>n>>w;
    	vl kosuu(4,0),weight(n);
    	vll value(4,vl(0));
    	ll v;
    	loop(i,0,n){
    		cin>>weight[i]>>v;
    		kosuu[weight[i]-weight[0]]++;
    		value[weight[i]-weight[0]].push_back(v);
    	}
    	loop(i,0,4){
    		sort(value[i].begin(),value[i].end());
    		reverse(value[i].begin(),value[i].end());
    	}
    	ll m=0;
    	ll sum;
    	loop(i,0,kosuu[0]+1){
    		loop(j,0,kosuu[1]+1){
    			loop(k,0,kosuu[2]+1){
    				loop(l,0,kosuu[3]+1){
    					if((i+j+k+l)*(weight[0])+j+2*k+3*l<=w){
    						sum=0;
    						loop(i2,0,i){
    							sum+=value[0][i2];
    						}
    						loop(i2,0,j){
    							sum+=value[1][i2];
    						}
    						loop(i2,0,k){
    							sum+=value[2][i2];
    						}
    						loop(i2,0,l){
    							sum+=value[3][i2];
    						}
    						m=max(m,sum);
    					}
    				}
    			}
    		}
    	}
    	cout<<m<<endl;
    }

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;

typedef long long i64;

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

  if (!(N & 1)) {
    printf("%d %d %d\n", N, N, N / 2);
    return 0;
  }

  for (register int i = 1; i <= 3500; ++i)
    for (register int j = 1; j <= 3500; ++j) {
      i64 down = 1LL * i * j * N;
      i64 up = 1LL * 4 * i * j - 1LL * i * N - 1LL * j * N;

      if (up > 0 && down % up == 0) {
	down /= up;
	printf("%d %d %lld\n", i, j, down);
	return 0;
      }
    }
  
  return 0;
}



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

int main(){
    string str;
    bool flag=false;
    cin >> str;
    sort(str.begin(),str.end());
    if(str.at(0)==str.at(1)){
        if(str.at(2)==str.at(3)){
            if(str.at(1)!=str.at(2)){
                flag=true;
            }
        }
    }
    if(flag) cout << "Yes" <<endl;
    else cout <<"No" << endl;
    return 0;
}

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

int n;
int garden[100];
int ans=0;

void water(int x, int y){
    if(!(x<=y&&0<=x&&y<n))return;
    bool all_ok=true;
    int done,counter=0;
    for(int i=x;i<=y;i++){
        if(garden[i]==0){
            all_ok=false;
            done=i;
            counter++;
        }
    }
    if(all_ok){
        for(int i=x;i<=y;i++)garden[i]--;
        ans++;
        water(x,y);
    }else{
        if(counter==(y-x+1))return;
        water(x,done-1);
        water(done+1,y);
    }
}

signed main(){
    cin>>n;
    fill(garden,garden+100,0);
    rep(i,n)cin>>garden[i];
    water(0,n-1);
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <utility>
using namespace std;
typedef pair<int,int> P;
#define fi first
#define sec second
int X,Y,Z;
int V[5],N[55],E[55],A[55];
P ev[55];
double dp[55][6000];
int main()
{
	while(1)
	{
		cin >> X >> Y >> Z;
		if(X==0&&Y==0&&Z==0)break;
		for(int i=0;i<X;i++)cin >> V[i];
		for(int i=0;i<55;i++)ev[i].fi=0,ev[i].sec=0;
		for(int i=0;i<Z;i++)
		{
			cin >> N[i] >> E[i] >> A[i];
			ev[N[i]].fi = E[i];
			ev[N[i]].sec = A[i];
		}
		for(int i=0;i<55;i++)for(int j=0;j<6000;j++)dp[i][j]=0.0;
		dp[0][0]=1.0;
		for(int i=0;i<Y;i++)
		{
			for(int j=0;j<=5200;j++)
			{
				for(int k=0;k<X;k++)
				{
					int id = min(i+V[k],Y);
					if(ev[id].fi==0)dp[id][j]+=dp[i][j]/(double)X;
					if(ev[id].fi==1)dp[min(id+ev[id].sec,Y)][j]+=dp[i][j]/(double)X;
					if(ev[id].fi==2)dp[id][j+ev[id].sec]+=dp[i][j]/(double)X;
					if(ev[id].fi==3)dp[id][max(0,j-ev[id].sec)]+=dp[i][j]/(double)X;
				}
			}
		}
		double ans = 0.0;
		for(int i=0;i<6000;i++)ans += (double)i*dp[Y][i];
		printf("%d\n",(int)ans);
	}
	return 0;
}

Measured memory_bytes: 3724
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define puts(i) cout << i << endl
#define INF INT_MAX
#define INFL LLONG_MAX
typedef long long ll;
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int> p(n);
  rep(i,n){
    cin >> p.at(i);
  }

  int ans = 0;

  for(int i=0;i<n-1;i++){
    if(p.at(i)==i+1){
      swap(p.at(i),p.at(i+1));
      ans++;
    }
  }

  if(p.at(n-1)==n){
    ans++;
  }

  cout << ans <<endl;
}


Measured memory_bytes: 3744
#include<iostream>

using namespace std;

int main(){
  long long n, m, bumbo=1, bunshi=1, ans=0;
  cin >> n >> m;
  for(int i=0;i<m;i++){
    bumbo*=2;
  }
  cout << (1900*m + 100*(n-m))*bumbo << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Text;

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

        static void Method(string[] args)
        {
            int k = ReadInt();
            long[] array = ReadLongs();
            Array.Reverse(array);
            if (array[0] != 2)
            {
                Console.WriteLine(-1);
                return;
            }
            long min = 2;
            long max = 3;
            for (int i = 1; i < k; i++)
            {
                if (min % array[i] != 0)
                {
                    min = (min / array[i] + 1) * array[i];
                }
                if (min > max)
                {
                    Console.WriteLine(-1);
                    return;
                }
                max = (max / array[i]) * array[i] + array[i] - 1;
                //Console.WriteLine(min + " " + max);
            }
            Console.WriteLine(min + " " + max);
        }

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


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

constexpr int SIZE = 1000000;
void solve(){
    int N;
    ll L;
    cin >> N >> L;
    pair<ll, ll> interval[N];
    vector<ll> compressTemp(N);
    map<ll, int> compress; // 座圧
    rep(i, N) {
        ll l, r;
        cin >> l >> r;
        compressTemp.push_back(l);
        compressTemp.push_back(r);
        interval[i] = make_pair(l, r);
    }
    sort(compressTemp.begin(), compressTemp.end());
    compressTemp.erase(unique(compressTemp.begin(), compressTemp.end()),compressTemp.end());
    rep(i, compressTemp.size()) {
        compress[compressTemp[i]] = i;
    } // ここまで座圧パート

    // xは区間スケジューリングなので貪欲
    sort(interval, interval+N);
    ll x = 0, xl = -1, xr = 0;
    rep(i, N) {
        if (interval[i].first > xl) {
            ++ x;
            xl = xr;
        }
        xr = max(xr, interval[i].second);
        if (xr >= L) break;
    }
    cout << x << " "; // ここまででxが解ける
    // 次にyは、座圧+imosで解けるね

    vector<int>imos(SIZE);
    rep(i, imos.size())
    {
        imos[i] = 0;
    }

    rep(i, N) {
        ++ imos[compress[interval[i].first]];
        -- imos[compress[interval[i].second]];
    }
    int y = N - imos[0] + 1;
    repi(i, 1, SIZE) {
        imos[i] += imos[i - 1];
        if (imos[i] > 0) y = max(y, N - imos[i] + 1);
    }
    cout << y << endl;
}

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

    
    return 0;
}


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

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

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

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

  cout << lcm(a, b) << endl;
}

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

int main(void){
  int x;
  cin >> x;
  if(x==22){
    cout << "Christmas Eve Eve Eve" << endl;
  }else if(x==23){
    cout << "Christmas Eve Eve" << endl;
  }else if(x==24){
    cout << "Christmas Eve" << endl;
  }else{
    cout << "Christmas" << endl;
  }
}

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

int f(int x)
{
  return x * x;
}

int main(void)
{
  int a, i, d;

  while(scanf("%d", &d) != EOF)
  {
    a = 0;

    for(i=1; i < 600/d; i++)
    {
      a = d * f(d*i) + a;
    }

    printf("%d\n", a);
  }

  return 0;
}



Measured memory_bytes: 3160
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
int dp[100004];
int func(int i,int arr[],int n)
{
    if(dp[i]!=-1)
    {
        return dp[i];
    }
    if(i>=n-2||i==n-3)
    {
        dp[i]=abs(arr[n-1]-arr[i]);
        return dp[i];
    }
    dp[i]=min(abs(arr[i+1]-arr[i])+func(i+1,arr,n),abs(arr[i+2]-arr[i])+func(i+2,arr,n));
    return dp[i];
}

int main()
{
    int n;
    cin>>n;
    int arr[n];
    for(int i=0;i<100004;i++)
    {
        dp[i]=-1;
    }
    for(int i=0;i<n;i++)
    {
        scanf("%d",&arr[i]);
    }
        func(0,arr,n);
    cout<<dp[0];
    return 0;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int n; cin >> n;
  VV<> g(n);
  V<> d(n);
  for (int i = 0; i < n - 1; ++i) {
    int u, v; cin >> u >> v, --u, --v;
    g[u].push_back(v);
    g[v].push_back(u);
    ++d[u], ++d[v];
  }
  V<> c(n); for (auto&& e : c) cin >> e;
  sort(begin(c), end(c));
  queue<int> que;
  V<> res(n);
  int p = 0;
  for (int v = 0; v < n; ++v) if (d[v] == 1) {
    res[v] = c[p++];
    que.push(v);
  }
  while (!que.empty()) {
    int v = que.front(); que.pop();
    for (int w : g[v]) {
      if (--d[w] == 1) {
        res[w] = c[p++];
        que.push(w);
      }
    }
  }
  lint sum = 0;
  for (int v = 0; v < n; ++v) for (int w : g[v]) {
    sum += min(res[v], res[w]);
  }
  sum >>= 1;
  cout << sum << '\n';
  for (int i = 0; i < n; ++i) cout << res[i] << " \n"[!(n + ~i)];
}

Measured memory_bytes: 1024
n = int(input())
prev_dst = 0
prev_time = 0
for _ in range(n):
    t, x, y = map(int, input().split())
    if t % 2 == 0 and (x + y) % 2 != 0:
        print('No')
        exit()
    if t % 2 == 1 and (x + y) % 2 != 1:
        print('No')
        exit()
    if (t - prev_time) < abs(x + y - prev_dst):
        print('No')
        exit()
    prev_time = t
    prev_dst = x + y
print('Yes')

Measured memory_bytes: 3064
function main(input) {
  const s = input.trim();
  const map = {};
  let result = "Yes";
  for (let i = 0; i < s.length; i++) {
    const char = s[i];
    if (!map[char]) {
      map[char] = 1;
    } else {
      if (map[char] === 2) {
        result = "No";
        break;
      }
      map[char] = map[char] + 1;
    }
  }
  Object.keys(map).map(key => {
    if (map[key] !== 2) {
      result = "No";
    }
  });
  console.log(result);
}
main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
m,k = map(int,input().split())

if m == 0:
    if k == 0:
        print(0,0)
    else:
        print(-1)
    exit()
if m == 1:
    if k == 0:
        print(0,0,1,1)
    else:
        print(-1)
    exit()
if k >= 2**m:
    print(-1)
    exit()
if k == 0:
    for i in range(2**m):
        print(i,i,end = ' ')
    exit()
res = []
used = [True]*(2**m)

tank = []

for i in range(2**m):
    if used[i]:
        tank.append((i,i^k))
        used[i] = used[i^k] = False
for i in range(len(tank)):
    if i % 2 == 1:
        continue
    a = tank[i][0]
    b = tank[i][1]
    c = tank[i+1][0]
    d = tank[i+1][1]
    res += [c,a,b,c,d,b,a,d]

for e in res:
    print(e,end=' ')


Measured memory_bytes: 16868
import sys
sys.setrecursionlimit(10**7)

def input():
    return sys.stdin.readline()

n, q = map(int,input().split())
g = [[] for _ in range(n+1)]
for  _ in range(n-1):
    a,b = map(int,input().split())
    g[a].append(b)
    g[b].append(a)
points = [0]*(n+1)
for _ in range(q):
    p, x = map(int,input().split())
    points[p] += x
# print(g)
# print(points)
def dfs(e,preve = -1):
    for nexte in g[e]:
        # print(nexte)
        if nexte == preve:
            continue
        points[nexte] = points[nexte] + points[e]
        dfs(nexte,e)
dfs(1)
print(*points[1:])



Measured memory_bytes: 268436
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#define N 3

int main(){
    int a[N];
    for(int i=0;i<3;i++){
        scanf("%d",&a[i]);
    }
    int kari;
    for(int i=0;i<3;i++){
        for(int j=2;j>i;j--){
            if(a[j]<a[j-1]){
                kari=a[j];
                a[j]=a[j-1];
                a[j-1]=kari;
            }
        }
    }
    printf("%d %d %d\n",a[0],a[1],a[2]);
    return 0;
}


Measured memory_bytes: 2076
#include <cstdio>
#define maxn 10005
#define sqrt __builtin_sqrt
using namespace std;

int cnt[maxn];

int main(int argc, char** argv)
{
	int n;
	scanf("%d", &n);
	int max = sqrt(n);
	for(int x=1; x<=max; x++)
		for(int y=1; y<=max; y++)
			for(int z=1; z<=max; z++)
			{
				int tmp = x * x + y * y + z * z + x * y + y * z + z * x;
				if(tmp <= n) cnt[tmp] ++;
			}
	for(int i=1; i<=n; i++) printf("%d\n", cnt[i]);
	return 0;
}

Measured memory_bytes: 2128
import java.util.Scanner;
public class Main {
	
	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)) {
			while(sc.hasNext()) {
				int n = sc.nextInt();
				if(n == 0) break;
				
				String f = "";
				int right = 0;
				int left = 0;
				int count = 0;
				int step = 0;
				
				for(int i=1; i<=n; i++) {
					f = sc.next();
					if(f.equals("ru")) {
						right++;
						step++;
					}
					else if(f.equals("lu")) {
						left++;
						step++;
					}
					else if(f.equals("rd")) {
						right--;
						step--;
					}
					else {
						left--;
						step--;
					}
					
					if(right == left && step ==2 || step == -2) {
						count++;
						step = 0;
					}
				}
				System.out.println(count);
			}
		}
	}
}


Measured memory_bytes: 36852
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int n;
int x[10005],y[10005];
vector<P>vec;
vector<int>pos[10005];
vector<int>edge[90005],redge[90005];
void make(int a,int b,int k,int l,int r,int from){
	if(r<a||b<l) return;
	if(a<=l&&r<=b){
		edge[from].pb(k);
		redge[k].pb(from);
		return;
	}
	make(a,b,k*2+1,l,(l+r)/2,from);
	make(a,b,k*2+2,(l+r)/2+1,r,from);
}
int c[90005],p[90005],k;
bool u[90005];
void dfs(int v){
	if(u[v]) return;
	u[v] = 1;
	for(int i=0;i<edge[v].size();i++){
		if(!u[edge[v][i]]) dfs(edge[v][i]);
	}
	c[k++] = v;
}
void sfd(int v){
	if(u[v]) return;
	u[v] = 1; p[v] = k;
	for(int i=0;i<redge[v].size();i++){
		if(!u[redge[v][i]]) sfd(redge[v][i]);
	}
}
bool sol(){
	//scc
	memset(u,0,sizeof(u)); k = 0;
	for(int i=0;i<(1<<16)+2*n;i++){
		if(!u[i]) dfs(i);
	}
	memset(u,0,sizeof(u)); k = 0;
	for(int i=(1<<16)+2*n-1;i>=0;i--){
		if(!u[c[i]]){
			sfd(c[i]); k++;
		}
	}
	for(int i=0;i<2*n;i++){
		if(p[(1<<15)-1+i] == p[(1<<16)+i]) return false;
	}
	return true;
}
int main(){
	cin>>n;
	rep(i,n){
		cin>>x[i]>>y[i];
		vec.pb(mp(x[i],i));
		vec.pb(mp(y[i],i));
	}
	SORT(vec);
	rep(i,2*n){
		pos[vec[i].sc].pb(i);
	}
	int lb = 0,ub = INF+5;
	while(ub-lb > 1){
		rep(i,90005) edge[i].clear(),redge[i].clear();
		rep(i,(1<<15)-1){
		    edge[i].pb(i*2+1);
		    edge[i].pb(i*2+2);
		    redge[i*2+1].pb(i);
		    redge[i*2+2].pb(i);
		}
		int mid = (lb+ub)/2;
		//旗を立てないといけない
		rep(i,n){
			int x = pos[i][0], y = pos[i][1];
			edge[(1<<15)-1+x].pb((1<<16)+y);
			edge[(1<<15)-1+y].pb((1<<16)+x);
			redge[(1<<16)+x].pb((1<<15)-1+y);
			redge[(1<<16)+y].pb((1<<15)-1+x);
		}
		//距離mid未満にあってはならない
		rep(i,2*n){
			int base = vec[i].fi;
			int x = POSU(vec,mp(base-mid+1,-1));
			int y = POSU(vec,mp(base+mid,-1));
			y--;
			if(x <= i-1) make(x,i-1,0,0,(1<<15)-1,(1<<16)+i);
			if(i+1 <= y) make(i+1,y,0,0,(1<<15)-1,(1<<16)+i);
		}
		if(sol()) lb = mid;
		else ub = mid;
	}
	cout << lb << endl;
}

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

int main() {
  char s, t, u;
  cin >> s >> t >> u;
  
  if((s != t) || (t != u)) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long int
const int mod =  1e9 +7;
using namespace std;
const int N = 10;
void mul(vector<vector<int>> A, vector<vector<int>> B, vector<vector<int>> &C, int n)
{
    
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            C[i][j]=0;
            for(int k=0;k<n;k++)
            {C[i][j] += (int)A[i][k] * B[k][j] % mod;
            if(C[i][j]>=mod)
            C[i][j] -= mod;
            }
        }
    }
}

void expo(vector<vector<int>> A, vector<vector<int>> &res, int k, int n)
{
    //memset(res,0,sizeof(res));
    for(int i=0;i<n;i++)
    res[i][i]=1;

    //cout<<res[1][1]<<endl;
    while(k>0)
    {
        if(k%2==1)
        mul(A,res,res,n);
        mul(A,A,A,n);
        k = k/2;
    }
}

signed main() {
    vector<vector<int>> A;
    int n,k;
    cin>>n>>k;
    A.resize(n,vector<int>(n));
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        cin>>A[i][j];
    }
    vector<vector<int>> res;
    res.resize(n,vector<int>(n));
    expo(A,res,k,n);
    int ans=0;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        ans += res[i][j]%mod;
        //cout<<res[i][j]<<" ";
        //cout<<endl;
    }
    cout<<ans%mod;
    return 0;
}


Measured memory_bytes: 384
#include <stdio.h>

int main(){
	int h[10000];
	int x,a,b,c,d,i,j,cnt;
	while(scanf("%d",&x)!=-1){
	i=cnt=0;
		for(a=0;a<=9;a++){				
			for(b=0;b<=9;b++){
				for(c=0;c<=9;c++){
					for(d=0;d<=9;d++){
						h[i]=a+b+c+d;
						i++;
					}
				}
			}
		}
		for(j=0;j<i;j++){
			if(h[j]==x) cnt++;
		}
			printf("%d\n",cnt);
	}
	return 0;
}

Measured memory_bytes: 636
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
inf = 10**17
mod = 10**9 + 7

a,b=MI()
print((a+b)%24)

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

using namespace std;

const int N = 500010;
const int LOG = 21;
const int ALPHA = 28;

int pr[N][LOG];
int f[N][ALPHA];
int a[N];
char foo[N];

int main() {
  scanf("%s", foo);
  int len = strlen(foo);
  for (int i = 0; i < len; i++) {
    a[i] = foo[i] - 'a';
  }
  for (int c = 0; c <= 26; c++) {
    f[len][c] = -1;
  }
  for (int i = len - 1; i >= 0; i--) {
    for (int c = 0; c <= 26; c++) {
      f[i][c] = -1;
    }
    f[i][a[i]] = i + 1;
    bool err = false;
    for (int c = a[i] + 1; c <= 26; c++) {
      int at = f[f[i][c - 1]][c - 1];
      if (at == -1) {
        err = true;
        break;
      }
      f[i][c] = at;
    }
    if (!err) {
      for (int c = 0; c < a[i]; c++) {
        f[i][c] = f[f[i][26]][c];
      }
    }
  }
  for (int i = 0; i <= len; i++) {
    pr[i][0] = f[i][26];
  }
  for (int j = 1; j < LOG; j++) {
    for (int i = 0; i <= len; i++) {
      if (pr[i][j - 1] == -1) {
        pr[i][j] = -1;
      } else {
        pr[i][j] = pr[pr[i][j - 1]][j - 1];
      }
    }
  }
  int tt;
  scanf("%d", &tt);
  while (tt--) {
    int x, y;
    scanf("%d %d", &x, &y);
    x--;
    for (int j = LOG - 1; j >= 0; j--) {
      if (pr[x][j] == -1) {
        continue;
      }
      if (pr[x][j] <= y) {
        x = pr[x][j];
      }
    }
    puts((x == y) ? "Yes" : "No");
  }
  return 0;
}


Measured memory_bytes: 98816
//Author: Lixiang
#include<stdio.h>
const int maxn=101;
struct D{
	int m[maxn][maxn],H,W,N;
	int x,y;
	bool flag;
	void next(){
		if(flag){
			y++;
			if(y>W){
				y=W;
				x++;
				flag=0;
			}
		}
		else{
			y--;
			if(y<1){
				y=1;
				x++;
				flag=1;
			}
		}
	}
	void paint(int n,int col){
		while(n--){
			m[x][y]=col;
			next();
		}
	}
	void init(){
		scanf("%d%d%d",&H,&W,&N);
		x=1;y=1;flag=1;
		for(int i=1,t;i<=N;i++){
			scanf("%d",&t);
			paint(t,i);
		}
	}
	void work(){
		for(int i=1;i<=H;i++){
			for(int j=1;j<W;j++)
				printf("%d ",m[i][j]);
			printf("%d\n",m[i][W]);
		}
	}
}sol;
int main(){
	sol.init();
	sol.work();
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)//iをaからn
#define per(i,a,n) for (int i=a-1;i>=n;i--)//iをnからa
#define db(x) cout << #x << " = " << x << endl
#define db2(x, y) cout << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n"; //デバッグ用
#define all(x) (x).begin(), (x).end()
#define INF 1000000000000 //10^12:∞
#define MOD 1000000007 //10^9+7:合同式の法

int main() {
  int N;
  cin >> N;
  
  vector<long long int> a(N);
  long long int all=0;
  rep(i,0,N){
      cin >> a.at(i);
      all+=a.at(i);
      all%=MOD;
  }
  
  //sort(all(a));
  
  long long int ans=0;
  
rep(i,0,N){
        all-=a.at(i);
        all=(all+MOD)%MOD;
        ans+=(a.at(i)*all)%MOD;
        ans%=MOD;
    }

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

Measured memory_bytes: 4752
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;

template <typename T1, typename T2>
string print_iterable(T1 begin_iter, T2 end_iter, int counter) {
    bool done_something = false;
    stringstream res;
    res << "[";
    for (; begin_iter != end_iter and counter; ++begin_iter) {
        done_something = true;
        counter--;
        res << *begin_iter << ", ";
    }
    string str = res.str();
    if (done_something) {
        str.pop_back();
        str.pop_back();
    }
    str += "]";
    return str;
}

vector<int> SortIndex(int size, std::function<bool(int, int)> compare) {
    vector<int> ord(size);
    for (int i = 0; i < size; i++) ord[i] = i;
    sort(ord.begin(), ord.end(), compare);
    return ord;
}

template <typename T>
bool MinPlace(T& a, const T& b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template <typename T>
bool MaxPlace(T& a, const T& b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template <typename Container>
int SZ(const Container& S) { return S.size(); }

template <typename S, typename T>
ostream& operator <<(ostream& out, const pair<S, T>& p) {
    out << "{" << p.first << ", " << p.second << "}";
    return out;
}

template <typename T>
ostream& operator <<(ostream& out, const vector<T>& v) {
    out << "[";
    for (int i = 0; i < (int)v.size(); i++) {
        out << v[i];
        if (i != (int)v.size()-1) out << ", ";
    }
    out << "]";
    return out;
}

#if DEBUG && !ONLINE_JUDGE
    ifstream input_from_file("input.txt");
    #define cin input_from_file

    #define dbg_var(x) clog << #x  << ": " << x << endl;
    #define dbg_array(x, len) clog << #x << ": " << print_iterable(x, x+len, -1) << endl;
#else
    #define dbg_var(x)
    #define dbg_array(x, len)
#endif

///////////////////////////////////////////////////////////////////////////
//////////////////// DO NOT TOUCH BEFORE THIS LINE ////////////////////////
///////////////////////////////////////////////////////////////////////////

const int MAXN = -1; 

bool is_present(char c, string s, int len) {
	for (int i = 0; i < len; i++) {
		if (s[i] == c) return true;
	}
	return false;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); // Remove in problems with online queries!
    string S;
    cin >> S;
    if (S == "zyxwvutsrqponmlkjihgfedcba") {
		cout << -1 << "\n";
		return 0;
	}
	if (S.size() != 26) {
		for (char c = 'a'; c <= 'z'; c++) {
			if (!is_present(c, S, S.size())) {
				S += c;
				cout << S << '\n';
				return 0;
			}
		}
	}
	for (int it = 25; it >= 0; it--) {
		for (char c = S[it]+1; c <= 'z'; c++) {
			if (!is_present(c, S, it)) {
				S[it] = c;
				S.resize(it+1);
				cout << S << '\n';
				return 0;
			}
		}
	}
}



Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

int main()
{
	char	s[16];
	char	t[16];
	int		n;
	int		len_s,len_t;
	int		errflg=0;
    // 文字列として取得
    scanf("%s",s);
	// 文字列として取得
    scanf("%s",t);
    // 条件判定
	len_s=strlen(s);
	len_t=strlen(t);
	// 小文字判定
	for( n=0;n<len_s;n++ ) {
		if( s[n]<'a' || s[n]>'z' ) {
			errflg=1;
			goto p_output;
		}
	}
	for( n=0;n<len_t;n++ ) {
		if( t[n]<'a' || t[n]>'z' ) {
			errflg=1;
			goto p_output;
		}
	}
	// 文字列長判定
	if( strlen(s)==0 || strlen(s)>10 ) {
		errflg=1;
		goto p_output;
	}
	// 文字列判定
	if( strlen(t)!=strlen(s)+1 || strncmp(s,t,strlen(s)) ) {
		errflg=1;
	}	
p_output:
	printf("%s\n",errflg?"No":"Yes");
    return 0;
}


Measured memory_bytes: 2152
n = int(input())
flower = [int(i) for i in input().split()]

ans = 0
for i in range(n):
    left = -1
    for j in range(n):
        if flower[j]:
            left = j
            break
    if left == -1:
        break

    MIN = flower[left]
    for k in range(left, n):
        if flower[k] == 0:
            right = k
            break
        else:
            MIN = min(MIN, flower[k])
    else:
        right = n
    for l in range(left, right):
        flower[l] -= MIN
    ans += MIN
print(ans)


Measured memory_bytes: 38896
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>

int main (int argc, char **argv)
{
  int i = 0;
  int j = 0;
  int n = 0;
  int d = 0;
  int axis[10][10] = {0};
  int ans = 0;

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

  for(i = 0; i < n; i++)
  {
    for(j = 0; j < d; j++)
    {
      scanf("%d", &axis[i][j]);
    }
  }

  for(i = 0; i < (n - 1); i++)
  {
    for(j = i + 1; j < n; j++)
    {
      int k = 0;
      int dist2 = 0;

      for(k = 0; k < d; k++)
      {
        dist2 += (axis[j][k] - axis[i][k]) * (axis[j][k] - axis[i][k]);
      }

      for(k = 1; (k * k) <= dist2; k++)
      {
        if((k * k) == dist2)
        {
          ans++;
          break;
        }
      }
    }
  }

  printf("%d", ans);

  return 0;
}


Measured memory_bytes: 128
#include <cstdio>
#include <iostream>

using namespace std;


char buf[10];
int main(void) {
  scanf("%s", buf);
  bool contains = false;
  for(int i = 0; buf[i]; ++i) {
    if(buf[i] == '9') {
      contains = true;
    }
  }
  puts(contains ? "Yes" : "No");
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define INF 1000000000000
#define MOD 1000000007
#define DEBUG(x) cerr<<'>'<<#x<<':'<<x<< endl
using namespace std;

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll x, y, z;
    cin >> x >> y >> z;
    cout << z << " " << x << " " << y << endl;      
    return 0;
}


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

using namespace std;

typedef long long ll;

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

	ll n;
	cin >> n;

	ll ans = n - 1;
	for(ll i = 1; i <= 1010101; i++){
		if(n % i == 0 && (i + n / i) < ans){
			ans = i + n / i - 2;
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 256
package main

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

func gcd1(a, b, c int) int {
	d := gcd2(b, c)
	if d < a {
		return gcd2(d, a)
	}
	return gcd2(a, d)
}

func gcd2(a, b int) int {
	r := b % a
	for {
		if r == 0 {
			break
		}
		a, b = r, a
		r = b % a
	}
	return a
}

func main() {
	var k int
	fmt.Scan(&k)

	solve := 0
	for i := 1; i <= k-2; i++ {
		for j := i + 1; j <= k-1; j++ {
			for l := j + 1; l <= k; l++ {
				solve += gcd1(i, j, l) * 6
			}
		}
	}

	for i := 1; i <= k-1; i++ {
		for j := i + 1; j <= k; j++ {
			solve += gcd2(i, j) * 3 * 2
		}
	}

	for i := 1; i <= k; i++ {
		solve += i
	}

	w := bufio.NewWriter(os.Stdout)
	defer w.Flush()
	fmt.Fprintln(w, solve)
}


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

int main() {
    int x, y, W, H, r;
    cin >> W >> H >> x >> y >> r;
    if (x < r || y < r)
        cout << "No" << endl;
    else if (x + r <= W&&y + r <= H)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

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

using namespace std;

using i64 = int64_t;

const i64 MOD = 1e9+7;

const i64 INF = 1e18+7;


signed main(){
    int n;
    cin >> n;
    if(n == 3){
        cout << "2 5 63\n";
        return 0;
    }

    // 総和が6の倍数
    // 2, 3, 4, 9
    vector<vector<int>> v(6);
    vector<int> ans = {2, 3, 4, 9};
    for(int i = 5; i <= 30000; ++i){
        if(i == 9)
            continue;
        if(i % 2 == 0 || i % 3 == 0)
            v[i % 6].emplace_back(i);
    }
    while(ans.size() < n){
        int nok = n - ans.size();
        if(nok >= 2 && !v[2].empty()){
            ans.emplace_back(v[2].back());
            ans.emplace_back(v[4].back());
            v[2].pop_back();
            v[4].pop_back();
        }else if(nok >= 2 && v[3].size() >= 2){
            ans.emplace_back(v[3].back());
            v[3].pop_back();
            ans.emplace_back(v[3].back());
            v[3].pop_back();
        }else{
            ans.emplace_back(v[0].back());
            v[0].pop_back();
        }
    }
    for(int i = 0; i < n; ++i)
        cout << ans[i] << " \n"[i == n - 1];
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main() {
    char a,b,c,d,e,f;
    cin >> a >> b >> c >> d >> e >> f;
    if(a == f && b == e && c == d) {
        cout << "YES" << endl;
    }else {
        cout << "NO" << endl;
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
int main(void){

int n,k,w;
int h[100010];
int dp[100010];

cin >> n >> k;

for(int i = 0; i < n; i++) cin >> h[i];

for(int i = 0;i < n; i++){
    if(i == 0) dp[i] = 0;
    else{
        if(i <= k) w = i;  
        int a[100010];
        for(int j = 0; j < w; j++) a[j] = abs(h[i] - h[i - j - 1]) + dp[i - j - 1];        
        sort(a, a + w);
        dp[i] = a[0];
        }
    }
    
cout << dp[n - 1] << "\n";

}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define pb push_back
#define ll long long
using namespace std;
long long int m=1000000007;
long long int power(long long int p,long long int k)
{
long long int a=1;
while(k)
{
if(k&1)
a=(a*p)%m;
p=(p*p)%m;
k>>=1;
}
return a;
}
int main()
{
ll n;
cin>>n;
cout<<n*(n-1)/2;
return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
void BubbleSort(int A[],int length)
{
    int i,j,t,count=0;
    for(i=0;i<=length-1;i++)
    {
        for(j=length-1;j>=i+1;j--)
        {
            if(A[j]<A[j-1])
            {
                t=A[j];
                A[j]=A[j-1];
                A[j-1]=t;
                count++;
            }
        }
    }
    for(i=0;i<length-1;i++)
    {
        printf("%d ",A[i]);
    }
    printf("%d\n",A[i]);
    printf("%d\n",count);
}
int main()
{
    int a[10000],n,i;
    scanf("%d",&n);
    for(i=0;i<n;i++)
        scanf("%d",&a[i]);
    BubbleSort(a,n);
}



Measured memory_bytes: 2096
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'

const int N = 1e5+10;

using namespace std;

main()
{
    fast;
    ll a,b;
    char c;
    cin>>a>>c>>b;
    if (c=='+')
        cout<<a+b<<endl;
    else
        cout<<a-b<<endl;
}

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

int N, Q;
vector< int > values, s;
vector< int > reader;

bool calc(int value, int a){ //reader[i]以下reader[i]-value以上
  int pre = 0, ng = 0;
  for(int i = 0; i < reader.size(); i++){
    int pos = lower_bound( values.begin(), values.end(), reader[i] - value) - values.begin(); //reader[i]-value以上
    ng += max( 0, pos - pre);
    pre = upper_bound( values.begin(), values.end(), reader[i]) - values.begin(); //reader[i]以下
  }
  ng += max< int >( 0, N - pre);
  return (ng <= a);
}

int main(){

  scanf("%d %d", &N, &Q);
  values.resize(N), s.resize(N);

  for(int i = 0; i < N; i++){
    scanf("%d", &s[i]);
    values[i] = s[i];
  }
  sort(values.begin(), values.end());

  while(Q--){
    char query[100];
    int a;
    scanf("%s %d", query, &a);

    if(strcmp(query,"ADD") == 0){

      a--;
      reader.push_back(s[a]);
      sort( reader.begin(), reader.end());

    } else if(strcmp(query,"REMOVE") == 0){

      a--;
      reader.erase(lower_bound( reader.begin(), reader.end(), s[a]));

    } else {
      int row = 0, high = 1000000001;
      while(high != row){
        int mid = (row + high) >> 1;
        if(calc(mid, a)) high = mid;
        else row = mid + 1;
      }

      if(row == 1000000001) puts("NA");
      else printf("%d\n", row);
    }

  }

}

Measured memory_bytes: 8856
N = int(input())
S = input()
ans = 0
for i in range(1,N):
    c = 0
    cc = 0
    for j in range(N-i):
        if S[j] == S[i+j]:
            cc += 1
        else:
            c = max(cc,c)
            cc = 0
    c = max(cc,c)
    c = min(i,c)
    ans = max(ans,c)
print(ans)


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





int main(){

  int n;
  cin>>n;
  long long sum=0;
  vector<long long>a(n);
  for(int i=0;i<n;i++){
    cin>>a[i];
    sum+=a[i];
  } 
  
  
   
  vector<long long>b(n,0);

  long long k=0;
  
  for(int i=1;i<=(n-1)/2;i++){
    k+=a[i*2-1];
  }

  b[0]=sum-2*k;

  

  for(int i=1;i<n;i++){
    b[i]=a[i-1]*2-b[i-1];
    
  }


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


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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a*b/gcd(a, b);
}

int main()
{
    cout << fixed << setprecision(15);
    int X, Y, Z;
    cin >> X >> Y >> Z;

    cout << Z << " " << X << " " << Y << endl;
    return 0;
}

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

int ld(int N){
    int c=N;
    for(;N!=0;N/=10){
        c = N;
    }
    return c;
}

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

    int r[10][10];
    for(int i=1; i<10; i++){
        for(int j=1; j<10; j++){
            r[i][j] = 0;
        }
    }

    for(int n=1; n<=N; n++){
        r[ld(n)][n%10]++;
    }

    uint64_t isum = 0;
    for(int i=1; i<10; i++){
        for(int j=1; j<10; j++){
            isum += r[i][j] * r[j][i];
        }
    }

    cout << isum << endl;

	return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vc = vector<char>;
using vvc = vector<vector<char>>;
using vs = vector<string>;

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repp(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define repd(i, n) for(ll i = n - 1; i >= 0; i--)
#define all(x) x.begin(), x.end()

int k, l, m, n;
const int M = 1e9 + 7;


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

    int d, t, s;
    cin >> d >> t >> s;

    if((double)d / s <= (double)t) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n;
    cin>>n;
    string s;
    cin>>s;
    std::map<int, int> r;
    std::map<int, int> g;
    std::map<int, int> b;
    for (int i=0;i<n;i++) {
        if (s[i]=='R') {
            r.emplace(i+1,1);
        } else if (s[i]=='G') {
            g.emplace(i+1,1);
        } else {
            b.emplace(i+1,1);
        }
    }
    long long int sum=r.size()*g.size()*b.size();
    long long int count=0;
    for (auto itr=r.begin();itr!=r.end();itr++) {
        for (int i=1;abs(itr->first-i-i)<=n;i++) {
            if (g[itr->first+i]==1&&b[itr->first+i+i]==1) {
                count++;
                //cout<<itr->first<<" "<<itr->first+i<<" "<<itr->first+i+i<<endl;
            }
            if (g[itr->first+i]==1&&b[itr->first-i]==1) {
                count++;
            }
            if (g[itr->first-i]==1&&b[itr->first+i]==1) {
                count++;
            }
            if (g[itr->first-i]==1&&b[itr->first-i-i]==1) {
                count++;
                //cout<<itr->first<<" "<<itr->first-i<<" "<<itr->first-i-i<<endl;
            }
            if (g[itr->first-i-i]==1&&b[itr->first-i]==1) {
                count++;
            }
            if (g[itr->first+i+i]==1&&b[itr->first+i]==1) {
                count++;
            }
        }
    }
    cout<<sum-count<<endl;
}

Measured memory_bytes: 5024
import java.util.Scanner;

class Main {
  public static void main(String[] args) {
    Scanner s = new Scanner(System.in);
    int k = s.nextInt();
    int n = s.nextInt();
    int[] a = new int[n];
    int answer = k;
    for(int i = 0; i < n; i++) {
      a[i] = s.nextInt();
    }
    if(n == 2) {
      answer = a[1]-a[0];
    } else {
      for(int i = 1; i < n; i++) {
        int y = a[i-1]+k-a[i];
        if(answer > y) {
          answer = y;
        }
      }
      int x = a[n-1]-a[0];
      if(answer > x) {
        answer = x;
      }
    }

    System.out.println(answer);
  }
}

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

    int main() {
      int64_t N,K;
      cin>>N>>K;
      int64_t t=N%K;
      int64_t l=abs(t-K);
      int64_t ans= min(l,t);
      cout<<ans<<endl;
     return 0;
    }

Measured memory_bytes: 256
#define ONLINE_JUDGE
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
const ll INF=1001001001;
const ll LINF=1001001001001001001;
const ll D4[]={0,1,0,-1,0};
const ll D8[]={0,1,1,0,-1,-1,1,-1,0};
#define _overload3(_1,_2,_3,name,...) name
#define _rep2(i,n) for(ll i=0;i<(n);++i)
#define _rep3(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,_rep3,_rep2)(__VA_ARGS__)
#define _repe2(i,n) for(ll i=0;i<=(n);++i)
#define _repe3(i,a,b) for(ll i=(a);i<=(b);++i)
#define repe(...) _overload3(__VA_ARGS__,_repe3,_repe2)(__VA_ARGS__)
#define _rrep2(i,n) for(ll i=(n)-1;i>=0;i--)
#define _rrep3(i,a,b) for(ll i=(b)-1;i>=(a);i--)
#define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
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;}
template<class T>
using pq=priority_queue<T,vector<T>,greater<T>>;

ll N;
vl A;
vl B;
vl C;

void solve();

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cin >> N;
    A = vl(N);
    for(int i = 0; i < N; ++i){
        cin >> A[i];
    }
    B = vl(N);
    for(int i = 0; i < N; ++i){
        cin >> B[i];
    }
    C = vl(N);
    for(int i = 0; i < N; ++i){
        cin >> C[i];
    }
    solve();
}

void solve(){
    sort(all(A));
    sort(all(B));
    sort(all(C));

    ll ans=0;
    rep(i,N){
        ll a=lower_bound(all(A),B[i])-A.begin();
        ll c=C.end()-upper_bound(all(C),B[i]);
        ans+=a*c;
    }
    cout<<ans<<endl;
}


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


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

struct edge {int to; ll cost; };

int dx[] = {-1, 1, 0,  0};
int dy[] = { 0, 0, 1, -1};
 
int main(){
  int n, m;
  cin >> n >> m;
  vector<int> ans(n, -1);
  for(int i=0; i<m; i++){
    int s, c;
    cin >> s >> c;
    s--;
    if(ans[s]!=-1 && ans[s]!=c){
      cout << -1 << endl;
      return 0;
    }
    if(s==0 && c==0 && n>1){
      cout << -1 << endl;
      return 0;
    }
    ans[s] = c;
  }
  if(n==1){
    if(ans[0]==-1) cout << 0 << endl;
    else cout << ans[0] << endl;
    return 0;
  }
  for(int i=0; i<n; i++){
    if(ans[i]==-1){
      if(i==0) cout << 1;
      else cout << 0;
    }
    else cout << ans[i];
  }
  cout << endl;
  return 0;
}


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

using namespace std;

#define range(i, m, n) for(int i = m; i < n; i++)
#define husk(i, m, n) for(int i = m; i > n; i--)

int n, m;

int main() {
  cin >> n >> m;
  string a, b;
  cin >> a >> b;
  long long s = 1LL * n * m / __gcd(n, m);
  map<long long, char> cur;
  range(i, 0, n) cur[s * i / n] = a[i];
  range(i, 0, m) {
    if(cur.count(s * i / m) && cur[s * i / m] != b[i]) {
      cout << -1;
      return 0;
    }
  }
  cout << s;
  return 0;
}


Measured memory_bytes: 6144
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define INF LLONG_MAX/5
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define S second
#define F first
#define f(i,n) for(int i=0;i<n;i++)
int mypow(int a,int b,int c){
	if(b==0)return 1;
	if(b%2)return mypow(a,b-1,c)*a%c;
	int z=mypow(a,b/2,c);
	return z*z%c;
}
int gcd(int a,int b){
	if(b==0)return a;
	return gcd(b,a%b);
}
int lcm(int a,int b){
	return a/gcd(a,b)*b%mod;
}
signed main(){
	int a,b;
	cin>>a>>b;
	cout<<6-a-b<<endl;
}


Measured memory_bytes: 256
# coding:utf-8
a, b, c, x, y = map(int, input().split())

cost = a * x + b * y
n = max(x, y)

for i in range(0, n + 1):
    tmp = 2 * i * c + max(0, x - i) * a + max(0, y - i) * b
    cost = min(tmp, cost)

print(cost)


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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define each(i,c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define all(v) v.begin(), v.end()
#define mset(a, n) memset(a, n, sizeof(a))

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;

const int INF = 1000000000;
const int MOD = 1000000007;
const double eps = 1e-9;

int main(int argc, char *argv[]) {
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    ll n, m;
    cin >> n >> m;

    ll cnt1 = 1, cnt2 = 1, ans = 0;

    for (ll i = max(n, m); i > 0; --i) {
        cnt1 *= i;
        cnt1 %= MOD;
    }

    for (ll i = min(n, m); i > 0; --i) {
        cnt2 *= i;
        cnt2 %= MOD;
    }

    if (abs(n - m) == 0) {
        ans = 2 * cnt1 * cnt2 % MOD;
    } else if (abs(n - m) == 1) {
        ans = cnt1 * cnt2 % MOD;
    } else {
        ans = 0;
    }

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

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<string>
#include<cmath>
#include<utility>
typedef long long ll;
int main() {
	int n = 0;
	int ar[100000] = {};
	int ans = 0;
	std::cin >> n;
	for (int i = 0; i < n; i++) {
		std::cin >> ar[i];
	}
	for (int i = 0; i < n; i++) {
		ans += ar[i] - 1;
	}
	std::cout << ans << std::endl;
	return 0;
}

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

int main() {
    ll n, k, ans = 0;
    cin >> n >> k;
    while (n > 0)
    {
        n /= k;
        ans++;
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
import fractions
n = int(input())
a = [int(i) for i in input().split()]

ans = a[0]
for i in range(1, n):
    ans = ans * a[i] // fractions.gcd(ans, a[i])

total = 0
ans -= 1
for i in a :
  total += ans%i

print(total)

Measured memory_bytes: 5344
n = int(input())
A = []
B = []
for i in range(n):
    a,b = map(int, input().split())
    A.append(a)
    B.append(b)
ans = 0
for i in range(n-1,-1,-1):
    a = A[i] + ans
    b = B[i]
    #print(a,b)
    if a % b == 0:
        tmp = 0
    else:
        tmp = (a // b + 1) * b - a
    ans += tmp
print(ans)

Measured memory_bytes: 11048
N, K = map(int, input().split())
s = 0
ab = [[0, 0] for i in range(N)]
for i in range(N):
    ab[i][0], ab[i][1] = map(int, input().split())
ab = sorted(ab)

#print(ab)
for i in range(N):
    s += ab[i][1]
    if s >= K:
        print(ab[i][0])
        break

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

#define ll long long
#define INF 99999999
#define rep(i,n) for(int i=0,temp=(int)(n);i<temp;++i) //vec.size()がnの時等の高速化
#define loop(i,start,end) for(int i=start,temp=(int)(end);i<end;++i)
#define rfor(v,x) for(const auto& x : v) //xは値を表す
#define all(x) (x).begin(),(x).end()
#define SORT(v, n) sort(v, v+n)
#define vsort(v) sort(v.begin(), v.end())
#define vfsort(v,lambda) sort(v.begin(),v.end(),lambda)
#define vint vector<int>
#define vvint vector<vector<int>>
#define vin(v) rep(i,v.size()) {cin >> v[i];}

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; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int ctoi(char c) {return c-'0';}
//(lambda (x y) (< x y)) => [](int x, int y) -> int { return x<y; }

int main(){
  int n;cin >> n;
  if(n%111==0) cout << n << endl;
  else{
    int res;
    rep(i,111){
      if((n+i)%111==0){
        cout << n+i << endl;
        return 0;
      }
    }
  }

  return 0;
}


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

#define INF 100000
#define MAX 101
#define NIL -6
#define WHITE 0
#define GRAY 1
#define BLACK 2

void Prim(void);

int n, G[MAX][MAX];

/*ここからがmain関数*/
int main()
{
  int i, j, e;

  scanf("%d",&n);

  for(i = 0; i < n; i++){
    for(j = 0; j < n; j++){
      scanf("%d", &e);
      if(e == -1)
	G[i][j] = INF;
      else
	G[i][j] = e;   
    }
  }
  
  Prim();
  
  return 0;
}

/*ここからがPrim関数*/
void Prim()
{
  int i, j, min, u, v, sum = 0;
  int d[MAX], pi[MAX], color[MAX];

  for(i = 0; i < n; i++){
    color[i] = WHITE;
    pi[i] = NIL;
    d[i] = INF;
  }
  
  d[0] = WHITE;

  while(1){
    u = NIL;
    min = INF;
    
    for(i = 0; i < n; i++){
      if(color[i] != BLACK && d[i] < min){      
	u = i;
	min = d[i];
      }
    }
    if(u == NIL)
      break;
    
    color[u] = BLACK;
    
    for(v = 0; v < n; v++){
      if(color[v] != BLACK && G[u][v] != INF){
	if(G[u][v] < d[v]){
	  color[v] = GRAY;
	  pi[v] = u;
	  d[v] = G[u][v];
	}
      }
    }
  }
  for(i = 0; i < n; i++)
    if(pi[i] != NIL)
      sum += G[i][pi[i]];
  
  printf("%d\n",sum);
}



Measured memory_bytes: 2052
N,X,Y = map(int,input().split())
X -=1
Y-=1
dist_dict = {i:0 for i in range(1,N)}
for i in range(N-1):
    for j in range(i+1,N):
        d0 = j -i
        d1 = abs(X-i) + 1 + abs(j-Y)
        d = min(d0,d1)
        dist_dict[d] += 1
for i in range(1,N):
    print(dist_dict[i])

Measured memory_bytes: 3572