akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<set>
#include<map>

using namespace std;

#define x first
#define y second
#define NMAX 100005

long long n,v[NMAX], sum, diff, oper, fac[NMAX], answer[NMAX];

int main (){
    
    scanf("%lld",&n);
    for(int i = 1; i <= n; i++){
        scanf("%lld",&v[i]);
        sum += v[i];
    }
    long long num = sum / (n * (n + 1) / 2);
    v[n + 1] = v[1];
    for(int i = 1; i <= n; i++){
        diff = v[i + 1] - v[i];
        if((num - diff) % n != 0){
            printf("NO\n");
            return 0;
        }
        if(num - diff < 0){
            printf("NO\n");
            return 0;
        }
        fac[i + 1] = (num - diff) / n;
        oper += (num - diff) / n;
      //  printf("%lld ", fac[i]);
    }
    //printf("\n");
    fac[1] = fac[n + 1];
    if(oper != num){
        printf("NO\n");
        return 0;
    }
    
    long long cost = 0, taken = 0;
    for(int i = 1; i <= n; i++){
        taken += fac[i];
        cost += taken;
        answer[i] += cost;
    }
    
    for(int i = 1; i <= n; i++){
        taken -= fac[i];
        cost += taken - fac[i] * n;
        answer[i] += cost;
    }
    
    for(int i = 1; i <= n; i++)
        if(answer[i] != v[i]){
            printf("NO\n");
            return 0;
        }
    
    printf("YES\n");
    
    return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef long long ll;

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

    int A, B, C,D;
    cin >> A >> B >> C >> D ;

    int tk = (C+B-1)/B;
    int ak = (A+D-1)/D;

    if (tk <= ak){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

}


Measured memory_bytes: 3636
#include "bits/stdc++.h"
using namespace std;
#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define LLINF ((long long) 1e18)//1234567890987654321
#define INF 1234567890ll
#define pb emplace_back
#define ins insert
#define f first
#define s second	
#define db 0
#define EPS (1e-7)    //0.0000001 the value
#define PI (acos(-1))
#define MAXN (300006)
#define MAXK 26
#define MAXX 15000006
#define ll long long int 
#define ld long double
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
#define FOR(ii, ss, ee) for(ll ii = ss; ii < ee; ++ii)
#define space " "
#define cbr cerr << "hi\n"
#define mmst(x, v) memset((x), v, sizeof ((x)))
#define siz(x) ((ll)x.size())
#define ph emplace
#define btinpct(x) __builtin_popcountll(x)
#define p2(x) (1LL<<(x))
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
typedef pair <ll, ll> pi;
typedef pair <ll, pi> spi;
typedef pair <pi, pi> dpi;
inline ll rand(ll x, ll y) { ++y; return (rng() % (y-x)) + x; } //inclusivesss
ll n,p[20006];
ll magic=30000;
int main()
{
	FAST
	cin>>n;
	FOR(i,0,n){
		ll a; cin>>a;
		p[a-1]=i;
	}
	FOR(i,0,n){
		cout<<(i+1)*magic<<' ';
	}
	cout<<'\n';
	FOR(i,0,n){
		cout<<(n-i-1)*magic+(p[i]+1)<<' ';
	}
	cout<<'\n';
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
int mp[10][10],b[10][10];

void mark(int y,int x){
  int dx[]={0,0,1,-1},dy[]={1,-1,0,0};
  for(int i=0;i<4;i++) {
    int nx=x+dx[i],ny=y+dy[i];
    if(nx<0||ny<0||nx>=10||ny>=10)continue;
    mp[ny][nx]=!mp[ny][nx];
  }
  mp[y][x]=!mp[y][x];
}

bool check(){
  for(int i=0;i<10;i++)
    for(int j=0;j<10;j++)if(mp[i][j])return 0;
  return 1;
}

void copy(int a[10][10],int b[10][10]){
  for(int i=0;i<10;i++)for(int j=0;j<10;j++)a[i][j]=b[i][j];
}

int main(){
  int q;
  cin>>q;
  while(q--){
    for(int i=0;i<10;i++)for(int j=0;j<10;j++)cin>>mp[i][j];
    copy(b,mp);
    int ans[10][10]={};
    for(int i=0;!check();i++){
      copy(mp,b),copy(b,mp);
      for(int j=0;j<10;j++)if((ans[0][j]=(i>>j)%2))mark(0,j);
      
      for(int j=1;j<10;j++)
	for(int k=0;k<10;k++)
	  if((ans[j][k]=mp[j-1][k]))mark(j,k);
    }

    for(int i=0;i<10;i++){
      for(int j=0;j<10;j++){
	if(j) cout <<" ";
	cout << ans[i][j];
      }
      cout <<endl;
    }
  }
  return 0;
}

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

int main() {
	int N;
	double a[60];
	double ave = 0;
	vector<double> v;
	cin >> N;
	for (int i = 0; i < N; ++i) {
		cin >> a[i];
		v.push_back(a[i]);
	}

	sort(v.begin(), v.end());
	ave = (v[0] + v[1]) / 2;

	for (int i = 2; i < N ; ++i) {
		ave = (ave + v[i]) / 2;
	}

	cout << ave << endl;
}

Measured memory_bytes: 256
from collections import Counter
N = int(input())
D = list(map(int,input().split()))
M = int(input())
T = list(map(int,input().split()))
Tcount = Counter(T)
flag = 'YES'
Dcount = Counter(D)
for n,c in Tcount.items():
    if n not in Dcount:
        flag = 'NO'
        break
    if c > Dcount[n]:
        flag = 'NO'
        break
print(flag)

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

int main() 
{
    int n,count=0;
    cin>>n;
    char a[n];
    cin>>a;
    
    for(int i=0;i<n-1;i++){
        if(a[i]!=a[i+1]) count++;
    }
    if(a[n-1]!=a[n])
    count++;
    cout<<count;
    
	return 0;
}

Measured memory_bytes: 384
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}

const ll mod=1e9+7;

int main(){
    string a,b;
    cin >> a >> b;
    bool ok=false;
    for(ll i=1;i<=1000;i++){
        string ans=to_string(i*i);
        if(a+b==ans){
            ok=true;
            break;
        }
    }
    if(ok) cout << "Yes" << endl;
    else cout << "No" << endl;
} 


Measured memory_bytes: 3664
// Fuwa Fuwa Time!

#include <bits/stdc++.h>

using namespace std;

#define DEBUG(...) fprintf(stderr, __VA_ARGS__)
#define mp make_pair
#define fst first
#define snd second
#define SZ(u) ((int) (u).size())
#define ALL(u) (u).begin(), (u).end()

inline void proc_status()
{
	ifstream t("/proc/self/status");
	cerr << string(istreambuf_iterator<char>(t), istreambuf_iterator<char>()) << endl;
}

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }
template<typename T> inline T read()
{
	register T sum(0), fg(1);
	register char ch(getchar());
	for(; !isdigit(ch); ch = getchar()) if(ch == '-') fg = -1;
	for(;  isdigit(ch); ch = getchar()) sum = sum * 10 - '0' + ch;
	return sum * fg;
}

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

const int MAXN = (int) 1e5;

int n;

int a[MAXN + 5];

inline void input()
{
	n = read<int>();
	for(int i = 1; i <= n; ++i) a[i] = read<int>();
}

inline void solve()
{
	sort(a + 1, a + n + 1);
	if(a[n] - a[1] > 1) { puts("No"); return; }
	if(a[1] == a[n]) puts(a[1] == n - 1 || a[1] <= n / 2 ? "Yes" : "No");
	else
	{
		int p = upper_bound(a + 1, a + n + 1, a[1]) - a - 1;
		int res = p + (n - p) / 2;
		puts(a[n] > p && n - p > 1 && a[n] <= res ? "Yes" : "No");
	}
}

int main()
{
#ifdef K_ON // K-ON!
	freopen("B.in", "r", stdin);
	freopen("B.out", "w", stdout);
#endif

	input();
	solve();

	return 0;
}



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

int main(){
	int n,m,a,i,j;
	for( ; cin >> n , n ; cout << a << endl ){
		for(a=0,i=n/2 ;j=m=i ;i-- )
			for( ; m < n ; m==n?a++:0 )
				m += ++j;
	}
}

Measured memory_bytes: 0
n, h = gets.split.map(&:to_i)
Ary = readlines.map(&:chomp!).map { |e| e.split.map(&:to_i) }
huri_max = Ary.max_by { |e| e[0] }

count = 0
Ary.sort_by! { |e| e[1] }.reverse_each do |katana|
  if katana[1] > huri_max[0]
    h -= katana[1]
    count += 1
    if h <= 0
      puts count
      exit
    end
  end
end

count += h / huri_max[0]
count += 1 if h % huri_max[0] != 0

puts count


Measured memory_bytes: 20600
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, a, b) for (int i = (a); i < (b); i++)
//#include "library/debug.cpp"

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

    int h, w, a, b;
    cin >> h >> w >> a >> b;
    if (h % a == 0 && w % b == 0) {
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;
    bool swp = false;
    if (w % b == 0) {
        swp = true;
        swap(w, h);
        swap(a, b);
    }
    vector<int> s(w + 1);
    for (int i = w; i >= 0; i -= b) {
        s[i] = (w - i) / b + 1;
    }
    int cnt = 0;
    rep(i, 0, w) {
        if (s[i] != 0)
            cnt--;
        else
            s[i] = cnt;
    }
    vector<int> x(w);
    rep(i, 0, w) x[i] = s[i + 1] - s[i];
    if (!swp) {
        rep(i, 0, h) {
            rep(j, 0, w) cout << x[j] << ' ';
            cout << endl;
        }
    } else {
        rep(i, 0, w) {
            rep(j, 0, h) cout << x[i] << ' ';
            cout << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 1408
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.stream.IntStream;
import java.util.List;
import java.util.Arrays;
import java.util.stream.Stream;
import java.util.Scanner;
import java.util.Comparator;
import java.util.stream.Collectors;

/**
 * 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);
        C solver = new C();
        solver.solve(1, in, out);
        out.close();
    }

    static class C {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int N = in.nextInt();

            int[] A = new int[N];
            for (int i = 0; i < N; i++) {
                A[i] = in.nextInt();
            }
            List<Integer> posi = Arrays.stream(A).filter(n -> 0 <= n).mapToObj(n -> Integer.valueOf(n)).collect(Collectors.toList());
            List<Integer> nega = Arrays.stream(A).filter(n -> 0 > n).mapToObj(n -> Integer.valueOf(n)).collect(Collectors.toList());
            posi.sort(Comparator.naturalOrder());
            nega.sort(Comparator.naturalOrder());

            StringBuilder sb = new StringBuilder();
            int ret;
            if (posi.isEmpty()) {
                ret = nega.remove(nega.size() - 1);
                for (Integer n : nega) {
                    sb.append(ret).append(' ').append(n).append(System.lineSeparator());
                    ret -= n;
                }
            } else if (nega.isEmpty()) {
                ret = posi.remove(0);
                int temp = posi.remove(posi.size() - 1);
                for (Integer n : posi) {
                    sb.append(ret).append(' ').append(n).append(System.lineSeparator());
                    ret -= n;
                }
                sb.append(temp).append(' ').append(ret).append(System.lineSeparator());
                temp -= ret;
                ret = temp;
            } else {
                ret = posi.remove(posi.size() - 1);
                int temp = nega.remove(0);
                for (Integer n : posi) {
                    sb.append(temp).append(' ').append(n).append(System.lineSeparator());
                    temp -= n;
                }
                for (Integer n : nega) {
                    sb.append(ret).append(' ').append(n).append(System.lineSeparator());
                    ret -= n;
                }
                sb.append(ret).append(' ').append(temp).append(System.lineSeparator());
                ret -= temp;
            }
            out.println(ret);
            out.print(sb.toString());
        }

    }
}



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

typedef long long ll;

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

    ll ans = 0;
    for(int b = k+1; b <= n; b++){
        int segment = n / b;
        ans += (ll)segment * (b-k) + (ll)max(0, n%b+1-k) - (k == 0);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)

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

//------------------------------------------------
int main(){
  int a,b,ans;
  cin>>a>>b;
  if(a>2*b){
    ans=a-2*b;
  }
  else ans=0;
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define sz(x) (int)(x.size())
#define fi first
#define se second

signed main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int n;
    cin >> n;
    map<int, int> cnt;
    int a[n];
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        cnt[a[i]]++;
    }
    vector<int> two, four;
    for (auto &el : cnt) {
        if (el.se >= 4) {
            four.push_back(el.fi);
        }
        if (el.se >= 2) {
            two.push_back(el.fi);
        }
    }
    int ans = 0;
    sort(four.rbegin(), four.rend());
    sort(two.rbegin(), two.rend());
    if (sz(four) >= 1) {
        ans = max(ans, four[0] * four[0]);
    }
    if(sz(two) >= 2) {
        ans = max(ans, two[0] * two[1]);
    }
    cout << ans << "\n";
}

Measured memory_bytes: 7296
#import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
#import heapq
#from fractions  import gcd
#input=sys.stdin.readline
import bisect
n=input()
l=len(n)
ans=0
d=[(0,0)]*l
d[0]=min(int(n[0]),10-int(n[0])+1),min(int(n[0])+1,10-int(n[0]))
for i in range(1,l):
    ori=min(int(n[i])+d[i-1][0],10-int(n[i])+d[i-1][1])
    ori_1=min(int(n[i])+1+d[i-1][0],10-int(n[i])-1+d[i-1][1])
    d[i]=ori,ori_1
print(d[l-1][0])

Measured memory_bytes: 106704
#include<iostream>
#include<vector>
#include<string>
#include<sstream>
using namespace  std;
vector<string> split(const string &s, char delimiter)
{
	vector<string> ret;
	size_t now = 0, find;
	while ((find = s.find_first_of(delimiter, now)) != string::npos)
	{
		ret.push_back(string(s, now, find - now));
		now = find + 1;
	}
	ret.push_back(string(s, now, s.size() - now));
	return ret;
}
int main()
{
	string in;
	while (cin >> in)
	{
		vector<string> v = split(in, ',');
		int disSum = 0;
		int dis[10];
		int sp[2];
		for (int i = 0; i < v.size(); i++)
		{
			stringstream ss;
			ss << v[i];
			if (i < 10)
			{
				ss >> dis[i];
				disSum += dis[i];
			}
			else
			{
				ss >> sp[i - 10];
			}
		}
		double a = disSum * sp[0] / (sp[0] + sp[1]);
		double b = disSum * sp[1] / (sp[0] + sp[1]);

		double fromStart = 0.0;
		double fromEnd = 0.0;
		int i = 0, j = 0;
		for (i = 0; i < 10; i++)
		{
			if (fromStart >= a)
			{
				break;
			}
			fromStart += dis[i];
		}
		for (j = 9; j >= 0; j--)
		{
			if (fromEnd >= b)
			{
				break;
			}
			fromEnd += dis[j];
		}
		/*cout << i << " " << j << endl;
		cout << a << " " << b << " " << fromStart << " " << fromEnd << endl;*/
		if (fromStart == a && fromEnd == b)
		{
			cout << i << endl;
		}
		else
		{
			if (fromStart == fromEnd)i++;
			cout << i << endl;
		}




	}
	return 0;
}

Measured memory_bytes: 1232
/********************************************************************************
	
	Code by a weak man who named CYJian, and he hope the code can get more points.

	Algorithm: Segment Tree  单调栈

 ********************************************************************************/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int __SIZE = 1 << 18;
char ibuf[__SIZE], *iS, *iT;

#define ge (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, __SIZE, stdin), (iS == iT ? EOF : *iS++)) : *iS++)
#define ri read_int()
#define rl read_ll()
#define FILE(s) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)

template<typename T>
inline void read(T &x) {
	char ch, t = 0; x = 0;
	while(!isdigit(ch = ge)) t |= ch == '-';
	while(isdigit(ch)) x = x * 10 + (ch ^ 48), ch = ge;
	x = t ? -x : x;
}
inline int read_int() { int x; return read(x), x; }
inline ll read_ll() { ll x; return read(x), x; }

template<typename T> inline void chkmax(T&a, T b) { a = a > b ? a : b; }

const int MAXN = 300010;

struct Segment_Tree {
#define ls (x << 1)
#define rs (x << 1 | 1)

	struct Node { int mx, tg; } T[MAXN << 2];

	inline void reset(int n) { for(int i = n << 2; i; --i) T[i] = T[0]; }

	inline void Modify(int x, int l, int r, int L, int R, int v) {
		if(L <= l && r <= R) return T[x].mx += v, T[x].tg += v, void();
		int mid = (l + r) >> 1;
		if(L <= mid) Modify(ls, l, mid, L, R, v);
		if(mid < R) Modify(rs, mid + 1, r, L, R, v);
		T[x].mx = max(T[ls].mx, T[rs].mx) + T[x].tg;
	} // 标记永久化，减小常数

#undef ls
#undef rs
}seg;

struct Node {
	int x, y;

	Node() {}
	Node(int x, int y):x(x), y(y) {}

	friend bool operator < (Node a, Node b) { return a.x < b.x; }
}a[MAXN];

int n, N, M;

inline int solve() {
	sort(a + 1, a + 1 + n);
	stack<Node> S1, S2;
	seg.reset(n);
	int res = 0, lim = M >> 1;
	for(int i = 1; i <= n; i++) {
		int x = a[i].x, y = a[i].y, last_pos = i - 1;
		if(y <= lim) {
			while(!S1.empty() && S1.top().y <= y) {
				if(S1.top().y != y) seg.Modify(1, 1, n, S1.top().x, last_pos, S1.top().y - y);
				last_pos = S1.top().x - 1, S1.pop();
			} if(last_pos < i - 1) S1.push(Node(last_pos + 1, y));
		} else {
			while(!S2.empty() && S2.top().y >= y) {
				if(S2.top().y != y) seg.Modify(1, 1, n, S2.top().x, last_pos, y - S2.top().y);
				last_pos = S2.top().x - 1, S2.pop();
			} if(last_pos < i - 1) S2.push(Node(last_pos + 1, y));
		} S1.push(Node(i, 0)), S2.push(Node(i, M));
		seg.Modify(1, 1, n, i, i, M - a[i].x);
		chkmax(res, seg.T[1].mx + a[i + 1].x);
	} return res << 1;
}

int main() {
	N = ri, M = ri, n = ri;

	for(int i = 1; i <= n; i++) a[i].x = ri, a[i].y = ri;
	a[++n] = Node(0, 0), a[++n] = Node(N, M);
	
	int res = solve();

	for(int i = 1; i <= n; i++) swap(a[i].x, a[i].y);
	swap(N, M);

	cout << max(res, solve()) << endl;
	return 0;
}

Measured memory_bytes: 13468
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int n;
long L,T,X[1<<17],W[1<<17],Y[1<<17];
main()
{
	cin>>n>>L>>T;
	for(int i=0;i<n;i++)cin>>X[i]>>W[i];
	long cnt=0;
	for(int i=1;i<n;i++)
	{
		if(W[i]!=W[0])
		{
			long now=W[0]==1?(2*T-(X[i]-X[0])+L-1)/L:(2*T+(X[i]-X[0])-1)/L;
			cnt+=W[0]==1?now:-now;
			cnt=(cnt+n)%n;
		}
	}
	for(int i=0;i<n;i++)Y[i]=((X[i]+(W[i]==1?T:-T))%L+L)%L;
	long get=Y[0];
	sort(Y,Y+n);
	int id;
	if(W[0]==1)
	{
		for(id=0;Y[id]!=get;id++);
	}
	else
	{
		for(id=n-1;Y[id]!=get;id--);
	}
	for(int i=0;i<n;i++)cout<<Y[(i+id-cnt+n)%n]<<endl;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
typedef long long int llint;
typedef unsigned long long int ullint;
std::string YesNo[] = {"No","Yes"};
#define loop(i,N) for(int i=0; i<(N); i++)
template<typename T>
auto sort_all(T& v) { return std::sort(v.begin(),v.end()); }
template<typename T>
auto sum_all(const T& v) { auto z = v[0]; z = 0;
    return std::accumulate(v.begin(),v.end(),z); }
template<typename T>
auto input(int N) {
    std::vector<T> v(N);
    loop(i,N) std::cin >> v[i];
    return std::move(v);
}

typedef llint Int;
const int M = 80;

int main(void)
{
    int H, W;
    cin >> H >> W;
    vector<vector<int>> A;
    vector<vector<int>> B;
    loop(i, H) {
        A.push_back(input<int>(W));
    }
    loop(i, H) {
        B.push_back(input<int>(W));
    }
    int K = (H+W)*M;
    auto dp = vector<int>((H+1)*(W+1)*K, 0);

    dp[(W+1)*K + K + abs(A[0][0]-B[0][0])] = 1;
    for(int h = 1; h<=H; h++) for(int w=1; w<=W; w++) {
        if (h == 1 && w == 1) {
           continue;
        }
        int p = abs(A[h-1][w-1]-B[h-1][w-1]);
        for (int k=0; k < K; k++) {
            dp[h*(W+1)*K + w*K + (k + p)]    |= dp[(h-1)*(W+1)*K + w*K     + k];
            dp[h*(W+1)*K + w*K + abs(k - p)] |= dp[(h-1)*(W+1)*K + w*K     + k];
            dp[h*(W+1)*K + w*K + (k + p)]    |= dp[h*(W+1)*K     + (w-1)*K + k];
            dp[h*(W+1)*K + w*K + abs(k - p)] |= dp[h*(W+1)*K     + (w-1)*K + k];
        }
    }
    int k;
    for(k = 0; k < K; k++) {
        if (dp[H*(W+1)*K + W*K + k] > 0) {
            cout << k << endl;
            break;
        }
    }

    return 0;
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

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

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b; cin>>a>>b;
    cout<<(a+b+1)/2<<endl;
    return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-

s = input()

first = len(s)
last = 0
for i in range(0, len(s)):
    if s[i] == "A":
        first = min(first, i)
    if s[i] == "Z":
        last = max(last, i)
#print(first, last)
print(len(s[first:last+1]))

Measured memory_bytes: 3516
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int INT_INF = 1LL << 30;

ll N;
vll C(500), S(500), F(500);

ll totaltime(ll n, ll t){ //時刻tにnにいる場合
  if(n == N-1) return t;

  ll next = max(S.at(n), (t + F.at(n) - 1)/F.at(n) * F.at(n)); //次の発車時刻
  return totaltime(n+1, next + C.at(n));

}

int main(){
  
  cin >> N;
  
  for(int i = 0; i < N-1; i++){
    cin >> C.at(i) >> S.at(i) >> F.at(i);
  }
  
  for(int i = 0; i < N; i++){
    cout << totaltime(i, 0) << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long a[200005];
long long b[200005],c[200005];
int main()
{
    long long n,m,i,j,k,x=0,y,z,t;
    cin>>n;
    for(i=2;i<=sqrt(n);i++){
        if(n%i==0){
            x=1;
            break;
        }
    }
    if(x==0){
        cout<<n<<endl;
        return 0;
    }
    j=n+1;
    while(1){
            x=0;
        for(i=2;i<=sqrt(j);i++){
            if(j%i==0){
            x=1;
            break;
        }
        }
    if(x==0){
        cout<<j<<endl;
        return 0;
    }
    j++;
    }

}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include<algorithm>
using namespace std;
typedef long long ll;
int main(){
ll n;
cin >>n;
ll x[n],a[n];
for(ll i=0;i<n;i++){
cin >>x[i];
a[i]=x[i];
}
sort(a,a+n);
ll memo=a[n/2-1];
ll memo1=a[(n/2)];
for(ll i=0;i<n;i++){
if(memo==memo1){
cout <<memo;
}
else{
if(x[i]<memo1){
cout <<memo1;
}
else{
cout <<memo;
}
}
if(i!=n-1)
cout <<endl;
}

return 0;

}

Measured memory_bytes: 5376
import math
import os
import random
import re
import sys
def dpfindpath(a):
	dpath=[int(0) for _ in range(len(a))]
	dpath[0]=0
	dpath[1]=abs(a[1]-a[0])
	for i in range(2,len(a)):
		dpath[i]=min(abs(a[i]-a[i-1])+dpath[i-1],abs(a[i]-a[i-2])+dpath[i-2])
	return dpath[len(a)-1]
n=int(input())
a=input().split()
for i in range(n):
  a[i]=int(a[i])
print (dpfindpath(a))


Measured memory_bytes: 18900
import sys
sys.setrecursionlimit(10**9)
INF=10**18
def input():
    return sys.stdin.readline().rstrip()

def main():
    M=int(input())
    d=[0]*M
    c=[0]*M
    ans=0
    l=[]
    for i in range(M):
        d[i],c[i]=map(int,input().split())
    ans+=sum(c)-1
    x=0
    for i in range(M):
        x+=c[i]*d[i]
    ans+=(x-1)//9
    print(ans)
        
        

if __name__ == '__main__':
    main()


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

using namespace std;
using ll = long long;

using Field = vector<vector<int>>;
using Graph = vector<vector<int>>;
using VI = vector<int>;
using VC = vector<char>;
using PI = pair<int, int>;

#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(x) x.begin(), x.end()

const long long INF = 1LL<<60;
const int mod = 1000000007;

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

int N;
vector<ll> A;
vector<vector<ll>> dp(400, vector<ll>(400, 0));


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

    cin >> N;
    A.resize(N + 1, 0);
    REP(i, N) cin >> A.at(i);

    REP(i, N) dp.at(i).at(i) = 0;

    for (int len = 1; len < N; len++) {
        for (int left = 0; left < N - len; left++) {
            ll tmp = INF;
            ll sum = 0;
            int right = left + len;
            for (int idx = left; idx < right; idx++) {
                tmp = min(tmp, dp.at(left).at(idx) + dp.at(idx + 1).at(right));
                sum  += A.at(idx);
            }
            sum += A.at(right);
            dp.at(left).at(right) = tmp + sum;

        }
    }

    cout << dp.at(0).at(N - 1) << endl;

    
    return 0;
}

Measured memory_bytes: 1536
# -*- coding: utf-8 -*-
n = int(input())
h = list(map(int, input().split()))

result = True
for i in range(n-1, 0, -1):
    diff = h[i-1] - h[i]
    if diff == 1:
        h[i-1] -= 1
    elif diff > 1:
        result = False
        break

if result:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 14396
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
int main(){
    ll n,ans=0;
    cin>>n;
    for(ll i=2;i<=sqrt(n);i++){
        if(n%i==0){
            ll p=n;
            while(p%i==0) p/=i;
            if(p%i==1) ans++;
        }
        else if(n%i==1) ans++;
    }
    for(ll i=1;i<sqrt(n-1);i++){
        if((n-1)%i==0) ans++;
    }
    cout<<ans+1;
}

Measured memory_bytes: 256
#include <float.h>
#include <inttypes.h>
#include <limits.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <math.h>
#ifdef __cplusplus
#include <bits/stdc++.h>
#endif

int32_t nextint(void){ char c=getchar_unlocked(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar_unlocked(); bool s=false; if(c=='-'){s=true;c=getchar_unlocked();} uint32_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar_unlocked(); } return s?-x:x; }

int n;

int p(int a, int b){
	if(a<b){
		return a+b*n;
	}else{
		return b+a*n;
	}
}

int a[1000][999];

int e1[1000000];
int e2[1000000];
int d[1000000];
bool b[1000000];

int f(int from){
	if(b[from]) return -1;
	if(d[from]) return d[from];
	b[from]=true;
	int to;
	to = e1[from];
	int max=0;
	if(to!=0){
		int now=f(to);
		if(now<0) return now;
		if(now>max) max=now;
	}
	to = e2[from];
	if(to!=0){
		int now=f(to);
		if(now<0) return now;
		if(now>max) max=now;
	}
	b[from]=false;
	return d[from]=max+1;
}

int main(void){
	n=nextint();
	for(int i=0; i<n; i++){
		for(int j=0; j<n-1; j++){
			a[i][j]=nextint()-1;
		}
	}
	for(int i=0; i<n; i++){
		for(int j=0; j<n-2; j++){
			int from = p(i, a[i][j]);
			int to = p(i, a[i][j+1]);
			if(e1[from]==0){
				e1[from]=to;
			}else if(e2[from]==0){
				e2[from]=to;
			}else{
				puts("-1");
				return 0;
			}
		}
	}
	int ans=0;
	for(int i=0; i<n; i++){
		int from = p(i, a[i][0]);
		int now=f(from);
		if(now<0){
			ans=-1;
			break;
		}
		if(now>ans) ans=now;
	}
	printf("%d\n", ans);
}


Measured memory_bytes: 16768
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    long A = scanner.nextLong();
    long B = scanner.nextLong();
    long K = scanner.nextLong();

    long da = Math.min(A, K);
    A -= da;
    K -= da;
    long db = Math.min(B, K);
    B -= db;
    System.out.printf("%d %d\n", A, B);
  }
}


Measured memory_bytes: 22228
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    long A = sc.nextLong() -1;
    long B = sc.nextLong();
    long C = sc.nextLong();
    long D = sc.nextLong();
    long E = lcm(C,D);
    
    long big = B - B/C - B/D + B/E;
    long small = A -A/C -A/D + A/E;
    System.out.println(big-small);
    
  }
  private static long lcm(long m,long n){
    return m*n/gcd(m,n);
  }
  private static long gcd(long m,long n){
    if (m<n) return gcd(n,m);
    if (n==0) return m;
    return gcd(n,m%n);
  }
}

Measured memory_bytes: 22100
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T,class U> using P = pair<T,U>;
template<class T> using vec = vector<T>;
template<class T> using vvec = vector<vec<T>>;
 

int main(){
    ll N;
    cin >> N;
    string S, T;
    cin >> S >> T;
    for (int i=0; i<N; i++){
        cout << S[i] << T[i];
    }
    cout << endl;
}

Measured memory_bytes: 256
/*********************************************************************| 
|---------|    /\  ....                  ....                         |         
     |        /  \   \                    /  /------| ----- |-------| |
     |       /    \   \                  /  /           |   |         |
     |      /      \   \       /\       /  |            |   |         |
     |     /        \   \     /  \     /   |---|        |   |----|    |
     |    /__________\   \   /    \   /        |---|    |   |         |
     |   /            \   \ /      \ /              |   |   |         |
     |  /              \   |        |               /   |   |         |
     _ __              __ ...      ...      |------/  ----- _         |
                                                                      |  
        Md Tawsif Rahman                                              |
        Institute Of Information Technology                           |
        Jahangirnagar University                                      |                                                                         
                                                                      |
**********************************************************************/                 
#include<bits/stdc++.h>

using namespace std;
#define ll long long int
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define mp make_pair
#define pii pair <int, int>
#define xx first
#define yy second
#define vc vector < int >
#define vcll vector < ll > 
#define f(i, c, n) for(i = c; i < n; i++)
#define fr(i, n, c) for(i = n - 1; i >= 0; i--) 
#define vbe(a) a.begin(), a.end()
#define mem(a) memset(a, 0, sizeof(a))
#define memn(a) memset(a, -1, sizeof(a))

#define srti(a, n) sort(a, a + n)
#define srtd(a, n) sort(a, a + n, greater<int>())
#define LB(a, x) (lower_bound(vbe(a), x) - a.begin())
#define UB(a, x) (upper_bound(vbe(a), x) - a.begin())

#define fast ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0)

int i, j, k;
vc prime;
vc is_prime;

int gcd(int a, int b) {
    if(b == 0) return a;
    else return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
    return (a * b) / (__gcd(a, b));
}
 
void solve() {

    int N;
  cin >> N;
  vector<int> A(N);
  for (auto i = 0; i < N; ++i)
  {
    cin >> A[i];
  }
  int now{1};
  int ans{0};
  for (auto i = 0; i < N; ++i)
  {
    if (A[i] == now)
    {
      ++ans;
      ++now;
    }
  }
  if (ans == 0)
  {
    ans = N + 1;
  }
  cout << N - ans << endl;
}

int main() {
    // int t; cin >> t; while(t--) 
    solve();
    
   
}  

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>

using namespace std;

int main(){
    int N, H;
    cin >> N >> H;
    int a_max = 0; 
    int b[N];
    for(int i=0; i<N; i++){
        int a;
        cin >> a >> b[i];
        a_max = max(a, a_max);
    } 
    int cnt = 0;
    sort(b, b + N, greater<int>());
    for(int i=0; i<N && H > 0 && b[i] > a_max; i++){
        H -= b[i];
        cnt++;
    }
    if(H > 0){
        cnt += (H - 1) / a_max + 1;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 4032
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	
	int n, m; cin >> n >> m;
	vector<vi> cards(m);
	vi mxpair(m);
	
	rep(i, n){
		int x; cin >> x;
		cards[x % m].pb(x);
	}
	rep(i, m){
		sort(all(cards[i]));
		rep(j, cards[i].size()){
			int k = j;
			for(; k < cards[i].size() && cards[i][j] == cards[i][k]; k++);
			mxpair[i] += (k - j) / 2;
			j = k - 1;
		}
	}
	
	int ans = cards[0].size() / 2;
	for(int i = 1; i * 2 < m; i++){
		int mx = 0;
		for(int j = 0, J = min(cards[i].size(), cards[m - i].size()); j <= J; j++){
			
			int tmp = j;
			tmp += min(mxpair[i], ((int)cards[i].size() - j) / 2);
			tmp += min(mxpair[m - i], ((int)cards[m - i].size() - j) / 2);
			mx = max(mx, tmp);
		}
		ans += mx;
	}
	if(m % 2 == 0) ans += cards[m / 2].size() / 2;
	
	cout << ans << endl;
	
	return 0;
}

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

int main() {
  int n,l;
  cin >> n >> l;
  if(l <= 0 && l+n > 0){
    cout << (l+(l+n-1)) * (n)/2 << endl;
  }
  else if(l > 0){
    cout << ((l+1)+(l+n-1)) *(n-1)/2 << endl;
  }
  else{
    cout << (l+(l+n-2)) *(n-1)/2 << endl;
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<deque>
#include<math.h>
using namespace std;
#define ll long long
bool visited[111];
int main(){
    ll N,K,C;
    cin >> N >> K >>C;
    string S;
    cin >> S;
    ll i,j;
    pair<ll,ll> ldp[N+1],rdp[N+1];
    ldp[0]=make_pair(0,0);
    rdp[N+1]=make_pair(0,0);
    for(i=1;i<=N;i++){
        if(S[i-1]=='o'&&ldp[i-1].second<=1)ldp[i]=make_pair(ldp[i-1].first+1,C+1);
        else ldp[i]=make_pair(ldp[i-1].first,max(ldp[i-1].second-1,(ll)0));
        if(S[N-i]=='o'&&rdp[N-i+1].second<=1)rdp[N-i]=make_pair(rdp[N-i+1].first+1,C+1);
        else rdp[N-i]=make_pair(rdp[N-i+1].first,max(rdp[N-i+1].second-1,(ll)0));
    }
    for(i=0;i<=N;i++){
        if(ldp[i].first+rdp[i+1].first==K-1)cout <<i+1<<endl;
    }
    return 0;
}


Measured memory_bytes: 8068
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <random>
#include <iterator>

using namespace std;

#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(v) reverse((v).begin(),(v).end())
#define ANS(ans) cout<<(ans)<<endl;
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
typedef vector<int> VI;
typedef pair<int, int> P;

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  for (int i = 0; i < (n); ++i)


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

	string ans = "ABC";
	ans += to_string(n);

	ANS(ans);


	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
using namespace std;
ll K,X,Y;
struct Vector{
    ll x,y;
    Vector(ll x=0,ll y=0):x(x),y(y){}
};
Vector operator + (Vector a,Vector b){
    return Vector(a.x+b.x,a.y+b.y);
}
void operator +=(Vector &a,Vector b){
    a=a+b;
}
ll flr(ll a,ll b){
    return (a+b-1)/b;
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>K>>X>>Y;
    bool xflg=false,yflg=false,xyflg=false;
    if(Y<0){
        Y*=-1;
        xflg=true;
    }
    if(X<0){
        X*=-1;
        yflg=true;
    }
    if(X<Y){
        swap(X,Y);
        xyflg=true;
    }
    ll n,typ=0;
    bool aflg=true;
    if(K%2==0){
        if((X+Y)%2==1){
            aflg=false;
        }else if(X+Y<K){
            n=2;
        }else{
            n=flr(X+Y,K);
        }
    }else{
        if(X+Y<K){
            if((X+Y)%2==0){
                n=2;
            }else{
                typ=1;
            }
        }else{
            if((X+Y)%2==0){
                if(flr(X+Y,K)%2==0){
                    n=flr(X+Y,K);
                }else{
                    n=flr(X+Y,K)+1;
                }
            }else{
                if(flr(X+Y,K)%2==1){
                    n=flr(X+Y,K);
                }else{
                    n=flr(X+Y,K)+1;
                }
            }
        }
    }
    vector<Vector> ans;
    if(typ==1){
        ans.push_back(Vector(X,X-K));
        ans.push_back(Vector((K+X-Y)/2,(K-X+Y)/2)+ans.back());
        ans.push_back(Vector(X,Y));
    }else{
        ll rem=0;
        rem=(K*n-X-Y)/2;
        Vector v(0,0);
        while(rem>=K){
            rem-=K;
            v+=Vector(0,-K);
            ans.push_back(v);
        }
        rem+=X;
        while(rem>=K){
            rem-=K;
            ll dy=v.y+(K*n-X-Y)/2;
            v.y-=dy;
            v.x+=K-dy;
            ans.push_back(v);
        }
        rem+=(K*n-X+Y)/2;
        while(rem>=K){
            rem-=K;
            ll dx=X-v.x;
            v.x+=dx;
            v.y+=K-dx;
            ans.push_back(v);
        }
    }
    if(!aflg){
        cout<<-1<<endl;
    }else{
        cout<<ans.size()<<endl;
        for(auto p:ans){
            if(xyflg){
                swap(p.x,p.y);
            }
            if(yflg){
                p.x*=-1;
            }
            if(xflg){
                p.y*=-1;
            }
            cout<<p.x<<' '<<p.y<<endl;
        }
    }
}

Measured memory_bytes: 6256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <map>
using namespace std;
typedef long long ll;
int main() {
	ll n, a[100010], b[100010];
	cin >> n;
	ll cnt = 0;
	for (int i = 0; i < n; i++)cin >> a[i] >> b[i];
	for (int i = n - 1; i >= 0; i--) {
		if ((a[i] + cnt) % b[i])cnt += b[i] * ((a[i] + cnt) / b[i] + 1) - (a[i] + cnt);
	}
	cout << cnt << endl;
	getchar();
	getchar();
	return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
    int n, m;
    while(cin >> n >> m, n){
        vector<int> h(n+1,0),w(m+1,0);
        for(int i = 0; i < n; i++) cin >> h[i+1];
        for(int i = 0; i < m; i++) cin >> w[i+1];
        for(int i = 0; i < n; i++) h[i+1] += h[i];
        for(int i = 0; i < m; i++) w[i+1] += w[i];
        vector<int> v1,v2;
        for(int i = 0; i <= n; i++) for(int j = 0; j < i; j++){
            v1.push_back(h[i] - h[j]);
        }
        for(int i = 0; i <= m; i++) for(int j = 0; j < i; j++){
            v2.push_back(w[i] - w[j]);
        }
        sort(v1.begin(),v1.end());
        sort(v2.begin(),v2.end());
        long long ans = 0;
        for(int i = 0; i < v1.size(); i++){
            int len = v1[i];
            ans += upper_bound(v2.begin(), v2.end(), len) - lower_bound(v2.begin(), v2.end(), len);
        }
        cout << ans << endl;
    }
}



Measured memory_bytes: 19688
n=int(input())
dict={}
xs=[]
for i in range(n):
  s=input()
  xs+=[s]
  if s not in dict:
    dict[s]=1
  else:
    dict[s]+=1
pin=0
xs=list(set(xs))
for i in xs:
  pin=max(pin,dict[i])
ans=[]
for i in xs:
  if dict[i]==pin:
    ans+=[i]
ans.sort()
for i in ans:
  print(i)

Measured memory_bytes: 163888
#include <iostream>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <limits>
#include <string>
#include <algorithm>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <numeric>
#include "math.h"
#include "assert.h"

using namespace std;

#define ll long long

#define BUFF ios::sync_with_stdio(false)
#define epsilon 1e-07
#define pi 2 * acos(0.0);
#define mod 1000000007   // 1e9+7
#define cerr if(false)cerr
#define watch(x) cerr << #x << " = " << x << endl;

#define inf std::numeric_limits<int>().max()

int gcd(int a, int b) {
	return b ? gcd(b, a % b) : a;
}

set<int> sieve_eratosthenes(int n) {
	vector<bool> v(n+1, 1);
	set<int> p;
	int k = 2;
	while (k * k <= n) {
		if (v[k]) {
			for(int i=k*k; i<=n; i+=k) {
				v[i] = 0; 
			}
		}
		k++;
	}
	for(int i=2; i<=n; i++) {
		if (v[i]) p.insert(i);	
	}
	return p;
}

int main() {
	int n;
	cin >> n;
	vector<int> v(n); 
	for(int i=0; i<n; i++) {
		cin >> v[i];
	}
	auto p = sieve_eratosthenes(1e7);
	map<int, int> mp;
	for(int i=0; i<n; i++) {
		int k = v[i];
		for(auto it = p.begin(); pow(*it,2) <= k and it != p.end(); it++) {
			int x = *it;
			if (k % x == 0) {
				while (k % x == 0) k /= x; 
				mp[x]++;
			}
		}
		if (k != 1) mp[k]++;
	}

	int ans = 0;
	for(auto it = p.begin(); it != p.end(); it++) {
		ans = max(mp[*it], ans);
//		if (mp[*it] > 0) cout << *it << " " << mp[*it] << endl; 
	}
	if (ans <= 1) cout << "pairwise coprime" << endl;
	else if (ans < n) cout << "setwise coprime" << endl;
	else cout << "not coprime" << endl;

}


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

int main(){
  while(1){
    int n,m,p;
    int x[110]={};
    cin >> n >> m >> p;
    if(n == 0 && m == 0 && p == 0)break;
    int ans=0;
    for(int i=1;i<=n;i++){
      cin >> x[i];
      ans += 100 * x[i];
    }
    int pe = x[m];
    ans = ans - ans*p/100;
    if(pe != 0)
      ans = ans / pe;
    else 
      ans=0;
    cout << ans << endl;
  }
  return 0;
}

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

int main(){

//int N,A,B,C,K,d,X;
unsigned long long X,N;
int C;
cin >> X;
N = 100;
C = 0;
//cin >> K >> A >> B;
//vector<int> A(N);

while(N<X){
	N += N/100;
	C++;
}
cout << C << endl;
}

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

int main(){
	string s;
	cin >> s;

	for(int i=0; i<( 1<<3 ); i++){
		bitset<3> bit(i);
		int cnt=0;
		int sum=(int)s.at(0)-48;
		vector<char> op(3);
		for(int j=0; j<3; j++){
			if( bit.test(j) ){
				cnt++;
				sum += (int)s.at(cnt)-48;
				op.at(j) = '+';
			}
			else{
				cnt++;
				sum -= (int)s.at(cnt)-48;
				op.at(j) = '-';
			}
		}
		if(sum==7){
			cout << s.at(0) << op.at(0);
			cout << s.at(1) << op.at(1);
			cout << s.at(2) << op.at(2);
			cout << s.at(3) << "=7" << endl;
			return 0;
		}
	}
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ff first
#define ss second
#define len(x) (int)(x.size())
#define all(x) x.begin(), x.end()
using namespace std;
using ll = long long;
using ii = pair<int, int>;

int main(){
	ios::sync_with_stdio(0);
	int n;
	cin >> n;
	vector<int> a(n), b(n), c(n-1);
	for(auto &x:a) cin >> x;
	for(auto &x:b) cin >> x;
	int ans = 0;
	for(auto &x:c) cin >> x;
	int last = -1;
	for(auto i:a){
		ans += b[i-1];	
		if(last+1==i)
			ans +=c[last-1];
		last = i;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;
// auto mod int
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {if ((x += a.x) >= mod) x -= mod; return *this;}
  mint& operator-=(const mint a) {if ((x += mod-a.x) >= mod) x -= mod; return *this;}
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
// combination mod prime
struct Combination {
  vector<mint> fact, ifact;
  Combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

int main() {
  int n;
  cin >> n;
  if(n==1){
    cout << 0 << endl;
  }else{
    mint ans = mint(10).pow(n) - mint(9).pow(n)*2 + mint(8).pow(n);
    cout << ans << endl;
  }
}


Measured memory_bytes: 3616