akhauriyash/Code-Regression huggingface dataset:
def get_gcd(a, b):
    while b != 0:
        a, b = b, a % b
    return a

def get_lcm(a, b, gcd=0):
    if gcd == 0:
        return a * b // get_gcd(a, b)
    else:
        return a * b // gcd


N = int(input())

T = []

for n in range(N):
    T.append(int(input()))

R = T[0]

for n in range(1, N):
    R = get_lcm(R, T[n])

print(R)


Measured memory_bytes: 3064
//--- pB ---//
import java.util.*;
import java.lang.*;
import java.io.*;
public class Main {
	public static void main (String[] args) throws java.lang.Exception {
		new Solution();
	}
}
class Solution {
	Reader reader;
	PrintWriter out;
	public Solution() {
		reader = new Reader();
		out = new PrintWriter(System.out);
		while (reader.hasNext()) {
			run_case();
		}
		out.flush();
	}

	private void run_case() {
		int t_h = reader.ni();
		int t_s = reader.ni();
		int a_h = reader.ni();
		int a_s = reader.ni();
		int dir = 1;

		int res = 0; // 0 -> t

		while (true) {
			if (dir == 1) {
				a_h -= t_s;
				if (a_h <= 0) {
					res = 0;
					break;
				}
			} else {
				t_h -= a_s;
				if (t_h <= 0) {
					res = 1;
					break;
				}
			}
			dir ^= 1;
		}

		if (res == 0) {
			out.println("Yes");
		} else {
			out.println("No");
		}

		return;
	}
}


class Reader {
	BufferedReader br;
	StringTokenizer st;
	public Reader(){
		try {
			br = new BufferedReader(new InputStreamReader(System.in));
			st = new StringTokenizer(br.readLine());
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	public String next() {
		if (st.hasMoreTokens()) return st.nextToken();
		try {
			st = new StringTokenizer(br.readLine());
		} catch (Exception e) {
			e.printStackTrace();
		}
		return st.nextToken();
	}
	public boolean hasNext() {
		try {
			if (!st.hasMoreTokens() && !br.ready()) return false;
			else return true;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return false;
	}
	public int ni() {return Integer.parseInt(this.next());}
	public long nl() {return Long.parseLong(this.next());}
	public String ns() {return this.next();}
}


Measured memory_bytes: 32736
////////////////////////////////////////////    _LeMur_
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#include <unordered_map>
#include <unordered_set>
#include <functional>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cassert>
#include <chrono>
#include <random>
#include <bitset>
#include <cstdio>
#include <vector>
#include <string>
#include <ctime>
#include <stack>
#include <queue>
#include <cmath>
#include <list>
#include <map>
#include <set>

using namespace std;

const int N = 150005;
const int inf = 1000 * 1000 * 1000;
const int mod = 998244353;

string s;

int main(){
	mt19937 myrand(chrono::steady_clock::now().time_since_epoch().count());
    cin >> s;
    int answ = 15 - (int)s.size();
    for(int i=0;i<(int)s.size();i++){
        answ += (s[i] == 'o');
    }
    if(answ >= 8)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define int long long
#define inf 1000000007
#define LINF 100000000000000007LL
#define ll long long
using namespace std;
signed main(){
	int n;
	cin>>n;
	int ans = 0;
	int sum = 0;
	for(int i=0;i<n;i++){
		int x,y;
		cin>>x>>y;
		ans += y;
		sum += x*y;
	}
	ans += sum/9;
	ans--;
	if( sum%9 == 0 )ans--;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	
	for i := 0.0; i < 50000; i++ {
		var tax float64
		tax = i * 1.08
		if int(tax) == n {
			fmt.Println(int(i))
			return
		}
	}
	fmt.Println(":(")
}

Measured memory_bytes: 512
<?php
  fscanf(STDIN, "%d %d", $X, $Y);
  for($i = 0; $i < $X+1; $i++){
      $j = $X - $i;
      if($i*2 + 4*$j == $Y){
          echo "Yes" ."\n";
          return;
      }
  }  
	echo "No" . "\n";
?>

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

#define sz(x) int(x.size())
#define Task "abc"
#define For(i, a, b) for(int i = (a), _b = (b); i <= b; ++i)
#define All(x) (x).begin(), (x).end()
#define mp make_pair

typedef unsigned long long ull;
typedef long long ll;

const int maxn = 1e5 + 10;
const int inf = 0x3f3f3f3f;
const ll mod = 1e9 + 7;

int main(){
  ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0);
//  freopen(Task".inp", "r", stdin); freopen(Task".out", "w", stdout);
  int n, m;
  cin >> n >> m;
  if (m >= n) cout << "unsafe";
  else cout << "safe";
}



Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
int main() {
  vector<int> a(3);
  for (int i = 0; i < 3; i++) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  int x = a[0]-a[1];
  int y = a[1]-a[2];
  cout << abs(x+y) << endl;
}

Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <sstream>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <complex>
#include <vector>
#include <bitset>
#include <cstdio>
#include <cmath>
#include <time.h>
#include <tuple>
#define all(c) ((c).begin(),(c).end())
#define rall(c) ((c).rbegin(),(c).rend())
#define ll long long
#define fi first
#define se second
#define inf (999999999)
using namespace std;
const ll MOD = 1e9 + 7;
const double PI = acos(-1.0);
//---------------------------------------------------------------------------------------------//
int n, m, t;
int a[110];

int main() {
	cin >> n >> m >> t;
	bool b[20100];
	for (int i = 0; i < t; i++)b[i] = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		for (int j = a[i] - m; j <= a[i]+m-1; j++) {
			b[j] = 1;
		}
	}
	int ans = 0;
	for (int i = 0; i < t; i++) {
		if (b[i]==0)ans++;
	}
	cout << ans<< endl;
	return 0;
}

Measured memory_bytes: 3104
#include<bits/stdc++.h>
using namespace std;
#define int long long
#ifdef LOCAL
#include<debug.h>
#else
#define db(...) 21
#endif
#define found(m,x) ((m).find(x)!=(m).end())
#define uset unordered_set
#define umap unordered_map
#define a(x) x.begin(),x.end()
#define fo(i,n) for(int i=0;i<(int)n;i++)
#define Fo(i,k,n) for(int i=k;k<n?i<=(int)n:i>=(int)n;k<n?i++:i--)
#define input(v,n) fo(i,n)cin>>v[i]
typedef vector<int> vi;
typedef long long ll;
typedef pair<int,int> pi;

const int nax = 1e5+7;
const int mod = 1e9+7; //1e9+2667 :: 0xcf : inf, 0xc0 -inf
const int inf = numeric_limits<int> :: max() - (int)1e3;
// ===================== MANASH =================== //

int n,m;

void test() {
	int x;
	cin >> x;
	cin >> n;
	set<int> s;
	for( int i = 0; i < n; i++) {
		int a;
		cin >> a;
		s.insert(a);
	}
	int f = 0, b = 0;
	for( int i = 0; ; i++) {
		if(!found(s,x+i)) {
			f = i;
			break;
		}
	}
	for( int i = -1; ; i--) {
		if(!found(s,x+i)) {
			b = i;
			break;
		}
	}
	if ( f == -b ) {
		cout << min(x+f,x+b);
		return;
	}
	// db(x,f,b);
	cout << (f > -b ? x+b : x+f);
}

signed main() {

	ios_base :: sync_with_stdio(false);
	cin.tie(NULL);

	#ifdef LOCAL
	freopen("input.txt","r",stdin);
	cout<<"Time Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec.\n";
	#endif

	int T = 1;
	//cin >> T;
	while(T--) {
		test();
		cout << "\n";
	}
	return 0;

}

Measured memory_bytes: 3620
from fractions import gcd

N = int(input())

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

divs = make_divisors(N)
#print(divs)
min_cnt = 10 ** 13
for d in divs:
    #print(d)
    x = N // d
    if (d + x - 2) < min_cnt:
        min_cnt = d + x - 2
print(min_cnt)

Measured memory_bytes: 5560
import java.util.Scanner;
import java.io.PrintWriter;

public class Main {
	static Scanner scan = new Scanner(System.in);
	static PrintWriter out = new PrintWriter(System.out);
	public static void main(String[] args){
		while(true){
			int n = si();
			if(n==0) break;
			boolean[][] list = new boolean[n][30];
			long[] map = new long[n];
			int res = -1;
			for (int i = 0; i < n; i++) {
				int m = si();
				map[i]=1L<<i;
				for (int j = 0 ;j < m ; j++)
					list[i][si()-1]=true;
			}
			for (int i = 0; i < 30; i++) {
				long tmp = 0;
				for (int j = 0; j < n; j++)
					if(list[j][i]) tmp |= map[j];
				for (int j = 0; j < n; j++)
					if(list[j][i]) map[j]=tmp;
				if(tmp==(1L<<n)-1){
					res = i+1;
					break;
				}
			}
			out.println(res);
		}
		out.flush();
	}
	static int si(){
		return Integer.parseInt(scan.next());
	}
}

Measured memory_bytes: 69264
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>

using namespace std;

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

int main(){

  int N, K; cin >> N >> K;
  string S; cin >> S;

  int ans = 0;
  for (int i = 0; i < S.length() - 1; i++){
    if (S[i] == S[i + 1]){
      ans++;
    }
  }
  
  ans += 2 * K;
  if (ans < N){
    cout << ans << endl;
  }else{
    cout << N - 1 << endl;
  }
  
  

  

  return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
typedef pair<int, ll> il;
typedef pair<ll , ll> lli;
typedef pair<ull , ull> ulli;
typedef vector<ii> vii;
typedef vector<il> vil;
typedef vector<li> vli;
typedef vector<lli> vlli;
typedef set <int> st;
typedef set <char> stc;
typedef vector<int>::iterator itr;

#define df first
#define ds second
#define pb push_back
#define mp make_pair
#define in insert
#define f0(b) for(int i=0;i<(b);i++)
#define f00(b) for(int j=0;j<(b);j++)
#define f1(b) for(int i=1;i<=(b);i++)
#define f11(b) for(int j=1;j<=(b);j++)
#define f2(a,b) for(int i=(a);i<(b);i++)
#define f22(a,b) for(int j=(a);j<(b);j++)
#define sq(a) a*a
#define cu(a) (sq(a)*a)


const int hell = (int)1e9+7;
const int maxn = (int)2e5+5;
const int inf = 1e9+9;
const ll INF = 1e18;


int main() 
{ 
    ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
    
    string a[]= {"SUN", "MON", "TUE" , "WED" , "THU" , "FRI", "SAT"};
    
    string s;
    
    cin >> s;
    
    int q;
    
    f0(7){
    	
    	if(s == a[i]){
    		
    	q=7-i;
		break;	
		}
    	
	}
	
	cout << q;
     
    return 0; 
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
#define SortAsc(c) std::sort(c.begin(), c.end())
#define SortDesc(c) std::sort(c.rbegin(), c.rend())
int dx[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int dy[8] = {1, 0, -1, 0, 1, -1, 1, -1};

const ll maxVal = 1000000000000000000;
int main() {
  int n;
  cin >> n;
  vector<ll> a(n);

  for (int i = 0; i < n; i++) {
    cin >> a.at(i);

    if (a.at(i) == 0) {
      cout << 0 << endl;
      return 0;
    }
  }

  ll ans = a.at(0);
  ll prev = a.at(0);

  for (int i = 1; i < n; i++) {
    if (maxVal / ans < a.at(i)) {
      cout << -1 << endl;
      return 0;
    }
    ans *= a.at(i);

    ll check = ans / a.at(i);
    if (check != prev) {
      cout << -1 << endl;
      return 0;
    }
    prev = ans;
  }
  cout << ans << endl;
}

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

struct edge_t {
	int cost;
	int l;
	int r;
} ;

int compare_edge(const void *a, const void *b) {
  struct edge_t *A = (struct edge_t *)a;
  struct edge_t *B = (struct edge_t *)b;
  return A->cost - B->cost;
}

struct tosi_t {
	int idnum;
	int x;
	int y;
} ;

int compare_x(const void *a, const void *b) {
  struct tosi_t *A = (struct tosi_t *)a;
  struct tosi_t *B = (struct tosi_t *)b;
  return A->x - B->x;
}

int compare_y(const void *a, const void *b) {
  struct tosi_t *A = (struct tosi_t *)a;
  struct tosi_t *B = (struct tosi_t *)b;
  return A->y - B->y;
}

static int par[200010];//親
static int rank[200010];//木の深さ

//n要素で初期化
void init(int n){
	int i;
	for(i=0;i<n;i++){
		par[i]=i;
		rank[i]=0;
	}
}

//木の根を求める
int find(int x){
	if(par[x]==x){
		return x;
	}else{
		par[x]=find(par[x]);
		return par[x];
	}
}

//xとyの属する集合を併合
void unite(int x, int y){
	x=find(x);
	y=find(y);
	if(x==y) return;
	if(rank[x]<rank[y]){
		par[x]=y;
	}else{
		par[y]=x;
		if(rank[x]==rank[y])rank[x]++;
	}
}



int main(void)
{
	//変数の宣言
	int n;
	static struct edge_t edge[200010];
	static struct tosi_t tosi[100010];

	//よく使う変数
	int i,j,k,l;
	int flag=0;
	long int ans=0;
	int count=0;
	int temp,temp1,temp2;
	int max,min;
	int len;
	//データの読み込み
	
	scanf("%d",&n);
	
	for(i=0;i<n;i++){
		scanf("%d %d",&tosi[i].x,&tosi[i].y);
		tosi[i].idnum=i;
	}


//	printf("nは%dです\n", n);
//	printf("データの読み込み終了\n");
	//実際の処理
	
//	printf("そのまま\n");
//	for(i=0;i<n;i++){
//		printf("%d %d %d\n",tosi[i].idnum,tosi[i].x,tosi[i].y);
//	}
	
	qsort(tosi,n,sizeof(struct tosi_t),compare_x);
	
//	printf("xでsort\n");
//	for(i=0;i<n;i++){
//		printf("%d %d %d\n",tosi[i].idnum,tosi[i].x,tosi[i].y);
//	}
	
	for(i=0;i<n-1;i++){
		edge[i].cost=tosi[i+1].x-tosi[i].x;
		edge[i].l=tosi[i].idnum;
		edge[i].r=tosi[i+1].idnum;
	}
	
	
	qsort(tosi,n,sizeof(struct tosi_t),compare_y);
	
//	printf("yでsort\n");
//	for(i=0;i<n;i++){
//		printf("%d %d %d\n",tosi[i].idnum,tosi[i].x,tosi[i].y);
//	}
	
//	printf("edge\n");
	for(i=0;i<n-1;i++){
		edge[i+n-1].cost=tosi[i+1].y-tosi[i].y;
		edge[i+n-1].l=tosi[i].idnum;
		edge[i+n-1].r=tosi[i+1].idnum;
//		printf("%d %d %d\n",edge[i+n-1].cost,edge[i+n-1].l,edge[i+n-1].r);
	}
	
	
	qsort(edge, 2*n-2, sizeof(struct edge_t), compare_edge);

	init(200010);
	for(i=0;i<2*n-2;i++){
		if(find(edge[i].l)!=find(edge[i].r)){
			unite(edge[i].l,edge[i].r);
			ans=ans+edge[i].cost;
		}
	}

//	printf("計算部分終了\n");
	//出力
	
	printf("%d",ans);
	
//	printf("結果の出力終了\n");
	
	return 0;
	
}



Measured memory_bytes: 7784
import collections
import itertools


N =int(input())
List = []
Dictionary = []
for i in range(N):
    In = input()
    List.append(In)
    
counters= collections.Counter(List)
counter = sorted(counters.items())
mode_v = counters.most_common()[0][-1]

for j in range(len(counter)):
    an = counter[j][1]
    if mode_v == an:
        print(counter[j][0])
    else:
        continue

Measured memory_bytes: 59372
# 2つの入力を空白で分割し、数値化
L, R = map(int, input().split())

left = range(L, R)
right = range(L+1, R+1)

minmond = 2019
for l in left:
    for r in right:
        x = l * r
        mod = x % 2019
        minmond = min(minmond, mod)
        if minmond == 0:
            print(0)
            exit(0)
print(minmond)

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

#define LEN 100005

typedef struct pp{
    char name[100];
    int t;
} P;

P Q[LEN];
int head, tail, n;

void enqueue(P x){
    Q[tail] = x;
    tail = (tail + 1) % LEN;
}

P dequeue(){
    P x = Q[head];
    head = (head+1) % LEN;
    return x;
}

int min(int a, int b) { return a < b ? a : b;}

int main(){
    int elaps = 0, c;
    int i, q;
    P u;
    cin >> n >> q;
    for(int  i = 1; i <= n; i++)
    {
        cin >> Q[i].name >> Q[i].t;
    }

    head = 1; tail = n+1;

    while(head!=tail){
        u = dequeue();
        c = min(q, u.t);
        u.t -= c;
        elaps += c;
        if(u.t > 0) enqueue(u);
        else cout << u.name << ' ' << elaps << endl;
    }
    

    return 0;
}


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

int main() {
  int N; cin >> N;
  vector<int> d(N);
  for(int i=0; i<N; i++){
    cin >> d.at(i);
  }
  int ans = 0;
  
  sort(d.begin(), d.end());
  
  ans = 1;
  for(int i=1; i<N; i++){
    if(d.at(i-1) < d.at(i)) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#
# Written by NoKnowledgeGG @YlePhan
# ('ω')
#
#import math
#mod = 10**9+7
#import itertools
#import fractions
#import numpy as np
#mod = 10**4 + 7
def kiri(n,m):
  r_ = n / m
  if (r_ - (n // m)) > 0:
    return (n//m) + 1
  else:
    return (n//m)
  
def main():
  n,d = map(int,input().split())
  d = d*2 + 1
  print(kiri(n,d))
  
if __name__ == '__main__':
  main()

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

using namespace std;

#define INF 1000000007
int h, w;
int dp[1000][1000];
char xy[1000][1000];

int dfs(int i, int j){
  if(xy[i][j] == '.'){
    if(i > 0) dp[i][j] += dp[i-1][j];
    dp[i][j] %= INF;
    if(j > 0) dp[i][j] += dp[i][j-1];
    dp[i][j] %= INF;
  }
  if(i != h-1 && j == w-1) dfs(i+1, 0);
  else if (j != w-1) dfs(i, j+1);
  return 0;
}

int main(){
  cin >> h >> w;
  for(int i = 0; i < h ; i++){
    for(int j = 0; j < w; j++){
      cin >> xy[i][j];
      dp[i][j] = 0;
    }
  }
  dp[0][0] = 1;
  dfs(0, 0);
  cout << dp[h-1][w-1] << endl;
}


Measured memory_bytes: 20736
N = int(input())
L = list(map(int,input().split()))

c = 0

for i in range(N):
    for j in range(N):
        for k in range(N):
            if j <= i or k <= j:
                continue

            if L[i] == L[j] or L[j] == L[k] or L[k] == L[i]:
                continue

            if L[i] + L[j] <= L[k] or L[k] <= abs(L[i] -L[j]):
                continue

            c += 1 

print(c)

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

int main()
{
	int N; cin >> N;
	set<int> s;
	for (int i = 0; i < N; ++i) {
		int d; cin >> d;
		s.insert(d);
	}
	cout << s.size() << endl;
	return 0;
}

Measured memory_bytes: 3148
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <set>
#include <array>
#include <stdio.h>
#include <string.h>
using ll = long long;
using ull = unsigned long long;
using namespace std;
#define int long long
#define CONTAINS_VEC(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define ARY_REVERSE(v,a) (reverse((v), (v)+(a)))
#define REP(i, n) for (int (i)=0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
#define CONTAINS_SET(m, a) (m).find((a)) != m.end()
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }

int flg[1000001];

signed main()
{
	int A, B;
	cin >> A >> B;
	YesNo(A != 2 && B != 2);
}



Measured memory_bytes: 3084
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	if(a==1 && b==1 && c==1)
	{
		cout<<"1"<<endl;
	}
	else
	{
	vector<int>v;
	int f = min(a,b);
	for(int i=1;i<=f;i++)
	{
		if((a%i)==0 && (b%i)==0)
		{
			v.push_back(i);
		}
	}
	sort(v.rbegin(),v.rend());
	cout<<v[c-1]<<endl;
	}
	return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define ll long long
using namespace std;
char s[100005];
int main (){
	int i,len,ans;
	scanf ("%s",s+1);
	ans=len=strlen(s+1);
	for (i=2;i<=len;i++)
	{if (s[i]!=s[i-1])
	{ans=min(ans,max(i-1,len-i+1));}
	}
	printf ("%d\n",ans);
	return 0;
}

Measured memory_bytes: 384
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)



vector<bool> f;

int main() {
    int m, n;
    cin >> m >> n;
    
    while(m | n){
        int k = 0;
        f.assign(8000000, false);
        for(int i = 2; i < 8000000; i++){
            if(!f[i] && i >= m){
                if(k < n){
                    k++;
                    for(int j = i; j < 8000000; j += i){
                        f[j] = true;
                    }
                }
                
                if(!f[i]){
                    cout << i << '\n';
                    break;
                }
            }
        }
        
        cin >> m >> n;
    }
}


Measured memory_bytes: 3824
#include<cstdio>
using namespace std;
typedef long long ll;
const int N=100100,P=1000000007;
int i,j,k,n,m,ch,ff,l,r,ans;
int Jc[N],Jc_[N],a[N],fg[N];
void R(int &x) {
	ff=x=0;ch=getchar();
	while (ch<'0' || '9'<ch) { if (ch=='-') ff=1;ch=getchar();}
	while ('0'<=ch && ch<='9') x=x*10+ch-'0',ch=getchar();
	if (ff) x=-x;
}
void R(ll &x) {
	ff=x=0;ch=getchar();
	while (ch<'0' || '9'<ch) { if (ch=='-') ff=1;ch=getchar();}
	while ('0'<=ch && ch<='9') x=x*10+ch-'0',ch=getchar();
	if (ff) x=-x;
}
void W(int x) {
	if (x>=10) W(x/10);
	putchar(x%10+'0');
}
void W(ll x) {
	if (x>=10) W(x/10);
	putchar(x%10+'0');
}
int ksm(int x,int y) {
	int z=1;
	for (;y;y>>=1,x=(ll) x*x%P) if (y&1) z=(ll) z*x%P;
	return z;
}
void pre(int n) {
	Jc[0]=Jc_[0]=1;
	int i,j,k;
	for (i=1;i<=n;i++) Jc[i]=(ll) Jc[i-1]*i%P;
	Jc_[n]=ksm(Jc[n],P-2);
	for (i=n-1;i;i--) Jc_[i]=(ll) Jc_[i+1]*(i+1)%P;
}
int C(int n,int m) {
	if (n<m) return 0;
	return (ll) Jc[n]*Jc_[m]%P*Jc_[n-m]%P;
}
int main() {
	R(n);
	pre(n+1);
	for (i=1;i<=n+1;i++) {
		R(a[i]);
		if (fg[a[i]]) {
			l=fg[a[i]]-1;
			r=n+1-i;
		}
		fg[a[i]]=i;
	}
	for (i=1;i<=n+1;i++) {
		ans=(C(n+1,i)+P-C(l+r,i-1))%P;
		W(ans);puts("");
	}
}

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

#define mp make_pair
#define fi first
#define se second
#define pb push_back

typedef long long ll;
typedef pair<int,int> ii;
typedef pair<ii,int> iii;
typedef pair<ll,ll> pll;

const int N = 2e5+2;
int n;
int ar[N];

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n;
    int xo = 0;
    for (int i = 1; i <= n; i++)
    {
        cin >> ar[i];
        xo ^= ar[i];
    }
    for (int i = 1; i <= n; i++)
    {
        cout << (xo ^ ar[i]) << ' ';
    }
    cout << '\n';
    return 0;
}

Measured memory_bytes: 4368
import sys
input = sys.stdin.readline
import numpy as np


N = int(input())
A = np.array([int(i) for i in input().split()])
maxA = max(A)

MOD = 10**9 + 7

answer = 0
# (i+1)桁目のとき、power_of_2 = 2^i
i = 0
power_of_2 = 1
while maxA:
    B = (A >> i) & 1
    # 1の個数
    count1 = np.count_nonzero(B)
    # 0の個数
    count0 = N - count1
    # XORが1となる個数
    count = count0 * count1
    answer = (answer + count * power_of_2) % MOD

    i += 1
    maxA >>= 1

    power_of_2 = (power_of_2 * 2) % MOD

print(answer)

Measured memory_bytes: 48828
#include <stdio.h>
int main(){
	char a;
	scanf("%c",&a);printf("%c",a);
	scanf("%c",&a);printf("%c",a);
	scanf("%c",&a);printf("%c",a);
	scanf("%c",&a);printf("%c",a);
	printf(" ");
	scanf("%c",&a);printf("%c",a);
	scanf("%c",&a);printf("%c",a);
	scanf("%c",&a);printf("%c",a);
	scanf("%c",&a);printf("%c",a);
	scanf("%c",&a);printf("%c",a);
	scanf("%c",&a);printf("%c",a);
	scanf("%c",&a);printf("%c",a);
	scanf("%c",&a);printf("%c",a);
	printf("\n");
	return 0;
}
	

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int SIZE = 1e5 + 666;

int dp[SIZE];
int tab[SIZE];
int n;

    void input(){
        cin >> n;
        for(int i = 0; i < n; i++)
            cin >> tab[i];
    }

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

    input();

    dp[0] = 0;
    dp[1] = abs(tab[0] - tab[1]);

    for(int i = 2; i < n; i++)
        dp[i] = min(dp[i - 1] + abs(tab[i] - tab[i - 1]), dp[i - 2] + abs(tab[i] - tab[i - 2]));     
    return cout << dp[n - 1], 0;
}

Measured memory_bytes: 1024
#include <cstdio>
 #include <cstdlib>
 #include <iostream>
 #include <fstream>
 #include <sstream>
 #include <set>
 #include <map>
 #include <vector>
 #include <list>
 #include <algorithm>
 #include <cstring>
 #include <cmath>
 #include <string>
 #include <queue>
 #include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
 #include <cassert>
 #include <iomanip>        //do setprecision
 #include <ctime>
 #include <complex>
 using namespace std;

 #define FOR(i,b,e) for(int i=(b);i<(e);++i)
 #define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
 #define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
 #define REP(x, n) for(int x = 0; x < (n); ++x)

 #define ST first
 #define ND second
 #define PB push_back
 #define PF push_front
 #define MP make_pair
 #define LL long long
 #define ULL unsigned LL
 #define LD long double
 #define pii pair<int,int>
 #define pll pair<LL,LL>

 const double pi = 3.14159265358979323846264;
 const int mod=1000000007;

int main(){
	LL k;
	cin>>k;
	vector<int> v(k+1,mod);
	priority_queue<pll> q;
	q.push(MP(-1,1));
	while(q.size()){
		pll pr=q.top();
		q.pop();
		LL d=-pr.ST,num=pr.ND;
		if(d>v[num])continue;
		if(d+1<v[(num+1)%k]){
			v[(num+1)%k]=d+1;
			q.push(MP(-(d+1),(num+1)%k));
		}
		if(d<v[(num*10)%k]){
			v[(num*10)%k]=d;
			q.push(MP(-d,(num*10)%k));
		}
	}
	cout<<v[0]<<endl;
	return 0;
}


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

const int MAX_C = 31;
const int MAX_T = (int) 1e5 + 1;

int pgm[MAX_C][MAX_T];

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

    int N, C;
    cin >> N >> C;

    while (N--) {
        int s, t, c;
        cin >> s >> t >> c;
        for (int i = s; i <= t; ++i) {
            pgm[c][i] = 1;
        }
    }

    int max_count = 0;
    for (int i = 1; i < MAX_T; ++i) {
        int count = 0;
        for (int j = 1; j <= C; ++j) {
            count += pgm[j][i];
        }
        max_count = max(max_count, count);
    }

    cout << max_count << '\n';

    return 0;
}


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

int main() {
  char a;
  cin>>a;
  if(a=='A'){
  cout <<'T'<< endl;
  }
   else if(a=='C'){
  cout <<'G'<< endl;
  }
  else if(a=='G'){
  cout <<'C'<< endl;
  }
  else {
  cout <<'A'<< endl;
  }
  
}




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


#define rep(s, e) for(int i(s); i < e; ++i)
#define mojinokazu 3

int main() {
    int marble_num(0);
    char tmp('\0');
    rep(0, 3) {
        cin >> tmp;
        if(tmp == '1') {
            marble_num += 1;
        }
    }
    cout << marble_num << "\n";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,k,num=0;
    scanf("%d%d",&n,&k);
    string s;
    cin>>s;
    for(int i=1;i<s.length();i++){
        if(s[i]==s[i-1]) num++;
    }
    for(int i=1;i<=k;i++){
        num=num+2;
    }
    printf("%d",min(num,n-1));
}

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

int main(){
	char p[5][6] =
	{{'a','f','k','p','u','z'},
	 {'b','g','l','q','v','.'},
	 {'c','h','m','r','w','?'},
	 {'d','i','n','s','x','!'},
	 {'e','j','o','t','y',' '}};
	string a;	
	while(cin >> a){
		bool flag = false;
		for(size_t i=0;i<a.size();i+=2){
			if(a[i]>'6' || a[i]<'1')
				flag = true;
			if(a[i+1]>'5' || a[i]<'1')
				flag = true;
		}
		if(flag||a.size()%2){
			cout << "NA" << endl;
		}else{
			for(size_t i=0;i<a.size();i+=2){
				cout << p[a[i+1]-'0'-1][a[i]-'0'-1];
			}
			cout << endl;
		}
	}
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
vector<int>v;
main()
{
	int t,p;
    scanf("%d",&t);
    for(int i = 0;i < t;i++)
    {
        scanf("%d",&p);
        v.push_back(p);
    }
    sort(v.begin(),v.end());
    int mx=0,pos=0;
    for(int i = 0;i < t-1;i++)
    {
        if(mx<min(v[t-1]-v[i],v[i]))
        {
            pos=i;
            mx=min(v[t-1]-v[i],v[i]);
        }
    }
    printf("%d %d",v[t-1],v[pos]);
}


Measured memory_bytes: 892
while True:
    n,m=map(int,input().split())
    if n==0:
        break
    nmax=0
    a=list(map(int,input().split()))
    for i in range(n):
        for j in range(i+1,n):
            sum=a[i]+a[j]
            if nmax<sum<=m:
                nmax=sum
    if nmax==0:
        print("NONE")
    else :
        print(nmax)


Measured memory_bytes: 5624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
constexpr int mod=1000000007;
constexpr int mod1=998244353;
vector<int> dx={0,1,0,-1},dy={-1,0,1,0};
bool inside(int y,int x,int h,int w){
	if(y<h && y>=0 && x<w && x>=0) return true;
	return false;
}


ll f[1000001],rf[1000001];

ll inv(ll x){
	ll ret=1;
	ll k=mod-2;
	ll y=x;
	while(k){
		if(k&1) ret=(ret*y)%mod;
		y=(y*y)%mod;
		k/=2;
	}
	return ret;
}

void init(){
	f[0]=1;
	for(int i=1;i<=1000000;++i) f[i]=(f[i-1]*i)%mod;
	rep(i,1000001) rf[i]=inv(f[i]);
}

ll calc(int n,int k){
	ll a=f[n];
	ll b=rf[n-k];
	ll c=rf[k];
	ll bc=(b*c)%mod;
	return (a*bc)%mod;
}


int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int x, y;cin >> x >> y;
	if(x < y) swap(x, y);
	if(x - y > y || (x + y) % 3 != 0){
		cout << 0 << endl;
		return 0;
	}
	init();
	int t = 0;
	for(int i = (x + y) / 3; i <= (x + y) / 3 * 2; i++){
		if(i == y){
			cout << calc((x + y) / 3, t) << endl;
			return 0;
		}
		t++;
	}
}


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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

typedef long long ll;
typedef long double R;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

// Problem Specific Parameter:

int main() {
  int n; cin >> n;
  string ans = "";
  while( n != 0 ) {
    if(n % 2 != 0) {
      n--;
      ans = "1" + ans;
    } else ans = "0" + ans;
    n /= -2;
  }
  if(ans == "") ans = "0";
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int arr[1000001];
int main()
{
    int n;
    cin>>n;
    vector<int> v(n);
    for(int i=0;i<n;i++)
    cin>>v[i];
    sort(v.begin(),v.end());
    for(int i=0;i<n;i++)
    { arr[v[i]]++;
        if(arr[v[i]]==1)
        {
            for(int j=2*v[i];j<=1000000;j+=v[i])
            arr[j]++;
        }
    }
    int ans=0;
    for(int i=0;i<n;i++)
    {
        if(arr[v[i]]==1)
        ans++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 7948
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1LL << 60;

int main() {
    int n;
    cin >> n;
    int p = 0, q = 0;
    for (int i = 0; i < n; i++) {
        int pin;
        cin >> pin;
        p *= 10;
        p += pin;
    }
    for (int i = 0; i < n; i++) {
        int qin;
        cin >> qin;
        q *= 10;
        q += qin;
    }
    int a = 0, b = 0;
    int max = 1;
    for (int i = 0; i < n; i++) {
        max *= 10;
    }
    int min = max / 10;
    int cnt = 0;
    bool *jun = new bool[10];

    for (int i = min; i < max; i++) {
        for (int j = 0; j < 10; j++) {
            jun[j] = false;
        }
        int m = i;
        for (int j = 0; j < n; j++) {
            // cout << m << ":" << m % 10 << endl;
            if (m % 10 > n or m % 10 == 0) {
                break;
            } else if (jun[m % 10] == true) {
                break;
            } else {
                jun[m % 10] = true;
                m /= 10;
            }
        }
        if (m != 0) {
            continue;
        }
        // cout << "jun" << i << endl;
        cnt++;
        if (p == i) {
            // cout << "aaa" << i << endl;
            a = cnt;
        }
        if (q == i) {
            // cout << "bbb" << i << endl;
            b = cnt;
        }
    }
    cout << abs(a - b) << endl;
    return 0;
}

Measured memory_bytes: 3600
#include <stdio.h>
#include <algorithm>

#define MAX_N 100000

using namespace std;

int N;

int dp[MAX_N][3];

int main() {

	scanf("%d ", &N);

	int inp[N][3];

	int i;
	for(i = 0; i<N; i++) {
		scanf(" %d %d %d", &inp[i][0], &inp[i][1], &inp[i][2]);
	
		if(i > 0) {
			dp[i][0] = max(dp[i-1][1]+inp[i][0], dp[i-1][2]+inp[i][0]);
			dp[i][1] = max(dp[i-1][0]+inp[i][1], dp[i-1][2]+inp[i][1]);
			dp[i][2] = max(dp[i-1][0]+inp[i][2], dp[i-1][1]+inp[i][2]);
		} else {
			dp[0][0] = inp[0][0];
			dp[0][1] = inp[0][1];
			dp[0][2] = inp[0][2];
		}
	}

	printf(" %d", max(dp[N-1][0], max(dp[N-1][1], dp[N-1][2])));

	return 0;
}

Measured memory_bytes: 2560
#include<stdio.h>
int main(void)
{
  int a, b;
  while(1)
  {
    scanf("%d %d", &a, &b);

    if(a == 0 && b == 0)
      {
	break;
      }
    else if(a < b)
      {
	printf("%d %d\n", a, b);
      }
    else
      {
	printf("%d %d\n", b, a);
      }
  }
}


Measured memory_bytes: 2040
import re
import sys
from collections import *
from functools import lru_cache
from heapq import *
from itertools import *
from statistics import *
from string import (
    ascii_letters as letters,
    ascii_lowercase as lcletters,
    ascii_uppercase as ucletters,
    digits
)

hexdigits='01234567890ABCDEFabcdef'
inf=float('inf')

sys.setrecursionlimit(2**31-1)

rfs=lambda:rl().split()
ri=lambda:int(rl())
ris=lambda:list(map(int,rfs()))
rls=lambda:list(sys.stdin)
rl=lambda:next(sys.stdin)
rrs=lambda:list(map(str.strip,rls()))
rs=lambda:rl().strip()
rt=lambda:sys.stdin.read()
rg=lambda:list(map(list,rrs()))
rig=lambda:[[*map(int,x.split())] for x in rls()]

def n4(i,j):
    return [
                (i-1,j),
        (i,j-1),        (i,j+1),
                (i+1,j),
    ]

def n8(i,j):
    return [
        (i-1,j-1),(i-1,j),(i-1,j+1),
        (  i,j-1),        (  i,j+1),
        (i+1,j-1),(i+1,j),(i+1,j+1),
    ]

inb=lambda i,j,m,n:0<=i<m and 0<=j<n

###########################################

N,Q=ris()

adj=defaultdict(list)
for _ in range(N-1):
    a,b=ris()
    adj[a].append(b)
    adj[b].append(a)

ct=[0]*N
for _ in range(Q):
    p,x=ris()
    ct[p-1]+=x
    
def dfs(u,p):
    if p!=-1:
        ct[u-1]+=ct[p-1]
    for v in adj[u]:
        if v!=p:
            dfs(v,u)

dfs(1,-1)

print(*ct)


Measured memory_bytes: 243224
#include<iostream>
using namespace std;
int main(){

	int N,A,B,C,D;
	
	cin >> N >> A >> B >> C >> D;
		
	int planA, planB;

	if(N % A == 0)
		planA = N / A * B;
	else
		planA = (N / A + 1) * B;

	if(N % C == 0)
		planB = N / C * D;
	else
		planB = (N / C + 1) * D;

	if(planA < planB)
		cout << planA << endl;
	else
		cout << planB << endl;

	/*
	int A,B,C,D,E;
	cin >> A >> B >> C >> D >> E;

	int answer;
	if(A < 0){
		answer = -A * C + D + B * E;
	}
	if(A > 0){
		answer = (B - A) * E;
	}
	cout << answer << endl;
	*/

	return 0;
}


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

#define rep(i, n) REP(i, 0, n)
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(x) cout << x << endl;

int main() {
    int n, d; cin >> n >> d;

    int kanshi = d * 2 + 1;
    int ans = n / kanshi;
    if(n % kanshi == 0){
        OP(ans);
    }else{
        OP(ans + 1);
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int n, m;
long long modulo = 1000000007;
long long factorial(long long n) {
	if (n == 1) return 1;
  	return (n * factorial(n-1)) % modulo;
}
int main() {
	cin >> n >> m;
  	if (abs(n-m) >= 2) {
    	cout << 0 << endl;
    } else if (n == m) {
    	cout << (2 * (factorial(m) * factorial(n)) % modulo) % modulo;
    }else {
      cout << (factorial(m) * factorial(n)) % modulo;
    }
  	return 0;
}
     

Measured memory_bytes: 4704
#include <iostream>
#include <utility>
#include <vector>
#include <queue>
#include <stack>
#include <array>
#include <algorithm>
#include <numeric>
#include <limits>
#include <string>
#include <regex>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

int main()
{
    string a, s, c;
    cin >> a >> s >> c;
    cout << 'A' << s[0] << 'C' << endl;
    return 0;
}


Measured memory_bytes: 256
N=int(input())
C=[]
for i in range(N):
  C.append((int(input()),"a")) 
for i in range(N):
  C.append((int(input()),"b")) 
C.sort()
mod=10**9+7
a,b=0,0
ans=1
for c in C:
  if c[1]=="a":
    if b>0:
      ans=(ans*b)%mod
      b-=1
    else:
      a+=1
  if c[1]=="b":
    if a>0:
      ans=(ans*a)%mod
      a-=1
    else:
      b+=1
print(ans)      
    

Measured memory_bytes: 71912
n=int(input())

a=list(map(int,input().split()))

s=[0]*(n) 
s[0]=a[n-1]
for i in range(1,n-1):
    s[i]=s[i-1]+a[n-1-i]
counter=0

for i in range(n-1):
    counter=counter+a[i]*s[n-2-i]
    
if counter>10**9+7:
  counter=counter%(10**9+7)
print(counter)

Measured memory_bytes: 31580
package main

import (
  "fmt"
  "sort"
)

func main() {
  var n, m, X, Y int 
  fmt.Scan(&n, &m, &X, &Y)
  x := make([]int, n)
  y := make([]int, m)
  for i := 0; i < n; i++ {
    fmt.Scan(&x[i])
  }
  for i := 0; i < m; i++ {
    fmt.Scan(&y[i])
  }
  x = append(x, X)
  y = append(y, Y)
  sort.Ints(x)
  sort.Ints(y)

  ans := "No War"
  if x[n] >= y[0] {
    ans = "War"
  }
  fmt.Println(ans)
}

Measured memory_bytes: 512
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cassert>
 
#define SIZE 100005
#define AM 998244353;
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;
 
using namespace std;
 
ll rui(ll a, ll b)
{
	ll c=1;
	while(b>0)
	{
		c=(c*a)%AM;
		b--;
	}
	return c;
}
 
int main()
{	
	ll N;
	scanf("%lld", &N);
	ll D[N];
	ll count[N];
	for(ll i=0;i<N;i++){
		scanf("%lld", &D[i]);
		count[i]=0;
	}
	
 
	for(ll i=0;i<N;i++){
		count[D[i]]++;
	}
	
	ll answer=1; 
 
	
	
	
	
	ll yos=1;
	if((count[0]!=1)||(D[0]!=0)){answer=0;}
	for(ll i=1;i<N;i++){
		if((count[i]!=0)&&(yos==1))
		{
		answer=(answer*rui(count[i-1],count[i]))%AM;
		}
		else
		{
			if((count[i]!=0)&&(yos==0))
			{
				answer=0;
			}
			yos=0;
		}
			
	}
	
	printf("%lld", answer);
}

Measured memory_bytes: 1664
#include <iostream>

using namespace std;

bool check_palindrome(string s){
  int right = 0;
  int left = s.size()-1;
  while(right <= left){
    if(s[right] != s[left]){
      return false;
    }
    right++;
    left--;
  }
  return true;
}

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

  bool check1 = check_palindrome(s);
  bool check2 = check_palindrome(s.substr(0, s.size() / 2));
  bool check3 = check_palindrome(s.substr((s.size() + 2) / 2));

  if(check1 && check2 && check3){
    std::cout << "Yes" << '\n';
  }else{
    std::cout << "No" << '\n';
  }
  return 0;
}


Measured memory_bytes: 888
colors = input()

ans_1 = '01' * int(len(colors) / 2)
ans_2 = '10' * int(len(colors) / 2)
if len(colors) % 2 == 1:
    ans_1 = ans_1 + '0'
    ans_2 = ans_2 + '1'

replace_1 = 0
replace_2 = 0
for base, char_1, char_2 in zip(colors, ans_1, ans_2):
    if base != char_1:
        replace_1 += 1
    if base != char_2:
        replace_2 += 1
print(min(replace_1, replace_2))


Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) FOR(i,0,n)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define PB push_back
#define LB lower_bound
#define UB upper_bound
#define PQ priority_queue
#define UM unordered_map
#define ALL(a) (a).begin(),(a).end()
typedef vector<ll> vi;
typedef vector<vector<ll>> vvi;
const ll INF = (1ll << 60);
typedef pair<ll,ll> pii;
struct Edge{ll s,t,d; Edge(ll s,ll t,ll d):s(s),t(t),d(d){}};
typedef vector<vector<Edge>> Graph;
typedef vector<pii> vpii;

int main() {
  ll N,M; cin>>N>>M;
  vi a(M),b(M); REP(i,M) cin>>a[i]>>b[i];
  UM<ll,ll> cnt; REP(i,M) {cnt[a[i]]+=1; cnt[b[i]]+=1;}
  for(pii p:cnt) {
    if(p.second%2) {cout<<"NO"<<endl; return 0;}
  }
  cout<<"YES"<<endl;
}


Measured memory_bytes: 5540
import sys
input = sys.stdin.readline
from collections import deque
N, M = map(int, input().split())
X = [[] for i in range(N)]
for i in range(N-1):
    x, y = map(int, input().split())
    X[x-1].append(y-1)
    X[y-1].append(x-1)

P = [-1] * N
Q = deque([0])
R = []
while Q:
    i = deque.popleft(Q)
    R.append(i)
    for a in X[i]:
        if a != P[i]:
            P[a] = i
            X[a].remove(i)
            deque.append(Q, a)

BU = [0] * N
TD = [1] * N
for i in R[::-1]:
    a = 1
    for j in X[i]:
        a = a * (BU[j] + 1) % M
    BU[i] = a
for i in R:
    c = len(X[i])
    AL = [1] * (c + 1)
    AR = [1] * (c + 1)
    for j in range(c):
        AL[j+1] = AL[j] * (BU[X[i][j]] + 1) % M
    for j in range(c)[::-1]:
        AR[j] = AR[j+1] * (BU[X[i][j]] + 1) % M
    for j in range(c):
        TD[X[i][j]] = (TD[i] * AL[j] * AR[j+1] + 1) % M

for i in range(N):
    print(BU[i] * TD[i] % M)

Measured memory_bytes: 84656
n, a, b = map(int, input().split())
mod = 10**9 + 7

def combi_mod(n, r, mod):
    numerator = 1
    denominater = 1
    for i in range(r):
        numerator = numerator * (n-i) % mod
        denominater = denominater * (i+1) % mod
    return numerator * pow(denominater, mod - 2, mod) % mod

print((pow(2, n, mod) -1 - combi_mod(n, a, mod) - combi_mod(n, b, mod)) % mod)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long int
#define pb push_back
#define mp make_pair
#define pii pair<ll,ll>
#define ff first
#define ss second
#define fill(a,b) memset(a, b, sizeof(a))
const long long N=200005, INF=2000000000000000000;


void solve(){
    ll n,i,ans=0;
    cin>>n;
    ll a[n+1];
    for(i=1;i<=n;i++)cin>>a[i];
    ll dp[n+1];
    dp[1]=0;
    for(i=1;i<=n;i++){
        if(i==2){
            dp[i]=abs(a[i]-a[i-1]);
        }else if(i>2){
            dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
        }
    }
    cout<<dp[n];
    return;
}

signed main(){
    boost;
    ll test;
    //cin>>test;
    test=1;
    while(test--){
        solve();

    }
}

Measured memory_bytes: 5108
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int)(n); 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; }
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll INF = 1LL<<60;
const ll MOD = 1e9 + 7;


int main() {
    ll N,M,X;
    cin >> N >> M >> X;
    ll book[N][M+1];
    for (ll i = 0;i<N;i++) {
        ll c;
        cin >> c;
        book[i][0] = c;
        for (ll j= 1;j<M+1;j++) {
            ll a;
            cin >> a;
            book[i][j] = a;

        }
    }
    ll ans = INF;

    for (int bit = 0; bit < (1<<N); ++bit) { //これで、ｎ桁の2進数以下全てを網羅
        ll m = 0;  //値段
        vector<ll> vec(M);
        for (ll i = 0;i<M;i++) vec.at(i) = 0;
        for (int i = 0; i < N; i++) {     //一桁ずつ、見ていく
            if (bit & (1 << i)) {  
                m+=book[i][0];   //値段追加
                for (ll j = 1;j<M+1;j++) {
                    ll rikai = vec.at(j-1);
                    rikai += book[i][j];
                    vec.at(j-1) = rikai; //理解度追加
                }
            }
        }
        bool ok = true;
        for (ll i = 0;i<M;i++) {
            if (vec.at(i) < X) ok = false;
        }
        
        if (ok) ans = min(ans,m);
    }
    if (ans != INF) cout << ans << endl;
    else cout << -1 << endl;
}

Measured memory_bytes: 3620
import java.io.*;
import java.util.*;
public class Main {
	public static void main(String[] args)throws Throwable {
		MyScanner sc=new MyScanner();
		PrintWriter pw=new PrintWriter(System.out);
		
		String s=sc.next();
		int n=s.length();
		int [] c=new int [26];
		for(int i=0;i<n;i++)
			c[s.charAt(i)-'a']++;
		long ans=1;
		for(int i=0;i<n;i++){
			c[s.charAt(i)-'a']--;
			int t=0;
			for(int j=0;j<26;j++)
				if(j!=s.charAt(i)-'a')
					t+=c[j];
			ans+=t;
		}
		pw.println(ans);
		pw.flush();
		pw.close();
	}
	
	static class MyScanner {
		BufferedReader br;
		StringTokenizer st;
		public MyScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
		String next() {while (st == null || !st.hasMoreElements()) {
			try {st = new StringTokenizer(br.readLine());}
			catch (IOException e) {e.printStackTrace();}}
		return st.nextToken();}
		int nextInt() {return Integer.parseInt(next());}
		long nextLong() {return Long.parseLong(next());}
		double nextDouble() {return Double.parseDouble(next());}
		String nextLine(){String str = "";
		try {str = br.readLine();}
		catch (IOException e) {e.printStackTrace();}
		return str;}
	}
}

Measured memory_bytes: 27604
N=int(input())

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return divisors
N_list = make_divisors(N) # 消す

if N_list[-1]*N_list[-2] == N:
    print(N_list[-1]+N_list[-2]-2)
else:
    print(N_list[-1]+N_list[-1]-2)

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

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

    string sr = s;
    reverse(sr.begin(), sr.end());
    if (s == sr) {
        string s2 = s.substr(0, (s.length()-1)/2);
        string s2r = s2;
        reverse(s2r.begin(), s2r.end());
        if (s2 == s2r) {
            string s3 = s.substr((s.length()+3)/2-1);
            string s3r = s3;
            reverse(s3r.begin(), s3r.end());
            if (s3 == s3r) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }

    cout << "No" << endl;
}

Measured memory_bytes: 3596
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main() {
    int n, sum = 0;
    cin >> n;
    vector<int> v;
    v.reserve(n);
    for (int i = 0, s; i < n; i++) {
        cin >> s;
        sum += s;
        if (s % 10 != 0) v.push_back(s);
    }
    cout << (sum % 10 ? sum : sum - (v.size() ? *min_element(v.begin(), v.end()) : sum)) << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>

using namespace std;

int main ()
{
    long long a, b, c, d, e, f, g, ca, cd, ce;
    scanf ("%lld %lld %lld %lld %lld %lld %lld", &a, &b, &c, &d, &e, &f, &g);
    ca = a;
    cd = d;
    ce = e;

    int nr = 0;

    if (a & 1LL) ++nr;
    a /= 2LL;
    a *= 4LL;

    b *= 2LL;

    if (d & 1LL) ++nr;
    d /= 2LL;
    d *= 4LL;

    if (e & 1LL) ++nr;
    e /= 2LL;
    e *= 4LL;

    a += b + d + e;
    if (nr == 3) a += 6LL;

    a /= 2LL;
    swap (a, ca);
    d = cd;
    e = ce;

    if (a && d && e)
    {
        a = (a - 1LL) / 2LL;
        a *= 4LL;

        d--;
        e--;
        a += 6LL;

        d /= 2LL;
        d *= 4LL;

        e /= 2LL;
        e *= 4LL;

        a += b + d + e;
        a /= 2LL;
    }

    else a = -200000000000000000LL;

    printf ("%lld\n", max (a, ca));

    return 0;
}


Measured memory_bytes: 128