akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); ++i)

typedef long long ll;
typedef pair<ll, ll> P;

const int MAX = 1e5 + 10;
const int INF = 1e9;
const int MOD = 1e9 + 7;

int N;
string s, t;

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

    int ans = N;
    rep(i, N){
        bool flg = true;
        rep(j, N){
            if(i + j < N && s[i + j] != t[j]){
                flg = false;
                break;
            }
        }
        if(flg) break;
        ans++;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const lint mod = 1e9 + 7;
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl((lint)(n))
#define fcout cout << fixed << setprecision(15)
#define highest(x) (63 - __builtin_clzl(x))
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T = string, class U = char>int character_count(T text, U character){ int ans = 0; for(U i: text){ ans += (i == character); } return ans; }
lint power(lint base, lint exponent, lint module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ lint root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position mv[4] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); } string to_string(string x){ return x; }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++) ans += to_string(*i) + " "; if(!ans.empty()) ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } }
template<class T> T gcd(T a, T b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }} template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct combination{ vector<lint> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } lint C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };
template<class itr> bool next_sequence(itr first, itr last, int max_bound){ itr now = last; while(now != first){ now--; (*now)++; if((*now) == max_bound){ (*now) = 0; }else{ return true; } } return false; }

int main(){
    int N;
    cin >> N;
    lint A[N + 1], B[N];
    cins(A, A + N + 1);
    cins(B, B + N);
    lint ans = 0;
    for(int i = 0; i < N; i++){
        lint attack = min(A[i], B[i]);
        ans += attack;
        A[i] -= attack;
        B[i] -= attack;
        attack = min(A[i + 1], B[i]);
        ans += attack;
        A[i + 1] -= attack;
    }
    cout << ans << endl;
}


Measured memory_bytes: 1792
n=gets.to_i
ts=gets.split.map(&:to_i)
m=gets.to_i
pxs=m.times.map{gets.split.map(&:to_i)}
m.times do |i|
  ans=0
  n.times{|j| ans+= (pxs[i][0]-1)==j ? pxs[i][1]:ts[j]}
  puts ans
end


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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define LCM(a, b) (a) / __gcd((a), (b)) * (b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define ln '\n'

using namespace std;
using LL = long long;
using ldouble = long double;
using P = pair<int, int>;
using LP = pair<LL, LL>;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1e9 + 7;
static const int SIZE = 200005;

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

vector<LL> Div(LL n) {
    vector<LL> ret;
    for(LL i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);
            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

class Node {
public:
    int next;
    long long cost;

    Node(int nxt, int cst) {
        next = nxt;
        cost = cst;
    }

    Node(int nxt) {
        next = nxt;
        cost = 0;
    }
};

class Tree {
public:
    vector<Node> tree[SIZE];
    int root;

    Tree() {
        root = 1;
    }

    Tree(int rt) {
        root = rt;
    }

    void insert(int u, int v) {
        tree[u].push_back(Node(v, 0ll));
        tree[v].push_back(Node(u, 0ll));
    }

    void insert(int u, int v, long long cost) {
        tree[u].push_back(Node(v, cost));
        tree[v].push_back(Node(u, cost));
    }

    int size(int u) {
        return tree[u].size();
    }

    Node getNode(int u, int idx) {
        return tree[u][idx];
    }

    long long getCost(int u, int idx) {
        return tree[u][idx].cost;
    }

    int getNext(int u, int idx) {
        return tree[u][idx].next;
    }

    void setRoot(int rt) {
        root = rt;
    }

};

void dfs(int cur, LL cnt);

LL counter[SIZE];
bool isvisit[SIZE];
Tree tree;

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

    int N, Q;
    cin >> N >> Q;
    tree.setRoot(1);

    for(int i = 0; i < N - 1; ++i) {
        int a, b;
        cin >> a >> b;
        tree.insert(a, b);
    }

    while(Q--) {
        int p, x;
        cin >> p >> x;
        counter[p] += x;
    }

    dfs(1, 0ll);

    for(int i = 1; i <= N; ++i) {
        cout << counter[i] << " ";
    }
    cout << endl;

    return 0;
}

void dfs(int cur, LL cnt) {
    if(isvisit[cur]) return;
    isvisit[cur] = true;

    counter[cur] += cnt;
    cnt = counter[cur];

    for(int i = 0; i < tree.size(cur); ++i) {
        dfs(tree.getNext(cur, i), cnt);
    }

    return;
}


Measured memory_bytes: 26688
#include<bits/stdc++.h>
#define rep(i, n) for (int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
 
int main(void){
    vector<int> v(5);
    rep(i, 5) cin>>v[i];
    rep(i, 5){
        if(v[i] == 0) cout<<i+1<<endl;
    }
    return 0;
}

Measured memory_bytes: 3620
def main():
    N, K = (int(i) for i in input().split())
    S = []
    for i in range(N):
        a, b = (int(i) for i in input().split())
        S.append((b, a))
    S.sort(key=lambda s: s[1])
    SS = [(0, 0)]
    for i in range(N):
        SS.append((S[i][0] + SS[i][0], S[i][1]))
    for b, a in SS:
        if K <= b:
            print(a)
            break


if __name__ == '__main__':
    main()


Measured memory_bytes: 67288
#include <bits/stdc++.h>
using namespace std;
int main(void){
  int N;
  int ans = 0;
  cin >> N;
  for (int i = 1; i < N+1; i++) {
    if (i < 10) {
    } else if (i < 100) {
      continue;
    } else if (i < 1000) {
    } else if (i < 10000) {
      continue;
    } else if (i < 100000) {
    } else if (i < 1000000) {
      continue;
    }
    ans++;
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;
typedef pair<int, int> P;
int B[] = { 0, 2, 5, 5, 4, 5, 6, 3, 7, 6 };

int compare(string s1, string s2)
{
	int l1 = s1.size();
	int l2 = s2.size();
	if (l1 != l2)
	{
		if (l1 < l2)
		{
			return(1);
		}
		else
		{
			return(-1);
		}
	}
	for (int i = 0; i < l1; ++i)
	{
		if (s1[i] == s2[i])
		{
			continue;
		}
		else if (s1[i] < s2[i])
		{
			return(1);
		}
		else
		{
			return(-1);
		}
	}
}

void solve()
{
	int N, M;
	cin >> N >> M;
	vector<int> A(M);
	for (int i = 0; i < M; ++i)
	{
		cin >> A[i];
	}
	vector<string> dp(N + 1);
	vector<int> vst(N + 1);
	vst[0] = 1;
	for (int i = 0; i < N; ++i)
	{
		if (!vst[i])
		{
			continue;
		}
		for (int j = 0; j < M; ++j)
		{
			int d = A[j];
			if (i + B[d] <= N && (!vst[i + B[d]] || (compare(dp[i + B[d]], dp[i] + to_string(d)) > 0)))
			{
				dp[i + B[d]] = dp[i] + to_string(d);
				vst[i + B[d]] = 1;
			}
		}
	}
	cout << dp[N] << endl;
}

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

Measured memory_bytes: 33024
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int main()
{
  int N;
  cin >> N;
  for (int i = 0; i < 7; i++)
  {
    if (pow(2, i) <= N && N < pow(2, i + 1))
    {
      cout << pow(2,i) << endl;
    }
  }
  return 0;
}


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

#define FOR(i,a,b) for (int i = a; i < b; ++i)
#define FORR(i,a,b) for (int i = b - 1; i >= a; --i)
#define REP(i,n) FOR(i,0,n)
#define REPR(i,n) FORR(i,0,n)

unordered_map<string, int> mp;
int N;
string input;

int main() {
  scanf("%d", &N);

  char last;
  for (int i = 0; i < N; ++i) {
    cin >> input;

    if (i != 0) {
      if (input[0] != last) {
        printf("No\n");
        return 0;
      }
    }
    last = input[input.length() - 1];

    auto itr = mp.find(input);
    if (itr != mp.end()) {
      printf("No\n");
      return 0;
    }
    mp[input] = 0;
  }
  
  printf("Yes\n");
  return 0;
}


Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

struct Scanner<R: Read> {
    reader: R,
}

#[allow(dead_code)]
impl<R: Read> Scanner<R> {
    fn new(reader: R) -> Scanner<R> {
        Scanner { reader: reader }
    }

    fn safe_read<T: FromStr>(&mut self) -> Option<T> {
        let token = self.reader.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        if token.is_empty() {
            None
        } else {
            token.parse::<T>().ok()
        }
    }

    fn read<T: FromStr>(&mut self) -> T {
        if let Some(s) = self.safe_read() {
            s
        } else {
            writeln!(stderr(), "Terminated with EOF").unwrap();
            std::process::exit(0);
        }
    }
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);

    let a: u32 = sc.read();
    let b: u32 = sc.read();
    println!("{} {} {:.09}", a / b, a % b, a as f64 / b as f64);
}



Measured memory_bytes: 5052
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <cmath>
using namespace std;


int main()
{
	string a, b;
	cin >> a >> b;
	int l=0;
	for(int i=0; i<a.length(); i++)
	{
		if(a[i] == b[i])
		{
			l++;
		}
	}
	if(l == a.length())
	{
		cout << "Yes";
	}
	else
	{
		cout << "No";
	}
}



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

#define N 100009

using namespace std;

deque<int> q;
vector<int> final;

int main(){
	int i,j,t1,t2,t3,t4,n;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&t1);
		if(i%2){
			q.push_back(t1);
		}
		else{
			q.push_front(t1);
		}
	}
	for(auto it : q){
		final.push_back(it);
	}
	if(n%2==0){
		reverse(final.begin(),final.end());
	}
	for(auto it : final){
		printf("%d ",it);
	}
	printf("\n");
    return 0;
}

Measured memory_bytes: 3960
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0; i<(n); i++)
#define all(v) (v).begin(),(v).end()
bool ok[55];
const int INF = -10000;
int main() {
  string S, T;
  cin >> S >> T;
  int max_num = INF;
  int cnt = 0;
  for(int i=0; i<S.size(); i++) ok[i]=true;
  for(int i=0; i<S.size()-T.size()+1; i++){
    for(int j=0; j<T.size(); j++){
      if(S.substr(i,T.size())[j]=='?') continue;
      else{
        if(S.substr(i,T.size())[j]!=T[j]) ok[i]=false;
      }
    }
  }
  rep(i,S.size()-T.size()+1){
    if(ok[i]==true){
      max_num = max(max_num,i);
    }
  } 
  //cout << max_num << endl;
  if(max_num==INF) cout << "UNRESTORABLE" << endl;
  else{
    S.replace(max_num,T.size(),T);
    rep(i,S.size()) if(S[i]=='?') S[i] = 'a';
    cout << S << endl;
  }
}

Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n, x, y = map(int, read().split())
ans = [0] * n
for k in range(1, n):
    for i in range(k + 1, n + 1):
        if i <= x:
            ans[i - k] += 1
        elif x < i <= y:
            ans[min(i - k, y - i + abs(x - k) + 1)] += 1
        else:
            if k <= x:
                ans[i - y + x - k + 1] += 1
            elif x <= k <= y:
                ans[min(k - x + 1 + i - y, i - k)] += 1
            else:
                ans[i - k] += 1
print('\n'.join(map(str, ans[1:])))


Measured memory_bytes: 3188
import math

#n = int(input())
a = int(input())
b = int(input())
c = int(input())
x = int(input())
#a,b = list(map(int,input().split(" ")))
#ls = list(input().split(" "))
#ls = list(map(int,input().split(" ")))
#a,b = list(input().split())
#string = input()
#ls = [int(input()) for i in range(n)]
#ls1 = [input() for i in range(n)]
#m = int(input())
#ls2 = [input() for i in range(m)]
ans= 0
for i in range(0,a+1):
  for j in range(0,b+1):
    for k in range(0,c+1):
      if i * 500 + j * 100 + k * 50 == x:
        ans += 1
print(ans)

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



int main() {
	int ans = 0;
	int tmp;
	rep(0, 3) {

		cin >> tmp;
		ans += tmp;
	}
	if (ans >= 22) {
		cout << "bust" << endl;
	}
	else {
		cout << "win" << endl;
	}
}


Measured memory_bytes: 256
//Be Name Khoda
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma optimize O3
using namespace __gnu_pbds;
using namespace std;
template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T> using ordered_multiset =  tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
typedef long long int LL;
typedef LL ll;
typedef long double ld;
typedef string str;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
typedef stringstream strs;
 
#define X first
#define Y second
#define PB push_back
#define For(i,a,b) for (int i=a;i<b;i++)
#define Ford(i,a,b) for (int i=a;i>=b;i--)
#define smax(a,b) a=max(a,b)
#define smin(a,b) a=min(a,b)
#define SZ(a) ((ll)a.size())
#define ER(a) cout << #a << ' ' << a << endl
#define LB(a,n,x) (lower_bound(a,(a)+(n),x)-(a))
#define RET(x) { cout << x; exit(0); } 
#define RETD(x) { cout << fixed << setprecision(15) << x; exit(0); }
const ll M=2e3+5,LG=32,SM=600+5,inf=1e18+5;
ll mod=1e9+7;

str s;

int main()
{
	ios::sync_with_stdio(0);
	cin >> s;
	ll res=SZ(s);
	For(i,'a','z'+1)
	{
        s+=(char)i;
    	ll pp=0;
    	ll jav=0;
    	For(j,0,SZ(s))
    	{
    	    if (s[j]!=i) continue;
    	    smax(jav,j-pp);
    	    pp=j+1;
    	}
    	s.pop_back();
    	smin(res,jav);
	}
	RET(res);
}    


Measured memory_bytes: 256
import java.util.*;

public class Main {

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] arrC = new int[n];
		int[] arrS = new int[n];
		int[] arrF = new int[n];
		for (int i = 0; i < n - 1; i++) {
			arrC[i] = sc.nextInt();
			arrS[i] = sc.nextInt();
			arrF[i] = sc.nextInt();
		}
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < n - 1; i++) {
			int total = 0;
			for (int j = i; j < n - 1; j++) {
				if (total < arrS[j]) {
					total = arrS[j];
				}
				if (total % arrF[j] != 0) {
					total += arrF[j] - total % arrF[j];
				}
				total += arrC[j];
			}
			sb.append(total).append("\n");
		}
		sb.append(0).append("\n");
		System.out.print(sb);
	}
}


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

#define REP(i,n) for(int i=0;i<n;i++)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define EPS (1e-7)
#define INF 1e18

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
int vx[]={0,1,0,-1};
int vy[]={1,0,-1,0};

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

const ll mod=1e9+7;
const int MAX_N=300;

int main(){
	ll n,m;
	cin>>n>>m;
	double s=100*(n-m)+1900*m;
	double sum=0;
	for(ll i=1;i<=1000;i++){
		double time=(double)i*s;
		for(int j=1;j<i;j++){
			time*=(pow(2,m)-1);
			time/=pow(2,m);
		}
		time/=pow(2,m);
		sum+=time;
	}
	cout<<sum<<endl;
	return 0;
}

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

using E = System.Linq.Enumerable;

public class Program
{
    public static void Main()
    {
        var nm = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
        var n = nm[0];
        var m = nm[1];
        var seqA = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();

        var items = new SortedSet<Item>();
        for (int i = 0; i < seqA.Length; ++i)
        {
            items.Add(new Item(seqA[i], i));
        }
        while (m > 0)
        {
            var item = items.Max;
            items.Remove(item);
            item.ApplyTicket();
            items.Add(item);
            --m;
        }
        
        Console.WriteLine(items.Sum(x => (long)x.Price));
    }

    struct Item : IComparable<Item>
    {
        public int Price { get; private set; }
        public int Index { get; private set; }

        public Item(int price, int index)
        {
            Price = price;
            Index = index;
        }

        public void ApplyTicket() => Price /= 2;

        int IComparable<Item>.CompareTo(Item other) => this.Price != other.Price ? this.Price.CompareTo(other.Price) : this.Index.CompareTo(other.Index);
    }
}


Measured memory_bytes: 34520
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define rep( i, n, m ) for(int i = ( n ); i < ( m ); i++)
#define rep_d( i, n, m ) for(int i = ( n ) - 1; i >= ( m ); i--)
const ll INF = 1LL << 60;
const int k_mod = 1e9 + 7;
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;
}

int main() {
	int a, b;
	cin >> a >> b;
	int max = a - b;
	if (max < a + b)
		max = a + b;
	if (max < a * b)
	max = a * b;
	cout << max << endl;
	return 0;
}


Measured memory_bytes: 256
// 失敗するからこそ そこから立ち向かって行く強さがあってそんな強さが本当の強さだと私は思うから
// ぜったいあきらめない
#include<bits/stdc++.h>
using namespace std;

#if defined(DAIJOBU)
#include "/home/ichigo/debug.hpp"
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define deb(x...)
#endif
#define FIO {ios::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);}



int main(){
	FIO
	
	int n;
	cin >> n;
	int a[n];
	for(int i = 0; i < n; i++)cin >> a[i];
	int q;
	cin >> q;
	while(q--){
		int b, e;
		cin >> b >> e;
		reverse(a + b, a + e);
	}
	cout << a[0];
	for(int i = 1; i < n; i++)cout << ' ' << a[i];
	cout << '\n';
	return 0;
}



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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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 ll INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

ll ngcd(vector<ll> a) {
  ll res = a[0];
  for(ll i=1; i<a.size() && res!=1; i++) res = gcd(a[i], res);
  return res;
}
ll nlcm(vector<ll> a){
  ll res = a[0];
  for(ll i=1; i<a.size(); i++) res = lcm(a[i], res);
  return res;
}
bool is_prime(ll n) {
  if(n < 2) return false;
  for (ll i = 2; i * i <= n; i++) if (n % i == 0) return false;
  return true;
}
ll digsum(ll n) {
  ll res=0;
  while(n) res += n%10, n /= 10;
  return res;
}
ll digcnt(ll n){
  ll res=0;
  while(n) res++, n /= 10;
  return res;
}
vector<ll> divisor(ll n) {
  vector<ll> res;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      res.push_back(i);
      if (i != n / i) res.push_back(n / i);
    }
  }
  sort(res.begin(), res.end());
  return res;
}
map<ll, ll> prime_factor(ll n) {
  map<ll, ll> res;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) ++res[i], n /= i;
  }
  if (n != 1) res[n] = 1;
  return res;
}

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll a,b; cin>>a>>b;
  ll g=gcd(a,b);
  auto m=prime_factor(g);
  ll ans=m.size()+1;
  cout<<ans<<endl;
}


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

int main() {
  int N; cin >> N;
  map<int, int> m;
  for (int i = 0; i < N; i++) {
    int a; cin >> a;
    if (m.count(a)) m[a]++;
    else m[a] = 1;
  }
  if (m.size() > 3) cout << "No" << endl;
  else if (m.size() == 3) {
    vector<pair<int, int>> v;
    for (auto p : m) v.push_back(p);
    bool ok = true;
    if (N % 3 != 0) ok = false;
    if ((v.at(0).first ^ v.at(1).first ^ v.at(2).first) != 0) ok = false;
    if (!(v.at(0).second == v.at(1).second && v.at(1).second == v.at(2).second)) ok = false;
    if (ok) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
  else if (m.size() == 2) {
    vector<pair<int, int>> v;
    for (auto p : m) v.push_back(p);
    if (v.at(0).first == 0 && v.at(0).second * 2 == v.at(1).second) {
      cout << "Yes" << endl;
    }
    else cout << "No" << endl;
  }
  else {
    if (m.count(0)) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
}


Measured memory_bytes: 3840
#include<iostream>
#include <algorithm>
using namespace std;
int main()
{
  int n,a,b;
  cin >> n;
  cin >> a >> b;

  int p[n];
  int num1 = 0;
  int num2 = 0;
  int num3 = 0;
  for(int i = 0; i < n; i++)
  {
    cin >> p[i];
    if(p[i] <= a)
      num1++;
    else if(p[i] <= b)
      num2++;
    else
      num3++;
  }
  cout << min({num1,num2,num3});
  
  return 0;
}

Measured memory_bytes: 256
str_MY = input()
int_f = int(str_MY[:2])
int_b = int(str_MY[2:])
if (12<int_f and 0<int_b<13) or (int_f ==0 and 0<int_b<13):
    print('YYMM')
elif (12<int_b and 0<int_f<13) or (int_b ==0 and 0<int_f<13):
    print('MMYY')
elif 0<int_b<13 and 0<int_f<13:
    print('AMBIGUOUS')
else:
    print('NA')

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

#define max(a, b) ((a > b) ? a : b)
#define min(a, b) ((a < b) ? a : b)

#define forn(n) for(int i = 0; i < n; i++)
#define fork(k, n) for(int i = k; i < n; i++)

#define pb(n) push_back(n);

typedef long long ll;
typedef double dbl;

const int MX = 1e6;
const int MOD = 1e9 + 7;
const string ALPHA = "abcdefghijklmnopqrstuvwxyz";
const double PI = 3.1415926535;

int main(){
  int n, m;
  cin>>n>>m;
  map<int, int> occ;
  bool bad = 0;
  while(m--){
    int s, c;
    cin>>s>>c;
    if(occ.count(s) && occ[s] != c){
      bad = 1;
      break;
    } else if(s == 1 && c == 0 && n > 1){
      bad = 1;
      break;
    } else {
      occ[s] = c;
    }
  }
  if(bad){
    cout<<-1<<endl;
  } else {
    int p = 1;
    while(p <= n){
      if(occ.count(p)){
        cout<<occ[p];
      } else {
        if(p == 1 && n > 1){
          cout<<"1";
        } else {
          cout<<"0";
        }
      }
      p++;
    }
    cout<<"\n";
  }
}


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

using namespace std;

#define REP(i, n)   for(int i = 0; i < (n); i++)
#define REPS(i, n)  for(int i = 1; i <= (n); i++)
#define RREP(i, n)  for(int i = (n)-1; i >= 0; i--)
#define RREPS(i, n) for(int i = (n); i > 0; i--)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define mp make_pair
#define mt make_tuple
#define pb push_back

using ll  = long long;
using pi  = pair<int, int>;
using pl  = pair<ll, ll>;
using vi  = vector<int>;
using vl  = vector<ll>;
using vs  = vector<string>;
using vb  = vector<bool>;
using vvi = vector<vi>;
using vvl = vector<vl>;

const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const ll  INFL = 1e18;
const double PI = 3.141592653589793;
const double EPS = 1e-9;

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

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

    int W, H, N; cin >> W >> H >> N;
    int l = 0, r = W, u = H, d = 0;
    REP(i, N)
    {
        int x, y, a; cin >> x >> y >> a;
        switch (a)
        {
            case 1:
                chmax(l, x);
                break;
            case 2:
                chmin(r, x);
                break;
            case 3:
                chmax(d, y);
                break;
            case 4:
                chmin(u, y);
                break;
        }
    }
    cout << max(r-l, 0) * max(u-d, 0) << endl;
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
int N;
int main(){
    cin >> N;
    int a;
    a = N / 10;
    a *= 10;
    N -= a;
    if(N == 3)cout << "bon" << endl;
    else if(N == 0 || N == 1 || N == 6 || N ==8)cout << "pon" << endl;
    else cout << "hon" << endl;
}

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

ll gcd(ll a,ll b){
  if(b == 0) return a;
  return gcd(b, a % b);
}

ll lcm(ll a, ll b){
  return a/gcd(a,b) * b;
}
ll func2(ll n){
  ll res = 0;
  while(n%2 == 0){
    n /= 2;
    res++;
  }
  return res;
}

ll zyou(ll a,ll b){//a＾b
  ll res = 1;
  for(int i = 1;i<=b;i++){
    res *= a;
  }
  return res;
}
struct Edge{
  int to;
  int weight;
  Edge(int t, int w) : to(t),weight(w){ }
};

typedef pair<int,int> P;
using Graph = vector<vector<int>>;

ll calc(ll a, ll b, ll p){//aのb乗をpで割った余り
  if(b == 0) return 1;

  else if(b%2 == 0){
    ll d = calc(a,b/2,p);
    return (d*d)%p;
  }
  else if(b%2 == 1){
    return (a * calc(a,b-1,p))%p;
  }
}


bool is_prime(int n){//nが素数であるかどうか判定 iで割り切れると素数でない
    if(n == 1) return false;//1は例外
    for(int i = 2;i*i <= n;i++){
        if(n%i == 0) return false;
    }
    
    return true;
}

bool palin(string S){//回文判定
  int n = S.size();
  bool flag = true;
  if(n%2 == 0){
    for(int i = 0;i<=n/2-1;i++){
      if(S[i] != S[n-i-1]){
        flag = false;
        break;
      }
    }
  }
  else if(n%2 == 1){
    for(int i = 0;i<=n/2-1;i++){
      if(S[i] != S[n-i-1]){
        flag = false;
        break;
      }
    }
  }
  return flag;
}
int main(){
    int N;
    string S;
    cin >> N;
    cin >> S;
    ll ans2 = 0;
    ll r = 0;
    ll b = 0;
    ll g = 0;
    for (int i = 0; i < N; i++) {
      if (S[i] == 'R') r++;
      if (S[i] == 'G') g++;
      if (S[i] == 'B') b++;
    }
    ll ans1 = r * g * b;

    for (int i = 0; i < N; i++) {
        for (int j = i+1; j < N; j++) {
          if (S[i] != S[j]) {
            int k = 2 * j - i;
            if(k >= N) continue;
            if (S[i] != S[k] && S[j] != S[k]) ans2++;
          }
        }
    }
    cout << ans1 - ans2 << endl;
}

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

/**
|||||||||||||       |||||     |||||    ||||||||||
||||||||||||||      |||||     |||||  |||||
|||||     |||||     |||||     |||||  |||||
||||||||||||||||    |||||||||||||||    ||||||||||
|||||||||||||||||   |||||||||||||||           |||||
|||||        |||||  |||||     |||||           |||||
|||||         ||||| |||||     |||||    ||||||||||
AHMED;HASSAN;SAEED;
*/

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n,k,q;
    cin>>n>>k>>q;
    int arr[n]={0};
    for(int i=0;i<q;i++){
        int t;
        cin>>t;
        arr[t-1]++;
    }
    for(int i=0;i<n;i++){
        int sn=k-(q-arr[i]);
        if(sn<=0)
            cout << "No" << endl;
        else
            cout << "Yes" << endl;

    }
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------


int N,A,B;
int ret[4020];

int ask(int a,int b) {
	string s;
	cout<<"? "<<a<<" "<<b<<endl;
	cin>>s;
	return s[0]=='Y';
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>A>>B;
	if(A<=B) {
		cout<<"Impossible"<<endl;
		return;
	}
	
	N=A+B;
	vector<int> path;
	y = B;
	FOR(i,N) {
		if(path.empty() || ask(path.back(),i)) {
			path.push_back(i);
		}
		else {
			path.pop_back();
			y--;
		}
		if(path.size()>y) break;
	}
	
	x = path.back();
	FOR(i,N) ret[i]=ask(x,i);
	cout<<"!";
	FOR(i,N) cout<<ret[i];
	cout<<endl;
	
	
	
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}


Measured memory_bytes: 724
N, K = gets.chomp.split(" ").map(&:to_i)

A = Hash.new(0)
numbers = gets.chomp.split(" ")
numbers.each do |number|
  A[number] += 1
end
if A.length > K+1 then
  reduce_size = A.length - (K + 1)
  ball_num = A.sort {|(k1, v1), (k2, v2)| v1 <=> v2 }[0..reduce_size].inject(["0",0]){|sum, item|
    sum[1] += item[1]
    sum
  }[1]
  print("#{ball_num}")
elsif A.length - K == 1 then
  ball_num = A.sort {|(k1, v1), (k2, v2)| v1 <=> v2 }[0][1]
  print("#{ball_num}")
else
  print("0")
end

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

using namespace std;

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL 9223372036854775
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define MOD 1000000007
#define MOD9 998244353
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define LD long double

#define int long long

using II = pair<int, int>;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(a)  begin((a)), end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())

const int MAX_N = 100005;
int N;
int X[MAX_N], Y[MAX_N];

class UnionFind{
public:
  UnionFind(int aN)
  {
    init(aN);
  }

  void init(int aN)
  {
    par.clear(); cnt.clear(); yset.clear();
    par.resize(aN); cnt.resize(aN); yset.resize(aN);
    for (size_t i = 0; i < aN; i++) {
      par[i] = i;
      cnt[i] = 1;
    }
  }

  int find(int aX)
  {
    if(aX == par[aX]) return aX;
    else return par[aX] = find(par[aX]);
  }

  bool same(int aX, int aY)
  {
    return find(aX) == find(aY);
  }

  int size(int aX)
  {
    return cnt[find(aX)];
  }

  void unite(int aX, int aY)
  {
    aX = find(aX);
    aY = find(aY);
    if(aX == aY) return;

    if(cnt[aX] > cnt[aY]) {
      swap(aX, aY);
    }

    par[aX] = aY;
    cnt[aY] += cnt[aX];
    for(auto it : yset[aX]) {
      yset[aY].insert(it);
    }
    // cerr << "UF" << endl;
    // for(auto it : yset[aY]) {
    //   cerr << it << endl;
    // }
  }

  vector<int> par;
  vector<int> cnt;
  vector<set<int>> yset;
};

UnionFind uf(MAX_N);

map<int, int> YMap;

bool used[MAX_N];

signed main()
{
  cin >> N;
  REP(n,N) {
    cin >> X[n] >> Y[n];
    int k = uf.find(X[n]);
    // cerr << X[n] << "," << Y[n] << " " << k << endl;

    uf.yset[k].insert(Y[n]);
    // cerr << "set" << endl;
    // for(auto it : uf.yset[k]) {
    //   cerr << it << endl;
    // }

    if(YMap[Y[n]] != 0) { // 既に他のグループが存在する場合
      uf.unite(YMap[Y[n]], k);
      // cerr << "unite: " << uf.find(YMap[Y[n]]) << ", " << uf.find(k) << endl;
    } else {
      YMap[Y[n]] = k;
    }
  }

  memset(used, 0, sizeof(used));
  int ans = 0;
  REP(n,MAX_N) {
    if(!used[uf.find(n)]) {
      used[uf.find(n)] = true;
      ans += uf.size(n) * uf.yset[uf.find(n)].size();
    }
  }

  cout << ans - N << endl;

  return 0;
}

Measured memory_bytes: 27904
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()
#define INF (1<<20)
using namespace std;

typedef long long ll;
typedef pair<int, int> P;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n; cin >> n;
	vector<string> S(n);
	rep (i, n){
		cin >> S[i];
	} // end rep

	int cnt[50][26];
	memset(cnt, 0, sizeof(cnt));
	rep (i, n){
		int m = (int)S[i].length();
		rep (j, m){
			++cnt[i][(int)(S[i][j] - 'a')];
		} // end rep
	} // end rep

	int minSum[26];
	rep (i, 26) minSum[i] = INF;
	rep (j, 26){
		rep (i, n){
			minSum[j] = min(minSum[j], cnt[i][j]);
		} // end rep
	} // end rep

	string res = "";
	rep (i, 26){
		rep (j, (int)minSum[i]){
			res += (char)('a' + i);
		} // end rep
	} // end rep
	cout << res << endl;
	
	return 0;
}

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

const int M = (int)1e9+7;
typedef long long LL;

void fastIO_test(void)
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}

void solve(void)
{
    LL n;
    cin >> n;
    LL d[n][2];
    for(LL i=0; i<n; i++)
    {
		for(LL j=0; j<2; j++)
			cin >> d[i][j];
	}
	bool ok = false;
	for(LL i=2; i<n; i++)
	{
		if(d[i][0]==d[i][1] && d[i-1][0]==d[i-1][1] && d[i-2][0]==d[i-2][1])
		{
			ok = true;
			break;
		}
	}
	if(ok==true)
		cout << "Yes" << '\n';
	else 
		cout << "No" << '\n';
}

int main()
{
    fastIO_test();

    LL t=1;
    //cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 3644
import java.util.*;
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        if(a<=b) {
            System.out.println(a);
        }else {
            System.out.println(a-1);
        }
    }
}

Measured memory_bytes: 21204
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
// ref https://atcoder.jp/contests/abc126/submissions/5458290
struct Tree {
    n: usize,
    edges: Vec<Vec<(usize, i64)>>,
}
impl Tree {
    fn new(n: usize) -> Tree {
        Tree {
            n: n,
            edges: vec![vec![]; n],
        }
    }
    fn add_edge(&mut self, s: usize, t: usize, w: i64) {
        self.edges[s].push((t, w));
        self.edges[t].push((s, w));
    }
    fn dists(&self, i: usize) -> Vec<i64> {
        let mut res = vec![0; self.n];
        self.dists_sub(i, self.n, &mut res);
        res
    }
    fn dists_sub(&self, i: usize, prev: usize, res: &mut Vec<i64>) {
        for &(v, w) in &self.edges[i] {
            if v == prev {
                continue;
            }
            res[v] = res[i] + w;
            self.dists_sub(v, i, res);
        }
    }
}
fn main() {
    input!{
        n: usize,
        abc: [(usize1,usize1,i64);n-1],
        q: usize,
        k: usize1,
        xy: [(usize1,usize1);q]
    }
    // println!("{:?}", abc);
    // println!("{:?}", xy);
    let mut tree = Tree::new(n);
    for &(a,b,c) in &abc {
        tree.add_edge(a,b,c);
    }
    // println!("{:?}", tree.dists(k));
    let dis = tree.dists(k);
    for &(x,y) in &xy {
        println!("{}", dis[x] + dis[y]);
    }
}

Measured memory_bytes: 28540
#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <bitset>
#include <functional>
#include <random>
#define REP(_i,_a,_n) for(int _i=_a;_i<=_n;++_i)
#define PER(_i,_a,_n) for(int _i=_n;_i>=_a;--_i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(_a) ({REP(_i,1,n) cout<<_a[_i]<<',';hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
inline int rd() {int x=0;char p=getchar();while(p<'0'||p>'9')p=getchar();while(p>='0'&&p<='9')x=x*10+p-'0',p=getchar();return x;}
//head



#ifdef __APPLE__
const int N = 1e2+50;
#else
const int N = 1e6+50;
#endif


int n;
ll a[N];

int calc() {
	int ans = 0;
	while (1) {
		sort(a+1,a+1+n);
		if (a[n]<=n-1) {exit(0);break;}
		++ans;
		a[n]-=n;
		REP(i,1,n-1) ++a[i];
		if (ans>=1) return ans;
	}
	return ans;
}

int main() {
	scanf("%d", &n);
	REP(i,1,n) scanf("%lld",a+i);
	ll ans = 0;
	while (1) {
		sort(a+1,a+1+n);
		if (a[1]>60) {
			ll t = a[1]-60;
			ans += t*n;
			REP(i,1,n) a[i]-=t;
		}
		if (a[n]<=n-1) break;
		if (a[n]<=2000) {
			ans += calc();
			continue;
		}
		ll ma = -1;
		int p = 0;
		REP(i,2,n) if (a[i]-a[i-1]>ma) ma = a[i]-a[i-1], p = i;
		if (ma<=200) throw;
		ll w = n-p+1, t = (a[p]-a[p-1])/(n+1);
		ans += t*w;
		REP(i,1,p-1) a[i] += t*w;
		REP(i,p,n) a[i] += t*(-n+w-1);
	}
	printf("%lld\n", ans);
}








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

using namespace std;

#define ll long long int
#define ull unsigned long long int
#define REPL(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define radrad(a)  180.0 * a / M_PI
#define pow(x) x*x
static const int MAX = 100010;
static const ll INFTY = 1e12;
static const int NUMMAX = 300;


int main() {

  int N;
  ull ans = 1;
  ll tmp = 1;
  ll maxmax = 0;
  int flag = 1;

  cin >> N;

  vector<int> num(MAX, 0);

  REP(i, N){
    cin >> tmp;
    num[tmp]++;
    maxmax = max(maxmax, tmp);
    if(i == 0){
      if(tmp != 0){
        flag = 0;
        ans = 0;
        break;
      }
    } else {
       if(tmp == 0){
        flag = 0;
        ans = 0;
        break;
      }     
    }
  }

  if(flag == 1){
    REPL(i, maxmax){
      if(num[i] == 0){
        ans = 0;
        break;
      }
      REP(j, num[i+1]){
        ans *= num[i];       
        if(ans > 998244353){
          ans %= 998244353;
        }
      }
    }
  }


  cout << (ans % 998244353) << endl;


  return 0;

}
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         pass System Test!
*/


Measured memory_bytes: 640
// #include <bits/stdc++.h>
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;

#define all(x) begin(x), end(x)
#define rep(i,n) for(int i=0; i<n; i++)

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

    vector<ll> l(n);
    rep(i, n) cin >> l[i];

    int ans = 0;
    ll x;
    for (int i=0; i<n; i++) {
        for (int j=i+1; j<n; j++) {
            if (l[i] == l[j]) continue; 
            x = max(l[i], l[j]);
            for (int k=j+1; k<n; k++) {
                if (l[j] == l[k]) continue;
                if (l[i] == l[k]) continue;
                if (l[i]+l[j]+l[k] > 2*max(x, l[k])) ans++;
            }
        }
    }

    cout << ans << endl;

    return 0;
}

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

int main(){
    int a, b;
    cin >> a >>b;
    cout(a*b);
}


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

int main() {
  int n, x;
  cin >> n >> x;
  vector<int> M(n);
  rep(i,n) {
    cin >> M[i];
    x -= M[i];
  }
  std::sort(M.begin(), M.end());
  int ans = n;
  ans += x / M[0];
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var a int
	fmt.Scan(&a)
	ans := "No"
	for i:=1; i<=9; i++ {
		for j:=1; j<=9; j++ {
			if i*j == a {
				ans = "Yes"
			}
		}
	}
	fmt.Println(ans)
}

Measured memory_bytes: 512
// template.cpp

// Defines.
//#define DEBUG
#define NUMBER_OF_DIGITS 6

// Includes.
#include <bits/stdc++.h>

#ifdef DEBUG
#include <chrono>
#endif

// Usings.
using namespace std;

// Main function.
int main()
{
#ifdef DEBUG
	chrono::system_clock::time_point start, end;
	
	start = chrono::system_clock::now();
#endif
	
	// settings.
	ios::sync_with_stdio(false);
	
	//cout << fixed;
	//cout << setprecision(NUMBER_OF_DIGITS);
	
	// logic.
	int n;
	cin >> n;
	
	string s;
	cin >> s;
	
	set<char> flags1;
	set<char> flags2;
	
	set<string> keys;
	for (int i = 0; i < n; i++)
	{
		if (flags1.count(s[i]) > 0)
		{
			continue;
		}
		
		for (int j = (i + 1); j < n; j++)
		{
			if (flags2.count(s[j]) > 0)
			{
				continue;
			}
			
			for (int k = (j + 1); k < n; k++)
			{
				string key;
				key += s[i];
				key += s[j];
				key += s[k];
				
				keys.insert(key);
				flags1.insert(s[i]);
				flags2.insert(s[j]);
			}
		}
		
		flags2.clear();
	}
	
	cout << keys.size() << endl;
	
#ifdef DEBUG
	end = chrono::system_clock::now();
	
	double elapsed = chrono::duration_cast<std::chrono::milliseconds>(end-start).count();
	cout << elapsed << "[ms]" << endl;
#endif
	
	return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i,m,n) for(int i=(int)(m);i<(int)(n);++i)
#define rREP(i,m,n) for(int (i)=(n)-1; (i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;

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;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

int main() {
	init();

	int N, M; cin >> N >> M;
	vector<pair<ll,ll>>stu(N);
	rep(i, 0, N) {
		ll a, b; cin >> a >> b;
		stu[i] = make_pair(a, b);
	}
	vector<pair<ll, ll>>check(M);
	rep(i, 0, M) {
		ll a, b; cin >> a >> b;
		check[i] = make_pair(a, b);
	}
	rep(i, 0, N) {
		ll dis = INF, sx = stu[i].first, sy = stu[i].second;
		int index = INF;
		rep(j, 0, M) {
			ll cx = check[j].first, cy = check[j].second;
			if (chmin(dis, abs(sx - cx) + abs(sy - cy)))index = j + 1;
		}
		cout << index << "\n";
	}

	return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;//java.util.scanner
import java.lang.*;//java.lang.Math
import java.text.*;
import java.math.*;
public class Main {
	private static int[] fa=new int[100005];
	private static int fd(int a) {
		if(fa[a]==a)return a;
		return fa[a]=fd(fa[a]);
	}
	public static void main(String[] args) throws IOException{
		BufferedReader re=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer t=new StringTokenizer(re.readLine());
		int n=Integer.parseInt(t.nextToken()),m=Integer.parseInt(t.nextToken());
		int[] a= new int[100005],b=new int[100005],num=new int[100005];
		long [] ans=new long[100005];
		ans[m]=(long)n*(n-1)/2;
		for(int i=0;i<m;++i) {
			t=new StringTokenizer(re.readLine());
			a[i]=Integer.parseInt(t.nextToken());
			b[i]=Integer.parseInt(t.nextToken());
		}
		for(int i=1;i<=n;++i) {
			fa[i]=i;
			num[i]=1;
		}
		for(int i=m-1;i>=0;--i) {
			if(fd(a[i])==fd(b[i])) {
				ans[i]=ans[i+1];
			}else {
				ans[i]=ans[i+1]-num[fa[a[i]]]*num[fa[b[i]]];
				num[fa[b[i]]]+=num[fa[a[i]]];
				fa[fa[a[i]]]=fa[b[i]];
			}
		}
		for(int i=1;i<=m;++i) {
			System.out.println(ans[i]);
		}
	}
}


Measured memory_bytes: 59696