akhauriyash/Code-Regression huggingface dataset:
#! usr/bin/env python
# -*- coding: utf-8 -*-

from collections import deque
import heapq
import math
import bisect


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

    cnt = [0] * M
    for i in range(N):
        L = list(map(int, input().split()))
        for j in range(1, len(L)):
            cnt[L[j]-1] += 1

    ans = 0
    for i in range(M):
        if cnt[i] == N:
            ans += 1

    print(ans)



if __name__ == '__main__':
    main()


Measured memory_bytes: 3572
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

ll x[100001];
const int MOD = 1e9 + 7;

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n; cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>x[i];
	}
	ll ans = 1; int siz=0; int ptr=0;
	for(int i = 0; i < n; i++)
	{
		while(ptr<n)
		{
			siz++; 
			if(x[ptr++]>=2*siz-1) continue;
			else break;
		}
		ans=(ans*siz)%MOD; siz--;
	}
	cout<<ans<<'\n';
	
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define FasterIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

typedef unsigned long long ull;
typedef long long ll;
typedef double db;

#define mem(a,x) memset(a,x,sizeof(a))
#define pb push_back
#define ff first
#define ss second
#define mk make_pair
#define pi pair<int,int>
#define vi vector<int>
#define pL pair<ll,ll>
#define vL vector<ll>
#define vp vector<pi>
#define vpL vector<pL>
#define pi3 pair<int, pi>
#define pi4 pair<pi, pi>

const int MX=300000+10;
const ll mod=998244353;

int T[4*MX], lazy[4*MX], N;

ll pw[MX],  dig[10][MX];

void propagate(int p, int l, int h)
{
    ll lo=N-h, hi=N-l, di=lazy[p];

    ll d=dig[di][hi-lo];
    d*=pw[lo]; d%=mod;

    T[p]=d;

    if(l!=h)
    {
        lazy[2*p]=lazy[p];
        lazy[2*p+1]=lazy[p];
    }
    lazy[p]=0;
}

void up(int p, int l, int h, int x, int y, int vl)
{
    if(lazy[p]!=0) propagate(p, l, h);
    if(x>h || y<l) return;
    if(l>=x && h<=y)
    {

        ll lo=N-h, hi=N-l, di=vl;

        ll d=dig[di][hi-lo];
        d*=pw[lo]; d%=mod;

        T[p]=d;

        if(l!=h)
        {
            lazy[2*p]=vl;
            lazy[2*p+1]=vl;
        }
        return;
    }
    int m=(l+h)/2;
    up(2*p, l, m, x, y, vl);
    up(2*p+1, m+1, h, x, y, vl);
    T[p]=(T[2*p]+T[2*p+1])%mod;
}

int main()
{
    FasterIO;

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


    N=n;

    pw[0]=1;
    for(int i=1; i<=n; i++) pw[i]=pw[i-1]*10, pw[i]%=mod;
    for(int d=1; d<=9; d++)
    {
        dig[d][0]=d;
        for(int j=1; j<=n; j++)
        {
            dig[d][j]=(dig[d][j-1]*10+d)%mod;
        }
    }

    up(1, 1, n, 1, n, 1);

    for(int i=1; i<=q; i++)
    {
        int l, r, d; cin>>l>>r>>d;
        up(1, 1, n, l, r, d);

        cout<<T[1]<<endl;
    }

    return 0;
}


Measured memory_bytes: 23432
#include <iostream>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <queue>
#include <cstdio>
#include <cmath>
#include <stack>
typedef long long ll;
#define INF 0x3f3f3f3f

using namespace std;
struct Node {
	int x, y;

};
bool cmp(Node n1, Node n2) {
	return n1.x < n2.x;
}

ll dp[200000 + 10];
Node node[100000 + 10];
ll pre[200000 + 10][2];
void solve() {
	int n, m;
	scanf("%d%d", &n, &m);
	for(int i = 1; i <= n; i++) {
			dp[i] = dp[i] = 1;
	}
	for(int i = 0; i < m; i++) {
		scanf("%d%d", &node[i].x, &node[i].y);
	}
	
	sort(node, node + m, cmp);
	
	for(int i = 0; i < m; i++) {
		ll pre1 = dp[node[i].y], pre2 = dp[node[i].y + 1];
		dp[node[i].y] += pre2 - pre[node[i].y][1];
		dp[node[i].y + 1] += pre1 - pre[node[i].y + 1][0];
		
		pre[node[i].y][1] = dp[node[i].y];
		pre[node[i].y + 1][0] = dp[node[i].y + 1];
		
	}
	
	printf("%lld", dp[1]);
	for(int i = 2; i <= n; i++) {
		printf(" %lld", dp[i]);
	}
	printf("\n");
		
}
int main(int argc, char *argv[]) {
	solve();
}

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

int main() {
    string a, b;
    cin >> a >> b;
    map<string, int> mp;
    int x, y;
    cin >> x >> y;
    mp[a] += x;
    mp[b] += y;
    string c;
    cin >> c;
    mp[c]--;
    printf("%d %d\n", mp[a], mp[b]);
    return 0;
}

Measured memory_bytes: 3728
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <functional>
#include <stack>
#include <utility>
#include <map>
#include <queue>
#include <set>

using namespace std;

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

const ll MOD = 1000000007;

ll n, W, w[100], v[100];
ll memo[101][101][301];

ll dp(ll ii, ll cnt, ll ww) {
	if (memo[ii][cnt][ww] != -1)return memo[ii][cnt][ww];

	ll res;
	if (ii == n)res = 0;
	else if (W - cnt * w[0] - ww - w[ii] < 0)res =  dp(ii + 1, cnt, ww);
	else res = max(dp(ii + 1, cnt, ww), v[ii] + dp(ii + 1, cnt + 1, ww + w[ii] - w[0]));

	memo[ii][cnt][ww] = res;
	return res;
}

int main() {
	
	cin >> n >> W;
	
	for (int i = 0; i < n; i++) {
		cin >> w[i] >> v[i];
	}
	for (int i = 0; i <= n; i++) {
		for (int j = 0; j <= n; j++) {
			for (int k = 0; k <= n * 3; k++) {
				memo[i][j][k] = -1;
			}
		}
	}
	cout << dp(0, 0, 0) << endl;
}

Measured memory_bytes: 24192
H,W=map(int,input().split())
N=int(input())
L=list(map(int,input().split()))
col=0
M=[[0]*W for _ in range(H)]



for i in range(H):
    if i%2==0:
        for j in range(W):
        # print(i)
        # print(j)
            if L[col]>0:
                M[i][j]=col+1
                L[col]-=1
            if L[col]==0:
                col+=1
    else:
        for j in range(W-1,-1,-1):
        # print(i)
        # print(j)
            if L[col]>0:
                M[i][j]=col+1
                L[col]-=1
            if L[col]==0:
                col+=1

for q in range(H):
    for w in range(W):
        print(M[q][w],end=" ")
    print()


Measured memory_bytes: 3920
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<math.h>
using namespace std;
int main(){

int a,b,c,x;
cin>> a >> b >> c >> x;
int count = 0;

for(int i=0;i<=a;i++){
	for(int j = 0;j<=b;j++){
		for(int k = 0;k<=c;k++){
			if(i*500 + j*100 + k*50 == x)
			count++;
		}
	}
}
cout<< count <<endl;
}


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

using ll = long long;
using P = pair<int, int>;

const int INF = 1e9;
const int MOD = 1e9 + 7;

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

  ll money = 1000;
  for (int i = 0; i < N - 1; i++) {
    ll stocks = 0;
    if (a[i] < a[i+1]) {
      stocks = money / a[i];
      money -= a[i] * stocks;
    }
    money += stocks * a[i+1];
  }

  cout << money << endl;
  return 0;
}


Measured memory_bytes: 3624
/*Stay true to yourself, yet always be open to learn. Work hard, and never give up on your dreams, 
even when nobody else believes they can come true but you. These are not cliches but real tools you 
need no matter what you do in life to stay focused on your path.
*/
 
 /*Pppppppp    UU      UU     CCCCCCCC    CCCCCCCC     HH     HH     UU      UU
   pp    pp    UU      UU     CC          CC           HH     HH     UU      UU
   pp    pp    UU      UU     CC          CC           HHHHHHHHH     UU      UU
   pppppppp    UU      UU     CC          CC           HHHHHHHHH     UU      UU
   pp          UU      UU     CC          CC           HH     HH     UU      UU
   pp          UUUUUUUUUU     CCCCCCCC    CCCCCCCC     HH     HH     UUUUUUUUUU
   */
 
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,k;
    cin >> n >> k;
    int h[n];
    for(int i=0;i<n;i++)
    cin >> h[i];
    int ans[n];
    ans[0]=0;
    for(int i=1;i<min(k,n);i++)
    {
        ans[i] = abs(h[i]-h[0]);
    }
    for(int i=k;i<n;i++)
    {
       // ans[i]= min(ans[i-1]+abs(h[i]-h[i-1]),ans[i-2]+abs(h[i]-h[i-2]));
       ans[i]=ans[i-1]+abs(h[i]-h[i-1]);
       for(int j=2;j<=k;j++)
       {
           if(ans[i]>ans[i-j]+abs(h[i]-h[i-j]))
             ans[i]= ans[i-j]+abs(h[i]-h[i-j]);
       }
    }
    cout<<ans[n-1]<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <deque>
#include <queue>
using namespace std;

int N, M;
long long A[100100], B, C;
vector<pair<long long, long long>> BC;

bool comp(const pair<long long, long long>& p1, const pair<long long, long long>& p2) {
    return p1.second > p2.second;
}

int main() {
    cin >> N >> M;
    for (int i=0; i<N; ++i) cin >> A[i];
    for (int i=0; i<M; ++i) {
        cin >> B >> C;
        BC.push_back(make_pair(B, C));
    }
    sort(A, A+N);
    sort(BC.begin(), BC.end(), comp);

    long long ans = 0;
    bool flag = true;
    int cnt = 0, b = 0;
    for (int i=0; i<N; ++i) {
        if (!flag) ans += A[i];
        else {
            if (cnt == BC[b].first) {
                cnt = 0;
                b++;
            }
            if (b == M) {
                flag = false;
                ans += A[i];
            } else if (BC[b].second <= A[i]) {
                flag = false;
                ans += A[i];
            } else {
                ans += BC[b].second;
                cnt++;
            }
        }
    }

    cout << ans << endl;
    return 0;
}

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

const int MAX_N = 1e5 + 5;
int n;
int dp[MAX_N];
int h[MAX_N];

int main() {
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> h[i];

	dp[1] = abs(h[1] - h[0]);
	for (int i = 2; i < n; i++)
		dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]));

	cout << dp[n - 1] << "\n";
	return 0;
}

Measured memory_bytes: 1024
N = int(input())
a = {}
for i in range(N):
	b = i + 1
	j = 2
	while j * j <= b:
		while b % j == 0:
			if j in a:
				a[j] += 1
			else:
				a[j] = 1
			b /= j
		j += 1
	if b != 1:
		if b in a:
			a[b] += 1
		else:
			a[b] = 1
c = 1
for i in a.values():
	c *= i + 1
print(c % 1000000007)

Measured memory_bytes: 44400
process.stdin.resume();
process.stdin.setEncoding('utf8');

process.stdin.on('data', function(input) {
  var s = +input.split('\n')[0];
  var m = Math.floor(s / 60);
  var h = Math.floor(m / 60);
  m %= 60;
  s %= 60;
  console.log(h+':'+m+':'+s);
});

Measured memory_bytes: 7644
#include<bits/stdc++.h>
using namespace std;
 
int main(){
	
	int n;
	cin >> n;
	int a[n+1];
	int ans[n+1];
	for(int i =1;i<=n;i++) {
		cin >> a[i];
	  ans[a[i]] = i;	
	}
     
    for(int i=1;i<=n;i++) cout << ans[i]<<" ";
    
    cout << endl;
   
	
	
	
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
#include <stdio.h>
#include <numeric>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define repone(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define Rep(j,n) for(int j=0;j<(int)(n);++j)
#define Repo(j,o,n) for(int j=o;j<(int)(n);++j)
#define Repone(j,n) for(int j=1;j<(int)(n);++j)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define int long long
#define pb(a) push_back(a)
#define eraser(v,i) (v).erase(v.begin()+(i))
#define pbpair(a,b) push_back(make_pair(a,b))
#define MOD 1000000007
#define INF 9223372036854775807
#define pairint pair<int,int>
int num[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
bool uru(int checkyear){if(checkyear%4==0){if(checkyear%100!=0||checkyear%400==0)return true;}return false;}
int gcd( int x, int y ){return y ? gcd(y, x%y) : x;}
bool pairCompare(const pairint& firstElof, const pairint& secondElof)
{
  if(firstElof.second!= secondElof.second)    return firstElof.second> secondElof.second;
  else return firstElof.first< secondElof.first;
}
signed main() {
int x=0,y=0,z=0,w=0,n=0,m=0;
std::cin >> x;

std::cout << (24-x)+24 << '\n';
}


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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll n_; cin >> n_;
  const ll n = n_;
  if (n%2 == 1 || n < 10) cout << 0 << endl;
  else {
    ll pow = 1, f = 0, ans = 0;
    vector<ll> pvec(30,0);
    while (pow < n) {
        pow *= 5;
        f += 1;
        pvec[f] = pow;
    }
    for (ll i = 1; i <= f; ++i) {
      ans += n/(2*pvec[i]);
    }
    cout << ans << endl;
  } 
  return 0;
}

Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
from math import floor, sqrt, factorial, hypot, log  # log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter, defaultdict, deque
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement
from bisect import bisect_left, bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint


def ceil(a, b): return (a + b - 1) // b


inf = float('inf')
mod = 10 ** 9 + 7


def pprint(*A):
    for a in A:     print(*a, sep='\n')


def INT_(n): return int(n) - 1


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


def MF(): return map(float, input().split())


def MI_(): return map(INT_, input().split())


def LI(): return list(MI())


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


def LF(): return list(MF())


def LIN(n: int): return [I() for _ in range(n)]


def LLIN(n: int): return [LI() for _ in range(n)]


def LLIN_(n: int): return [LI_() for _ in range(n)]


def LLI(): return [list(map(int, l.split())) for l in input()]


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


def F(): return float(input())


def ST(): return input().replace('\n', '')

def main():
    MAX = 10000
    X, N = MI()
    P = LI()
    ans = {}
    for i in range(102):
        ans[i] = i
    for p in P:
        ans[p] = MAX
    answer = MAX
    ab = MAX
    for i in range(102):
        if ans[i] == MAX:
            continue
        if ab > abs(ans[i] - X):
            ab = abs(ans[i] - X)
            answer = i
    print(answer)


if __name__ == '__main__':
    main()

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

using namespace std;

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

const int INF = 1000000000;
const ll LINF = (ll) 4000000000000000000;
const ll MOD = (ll) 1000000007;
const double PI = acos(1.0);
const int limit = 100010;

#define REP(i,m,n) for(int i = (int)m; i < (int)n; i++)
#define rep(i,n) REP(i,0,n)
#define rep2(i,n) REP(i,1,n+1)
#define rep3(i,n) REP(i,0,n+1)
#define REPM(i,m,n) for(int i = (int)m; i >= (int)n; i--)
#define REPLL(i,m,n) for(ll i=m;i<(ll)(n);i++)
#define repll(i,n) REPLL(i,0,n)
#define repll2(i,n) REPLL(i,1,n+1)
#define MP make_pair
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define NP(v) next_permutation(v.begin(),v.end())
#define Size(s) (int) s.size()
#define greater_queue  priority_queue <ll, vector<ll>, greater<ll> >

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

int main() {
    ll n, l;
    cin >> n >> l;
    ll a[n];
    rep(i, n) cin >> a[i];

    rep(i, n - 1) {
        if (a[i] + a[i + 1] >= l) {
            stack<ll> stk;
            i++;
            stk.push(i);
            int j = i + 1;
            while (j < n) {
                stk.push(j);
                j++;
            }
            j = i - 1;
            while (j >= 1) {
                stk.push(j);
                j--;
            }

            Possible(true);
            while (!stk.empty()) {
                cout << stk.top() << endl;
                stk.pop();
            }
            return 0;
        }
    }

    Possible(false);

    return 0;
}


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

int main(void){
    // Your code here!
    int N, temp = 0;
    cin >> N;
    
    int* A = new int[N];
    for(int i=0; i<N; i++){
        cin >> A[i];
        temp += (i % 2 == 0) ? A[i] : (-1 * A[i]);
    }
    
    cout << temp;
    
    for(int i=0; i<N - 1; i++){
        cout << " " << 2 * (A[i] - temp/2);
        temp = 2 * (A[i] - temp/2);
    }
    
    cout << endl;
}

Measured memory_bytes: 1664
r,c=map(int,input().split())

a = []

for i in range(r):
    a.append(list(map(int, input().split())))
    a[i]+=[sum(a[i])]
    print(*a[i])
a=list(zip(*a[::-1]))

for i in range(c):print(sum(a[i]),end=' ')
print(sum(a[c]))


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



int gcd(int a,int b){
  int c;
  c=a;
  a=max(a,b);
  b=min(c,b);
  c=a;
  while(b > 0){
    a = b;
    b = c % b;
    c = a;
  }
  return a;
}

int main() {
#define rep(i, n) for(int i = 1; i <= (int)(n); i++)
  int N;
  cin>>N;
  int answer=0;
  int p;
  rep(i,N){
    rep(j,N){
      p=gcd(i,j);
      rep(k,N){
        answer+=gcd(p,k);
      }
    }
  }
  cout<<answer;
}

Measured memory_bytes: 3620
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <string>
#include <queue>
#include <stack>
#include <math.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<ll, ll> P;
typedef vector<int> vi;
typedef vector<vi> vvi;

#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REPR(i, n) for (ll i = (n) - 1; i >= 0; --i)
#define FOR(i, n, m) for (ll i = (n); i < (m); ++i)
#define FORR(i, n, m) for (ll i = (m) - 1; i >= (n); --i) 
#define FORE(x, xs) for (auto &x: (xs))
#define ALL(v) v.begin(), v.end()
#define ZERO(a) memset(a,0,sizeof(a))

const int INF = 1000000009;
const int MOD = 1000000007;
const double EPS = 1e-14;
const double PI = acos(-1);

const int MAX = 410;

int H, W;
bool S[MAX][MAX];
int parent[MAX][MAX];
const int dx[4] = {0, -1, 0, 1};
const int dy[4] = {-1, 0, 1, 0};

void dfs(int w, int h, int p) {
    parent[h][w] = p;
    REP (i, 4) {
        int x = w+dx[i], y = h+dy[i];
        if (x >= 0 && x < W && h >= 0 && h < H) {
            if (parent[y][x] == -1 && S[h][w] != S[y][x]) dfs(x, y, p);
        }
    }
}

int main() {
    cin >> H >> W;

    REP (h, H) {
        string s;
        cin >> s;
        REP (w, W) {
            S[h][w] = (s[w] == '#');
            parent[h][w] = -1;
        }
    }

    int p = 0;
    REP (h, H) REP (w, W) {
        if (parent[h][w] == -1) dfs(w, h, p++);
    }

    int count[MAX*MAX][2];
    REP (i, MAX*MAX) count[i][0] = count[i][1] = 0;
    REP (h, H) REP (w, W) {
        int b = S[h][w];
        count[parent[h][w]][b]++;
    }

    ll ans = 0;
    REP (i, MAX*MAX) ans += 1ll * count[i][0] * count[i][1];
    cout << ans << endl;
}

Measured memory_bytes: 14848
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		int w = sc.nextInt();
		StringBuilder sb = new StringBuilder();

		for(int i = 0; i < S.length(); i += w) {
			sb.append(S.charAt(i));
		}

		System.out.println(sb);

		return;
	}
}


Measured memory_bytes: 22868
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <limits>
using namespace std;
#define ll long long
#define ld long double
#define pii pair<int,int>
#define x first
#define y second
#define sf scanf
#define pf printf
#define vec vector
#define pb push_back
#define mp make_pair
#define sz(a) int(a.size())
#define all(a) a.begin(),a.end()
#define clr(a,b) memset(a,b,sizeof(a))
#define bin_cnt(x) __builtin_popcount(x)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define rrep(i,b,a) for(int i=b;i>=a;i--)
#define srep(sub,s) for(int sub=s&(s-1);sub;sub=(sub-1)&s)
#define irep(i,a) for(__typeof(a.begin()) i=a.begin();i!=a.end();i++)
#define irrep(i,a) for(__typeof(a.rbegin()) i=a.rbegin();i!=a.rend();i++)
#define inf numeric_limits<int>::max()
#define finf numeric_limits<double>::infinity()
#define eps 1e-8
#pragma GCC optimize ("O3")
#define o3 __attribute__((optimize("O3")))
#pragma comment(linker, "/STACK:32505856")

template<class T> inline T sqr(T a) {return a*a;}
template<class T> inline int gmin(T&a,T b) {if(a>b){a=b;return 1;}return 0;}
template<class T> inline int gmax(T&a,T b) {if(a<b){a=b;return 1;}return 0;}
inline int dcmp(const double &a) {return a>eps?1:(a<-eps?-1:0);}
struct Initializer{Initializer(){ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);}}initializer;

#define N 100010
int a[N];

int main() {
    int n;
    sf("%d", &n);
    int minv = 1;
    ll ans = 0;
    rep(i,1,n) {
        sf("%d", a + i);
    }
    rep(i,1,n) {
        if (a[i] > minv) {
            ll k = (a[i] - 1) / minv;
            ans += k;
            a[i] -= k * minv;
            if (a[i] == minv) a[i] = 1;
        }
        if (a[i] == minv) minv++;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 768
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<iomanip>
#include<map>
#include<utility>
#include<string>
#include<unordered_map>
#include <queue>

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

using namespace std;

#define min_3(a, b, c) min(a, min(b, c))
#define max_3(a, b, c) max(a, max(b, c))
typedef long long ll;

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

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


Measured memory_bytes: 256
package main

import (
	"fmt"
	"strconv"
)

func main() {
	var s string
	fmt.Scan(&s)
	a, _ := strconv.Atoi(s[0:1])
	b, _ := strconv.Atoi(s[1:2])
	c, _ := strconv.Atoi(s[2:])
	fmt.Println(a + b + c)
}


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

#define INF 1001001001
#define LINF 1001001001001001001
#define MOD 1000000007
#define MOD2 998244353

#define all(a)  (a).begin(),(a).end()
#define dig(n)  to_string(n).length()

#define pb push_back
#define eb emplace_back
#define mkp make_pair

#define se second
#define fi first

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

int main(){

    bool flag=false;
    ll ans=0,sum=0;

    ll n,t;
    ll st=0;
    cin >>n>>t;
    vector<ll> a(n);

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

        if(a[i] < st)ans -= (st-a[i]);

        ans += t;
        st = a[i]+t;

    }

    //cout <<fixed<<setprecision(16)<< << endl;
    cout << ans << endl;

    //if(flag)cout << "Yes" <<endl;
    //else cout << "No" <<endl;
    
    return 0;
}


Measured memory_bytes: 1792
#include<iostream>
using namespace std;
int main(){
    int x, y, z;
    cin >> x >> y >> z;
    
    if((x <= y) && (x <= z)){ // x y z    y x z
        if(y <= z) cout << x <<" "<< y <<" "<< z << endl;
        else if(y >= z) cout << x <<" "<< z <<" "<< y << endl;
        
        
    }else if((y <= x) && (y <= z)){ // y x z   y z x
        if(x <= z) cout << y <<" "<< x <<" "<< z << endl;
        else if(x >= z) cout << y <<" "<< z <<" "<< x << endl;
        
    } else if((z <= x) && (z <= y)) { //z x y      z y x
        if(x <= y) cout << z <<" "<< x <<" "<< y << endl;
        else if(x >= y) cout << z <<" "<< y <<" "<< x << endl;
    }
        
    
    return 0;
} 


Measured memory_bytes: 3112
//#include <bits/stdc++.h>
#include<iostream>
#include<climits>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<stdio.h>
#include <string>
#include <complex>
#include <functional>
#include <map>
#include <queue>
#include <cctype>
using namespace std;
using ll = long long;
const int mod = 1000000007;

ll gcd(ll a, ll b){return b ? gcd(b,a%b) : a;};//最大公約数
ll lcm(ll a, ll b){return a*b/gcd(a,b);};//最小公倍数
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
//typedef pair<string,string> P;
//double dat[100][100];
//int dp[6][1010];//動的計画法
//int prime[100001];
//char str[1010][1010];
//typedef pair<ll,ll> A;
//vector<A> pc;
//int ABS(int a){return max(a,-a);}
//ll a[100000];
//ll dom[100001];

int main(){
  ll n;
  cin>>n;
  ll p = (ll)log2(n);
  ll ans=0;
  //cout<<p;
  while(p){
    ans+=(ll)pow(2,p);
    p--;
  }
  ans++;
  cout<<ans;
   return 0;
}

Measured memory_bytes: 512
N = int(input())
def dfs(s):
  if len(s) == N:
    print(s)
    return
  else:
    for i in range(ord("a"), ord("z")+1):
      if i < ord(max(list(s)))+2:
        dfs(s+chr(i))
      else:
        return
dfs("a")

Measured memory_bytes: 4412
// ------------------------------------
// Date:2018/ 3/ 6
// Problem:ABC 080 a a.cpp
//
// ------------------------------------

#include <bits/stdc++.h>

using namespace std;

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

typedef long long ll;

static const int MOD = 1000000007;

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

  int N, A, B;
  cin >> N >> A >> B;

  int sum = A * N;
  cout << min(sum, B) << endl;
  
  return 0;
}



Measured memory_bytes: 384
N=int(input())
h=list(map(int,input().split()))
max_counter=0
counter=0
for i in range(N-1):
    if h[i]<h[i+1]:
        max_counter=max(max_counter,counter)
        counter=0
    else:
        counter+=1

if counter>max_counter:
    max_counter=counter
print(max_counter)

Measured memory_bytes: 15020
import java.util.*;
import static java.lang.Integer.*;
//import static java.lang.Long.*;
//import static java.lang.Math.*;
import static java.lang.System.*;
import static java.lang.Math.*;

public class Main {
	public static void main(String[] args) {
		int i,j;
		Scanner sc = new Scanner(in);
		char[] s = sc.next().toCharArray();
		sc.close();
		s[3] = '8';
		out.println(new String(s));
	}
}


Measured memory_bytes: 21588
#include <algorithm>
#include <climits>
#include <iostream>
#include <iomanip>
#include <random>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using std::cin;
using std::cerr;
using std::cout;
using std::endl;
using std::make_pair;
using std::pair;
using std::stack;
using std::string;
using std::unordered_map;
using std::unordered_set;
using std::vector;
using std::lower_bound;
using std::upper_bound;

int main(int argc, char* argv[]) {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }

  unordered_map<int, int> count;
  for (int i = 0; i < n; ++i) {
    ++count[a[i]];
  }
  unordered_map<int, long> comb;
  long sum = 0;
  for (const auto c : count) {
    comb[c.first] = 1L * c.second * (c.second - 1) / 2;
    sum += comb[c.first];
  }

  for (int i = 0; i < n; ++i) {
    if (count[a[i]] == 1) {
      cout << sum << endl;
    } else {
      cout << sum - comb[a[i]] + (1l * (count[a[i]] - 1) * (count[a[i]] - 2)) / 2 << endl;
    }
  }

  return 0;
}


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

// why am I so weak

int n, p;
int a[55];
int dp[55][55];

int comb(int n, int k) {
	if (k == 0 || k == n) return 1;
	return dp[n][k] = comb(n - 1, k) + comb(n - 1, k - 1);
}
int main() {
	cin >> n >> p;

	int odd = 0, even = 0;

	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);

		if (a[i] & 1) odd++;
		else even++;
	}

	long long res = 0ll;

	if (p == 0) {
		for (int i = 0; i <= odd; i += 2) {
			res += (1ll << even) * comb(odd, i);
		}
	} else {
		for (int i = 1; i <= odd; i += 2) {
			res += (1ll << even) * comb(odd, i);
		}
	}

	printf("%lld\n", res);

	return 0;
}


Measured memory_bytes: 256
N = int(input())
List = list(map(int,input().split()))

ans = 1
c=0
for i in range(N):
  a = List[i]
  ans *= a
  if ans > 10**18:
    c=1
    break
d =0
for i in range(N):
  a = List[i]
  if a == 0:
    d = 1
    
if d == 1:
  print(0)
elif c ==1:
  print(-1)
else:
  print(int(ans))

Measured memory_bytes: 21636
#include <stdio.h>

long int max_yakusu(long int, long int);

int main(void) {
	long int a, b;
	long int x, y;
	
	while (scanf("%ld%ld", &a, &b) != EOF) {
		if( a == b)
			x = a;
		else
			x = max_yakusu(a, b);
		y = a/x*b;
		printf("%ld %ld\n", x, y);
	}
	
	return 0;
}

long int max_yakusu(long int a, long int b){
	long int answer;
	long int swap;
	
	
	if( a < b) {
		swap = a;
		a = b;
		b = swap;
	}
	swap = b;
	
	b = a - b;
	a = swap;
	if ( a == b)
		answer = a;
	else
		answer = max_yakusu(a, b);
	return answer;
}

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

using namespace std;
typedef long long ll;
#define all(x) (x).begin(), (x).end()
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<bool>> vvb;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
void debugF(ostream &os) {os << endl;}
template <typename Head, typename... Tail>
void debugF(ostream &os, Head H, Tail... T) { os << " " << H; debugF(os, T...); }
#define debug(...) cout << "[" << #__VA_ARGS__ << "]:", debugF(cout, __VA_ARGS__)
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); os << (i>0 ? " ":"") << v[i++]); return os;}


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, x, y, z;
    cin >> n;
    vi ans(n+1, 0);
    for(x=1;x*x <= n; x++){
        for(y=1;y*y <= n;y++){
            for(z=1;z*z <= n; z++){
                int sm = x*x + y*y + z*z + x*y + x*z + y*z;
                if(sm <= n) ans[sm]++;
            }
        }
    }
    for(x=1;x<=n;x++) cout << ans[x] << "\n";   
    return 0;
}

Measured memory_bytes: 3660
S = input()
l = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']

for x in l:
    if x not in S:
        print(x)
        exit()

print('None')

Measured memory_bytes: 9056
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <list>
#include <cmath>

auto& in = std::cin;
auto& out = std::cout;
#define all_range(C) std::begin(C), std::end(C)
const double PI = 3.141592653589793238462643383279502884197169399375105820974944;

int dp[110000];
int func(int x) {
	if (x < 0) {
		return 0;
	}
	if (x == 0) {
		return 1;
	}
	if (dp[x]!=-1) {
		return dp[x];
	}

	dp[x] = 0;
	dp[x] |= func(x - 100);
	dp[x] |= func(x - 101);
	dp[x] |= func(x - 102);
	dp[x] |= func(x - 103);
	dp[x] |= func(x - 104);
	dp[x] |= func(x - 105);
	return dp[x];
}

template<typename T, typename U>
std::enable_if_t<std::rank<T>::value == 0> fill_all(T& arr, const U& v) {
	arr = v;
}
template<typename ARR, typename U>
std::enable_if_t<std::rank<ARR>::value != 0> fill_all(ARR& arr, const U& v) {
	for (auto& i : arr) {
		fill_all(i, v);
	}
}

int main()
{
	int32_t N;
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);
	in.tie(nullptr);
	out.tie(nullptr);

	in >> N;
	fill_all(dp, -1);
	out << func(N) << endl;

	return 0;
}
#endif


Measured memory_bytes: 768
// Problem : D - Replacing
// Contest : AtCoder - AtCoder Beginner Contest 171
// URL : https://atcoder.jp/contests/abc171/tasks/abc171_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
#define F first
#define S second
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define pb push_back
#define mk make_pair
#define fast                    \
  ios_base::sync_with_stdio(0); \
  cin.tie(0);                   \
  cout.tie(0);
#define rep(i, a, b) for (ll i = a; i < b; i++)
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define sz(x) (int)x.size()
#define mem(a, val) memset(a, val, sizeof(a))
#define deci(x) cout << fixed << setprecision(x);
#define bitcount(x) __builtin_popcountll(x)

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

const long long int mod = 1e9 + 7;
const long double EPS = 1e-12;
const int N = 1e5 + 20;

ll A[N];

void solve() {
  ll n, ans = 0;
  cin >> n;
  rep(i, 0, n) {
    ll temp;
    cin >> temp;
    ans += temp;
    A[temp]++;
  }
  ll q;
  cin >> q;
  while (q--) {
    ll b, c;
    cin >> b >> c;
    ans += (A[b] * (c - b));
    A[c] += A[b];
    A[b] = 0;
    cout << ans << '\n';
  }
}
int main() {
  fast;
  ll t;
  t = 1;

  // cin>>t;

  while (t--) {
    solve();
  }

  return 0;
}


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

int main() {
 int N, K;
 int A =1;
  cin >> N >> K ;
  rep(i, N) {
 if(A>=K){
  A +=K;
 }
 else{
 A *=2;
 }
  }
cout  << A << endl;
}

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

struct UnionFind {
    vector<int> r;

    UnionFind(int N) {
        r = vector<int>(N, -1);
    }

    int root(int x) {
        if (r[x] < 0) return x;
        return r[x] = root(r[x]);
    }

    bool unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (r[x] > r[y]) swap(x, y);
        r[x] += r[y];
        r[y] = x;
        return true;
    }

    int size(int x) {
        return -r[root(x)];
    }
};

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

    UnionFind UF(N);
    for (int i = 0; i < M; i++) {
        int A, B;
        cin >> A >> B;
        A -= 1; B -= 1;
        UF.unite(A, B);
    }

    int ans = 0;
    for (int i = 0; i < N; i++) {
        ans = max(ans, UF.size(i));
    }

    cout << ans << endl;
    return 0;
}

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

std::vector< std::tuple<long, long> > graph[112345];
int V, E, r;
long dist[112345];
const long INF = (1LL << 60);

int main() {
  for(long& I : dist) I = INF;
  scanf("%d %d %d", &V, &E, &r);
  for(int i = 0; i < E; ++i) {
    int s, t, d;
    scanf("%d %d %d", &s, &t, &d);
    graph[s].push_back(std::tuple<long, long>(t, d));
  }

  // node cost / id
  std::priority_queue< std::tuple<long, long> >q;
  dist[r] = 0;
  q.push(std::tuple<long, long>(0, r));
  while( not q.empty() ) {
    long cost, id;
    std::tie(cost, id) = q.top(); q.pop();
    cost = -cost;
    for(int i = 0; i < (int)graph[id].size(); ++i) {
      long next, edgecost;
      std::tie(next, edgecost) = graph[id][i];
      if( dist[next] > cost + edgecost ) {
        dist[next] = cost + edgecost;
        q.push(std::tuple<long, long>(-dist[next], next));
      }
    }
  }

  for(int i = 0; i < V; ++i) {
    if( dist[i] == INF ) {
      puts("INF");
    }
    else {
      printf("%ld\n", dist[i]);
    }
  }
  
  return 0;
}

Measured memory_bytes: 19812
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b;
  cin>>a>>b;
  int cnt=0;
  if(a>b){
    cnt+=a;
    a--;
  }else{
    cnt+=b;
    b--;
  }
  if(a>b){
    cnt+=a;
    a--;
  }else{
    cnt+=b;
    b--;
  }
  cout<<cnt<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define mod 1000000007
#define mod2 1000000000
#define mod1 998244353
#define lol ios_base::sync_with_stdio(false);cin.tie(NULL);
#define all(x) (x).begin(), (x).end()
#define F(i, n) for (ll (i) = 0; (i) < (n); (i)++)
#define pb push_back
#define pf push_front
#define mp make_pair
#define f first
#define ss second
int main()
{
    ll a,b,c;
    ll k;
    ll sum = 0;
    cin >> a >> b >> c >> k;
    if(k<=a)
    {
        cout << k << endl;
        return 0;
    }
    else
    {
        k = k-a;
        sum = sum + a;
    }
    if(k<=b)
    {
        cout << sum << endl;
        return 0;
    }
    else
    {
        k = k-b;
    }
    cout << sum-k << endl;
}
    

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


int main() {
  ll x;
  cin >> x;
  for(int a=0;a<2000;a++){
    for(int b=-2000;b<2000;b++){
      ll q=pow(a,5)-pow(b,5);
      if(x==q){cout << a << " " << b << endl;
      return 0;}
    }
  }
}

Measured memory_bytes: 4188
import java.util.Scanner;

class Main{

	public static void main(String[] args) {




		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int K = scan.nextInt();
		
		int x = N % 500;
		boolean flag = false;
		if(x > K){
			System.out.println("No");
		}else{
			System.out.println("Yes");

		}
		
	}


}


Measured memory_bytes: 22992
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;
ll solve(ll n,ll k){
  while(n>k*k) {
    if(n%k==0) return n/k;
    n-=(n/k)+1;
  }
  if(n%k==0) return n/k;
  while(n>0){
    ll lb=0,rb=n;
    while(rb-lb>1){
      ll mid=(lb+rb)/2;
      ll nn=n-mid*(n/k+1);
      if(nn/k==n/k) lb=mid;
      else rb=mid;
    }
    ll n_n=n-lb*(n/k+1);
    if(n_n%k==0) return n_n/k;
    n=n_n;
    n-=(n/k+1);
  }
  return n;
}
int main(){
  ll n;
  cin>>n;
  ll ans=0;
  for(int i=0;i<n;i++){
    ll a,k;
    cin>>a>>k;
    ans^=solve(a,k);
  }
  cout<<(ans==0?"Aoki":"Takahashi")<<endl;
}


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

using namespace std;

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    if (a == b)
        cout << c;
    else if (a == c)
        cout << b;
    else
        cout << a;
    cout << endl;
    return 0;
}


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

using namespace std;

string backtrack(vector<vector<int>> dp, int n, int m, string s, string t) {
    int i = n;
    int j = m;
    string ans="";
    while(i!=0 && j!=0) {
        if(dp[i][j] == dp[i-1][j]) {
                i=i-1;
            } else if(dp[i][j] == dp[i][j-1]) {
                j=j-1;
        }
        else {
            ans+=s[i-1];
            i = i-1;
            j = j-1;
        }
    }
    reverse(ans.begin(), ans.end());
    return ans;
}

int main() {
	string s,t;
	cin>>s>>t;
	int n = s.length();
	int m = t.length(); 
  	vector<vector<int>> dp(n+1,vector<int> (m+1,0));
  	
  	for(int i=1; i<=n; i++) {
    	for(int j=1; j<=m; j++) {
        	if( s[i-1] == t[j-1]) {
        	    dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
        	    dp[i][j] = max(dp[i-1][j-1]+1, dp[i][j]);
        	} else {
        	    dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
        	}
        }
    }
    //cout<<dp[n][m];
    cout<<backtrack(dp,n,m,s,t);
    /*for(int i=0;i<=n;i++) {
		for(int j=0; j<=k; j++) {
			cout<<dp[i][j]<<" ";
		}
		cout<<endl;
	}*/
  	//cout<<dp[n][m];
	return 0;
}

Measured memory_bytes: 70912
#include<bits/stdc++.h>
#define ri register int
#define ll long long
using namespace std;

int main(void){
	int n,d;
	cin>>n>>d;
	int num=0;
	double judge=(double)d*d;
	for(ri i=1;i<=n;i++){
		int x,y;cin>>x>>y;
		double hh=(double)((double)x*x+(double)y*y);
		if(hh<=judge) num++;
	}
	cout<<num<<endl;
	return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x,h,w) (y) < 0 || (h) <= (y) || (x) < 0 || (w) <= (x)
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
const long double pi = acos(-1);
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; }return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; }return 0; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& input, vector<T>& v) { for (auto& elemnt : v)input >> elemnt; return input; }

int main() {
    init();

    int r; cin >> r;
    if (r < 1200)cout << "ABC\n";
    else if (r < 2800)cout << "ARC\n";
    else cout << "AGC\n";
}


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

int main(){
  int N,M;
  cin >> N >> M;
  vector<tuple<int,int,int>> vec(M);
  for(int i=0; i<M; i++){
    int a,b;
    cin >> a >> b;
    vec.at(i) = make_tuple(a,b,i);
  }
  sort(vec.begin(),vec.end());

  int num = 0;
  int x = get<0>(vec.at(0));
  
  vector<vector<int>> ans(M,vector<int>(3));
  
  for(int i=0; i<M; i++){
    int y = get<0>(vec.at(i));
    if(x != y){
      num = 0;
      x = get<0>(vec.at(i));
    }
    num++;
    int z = get<2>(vec.at(i));
    ans.at(i).at(0) = z;
    ans.at(i).at(1) = x;
    ans.at(i).at(2) = num;
  }
  
  sort(ans.begin(),ans.end());
  
  for(int i=0; i<M; i++){
    cout << setfill('0') << right << setw(6) << ans.at(i).at(1);
    cout << setfill('0') << right << setw(6) << ans.at(i).at(2);
    cout << endl;
  }
}

Measured memory_bytes: 8192
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 105;

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

int main(){
	int i, mx = 0, s = 0;
	scanf("%d", &n);
	for(i = 1; i <= n; ++ i)
		scanf("%d", &a[i]);
	for(i = 1; i <= n; ++ i)
		scanf("%d", &b[i]), s += b[i];
	for(i = 1; i <= n; ++ i){
		s += a[i];
		if(s > mx) mx = s;
		s -= b[i];
	} printf("%d\n", mx);
	return 0;
}

Measured memory_bytes: 256
from bisect import bisect

N, Q = map(int, input().split())

ans = (N-2)*(N-2)
wx = wy = 0
Ax = []
Ay = []

for _ in range(Q):
    t, p = map(int, input().split())
    p = N-p
    
    if t==1:
        i = bisect(Ax, (p, 0))
        if i==len(Ax):
            Ax.append((p, wy))
            wx = p
            rev = N-2-wy
        else:
            rev = N-2-Ax[i][1]
    else:
        i = bisect(Ay, (p, 0))
        if i==len(Ay):
            Ay.append((p, wx))
            wy = p
            rev = N-2-wx
        else:
            rev = N-2-Ay[i][1]

    ans -= rev

print(ans)


Measured memory_bytes: 29388
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#define REP(i, n) for(i=0; i<n; i++)
#define REPR(i, n) for(i=n; i>=0; i--)
#define FOR(i, m, n) for(i=m; i<n; i++)
#define INF 100000000
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;

int main() {
    ll n, i, j, a, b, c, d, ans=0;
    cin >> n;
    
    vector<p> red ,blu;
    
    for(i=0; i<n; i++) {
        cin >> a >> b;
        red.push_back(make_pair(b, a));
    }
    for(i=0; i<n; i++) {
        cin >> c >> d;
        blu.push_back(make_pair(c, d));
    }
    
    sort(red.begin(), red.end());
    sort(blu.begin(), blu.end());
    
    for(i=n-1; i>=0; i--) {
        for(j=0; j<n; j++) {
            if(red[i].first!=INF && blu[j].first!=INF && red[i].second<blu[j].first && red[i].first<blu[j].second) {
                ans++;
                red[i].first=INF;
                blu[j].first=INF;
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
const int mod = 1e9 + 7;
const int INF = 1e9;
const double pi = acos(-1.0);
typedef long long ll;
typedef vector<ll> vll;
typedef vector<int> vi;
int main(){
    ll a;
    double b;
    cin >> a >> b;
    ll B = round(b*100);
    //cout << B << e\ndl;

    cout << (a*B)/100 << endl;
    return 0;
}  

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

int main()
{
    int N,M;
    cin >> N >> M;
    int a, b;
    vector<pair<long long,long long>> AB(N);
    rep(i,N){
        cin >> a >> b;
        AB[i] = make_pair(a,b);
    }
    sort(AB.begin(),AB.end());

    long long n = 0,kingaku = 0;

    rep(i,N){
        if (n+AB[i].second>=M){
            kingaku = kingaku + (M-n) * AB[i].first;
            break;
        }else{
            n+=AB[i].second;
            kingaku = kingaku + AB[i].second * AB[i].first;
        }
    }

    cout << kingaku;

    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define pb push_back 
#define mp make_pair
using namespace std;

const int maxn=2e5+7;
typedef long long ll;

struct My{
	int l,r;
	pair<int,int> p;
	My(int L,int R,pair<int,int>P)
		:l(L),r(R),p(P) {}
};

bool operator<(const My &a,const My &b)
{
	if(a.p>b.p) return 1;
	return 0;
}

priority_queue<My>q;

vector<pair<int,int> >ans;

vector<int>b1,b2;

int n;
int h1,h2;

int a[maxn];
int pos[maxn];
//int f[maxn];

struct node{
	int l,r;
	int min;
	void update(int v)
	{
		min+=v;
	}
	
}tree[maxn*4],tree2[maxn*4];

void push_up(int o)
{
	tree[o].min=min(tree[o<<1].min,tree[o<<1|1].min);
}

void build(int l,int r,int o)
{
	tree[o].l=l;tree[o].r=r;
	if(l==r)
	{
		tree[o].min=b1[l];
	}
	else
	{
		int mid=(l+r)/2;
		build(l,mid,o<<1);
		build(mid+1,r,o<<1|1);
		push_up(o);
	}
}

void update(int p,int x,int o)
{
	
}

int qmin;
void query(int ql,int qr,int o)
{
	int l=tree[o].l,r=tree[o].r;
	if(ql<=l&&r<=qr)
	{
		qmin=min(qmin,tree[o].min);
	}
	else
	{
		int mid=(l+r)/2;
		if(ql<=mid) query(ql,qr,o<<1);
		if(qr>mid) query(ql,qr,o<<1|1);
	}
}


///////////////////////////////////////
///////////////////////////////////////



void push_up2(int o)
{
	tree2[o].min=min(tree2[o<<1].min,tree2[o<<1|1].min);
}

void build2(int l,int r,int o)
{
	tree2[o].l=l;tree2[o].r=r;
	if(l==r)
	{
		tree2[o].min=b2[l];
	}
	else
	{
		int mid=(l+r)/2;
		build2(l,mid,o<<1);
		build2(mid+1,r,o<<1|1);
		push_up2(o);
	}
}

void update2(int p,int x,int o)
{
	
}

void query2(int ql,int qr,int o)
{
	int l=tree2[o].l,r=tree2[o].r;
	if(ql<=l&&r<=qr)
	{
		qmin=min(qmin,tree2[o].min);
	}
	else
	{
		int mid=(l+r)/2;
		if(ql<=mid) query2(ql,qr,o<<1);
		if(qr>mid) query2(ql,qr,o<<1|1);
	}
}

int Q1(int l,int r)
{
	l=(l+1)/2;
	r=(r+1)/2;
	qmin=1e9;
	query(l,r,1);
	return pos[qmin];
}

int Q2(int l,int r)
{
	l=(l)/2;
	r=(r)/2;
	qmin=1e9;
	query2(l,r,1);
	return pos[qmin];
}

int num1,num2;




pair<int,int> work(int l,int r)
{	
	
	if(l+1==r)
	{
		return mp(a[l],a[r]);
	}
	
	int i,j,k;
	
	
	
	if(l%2==1)
	  num1=Q1(l,r);
	else num1=Q2(l,r);
	
	
	if(l%2==1) num2=Q2(num1+1,r);
	else num2=Q1(num1+1,r);
	
	//ans.pb(mp(a[num1],a[num2]));
	/*
	work(l,num1-1);
	work(num2+1,r);
	work(num1+1,num2-1);
	*/
	
	return mp(a[num1],a[num2]);
}





void doit()
{
	q.push(My(1,n,work(1,n)));
	while(!q.empty())
	{
		My now=q.top();
		q.pop();
		ans.pb(now.p);
		int l,r,l1,r1;
		l=now.l;
		r=now.r;
		l1=pos[now.p.first];
		r1=pos[now.p.second];
		if(l<l1-1) q.push(My(l,l1-1,work(l,l1-1)));
		if(l1+1<r1-1) q.push(My(l1+1,r1-1,work(l1+1,r1-1)));
		if(r1+1<r) q.push(My(r1+1,r,work(r1+1,r)));
	}
}

int main()
{
	int i,j,k;
	scanf("%d",&n);
	b1.pb(0);
	b2.pb(0);
	for(i=1;i<=n;++i)
	{
		scanf("%d",&a[i]);
		pos[a[i]]=i;
		if(i&1)
		{
			b1.pb(a[i]);
		}
		else b2.pb(a[i]);
	} 
	
	h1=b1.size()-1;
	h2=b2.size()-1;
	
	build(1,h1,1);
	build2(1,h2,1);
	
	doit();
	
	
	int len=ans.size();
	
	for(i=0;i<len-1;++i)
	{
		printf("%d %d ",ans[i].first,ans[i].second);
	}
	
	printf("%d %d\n",ans[len-1].first,ans[len-1].second);
	
	
	return 0;
}


Measured memory_bytes: 15688