akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>

int main(int argc, char *argv[])
{
  int n;
  scanf("%d", &n);
  int *x, i;
  x = (int*)malloc(sizeof(int) * n);
  for(i=0;i<n;i++){
    scanf("%d", x+i);
  }

  int mi;
  mi = 0;
  for(i=1;i<n;i++){
    if(x[i] > x[mi]){
      mi = i;
    }
  }
  /* printf("mi = %d\n", mi); */
  int s=0;
  for(i=0;i<n;i++){
    if(i==mi){
      continue;
    }else{
      s+=x[i];
    }
  }
  /* printf("s = %d\n", s); */

  if(s > x[mi]){
    printf("Yes\n");
  }else{
    printf("No\n");
  }
  free(x);
  return 0;
}


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

inline int read()
{
	int ret=0; char c=getchar();
	while(c<48||c>57)c=getchar();
	while(c>=48 && c<=57)ret=ret*10+c-48,c=getchar();
	return ret;
}//define
long long a[100060],f[100060],n,ss;
int main()
{
	n=read();
	for(int i=1;i<=n;++i)a[i]=read()<<1;
	for(int i=1;i<n;++i)if(i%2)ss-=a[i];else ss+=a[i];
	f[1]=(a[n]-ss)/2;
	for(int i=2;i<=n;++i)f[i]=a[i-1]-f[i-1];
	for(int i=1;i<=n;++i)printf("%lld ",f[i]);
}

Measured memory_bytes: 2816
package main

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

var sc = bufio.NewScanner(os.Stdin)

func Scanner() string {
	sc.Scan()
	return sc.Text()
}

func intScanner() int {
	n, _ := strconv.Atoi(Scanner())
	return n
}

func floatScanner() float64 {
	n, _ := strconv.ParseFloat(Scanner(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func stringSliceScanner(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scanner()
	}
	return a
}
func intSliceScanner(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = intScanner()
	}
	return a
}

var mod int

func main() {
	mod = 1000000007
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	n := intScanner()
	m := intScanner()
	q := make([]int, n)
	for i := 0; i < n; i++ {
		q[i] = 1
	}
	r := make([]bool, n)
	r[0] = true
	for i := 0; i < m; i++ {
		x, y := intScanner()-1, intScanner()-1
		if r[x] {
			r[y] = true
		}
		if q[x] == 1 && r[x] {
			r[x] = false
		}
		q[x]--
		q[y]++
	}
	ans := 0
	for i := 0; i < n; i++ {
		if r[i] {
			ans++
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 2560
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N,num):
    if N<=0:
        return [[] for _ in range(num)]
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [tuple(II()) for _ in range(N)]
        return map(list, zip(*read_all))

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

N = I()
K = I()

S = str(N)
L = len(S)

# dp[i][x][f] : i桁目まで見て，0以外がx個ある総数
#              （f=1:N未満が確定，f=0:未確定）
dp = [[[0]*2 for _ in range(K+1)] for _ in range(L)]
dp[0][0][1] = 1
dp[0][1][0] = 1
dp[0][1][1] = int(S[0])-1

for i in range(1,L):
    for x in range(K+1):
        if S[i] == '0':
            dp[i][x][0] = dp[i-1][x][0]
            dp[i][x][1] = dp[i-1][x][1]
            if x >= 1:
                dp[i][x][1] += 9*dp[i-1][x-1][1]
        else:
            dp[i][x][1] = dp[i-1][x][0] + dp[i-1][x][1]
            if x >= 1:
                dp[i][x][0] = dp[i-1][x-1][0]
                dp[i][x][1] += 9*dp[i-1][x-1][1] + (int(S[i])-1)*dp[i-1][x-1][0]

print(dp[L-1][K][0]+dp[L-1][K][1])

Measured memory_bytes: 38256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define repp(i,n) for(int i=1; i<n; i++)
#define int long long
using namespace std;
int gcd(int a, int b)
{
    if (a % b == 0) return b;
    return gcd(b, a % b);
}
signed main(){
  int n,m;
  while(cin >> n >> m){
    int a = gcd(n,m);
    int b = n*m/a;
    cout << a << " " << b << endl;
  }
  return 0;
}



Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define in(x,y,h,w) x >= 0 && x < h && y >= 0 && y < w

#define int long long
//typedef    long long          ll;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      P;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;
 
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

signed main(){
	int n;
	cin >> n;
	if(n <= 999) cout << "ABC" << endl;
	else cout << "ABD" << endl;
	return 0;
}

Measured memory_bytes: 256
class MatrixChainMul
  # for memoization
  @@MATRIX_MAX_NUM= 100
  @@MATRIX_MAX_SIZE = 100
  @@INF = @@MATRIX_MAX_SIZE**3
  @@mul_times_table = Array.new(@@MATRIX_MAX_NUM).map{Array.new(@@MATRIX_MAX_NUM,0)}

  def self.debugout
    10.times do |n|
      p @@mul_times_table[n]
    end
  end

  def self.min_mul_times (n,p)
    if n < 2
      return 0
    end
    2.upto(n) do |l|
      1.upto(n-l+1) do |i|
        j = i + l - 1
        @@mul_times_table[i][j] = @@INF
        i.upto(j-1) do |k|
          # p "i:#{i}, j:#{j}, k:#{k}"
          # p "m[i][k]:#{@@mul_times_table[i][k]}"
          # p "m[i][j]:#{@@mul_times_table[i][j]}"
          # p "m[k+1][j]:#{@@mul_times_table[k+1][j]}"
          @@mul_times_table[i][j] = [ @@mul_times_table[i][j], @@mul_times_table[i][k] + @@mul_times_table[k+1][j] + p[i-1]*p[k]*p[j] ].min
          
          #self.debugout
        end
      end
    end
    return @@mul_times_table[1][n]
  end
end

n = STDIN.gets.to_i
p = Array.new(n+1,nil)
1.upto(n) do |i|
  p[i-1],p[i] = STDIN.gets.split(' ').map{ |j| j.to_i }
end

print "#{MatrixChainMul::min_mul_times(n,p)}\n"

Measured memory_bytes: 8864
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <algorithm>
#include <cmath>
#include <functional>

using namespace std;

int main() {
	int k, t;
	cin >> k >> t;
	vector<int> data(t);
	for (int i = 0; i < t; i++) {
		cin >> data[i];
	}

	sort(data.begin(), data.end(), greater<int>());

	while(true) {
		int sz = data.size();
		if (sz == 0) {
			break;
		} else if (sz == 1) {
			break;
		} else {			
			data[0] -= data[sz-1];
			vector<int>::iterator ite = data.end();
			ite--;
			data.erase(ite);
			sort(data.begin(), data.end(), greater<int>());
		}
	}
	if (data.size() == 0 || data[0] == 0) {
		cout << 0 << endl;
	} else {
		cout << data[0]-1 << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
using vs = vector<string>;
#define  rep(i,n) for(ll i = 0; i < (n); ++i)
#define  red(i,n) for(ll i = (n)-1; i >= 0; --i)
#define  all(a)   begin(a),end(a)
#define  pb(a)    push_back(a)
#define  yn(a)    cout << ( (a)?"Yes\n":"No\n" )
inline ll gcd(ll a,ll b) { return b?gcd(b,a%b):a; }
ll INF = 1e9+9, LINF = 1e18;

int main(){
    int n,k,d,a,ans;
    cin>>n>>k;
    bool x[n]={0};
    ans=n;
    rep(i,k){
        cin>>d;
        rep(j,d)cin>>a,ans-=(x[a-1]==0),x[a-1]=1;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3584
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
template <typename T> using vec = std::vector<T>;

int main() {
    int N;
    cin >> N;
    
    vec<int> h(N);
    rep(i, N) cin >> h[i];

    vec<int> dp(N+2,1e9);
    dp[1] = 0;
    for(int i=1;i<=N-1;++i){
        dp[i+1] = min(dp[i+1],dp[i] + abs(h[i-1]-h[i]));
        dp[i+2] = min(dp[i+2],dp[i] + abs(h[i-1]-h[i+1]));
    }
    cout << dp[N] << endl;
}


Measured memory_bytes: 4040
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstdio>
#include <queue>
#include <map>

#define rep(i, n) for(int i = 0; i < n; i++)
#define FOR(i, a, b) for(int i = a; i < b; i++)
#define all(v) (v).begin(), (v).end()
#define f first
#define s second

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> P;

void pp(vi v){
	rep(i, v.size()){
		cout << v[i] << ' ';
	}
	cout << endl;
}

void pp(vector<string> v){
	rep(i, v.size()){
		cout << v[i] << endl;
	}
}

void pp(int (*f)[21]){
	rep(i, 21){
		rep(j, 21){
			cout << f[i][j];
		}
		cout << endl;
	}
}

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

int main(){
	int n;

	int dir[200] = {};
	dir['N'] = 0;
	dir['E'] = 1;
	dir['S'] = 2;
	dir['W'] = 3;

	while(cin >> n, n){
		int field[21][21] = {};
		rep(i,n){
			int x, y;
			cin >> x >> y;
			field[y][x] = 1;
		}

		int posx = 10, posy = 10;
		field[posy][posx] = 0;

		//pp(field);

		int m;
		cin >> m;
		//cout << "x:" << posx << endl;
		//cout << "y:" << posy << endl;
		rep(i, m){
			char d;
			int l;
			cin >> d >> l;
			rep(i, l){
				posx += dx[dir[d]];
				posy += dy[dir[d]];
				field[posy][posx] = 0;
			}
			//cout << "x:" << posx << endl;
			//cout << "y:" << posy << endl;
		}

		//pp(field);

		int check = 0;
		rep(i, 21){
			rep(j, 21){
				check += field[i][j];
			}
		}

		if(check == 0){
			cout << "Yes" << endl;
		}else{
			cout << "No" << endl;
		}

	}


	return 0;
}

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

int main() {
  int a, b;
  cin >> a >> b;
  if (a == 1) a += 13;
  if (b == 1) b += 13;
  if (a > b) {
    cout << "Alice" << endl;
  } else if (a == b) {
    cout << "Draw" << endl;
  } else {
    cout << "Bob" << endl;
  }
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int main()
{
	int s,j;
	int i[101];
	i[0]=1;
	while(scanf("%d",&s)!=EOF)
	{
		int c=0;
		for(j=1;j<=s;j++)
		{
			i[j]=pow(2,j);
			if(i[j]>s)
			{
				c=i[j-1];
				break;
			}
		}
		printf("%d\n",c);
	}
	return 0;
}

Measured memory_bytes: 128
from sys import stdin, stdout
from time import perf_counter

import sys
sys.setrecursionlimit(10**9)
mod = 10**9+7

# import sys
# sys.stdout = open("e:/python/cp/output.txt","w")
# sys.stdin = open("e:/python/cp/input.txt","r")

s = input()
print(f"A{s[8].upper()}C")

Measured memory_bytes: 9012
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const string ln = "\n";
constexpr int INF = 1001001001;
constexpr int MOD = 1000000007;

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

  int s;
  cin>>s;

  int h = s / 3600;
  s %= 3600;
  int m = s / 60;
  s %= 60;

  cout << h << ":" << m << ":" << s << ln;

  return 0;
}


Measured memory_bytes: 3212
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;


int main(){
    int H,A; cin >> H >> A;
    cout << (H+A-1)/A << endl;
}
    



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

import sys
import copy

sys.setrecursionlimit(1000000)

#input = sys.stdin.readline
from collections import defaultdict

# ~~~~~~~~~~~~~~~~~~~~~_(＾～＾ ｣ ∠)_~~~~~~~~~~~~~~~~~~~~~

N = int(input())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]

ans = 0
for i in range(N):
    d = min(A[i], B[i])
    ans += d
    A[i] -= d
    B[i] -= d
    d = min(A[i + 1], B[i])
    ans += d
    A[i + 1] -= d
    B[i] -= d

print(ans)


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

using namespace std;

struct TRAMP{
	char mark;
	int number;
};

int main(){
	int n,min;
	char buf[3];
	scanf("%d",&n);

	TRAMP selectArray[n],bubbleArray[n];

	for(int i = 0; i < n; i++){
		scanf("%s",buf);
		selectArray[i].mark = buf[0];
		selectArray[i].number = buf[1] - '0';
		bubbleArray[i] = selectArray[i];
	}

	for(int i = n-1; i >= 0; i--){
		for(int j = 0; j < i; j++){
			if(bubbleArray[j].number > bubbleArray[j+1].number) swap(bubbleArray[j], bubbleArray[j+1]);
		}
	}

	for(int i = 0; i < n-1; i++){
		min = i;
		for(int j = i+1; j < n; j++){
			if(selectArray[j].number < selectArray[min].number){
				min = j;
			}
		}
		if(i != min){
			swap(selectArray[i],selectArray[min]);
		}
	}

	for(int i = 0; i < n-1; i++) printf("%c%d ",bubbleArray[i].mark,bubbleArray[i].number);
	printf("%c%d\n",bubbleArray[n-1].mark,bubbleArray[n-1].number);
	printf("Stable\n");
	for(int i = 0; i < n-1; i++) printf("%c%d ",selectArray[i].mark,selectArray[i].number);
	printf("%c%d\n",selectArray[n-1].mark,selectArray[n-1].number);

	int p;
	for(p=0; p < n; p++){
		if(selectArray[p].number != bubbleArray[p].number || selectArray[p].mark != bubbleArray[p].mark)
			break;
	}
	if(p == n){
		printf("Stable\n");
	}else{
		printf("Not stable\n");
	}

	return 0;
}



Measured memory_bytes: 2756
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
#define all(x) (x).begin(),(x).end()
#define rep(i,m,n) for(int i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(int i = m;i >= n;--i)
#define INF INT_MAX/2
using namespace std;
using ll = long long;
using R = double;
using Data = pair<ll, vector<int>>;
const ll MOD = 1e9 + 7;
const ll inf = 1LL << 50;
struct edge { ll from; ll to; ll cost; };
typedef tuple<ll, ll, ll>T;
typedef pair<int, int>pint;


ll po[40];

int main() {
	double n, k;
	cin >> n >> k;

	po[0] = 1;
	rep(i, 1, 33)po[i] = po[i - 1] * 2;

	double ans = 0.0;
	for (ll p = 1; p <= n; p++) {
		if (p >= k) {
			ans += 1 / n;
		}
		else {
			int cur = 0;
			double temp = 1 / n;
			while (p*po[cur] < k) {
				temp *= 0.5;
				cur++;
			}
			ans += temp;
		}
	}
	printf("%.20f",ans);
	cout << endl;

	return 0;
}

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

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

int main() {
 int n; cin>>n;
  int que[n]; 
  int quem[n];
  rep(i, n){cin>>que[i];
           quem[i]=que[i];}
  
  sort(que,que+n,greater<int>());
  int med=que[n/2-1];
  
 rep(i, n){
   if(quem[i]>=que[n/2-1])cout<<que[n/2]<<endl;
   else cout<<que[n/2-1]<<endl;
 }
  
  }


Measured memory_bytes: 3712
#include <stdio.h>

int main()
{
	int N, i, j, k, count = 0;
	int A[100];
	
	scanf("%d",&N);
	for(i = 0; i < N; i++) scanf("%d",&A[i]);
	
	for(j = 0; j < N-1; j++){
		for(i = N-1; i > 0; i--){
			if(A[i] < A[i-1]){
				k = A[i];
				A[i] = A[i-1];
				A[i-1] = k;
				count++;
			}
		}
	}

	
	for(i = 0; i < N; i++){
		if(i > 0) printf(" ");
		printf("%d",A[i]);
	}
	printf("\n");
	printf("%d\n",count);
	
	return 0;
}

Measured memory_bytes: 1852
while True:
    l = list(map(int,input().split()))
    n = l[0]
    x = l[1]

    if n == x == 0:
        break
    
    ans = 0
    for i in range(1,n+1):
        for j in range(i+1,n+1):
            for k in range(j+1,n+1):
                if (i+j+k) == x:
                    ans += 1
                    # print(f"i:{i},j:{j},k:{k}")
    
    print(ans)


Measured memory_bytes: 5596
n, m, x = map(int, input().split())
books = [0]*n
for i in range(n):
  books[i] = [int(x) for x in input().split()]

ans = 10**9
for i in range(2**n):
  cost = 0
  point = [0]*m
  for j in range(n):
    if (i>>j)&1:
      cost += books[j][0]
      for k in range(1, m+1):
        point[k-1] += books[j][k]
  flag = True
  for j in range(m):
    if point[j] < x:
      flag = False
  if flag and ans > cost:
    ans = cost

print(ans if ans != 10**9 else -1)

Measured memory_bytes: 9116
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <cctype>
#include <cstdlib>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#include <list>
#include<set>
#include<map>
using namespace std;

int H;
void maxHeapify(int A[], int i) {
	int l = 2 * i, r = 2 * i + 1;
	int largest;
	if (l <= H && A[l] > A[i]) largest = l;
	else largest = i;
	if (r <= H && A[r] > A[largest]) largest = r;
	if (largest != i) {
		swap(A[largest], A[i]);
		maxHeapify(A, largest);
	}
}

void buildmaxHeap(int A[]) {
	for (int i = H / 2; i >= 1;i--) {
		maxHeapify(A, i);
	}
}

int main() {
	int A[500001] = {};
	cin >> H;
	for (int i = 1; i <= H;i++) {
		cin >> A[i];
	}
	buildmaxHeap(A);
	for (int i = 1; i <= H;i++) {
		cout << " " << A[i];
	}
	cout << endl;
}



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

const int inf = 1e9+7;

using namespace std;

bool v[400];        
int g[400][400],r[10];
int ans = inf;
int N,M,R;

void dfs(int now,int num,int cost){
	if(num == R){
		ans = min(ans,cost);
		return ;
	}
	rep(i,R){
		if(now == r[i])continue;
		if(v[r[i]])continue;
		v[r[i]] = 1;
		dfs(r[i],num+1,cost + g[now][r[i]]);
		v[r[i]] = 0;
	}
}
int main(void){
	cin >> N >> M >> R;
	rep(i,400)rep(j,400)g[i][j] = inf;
	rep(i,R)cin >> r[i];
	rep(i,M){
		int a,b,c;
		cin >> a >> b >> c;
		g[a][b] = c;
		g[b][a] = c;
	}
	rep(k,N+1)rep(i,N+1)rep(j,N+1)g[i][j] = min(g[i][j],g[i][k] + g[k][j]);
	rep(i,R){
		v[r[i]] = 1;
		dfs(r[i],1,0);
		v[r[i]] = 0;
	}
	cout << ans << endl;
}

Measured memory_bytes: 896
#include<stdio.h>
int main(){
	char s[1];
  	scanf("%s",s);
  	if(s[0]=='A') printf("T");
  	else if(s[0]=='T') printf("A");
  	else if(s[0]=='C') printf("G");
  	else printf("C");
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define all(v) v.begin(),v.end()
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
template<class T> void chmin(T &a,const T &b){if(a>b) a=b;}
template<class T> void chmax(T &a,const T &b){if(a<b) a=b;}

class BIT{//1-indexed
public:

  vector<ll> bit;
  BIT(){}
  BIT(int size){
    bit.resize(size,0);
  }

  ll sum(int i){
    ll s=0;
    while(i>0){
      s+=bit[i];
      i-=i&(-i);
    }
    return s;
  }

  void add(int i,ll x){//i!=0
    while(i<bit.size()){
      bit[i]+=x;
      i+=i&(-i);
    }
  }
};


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

  int N,Q;
  cin>>N>>Q;
  vector<int> C(N);
  rep(i,N) cin>>C[i];
  vector<int> L(Q),R(Q);
  rep(i,Q) cin>>L[i]>>R[i];

  rep(i,Q) L[i]--;

  vector<int> ord(Q);
  rep(i,Q) ord[i]=i;
  sort(all(ord),[&](int a,int b){
      if(L[a]==L[b]){
          if(R[a]==R[b]) return a<b;
          else return R[a]<R[b];
      }else return L[a]<L[b];
  });

  vector<vector<int>> idxs(N);
  rep(i,N) C[i]--;
  for(int i=N-1;i>=0;i--) idxs[C[i]].push_back(i);
  BIT bit(N+2);
  vector<int> ans(Q,0);
  int now=0;
  for(int i=0;i<N;i++){
      if(idxs[i].size()) bit.add(idxs[i].back()+1,1);
  }

  for(auto i:ord){
      while(now<L[i]){
          int tar=idxs[C[now]].back();
          bit.add(tar+1,-1);
          idxs[C[now]].pop_back();
          if(idxs[C[now]].size()) bit.add(idxs[C[now]].back()+1,1);
          now++;
      }

      ans[i]=bit.sum(R[i]);
  }

  rep(i,Q) cout<<ans[i]<<"\n";

  return 0;
}


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


int main(){
  ll n,a,b;
  cin >>n>>a>>b;
  ll blueball =0;
  ll sum = 0;
  ll rb =a+b;
  ll count =0;

  count =n/rb;
  sum=(count*rb)+a;
  //cout<<"sum:"<<sum<<endl;
  if(sum<=n){
    blueball =(count+1)*a;
  }

  else{
    ll x = sum-n;
  //  cout<<x<<endl;
    blueball =(count+1)*a -x;
  }
  cout <<blueball<<endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int y = sc.nextInt();
        String result = "No";
        for(int i=0;i<=x;i++)
        {
            int ans = i*2  + (x-i) * 4;
            if(ans==y){
                result = "Yes";
            }
        }
        System.out.println(result);
    }
}

Measured memory_bytes: 35760
N = int(input())
K = list(map(int,input().split()))
L = list(map(int,input().split()))
sum_k  = []
sum_l = []
tmp_k = 0
tmp_l = 0

for index,k in enumerate(K):
  tmp_k += k
  sum_k.append(tmp_k)
for index,l in enumerate(reversed(L)):
  tmp_l += l
  sum_l.append(tmp_l)

ma = 0
for i in range(N):
  if ma < sum_k[i] + sum_l[N-1-i]:
    ma = sum_k[i] + sum_l[N-1-i]
print(ma)

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

using ll = long long;
using vll = vector<ll>;
using pl4 = pair<ll,ll>;
using str = string;
using vpl4 = vector<pair<ll,ll>>;

#define sz size()
#define be begin()
#define en end()
#define fi first
#define se second
#define pb push_back
#define mp make_pair

#define llin(x) ll (x);cin >>(x);
#define stin(x) str (x);cin >>(x);
#define vllin(x,n) vll (x)(n);FOR(i,0,n-1){cin >>(x)[i];}
#define FOR(i,a,b) for(ll i = a ; i <= b ; i++)
#define rFOR(i,b,a) for(ll i = a; i >= b ; i--)
#define SORT(x) sort(x.be, x.en)
#define rSORT(x) sort(x.rbegin(), x.rend())
#define say(x) cout<<(x);
#define sal(x) cout<<(x)<<endl;
#define yn(a) cout <<((a)?"yes":"no")<<endl;
#define Yn(a) cout <<((a)?"Yes":"No")<<endl;
#define YN(a) cout <<((a)?"YES":"NO")<<endl;
#define Imp(a) cout <<((a)?"Possible":"Impossible")<<endl;
#define IMP(a) cout <<((a)?"POSSIBLE":"IMPOSSIBLE")<<endl;
#define pow(a,b) ll(pow(a,b))

ll MOD=1000000007;
vector<vector<vector <long double>>> e(0,vector<vector<long double>> (0,vector<long double> (0,0)));

long double solve(ll o,ll t,ll h,ll n,long double p){
	if(o==0&&t==0&&h==0) return 0;
	if(o==-1||t==-1||h==-1) return 0;
	long double sum=(long double)(o+t+h);
	if(e[o][t][h]>0){
		return e[o][t][h]*p;
	}else{
		e[o][t][h]=(long double)(n)/(long double)(o+t+h)+solve(o-1,t,h,n,(long double)(o)/sum)+solve(o+1,t-1,h,n,(long double)(t)/sum)+solve(o,t+1,h-1,n,(long double)(h)/sum);
		return e[o][t][h]*p;
	}
}

signed main(){
	llin(n);
	ll a;
	vll s(4,0);
	FOR(i,0,n-1){
		cin >>a;
		s[a]++;
	}
	e.assign(n+1,vector<vector<long double>> (n+1,vector<long double> (n+1,0)));
	cout <<fixed<<setprecision(10)<<solve(s[1],s[2],s[3],n,1.0)<<endl;
}

Measured memory_bytes: 431488
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include <algorithm>
#include<bits/stdc++.h>
using namespace std;
string a[30000];
bool compare(string a,string b)
{
    return a<b;
}
int main()
{
    string s;
    cin>>s;
    int num;
    cin>>num;
    int len = s.length();
    int count = 0;
    for(int i=1; i<=5; i++)
    {
        for(int j=0; j<len; j++)
        {
            a[count++] = s.substr(j,i);
        }
    }
    sort(a,a+count,compare);
    unique(a,a+count);
    cout<<a[num-1]<<endl;
    return 0;
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
const double PI=acos(-1);

int main(){
    ll n, c, k;
    cin >> n >> c >> k;
    vector<ll> t(n);
    rep(i, n) cin >> t[i];
    sort(t.begin(), t.end());
    ll cnt = 1, p = 0, lim = 0;
    rep(i, n){
        if(i == 0){
            lim = t[i] + k;
            p++;
        }
        else if(p == c || lim < t[i]){
            p = 1;
            cnt++;
            lim = t[i] + k;
        }
        else {
            p++;
        }
        //printf("%lld %lld %lld\n", cnt, p, lim);
    }
    cout  << cnt << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cctype>
#include <numeric>
using namespace std;

#define rep(i,n) for(int (i)=0; (i)<(int)(n); ++(i))
#define foreach(c,i) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)

int N, A, B, C, X;

int main() {
  while (scanf("%d%d%d%d%d", &N, &A, &B, &C, &X), N) {
    vector<int> y;
    int t;
    rep(i,N) {
      scanf("%d", &t);
      y.push_back(t);
    }

    // sort(y.begin(), y.end());
    // y.erase(unique(y.begin(), y.end()), y.end());
    
    int turn = 0, p = 0;
    bool ok = false;

    do {
      // rep(i,y.size()) {
      //   printf("{%d}", y[i]);
      // }
      // puts("");
      // if (binary_search(y.begin(), y.end(), X)) {
      //   y.erase(lower_bound(y.begin(), y.end(), X));
      // }

      if (y[p] == X) ++p;
      
      if (p == N) {
        ok = true;
        break;
      }
      X = (A * X + B) % C;
      ++turn;
    } while (turn <= 10000);

    printf("%d\n", ok ? turn : -1);
  }
  return 0;
}

Measured memory_bytes: 1208
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();
// freopen("input.txt", "r", stdin);

int main() {
	ll n, k;
  	cin >> n >> k;
  	n %= k;
  	cout << min(n, k-n) << endl;
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
using namespace std;
typedef long long int ll;
typedef long double ld;
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; }
const long long INF = 1LL << 60;
typedef pair<ll,ll> pairs;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
#define MAX_N 1000100
bool x[MAX_N];
ll num[MAX_N];
ll fibl[MAX_N]={0};
// 四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
 
ll fib(ll a){
    if (fibl[a]!=0)return fibl[a];
    if (a==0){
        return 0;
    }else if (a==1){
        return 1;
    }
    return fibl[a]=fib(a-1)+fib(a-2);
}
 
ll eratosthenes(ll n) {
    int p = 0;
    for (ll i=0; i<=n; ++i) x[i] = true;
    x[0] = x[1] = false;
    for(int i=2; i<=n; ++i) {
        if(x[i]) {
            p++;
            for(int j=2*i; j<=n; j+=i) x[j] = false;
        }
        
        num[i] = p;
    }
    return p;
}
 
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}
 
ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

int main(){
    ll n,a,b;
    ll count=0,bcount=0;
    cin >> n >> a >> b;
    string s;
    cin >> s;
    for (ll i=0;i<n;i++){
        if (s[i]=='c'){
            cout << "No" << endl;
        }else if (s[i]=='a'){
            if (count<a+b){
                count++;
                cout << "Yes" << endl;
            }else{
                cout << "No" << endl;
            }
        }else{
            if (count<a+b and bcount<b){
                count++;
                bcount++;
                cout << "Yes" << endl;
            }else{
                cout << "No" << endl;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 896
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef unsigned long ul;
typedef unsigned int ui;
#define All(v) (v).begin(),(v).end()
#define REP(i,n) for(int i = 0; i < (int)n; i++)
#define REPS(i,n) for(int i = 1; i <= (int)n; i++)
#define FOR(i,m,n) for(int i = m; i < n; i++)
#define INF 2e9
#define F first
#define S second
#define pb push_back
#define mp make_pair
struct speedup{speedup(){cin.tie(); ios::sync_with_stdio(false); cout << fixed << setprecision(18);}}speedup;


int main (){
    int N,T;
    cin >> N >> T;
    vector<int> t(N);
    REP(i,N) cin >> t[i];
    ll ans = 0;
    REP(i,N-1){
        if(t[i+1]-t[i] >= T){
            ans += T;
        }else{
            ans += t[i+1]-t[i];
        }
    }
    ans += T;
    cout << ans << "\n";
}

Measured memory_bytes: 1024
package main

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

// PfsMap :
func PfsMap(n int) map[int]int {
	pfs := make(map[int]int)
	for n%2 == 0 {
		pfs[2] = pfs[2] + 1
		n = n / 2
	}

	for i := 3; i*i <= n; i = i + 2 {
		for n%i == 0 {
			pfs[i] = pfs[i] + 1
			n = n / i
		}
	}

	if n > 2 {
		pfs[n] = pfs[n] + 1
	}

	return pfs
}

func out(x ...interface{}) {
	//	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func nextString() string {
	sc.Scan()
	return sc.Text()
}

// mod. m での a の逆元 a^{-1} を計算する
func modinv(a, m int) int {
	b := m
	u := 1
	v := 0
	for b != 0 {
		t := a / b
		a -= t * b
		a, b = b, a
		u -= t * v
		u, v = v, u
	}
	u %= m
	if u < 0 {
		u += m
	}
	return u
}

func main() {
	sc.Split(bufio.ScanWords)
	MOD := 1000000007
	N := nextInt()
	a := make(map[int]map[int]int)
	A := make([]int, N)
	for i := 0; i < N; i++ {
		v := nextInt()
		A[i] = v
		a[i] = PfsMap(v)
		out(a[i])
	}

	// merge
	s := make(map[int]int)
	for i := 0; i < N; i++ {
		for n, m := range a[i] {
			if s[n] < m {
				s[n] = m
			}
		}
	}

	out(s)

	//
	sum := 1
	for n, m := range s {
		sum *= int(math.Pow(float64(n), float64(m))) % MOD
		sum = sum % MOD
	}

	out(sum)

	ans := 0
	for i := 0; i < N; i++ {
		ans += sum * modinv(A[i], MOD) % MOD
		ans = ans % 1000000007
	}

	fmt.Println(ans)
	/*
		xa := 12345678900000
		xb := 100000

		xa %= MOD
		fmt.Println(xa, xb, xa*modinv(xb, MOD)%MOD)
	*/
	/*
		sum := 0
		for i := 0; i < N; i++ {
			val := 1
			for n, m := range s {
				x := m - a[i][n]
				val *= int(math.Pow(float64(n), float64(x)))
			}
			sum += val
			sum = sum % 1000000007
			out(val)
		}
		fmt.Println(sum)
	*/
}


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

int ordem( const void * x, const void *y){
	int a = *((int *) x), b = *((int *) y);

	if (a<b)
		return -1;
	if (a>b)
		return 1;
	return 0;
}


int main(){

	int n;
	long long int num[101];
	scanf("%d", &n);
	for (int i = 0; i<n; ++i){
		scanf("%lld", &num[i]);
	}

	qsort(num, n, sizeof(num[0]), ordem);

	long long int dif = num[n-1] - num[0];

	printf("%lld\n", dif);




	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl

ll n,cnt,ans,a[ohara],b[ohara],c,d[ohara],tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz");
bool fl;
struct edge{ll to,cost;};
vector<edge> g[ohara];
pair<ll,ll> p[ohara];
pair<ll,ll> pp[ohara];
map<pair<ll,ll>,ll> mp;

//-------------------------↓↓↓↓↓↓------------------------

void dijkstra(ll s){
    priority_queue<pair<ll,ll>,vector<pair<ll,ll>>,greater<pair<ll,ll>>>que;
    fill(d,d+n,LINF);
    d[s]=0;
    que.push(pair<ll,ll>(0LL,s));
    while(!que.empty()){
        pair<ll,ll> pp=que.top();que.pop();
        ll v=pp.second;
        if(d[v]<pp.first)continue;
        rep(i,Size(g[v])){
            edge e=g[v][i];
            if(d[e.to]>d[v]+e.cost){
                d[e.to]=d[v]+e.cost;
                que.push(pair<ll,ll>(d[e.to],e.to));
            }
        }
    }
}

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

    cin>>n;
    rep(i,n)cin>>a[i];
    rep(i,n)p[i]=make_pair(a[i],i);
    rep(i,n)cin>>b[i];
    rep(i,n)pp[i]=make_pair(b[i],i);
    sort(p,p+n);
    sort(pp,pp+n);
    rep(i,n-1){
        //pos=min(abs(p[i].first-p[i+1].first),abs(pp[i].first-pp[i+1].first));
        if(mp[{p[i].second,p[i+1].second}]!=0)mp[{p[i].second,p[i+1].second}]=min(abs(p[i].first-p[i+1].first),mp[{p[i].second,p[i+1].second}]),mp[{p[i+1].second,p[i].second}]=mp[{p[i].second,p[i+1].second}];
        else mp[{p[i].second,p[i+1].second}]=abs(p[i].first-p[i+1].first),mp[{p[i+1].second,p[i].second}]=mp[{p[i].second,p[i+1].second}];
        if(mp[{pp[i].second,pp[i+1].second}]!=0)mp[{pp[i].second,pp[i+1].second}]=min(abs(pp[i].first-pp[i+1].first),mp[{pp[i].second,pp[i+1].second}]),mp[{pp[i+1].second,pp[i].second}]=mp[{pp[i].second,pp[i+1].second}];
        else mp[{pp[i].second,pp[i+1].second}]=abs(pp[i].first-pp[i+1].first),mp[{pp[i+1].second,pp[i].second}]=mp[{pp[i].second,pp[i+1].second}];
    }
    rep(i,n-1){
        pos=mp[{p[i].second,p[i+1].second}];
        g[p[i].second].push_back({p[i+1].second,pos});
        g[p[i+1].second].push_back({p[i].second,pos});
    }
    rep(i,n-1){
        pos=mp[{pp[i].second,pp[i+1].second}];
        g[pp[i].second].push_back({pp[i+1].second,pos});
        g[pp[i+1].second].push_back({pp[i].second,pos});
    }
    dijkstra(0);
    rep(i,n){
        Cout(d[i]);
    }
    return 0;
}



Measured memory_bytes: 66936
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s, t;
    int a, tmp;
    bool flag=false;
    
    cin >> s >> t;

    s+=t;
    a = stoi(s);
    tmp=(int)sqrt(a);
    if(pow(tmp, 2)==a)
	flag=true;

    cout << (flag? "Yes": "No") << endl;    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>

using namespace std;

int main() {
  
  int N, ans;
  cin >> N;
  ans = 100000000;
  
  for (int i = 0; i < N ; i++){
    
    int A, num = 0;
    cin >> A;
    bool bul = true;
    
    while (bul){
      if (A % 2 == 1){
        bul = false;
      }
      
      else{
        A /= 2;
        num ++;
      }
      
    }
    
    if (num < ans){
      ans = num;
    }
  }
  
  cout << ans << endl;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MOD = pow(10, 9) + 7;
//const int MOD = 998244353;
//const int MOD = ;
int mod(int A, int M) {return (A % M + M) % M;}
const int INF = 1LL << 60;
const string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const string abc = "abcdefghijklmnopqrstuvwxyz";
template <class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template <class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
int divCeil(int A, int B) {return (A + (B - 1)) / B;}
int myctoi(char C) {return C - 48;}
char myitoc(int N) {return '0' + N;}

signed main()
{
  int N;
  cin >> N;
  vector<int> A(N);
  vector<int> B(N);
  for (int i = 0; i < N; i++) cin >> A.at(i);
  for (int i = 0; i < N; i++) cin >> B.at(i);

  vector<int> Dp;
  int dms = 0;
  int ans = 0;
  for (int i = 0; i < N; i++)
  {
    int d = A.at(i) - B.at(i);
    if (d >= 0) Dp.push_back(d);
    else
    {
      dms += -d;
      ans++;
    }
  }
  
  sort(Dp.begin(), Dp.end(), greater<int>());
  
  int dps = 0;
  for (int i = 0; i < Dp.size(); i++)
  {
    if (dps >= dms) break;
    dps += Dp.at(i);
    ans++;
  }
  if (dps < dms) ans = -1;
  
  cout << ans << endl;
}

Measured memory_bytes: 2936
R=[0,3,6]
N=range(9)
Z=[0]*9

n=input()
while n:
  M=[]
  F=[[" " for _ in Z] for _ in Z]
  M=[map(int,raw_input().split()) for _ in Z]
  M1=[[M[y][x] for y in N] for x in N]
  M2=[M[y][x:x+3]+M[y+1][x:x+3]+M[y+2][x:x+3] for y in R for x in R]
  for y in N:
    A=M[y]
    for x in N:
      A1=M2[x/3+y/3*3]
      a=A[x]
      if A.count(a)>1 or M1[x].count(a)>1 or A1.count(a)>1: F[y][x]="*"
  for i in N:
    s=zip(F[i],map(str,M[i]))
    print "".join([a+b for a,b in s])
  if n>1: print
  n-=1

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

int main(){
    int n;
    cin >> n;
    vector<int> w(n);
    rep(i,n) cin >> w[i];
    vector<int> s(n+1);
    rep(i,n) s[i+1] = s[i]+w[i];
    int ans = 100000;
    rep(t,n-1){
        int s1 = s[t+1];
        int s2 = s[n] - s[t+1];
        ans = min(ans,abs(s1-s2));
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


class CmbMod:
    def __init__(self, n, p):
        """
        二項係数nCr(n個の区別できるものからr個のものを選ぶ組み合わせの数)をpで割った余りを求める
        """
        self.n = n
        self.p = p
        self.fact = [1, 1]
        self.factinv = [1, 1]
        self.inv = [0, 1]

    def cmb_mod(self, n, r):
        """
        二項係数nCr(mod p)をO(r)にて計算。nが大きいがrは小さい時に使用。
        """
        numer, denom = 1, 1
        for i in range(r):
            numer = (numer * (n - i)) % self.p
            denom = (denom * (i + 1)) % self.p
        return (numer * pow(denom, self.p - 2, self.p)) % self.p

    def prep(self):
        """
        二項係数nCr(mod p)をO(1)で求める為の前処理をO(N)にて実行。
        """
        for i in range(2, self.n + 1):
            self.fact.append((self.fact[-1] * i) % self.p)
            self.inv.append((-self.inv[self.p % i] * (self.p // i)) % self.p)
            self.factinv.append((self.factinv[-1] * self.inv[-1]) % self.p)

    def cmb_mod_with_prep(self, n, r):
        """
        二項係数nCr(mod p)をO(1)で求める。事前にprepを実行する事。
        """
        if (r < 0) or (n < r):
            return 0
        r = min(r, n - r)
        return self.fact[n] * self.factinv[r] * self.factinv[n - r] % self.p


def resolve():
    X, Y = map(int, input().split())

    cnt = (X + Y) // 3
    left = 0
    right = 0
    for i in range(cnt):
        if (i * 1 + (cnt - i) * 2 == X and i * 2 + (cnt - i) * 1 == Y) or (
                i * 1 + (cnt - i) * 2 == Y and i * 2 + (cnt - i) * 1 == X):
            left = i
            right = cnt - i
            break
    else:
        print(0)
        exit()

    cmb = CmbMod(cnt, mod)
    res = cmb.cmb_mod(cnt, min(left, right))
    print(res)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 3192
#include <stdio.h>
int main()
{
    int a,b;

    scanf("%d %d",&a,&b);

    if(a>b){
        printf("a > b\n");
    }else if(a<b){
        printf("a < b\n");
    }else if(a==b){
        printf("a == b\n");
    }
    return 0;
}

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

public class Main {
    public static void main(String[] args) throws IOException {
        // Here your code !
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] Data = br.readLine().split(" ");
        int a = Integer.parseInt(Data[0]);
        int b = Integer.parseInt(Data[1]);
        int c = Integer.parseInt(Data[2]);
        if (a > b) {
            int temp = a;
            a = b;
            b = temp;
        }
        if (b > c) {
            int temp = b;
            b = c;
            c = temp;
        }
        if (a > b) {
            int temp = a;
            a = b;
            b = temp;
        }
        System.out.println( a +" "+ b +" "+ c );
    }
}



Measured memory_bytes: 24200
N,M=map(int,input().split())
SC=[list(map(int,input().split())) for i in range(M)]

def check(x):
  x=str(x)#文字に変換
  if len(x)!=N:
    return False
  for s,c in SC:
    if x[s-1]!=str(c):
      return False
  return True

for i in range(1000):
  if check(i):
    print(i)
    exit()
print(-1)

Measured memory_bytes: 3060
<?php
//error_reporting(0);
//$N = trim(fgets(STDIN));
list($A,$B,$C) = explode(" ",trim(fgets(STDIN)));
$K = trim(fgets(STDIN));
//$A  = explode(" ",trim(fgets(STDIN)));
$n = max($A,$B,$C);
$tot = $n;
for($i=0;$i<$K;$i++) {
  $tot*=2;
}
if ($n == $A) {
  printf("%d\n",$B+$C+$tot);
  exit;
}
if ($n == $B) {
  printf("%d\n",$A+$C+$tot);
  exit;
}
printf("%d\n",$A+$B+$tot);


Measured memory_bytes: 3828
package main

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

var (
	reader = bufio.NewReader(os.Stdin)
	writer = bufio.NewWriter(os.Stdout)
)

func main() {
	defer writer.Flush()
	var s string
	fmt.Fscanf(reader, "%s", &s)
	temp := strings.Split(s, "")
	sum := 700
	for _, v := range temp {
		if v == "o" {
			sum += 100
		}
	}
	fmt.Fprintln(writer, sum)
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
static const int INF (1<<30);

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

  if (X < A) cout << 0 << endl;
  else cout << 10 << endl;

  return 0;
}

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

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; }

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

    int N;
    std::cin >> N;

    std::string S;
    std::cin >> S;

    std::vector<int> leftCumE(N, ((S[0] == 'E') ? 1 : 0));
    for (int i = 1; i < N; ++i) {
        leftCumE[i] = leftCumE[i - 1] + ((S[i] == 'E') ? 1 : 0);
    }
    std::vector<int> rightCumW(N, ((S[N-1] == 'W') ? 1 : 0));
    for (int i = N-2; i >= 0; --i) {
        rightCumW[i] = rightCumW[i + 1] + ((S[i] == 'W') ? 1 : 0);
    }

    int maxNbGuys = 0;
    // first
    chmax(maxNbGuys, rightCumW[1]);

    // middle
    for (int i = 1; i < N-1; ++i) {
        chmax(maxNbGuys, leftCumE[i -1] + rightCumW[i+1]);
    }
    // last
    chmax(maxNbGuys, leftCumE[N-2]);

    const int res = N - maxNbGuys -1;

    std::cout << res << "\n";

    return 0;
}

Measured memory_bytes: 2964
#include<bits/stdc++.h>
#define rep0(i,n) for(i=0;i<n;i++)
#define rep(i,n) for(i=1;i<=n;i++)
#define reps(i,a,n) for(i=a;i<=n;i++)
#define mem(ara,n) memset(ara,n,sizeof(ara))
#define memb(ara) memset(ara,false,sizeof(ara))
#define all(x) (x).begin(),(x).end()
#define fast ios_base:: sync_with_stdio( false ); cin.tie(0); cout.tie(0);
#define eb              emplace_back
#define em              emplace
#define pb              push_back
#define Mp              make_pair
#define ff              first
#define ss              second
#define mod 1000000007
typedef long long ll;
using namespace std;

const int M = (int)(2e6 + 239);

void decitobinbitodeci()
{
    string binary = bitset<8>(128).to_string(); //to binary
    cout<<binary<<"\n";

    unsigned long decimal = bitset<8>(binary).to_ulong();
    cout<<decimal<<"\n";
}

int getnum(string a)
{
    int i,p=0;
    rep0(i,a.size())
    {
        p*=10;
        p+=a[i]-'0';
    }
    return p;
}

/*
1.always remember for ncr(n,2), you can calculate by
n*(n-1)/2
2.Power of 2 ->  (1ll<<i)
*/

int main()
{
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif*/
    fast

    ll a,b,c,d,e;
    cin>>a>>b;
    set<ll>s,s1;
    for(int i=1; i<=a; i++)
    {
        s1.insert(i);
    }
    for(int i=0; i<b; i++)
    {
        cin>>c;
        for(int j=0; j<c; j++)
        {
            cin>>d;
            s.insert(d);
        }
    }
    cout<<s1.size()-s.size()<<endl;
}


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

int main()
{
  string S;
  cin >> S;
  int64_t cnt = 0, ans = 0;
  for (int i = 1; i <= S.size(); i++)
  {
    if (S.at(i - 1) == 'W')
    {
      cnt++;
      ans += (i - cnt);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 640
#include <stdio.h>

int main(){
	int l,r,d;
	int j = 0;
	scanf("%d %d %d" ,&l,&r,&d);
	for(int i = l; i <= r; i++){
		if(i % d == 0){
			j++;
		}
	}
	printf("%d" ,j);
	return 0;
}

Measured memory_bytes: 1720
#include <stdio.h>

int main(){
  int v,w;
  while(scanf("%d",&w),w!=-1){
    v=1150;
    if(w>10 && w<=20) v=1150+(w-10)*125;
    if(w>20 && w<=30) v=1150+1250+(w-20)*140;
    if(w>30) v=1150+1250+1400+(w-30)*160;
    printf("%d\n",4280-v);
  }
  return 0;
}

Measured memory_bytes: 600
import java.util.Scanner;

public class Main {
	public static void main(String[] args)
	{
		Scanner stdIn = new Scanner(System.in);
		
		while(true)
		{
			int n = stdIn.nextInt();
			int p = stdIn.nextInt();
			
			if(n==0 && p==0)
			{
				break;
			}
			
			int[] x = new int[50];
			int y = p;
			int z = 0;
			
			for(int i=0;i<50;i++)
			{
				x[i] = 0;
			}
			
			while(z == 0)
			{
				for(int i=0;i<n;i++)
				{
					if(y==0)
					{
						y = x[i];
						x[i] = 0;
					}
					else
					{
						y--;
						x[i]++;
						if(x[i]==p)
						{
							System.out.println(i);
							z++;
						}
					}
				}
			}
			
		}
	}

}

Measured memory_bytes: 20272
N = int(input())
H = list(map(int, input().split()))
ans = 0
c = 0
for i in range(N - 1):
    if H[i] >= H[i + 1]:
        c += 1
    else:
        ans = max(ans, c)
        c = 0
ans = max(ans, c)
print(ans)


Measured memory_bytes: 14224
#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pld = pair<ld, ld>;
template <typename Q_type>
using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>;

constexpr int MOD_TYPE = 2;
constexpr ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353);
constexpr int INF = (int)1e9;
constexpr ll LINF = (ll)4e18;
constexpr ld PI = acos(-1.0);
constexpr ld EPS = 1e-11;
constexpr int Dx[] = {0, 0, -1, 1, -1, 1, -1, 1, 0};
constexpr int Dy[] = {1, -1, 0, 0, -1, -1, 1, 1, 0};

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << "\n"
#define Yes(n) cout << ((n) ? "Yes" : "No") << "\n"
#define possible(n) cout << ((n) ? "possible" : "impossible") << "\n"
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << "\n"
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << "\n"
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << "\n";

#pragma endregion

bool chmin(ll &a, ll b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(20) << setiosflags(ios::fixed);

  ll a, b, c, x, y;
  cin >> a >> b >> c >> x >> y;
  ll Min = LINF;
  chmin(Min, a * x + b * y);
  chmin(Min, max(x, y) * c * 2);
  if (x <= y)
    chmin(Min, c * x * 2 + b * (y - x));
  else
    chmin(Min, c * y * 2 + a * (x - y));
  cout << Min << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll         long long int
#define co         cout
#define ci         cin
#define sf1(n)     scanf("%lld",&n)
#define sf2(n,m)   scanf("%lld %lld",&n,&m);
#define sf3(n,m,p) scanf("%lld %lld %lld",&n,&m,&p);
#define pf1(n)     printf("%lld\n",n);
#define mem(a,b)   memset(a,b,sizeof(a))
#define en         cout<<endl;
#define pb         push_back
#define gcd(n,m)   __gcd(n,m)
#define lcm(n,m)   ((n)/__gcd(n,m))*(m)
#define fi         first
#define se         second
#define coy        cout<< "YES"<<endl;
#define con        cout<< "NO"<<endl;
#define f(a,b)     for(ll i=a;i<b;i++)
#define all(x)     (x).begin(),(x).end()
#define allr(x)    (x).rbegin(),(x).rend()
#define pi         pair<ll,ll>
#define br         break;
#define i64        long long
#define PI         2*acos(0.0)


int main()
{
    ll t,n,g,k,m,mx=0,mn=1e9,c,res,c1,x,y,w,z,c2;
    ci>>n;
    vector<ll>a(n);
    f(0,n) ci>>a[i];
    res=a[0];
    f(1,n)
    {
        if(a[i]>a[i-1]) res+=a[i]-a[i-1];
    }
    co<<res;
}



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

int main(){
    int n;  cin >> n;
    vector<int>a(n);
    rep(i, n)	cin >> a[i];
    int ans=0;
    sort(a.begin(), a.end());
    for(int i = 1; i < n; i++){
	ans += a[i]-a[i-1];
    }
    cout << ans << endl;
}


Measured memory_bytes: 256