akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <math.h>
#include <string.h>
#include <vector>
#include <algorithm>
#include <stack>

using namespace std;

int gcd(int x,int y){
    if(x<y) return gcd(y,x);
    if(y==0) return x;
    return gcd(y,x%y);
}

int max(int x,int y){
    if(x>=y) return x;
    return y;
}

int main(){
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)cin>>a[i];
    int b[n],c[n];
    b[0]=a[0];
    c[n-1]=a[n-1];
    for(int i=1;i<n;i++){
        b[i]=gcd(b[i-1],a[i]);
    }
    for(int i=n-2;i>=0;i--){
        c[i]=gcd(c[i+1],a[i]);
    }
    int ans;
    ans=max(b[n-2],c[1]);
    for(int i=1;i<=n-2;i++){
        ans=max(ans,gcd(b[i-1],c[i+1]));
    }
    cout<<ans<<endl;
    
}


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

#include <boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;

using Cint = cpp_int;

int main() {
	Cint temp_1, temp_2; int n; cin >> n;
	Cint max = pow((Cint)10, 80);
	for (int i = 0; i < n; i++) {
		cin >> temp_1 >> temp_2;
		if (temp_1 + temp_2 >= max) cout << "overflow" << endl;
		else cout << temp_1 + temp_2 << endl;
	}
	return 0;
}


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

pair<ll, ll> dp[3000][3000];

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  rep(i, n) {dp[i][i].first = a[i]; dp[i][i].second = 0;}
  for (int i=1; i<n; i++) for(int j=0; j<n-i; j++) {
    if (a[j] + dp[j+1][j+i].second - dp[j+1][j+i].first > 
        a[j+i] + dp[j][j+i-1].second - dp[j][j+i-1].first) {
      dp[j][j+i].first = a[j] + dp[j+1][j+i].second;
      dp[j][j+i].second = dp[j+1][j+i].first;
    } else {
      dp[j][j+i].first = a[j+i] + dp[j][j+i-1].second;
      dp[j][j+i].second = dp[j][j+i-1].first;
    }
//    cout << j << " " << j+i << " " << dp[j][j+i].first << " " << dp[j][j+i].second << endl;
  }
  cout << dp[0][n-1].first - dp[0][n-1].second << endl;
}


Measured memory_bytes: 139648
import math
n,k = map(int,input().split())

needl = []
for i in range(n):
    need = max(math.ceil((math.log(k/(i+1),2))), 0) 
    needl.append(need)
    

ansl = []
for i in needl:
    ansl.append((1/2)**i * (1/n))

print(sum(ansl))
    
    

Measured memory_bytes: 47284
#include <iostream>
#include <vector>
#include <algorithm>
using namespace	std;

int main() {
  vector<int> s1;
  vector<int> s2;

  int S1, S2;

  for(int i; i < 4; i++) {
    cin >> S1;
    s1.push_back(S1);
  }

  for(int i; i < 2; i++) {
    cin >> S2;
    s2.push_back(S2);
  }

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

  int sum	= 0;
  for(int i = 0; i < 3; i++) {
    sum += s1[i];
  }
  for(int i = 0; i < 1; i++) {
    sum += s2[i];
  }

  cout << sum << endl;

  return 0;
}


Measured memory_bytes: 3112
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <math.h>
#include <bitset>
#include <queue>
#include <set>
#include <iomanip>
#include <math.h>
#include <assert.h>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr long long int infll = 1001001001001001LL;
constexpr int INF = 1000000007;
constexpr int inf = 1000000007;
const int mod = 1000000007;

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

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

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

inline double nCr(const int n, int r)
{
    if (n == 0)
    {
        return 0;
    }
    if (r == 0)
    {
        return 1;
    }
    if (r == 1)
    {
        return n;
    }
    if (n == r)
    {
        return 1;
    }

    if (r > n / 2)
    {
        r = n / 2;
    }

    double result = 1;
    for (double i = 1; i <= r; i++)
    {
        result *= (n - i + 1) / i;
    }

    return (result);
}

template <typename T>
T seinomi(T a)
{
    if (a > 0)
    {
        return a;
    }
    else
    {
        return 0;
    }
}

template <typename T>
map<T, T> soinsuubunkai(T n) //連想配列[素因数f.first][個数f.second]
{
    map<T, T> ret;
    for (T i = 2; i * i <= n; i++)
    {
        while (n % i == 0)
        {
            ret[i]++;
            n /= i;
        }
    }
    if (n != 1)
        ret[n] = 1;
    return ret;
}

template <typename T>
T ketasuu(T num)
{
    return std::to_string(num).length();
}

int kaizyou(int k)
{
    int sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

template <class ForwardIt, class T>
void iota(ForwardIt first, ForwardIt last, T value)
{
    while (first != last)
    {
        *first++ = value;
        ++value;
    }
}

//nの階乗を計算
int factorial(int n)
{
    int answer = 1;
    while (n > 1)
    {
        answer *= n;
        n--;
    }
    return answer;
}
int comb(int n, int r)
{
    return factorial(n) / (factorial(r) * factorial(n - r));
}

long long modpow(long long a, long long n, long long mod)
{
    long long res = 1;
    while (n > 0)
    {
        if (n & 1)
            res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}


template <typename T>
T amarinasi(T a,T b){
    if(a%b==0)
{
    return a/b;
}
else if(a%b>0)
{
    return a/b+1;
}
else
{
    return a/b-1;
}
}

//小数点以下10桁テンプレート（main関数内の最初に貼付け）
//std::cout << std::fixed << std::setprecision(10);

//----------------------------------------------------------------

int main(){ 
ll n;
cin>>n;
ll a;
ll sum=0;
for(ll i=0;i<n;i++){
    cin>>a;
    sum+=a-1;
}
cout<<sum<<endl;
}









Measured memory_bytes: 256
import itertools
def combinations(array, choose):
    return list(itertools.combinations(array, choose))

def resolve():
    N = int(input())
    Pos = [list(map(int, input().split(" "))) for i in range(N)]
    Pos = sorted(Pos, key=lambda x: (x[0], x[1]), reverse=True)
    diffs = []
    comb = combinations(Pos, 2)
    for i in range(len(comb)):
        xdiff = comb[i][0][0] - comb[i][1][0]
        ydiff = comb[i][0][1] - comb[i][1][1]
        for d in diffs:
            if d[0] == xdiff and d[1] == ydiff:
                d[2] += 1
                break
        else:
            diffs.append([xdiff, ydiff, 1])
    
    maxcnt = 0
    for d in diffs:
        if maxcnt < d[2]:
            maxcnt = d[2]
    
    print(N-maxcnt)

if '__main__' == __name__:
    resolve()

Measured memory_bytes: 3316
H,W,K = gets.split.map &:to_i
x1,y1,x2,y2 = gets.split.map{|s| s.to_i - 1}
Map = H.times.map{ gets.chars.map{|s| s=='.'}}

INF = 10**10
Cost = Array.new(H){[INF]*W}

q = [[x1,y1,0]]
Cost[x1][y1] = 0

while xyc = q.shift
    #p xyc
    x,y,c = xyc
    if x==x2 && y==y2 then
        puts c
        exit
    end

    nc = c+1

    1.upto(K) do |i|
        nx = x - i
        break if nx<0 || !Map[nx][y] || Cost[nx][y]<=c
        if nc < Cost[nx][y] then
            Cost[nx][y] = nc
            q << [nx,y,nc]
        end
    end

    1.upto(K) do |i|
        nx = x + i
        break if H<=nx || !Map[nx][y] || Cost[nx][y]<=c
        if nc < Cost[nx][y] then
            Cost[nx][y] = nc
            q << [nx,y,nc]
        end
    end

    1.upto(K) do |i|
        ny = y - i
        break if ny<0 || !Map[x][ny] || Cost[x][ny]<=c
        if nc < Cost[x][ny] then
            Cost[x][ny] = nc
            q << [x,ny,nc]
        end
    end

    1.upto(K) do |i|
        ny = y + i
        break if W<=ny || !Map[x][ny] || Cost[x][ny]<=c
        if nc < Cost[x][ny] then
            Cost[x][ny] = nc
            q << [x,ny,nc]
        end
    end
end

puts -1

Measured memory_bytes: 112176
f :: String -> Int -> Int -> (Int, Int)
f [] l r = (l, r)
f ('(':xs) l r = f xs (l + 1) r
f (')':xs) 0 r = f xs 0 (r + 1)
f (')':xs) l r = f xs (l - 1) r

main = do
    n <- readLn :: IO Int
    s <- getLine
    let (l, r) = f s 0 0
    putStrLn $ replicate r '(' ++ s ++ replicate l ')'

Measured memory_bytes: 508
#include <iostream>
#include <string>

using namespace std;

int main()
{
	string grade;

	while (true)
	{
		int m, f, r;
		cin >> m >> f >> r;

		if (m == -1 && f == -1 && r == -1)
			break;

		if (m == -1 || f == -1 || m + f < 30)
			grade += "F";

		else if (m + f >= 80)
			grade += "A";

		else if (m + f >= 65)
			grade += "B";

		else if (m + f >= 50 || r >= 50)
			grade += "C";

		else if (m + f >= 30)
			grade += "D";
	}

	for (int i = 0; i < grade.size(); ++i)
		cout << grade[i] << endl;

	return 0;
}

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

int main() {
    int n;
    cin >> n;
    int p[n], ans= 0;
    rep(i, n) cin >> p[i];
    rep(i, n-2) {
        if (p[i] < p[i+1] && p[i+1] < p[i+2]) ans++;
        if (p[i] > p[i+1] && p[i+1] > p[i+2]) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n, k;
	cin >> n >> k;
	string s;
	cin >> s;
	for (int i = 0; i < s.size(); i++) {
		if (i==k-1) {
			s[i] += 32;
		}
		printf("%c", s[i]);
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define DEBUG if(0)
#define lli long long int
#define ldouble long double
using namespace std;

/* Tutorial:
  Notice that if you substitute d by d % m, nothing changes. Do it :3

  We want to count a_i mod m < a_(i+1) mod m
  But it's actually easier to count when that doens't happen!

  a_i mod m == a_(i+1) mod m:
    Only happens when d mod m == 0
  a_i mod m > a_(i+1) mod m:
    a_i / m < a_(i+1) / m, by EXACTLY 1 (since we did substitute d by d % m)

  Now ans = n - 1 - x - y
  x = (sumOfTheSequence / m), the amount of a_i mod m > a_(i+1) mod m
  y = how many d mod m = 0 happened in the sequence

  BUT, it's much easier if you merge both cases by instead of adding d % m;
  you add (d % m == 0 ? m : d % m). This way, all cases where d % m == 0
  will be counted as a_i mod m > a_(i+1) mod m. FANTASTIC
*/

const int maxK = 5000; int k, q;
lli d[maxK], n, x, m;
lli acc[maxK + 1];

int main()
{
  while (scanf("%d %d", &k, &q) != EOF)
  {
    for (int i = 0; i < k; i ++)
      scanf("%lld", &d[i]);

    while (q --)
    {
      scanf("%lld %lld %lld", &n, &x, &m);

      for (int i = 0; i < k; i++)
        acc[i + 1] = acc[i] + (d[i] % m == 0 ? m : d[i] % m);
      lli s = (x % m) + acc[k]*((n - 1) / k) + acc[(n - 1) % k];
      lli ans = n - 1 - s / m;
      printf("%lld\n", ans);
    }
  }
  return 0;
}

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

int main() {
    int n, m, u, v;
    cin >> n >> m;
    vector<pair<ll, ll>> student;
    vector<pair<ll, ll>> ckpt;
    for(int i = 0; i < n; i++) {
        cin >> u >> v;
        student.push_back({u, v});
    }
    for(int i = 0; i < m; i++) {
        cin >> u >> v;
        ckpt.push_back({u, v});
    }
    for(int i = 0; i < n; i++) {
        ll dis = INT_MAX;
        int ans = 0;
        for(int j = 0; j < m; j++) {
            ll tmp = llabs(student[i].first - ckpt[j].first) + llabs(student[i].second - ckpt[j].second);
            if (tmp < dis) {
                dis = tmp;
                ans = j+1;
            }
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3648
#include <cstdio>
#include <iostream>
#define N 200010
using namespace std;
int n,cnt,tot,X,Y,ans,head[N],fa[N],dep[N],dis[N],Q[N],be[N],ed[N],a[N][2];
bool vis[N],p[N];
struct edge { int to,from,v; }e[N*4];

void insert(int x,int y,int v) 
{
	e[++cnt].to=y,e[cnt].from=head[x],head[x]=cnt,e[cnt].v=v;
	e[++cnt].to=x,e[cnt].from=head[y],head[y]=cnt,e[cnt].v=v;
}
void dfs(int x)
{
	dep[x]=dep[fa[x]]+1,be[x]=++tot;
	for (int i=head[x];i;i=e[i].from) if (e[i].to!=fa[x]) fa[e[i].to]=x,dfs(e[i].to);
	ed[x]=++tot;
}
void bfs()
{
	int l=1,r=1; Q[1]=X,vis[X]=1;
	while (l<=r)
	{
		int x=Q[l++];
		for (int i=head[x];i;i=e[i].from) if (!e[i].v&&!vis[e[i].to])
		{
			dis[e[i].to]=dis[x]+1;
			if (dis[e[i].to]<dep[e[i].to]) vis[e[i].to]=1,Q[++r]=e[i].to;
		}
	}
}
bool pd(int x,int y)
{
	if (be[x]>be[y]) swap(x,y);
	if (be[x]<be[y]&&ed[x]>ed[y]) return dep[y]-dep[x]>2?true:false;
	if (fa[x]==fa[y]) return false;
	return true;
}
int main()
{
	scanf("%d%d%d",&n,&X,&Y);
	for (int i=1;i<n;i++) scanf("%d%d",&a[i][0],&a[i][1]);
	for (int i=1,x,y;i<n;i++) scanf("%d%d",&x,&y),insert(x,y,1);
	dep[0]=-1,dfs(Y);
	for (int i=1;i<n;i++) if (pd(a[i][0],a[i][1])) p[a[i][0]]=p[a[i][1]]=1; else insert(a[i][0],a[i][1],0);
	bfs();
	for (int i=1;i<=n;i++) if (p[i]&&vis[i]) { printf("-1"); return 0; }
	for (int i=1;i<=n;i++) if (vis[i]) ans=max(ans,dep[i]*2);
	printf("%d",ans);
}

Measured memory_bytes: 22656
#include <bits/stdc++.h>
using namespace std;
#define  rep(i, n) for(int i = 0; i < n; i++) 
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair<ll, ll>
#define F first
#define S second
const int MOD = 1000000007;
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; }
//sort(all(x))とするとソートできるよ
// 10^x は pow(10,(x)) 
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main(){
   LL N,K;cin >> N >> K;
   vector<pair<LL,LL>> L(N);
   rep(i,N){
       LL a,b;cin >> a >> b;
       L[i].F = a;
       L[i].S = b;
   }
   sort(all(L));
   LL tmp = 0;
   LL ans = 0;
   rep(i,N){
       tmp += L[i].S;
       if(tmp >= K){
           ans = L[i].F;
           break;
       }
   }
   cout << ans << endl;
}


Measured memory_bytes: 1792
#include<cstdio>
#include<algorithm>
#include<cstring>
#define MN 200005
using namespace std;
int n,a[MN];long long ans;
int main(){
	scanf("%d",&n);bool ok=1;
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	if(a[1]!=0)ok=0;
	for(int i=2;i<=n;i++)if(a[i]-a[i-1]>=2){ok=0;break;}
	if(!ok)puts("-1");
	else {
		for(int i=2;i<=n;i++)if(a[i]-a[i-1]==1)ans++;else ans+=a[i];
		printf("%lld\n",ans);
	}
}

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

namespace ABC112A
{
    static class MainClass
    {
        public static void Main(string[] args)
        {

            string[] input1 = Console.ReadLine().Split(' ');
            int N = int.Parse(input1[0]);

            if(N == 1){
                Console.WriteLine("Hello World");

            }else{
                string[] input2 = Console.ReadLine().Split(' ');
                int A = int.Parse(input2[0]);
                string[] input3 = Console.ReadLine().Split(' ');
                int B = int.Parse(input3[0]);
                Console.WriteLine(A+B);

                
            }

        }


     

    }

}






Measured memory_bytes: 11092
// ------------------------------------
// Date:2018/ 3/11
// Problem:ABC 090 . a.cpp
//
// ------------------------------------

#include <bits/stdc++.h>

using namespace std;

#define EACH(i,a) for (auto&& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl

typedef long long ll;

static const int MOD = 1000000007;

char c[3][3];

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

  REP(i, 3) {
    REP(j, 3) {
      cin >> c[i][j];
      if (i == j) cout << c[i][j];
    }
  }

  cout << endl;
  
  return 0;
}



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

#define MAX 1000

int dp[MAX+1][MAX+1];

int lcs(char x[], char y[]){
  int x_length = strlen(x);
  int y_length = strlen(y);

  for(int i = 0; i<=x_length; i++) dp[i][0] = 0;
  for(int j = 0; j<=y_length; j++) dp[0][j] = 0;

  for(int i = 1; i<=x_length; i++){
    for(int j = 1; j<=y_length; j++){
      dp[i][j] = (x[i-1] == y[j-1]) ? dp[i-1][j-1] + 1 :
                                  max(dp[i-1][j],dp[i][j-1]);
    }
  }

  return dp[x_length][y_length];
}

int main(){

  int q;
  scanf("%d", &q);

  char X[MAX + 1];
  char Y[MAX + 1];
  for(int i=0; i<q; i++){
    scanf("%s\n%s\n", X, Y);
    printf("%d\n", lcs(X, Y));
  }

  return 0;
}



Measured memory_bytes: 7076
def zadanie_2():

    # n - liczba wierzchołków, m - liczba łuków
    [n, m] = list(map(int, input().strip().split(" ")))

    sasiedzi = [[] for _ in range(n)]
    stopnie = [0 for _ in range(n)]
    kolejka = []
    kolejnosc = []

    for i in range(m):
        luk = list(map(int, input().strip().split(" ")))
        sasiedzi[luk[0]].append(luk[1])
        stopnie[luk[1]] += 1

    for i in range(n):
        if stopnie[i] == 0:
            kolejka.append(i)

    while len(kolejka) > 0:
        wierzcholek = kolejka.pop(0)
        kolejnosc.append(wierzcholek)
        for sasiad in sasiedzi[wierzcholek]:
            stopnie[sasiad] -= 1
            if stopnie[sasiad] == 0:
                kolejka.append(sasiad)

    for i in range(len(kolejnosc)):
        print(str(kolejnosc[i]), end="")
        if i < len(kolejnosc) - 1:
            print("")


zadanie_2()



Measured memory_bytes: 8944
s = input()
l = len(s)
prev = s[0]
a = []
cnt = 0
for i in range(l):
    if s[i] != prev:
        a.append(cnt)
        prev = s[i]
        cnt = 0
    cnt += 1
a.append(cnt)
if s[0]=="<": a = [0]+a
for i in range(len(a)-1): a[i+1] += a[i]
a = a[::2]

b = [0] * (l+1)
s = "=" + s + "="
for i in a:
    bi = 0
    while s[i-bi]==">":
        b[i-bi-1] = max(b[i-bi-1], b[i-bi]+1)
        bi += 1
    bi = 0
    while s[i+bi+1]=="<":
        b[i+bi+1] = max(b[i+bi+1], b[i+bi]+1)
        bi += 1
print(sum(b))

Measured memory_bytes: 60836
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll,ll>;
const ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define pow(x,y) modpow(x,y)
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)

template <class T = int>T in(){
    T x;
    cin >> x;
    return (x);
}

int group(int t){
    if(t == 1||t == 3||t == 5||t == 7||t == 8||t == 10||t == 12) return 1;
    if(t == 4||t == 6||t == 9||t == 11)return 2;
    if(t == 2)return 3;
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    cout << (group(in()) == group(in()) ? "Yes" : "No") << "\n";
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		String str=sc.next();
		String str2="";
		char[] chr=str.toCharArray();
		for(int j=0;j<str.length();j++){
			str2+=chr[str.length()-j-1];
		}
		System.out.println(str2);
		sc.close();
	}
}

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

using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) x.begin(),x.end() //sortなどの引数を省略したい
#define SIZE(x) ll(x.size()) //sizeをsize_tからllに直しておく
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB emplace_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define Umap unordered_map
#define Uset unordered_set

long long modPow(long long x, long long a) {
    if (a == 1) return x;
    if (a % 2) return (x * modPow(x, a - 1)) % MOD;
    long long t = modPow(x, a / 2);
    return (t * t) % MOD;
}

long long modInv(long long x) {
    return modPow(x, MOD - 2);
}

long long modPerm(long long n, long long k) {
    long long ret = 1;
    for (long long i = 0; i < k; i++) {
        ret = (ret * (n - i)) % MOD;
    }
    return ret;
}

int main(){
    ll n, k;
    cin >> n >> k;
    ll b_num = k-1, b_sep = 0, r_num = n-k, r_sep = 1;
    REP(i, k){
        if(b_num < 0 || r_num < 0){
            cout << 0 << endl;
            continue;
        }
        ll b = modPerm(b_num+b_sep, b_num+b_sep) * modInv((modPerm(b_num, b_num)*modPerm(b_sep, b_sep))%MOD);
        ll r = modPerm(r_num+r_sep, r_num+r_sep) * modInv((modPerm(r_num, r_num)*modPerm(r_sep, r_sep))%MOD);
        b %= MOD;
        r %= MOD;
        cout << (b * r) % MOD << endl;
        b_num--;
        b_sep++;
        r_num--;
        r_sep++;
    }
    return 0;
}

Measured memory_bytes: 3528
# coding: utf-8
import re
import bisect
from datetime import datetime as dt

A, B, K = map(int, raw_input().split())
max = max(A, B)
a = []

for i in range(1, max + 1):
    if A % i == 0 and B % i == 0:
        a.append(i)
print a[len(a)-K]


Measured memory_bytes: 2812
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <string>
using namespace std;
typedef long long int lli;

int main()
{
    lli X;
    lli now = 100;
    cin >> X;
    lli count = 0;
    while (now < X)
    {
        count++;
        now *= 1.01;
    }
    cout << count << endl;

    return 0;
}

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

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

    if(A % 3 == 0 || B % 3 == 0 || (A + B) % 3 == 0){
        cout << "Possible" << endl;
    }
    else{
        cout << "Impossible" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LL long long
#define PII pair<int, int>
#define f first
#define s second 
using namespace std;
const LL INF = (LL) 1e9 + 5;
const LL MOD = (LL) 1e9 + 7;
const int MAXN = 100005;

int n, dp[MAXN];
PII rob[MAXN];

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

	cin >> n;
	for (int i = 0; i < n; i++) {
		int x, l;
		cin >> x >> l;
		rob[i] = {x, l};
	}
	sort(rob, rob + n);
	
	vector<PII> stk;
	for (int i = 0; i < n; i++) {
		while (!stk.empty() && rob[i].f + rob[i].s <= stk.back().f + stk.back().s) {
			stk.pop_back();
		}
		if (stk.empty() || stk.back().f - stk.back().s < rob[i].f - rob[i].s) {
			stk.push_back(rob[i]);
		}
	}
	
	int ptr = 1;
	n = stk.size();
	for (int i = 1; i <= n; i++) {
		rob[i] = stk[i - 1];
		while (ptr < i && rob[ptr].f + rob[ptr].s <= rob[i].f - rob[i].s) {
			ptr++;
		}
//		cout << i << " -> " << rob[i].f << ' ' << rob[i].s << '\n';
		dp[i] = max(dp[i - 1], dp[ptr - 1] + 1);
	}
	
	cout << dp[n] << '\n';

	return 0;
}

Measured memory_bytes: 2292
#include<stdio.h>
int main()
{
int a,b,j,d,e;
  d=0;
  e=0;
  scanf("%d %d",&a,&b);
int c[a];
  for(j=0;j<a;++j)
  {
  scanf("%d",&c[j]);
    e=e+c[j];
  if(e<=b) d++;
  }
 printf("%d",d+1);   
    
return 0;    
}

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

int main(void){
 int N,M,a;
 map<int,int> B; 
 long long int ans=0;

 cin>>N>>M;
 vector<long long int>A(N+1,0);
 for(int i=1; i<N+1;i++){
  cin>>a;
  A[i]=(A[i-1]+a)%M;
 }
 for(int i=0; i<N+1; i++){
  ans+=B[A[i]];
  B[A[i]]++;
 }
 std::cout<<ans<<std::endl;
}


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

int main() {
  string o,e;
  cin>>o>>e;
  rep(i,o.size()){
    if(o.size()!=e.size()&&i==o.size()-1)cout<<o[i]<<endl;
    else cout<<o[i]<<e[i];
  }
  return 0;
}

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

using namespace std;

int main() {

	int n, q;
	cin >> n >> q;

	queue<string> str;
	queue<int> ti;

	string ta;
	int tb;
	for (int i = 0; i < n; i++) {
		cin >> ta >> tb;
		str.push(ta);
		ti.push(tb);
	}

	int totaltime = 0;
	while (str.size() != 0) {
		if (ti.front() > q) {
			ti.front() -= q;
			ti.push(ti.front());
			str.push(str.front());
			ti.pop();
			str.pop();
			totaltime += q;
		}
		else {
			totaltime += ti.front();
			cout << str.front() << " " << totaltime << endl;
			ti.pop();
			str.pop();
		}
	}


}


Measured memory_bytes: 5800
fun main() {
    readLine()
    val a = readLine()!!.splitToSequence(" ").map(String::toLong).toList()
    var sum = 0L
    var previous = 0L
    for (ai in a) {
        if (previous < ai) {
            previous = ai
        } else {
            sum += previous - ai
        }
    }
    println(sum)
}

Measured memory_bytes: 66844
#include <iostream>

using namespace std;

enum class KeyKind {
	Zero='0',
	One='1',
	Back='B'
};

string&& acceptKey(KeyKind k, string&& s) {
	if (k == KeyKind::Back && s.empty() == false)
		s.pop_back();
	if (k != KeyKind::Back)
		s.push_back(static_cast<char>(k));
	return move(s);
}

int main() {
	string output, input;
	cin >> input;
	for (char input_char : input)
		output = acceptKey(static_cast<KeyKind>(input_char), move(output));
	cout << output << endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <bitset>
#include <random>
#include <chrono>
#include <complex>
#include <algorithm>
#include <utility>
#include <functional>
#include <cmath>
#include <cstring>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iomanip> 

using namespace std;

#define sqr(x) ((x)*(x))
#define mp make_pair
#define pb push_back
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define RE(i, n) FOR(i,1,n)
#define REP(i,n) FOR(i, 0, (int)(n)-1)
#define all(x) (x).begin(), (x).end()
#define fst first
#define snd second

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;
typedef tuple<ll,ll,ll> iii;

string to_string(string s) {
    return '"' + s + '"';
}
    
string to_string(const char* s) {
    return to_string((string) s);
}
    
string to_string(bool b) {
    return (b ? "true" : "false");
}
    
template <typename A, typename B>
string to_string(pair<A, B> p) {
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
    
template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for (const auto &x : v) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

void fastIO() {
    cin.sync_with_stdio(false);
    cin.tie(0);
}

template<typename T>
vector<T> make_unique(vector<T> v) {
    sort(all(v));
    return v.resize(unique(all(v)) - v.begin());
}

int nxt() {
    int x;
    cin >> x;
    return x;
}


int XMOV[4] = {0, 0, 1, -1};
int YMOV[4] = {1, -1, 0, 0};

//#############################
const int MAXN = 1000005;
int n = nxt(), m = nxt(), q = nxt();
pair<ll, iii> x[51];
vector<ll> ans(n+1, -1);
ll max_score;

ll get_score(){
    ll score = 0;
    for(int i = 0; i < q; i++) {
        int ai, bi, ci;
        tie(ai,bi,ci) = x[i].second;
        if(ans[bi]-ans[ai] == ci)
            score += x[i].first;
    }
    return score;
}

void bf(int idx, int prev) {
    if (idx > n){
        ll score = get_score();
        max_score = max(max_score, score);
        // cout << to_string(ans) << score << endl;
        return;
    }
    for(int i = 1; i <= m; i++){
        if(i >= prev){
            ans[idx] = i;
            bf(idx+1,i);
        }
    }
}

int main() {

    int a, b, c, d;
    for(int i = 0; i < q; i++) {
        a = nxt(), b = nxt(), c = nxt(), x[i].first = nxt();
        x[i].second = tie(a,b,c);
    }
    max_score = -1;
    bf(1,1);
    // cout << to_string(ans) << endl;
    cout << max_score << endl;
    return 0;
}

Measured memory_bytes: 3188
import math
A, B, H, M = map(int, input().split())
a = math.pi/360 * (H*60 + M)
b = math.pi/30 * M
if abs(a - b) > math.pi:
    theta = 2 * math.pi - abs(a-b)
else:
    theta = abs(a-b)
L = math.sqrt(A**2 + B**2 - 2*A*B*math.cos(theta))
print(L)

Measured memory_bytes: 81100
#include"stdio.h"
#include"stdlib.h"
#include"string.h"
struct que
{
  char name[10];
  int time;
  struct que *next;
};
typedef struct que* Que;
Que head;
Que fin;
Que getQue(Que back)
{
  back->next=(struct que*)malloc(sizeof(struct que));
  back->next->next=NULL;
  return back->next;
}
void push(char *name,int time)
{
  fin=getQue(fin);
  strcpy(fin->name,name);
  fin->time=time;
}
int deQue(int q)
{
  Que buf;
  static int time=0;
  if(head->next!=NULL)
    {
      if(head->next->time>q)
        {
          push(head->next->name,head->next->time - q);
          buf=head->next;
          head->next=head->next->next;
          time+=q;
          free(buf);
          return 1;
        }
      else
        {
          buf=head->next;
          head->next=head->next->next;
          time+=buf->time;
          printf("%s %d\n",buf->name,time);
          free(buf);
          return 1;
        }
    }
  else
    {
      return 0;
    }
}
int main()
{
  head=(struct que*)malloc(sizeof(struct que));
  fin=head;
  Que p;
  Que buf;
  int n,q;
  int time;
  char name[10];
  int i;
  scanf("%d%d",&n,&q);
  for(i=0;i<n;i++)
    {
      scanf("%s%d",name,&time);
      push(name,time);
    }
  while(deQue(q));
  return 0;
}


Measured memory_bytes: 3324
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define fi first
#define se second
#define PI (acos(-1))

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;
}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i];if(i<len-1) s<<" ";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i]<<endl;
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){
	s<<"{ ";
	for(auto itr=v.begin();itr!=v.end();++itr) {
		if (itr!=v.begin()) {s<< ", ";}
		s<<(*itr);
	}
	s<<" }";
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){
	s<<"{"<<endl;
	for(auto itr=m.begin();itr!=m.end();++itr){
		s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;
	}
	s<<"}"<<endl;
	return s;
}

const ll mod=1e9+7;
const ll inf=1e15;
const int INF=1e9;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
    ll n,a,b;
    cin>>n>>a>>b;
    ll cnt=b-a-1;
    if(cnt%2==0){
        ll ans=min(b-1,n-a);
        ll x=a-1,y=n-b;
        //cout<<x<<' '<<y<<endl;
        if(cnt>=1){
            ll now=cnt-1;
            //cout<<now<<' '<<2*x+1+(now+1)/2<<endl;
            ans=min(ans,x+1+(now+1)/2);
        }
        if(cnt>=1){
            ll now=cnt-1;
            //cout<<now<<' '<<2*y+1+(now+1)/2<<endl;
            ans=min(ans,y+1+(now+1)/2);
        }
        cout<<ans<<endl;
    }else{
        cout<<(cnt+1)/2<<endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <bitset>
#include <assert.h>

using namespace std;
typedef long long ll;
typedef set<int>::iterator ssii;

#define Cmp(a, b) memcmp(a, b, sizeof(b))
#define Cpy(a, b) memcpy(a, b, sizeof(b))
#define Set(a, v) memset(a, v, sizeof(a))
#define debug(x) cout << #x << ": " << x << endl
#define _forS(i, l, r) for(set<int>::iterator i = (l); i != (r); i++)
#define _rep(i, l, r) for(int i = (l); i <= (r); i++)
#define _for(i, l, r) for(int i = (l); i < (r); i++)
#define _forDown(i, l, r) for(int i = (l); i >= r; i--)
#define debug_(ch, i) printf(#ch"[%d]: %d\n", i, ch[i])
#define debug_m(mp, p) printf(#mp"[%d]: %d\n", p->first, p->second)
#define debugS(str) cout << "dbg: " << str << endl;
#define debugArr(arr, x, y) _for(i, 0, x) { _for(j, 0, y) printf("%c", arr[i][j]); printf("\n"); }
#define _forPlus(i, l, d, r) for(int i = (l); i + d < (r); i++)
#define lowbit(i) (i & (-i))
#define MPR(a, b) make_pair(a, b)

pair<int, int> crack(int n) {
    int st = sqrt(n);
    int fac = n / st;
    while (n % st) {
        st += 1;
        fac = n / st;
    }

    return make_pair(st, fac);
}

inline ll qpow(ll a, int n) {
    ll ans = 1;
    for(; n; n >>= 1) {
        if(n & 1) ans *= 1ll * a;
        a *= a;
    }
    return ans;
}

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

int judge(int x) {
    if(x < 400) return 0;
    else if(400 <= x && x <= 599) return 8;
    else if(600 <= x && x<= 799) return 7;
    else if(800 <= x && x <= 999) return 6;
    else if(1000 <= x && x <= 1199) return 5;
    else if(1200 <= x && x <= 1399) return 4;
    else if(1400 <= x && x <= 1599) return 3;
    else if(1600 <= x && x <= 1799) return 2;
    else if(1800 <= x && x <= 1999) return 1;
    else return 0;
}

int main() {
    //freopen("input.txt", "r", stdin);
    cin >> x;
    int ans = judge(x);
    cout << ans << endl;
}

Measured memory_bytes: 3676
package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 10000000
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wt = bufio.NewWriter(os.Stdout)
)

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

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(next(), 64)
	return f
}

func nextFloat64s(n int) []float64 {
	slice := make([]float64, n)
	for i := 0; i < n; i++ {
		slice[i] = nextFloat64()
	}
	return slice
}

func putf(format string, a ...interface{}) {
	fmt.Fprintf(wt, format, a...)
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initialBufSize), maxBufSize)
	defer wt.Flush()

	const mod = 1000000007
	n, k := nextInt(), nextInt()

	ans := 0
	for i := k; i <= n+1; i++ {
		// n-i+1,...,n
		max := (n*(n+1))/2 - ((n-i)*(n-i+1))/2
		// 0,..,i-1
		min := ((i - 1) * i) / 2
		ans = (ans + max - min + 1) % mod
	}

	puts(ans)
}


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

using namespace std;
typedef long long ll;
#define rep(i,j,n) for (int i = j; i < (n); i++)
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const ll INF = 1e9;

int main(){

  int n;cin>>n;
  vector<int>v;
  deque<int>d;
  rep(i,0,n){
    int b;cin>>b;
    v.push_back(b);
  }
  rep(i,0,n){
    for(int j=v.size()-1;j>=0;j--){
      if(v[j]==j+1){
        d.push_front(v[j]);
        v.erase(v.begin()+j);
        break;
      }
    }
  }

  if(v.size()!=0)out(-1);
  else{
    rep(i,0,d.size())out(d[i]);
  }

  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <stdlib.h>
#include <algorithm>
#include <iostream>
using namespace std;
int main()
{
	int a,b,x;
	cin >> a >> b;
	if (a<10&&b<10&&a>=1&&b>=1) {
		cout << a * b;
	}
	else {
		cout << "-1";
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <functional>
#include <stack>
#include <numeric>
typedef long long ll;
using namespace std;
const int MOD = (int)1e9 + 7;
const ll INF = (ll)1e18 + 7;
#define int long long
#define vint vector<int>
#define pint pair<int,int>
#define pb(a) push_back(a)
#define all(v) v.begin(),v.end()
#define dbg(x) cerr << #x << " = " << (x) << endl
#define yn(b) cout << ((b) ? "Yes" : "No") << endl
#define YN(b) cout << ((b) ? "YES" : "NO") << endl

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

struct B
{
	string name;
	int ten;
	int no;
};

bool cmp(B &a,B &b){
	if(a.name==b.name){
		return a.ten>b.ten;
	}else{
		return a.name<b.name;
	}
}

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

	int N;
	cin>>N;
	vector<B> V(N);
	
	for (int i = 0; i < N; i++) {
		cin>>V[i].name>>V[i].ten;
		V[i].no=i+1;
	}
	
	sort(all(V),cmp);
	
	for (int i = 0; i < N; i++) {
		cout<<V[i].no<<endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
const LL mod=1000000007;
const LL LINF=1LL<<62;
const int INF=1<<30;
int dx[]={1,0,-1,0,1,-1,1,-1};
int dy[]={0,1,0,-1,1,-1,-1,1};


int main(){
    string s;cin >> s;
    string t;cin >> t;
    if(s == t.substr(0,s.length())) puts("Yes");
    else puts("No");
    return 0;
}


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

int main()
{
	ios::sync_with_stdio(false), cin.tie(0);
	int H, W, N;
	while (cin >> H >> W >> N, H | W | N) {
		vector<vector<int>> a(H + 1, vector<int>(W + 1));
		for (int i = 0; i < H; i++) {
			for (int j = 0; j < W; j++) {
				cin >> a[i][j];
			}
		}
		vector<vector<int>> dp(H + 1, vector<int>(W + 1));
		dp[0][0] = N - 1;
		for (int i = 0; i < H; i++) {
			for (int j = 0; j < W; j++) {
				dp[i + 1][j] += a[i][j] ? dp[i][j] / 2 : (dp[i][j] + 1) / 2;
				dp[i][j + 1] += a[i][j] ? (dp[i][j] + 1) / 2 : dp[i][j] / 2;
			}
		}
		int ti = 0, tj = 0;
		while (ti < H && tj < W) {
			if (a[ti][tj] ^ (dp[ti][tj] & 1)) {
				tj++;
			}
			else {
				ti++;
			}
		}
		cout << ti + 1 << ' ' << tj + 1 << endl;
	}
	return 0;
}



Measured memory_bytes: 10820
using System;
using System.Collections.Generic;
using System.Linq;
class Program{
	const int mod=1000000007;
	static void Main(){
		Sc sc=new Sc();
		int n=sc.I;
		long[] a=sc.La;
		long ans=0;
		bool b=true;
		while(b){
			long p=0;
			for(int i = 0;i<n;i++) {
				long q=Math.Max((a[i]-(n-1)),0)/n+(Math.Max((a[i]-(n-1)),0)%n==0?0:1);
				a[i]-=q*n+q;
				p+=q;
			}
			b=false;
			for(int i = 0;i<n;i++) {
				a[i]+=p;
				if(a[i]>=n){b=true;}
			}
			ans+=p;
		}
		Console.WriteLine(ans);
	}
}

class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
}

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

int main() {
    ll d, g; cin >> d >> g;
    g /= 100;
    vector<int> p(d), c(d);
    rep (i, d) {
        cin >> p[i] >> c[i];
        c[i] /= 100;
    }

    ll ans = INT_MAX;
    rep (i, (1<<d)) {
        ll cnt = 0, sum = 0;
        rep (j, d) {
            if (i & (1<<j)) {
                cnt += p[j];
                sum += p[j]*(j+1) + c[j];
            }
        }
        for (ll j = d-1; j >= 0; j--) {
            // iをbit反転してj番目のフラグが立っていたら足していく
            if (~i>>j & 1) {
                for (ll k = 0; k < p[j] && sum < g; k++) {
                    sum += j+1;
                    cnt++;
                }
            }
        }
        if (sum >= g) {
            ans = min(cnt, ans);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
n,x = map(int,input().split())
l = list(map(int,input().split()))
ln = [0]*(n+1)
for i in range(n):
  ln[i+1] = ln[i] +l[i]
 

for i in range(n+1):
  if ln[i]>x:
    print(i)
    exit()

print(n+1)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define int long long
using namespace std;
using P = pair<int, int>;
const int INF = 1LL<<60;
const int MOD = 998244353;

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    string s;
    cin >> n >> s;
    for (int i = 0; i < s.size(); i++) {
        s[i] = 'A' + (s[i] - 'A' + n) % 26;
    }
    cout << s << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
// rep(i, 1, 5) --> {1,2,3,4}
// rep(i, 5, 1) --> {4,3,2,1}
// rep(it, end(v), begin(v)) --> *it

using namespace std;

int main()
{
    int h, w;
    cin >> h >> w;
    vector<string> v(h+2);
    v[0] = string(w, '.');
    v[h+1] = string(w, '.');
    rep(i, 1, h+1)
    {
        string s;
        cin >> s;
        v[i] = '.' + s + '.';
    }
    rep(i, 1, h+1)
        rep(j, 1, w+1)
        {
            if (v[i][j] == '.')
            {
                int sum = 0;
                if (v[i-1][j-1] == '#') sum++;
                if (v[i-1][j] == '#') sum++;
                if (v[i-1][j+1] == '#') sum++;
                if (v[i+1][j-1] == '#') sum++;
                if (v[i+1][j] == '#') sum++;
                if (v[i+1][j+1] == '#') sum++;
                if (v[i][j-1] == '#') sum++;
                if (v[i][j+1] == '#') sum++;
                v[i][j] = to_string(sum)[0];
            }
        }
    rep(i, 1, h+1)
        cout << v[i].substr(1, w) << endl;
    return 0;
}

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

using namespace std;

typedef long long LL;

const int Mod = 1e9 + 7;
const int N = 5e5 + 4;

LL f[N]{1};
int n, m;

LL fp(LL a, LL b) {
    LL res = 1;
    while (b) {
        if (b & 1) res = res * a % Mod;
        a = a * a % Mod;
        b >>= 1;
    }
    return res;
}

LL inv(LL x) {
    return fp(x, Mod - 2);
}

LL A(LL a, LL b) {
    return f[a] * inv(f[a - b]) % Mod;
}

LL C(LL a, LL b) {
    return A(a, b) * inv(f[b]) % Mod;
}

signed main() {
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);

    
    cin >> n >> m;
    if (n > m) {
        cout << 0 << endl;
        return 0;
    }

    for (int i = 1; i <= m; i++) {
        f[i] = i * f[i - 1] % Mod;
    }

    LL ans = 0;
    for (int i = 0; i <= n; i++) {
        LL x = A(m - i, n - i) * C(n, i) % Mod;
        if (i & 1) {
            ans = ans + Mod - x;
        }
        else ans += x;
        ans %= Mod;
    }
    cout << ans * A(m, n) % Mod << endl;
    return 0;
}

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

// 入力
long long N;

// cur: 現在の値、use: 7, 5, 3 のうちどれを使ったか, counter: 答え
void func(long long cur, int use, long long& counter) {
	if (cur > N) return; // ベースケース
	if (use == 0b111) ++counter; // 答えを増やす

	// 7 を付け加える
	func(cur * 10 + 7, use | 1<<0, counter);

	// 5 を付け加える
	func(cur * 10 + 5, use | 1<<1, counter);

	// 3 を付け加える
	func(cur * 10 + 3, use | 1<<2, counter);
}

int main() {
	cin >> N;
	long long res = 0;
	func(0, 0, res);
	cout << res << endl;
}

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

int main(void)
{
	unsigned long long n,p=1;
	cin >> n;
	
	for(unsigned int i=1;i<=n;i++){
		p = (p*i)%1000000007;
	}
	cout << p << endl;
	return 0;
}


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

int main() {
    vector<int> v(3), w(3);
    for (int i = 0; i < 3; ++i) cin >> v[i];
    for (int i = 0; i < 3; ++i) w[i] = abs(v[i] - v[(i + 1) % 3]);
    cout << accumulate(w.begin(), w.end(), 0LL) - *max_element(w.begin(), w.end()) << endl;
}


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

int main(){
  int n; cin>>n;
  vector<int> a(n);
  for(int i=0; i<n; ++i)cin>>a[i];

  long long ans1=0LL, ans2=0LL, sum=0LL;
  for(int i=0; i<n; ++i){
    sum+=a[i];
    if(i%2==0 && sum<=0){ans1+=1-sum; sum=1;}
    else if(i%2==1 && sum>=0){ans1+=1+sum; sum=-1;}
  }

  sum=0;
  for(int i=0; i<n; ++i){
    sum+=a[i];
    if(i%2==1 && sum<=0){ans2+=1-sum; sum=1;}
    else if(i%2==0 && sum>=0){ans2+=1+sum; sum=-1;}
  }

  cout<<min(ans1, ans2)<<endl;
}


Measured memory_bytes: 640
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main implements Runnable {

    public static void main(String[] args) {
        new Thread(null, new Main(), "", 128 * 1024 * 1024).start();
    }

    public void run() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] a = new int[N + 1];
        boolean allNegative = true, allPositive = true;
        int maxIdx = 1;
        boolean isMaxPositive = false;
        boolean isSorted = true;
        for (int i = 1; i <= N; i++) {
            a[i] = sc.nextInt();
            if (a[i] > 0) {
                allNegative = false;
            }
            if (a[i] < 0) {
                allPositive = false;
            }
            if (Math.abs(a[i]) >= Math.abs(a[maxIdx])) {
                isMaxPositive = a[i] > 0;
                maxIdx = i;
            }
            if (i != 1 && a[i - 1] > a[i]) {
                isSorted = false;
            }
        }

        List<Pair> pairs = new ArrayList<>();
        if (!allNegative && !allPositive) {
            for (int i = 1; i <= N; i++) {
                pairs.add(new Pair(maxIdx, i));
                a[i] += a[maxIdx];
            }
        }

        if (!isSorted) {
            if (isMaxPositive) {
                for (int i = 1; i <= N - 1; i++) {
                    pairs.add(new Pair(i, i + 1));
                    a[i + 1] += a[i];
                }
            } else {
                for (int i = N; i >= 1 + 1; i--) {
                    pairs.add(new Pair(i, i - 1));
                    a[i - 1] += a[i];
                }
            }
        }

        System.out.println(pairs.size());
        for (int i = 0; i < pairs.size(); i++) {
            System.out.println(pairs.get(i).x + " " + pairs.get(i).y);
        }
    }

    class Pair {

        public Pair(int x, int y) {
            this.x = x;
            this.y = y;
        }

        int x;
        int y;
    }
}

Measured memory_bytes: 25940
from itertools import product

h, w, k = map(int, input().split())
c = [list(input()) for _ in range(h)]

ans = 0

for row_bit in product(range(2), repeat=h):
    for col_bit in product(range(2), repeat=w):
        cnt = 0
        for row in range(h):
            for col in range(w):
                if c[row][col] == "#" and (row_bit[row] and col_bit[col]):
                    cnt += 1
        if cnt == k:
            ans += 1

print(ans)

Measured memory_bytes: 9064
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#include <set>
#include <map>
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(0), cout << fixed << setprecision(20);
#define rep(i,n) for (int i=0; i<n;++i)
#define ALL(a)  (a).begin(),(a).end()
#define PI 3.14159265358979
typedef long long ll;
using namespace std;
const ll MOD = 1e9+7LL;
const int INF = 2e9;
int L,R,d;

int main() {
  INCANT;
  cin >> L >> R >> d;
  cout << (R/d)-((L-1)/d) << "\n";
  return 0;
}

Measured memory_bytes: 3640