akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(int i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define si(x)	scanf("%d",&x)
#define sl(x)	scanf("%lld",&x)
#define ss(s)	scanf("%s",s)
#define pi(x)	printf("%d\n",x)
#define pl(x)	printf("%lld\n",x)
#define ps(s)	printf("%s\n",s)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define wi(t) int t;cin>>t;while(t--)
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pl;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<pii>		vpii;
typedef vector<pl>		vpl;
typedef vector<vi>		vvi;
typedef vector<vl>		vvl;
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim) {
	uniform_int_distribution<int> uid(0,lim-1);
	return uid(rang);
}
int mpow(int base, int exp); 
void ipgraph(int n, int m);
void dfs(int u, int par);

const int mod = 1000000007;
const int N = 3e5, M = N;
//=======================

vi g[N];
int a[N];

void solve()
    {
  
  int n;
  cin>>n;
  map<string,int> m;
   while(n--)
   {
       string s;
       cin>>s;
       m[s]++;
   }
   cout<<"AC x "<<m["AC"]<<endl;
   cout<<"WA x "<<m["WA"]<<endl;
   cout<<"TLE x "<<m["TLE"]<<endl;
   cout<<"RE x "<<m["RE"]<<endl;
  
  
    }

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());

   // wi(t)
    {
      solve();
    }

    return 0;
}

int mpow(int base, int exp) {
  base %= mod;
  int result = 1;
  while (exp > 0) {
    if (exp & 1) result = ((ll)result * base) % mod;
    base = ((ll)base * base) % mod;
    exp >>= 1;
  }
  return result;
}

void ipgraph(int n, int m){
	int i, u, v;
	while(m--){
		cin>>u>>v;
    u--, v--;
		g[u].pb(v);
		g[v].pb(u);
	}
}

void dfs(int u, int par){
	for(int v:g[u]){
		if (v == par) continue;
		dfs(v, u);
	}
}






Measured memory_bytes: 10700
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef double db;
#define go(u) for(int i = head[u], v = e[i].to; i; i=e[i].lst, v=e[i].to)
#define rep(i, a, b) for(int i = a; i <= b; ++i)
#define pb push_back
#define re(x) memset(x, 0, sizeof x)
inline int gi() {
	LL x = 0, f = 1; char ch = getchar();
	while(!isdigit(ch)) { if(ch == '-') f = -1; ch = getchar();}
	while(isdigit(ch)) { x = (x << 3) + (x << 1) + ch - 48; ch = getchar();}
	return x * f;
}
template <typename T> inline bool Max(T &a, T b){return a < b ? a = b, 1 : 0;}
template <typename T> inline bool Min(T &a, T b){return a > b ? a = b, 1 : 0;}
const int N = 1e5 + 7;
int n, ans;
int low[N], pri[N], pc, a[N];
void sieve(int n) {
	int to;
	rep(i, 2, n) {
		if(!low[i]) low[i] = i, pri[++pc] = i;
		for(int j = 1; j <= pc && (to = i * pri[j]) <= n; ++j) {
			low[to] = pri[j];
			if(i % pri[j] == 0) break;
		}
	}
}
map<LL, int> cnt;
int main() {
#ifndef ONLINE_JUDGE
//	freopen("data.in", "r", stdin);
#endif
	sieve(2159);
	n = gi();
	rep(i, 1, n) {
		LL x, now = 1, r = 1;
		scanf("%lld", &x);
		rep(j, 1, pc) if(x % pri[j] == 0) {
			int cnt = 0;
			while(x % pri[j] == 0) ++cnt, x /= pri[j];
			if(cnt % 3 == 1) now *= pri[j], r *= pri[j] * pri[j];
			if(cnt % 3 == 2) now *= pri[j] * pri[j], r *= pri[j];
		}
		if((LL) sqrt(x) * (LL) sqrt(x) == x)
			r *= (LL) sqrt(x);
		else 
			r *= x * x;
		++cnt[now *= x];
		if(now != 1 && cnt[now] > cnt[r]) ++ans;
	}
	if(cnt[1] >= 1) ans ++;
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 12800
#include <bits/stdc++.h>
using namespace std;
const int N = (int)1e7 + 10;
inline int read()
{
  int p=0; int f=1; char ch=getchar();
  while(ch<'0' || ch>'9'){if(ch=='-') f=-1; ch=getchar();}
  while(ch>='0' && ch<='9'){p=p*10+ch-'0'; ch=getchar();}
  return p*f;
}

int prime[N],pri; bool v[N];
void get_prime(int n)
{
  memset(v,1,sizeof(v)); v[0] = v[1] = 0; pri = 0;
  for(int i=2;i<=n;i++)
  {
    if(v[i]) prime[++pri] = i;
    for(int j=1;(j<=pri) && (i*prime[j] <= n);j++)
    {
      v[i*prime[j]] = 0;
      if(i%prime[j]==0) break;
    }
  }
  v[2] = 0;
}

struct node{int x,y,next;}edge[100010]; int len,first[N];
void ins(int x,int y){len++; edge[len].x=x; edge[len].y=y; edge[len].next=first[x]; first[x]=len;}

int n,a[N],b[N];


int chw[N],match[N];
bool dfs(int x)
{
  for(int k=first[x];k!=-1;k=edge[k].next)
  {
    int y=edge[k].y;
    if(!chw[y])
    {
      chw[y] = 1;
      if((match[y] == 0) || dfs(match[y])){match[y] = x; return 1;}
    }
  }
  return 0;
}

int main()
{

  get_prime(1e7+1);

  n = read(); len = 0; memset(first,-1,sizeof(first));
  for(int i=1;i<=n;i++) a[read()] = 1;
  for(int i=1;i<=(int)1e7+1;i++) b[i] = abs(a[i] - a[i-1]);
  for(int i=1;i<=(int)1e7+1;i++) a[i] = b[i];
  int blen = 0; for(int i=1;i<=(int)1e7+1;i++) if(a[i] == 1) b[++blen] = i;
  int c=0,d=0; for(int i=1;i<=blen;i++) if(b[i] & 1) c++; else d++;
  for(int i=1;i<=blen;i++) if(b[i] & 1) for(int j=1;j<=blen;j++) if(!(b[j]&1)) if(v[abs(b[i] - b[j])]) ins(i,j);
  int ans=0; for(int i=1;i<=blen;i++)
  {
    for(int j=1;j<=blen;j++) chw[j] = 0;
    if(dfs(i)) ans++;
  }
 
  c-=ans; d-=ans;
  ans += 2*(c/2 + d/2); c%=2; d%=2;
  if(c && d) ans+=3;

  return printf("%d\n",ans),0;
}

Measured memory_bytes: 133376
x, y = map(int, input().split())
if x < y:
    if x * y < 0:
        print(1 + abs(y-abs(x)))
    else:
        print(y-x)
else:
    if x * y <= 0:
        print(1+abs(x-abs(y)))
    else:
        print(2+ abs(x-y))



Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = a; i < b; ++i)
#define all(c) c.begin(), c.end()
#define gmax(x,y) x=max(x,y)
#define gmin(x,y) x=min(x,y)
using namespace std;

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

int main(){
	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio(0);
	int n;
	cin >> n;
	++n;
	vector<int> v(n);
	rep(i,0,n)cin >> v[i];
	sort(all(v));
	int gcd = 0;
	rep(i,0,n-1){
		gcd = __gcd(gcd,v[i+1] - v[i]);
	}
	cout << gcd << '\n';
}


Measured memory_bytes: 640
n = int(input())

a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

sc = 0
for i in range(len(a)):
    sc+=b[a[i] - 1]
    if (len(a) - 1)> i:
        if (a[i]+1) == a[i+1]:
            sc+=c[a[i] - 1]
print(sc)


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

const int mod = 1e9+7;

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

void add(long long &a, long long b){
    a += b;
    if(a >= mod) a-= mod;
}

long long solve(int N){
    auto dp = make_v<long long>(N+1, 5, 5, 5);
    dp[0][0][0][0] = 1;
    for(int n=0; n<N; n++){
        for(int i=0; i<5; i++){
            for(int j=0; j<5; j++){
                for(int k=0; k<5; k++){
                    for(int l=1; l<5; l++){
                        if(i==1&&j==2&&l==3) continue;
                        if(i==1&&k==2&&l==3) continue;
                        if(j==1&&k==2&&l==3) continue;
                        if(j==2&&k==1&&l==3) continue;
                        if(j==1&&k==3&&l==2) continue;
                        add(dp[n+1][j][k][l], dp[n][i][j][k]);
                    }
                }
            }
        }
    }
    long long res=0;
    for(int i=1; i<5; i++){
        for(int j=1; j<5; j++){
            for(int k=1; k<5; k++){
                add(res, dp[N][i][j][k]);
            }
        }
    }
    return res;
}



int main(){
    int N; cin >> N;
    cout << solve(N) << endl;
}


Measured memory_bytes: 384
import java.util.*;

class Main {
	Scanner sc = new Scanner(System.in);

	public void run() {
		int n=sc.nextInt();
		
		long res=1;
		while(n!=0){
			res*=n;
			n--;
		}
		ln(res);
	}

	public static void main(String[] args) {
		new Main().run();
	}

	public static void pr(Object o) {
		System.out.print(o);
	}

	public static void ln(Object o) {
		System.out.println(o);
	}

	public static void ln() {
		System.out.println();
	}
}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for(int i = (a); i >= (b); i--)
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define fast_io ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define ll long long int
#define vi         vector<int>
#define vll        vector<ll>
#define vpii       vector<pair<int,int>>
#define pr        pair<int,int>
#define vpll       vector<pair<ll,ll>>
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define sz(container) int((container).size())
#define mape map<int,int>
const ll mod=1e9+7;
const int N=2e5+5;
//cout << fixed << setprecision(6) <<
using namespace std;
int main()
{
    int x,n,temp,ans=10000,index;
    cin>>x>>n;
    set<int>s;
    FOR(i,1,n)
    {
     cin>>temp;
     s.insert(temp);
    }
    FOR(i,0,101)
    if(s.find(i)==s.end() and abs(x-i)<ans)
    {index=i; ans=abs(x-i);};
    cout<<index;
}

Measured memory_bytes: 3636
#include <iostream>
using namespace std;
 
int gcd(int p, int q) {
	if (p % q == 0) return q;
  	return gcd(q,p%q);
}

int main() {
	int n; cin>>n;
  	long long ans=0;
  	for (int i=1;i<=n;i++) {
    	for (int j=1;j<=n;j++) {
        	for (int k=1;k<=n;k++) {
            	ans += gcd(gcd(i,j),k);
            }
        }
    }
  	cout << ans << endl;
  	return 0;
}

Measured memory_bytes: 3576
#pragma GCC optimize("Ofast")
#pragma GCC target("avx")
#include <bits/stdc++.h>
using namespace std;

#define INIT std::cin.tie(0);std::ios::sync_with_stdio(false);
#define ALL(c) (c).begin(), (c).end()
#define CALL(c) (c).cbegin(), (c).cend()
#define RALL(c) (c).rbegin(), (c).rend()
#define CRALL(c) (c).crbegin(), (c).crend()
#define REP(i, n) for (int i = 0; i < static_cast<int>(n); i++)
#define FOR(i, s, n) for (int i = s; i < static_cast<int>(n); i++)
#define ASC(t) [](t& x, t& y){ return x < y; }
#define DESC(t) [](t& x, t& y){ return x > y; }
#define PSORT(s,p,e) partial_sort((s), next((s), (p)), (e))
#define VIEW(v,t) for_each((v).begin(), (v).end(), [](t& a) { cout << a << " "; }); cout << endl;

#define IN(a, x, b) (a<=x && x<b)
template<class T> inline T CHMAX(T& x, const T y){return x=(x<y)?y:x;}
template<class T> inline T CHMIN(T& x, const T y){return x=(x>y)?y:x;}
#define OUT(dist) std::cout<<(dist);
#define WS std::cout<<" ";
#define NL std::cout<<"\n"

using PII = pair<int, int>;
using PLL = pair<long long, long long>;
using LL = long long;
using ULL = unsigned long long;
template<class T> using V = vector<T>;
template<class T> using V2 = vector<vector<T>>;
template<class T, int W=255> using A = array<T, W>;
template<class T, int W=255, int H=255> using A2 = array<array<T, W>, W>;

LL R,G,B,N;

int main(){
    INIT;
    cin >> R >> G >> B >> N;

    LL cnt = 0;
    for(LL r = 0; r <= N; r++) {
        for(LL g = 0; g <= N; g++) {
            LL b = N - r*R - g*G;
            if(0 <= b && b % B == 0 && r*R + g*G + b == N) {
                cnt++;
            }
        }
    }

    cout << cnt << "\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
  int n[3],i;
  for(cin>>i;i>0;i--){
    cin >> n[0] >> n[1] >> n[2];
    sort(n,n+3);
    if(n[0]<=1000&&n[1]<=1000&&n[2]<=1000&&0<n[0]&&0<n[1]&&0<n[2]){
      n[2] *= n[2];
      n[1] = n[1]*n[1] + n[0]*n[0];
      if(n[2] == n[1])
	  cout << "YES" << endl;
      else 
	  cout << "NO" << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 1172
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.AbstractCollection;
import java.util.Scanner;
import java.util.LinkedList;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        D solver = new D();
        solver.solve(1, in, out);
        out.close();
    }

    static class D {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int N = in.nextInt();
            int K = in.nextInt();
            int[][] sushi = new int[N][2];
            for (int i = 0; i < N; i++) {
                sushi[i] = new int[]{in.nextInt(), in.nextInt()};
            }
            Arrays.sort(sushi, (a, b) -> Integer.compare(b[1], a[1]));

            int[] count = new int[N + 1];
            LinkedList<int[]> que = new LinkedList<>();
            long kinds = 0;
            long sum = 0;
            for (int i = 0; i < K; i++) {
                sum += sushi[i][1];
                int kind = sushi[i][0];
                count[kind]++;
                if (count[kind] == 1) {
                    kinds++;
                }
                if (count[kind] >= 2) {
                    que.add(new int[]{sushi[i][1], i});
                }
            }

            long max = sum + kinds * kinds;
            for (int i = K; i < N; i++) {
                int kind = sushi[i][0];
                if (count[kind] <= 0) {
                    if (que.isEmpty()) {
                        break;
                    }
                    int[] q = que.removeLast();
                    while (count[sushi[q[1]][0]] < 2) {
                        q = que.isEmpty() ? null : que.removeLast();
                        if (q == null) {
                            break;
                        }
                    }
                    if (q == null) {
                        break;
                    }
                    int index = q[1];
                    sum += (sushi[i][1] - sushi[index][1]);
                    kinds++;
                    max = Math.max(max, sum + kinds * kinds);
                    count[kind]++;
                    count[sushi[index][0]]--;
                }
            }

            out.println(max);
        }

    }
}



Measured memory_bytes: 95984
while True:
	t = list(input().split())
	a = int(t[0])
	op = t[1]
	b = int(t[2])

	if (op == "?"):
		break
	elif (op == "+"):
		print(str(a + b))
	elif (op == "-"):
		print(str(a - b))
	elif (op == "*"):
		print(str(a * b))
	else :
		c = int(a/b)
		print(str(c))
	

Measured memory_bytes: 7604
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;


int main(){
    int n, m;
    cin >> n >> m;
    
    
    if (n%2==1) {
        rep(i, m) {
            cout << i+1 << " " <<  n-1-i << endl;
        }
        return 0;
    }

    int num = 0;
    int i = 0;
    bool flg = true;
    
    while (num<m) {
        int x, y;
        if (flg) {
            x = n/2-i;
            y = n/2+i+1;
        }
        else {
            //cout << "aaa" << endl;
            x = i+1;
            y = n-1-i;
            
        }
        if (y-x!=n/2) { 
            cout << x << " " << y << endl;
            num++;
        }
        i++;
        if (i==n/4) {
            i = 0;
            flg = false;
        }

    }
    return 0;
}


Measured memory_bytes: 3628
# _*_ coding:utf-8 _*_
#  Atcoder_Grand_Contest031-A
#  TODO https://atcoder.jp/contests/agc031/tasks/agc031_a
from collections import Counter

def solveProblem(S):
	# Sはサンプル3の[abcab]を取って説明
	# SSorted = sorted(S)
	# SSorted = aabbc
	# Counterクラスを使うと整列もしれくれるのでソートは不要と判断
	stringCounterBox = Counter(S)
	# [(a,2),(b,2),(c,1)]
	maxStrLength = len(stringCounterBox)
	# 文字そのものを並べる文字列長さは 1から3まで
	countList = list(stringCounterBox.values())
	# [2,2,1] と 各文字数だけ取り出した配列になった
	'''
	戦略
	リストに入った数値に1足した物を掛けて行く。最後に1を引いたのが答え。
	根拠
	このabcの時を例に出すとa,b,cの3字について
	a→0回～2回出す
	b→aと同じ
	c→0回～1回出す
	ケースの組み合わせを考えると 3 * 3 * 2 = 18通りある
	しかし 全ての文字0回という選択をすると文字列そのものが無くなってしまう。
	この場合は対象外となるので1減らす。
	'''
	counter = 1
	for i in range(0,len(countList),+1):

		# counter = (counter * (countList[i]+1)) % (10^9+7)
		counter = (counter*(countList[i]+1)) % (pow(10,9)+7)

	answer = counter-1
	return answer


if __name__ == '__main__':
	_ = int(input().strip())
	S = str(input().strip())
	solution = solveProblem(S)
	print("{}".format(solution))


Measured memory_bytes: 3444
#include<bits/stdc++.h>
using namespace std;
int main()
{
  long long n,i,j,k;
  cin>>n;
  long long a[n];
  for(i=0;i<n;i++)cin>>a[i];
  long long dp[n];
  dp[0]=0;
  dp[1]=abs(a[1]-a[0]);
  for(i=2;i<n;i++)
  {
    j=abs(a[i-1]-a[i])+dp[i-1];
    k=abs(a[i-2]-a[i])+dp[i-2];
    dp[i]=min(j,k);
  }
  cout<<dp[n-1];
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;

int k, x;

int main() {
    cin >> k >> x;

    for (int i = x - k + 1; i < x + k; ++i) {
        cout << i << " ";
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
ll par[200002];
ll rk[200002];
ll sz[200002];
void init(ll n){
	for(ll i=0; i<n; i++){
		par[i]=i; sz[i]=1;
	}
}
 
ll find(ll x){
	if(par[x]==x){
		return x;
	}else{
		return par[x]=find(par[x]);
	}
}
 
void unite(ll x, ll y){
	x=find(x);
	y=find(y);
	if(x==y) return;
	if(rk[x]<rk[y]){
		par[x]=y; sz[y]+=sz[x];
	}else{
		par[y]=x; sz[x]+=sz[y];
		if(rk[x]==rk[y]) rk[x]++;
	}
}
 
bool same(ll x, ll y){
	return find(x)==find(y);
}
int main()
{
  ll n, m; cin>>n>>m;
  ll ans[20002];
  ll a[200002], b[200002];
  for(ll i=0; i<m; i++){
    cin>>a[i]>>b[i];
    a[i]--; b[i]--;
  }
  init(n);
  ll c=0;
  ll cnt;
  cnt=0;
  for(ll i=m-1; i>=0; i--){
    ans[i]=c;
    ll x=a[i], y=b[i];
    if(same(x, y)){
      continue;
    }
    x=find(x), y=find(y);
    unite(x, y);
	
  }
  map<ll,ll>mp;
  for(ll i=0;i<n;i++){
	  mp[find(i+1)]++;
  }
  ll max=0;
  for(auto p:mp){
	  if(max<p.second){
	  	max=p.second;
	  }
  }
  cout<<max<<endl;
  
	return 0;
}


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

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<unordered_set>
#include<bitset>
#include<complex>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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 (b < a) { a = b; return true; } return false; }

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD =  (int)1e9 + 7;
const double EPS = 1e-9;

signed main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	string S;
	int l = 0, r = 0;
	cin >> S;

	rep(i, 0, SZ(S))
	{
		if (i % 2 == 0&&S[i]=='p')
		{
			l++;
		}
		if (i % 2 == 1 && S[i] == 'g')
		{
			r++;
		}
	}

	cout << r - l << endl;

	return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <string.h>
#include <algorithm>
using namespace std;
int main(){
  int n;
  cin >> n;
  int a,b,c = 100000001;
  if(n == 2)cin >> a >> b;
  if(n == 3)cin >> a >> b >> c;
  int mn = min(a,min(b,c));
  if(n == 2)c = 0;
  for(int i = 1 ; i <= mn ; i++ ){
    if(a%i == 0 && b%i == 0 && c%i == 0)cout << i << endl;
  }
  return 0;
}

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

int main()
{
  int n,x;
  cin>>x>>n;
   set<int> y;
  for(int i=-200;i<=200;i++)
  y.insert(i);
  for(int i=0;i<n;i++)
  {
  	int x;
  	cin>>x;
  	y.erase(x);
  }
  map<int,int> m;
  for(auto it:y)
  {
    int diff=abs(x-it);
    if(m.find(diff)!=m.end())
    {
      m[diff]=min(m[diff],it);
    }
    else m[diff]=it;
  }
  for(auto it:m)
  {
    cout<<it.second;
    break;
  }
}


Measured memory_bytes: 3664
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0296

"""
import sys
from sys import stdin
input = stdin.readline


def main(args):
    ans = 0
    c1, c5, c10, c50, c100, c500 = map(int, input().split())
    if c1 + c5*5 + c10*10 + c50*50 + c100*100 + c500*500 >= 1000:
        ans = 1
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])
    

Measured memory_bytes: 7784
use proconio::input;
use proconio::marker::Chars;
fn main() {
    input! {
        l: Chars,
    }

    let mo = 10usize.pow(9) + 7;
    let mut dp = vec![vec![0; 2]; l.len() + 1];
    //初期値は飛ばす　良く分からない
    //dp[0][0] = 1;
    dp[0][1] = 1;

    for i in 0..l.len() {
        if l[i] == '0' {
            //ギリギリなら(0,0)しかない
            dp[i + 1][1] += dp[i][1];
            dp[i + 1][1] %= mo;
        } else if l[i] == '1' {
            //choose (1, 0) (0, 1)
            dp[i + 1][1] += dp[i][1] * 2 % mo;
            dp[i + 1][1] %= mo;
            //choose (0, 0)
            dp[i + 1][0] += dp[i][1];
            dp[i + 1][0] %= mo;
        }
        //ギリギリじゃないなら(0,0)(0,1)(1,0)なんでもいい
        dp[i + 1][0] += dp[i][0] * 3 % mo;
        dp[i + 1][0] %= mo;
    }
    let ans = (dp[l.len()][0] + dp[l.len()][1]) % mo;
    println!("{}", ans);
}


Measured memory_bytes: 8080
n,x,y = map(int,input().split())

dist_list = [0 for _ in range(n)]

for i in range(1,n+1):
    for j in range(i+1,n+1):
        if j <= x or i >= y:
            distance = j-i
        else:
            distance = min(j-i,abs(x-i)+abs(y-j)+1)
        dist_list[distance] += 1

for i,dist in enumerate(dist_list):
    if i >= 1:
        print(dist)

Measured memory_bytes: 3572
#include<bits/stdc++.h>
#define two(a) (1<<(a))
#define LINF (1ll<<61)
#define EPS (1e-14)
#define Lshift(a,b) ((a)<<(b))
#define Rshift(a,b) ((a)>>(b))
#define rep(a,b) for(a=0 ; a<b ; a++)
#define xrep(a,b,c) for(a=b ; a<c ; a++)
#define INF (1<<29)
#define sz(a) int(a.size())
#define swap(a,b) ( (a^=b) , (b^=a) , (a^=b) )
#define GET(x) (mark[x>>5]>>(x&31)&1)
#define SET(x) (mark[x>>5]|=1<<(x&31))
#define maxL (10000000>>5)+1
#define mod 1000000007
#define vi vector<int>
#define pii pair<int, int>
#define mii map<int, int>
#define si set<int>
#define pb push_back
typedef long long ll;
using namespace std;


int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    while (1) {
        c -= b;
        if ( c <= 0) {
            cout << "Yes" << endl;
            break;
        }
        a -= d;
        if ( a <= 0) {
            cout << "No" << endl;
            break;
        }
    }
}


Measured memory_bytes: 3636
n = int(input())
a = list(map(int, input().split()))
sma = sum(a)
ans = []
ans.append(sma- 2*sum(a[1:n-1:2]))
for i in range(n-1):
    val = 2*a[i]-ans[i]
    ans.append(val)

for i in ans:
    print(i,end=" ")

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

// #define multitest 1
#ifdef WIN32
#define db(...) ZZ(#__VA_ARGS__, __VA_ARGS__);
#define pc(...) PC(#__VA_ARGS__, __VA_ARGS__);
template <typename T, typename U>
ostream &operator<<(ostream &out, const pair<T, U> &p)
{
	out << '[' << p.first << ", " << p.second << ']';
	return out;
}
template <typename Arg>
void PC(const char *name, Arg &&arg)
{
	std::cerr << name << " { ";
	for (const auto &v : arg)
		cerr << v << ' ';
	cerr << " }\n";
}
template <typename Arg1>
void ZZ(const char *name, Arg1 &&arg1)
{
	std::cerr << name << " = " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void ZZ(const char *names, Arg1 &&arg1, Args &&... args)
{
	const char *comma = strchr(names + 1, ',');
	std::cerr.write(names, comma - names) << " = " << arg1;
	ZZ(comma, args...);
}
#else
#define db(...)
#define pc(...)
#endif

using ll = long long;
#define f first
#define s second
#define pb push_back
const long long mod = 1000000007;
auto TimeStart = chrono::steady_clock::now();

const int nax = 2e5 + 10;

void solve()
{
	int n;
	cin >> n;
	vector<int> h(n);
	for (auto &x : h)
		cin >> x;
	reverse(h.begin(), h.end());
	int prevAns = 0, ans = 0, prevHt = h[0];
	for (int i = 1; i < n; ++i)
	{
		if (h[i] < prevHt)
		{
			prevAns = 0;
		}
		else
		{
			prevAns++;
			ans = max(ans, prevAns);
		}
		db(ans, prevHt, prevAns);
		prevHt = h[i];
	}
	cout << ans;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int t = 1;
#ifdef multitest
	cin >> t;
#endif
	while (t--)
		solve();
#ifdef WIN32
	cerr << "\n\nTime elapsed: " << chrono::duration<double>(chrono::steady_clock::now() - TimeStart).count() << " seconds.\n";
#endif
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)



template< int mod >
struct ModInt {
  int x;

  ModInt() : x(0) {}

  ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}

  ModInt &operator+=(const ModInt &p) {
    if((x += p.x) >= mod) x -= mod;
    return *this;
  }

  ModInt &operator-=(const ModInt &p) {
    if((x += mod - p.x) >= mod) x -= mod;
    return *this;
  }

  ModInt &operator*=(const ModInt &p) {
    x = (int) (1LL * x * p.x % mod);
    return *this;
  }

  ModInt &operator/=(const ModInt &p) {
    *this *= p.inverse();
    return *this;
  }

  ModInt operator-() const { return ModInt(-x); }

  ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }

  ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }

  ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }

  ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }

  bool operator==(const ModInt &p) const { return x == p.x; }

  bool operator!=(const ModInt &p) const { return x != p.x; }

  ModInt inverse() const {
    int a = x, b = mod, u = 1, v = 0, t;
    while(b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModInt(u);
  }

  ModInt pow(int64_t n) const {
    ModInt ret(1), mul(x);
    while(n > 0) {
      if(n & 1) ret *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ret;
  }

  friend ostream &operator<<(ostream &os, const ModInt &p) {
    return os << p.x;
  }

  friend istream &operator>>(istream &is, ModInt &a) {
    int64_t t;
    is >> t;
    a = ModInt< mod >(t);
    return (is);
  }

  static int get_mod() { return mod; }
};
const int mod=1e9+7;
using modint = ModInt< mod >;

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

  int h,w,n;
  cin >> h >> w >> n;
  vector<pair<int, int> > cor(n);
  rep(i,n){
    int r,c;
    cin >> r >> c;
    --r;--c;
    cor[i]=mp(r,c);
  }
  sort(cor.begin(), cor.end());
  const int n_max=h+w+10;
  vector<modint> kai(n_max);
  vector<modint> ikai(n_max);
  kai[0]=1;
  rep1(i,n_max-1) kai[i]=kai[i-1]*((modint)i );
  rep(i,n_max) ikai[i]=((modint)1)/kai[i];
  vector<vector<modint> > dp(n, vector<modint>(2));
  rep(i,n) dp[i][0]=0;
  rep(i,n){
    int r=cor[i].first;
    int c=cor[i].second;
    dp[i][1]=kai[r+c]*ikai[r]*ikai[c];
  }
  modint ans=kai[h+w-2]*ikai[h-1]*ikai[w-1];
  rep(i,n){
    int ci=cor[i].second;
    int ri=cor[i].first;
    rep(j,i){
      int cj=cor[j].second;
      if(ci >= cj){
	int rj=cor[j].first;
	modint fac=kai[ri-rj+ci-cj]*ikai[ri-rj]*ikai[ci-cj];
	dp[i][0] += dp[j][1]*fac;
	dp[i][1] += dp[j][0]*fac;
      }
    }
    ans +=(dp[i][0] - dp[i][1])*kai[h-1-ri+w-1-ci]*ikai[h-1-ri]*ikai[w-1-ci];
  }

  cout << ans << endl;
  return 0;
    

}


Measured memory_bytes: 2048
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rrep(i, a, b) for (int i = a; i >= (b); i--)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
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;
}
void hr() {
   cerr << "--------------" << endl;
}
const int INF = 1001001001;
const int MOD = 1000000007;

int f(int x) {
   if (x == 0) return 0;
   return f(x % __builtin_popcount(x)) + 1;
}
int main() {
   cin.tie(0);
   ios_base::sync_with_stdio(0);

   int n;
   cin >> n;
   string s;
   cin >> s;
   vector<int> x(n);
   rep(i, 0, n) x[i] = s[i] - '0';
   int pc = 0;
   rep(i, 0, n) pc += x[i];
   vector<int> ans(n);
   rep(b, 0, 2) {
      int npc = pc;
      if (b == 0)
         npc++;
      else
         npc--;
      if (npc <= 0) continue;
      int r0 = 0;
      rep(i, 0, n) {
         r0 = (r0 * 2) % npc;
         r0 += x[i];
      }
      int k = 1;
      rrep(i, n - 1, 0) {
         if (x[i] == b) {
            int r = r0;
            if (b == 0)
               r = (r + k) % npc;
            else
               r = (r - k + npc) % npc;
            ans[i] = f(r) + 1;
         }
         k = (k * 2) % npc;
      }
   }
   rep(i, 0, n) cout << ans[i] << endl;
   return 0;
}

Measured memory_bytes: 5176
n = int(input())
a = list(map(int, input().split()))

s = {}
for x in a:
    if x in s:
        s[x] += 1
    else:
        s[x] = 1

sum = 0
for k in s:
    v = s[k]
    sum += v*(v-1)//2
for x in a:
    print(sum - (s[x]-1))


Measured memory_bytes: 25644
using System;
using System.Collections;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using System.Threading.Tasks;

class Program
{
	//しゃくとり法のテンプレ
	/*
	取り敢えず、long配列を受け取り、intの値を返すことを前提としたテンプレ
	（e.g. 例として、積がK以下となる区間のうち、最長のものを求める問題）
	*/
	static long Shakutori(long[] Arr){
		//配列の長さを取得
		int len = Arr.Length;
		//右端を使い回す（※ここがしゃくとり法の肝）
		int right = 0;
		//答え（区間の合計）
		long ans = 0;

		//探索に使う数値
		long xor = 0;
		long sum = 0;

		//しゃくとり法による探索の開始
		for(int left=0; left<len; left++){
			//0. 仕切り直し
			//左端が右端を追い抜いた場合の処理（rightをleftに合わせる）
			if(right < left){
				//右端を左端に揃える
				right = left;
			}

			//debug（現在の左端と右端）
			//Console.WriteLine("l:{0},r:{1}",left,right);

			//1. 右端を動かして大丈夫な場合は、右端をずらす処理へ
			//（※2つ目の条件：xor An+1 = sum + An+1）
			while(right < len && ((xor^Arr[right]) == sum + Arr[right])){
				//値を更新
				xor = xor^Arr[right];
				sum += Arr[right];

				//右に進む
				right ++;
			}

			//2. 最長区間に対する処理（現時点でのrightが、今回のleftに対する最右端）
			//e.g. 区間の長さを取得し、加算
			ans += (long)(right - left);

			//3. 左端を1つ右に動かす処理
			//合計からの減算
			sum -= Arr[left];
			//xorの打ち消し
			xor = xor^Arr[left];
		}
		
		//最後に、値を出力
		return ans;
	}

	//Main
	static void Main(string[] args)
	{
		//読み込む
		string[] line = Console.ReadLine().Split(' ');
		int N = int.Parse(line[0]);
		long[] An = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();

		//しゃくとり法
		long ans = Shakutori(An);

		Console.WriteLine(ans);
	}
}



Measured memory_bytes: 37252
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <numeric>
#include <functional>
#include <sstream>
#include <iostream>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <cassert>
using namespace std;

#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll> 
#define VVI vector<vector<ll> >
#define VVVI vector<vector<vector<ll>>>
#define VVVVI vector<vector<vector<vector<ll>>>>
#define REP(i,n) for(ll i=0,_n=(n);(i)<(ll)_n;++i)
#define REPR(i,n) for(ll i=(ll)(n)-1;0<=(i);--i)
#define RANGE(i,a,b) for(ll i=(ll)a,_b=(ll)(b);(i)<_b;++i)
#define RANGER(i,a,b) for(ll i=(ll)(b)-1,_a=(ll)(a);(_a)<=i;--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define UNIFORM_DOUBLE(a, b) (((b-a)*(double)rand()/RAND_MAX)+a) // [a, b) 
#define UNIFORM_LL(a, b) (ll)UNIFORM_DOUBLE(a, b) // [a, b) 
#define IN(v, lo, hi) ((lo)<=(v) && (v)<(hi))
#define DD(v) cout<<#v<<": "<<v<<endl
#define FI first
#define SE second
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }
template<typename T>void maxUpdate(T& a, T b) {a = max(a, b);}
template<typename T>void minUpdate(T& a, T b) {a = min(a, b);}
string YN(bool v) { return v ? "Yes":"No"; }

#define INF (1LL<<60)

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll N,M,W,H;
	string s;
	while(cin>>N) {
		VI A(N);
		REP(i, N) cin>>A[i];
		ll p=0, ans=-1;
		REP(i, N*2) {
			p=A[p]-1;
			if(p==1) {ans=i+1;break;}
		}
		
		cout<<ans<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define show(x) cout<<x<<'\n'
#define showh(x) cout<<x<<' '
#define go(i,a,n) for(ll i=a;i<n;i++)
#define gor(i,a,n) for(ll i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define mod 1000000007
bool prime[100001];
bool ispoweroftwo(ll x)
{
    return x && !(x & (x-1));
}
ll xorcal(ll n)
{
    if(n%4==0)
        return n;
    if(n%4==1)
        return 1;
    if(n%4==2)
        return n+1;
    if(n%4==3)
        return 0;
}
void sieve(ll n)
{
    memset(prime,true,sizeof(prime));
    prime[0]=false;
    prime[1]=false;
    for(ll i=2;i*i<=n;i++)
    {
        if(prime[i]==true)
        {
            for(ll j=i*i;j<=n;j+=i)
            {
                prime[j]=false;
            }
        }
    }
}
bool isprime(ll n)
{
    if (n<=1) return false;
    if (n<=3) return true;

    if(n%2==0 or n%3==0) return false;

    for(ll i=5;i*i<=n;i+=6)
    {
        if(n%i==0 or n%(i+2)==0) return false;
    }
    return true;
}

ll modinverse(ll a,ll m)
{
    ll m0 = m;
    ll y = 0, x = 1;

    if (m == 1)
      return 0;

    while (a > 1)
    {
        ll q = a / m;
        ll t = m;

        m = a % m; a = t;
        t = y;

        y = x - q * y;
        x = t;
    }

    if (x < 0)
       x += m0;

    return x;
}

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

ll power(ll A, ll B)
{
    if (A == 0)
        return 0;
    if (B == 0)
        return 1;

    ll y;
    if (B % 2 == 0) {
        y = power(A, B / 2);
        y = (y * y) % mod;
    }

    else {
        y = A % mod;
        y = (y * power(A, B - 1) % mod) % mod;
    }

    return (ll)((y + mod) % mod);
}
bool recur(string s1,string s2 ,ll m,ll n)
{
    if(m==0) return false;
    if(n==0) return true;
    if(s1[m-1]==s2[n-1])
    {
        return recur(s1,s2,m-1,n-1);
    }
    return recur(s1,s2,m-1,n);
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll r;
    cin>>r;
    show((3*r*r));
    return 0;
}


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

using namespace std;

struct point{
	int id;
	int a, b;
	point(){}
	point(int i, int x, int y){
		this->id = i, this->a = x, this->b = y;
	}
	bool operator<(const point& ope)const{
		return a < ope.a || (a == ope.a && b < ope.b);
	}
};

int n;
int x[3005], y[3005], d[3005];
int next[3005][4];
point XY[3005], YX[3005];

void make_link(point p[], int dir)
{
	int prev = 1000000005;
	for(int i = 0; i < n; i++){
		if(prev == p[i].a){
			next[p[i-1].id][dir] = p[i].id;
		}
		else if(i != 0){
			next[p[i-1].id][dir] = -1;
		}
		prev = p[i].a;
	}
	next[p[n-1].id][dir] = -1;
}

int search(int s)
{
	int next2[3005][4];
	for(int i = 0; i < n; i++){
		for(int j = 0; j < 4; j++){
			next2[i][j] = next[i][j];
		}
	}
	
	int ret = 0, pos = s;
	while(1){
		for(int dir = 0; dir < 4; dir++){
			if(next2[pos][dir] == -1) continue;
			next2[next2[pos][dir]][(dir+2)%4] = next2[pos][(dir+2)%4];
		}
		pos = next2[pos][d[pos]];
		ret++;
		if(pos == -1) return ret;
	}
}

int main(void)
{
	cin >> n;
	
	char c;
	for(int i = 0; i < n; i++){
		cin >> x[i] >> y[i] >> c;
		if(c == '>') d[i] = 0;
		if(c == '^') d[i] = 1;
		if(c == '<') d[i] = 2;
		if(c == 'v') d[i] = 3;
	}
	
	for(int i = 0; i < n; i++){
		XY[i] = point(i, x[i], y[i]);
		YX[i] = point(i, y[i], x[i]);
	}
	
	sort(XY, XY+n); make_link(XY, 3);
	reverse(XY, XY+n); make_link(XY, 1);
	sort(YX, YX+n); make_link(YX, 0);
	reverse(YX, YX+n); make_link(YX,  2);
	
	int ans = 0;
	for(int i = 0; i < n; i++){
		ans = max(ans, search(i));
	}
	
	cout << ans << endl;
}

Measured memory_bytes: 3292
import math

n, k = map(int, input().split())
a = [int(x) for x in input().split()]

l, r = 0, 10**9+2

while r-l > 1:
  key = (r+l)//2
  count = 0
  for i in range(n):
    count += (a[i]-1)//key
  if count <= k:
    r = key
  else:
    l = key

print(r)

Measured memory_bytes: 31116
n = gets.to_i
x = gets.chomp
xs = x.to_i(2)
xc = x.count('1')
def mpow(n, p, mod)
  r = 1
  while p > 0
    r = r * n % mod if p & 1 == 1
    n = n * n % mod
    p >>= 1
  end
  r
end
def popcount(u)
  return 0 if u.zero?
  a = u % u.to_s(2).count('1')
  1 + popcount(a)
end
xsp = xs % (xc + 1)
if xc == 1
  xsm = 0
else
  xsm = xs % (xc - 1)
end
n.times do |i|
  if x[i] == '0'
    y = xsp + mpow(2, n - i - 1, xc + 1)
    y = mpow(y, 1, xc + 1)
  elsif xc == 1
    puts '0'
    next
  else
    y = xsm - mpow(2, n - i - 1, xc - 1)
    y = mpow(y, 1, xc - 1)
  end
  puts popcount(y) + 1
end

Measured memory_bytes: 14684
class Stack:
    def __init__(self):
        self.stack = []

    def push(self, num):
        self.stack.append(num)

    def pop(self):
        return self.stack.pop()

    def calc(self, ope):
        ans = 0
        num1 = self.pop()
        num2 = self.pop()
        if ope == '+':
            ans = num2 + num1
        elif ope == '-':
            ans = num2 - num1
        elif ope == '*':
            ans = num2 * num1
        self.push(ans)


stack = Stack()
input_list = input().split()
for i in input_list:
    if i.isdecimal():
        stack.push(int(i))
    else:
        stack.calc(i)
print(stack.pop())


Measured memory_bytes: 5596
#!/usr/bin/ruby
#encoding: utf-8

s = gets.chomp
y,m,d = s.split("/").map(&:to_i)


if y > 2019 then
  puts "TBD"
elsif y == 2019 && m >= 5 then
  puts "TBD"
else
  puts "Heisei"
end


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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP0(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP1(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define RREP0(i,n) for(int i=n-1; i>=0; --i)
#define RREP1(i,n) for(int i=n; i>=1; --i)

#define SORT(c) sort((c).begin(),(c).end())
#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define CLR(a) memset((a), 0 ,sizeof(a))

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
int gcd(int a,int b){return b?gcd(b,a%b):a;}

typedef long long LL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;

const int INTINF = 2147483647;
const LL LLINF = 9223372036854775807;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int WHITE = 0;
const int GRAY = 1;
const int BLACK = 2;
const int MAX = 10001;

struct init{
    init(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);
    };
} init;

int D;

void input(){
  std::cin >> D;
}


int main(int argc, char const *argv[]) {
  input();
  if (D==25) {
    std::cout << "Christmas" << '\n';
  } else if (D==24){
      std::cout << "Christmas Eve" << '\n';
  } else if (D==23){
    std::cout << "Christmas Eve Eve" << '\n';
  } else if (D==22){
    std::cout << "Christmas Eve Eve Eve" << '\n';
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
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;
	return 0;
}

Measured memory_bytes: 384
import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
import copy
from decimal import *
from collections import deque
sys.setrecursionlimit(10**7)
MOD = 10**9+7
INF = float('inf') #無限大
def gcd(a,b):return fractions.gcd(a,b) #最大公約数
def lcm(a,b):return (a*b) // fractions.gcd(a,b) #最小公倍数
def iin(): return int(sys.stdin.readline()) #整数読み込み
def ifn(): return float(sys.stdin.readline()) #浮動小数点読み込み
def isn(): return sys.stdin.readline().split() #文字列読み込み
def imn(): return map(int, sys.stdin.readline().split()) #整数map取得
def imnn(): return map(lambda x:int(x)-1, sys.stdin.readline().split()) #整数-1map取得
def fmn(): return map(float, sys.stdin.readline().split()) #浮動小数点map取得
def iln(): return list(map(int, sys.stdin.readline().split())) #整数リスト取得
def iln_s(): return sorted(iln()) # 昇順の整数リスト取得
def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得
def fln(): return list(map(float, sys.stdin.readline().split())) # 浮動小数点リスト取得
def join(l, s=''): return s.join(l) #リストを文字列に変換
def perm(l, n): return itertools.permutations(l, n) # 順列取得
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) # 順列の総数
def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得
def comb_count(n, r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) #組み合わせの総数
def two_distance(a, b, c, d): return ((c-a)**2 + (d-b)**2)**.5 # 2点間の距離
def m_add(a,b): return (a+b) % MOD
def print_list(l): print(*l, sep='\n')

def sieves_of_e(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i * 2, n+1, i): is_prime[j] = False
    return is_prime

N = iin()

ans = INF
for i in range(1, N):
    total = 0
    A = str(i)
    B = str(N-i)
    for a in A:
        total += int(a)
    for b in B:
        total += int(b)
    ans = min(ans, total)
print(ans)
    


Measured memory_bytes: 5676
#include <bits/stdc++.h>
using namespace std;
using vi=vector<int>;

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

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

const long long INF = 100000000;

int main() {
  long long n;
  cin >> n;
  vector<long long> flog(n);
  vector<long long> dp(n);
  for(long long i = 0; i < n; ++i) {
    cin >> flog[i];
  }
  auto a = [](long long a, long long b){
    if(a<b) return a;
    else return b;
  };

  dp[0] = 0;
  dp[1] = abs(flog[1] - flog[0]);
  for(long long i = 2; i < n; ++i) {
      dp[i] = a(dp[i - 1] + abs(flog[i - 1] - flog[i]),dp[i - 2] + abs(flog[i - 2] - flog[i]));
  }
  cout << dp[n - 1] << endl;
  return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define INF 2000000000
#define MOD 1000000007
#define EPS (1e-10)

using namespace std;

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

	int N; cin >> N;
	int ans = 0;
	vector<int> A(N,0);
	vector<int> B(N-1,0);
	for (int i = 0; i < N-1; i++) {
		cin >> B[i];
	}

	A[0] = B[0];
	A[1] = B[0];

	for (int i = 1; i < N-1; i++) {
		if (A[i] > B[i]) {
			A[i] = B[i];
		}
		A[i+1] = B[i];
	}

	for (int i = 0; i < N; i++) {
		ans += A[i];
	}

	cout << ans << endl;


	return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define DEBUG fprintf(stderr, "Passing [%s] line %d\n", __FUNCTION__, __LINE__)
#define File(x) freopen(x".in","r",stdin); freopen(x".out","w",stdout)

using namespace std;

typedef long long LL;
typedef pair <int, int> PII;
typedef pair <int, PII> PIII;

inline int gi()
{
	int f = 1, x = 0; char c = getchar();
	while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f * x;
}

inline LL gl()
{
	LL f = 1, x = 0; char c = getchar();
	while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f * x;
}

const int INF = 0x3f3f3f3f, N = 300003, M = N << 1;

int n, m;
int a[N], b[N];
char s[N];

int main()
{
	//File("");
    cin >> n;
    m = n % 10;
    if (m == 2 || m == 4 || m == 5 || m == 7 || m == 9)
        puts("hon");
    else if (m == 0 || m == 1 || m == 6 || m == 8)
        puts("pon");
    else puts("bon");
	return 0;
}

Measured memory_bytes: 3640
#include <stdio.h>

int main(void) {
    int D, T, S;
    double result1, result2;

    scanf("%d %d %d", &D, &T, &S);

    result1 = D/S;
    result2 = D%S;
    

    if(result1 == T && result2 == 0 || result1 <= T-1) {
        puts("Yes");
    }
    else puts("No");

    return 0;
}

Measured memory_bytes: 1660
main = do
    let toInt = (read :: String -> Int) 
    xs <- getLine >>= return . map toInt . words
    let lx = xs !! 0
    let ly = xs !! 1
    let con = [(x,y) | 
            x <- [0..lx],
            y <- [0..lx],
            x * 2 + y * 4 == ly,
            x + y == lx
            ] 
    putStr $ if length con > 0 then "Yes" else "No"

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

using namespace std;
using ll = long long;

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

  if (A%2==0 && A == B && B == C) {
    cout << -1 << endl;
    return 0;
  }

  ll ans = 0;
  while (A%2==0 && B%2==0 && C%2==0) {
    ll a=A, b=B, c=C;
    A = (b+c)/2, B=(a+c)/2, C=(a+b)/2;
    ans++;
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
def pow(m, n, mod)
  return 1 if n == 0
  
  if n.even?
    return pow(m * m % mod, n / 2, mod)
  else
    return m * pow(m, n - 1, mod) % mod
  end
end
m, n = gets.split.map(&:to_i)
puts pow(m, n, 1_000_000_007)

Measured memory_bytes: 8584