akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <bitset>

#define INPUT_FROM_FILE (0) 
#if INPUT_FROM_FILE
#include <fstream>
#endif

int main(){
	std::bitset<64> flag;
	std::vector<std::bitset<64> > masks;
	int q;
	int com, n, m, k, b;

#if INPUT_FROM_FILE
	std::ifstream ifs("test.txt");
	//FILE *fp = fopen("test.txt", "r");
#endif

#if INPUT_FROM_FILE
	ifs >> n;
#else
	std::cin >> n;
#endif
	masks.resize(n);
	for(int i = 0; i < n; i++){
#if INPUT_FROM_FILE
		ifs >> k;
#else
		std::cin >> k;
#endif
		for(int j = 0; j < k; j++){
#if INPUT_FROM_FILE
			ifs >> b;
#else
			std::cin >> b;
#endif
			masks[i].set(b);
		}
	}

#if INPUT_FROM_FILE
	ifs >> q;
#else
	std::cin >> q;
#endif

	for(int i = 0; i < q; i++){
#if INPUT_FROM_FILE
		ifs >> com >> m;
#else
		std::cin >> com >> m;
#endif
		if(com == 0){
			if(flag.test(m)){
				std::cout << "1" << std::endl;
			}
			else{
				std::cout << "0" << std::endl;
			}
		}
		else if(com == 1){
			flag = (flag | masks[m]);
		}
		else if(com == 2){
			for(int i = 0; i < 64; i++){
				if(masks[m].test(i)){
					flag.reset(i);
				}
			}
		}
		else if(com == 3){
			for(int i = 0; i < 64; i++){
				if(masks[m].test(i)){
					flag.flip(i);
				}
			}
		}
		else if(com == 4){
			bool is_all = true;

			for(int i = 0; i < 64; i++){
				if(masks[m].test(i) && !flag.test(i)){
					is_all = false;
					break;
				}
			}
			
			if(is_all){
				std::cout << "1" << std::endl;
			}
			else{
				std::cout << "0" << std::endl;
			}
		}
		else if(com == 5){
			bool is_any = false;

			for(int i = 0; i < 64; i++){
				if(masks[m].test(i) && flag.test(i)){
					is_any = true;
					break;
				}
			}
			
			if(is_any){
				std::cout << "1" << std::endl;
			}
			else{
				std::cout << "0" << std::endl;
			}
		}
		else if(com == 6){
			bool is_none = true;

			for(int i = 0; i < 64; i++){
				if(masks[m].test(i) && flag.test(i)){
					is_none = false;
					break;
				}
			}
			if(is_none){
				std::cout << "1" << std::endl;
			}
			else{
				std::cout << "0" << std::endl;
			}
		}
		else if(com == 7){
			int count = 0;

			for(int i = 0; i < 64; i++){
				if(masks[m].test(i) && flag.test(i)){
					count++;
				}
			}
			std::cout << count << std::endl;
		}
		else if(com == 8){
			std::bitset<64> result;

			for(int i = 0; i < 64; i++){
				if(masks[m].test(i) && flag.test(i)){
					result.set(i);
				}
			}
			std::cout << result.to_ulong() << std::endl;
		}
	}
   
#if INPUT_FROM_FILE
	//fclose(fp);
#endif
	return 0;
}


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

public class Main{
	public static void main(String[] args)throws IOException{
		InputStreamReader isr = new InputStreamReader(System.in);
		BufferedReader reader = new BufferedReader(isr);
		Main app = new Main();
		String string;
		
		int n, r, p, c;
		while(true){
			string = reader.readLine();
			n = Integer.valueOf(string.split(" ")[0]);
			r = Integer.valueOf(string.split(" ")[1]);
			if((n | r) == 0) break;
			
			int card[] = new int[n];
			for(int i = 0; i < n; i++) card[i] = n - i;
			
			for(int i = 0; i < r; i++){
				string = reader.readLine();
				p = Integer.valueOf(string.split(" ")[0]) - 1;
				c = Integer.valueOf(string.split(" ")[1]);
				
				card = app.shuffle(card, p, c);
			}
			System.out.println(card[0]);
		}
		reader.close();
	}
	
	public int[] shuffle(int card[], int p, int c){
		int n = card.length;
		int res[] = new int[n];
		
		for(int i = 0; i < c; i++){
			res[i] = card[p + i];
		}
		for(int i = 0; i < p; i++){
			res[c + i] = card[i];
		}
		for(int i = p + c; i < n; i++){
			res[i] = card[i];
		}
		
		return res;
	}
}


Measured memory_bytes: 29460
# N = int(input())
N,M = map(int,input().split())
A_list = sorted(list(map(int,input().split())),reverse=True)
#print(A_list)
A_sum = sum(A_list)
is_selected = 1 / (4 * M) * A_sum
#print(is_selected)
for i in range(M):
    if A_list[i] >= is_selected:
        continue
    else:
        print('No')
        exit(0)
print('Yes')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define rep(i, r) for(int i = 0; i < r; i++)
#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define ll long long
#define pb push_back

int main()
{
    fastIO
    ll x, t = 1;
    ll cur_amount = 100;
    cin >> x;

    for(; ;t++)
    {
        long double val = (1.0 * cur_amount) * (1 + 0.01);
        cur_amount = (ll)val;
        if(cur_amount >= x)
        {
//            cout << amt << endl;
            cout << t << endl;
            break;
        }
    }

    return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
 
#define int long long
 
#define pii pair<int, int>
 
#define x1 x1228
#define y1 y1228
 
#define left left228
#define right right228
 
#define pb push_back
#define eb emplace_back
 
#define mp make_pair                                                                
                                                                                                                                        
#define ff first                                                                  
#define ss second   
 
#define matr vector<vector<int> > 
 
#define all(x) x.begin(), x.end()
 
 
using namespace std;
typedef long long ll; 
typedef long double ld; 
                                                                                                   
const int maxn = 3e5 + 7, mod = 998244353, inf = 1e18, MAXN = 1e6 + 7;
const double eps = 1e-9;
mt19937 rnd(time(0));
int n; 
int a[maxn];
int val[maxn]; 
 
void solve() { 
    cin >> n;    
    for (int i = 0; i < n; ++i) {
        val[i] = inf; 
    } 
    for (int i = 0; i < n - 1; ++i) {
        cin >> a[i]; 
        val[i] = min(val[i], a[i]); 
        val[i + 1] = min(val[i + 1], a[i]); 
    }
    int ans = 0; 
    for (int i = 0; i < n; ++i) {
        ans += val[i]; 
    }
    cout << ans; 
}                                
   
signed main() {
#ifdef LOCAL
    freopen("TASK.in", "r", stdin);
    freopen("TASK.out", "w", stdout);
#else 
    
#endif // LOCAL
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(20); 
    cout << fixed; 
    int t = 1; 
    for (int i = 0; i < t; ++i) {              
        solve();
    }
    return 0;
}  

Measured memory_bytes: 2304
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <set>
#include <queue>
#include <map>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<ld> vld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define INF ((int)1e9)
#define INFLL ((ll)1e18)
#define MOD (1000000007LL)

class UnionFind
{
public:
    explicit UnionFind(int N)
    {
        m_par.reserve(N);
        for (int n = 0; n < N; ++n) {
            m_par.push_back(n);
        }
        m_dist = vll(N);
    }
    int Root(int n)
    {
        if (m_par[n] == n) return n;
        while (m_par[n] != m_par[m_par[n]]) {
            m_dist[n] += m_dist[m_par[n]];
            m_par[n] = m_par[m_par[n]];
        }
        return m_par[n];
    }
    bool Unite(int n, int m, ll d)
    {
        if (Root(n) == Root(m)) {
            if (m_dist[m] - m_dist[n] == d)  return true;
            else return false;
        }
        m_dist[Root(n)] = m_dist[m]-d;
        if (n != Root(n)) m_dist[Root(n)] += -m_dist[n];
        m_par[Root(n)] = Root(m);
        return true;
    }
    bool Same(int n, int m)
    {
        return Root(n) == Root(m);
    }
    vi m_par;
    vll m_dist;
};

int main(int argc, const char * argv[]) {
    ios_base::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    UnionFind UF(N);
    for (int m = 0; m < M; ++m) {
        int l, r;
        ll d;
        cin >> l >> r >> d;
        --l; --r;
        if (!UF.Unite(l, r, d)) {
            cout << "No\n";
            return 0;
        }
    }
    for (int n = 0; n < N; ++n) {
        UF.Root(n);
        if (abs(UF.m_dist[n]) > 1e9) {
            cout << "No\n";
            return 0;
        }
    }
    cout << "Yes\n";

    return 0;
}


Measured memory_bytes: 1408
ans=[]
n,m=map(int,input().split())
while n!=0 and m!=0:
    a=[0]*n
    a=list(input().split())
    for i in range(n):
        a[i]=int(a[i])
    max=0
    for i in range(n):
        for j in range(n):
            if i<j:
                tmp=a[i]+a[j]
                if tmp>max and tmp<=m:
                    max=tmp
                else: pass
            else: pass
    ans.append(max)
    n,m=map(int,input().split())
for i in range(len(ans)):
    if ans[i]==0:
        print("NONE")
    else:
        print(ans[i])
    


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

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

using namespace std;

/////////////////////////////////////////////////////
ll N,U,V;
vector<ll> ABv[101010];
ll Ut[101010], Vt[101010];

ll i, j, k, ans;
void dfs(ll a,ll p,ll d,ll *dt){
    dt[a] = d;
    ll i;
    fornum(i,0,ABv[a].size()){
        ll b = ABv[a][i];
        if(b==p)
            continue;
        dfs(b, a, d + 1, dt);
    }
}
int main(){
    scanf("%lld%lld%lld", &N,&U,&V);
    fornum(i,1,N){
        ll a, b;
        scanf("%lld%lld", &a, &b);
        ABv[a].push_back(b);
        ABv[b].push_back(a);
    }
    dfs(U, -1, 0, Ut);
    dfs(V, -1, 0, Vt);
    queue<pll> q;
    q.push({U,-1});
    ans = 0;
    while(q.size()){
        pll qa = q.front();
        q.pop();
        ans = max(ans, Vt[qa.first] - 1);
        if(Ut[qa.first]>=Vt[qa.first])
            continue;
        fornum(i,0,ABv[qa.first].size()){
            ll b = ABv[qa.first][i];
            if(b==qa.second)
                continue;
            q.push({b, qa.first});
        }
    }
    printf("%lld", ans);
    return 0;
}

Measured memory_bytes: 13952
using System;
using System.Collections.Generic;
namespace _110c
{
    class Program
    {
        static void Main(string[] args)
        {
            string S = Console.ReadLine();
            string T = Console.ReadLine();
            var hs = new Dictionary<char,int>();
            var ht = new Dictionary<char,int>();
            string ans = "Yes";
            for(int i = 0; i < S.Length;i++){
                if(!hs.ContainsKey(S[i])){
                    hs.Add(S[i],1);
                }else{
                    hs[S[i]]++;
                }
                if(!ht.ContainsKey(T[i])){
                    ht.Add(T[i],1);
                }else{
                    ht[T[i]]++;
                }
                if(hs[S[i]]!=ht[T[i]]){
                    ans = "No";
                }
            }
            Console.WriteLine(ans);
        }
    }
}

Measured memory_bytes: 14304
#include<stdio.h>

#define SIZE 20005

int get_area(char* str, int len, int s, int t){
  int depth = 0, i;
  double res = 0;
  for(i = s; i < t; i++){
    if(str[i] == '/'){
      res += (double)depth-0.5;
      depth--;
    }
    if(str[i] == '\\'){
      res += (double)depth+0.5;
      depth++;
    }
    if(str[i] == '_') res += depth;
  }
  return res;
}

int main(){

  char str[SIZE];
  int height[SIZE] = {0}, vec[SIZE] = {0};
  scanf("%s",str);
  int len, h = 0;
  for(len = 0; ; len++){
    height[len] = h;
    if(str[len] == '/') h++;
    if(str[len] == '\\') h--;
    if(str[len] == '\0') break;
  }

  int pos = 0, cur = 0;
  while(pos < len){
    while(str[pos] != '\\' && pos < len) pos++;
    int nex = pos+1;

    while(nex <= len && height[nex] != height[pos]) nex++;
    if(nex <= len){
      vec[cur++] = get_area(str, len, pos, nex);
      pos = nex;
    }else{
      pos++;
    }
  }
  
  int i,sum = 0;
  for(i = 0; i < cur; i++) sum += vec[i];
  printf("%d\n%d", sum, cur);
  for(i = 0; i < cur; i++) printf(" %d", vec[i]);
  printf("\n");
  return 0;
}

Measured memory_bytes: 728
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define int long long
#define inf 1000000007
#define LINF 100000000000000007LL
using namespace std;
typedef pair<int,int> P;
struct edge{int to, cost; };
int n;
vector< edge > g[114514];
int d[114514];
void dijkstra( int s ){
	priority_queue< P, vector<P>, greater<P> > que;
	for(int i=1;i<=n;i++){
		d[i] = LINF;
	}
	d[s] = 0;
	que.push( P(0,s) );
	while( !que.empty() ){
		P p = que.top(); que.pop();
		int v = p.second;
		if( d[v] < p.first ) continue;
		for(int i=0;i<g[v].size();i++){
			edge e = g[v][i];
			if( d[e.to] > d[v] + e.cost ){
				d[e.to] = d[v] + e.cost;
				que.push(P(d[e.to],e.to));
			}
		}
	}
}
signed main(){
	cin>>n;
	int m;
	cin>>m;
	for(int i=0;i<m;i++){
		int l,r,c;
		cin>>l>>r>>c;
		g[l].pb( (edge){r,c} );
	}
	for(int i=2;i<=n;i++){
		g[i].pb( (edge){i-1,0} );
	}
	dijkstra(1);
	if( d[n] == LINF )d[n]=-1;
	cout<<d[n]<<endl;
	return 0;
}

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

int main(){
  string S,T,U;
  int A,B;
  cin >> S>>T;
  cin >> A>>B;
  cin >> U;
  if(S==U){
    A--;
  }else{
    B--;
  }
  cout << A <<" "<<B<< endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <functional>
#include <numeric>
#include <cassert>
#include <algorithm>

#define INF 100000000
#define mod 1000000007
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using p = pair<int, int>;


int main() {
    ll x,ans,a,b,c,temp1,temp2;
    ans = 0;
    a = 1;
    b = 1;
    c = 1;
    cin >> x;
    rep(i,x){
        a = (a*10) % mod;
        b = (b*8) % mod;
        c = (c*9)%mod;
    }
    
    temp1 = a-c;
    if(temp1<0){
        temp1 += mod;
    }
    temp1 = (temp1 *2)%mod;
    temp2 = a-b;
    if(temp2<0){
        temp2 += mod;
    }
    temp2 = temp2 %mod;
    ans = temp1 - temp2;
    if(ans<0){
        ans += mod;
    }
    ans = ans%mod;
    if (x == 1){
        ans = 0;
    }
    
    
    cout << (ans) << endl;
}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define pb push_back
#define MOD 1000000007
int a[100010];
int dp[100010];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n=0;
    cin>>n;
    for(int i=0;i<n;++i)
        cin>>a[i];
    dp[0]=0;
    dp[1]=abs(a[1]-a[0]);
    for(int i=2;i<n;++i)
    {
        dp[i]=min(dp[i-1]+abs(a[i-1]-a[i]),dp[i-2]+abs(a[i-2]-a[i]));
    }
    cout<<dp[n-1]<<endl;
}


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

int main() {
  int N;
  long long p = 1;
  cin >> N;

  int mod = 1000000007;

  for (int i = 1; i <= N; i++) {
    p = (p % mod) * (i % mod) % mod;
  }
  
  cout << p << endl;
  
  return 0;
}


Measured memory_bytes: 256
// AtCoder.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

// AtCoder.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//


#define _USE_MATH_DEFINES
#include<math.h>

//#include<cmath>

#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
#include<memory>



//#include "Ants.h"
using namespace std;
typedef long long ll;
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i,n) for(int i=0;i<n;i++)
#define show(s) cout<<s<<endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define LINF (1000000000000000000ll)
//typedef pair < int, int> P;
ll gcd(ll a, ll b) {//最大公約数を求める///最大公倍数a*b/gcd(a,b)
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcd(ll a, ll b) {//最小公倍数を求める　b=0のときaを返す
	if (b == 0) return a;
	return (a / gcd(a, b)) * b;
}
vector<int> divnum(ll num) {
	int dig;
	vector<int>p;
	while (num) {
		dig = num % 10;
		p.push_back(dig);
		num /= 10;
	}
	return p;
}
int digiter(ll num) {
	int dig;
	vector<int>p;
	while (num) {
		dig = num % 10;
		p.push_back(dig);
		num /= 10;
	}
	return p.size();
}
vector<int> convertstring(string s) {
	vector<int> d;
	ll n = s.size();
	rep(i, n) {
		d.push_back(s[i] - '0');
	}
	return d;
}
map< int64_t, int > prime_factor(int64_t n) {
	map< int64_t, int > ret;
	for (int64_t i = 2; i * i <= n; i++) {
		while (n % i == 0) {
			ret[i]++;
			n /= i;
		}
	}
	if (n != 1) ret[n] = 1;
	return ret;
}
vector<ll> divisor(ll n) {
	vector<ll>res;
	for (ll i = 1; i * i <= n; i++) {
		if (n % i != 0)continue;
		res.push_back(i);
		if (i * i != n)res.push_back(n / i);
	}
	return res;
}
ll MOD = 1000000007;

ll myPow(ll x, ll n, ll m) {
	if (n == 0)
		return 1;
	if (n % 2 == 0)
		return myPow(x * x % m, n / 2, m);
	else
		return x * myPow(x, n - 1, m) % m;
}
int N,A[200000];
int main()
{
	cin >> N;
	rep(i, N)cin >> A[i];
	int ans = A[0];
	rep(i, N) {
		ans=gcd(ans, A[i]);
	}
	cout << ans << endl;

}

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

int main () {

    int X;
    cin >> X;

    int ans = 1;
    for (int b = 2; b <= 1000; b++) {
        for (int p = 2;; p++) {
            int num = (int)pow(b, p);

            if (num > X) break;

            if (num > ans) {
                ans = num;
            }
        } 
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 384
n = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
maxcandy = 0

for i in range(n):
    candy = 0
    for j in range(i+1):
        candy += A[j]
    for k in range(i,n):
        candy += B[k]
    maxcandy = max(maxcandy,candy)

print(maxcandy)

Measured memory_bytes: 3188
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x1 = sc.nextInt();
		int y1 = sc.nextInt();
		int x2 = sc.nextInt();
		int y2 = sc.nextInt();

		int x = x2 - x1;
		int y = y2 - y1;

		int x3 = x2 - y;
		int y3 = y2 + x;
		int x4 = x1 - y;
		int y4 = y1 + x;
		System.out.println(x3 + " " + y3 + " " + x4 + " " + y4);
	}

}

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

using namespace std;

#define fread freopen("in.txt", "r", stdin)
#define fwrite freopen("out.txt", "w", stdout)

int main ()
{
    int n;

    scanf("%d", &n);
    while (1) {
        if (n > 0) n -= 1000;
        else break;
    }
    printf("%d\n", abs(n));

    return 0;
}

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

int main() {
  double A,B,H,M,R;
  
  cin>>A>>B>>H>>M;
  
  R=(30*H-5.5*M)*acos(-1)/180;
  double X;
  X=sqrt(A*A+B*B-2*A*B*cos(R));
  printf("%.16f", X);
}

Measured memory_bytes: 4188
#include<bits/stdc++.h>
#define int long long int
#define ldouble long double
#define vin vector<int>
#define rep(a,n) for(int i=(a);i<(n);i++)
#define INF (int)1000000007

//setprecision()<<

using namespace std;

void fin(int n,vin &a){
    rep(0,n){
        cin>>a.at(i);
    }
}

signed main(){
    typedef pair<int,int> P;
    string s;
    cin>>s;
    rep(0,s.size()){
        cout<<'x';
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int i,n,l[100001],r[100001],cnt=0;
  scanf("%d",&n);
  for(i=0;i<n;i++)scanf("%d %d",&l[i],&r[i]);  
  
  for(i=0;i<n;i++){
     cnt=cnt+r[i]-l[i]+1;
  }
  printf("%d",cnt);
}


Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<pair<ll, ll>>> vvpll;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

int main() {
    ll r, d, x;
    cin >> r >> d >> x;

    rep(i, 10) {
        x = r*x - d;
        out(x);
    }

    re0;
}

Measured memory_bytes: 256
import bisect
from collections import defaultdict
d = defaultdict(list)

N,M = map(int, input().split())
li = [list(map(int, input().split())) for i in range(M)]

for i in li:
  d[i[0]].append(i[1])
  
for s in d:
  d[s].sort()
  
for i in li:
  index = bisect.bisect_left(d[i[0]],i[1])
  print(str(i[0]).zfill(6) + str(index+1).zfill(6))

Measured memory_bytes: 42488
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

#define dump(x) cerr << #x << " = " << (x) << endl;
#define PB push_back
#define MP make_pair
#define ll long long

inline int toInt(string s)
{
    int v;
    istringstream sin(s);
    sin >> v;
    return v;
}
template <class T>
inline string toString(T x)
{
    ostringstream sout;
    sout << x;
    return sout.str();
}

int visited_depth[201];
int res = 0;
bool check_loop(vector<string> &s, int prev, int node, int n, int odd)
{
    visited_depth[node] = odd;
    bool ret = false;
    for (int i = 0; i < n; i++)
    {
        if (s[node][i] == '1')
        {
            if (i != prev)
            {
                if (visited_depth[i] != -1)
                {
                    if ((1-visited_depth[node]) != visited_depth[i])
                    {
                        return true;
                    }
                }
                else
                {
                    ret = ret || check_loop(s, node, i, n, 1 - odd);
                }
            }
        }
    }
    return ret;
}

int main()
{
    std::ios::sync_with_stdio(false);
    // check there's no loop
    int n;
    cin >> n;
    vector<string> s(n);
    int dist[n][n] = {};
    for (int i = 0; i < n; ++i)
    {
        visited_depth[i] = -1;
        cin >> s[i];
        for (int j = 0; j < n; ++j)
        {
            int tmp = s[i][j] - '0';
            if (tmp == 0)
            {
                if (i == j)
                {
                    dist[i][j] = 0;
                }
                else
                {
                    dist[i][j] = 1 << 29;
                }
            }
            else
            {
                dist[i][j] = 1;
            }
        }
    }
    if (check_loop(s, -1, 0, n, 0))
    {
        cout << -1 << endl;
        return 0;
    }

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

    int max_len = 0;
    for (int i = 0; i < n; ++i)
    {
        for (int j = 0; j < n; ++j)
        {
            max_len = max(max_len, dist[i][j]);
        }
    }
    cout << max_len + 1 << endl;
}

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

int main(){
    int n; cin>>n;
    vector<int> b(n-1);
    rep(i,n-1) cin>>b[i];
    vector<int> ans(n);
    ans[0]=b[0];
    for(int i=1;i<=n-2;i++){
       ans[i]=min(b[i],b[i-1]);
    }
    ans[n-1]=b[n-2];
    int sum=0;
    rep(i,n) sum+=ans[i];
    cout<<sum<<endl;
    return 0;
}

   


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

int top, S[1000];

int pop(){
  return S[top--];
}

void push(int x){
  S[++top] = x;
}

int main(){
  int a, b;
  top = 0;
  char s[100];

  while (scanf("%s", s) != EOF){
    if (s[0] == '+'){
      a = pop();
      b = pop();
      push(a+b);
    } else if (s[0] == '-') {
      b = pop();
      a = pop();
      push(a-b);
    } else if (s[0] == '*') {
      a = pop();
      b = pop();
      push(a*b);
    } else {
      push(atoi(s));
    }
  }

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

  return 0;
}



Measured memory_bytes: 2100
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define sci(x) scanf("%d",&x);
#define scd(x) scanf("%lf",&x);

int main()
{
    int n,r,ans;
    cin>>n>>r;
    if(n<10)
        ans=100*(10-n);
    else
        ans=0;
    cout<<ans+r<<endl;
}


Measured memory_bytes: 256
#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;
}
int main() {
	int a, b;
	cin >> a >> b;
	int s = b - a;
	int ans = 0;
	for (int i = 1; i <= s; i++) {
		ans = ans + i;
	}
	cout << ans - b;
}

Measured memory_bytes: 256
#include<iostream>
#include<fstream>
#include<math.h>
#include<algorithm>
#include<string>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<sstream>
#include<set>

using namespace std;

#define forn(i,n) for(int i=0;i<(int)(n); i++)
#define forsn(i,s,n) for(int i=(s);i<(int)(n); i++)
#define esta(x,v) (find((v).begin(),(v).end(),(x)) !=  (v).end())
#define index(x,v) (find((v).begin(),(v).end(),(x)) - (v).begin())
#define debug(x) cout << #x << " = "  << x << endl
#define pb push_back
#define mp make_pair

typedef long long tint;
typedef unsigned long long utint;
typedef long double ldouble;

typedef vector<int> vint;

int toNumber (string s)
{
	int Number;
	if ( ! (istringstream(s) >> Number) ) Number = 0; // el string vacio lo manda al cero
	return Number;
}

string toString (int number)
{
    ostringstream ostr;
    ostr << number;
    return  ostr.str();
}

int main (){
	tint n;
	cin>>n;
	set<int> se;
	map<int,int>m;
	forn(i, n){
		int p;
		cin>>p;
		se.insert(p);
		m[p]++;
	}
	int cant=0;
	for(map<int, int>::iterator it=m.begin(); it!=m.end(); it++){
		if((it->second)%2==0){
			cant+=1;
		}
	}
	if(cant%2==0)cout<<se.size()<<endl;
	else cout<<se.size()-1<<endl;
}


Measured memory_bytes: 9600
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    String M =sc.next();
    if(M.contains("AB")){System.out.println("Yes");}
    else if(M.contains("BA")){System.out.println("Yes");}
            else{System.out.println("No");}
  }
}


Measured memory_bytes: 23124
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <utility>
#include <iterator>
using namespace std;

int main() {
    int N; cin >> N;
    map<string, int> dict;
    while(N--) {
        string s; int x; cin >> s >> x;
        dict[s] += x;
    }
    vector<pair<string, int> > v;
    for(auto it : dict) {
        v.push_back(it);
    }
    sort(begin(v), end(v), [](pair<string, int> a, pair<string, int> b) {
            if(a.first.length() != b.first.length()) return a.first.length() < b.first.length();
            else return a.first < b.first;
            });
    for(auto it : v) {
        cout << it.first << ' ' << it.second << endl;
    }

}

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

#define pb         push_back

typedef long long ll;
const ll INF = 1000000000ll;
const ll MOD = 1000000007ll;
const double EPS = 1e-8;

int main(void) {
	//ios_base::sync_with_stdio(false);
	//cin.tie(0);
	
	int n5 = 0;
	int n7 = 0;

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

	if(a == 5){
		n5++;
	}else if(a == 7){
		n7++;
	}
	if(b == 5){
		n5++;
	}else if(b == 7){
		n7++;
	}
	if(c == 5){
		n5++;
	}else if(c == 7){
		n7++;
	}

	if(n5 == 2 && n7 == 1){
		puts("YES");
	}else{
		puts("NO");
	}

	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 ll long long
ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }    //最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }     //最小公倍数
using Graph = vector<vector<ll>>;
ll inf=300000000000000000;
const double PI = 3.14159265358979323846;
int n;
pair<pair<int,int>,int>solve(vector<pair<pair<int,int>,int>> &ma,vector<int> &a,int key){
  if(ma[key].first.first>=0)return ma[key];
  else{
    int s=0;
    pair<int,int> f=make_pair(a[key],key);
    rep(i,n){
      if(key&(1<<i)){
        pair<pair<int,int>,int> w=solve(ma,a,key-(1<<i));
        int c=w.first.first;
        int l=w.second;
        if(f.second!=w.first.second){
          if(c>f.first){
            s=f.first;
            f=make_pair(c,w.first.second);
          }
          else if(c>s){
            s=c;
          }
        }
        if(l>s){
          s=l;
        }
      }
    }
    ma[key]=make_pair(f,s);
    return make_pair(f,s);
  }
}
int main(){
  cin  >> n;
  int o=1;
  rep(i,n)o=o*2;
  vector<pair<pair<int,int>,int>> ma(o,make_pair(make_pair(-1,-1),-1));
  vector<int> a(o,-1);
  rep(i,o)cin >> a[i];
  ma[0]=make_pair(make_pair(a[0],0),-1);
  rep(i,n){
    int y=(1<<i);
    if(a[0]>a[y])ma[y]=make_pair(make_pair(a[0],0),a[y]);
    else ma[y]=make_pair(make_pair(a[y],y),a[0]);
  }
  solve(ma,a,o-1);
  int ans=0;
  rep(i,o-1){
    ans=max(ans,ma[i+1].first.first+ma[i+1].second);
    cout << ans << endl;
  }
}  


Measured memory_bytes: 7168
#include<stdio.h>
#include<math.h>
int main()
{
    double x1, x2, y1, y2, x, y, kyori;
  
    scanf(" %lf %lf %lf %lf", &x1, &y1, &x2, &y2);
  
    x = x2 - x1;
    y = y2 - y1;
  
    x = pow(x,2);
    y = pow(y,2);
  
    kyori = x + y;
  
    kyori = sqrt(kyori);
  
    printf("%f", kyori);
  
    return 0;
}
 

Measured memory_bytes: 652
#include<iostream>
using namespace std;
int main(){
	int n,i,cnt=0;
	char a[100];
	cin>>n;
	scanf("%s",a);
	for(i=0;i<n-2;i++){
		if(a[i]=='A'&&a[i+1]=='B'&&a[i+2]=='C'){
			cnt++;
		}
	}
	cout<<cnt;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
// Type alias
using ll=long long;
using ld=double;
 
using pi=pair<int,int>;
using pll=pair<ll,ll>;
using pld=pair<ld,ld>;
using ti3=tuple<int, int, int>;
 
using vi=vector<int>;
using vll=vector<ll>;
using vld=vector<ld>;
using vpi=vector<pi>;
using vpll=vector<ll>;
using vpld=vector<ld>;
using vti3=vector<ti3>;
 
// Constants
const double EPS = 1e-9;
const int inf = numeric_limits<int>::max();
 
// Macro
#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 REP(i,a,b) for(int i=int(a);i<int(b);++i)
#define RREP(i,a,b) for(int i=int(b-1);i>=int(a);--i)
#define SHOW(a) cout << #a << " = " << a << endl
#define ARR(a,n) for(int i=0;i<int(n);++i) cout << #a << "[" << i << "]" << " = " << a[i] << endl
 
#define ALL(a) a.begin(),a.end()
 
// Funtcions
ll pow(ll base, ll i, ll mod){
  ll a = 1;
  while(i){
    if (i & 1) {
      a *= base;
      a %= mod;
    }
    base *= base;
    base %= mod;
    i >>= 1;
  }
  return a;
}
ll gcd(ll a, ll b){
  while(b){
    ll c = a % b;
    a = b;
    b = c;
  }
  return a;
}
ll lcm(ll a, ll b){
  return a / gcd(a, b) * b;
}
 
 
void solve(){
  int N, M;
  cin >> N >> M;
  int A[105];
  rep(i, N) cin >> A[i];
  int sum = 0;
  rep(i, N) sum += A[i];

  sort(A, A+N, std::greater<int>());
  if(A[M-1] < sum / 4.0 / M)
    cout << "No";
  else
    cout << "Yes";
  cout << endl;
}
 
int main(){
  // FastIO
  //ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  solve();
  return 0;
}





















Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <limits>
#include <numeric>
#include <queue>
#include <set>
#include <bitset>
#include <map>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<long long> vll;
typedef queue<int, int> qii;
typedef pair<int, int> pii;

#define PI 3.14159265359
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repz(i,n) rep(i,0,n)

//int型を受け取ってその桁数を返す
int check_digits(int n) {
	int digits = 0;
	while (n != 0) {
		n /= 10;
		digits++;
	}
	return digits;
}

//int型を受け取ってその各桁の和を返す
int sum_digits(int n) {
	int sum=0;
	int N = n;
	while (N) {
		sum += N % 10;
		N /= 10;
	}
	return sum;
}


//最大公約数を返す関数
int gcd(int n, int m) {
	while (n != 0) {
		if (n < m) swap(n, m);
		n = n % m;
	}
	return m;
}


//2点間の距離を返す
float dis(int x1, int y1, int x2, int y2) {
	return sqrt(pow(abs(x1 - x2), 2) + pow(abs(y1 - y2), 2));
}



bool mm(int n) {
	if (n >= 1 && n <= 12) {
		return true;
	}
	else {
		return false;
	}
}

bool yy(int n) {
	if (n >= 0 && n <= 99) {
		return true;
	}
	else {
		return false;
	}
}

int main() {
	string s;
	cin >> s;
	int a = stoi(s.substr(0, 2));
	int b = stoi(s.substr(2, 2));

	if (mm(a) && mm(b))cout << "AMBIGUOUS " << endl;
	else if (yy(a) && mm(b))cout << "YYMM" << endl;
	else if (mm(a) && yy(b))cout << "MMYY" << endl;
	else cout << "NA" << endl;

	system("pause");
	return 0;
}


Measured memory_bytes: 504
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int dp[52][52][52][52];
void solve(int h, int w){
    for(auto &i : dp) for(auto &j : i) for(auto &k : j) for(auto &l : k) l = INF<int>;
    int tx, ty, kx, ky;
    cin >> tx >> ty >> kx >> ky;
    vector<vector<int>> G(h+2, vector<int>(w+2, 1));
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            cin >> G[i+1][j+1];
        }
    }
    array<int, 4> dx{-1, 1, 0, 0}, dy{0, 0, -1, 1};
    queue<tuple<int, int, int, int>> Q;
    Q.emplace(ty, tx, ky, kx);
    dp[ty][tx][ky][kx] = 0;
    while(!Q.empty()){
        int y1, x1, y2, x2; tie(y1, x1, y2, x2) = Q.front(); Q.pop();
        if(dp[y1][x1][y2][x2] >= 100) break;
        if(y1 == y2 && x1 == x2){
            cout << dp[y1][x1][y2][x2] << "\n";
            return;
        }
        for (int k = 0; k < 4; ++k) {
            int Y1 = y1+dy[k], X1 = x1+dx[k], Y2 = y2-dy[k], X2 = x2-dx[k];
            if(G[Y1][X1]) Y1 -= dy[k], X1 -= dx[k];
            if(G[Y2][X2]) Y2 += dy[k], X2 += dx[k];
            if(dp[Y1][X1][Y2][X2] > dp[y1][x1][y2][x2]+1){
                Q.emplace(Y1, X1, Y2, X2);
                dp[Y1][X1][Y2][X2] = dp[y1][x1][y2][x2]+1;
            }
        }
    }
    puts("NA");
}

int main() {
    int w, h;
    while(cin >> w >> h, w){
        solve(h, w);
    }
    return 0;
}


Measured memory_bytes: 31816
#include<iostream>
using namespace std;
const long long uf=(1000000000000000000)-1;
int main()
{
	long int A,B,C;
	cin>>A;
	cin>>B;
	cin>>C;
	long long int k;
	cin>>k;
	long long int ans;
	if(k%2==0)
		ans=A-B;
	else
		ans=B-A;

	if(ans>uf)
		cout<<"unfair"<<endl;
	else
		cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N,Q = map(int,readline().split())
ABPX = list(map(int,read().split()))
AB = iter(ABPX[:N+N-2])
PX = iter(ABPX[N+N-2:])

graph = [[] for _ in range(N+1)]
for a,b in zip(AB,AB):
    graph[a].append(b)
    graph[b].append(a)

val = [0] * (N+1)
for p,x in zip(PX,PX):
    val[p] += x

stack = [1]

parent = [0] * (N+1)
while stack:
    x = stack.pop()
    for y in graph[x]:
        if y == parent[x]:
            continue
        parent[y] = x
        stack.append(y)
        val[y] += val[x]

print(' '.join(map(str,val[1:])))


Measured memory_bytes: 85876
const input=require('fs').readFileSync('/dev/stdin','utf8').split(/[\s]/);let input_i=-1;const tn=():number=>{input_i++;return Number(input[input_i])};const tnn=(n:number):number[]=>{const a=[];for(let i=0;i<n;i++){a.push(tn())}return a};const ts=():string=>{input_i++;return String(input[input_i])};const tss=(n:number):string[]=>{const a=[];for(let i=0;i<n;i++){a.push(ts())}return a};const to=(...arg)=>{console.log(...arg)};const abs=(a)=>{return Math.abs(a)};const min=(...a)=>{return Math.min(...a)};const max=(...a)=>{return Math.max(...a)};const floor=(a)=>{return Math.floor(a)};const asc=(ar:number[])=>{const t=[...ar];return ar.sort((a,b)=>{return a-b})};const desc=(ar:number[])=>{const t=[...ar];return t.sort((a,b)=>{return b-a})};const sw=(a,arr:any[],op:'=='|'>='|'>'|'<='|'<'='==')=>{for(let i=0;i<arr.length-1;i+=2){if(eval(a+op+arr[i])){return arr[i+1]}}return arr[arr.length-1]};const near=(n:number,arr:number[]):number=>{let ne=arr[0],ni=0;for(let i=1;i<arr.length;i++){if(Math.abs(n-ne)>Math.abs(n-arr[i])){ne=arr[i];ni=i}}return ni};const deduplicate=(a:any[]):any[]=>{return Array.from(new Set(a))};const gcd=(x,y)=>{while(y){[x,y]=[y,x%y]}return x};const sum=(arr)=>{return arr.reduce((a,b)=>a+b);};
const main=()=>{
  let n=tn(),a=tnn(n),b=[0],s=sum(a)
  for(let i=0;i<n;i++){
    b.push(a[i]+b[i])
  }
  let ans=b[n]
  for(let i=0;i<n;i++){
    ans=min(abs(b[b.length-1]-b[i]-b[i]),ans)
  }
  to(ans)
}
main()


Measured memory_bytes: 61396
n=int(input())
x=list(map(int,input().split()))
x.sort()
ans=0
result=[]
for i in range(x[0],x[n-1]+1):
    for j in range(0,n):
        ans+=(x[j]-i)**2
    result.append(ans)
    ans=0

print(min(result))
        

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

#define debug(x) cout << #x" = " << x;

#define st first
#define nd second

using namespace std;
using namespace placeholders;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

const int MAXN = 1E5 + 10;

int n;
int a[MAXN];

int main(){
	scanf("%d", &n);
	for (int i = 0; i < n; ++i)
		scanf("%d", a + i);
	if (n == 1)
		puts("Second");
	else{
		bool flag = false;
		while (true){
			auto odd = [](int t){return t & 1;};
			int cnt = count_if(a, a + n, odd), t = find_if(a, a + n, odd) - a;
			if (cnt > 1 || a[t] == 1)
				break;
			flag ^= 1;
			--a[t];
			transform(a, a + n, a, bind2nd(divides<int>(), accumulate(a, a + n, 0, __gcd<int>)));
		}
		flag ^= accumulate(a, a + n, 0ll) - n & 1;
		puts(flag ? "First" : "Second");
	}
	return 0;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
#define LOOP(n) for (int _i = 0; _i < (n); _i++)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define FOR(i, r, n) for (int i = (r); i < (n); ++i)
#define ALL(obj) begin(obj), end(obj)
using namespace std;
using ll = long long;
using ull = unsigned long long;

const int INF = 2100100100;
const int MOD = 1e9 + 7;

// 多次元 vector 生成
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
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 main() {
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    string N;
    cin >> N;
    int K;
    cin >> K;
    ll n = (ll)N.size();

    vector<int> keta, val;
    REP(i, n) {
        if (N[i] != '0') {
            keta.push_back(n - i - 1);
            val.push_back((int)(N[i] - '0'));
        }
    }
    REP(i, 3) {
        keta.push_back(0);
        val.push_back(0);
    }

    // debug
    // REP(i, 3) { cout << i << " " << keta[i] << " " << val[i] << endl; }

    ll ans = 0;
    REP(i, n - 1) {
        if (K == 1) {
            ans += 9;
        } else if (K == 2) {
            ans += 9 * 9 * i;
        } else if (K == 3) {
            ans += 9 * 9 * 9 * (i * (i - 1) / 2);
        }
        // cout << i << " " << ans << endl;  // debug
    }

    if (K == 1) {
        ans += val[0];
    } else if (K == 2) {
        ans += (val[0] - 1) * 9 * (n - 1);
        ans += val[1];
        ans += 9 * keta[1];
    } else if (K == 3) {
        ans += (val[0] - 1) * 9 * 9 * (n - 1) * (n - 2) / 2;
        ans += (val[1] - 1) * 9 * (keta[1]);
        ans += val[2];
        ans += 9 * keta[2];
        ans += 9 * 9 * (keta[1]) * ((keta[1]) - 1) / 2;
    }

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


Measured memory_bytes: 256
# left ~ rightの中で、divで割ったときに
# div/2以上余るものの個数を返す
def one_check(left, right, div):
    if(left == right):
        if(left % div >= div/2):
            return 1;
        else:
            return 0;
    else:
        if(left < div/2):
            if(right < div/2):
                return 0;
            elif(div/2 <= right and right < div):
                return right+1 - div/2;
            else:
                return div/2;
        else:
            if(right < div):
                return right+1-left;
            elif(div <= right and right < div*3/2):
                return div-left;
            else:
                return right+1-left - div/2;


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

answer = 0;

if(A==B):
    answer = A;
else:
    div = 2;
    while(div/2<=B):
        if(div==2):
            remainSets = ((B-A+1) // div);
            oneNum = remainSets%2;
            if((B-A)%2 == 0):
                Arem = A % div;
                Brem = B % div;
                if(Arem > Brem):
                    Brem += div;
                oneNum += one_check(Arem, Brem, div);
        else:
            oneNum = 0;
            Arem = A % div;
            Brem = B % div;
            if(Arem > Brem):
                Brem += div;
            oneNum += one_check(Arem, Brem, div);
        if(oneNum%2 == 1):
            answer += div/2;
        div*=2;



print(int(answer));


Measured memory_bytes: 3064
//#i#include "pch.h"
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <limits.h>
#include <string>
#include <stack>
#include <deque>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <time.h>
#include <cassert>
#include <fstream>
#include <stdio.h>

typedef long long ll;
typedef std::pair<int, int> Pii;
typedef std::pair<long long, long long> Pll;
typedef std::pair<double, double> Pdd;

#define rip(i, n, s) for (int i = (s);i < (int)( n ); i++)
#define mapa make_pair
#define all(a) a.begin(), a.end()
#define MM << " " <<

template<typename T>
using MaxHeap = std::priority_queue<T>;
template<typename T>
using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

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

template<typename T>
std::vector<T> vec(int len, T elem) { return std::vector<T>(len, elem); }
template<typename T>
void vdeb(std::vector<T> &da) {
	for (int i = 0;i < da.size();i++) {
		if (i == da.size() - 1) std::cout << da[i];
		else std::cout << da[i] << ' ';
	}
	std::cout << std::endl;
}
template<typename T>
void vdeb(std::vector<std::vector<T>> &da) {
	for (int i = 0;i < da.size();i++) vdeb(da[i]);
	std::cout << std::endl;
}

using namespace std;

int Pow(int x){
    int ret = 1;
    rip(i,x,0) ret *= 2;
    return ret;
}

int main(){
    int n;cin >> n;
    vector<vector<ll>> da(n,vector<ll>(n));
    rip(i,n,0) rip(j,n,0) cin >> da[i][j];
    vector<ll> dp(Pow(n), 0);
    rip(k,Pow(n),0){
        int now = 1;
        rip(i,n,0){
            if(now&k){
                int now2 = 1;
                rip(j,n,0){
                    if(now2&k) dp[k] += da[i][j];
                    now2 <<= 1;
                }
            }
            now <<= 1;
        }
        //cout << dp[k] << endl;
        vector<int> li(0);
        now = 1;
        rip(i,n,0){
            if(k&now) li.push_back(now);
            now <<= 1;
        }
        rip(i,Pow(li.size()-1),0){
            int look = 1, id = 0;
            rip(j, li.size(),0){
                if(i&look) id |= li[j];
                look <<= 1;
            }
            chmax(dp[k], dp[id]+dp[k^id]);
        }
    }
    //vdeb(dp);
    cout << dp.back()/2 << endl;
}

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

#define REP(i, n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()
const int INF = 1e9;

using namespace std;
int adj[105][105] = {0};
int res[105] = {0};
int n;

int main() {
    cin >> n;
    REP(i, n){
        int u, k;
        cin >> u >> k;
        REP(j, k) {
            int tmp;
            cin >> tmp;
            adj[u-1][tmp-1] = 1;
        }
        res[i] = INF;
    }
    res[0] = 0;
    REP(k, 3) REP(i, n) REP(j, n)
        if(adj[i][j] != 0)
            res[j] = min(res[j], res[i]+1);

    REP(i, n){
        if(res[i] != INF)
            cout << i+1 << " " << res[i] << endl;
        else
            cout << i+1 << " -1" << endl;
    }
    return 0;
}

Measured memory_bytes: 1200
n=int(input())
import math
import itertools
#total=0
x=[]
y=[]
total=0
num=math.factorial(n)
for i in range(n):
    X,Y=map(int,input().split())
    x.append(X)
    y.append(Y)
num_lis=[i for i in range(n)]
P=itertools.permutations(num_lis,n)
for p in P:
    for i in range(n-1):
        tmp=math.sqrt((x[p[i+1]]-x[p[i]])**2+(y[p[i+1]]-y[p[i]])**2)
        total+=tmp
print(total/num)



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

int main() 
{
  string moji;
  cin >> moji;
  if(moji.at(2) == moji.at(3) && moji.at(4) == moji.at(5))
  {
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <regex>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include<tuple>

using namespace std;

const int N_MAX = 500;
const int M_MAX = 200000;

int main() {
	int N, M, Q;
	int grid[N_MAX][N_MAX] = { {0} };
	int sum[N_MAX][N_MAX] = { {0} };

	cin >> N >> M >> Q;

	for (int i = 0; i < M; i++) {
		int l, r;
		cin >> l >> r;
		grid[l - 1][r - 1]++;
	}

	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			sum[i][j] += grid[i][j];

			if (i != 0 && j != 0) sum[i][j] -= sum[i - 1][j - 1];
			if (i != 0)sum[i][j] += sum[i - 1][j];
			if (j != 0)sum[i][j] += sum[i][j - 1];
		}
	}

	for (int i = 0; i < Q; i++) {
		int l, r;
		cin >> l >> r; l--; r--;

		int ans = sum[r][r];
		if (l > 0)ans = ans - sum[r][l - 1] - sum[l - 1][r] + sum[l - 1][l - 1];

		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 2944