akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include<iostream>
#include<vector>
#include<map>
#include<string>

#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>

#define MAX 100
#define WHITE 1
#define BLACK 2
using namespace std;
void makeQuad(int x,int y,int grid[][MAX+2]){
  //x,yの回りを黒くする
  int ii,jj;
  for(ii=0;ii<=2;ii++){
	grid[y-1][x-1+ii] = BLACK;
	grid[y+1][x-1+ii] = BLACK;
	grid[y-1+ii][x-1] = BLACK;
	grid[y-1+ii][x+1] = BLACK;	
  }
}
int main(){
  int a,b,ii,jj,wnum,bnum,x,y;
  cin >> a >> b;
  int grid[MAX+2][MAX+2];
  memset(grid,0,sizeof(grid));

  //全部白に
  for(ii=1;ii<=MAX;ii++){
	for(jj=1;jj<=MAX;jj++){
	  grid[ii][jj] = WHITE;
	}
  }
  
  wnum = 1;
  bnum = 0;
  //makeQuad(2,2,grid);
  //a-1個分の四角を作る
  x = 2;
  y = 2;
  
  while(wnum<a){
	if(x >= 100){
	  x = 2;
	  y += 3;
	}
	makeQuad(x,y,grid);
	x = x + 3;
	bnum = 1;
	wnum++;
  }

  x = 1;
  y = 51;
  while(bnum < b){
	if(x >= 100){
	  x = 1;
	  y += 2;
	}
	grid[y][x] = BLACK;
	x += 2;
	bnum++;
  }
  
  cout << MAX << " " << MAX << endl;
  for(ii=1;ii<=MAX;ii++){
	for(jj=1;jj<=MAX;jj++){
	  if(grid[ii][jj] == WHITE){
		cout << ".";
	  }
	  else{
		cout << "#";
	  }
	}
	cout << endl;
  }
  return 0;
}


Measured memory_bytes: 256
import numpy as np


n, m = map(int, input().split())
py = [list(map(int, input().split())) for _ in range(m)]
p = [[] for _ in range(n)]
for _p, _y in py:
    p[_p - 1].append(_y)
for i in range(n):
    p[i] = np.argsort(np.argsort(p[i]))

counter = [0 for _ in range(n)]
for _p, _y in py:
    t = "{:06}{:06}".format(_p, p[_p - 1][counter[_p - 1]] + 1)
    print(t)
    counter[_p - 1] += 1


Measured memory_bytes: 56676
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int i,n,h[105]={};
  int count=0,ans=0,flag=0;
  cin>>n;
  for(int i=0; i<n; i++){
    cin>>h[i];
    if(h[i]!=0){
      count++;
    }
  }
  while(count!=0){
    while(h[flag]==0){
      flag++;
    }
    i=flag;
    while(h[i]>0){
      h[i]--;
      if(h[i]==0){
	count--;
      }
      i++; 
    }
    ans++;
  }
  cout<<ans<<'\n';
  return 0;
}


Measured memory_bytes: 768
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <cmath>
#include <iomanip>
#include <tuple>
#include <map>
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;


int main() {
    int n,k; cin >> n >> k;
    ll ans = 0;
    for (ll i = k; i <= n + 1; i++) {
        ll tmp1 = (i - 1) * i / 2;
        ll tmp2 = (2 * n - i + 1) * i / 2;
        ans += tmp2 - tmp1 + 1;
        ans %= mod;
    }
    cout << ans << "\n";
}

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

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    if (a + b == c || a + c == b || b + c == a) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

int main(){
    //入力を受け取る
    int N;
    cin >> N;
    vector<int> a;
    for(int i = 0;i < N;i++){
        int b;
        cin >> b;
        a.push_back(b);
    }
    //小さい順に並び替え
    sort(a.begin(),a.end());
    reverse(a.begin(),a.end());
    int Alice = 0; //Alice's Points
    int Bob = 0; //Bob's Points
    for(int turn = 0;turn < N;turn++){
        if(turn%2 == 0){
            Alice += a.at(turn);
        }else{
            Bob += a.at(turn);
        }
    }
    cout<<Alice-Bob<<endl;
}



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

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 3;
constexpr int MOD = 1e9 + 7;

template <typename T>
void printv(const vector<T> &v)
{
    int sz = v.size();
    for (int i = 0; i < sz; i++)
    {
        cout << v[i] << " \n"[i == sz - 1];
    }
}

class BipartiteMatching
{
    int size;
    std::vector<std::vector<int>> g;
    std::vector<int> match;
    std::vector<bool> used;
    bool dfs(int v)
    {
        used[v] = true;
        for (const auto &u : g[v])
        {
            int w = match[u];
            if (w < 0 || (!used[w] && dfs(w)))
            {
                match[v] = u;
                match[u] = v;
                return true;
            }
        }
        return false;
    }

public:
    BipartiteMatching(int v) : size(v), g(v), match(v), used(v) {}
    void add_edge(int u, int v)
    {
        g[u].push_back(v);
        g[v].push_back(u);
    }
    int maximum_matching(void)
    {
        int res = 0;
        fill(begin(match), end(match), -1);
        for (int v = 0; v < size; ++v)
        {
            if (match[v] >= 0)
                continue;
            fill(begin(used), end(used), 0);
            if (dfs(v))
                ++res;
        }
        return res;
    }
};

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

    int n, m, l;
    while (cin >> n >> m >> l, n || m || l)
    {
        vector<vector<int>> dist(n, vector<int>(n, INF));
        for (int i = 0; i < n; i++)
            dist[i][i] = 0;
        for (int i = 0; i < m; i++)
        {
            int u, v, d;
            cin >> u >> v >> d;
            dist[u][v] = dist[v][u] = d;
        }
        for (int k = 0; k < n; k++)
        {
            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    dist[i][j] = min(dist[i][k] + dist[k][j], dist[i][j]);
                }
            }
        }
        // place, time;
        vector<int> p(l), t(l);
        for (int i = 0; i < l; i++)
        {
            cin >> p[i] >> t[i];
        }
        BipartiteMatching bm(2 * l);
        for (int i = 0; i < l; i++)
        {
            for (int j = 0; j < l; j++)
            {
                if(i==j) continue;
                // i を処理してから j を処理できるか
                if (dist[p[i]][p[j]] <= t[j] - t[i])
                {
                    bm.add_edge(i, j + l);
                }
            }
        }
        //for(int i=0;i<n;i++)for(int j=0;j<n;j++) cout << i << " "<<j << " "<<dist[i][j]<<endl;
        // cout << bm.maximum_matching() << endl;
        cout << l - bm.maximum_matching() << endl;
    }
}



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

int main() {
  int A, B;
  int d1, d2, d4, d5;
  int cnt = 0;
  
  cin >> A >> B;
  for(int i = A; i <= B; i++){
  	d1 = i % 10;
   	d2 = (i % 100) / 10;
    d4 = (i / 1000) % 10;
    d5 = i /10000;
    
    if(d1 == d5 and d2 == d4){
      cnt++;
    }
  }
  cout << cnt << endl;
}



Measured memory_bytes: 256
N, K = map(int, input().split())
xs = list(map(int, input().split()))
x1 =[0]
x2 = [0]
dist = []
for i in xs:
    if i < 0:
        x1.append(i)
    else:
        x2.append(i)
x1.sort(reverse = True)
l1 = len(x1)
l2 = len(x2)
m = K-l1+1
for i in range(max(0, m), min(K+1, l2)):
    d1 = 2*x2[i] -x1[K-i]
    d2 = x2[i] - 2*x1[K-i]
    dist.append(min(d1, d2))
print(min(dist))
    

Measured memory_bytes: 14664
#include <bits/stdc++.h> 
using namespace std;
 
int main(){
  int A, B; cin >> A >> B;
  if (A==B) cout << 2*A << endl;
  if (A>B) cout << 2*A-1 << endl;
  if (A<B) cout << 2*B-1 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>
#define ll long long

using namespace std;

long long MOD = 1000000007;

vector<int> primes(0);
void prime_number(int N){
    vector<int> tmp(N+1,1);
    tmp[0]=tmp[1]=0;
    for(int i=2; i<=N; i++){
        if(tmp[i]==1){
            primes.push_back(i);
        }
        for(long long j= (long long) i*i; j<=N; j+=i){
            tmp[j]=0;
        }
    }
}

vector<int> factorize(ll x){
    vector<int> ret(primes.size(),0);
    for(int i=0; i<primes.size(); i++){
        ll p=primes[i];
        while(x%p==0){
            x/=p;
            ret[i]++;
        }
    }
    if(x!=1){
        primes.push_back(x);
        ret.push_back(1);
    }
    return ret;
}

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

    prime_number(1000000);

    vector<int> fact=factorize(N);
    int cnt=0;
    for(int i=0;i<(int)fact.size(); i++){
        for(int j=1; j<=fact[i]; j++){
            cnt++;
            fact[i]-=j;
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 7840
import sys
input = sys.stdin.readline
import random
import time
import copy
from operator import itemgetter
time0=time.time()

D=int(input())
C=[0]+list(map(int,input().split()))
S=[0]+[[0]+list(map(int,input().split())) for i in range(D)]


CI=sorted([(v,i) for i,v in enumerate(C)],key=itemgetter(0),reverse=True)
CHO=[i for v,i in CI[:8]]

CHOICES=[[0]]
for i in range(1,D+1):
    SI=sorted([(v,i) for i,v in enumerate(S[i])],key=itemgetter(0),reverse=True)
    CHOICES.append([i for v,i in SI[:8]])
    
ANS=0
T=[0]
LAST=[0]*27
for day in range(1,D+1):
    SCORE=[-1<<30]*27
    for j in range(1,27):
        SC=0
        SC+=S[day][j]

        for k in range(1,27):
            if j==k:
                continue
            SC-=C[k]*(day-LAST[k])
        SCORE[j]=SC

    choose=SCORE.index(max(SCORE))
    T.append(choose)
    LAST[choose]=day

ANS=0
LAST=[[0]*27 for i in range(D+1)]
for day in range(1,D+1):
    for j in range(1,27):
        LAST[day][j]=LAST[day-1][j]
    t=T[day]
    ANS+=S[day][t]
    LAST[day][t]=day

    for j in range(1,27):
        ANS-=C[j]*(day-LAST[day][j])

MAX=ANS
MAXT=copy.deepcopy(T)
d=0
after_t=0

while time.time()-time0<1.82:
    BT=copy.deepcopy(T)
    BLAST=copy.deepcopy(LAST)
    BANS=ANS
    
    d=random.randint(1,D)
    after_t=random.choice(CHO+CHOICES[d])

    before_t=T[d]

    ANS+=S[d][after_t]-S[d][before_t]

    T[d]=after_t

    memolast=[]

    for day in range(d,D+1):
        if T[day]!=before_t:
            ANS+=C[before_t]*(day-LAST[day][before_t])
            memolast.append((day,before_t,LAST[day][before_t]))
            LAST[day][before_t]=LAST[day-1][before_t]
            ANS-=C[before_t]*(day-LAST[day][before_t])
        else:
            break

    ANS+=C[after_t]*(d-LAST[d][after_t])
    memolast.append((d,after_t,LAST[d][after_t]))
    LAST[d][after_t]=d

    for day in range(d+1,D+1):    
        if T[day]!=after_t:
            ANS+=C[after_t]*(day-LAST[day][after_t])
            memolast.append((day,after_t,LAST[day][after_t]))
            LAST[day][after_t]=LAST[day-1][after_t]
            ANS-=C[after_t]*(day-LAST[day][after_t])

    if ANS*10000<MAX*9995:
        T=BT
        ANS=BANS
        for dd,tt,ll in memolast:
            LAST[dd][tt]=ll
    elif ANS>MAX:
        MAX=ANS
        MAXT=copy.deepcopy(T)

print(*MAXT[1:])

Measured memory_bytes: 179260
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(LL &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const LL &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
int a[40]={0, 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
int main(){
    int K;
    R(K);
    W(a[K]);
    return 0;
}


Measured memory_bytes: 256
from heapq import heappush, heappop

n, m = map(int, input().split())
a = list(map(int, input().split()))
card = [list(map(int, input().split())) for _ in range(m)]
card = sorted(card, key=lambda x:-x[1])

hq = []
for i in range(n):
    heappush(hq, a[i])

ans = sum(a)
for i in range(m):
    for j in range(card[i][0]):
        if hq == []:
            break
        num = heappop(hq)
        if num >= card[i][1]:
            heappush(hq, num)
            break
        else:
            ans += card[i][1]-num
print(ans)


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

int main() {
  int payment, oneYens;
  cin >> payment >> oneYens;
  
  payment = payment % 500;
  if( payment <= oneYens) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<cstring>
using namespace std;
int main(){
    string S;
    cin >> S;
    int count = 0;
    int res = 0;
    for(int i = 0; i < S.size(); ++i){
        if(S[i] == 'A' || S[i] == 'T' || S[i] == 'C' || S[i] == 'G'){
            count++;
            res = max(count, res);
        }
        else count = 0;
    }
    cout << res << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using LL = long long;
constexpr int maxn = 100000;
int a[maxn + 1], h[maxn + 1], N, K, ans;
vector<int> G[maxn + 1];
void DFS(int u){
    h[u] = 0;
    for(int v : G[u]){
        DFS(v);
        if(u != 1 and h[v] >= K) ans += 1;
        else h[u] = max(h[u], h[v]); 
    }
    h[u] += 1;
}
int main(){
    ios::sync_with_stdio(false);
    cin >> N >> K;
    for(int i = 1; i <= N; i += 1){
        cin >> a[i];
        if(i != 1) G[a[i]].push_back(i);
    }
    ans += a[1] != 1;
    a[1] = 1;
    DFS(1);
    cout << ans;
}

Measured memory_bytes: 11264
#include <stdio.h>
#define max(x,y) ((x)>(y)?(x):(y))
#define min(x,y) ((x)<(y)?(x):(y))
#define FOR(i,m,n) for(i=m;i<n;i++)

int main(void)
{
	int a[10],b=10,c=0,i;
	for(i=0;i<5;i++){
		scanf("%d",&a[i]);
		if(a[i]%10!=0){
			b=min(b,a[i]%10);
			a[i]=a[i]/10*10+10;
		}
		c=c+a[i];
	}
	printf("%d",c-10+b);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>

using namespace std;

int main(){
    int D, G;
    cin >> D >> G;
    vector<int> p(D), c(D), all(D);
    for(int i = 0; i < D; i++){
        cin >> p[i] >> c[i];
        all[i] = 100*(i+1)*p[i]+c[i];
    }

    long long ans = 1e9;
    for(int bit = 0; bit < (1 << D); bit++){
        long long s = 0, cnt = 0;
        for(int i = 0; i < D; i++){
            if(bit & (1 << i)){ // 100*i点のPi問を全て解く
                s += all[i];
                cnt += p[i];
            }
        }

        if(s >= G){
            ans = min(ans, cnt);
            continue;
        }else{
            int j;
            for(int i = D-1; i >= 0; i--){
                if(!(bit & (1 << i))){ // j := 解いてない問題の中で最も高い点を得られる i
                    j = i;
                    break;
                }
            }

            if(s+100*(j+1)*(p[j]-1)<G){
                continue;
            }else{
                cnt += (G-s)/(100*(j+1))+((G-s)%(100*(j+1)) != 0);
            }

            ans = min(ans, cnt);
        }
    }

    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int               long long
#define ff                first
#define ss                second
#define md                1000000007
#define md1               998244353
#define inf               1000000000000000
#define minf              -1000000000000000
#define pb                push_back
#define ppb               pop_back
#define in                insert
#define mkp               make_pair
#define mpll              map<ll,ll>
#define len(p)            (ll)p.size()
#define pll               pair<ll,ll>
#define all(v)            v.begin(),v.end()
#define mem(a,t)          memset(a,t,sizeof(a))
#define endl              "\n"
#define ar                array
#define vl                vector<ll>
#define vvl               vector<vl>
#define lb                lower_bound
#define ub                upper_bound
#define be()              begin()
#define en()              end()
#define vpll              vector<pair<ll,ll>>
#define f(i,yha,wha)      for(ll i=yha;i<wha;i++)
#define rf(i,wha,yha)     for(ll i=wha;i>=yha;i--)
#define f0(n)             for(ll i=0;i<n;i++)
#define f1(n)             for(ll i=1;i<=n;i++)
#define fg(i,yha,wha,gap) for(ll i=yha;i<wha;i+=gap)

void flash()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}


void solve()
{
    ll n;
    cin >> n;
    map<ll, ll>mp;
    for (int j = 2; j * j <= n; j++)
    {
        if (n % j == 0)
        {
            while (n % j == 0)
            {
                mp[j]++;
                n /= j;
            }
        }
    }
    if (n > 1)
        mp[n]++;
    ll ans = 0;
    for (auto it : mp)
    {
        ll st = 1, en = it.ss;
        ll x = 0;
        while (st <= en)
        {
            ll mid = (st + en) / 2;
            if ((mid * (mid + 1)) / 2 <= it.ss)
            {
                x = mid;
                st = mid + 1;
            }
            else
                en = mid - 1;
        }
        ans += x;
    }
    cout << ans << endl;
}

int32_t main()
{
    flash();
    int t;
    t = 1;
    // cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s,s1;
	cin>>s>>s1;
	long long ans=0;
	for(int i=0;i<=s.size();i++)
	{
		if(s[i]!=s1[i]) ans++;
	}
	cout<<ans;
}

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

ll solve(ll ai, ll aj, ll bi, ll bj) {
    if (aj>bj) {
        swap(ai, bi);
        swap(aj, bj);
    }
    ll s = 1;
    rep(i, 30) s *= 3;
    ll dist = abs(ai-bi) + abs(aj-bj);
    ll res = dist;
    while(1) {
        s /= 3;
        if (s==0) {
            break;
        }
        ll nai = ai/s;
        ll nbi = bi/s;
        if (nai!=nbi) {
            break;
        }
        ll naj = aj/s;
        ll nbj = bj/s;
        if (abs(naj-nbj)>1 && nai%3==1) {
            ll loss = 2 * (min(ai, bi) - s*nai + 1);
            loss = min(loss, 2*((1+nai)*s-max(ai, bi)));
            res = dist + loss;
            break;
        }
    }
    return res;
}

int main(){
    int q;
    cin >> q;
    rep(qi, q) {
        ll ai, aj, bi, bj;
        cin >> ai >> aj >> bi >> bj;
        ai--; aj--; bi--; bj--;
        ll ans = solve(ai, aj, bi, bj);
        ans = max(ans, solve(aj, ai, bj, bi));
        cout << ans << endl;
    }
    
    return 0;
}


Measured memory_bytes: 384
import java.util.*;

public class Main {

    public static void main(String[] args) {
        // write your code here
        // AGC 008 Simple Calculator
        Scanner sc = new Scanner(System.in);
        long x = sc.nextInt();
        long y = sc.nextInt();
        long ans = Math.abs(Math.abs(x) - Math.abs(y));
        if (x * y < 0) {
            ans++;
        } else if (x > y) {
            if (x == 0 || y == 0) {
                ans++;
            } else {
                ans += 2;
            }
        }
        System.out.println(ans);
    }
}

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

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

ll fst(ll N, vector<ll>& a, vector<ll>& b) {
	ll ret = N;
	for (ll i = 0; i <= N / a[0]; ++i) {
		for (ll j = 0; j <= N / a[1]; ++j) {
			ll k = N - i * a[0] - j * a[1];
			if (k < 0) { break; }
			ret = max(ret, i*b[0] + j*b[1] + (k/a[2])*b[2] + k % a[2]);
		}
	}
	return ret;
}

ll snd(ll N, vector<ll>& a, vector<ll>& b) {
	ll ret = N;
	for (ll x = 0; x <= N / a[0]; ++x) {
		ll y = N - x * a[0];
		if (y < 0) { break; }
		ret = max(ret, x*b[0] + (y/a[1])*b[1] + y % a[1]);
	}
	return ret;
}

int main() {
	ll N;
	cin >> N;
	vector<ll> A(3), B(3);
	for (int i = 0; i < 3; ++i) { cin >> A[i]; }
	for (int i = 0; i < 3; ++i) { cin >> B[i]; }
	
	vector<P> v(3);
	for (int i = 0; i < 3; ++i) { v[i] = P(B[i] - A[i], i); }
	sort(v.rbegin(), v.rend());
	vector<ll> a(3), b(3);
	for (int i = 0; i < 3; ++i) {
		a[i] = A[v[i].second];
		b[i] = B[v[i].second];
	}

	ll res = fst(N, a, b);
	reverse(a.begin(), a.end());
	reverse(b.begin(), b.end());
	if (res == N) { res = fst(N, b, a); }
	else { res = snd(res, b, a); }
	cout << res << endl;

	return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main {
	public static void main(String[] args) throws IOException{
		Scanner sc=new Scanner(System.in);
		Reader reader=new Reader();
		int t=1;//sc.nextInt();
		while(t-->0) {
			int n=sc.nextInt();
			int m=sc.nextInt();
			ArrayList<ArrayList<Integer>> gp=new ArrayList<>();
			ArrayList<HashSet<Integer>> gpset=new ArrayList<>();
			for(int i=0;i<n;i++) {
				gp.add(new ArrayList<>());
				gpset.add(new HashSet<>());
			}
			for(int i=0;i<m;i++) {
				int u=sc.nextInt();
				int v=sc.nextInt();
				u--;v--;
				if(!gpset.get(u).contains(v)) {
					gpset.get(u).add(v);
					gp.get(u).add(v);
					gpset.get(v).add(u);
					gp.get(v).add(u);
				}
			}
			System.out.println(dfs(gp));
		}
	}
	static int dfs(ArrayList<ArrayList<Integer>> gp) {
		int max=0;
		boolean[] visited = new boolean[gp.size()];
		for(int i=0;i<gp.size();i++) {
			if(!visited[i]) {
				int cur=dfs_util(i,visited,gp);
				max=Math.max(cur, max);
			}
		}
		return max;
	}
	static int dfs_util(int index,boolean[] visited,ArrayList<ArrayList<Integer>> gp) {
		visited[index]=true;
		int count=1;
		for(int i: gp.get(index)) {
			if(!visited[i]) {
				count+=dfs_util(i,visited,gp);
			}
		}
		return count;
		
	}
}
class Reader{
	BufferedReader reader;
	Reader(){
		reader=new BufferedReader(new InputStreamReader(System.in));
	}
	int nextInt() throws IOException{
		String in=reader.readLine().trim();
		return Integer.parseInt(in);
	}
	long nextLong() throws IOException{
		String in=reader.readLine().trim();
		return Long.parseLong(in);
	}
	String next() throws IOException{
		return reader.readLine().trim();
	}
	String[] stringArray() throws IOException{
		return reader.readLine().trim().split("\\s+");
	}
	int[] intArray() throws IOException{
		String[] inp=this.stringArray();
		int[] arr=new int[inp.length];
		int i=0;
		for(String s:inp) {
			arr[i++]=Integer.parseInt(s);
		}
		return arr;
	}
}


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

using namespace std;

int main()
{
    int n;
    int a[100010];
    int ans = 0;

    cin >> n;

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

    sort(a, a + n);

    for (int i = 0; i < n; i++) {
        if (i == n-1) {
            ans += (a[i] / 2);
        }
        else {
            ans += a[i];
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define F first
#define S second
const int A = 2e5 + 2;
const int mod = 1e9 + 7;
ll n, x, m;
ll freq[A];
ll solve() {
    deque<ll> dq;
    ll cur = x, start = -1;
    dq.push_back(cur);
    for (int i = 1; i < min((ll)A, n); i++) {
        cur = (cur * cur) % m;
        freq[cur]++;
        if (freq[cur] == 2) {
            start = cur; break;
        }
        dq.push_back(cur);
    }
    ll ans = 0;
    while(!dq.empty()) {
        int cur = dq.front();
        if (cur == start) break;
        dq.pop_front();
        ans += cur, n--;
    }
    if (start == -1)
        return ans;
    ll sz = dq.size(), cnt = n / sz, rem = n % sz;
    for (int i = 0; i < dq.size(); i++) {
        ans += dq[i] * cnt;
        if (i < rem)
            ans += dq[i];
    }
    return ans;
}
int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> n >> x >> m;
    cout << solve();
    return 0;
}

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

int main(){
  int k;
  cin >> k;
  int keta = 1, num = 7;
  for(int i=1; i<=k; ++i){
    if(num %k == 0){
      cout << i << endl;
      return 0;
    }
    keta *= 10;
    keta %= k;
    num += keta * 7;
    num %= k;
  }
  cout << -1 << endl;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
int main() {
  int N;
  cin >> N;
  int ans=0;
  for (int i = 1; i <= N; i++) {
    if(i%2==0){
      continue;
    }
    int cnt = 0;
    for (int j = 1; j <= N; j++) {
      if (i % j == 0) cnt++;
    }
    if(cnt==8){
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
#define int long long
int h[100005];
int dp[100005];
 long mincost(int i,int j)
 {
     if(i==j){
         return 0;
     }
     if(i>j){
         return INT_MAX;
     }
     if(dp[i] != -1){
         return dp[i];
     }
     int ans ;
     int op1 = abs(h[i+1] - h[i]) + mincost(i+1,j);
     int op2 = abs(h[i+2] - h[i]) + mincost(i+2,j);
     ans = min(op1,op2);

     return dp[i] = ans;

 }
 int32_t main(){
     int n;cin>>n;
     memset(h,0,sizeof(h));
     for(int i=1;i<=n;i++){
         cin>>h[i];
     }
     memset(dp,-1,sizeof(dp));
     cout<<mincost(1,n);
 }

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

using namespace std;
typedef long long ll;
int main(){
	ll N; cin>>N;
  vector<ll> a(N+1,0);
  vector<ll> s(N+1,0);
  for(int i=1;i<=N;i++){
    cin>>a[i];
    s[i]=s[i-1]+a[i];
  }
  sort(s.begin(),s.end());
  ll mem=s[0],cnt=1;
  ll ans=0;
  for(int i=1;i<=N;i++){
  	if(s[i]==mem) cnt++;
    else{
      	if(cnt>=2) ans+=cnt*(cnt-1)/2;
    	cnt=1;
      	mem=s[i];
    }
  }
  if(cnt>=2) ans+=cnt*(cnt-1)/2;
	printf("%lld",ans);
}

Measured memory_bytes: 3328
#include <iostream>
#include <vector>
#include <string>
#include <complex>
#include <cmath>
#include <algorithm>

using namespace std;

int n, T, ans = 1e9;

int main()
{
    cin >> n >> T;
    for (int i = 0; i < n; i++)
    {
        int a, b;
        cin >> a >> b;
        if (b <= T)
        {
            ans = min(ans, a);
        }
    }
    
    if (ans == 1e9)
    {
        cout << "TLE";
        return 0;
    }
    cout << ans;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
#define FOR(i,a,b) for(int (i)=(a); (i)<=(b); (i)++)
#define REP(i,N) FOR((i), 0, (N)-1)
int gcd(int a, int b){if(a>b) swap(a,b); return a==0 ? b : gcd(b%a,a);}

int main(){
    int N,M,K,A;
    int m[31][31];
    REP(i,31) REP(j,31) m[i][j]=0;
    cin >> N >> M;
    FOR(i,1,N){
        cin >> K;
        REP(j,K){
            cin >> A;
            m[i][A] = 1;
        }
    }
    int ans = 0;
    FOR(j,1,M){
        int flag = 1;
        FOR(i,1,N){
            if(m[i][j] == 0) flag=0;
        }
        ans += flag;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define rrep(i, n) for (int i = (int)n-1; i >= 0; --i)
using namespace std;
using ll = long long;
template<typename T>
inline bool chmax(T& a, const T& b) {
    if (a < b){
        a = b;
        return true;
    }
    return false;
}
template<typename T>
inline bool chmin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T> vector<T> make_vec(size_t n) { return vector<T>(n); }
template<typename T, typename... Args> auto make_vec(size_t n, Args... args) {
    return vector<decltype(make_vec<T>(args...))>(n, make_vec<T>(args...));
}
template<typename T, typename U, typename... V>
typename enable_if<is_same<T, U>::value>::type fill_v(U& u, const V... v) { u = U(v...); }
template<typename T, typename U, typename... V>
typename enable_if<!is_same<T, U>::value>::type fill_v(U& u, const V... v) {
    for (auto& e : u) fill_v<T>(e, v...);
}

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

    int n, k;
    cin >> n >> k;
    vector<int> p(n), c(n);
    rep(i, n) cin >> p[i], p[i]--;
    rep(i, n) cin >> c[i];

    const ll inf = 5e18;
    ll ans = -inf;
    vector<int> now(n);
    auto point = make_vec<ll>(n+1, n);
    vector<int> isshu(n);

    rep(i, n) now[i] = i;

    bool stop = false;
    for (int i = 1; i <= k; ++i) {
        bool ok = true;
        rep(j, n) {
            now[j] = p[now[j]];
            if (!isshu[j] && now[j] == j) isshu[j] = i;
            if (!isshu[j]) ok = false;
            point[i][j] = point[i-1][j] + c[now[j]];
            chmax(ans, point[i][j]);
        }
        if (ok && i != k) {
            stop = true;
            break;
        }
    }
    // rep(i, n+1) rep(j, n) cout << point[i][j] << (j == n-1 ? '\n' : ' ');
    // rep(i, n) cout << isshu[i] << '\n';
    if (!stop) cout << ans << '\n';
    else {
        rep(i, n) {
            if (!isshu[i]) continue;
            if (point[isshu[i]][i] <= 0) continue;
            if (k % isshu[i] != 0) {
                for (int j = 0; j <= k % isshu[i]; ++j) {
                    chmax(ans, point[isshu[i]][i] * (k / isshu[i]) + point[j][i]);
                }
            } else {
                for (int j = 0; j <= isshu[i]; ++j) {
                    chmax(ans, point[isshu[i]][i] * (k / isshu[i] - 1) + point[j][i]);
                }
            }
        }
        cout << ans << '\n';
    }
}


Measured memory_bytes: 198836
#include<bits/stdc++.h>
 using namespace std;
 
 int main() 
 {
 	string s;
 	cin>>s;
 	
 	for(int i=0;i<s.size()-1;i++)
 	{
 		if(s[i]==s[i+1])
 		{
 			cout<<i+1<<" "<<i+2<<endl;
 			return 0;
		 }
		 if(i+2<s.size())
		 {
		 	if(s[i]==s[i+2])
		 	{
		 		cout<<i+1<<" "<<i+3<<endl;
		 		return 0;
			 }
		 }
	}
	cout<<-1<<" "<<-1<<endl;
 }

Measured memory_bytes: 3692
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<memory>
#include<functional>

#define rep(i, n) REP(i, 0, n)
#define REP(i, a, n) for(int i = a ; i < (int)n ; i++)
#define ALL(v) v.begin(), v.end()
#define pb push_back
#define mp make_pair
#define eps 1e-14
#define INF 1e9
#define m0(x) memset(x, 0, sizeof(x))

using namespace std;

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

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

signed main(){
  int a, b, c, x, y;
  
  cin >> a >> b >> c >> x >> y;
  
  // 普通に買えばいい場合
  if(a * x + b * y <= c * (x + y)){
    cout << a * x + b * y << endl;
  }else{
    int _min = 1e9;
    
    // 2倍分買えばよさそう
    int max_num = 2 * max(x, y);
    int highest_price, highest_num;
    if(x < y){
      highest_price = b;
      highest_num = y;
    }else{
      highest_price = a;
      highest_num = x;
    }    
    
    while(0 <= max_num && max_num / 2 >= min(x, y)){
      _min = min(_min, highest_price * (highest_num - max_num / 2) + max_num * c);
      max_num-=2;
    }
    cout << _min << endl;
  }
}


Measured memory_bytes: 256
from queue import PriorityQueue

def sssp(adj_list):
    n = len(adj_list)
    d = [None]*n
    pq = PriorityQueue()
    pq.put((0, 0)) # d, v

    while(not pq.empty()):
        d_v, v = pq.get()
        if d[v] is not None:
            continue
        d[v] = d_v
        for u, c_vu in adj_list[v]:
            pq.put((d[v]+c_vu, u))

    return d


if __name__ == '__main__':
    n = int(input())
    adj_list = []
    for _ in range(n):
        adj_list.append([])

    for _ in range(n):
        l = list(map(int, input().rstrip().split(' ')))
        u = l[0]
        k = l[1]
        adj_list_for_u = []
        for v, c in zip(l[2::2], l[3::2]):
            adj_list_for_u.append((v,c))
        adj_list[u] = adj_list_for_u

    d = sssp(adj_list)
    for u, d_u in zip(range(n), d):
        print (u, d_u)

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

int main() {
  int N; cin >> N;
  vector<int> A(N);
  vector<int> B(N);
  vector<int> C(N - 1);
  int sati = 0;
  
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
    A.at(i)--;
  }
  for (int i = 0; i < N; i++) {
    cin >> B.at(i);
  }
  for (int i = 0; i < N - 1; i++) {
    cin >> C.at(i);
  }
  for (int i = 0; i < N; i++) {
    sati += B.at(A.at(i));
    if (i < N - 1 && A.at(i) + 1 == A.at(i + 1)) {
      sati += C.at(A.at(i));
    }
  }
  cout << sati << endl;
}

Measured memory_bytes: 256
using System;

class alds12a
{
    static void swap(ref int a, ref int b)
    {
        int tmp = a;
        a = b;
        b = tmp;
    }
    static void Main()
    {
        int  tn=int.Parse(Console.ReadLine());
        string[] input = Console.ReadLine().Split(' ');
        int[] num = new int[tn];
        int count = 0;
        for (int i = 0; tn > i; i++)
        {
            num[i] = int.Parse(input[i]);
        }
        for (int i = 0; tn > i; i++)
        {
            int min = i;
            for (int j = i; j < tn; j++)
            {
                if (num[j] < num[min]) min = j;
            }
            if (i != min)
            {
                swap(ref num[i], ref num[min]);
                count++;
            }
        }
        for (int i = 0; tn - 1 > i; i++)
        {
            Console.Write(num[i]);
            Console.Write(' ');
        }
        Console.WriteLine(num[tn-1]);
        Console.WriteLine(count);
    
    
    }

}

Measured memory_bytes: 5620
if __name__ == '__main__':
    n = int(input())
    al = [int(a) for a in input().split()]
    bl = [int(b) for b in input().split()]

    score = 0
    remaining = 0
    for i in range(n):
        a = al[i]
        b = bl[i]
        if a >= b:
            score += b
        else:
            score += a
            b -= a
            a2 = al[i + 1]
            if a2 > b:
                score += b
                a2 -= b
                al[i + 1] = a2
            else:
                score += a2
                al[i + 1] = 0
    print(score)




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

cnt = [0 for i in range(n-1)]
for i in range(1, n):
    for j in range(i+1, n+1):
        k = min(j - i, abs(x-i) + abs(y-j) + 1)
        cnt[k-1] += 1

for c in cnt:
    print(c) 

Measured memory_bytes: 3444
A, B, C, X, Y = [int(_) for _ in input().split()]
C*=2

if X > Y:
    X, Y = Y, X
    A, B = B, A
ans = 0
if X * (A + B) > X * C:
    ans += X * C
    Y -= X
else:
    ans += X * A

ans += min(B * Y, Y * C)
print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rep_ll(i,n) for(ll i = 0; i < (ll)(n); i++)

using namespace std;
 
typedef long long ll;
typedef unsigned long long u_ll;
typedef pair<int, int> pair_;

const long double PI = (acos(-1));
 
const int INF = 1001001001;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
 
int gcd(int a, int b){
    if(b == 0) return a;
 
    return gcd(b, a%b);
}
 
int main(){
    int k;
   string n;
   cin >> k >> n;

   int size_ = n.size();

   if(size_<=k) cout << n;
   else {
       rep(i,k) cout << n.at(i);
       cout << "...";
   }
   
   return 0;
}

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

int main(void) {
    int a, b, c, d;

    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> a >> b >> c >> d;
    cout << max(a * b, c * d) << "\n";
    return 0;
}

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

using namespace std;

int write(int x,int y)
{
	for(int k=0;k<x;k++)
	{
		for(int l=0;l<y;l++)
		{
			cout<<"#";
		}
		cout<<endl;
	}
	return(0);
}
int main()
{
	int a,b;
	unsigned int i=0;
	unsigned int j;
	vector<int> n;
	vector<int> m;
	
	while(1)
	{
		cin>>a>>b;
		
		if(a==0&&b==0)
			break;
		else
		{
		n.push_back(a);
		m.push_back(b);
		i++;
		}
	}
	
	for(j=0;j<i;j++)
	{
		write(n[j],m[j]);
		cout<<endl;
	}
	
}



Measured memory_bytes: 3156
#![allow(unused_imports, dead_code)]
use std::f64::*;
use std::cmp::*;
use std::collections::*;

macro_rules! dump{
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

const INF: i64 = 0x3f3f3f3f3f3f3f3f;
const MOD: i64 = 1000000007;
const NOTHING: usize = std::usize::MAX;
const DX: [usize; 4] = [1, 0, std::usize::MAX, 0];
const DY: [usize; 4] = [0, 1, 0, std::usize::MAX];

fn main() {
    let s: Vec<char> = readln();
    let mut freq: Vec<usize> = vec![0;128];
    for i in 0..s.len() {
        freq[s[i] as usize] += 1;
    }

    let mut res = 1;
    for i in 0..128 {
        for j in i + 1..128 {
            res += freq[i] as i64 * freq[j] as i64;
        }
    }

    println!("{}", res);
}



trait Read {
    fn read(s: &str) -> Self;
}

fn readln<T: Read>() -> T {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    T::read(buf.trim_right())
}

macro_rules! read_impl{
    ($($t:ty)*) => ($(
        impl Read for $t {
            fn read(s: &str) -> $t{
                s.parse().unwrap()
            }
        }
    )*)
}
read_impl! { usize u8 u16 u32 u64 isize i8 i16 i32 i64 f32 f64 }

impl Read for String {
    fn read(s: &str) -> Self {
        s.to_string()
    }
}

impl Read for Vec<char> {
    fn read(s: &str) -> Self {
        s.chars().collect()
    }
}

impl<T: Read> Read for Vec<T> {
    fn read(s: &str) -> Self {
        s.split_whitespace().map(T::read).collect()
    }
}

impl<A: Read, B: Read> Read for (A, B) {
    fn read(s: &str) -> Self {
        let tokens: Vec<_> = s.split_whitespace().collect();
        (A::read(tokens[0]), B::read(tokens[1]))
    }
}

impl<A: Read, B: Read, C: Read> Read for (A, B, C) {
    fn read(s: &str) -> Self {
        let tokens: Vec<_> = s.split_whitespace().collect();
        (A::read(tokens[0]), B::read(tokens[1]), C::read(tokens[2]))
    }
}

impl<A: Read, B: Read, C: Read, D: Read> Read for (A, B, C, D) {
    fn read(s: &str) -> Self {
        let tokens: Vec<_> = s.split_whitespace().collect();
        (A::read(tokens[0]), B::read(tokens[1]), C::read(tokens[2]), D::read(tokens[3]))
    }
}


Measured memory_bytes: 4352
#include <stdio.h>
#include <stdint.h>
#include <iostream>
#include <fstream>
#include <cassert>
using namespace std;

#define DEBUG (0)

#if DEBUG
#define DPRINTF(...)  printf("D(L%d) %s: ", __LINE__, __func__); printf(__VA_ARGS__)
#else
#define DPRINTF(...)
#endif // DEBUG

int main()
{
  int numOfLoad, numOfTrack;
  cin >> numOfLoad >> numOfTrack;
  DPRINTF("numOfLoad %d\n", numOfLoad);
  DPRINTF("numOfTrack %d\n", numOfTrack);

  int sum_of_weight = 0;
  int max_weight_of_load = -1;
  int weight_array[numOfLoad];
  for (int i = 0; i < numOfLoad; i++)
  {
    int weight;
    cin >> weight_array[i];
    sum_of_weight += weight_array[i];
    if (max_weight_of_load < weight_array[i])
      max_weight_of_load = weight_array[i];
  }
  const int average = sum_of_weight / numOfTrack;
  const int init_capacity = max(max_weight_of_load, average);
  DPRINTF("SUM OF WEIGHT %d\n", sum_of_weight);
  DPRINTF("AVERAGE OF WEIGHT %d\n", average);

  bool foundSolution = false;
  int capacityOfTrack = init_capacity;

  const int MAX_NUM_OF_LOAD = 100 * 1000;
  const int MAX_WEIGHT_OF_LOAD = 10 * 1000;
  const int MAX_TRACK_CAPACITY = MAX_NUM_OF_LOAD * MAX_WEIGHT_OF_LOAD;

  while (!foundSolution && capacityOfTrack < MAX_TRACK_CAPACITY)
  {

    int currentCapacity = 0;
    int leftOfTrackNum = numOfTrack - 1;

    DPRINTF("CAPACITY_OF_TRACK %d\n", capacityOfTrack);

    for (int i = 0; i < numOfLoad; i++)
    {

      DPRINTF("LOAD %d  WEIGHT %d\n",  i, weight_array[i]);

      if (currentCapacity + weight_array[i] <= capacityOfTrack)
      {
        currentCapacity += weight_array[i];
      }
      else
      {
        if (leftOfTrackNum > 0) // Start to load to the next track
        {
          leftOfTrackNum--;
          currentCapacity = weight_array[i];
        }
        else // The track capacity is not enough; Increase the capacity and try again
        {
          break;
        }
      }

      if (i == numOfLoad - 1)
        foundSolution = true;

      DPRINTF("CURRENT_CAPACITY %d  LEFT_OF_TRACK_NUM %d\n",
          currentCapacity, leftOfTrackNum);
    }

    if (!foundSolution)
      capacityOfTrack++;
  }

  cout << capacityOfTrack << endl;
  return 0;
}



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

#define mp make_pair
#define pb push_back
#define f first
#define s second

using namespace std;

typedef long long ll;
const int INF = 1e9;
const ll INFl = 1e18;

typedef pair<int,int> pii;
typedef vector<int> vi;
typedef set<int> si;
typedef map<int,int> mii;
typedef unordered_map<int,int> umii;
typedef queue<int> qi;



int main() {
	ios::sync_with_stdio(false); cin.tie(0);
	
	ll n, k; cin >> n >> k;
	cout << min(n%k, abs((n%k)-k)) << '\n';
		
	return 0;
}


Measured memory_bytes: 256
// #include <bits/stdc++.h>
#include <cctype>
#include <cstdio>
#include <algorithm>
#include <emmintrin.h>

using std::scanf;
using std::printf;
using std::max;
using std::isdigit;

typedef long long ll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)

#define __my_getchar getchar
inline void read(unsigned int &x){
  x=0;char c;
  while(!isdigit(c=__my_getchar()));
  x=c-'0';
  while(isdigit(c=__my_getchar()))x=10*x+(c-'0');
}

unsigned int n,m;
const int MAX_N = 5000;
const int MAX_M = 200;
unsigned int a[MAX_N] __attribute__((aligned(16)));
unsigned int b[MAX_N * MAX_M] __attribute__((aligned(16)));
unsigned int mx[MAX_M] __attribute__((aligned(16)));

static inline __m128i __attribute__((always_inline))
po_mm_max_epi32(__m128i a, __m128i b){
  __asm__("pmaxsd %1, %0" : "+x" (a) : "xm" (b));
  return a;
}
unsigned long long tmp[2] __attribute__((aligned(16)));

// // max of two array
// // a[i] = max(a[i], b[i])
// void vec_chmax(int n, unsigned int *a, unsigned int *b){
//   for(int i=0;i<n;i+=4){
//     __m128i xx = _mm_load_si128((__m128i*)(a+i));
//     __m128i yy = _mm_load_si128((__m128i*)(b+i));
//     xx = po_mm_max_epi32(xx,yy);
//     _mm_store_si128((__m128i*)(a+i), xx);
//   }
// }

// // sum of array
// // Σa[i]
// ll vec_sumll(int n, unsigned int *a){
//   __m128i x = _mm_setzero_si128();
//   __m128i y = _mm_setzero_si128();
//   const __m128i zero = _mm_setzero_si128();
 
//   for(int i=0;i<n;i+=4){
//     __m128i xx = _mm_load_si128((__m128i*)(a+i));
//     __m128i yy = _mm_unpackhi_epi32(xx,zero);
//             xx = _mm_unpacklo_epi32(xx,zero);
//     x = _mm_add_epi64(x,xx);
//     y = _mm_add_epi64(y,yy);
//   }
//   x = _mm_add_epi64(x,y);
//   _mm_store_si128((__m128i*)tmp, x);
//   return tmp[0] + tmp[1];
// }

inline ll func(int z,ll sub){
  // vec_chmax(m,mx,b+MAX_M*z);
  // return vec_sumll(m,mx)-sub;
  __m128i x = _mm_setzero_si128(), y = _mm_setzero_si128();
  const __m128i zero = _mm_setzero_si128();
  for(int i=0;i<m;i+=4){
    __m128i xx = _mm_load_si128((__m128i*)(mx+i));
    __m128i yy = _mm_load_si128((__m128i*)(b+MAX_M*z+i));
    xx = po_mm_max_epi32(xx,yy);
    _mm_store_si128((__m128i*)(mx+i), xx);
    yy = _mm_unpackhi_epi32(xx,zero);
    xx = _mm_unpacklo_epi32(xx,zero);
    x = _mm_add_epi64(x,xx);
    y = _mm_add_epi64(y,yy);
  }
  x = _mm_add_epi64(x,y);
  _mm_store_si128((__m128i*)tmp, x);
  return tmp[0]+tmp[1]-sub;
}

int main(){
  read(n);read(m);
  REP(i,n-1)read(a[i]);
  REP(i,n)REP(j,m)read(b[MAX_M*i+j]);

  ll ans = 0;
  REP(l,n){
    ll lensum = 0;
    REP(j,m)mx[j]=0;
    ans = max(ans, func(l,lensum));

    FOR(r,l+1,n){
      lensum += a[r-1];
      ans = max(ans, func(r,lensum));
    }
  }
  printf("%lld\n",ans);
  return 0;
}


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

namespace question2
{
    class Program
    {
        static void Main(string[] args)
        {
            var p = new Program();
            p.Run();
        }

        void Run(){
            var n = int.Parse(Console.ReadLine());
            var vlist = Console.ReadLine().Split(' ').Select(v=>int.Parse(v)).ToArray();
            var clist = Console.ReadLine().Split(' ').Select(c=>int.Parse(c)).ToArray();

            var total = 0;
            for(int i=0;i<n;i++){
                if( vlist[i]-clist[i] > 0 ){
                    total += vlist[i]-clist[i];
                }
            }

            Console.WriteLine(total);
        }
    }
}


Measured memory_bytes: 13268
#include<bits/stdc++.h>
using namespace std;
#define PI acos(-1)
#define INF 0x3f3f3f
#define ll long long
#define pb push_back
#define mp make_pair
#define pair pair<int,int>
#define C(a) cout<<a<<endl;
#define CY cout<<"YES"<<endl;
#define CN cout<<"NO"<<endl;
#define Cy cout<<"Yes"<<endl;
#define Cn cout<<"No"<<endl;
#define ull unsigned long long
#define me(a) memset(a,0,sizeof(a));
#define my(a,b) memcpy(a,b,sizeof(b));
#define cio ios::sync_with_stdio(false)
ll mod=1e9+7;
ll gcd(ll a,ll b){return (a%b==0) ? b : gcd(b,a%b);}
ll s[501000];
int rt[501000];
int lc[20000100],rc[20000100],tol;
ll sum[20000100];
map<ll,ll>vis;
void init(){
	tol=1;
	vis.clear();
}
void update(int &u, int x, int y, int p, ll v)
{
    sum[tol]=sum[u]+v;
	lc[tol]=lc[u];
	rc[tol]=rc[u];
    u=tol++;
    if(x==y) return;
    int m=(x+y)/2;
    if(p<=m) update(lc[u],x,m,p,v);
    else update(rc[u],m+1,y,p,v);
}
ll query(int u, int x, int y, int ql, int qr)
{
    if(ql <= x && y <= qr) {
    	return sum[u];	
	}
    int m = (x+y)/2;
    ll ans = 0;
    if(ql<=m){
    	ans+=query(lc[u],x,m,ql,qr);
	} 
    if(qr>m){
    	ans+=query(rc[u],m+1,y,ql,qr);
	} 
    return ans;
}
inline void solve(int n,int q){

	for(int i=1;i<=n;i++){
		scanf("%lld",&s[i]);
	}	
	for(int i=1;i<=n;i++){
		rt[i]=rt[i-1];
		if(vis.find(s[i])!=vis.end())
		{
			int tmp=rt[i-1];
			update(tmp,1,n,vis[s[i]],-1);
			rt[i]=tmp;
			update(rt[i],1,n,i,1);
		}
		else 
		{
			rt[i] = rt[i-1];
            update(rt[i],1,n,i,1);
        }
        vis[s[i]]=i;
	}
	while(q--){
		int l,r;
		scanf("%d %d",&l,&r);
		ll g=query(rt[r],1,n,l,r);
		printf("%lld\n",g);
	}
}
int main(){
	cio;
	int n,q;
	init();
	scanf("%d %d",&n,&q);
	solve(n,q);
	return 0;
}

Measured memory_bytes: 321072
#include <iostream>

using namespace std;

int N;
long long A[100005];

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

#define K 0
#define U 1
#define D 2

	int f = K;
	int cnt = 1;

	for (int i = 0; i < N - 1; i++){
		if (f == U && A[i] > A[i + 1]){
			cnt++;
			f = K;
			continue;
		}
		if (f == D && A[i] < A[i + 1]){
			cnt++;
			f = K;
			continue;
		}
		if (f == K && A[i] < A[i + 1]){
			f = U;
			continue;
		}
		if (f == K && A[i] > A[i + 1]){
			f = D;
			continue;
		}
	}

	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 1024