akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[] num = new int[4];
        String ss = sc.next();
        for (int i=0;i<4;i++){
            num[i]=ss.charAt(i)-'0';
        }
        boolean b = true;
        for (int i=0;i<8&&b;i++){
            int ans = num[0];
            int[] integer = {i/4,(i%4)/2,i%2};
            for (int j=0;j<3;j++){
                if (integer[j]==0) ans+=num[j+1];
                else ans-=num[j+1];
            }
            char[] c = new char[3];
            for (int j=0;j<3;j++){
                if (integer[j]==0)c[j]='+';
                else c[j]='-';
            }
            if (ans==7){
                b=false;
                System.out.println(""+num[0]+c[0]+num[1]+c[1]+num[2]+c[2]+num[3]+"=7");
            }
        }
    }
}


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

#define ios ios_base::sync_with_stdio(0), cout.tie(0), cin.tie(0);
#define S second
#define F first
#define pb push_back
#define nl '\n'
#define mp make_pair
#define NL cout << '\n';
#define EX exit(0)
#define all(s) s.begin(), s.end()

const long long MXN = 1e5 + 1;
const long long MNN = 1e3 + 1;
const long long MOD = 1e9 + 7;
const long long INF = 1e18;
const long long OO = 1e9 + 500;

typedef long long llong;

using namespace std;

int n, ok, x, y, t, te;
pair<int, int> p[MXN];

int main(){
    ios;
    //freopen("input.in", "r", stdin);
    //freopen("output.out", "w", stdout);
    cin >> n;
    int curx = 0, cury = 0;
    for(int i = 1; i <= n; i++){
        cin >> t >> x >> y;
        int ct = abs(te - t);
        int dist = abs(curx - x) + abs(cury - y);
        if(ct >= dist && (ct - dist) % 2 == 0){
            curx = x;
            cury = y;
            te = t;
        }else{
            ok = 1;
        }
    }cout << (ok == 1 ? "No" : "Yes");
    return 0;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

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

    rep(i, N)
        cin >> P.at(i);
    
    int s = 0;
    int m = 0;
    int l = 0;

    rep(i, N) {
        if (P.at(i) <= A)
            s++;
        else if (P.at(i) <= B)
            m++;
        else
            l++;
    }

    cout << min(min(s, m), l);
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(N: int, D: "List[List[int]]"):
    n = 0
    for d in D:
        if d[0] == d[1]:
            n += 1
        else:
            n = 0
        if n == 3:
            print(YES)
            break
    else:
        print(NO)
    # if n==3:
    #     print(YES)
    # else:
    #     print(NO)
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    D = [[int(next(tokens)) for _ in range(2)] for _ in range(N)]  # type: "List[List[int]]"
    solve(N, D)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9196
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int a[1223];
int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=2*n;i++)
    {
        cin>>a[i];
    }
    sort(a+1,a+1+2*n);
    int sum=0;
    for(int i=1;i+1<=2*n;i+=2)
    {

        sum+=min(a[i],a[i+1]);
    }
    cout<<sum;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define ss(x) scanf("%s",x)
#define mod 1000000007
#define bitcount __builtin_popcountll
#define ll long long
#define pb push_back
#define pi pair<int,int>
#define pii pair<pi,int>
#define mp make_pair
int a[100005],b[100005];
int main()
{
	int n;
	sd(n);
	int i,j,k;
	for(i=1;i<=n;i++){
		sd(a[i]);
		a[i]+=a[i-1];
	}
	for(i=1;i<=n;i++)
		sd(b[i]);
	for(i=n-1;i>=1;i--)
		b[i]+=b[i+1];
	int ans=0;
	for(i=1;i<=n;i++)
		ans=max(ans,a[i]+b[i]);
	printf("%d\n",ans );
	return 0;
}

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

int solve_testcase() {
  int N; cin >> N;
  if(N == 0) return 1;

  bool exist[21][21] = {};
  bool pass[21][21] = {};
  for(int i=0; i<N; i++) {
    int y, x; cin >> y >> x;
    exist[x][y] = true;
    // fprintf(stderr, "x = %d, y = %d\n", x, y);
  }

  int x = 10, y = 10;
  pass[x][y] = true;

  int M; cin >> M;
  for(int i=0; i<M; i++) {
    char c; cin >> c;
    int m; cin >> m;
    for(int j=0; j<m; j++) {
      if(c == 'N') x++;
      if(c == 'S') x--;
      if(c == 'E') y++;
      if(c == 'W') y--;
      pass[x][y] = true;
    }
  }

  bool ok = true;
  for(int i=0; i<=20; i++) {
    for(int j=0; j<=20; j++) {
      ok &= (!exist[i][j] or pass[i][j]);
    }
  }

  cout << (ok ? "Yes" : "No") << endl;
  return 0;
}

int main() {
  while(!solve_testcase());
  return 0;
}



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

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

const ll MOD = 1e9+7;
// const ll MOD = 998244353;
const ll INF = 1ll<<60;

#define FOR(i,a,b) for (ll i=(a);i<(ll)(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define DEBUG(x) ;
#define DEBUG(x) std::cerr << #x << " : " << (x) << std::endl;

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



int main(int argc, char **argv)
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	ll N, L; cin >> N >> L;
	vector<string> S(N);
	REP(i, N) cin >> S[i];

	sort(ALL(S));
	
	string res{""};
	REP(i, N)
		res += S[i];

	std::cout << res<< std::endl;
	return 0;
}


Measured memory_bytes: 3560
function Main(input) {
  let tmp = input.split("\n");
  let n = parseInt(tmp[0]);
  let nums = tmp[1].split(" ").map((n) => parseInt(n, 10));
  let ans = 100000;
  for (let i = 0; i < n; i++) {
    let cnt = 0;
    while (nums[i] % 2 === 0) {
      cnt++;
      nums[i] /= 2;
    }
    ans = Math.min(ans, cnt);
  }
  console.log(ans);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7500
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace C
{
    public class Program

    {
        public static void Main(string[] args)
        {
            int[] nm = RIntAr();
            int n = nm[0];
            int m = nm[1];

            if (n >= m)
            {
                Console.WriteLine(0);
            }
            else
            {
                int[] items = RIntAr();

                int cnt = 0;
                int sum = 0;

                Array.Sort(items);
                int[] distance = new int[items.Length - 1];
                for (int i = 1 ; i < items.Length ; i++)
                {
                    distance[i - 1] = items[i] - items[i - 1];
                }

                foreach (var item in distance.OrderBy(x => x))
                {
                    sum += item;
                    cnt++;
                    if (cnt == (m - n)) break;
                }
                Console.WriteLine(sum);
            }
        }

        static string RSt() { return Console.ReadLine(); }
        static int RInt() { return int.Parse(Console.ReadLine().Trim()); }
        static long RLong() { return long.Parse(Console.ReadLine().Trim()); }
        static double RDouble() { return double.Parse(Console.ReadLine()); }
        static string[] RStAr(char sep = ' ') { return Console.ReadLine().Trim().Split(sep); }
        static int[] RIntAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => int.Parse(e)); }
        static long[] RLongAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => long.Parse(e)); }
        static double[] RDoubleAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => double.Parse(e)); }
        static string WAr<T>(IEnumerable<T> array, string sep = " ") { return string.Join(sep, array.Select(x => x.ToString()).ToArray()); }
    }

}


Measured memory_bytes: 20960
#include<cstdio>
#include<iostream>
#include<vector>
#include<string>
using namespace std;
typedef long long int ll;
static const int MAX_N = 1000;
static const ll MOD = 1000000007;

int N;
string node[MAX_N];
vector<int> G[MAX_N];

ll rec(int v, int pv){
	ll ret;
	if(node[v][0] == 'E' || node[v][0] == 'R') ret = 1;
	else ret = 0;
	for(int i = 0; i < G[v].size(); i++){
		if(G[v][i] == pv) continue;
		if(node[v][0] == 'E') ret *= rec(G[v][i], v);
		else if(node[v][0] == 'A') ret += rec(G[v][i], v);
		else ret *= (rec(G[v][i], v) + 1);
		ret %= MOD;
	}
	if(node[v][0] != 'R' && node[v].length() == 2 && node[v][1] == '?'){
		ret++;
		ret %= MOD;
	}
	if(node[v] == "R"){
		ret--;
		if(ret < 0) ret += MOD;
	}
	return ret;
}

int main(){
	scanf("%d", &N);
	for(int i = 0; i < N; i++) cin >> node[i];
	for(int i = 0; i < N - 1; i++){
		int s, t;
		scanf("%d %d", &s, &t);
		s--;
		t--;
		G[s].push_back(t);
		G[t].push_back(s);
	}
	printf("%lld\n", rec(0, -1));
	return 0;
}



Measured memory_bytes: 3364
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 5LL << 60;
const ll mod = 1e9 + 7;

int main() {
	ll N, A, B;
	cin >> N >> A >> B;
	cout << (N / (A + B)) * A + min(A, N % (A + B)) << "\n";
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
    int N;
    scanf("%d",&N);
    int a = N /100;
    int b = a*100 + a*10 + a; //全ての桁が同じ
    if(N <= b) printf("%d\n",b);
    else printf("%d\n",b+111);
    return 0;
}

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

int main(int argc, const char *argv[])
{
    int n, x, cnt = 0;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> x;
        if (x % 2 == 1)
        {
            cnt++;
        }
    }

    if (cnt % 2 == 0 || cnt == 1 && n == 1)
    {
        cout << "YES" << endl;
    }
    else
    {
        cout << "NO" << endl;
    }
}


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

using namespace std;

typedef long long ll;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	ll l, r;
	cin >> l >> r;
	r = min(r, l + 4038);
	int ans = 2018;
	for (ll i = l; i <= r; i++){
		for (ll j = i + 1; j <= r; j++) {
			int x = i * j % 2019;
			ans = min(ans, x);
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
int main(){
  ll n;
  cin >> n;
  n;
  string ans = "";
  while(n !=0){
    ll tmp = (n-1)%26 ;
    char tc = 'a' + tmp;
    ans = tc + ans;
    n /= 26;
    if(tmp == 25) n--;
  }
  cout<<ans << endl;
//    cout << fixed << setprecision(10);
}


Measured memory_bytes: 3624
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

int main()
{
	int N = 0;
	std::cin >> N;

	if (N == 1)
	{
		std::cout << "1\n";
		return 0;
	}

	std::vector<std::string> S(N);
	for (int i = 0; i < N; ++i)
	{
		std::cin >> S.at(i);
	}

	std::sort(S.begin(), S.end());

	int overcoatNum = 0;
	std::string searchStr = S.at(0);
	for (int i = 1, n = S.size(); i < n; ++i)
	{
		if (searchStr == S.at(i))
		{
			overcoatNum++;
		}
		else
		{
			searchStr = S.at(i);
		}
	}

	std::cout << S.size() - overcoatNum << "\n";

	return 0;
}

Measured memory_bytes: 9536
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#include<algorithm>
#include<cstdio>
#include<cmath>
#define re register
using namespace std;
int n,m,clb,fz,fm,len,col[500002],cnt[500002],ans[500002],bl[500002],l=1,r,g,pos;
struct que{
	int l,r,id;
	bool operator<(que&b){
		return bl[l]==bl[b.l]?bl[l]&1?r>b.r:r<b.r:l<b.l;
	}
}q[500002];
inline void add(int x){if(!(cnt[x]++))++pos;}
inline void del(int x){if(!(--cnt[x]))--pos;}
const int Mxdt=500000;	//单次大小 
inline char gc(){
	static char buf[Mxdt],*p1=buf,*p2=buf;
	return p1==p2&&(p2=(p1=buf)+fread(buf,1,Mxdt,stdin),p1==p2)?EOF:*p1++;
}
inline int read(){
	int t=0;char v=gc();
	while(v<'0')v=gc();
	while(v>='0')t=(t<<3)+(t<<1)+v-48,v=gc();
	return t;
}
inline char pc(char ch,bool bj){
	static char buf[Mxdt],*p1=buf,*p2=buf+Mxdt;
	return (bj||(*p1++=ch)&&p1==p2)&&fwrite(p1=buf,1,p1-buf,stdout),0;
}
void print(int x)
{
	if(x>9)print(x/10);
	pc(x%10^48,false);
}
inline void printnum(int x,char ch)
{
	print(x),pc(ch,false);
}
int main(){
	n=read(),m=read();
	clb=sqrt(n*2);
	for(re int i=1;i<=n;++i)bl[i]=i/clb,col[i]=read();
	for(re int i=0;i<m;++i)q[i].l=read(),q[i].r=read(),q[i].id=i;
	sort(q,q+m);
	for(int i=0;i<m;i++){
		while(l>q[i].l)add(col[--l]);
		while(r<q[i].r)add(col[++r]);
		while(l<q[i].l)del(col[l++]);
		while(r>q[i].r)del(col[r--]);
		ans[q[i].id]=pos;
	}
	for(int i=0;i<m;++i)printnum(ans[i],'\n');
	return pc('o',1);
}

Measured memory_bytes: 18284
from collections import Counter
n=int(input())
v=list(map(int,input().split()))
a=Counter(v[::2]).most_common() #(数字,何回出現)が出現回数が大きい方から
b=Counter(v[1::2]).most_common()
if len(a)==1:
    a.append([0,0])
if len(b)==1:
    b.append([0,0])
if a[0][0]==b[0][0]:
    print(min(n-a[1][1]-b[0][1],n-a[0][1]-b[1][1]))
else:
    print(n-a[0][1]-b[0][1])

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

int main() {
  int n;
  cin >> n;
  int m;
  vector<priority_queue<int>> s(n);
  int c;
  int i, j;
  for (i = 0; i < n; i++) {
    cin >> m;
    for (j = 0; j < m; j++) {
      cin >> c;
      s[i].push(c);
    }
  }
  priority_queue<int> max_list;
  max_list.push(-s[0].top());
  for (i = 1; i < n; i++) {
    max_list.push(-s[i].top());
    s[i].pop();
    while (s[i].top() > -max_list.top() && s[i].size()) {
      max_list.pop();
      max_list.push(-s[i].top());
      s[i].pop();
    }
  }
  long long result = 0;
  while (max_list.size()) {
    result -= max_list.top();
    max_list.pop();
  }
  cout << result << endl;
  return 0;
}



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

// macro
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long
#define all(v) v.begin(), v.end()

// code starts
#define MOD1 998244353
#define MOD2 469762049
#define A_MAX 100000

ll pow(ll n, ll k, ll mod)
{
  ll num=n;
  ll ans=1;
  while(k!=0)
  {
    if(k%2==1)ans=(ans*num)%mod;
    k/=2;
    num=(num*num)%mod;
  }
  return ans;
}

ll mod_inv(ll n, ll mod)
{
  return pow(n, mod-2, mod);
}

vector<ll> ntt(vector<ll> f, ll n, ll mod)
{
  if(n==1)return f;
  else
  {
    vector<ll> f0(n/2);
    vector<ll> f1(n/2);
    int i;
    rep(i,n/2)
    {
      f0[i]=f[2*i];
      f1[i]=f[2*i+1];
    }
    f0 = ntt(f0, n/2, mod);
    f1 = ntt(f1, n/2, mod);
    ll zeta = pow((ll)3, (mod-1)/n, mod);//prepare num;
    ll pow_zeta = 1;
    rep(i,n)
    {
      f[i] = (f0[i%(n/2)] + pow_zeta * f1[i%(n/2)])%mod;
      pow_zeta = (pow_zeta*zeta)%mod;
    }
    return f;
  }
}

vector<ll> inv_ntt(vector<ll> f, ll n, ll mod, ll nf)
{
  if(n==1)return f;
  else
  {
    vector<ll> f0(n/2);
    vector<ll> f1(n/2);
    int i;
    rep(i,n/2)
    {
      f0[i]=f[2*i];
      f1[i]=f[2*i+1];
    }
    f0 = inv_ntt(f0, n/2, mod, nf);
    f1 = inv_ntt(f1, n/2, mod, nf);
    ll zeta = mod_inv(pow((ll)3, (mod-1)/n, mod), mod);
    ll pow_zeta = 1;
    rep(i,n)
    {
      f[i] = (f0[i%(n/2)] + pow_zeta * f1[i%(n/2)])%mod;
      pow_zeta = (pow_zeta*zeta)%mod;
    }
    if(n==nf)
    {
      rep(i,n)f[i]=(f[i]*mod_inv(n,mod))%mod;
    }
    return f;
  }
}

int main()
{
  ll n,m;cin>>n>>m;
  vector<int> a(n);
  int i;
  rep(i,n)cin>>a[i];
  vector<ll> num(A_MAX+1,0);
  rep(i,n)num[a[i]]++;
  ll n2 = 1;
  while(n2<=2*A_MAX)n2*=2;
  vector<ll> gt(n2,0);
  rep(i,A_MAX+1)gt[i]=num[i];
  gt = ntt(gt, n2, MOD1);
  vector<ll> ggt(n2);
  rep(i,n2)ggt[i]=(gt[i]*gt[i])%MOD1;

  vector<ll> ht(n2,0);
  rep(i,A_MAX+1)ht[i]=num[i];
  ht = ntt(ht, n2, MOD2);
  vector<ll> hht(n2);
  rep(i,n2)hht[i]=(ht[i]*ht[i])%MOD2;

  vector<ll> ans1(n2,0);
  ans1 = inv_ntt(ggt,n2,MOD1,n2);
  vector<ll> ans2(n2,0);
  ans2 = inv_ntt(hht,n2,MOD2,n2);
  
  vector<ll> pats(A_MAX*2+1);
  rep(i,A_MAX*2+1)
  {
    pats[i]=ans1[i];
    while(pats[i]%MOD2!=ans2[i])
    {
      pats[i]+=MOD1;
    }
  }
  ll count=0;
  ll total=0;
  ll now=A_MAX*2;
  while(count<m)
  {
    ll take=min(m-count,pats[now]);
    count+=take;
    total+=now*take;
    now--;
  }
  cout<<total<<endl;
}


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

int main(){
    int Q;
    cin >> Q;
    while(Q--){
        int c,a,n,st;
        cin >> c >> a >> n;
        int ans = min(min(c,a),n);
        c -= ans; a -= ans; n -= ans;
        st = min(c/2,a); c -= st*2; a -= st;
        ans += st;
        ans += c/3;
        cout << ans << endl;
    }
}

Measured memory_bytes: 1160
import sys

def II(): return int(input())
def MI(): return map(int,input().split())
def LI(): return list(map(int,input().split()))
def TI(): return tuple(map(int,input().split()))
def RN(N): return [input().strip() for i in range(N)]


def main():
    N = II()
    Nstr = str(N)
    Nsl = list(Nstr)
    ans = 0

    for i in range(len(Nstr)):
        n = int(Nsl[i])
        ans += n

    if ans%9 == 0:
        print("Yes")
    else:
        print("No")
    
    #print(len(Nstr))

if __name__ == "__main__":
	main()

Measured memory_bytes: 10776
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

string A,B,C;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>A>>B>>C;
	cout<<A[0]<<B[0]<<C[0]<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}


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

int main () {
    int a, b;
    cin >> a >> b;
    
    vector<int>hi1(b);
    vector<int>hi2(b);
    vector<int>k(a);
    
    for (int t = 0; t < b; t++) {
        cin >> hi1.at(t) >> hi2.at(t);
    }
    
    for (int t = 0; t < b; t++) {
        for (int s = 0; s < a; s++) {
            if (hi1.at(t) == s+1) {
                k.at(s) += 1;
            } else if (hi2.at(t) == s+1) {
                k.at(s) += 1;
            }
        }
    }
    
    for (int s = 0; s < a; s++) {
        cout << k.at(s) << endl;
    }
}









Measured memory_bytes: 256
//clear adj and visited vector declared globally after each test case
//check for long long overflow
//while adding and subs check if mod becomes -ve
//while using an integer directly in a builtin function add ll
//Mod wale question mein last mein if dalo ie. Ans<0 then ans+=mod;
//Dont keep array name as size or any other key word

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define int long long
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);cout.precision(dbl::max_digits10);
#define pb push_back
#define mod 1000000007 //998244353
#define lld long double
#define mii map<int, int>
#define mci map<char, int>
#define msi map<string, int>
#define pii pair<int, int>
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define rep(i,x,y) for(int i=x; i<y; i++)
#define fill(a,b) memset(a, b, sizeof(a))
#define vi vector<int>
#define setbits(x) __builtin_popcountll(x)
#define print2d(dp,n,m) for(int i=0;i<=n;i++){for(int j=0;j<=m;j++)cout<<dp[i][j]<<" ";cout<<"\n";}
typedef std::numeric_limits< double > dbl;
using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
const long long N=200005, INF=2000000000000000000;
lld pi=3.1415926535897932;
int lcm(int a, int b)
{
    int g=__gcd(a, b);
    return a/g*b;
}
int power(int a, int b, int p)
    {
        if(a==0)
        return 0;
        int res=1;
        a%=p;
        while(b>0)
        {
            if(b&1)
            res=(res*a)%p;
            b>>=1;
            a=(a*a)%p;
        }
        return res;
    }

int32_t main()
{
    IOS;
    int x,n;
    cin>>x>>n;
    mii mp;
    if(n>0){
    int ar[n];
    for(int i=0;i<n;i++)
    {
        cin>>ar[i];
        mp[ar[i]]++;
    }}
    for(int i=0;i<=200;i++)
    {
        if(mp.find(x-i)==mp.end())
        {
            cout<<x-i;
            return 0;
        }
        if(mp.find(x+i)==mp.end())
        {
            cout<<x+i;
            return 0;
        }
    }
}

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

void print(const vector<int>& xs) {
  for (const auto& x : xs) cout << x << ", ";
  cout << endl;
}

int main() {
  int N, M, X;
  cin >> N >> M >> X;
  vector<int> xs(N + 1);
  for (int i = 1; i <= M; ++i) {
    int A;
    cin >> A;
    ++xs[A];
  }
  for (int i = 1; i <= N + 1; ++i) xs[i] += xs[i - 1];
  cout << min(xs[X], xs[N] - xs[X]) << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
//deque/functional/iterator/list/map/memory/numeric/queue/set/stack/utility/vector
//#include<bits/stdc++.h>
#define ll long long
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	int a,b,k;
	cin>>a>>b>>k;
	if(k>(b-a+1)/2){
		for(int i=a;i<=b;i++){
			cout<<i<<endl;
		}
	}else{
		for(int i=0;i<k;i++){
			cout<<a+i<<endl;
		}
		for(int i=k-1;i>=0;i--){
			cout<<b-i<<endl;
		}
	}


return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
 
class Program
{
    static void Main(string[] args)
    {
        int N = int.Parse(Console.ReadLine());
        List<int> L = Console.ReadLine().Split(' ').Select(o => int.Parse(o)).ToList();

        Console.WriteLine(L.OrderBy(o => o).Where((o, p) => p % 2 == 0).Sum());
    }
}

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

using namespace std;

int main() {
	long long n;
	cin >> n;
	
	long long c = 1;
	while(n > 0) {
		c = (c * n) % 1000000007;
		n--;
	}
	
	cout << c << endl;
	
}

Measured memory_bytes: 3596
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a_min = min(a)
b_min = min(b)
total_min = a_min + b_min 
for i in range(M):
    x, y, c = map(int, input().split())
    total = a[x-1] + b[y-1] - c
    if total < total_min:
        total_min = total
print(total_min)

Measured memory_bytes: 18612
#include <bits/stdc++.h>
#define mset(a, b) memset(a, b, sizeof(a))
#define mcpy(a, b) memcpy(a, b, sizeof(a))
#define rg register
using namespace std;
typedef long long LL;
const int MAXN = 2005;

template <typename T> inline void read(T &AKNOI) {
	T x = 0, flag = 1;
	char ch = getchar();
	while (!isdigit(ch)) {
		if (ch == '-') flag = -1;
		ch = getchar();
	}
	while (isdigit(ch)) {
		x = x * 10 + ch - '0';
		ch = getchar();
	}
	AKNOI = flag * x;
}

namespace ModCalculator {
	const int MOD = 1e9 + 7;
	inline void Inc(int &x, int y) {
		x += y; if (x >= MOD) x -= MOD;
	}
	inline int Add(int x, int y) {
		Inc(x, y); return x;
	}
	inline void Dec(int &x, int y) {
		x -= y; if (x < 0) x += MOD;
	}
	inline int Sub(int x, int y) {
		Dec(x, y); return x;
	}
}
using namespace ModCalculator;

int n, m, K, dp[MAXN*2][MAXN][2], sum[MAXN], ans;

void solve() {
	read(n); read(m); read(K);
	--m; --K;
	dp[0][0][0] = 1;
	for (int i=1,rbd=max(n, m)*2;i<=rbd;++i) {
		for (int j=0;j<=n;++j) {
			sum[j+1] = Add(sum[j], Add(dp[i-1][j][0], dp[i-1][j][1]));
		}
		for (int j=0;j<=n;++j) {
			dp[i][j][0] = Sub(sum[j+1], sum[j]);
			dp[i][j][1] = Sub(sum[j], sum[max(0, j-K)]);
		}
		for (int j=0;j<=n;++j) {
			if (j%K != n%K) continue;
			if (i*K-j > m || (i*K-j)%K != m%K) continue;
			Inc(ans, dp[i][j][1]);
		}
	}
	printf("%d\n", ans);
}

int main() {
	solve();
	return 0;
}


Measured memory_bytes: 62976
//A.cpp
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <math.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b!=0?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
const ll mod=1e9+7;


int main(){
  int n,q;
  cin >> n >> q;
  string s;
  cin >> s;
  int a[n] = {0};
  rep(i,n-1){
    a[i+1] += a[i];
    if(s.substr(i,2) == "AC") a[i+1]++;
  }
  int l[q];
  int r[q];
  rep(i,q) cin >> l[i] >> r[i];
  rep(i,q){
    // cin >> l >> r;
    printf("%d\n", a[r[i]-1] - a[l[i]-1]);
  }
  return 0;
}


Measured memory_bytes: 2176
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll len(ll x){
  ll a=1,k=0,j=1;
  while(a*10<=x) k+=9*a*j,a*=10,j++;
  k+=(x-a+1)*j;
  return k;
}
int main(){
  ll n,k;
  while(cin>>n>>k,n||k){
    ll l=0,r=1000000000LL,m,i;
    string s;
    while(l+1<r) (len(m=(l+r)/2)<n)?l=m:r=m;
    for(i=1;i<10000;i++) s+=to_string(l+i);
    for(i=0;i<k;i++) cout << s[n-len(l)-1+i];
    cout << endl;      
  }
  return 0;
}

Measured memory_bytes: 3344
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include <vector>

using namespace std;
template <class T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto i = v.begin(); i != v.end(); i++) {
    os << *i << " ";
  }
  return os;
}

bool check_blank_col(vector<string> &v, int col) {
  bool f = true;
  for (auto it = v.begin(); it != v.end(); it++) {
    if (it->at(col) != '.')
      f = false;
  }
  return f;
}

void remove_col(vector<string> &v, int col) {
  for (auto it = v.begin(); it != v.end(); it++) {
    it->erase(col, 1);
  }
}

int main(void) {
  vector<string> v;
  int h, w;
  cin >> h >> w;
  for (int i = 0; i < h; i++) {
    string x;
    cin >> x;
    if (x != string(w, '.'))
      v.push_back(x);
  }
  for (int i = 0; i < v.begin()->size(); i++) {
    if (check_blank_col(v, i)) {
      remove_col(v, i);
      i = -1;
    }
  }
  for (auto i = v.begin(); i != v.end(); i++) {
    std::cout << *i << std::endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
typedef pair<int,int> PA;
const int  INF = (1<<29);
vector<PA> vec[101];
int min_cost[303];
priority_queue<PA,vector<PA>,greater<PA> > pq;

int dijkstra(int s,int t){
  
  int cost,to,spot;
  
  fill(min_cost,min_cost+303,INF);
  min_cost[s] = 0;
  
  pq.push(PA(0,s));
  
  while(!pq.empty()){
    
    PA p = pq.top();
    pq.pop();
    
    if(p.second <= 100) spot = p.second;
    else if(p.second <= 200) spot = p.second - 100;
    else if(p.second <= 300) spot = p.second - 200;
    
    for(int i=0;i<vec[spot].size();i++){
      
      if(p.second <= 100){
	
	cost = p.first + vec[spot][i].first;
	to = vec[spot][i].second;
	
	if(min_cost[to] > cost){
	  min_cost[to] = cost;
	  pq.push(PA(cost,to));
	}
	
	cost = p.first;
	to = vec[spot][i].second + 100;
	
	if(min_cost[to] > cost){
	  min_cost[to] = cost;
	  pq.push(PA(cost,to));
	}
	
      }else if(p.second <= 200){
	
	cost = p.first;
	to = vec[spot][i].second + 200;
	
	if(min_cost[to] > cost){
	  min_cost[to] = cost;
	  pq.push(PA(cost,to));
	}
	
      }else if(p.second <= 300){
	
	cost = p.first + vec[spot][i].first;
	to = vec[spot][i].second + 200;
	
	if(min_cost[to] > cost){
	  min_cost[to] = cost;
	  pq.push(PA(cost,to));
	}
	
      }
      
    }
    
  }
  
  return( min(min_cost[t],min_cost[200+t]) );
}

int main(){

  int n,m,a,b,c;
 
  while(cin >> n >> m,n!=0&&m!=0){
    for(int i=0;i<m;i++){
      cin >> a >> b >> c;
      vec[a].push_back(PA(c,b));
      vec[b].push_back(PA(c,a));
    }
    
    cout << dijkstra(1,n) << endl;
    for(int i=1;i<=n;i++) vec[i].clear();
  }
  
  return(0);
}



Measured memory_bytes: 3100
fun main(args: Array<String>) {
    val N = readLine()?.toInt()?: 0
    val s = Array<String>(N,{it.toString()})
    val set = mutableSetOf<String>();
    for(i in 0..N-1){
      s[i] = readLine()!!
      set += s[i];
    }
    val M = readLine()?.toInt()?: 0
    val t = Array<String>(M,{it.toString()})
    for(i in 0..M-1){
      t[i] = readLine()!!
    }
    var ans = 0;
    set.map{word ->
    val result = plusCount(word, s) - minusCount(word, t)
    if(result > ans) ans = result
    }
    if(ans < 0) println("0") else println(ans)

}

fun plusCount(set: String, s: Array<String>): Int {
  return s.filter{str -> set == str}.count()
}
fun minusCount(set: String, t: Array<String>): Int {
  return t.filter{str -> set == str}.count()
}

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

#define rep(i,a,b) for(int i=a;i<b;i++)
#define drep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
using namespace std;
void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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 (b < a) { a = b; return 1; } return 0; }

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

void _main() {
    int K, A, B;
    cin >> K;
    cin >> A >> B;
    bool res = false;
    rep(i, A, B + 1) {
        if (i % K == 0) {
            res = true;
            break;
        }
    }
    if (res) cout << "OK" << endl;
    else cout << "NG" << endl;
}

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

#define pb push_back
#define ll long long
#define maxn 300005
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define ms(i) memset(i,0,sizeof(i));
#define ms1(i) memset(i,-1,sizeof(i));
#define bg begin()
#define ed end()
#define pii pair<int,int>

int main()
{
	ll a,b,c;
	while(cin >> a >> b >> c){
		ll ans = 0;
		ll need = b-1;
		if(c-b<=2){
			ans=a+1;
		}
		else if(a<need+2){
			ans=a+1;
		}
		else{
			ans=b;
			a-=need;
			if(a%2)ans++;
			ans += (c-b)*(a/2);
		}
		cout << ans << endl;
	}
	
	
}


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

int main(void){
    int N, sum;
    sum = 0;
    cin >> N;
    for (int i = 0; i < N; i++) {
        int n, m;
        cin >> m >> n;
        sum += (n - m + 1);
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 256
import collections
N = int(input())
A = list(map(int, input().split()))
cnt = collections.Counter(A)
cmb = {}
cmb_sub = {}
for key, val in cnt.items():
    cmb[key] = int(val * (val - 1) / 2)
    cmb_sub[key] = int((val - 1) * (val - 2) / 2)
cmbsum = sum(cmb.values())
dict_ans = {}
for key in cmb.keys():
    dict_ans[key] = cmbsum - cmb[key] + cmb_sub[key]
for a in A:
    print(dict_ans[a])

Measured memory_bytes: 47388
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include "bits/stdc++.h"

#define REP(i,x,y) for(int i=(x);i<(y);i++)
#define RREP(i,x,y) for(int i=(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
//#define int long long

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

#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

typedef long long ll;

const ll MOD = 1e9 + 7;

class BSortingASegment {
public:
	void solve(std::istream& in, std::ostream& out) {
	    int N, K;
	    in >> N >> K;
	    vector<int> P(N);
	    REP(i,0,N) in >> P[i];

	    vector<bool> notChanged(N-K+1, false);
        int continuousAdd = 0;
        REP(i,1,N) {
	        if (P[i] > P[i-1]) continuousAdd++;
	        else continuousAdd = 0;
	        if (continuousAdd >= K-1) {
	            notChanged[i-K+1] = true;
	        }
	    }

	    map<int, bool> sorted;
	    REP(i,0,K) sorted[P[i]] = true;
	    int answer = notChanged[0] ? 0 : 1, prevSecond = next(sorted.begin())->first, prevLast = sorted.rbegin()->first;
	    REP(i,1,N-K+1) {
	        sorted.erase(P[i-1]);
	        sorted[P[i+K-1]] = true;
	        int first = sorted.begin()->first, lastSecond = next(sorted.rbegin())->first;
	        if ((first != prevSecond || prevLast != lastSecond) && !notChanged[i]) answer++;
	        prevSecond = next(sorted.begin())->first;
	        prevLast = sorted.rbegin()->first;
	    }
        if (find(all(notChanged), true) != notChanged.end()) {
            answer++;
        }
	    out << answer << "\n";
	}
};


signed main() {
	BSortingASegment solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 10368
/* 実行時間1s制限の場合10^6 1,000,000 : 余裕をもって間に合う10^7
  10,000,000 : おそらく間に合う10^8 100,000,000 : 非常にシンプルな処理
  でないと厳しい
 */
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#include <bits/stdc++.h>
using namespace std;

typedef long long ll; // long longはデータモデル(LLP64, LP64, ...)によらず64bit.
ll gcd(ll a, ll b) {return b ? gcd(b, a%b) : a;}  // Greatest Common Divisor ユークリッドの互除法（aが長辺）
vector<pair<ll,int>> factorize(ll n) {            // a,bの公約数 = GCD(a, b)の約数
    vector<pair<ll,int>> res;
    for (ll i = 2; i*i <= n; i++) { // √nまで探せばよい
        if (n%i) continue;
        res.emplace_back(i, 0);     // 割り切れたら
        while (n%i == 0) {
            n /= i;
            res.back().second++;
        }
    }
    if (n != 1) res.emplace_back(n, 1); // この時点で1でなかったら、残りは素数.
    return res;
}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}         // Least Commont Multiple オーバーフローしないように先に割る
ll ceil(ll a, ll b) {return (a+b-1)/b;}

const ll INF = LONG_MAX;
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; }

int main(int argc, char* argv[])
{
#ifdef LOCAL
    // 以降 cin の入力元が 'xxx.txt' になる
    // std::ifstream in(argv[1]);
    //std::cin.rdbuf(in.rdbuf());
    //std::ifstream in(string(argv[0]) + ".txt");
    std::ifstream in("in.txt");
    std::cin.rdbuf(in.rdbuf());
#endif

    int n, k;
    cin >> n >> k;

    int ans = 1;
    rep(i, n) {
        int a = ans * 2;
        int b = ans + k;
        if (a < b) {
            ans = a;
        }
        else {
            ans = b;
        }
    }

    cout << ans;



    return 0;
}

/*
  - 1e9 : 10^9
  - container一般
    - 合計
      accumulate(a.begin(), a.end(), 0LL)  0LLはオーバーフロー用
  - vector
    vector<int> A(N, 0); // 0で初期化(省略可)
    - loop
      for  (int i = 0; i < A.size(); i++) {}
      for  (int elem : A) {}
    - sort
      std::sort(v.begin(), v.end());  // 昇順
      std::sort(v.begin(), v.end(), std::greater<int>()); //降順
      - vector<vector<int>> cnt(h, vector<int>(w))
    - sort(struct)
        struct st_t {
            string name;
            int p;
            bool operator<(const st_t& another) const {
                if (name == another.name)
                {
                    return p > another.p;
                }
                return name < another.name;
            }
        };
        vector<st_t> st(n);
        sort(st.begin(), st.end());
  - pair
    - pairのソートの定義 : firstが優先的に比較。同じだったらsecond。
    - pair<pair<string,int>,int> p[110];
      std::sort(p,p+a);
        こうすると、first.first -> first.second -> secondの順にソートされる
    - sort
      - sort(a.begin(), cb.end(), greater<pair<int, int>>());
  - map
    - for (auto x : map) {}  // x.first:key  x.second:value.
  - priority_queue<int> q;
    - q.top()に最大値が入っている
  - string
    - loop
      for (char& c : s) {}
 */



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>

using namespace std;

int main() {
    double a, b, c, d, e, f;


    while (cin >> a >> b >> c >> d >> e >> f) {
        double div = 1 / (a*e - b*d);
        double x = (e*c - b*f) * div + 0;
        double y = (a*f - d*c) * div + 0;

        x = roundf(x * 1000) / 1000.;
        y = roundf(y * 1000) / 1000.;
        printf("%.3f %.3f\n", x, y);
    }

    return 0;
}

Measured memory_bytes: 3240
#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
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 (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

using ll = long long;
using ull = unsigned long long;
const int INF = 1e9;
// const int MOD = 1e9 + 7;
// 1次元 vector
template <class T>
ostream &operator<<(ostream &s, vector<T> vec) {
    for (int i = 0; i < (int)vec.size(); ++i) {
        if (i > 0) {
            s << " ";
        }
        s << vec[i];
    }
    return s << endl;
}
template <class T>  // 2次元 vector
ostream &operator<<(ostream &s, vector<vector<T>> vec2) {
    for (int i = 0; i < (int)vec2.size(); ++i) {
        s << vec2[i];
    }
    return s;
}

int main() {
    int N;
    cin >> N;
    vector<int> S(1 << N), T;
    priority_queue<int> que;
    for (int i = 0; i < (1 << N); i++) {
        cin >> S.at(i);
        que.push(S[i]);
    }
    sort(S.begin(), S.end(), greater<int>());

    T.push_back(que.top());
    que.pop();
    for (int i = 0; i < N; i++) {
        //cerr << T;
        vector<int> s;
        for (int j = 0; j < (1 << i); j++) {
            while (!que.empty()) {
                int now = que.top();
                if (now >= T[j]) {
                    s.push_back(now);
                    que.pop();
                } else {
                    T.push_back(now);
                    break;
                }
            }
            if (que.empty()) {
                cout << "No\n";
                return 0;
            } else {
                que.pop();
            }
        }
        sort(T.begin(), T.end(), greater<int>());
        for (auto a : s) {
            que.push(a);
        }
    }
    cout << "Yes\n";
}


Measured memory_bytes: 4408
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <vector>
#include <list>
#include <bitset>
#include <iostream>
#include <set>
#include <map>
#include <string>
#include <sstream>
#include <climits>
#include <cmath>
#include <stack>
#include <queue>
#include <cfloat>
#include <initializer_list>
#include <iomanip>
#include <functional>
#include <unordered_map>
#include <regex>

using namespace std;

const int INF = 1 << 24;
int A[42], B[42], C[42];
int Ma, Mb;
int N;
int memo[42][410][410];

int solve(int index, int a, int b)
{
  if (a != 0 && a % Ma == 0 && b % Mb == 0 && a * Mb == b * Ma) return 0;
  if (index == N) return INF;
  int& res = memo[index][a][b];
  if (res != -1) return res;
  res = min(C[index] + solve(index + 1, a + A[index], b + B[index]),
            solve(index + 1, a, b));
  return res;
}

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(false);
  cin >> N >> Ma >> Mb;
  for (int i = 0; i < N; ++i)
    {
      cin >> A[i] >> B[i] >> C[i];
    }
  memset(memo, -1, sizeof memo);
  int res = solve(0, 0, 0);
  cout << (res == INF ? -1 : res)  << endl;
}


Measured memory_bytes: 27776
#include <stdio.h>
int main(void) {
	long long int n;
    scanf("%lld", &n);
    long long int a[n];
    for(int i=0; i<n; i++) scanf("%lld", &a[i]);
    //for(int i=0; i<n; i++) printf("%d\n", a[i]);
    long long int sum_height = 0;
    for(int i=1; i<n; i++){
    	if(a[i] < a[i-1]){
        	sum_height += a[i-1] - a[i];
            a[i] = a[i-1];
        }
    }
    printf("%lld\n", sum_height);
    return 0;
}

Measured memory_bytes: 3260
#include<stdio.h>

int search(int A[],int N,int key){
  int i=0;
  A[N]=key;
  while(A[i] !=key)
    i++;
  return i !=N;
}

int main(){
  int i,N,M,A[10001],key,k=0;
  scanf("%d",&N);
  for(i=0;i<N;i++){
    scanf("%d",&A[i]);
  }
  scanf("%d",&M);
  for(i=0;i<M;i++){
    scanf("%d",&key);
    if(search(A,N,key))
      k++;
  }
  printf("%d\n",k);

  return 0;
}


Measured memory_bytes: 2104
#include <iostream>
#include <cstdio>
#include <iostream>
#include <string>
#include <fstream>
#include <queue>
#include <cmath>
using namespace std;

int main(){
  int a;
  string s;
  cin>>s;
  if(s[0]==s[1]&& s[1]==s[2])puts("No");
  else puts("Yes");
  
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)(((n)>>(m))&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)

int main(){
	int n;
	scanf("%d",&n);
	int ans=0;
	rep(i,1,n+1){
		int t;
		scanf("%d",&t);
		if(i%2==1&&t%2==1)ans++;
	}
	printf("%d",ans);
}

Measured memory_bytes: 1720
#include<iostream>
using namespace std;
int arr[10];
bool dfs(int);
int l,r;
int main(){
	int t;
	cin>>t;
	while(t--){
		for(int i=0;i<10;i++)
			cin>>arr[i];
		l=r=0;
		if(dfs(0))
			cout<<"YES\n";
		else cout<<"NO\n";
	}
	return 0;
}
bool dfs(int t){
	if(t==10) return 1;
	int t1=l;
	if(arr[t]>l){
		l=arr[t];
		if(dfs(t+1))
			return 1;
		l=t1;
	}
	int t2=r;
	if(arr[t]>r){
		r=arr[t];
		if(dfs(t+1))
			return 1;
		r=t2;
	}
	return 0;
}



Measured memory_bytes: 2956
import numpy as np
from itertools import accumulate
from operator import add, mul

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

l = np.arange(N+1)
L = l.tolist()
L = accumulate(L, add)
L = list(L)

rev_L = reversed(l)
rev_L = accumulate(rev_L, add)
rev_L = list(rev_L)
ans = 0

for i in range(N+2-K):
  min_sum = L[K-1+i]
  max_sum = rev_L[K-1+i]
  ans += max_sum - min_sum + 1
  q, mod = divmod(ans, 10**9+7)

print(mod)

Measured memory_bytes: 46912
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

#define rep(i, l, n) for(int i=(l); i<(int)(n); i++)
#define REP(i, n) for(int i=1; i<=(int)(n); i++)

using namespace std;

int main(){
    int N;
    int K;
    cin >> N;
    cin >> K;
    vector<int> h(N+1);
    vector<int> dp(N+1);

    rep(i, 1, N+1) {
        cin >> h[i];
    }

    rep(i, 0, N+1) dp[i] = 0;

    rep(i, 2, N+1) {
        dp[i] = dp[i-1] + abs(h[i-1] - h[i]);
        rep(j, 1, K+1) {
            if (i-j>=1) {
                dp[i] = min(dp[i], dp[i-j] + abs(h[i-j] - h[i]));
            }
        }
    }
    cout << dp[N] << endl;

    return 0;
}



Measured memory_bytes: 1024
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<long long> a(n);
    for(int i=0; i<n; ++i)
        cin >> a[i];
    sort(a.begin(), a.end());

    long long ret = 0;
    for(int i=0; i<n; ++i){
        if(a[i] > ret + 1)
            break;
        ret += a[i];
    }

    cout << (ret + 1) << endl;
    return 0;
}

Measured memory_bytes: 1296
#include <bits/stdc++.h>
using i64 = long long;

int main() {
    i64 a, b;
    std::cin >> a >> b;

    if (a == 1 || b == 1)  std::cout << 1 << std::endl;
    else std::cout << (a * b + 1) / 2 << std::endl;

    return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var N int
	fmt.Scan(&N)
	var expect = 1
	for i := 0; i < N; i++ {
		var givenValue int
		fmt.Scan(&givenValue)
		if givenValue == expect {
			expect++
		}
	}
	var answer int
	if expect != 1 {
		answer = N - expect + 1
	} else {
		answer = -1
	}

	fmt.Println(answer)
}


Measured memory_bytes: 7684
#include <iostream>
#include <string>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <set>

using namespace std;

typedef long long i64;
typedef i64 int_t;
typedef vector<int_t> vi;
typedef vector<vi> vvi;

typedef pair<int_t, int_t> pi;

#define tr(c, i) for(auto i = (c).begin(); i != (c).end(); i++)
#define pb push_back
#define sz(a) int((a).size())
#define all(c) (c).begin(), (c).end()
#define REP(s, e, i) for(i=(s); i < (e); ++i)

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

  i64 N, i;
  cin >> N;
  vector<pi> A(N);
  REP(0, N, i) {
    cin >> A[i].first;
    A[i].second = i + 1;
  }
  sort(all(A));
  REP(0, N, i) {
    if(i != 0) {
      cout << " ";
    }
    cout << A[i].second;
  }
  cout << endl;
  
  return 0;
}


Measured memory_bytes: 2432
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;

double pdistance(double X[], double Y[], double n) {
    double sum = 0;
    for (int i = 0; i < n; i++) sum += pow(Y[i] - X[i], 2);
    sum = sqrt(sum);
    return sum;
}

int main() {
    int N, D;
    double X[10][10];

    cin >> N >> D;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < D; j++) {
            cin >> X[i][j];
        }
    }

    int cnt = 0;
    for (int i = 0; i < N; i++) {
        for (int j = i + 1; j < N; j++) {
            double d = pdistance(X[i], X[j], D);
            //cout << "(" << i << "," << j << ") " << d << endl;
            if (ceil(d) == d) cnt++;
        }
    }

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/tree_policy.hpp>
 
#define pb push_back
#define mp make_pair

typedef long long ll; 

#define fi first
#define se second
 
#define all(x) (x).begin(), (x).end()
 
using namespace std;             
//using namespace __gnu_pbds;
 
//template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

int n, k;
int a[100500], m[100500];

void solve() {       
    int cnt = 0;
    cin >> n;

    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        m[a[i]] = i;
    }
    
    for (int i = 1; i <= n; i++) cout << m[i] << ' ';

}           
 
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    int tt = 1;
 
    while (tt--) {
        solve();
    }
 
    return 0;
}

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

bool search_small_area(vector<vector<char>>a,vector<vector<char>>b,int i,int j) {
	for (int k(0); k < b.size(); k++) {
		for (int l(0); l < b.size(); l++) {
			if (a[i + k][j + l] != b[k][l])return false;
		}
	}
	return true;
}

bool search_large_area(vector<vector<char>>a,vector<vector<char>>b) {
	int search_length = a.size() - b.size() + 1;
	for (int i(0); i < search_length; i++) {
		for (int j(0); j < search_length; j++) {
			if (search_small_area(a, b, i, j))return true;
		}
	}
	return false;
}

int main(void) {
	int n, m;
	cin >> n >> m;
	vector<vector<char>>a;
	vector<vector<char>>b;
	for (int i(0); i < n; i++) {
		vector<char>tmp_vector;
		for (int j(0); j < n; j++) {
			char tmp;
			cin >> tmp;
			tmp_vector.push_back(tmp);
		}
		a.push_back(tmp_vector);
	}
	for (int i(0); i < m; i++) {
		vector<char>tmp_vector;
		for (int j(0); j < m; j++) {
			char tmp;
			cin >> tmp;
			tmp_vector.push_back(tmp);
		}
		b.push_back(tmp_vector);
	}
	if (search_large_area(a, b))cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256