akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> p;
#define fi first
#define se second
int main(){
  ll n; cin >> n;
  vector<ll> v(n);
  ll m = 0;
  map<ll,ll> ma;
  for(int i=0 ; i<n ; i++){
    ll x; cin >> x;
    ma[x]++; ma[x-1]++; ma[x+1]++;
  }
  ll i=0;
  ll cnt =0 ;
  for(auto ite=begin(ma) ; ite!=end(ma) ; ite++){
    m = max(ite->second, m);
  }
  cout << m << endl;
  return 0;
}


Measured memory_bytes: 6912
#include <iostream>
#include <vector>
#include <map>
#include <cstring>
#include <string>
#include <stack>
#include <queue>
#include <cmath>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <sstream>
using namespace std;

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define repp(i,k,n) for(int i=k;i<(int)n;i++)
#define re(n) for(int i=0;i<(int)n;i++)
#define al(s) s.begin(),s.end()


vector<int> pri;
bool fl[10000001] = {};
void set_pri(int n)
{
	
	for (int i = 2; i <= n; i++)
	{
		if (fl[i] == false)
		{
			pri.push_back(i);
			for (int l = i; l <= n; l += i)fl[l] = true;
		}
	}
	return;
}

int main()
{
	int n;
	set_pri(10000000);
	vector<int> ans;
	for (int i = 0; i < pri.size(); i++)
	{
		if (binary_search(al(pri), pri[i] + 2) && binary_search(al(pri), pri[i] + 6) && binary_search(al(pri), pri[i] + 8))
		{
			ans.push_back(pri[i] + 8);
		}
	}

	while (cin >> n&&n)
	{
		if (binary_search(al(ans), n))
		{
			cout << *(lower_bound(al(ans), n)) << endl;
		}
		else
		{
			cout << *(upper_bound(al(ans), n)-1) << endl;
		}
	}



	return 0;
}

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

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

    vector<int> x(N);
    vector<int> y(M);

    for(int i = 0; i < N ; i++){
        cin >> x[i];
    }
    for(int i=0 ; i < M; i++){
        cin >> y[i];
    }

    x.push_back(X);
    y.push_back(Y);

    int XMAX = *max_element(x.begin(),x.end());
    int YMAX = *min_element(y.begin(),y.end());

    if(XMAX < YMAX) cout << "No War" << endl;
    else cout << "War" << endl;

    return 0;
}

Measured memory_bytes: 256
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop;


void main() {
    auto s = readln.split.map!(to!int);
    auto V = s[0];
    auto E = s[1];
    auto F = s[2];

    auto mcf = new MinCostFlow(V);

    foreach (_; 0..E) {
        s = readln.split.map!(to!int);
        mcf.add_edge(s[0], s[1], s[2], s[3]);
    }

    mcf.run(0, V-1, F).writeln;
}


class MinCostFlow {
    alias Tuple!(int, "to", int, "cap", int, "cost", int, "rev") Edge;
    immutable int INF = 1 << 29;

    int V;
    Edge[][] G;
    int[] h;
    int[] dist;
    int[] prevv;
    int[] preve;

    this(int v) {
        V = v;
        G = new Edge[][](v);
        h = new int[](v);
        dist = new int[](v);
        prevv = new int[](v);
        preve = new int[](v);
    }

    void add_edge(int from, int to, int cap, int cost) {
        G[from] ~= Edge(to, cap, cost, G[to].length.to!int);
        G[to] ~= Edge(from, 0, -cost, G[from].length.to!int - 1);
    }

    int run(int s, int t, int f) { // source, sink, flow
        int res = 0;
        h.fill(0);
        while (f > 0) {
            auto pq = new BinaryHeap!(Array!(Tuple!(int, int)), "a[0] < b[0]");
            dist.fill(INF);
            dist[s] = 0;
            pq.insert(tuple(0, s));
            while (!pq.empty) {
                auto p = pq.front;
                pq.removeFront;
                int v = p[1];
                if (dist[v] < p[0]) continue;
                foreach (i; 0..G[v].length.to!int) {
                    auto e = G[v][i];
                    if (e.cap > 0 && dist[e.to] > dist[v] + e.cost + h[v] - h[e.to]) {
                        dist[e.to] = dist[v] + e.cost + h[v] - h[e.to];
                        prevv[e.to] = v;
                        preve[e.to] = i;
                        pq.insert(tuple(dist[e.to], e.to));
                    }
                }
            }
            if (dist[t] == INF) {
                return -1;
            }
            foreach (v; 0..V) {
                h[v] += dist[v];
            }

            int d = f;
            for (int v = t; v != s; v = prevv[v]) {
                d = min(d, G[prevv[v]][preve[v]].cap);
            }
            f -= d;
            res += d * h[t];
            for (int v = t; v != s; v = prevv[v]) {
                G[prevv[v]][preve[v]].cap -= d;
                G[v][G[prevv[v]][preve[v]].rev].cap += d;
            }
        }

        return res;
    }
}

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

int a,b,year=2019,ans=1e9+7;

signed main()
{
	cin>>a>>b;
	if (a/2019!=b/2019)  return cout<<0<<endl,0;
	
	a=a%year,b=b%year;
	if (a>b)  b+=year;
	
	for (int i=a;i<=b-1;i++)
	{
		for (int j=i+1;j<=b;j++)  ans=min(ans,(i*j)%year);
	}
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 256
# import sys
# import math
# import decimal
# import queue
# import bisect
# import heapq # priolity-queue
# import time
# import itertools
# import collections # queue
# from operator import itemgetter
# from fractions import Fraction

mod = int(1e9+7)
INF = 1<<29
lINF = 1<<35

def main():
    s = input()
    ans = 0
    for i in range(len(s)-2,-1,-1):
        if (i+1)%2==0:
            res = True
            for j in range((i+1)//2):
                if s[j]!=s[j+(i+1)//2]:
                    res = False
                    break
            if res:
                ans = i + 1
                break
    print(ans)
    return

if __name__=='__main__':
    main()

Measured memory_bytes: 3064
#include<stdio.h>

int main(){

    int x,y,a=0,b=0;

    scanf("%d %d",&x,&y);

    a=x*4;
    b=x*2;

    if(y%2==0&&b<=y&&a>=y){
        printf("Yes");

    }else{
        printf("No");
    }
    return 0;




}

Measured memory_bytes: 1732
//#include<bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<numeric>
#include<vector>
#include<set>
#include<map>
#include<unordered_map>
#include<stack>
#include<queue>
#include<list>
using namespace std;

typedef long long ll;

#define MOD 1000000007

class Comb{
private:
  ll *fac,*finv,*inv;
public:
  Comb(){
    fac = new ll[1000000];
    finv = new ll[1000000];
    inv = new ll[1000000];
    fac[0] = 1;
    for(int i=1;i<1000000;i++){
      fac[i] = i*fac[i-1];
      fac[i] %= MOD;
    }
    inv[1] = 1;
    for(int i=2;i<1000000;i++){
      inv[i] = MOD-inv[MOD%i]*(MOD/i)%MOD;
    }
    finv[0] = 1;
    for(int i=1;i<1000000;i++){
      finv[i] = inv[i]*finv[i-1];
      finv[i] %= MOD;
    }
  }
  ll calc(ll n,ll k){
    ll c = fac[n];
    c *= finv[k];c %= MOD;
    c *= finv[n-k];c %= MOD;
    return c;
  }
};

int main(){
  ll a,b,k;
  cin >> a >> b >> k;
  if(a >= k){
    cout << a-k << " " << b << endl;
  }
  else{
    cout << 0 << " " << max(b-(k-a),0ll) << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int status[100002]{};
void sieve()
{
    int N=100001;
	int sq=sqrt(N);
	for(int i=4;i<=N;i+=2) status[i]=1;
	for(int i=3;i<=sq;i+=2){
		if(status[i]==0)
		{
			for(int j=i*i;j<=N;j+=i) status[j]=1;
		}
	}
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    sieve();
    int a;
    //for(int i=0;i<=20;i++) cout<<status[i]<<" ";
    cin>>a;
    if(a>99991) {cout<<100003<<endl;return 0;}
    for(int i=a;i<=100000;i++)
    if(!status[i]) {cout<<i<<endl;break;}
    return 0;
}



Measured memory_bytes: 640
#合計値がXにすることができる整数の合計値の最小個数
#Xまでの整数を使う、使わないで行くと、計算数が多すぎる
#ARC070-C GO HOME

x = int(input())
x = abs(x)
ans = 0
sum = 0
i = 0

while sum + i < x:
    sum += i
    i += 1
print(i)


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

const int Maxn=1e5+5;
int n;
long long c,x[Maxn],v[Maxn];

int main(){
	cin>>n>>c;
	for(int i=1;i<=n;i++){
		cin>>x[i]>>v[i];
	}
	x[n+1]=c;
	long long ans=0,sum=0;
	for(int i=1;i<=n;i++){
		sum+=v[i]-(x[i]-x[i-1]);
		ans=max(ans,sum);
	}
	sum=0;
	for(int i=n;i>=1;i--){
		sum+=v[i]-(x[i+1]-x[i]);
		ans=max(ans,sum);
	}
	
	long long l[Maxn]={0},r[Maxn]={0};
	sum=0;
	long long maxv=0;
	for(int i=1;i<=n;i++){
		sum+=v[i]-2*(x[i]-x[i-1]);
		maxv=max(maxv,sum);
		l[i]=maxv;
	}
	sum=0; maxv=0;
	for(int i=n;i>=1;i--){
		sum+=v[i]-(x[i+1]-x[i]);
		maxv=max(maxv,sum);
		r[i]=maxv;
	}
	for(int i=2;i<=n;i++){
		ans=max(ans,l[i-1]+r[i]);
	}
	
	memset(l,0,sizeof(l));
	memset(r,0,sizeof(r));
	sum=0; maxv=0;
	for(int i=1;i<=n;i++){
		sum+=v[i]-(x[i]-x[i-1]);
		maxv=max(maxv,sum);
		l[i]=maxv;
	}
	sum=0; maxv=0;
	for(int i=n;i>=1;i--){
		sum+=v[i]-2*(x[i+1]-x[i]);
		maxv=max(maxv,sum);
		r[i]=maxv;
	}
	for(int i=2;i<=n;i++){
		ans=max(ans,l[i-1]+r[i]);
	}
	cout<<ans;
} 

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

int main() {
  ll x; cin >> x; 
  ll ans=0;;
  ll y = 100;
  while(y<x) {
    y *= 1.01;
    ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3672
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
using namespace std;
#define maxn 100010

const int inf=1e9;
struct node
{
	int x,y,next;
}a[maxn*2];int len,first[maxn];
int mymin(int x,int y){return (x<y)?x:y;}
void ins(int x,int y)
{
	len++;a[len].x=x;a[len].y=y;
	a[len].next=first[x];first[x]=len;
}
int ans=0,ff[maxn];
int ffind(int x){return (x==ff[x])?x:ff[x]=ffind(ff[x]);}
int whi[maxn],col[maxn],siz[maxn],bak[maxn],w[maxn],dep[maxn],fa[maxn];
void treedp(int x)
{
	bak[x]=col[x];siz[x]=1;
	for (int k=first[x];k!=-1;k=a[k].next)
	{
		int y=a[k].y;
		if (y==fa[x]) continue;
		col[y]=1-col[x];
		dep[y]=dep[x]+1;
		fa[y]=x;treedp(y);
		bak[x]+=bak[y];
		siz[x]+=siz[y];
	}
	whi[x]=siz[x]-bak[x];
}
int A[maxn],cnt,B[maxn],bl,C[maxn],cl;
void mov(int x,int y)
{
	if (dep[x]<dep[y]) swap(x,y);
	while (dep[x]>dep[y])
	{
		A[++cnt]=-(whi[x]-bak[x]);
		B[++bl]=x;x=fa[x];
	}
	while (x!=y)
	{
		A[++cnt]=-(whi[x]-bak[x]);
		A[++cnt]=(whi[y]-bak[y]);
		B[++bl]=x;C[++cl]=y;
		x=fa[x];y=fa[y];
	}
}
int get_ans(int x)
{
	int ret=0;bak[x]=col[x];
	for (int k=first[x];k!=-1;k=a[k].next)
	{
		int y=a[k].y;
		if (y==fa[x]) continue;
		ret+=get_ans(y);
		bak[x]+=bak[y];
		ret+=abs(whi[y]-bak[y]+w[y]);//(siz[y]-bak[y])-(bak[y]-w[y])
	}return ret;
}
int main()
{
	int T,n,m,x,y,i,s,t;
	{
		scanf("%d%d",&n,&m);
		for (i=1;i<=n;i++) ff[i]=i;
		len=0;memset(first,-1,sizeof(first));
		for (i=1;i<=m;i++)
		{
			scanf("%d%d",&x,&y);
			int fx=ffind(x),fy=ffind(y);
			if (fx!=fy) {ins(x,y);ins(y,x);ff[fx]=fy;}
			else {s=x;t=y;}
		}
		dep[1]=1;fa[1]=0;col[1]=1;treedp(1);
		memset(w,0,sizeof(w));
		if (m==n-1)//乱来
		{
			if (bak[1]*2!=n) printf("-1\n");
			else printf("%d\n",get_ans(1));
		}else
		{
			if (col[s]==col[t])
			{
				if (whi[1]%2!=bak[1]%2) printf("-1\n");
				else
				{
					int ls=(whi[1]-bak[1])/2;
					col[s]+=ls;	col[t]+=ls;
					printf("%d\n",get_ans(1)+abs(ls));
				}
			}else
			{
				if (bak[1]*2!=n) printf("-1\n");
				else
				{
					bl=cl=cnt=0;A[++cnt]=0;mov(s,t);
					sort(A+1,A+1+cnt);
					int mid=A[(cnt+1)/2];
					for (i=1;i<=bl;i++) w[B[i]]+=mid;
					for (i=1;i<=cl;i++) w[C[i]]-=mid;
					printf("%d\n",get_ans(1)+abs(mid));
				}
			}
		}
	}
	return 0;
}

Measured memory_bytes: 11264
using System;
using System.Linq;

class Program {
    static void Main (string[] args) {
        string str = Console.ReadLine ();
        var ary = str.Select (x => int.Parse (x.ToString ())).ToArray ();
        var even = ary.Where ((x, y) => (y % 2 == 0));
        var odd = ary.Where ((x, y) => (y % 2 != 0));
        var ptnA = even.Sum () + odd.Count () - odd.Sum ();
        var ptnB = even.Count () - even.Sum () + odd.Sum ();

        if (ptnA < ptnB) {
            Console.WriteLine (ptnA);
        } else {

            Console.WriteLine (ptnB);
        }
    }
}

Measured memory_bytes: 15072
#include <iostream>
using namespace std;
int main(){
  long long n,k;cin>>n>>k;
  long long a[n];
  for(int i = 0; n > i; i++)cin>>a[i];
  long long mn = 10000000000000;
  for(int i = 0; n > i+k-1; i++){
    if(a[i] >= 0){
      mn = min(mn,a[i+k-1]);
    }else{
      mn = min(mn,a[i]*-2+a[i+k-1]);
    }
  }
  for(int i = 0; n > i; i++)a[i]*=-1;
  for(int i = n-1; 0 <= i-k+1; i--){
    if(a[i] >= 0){
      
      mn = min(mn,a[i-k+1]);
    }else{
      mn = min(mn,a[i]*-2+a[i-k+1]);
    }
  }
  cout <<mn << endl;
}

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

int main() {
    int n, a[200];
    cin >> n;
    for(int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    int cnt = 0;
    int ans = 1e9;
    for(int i = 0; i < n; ++i) {
        int d = 0;
        while(!(a[i] & 1)) {
            a[i] >>= 1;
            ++d;
        }
        ans = min(ans, d);
    }
    cout << ans << endl;
}

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

int main() {
    string a, b, c;
    cin >> a >> b >> c;
    if (a.back() == b.at(0) && b.back() == c.at(0))
        cout << "YES" << endl;
    else
        cout << "NO" << endl;

    return 0;
}


Measured memory_bytes: 3624
#include <cmath>
#include <vector>
#include <map>
#include <functional>
#include <queue>
#include <iostream>
#include <string.h>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <cstdint>
#include <climits>
#include <unordered_set>
#include <sstream>

using namespace std;

#define ll long long int

int main()
{
    ll n;
    cin >> n;
    ll upper = sqrt(n * 2) + 1;
    ll prev = 0;
    ll diff = 0;
    ll result = 0;
    for(ll i = 1;i <= upper;i++)
    {
        ll current = (i + 1) * i / 2LL;
        if(prev <= n && current >= n)
        {
            diff = current - n;
            result = i;
            break;
        }
        prev = current;
    }
    for(ll i = 1;i <= result;i++)
    {
        if(i != diff)
        {
            cout << i << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<iomanip>
#include<cstdio>

using namespace std;

int main(void)

{
	int a, b;
	char op;
	while (1)
	{
		cin >> a >> op >> b;

		





		if (op == '*')

		{
			cout << a * b << endl;

		}
		else if (op == '/')
		{
			cout << a / b << endl;

		}
		else if (op == '+')
		{

			cout << a + b << endl;

		}
		else if (op == '-')
		{
			cout << a - b << endl;


		}

		else
		{
			break;
		}


	}

	return( 0 );
}



Measured memory_bytes: 3080
#include <iostream>
#include <set>
#include <map>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <climits>
#include <math.h>
#include <cassert>
#include <unordered_map>
using namespace std;
#pragma warning(disable : 4996)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;


int gcd(int a, int b) {
	if (a < b)swap(a, b);
	while (b > 0) {
		int c = b;
		b = a % b;
		a = c;
	}
	return a;
}

int main() {
#ifdef _DEBUG
	freopen("input1.txt", "r", stdin);
	freopen("output2.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int k;
	cin >> k;
	ll ans = 0;
	for (int i = 1; i <= k; i++) {
		for (int j = 1; j <= k; j++) {
			for (int m = 1; m <= k; m++) {
				ans += gcd(i, gcd(m, j));
			}
		}
	}
	cout << ans;
}

Measured memory_bytes: 3688
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    rr = []

    def f(t,d,l):
        a = [I() for _ in range(t)]
        r = [0] * t
        for i in range(t-1,-1,-1):
            c = a[i]
            if c >= l:
                r[i] = 1
                for j in range(i+1,min(i+d,t)):
                    if r[j] > 0:
                        break
                    r[j] = 1

        return sum(r[:-1])

    while 1:
        n,m,l = LI()
        if n == 0:
            break
        rr.append(f(n,m,l))

    return '\n'.join(map(str, rr))


print(main())



Measured memory_bytes: 14472
import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = println(solve(new Scanner(System.in)))

  def solve(in: String): String = solve(new Scanner(in))

  def solve(sc: Scanner): String = {
//    for (i <- 1 to 200 by 2) {
//      var cnt = 0
//      for (j <- 1 to i by 2) {
//        if (i % j == 0) cnt += 1
//      }
//      if (cnt == 8) println(i)
//    }

    val N = sc.nextInt
    val ans = Array(105, 135, 165, 189, 195)
    ans.count(_ <= N).toString
  }
}


Measured memory_bytes: 25780
N, M = list(map(lambda n: int(n), input().split(" ")))

fibonacci = [1, 1, 2]
for i in range(1, N + 1):
  fibonacci.append((fibonacci[i] + fibonacci[i + 1]) % 1000000007)

fibonacci.append(1)
fibonacci.append(0)

A = [-1]
for i in range(M):
  A.append(int(input()))
A.append(N + 1)

ans = 1
# 1 23 45 67 89 (101)
# 0 -> 0
# 2 -> 22
# 24 -> 44
# 46 -> 66
# fibonacci(A[i + 1] - 2 - A[i])

for i in range(len(A) - 1):
  ans *= fibonacci[A[i+1]-A[i]-2] % 1000000007
  ans = ans % 1000000007
print(ans)

Measured memory_bytes: 16740
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
vector<int> X,Y;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;cin>>N;
  X.resize(N);
  Y.resize(N);
  FOR(i,0,N){
    cin>>X[i];
    Y[i]=X[i];
  }
  sort(X.begin(),X.end());
  int a,b;
  a=X[N/2-1];
  b=X[N/2];
  FOR(i,0,N){
    if(Y[i]<b){
      cout<<b<<endl;
    }else{
      cout<<a<<endl;
    }
  }
}

Measured memory_bytes: 3840
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<vector>
#include<string.h>
#include<set>
using namespace std;
#define PB push_back
inline int in() {
	int temp;
	scanf("%d", &temp);
	return temp;
}
int gcd(int a, int b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}
int main() {
	long long n = in(), t[1000], a[1000], st = 0, sa = 0, tt, aa, ss;
	for (int i = 0; i < n; i++) {
		t[i] = in(); a[i] = in();
		 ss = gcd(t[i], a[i]);
		 t[i] /= ss; a[i] /= ss;
	}
	st = t[0]; sa = a[0];
	for (int i = 1; i < n; i++) {
		tt = st / t[i]; aa = sa / a[i];
		if (st % t[i]) {
			tt++;
		}
		if (sa % a[i]) {
			aa++;
		}
		ss = max(aa, tt);
		st = t[i] * ss; sa = a[i] * ss;
	}
	cout << st + sa << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
#define FORV(i, v) for (auto i = v.begin(); i != v.end(); i++)
using namespace std;

typedef long long ll;

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; }
const ll INF = 1e9;
const long long INFL = 1LL<<60;

int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  int ans = 1;
  char prev = s[0];
  for (int i = 1; i < s.size(); i++) {
    if (s[i] != prev) {
      ans++;
    }
    prev = s[i];
  }

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


Measured memory_bytes: 512
#include <bits/stdc++.h>
 
using namespace std;
 
#define repr(i,a,b) for (int i=a; i<b; i++)
#define rep(i,n) for (int i=0; i<  n; i++)
 
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; }
 
const long long INF = 1LL << 60;
#define PI 3.14159265359 
 
template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
    vector.erase(vector.begin() + index);
}
 
int gcd(int a, int b){
    if(b == 0) return a;
    else return gcd(b, a%b);
}
 
long long lcm (int a, int b){
    return  (long long) a*b /gcd(a,b);
}


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

    int ans = 0;
    rep(i,N+1){
        int s = i;
        int keta = 0;

        while(s>0){
            keta += 1;
            s /= 10;
        }
        if(keta %2 ==1){
            ans +=1;
        }
    }
    cout << ans << endl;
}

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

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

int main() {
    int n, m;
    cin >> n >> m;
    vector<P> p(n);
    rep(i, n) {
        p[i].first = i;
        p[i].second = i+1;
    }
    int cur = -1;
    rep(i, m) {
        int e;
        cin >> e;
        e--;
        p[e].first = cur;
        cur--;
    }
    sort(p.begin(), p.end());
    rep(i, n) {
        cout << p[i].second << endl;
    }
    return 0;
}



Measured memory_bytes: 5944
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cmath>
#include <iomanip>
#include <string>
#include <queue>

typedef long long ll;
using namespace std;
const int mod = 1000000007;


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

    string S; cin >> S;
    
    int cnt = 1;
    vector<int> counter;
    for (int i = 1; i < S.size(); i++) {
        if (S[i] == S[i-1]) cnt++;
        else {
            counter.push_back(cnt);
            cnt = 1;
        }
    }
    if (cnt >= 1) counter.push_back(cnt);
    int last = counter.size() - 1;
    for (int k = 0; k < K; k++) {
        if (last == 0) break;
        else if (last == 1) {
            counter[last-1] += counter[last];
            last--;
        }
        else if (last >= 2) {
            counter[last-2] += counter[last-1] + counter[last];
            last -= 2;
        }
    }


    int ans = 0;
    for (int i = 0; i <= last; i++) {
        ans += counter[i] - 1;
    }
    cout << ans << '\n';

}


Measured memory_bytes: 1020
#include<bits/stdc++.h>
using namespace std;
string s[100001];
int main(){
	int n;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>s[i];
		for(int j=0;j<s[i].length();j++){
			for(int k=j+1;k<s[i].length();k++){
				if(s[i][k]<s[i][j])swap(s[i][k],s[i][j]);
			}
		}
	}
	sort(s+1,s+n+1);
	long long ans=0,l=1;
	for(int i=2;i<=n;i++){
		if(s[i]==s[i-1])l++;
		else{
			ans+=l*(l-1)/2;
			l=1;
		}
	}	
	ans+=l*(l-1)/2;
	printf("%lld",ans);
} 

Measured memory_bytes: 7296
n, q = gets.chomp.split.map(&:to_i)

children = Array.new(n+1).map{[]}

(n-1).times do
  a, b = gets.chomp.split.map(&:to_i)
  children[a] << b
end

scores = Array.new(n+1).map{0}

q.times do
  point, x = gets.chomp.split.map(&:to_i)
  scores[point] += x
end

queue = [1]
while(queue.size > 0) do
  i = queue.shift
  
  children[i].each do |child|
    queue.push(child)
    scores[child] += scores[i]
  end
end

puts scores[1..-1].join(" ")


Measured memory_bytes: 28980
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int div = n;
        int ans = 0;
        while (div >= k) {
            div = div / k;
            ans++;
        }
        ans++;
        System.out.println(ans);
    }
}

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

string s;

int main(void)
{
	cin.tie(NULL);
	cout.tie(NULL);
	ios_base::sync_with_stdio(false);

	int n, k, i;

	cin >> n >> k >> s;

	int ans = 0;
	for (i = 0; i < n - 1; i++)
		if (s[i] == s[i + 1])
			++ans;

	cout << min(ans + 2 * k, n - 1);
	return 0;
}

Measured memory_bytes: 512
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#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>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

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

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

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

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define d(x)  //cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

LL D,G,minc=10000000,temp,dmax,co;
int p[11],c[11];

int main(void){
    cin>>D>>G;
    REP(i,D)cin>>p[i]>>c[i];
    REP(i,1<<D){
        d(i)
        temp=G;
        co=0;
        REP(j,D){
            if((1&i>>j) == 1){
                d(c[j])
                d((j+1)*100)
                temp-=(j+1)*100*p[j]+c[j];
                d(temp)
                co+=p[j];
            }
        }
        for(dmax=D-1;dmax>0;dmax--){
            if((1&i>>dmax) == 0)break;
        }
        d(co)
        d(temp)
        d(dmax)
        if((dmax+1)*100*p[dmax]>temp){
            if(temp>=0){
                d(temp/((dmax+1)*100))
                co+=(int) ceil((float) temp/((dmax+1)*100));
            }
        }
        else{
            continue;
        }
        d(co)
        if(co<minc)minc=co;
    }
    cout<<minc<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
vector <int> des[200010];
int col[200010];
bool dfs(int s)
{
	bool ans=true;
	for (int k=0;k<des[s].size();k++)
	{
		if (col[des[s][k]]==-1) {col[des[s][k]]=!col[s];if (!dfs(des[s][k])) ans=false;}
		else if (col[des[s][k]]==col[s]) ans=false;
	}
	return ans;
}
int main()
{
	int n,m;scanf("%d%d",&n,&m);
	for (int i=1;i<=m;i++)
	{
		int u,v;scanf("%d%d",&u,&v);
		des[u].push_back(v);des[v].push_back(u);
	}
	for (int i=1;i<=n;i++) col[i]=-1;
	long long yes=0,no=0,sig=0;
	for (int i=1;i<=n;i++) if (col[i]==-1)
	{
		col[i]=0;
		if (des[i].size()==0) sig++;
		else if (dfs(i)) yes++;else no++;
	}//cout<<sig<<' '<<yes<<' '<<no<<endl;
	printf("%lld\n",sig*sig+sig*(n-sig)*2+yes*yes*2+no*no+yes*no*2);
}

Measured memory_bytes: 12288
"""
author : halo2halo
date : 24, Jan, 2020
"""

import sys

# import itertools
# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

A = int(readline())
S = [int(i) for i in readline().decode().split()]
S.sort()
S.reverse()

ans = 0
j = 1
for i in S:
    ans += i * j
    j *= -1
print(ans)



Measured memory_bytes: 3060
#define debug_interval ','
#define dump_interval ' '
#define debug_toggle 1
//{
#include<bits/stdc++.h>
using namespace std;
#define hi cerr<<"hi"<<endl;
#define int long long
#define INT_MAX LLONG_MAX
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define fi first
#define se second
#define mp make_pair
#define rev reverse
#define dans dump(ans)
#define MOD 1000000007
#define amp(v,n) (v).count(n)?v[n]++:v[n]=1
#define sysp system("pause")
#define PI acos(-1)
#define pf push_front
#define ins insert
#define fh(x,v) for(auto x:v)

//{
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class...A> inline void dump(){cout<<endl;}
template<class...A> inline void dump_rest() {cout<<endl;}
template<class T, class...A> inline void dump_rest(const T& first, const A&... rest){cout<<dump_interval<<first;dump_rest(rest...);}
template<class T,class...A> inline void dump(const T&first,const A&...rest){cout<<first;dump_rest(rest...);}
template<class...A> inline void debug(){cerr<<endl;}
template<class...A> inline void debug_rest() {cerr<<endl;}
template<class T, class...A> inline void debug_rest(const T& first, const A&... rest){cerr<<debug_interval<<first;debug_rest(rest...);}
template<class T,class...A> inline void debug(const T&first,const A&...rest){if(debug_toggle)cerr<<first,debug_rest(rest...);}
unsigned XorShift(void){static unsigned x = 123456789;static unsigned y = 362436069;static unsigned z = 521288629;static unsigned w = 88675123;unsigned t;t = x ^ (x << 11);x = y; y = z; z = w;return w = (w ^ (w >> 19)) ^ (t ^ (t >> 8));}
//}

typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}
template<int m>class mint{private:int i;public:mint() : i(0){}mint(int i): i((i%m+m)%m){}mint operator+(const mint& o){return o.i+i;}mint operator*(const mint& o){return o.i*i;}mint operator-(){return -i;}operator int() {return i;}};
//template<class T>vector<T> var_vec(size_t a){return vector<T>(a);}
//template<class T, class... Ts>auto var_vec(size_t a, Ts... ts){return vector<decltype(var_vec<T>(ts...))>(a, var_vec<T>(ts...));}

//}

string s;
int ans;

main(){
	int n;cin>>n;
	int p[n];rep(i,n)cin>>p[i];
	for(int i=1;i<n-1;i++){
		if((p[i]>p[i-1]&&p[i]<p[i+1])||(p[i]<p[i-1]&&p[i]>p[i+1]))ans++;
	}
	dans;
}



Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<string.h>
int *bubblesort(int *N,int len){
    int i,j;
    for(i=0;i<len;i++){
        for(j=len-1;j>i;j--){
            if(N[j]<N[j-1]){
                int temp=N[j];
                N[j]=N[j-1];
                N[j-1]=temp;
            }
        }
    }
    return N;
}
int max(int x,int y){
    if(x>y){
        return x;

    }else{
        return y;

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

    }else{
        return x;

    }
}
int main(void){
    double W,H,x,y;
    scanf("%lf %lf %lf %lf",&W,&H,&x,&y);
    double ans=W*H/2;
    int xx=0;
    if(x==W/2&&y==H/2){
        xx=1;

    }
    printf("%.10lf\n",ans);
    printf("%d\n",xx);





}

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

int main(int argc, char const *argv[]) {
  int a, b;
  string op;
  cin >> a >> op >> b;
  if(op[0] == '+') {
    cout << a + b << endl;
  }
  if(op[0] == '-') {
    cout << a - b << endl;
  }
  return 0;
}


Measured memory_bytes: 256
class Segment_Tree():
    """
    このプログラム内は1-index
    """

    def __init__(self,L,calc,unit):
        """calcを演算とするリストLのSegment Treeを作成

        calc:演算(2変数関数,モノイド)
        unit:モノイドcalcの単位元 (xe=ex=xを満たすe)
        """
        self.calc=calc
        self.unit=unit

        N=len(L)
        d=max(1,(N-1).bit_length())
        k=1<<d

        self.data=[unit]*k+L+[unit]*(k-len(L))
        self.N=k
        self.depth=d

        for i in range(k-1,0,-1):
            self.data[i]=calc(self.data[i<<1],self.data[i<<1|1])

    def get(self,k,index=1):
        """第k要素を取得
        """
        assert 0<=k-index<self.N,"添字が範囲外"
        return self.data[k-index+self.N]

    def update(self,k,x,index=1):
        """第k要素をxに変え,更新を行う.

        k:数列の要素
        x:更新後の値
        """
        assert 0<=k-index<self.N,"添字が範囲外"
        m=(k-index)+self.N
        self.data[m]=x

        while m>1:
            m>>=1
            self.data[m]=self.calc(self.data[m<<1],self.data[m<<1|1])


    def product(self,From,To,index=1,left_closed=True,right_closed=True):
        L=(From-index)+self.N+(not left_closed)
        R=(To-index)+self.N+(right_closed)

        vL=self.unit
        vR=self.unit

        while L<R:
            if L&1:
                vL=self.calc(vL,self.data[L])
                L+=1

            if R&1:
                R-=1
                vR=self.calc(self.data[R],vR)

            L>>=1
            R>>=1

        return self.calc(vL,vR)

    def all_product(self):
        return self.data[1]
#================================================
N,K=map(int,input().split())
A=[0]*N
for i in range(N):
    A[i]=int(input())

T=max(A)
S=Segment_Tree([0]*(T+1),max,0)

for i in range(N-1,-1,-1):
    S.update(A[i],S.product(max(0,A[i]-K),min(T,A[i]+K),0)+1,0)

print(S.all_product())

Measured memory_bytes: 108560
N, K = map(int, input().split())
c = [0] * N
ans = 0

for _ in range(K):
  d = int(input())
  A = list(map(int, input().split()))
  
  for a in A:
    c[a - 1] += 1
    
ans = c.count(0)

print(ans)

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

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

	for(auto &row: A) for(auto &v: row) cin >> v;

	int sum = A[0][0];
	for(auto &v: A[1]) sum += v;

	int ans = sum;
	for(int i=0; i<N-1; i++){
		sum += A[0][i+1] - A[1][i];
		ans = max(ans, sum);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * 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 a = Integer.parseInt(in.next());
            int b = Integer.parseInt(in.next());

            for (int i = 10; i < 1010; i++) {
                if (Math.floor(i * 0.08) == a && Math.floor(i * 0.1) == b) {
                    out.print(i);
                    return;
                }
            }

            out.println(-1);

        }

    }
}



Measured memory_bytes: 23636
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
a = list(map(int, input().split()))
c = 1
if 0 in a:
    print(0)
else:
    for num in a:
        c *= num
        if c>10**18:
            print(-1)
            break
    else:
        print(c)

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

int table[8][1024 * 4];

int main(void) {
	int n;

	for(int i = 0; i < 8; i++)
		for(int j = 0; j < 1024 * 4; j++)
			table[i][j] = 0;

	for(int i = 0; i < 1001; i++)
		table[0][i] = 1;

	for(int i = 1; i < 4; i++) {
		for(int j = 0; j < 1024 * 4; j++) {
			for(int k = 0; k < 1001 && k <= j; k++) {
				table[i][j] += table[i - 1][j - k];
			}
		}
	}

	while(cin >> n) {
		cout << table[3][n] << endl;
	}
}

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

using ll = long long;
using P = pair<ll, ll>;
using vi = vector<ll>;
using vvi = vector<vi>;

template <class T>
using max_heap = priority_queue<T>;
template <class T>
using min_heap = priority_queue<T, vector<T>, greater<T>>;

template <class T, class U>
void chmax(T &a, U b) {
    if (a < b) a = b;
}
template <class T, class U>
void chmin(T &a, U b) {
    if (b < a) a = b;
}

#define rep(i, j) for (int i = 0; i < j; i++)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
#define debug(x) cerr << #x << ": " << x << endl;
#define int ll

const ll mod = 1e9 + 7;
const ll inf = ll(1e18) + 1;

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;

    int N, K;
    cin >> N >> K;
    vi A(N);
    rep(i, N) cin >> A[i];
    sort(all(A));

    int lo = -inf, hi = inf;
    while (hi - lo > 1) {
        int mid = (hi + lo) / 2;
        int tot = 0;
        rep(i, N) {
            int l = -1, r = N;
            if (A[i] < 0) {
                while (r - l > 1) {
                    int m = (l + r) / 2;
                    if (A[i] * A[m] < mid) {
                        r = m;
                    } else {
                        l = m;
                    }
                }
                tot += N - r;
            } else {
                while (r - l > 1) {
                    int m = (l + r) / 2;
                    if (A[i] * A[m] < mid) {
                        l = m;
                    } else {
                        r = m;
                    }
                }
                tot += r;
            }
            if (A[i] * A[i] < mid) tot--;
        }
        tot /= 2;
        if (tot < K) {
            lo = mid;
        } else {
            hi = mid;
        }
    }

    cout << lo << endl; // Failed to predict input format
    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please


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

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

	if ((B - A) % 2) co("Borys");
	else co("Alice");

	Would you please return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <utility>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;

#define INF_LL (ll)1e18
#define INF (int)1e9
#define REP(i, n) for(int i = 0;i < (n);i++)
#define FOR(i, a, b) for(int i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
using ll = long long;
using PII = pair<int, int>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

class Union_find{
private:
	vector<int> par;
	vector<int> rank;
	int n;

public:
	Union_find(int a){
		n = a;
		for(int i = 0;i < n;i++){
			par.push_back(i);
			rank.push_back(0);
		}
	}

	int find(int x){
		if(par[x] == x){
			return x;
		}else{
			return par[x] = find(par[x]);
		}
	}

	void unite(int x, int y){
		x = find(x);
		y = find(y);
		if(x == y) return;

		if(rank[x] < rank[y]){
			par[x] = y;
		}else{
			par[y] = x;
			if(rank[x] == rank[y]) rank[x]++;
		}
	}

	bool same(int x, int y){
		return find(x) == find(y);
	}
};

const ll mod = 1e9+7;

vector<int> G[114514];
deque<int> deq;

int main(void){
	int N, M;
	cin >> N >> M;
	Union_find uf(N);
	REP(i, M){
		int a, b;
		cin >> a >> b; a--; b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	deq.push_back(0);
	while(1){
		int v1 = deq.front(), v2 = deq.back();
		bool a = true, b = true;
		REP(i, G[v1].size()){
			if(!uf.same(G[v1][i], v1)){
				uf.unite(G[v1][i], v1);
				deq.push_front(G[v1][i]);
				a = false;
				break;
			}
		}
		REP(i, G[v2].size()){
			if(!uf.same(G[v2][i], v2)){
				uf.unite(G[v2][i], v2);
				deq.push_back(G[v2][i]);
				b = false;
				break;
			}
		}
		if(a && b) break;
	}
	cout << deq.size() << endl;
	while(deq.size()){
		cout << deq.front()+1 << " ";
		deq.pop_front();
	}
	cout << endl;
}


Measured memory_bytes: 7796
#[allow(unused_macros)]
macro_rules! get {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
            get!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
            get!($($t),*)
        ).collect::<Vec<_>>()
    };
    ($t:ty ;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty ;; $n:expr) => {
        (0..$n).map(|_| get!($t ;;)).collect::<Vec<_>>()
    };
}

#[allow(unused_macros)]
macro_rules! get_chars {
    () => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().chars().collect::<Vec<_>>()
        }
    };
    ($n:expr) => {
        {
            (0..$n)
                .map(|_| get_chars!())
                .collect::<Vec<_>>()
        }
    };
}

fn main() {
    let (a, b, n) = get!(i64, i64, i64);
    let x = if n >= b {
        b - 1
    } else {
        n
    };

    let ans = (a * x) / b - a * (x / b);
    println!("{}", ans);
}


Measured memory_bytes: 2108
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 0xccccccc;
const ll LINF = 922337203685477580LL;
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);}
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);}
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}

const int N = 2e5+10;

//head

int n;
ll a[N];
ll ma;
ll sum;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  rep(i, n) cin >> a[i];
  //reverse(a, a+n);
  rep(i, n) {
    if(!chmax(ma, a[i])) {
      sum += ma-a[i];
    }
  }

  cout << sum << endl;
}

Measured memory_bytes: 5172
n, k = map(int, input().split())
alst = list(map(int, input().split()))

MOD = 10 ** 9 + 7
N = n + 10
fact = [0 for _ in range(N)]
invfact = [0 for _ in range(N)]
fact[0] = 1
for i in range(1, N):
    fact[i] = fact[i - 1] * i % MOD

invfact[N - 1] = pow(fact[N - 1], MOD - 2, MOD)

for i in range(N - 2, -1, -1):
    invfact[i] = invfact[i + 1] * (i + 1) % MOD
def nCk(n, k):
    if k < 0 or n < k:
        return 0
    else:
        return fact[n] * invfact[k] * invfact[n - k] % MOD
        
alst.sort()
ans = 0
for i, num in enumerate(alst):
    ans -= num * nCk(n - 1 - i, k - 1)
    ans %= MOD

for i, num in enumerate(alst[::-1]):
    ans += num * nCk(n - 1 - i, k - 1)
    ans %= MOD
print(ans)


Measured memory_bytes: 21676
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include<math.h>
#include<map>
#include<set>
using namespace std;
#define INF 11000000000
#define MOD 1000000007
typedef long long ll;
typedef pair<int,int> P;

int num[110000];

int main(){
  string a,b,c;
  cin>>a>>b>>c;
  cout<<a[0]<<b[1]<<c[2]<<endl;
}


Measured memory_bytes: 504
n, k = map(int, input().split())
p = list(map(int, input().split()))

p = list(map(lambda x: x * (x+1) /2 /x, p))

for i in range(1, n):
    p[i] = p[i-1] + p[i]

m = p[k-1]
for i in range(k, n):
    a = p[i] - p[i-k]
    if m < a:
        m = a

print(m)

Measured memory_bytes: 75784
#include <stdio.h>

using namespace std;

struct Node{
	Node(){
		left_child = right_child = parent = -1;
	};
	int left_child,right_child,parent;
};

void preORDER(Node order[],int id){
	printf(" %d",id);
	if(order[id].left_child != -1) preORDER(order,order[id].left_child );
	if(order[id].right_child != -1) preORDER(order,order[id].right_child );
}

void inORDER(Node order[],int id){
	if(order[id].left_child != -1) inORDER(order,order[id].left_child );
	printf(" %d",id);
	if(order[id].right_child != -1) inORDER(order,order[id].right_child );
}

void postORDER(Node order[],int id){
	if(order[id].left_child != -1) postORDER(order,order[id].left_child );
	if(order[id].right_child != -1) postORDER(order,order[id].right_child );
	printf(" %d",id);
}

int main(){
	int n,id,left,right,root_id;
	scanf("%d",&n);
	Node order[n];
	for(int i = 0; i < n; i++){
		scanf("%d %d %d",&id,&left,&right);
		if(left != -1){
			order[id].left_child = left;
			order[left].parent = id;
		}
		if(right != -1){
			order[id].right_child = right;
			order[right].parent = id;
		}
	}

	for(root_id = 0; root_id < n; root_id++){
		if(order[root_id].parent == -1) break;
	}

	printf("Preorder\n");
	preORDER(order,root_id);
	printf("\n");

	printf("Inorder\n");
	inORDER(order,root_id);
	printf("\n");

	printf("Postorder\n");
	postORDER(order,root_id);
	printf("\n");
}



Measured memory_bytes: 2760
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int main(){    
  long long H,N;
  cin >> H >> N; 
  vector<long long> vec(N);
  for(int i = 0; i < N; i++){
    cin >> vec.at(i);
  }
  
  long long a = 0;
  for(int i = 0; i < N; i++){
    a += vec.at(i);
  }
  
  if(H <= a) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  
  
}


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

int N;
vector<int> g[101010];
ll dp[101010][2];
const ll mod = 1e9 + 7;

void dfs(int v, int p = -1) {
    dp[v][0] = dp[v][1] = 1;
    for (auto & u : g[v]) {
        if (u == p) continue;
        dfs(u, v);
        dp[v][0] = dp[v][0] * ((dp[u][0] + dp[u][1])%mod) % mod;
        dp[v][1] = dp[v][1] * dp[u][0] % mod;
    }
}

int main() {
    cin >> N;
    for (int i = 0; i < N-1; ++i) {
        int x, y;
        cin >> x >> y;
        x--; y--;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    dfs(0);
    cout << (dp[0][0] + dp[0][1]) % mod << endl;
}


Measured memory_bytes: 12928