akhauriyash/Code-Regression huggingface dataset:
import java.io.*;
import java.math.BigDecimal;
import java.util.*;

public class Main {
	static int INF = 2 << 27;
	static int[] vx = {1,0,-1,0};
	static int[] vy = {0,1,0,-1};
	public static void main(String[] args) {	
		//FastScanner sc = new FastScanner();
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		while(true) {
			int p = sc.nextInt();
			int q = sc.nextInt();
			if(p == 0 && q == 0) break;
			char[][] inx = new char[p][];
			for(int i = 0; i < p; i++) {
				inx[i] = sc.next().toCharArray();
			}
			ArrayList<Integer> rr = new ArrayList<Integer>();
			ArrayList<Integer> cc = new ArrayList<Integer>();
			ArrayList<Integer> ss = new ArrayList<Integer>();
			for(int i = 1; i <= 20; i++) {
				for(int j = 1; j <= 20; j++) {
					IN:for(int k = 1; k <= 20; k++) {
						int rrr = 0;
						int ccc = 0;
						int sss = 0;
						for(int l = 0; l < p; l++) {
							int in = 0;
							for(int m = 0; m < inx[l].length; m++) {
								if(inx[l][m] != '.') break;
								in++;
							}
							
							if(rrr * i + ccc * j + sss * k != in) continue IN;
							for(int m = 0; m < inx[l].length; m++) {
								if(inx[l][m] == '(') rrr++;
								if(inx[l][m] == ')') rrr--;
								if(inx[l][m] == '{') ccc++;
								if(inx[l][m] == '}') ccc--;
								if(inx[l][m] == '[') sss++;
								if(inx[l][m] == ']') sss--;
							}
						}
						rr.add(i);
						cc.add(j);
						ss.add(k);
					}
				}
			}
			int rrr = 0;
			int ccc = 0;
			int sss = 0;
			for(int i = 0; i < q; i++) {
				int sum = -2;
				for(int j = 0; j < rr.size(); j++) {
					int ll = rrr * rr.get(j) + ccc * cc.get(j) + sss * ss.get(j);
					if(sum != -2 && sum != ll) sum = -1;
					else if(sum == -2) sum = ll;
				}
				
				if(sum == -2) sum = -1;
				if(i != 0) System.out.print(" ");
				System.out.print(sum);
				if(i != q) {
					char[] in = sc.next().toCharArray();
					for(int j = 0; j < in.length; j++) {
						if(in[j] == '(') rrr++;
						if(in[j] == ')') rrr--;
						if(in[j] == '{') ccc++;
						if(in[j] == '}') ccc--;
						if(in[j] == '[') sss++;
						if(in[j] == ']') sss--;
					}
				}
			}
			System.out.println();
			
			
		}
	}
}

Measured memory_bytes: 33084
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
using namespace std;
#define ll long long
int main(){
    ll N;
    cin >> N;
    ll a[N];
    ll i;
    for(i=0;i<N;i++){
      cin >> a[i];
    }
    sort(a,a+N);
    ll ans=0;
    ll tmp=0;
    for(i=0;i<N;i++){
      if (tmp!=a[i])ans++;
      tmp = a[i];
    }
    cout << ans <<endl;
    return 0;
}


Measured memory_bytes: 256
n,m,c = map(int,input().split())
b = list(map(int,input().split()))
ans = 0
for i in range(n):
    cnt = 0
    a = list(map(int,input().split()))
    for j in range(m):
       cnt += a[j] * b[j]
    cnt += c
    if cnt > 0:
        ans += 1
print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
int main() {
  int x;
  cin>>x;
  if(x==1)
    cout<<0<<endl;
  else 
    cout<<1<<endl;
}


Measured memory_bytes: 3596
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>

using namespace std;

int main() {
	int n; cin >> n;
	vector<pair<int, int> > a(n);
	for (int i = 0; i < n; ++i) cin >> a[i].first, a[i].second = i + 1;
	sort(a.begin(), a.end());
	for (int i = 0; i < n; ++i) {
		if (i) cout << " ";
		cout << a[i].second;
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 1664
from fractions import gcd


def main():
    N = int(input())
    *A, = map(int, input().split())

    L = [0] * (N+1)
    R = [0] * (N+1)
    G = [0] * N
    L[0] = A[0]
    R[N-1] = A[N-1]
    for i in range(1, N):
        L[i] = gcd(L[i-1], A[i])
    for i in range(N-1)[::-1]:
        R[i] = gcd(R[i+1], A[i])
    G[0] = R[1]
    G[N-1] = L[N-2]
    for i in range(1, N-1):
        G[i] = gcd(L[i-1], R[i+1])
    print(max(G))


main()


Measured memory_bytes: 16132
N, K, S = map(int, input().split())
if S!=10**9:
    A = [S+1]*N
    for i in range(K):
        A[i] -= 1

    for c in A:
        print(c, end=" ")
else:
    A = [1]*N
    for i in range(K):
        A[i] = S
    for c in A:
        print(c, end=" ")

Measured memory_bytes: 7728
from collections import Counter
from functools import reduce
from operator import mul


def ncr(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom


N, P = list(map(int, input().split()))
A = Counter(list(map(lambda x: int(x) % 2, input().split())))
ans = 2 ** A[0]
if P:
    print(ans * sum(ncr(A[1], i) for i in range(1, A[1] + 1, 2)))
else:
    print(ans * sum(ncr(A[1], i) for i in range(0, A[1] + 1, 2)))


Measured memory_bytes: 3564
#include<bits/stdc++.h>
using namespace std;
#define lld long long int
int main()
{
	int n;
	cin>>n;
	lld sum=0;
	while(n--)
	{
		int l,r;
		cin>>l>>r;
		sum+=(r-l+1);
	}
	cout<<sum<<"\n";
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
 
int main(){
    int h,w,a,b;
    cin >> h >> w >> a >> b;
    for(int i=0;i<b;i++){
    	for(int j=0;j<a;j++){
        	cout << '1';
        }
      	for(int j=0;j<w-a;j++){
        	cout << '0';
        }
        cout << endl;
    }
    for(int i=0;i<h-b;i++){
    	for(int j=0;j<a;j++){
        	cout << '0';
        }
      	for(int j=0;j<w-a;j++){
        	cout << '1';
        }
        cout << endl;
    }
	return 0;
}

Measured memory_bytes: 1280
use std::io;


fn read_line() -> String {
    let mut line = String::new();

    io::stdin().read_line(&mut line)
        .expect("Failed to read line");
    return line;
}
fn to_i(s: &str) -> i64 {
    return s.trim().parse()
        .expect("Please type a number!");
}

fn main() {

    let l1 = read_line();
    
    let nx: Vec<&str> = l1.split(' ').collect();

    let n: i64 = to_i(nx[0]);
    let x: i64 = to_i(nx[1]);

    let l2 = read_line();
    

    let items: Vec<&str> = l2.split(' ').collect();
    //println!("items:{:?}", items);

    let mut nums: Vec<i64> = Vec::new();

    let mut sum = 0;
    for item in items {
        let num = to_i(item);
        nums.push(num);
        sum += num;
    }
    if sum == x {
        print!("{}", n);
        return;
    }
    nums.sort();
    //nums.reverse();

    //println!("nums:{:?}", nums);

    let mut sum = 0;
    let mut count = 0;
    for i in 0..nums.len() {
        let num = nums[i];
        //println!("{} {} {}", i, sum + num, x);
        if sum + num <= x {
            
                count = i+1;
                sum += num;
            
        } else {
            break;
        }
    }
    
    //println!("count:{:?}", count);

    if count >= nums.len() {
        if n==0 {
            count = 0;
        } else {
            count = (n-1) as usize;
        }
    }


    print!("{}", count);


}   

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

using namespace std;
const int MOD = 10000;
inline void add(unsigned short& x, unsigned short y){ x = (x + y) % MOD; }

int calc(string s, int M){
    int N = s.size();
    vector<int> a(N);
    REP(i, N) a[i] = s[i] - '0';
    // [i-th][mod][last][zeros, first, down, up][low or not]
    static unsigned short dp[502][502][10][4][2] = {};
    memset(dp, 0, sizeof(dp));
    dp[0][0][0][0][0] = 1;
    unsigned short pow_10[502] = {};
    pow_10[0] = 1;
    for(int i = 1; i < N; i++){
        pow_10[i] = pow_10[i - 1] * 10 % M;
    }
    for(int i = 0; i < N; i++)
    for(int mod = 0; mod < M; mod++)
    for(int last = 0; last < 10; last++)
    for(int type = 0; type < 4; type++)
    for(int islow = 0; islow < 2; islow++)
    for(int next = 0; next < 10; next++){
        const int& cur = dp[i][mod][last][type][islow];
        if(cur == 0) continue;
        if(!islow && a[i] < next) continue;
        int nlow = islow || (next < a[i]);
        int nmod = (mod + next * pow_10[N - 1 - i]) % M;
        if(type == 0){
            int ntype = (next == 0 ? 0 : 1);
            add(dp[i + 1][nmod][next][ntype][nlow], cur);
        }else if(type == 1 && last != next){
            int ntype = (last < next ? 3 : 2);
            add(dp[i + 1][nmod][next][ntype][nlow], cur);
        }else if(type == 2 && last < next){
            int ntype = 3;
            add(dp[i + 1][nmod][next][ntype][nlow], cur);
        }else if(type == 3 && last > next){
            int ntype = 2;
            add(dp[i + 1][nmod][next][ntype][nlow], cur);
        }
    }
    unsigned short ans = 0;
    for(int last = 0; last < 10; last++)
    for(int type = 0; type < 4; type++)
    for(int islow = 0; islow < 2; islow++){
        add(ans, dp[N][0][last][type][islow]);
    }
    return ans;
}
string dec(string s){
    for(int i = s.size() - 1; i >= 0; i--){
        if(s[i] != '0'){
            s[i] --;
            break;
        }else{
            s[i] = '9';
        }
    }
    return s;
}

int main(){
    string A, B;
    while(cin >> A >> B){
        int M;
        cin >> M;
        cout << (calc(B, M) - calc(dec(A), M) + MOD) % MOD << endl;
    }
    return 0;
}

Measured memory_bytes: 40604
h,w,d = map(int,raw_input().split(" "))

mp = {}
now = 0

for a in range(h):
  z = map(int,raw_input().split(" "))
  for zz in z:
    mp[zz] = now
    now += 1

data = [-1] * (h*w + 1)
data2 = [-1] * (h*w + 1)

for a in range(d+1,h*w+1):
  l = mp[a-d]
  r = mp[a]
  x = abs((r/w) - (l/w))
  y = abs((r%w) - (l%w))
  data[a] = x+y
  if a - d <= 0:
    continue
  data2[a] = data2[a-d] + data[a]

q = int(raw_input())

for a in range(q):
  l,r = map(int,raw_input().split(" "))
  print data2[r] - data2[l]


Measured memory_bytes: 23864
#include <bits/stdc++.h>
using namespace std;
bool prime[10000001];
int main() {
    for(int i=3;i<3162;i++)if(!prime[i])for(int j=i*2;j<10000001;j+=i)prime[j]=1;
    int n;
    while(cin>>n,n){
        if(n%2==0)n--;
        while(prime[n]||prime[n-2]||prime[n-6]||prime[n-8])n-=2;
        cout<<n<<endl;
    }
}

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

using namespace std;
int main(){
    unsigned long n;
    cin >> n;
    vector<unsigned long> a(n);
    for(int i = 0;i < n;i++){
        cin >> a[i];
    }
    sort(a.begin(),a.end());
    while(a.size() > 1){
        auto first = a.begin();
        unsigned long first_val = *first;
        auto last = a.end();
        last--;
        unsigned long last_val = *last;
        if(last_val % first_val == 0){
            a.pop_back();
        }else{
            *last = last_val % first_val;
            sort(a.begin(),a.end());
        }
    }
    cout << a[0] << endl;
    return 0;

}

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

using namespace std;

int main() {
	const int len = 3;
	int in[len];

	for (int i = 0; i < len; i++)
		cin >> in[i];

	sort(in, in + len);

	for (int i = 0; i < len - 1; i++)
		cout << in[i] << " ";
	cout << in[2] << endl;

	return 0;
}

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

using namespace std;

int main ()
{
    int n, m;
    static long long c, x[100010], v1, v, ans=0, cal_sum[100010], c_max[100010], d_max[100010];
    cin>>n>>c;
    cal_sum[0]=0;
    for (int i=1; i<=n; i++)
    {
        cin>>x[i]>>v;
        if (i==1) v1=v;
        cal_sum[i]=cal_sum[i-1]+v;
    }
    for (int i=n; i>=1; i--)
    {
        if (i==n)
        {
            d_max[n]=v-(c-x[n]);
            m=n;
        }
        else
        {
            if (-(x[m]-x[i])+(cal_sum[m-1]-cal_sum[i-1])>0)
            {
                d_max[i]=d_max[m]-(x[m]-x[i])+(cal_sum[m-1]-cal_sum[i-1]);
                m=i;
            }
            else d_max[i]=d_max[m];
        }
    }
    for (int i=1; i<=n; i++)
    {
        if (i==1)
        {
            c_max[1]=v1-x[1];
            m=1;
        }
        else
        {
            if (-(x[i]-x[m])+(cal_sum[i]-cal_sum[m])>0)
            {
                c_max[i]=c_max[m]-(x[i]-x[m])+(cal_sum[i]-cal_sum[m]);
                m=i;
            }
            else c_max[i]=c_max[m];
        }
    }
    for (int i=1; i<=n; i++) ans=max(ans, cal_sum[i]-x[i]);
    for (int i=n; i>=1; i--) ans=max(ans, (cal_sum[n]-cal_sum[i-1])-(c-x[n]+(x[n]-x[i])));
    for (int i=1; i<n; i++) ans=max(ans, cal_sum[i]-x[i]*2+d_max[i+1]);
    for (int i=n; i>1; i--) ans=max(ans, (cal_sum[n]-cal_sum[i-1])-(c-x[n]+(x[n]-x[i]))*2+c_max[i-1]);
    cout<<ans<<'\n';
    return 0;
}


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

using namespace std;

#define rep(i, n) for(int i=0; i<(int)(n); i++)

int main() {
  int N, M;
  cin >> N >> M;
  
  vector<int> path_sizes(N, 0);
  
  rep(i, M*2){
    int capital;
    cin >> capital;
    path_sizes.at(capital-1)++;
  }
  rep(i, N){
    cout << path_sizes.at(i) << endl;
  }
}
    
  
 

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

const int N = 1e5 + 2 ;
int p[N];
int dp[N][2] ;
int n, K ;

bool winner(int k, bool player)
{
    if(k == 0) return 0;
    if(dp[k][player] != -1) return dp[k][player] ;
    //cout << k << " : " << player << " :: " << endl ;
    bool win = 0 ;
    for(int i = 0; i < n; i++)
        if(k >= p[i])
            win |= !winner(k-p[i], !player);
    //cout << k << " : " << player << " :: " << win << endl ;
    return dp[k][player] = win ;
}

int main()
{
    cin >> n >> K ;
    for(int i = 0; i < n; i++)
        cin >> p[i] ;
    memset(dp, -1, sizeof(dp));
    if( winner(K, 0) )
        cout << "First" ;
    else
        cout << "Second" ;
}

/*
double rec(int i, int last)
{
    if(i >= n)
    {
        if(last > ( n - last)) return 1.0 ;
        else return 0.0 ;
    }
    if(dp[i][last] != -1) return dp[i][last] ;

    double head = p[i] * rec(i+1, last + 1);
    double tail = (1 - p[i]) * rec(i+1, last);

    dp[i][last] = (head + tail) ;
}
*/


Measured memory_bytes: 8832
from itertools import accumulate
n, K = map(int,input().split())
A = list(map(int,input().split()))
b = [0 for _ in range(n+1)]

for _ in range(K):
    for i,a in enumerate(A):
        b[max(0, i-a)] += 1
        b[min(n, i+a+1)] -= 1

    ac = list(accumulate(b))
    A = ac[:-1]
    b = [0 for _ in range(n+1)]
    if sum(A) == n*n:
        break
    
print(*A)

Measured memory_bytes: 186452
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define OUT(x) cout << (x) << endl;
#define OUTA(a, n) \
    REP(i, n) { cout << (a[i]) << (i == n - 1 ? "\n" : " "); }
#define ALL(a) (a).begin(), (a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) \
    SORT(a);     \
    reverse(ALL(a))

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

ll A, B, C;

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

    if (A == B and B != C or A == C and B != C or B == C and A != B)
    {
        OUT("Yes");
    }
    else
    {
        OUT("No");
    }
}

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

int main() {
  string s;
  ll q;
  cin >> s >> q;
  bool rev=true; 
  string before,after; 
  for(ll i=0; i<q; i++){
    int t,f;
    char c;
    cin >> t;
    if(t==1){
      rev=!rev; 
    }
    if(t==2){
      cin >> f >> c;
      if((f==1)==rev){
          before+=c; 
      }else{
        after+=c; 
      } 
    }
  }
   
  if(!rev){
    reverse(ALL(s)); 
    reverse(ALL(after)); 
    cout << after << s << before << endl;
  }else{
    reverse(ALL(before)); 
    cout << before << s << after << endl;
  }
}



Measured memory_bytes: 1088
#include <vector>
#include <map>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long int ll;

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

ll bin(vector<ll> &vec, ll s, ll e, ll v) {
    if (e - s > 1) {
        ll mid = ((s + e) / 2);
        if (vec[mid] >= v) {
            return bin(vec, mid, e, v);
        } else {
            return bin(vec, s, mid, v);
        }
    } else {
        return e;
    }
}

int main(int argc, const char * argv[]) {
    
    ll N;
    cin >> N;
    vector<ll> maximums = vector<ll>();
    ll count = 0;
    
    for (ll i = 0; i < N; i++) {
        ll data;
        cin >> data;
        if (count == 0 || maximums[count-1] >= data) {
            maximums.push_back(data);
            count++;
            continue;
        } else if (maximums[0] < data) {
            maximums[0] = data;
            continue;
        }
        
        ll index = bin(maximums, 0, count - 1, data);
        maximums[index] = data;

    }
    
    cout << count;
    
    return 0;
}


Measured memory_bytes: 1400
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
using namespace std;

int main(){
  int h,w;
  cin >> h >> w;
  int c[10][10];
  for(int i = 0; i < 10; i++){
    for(int j = 0; j < 10; j++){
      cin >> c[i][j];
    }
  }
  int dp[10];
  for(int j = 0; j < 10; j++){
    dp[j] = c[j][1];
  }
  for(int i = 1; i < 10; i++){
    for(int j = 0; j < 10; j++){
      for(int k = 0; k < 10; k++){
        dp[j] = min(dp[j],dp[k]+c[j][k]);
      }
    }
  }
  int cnt[10] = {};
  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      int a;
      cin >> a;
      if(a!=-1){
        cnt[a]++;
      }
    }
  }
  long ans = 0;
  for(int i = 0; i < 10; i++){
    ans += cnt[i]*dp[i];
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

// increment
#define rep_n(_1, _2, _3, NAME, ...) NAME
#define rep_2(i, n) for (int(i) = 0; (i) < (int)(n); ++(i))
#define rep_3(i, initial, n) for (int(i) = (int)(initial); (i) < (int)(n); ++(i))
#define rep(...) rep_n(__VA_ARGS__, rep_3, rep_2, rep_1)(__VA_ARGS__)
// decrement
#define rep_r_n(_1, _2, _3, NAME, ...) NAME
#define rep_r_2(i, n) for (int(i) = (int)(n); (i) > 0; (i)--)
#define rep_r_3(i, initial, n) for (int(i) = (int)(initial); (i) > (int)(n); (i)--)
#define rep_r(...) rep_r_n(__VA_ARGS__, rep_r_3, rep_r_2)(__VA_ARGS__)
// define type definition
using namespace std;
typedef long long ll;
using mpint = boost::multiprecision::cpp_int; // 多倍長整数（任意精度）
typedef pair<int, int> P;

// define construct variable
const double EPS = numeric_limits<double>::epsilon();
// 10^9 + 7
const ll MOD = ll(1e9)+7;
const ll INF = ll(1e10);
const string ALPHABET = "abcdefghijklmnopqrstuvwxyz";

// define methods
// 最大公約数
ll gcd(const ll a, const ll b) { return b ? gcd(b, a % b) : a; }
// 最小公倍数
ll lcm(const ll a, const ll b) { return a / gcd(a, b) * b; }
// char -> int
int ctoi(char c) { return (int)(c - '0'); }
// 素因数分解
vector< pair<ll, ll> > prime_factorize(ll n) {
  vector< pair<ll, ll> > p;
  for (ll i = 2; i * i <= n; i++) {
    if ((n % i) != 0) continue;
    p.push_back(make_pair(i, 0));
    while ((n % i) == 0) {
      n /= i;
      p[i].second += 1;
    }
    p.push_back(make_pair(n, 0));
  }

  if (n != 1) p.push_back(make_pair(n, 1));
  return p;
}
// 組み合わせの整合性を保つ（後ほど解析する）
ll modinv(ll a) {
	ll b = MOD, u = 1, v = 0;
	while (b) {
		ll t = a / b;
		a -= t * b;
		swap(a, b);
		u -= t * v;
		swap(u, v);
	}
	u %= MOD;
	if (u < 0) { u += MOD; }
	return u;
}
// 順列
ll permutation(const ll n, const ll m) {
	ll result = 1;
	for (ll i = n; i > n - m; i--) { result = (result * i) % MOD; }
	return result;
}

// 繰り返し n 乗法
ll repeat_square(const ll n, const ll x) {
	if (x == 0) return 1;
	ll res = repeat_square(n, x/2);
	res = res * res % MOD;
	if ((x % 2) == 1) res = res * n % MOD;
  return res;
}
// 組み合わせ
ll combination(const ll n, const ll a) {
	ll x = 1, y = 1;
  for(ll i = 0; i < a; i++){
    x = x * (n-i) % MOD;
    y = y * (i+1) % MOD;
  }
  return x * repeat_square(y, MOD-2) % MOD;
}

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

  vector<int> total(200004, 0);
  rep(i, N) {
    int a;
    cin >> a;
    if ((a-1) > 0) total[a-1]++;
    total[a]++;
    total[a+1]++;
  }

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

  cout << total[0] << endl;
  return 0;
}


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

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i ,a, b) for (int i = a ; i <= b ; i++)
#define sz(a) int(a.size())
#define cuti(a) cout << a << endl;
#define cutii(a,b) cout << a << " " << b << endl;
#define cutiii(a,b,c) cout << a << " " << b << " " << c << endl;
#define vec(a) vector<int > a;

template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }

typedef long long LL;
typedef pair<int ,int > pii;
typedef pair<string ,int > psi;
typedef pair<string ,string > pss;
typedef pair<LL, LL> pLL;

const long long oo = 1e9 + 7;
const double PI = acos(-1.0);

double DEG_to_RAD(double d) { return d * PI / 180.0; }

int n;
int d[123456];

int main(){
  //  freopen("test.txt","r",stdin);
    cin >> n;
    for (int i = 0 ; i < n ; i++) cin >> d[i];
    sort(d,d+n);
    int res = 1;
    for (int i =0 ; i < n-1 ; i++) {
        if (d[i] != d[i+1]) res++;
    }
    cout << res << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
#define nl cout<<'\n' ; 
void speed() { ios_base::sync_with_stdio(false);cin.tie(NULL);}
const ll inf = 1e18L + 1 ;

void max_self(ll &a , ll b)
{
	a= max(a,b);
}

void solve()
{
	int n , w ; cin>>n>>w ; 
	
	vector<pair<int, int >> items ; 
	
	for(int i=0 ; i<n ; i++) 
	{
      int weight , val ; 
      cin>>weight>>val ; 
      items.push_back(make_pair(weight , val));
	}
	
	ll total_val =0 ; 
	for(int i=0 ; i<n ; i++) total_val+=items[i].second ; 
	vector<ll> dp(total_val+1 , inf); 
	dp[0]=0 ;
	
	for(int ind=0 ; ind<n ; ind++)
	{
		for( int val = total_val ; val>=0 ; val--)
		{
		if(val + items[ind].second<=total_val)
		{
			dp[val+items[ind].second] = min(dp[val+items[ind].second] , dp[val] + items[ind].first);
		}	
		}	
	}
	
	ll answer =0 ; 
	for(ll i=0 ; i<=total_val ; i++)
	{
		if(dp[i]<=w)
		{
			answer = max(answer , i);
		}
	}
	
	cout<<answer ; 
	
	
}

int main()
{
	speed(); 
    int T = 1;
   // cin >> T;
    while (T--){
    solve();
}
}




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

int main(){
    double r;
    cin >> r;
    
    cout << fixed << setprecision(6) << r * r * 3.14159265358979 << " ";
    cout << fixed << setprecision(6) << 2 * r * 3.14159265358979;
}


Measured memory_bytes: 3272
#include <bits/stdc++.h>
#define FOR(i,a,b) for (long long i = (a); i <= (b); i++)
#define FORD(i,b,a) for (long long i = (b); i >= (a); i--)
#define endl "\n"
#define ll long long
#define x1 asdasdsaas
#define y1 cdaca1231
#define fi first
#define se second
#define pb push_back
using namespace std;
const int MAXN = 1e6;
const int dx[4] = { -1, 0, 1, 0};
const int dy[4] = {0, 1, 0, -1};
void solve() {
	int n, h[MAXN], f[MAXN];
	cin >> n;
	FOR(i, 1, n) cin >> h[i];
	f[0] = INT_MAX;
	f[1] = 0;
	f[2] = abs(h[1]-h[2]);
	FOR(i, 3, n) {
		f[i] = min(f[i - 2] + abs(h[i - 2] - h[i]), f[i - 1] + abs(h[i - 1] - h[i]));
	}
	cout << f[n];
}

int main() {
	// freopen("in.txt", "r", stdin);
	// freopen("out.txt", "w", stdout);
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	solve();
	return 0;
}

Measured memory_bytes: 4736
#include<iostream>
#include<string>
#include <cmath>
#include <ctype.h>
using namespace std;
string a, b;
int main() {
    cin >> a >> b;
    if((a=="H"&&b=="H")||(a=="D"&&b=="D")) cout << "H" << endl;
    else cout << "D" << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*
fun main(args: Array<String>) {

    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    var max = 0
    var ans = 0;
    for (i in 0 until n) {
        val p = sc.nextInt()
        if (max < p) {
            max = p;
        }
        ans += p;
    }

        println(ans-max/2)
}


Measured memory_bytes: 31384
def prefix_XOR(n):
	if n&1:
		if n&2:
			return 0
		else:
			return 1
	else:
		return (n+1)^prefix_XOR(n+1)
A, B = map(int,input().split())
print(prefix_XOR(B)^prefix_XOR(A-1))

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

int main() {  
	int N,error;
    cin >> N;
  	error=0;
  vector<long int>a(N);
    for(int i=0;i<N;i++){
    cin >>a.at(i);
    }
 	sort(a.begin(), a.end());
   
  	for(int i=0;i<N-1;i++){
    if(a.at(i)==a.at(i+1)){error=1;break;}
    }
  if(error==0){cout <<"YES"<<endl;}
  else{cout << "NO"<<endl;}
}

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

int N, P[100005];

void connect(int tail, int head) {
  P[tail] = head;
}

int find(int node) {
  int cur_node = node, p = P[node];
  while (cur_node != p) {
    P[cur_node] = P[p];
    cur_node = p;
    p = P[p];
  }
  return cur_node;
}

int main() {
  int M, x, y, z, root_x;
  cin >> N >> M;
  for (int i = 0; i < N; i++) P[i] = i;
  int res = N;
  for (int c = 0; c < M; c++) {
    cin >> x >> y >> z; x--; y--;
    if ((root_x = find(x)) != find(y)) {
      connect(root_x, y); res--;
    }
  }
  cout << res << endl;
}

Measured memory_bytes: 640
import sys
def input():
    return sys.stdin.readline().strip()
n, a, b, c = map(int, input().split())
s = []
for _ in range(n):
    i = input()
    if i == 'AB':
        s.append(2)
    elif i == 'AC':
        s.append(1)
    else:
        s.append(0)

# 'No'の処理
if a == 0 and b == 0 and c == 0:
    print('No')
    exit()

if a == 0 and b == 0:
    if s[0] == 2:
        print('No')
        exit()
if a == 0 and c == 0:
    if s[0] == 1:
        print('No')
        exit()
if b == 0 and c == 0:
    if s[0] == 0:
        print('No')
        exit()

ans = []
if a + b + c == 1:
    for i in range(n):
        if s[i] == 0:
            if b > c:
                ans.append('C')
                b -= 1
                c += 1
            else:
                ans.append('B')
                b += 1
                c -= 1

        elif s[i] == 1:
            if a > c:
                ans.append('C')
                a -= 1
                c += 1
            else:
                ans.append('A')
                a += 1
                c -= 1

        else:
            if a > b:
                ans.append('B')
                a -= 1
                b += 1
            else:
                ans.append('A')
                a += 1
                b -= 1
        if a < 0 or b < 0 or c < 0:
            print('No')
            exit()
    
    print('Yes')
    for i in ans:
        print(i)
    exit()

# 0 <= i < n-1
print('Yes')
for i in range(n-1):
    if s[i] == 0:
        if b > c:
            print('C')
            b -= 1
            c += 1
        elif b < c:
            print('B')
            b += 1
            c -= 1
        elif s[i+1] == 2:
            print('B')
            b += 1
            c -= 1
        else:
            print('C')
            b -= 1
            c += 1

    elif s[i] == 1:
        if a > c:
            print('C')
            a -= 1
            c += 1
        elif a < c:
            print('A')
            a += 1
            c -= 1
        elif s[i+1] == 0:
            print('C')
            a -= 1
            c += 1
        else:
            print('A')
            a += 1
            c -= 1

    else:
        if a > b:
            print('B')
            a -= 1
            b += 1
        elif a < b:
            print('A')
            a += 1
            b -= 1
        elif s[i+1] == 1:
            print('A')
            a += 1
            b -= 1
        else:
            print('B')
            a -= 1
            b += 1

# i = n-1
if s[n-1] == 0:
    if b > c:
        print('C')
        b -= 1
        c += 1
    else:
        print('B')
        b += 1
        c -= 1

elif s[n-1] == 1:
    if a > c:
        print('C')
        a -= 1
        c += 1
    else:
        print('A')
        a += 1
        c -= 1

else:
    if a > b:
        print('B')
        a -= 1
        b += 1
    else:
        print('A')
        a += 1
        b -= 1

Measured memory_bytes: 10740
use std::io;
use std::str::FromStr;
use std::cmp::min;

fn input<T:FromStr>() -> T {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    line.trim().parse().ok().unwrap()
}

fn input_tuple() -> (u64, u64) {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    let vec: Vec<u64> = line.split_whitespace().map(|s| s.parse().unwrap()).collect();
    (vec[0], vec[1])
}

fn input_vec() -> Vec<u64> {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    line.split_whitespace().map(|s| s.parse().unwrap()).collect()
}

fn main() {
    let n: u64 = input();
    let (a, b) = input_tuple();
    let p_vec = input_vec();
    let mut counts = vec![0; 3];
    for p in p_vec {
        if p <= a {
            counts[0] += 1;
        } else if p <= b {
            counts[1] += 1;
        } else {
            counts[2] += 1;
        }
    }
    println!("{}", min(min(counts[0], counts[1]), counts[2]));
}


Measured memory_bytes: 2084
package main

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

type Restaurants [][]int

func (r Restaurants) Len() int {
	return len(r)
}
func (r Restaurants) Less(i, j int) bool {
	return r[i][1] > r[j][1]
}
func (r Restaurants) Swap(i, j int) {
	r[i], r[j] = r[j], r[i]
}

func main() {
	var n int
	fmt.Scan(&n)

	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	var cities []string
	restaurantsMap := make(map[string]Restaurants)
	for i := 0; i < n; i++ {
		scanner.Scan()
		s := scanner.Text()
		scanner.Scan()
		p, _ := strconv.Atoi(scanner.Text())
		if _, ok := restaurantsMap[s]; !ok {
			cities = append(cities, s)
			restaurantsMap[s] = [][]int{}
		}
		restaurantsMap[s] = append(restaurantsMap[s], []int{i + 1, p})
	}

	sort.Strings(cities)
	for i := 0; i < len(cities); i++ {
		restaurants := restaurantsMap[cities[i]]
		sort.Sort(restaurants)
		for j := 0; j < len(restaurants); j++ {
			fmt.Println(restaurants[j][0])
		}
	}
}


Measured memory_bytes: 640
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner scan = new Scanner(System.in);
        int a = scan.nextInt();
        int b = scan.nextInt();
        int[] c = new int[100000];
        for(int i=1;i<=9;i++)
        {
            for(int j=0;j<=9;j++)
            {
                for(int k=0;k<=9;k++)
                {
                    c[i*10000+j*1000+k*100+j*10+i]=1;
                }
            }
        }
        int ans = 0;
        for(int i=a;i<=b;i++)
        {
            ans += c[i];
        }
        System.out.println(ans);
    }    
}

Measured memory_bytes: 22996
N = int(input())
X = list(map(int, input().split()))
X_min = min(X)
X_max = max(X)
S = []
if X_min == X_max:
    S.append(0)
for x in range(X_min, X_max):
    s = 0
    for i in range(N):
        s += (X[i]-x)**2
    S.append(s)
print(min(S))

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

#define endl '\n'
#define rep(i,s,n)      for (int i = s ; i < n ; i++)
#define repp(i,s,n)    for (int i = s ; i <= n ;i++)
#define all(a)      a.begin(),a.end()
#define sz(v)    (int)v.size()
#define NumofDigits(n)    ((long long)log10(n)+1)
#define Unique(n)         (n).erase(unique(all(n)), (n).end())
#define test    int s ; cin >> s; while (s--)
#define readArr    int n ; cin >> n ; int arr[n]; rep(i,0,n)cin>>arr[i]
#define isvowel(a)   (a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u')
#define fast        ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

typedef long long ll ;

void readFromText ()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
#endif // ONLINE_JUDGE
}

const double Pi = acos(-1.0);

bool isMultiBy4 (int a ){
    return a%4==0;
}

bool myFun (int i , int j ) {

}

const int MAX = 1e6;
int mn [MAX+9];
int freq[MAX+9];
int pref[MAX+9];

int main()
{
    fast;
//    readFromText();
    int x , n ; cin >> x >> n ;
    vector<int>v;
    for (int i = 0 ; i < n ; i++){
        int a ;
        cin >> a;
        v.push_back(a);
    }
    sort(all(v));
    int mn = INT_MAX , ii = x ;
    for (int i = -1 ; i <= 105 ; i++ ){
        if (!binary_search(all(v),i)&&abs(x-i)<mn){mn=abs(x-i);ii=i;}
    }
    cout << ii << endl ;
    return 0;
}



Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;
#define REP(i,m,n) for(LL i=(m);i<(n);i++)

int main(){
  LL n,a,b;
  cin >> n >> a >> b;
  
  if(a*n < b){
    cout << a*n << endl;
  }
  else {
    cout << b << endl;
  }
  
  return 0;
}


Measured memory_bytes: 3620
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <set>

using namespace std;
typedef long long ll;
const ll INF = 1LL << 50;

int solve();

ll gcd(ll p, ll q) {
	if (q == 0) { return p; }
	return gcd(q, p%q);
}

int main(void) {
	while (solve()) {}
	return 0;
}

int solve() {

	ll p, q, g;

	cin >> p >> q;

	g = gcd(max(p, q), min(p, q));

	//	約分
	p = p / g;
	q = q / g;

	//	答えはqの素因数をすべて掛け合わせたもの
	//	sqrt{q}までの素数を調べる
	const ll M = (1e+9) + 1;
	const ll N = sqrt(M) + 1;
	ll ans;

	//cout << M << " " << N << endl;
	//	エラトステネスの篩
	vector<ll> primes;
	primes.reserve(5000);
	vector< bool > isPrime(M, true);
	isPrime[0] = false;
	isPrime[1] = false;

	for (ll i = 2; i < N; i++) {
		if (isPrime[i] == false) { continue; }	//	合成数なら
		primes.push_back(i);
		for (ll j = i; i * j < N; j++) {
			isPrime[i*j] = false;
		}
	}
	
	
	ll qc = q;
	set<ll> facts;
	
	for (auto p : primes) {
		if( qc % p == 0 ) {
			while(qc % p == 0)
				qc /= p;	
			if( qc % p > 0 ) {
				facts.insert(p);
			}
		}
	}
	ans = qc;
	for( auto itr = facts.begin(); itr != facts.end(); ++itr ){
		ans *= (*itr);	
	}
	
	cout << ans << endl;



	return 0;
}


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

using namespace std;

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

    int count=0,i=0;

    int l=s.size();

    while(i<l){
        if(s[i]!=t[i]){
            count++;
        }
        i++;

    }

    cout<<count<<endl;



    return 0;
}


Measured memory_bytes: 3836
n=int(input())
a=[int(input())-1 for _ in range(n)]
i=0
ct=0
while i!=1:
  if a[i]==-1:
    print("-1")
    break
  k=i
  i=a[i]
  a[k]=-1
  ct+=1
else:
  print(ct)

Measured memory_bytes: 12604
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;

#define REP(i,n) for(long long i = 0; i < (n); i++)
#define FOR(i, m, n) for(long long i = (m);i < (n); ++i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SPEED cin.tie(0);ios::sync_with_stdio(false);

template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;

const ll MOD = (ll)1e9 + 7;
const ll MOD2 = 998244353;
const ll HIGHINF = (ll)1e18;
const ll LOWINF = (ll)1e15;
const long double PI = 3.1415926535897932384626433;

template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const multiset<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "{" << obj.first << ", " << obj.second << "}"; return o;}
template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
void print(void) {cout << endl;}
template <class Head> void print(Head&& head) {cout << head;print();}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head << " ";print(forward<Tail>(tail)...);}
template <class T> void chmax(T& a, const T b){a=max<T>(a,b);}
template <class T> void chmin(T& a, const T b){a=min<T>(a,b);}
void YN(bool flg) {cout << ((flg) ? "YES" : "NO") << endl;}
void Yn(bool flg) {cout << ((flg) ? "Yes" : "No") << endl;}
void yn(bool flg) {cout << ((flg) ? "yes" : "no") << endl;}

int main() {
	int k = 100;
	V<V<ll>> dp1(k,V<ll>(k,0)),dp2(k,V<ll>(k,0)),dp3(k,V<ll>(k,0)),dp4(k,V<ll>(k,0)),dp(k,V<ll>(k,0));
	dp4[0][2] = 1;
	dp1[2][0] = 1;
	dp2[1][1] = 1;
	dp3[1][1] = 1;
	
	dp[0][2] = 1;
	dp[2][0] = 1;
	dp[1][1] = 2;
	

	for(int i = 0; i < k; ++i){
		for(int j = 0; j < k; ++j){
			if(i+j<=2) continue;
			if(0<=i-1) (dp1[i][j] += dp1[i-1][j]+dp2[i-1][j]) %=100000;
			if(0<=i-1) (dp2[i][j] += dp4[i-1][j]) %=100000;
			if(0<=j-1) (dp3[i][j] += dp1[i][j-1]) %=100000;
			if(0<=j-1) (dp4[i][j] += dp3[i][j-1]+dp4[i][j-1]) %=100000;
			dp[i][j] = dp1[i][j]+dp2[i][j]+dp3[i][j]+dp4[i][j];
			dp[i][j] %= 100000;
		}
	}
	
	while(1){
		int w,h; cin >> w >> h;
		if(w==0&&h==0) return 0;
		cout << dp[h-1][w-1] << endl;
	}
	return 0;
}



Measured memory_bytes: 3400
#include<bits/stdc++.h>
using namespace std;
long long h;
long long abc(long long i)
{
	if(i==1)return 1;
	return 2*abc(i/2)+1;
}
int main()
{
	scanf("%lld",&h);
	printf("%lld",abc(h));
	return 0;
}

Measured memory_bytes: 256
#include"bits/stdc++.h"

#define rep(i, N) for(int i = 0;i < N;i++)

typedef long long ll;

const int mod = 1e9 + 7;

using namespace std;

/* 採点コード
	vector<int> t(D);
	rep(i, D) {
		cin >> t[i];
		t[i]--;
	}
	vector<int> last(26, 0);

	int v = 0;
	rep(i, D) {
		v += s[i][t[i]];
		last[t[i]] = i+1;
		rep(j, 26) {
			v -= c[j] * (i + 1 - last[j]);
		}
		cout << v << endl;
	}
	*/

int main(void) {
	auto start = clock();
	int D; cin >> D;
	vector<int> c(26, 0);
	rep(i, 26)cin >> c[i];
	vector<vector<int>> s(D, vector<int>(26, 0));
	rep(i, D)rep(j, 26)cin >> s[i][j];

	vector<int> t(D, 0);
	vector<int> ans(D, 0);
	int best = 0;

	srand(time(NULL));

	while (clock() - start < 1500) {
		int idx = rand() % D;
		t[idx] = rand() % 26;

		//採点
		vector<int> last(26, 0);
		int v = 0;
		rep(i, D) {
			v += s[i][t[i]];
			last[t[i]] = i + 1;
			rep(j, 26) {
				v -= c[j] * (i + 1 - last[j]);
			}
		}
		//採点
		if (best <= v) {
			ans = t;
		}
	}

	for (auto x : ans) {
		cout << x + 1 << endl;
	}

	return 0;
}

Measured memory_bytes: 3724
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <set>
#include <string>
using namespace std;

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long 
#define ull unsigned long long 
#define f(i,x,n) for(ll int i=x;i<n;i++) 
#define re(j,x,n) for(ll int j=x;j>=n;j--)
#define f1(k,x,n) for(ll int k=x;k<=n;k++)
#define mp make_pair
#define pb push_back
#define mod 1000000007
using namespace std;
int main(){
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   ll int n;
   cin>>n;
   ll int a[n],b[n],c[n-1];
   f(i,0,n)
   cin>>a[i];
   f(i,0,n)
   cin>>b[i];
   f(i,0,n-1)
   cin>>c[i];
   ll int sum=b[a[0]-1],temp=a[0];
   f(i,1,n)
   { 
     if(temp+1!=a[i])
     {
       sum+=b[a[i]-1];
     }
     else
     {
       sum+=b[a[i]-1]+c[a[i]-2];
     }
     temp=a[i];
   }
   cout<<sum;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)
#define pcnt __builtin_popcountll
#define rng(a) a.begin(), a.end()
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
#define fi first
#define se second

using namespace std;
using ll = long long;
using P = pair<int, int>;
using LP = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;

template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) {if (a > b) { a = b; return true; } return false; }

ll INF = 1001001001;
ll LINF = 1001001001001001001ll;

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

    ll n, a, b;
    cin>>n>>a>>b;
    vl hs(n);
    cin>>hs;

    sort(rng(hs));
    reverse(rng(hs));

    ll l = -1, r = 1e10;
    while (l + 1 < r) {
        ll m = (l + r) / 2;
        ll cnt = 0;
        rep(i, n) {
            cnt += max((hs[i] - b * m + (a - b) - 1) / (a - b), 0ll);
        }
        if (cnt > m) l = m;
        else r = m;
    }

    cout<<r<<endl;
}


Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;

namespace ABC144c_2 {
    class Program {
        static void Main(string[] args) {
            var n = long.Parse(Console.ReadLine());

            var result = new List<long>();
            var sqrt = Math.Sqrt(n);
            for (long i = 1; i <= sqrt; i++) {
                if (n % i == 0) {
                    result.Add(i + n / i - 2);
                }
            }

            Console.WriteLine(result.Min());
        }
    }
}

Measured memory_bytes: 13268
#include <iostream>
#include <vector>
#include <utility>
using namespace std;

int N,M;
int V[100010] = {0};
int B[100010] = {0};
int count = 0;

int main(){
	cin >> N >> M;
	vector<pair<int,int>> v(M);
	for(int i=0;i<M;i++){
		int a,b;
		cin >> a >> b;
		v[i] = make_pair(a,b);
	}
	for(int i=1;i<=N;i++){
		B[i] = 1;
	}
	V[1] = 1;
	for(int i=0;i<v.size();i++){
		int f = v[i].first,s = v[i].second;
		B[f]--;
		B[s]++;
		if(V[f]==1) V[s] = 1;
		if(B[f] == 0 && V[f] == 1) V[f] = 0;
	}
	for(int i=1;i<=N;i++){
		if(V[i] == 1) count++;
	}
	cout << count << endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,k,i;
  cin >> n >> k;
  int p[1010];
  for(i=0;i<n;i++){
  cin >> p[i];
  }
  sort(p,p+n);
  int sum=0;
  for(i=0;i<k;i++){
  sum+=p[i];
  }
  cout << sum << endl;
}

Measured memory_bytes: 3596
//
//  abc153_Caracal_Monster.cpp
//  learningCplusplus
//
//  Created by Tran Duc Chinh on 2020/04/04.
//  Copyright © 2020 Tran Duc Chinh. All rights reserved.
//

#include <iostream>
#include <queue>
#include <map>
using namespace std;
typedef long long ll;
ll mod = 1000000007;
#define PI 3.14159265


int main(int argc, const char* argv[]) {

  ll h;
  std::cin >> h;
  ll n = 1;
  ll attack = 0;
  while (h > 1) {
    // std::cout << "h " << h << " n " << n << " attack " << attack << std::endl;
    h = h/2;

    attack = attack + n;
    n = n*2;
  }


  std::cout << attack + n << std::endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
#include <string>
#include <stdlib.h>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <fstream>
#include <typeinfo>
#include <sstream>
#define ll long long
#define ld long double
#define vll vector<ll>
#define pll pair<ll, ll>
#define vpll vector<pll>
#define I insert
#define pb push_back
#define F first
#define S second
#define br "\n"
#define repi(i, a, b) for (ll i = a; i < b; i++)
#define repj(j, a, b) for (ll j = a; j < b; j++)
#define vi vector<int>
#define pii pair<int, int>
#define vpii vector<pii>
#define mod 1000000007
#define lim 100001
#define pi 3.14159265

using namespace std;

ll factorial(ll n)      {    return (n == 1 || n == 0) ? 1 : n * factorial(n - 1); }
ll gcd(ll a, ll b)      {    if (a == 0)  return b; else return gcd(b % a, a);}
ll power(ll a, ll n)    {    if (n == 1) return a;else if (n == 0) return 1; else{ ll r = power(a, n / 2);if (n % 2 == 0)    return r * r;    else    return r * a * r;}}
ll nCr(ll n, ll r)      {    return ((factorial(n)) / (factorial(n - r) * factorial(r))); }
double precise(double n){    return floor(pow(10, 250) * n) / pow(10, 250);}

ll calculate(ll w,ll n, ll weights[], ll value[], vector<vll>& rec){
    if((w==0) or (n==-1)){
        return 0;
    }
    if(rec[w][n]!=-1){
        return (rec[w][n]);
    }
    ll weight = weights[n];
    if(weight>w){
        return  rec[w][n] = calculate(w, n - 1, weights,value,rec);
    }
    else{
    return rec[w][n] = max(calculate(w, n - 1, weights, value, rec), value[n] + calculate(w - weight, n-1, weights, value, rec));
    }
}

void solve(){
    ll n;
    ll w;
    cin >> n >> w;
    ll value[n], weights[n];
    for (int i = 0; i < n;i++){
        cin >> weights[i]>>value[i];
    }
    vector<vll> rec;
    for (int i = 0; i < w+1;i++){
        vll foo;
        rec.pb(foo);
        for (int j = 0; j < n; j++)
        {
            rec[i].pb(-1);
        }
    }
    ll ans = calculate(w, n-1, weights, value,rec);
    cout << ans << br;
}

int main()
{    
#ifndef ONLINE_JUDGE
    // for getting input from input.
    freopen("running_on_fumes_chapter_1_validation_input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
#endif
    ll t;
	t = 1;
	//cin >> t;
	while(t--){
		solve();
	}
	cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
	return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<double> X(N),Y(N);
  for(int i=0;i<N;i++) cin >> X[i] >> Y[i];
  vector<int> V(N),K(N+1,1);
  for(int i=0;i<N;i++) V[i] = i;
  for(int i=2;i<=N;i++) K[i] = K[i-1]*i;
  
  double ans=0;
  do {
    for(int i=0;i<N-1;i++) ans += sqrt((X[V[i]]-X[V[i+1]])*(X[V[i]]-X[V[i+1]]) + (Y[V[i]]-Y[V[i+1]])*(Y[V[i]]-Y[V[i+1]]) ) / K[N];
  } while (next_permutation(V.begin(), V.end()));
  
  cout << fixed << setprecision(16);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#define N 8500
    #define M 210000
    #include <cstdio>
    #include <cstring>
    #include <iostream>
    #include <algorithm>
    using namespace std;
    #define ll long long 
    const int p = 1e9 + 7;
    #define C(n,m) ((ll)fac[n]*inv[m]%p*inv[n-m]%p)
    ll fac[N], inv[N];
    int f[N>>1][N>>1];
    int a[M], b[M];
    int ans, n, i, j;
    ll qp(ll x, ll y) {ll ret=1;while(y){if(y&1) ret=ret*x%p;x=x*x%p;y>>=1;}return ret;}
    inline int init() {
    	scanf("%d", &n);
    	for(i=1;i<=n;i++)scanf("%d%d", &a[i], &b[i]),f[2001-a[i]][2001-b[i]]++;
    	for(i=1;i<=4002;i++)for(j=1;j<=4002;j++)f[i][j]=(f[i][j]+f[i-1][j]+f[i][j-1])%p;
    	for(fac[0]=i=1;i<=8004;i++)fac[i]=(fac[i-1]*i)%p;
    	for(inv[8004]=qp(fac[8004],p-2),i=8004;i>=1;i--)inv[i-1]=inv[i]*i%p;
    	for(i=1;i<=n;i++)ans=(((ans+f[2001+a[i]][2001+b[i]]-C(((a[i]+b[i])<<1),(b[i]<<1)))%p)+p)%p;
    	printf("%lld\n", ans*qp(2, p-2)%p);
    	return 0;
    }
    int E = init();
    int main() {}

Measured memory_bytes: 69888
def factors(N): #約数を全て求める。ただし、順不同
    from collections import deque
    ret = deque()
    middle = int( N**(1/2))
    for i in range(1, middle):
        if N%i == 0:
            ret.append(i)
            ret.append(N//i)
            
    if N%middle == 0:
        ret.append(middle)
        if middle != N//middle:
            ret.append(N//middle)
    return ret

#import sys
#input = sys.stdin.readline
def main():
    N = int( input())
    ans = 0
    F = factors(N)
    for k in F:
        if k == 1:
            continue
        x = N
        while x%k == 0:
            x //= k
        x %= k
        if x == 1:
            ans += 1
    G = factors(N-1)
    for k in G:
        if k == 1:
            continue
        x = N
        while x%k == 0:
            x //= k
        x %= k
        if x == 1:
            ans += 1
    print(ans)
if __name__ == '__main__':
    main()


Measured memory_bytes: 3692
import sys
input = sys.stdin.readline
N = int(input())
rbg = [0, 0, 0]
ans = 1
A = [int(a) for a in input().strip().split()]
for a in A:
    if rbg.count(a) == 0:
        print(0)
        exit()
    ans = (ans * rbg.count(a)) % (10 ** 9 + 7)
    rbg[rbg.index(a)] += 1

print(ans)

Measured memory_bytes: 14364