akhauriyash/Code-Regression huggingface dataset:
/**
 *    author:  tourist
 *    created: 23.05.2020 15:42:46       
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  string s;
  cin >> s;
  int len = (int) s.size();
  vector<int> pref(len + 1);
  for (int i = 0; i < len; i++) {
    pref[i + 1] = pref[i] + (s[i] == 'S');
  }
  vector<int> to(1, 0);
  vector<vector<int>> inc(1);
  for (int i = 0; i < len; i++) {
    if (s[i] == 'R') {
      inc[0].push_back(i);
    }
  }
  for (int it = 0; it < n; it++) {
    int sz = (int) inc.size();
    vector<int> new_to(3 * sz);
    vector<vector<int>> new_inc(3 * sz);
    for (int r = 0; r < sz; r++) {
      for (int start = 0; start < 3; start++) {
        int dig = start;
        int last = -1;
        for (int pos : inc[r]) {
          int flips = pref[pos] - pref[last + 1];
          if (dig != 0 && flips % 2 == 1) {
            dig = 3 - dig;
          }
          if (dig == 2) {
            new_inc[start * sz + r].push_back(pos);
          }
          dig = (dig + 1) % 3;
          last = pos;
        }
        int flips = pref.back() - pref[last + 1];
        if (dig != 0 && flips % 2 == 1) {
          dig = 3 - dig;
        }
        new_to[start * sz + r] = dig * sz + to[r];
      }
    }
    swap(to, new_to);
    swap(inc, new_inc);
  }
  for (int i = 0; i < (int) to.size(); i++) {
    if (i > 0) {
      cout << " ";
    }
    cout << to[i];
  }
  cout << '\n';
  return 0;
}


Measured memory_bytes: 35200
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
using namespace std;

struct Node {
	int key;
	Node* l, * p, * r;
};

Node* root, * Nil;

void insert(int key) {
	Node* x, * y, * z;
	x = root;
	y = Nil;
	z = (Node*)malloc(sizeof(Node));
	z->key = key;
	z->l = Nil;
	z->r = Nil;
	while (x != Nil) {
		y = x;
		if (x->key > z->key) {
			x = x->l;
		}
		else {
			x = x->r;
		}
	}
	z->p = y;
	if (y == Nil) {
		root = z;
	}
	else {
		if (z->key < y->key) {
			y->l = z;
		}
		else {
			y->r = z;
		}
	}

}

Node* find(Node* u, int key) {
	while (u != Nil && u->key != key) {
		if (key < u->key) {
			u = u->l;
		}
		else {
			u = u->r;
		}
	}
	return u;
}

void In(Node* h) {
	if (h == Nil) {
		return;
	}
	In(h->l);
	cout << " " << h->key;
	In(h->r);
}

void Pre(Node* p) {
	if (p == Nil) {
		return;
	}
	cout << " " << p->key;
	Pre(p->l);
	Pre(p->r);
}

int main() {
	int n, num;
	string S;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> S;
		if (S == "insert") {
			cin >> num;
			insert(num);
		}
		else if (S == "find") {
			cin >> num;
			Node* j = find(root, num);
			if (j != Nil) {
				cout << "yes" << endl;
			}
			else {
				cout << "no" << endl;
			}
		}
		else if (S == "print") {
			In(root);
			cout << endl;
			Pre(root);
			cout << endl;
		}
	}
}


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

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

    if (s.substr(0, 2) == "00" || "13" <= s.substr(0, 2)) {
        if ("01" <= s.substr(2, 2) && s.substr(2, 2) <= "12") {
            ans = "YYMM";
        }
        else {
            ans = "NA";
        }
    }
    else {
        if ("01" <= s.substr(2, 2) && s.substr(2, 2) <= "12") {
            ans = "AMBIGUOUS";
        }
        else {
            ans = "MMYY";
        }
    }

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

Measured memory_bytes: 256
from collections import deque

q = deque()

n = int(input())
*a, = map(int, input().split())
for i, x in enumerate(a):
    if i % 2 == 0:
        q.append(x)
    else:
        q.appendleft(x)
if n % 2:
    print(*reversed(q))
else:
    print(*q)


Measured memory_bytes: 25412
s = input()
s_len = len(s)-1
ans = 0

for i in range(1 << s_len):
    temp  = int(s[0])
    value = 0
    for j in range(s_len):
        if i>>j & 1:
            value += temp
            temp  =  int(s[j+1])
        else:
            temp  = 10*temp + int(s[j+1])
    value += temp
    ans += value

print(ans)

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

int main() {
   int N,N1,N2,N3,N4;
  cin >>N ;
  N1 = N /1000 ;
  N2 = (N-N1*1000)/100 ;
  N3 = (N-N1*1000-N2*100)/10 ;
  N4 =  N-N1*1000-N2*100-N3*10 ;
  
  if ((N1==N2)&&(N2==N3)||(N2==N3)&&(N3==N4)){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}
    


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

using namespace std;

int main(void) {
  int N;
  cin >> N;
  int n4 = 0, n2 = 0;
  int no;
  for (int i = 0; i < N; i++) {
    int val;
    cin >> val;
    if (val % 4 == 0)
      n4++;
    else if (val % 2 == 0)
      n2++;
  }
  no = N - n2 - n4;

  if (no == 0) {
    cout << "Yes" << endl;
    return 0;
  }

  int need4 = no + ((n2 == 0) ? 0 : 1);
  if (need4 - n4 > 1)
    cout << "No" << endl;
  else
    cout << "Yes" << endl;

  return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args) {
    
    Scanner sc = new Scanner(System.in);
      
      //入力
      long N =sc.nextLong();
      long K =sc.nextLong();

      long P = N % K;
      
      System.out.println(Math.min(P,K-P));
    }
}

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

int main(void){
  unsigned long N,M;
  cin >> N >> M;
  vector<unsigned long> A,B;
  vector<pair<unsigned long,unsigned long>> AB;
  AB.resize(N);
  for(unsigned long i=0;i<N;i++){
    cin>>AB[i].first>>AB[i].second;
  }

  sort(AB.begin(),AB.end());


  unsigned long money=0;
  unsigned long num = M;
  unsigned long min=-1;
  unsigned long minIndex=-1;
  for(auto pair:AB){
    // この店で買いきれるか
    if(pair.second>=num){
      // 買いきれるなら，必要量買い，ループ終了
      money+=pair.first*num;
      break;
    }else{
      // 買いきれないなら，全て買い，ループ継続
      money+=pair.first*pair.second;
      num-=pair.second;
    }
  }

  cout<<money<<endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include <stdio.h>
using namespace std;
  
int main()
{
	char cha;
	int e;
	while(1) {
		scanf("%c", &cha);
		e = (int)cha;
		if ((e >= 0x61)&&(e <= 0x7a)) {
			e -= 32;
			printf("%c", e);
		}
		else if ((e >= 0x41)&&(e <= 0x5a)) {
			e += 32;
			printf("%c", e);
		}
		else
			printf("%c", e);
		if(cha=='\n') break;
	}
	return 0;

}

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

int main() {
  int N;
  cin>>N;
  vector<int> vec(N);
  for(int i=0;i<N;i++){
    cin>>vec[i];
  }
  sort(vec.begin(),vec.end());
  int m=N/2;
  cout<<(vec[m]-vec[m-1]);
}

Measured memory_bytes: 640
import java.util.*;

class Main {
        public static void main(String args[]) {
                try (Scanner sc = new Scanner(System.in)) {
                        int N = sc.nextInt();
                        String A = sc.next();
                        String B = sc.next();
                        for (int i = 0; i <= N; i++) {
                                boolean f = true;
                                for (int j = i; j < N; j++) {
                                        if (A.charAt(j) != B.charAt(j - i)) {
                                                f = false;
                                        }
                                }
                                if (f) {
                                        System.out.println(i + N);
                                        return;
                                }
                        }
                }
        }
}

Measured memory_bytes: 9792
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>

#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i>b;i--)
#define vint vector<int> 
#define vvint vector<vint>
#define CST(x) cout<<fixed<<setprecision(x)//小数点以下の桁数指定
#define ct(a) cout<<a<<endl
static const double pi = 3.141592653589793;
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const int INF = 1e9+7;

class unionfind {
public:
	vector<int> par;
	vector<int> siz;

	unionfind(int N) :par(N), siz(N,1) {//コンストラクタ
		for (int i = 0; i < N; i++) {
			par[i] = i;
		}
	}

	int root(int x) {//データｘが属する木の根を再帰で得る:root(x)={ｘの木の根}
		while (par[x] != x) {
			x = par[x] = par[par[x]];
		}
		return x;
	}

	bool unite(int x, int y) {
		x = root(x);
		y = root(y);
		if (x == y)return false;//ｘとｙの根が同じ（＝同じ木にある）時はそのまま
		if (siz[x] < siz[y])swap(x, y);
			siz[x] += siz[y];
			par[y] = x;
			return true;
	}

	bool same(int x, int y) {
		return root(x) == root(y);
	}
	int size(int rx) {
		return siz[root(rx)];
	}

};



int main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);
	
	int N, M, K;
	cin >> N >> M >> K;
	unionfind f(N);
	
	int mi[100001];
	FOR(i, 0, N)mi[i] = 1;

	FOR(i, 0, M) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		f.unite(a, b);
		mi[a]++;
		mi[b]++;
	}
	FOR(i, 0, K) {
		int c, d;
		cin >> c >> d;
		c--; d--;
		if (f.same(c, d)) {
			mi[c]++; mi[d]++;
		}
	}
	FOR(i, 0, N) {
		cout << f.size(i) - mi[i] << " ";
	}

	return 0;
}


Measured memory_bytes: 2048
using System;

namespace abc155_b
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            string[] stra = Console.ReadLine().Split(' ');
            int[] a = new int[n];
            Boolean ok = true;
            for (int i = 0; i < n; ++i)
            {
                a[i] = int.Parse(stra[i]);
                if (a[i] % 2 == 0)
                {
                    if (!(a[i] % 3 == 0 || a[i] % 5 == 0))
                    {
                        ok = false;
                    }
                }
            }
            if (ok == true)
            {
                Console.WriteLine("APPROVED");
            }
            else
            {
                Console.WriteLine("DENIED");
            }
        }
    }
}


Measured memory_bytes: 13140
#include <stdio.h>
#include <stdlib.h>

#define N 101

int top,S[N];

int pop(){

  if(top == 0){
    fprintf(stderr,"アンダーフロー\n");
    exit(2);
  }


  
  return S[top--];

}

void push(int x){

  if(top == 100){
    fprintf(stderr,"オーバーフロー\n");
    exit(1);
  }

  S[++top] = x;

}


int main(){

  int n,a,status;

  char A[1000000];

  S[top] = NULL;

  while((status = scanf("%s",&A)) != EOF){
    
    if(A[0]==42 || A[0] == 43 || A[0] == 45){
      switch(A[0]){
	
      case 42:
	push(pop() * pop());
	break;

      case 43:
	push(pop() + pop());
	break;

      case 45:
	a =pop();
	push(pop() - a);
	break;
      }
    }
    
    else{
      push(atoi(A));
    }
    
  }

  printf("%d\n",S[top]);

  return 0;
}





Measured memory_bytes: 2128
#include "bits/stdc++.h"
using namespace std;
const int MAX = 700000;
const int MOD = 1000000007;

long long  fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y) {
	return(x + y - 1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}
/*逆元計算*/
long long int  modinv(long long a, long long m) {
	long long int b = m, u = 1, v = 0;
	while (b) {
		long long int t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
// index が条件を満たすかどうか
vector<long long int >meguru;
bool isOK(int index, int key) {
	if (meguru[index] <= key) return true;
	else return false;
}
// 汎用的な二分探索のテンプレ
int binary_search(int key) {
	int left = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
	int right = (int)meguru.size(); // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()
	/* どんな二分探索でもここの書き方を変えずにできる！ */
	while (right - left > 1) {
		int mid = left + (right - left) / 2;

		if (isOK(mid, key)) left = mid;
		else right = mid;
	}
	/* left は条件を満たす最大の値、right は条件を満たさない最小の値になっている */
	return left;
}
long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}
double PI = 3.141592653589793238;
int main() {
	double a, b;
	double h, m;
	cin >> a >> b >> h >> m;
	double c, d;
	c = 30 * h + 30 * (m / 60);
	d = 360 * (m / 60);
	double ang = min(abs(c - d), min(c + 360 - d, -c + 360 + d));
	if (ang == 0) {
		cout << abs(a - b);
		return 0;
	}
	else if(ang == 180) {
		cout << a + b;
		return 0;
	}
	double ans = pow(a * a + b * b - 2 * a * b*cos(PI*ang/180),0.5);
	cout <<fixed<<setprecision(15)<< ans;
}

Measured memory_bytes: 4328
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
from collections import deque
from fractions import gcd
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#############
# Main Code #
#############

A,B  = inputIL()

if A>12:
  print(B)
  exit()
if A<6:
  print(0)
  exit()
  
print(B//2)

Measured memory_bytes: 66292
import sys
input = sys.stdin.readline


A, B, C, D = map(int, input().split())


import fractions
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)


def f(d):
    return B//d - (A-1)//d


def main():
    ans = (B-A+1) - f(C) - f(D) + f(lcm(C, D))
    print(ans)


if __name__ == '__main__':
    main()


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

int a;

int main()
{
  cin >> a;
  cout << a*(1+a+a*a) << endl;
}

Measured memory_bytes: 3640
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();

		int[] arr = new int[n];

		for(int i = 0; i < n; i++) {
			arr[n - 1 - i] = sc.nextInt();

		}

		for(int i = 0; i < n; i++) {
			System.out.print(arr[i]);
			if (i < n - 1) {
				System.out.print(" ");
			}
		}
		System.out.println();
		sc.close();
	}

}


Measured memory_bytes: 26108
#include<iostream>
#include<vector>
#include<algorithm>
#include<string.h>
#include<complex>
using namespace std;
typedef long long int llint;
int main(){
	int x, y;
	cin >> x >> y;
	if (x + y >= 10){
		cout << "error" << endl;
	}
	else{
		cout << x + y << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <bitset>

#define lp(n) for(int i=0;i<n;i++)
#define LP(n,i) for(int i=0;i<n;i++)
#define mod 1000000007
#define sp ' '
#define intmax 2147483647
#define intmin -2147483637
#define llmax 9223372036854775807
typedef long long ll;

using namespace std;

vector<pair<int,int>>gp[100000];
int q,k,x,y,a,b,c,n;
ll ans[100000];

/*ll gcd(ll x,ll y){
	if(y==0)return x;
	return gcd(y,x%y);
}
ll lcm(ll x,ll y){
	ll g=gcd(x,y);
	return x/g*y;
}*/

int dfs(int X){
//	cout<<X<<endl;
	while(!gp[X].empty()){
		ans[gp[X][gp[X].size()-1].first]=ans[X]+gp[X][gp[X].size()-1].second;
		lp(gp[gp[X][gp[X].size()-1].first].size())
			if(gp[gp[X][gp[X].size()-1].first][i].first==X){
				gp[gp[X][gp[X].size()-1].first].erase(gp[gp[X][gp[X].size()-1].first].begin()+i);
				break;
			}
		dfs(gp[X][gp[X].size()-1].first);
		gp[X].pop_back();
		}
	return 0;
}

int main(){
	cin>>n;
	lp(n-1){
		cin>>a>>b>>c;
		gp[a].push_back(make_pair(b,c));
		gp[b].push_back(make_pair(a,c));
	}
	cin>>q>>k;
	ans[k]=0;
	dfs(k);
	lp(q){
		cin>>x>>y;
		cout<<ans[x]+ans[y]<<endl;
	}
	return 0;
}


Measured memory_bytes: 12800
#import sys
MOD = 10 ** 9 + 7
INFI = 10**10
#input = sys.stdin.readline
import math
from collections import deque
import itertools
import heapq
#import bisect
from fractions import Fraction
import copy
from functools import lru_cache
from collections import defaultdict
import pprint

#oo=list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
# ko=list("abcdefghijklmnopqrstuvwxyz")

def sosuhante(n):
    for k in range(2, int(math.sqrt(n))+1):
        if n% k ==0:
            return False
    return True
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def kingaku(a,b,n):
    keta=len(str(n))
    return a*n+b*keta

def my_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default

#    h,w,a,b = map(int, input().split())
#    c = [[0 for j in range(n)] for i in range(n)]

def ret(a):
    c=[None]*(len(a)-1)
    if len(a)==1:
        return a[0]
    elif len(a)==0:
        return 0
    for i in range(1,len(a)):
        c[i-1]=abs(a[i]-a[i-1])
    return ret(c)

def soinsubunkai(n):
    a = []
    i = 1
    while i*i <= n:
        if n % i == 0 and i!=1:
            a.append(i)
            n=n//i

        if n% i !=0 or i==1:
            i += 1
    nokori=[n]
    return a + nokori

def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

def main():
    n=int(input())
    total=0
    for i in range(1,n+1):
        maxint=n//i
        total+=maxint*(maxint+1)*i//2
    print(total)


if __name__ == "__main__":

    main()

Measured memory_bytes: 72664
#include <map>
#include <iostream>
using namespace std;
void A()
{
	int S[10000];
	int T[500];
	int N;
	int Q;
	int C = 0;
	cin >> N;
	for (int i = 0; i < N; i++)
	{
		cin >> S[i];
	}

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

	for (int i = 0; i < Q; i++)
	{
		for (int j = 0; j < N; j++)
		{
			if (T[i] == S[j])
			{
				C++;
				break;
			}
		}
	}

	cout << C << endl;
}

void B()
{
	int S[100001];
	int T[50000];
	int N;
	int Q;
	int C = 0;

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

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

	for (int i = 0; i < Q; i++)
	{
		int left = 0;
		int right = N;
		while (left < right)
		{
			int center = (left + right) / 2;

			if (T[i] == S[center])
			{
				C++;
				break;
			}

			if (T[i] > S[center])
			{
				left = center + 1;
			}
			else
			{
				right = center;
			}
		}
	}

	cout << C << endl;
}
/*long MAX = 1000000;
char a = 'A';
char c ='C';
char g = 'G';
char t = 'T';
bool table[1000000][20];

int toNumber(char ch)
{
	if (ch == 'A')
	{
		return 1;
	}
	else if (ch == 'C')
	{
		return 2;
	}
	else if (ch == 'G')
	{
		return 3;
	}
	else if (ch == 'T')
	{
		return 4;
	}
	else
	{
		return 0;
	}
}
int hash(int num,int i)
{
	return (hash1(num) + (i*hash2(num))) % MAX;
}

int hash1(int num)
{
	return num % MAX;
}
int hash2(int num)
{
	return num %(MAX - 1);
}

void insert(char data[])
{
	int sum = 0;
	for (int i = 0; i < strlen(data); i++)
	{
		sum += toNumber(data[i]);
	}

	for (int i = 0; i < strlen(data); i++)
	{
		table[sum][i] = data[i];
	}
}

void find(char data[])
{

}*/

/*void C()
{
	map<string, bool> dictionary;
	int N;
	scanf_s("%d", &N);
	//cin >> N;
	char command[20],data[20];
	for (int i = 0; i < N; i++)
	{
		scanf_s("%s", command, 20);
		scanf_s("%s", data, 20);
		//cin >> command;
		//cin >> data;

		if (command[0] == 'i')
		{
			string key = data;
			dictionary[key] = true;
		}
		else if (command[0] =='f')
		{
			string key = data;
			if (dictionary.find(key) == dictionary.end())
			{
				cout << "no" << endl;
			}
			else
			{
				cout << "yes" << endl;
			}
		}
	}

}*/
int check(long long p,int w[],int n,int k)
{
	int i = 0;
	for (int j = 0; j < k; j++)
	{
		long long s = 0;
		while (s + w[i] <= p)
		{
			s += w[i];
			i++;
			if (i == n)return n;
		}
	}
	return i;
}
void D()
{
	int w[100000];
	int n;
	int k;

	cin >> n;
	cin >> k;
	for (int i = 0; i < n; i++)
	{
		cin >> w[i];
	}

	long long left = 0;
	long long right = 100000 * 10000;
	long long mid = 0;
	while (left + 1 < right)
	{
		mid = (left + right) >> 1;
		int r = check(mid,w,n,k);
		if (r >= n)right = mid;
		else left = mid;
	}
	cout << right << endl;

}
int main()
{
	//A();
	//B();
	//C();
	D();
	return 0;
}

Measured memory_bytes: 1544
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())//vectorの降順ソート
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;

typedef tuple<ll, ll, ll> T;

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string o,s;
    cin>>o>>s;
    for(int i=0;i<o.size();i++){
        cout<<o[i];
        if(i<s.size()) cout<<s[i];
    }
    cout<<endl;
}

Measured memory_bytes: 256
n,m=map(int,input().split())
c=[list(map(int,input().split())) for i in range(m)]
cnt=[0 for i in range(n)]
for i in range(m):
    cnt[c[i][0]-1]+=1
for i in range(m):
    cnt[c[i][1]-1]+=1
for i in range(n):
    print(cnt[i])

Measured memory_bytes: 3064
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
const int maxn = 4e5 + 4;
const int inf = 0x3f3f3f3f;
int n, m;
vector<int> G[maxn];
int main(){
	scanf("%d%d", &n, &m);
	int u, v;
	for(int i = 0; i < m; i++){
		scanf("%d%d", &u, &v);
		G[u].push_back(v);
		G[v].push_back(u);
	}
	bool flag = false;
	for(int i = 0; i < G[1].size(); i++){
		u = G[1][i];
		for(int j = 0; j < G[u].size(); j++){
			v = G[u][j];
			if(v == n){
				flag = true;
				break;
			}
		}
		if(flag) break;
	}
	if(flag) puts("POSSIBLE");
	else puts("IMPOSSIBLE");
}

Measured memory_bytes: 16624
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
int main()
{
	int N;
	std::cin >> N;
	switch (N % 10) {
	case 2:
	case 4:
	case 5:
	case 7:
	case 9:
		std::cout << "hon" << std::endl;
		break;
	case 3:
		std::cout << "bon" << std::endl;
		break;
	default:
		std::cout << "pon" << std::endl;
		break;
	}
	return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
#define P(x) cout << (x) << endl
#define p(x) cout << (x)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define vv(type, c, m, n, i) vector<vector<type>> c(m, vector<type>(n, i));
#define rep(i,a,n) for(int i=(a), i##_len=(n); i<i##_len; ++i)
#define rrep(i,a,n) for(int i=(a), i##_len=(n); i>i##_len; --i)
#define len(x) ((int)(x).size())
#define mp make_pair
#define eb emplace_back
typedef long long ll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
constexpr int MAX = 101;
constexpr int INF = (1<<21);
int n;
vv(int, M, MAX, MAX, 0);
vi d(MAX, INF);
inline void bfs() {
	d[1] = 0;
	deque<int> dq;
	dq.eb(1);
	int u;
	while(!dq.empty()) {
		u = dq.front(); dq.pop_front();
		rep(v, 1, n + 1) {
			if(M[u][v] == 0 || d[v] != INF) continue;
			d[v] = d[u] + 1;
			dq.eb(v);
		}
	}
	rep(i, 1, n + 1) {
		cout << i << " " << ((d[i] == INF) ? (-1) : d[i]) << endl;
	}
}
int main() {
	cin >> n;
	int u, k, v;
	rep(i, 1, n + 1) {
		cin >> u >> k;
		rep(j, 1, k + 1) {
			cin >> v;
			M[u][v] = 1;
		}
	}
	bfs();
	return 0;
}

Measured memory_bytes: 3256
package main

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

var scanner = bufio.NewScanner(os.Stdin)

func readInt() (read int) {
	scanner.Scan()
	read, err := strconv.Atoi(scanner.Text())
	if err != nil {
		panic(err)
	}
	return
}

func main() {
	scanner.Split(bufio.ScanWords)

	n := readInt()
	S := make([]int, n)
	for i := 0; i < n; i++ {
		S[i] = readInt()
	}

	cnt := 0
	q := readInt()
	for j := 0; j < q; j++ {
		t := readInt()
		if binarySearch(S, t, n) > -1 {
			cnt++
		}
	}

	fmt.Println(cnt)
}

func binarySearch(A []int, key int, n int) int {
	left := 0
	right := n
	for left < right {
		mid := (left + right) / 2
		if A[mid] == key {
			return mid
		} else if key < A[mid] {
			right = mid
		} else {
			left = mid + 1
		}
	}
	return -1
}



Measured memory_bytes: 2676
if __name__ == '__main__':
   a, b, n = map(int, input().split())
   lista =  [int(i) for i in input().split()]
   listb =  [int(i) for i in input().split()]
   minP = min(lista) + min(listb)

   for i in range(n):
       c = [int(i) for i in input().split()]
       now =lista[c[0]-1] + listb[c[1]-1] - c[2]
       if  now< minP :
           minP=now

   print(minP)

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

using namespace std;



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

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

    int r[R + 1];
    for (int i = 1; i <= R; ++i)
        cin >> r[i];

    const int INF = (int)1e9;

    int cost[n + 1][n + 1];
    for (int i = 1; i <= n; ++i)
        for (int j = 1; j <= n; ++j)
            cost[i][j] = INF;

    for (int i = 1; i <= m; ++i) {
        int a, b, c;
        cin >> a >> b >> c;

        cost[a][b] = cost[b][a] = min(cost[a][b], c);
    }

    for (int k = 1; k <= n; ++k)
        for (int i = 1; i <= n; ++i)
            for (int j = 1; j <= n; ++j)
                cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);

    sort(r + 1, r + R + 1);

    int minCost = INF;

    do {
        int totalCost = 0;
        for (int i = 2; i <= R; ++i)
            totalCost += cost[r[i]][r[i - 1]];

        minCost = min(minCost, totalCost);
    } while (next_permutation(r + 1, r + R + 1));

    cout << minCost;

    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <cstdint>
#include <cmath>
using namespace std;

int main()
{
  int64_t a;
  double b;
  cin>>a>>b;
  #if 1
  int64_t b2=(int64_t)llround(b*100);
  #else
  int64_t b2=(int64_t)(b*100.0+0.5);
  #endif
    cout<<a*b2/100<<endl;
  
}

Measured memory_bytes: 3720
import java.util.*;
 
public class Main{
    public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
   
    int A = sc.nextInt();
    int B = sc.nextInt();
    
    //Aが1の場合
    if(A == 1){
      if(B == 2){
      	System.out.println(3);
      }else{
        System.out.println(2);
      }
    }else if(A == 2){
      //Aが２の場合
      if(B == 1){
      	System.out.println(3);
      }else{
        System.out.println(1);
      }
    }else{
      //それ以外(Aが３の場合)
      if(B == 1){
      	System.out.println(2);
      }else{
        System.out.println(1);
      }
    }
      

  }
      
 }

Measured memory_bytes: 23124
a_1 = list(map(int, input().split()))
a_2 = list(map(int, input().split()))
a_3 = list(map(int, input().split()))
a = [a_1, a_2, a_3]
n = int(input())
for i in range(n):
    number = int(input())
    for j in range(3):
        if a_1[j] == number:
            a_1[j] = 0
            break
        elif a_2[j] == number:
            a_2[j] = 0
            break
        elif a_3[j] == number:
            a_3[j] = 0
            break
if (a[0][0]+a[1][1]+a[2][2])*(a[0][2]+a[1][1]+a[2][0])*(a[0][0]+a[1][0]+a[2][0])*(a[0][1]+a[1][1]+a[2][1])*(a[0][2]+a[1][2]+a[2][2])*(a[0][0]+a[0][1]+a[0][2])*(a[1][0]+a[1][1]+a[1][2])*(a[2][0]+a[2][1]+a[2][2]) == 0:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3064
#include <stdio.h>
#include <stdlib.h>
int main()
{   int n,i;
   char s[200],g[200];
scanf("%d",&n);
scanf("%s %s",s,g);
for(i=0;i<n;i++)
{  printf("%c%c",s[i],g[i]);

}

    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <stdio.h>

using namespace std;

struct Dice{

	int u;	int w;	int s;	int e;	int n;	int d;
	
	Dice (int d1, int d2, int d3, int d4, int d5, int d6)
		{u = d1; s = d2; e = d3; w = d4; n = d5; d = d6;}
	
	Dice (int *num){
		u = num[0]; s = num[1]; e = num[2];
		w = num[3]; n = num[4]; d = num[5];}
	
	Dice ()
		{u = 1; s = 2; e = 3; w = 4; n = 5; d = 6;}

	void rotate(char *direction){
		int dam = 0;
		for (int i = 0; direction[i] != '\0'; i++){
			switch (direction[i]){
			case 'E':
				dam = e;
				e = u; u = w; w = d; d = dam;
				break;
			case 'N':
				dam = n;
				n = u; u = s; s = d; d = dam;
				break;
			case 'S':
				dam = s;
				s = u; u = n; n = d; d = dam;
				break;
			case 'W':
				dam = w;
				w = u; u = e; e = d; d = dam;
				break;
			default:
				break;
			}
		}
	}	
	
	void display(char direction){
		switch (direction){
			case 'E': printf("%d\n",e); break;
			case 'N': printf("%d\n",n); break;
			case 'S': printf("%d\n",s); break;
			case 'W': printf("%d\n",w); break;
			case 'U': printf("%d\n",u); break;
			case 'D': printf("%d\n",d); break;
			default: break;
		}
	}
};


int main(){
	int num[6];
	for (int i = 0; i < 6; i++)cin >> num[i];
	Dice d = num;
	
	char s[100];
	cin >> s;
	d.rotate(s);
	d.display('U');
	return 0;
}

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

int main(){
    int a,b,x;
    cin >> a >> b >> x;
    if(x%500!=0){
        x += 500-x%500;
    }

    if(x<=500){
        cout << min(a,b) << endl;
    }else{
        int twice_b(b*2);
        int ans(0);
        ans += x/1000*min(a,twice_b);
        x -= x/1000*1000;

        ans += x/500*b;

        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 3112
import sys
stdin = sys.stdin

mod = 10**9 + 7

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))

n = ni()
ans = 0
for m in range(1, n+1, 2):
    div = set()
    for i in range(1, int(m**0.5)+1):
        if m % i == 0:
            div.add(i)
            div.add(m//i)
    if len(div) == 8:
        ans += 1
print(ans)



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

int n;
std::vector<std::pair<int, int> > ans;
int main() {
	scanf("%d", &n);
	if (n & 1) {
		for (int i = 1; i < n; ++i) {
			ans.emplace_back(i, n);
		}
		--n;
	}
	for (int i = 1; i <= n; ++i) {
		for (int j = i + 1; j <= n; ++j) {
			if (i + j != n + 1) {
				ans.emplace_back(i, j);
			}
		}
	}
	printf("%d\n", static_cast<int>(ans.size()));
	for (auto p : ans) {
		printf("%d %d\n", p.first, p.second);
	}
}

Measured memory_bytes: 3900
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<n;i++)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define ALL(a) a.begin(),a.end()
int main()
{
    char a;
    cin >> a;
    cout << static_cast<char>(a+1) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = ((int)(n)-1); i >= 0; i--)
#define all(x) (x).begin(),(x).end()
 
using namespace std;
using ll = long long;
 
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; }

struct edge { int to; int cost; };
 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> P;
 
const int INF = 1e9;
const int MOD = 1e9+7;
const double EPS = 1.0e-10;
const double PI = acos(-1.0);
 
const int mx4[] = {0,1,0,-1};
const int my4[] = {1,0,-1,0};
const int mx8[] = {0,1,1,1,0,-1,-1,-1};
const int my8[] = {1,1,0,-1,-1,-1,0,1};

int n,m;
int c[30];

int main(){
	cin >> n >> m;
	rep(i,m) cin >> c[i];
	
	int dp[60010];
	rep(i,60010) dp[i] = INF;
	dp[0] = 0;
	for(int i = 0; i < n; i++){
		if(dp[i] != INF){
			for(int j = 0; j < m; j++){
				chmin(dp[i+c[j]],dp[i]+1);
			}
		}
	}
	cout << dp[n] << endl;
	return 0;
}


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

int main() {
  double W, H, X, Y;
  cin >> W >> H >> X >>Y;
  cout << fixed << setprecision(10) << (W * H) / 2;
  cout << " ";
  if (W / 2 == X && H / 2 == Y) {
    cout << 1;
  }
  else {
    cout << 0;
  }
}

Measured memory_bytes: 256
def primefact(n):
    l=[]
    if n%2==0:
        while n%2==0:
            n=n//2
        l.append(2)
    for i in range(3,int(n**0.5)+1,2):
        if n%i==0:
            while n%i==0:
                n=n//i
            l.append(i)
    if n>2:
        l.append(n)
    return l

n=int(input())
c=0
a=(primefact(n))
for i in a:
    x=i
    while n%x==0:
        n=n//x
        c+=1
        x=x*i
print(c)
        


Measured memory_bytes: 9464
import fractions
import math
 
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)
 
 
n, m = list(map(int, input().split()))
a = list(map(lambda x: int(x) // 2, input().split()))
lcm_all = 1
for e in a:
    lcm_all = lcm(lcm_all, e)
    if (lcm_all // e) % 2 == 0:
        print(0)
        exit()
print(math.ceil((m // lcm_all) / 2))


Measured memory_bytes: 89708
#include <stdio.h>
#include <math.h>

int main(){
  int n, a[10000], count, i ,j;
  
  scanf("%d" ,&n);
  for(i = 0; i < n; i++){
    scanf("%d" ,&a[i]);
    if(a[i] == 2){
      count++;
      continue;
    }
    else if(a[i] < 2 || a[i] % 2 == 0) continue;
    j = 3;
    while(j <= sqrt(a[i])){
      if(a[i] % j == 0){
        j = 1;
        break;
      }
      j += 2;
    }
    if(j == 1) continue;
    count++;
  }
  printf("%d\n" ,count);
  return 0;
}

Measured memory_bytes: 628
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int> >;
#define rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define erep(i,container) for (auto i : container)
#define irep(i, n)        for(int i = n-1; i >= (int)0; i--)
#define rrep(i,m,n) for(int i = m; i < (int)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define all(x) (x).begin(),(x).end()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define itn int
#define mp make_pair
#define sum accumulate
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
typedef long long ll;
const int INF = 2000000000;
const ll INF64 = 9223372036854775806ll;
const ll MOD = 1000000007LL;
/*メモ XOR問題のまとめ
性質 1「交換則、結合則が成り立つ」
　　 2「a xor a = 0」
　　 3「ある数xのb番目のビットが1である <=> x mod 2^(b+1) ≧ 2^b」
　　 4「0≦aのとき、4a, 4a+1, 4a+2, 4a+3のxor和は0」
方針 
!!!!!1「xor計算は各ビットで独立なので別々に計算」
　　 2「trieを使ったxorの最大最小探索がある解説」
・しゃくとり法は[ｌ,r)で考えるとわかりやすいよ！
*/
int main(){
    int n;
    std::cin >> n;
    std::vector<pair<int,string>> a;
    std::vector<string> dum(n);
    rep(i,n)std::cin >> dum[i];
    
    sort(all(dum));
    a.pb(mp(1,dum[0]));
    rep(q,n-1){
        string s;
        s=dum[q+1];
        //std::cout << s << std::endl;
        int i=a.size()-1;
        //std::cout << i << std::endl;
        if(a[i].se==s){
            a[i].fi++;
        }
        else{
            a.pb(mp(1,s));
        }
    }
    
    //std::cout << 11 << std::endl;
    sort(all(a),greater<pair<int,string>>());
    std::vector<string > ans;
    int v=a[0].fi;
    //std::cout << v << std::endl;
    rep(i,a.size()){
   //     std::cout << a[i].se << std::endl;
        if(a[i].fi==v)ans.pb(a[i].se);
    }
 //  std::cout << 123 << std::endl;
    sort(all(ans));
    rep(i,ans.size()){
        std::cout << ans[i] << std::endl;
    }
    
    
}

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

int main(void){
	int a,b,c,i,j = 0;
	cin >> a >> b >> c;

	for( i = a;i <= b;i++){
		if( c % i == 0){
			j++;
		}
	}
	cout << j <<endl;
	return 0;
}

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

int saitan[100000] = {};

int keisan(int okane, int kaisuu) {

	if (okane < 6) return kaisuu + okane;
	if (okane == 123456) return 123456;

	int saishou6 = 100000;
	rep(i, 7) {
		int kari = okane - pow(6, i);
		if (kari >= 0 && saishou6 > kari) {
			saishou6 = kari;
		}
		else if (kari < 0) break;
	}
	int saishou9 = 100000;
	rep(i, 6) {
		int kari = okane - pow(9, i);
		if (kari >= 0 && saishou9 > kari) {
			saishou9 = kari;
		}
		else if (kari < 0) break;
	}
	int test6, test9;
	if (saitan[saishou6] != 0 && saitan[saishou6] <= kaisuu + 1) test6 = 123456;
	else {
		saitan[saishou6] = kaisuu + 1;
		test6 = keisan(saishou6, kaisuu + 1);
	}
	if (saitan[saishou9] != 0 && saitan[saishou9] <= kaisuu + 1) test9 = 123456;
	else {
		saitan[saishou9] = kaisuu + 1;
		test9 = keisan(saishou9, kaisuu + 1);
	}
	return min(test6, test9);
}

int main() {
	//おまじない
	cin.tie(0);
	ios::sync_with_stdio(false);


	int N;
	cin >> N;

	cout << keisan(N, 0) << "\n";

	Would you please return 0;
}

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

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

  vector<int> L,R;
  int inputa,inputb;
  for (int i = 0; i < M; ++i) {
    cin >> inputa;
    cin >> inputb;
    L.push_back(inputa);
    R.push_back(inputb);
  }

  int holda = 0;
  int holdb = N;

  for (int i = 0; i < M; ++i){
    if(L.at(i)>holda) holda = L.at(i);
    if(R.at(i)<holdb) holdb = R.at(i);
  }

  if(holdb<holda) cout << 0 << endl;

  else cout << holdb - holda +1 << endl;
}

Measured memory_bytes: 1276
#include <vector>
#include <numeric>
#include <utility>
#include <cassert>
#include <functional>
#include <stack>

template<typename T>
struct PotentializedUnionFind {
public:
	using value_type = T;
	using const_reference = const value_type &;
	using size_type = std::size_t;
	using F = std::function<T(T, T)>;
	
	PotentializedUnionFind(size_type n, const F &f, const_reference id_elem)
			: n(n), f(f), id_elem(id_elem), size_(n, 1), val(n, id_elem) {
		par.resize(n);
		std::iota(par.begin(), par.end(), 0);
	}
	
	size_type size(size_type x) { return size_[find(x)]; }
	
	value_type get(size_type x) {
		find(x);
		if (par[x] == x) return val[x];
		return f(val[par[x]], val[x]);
	}
	
	size_type add(const_reference v) {
		size_.emplace_back(1);
		par.emplace_back(n);
		val.emplace_back(v);
		return n++;
	}
	
	size_type find(size_type x) {
		assert(x < n);
		std::stack<size_type> stk;
		stk.push(x);
		while (par[stk.top()] != stk.top()) stk.push(par[stk.top()]);
		
		size_type r = stk.top();
		stk.pop();
		bool r_child = true;
		while (!stk.empty()) {
			const size_type &t = stk.top();
			if (!r_child) val[t] = f(val[par[t]], val[t]);
			par[t] = r;
			r_child = false;
			stk.pop();
		}
		return r;
	}
	
	void link(size_type p, size_type x) {
		assert(par[x] == x);
		par[x] = p;
		size_[find(p)] += size_[x];
	}
	
	bool issame(size_type x, size_type y) { return find(x) == find(y); }
	
private:
	size_type n;
	value_type id_elem;
	F f;
	std::vector<size_type> size_, par;
	std::vector<value_type> val;
};


#include <cstdio>

int main() {
	int N, M;
	while(scanf("%d %d", &N, &M), N && M) {
		PotentializedUnionFind<int> puf(N, [](int a, int b){ return a + b; }, 0);
		for (int i = 0; i < M; ++i) {
			char c;
			int a, b;
			scanf(" %c %d %d", &c, &a, &b);
			--a; --b;
			
			if (c == '!') {
				int w;
				scanf("%d", &w);
				if (!puf.issame(a, b)) {
					int u = puf.add(w - puf.get(b));
					puf.link(a, u);
					puf.link(u, puf.find(b));
				}
			}
			else {
				if (puf.issame(a, b)) printf("%d\n", puf.get(b) - puf.get(a));
				else puts("UNKNOWN");
			}
		}
	}
	return 0;
}



Measured memory_bytes: 6884
// Name: Numeral System
// Level: 2
// Category: 文字列
// Note:

/**
 * MCXIから数値への変換は、先頭から読んでいって
 * ・数字だったらもう1文字読み込む
 * ・文字だったら係数1として扱う
 * というルールで変換すればよい。
 *
 * 数値からMCXIへの変換は、数値を10進法の文字列に直すやり方と同様にできる。
 *
 * オーダーは O(NS)。
 * ただしSは1行あたりの最大文字列長。
 */
#include <iostream>
#include <string>
#include <cctype>
#include <cassert>

using namespace std;

int from_mcxi(const string &s) {
    int res = 0;
    for(auto it = begin(s); it != end(s); ) {
        int coef = 1;
        if(isdigit(*it)) {
            coef = *it - '0';
            ++it;
        }
        char ord = *it++;
        switch(ord) {
            case 'm':
                res += 1000 * coef;
                break;
            case 'c':
                res += 100 * coef;
                break;
            case 'x':
                res += 10 * coef;
                break;
            case 'i':
                res += 1 * coef;
                break;
            default:
                assert(false);
        }
    }
    return res;
}

string to_mcxi(int v) {
    int ord = 1000;
    string res = "";
    while(ord > 0) {
        int coef = v / ord;
        if(coef > 0) {
            if(coef > 1) {
                res += to_string(coef);
            }
            res += ord == 1000 ? 'm' : ord == 100 ? 'c' : ord == 10 ? 'x' : 'i';
        }
        v %= ord;
        ord /= 10;
    }
    return res;
}

bool solve() {
    int N;
    if(!(cin >> N)) return false;
    if(!N) return false;

    while(N--) {
        string a, b;
        cin >> a >> b;
        cout << to_mcxi(from_mcxi(a) + from_mcxi(b)) << endl;
    }
    return true;
}

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

    while(solve()) ;
    return 0;
}

Measured memory_bytes: 1248
//config = { input: 'tmp', newline: '\r\n' }; // win
config = { input: '/dev/stdin', newline: '\n' }; // linux

A = require('fs').readFileSync(config.input, 'ascii')
  .split(config.newline, 2);
A = A[1].split(' ');

stable = [].concat(A);
stableSort(stable);

bubble = [].concat(A);
bubbleSort(bubble);
console.log(bubble.join(' '));
console.log(equal(bubble, stable) ? 'Stable' : 'Not stable');

selection = [].concat(A);
selectionSort(selection);
console.log(selection.join(' '));
console.log(equal(selection, stable) ? 'Stable' : 'Not stable');

function bubbleSort(C) {
  var i, j, tmp;
  for (i in C) {
    for (j = C.length - 1; j > i; j--) {
      if (C[j][1] < C[j-1][1]) {
        tmp = C[j];
        C[j] = C[j-1];
        C[j-1] = tmp;
      }
    }
  }
}

function selectionSort(C) {
  var i, minj, j, tmp;
  for (i in C) {
    minj = i;
    for (j = i; j < C.length; j++) {
      if (C[j][1] < C[minj][1])
        minj = j;
    }
    tmp = C[i];
    C[i] = C[minj];
    C[minj] = tmp;
  }
}

function stableSort(A) {
  var res, i, j;
  res = [];
  for (i = 1; i <= 9; i++) {
    for (j in A) {
      if (A[j][1] === String(i)) res.push(A[j]);
    }
  }
  for (i in A) A[i] = res[i];
}

function equal(A, B) {
  var i;
  for (i in A)
    if (A[i] !== B[i]) return false;
  return true;
}

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

int n, m;
vector<int> a, b;
vector<long long> ans;
class UnionFind{
public:
	vector<int> Parent;
	vector<int> Rank;
	vector<int> Size;
	UnionFind(int n){
		++n;
		Parent.resize(n, 0);
		Rank.resize(n, 0);
		Size.resize(n, 1);
		for(int i=0; i<n; ++i)
			Parent[i] = i;
	}

	int find(int x){
		if(Parent[x] == x) return x;
		return Parent[x] = find(Parent[x]);
	}

	void unite(int x, int y){
		x = find(x);
		y = find(y);
		if(x == y) return;
		if(Rank[x] < Rank[y]){
			Parent[x] = y;
			Size[y] += Size[x];
		}else{
			Parent[y] = x;
			Size[x] += Size[y];
			if(Rank[x] == Rank[y]) ++Rank[x];
		}
	}

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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> n >> m;
	for(int i=0; i<m; ++i){
		int s, t;
		cin >> s >> t;
		a.push_back(s);
		b.push_back(t);
	}
	UnionFind uf(n);
	long long tmp = (long long)n * (n-1) / 2;
	ans.push_back(tmp);
	for(int i=m-1; i>=0; --i){
		if(uf.find(a[i]) != uf.find(b[i]))
			tmp -= (long long)uf.Size[uf.find(a[i])] * uf.Size[uf.find(b[i])];
		uf.unite(a[i], b[i]);
		ans.push_back(tmp);
	}
	for(int i=m-1; i>=0; --i)
		cout << ans[i] << "\n";
}

Measured memory_bytes: 4208