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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;
vector<vector<ll>> to(100001, vector<ll>());
bool used[100001];
ll costs[100001];

ll dfs(ll s){
  if(used[s])return costs[s];
  used[s]=true;

  ll t = 0;
  for(auto n: to[s]){
    t = max(t, dfs(n)+1);
  }
  return costs[s]=t;
}

int main(){
  ll n,m;cin>>n>>m;
  to.resize(n+1);

  rep(i, m){
    ll x,y;cin>>x>>y;
    to[x].push_back(y);
  }

  rep1(i,n)costs[i] = dfs(i);

  ll result=0;
  rep1(i, n) result = max(result, costs[i]);

  cout<<result<<endl;

  return 0;
}

Measured memory_bytes: 8576
#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
int main()
{
    int n;
    cin >> n;
    set<P> a;
    vector<P> b(n);

    for(int i = 0; i < n; i++)
    {
        int x, y;
        cin >> x >> y;
        a.insert(P(x,y));
    }
    for(int i = 0; i < n; i++)
    {
        int x, y;
        cin >> x >> y;
        b[i] = P(x, y);
    }
    sort(b.begin(), b.end());

    int ans = 0;
    for(int i = 0; i < n; i++)
    {
        P p = b[i];
        int bx = p.first;
        int by = p.second;
        auto pos = a.end();
        int maxy = -1;
        for(auto itr = a.begin(); itr != a.end(); itr++)
        {
            P pa = *itr;
            int ax = pa.first;
            int ay = pa.second;
            if(ax < bx && ay < by && maxy < ay)
            {
                pos = itr;
                maxy = ay;
            }
        }
        if(pos != a.end())
        {
            ans++;
            a.erase(pos);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S;
  cin >> S;
  int N = S.size();
  vector<char> s(N);
  for (int i = 0; i < N; i++) {
    s.at(i) = S.at(i);
  }
  int n = N/2;
  bool f = true;
  for (int i = 0; i < N; i++) {
    if (s.at(i) != s.at(N-i-1)) {
      f = false;
      break;
    }
  }
  for (int i = 0; i < n; i++) {
    if (s.at(i) != s.at(n-i-1)) {
      f = false;
      break;
    }
  }
  for (int i = n+1; i < N; i++) {
    if (s.at(i) != s.at(N-i-1)) {
      f = false;
      break;
    }
  }
  if (f) {
    cout << "Yes" <<endl;
  }
  else {
    cout << "No" <<endl;
  }
}

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

//サイコロ1
class Dise1 {
public:
	//コンストラクタ
	Dise1();
	int Number[6];
};

//サイコロ2
class Dise2 {
public:
	Dise2();
	int Number[6];
};

Dise1::Dise1()
{
	for (int i = 0; i < 6; i++) {
		cin >> Number[i];
	}
}

Dise2::Dise2()
{
	for (int i = 0; i < 6; i++) {
		cin >> Number[i];
	}
}


/* 1
  4235
   6*/

//複数の回転
void Rotation1(Dise1 *dise1, Dise2 *dise2)
{
	do {
		swap(dise2->Number[0], dise2->Number[4]);
		swap(dise2->Number[0], dise2->Number[5]);
		swap(dise2->Number[0], dise2->Number[1]);
	} while (dise1->Number[0] != dise2->Number[0]);
}

void Rotation2(Dise1 *dise1, Dise2 *dise2)
{
	do {
		swap(dise2->Number[0], dise2->Number[3]);
		swap(dise2->Number[0], dise2->Number[5]);
		swap(dise2->Number[0], dise2->Number[2]);
	} while (dise1->Number[0] != dise2->Number[0]);
}

void Rotation3(Dise1 *dise1, Dise2 *dise2)
{
	do {
		swap(dise2->Number[1], dise2->Number[3]);
		swap(dise2->Number[1], dise2->Number[4]);
		swap(dise2->Number[1], dise2->Number[2]);
	} while (dise2->Number[1] != dise1->Number[1]);
}

bool CheckDise(Dise1 *dise1, Dise2 *dise2)
{
	for (int i = 0; i < 6; i++) {
		if (dise1->Number[i] != dise2->Number[i]) {
			return false;
		}
	}

	return true;
}

int main()
{
	Dise1 dise1;
	Dise2 dise2;

	for (int i = 0; i < 6; i++) {
		//まず上合わせ
		if (dise2.Number[i] == dise1.Number[0]) {
			if (i == 2 || i == 3) {
				Rotation2(&dise1, &dise2);
			}
			else if (i != 0) {
				Rotation1(&dise1, &dise2);
			}
			//まえ
			for (int j = 1; j < 5; j++) {
				if (dise2.Number[j] == dise1.Number[1]) {
					if (j != 1) {
						Rotation3(&dise1, &dise2);
					}
				}
			}
		}

		if (CheckDise(&dise1, &dise2)) {
			cout << "Yes" << endl;
			exit(0);
		}

	}

	cout << "No" << endl;

	return 0;
}


Measured memory_bytes: 3080
a={1, 3, 5, 7, 8, 10, 12}
b={4, 6, 9, 11}
c={2}
x, y = map(int, input().split())
print('Yes' if (x in a and y in a) or (x in b and y in b) or (x in c and y in c) else 'No')

Measured memory_bytes: 3060
#include<iostream>
using namespace std;
int main(){
  int a,b;
  char op;
  cin >> a >> op >> b;
  while(op!='?'){
    int c;
    if(op=='+') c=a+b;
    if(op=='-') c=a-b;
    if(op=='*') c=a*b;
    if(op=='/') c=a/b;
    cout << c << endl;
    cin >> a >> op >> b;
  }
}



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

int main() {
  string s;
  cin >> s;
  vector<bool> app(26);
  rep(i, 26) app[i] = false;
  rep(i, s.size()) app[s[i] - 'a'] = true;
  rep(i, 26) if(!app[i]) {
    cout << string(1, i + 'a') << endl;
    return 0;
  }
  
  cout << "None" << endl;
  return 0;
}

Measured memory_bytes: 3664
//Author : Sidiq Tri Pratikto
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(v) v.begin(), v.end()

using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> new_data_set;
//order_of_key(x) = number of elements stricly smaller than x
//find_by_order(x) = return x-th largest element
typedef long long LL;
const LL MOD = 998244353;
const double PI = 2 * acos(0);

int main() {
	int R;
	scanf("%d", &R);
	printf("%.2f\n", 2 * R * PI);
}


Measured memory_bytes: 3812
#include <iostream>

 

using namespace std;

 

int main()
{
    int i, ans, a, b, c;
    
    cin >> a >> b >> c;
    ans = 0;
    
    for(i=a; i<=b; i++)
    {
        if( c % i == 0 )
       ans++;
    }
    cout << ans << endl;
}



Measured memory_bytes: 3112
#include <bits/stdc++.h>
#define PI 3.14159265359
#define NIL (-1)
#define LL long long
using namespace std;
const int64_t MOD = 1e9 + 7;

int main() {
	int A, B, C, X;
	cin >> A >> B >> C >> X;

	int cnt = 0;
	for (int i = 0; i <= A; i++) {
		for (int j = 0; j <= B; j++) {
			int n = 500 * i + 100 * j;
			if (n > X) continue;
			int m = X - n;
			if ((m % 50 == 0)&&(m/50<=C)) cnt++;
		}
	}

	cout << cnt << endl;
}

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

string s;

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

    cin >> s;
    int k1 = stoi(s.substr(0,2));
    int k2 = stoi(s.substr(2));
    bool f1 = false, f2 = false;
    if(1 <= k1 && k1 <= 12)f1 = true;
    if(1 <= k2 && k2 <= 12)f2 = true;
    if(f1 && f2){
        puts("AMBIGUOUS");
    }else if(f1){
        puts("MMYY");
    }else if(f2){
        puts("YYMM");
    }else{
        puts("NA");
    }
}


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

using namespace std;

int main(){

	int l;
	while(cin>>l&&l!=0){
		int a[26];
		for(int i = 0; i < l; i++){
			cin>>a[i];
		}
		int left=32;

		int tern=0;
		int idx=0;
		while(1){
			if(left==0)
				break;
			if(tern){
				left-=min(left,a[idx]);
				idx++;
				idx%=l;
			}
			else{
				left-=((left-1)%5);
			}
			cout<<left<<endl;
			tern^=1;
		}

	}
	return 0;
}

Measured memory_bytes: 0
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a_value_list = []
a_real_list = [1]
a_real = []
b_value_list = []
b_real_list = [1]
b_real = []
a_ans = 1
b_ans = 1
c = []

#value_list
for i in range(n):
    a_value_list.append(1)
    b_value_list.append(1)

""""
x = a[0]-1
value_list[x] = 0
print(value_list)
"""
#rael_list
for i in range(n):
    x = i + 1
    a_real_list.append(a_real_list[i]*x)
    a_real.append(x)
    b_real_list.append(b_real_list[i] * x)
    b_real.append(x)

a_real_list.pop(0)
b_real_list.pop(0)

for i in range(n-1):
    m = n-i-1
    x = a[i] - 1
    a_value_list[x] = 0
    c = a_value_list[:x+1]
    y = sum(c)
    a_ans += a_real_list[m]*y/a_real[m]


for i in range(n-1):
    m = n-i-1
    x = b[i] - 1
    b_value_list[x] = 0
    c = b_value_list[:x+1]
    y = sum(c)
    b_ans += b_real_list[m]*y/b_real[m]

print(int(abs(a_ans-b_ans)))

Measured memory_bytes: 3064
#include <stdio.h>

int main(void)
{
	int a;
	int b;
	int c;
	int d;
	int n;
	int kai;
	
	while (scanf("%d", &n) != EOF){
	kai = 0;
	
	for (a = 0; a <= 9; a++){
		for (b = 0; b <= 9; b++){
			for (c = 0; c <= 9; c++){
				for (d = 0; d <= 9; d++){
					if (a + b + c + d == n) kai++;
				}
			}
		}
	}
	printf("%d\n", kai);
	}
	return (0);
}

Measured memory_bytes: 0
import numpy as np
#import copy
#import fractions
#
###############入  力###################
#a, b, c, d = map(int, input().split())  # a=2 b=4 c=5 d =7
#a = list(map(int, input().split()))     # a = [2, 4, 5, 6]
#s=[list(map(int,list(input()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき
##行数指定
##3
##hoge
##foo
##bar
#n=int(input())
#string_list=[input() for i in range(n)] #['hoge','foo','bar']
#
###############初期化、コピー##############
#a=[0]*5 #[0, 0, 0, 0, 0]
#b=copy.deepcopy(a)  #2次元配列はこうコピーする
#b2=a[:]  #1次元のときはコピーはこれで良い
#
###############小数点表示################
#a = 0.364364
#print(a) #0.364364
#print("{:.6f}".format(a)) #0.364364
#print("{:.4f}".format(a)) #0.3644 小数点第4位に丸めることもできる。
#
###############ゼロ埋め・幅寄せ################
#print("python".ljust(15,'-')) # 左詰め　　　 #python---------
#print("python".center(15,'-'))# 中央寄せ　　#-----python----
#print("python".rjust(15,'-')) # 右詰め　　　 #---------python
#print(str(29).rjust(10,'0')) #10桁ゼロ埋め　 #0000000029
#
###############文字列操作################
#'abc123def'[:] #すべての文字列が取れる #'abc123def'
#'abc123def'[-1:] #終端文字がとれる    #'f'
#'abc123def'[:-1] #最後の1文字以外のものがとれる。 #'abc123de'
#'abc123def'[::-1] #文字が逆転する #'fed321cba'
#
###############二分探索################
#import bisect
#listA=[1,2,5,2,4,6,7,8,6,56,3,56,76,34,32,2,6,0,32,6,0] 
#listA.sort()
#zeroindex=bisect.bisect_right(listA,0) #ソートされたリスト内で0の場所を探し、右側Indexを返す
#clearlistA=listA[zeroindex:]#0以下が存在しないリストを得る
#
#
###############最小公倍数,最大公約数
#import fractions
#a,b=map(int, input().split())
#a,b= 24, 6
#f=fractions.gcd(a,b)
#f2=a*b//f
#print(f,f2)
#
###############四則演算
#a + b #足し算（加算）: +演算子
#a - b#引き算（減算）: -演算子
#a * b#掛け算（乗算）: *演算子
#a / b#割り算（除算）: /演算子
#a// b#割り算の整数部（整数除算）: //演算子
#a % b#割り算の剰余（余り, mod）: %演算子
#a** b#べき乗: **演算子

X = int(input())
XX=np.arange(X,X+10**4)

s=0
for j in XX:
    if (s==1):
        break
    for i in range(2, j+1):
        N= j % i
#        print('j=' ,j ,' i=' ,i, N)
        if (N ==  0 and i==j ):
            print(j)
            s=1
        if (N ==  0):
          #  print('true')
            break
#        else:
#            print(j)



Measured memory_bytes: 14556
//g++ -std=c++14 test.cpp -o test.out
//問題URL
//https://atcoder.jp/contests/abc154/tasks/abc154_e

#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <unordered_map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (1LL<<60);
const int INF_INT = 2147483647-1e6-1;
//const LL mod = 1000000007ll;
const int mod_int = 1000000007;

//https://github.com/atcoder-live/library/blob/master/mint.cpp
#define LL long long int
const LL mod = 998244353ll;
struct mint {
  LL x; 
  mint(LL x=0):x((x%mod+mod)%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(LL t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};
 
struct combination {
  vector<mint> fact, ifact;//factに階乗を計算、ifactはその各々に対する逆元
  combination(LL n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (LL i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (LL i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(LL n,LL k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

LL N,M,K;

mint ans = 0;

void solve(){
	//(M-1)のi乗をpowM_1[i]とおく
	vector<mint> powM_1(N,1);
	for(int i=1;i<=N-1;i++) powM_1[i] = powM_1[i-1]*mint(M-1);
	combination c(N-1);
	for(int k=0;k<=K;k++){
		ans += mint(M)*powM_1[N-k-1]*c(N-1,k);
	}
}

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

    solve();

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

Measured memory_bytes: 7516
import java.util.*;

class Main {
    static int nail[][];
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        nail = new int[n+1][];
        for (int i = 1; i <= n; i++) {
            nail[i] = new int[i+1];
        }
        int ct = 0;
        for (int i = 0; i < m; i++) {
            int a = sc.nextInt();
            int b = sc.nextInt();
            int x = sc.nextInt();
            ct += count(a, b, x);
        }
        System.out.println(ct);
    }

    static int count(int a, int b, int x) {
        if (x < 0) return 0;
        int y = nail[a][b];
        if (y > x) return 0;
        int c = 0;
        if (y == 0) c++;
        nail[a][b] = x + 1;
        c += count(a + 1, b, x - 1);
        c += count(a + 1, b + 1, x - 1);
        return c;
    }
}

Measured memory_bytes: 345616
#include <bits/stdc++.h>
using namespace std;
long double a,c=1.08;
long long x;
int main()
{
  cin>>a;
  if((int)(a/1.08)<(int)((a+1)/1.08-0.00000001))
    cout<<(int)((a+1)/1.08);
  else cout<<":(";
}


Measured memory_bytes: 256
#e
H,W,M = map(int,input().split())
h = [None]*M
w = [None]*M
for i in range(M):
    a,b = map(int,input().split())
    h[i],w[i] = a-1,b-1


from collections import Counter
ch = Counter(h)
cw = Counter(w)

x_max=max(ch.values())
cand_x_max = [x for x in range(H) if ch[x]==x_max]

y_max=max(cw.values())
cand_y_max = [y for y in range(W) if cw[y]==y_max]

    
cnt=0
for i in range(M):
    if ch[h[i]]==x_max and cw[w[i]]==y_max:
        cnt+=1
if cnt<len(cand_x_max)*len(cand_y_max):
    print(x_max+y_max)
else:
    print(x_max+y_max-1)


        

Measured memory_bytes: 227520
N,K = map(int,input().split())
A = list(map(int,input().split()))
s = 1
B = []
set_ = set()
for i in range(N):
    if A[s-1] not in set_:
        set_.add(A[s-1])
        B.append(A[s-1])
        s = A[s-1]
        
    else:
        e = i
        break
idx = B.index(A[s-1])
if K-1<idx: print(B[K-1])
else:
    print(B[idx + (K-idx-1)%(e-idx)])
    

Measured memory_bytes: 131072
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from collections import deque 

class Edge:
    def __init__(self, to, id):
        self.to = to
        self.id = id

def main():
    
    n = int(readline())
    g = [[] for _ in range(n)]

    for i in range(n-1):
        a, b = map(int, readline().split())
        g[a-1].append(Edge(b-1, i))
        g[b-1].append(Edge(a-1, i))

    dq = deque()    
    done = [0 for _ in range(n)]
    dq.append(0)
    done[0] = 1
    edgecolor = [0 for _ in range(n-1)]

    while len(dq) > 0: 
        v = dq.pop()
        c = -1
        for i in range(len(g[v])):
            nx = g[v][i].to
            edge_id = g[v][i].id
            if done[nx]:
                c = edgecolor[edge_id]
        k = 1
        for i in range(len(g[v])):
            nx = g[v][i].to
            edge_id = g[v][i].id
            if done[nx]:
                continue
            if k == c:
                k += 1
            edgecolor[edge_id] = k
            k += 1  
            done[nx] = 1
            dq.append(nx)

    mx = max(edgecolor) 
    print(mx)
    for ec in edgecolor:
        print(ec)

if __name__ == '__main__':
    main()


Measured memory_bytes: 83488
"""
author : halo2halo
date : 9, Jan, 2020
"""

import sys

# import numpy as np
import itertools

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

N = int(readline())
SP = [(x.split()[0].decode('utf8'), int(x.split()[1])) for x in readlines()]
SPs = sorted((name, -pt, i + 1) for i, (name, pt) in enumerate(SP))
print('\n'.join(str(a[2]) for a in SPs))


Measured memory_bytes: 3188
#include<cmath>
#include<algorithm>
#include<iostream>
using namespace std;
int x,i,f[1001];
int main()
{
	cin>>x;
	f[1]=1;
	for(i=2;i<=1000;i++) f[i]=0;
	for(i=2;i<=31;i++) f[i*i]=1;
	for(i=2;i<=10;i++) f[int(pow(i,3))]=1;
	for(i=2;i<=5;i++)  f[int(pow(i,4))]=1;
	for(i=2;i<=3;i++)  f[int(pow(i,5))]=f[int(pow(i,6))]=1;
	for(i=7;i<=9;i++)  f[int(pow(2,i))]=1;  
	i=x+1; 
	while(i--)
		if(f[i]==1) {cout<<i; return 0;} 
}

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

int sum;

template<typename comparable>
void merge(vector<comparable>& arr, const int& left,const int& mid, const int& right) {
	int leftSideLength = mid - left;
	int rightSideLength = right - mid;

	vector<comparable> leftSide(leftSideLength);
	vector<comparable> rightSide(rightSideLength);

	for (int i = 0; i < leftSideLength; i++) {
		leftSide[i] = arr[left + i];
	}
	for (int i = 0; i < rightSideLength; i++) {
		rightSide[i] = arr[mid + i];
	}

	int i = 0, j = 0, cnt = 0;
	for (int k = left; k < right; k++) {
		sum++;
		if (i >= leftSideLength) {
			arr[k] = rightSide[j];
			j++;
			continue;
		}
		if (j >= rightSideLength) {
			arr[k] = leftSide[i];
			i++;
			continue;
		}
		
		if (leftSide[i] <= rightSide[j]) {
			arr[k] = leftSide[i];
			i++;
		}
		else {
			arr[k] = rightSide[j];
			j++;
		}
	}
}

template<typename comparable>
void mergeSort(vector<comparable>& arr, const int& left, const int& right) {
	if (right - left > 1) {
		const int mid = (left + right) / 2;
		mergeSort(arr, left, mid);
		mergeSort(arr, mid, right);
		merge(arr, left, mid, right);
	}
}

int main() {
	int N;
	cin >> N;
	vector<int> arr(N);
	for (int i = 0; i < N; i++) cin >> arr[i];
	mergeSort(arr, 0, N);
	for (int i = 0; i < N; i++) {
		cout << arr[i];
		if (i == N - 1) cout << '\n';
		else cout << " ";
	}
	cout << sum << endl;
}



Measured memory_bytes: 6768
#include<iostream>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;

int64_t N, A[300000], ans, MOD = 1e9 + 7;

int main() {
    cin >> N;
    rep(i, N) cin >> A[i];
    rep(i, 60) {
        int64_t c0 = 0, c1 = 0, bit = (1L << i);
        rep(j, N) {
            if (A[j] & bit) c1++;
            else c0++;
        }
        ans += (bit % MOD) * (c0 * c1 % MOD);
        ans %= MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int MOD =1e9+7;
using ll=long long;
ll n, a, b;
int main(){
  cin >> n >> a >> b;
  if(a > b) cout << 0 << endl;
  else if(a == b) cout << 1 << endl;
  else if(a < b){
    if(n == 1) cout << 0 << endl;
    else cout << a+(n-1)*b - (b+(n-1)*a) +1 << endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}


const int mod = 1000000007;
const int max_n = 600005;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
  mint P(int n, int k){
    return fact[n]*ifact[n-k];
  }
}comb(max_n);


int main(){
  ll n,m;cin >> n >>m;
  mint ans=0;
  rep(i,n+1){
    mint p=comb.P(m,i)*comb(n,i)*comb.P(m-i,n-i)*comb.P(m-i,n-i);
    if(i&1)p*=-1;
    ans+=p;
  }
  cout << ans <<endl;
}

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

using namespace std;
using llong = long long;
using ldbl = long double;
using lpair = pair<llong, llong>;

#define ALL(x) x.begin(), x.end()

template<typename T>
constexpr T inf = static_cast<T>(pow(10, static_cast<int>(log10(numeric_limits<T>::max())))) + 7;
constexpr llong mod = 1e9+7;

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

  cout << R + 100*(10 - min(10, N)) << endl; 

  return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <functional>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <cassert>
using namespace std;

#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll> 
#define VVI vector<vector<ll> >
#define REP(i,n) for(int i=0,_n=(n);(i)<(int)_n;++i)
#define RANGE(i,a,b) for(int i=(int)a,_b=(int)(b);(i)<_b;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define PRINT1(table, D0) REP(d0, D0) cout<<table[d0]<<" "; cout<<"\n";
#define PRINT2(table, D0, D1) REP(d0, D0) { REP(d1, D1) cout<<table[d0][d1]<<" "; cout<<"\n"; }
#define PRINT3(table, D0, D1, D2) REP(d0, D0) { REP(d1, D1) { REP(d2, D2) cout<<table[d0][d1][d2]<<" "; cout<<"\n"; } cout<<"\n"; }
#define UNIFORM_DOUBLE(a, b) (((b-a)*(double)rand()/RAND_MAX)+a) // [a, b) 
#define UNIFORM_LL(a, b) (ll)UNIFORM_DOUBLE(a, b) // [a, b) 
#define IN(v, lo, hi) ((lo)<=(v) && (v)<(hi))
#define DD(v) cout<<#v<<": "<<v<<endl
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }

#define MOD 1000000007LL
#define INF (1LL<<60)

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll N,K;
	while(cin>>N>>K) {
		ll c0 = 0, ch = 0;
		RANGE(i, 1, N+1) {
			if(i%K==0) c0++;
			if(K%2==0 && i%K==K/2) ch++;
		}
		ll ans = c0*c0*c0 + ch*ch*ch;
		cout<<ans<<endl;
	}
	
	return 0;
}


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

using namespace std;

const int MOD = 1000000007;

long long modPow(int a, int p){
	if(p == 0) return 1;
	if(p == 1) return a;
	long long res = modPow(a, p/2);
	res = res*res;
	res %= MOD;
	if(p%2 == 1) res = (res * a) % MOD;
	return res;
}

int main(){
	int N;
	static int comb[8001][8001];
	for(int i=1;i<=8000;i++){
		comb[i][0] = 1;
		for(int j=1;j<i;j++){
			comb[i][j] = comb[i-1][j] + comb[i-1][j-1];
			comb[i][j] %= MOD;
		}
		comb[i][i] = 1;
	}
	static int path[4001][4001];
	while(cin >> N){
		memset(path, 0, sizeof(path));
		vector<int> A(N), B(N);
		for(int i=0;i<N;i++){
			cin >> A[i] >> B[i];
			path[2000-A[i]][2000-B[i]]++;
		}
		for(int i=0;i<=4000;i++){
			for(int j=0;j<=4000;j++){
				if(i+1 <= 4000){
					path[i+1][j] += path[i][j];
					path[i+1][j] %= MOD;
				}
				if(j+1 <= 4000){
					path[i][j+1] += path[i][j];
					path[i][j+1] %= MOD;
				}
			}
		}
		long long res = 0;
		for(int i=0;i<N;i++){
			res += path[2000+A[i]][2000+B[i]];
			res %= MOD;
			res += MOD - comb[2*(A[i]+B[i])][2*A[i]];
			res %= MOD;
		}
		res *= modPow(2, MOD-2);
		res %= MOD;
		cout << res << endl;
	}
}


Measured memory_bytes: 219392
# どの文字を持っているかを二進数で1000101010...と表す
# or で足していく
class SegmentTree:
  arr=None
  tree=None
  n=0
  # 結果に影響を与えないdefault value
  DEF=0

  def __init__(self,arr):
    self.arr=arr
    size=len(arr)
    # n階層目は2**(n-1)要素
    self.n=1
    while self.n<size:
      self.n*=2
    self.tree=[self.DEF]*(2*self.n-1)
    # 親=(n-1)//2
    # 子=2*n+1,2*n+2
    # 最下階層の要素を埋めていく
    for i in range(size):
      self.tree[i+self.n-1]=arr[i]
    for i in range(self.n-2,-1,-1):
      self.tree[i]=self.__choose__(self.tree[2*i+1],self.tree[2*i+2])
    
    
  # 区間からの代表値の選び方を定義する（最小値を選ぶ場合はminなど）
  def __choose__(self,a,b):
    return a | b
  
  # 添字xをvalで更新する
  def update(self,x,val):
    x+=self.n-1
    self.tree[x]=val
    while x>0:
      x=(x-1)//2
      self.tree[x]=self.__choose__(self.tree[2*x+1],self.tree[2*x+2])
      
  # 対象区間[a,b)の値を求めるクエリ (bは含まないので注意)
  # k:自分がいるノードのindex
  # [l,r):検査する区間
  def get_val(self,a,b,k=0,l=0,r=-1):
    # 最初に呼び出されたときは対象区間が[0,N)
    if r<0:
      r=self.n
      
    # 要求区間と対象区間が交わらない
    if r<=a or b<=l:
      return self.DEF
    
    # 要求区間が対象区間を完全に満たす->対象区間を計算に使用する
    if a<=l and r<=b:
      return self.tree[k]
    
    # 要求区間が対象区間の一部を満たす->子を探索
    ll=self.get_val(a,b,2*k+1,l,(l+r)//2)
    rr=self.get_val(a,b,2*k+2,(l+r)//2,r)
    
    return self.__choose__(ll,rr)
    
  def show(self):
    print("----")
    print(list(map(bin,self.tree)))
    print(self.tree)
    
base=ord("a")
ALPHA="abcdefghijklmnopqrstuvwxyz"
def change_alpha_to_num(c):
  if c not in ALPHA:
    return 0
  return 1<<(ord(c)-base)

import sys
readline=sys.stdin.readline

N=int(readline())
S=readline()
Sarr=list(map(change_alpha_to_num,list(S)))
ST=SegmentTree(Sarr)
Q=int(readline())
for i in range(Q):
  q=list(readline().split())
  if q[0]=="1":
    i,c=int(q[1])-1,q[2]
    ST.update(i,change_alpha_to_num(c))
  elif q[0]=="2":
    l,r=int(q[1])-1,int(q[2])-1
    print(bin(ST.get_val(l,r+1)).count("1"))


Measured memory_bytes: 48380
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
int main(){
  int n;
  cin>>n;
  set<P>S;
  int ans=0;
  for(int i=0;i<n;i++){
    int a;
    cin>>a;
    ans+=S.count(P(a,i+1));
    S.insert(P(i+1,a));
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 4992
from collections import Counter
order = Counter()
N = int(input())
for i in range(N):
    A = input().split()
    name,quantity = A[0],int(A[1])
    order[name] += quantity
po = sorted(order.items(),key=lambda x:x[0])
pu = sorted(po,key=lambda x:len(x[0]))
for j,k in pu:
    print(j,k)

Measured memory_bytes: 6012
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static int INF = 1 << 30;
	static long LINF = 1L << 55;
	static int MOD = 1000000007;
	static int[] mh4 = { 0, -1, 1, 0 };
	static int[] mw4 = { -1, 0, 0, 1 };
	static int[] mh8 = { -1, -1, -1, 0, 0, 1, 1, 1 };
	static int[] mw8 = { -1, 0, 1, -1, 1, -1, 0, 1 };

	static class TaskX {

		public void solve(int testNumber, InputReader in, PrintWriter out) {

			char[] s = in.nextString().toCharArray();
			for (int i = 0; i < s.length; i++) {
				out.print(s[i] == '1' ? 9 : 1);
			}
			out.print("\n");

		}
	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(nextString());
		}

		public long nextLong() {
			return Long.parseLong(nextString());
		}

		public double nextDouble() {
			return Double.parseDouble(nextString());
		}

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}

		public int[] nextIntArrayDec(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt() - 1;
			}
			return res;
		}

		public int[] nextIntArray1Index(int n) {
			int[] res = new int[n + 1];
			for (int i = 0; i < n; i++) {
				res[i + 1] = nextInt();
			}
			return res;
		}

		public long[] nextLongArray(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong();
			}
			return res;
		}

		public long[] nextLongArrayDec(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong() - 1;
			}
			return res;
		}

		public long[] nextLongArray1Index(int n) {
			long[] res = new long[n + 1];
			for (int i = 0; i < n; i++) {
				res[i + 1] = nextLong();
			}
			return res;
		}

		public double[] nextDoubleArray(int n) {
			double[] res = new double[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextDouble();
			}
			return res;
		}

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}
	}

}


Measured memory_bytes: 21460
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define showmap(is, js, x) {rep(i, is){rep(j, js){cout << x[i][j] << " ";}cout << endl;}}
#define show(x) {for(auto i: x){cout << i << " ";} cout<<endl;}
#define showm(m) {for(auto i: m){cout << m.x << " ";} cout<<endl;}
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> llP;
ll gcd(int x, int y){ return y?gcd(y, x%y):x;}
ll lcm(ll x, ll y){ return (x*y)/gcd(x,y);}


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



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

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(lol i=0;i<lol(n);i++)
#define REPD(i,n) for(lol i=n-1;i>=0;i--)
#define FOR(i,a,b) for(lol i=a;i<=lol(b);i++)
#define FORD(i,a,b) for(lol i=a;i>=lol(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) x.begin(),x.end() //sortなどの引数を省略したい
#define SIZE(x) lol(x.size()) //sizeをsize_tからllに直しておく
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//最大値最小値
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}

void rec(vector<vector<int>>, int[], int, vector<int>);

int main()
{
    lol result{0};
    int a1, a2;
    int n; cin >> n;
    int m; cin >> m;
    vector<vector<int>> a(n+1);
    vector<int> b(n+1, 0);
    FOR(i, 1, m)
    {
        cin >> a1 >> a2;
        a[a1].push_back(a2);
        a[a2].push_back(a1);
    }

    bool fl = true;
    bool flag = true;

    queue<int> q;
    q.push(1);
    while(!q.empty())
    {
        int i = q.front();
        q.pop();
        REP(j, a[i].size())
        {
            if(b[a[i][j]] == 0)
            {
                b[a[i][j]] = i;
                //cout << a[i][j] << " ";
                q.push(a[i][j]);
            }
        }
    }

    FOR(i, 2, n)
    {
        if(b[i] == 0)
            flag = false;
    }
    if(flag)
    {
        cout << "Yes" << endl;

        for(int i = 2; i <= n; i++)
        {
            cout << b[i] << endl;
        }
    }
    else
    {
        cout << "No" << endl;
        
    }
    
    return 0;
}


Measured memory_bytes: 10252
import math
N = int(input())
a = map(int, input().split())
A = list(a)

min = 10**10
for e in A:
    m=0 #eが2で割り切れる回数
    while e%2==0:
        e = e/2
        m+=1
    if min>m:
        min = m
print(min)

Measured memory_bytes: 3060
#include<cstdio>
#include<map>
using namespace std;
map<unsigned long long,int>p;
const int mo=19260817;
int  n,m,i,j,a[100],f[19260817];
unsigned long long ans,k,pow[30];
char s[15];
int main()
{
	pow[1]=1;
	for (i=2;i<=26;i++)
	pow[i]=pow[i-1]*31;
	scanf("%d",&n);
	for (i=1;i<=n;i++)
	{
		scanf("%s",s+1);
		for (j=1;j<=26;j++)
		a[j]=0;
		for (j=1;j<=10;j++)
		a[s[j]-'a'+1]++;
		k=0;
		for (j=1;j<=26;j++)
		k+=a[j]*pow[j];
		ans+=p[k],p[k]++;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 6528
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <cmath>
#include <limits.h>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
#include <stdio.h>
using namespace std;

long long MOD = 1000000007;

int main() {
    
    int A[3] = {0};
    string S;
    cin >> S;
    
    if ( S.length() == 1 ) {
        cout << "YES" << endl;
    }
    else if ( S.length() == 2 ) {
        cout << ( S[0] == S[1] ? "NO" : "YES" ) << endl;
    }
    else {            
        for ( int i = 0; i < S.length(); i++ ) {
            A[S[i] - 'a']++;
        }
        bool ans = abs(A[0]-A[1]) <= 1 && abs(A[1]-A[2]) <= 1 && abs(A[0]-A[2]) <= 1;
        cout << ( ans ? "YES" : "NO" ) << endl;
    }
    return 0;
}

Measured memory_bytes: 512
n = gets.chop.to_i
a = []
a << gets.chop
t = a[0].split(" ")
N = []
t.each do |a|
	N << a.to_i
end
cnt = 0
N.each_with_index do |x, i|
    if i + 2 == N.length
        break
    end
    if x < N[i + 1] && N[i + 1] < N[i + 2] || N[i + 2] < N[i + 1] && N[i + 1] < x
        cnt = cnt + 1
    end
end
puts cnt

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
template <class T> void corner(bool flg, T hoge) {
    if (flg) {
        cout << hoge << endl;
        exit(0);
    }
}
#define all(v) v.begin(), v.end()
#define inputv(v, n)                                                           \
    vl v;                                                                      \
    rep(i, n) {                                                                \
        ll x;                                                                  \
        cin >> x;                                                              \
        v.push_back(x);                                                        \
    }
const ll INF = 999999999999999;
const ll MOD = 1000000007;
const ll MAX_N = 500010;
ll a, b, c, d, e, f, p, t, x, y, z, q, m, n, r, h, k, w, l, ans;
int main() {
    cin >> n;
    while (n > 0) {
        a++;
        n = n / 2;
    }

    cout << (1LL << a) - 1 << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

public class Main implements Closeable {

  private InputReader in = new InputReader(System.in);
  private PrintWriter out = new PrintWriter(System.out);

  public void solve() {
    n = in.ni();
    for (int i = 0; i <= n; i++) {
      graph.add(new ArrayList<>());
    }
    for (int i = 1; i < n; i++) {
      graph.get(i).add(i + 1);
      graph.get(i + 1).add(i);
    }
    int x = in.ni(), y = in.ni();
    graph.get(x).add(y);
    graph.get(y).add(x);
    result = new int[n];
    for (int start = 1; start <= n; start++) {
      bfs(start);
    }
    for (int k = 1; k < n; k++) {
      out.println(result[k] / 2);
    }
  }

  private int n;
  private List<List<Integer>> graph = new ArrayList<>();
  private int[] result;

  private void bfs(int start) {
    ArrayDeque<Integer> queue = new ArrayDeque<>();
    queue.add(start);
    int[] dist = new int[n + 1];
    boolean[] visited = new boolean[n + 1];
    visited[start] = true;
    while (queue.size() > 0) {
      int u = queue.pollFirst();
      for (int v : graph.get(u)) {
        if (!visited[v]) {
          dist[v] = dist[u] + 1;
          visited[v] = true;
          queue.add(v);
          result[dist[v]]++;
        }
      }
    }
  }

  @Override
  public void close() throws IOException {
    in.close();
    out.close();
  }

  static class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
      reader = new BufferedReader(new InputStreamReader(stream), 32768);
      tokenizer = null;
    }

    public String next() {
      while (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          tokenizer = new StringTokenizer(reader.readLine());
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
      return tokenizer.nextToken();
    }

    public int ni() {
      return Integer.parseInt(next());
    }

    public long nl() {
      return Long.parseLong(next());
    }

    public void close() throws IOException {
      reader.close();
    }
  }

  public static void main(String[] args) throws IOException {
    try (Main instance = new Main()) {
      instance.solve();
    }
  }
}


Measured memory_bytes: 57172
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<stdio.h>
#include<stdlib.h>
#include<cassert>
using namespace std;

#define N 8
#define FREE -1
#define NOT_FREE 1

int row[N], col[N], dpos[2 * N -1], dneg[2 * N -1];

bool X[N][N];

void initialize() {
    for (int i = 0; i < N; i++) {
        row[i] = FREE, col[i] = FREE;
    }
    for (int i = 0; i < N; i++) {
        dpos[i] = FREE;
        dneg[i] = FREE;
    }
}

void printBoard() {
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            if (X[i][j]) {
                if(row[i] != j) return;
            }
        }
    }
    for(int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            cout << ((row[i] == j) ? "Q" : "." );
        }
        cout << endl;
    }
}

void recursive(int i) {
    if (i == N) {
        printBoard();
        return;
    }
    
    for (int j = 0; j < N; j++) {
        if (NOT_FREE == col[j] || NOT_FREE == dpos[i + j] || NOT_FREE == dneg[i - j + N - 1]) continue;
        row[i] = j;
        col[j] = dpos[i + j] = dneg[i - j + N - 1] = NOT_FREE;
        recursive(i + 1);
        row[i] = col[j] = dpos[i + j] = dneg[i - j + N - 1] = FREE;
    }
}

int main() {
    initialize();
    
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) X[i][j] = false;
    }
    
    int k;
    cin >> k;
    for(int i = 0; i < k; i++) {
        int r, c;
        cin >> r >> c;
        X[r][c] = true;
    }
    
    recursive(0);
    
    return 0;
}


Measured memory_bytes: 3128
#include <iostream>

using namespace std;
typedef long long ll;
#define REP(i,n) for (ll i = 0; i < (n); ++i)

int main(){
    ll a, b, x;
    cin >> a >> b >> x;
    cout << b / x - a / x + (a % x == 0) << endl;
    return 0;
}


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

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

  vector<tuple<int, int, int>> keys;
  keys.reserve(M);
  for (int i = 0; i < M; i++) {
    int a,b; cin>>a>>b;
    int s = 0;
    for (int j = 0; j < b; j++) {
      int c; cin>>c;
      c--;
      s |= 1<<c;
    }
    keys.emplace_back(a,b,s);
  }

  vector<int> dp(1<<N, INF);
  dp[0] = 0;
  for (int s = 0; s < 1<<N; s++) {
    for (int i = 0; i < M; i++) {
      int t = s | get<2>(keys[i]);
      dp[t] = min(dp[t], dp[s] + get<0>(keys[i]));
    }
  }

  int ans = dp.back();
  if (ans == INF) ans = -1;
  cout << ans << endl;

  return 0;
}


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

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ for(auto it : P) { s << "<" << it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ for(auto it : P) { s << "<" << it.first << "->" << it.second << "> "; } return s << endl; }
 

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using ll = long long;
using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using ld = long double;
using str = string;

#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

long int M = 1e+9+7;
int inf = 1e+9;

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << std::setprecision(10);


    int ans=0;    
    int n;
    cin >> n;
    int iti = n%10;
    if(iti == 3){
        cout << "bon" << endl;
    }else if(iti == 0 || iti == 1 || iti == 6 || iti == 8){
        cout << "pon" << endl;
    }else{
        cout << "hon" << endl;   
    }

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

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define N 10000000
using namespace std;

int main(){
  while(1){
    int m,n;
    cin>>m>>n;
    if(!m&&!n) break;
    vector<bool> used(N);
    for(int i=0,cnt=0;cnt<n;i++)
      if(!used[m+i]){
	cnt++;
	for(int j=m+i;j<N;j+=m+i) used[j]=1;
      }
    int ans=m;
    while(used[ans])ans++;
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 4288
N = int(input())
L = []
res = []

for i in range(N):
    S = input()
    L.append(S)

L.sort()

max_cnt = 0
cnt = 0

L.append(0)

for i in range(len(L) - 1):
    if L[i] == L[i+1]:
        cnt += 1
    else:
        if cnt > max_cnt:
            max_cnt = cnt
            res = []
            res.append(L[i])
        elif cnt == max_cnt:
            res.append(L[i])
        cnt = 0

for i in res:
    print(i)

Measured memory_bytes: 25188
#include<bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n ; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x) // decltypeで型取得、引数があればva_argsのところに入れる
using namespace std;
typedef long long ll; // long longをllでかけるようにした
const int INF = 1e9;

int main(void){
    int k, x; cin >> k >> x;
    cout << (500*k >= x ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define sz(x) (int)(x.size())

int digit_sum(int x) {
    int res = 0;
    while (x > 0) {
        res += x % 10;
        x /= 10;
    }
    return res;
}
signed main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int n;
    cin >> n;
    int dp[n];
    for (int i = 1; i < n; i++) {
        dp[i] = digit_sum(i);
    }
    int ans = n * 1000;
    for (int i = 1; i < n; i++) {
        ans = min(ans, dp[i] + dp[n - i]);
    }
    cout << ans << "\n";
}

Measured memory_bytes: 1024
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        A solver = new A();
        solver.solve(1, in, out);
        out.close();
    }

    static class A {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int a = Integer.parseInt(in.next());
            int b = Integer.parseInt(in.next());

            // 出力
            if (b >= a) {
                out.println("unsafe");
            } else {
                out.println("safe");
            }

        }

    }
}



Measured memory_bytes: 35792