akhauriyash/Code-Regression huggingface dataset:
/*  Sourav Verma IPG_2013  ABV_IIITMG 
        Task @ Codeforces & Atcoder  */

#include<bits/stdc++.h>

#define ll                    long long int
#define loop(i,a,b)           for(int i=(int)a;i<(int)b;++i)
#define rloop(i,a,b)          for(int i=(int)a;i<=(int)b;++i)
#define loopr(i,a,b)          for(int i=(int)a;i>=(int)b;--i)
#define count_1(n)            __builtin_popcountll(n)
#define pb                    push_back
#define mset(a,b,c)           loop(i,0,b) a[i]=c
#define F                     first
#define S                     second
#define mp                    make_pair
#define clr(x)                x.clear()
#define MOD                   1000000007
#define MAX                   1e9
#define MIN                   -1e9
#define itoc(c)               ((char)(((int)'0')+c))
#define vi                    vector<int>
#define vvi                   vector<vi>
#define pll                   pair<ll,ll>
#define pii                   pair<int,int>
#define all(p)                p.begin(),p.end()
#define mid(s,e)              (s+(e-s)/2)
#define mini                  INT_MIN
#define sv()                  int t; scanf("%d",&t); while(t--)
using namespace std;
ll extgcd(ll a,ll b,ll& x,ll& y){if(b==0){x=1;y=0;return a;}else{int g=extgcd(b,a%b,y,x);y-=a/b*x;return g;}}
ll lcm(int x, int y) { return x * 1ll * y / (int)__gcd(x, y); }
ll hcf(ll a, ll b) {if(b>a) return (hcf(b, a)); if(a%b==0) return b; return (hcf(b, a%b));} 
ll modpow(ll a,ll b) {ll res=1;a%=MOD;for(;b;b>>=1){if(b&1)res=res*a%MOD;a=a*a%MOD;}return res;}

void solve(std::istream &in, std::ostream &out){
    int n; in>>n; int t[105],tmp[105],m,p,x; ll sum;
    rloop(i,1,n) {
        in>>t[i]; tmp[i]=t[i];
    }
    in>>m;
    while(m--){
        rloop(i,1,n) tmp[i]=t[i];
        in>>p>>x;
        tmp[p]=x; 
        sum=0;
        rloop(i,1,n) {sum+=tmp[i];}
        out<<sum<<"\n";
        //rloop(i,1,n) out<<tmp[i]<<" ";
        //rloop(i,1,n) out<<t[i]<<" ";
    }
    
}

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
    #ifdef debug
        freopen("in.txt", "r", stdin);
    	freopen("out.txt", "w", stdout);
	#endif
    
    solve(std::cin, std::cout);
    
    #ifdef debug
        fprintf(stdout,"\nTIME: %.3lf sec\n", (double)clock()/(CLOCKS_PER_SEC));
    #endif
    
    return 0;
}

Measured memory_bytes: 256
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter,defaultdict
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
sys.setrecursionlimit(10**6)
INF =  float("inf")
import bisect
import statistics
mod = 10**9+7

def bit(S, j):
    # Sの右からj bit目(0-indexed)
    return (S>>j)&1

N = int(input())
a = [[] for i in range(N)]
for i in range(N):
    a[i] = list(map(int, input().split()))

dp = [-INF for i in range(1<<N)]
dp[0] = 0

for S in range(1<<N):
    dp[S] = 0
    for i in range(N):
        for j in range(i+1, N):
            if bit(S,i) and bit(S,j): dp[S] += a[i][j]

    T = S - 1
    T = T & S
    while T > 0:
        dp[S] = max(dp[S], dp[T] + dp[S^T])
        T = T - 1
        T = T & S

print(dp[(1<<N)-1])




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

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

constexpr int atcoder_mod = 1e9+7;

using namespace std;
using ll = long long;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

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

	int A=in(),B=in(),C=in();
	if(A<B && B<C) out("Yes");
	else out("No");
	
	return 0;
}



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

#define int long long

#define REP(i, a) for(int i = 0; i < (a); i++)

using namespace std;

signed main()
{
    cout << fixed << setprecision(10);

    while(true)
    {
        int H, W; cin >> H >> W;
        if(H == 0 && W == 0) break;
        REP(i, H)
        {
            REP(j, W)
            {
                cout << '#';
            }
            cout << endl;
        }
        cout << endl;
    }
}


Measured memory_bytes: 3092
from typing import List, Any


def read_int() -> int:
    return int(input().strip())


def read_ints() -> List[int]:
    return list(map(int, input().strip().split(' ')))


def solve() -> Any:
    N, X, M = read_ints()
    seen = [0]*M
    answer = X
    cycle_length = 1
    cycle_prefix = [0, X]
    N -= 1
    count = 0
    while N > 0:
        next_X = (X**2) % M
        if seen[next_X]:
            cycle_length = count-seen[next_X]+1
            break
        seen[next_X] = seen[X]+1
        cycle_prefix.append(cycle_prefix[-1]+next_X)
        answer += next_X
        N -= 1
        X = next_X
        count += 1
    if N == 0:
        return answer
    answer += (N//cycle_length)*(cycle_prefix[-1]-cycle_prefix[-cycle_length-1])
    N %= cycle_length
    while N > 0:
        X = (X**2) % M
        answer += X
        N -= 1
    return answer


if __name__ == '__main__':
    print(solve())


Measured memory_bytes: 73664
n=int(input())
A=[[0,0] for i in range(n)]
for i in range(n):
  A[i][1],A[i][0]=map(int,input().split())
  
A.sort()
time=0
flg=True
for i in range(n):
  time+=A[i][1]
  if time>A[i][0]:
    flg=False
    
if flg:
  print('Yes')
else:
  print('No')
  
  

Measured memory_bytes: 35616
fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toLong)
fun <T> Array<Array<T>>.print() {
    this.forEach {
        println(it.joinToString(" "))
    }
}

fun main() {
    var n = readInt()
    while(n > 1000) {
        n -= 1000
    }
    println(1000 - n)
}


Measured memory_bytes: 34432
#2020-03-21
turn = int(input())
s = 0
t = 0

for i in range(turn):
    a,b = map(str,input().split())
    if a > b :
        s += 3
    elif a < b:
        t += 3
    elif a == b:
        s += 1
        t += 1
print(s,t)


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

string s;

int main() {
  cin >> s;
  int state = 0;
  for (auto c : s)
    if (state == 0 && c == 'C')
      state = 1;
    else if (state == 1 && c == 'F')
      state = 2;
  if (state == 2)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 3628
#include <stdio.h>
#include <string.h>

char dict[30600000];

char word[26];

long encode(const char *key){
  int n=strlen(key),i;
  long sum=0;
  long keta=1;
  for(i=0;i<n;i++){
    int keyi=key[i];
    sum = sum + keta * word[keyi];
    //    if (key[i]=='A')      sum = sum + keta;
    //    else if (key[i]=='C') sum = sum + (keta << 1);
    //    else if (key[i]=='G') sum = sum + (keta << 1) + keta;
    //    else if (key[i]=='T') sum = sum + (keta << 2);
    keta=keta*5;
  }
  return (sum);
}

void insert(const char *key2) {
  long key=encode(key2);
  long keta=key/8;
  dict[keta]=(dict[keta]|(1<<(key%8)));
}

int find_h(const char *key2) {
  long key=encode(key2);
  return (dict[key/8] & 1<<(key%8));
}

int main(void) {
  long n,i;
  word['A'] = 1;
  word['C'] = 2;
  word['G'] = 3;
  word['T'] = 4;
  scanf("%ld\n",&n);
  for(i=0;i<n;i++){
    char cmd[8], str[14]; scanf("%s %s\n",cmd, str);
    if(cmd[0]=='i') {
      insert(str);
    }
    else {
      if(find_h(str)) printf("yes\n");
      else printf("no\n");
    }
  }
  return 0;
}

Measured memory_bytes: 1432
#include <bits/stdc++.h>
using namespace  std;
#define ll long long 
int main(){
    ll r , c ;
    cin >> r >> c ;
    char a[r+5][c+5];
    ll i , j ;
    for ( i = 0 ; i < r ; i++ ){
        for ( j = 0 ; j < c ; j++){
            cin >> a[i][j] ;
        }
    }
    
    for ( i = -1 ; i < r + 1 ; i++ ){
        for ( j = -1 ; j < c + 1 ; j++ ){
            if ( i == -1 || i == r  || j == -1 || j == c  ){
                cout << "#" ;
            }
            else cout << a[i][j] ;
        }cout << endl ;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  char b;
  cin >> b;
  if (b == 'A') puts("T");
  else if (b == 'T') puts("A");
  else if (b == 'C') puts("G");
  else puts("C");
}

Measured memory_bytes: 256
#define FOR(i,j,n) for (int i=(j);i<(n);i++)
#define REP(i,n) for (int i=0;i<(n);i++)
#define REPN(i,n) for (int i=(n);i>=0;i--)
#define I(n) scanf("%d", &(n))
#define LL(n) scanf("%lld", &(n))
#define pb(n) push_back((n))
#define mp(i,j) make_pair((i),(j))
#include <bits/stdc++.h>
using namespace std;

//------------------------------typedef集
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
typedef vector<vi> vvi;
typedef vector<vpi> vvpi;
typedef vector<vvi> vvvi;

int k,a[100001],maxa;
long long mini,maxi,hit,tmp,gmtmp;

long long game(long long t){
    REP(i,k) t = t/a[i]*a[i];
    return t;
}

int main(){
    I(k);
    REP(i,k) {
        I(a[i]);
        if (maxa < a[i]) maxa = a[i];
    }
    maxi = (long long) maxa * k + 2;
    while(1){
        tmp = (mini+maxi)/2;
        gmtmp = game(tmp);
        if (gmtmp > 2){
            maxi = tmp;
        } else if (gmtmp < 2){
            mini = tmp;
        } else {
            hit = tmp;
            break;
        }

        if (maxi - mini <= 1){
            cout << "-1\n";
            return 0;
        }
    }

    while(maxi - hit > 1){
        tmp = (hit+maxi)/2;
        gmtmp = game(tmp);
        if (gmtmp > 2){
            maxi = tmp;
        } else {
            hit = tmp;
        }
    }

    while (hit - mini > 1){
        tmp = (hit+mini)/2;
        gmtmp = game(tmp);
        if (gmtmp == 2){
            hit = tmp;
        } else {
            mini = tmp;
        }
    }

    cout << mini+1 << " " << maxi-1 << endl;
}


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

using namespace std;

long long n,w1,w[105],v[105];
long long f[105][100005];
 main()
{
    cin>>n>>w1;
    for (long long i=1;i<=n;i++) cin>>w[i]>>v[i];
    for (long long i=1;i<=w1;i++)
    {
        for (long long j=1;j<=n;j++)
        {
            if (i>=w[j]) f[j][i]=max(f[j-1][i],f[j-1][i-w[j]]+v[j]);
            else f[j][i]=f[j-1][i];
        }
    }
    cout<<f[n][w1];
    return 0;
}


Measured memory_bytes: 79360
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations
import sys
import bisect
import string
import math
import time
from fractions import gcd
#import random


def I(): return int(input())


def MI(): return map(int, input().split())


def MS(): return map(str, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


YN = ['Yes', 'No']
MOD = 10**9+7
inf = float('inf')
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)


# show_flg = False
show_flg = True


def main():
    N, L = MI()
    apples = [L + i - 1 for i in range(1, N+1)]
    apple_pie = sum(apples)
    apple_pie_n = []

    for i in range(N):
        tmp = 0
        for j in range(N):
            if j != i:
                tmp += apples[j]
        apple_pie_n.append((abs(apple_pie - tmp), i))

    apple_pie_n.sort()
    print(apple_pie - apples[apple_pie_n[0][1]])


if __name__ == '__main__':
    main()


Measured memory_bytes: 66284
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i,m,n) for(int (i)=(m);(i)<(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<vector<int>>d(N, vector<int>(N, INF));
	rep(i, 0, N)d[i][i] = 0;
	vector<pair<int,int>>edge;
	vector<int>cost;
	rep(i, 0, M) {
		int a, b, c; cin >> a >> b >> c;
		--a; --b;
		d[a][b] = c;
		d[b][a] = c;
		edge.push_back({ a,b });
		cost.push_back(c);
	}
	rep(k, 0, N) {
		rep(i, 0, N) {
			rep(j, 0, N) {
				d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
			}
		}
	}
	int ans = M;
	rep(i, 0, M) {
		bool ok = false;
		rep(j, 0, N) {
			int x = edge[i].first, y = edge[i].second;
			if (d[j][x] + cost[i] == d[j][y])ok = true;
		}
		if (ok)ans--;
	}
	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

struct TopologicalSort{
  vector< set<int> > G;
  vector<int> used,indeg,ps;

  TopologicalSort(){}
  TopologicalSort(int n):G(n),used(n,0),indeg(n,0){}

  void add_edge(int s,int t){
    G[s].emplace(t);
    indeg[t]++;
  }

  void bfs(int s){
    queue<int> que;
    que.emplace(s);
    used[s]=1;
    while(!que.empty()){
      int v=que.front();que.pop();
      ps.emplace_back(v);
      for(int u:G[v]){
        indeg[u]--;
        if(indeg[u]==0&&!used[u]){
          used[u]=1;
          que.emplace(u);
        }
      }
    }
  }

  vector<int> build(){
    int n=G.size();
    for(int i=0;i<n;i++)
      if(indeg[i]==0&&!used[i]) bfs(i);
    return ps;
  }
};

//INSERT ABOVE HERE
signed main(){
  string s;
  cin>>s;
  int n=s.size()+1;

  TopologicalSort G(n);
  for(int i=0;i+1<n;i++){
    if(s[i]=='>') G.add_edge(i+1,i);
    if(s[i]=='<') G.add_edge(i,i+1);
  }
  auto ord=G.build();

  vector<int> dp(n,0);
  for(int v:ord)
    for(int u:G.G[v])
      chmax(dp[u],dp[v]+1);

  cout<<accumulate(dp.begin(),dp.end(),0LL)<<endl;
  return 0;
}


Measured memory_bytes: 57592
using namespace std;
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cfloat>
#include <iomanip>
#define all(x) (x).begin(),(x).end()

void solve(){

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

    double sum = 0;
    for (int i = 0; i < n; i++){
        sum += a[i];
    }
    double mean = sum / n;
    double min_width = 200.0;
    int min_num;

    for (int i = 0; i < n; i++){
        if (abs(a[i] - mean) < min_width ){
            min_num = i;
            min_width = abs(a[i] - mean);
        }
    }
    cout << min_num << endl;
    return 0;
}


Measured memory_bytes: 256
def scc_decomposition(G):
    n = len(G)
    G_rev = [[] for _ in range(n)]
    for u in range(n):
        for v in G[u]:
            G_rev[v].append(u)

    # dfs
    vs = []
    visited = [False] * n
    used = [False] * n
    for u in range(n):
        if visited[u]:
            continue
        stack = [u]
        while stack:
            v = stack.pop()
            if used[v]:
                continue
            if not visited[v]:
                visited[v] = True
            else:
                vs.append(v)
                used[v] = True
                continue
            stack.append(v)
            for c in G[v]:
                if not visited[c]:
                    stack.append(c)

    # reverse dfs
    visited = [False] * n
    component = [-1] * n
    for i, u in enumerate(vs[::-1]):
        if visited[u]:
            continue
        stack = [u]
        while stack:
            v = stack.pop()
            visited[v] = True
            component[v] = i
            for c in G_rev[v]:
                if not visited[c]:
                    stack.append(c)

    return component

class UnionFind:
    def __init__(self, N):
        self.parent = list(range(N))
        self.rank = [0] * N
        self.size = [1] * N

    def find(self, x):
        r = x
        while self.parent[r] != r:
            r = self.parent[r]
        while self.parent[x] != r:
            x, self.parent[x] = self.parent[x], r
        return r

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.rank[x] < self.rank[y]:
            self.parent[x] = y
            self.size[y] += self.size[x]
        else:
            self.parent[y] = x
            self.size[x] += self.size[y]
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def get_size(self, x):
        return self.size[self.find(x)]

V, E = map(int, input().split())
G = [[] for _ in range(V)]
for _ in range(E):
    s, t = map(int, input().split())
    G[s].append(t)
component = scc_decomposition(G)
uf = UnionFind(2 * V)
for v in range(V):
    uf.unite(v, V + component[v])
Q = int(input())
for _ in range(Q):
    u, v = map(int, input().split())
    if uf.same(u, v):
        print(1)
    else:
        print(0)


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

int calc(int i, int j, int op) {
  if (op == 0) {
    return i + j;
  } else {
    return i - j;
  }
}

int main() {

  string input;
  cin >> input;
  int a = input[0] - '0';
  int b = input[1] - '0';
  int c = input[2] - '0';
  int d = input[3] - '0';

  char op1, op2, op3;

  for (int i = 0; i < 2; i++) {
    for (int j = 0; j < 2; j++) {
      for (int k = 0; k < 2; k++) {
        int tmp = 0;

        tmp = calc(a, b, i);
        tmp = calc(tmp, c, j);
        tmp = calc(tmp, d, k);

        if (tmp == 7) {
          op1 = (i == 0) ? '+' : '-';
          op2 = (j == 0) ? '+' : '-';
          op3 = (k == 0) ? '+' : '-';
          printf("%d%c%d%c%d%c%d=7\n",a,op1,b,op2,c,op3,d);
          return 0;
        }

      }
    }
  }
}

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

#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define for1(i, n) for (int i = 1; i <= int(n); ++i)
#define fore(i, l, r) for (int i = int(l); i <= int(r); ++i)
#define ford(i, n) for (int i = int(n)-1; i >= 0; --i)
#define pb push_back
#define eb emplace_back
#define ms(a, x) memset(a, x, sizeof(a))
#define F first
#define S second
#define endl '\n'
#define all(x) (x).begin(),(x).end()

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 0x3f3f3f3f;
mt19937 gen(chrono::high_resolution_clock::now().time_since_epoch().count());

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
	int ans=0;
    ll n;
    cin>>n;
    ll x=n-1;
    ll cc=1;
    for(ll f=2;f*f<=x;f++){
        if(x%f==0){
            int cnt=0;
            while(x%f==0){
                cnt++;
                x/=f;
            }
            cc*=cnt+1;
        }
    }
    if(x>1) cc*=2;
    ans+=cc;
    for(ll f=2;f*f<=n;f++){
        if(n%f==0){
            ll tmp=n;
            while(tmp%f==0) tmp/=f;
            if((tmp)%f==1) ans++;
        }
    }
    cout<<ans;
    return 0;
}



Measured memory_bytes: 256
#include "bits/stdc++.h"
#define ll long long
#define ALL(x) x.begin(),x.end()
#define MOD 1000000007
using namespace std;

int main(){
  ll N,K;
  cin>>N>>K;
  vector<ll> A(N);

for(ll i=0;i<N;i++){
  cin>>A[i];
}
vector<ll> c(N,0);
for(ll i=0;i<N;i++){
  for(ll j=i+1;j<N;j++){
    if(A[i]>A[j]){
      c[i]++;
    }
  }
}

vector<ll> cc(N,0);
for(ll i=0;i<N;i++){
  for(ll j=0;j<N;j++){
    if(A[i]>A[j]){
      cc[i]++;
    }
  }
}

ll ans=0;
ll tmp,tmp1;

if(K%2==0){
  tmp=K/2;
  tmp1=K-1;
}
else{
  tmp=(K-1)/2;
  tmp1=K;
}

for(ll i=0;i<N;i++){

ans += (((cc[i]*tmp1)%MOD)*tmp)%MOD+(c[i]*K)%MOD;
ans%=MOD;
}





cout<<ans%MOD<<endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define x first
#define y second
#define ndl '\n'
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define up_b upper_bound
#define low_b lower_bound
#define sz(x) (int)x.size()
#define bit __builtin_popcount
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

using namespace std;
using namespace __gnu_pbds;

template<typename T> using indexed_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<int, ull> piu;
typedef vector<vector<int>> matrix;

const ll INF = 1e18 + 123;
const ld EPS = 1e-9;
const int inf = 1e9 + 123;
const int MOD = 1e9 + 7;
const int N = 5e5 + 123;
const int M = 1e6 + 123;
const double pi = acos(-1.0);
const int dx[] = {0, 0, 1, -1};
const int dy[] = {1, -1, 0, 0};

int c[3];

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    string s;
    int k;
    cin >> s >> k;
    int n = sz(s);
    string t = s+s+s;
    int e = 0;
    for (int i = 1; i < n+n+n; i++){
        if (t[i] == t[i-1]){
            t[i] = e++;
            if (e == 'a'){
                e = 'z'+1;
            }
            c[i/n]++;
        }
    }
    ll ans = c[0];
    k--;
    if (!k){
        cout << ans;
        return 0;
    }
    k--;
    ans += 1ll * (k+1)/2 * c[1];
    ans += 1ll * k/2 * c[2];
    if (k&1){
        t += s;
        for (int i = sz(t) - n; i < sz(t); i++){
            if (t[i] == t[i-1]){
                t[i] = e++;
            }
        }
        t += s;
    }
    else{
        t += s;
    }
    for (int i = sz(t) - n; i < sz(t); i++){
        if (t[i] == t[i-1]){
            i++;
            ans++;
        }
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<queue>
#include<algorithm>
#define maxn 100005
#define LL long long
#define INF (LL)1e16
using namespace std;
int x,y,z,n;
LL sau[maxn],sag[maxn],scu,ans=-INF;
struct node { int a,b,c; } a[maxn];
bool cmp(node p,node q) { return p.a-p.b<q.a-q.b; }
priority_queue<int,vector<int>,greater<int> > au,ag;
int main()
{
	scanf("%d%d%d",&x,&y,&z); n=x+y+z;
	for(int i=1;i<=n;i++) 
	{
		scanf("%d%d%d",&a[i].a,&a[i].b,&a[i].c);
		a[i].a-=a[i].c,a[i].b-=a[i].c;
	}
	sort(a+1,a+n+1,cmp);
	for(int i=n;i;i--)
	{
		sau[i]=sau[i+1]+1ll*a[i].a;
		au.push(a[i].a);
		if(au.size()>x) { sau[i]-=au.top(); au.pop(); }
	}
	for(int i=1;i<=n;i++)
	{
		sag[i]=sag[i-1]+1ll*a[i].b;
		ag.push(a[i].b);
		if(ag.size()>y) { sag[i]-=ag.top(); ag.pop(); }
	}
	for(int i=1;i<=n;i++) scu+=1ll*a[i].c;
	for(int i=y;i<=n-x;i++) ans=max(ans,sau[i+1]+sag[i]);
	printf("%lld\n",ans+scu);
}


Measured memory_bytes: 3456
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define REP(i,n) for(int i=(0);i<(n);i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;

template<class T> inline void read(T &x){
	int f=0;x=0;char ch=getchar();
	for(;!isdigit(ch);ch=getchar())f|=(ch=='-');
	for(;isdigit(ch);ch=getchar())x=x*10+ch-'0';
	if(f)x=-x;
}

const int N=100005;
struct node{
	ll d; int sz,id;
	friend bool operator < (node a,node b){
		return a.d<b.d;
	}
};
set<node> s;
vector<pii> ans;
int d[N],n;
ll rem;
vi e[N];

void dfs(int u,int fa){
	for(auto v:e[u])
		if(v!=fa){
			d[v]=d[u]+1;
			dfs(v,u);
		}
	rem-=d[u];
}

int main(){
	read(n);	
	rep(i,1,n){
		ll tmp; read(tmp);
		s.insert((node){tmp,1,i});
	}
	while(s.size()>=2){
		node t=*(--s.end());
		s.erase(--s.end());
		set<node>::iterator it=s.lower_bound((node){t.d-n+2*t.sz,0});
		if(it==s.end()||it->d!=t.d-n+2*t.sz)
			return puts("-1"),0;
		int x=t.id,y=it->id;
		if(x>y)swap(x,y);
		ans.pb(mp(x,y));
		node v=*it;
		v.sz+=t.sz;
		s.erase(it);
		s.insert(v);
	}
	for(auto x:ans)
		e[x.fi].pb(x.se),e[x.se].pb(x.fi);
	int rt=s.begin()->id;
	rem=s.begin()->d;
	dfs(rt,0);
	if(rem!=0)return puts("-1"),0;
	sort(ans.begin(),ans.end());
	for(auto x:ans)
		printf("%d %d\n",x.fi,x.se);
	return 0;
}

Measured memory_bytes: 13688
<?php
$input = explode(' ', trim(fgets(STDIN)));;

$n = (int)$input[0];
$a = (int)$input[1];
$b = (int)$input[2];
$hs = [];
for ($i=0; $i < $n; $i++) { 
	$hs[] = (int)trim(fgets(STDIN));
}
rsort($hs);

$left = 0;
$right = $n * 1000000000;
$min = $right;
while ($left < $right) {
	$mid = (int)floor(($left + $right) / 2);
	$e = evaluate($hs,$a,$b,$mid);
	if ($e < $n) {
		$left = $mid+1;
	}else{
		$right = $mid;
		$min = min($min, $mid);
	}
	// echo 'l:' . $left . ' r:' . $right . ' mid:' . $mid . ' e:' . $e . PHP_EOL;
}
echo $min;



function evaluate($hs, $a, $b, $p){
	$a_count = 0;
	$b_count = 0;
	$kill = 0;
	$base_damage = $b * $p;
	$add_damage = $a-$b;
	foreach ($hs as $h) {
		if ($h <= $base_damage) {
			++$b_count;
			++$kill;
		}else{
			$need = (int)ceil(($h-$base_damage) / $add_damage);
			if ($a_count + $need <= $p) {
				++$kill;
				$a_count += $need;
			}else{
				break;
			}
		}
	}
	// echo 'a_count:' . $a_count . ' b_count' . $b_count . PHP_EOL;
	return $kill;
}

Measured memory_bytes: 10744
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<long long,long long>
#define mod 1000000007
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);

ll power(ll a,ll b){
	ll ans=1;
	while(b>0){
		if(b%2!=0){
			ans=(ans*a)%mod;
		}
		a=(a*a)%mod;
		b>>=1;
	}
	return ans;
}
bool palin(string s){
	int i=0,j=s.size()-1;
	while(i<j){
		if(s[i]!=s[j])
		return false;
		i++;
		j--;
	}
	return true;
}

int main() {
	IOS;
	int t=1;
	//cin>>t;
	while(t--){
		string s;
		cin>>s;
		if(palin(s)==false){
			cout<<"No";
			return 0;
		}
		string t;
		int n=s.size();
		for(int i=0;i<(n-1)/2;i++){
			t+=s[i];
		}
		if(palin(t)==false){
			cout<<"No";
			return 0;
		}
		t="";
		for(int i=((n+3)/2)-1;i<n;i++)
		t+=s[i];
		
		if(palin(t)==false){
			cout<<"No";
			return 0;
		}
		cout<<"Yes";
	}
	return 0;
}

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int vector_finder(std::vector<ll> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

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

int main() {
  int H, W; cin >> H >> W;
  vector<string> s(H); REP(i, H) cin >> s[i];
  string ans = "Yes";
  for(int i = 0; i < H; ++i) {
    for(int k = 0; k < W; ++k) {
      if(s[i][k] == '#') {
        for(int m = 0; m < 4; ++m) {
          if(i <= 0 || k <= 0 || i >= H - 1 || k >= W - 1) continue;
          if(s[i + dx[m]][k + dy[m]] == '#') break;
          if(m == 3) ans = "No";
        }
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define printV(v) for(auto&& x : v){cout << x << " ";} cout << endl
#define printVV(vv) for(auto&& v : vv){for(auto&& x : v){cout << x << " ";}cout << endl;}
#define printP(p) cout << p.first << " " << p.second << endl
#define printVP(vp) for(auto&& p : vp) printP(p);

typedef long long ll;
typedef pair<int, int> Pii;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<Pii> vp;
const int inf = 1e9;
const int mod = 1e9 + 7;

#define dame cout << "Impossible" << endl; return 0
#define ok cout << "Possible" << endl; return 0

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

    int n;
    cin >> n;
    vi a(n);
    rep(i, n) cin >> a[i];

    vi cnt(n + 1);
    rep(i, n) {
        cnt[a[i]]++;
    }

    int mi = *min_element(all(a));
    int ma = *max_element(all(a));
    if (mi * 2 < ma) {
        dame;
    }

    if (ma % 2 == 1 && cnt[mi] != 2) {
        dame;
    }
    if (ma % 2 == 0 && cnt[mi] != 1) {
        dame;
    }

    rep2(i, mi + 1, ma + 1) {
        if (cnt[i] < 2) {
            dame;
        }
    }

    ok;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair

using namespace std;

const int INF = 2000000000;
const double pi = 3.1415926;
const int base = 1000000007;

int n, k, ans;


int main()
{
    //ifstream cin ("sysadmin.in");
    //ofstream cout ("sysadmin.out");
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cout.precision(20);
    cin >> n >> k;
    while (n > 0)
    {
        ans++;
        n /= k;
    }
    cout << ans;
    return 0;
}


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

using namespace std;

int w,h;
int sum;
vector<string> tile(20);

void search(int x,int y);

int main(){

  int now_x,now_y;
  
  while(1){

	sum=0;
	cin>>w>>h;

	if(w==0 && h==0)
	  break;

	tile.clear();

	for(int i=0;i<h;++i)
	  cin>>tile[i];
		
	for(int i=0;i<h;++i){
	  for(int j=0;j<w;++j){
		if(tile[i][j]=='@'){
		  now_x=j;
		  now_y=i;
		  break;
		}
	  }
	}
	
	search(now_x,now_y);
	cout<<sum<<endl;
	
  }

  return 0;
  
}
  
void search(int x,int y){

  int i;
  tile[y][x]='#';
  sum++;
  
  if(x+1 < w){
	if(tile[y][x+1]=='.')
	  search(x+1,y);
  }
  
  if(x-1 >= 0){
	if(tile[y][x-1]=='.')
	  search(x-1,y);
  }
  
  if(y+1 < h){
	if(tile[y+1][x]=='.')
	  search(x,y+1);
  }
  
  if(y-1 >= 0){
	if(tile[y-1][x]=='.')
	  search(x,y-1);
  }
  
}



Measured memory_bytes: 3124
#include<bits/stdc++.h>
using namespace std;
int main(){
    int A,B,C,D=1;
  cin >> A >>B >> C;
  if(A==B){
    if(A==C){
      cout << "Yes" << endl;
      D=0;
    }
  }
  if(D)cout << "No" << endl;
}


Measured memory_bytes: 256
/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		Scanner scanner = new Scanner(System.in);
		
		long x = scanner.nextInt();
		long y = scanner.nextInt();
		
		/*
		long a;
		while (x % y != 0) {
			a = x;
			x = y;
			y = a % y;
			
		}
		System.out.println(y);
		*/
		
		long result = getGcd(x, y);
		
		System.out.println(result);
	}
	
	static long getGcd(long x, long y) {
		long a;
		//System.out.println(x + "," + y);
		// 終了条件
		if (x % y == 0) {
			return y;
		}
		// 引数を再設定
		a = x;
		x = y;
		y = a % y;
		
		// 再実行
		return getGcd(x, y);
	}
}


Measured memory_bytes: 26152
#include<iostream>
using namespace std;
#define df 0
#define rep(i,n) for(int i=0;i<(n);i++)
#define repa(i,a,n) for(int i=(a);i<(n);i++)
typedef long int li;

int main(){
  if(df) printf("*debug mode*\n");
  int n;string s; cin >>n >>s;
  int cnt=0;
  rep(i,n-2){
    if(s.at(i)=='A' and s.at(i+1)=='B' and s.at(i+2)=='C')
      cnt++;
  }
  cout << cnt;
}

/// confirm df==0 ///


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
const int MAXN = 1e5 + 5;
typedef long long ll;
 
ll xL[MAXN], xR[MAXN], C, preL[MAXN], preR[MAXN], mxL[MAXN], mxR[MAXN];
int vL[MAXN], vR[MAXN], N;
 
int main(){
	scanf("%d %lld", &N, &C);
	for(int i=1; i<=N; ++i){
		scanf("%lld %d", &xL[i], &vL[i]);
		xR[N - i + 1] = C - xL[i];
		vR[N - i + 1] = vL[i];
	}
	for(int i=1; i<=N; ++i) preL[i] = preL[i - 1] - xL[i] + xL[i - 1] + vL[i];
	for(int i=1; i<=N; ++i) preR[i] = preR[i - 1] - xR[i] + xR[i - 1] + vR[i];
	for(int i=1; i<=N; ++i) mxR[i] = max(mxR[i - 1], preR[i]);
	for(int i=1; i<=N; ++i) mxL[i] = max(mxL[i - 1], preL[i]);
	ll best = 0;
	for(int L=0; L<=N; ++L){
		ll cur = preL[L];
		if(cur > best) best = cur;
		cur = cur - xL[L] + mxR[N - L];
		if(cur > best) best = cur;
	}
	for(int R=0; R<=N; ++R){
		ll cur = preR[R];
		if(cur > best) best = cur;
		cur = cur - xR[R] + mxL[N - R];
		if(cur > best) best = cur;
	}
	printf("%lld\n", best);
	return 0;
}

Measured memory_bytes: 9288
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cassert>
#include <bitset>

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

//std::cout << std::fixed << std::setprecision(10)
//std::ios::sync_with_stdio(false);
constexpr long long MOD = 1000000007;

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

int solve(int K)
{
  if(K < 10)
  {
    std::cout << K << std::endl;
    return 0;
  }
  std::vector<std::vector<long long>> prev(10);
  for(int i = 0; i < prev.size(); ++i)
    prev[i].push_back(i);
  int cnt = 9;
  long long pow = 10;
  while(true)
  {
    std::vector<std::vector<long long>> nexts(10);
    {
      std::vector<long long> next;
      next.reserve(prev[0].size() + prev[1].size());
      for(auto val: prev[0])
        next.push_back(val);
      for(auto val: prev[1])
        next.push_back(val);
      nexts[0] = std::move(next);
    }
    for(int i = 1; i < 9; ++i)
    {
      std::vector<long long> next;
      next.reserve(prev[i - 1].size() + prev[i].size() + prev[i + 1].size());
      for(auto val: prev[i - 1])
      {
        next.push_back(pow * i + val);
        ++cnt;
        if(cnt == K)
        {
          std::cout << next.back() << std::endl;
          return 0;
        }
      }
      for(auto val: prev[i])
      {
        next.push_back(pow * i + val);
        ++cnt;
        if(cnt == K)
        {
          std::cout << next.back() << std::endl;
          return 0;
        }
      }
      for(auto val: prev[i + 1])
      {
        next.push_back(pow * i + val);
        ++cnt;
        if(cnt == K)
        {
          std::cout << next.back() << std::endl;
          return 0;
        }
      }
      nexts[i] = std::move(next);
    }
    {
      std::vector<long long> next;
      next.reserve(prev[8].size() + prev[9].size());
      for(auto& val: prev[8])
      {
        next.push_back(pow * 9  + val);
        ++cnt;
        if(cnt == K)
        {
          std::cout << next.back() << std::endl;
          return 0;
        }
      }
      for(auto& val: prev[9])
      {
        next.push_back(pow * 9 + val);
        ++cnt;
        if(cnt == K)
        {
          std::cout << next.back() << std::endl;
          return 0;
        }
      }
      nexts.back() = std::move(next);
    }
    prev.swap(nexts);
    pow *= 10;
  }
  return 0;
}

int main()
{
  int K;
  std::cin >> K;
  solve(K);
  return 0;
}



Measured memory_bytes: 4140
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;

//WA

ll N,K,a[5010],ans=0;
bool dp[5010],dp2[5010];

bool can(int x){
	reg(i,0,K)dp[i]=false;
	dp[0]=true;
	reg(i,1,N){//i枚目までで
		if(i==x)continue;//midは使わない
		reg(j,0,K)dp2[j]=false;
		reg(j,0,K){
			if(dp[j]){
				dp2[j]=true;
				if(j+a[i]<=K)dp2[j+a[i]]=true;
			}
		}
		reg(j,0,K)dp[j]=dp2[j];
	}
	bool ok=true;//不要
	int begin = 0;
	if(begin<K-a[x])begin = K-a[x];
	reg(i,begin,K-1){
		if(dp[i]){//条件を満たすような和が１つでもあれば
			ok=false;//必要
			break;
		}
	}
	return ok;
}

int main(void){
	cin>>N>>K;
	reg(i,1,N)cin>>a[i];
	sort(a,a+N+1);
	if(can(N)){
		printf("%lld\n",N);
	}else if(!can(1)){
		printf("%lld\n",0);
	}else{
		ll l=1,r=N;
		while(r-l>1){
			ll mid = (r+l)/2;
			if(can(mid)){
				l=mid;//不要
			}else{
				r=mid;
			}
		}
		if(can(r)){
			printf("%lld\n",r);
		}else{
			printf("%lld\n",l);
		}
	}
	// rep(i,N)if(can(i))ans++;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
	public static void main(String arge[]){
    	Scanner scan = new Scanner(System.in);
      	int i= scan.nextInt();
      String[] a;
      a = new String[i];
      String ans="Three";
      
      for(int j=0;j<i;j++){
      	a[j]=scan.next();
        if(a[j].equals("Y")){
        ans="Four";
        }
      }
      System.out.print(ans);
      
    }
}


Measured memory_bytes: 21588
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> VI;

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()

int main() {
    int h, w, k;
    cin >> h >> w >> k;
    vector<vector<int>> g(h, vector<int>(w));
    int ctr = 0;
    rep (i, h) {
        string s;
        cin >> s;
        rep (j, w) {
            if (s[j] == '#') {
                g[i][j] = ++ctr;
            } else {
                g[i][j] = 0;
            }
        }
    }
    rep (i, h) {
        rep (j, 1, w) {
            if(g[i][j] == 0) {
                g[i][j] = g[i][j-1];
            }
        }
    }
    rep (i, h) {
        for(int j = w - 2; j >= 0; j--) {
            if(g[i][j] == 0) {
                g[i][j] = g[i][j+1];
            }
        }
    }
    rep (i, 1, h) {
        rep (j, w) {
            if(g[i][j] == 0) {
                g[i][j] = g[i-1][j];
            }
        }
    }
    for (int i = h - 2; i >= 0; i--) {
        rep (j, w) {
            if(g[i][j] == 0) {
                g[i][j] = g[i+1][j];
            }
        }
    }
    rep (i, h) {
        rep (j, w) {
            if(j) cout << " ";
            cout << g[i][j];
        }
        cout << endl;
    }
}

Measured memory_bytes: 1152
def revPoland(expr):
    stack = []

    for l in expr:
        if l.isdigit():
            stack.append(int(l))
            # print(stack)
        else:
            a = stack.pop()
            b = stack.pop()
            c = eval(str(b) + l + str(a))
            stack.append(c)
            # print(stack)

    return stack.pop()

expr = input().split()

print(revPoland(expr))

Measured memory_bytes: 7724
use std::io::stdin;
use std::str::FromStr;

fn main(){
    let (a, b, t): (i64, i64, i64) = get_triple();
    let z = t / a;
    println!("{}", z * b);
}

#[allow(dead_code)]
fn get_line() -> String {
    let mut s = String::new();
    match stdin().read_line(&mut s){
        Ok(_) => {s.trim().to_string()}
        Err(_) => String::new()
    }
}

#[allow(dead_code)]
fn get_vec<T: std::str::FromStr>() -> Vec<T> {
    let line = get_line();
    line.split_whitespace().filter_map(|x| x.parse().ok()).collect()
}

#[allow(dead_code)]
fn get_one<T: FromStr + Copy>() -> T {
    let v = get_vec();
    v[0]
}

#[allow(dead_code)]
fn get_pair<T: FromStr + Copy>() -> (T, T) {
    let v = get_vec();
    (v[0], v[1])
}

#[allow(dead_code)]
fn get_triple<T: FromStr + Copy>() -> (T, T, T) {
    let v = get_vec();
    (v[0], v[1], v[2])
}

#[allow(dead_code)]
fn get_chars() -> Vec<char> {
    get_line().chars().collect()
}


Measured memory_bytes: 4352
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

n = inn()
a = inl()

cnt = 0
while max(a)>n-1:
    sm = 0
    for i in range(n):
        j = a[i]//n
        a[i] -= j*(n+1)
        sm += j
    a = [x+sm for x in a]
    cnt += sm
#
print(cnt)
#ddprint(foo(0))
#ddprint(foo(1))


Measured memory_bytes: 41436
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdlib>
using namespace std;
#define INF 1e9

static const int seed=6;
static const int D=365;
static const int ntype=26;
static int ans[D+1];
static int max_score=-INF;
static int t=120000;
class Contest{
public:
    Contest(){
        last=0;
    }
    int s[D+1];
    int c;
    int last;
};

static Contest contest[ntype+1];

void Input(){
    int d;
    cin>>d;
    for(int i=1;i<=ntype;++i){
        int t;
        cin>>t;
        contest[i].c=t;
    }
    for(int day=1;day<=D;++day){
        for(int type=1;type<=ntype;++type){
            int t;
            cin>>t;
            contest[type].s[day]=t;
        }
    }
}

int evaluate(){
    int sum=0;
    vector<int> l(ntype+1,0);
    for(int day=1;day<=D;++day){
        int type=ans[day];
        sum+=contest[type].s[day];
        l[type]=day;
        for(int t=1;t<=ntype;++t){
            sum-=contest[t].c*(day-l[t]);
        }
    }
    return sum;   
}

void Output(){
    for(int d=1;d<=D;++d) cout<<ans[d]<<endl;
}

void Init(){
    for(int d=1;d<=D;++d) ans[d]=rand()%ntype+1;
}

void Greedy(){
    vector<int> l(ntype+1,0);
    int score=0;
    for(int d=1;d<=D;++d){
        for(int i=1;i<=ntype;++i) score-=contest[i].c*(d-l[i]);
        int temp=score;
        int t=-1;
        for(int i=1;i<=ntype;++i){
            int k=contest[i].s[d]+contest[i].c*(d-l[i])+score;
            if(k>temp){
                temp=k;
                t=i;
            }
        }
        ans[d]=t;
        l[t]=d;
    }
}

void change(){
    int p=rand()%D+1;
    int temp=ans[p];
    ans[p]=rand()%ntype+1;
    int temp_score=evaluate();
    if(max_score<temp_score) max_score=temp_score;
    else ans[p]=temp;
}

void swap(){
    int p1=rand()%D+1;
    int p2=rand()%D+1;
    while(p1==p2) p2=rand()%D+1;
    int temp=ans[p1];
    ans[p1]=ans[p2];
    ans[p2]=temp;
    int temp_score=evaluate();
    if(max_score<temp_score) max_score=temp_score;
    else{
        ans[p2]=ans[p1];
        ans[p1]=temp;
    }
}

void solve(int times){
    max_score=evaluate();
    for(int i=0;i<times;++i){
        swap();
        change();
    }
}

int main(){
    srand(seed);
    Input();
    Greedy();
    solve(t);
    Output();
}


Measured memory_bytes: 3652
//
// Created by yamunaku on 2019/08/30.
//

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repl(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perl(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD9 998244353
#define MOD1 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)
#define CST(x) cout<<fixed<<setprecision(x)

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> mti;
typedef vector<ll> vl;
typedef vector<vector<ll>> mtl;

int main(){
    int n, m;
    cin >> n >> m;
    vector<pair<int, int>> p(n);
    rep(i, n) cin >> p[i].first >> p[i].second;
    sort(all(p), [](pair<int, int> &l, pair<int, int> &r){
        return l.first > r.first;
    });
    int i=0, ls=0;
    priority_queue<int> q;
    for(int li = m; li >= 1; li--){
        while(i < n){
            if(p[i].first < li) break;
            q.push(p[i].second);
            i++;
        }
        if(!q.empty()){
            q.pop();
            ls++;
        }
    }
    while(!q.empty()) q.pop();
    i = 0;
    for(int li = ls; li >= 1; li--){
        while(i < n){
            if(p[i].first < li) break;
            q.push(p[i].second);
            i++;
        }
        q.pop();
    }
    for(; i < n; i++){
        q.push(p[i].second);
    }
    priority_queue<int> r;
    while(!q.empty()){
        r.push(-q.top());
        q.pop();
    }
    int rs = 0;
    for(int j = ls + 1; j <= m; j++){
        if(r.empty()) break;
        if(j >= -r.top()){
            rs++;
            r.pop();
        }
    }
    cout << n - ls - rs << endl;
    return 0;
}


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

int main() {
  int n,k;
  cin>>n>>k;
  int kotae=1;
  for(int i=0;i<n;i++){
    kotae=min(kotae*2,kotae+k);
  }
  cout<<kotae<<endl;
  return 0;
}


Measured memory_bytes: 256
#1問目
N = int(input())
maisuu = 0
while N - 1000 * maisuu >= 1000:
    maisuu += 1
if(N - 1000 * maisuu == 0):
    print(1000 * (maisuu) - N)
else:
    print(1000 * (maisuu+1) - N)

Measured memory_bytes: 61760