akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

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

typedef long long ll;

const int INF = 1 << 30;
const ll LLINF = 1LL << 62;

int mod = 1000000007;

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

Measured memory_bytes: 3656
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N;
        int[] V = new int[20];
        int[] U = new int[20];
        N=sc.nextInt();
        for(int i=0;i<N;i++){
            V[i]=sc.nextInt();
        }
        for(int i=0;i<N;i++){
            U[i]=sc.nextInt();
        }
        int sum=0;
        for(int i=0;i<N;i++){
            if(V[i]-U[i]>0) sum=sum+V[i]-U[i];
        }
        System.out.println(sum);
    }
}

Measured memory_bytes: 21460
#include<iostream>
using namespace std;
int main(){
	int a[5],min=10,sum=0;
	for(int i=0;i<5;i++){
		cin >> a[i];
		int rem = a[i]%10;
		if(rem!=0 && min>rem)	min = rem;
		sum += (a[i]+9)/10;	
	}
	cout << (sum-1)*10+min << endl;
	return 0;
}

Measured memory_bytes: 256
import fractions
from functools import reduce
def func():
    n,x0 = map(int,input().split())
    x = [int(i) for i in input().split()]
    x.append(x0)
    x.sort()
    x.reverse()
    
    l = []
    before = 0
    before = None
    for xi in x:
        if before == None:
            before = xi
            continue
        l.append(xi-before)
        before = xi
    
    print(abs(reduce(fractions.gcd,l)))
func()

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

const ll N = 2e5 + 8;
ll n, m;
vector <ll> g[N];
vector <ll> ans(N, 0);
vector <bool> was(N, false);

void DFS (ll v) {
    was[v] = true;
    if (g[v].size() == 0) {
        ans[v] = 0;
        return;
    }
    for (ll u : g[v]) {
        if (!was[u])
            DFS(u);
        ans[v] = max(ans[v], ans[u] + 1);
    }
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ///freopen("input.in", "r", stdin);
    ///freopen("output.out", "w", stdout);
    cin >> n >> m;
    for (ll i = 0; i < m; ++i) {
        ll v, u;
        cin >> v >> u;
        --v, --u;
        g[v].push_back(u);
    }
    for (ll i = 0; i < n; ++i)
        if (!was[i])
            DFS(i);
    ll mx = 0;
    for (ll i = 0; i < n; ++i)
        if (ans[i] > mx)
            mx = ans[i];
    cout << mx;
    return 0;
}

/**


**/


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

#define fl(n)             for(long long int i=0;i<n;i++)
#define sz(a)             int((a).size())
#define tr(c,i)           for(auto i = (c).begin(); i != (c).end(); i++)
#define trr(c,i)          for(auto i = (c).rbegin(); i != (c).rend(); i++)
#define present(c,x)      ((c).find(x) != (c).end())
#define cpresent(c,x)     (find(all(c),x) != (c).end())
#define vi                vector <int>
#define vvi               vector < vi >
#define pb                push_back
#define all(x)            (x).begin(),(x).end()
#define ll                long long
#define fr                first
#define sc                second
#define vc                vector
#define pii               pair<int,int>
#define msi               map<string,int>
#define mii               map<int,int>
#define psi               pair<string,int>
#define pis               pair<int,string>
#define M                 1000000007LL


int solve()
{
  string s;
  cin>>s;
  cout<<s;
  if(s[sz(s)-1]=='s')
  {
    cout<<"es";
  }
  else
    cout<<"s";


  return 0;
}


int main() {
  #ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);
  #endif

      ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);       

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




Measured memory_bytes: 3668
#include <bits/stdc++.h>
 
using namespace std;
 
int main() {
  
  int  A , B , C , D , N ;
  
  cin >>  N ; 
  
  A = N / 1000 ;                                   
  
  B = ( N - A * 1000 ) / 100 ;                     
  
  C = ( N - A * 1000 - B * 100 ) / 10 ;            
  
  D = N % 10 ;            
  
  if (B != C) {
    cout << " No " << endl ;
  }
  
  else if ( A == B ) {
    cout << " Yes " << endl ;   
  }
  
  else if ( D == B ) {
    cout << " Yes " << endl ;
  }
  
  else  {
    cout << " No " << endl ;
  }  
  
}

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

int main() {
    int x,a,b;
    cin >> x >> a >> b;
    
    int d1 = abs(x-a);
    int d2 = abs(x-b);
    
    d1<d2?cout<<"A":cout<<"B";
    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


def eratosthenes(n):
    p = []
    t = [True] * n

    t[1] = True
    for i in range(2, int(math.ceil(math.sqrt(n)))):
        if t[i]:
            p.append(i)
            for j in range(2*i, n, i):
                t[j] = False

    for j in range(i+1, n):
        if t[j]:
            p.append(j)

    return p


def divisor(n):
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            yield i
            if i != n // i:
                yield n // i


@mt
def slv(N):
    ans = 0
    for i in divisor(N):
        m = i-1
        if m == 0:
            continue
        if N//m == N % m:
            ans += m
    return ans


def slv2(N):
    ans = 0
    for m in range(1, N+1):

        if N//m == N % m:
            # print(m)
            print(m, N//m, N % m)
            ans += m
    return ans


def main():
    N = read_int()
    # print(slv2(N))
    print(slv(N))


if __name__ == '__main__':
    main()


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

int main() {
    long mod = 1000000007;

    long long n, k;
    cin >> n >> k;

    long long amount = 0;
    for (long long i = k; i <= n+1; i++) {
        amount = (i * (n - i + 1) % mod + 1 + amount) % mod;
    }

    cout << amount << endl;

    return 0;
}


Measured memory_bytes: 3592
import java.util.Scanner;
public class Main {
    public static void main(String[] defargs) {
        Scanner scanner = new Scanner(System.in);
        int a = scanner.nextInt();
        int b = scanner.nextInt();
        int d = a / b;
        int r = a % b;
        double f = (double)a / (double)b;
        System.out.print(d + " " + r + " ");
        System.out.printf("%f\n", f);
    }
}


Measured memory_bytes: 26480
import numpy as np
N,K = map(int,input().split())
X = np.array(input().split(), dtype=np.int64)

INF = 10 ** 18
neg = np.concatenate([-X[X <= 0][::-1], np.full(N+1,INF,dtype=np.int64)])[:K]
pos = np.concatenate([X[X > 0], np.full(N+1,INF,dtype=np.int64)])[:K]

answer = INF
# 左のみ
answer = min(answer, neg[-1])
# 右のみ
answer = min(answer, pos[-1])
if K >= 2:
  # 左にa個、右にK-a個
  answer = min(answer, (neg[:K-1] * 2 + pos[K-2::-1]).min())
  # 右にa個、右にK-a個
  answer = min(answer, (pos[:K-1] * 2 + neg[K-2::-1]).min())

print(answer)


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

using namespace std;
using ll = long long;
using ld = long double;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define reps(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
const ll mod = 1e9 + 7;
const int INF = 1e9;

int main() {
	cin.sync_with_stdio(false);
	int N;
	cin >> N;
	vector<int>A(N), B(N), C(N);
	rep(i, N)cin >> A[i];
	rep(i, N)cin >> B[i];
	rep(i, N)cin >> C[i];
	sort(A.begin(), A.end());
	sort(C.begin(), C.end());
	ll ans = 0;
	rep(i, N) {
		ll x= (lower_bound(A.begin(), A.end(), B[i]) - A.begin());
		ll y= (N - (upper_bound(C.begin(), C.end(), B[i]) - C.begin()));
		ans += x*y;
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;

const int maxn = 1e5 + 7;
int main(){
    int n, num2 = 0, num4 = 0;
    scanf("%d", &n);
    for(int i = 0; i < n; i++){
        int x;
        scanf("%d", &x);
        if(x % 4 == 0) num4++;
        if(x % 2 == 0) num2++;
    }
    num2 -= num4;
    if(num2 > 0)
    n -= num2 - 1;
    if(num4 >= n / 2) puts("Yes");
    else puts("No");
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define  forloop for(int i=0;i<n;i++)
#define pb push_back 
#define ull unsigned long long
#define ll long long
#define mod 1000000007
#define MOD 998244353;
#define unmap unordered_map
#define pi 3.1415926536
#define testcases ll t;cin>>t;while(t--)
#define  mp make_pair
#define  vcp vector<pair<ll,ll>>
#define preci(x,y)  fixed<<setprecision(y)<<x
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define fast ios::sync_with_stdio(false);   cin.tie(0); cout.tie(0);
#define preinc priority_queue <ll, vector<ll>, greater<ll>>
#define predec priority_queue<ll> 
#define vll vector<ll>
#define f(a,b) for(ll i=a;i<=b;i++)
ll cost(ll n,ll w,ll ind,ll we[],ll co[],vector<vector<ll>>&v)
{
   if(ind>=n)
   {
    return 0;
   }
   ll inc=LONG_MIN;
   if(v[ind][w]!=-1)
    return v[ind][w];
   if(w-we[ind]>=0)
   {
    inc=cost(n,w-we[ind],ind+1 ,we,co,v)+co[ind];
   }
   ll exc=cost(n,w,ind+1,we,co,v);
   return v[ind][w]=max(inc,exc);
}
int main() {
    #ifndef ONLINE_JUDGE
   freopen("inp.txt", "r", stdin);
   freopen("output.txt", "w", stdout);
   #endif
   fast
ll n;
   cin>>n;
   ll w;
   cin>>w;
   ll we[n],co[n];
   vector<vector<ll>>v(n+1,vector<ll>(w+1,-1));
   for(int i=0;i<n;i++)
   {
    cin>>we[i];
    cin>>co[i];
   }
   cout<<cost(n,w,0,we,co,v);
    // your code goes here
    return 0;
}

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

int d[100], a[100];
map<vector<int>, int>id;
unordered_map<int, vector<int>>re;
int dp[100][5040];

int main() {
	int n; scanf("%d", &n);
	rep(i, n)scanf("%d", &d[i]);
	rep(i, n)scanf("%d", &a[i]);
	vector<int>v(7); iota(v.begin(), v.end(), 0);
	int p = 0;
	do {
		id[v] = p; re[p] = v;
		int cnt = 0, t = 0;
		for (int i : v) {
			rep(j, 7) {
				if ((t >> j & 1) && abs(j - i) <= d[j])cnt += a[j];
			}
			t |= 1 << i;
		}
		dp[0][p] = cnt;
		p++;
	} while (next_permutation(v.begin(), v.end()));
	int ans = 0;
	for (int i = 1; i + 6 < n; i++)rep(j, 5040) {
		rep(k, 8) {
			auto t = re[j].begin();
			int cnt = 0, p = 0, o = 0;
			vector<int>q(7);
			rep(l, 8) {
				if (k == l) {
					rep(y, 8) {
						if ((p >> y & 1) && y + d[i - 1 + y] >= 7)
							cnt += a[i - 1 + y];
					}
					p |= 1 << 7; q[o++] = 6;
				}
				else {
					if ((p >> 7 & 1) && 7 - d[i + 6] <= *t)cnt += a[i + 6];
					p |= 1 << *t;
					if (*t)q[o++] = *t - 1;
					t++;
				}
			}
			int v = id[q];
			dp[i][v] = max(dp[i][v], dp[i - 1][j] + cnt);
			ans = max(ans, dp[i][v]);
		}
	}
	printf("%d\n", ans);
}

Measured memory_bytes: 6272
#include "bits/stdc++.h"
 
typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
// #define INF LLONG_MAX/2

using namespace std;

int MOD = 1000000007;
int n,a,b;

signed main(){


    cin >> n >> a >> b;
    int ans = 0;
    int x[100010] = {0};
    rep(i,n) cin >> x[i];
    for(int i = 1;i <= n-1;i++){
        ans += min(b,a*(x[i]-x[i-1]));
    }

    cout << ans <<endl;
    

    return 0;
}
// g++ -std=c++14 code1.cpp
// rm -r -f test;oj dl 

Measured memory_bytes: 1024
N=int(input())
sub=[]
AB=[]
for _ in range(N):
    a,b=map(int,input().split())
    AB.append((a,b,a+b))
    sub.append(a+b)
ta=0
ao=0
AB.sort(key=lambda x:-x[2])
for i in range(N):
    if i%2==0: ta+=AB[i][0]
    else: ao+=AB[i][1]
print(ta-ao)

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

int main() {
	char A, B; cin >> A >> B;
	if (A - 'A' > B - 'A') cout << '>' << endl;
	else if (A - 'A' < B - 'A') cout << '<' << endl;
	else cout << '=' << endl;

	return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
	public static void main(String args[]){
		
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		if((n%1000)==0)
		{
			System.out.println(0);
		}
		else{
			System.out.println(1000-n%1000);
		}
	}
};

Measured memory_bytes: 35704
package main

import (
	"fmt"
)

func main() {
	listA := make([][]int, 3)
	for i := 0; i < 3; i++ {
		listA[i] = make([]int, 3)
	}
	for i := 0; i < 3; i++ {
		for j := 0; j < 3; j++ {
			fmt.Scan(&listA[i][j])
		}
	}
	var n int
	fmt.Scan(&n)
	listB := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&listB[i])
	}

	flagList := make([][]int, 3)
	for i := 0; i < 3; i++ {
		flagList[i] = make([]int, 3)
	}

	for i := 0; i < n; i++ {
		for j := 0; j < 3; j++ {
			for k := 0; k < 3; k++ {
				if listB[i] == listA[j][k] {
					flagList[j][k] = 1
				}
			}

		}
	}

	if flagList[0][0] == 1 && flagList[0][1] == 1 && flagList[0][2] == 1 {
		fmt.Println("Yes")
		return
	}
	if flagList[1][0] == 1 && flagList[1][1] == 1 && flagList[1][2] == 1 {
		fmt.Println("Yes")
		return
	}
	if flagList[2][0] == 1 && flagList[2][1] == 1 && flagList[2][2] == 1 {
		fmt.Println("Yes")
		return
	}
	if flagList[0][0] == 1 && flagList[1][0] == 1 && flagList[2][0] == 1 {
		fmt.Println("Yes")
		return
	}
	if flagList[0][1] == 1 && flagList[1][1] == 1 && flagList[2][1] == 1 {
		fmt.Println("Yes")
		return
	}
	if flagList[0][2] == 1 && flagList[1][2] == 1 && flagList[2][2] == 1 {
		fmt.Println("Yes")
		return
	}
	if flagList[0][0] == 1 && flagList[1][1] == 1 && flagList[2][2] == 1 {
		fmt.Println("Yes")
		return
	}
	if flagList[0][2] == 1 && flagList[1][1] == 1 && flagList[2][0] == 1 {
		fmt.Println("Yes")
		return
	}

	fmt.Println("No")
}


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

using namespace std;

int main() {
  string S, T;
  cin >> S >> T;
  
  vector<char> S1(S.size());
  vector<char> T1(T.size());
  
  for (int i = 0; i < S.size(); i++) {
    S1.at(i) = S.at(i);
  }
  for (int i = 0; i < T.size(); i++) {
    T1.at(i) = T.at(i);
  }
  int count = 0;
  for (int i = 0; i < S.size(); i++) {
    if (S.at(i) == T.at(i)) {
      count++;
    }
  }
  if (count == S.size()) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
int main(){
int y,x,m;
while(1){
cin >> x>>y;
if (x==0&&y==0) break;
if(x<y) {m=x;x=y;y=m;};
cout<<y<<" "<<x<<endl;
x=0;
y=0;
}	return 0;
}


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

sys.setrecursionlimit(10**7)
inf = 10**9

def f():
    a,b,c = list(map(int, input().split()))
    return min(b*c*(a%2),a*b*(c%2),a*c*(b%2))

print(f())


Measured memory_bytes: 7840
#!/usr/bin/env python3
import sys
from math import *
from itertools import *
from collections import *
from functools import *
try:
    from math import gcd
except Exception:
    from fractions import gcd


def dfs(s, N):
    if N < int(s):
        return 0

    ret = 1 if all([c in s for c in '753']) else 0
    for c in '753':
        ret += dfs(s + c, N)
    return ret


def solve(N: int):
    return dfs('0', N)


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
    result = solve(N)
    print(result)

if __name__ == '__main__':
    main()


Measured memory_bytes: 5124
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <cmath>
#include <vector>

typedef long long ll;
const ll LL_MAX (1LL<<60);

#define rep(i,s,e) for(ll i=(s); i<(e); i++) 

using namespace std;

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

    ll n;
    cin >>n;
    vector<ll> d(n,0);
    rep(i,0,n) cin>>d[i];

    ll sum(0);
    rep(j,0,n)
        rep(i,j,n)
            if (i != j)
            {
                ll y = d[i] * d[j];  
                //cout << y << ' ' << i << ',' << j  << endl;
                sum += y;  
            }

    cout << sum << endl;

    return 0;

}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define rep2(i,n) for(int i=0;i<=n;i++)
#define repr(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define uni(e) e.erase(unique(e.begin(),e.end()),e.end())
#define double long double
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 INF=1e10;
int MOD=1e9+7;
signed main(){
 int a;
  string b;
  cin>>a>>b;
  rep1(i,b.size()){
  if(a<i){
  cout<<"...";
    break;
  }
    cout<<b[i-1];
  }
  
}

Measured memory_bytes: 3628
#include <stdio.h>
int main(void){
    int a, b, c, d;
    
    scanf("%d %d %d %d", &a, &b, &c, &d);
    
    for(;;){
        c = c - b;
        if(c < 1){
            printf("Yes\n");
            break;
        }
        a = a - d;
        if(a < 1){
            printf("No\n");
            break;
        }
    }
    
}


Measured memory_bytes: 1580
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <stack>
#include <queue>
using namespace std;
using ll = long long;
using P = pair<int, ll>;

int main()
{
    int n;
    cin >> n;
    vector<ll> a(n);
    for (int i = 0; i < n; ++i) 
    {
        cin >> a[i];
        if (a[i] & 1)
        {
            cout << 0 << endl;
            return 0;
        }
    }

    ll ans = 0;
    while(true)
    {
        ++ans;
        bool ok = true;
        for (int i = 0; i < n; ++i)
        {
            a[i] = a[i] / 2;
            if  (a[i] & 1)
            {
                ok = false;
                break;
            }
        }
        if (!ok) break;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
	int N, H, W, A, B, i, ans = 0;
	scanf("%d%d%d", &N, &H, &W);
	for(i = 0; i < N; i++){
		scanf("%d%d", &A, &B);
		if(A >= H && B >= W){
			ans++;
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

int Digits(int a) {
  int ret = 0;
  while(a > 0) {
    a /= 10;
    ++ret;
  }
  return ret;
}

int main(void) {
  int a, b, c, d;
  scanf("%d%d", &a, &b);
  c = a;
  d = Digits(b);
  for (int i = 0; i < d; ++i) {
    c *= 10;
  }
  c += b;
  
  int ok = 0;
  for (int i = 0; i < 1000; ++i) {
    if (i * i == c) ok = 1;
  }
  puts(ok ? "Yes" : "No");
  return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<map>
#include<vector>
using namespace std;
#define INF (1<<20)
map<string,int> m;
vector<int> num;
main(){
  m["I"]=1;
  m["II"]=2;
  m["III"]=3;
  m["IV"]=4;
  m["V"]=5;
  m["VI"]=6;
  m["VII"]=7;
  m["VIII"]=8;
  m["IX"]=9;
  m["X"]=10;

  m["XI"]=11;
  m["XII"]=12;
  m["XIII"]=13;
  m["XIV"]=14;
  m["XV"]=15;
  m["XVI"]=16;
  m["XVII"]=17;
  m["XVIII"]=18;
  m["XIX"]=19;
  m["XX"]=20;

  m["XXX"]=30;
  m["XL"]=40;
  m["L"]=50;
  m["LX"]=60;
  m["LXX"]=70;
  m["LXXX"]=80;
  m["XC"]=90;
  m["C"]=100;
  m["D"]=500;
  m["M"]=1000;
  string str;
  while(cin >> str){
    int res=0;
    int tmp;
    for(int i=0;i<(int)str.size();i++){
      for(int j=4;j>0;j--){
	if(i+j>str.size()) continue;
	if(m[str.substr(i,j)]>0){
	  num.push_back(m[str.substr(i,j)]);
	  i+=(j-1);
	  break;
	}
      }
    }
    int i=0;
    for(i=0;i<num.size()-1;i++){
      // cout << num[i] << endl;
      if(num[i]>=num[i+1]) res += num[i];
      else{ res += (num[i+1]-num[i]); i++;}
    }
    
    //   cout << num.back() << endl;
    if(i==num.size()-1)
      res += num.back();
    cout << res << endl;
    num.clear();
  }
}

Measured memory_bytes: 1236
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll MOD = 1000000007;

#define vec                vector<int>
#define vecll              vector<ll>
#define vecst              vector<string>
#define vecb               vector<bool>
#define vec2(var, n, m)    vector<vector<int>> var(n, vector<int>(m, 0))
#define vecll2(var, n, m)  vector<vector<ll>> var(n, vector<ll>(m, 0))

#define rep(i,n)         for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n)       for(ll i=(ll)m; i<(ll)n; i++)
#define arr(var, n)      vec var(n); rep(i,n){cin >> var[i];}
#define arrll(var, n)    vecll var(n); rep(i,n){cin >> var[i];}
#define arrst(var, n)    vecst var(n); rep(i,n){cin >> var[i];}
#define all(var)         (var).begin(), (var).end()
#define sortall(var)     sort(all(var))
#define uniqueall(v)     v.erase(unique(v.begin(), v.end()), v.end());
#define f_sum(var)       accumulate(all(var), 0)
#define f_sumll(var)     accumulate(all(var), 0LL)
#define chmin(v1, v2)    v1 = min(v1, v2)
#define chmax(v1, v2)    v1 = max(v1, v2)
#define pb(var)          push_back(var)
#define prt(var)         cout << (var) << "\n"
#define prtd(n, var)     cout << fixed << setprecision(n) << var << "\n"
#define prtfill(n, var)  cout << setw(n) << setfill('0') << var;
#define prt2(v1, v2)     cout << v1 << " " << v2 << "\n"
#define prt3(v1, v2, v3) cout << v1 << " " << v2 << " " << v3 << "\n"
#define prtall(v)        rep(i,v.size()){cout<<v[i]<<(i!=v.size()-1?" ":"\n");}
void prtok(bool ok){prt(ok ? "yes" : "no");}
//----------------------------------------------------------------
#define bitrep(i, n)     for(ll i=0; i<(ll) (1<<n); i++)
#define bis(i, j)        i & (1<<j)

int main(void) {
  int n;
  cin >> n;
  arr(a,n);
  sort(all(a), greater<int>());
  int q;
  cin >> q;
  arr(m,q);

  map<ll,int> exist;
  bitrep(i,n){
    ll tmp=0;
    rep(j,n){
      if(bis(i,j)){
        tmp += a[j];
      }
    }
    if(exist.find(tmp)==exist.end()){
      exist[tmp]=1;
    }
  }

  rep(i,q){
    if(exist.find(m[i])==exist.end()) prt("no");
    else prt("yes");
  }
}



Measured memory_bytes: 3144
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
#include <cmath>
#include <stack>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll = long long int;

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

const long long MOD = 1000000007;

int main(){
  ll x, y;
  ll ans = 0;
  cin>>x>>y;
  while(x<=y) {
    x*=2;
    ans++;
  }
  std::cout << ans << std::endl;
  return 0;
}


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

using namespace std;
#define DBG(x)                         \
    (void)(cout << "L" << __LINE__     \
                << ": " << #x << " = " \
                << (x) << '\n')
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
typedef long long ll;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const long double PI = (acos(-1));
const long double EPS = 0.0000000001;
const int INF = 0x3f3f3f3f;
const int maxn = 1100000;
ll a[maxn];
void run_case()
{
    int n;
    cin >> n;
    //ll ans = 0;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
    }
    sort(a + 1, a + 1 + n, greater<int>());
    ll ans = 1ll * a[1];
    int cnt = n - 2;
    for (int i = 2; i <= n; i++)
    {
        if (cnt == 0)
            break;
        ans += 1ll * a[i];
        cnt--;
        if (cnt == 0)
            break;
        ans += 1ll * a[i];
        cnt--;
        if (cnt == 0)
            break;
    }
    cout << ans << "\n";
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setiosflags(ios::fixed) << setprecision(12);
    run_case();
    cout.flush();
    return 0;
}

Measured memory_bytes: 5196
// Gaurav Nuti
 
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii > vii;
typedef vector<pll > vll;
#define pb push_back
#define mp make_pair 
#define ar array
#define mod 1000000007
#define F first
#define S second
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define For(i, a, b) for(__typeof (a) i=a; i<=b; i++)
#define inp_arr(a,n) for(__typeof (n) i=0; i<n; ++i) {cin>>a[i];}
#define debug_arr(a,n) {{for(__typeof (n) i=0; i<n; ++i) {cout<<a[i]<<" ";}cout<<"\n";}}
#define INF 1e9 

ll power(ll x, ll y) 
{ 
    ll res = 1;   
    while (y > 0) { 
        if (y & 1) 
            res = (res*x)%mod; 
        y = y>>1;
        x = (x*x)%mod; 
    } 
    return res%mod; 
}

ll power_without_mod(ll x, ll y) 
{ 
    ll res = 1;   
    while (y > 0) { 
        if (y & 1) 
            res = (res*x); 
        y = y>>1;
        x = (x*x); 
    } 
    return res; 
}

bool comparep(pair<ll, ll> i1, pair<ll, ll> i2){
	return (i1.S < i2.S);
} 

ll modInverse(ll a)
{
    return power(a , mod - 2);
}

vector<vector<ll>> graph;
vector<bool> visited;
vector<ll> dist;
map<ll,ll> mymap;
ll max_dist = 1;

void bfs(int u1){
    visited[u1] = 1;
    dist[u1] = 1;
    mymap[1] = u1;
    queue<ll> q;
    q.push({u1});
    while(!q.empty()){
        ll u = q.front();
        q.pop();
        for(auto i=graph[u].begin();i!=graph[u].end();i++){
            if(!visited[*i]){
                dist[*i] = dist[u] + 1;
                visited[*i] = 1;
                max_dist = max(dist[*i],max_dist);
                mymap[dist[*i]] = *i;
                q.push({*i});
            }
        }
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
 
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout); 
    #endif  
	
    ll t;
    // cin>>t;
    t = 1;
    for(ll z=0;z<t;z++){
        ll k,a,b;
        cin>>k>>a>>b;
        int flag = 0;
        for(ll i=a;i<=b;i++){
            if(i%k == 0){
                flag = 1;
            }
        }
        if(flag == 1)
            cout<<"OK";
        else
            cout<<"NG";
    }
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define rep3(i, s, n, a) for (int i = (s); i < (int)(n); i += a)
#define rep2(i, s, n) rep3(i, s, n, 1)
#define rep(i, n) rep2(i, 0, n)

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

int main(){
    ll n;
    cin >> n;
    for(ll i=sqrt(n);i>=1;i--){
        if(n%i==0){
            ll big = n / i;
            int dig=0;
            while(big){
                dig++;
                big /= 10;
            }
            cout << dig << endl;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define faster ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
 
typedef vector<int> vi;;
typedef vector<ll> vll;

#define l() length()
#define sz() size()
 
#define b() begin()
#define e() end()
#define all(x) x.begin(), x.end()
 
#define pb(i) push_back(i)
#define PB() pop_back()
 
 
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;
#define mp make_pair
#define Fi first
#define Se second
 
const int maxx=100009;
 
// Happy Coding!

bool disl[10];
bool checkAllDigits(int num){
    while(num>0){
        int d=num%10;
        if(disl[d]==true){
            return false;
        }
        num/=10;
    }
    return true;
}
int _find(int n){
    while(1){
        if(checkAllDigits(n)){
            return n;
        }
        n++;
    }
    return n;
}
void solve(){
   int n,k;
   cin>>n>>k;
   
   memset(disl,false,sizeof(disl));
   for(int i=0;i<k;i++){
       int d;
       cin>>d;
       disl[d]=true;
   }
   
   cout<<_find(n)<<endl;
}
 
int main() {
    faster;
    int t=1;
    // cin>>t;
    
    while(t-->0){
        solve();
    }
	return 0;
}

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

template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void POSS(T condition){ if(condition) cout << "POSSIBLE" << endl; else cout << "IMPOSSIBLE" << endl; }
template<class T> inline void Poss(T condition){ if(condition) cout << "Possible" << endl; else cout << "Impossible" << endl; }
template<class T> inline void First(T condition){ if(condition) cout << "First" << endl; else cout << "Second" << endl; }
int character_count(string text, char character){ int ans = 0; for(int i = 0; i < text.size(); i++){ ans += (text[i] == character); } return ans; }
long power(long base, long exponent, long module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ long root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position move_pattern[4] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++){ ans += to_string(*i) + " "; } ans.pop_back(); cout << ans << endl; }
template<class T> T gcd(T a, T b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }} template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
#define mod long(1e9 + 7)
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl(long(n))

int main(){
    string s;
    cin >> s;
    string ans;
    for(int i = 0; i < s.size(); i++){
        if(s[i] == 'B'){
            if(ans.size()){
                ans.pop_back();
            }
        }else{
            ans.push_back(s[i]);
        }
    }
    cout << ans << endl;
}



Measured memory_bytes: 256
from collections import Counter
import heapq
N,M = map(int,input().split())
A = Counter(list(map(int,input().split())))

cards = []
for x,y in A.items():
  heapq.heappush(cards, (-x,y))

for _ in range(M):
  b,c = map(int,input().split())
  heapq.heappush(cards, (-c,b))
cnt = N
ans = 0
while cnt <= N:
  v,c = heapq.heappop(cards)
  v *= -1
  if cnt-c < 0:
    ans += v*cnt
    break
  else:
    ans += v*c
    cnt -= c

print(ans)


Measured memory_bytes: 105600
n = gets.to_i
a = gets.split.map(&:to_i)
b = gets.split.map(&:to_i)
c = gets.split.map(&:to_i)
pre = 0
sum = 0
for i in 0..(n-1)
  sum += b[a[i]-1]
  if pre != 0 && pre + 1 == a[i]
    sum += c[pre-1]
  end
  pre = a[i]
end
puts sum

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)


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

  int n;
  cin >> n;
  int a[n][2];
  rep(i,n) cin >> a[i][0];
  rep(i,n) cin >> a[i][1];

  int ans=0;
  rep(i,n){
    int sum=0;
    rep(j,n){
      if(j<i){
	sum+=a[j][0];
      }
      else if(j==i) sum+=a[j][0]+a[j][1];
      else {
	sum+=a[j][1];
      }	
    }
    ans=max(ans,sum);
  }
  cout << ans << endl;
  
  return 0;
    

}


Measured memory_bytes: 256
// in the name of Allah

#include <bits/stdc++.h>
using namespace std;

#define endl '\n'
#define pb push_back
#define ll long long
#define double long double
#define sz(x) ((int) (x.size()))

#define fr first
#define se second

#define inf 1e9
#define max_n 123456
#define mod 1000000007

ll add(ll a, ll b) {
	a += b;
	if(a >= mod) return a - mod;
	return a;
}

ll mul(ll a, ll b) {
	a *= b;
	if(a >= mod) return a % mod;
	return a;
}

ll power(ll a, ll b) {
	ll p = 1;
	while(b) {
		if(b&1) p = mul(p, a);
		a = mul(a, a);
		b /= 2;
	}
	return p;
}

int n;
ll a[3333];
ll dp[3333][3333][2];

ll memo(int i, int j, int t) {
	if(i == j) {
		if(t == 0) return a[i];
		return -a[i];
	}
	if(dp[i][j][t] != -1) return dp[i][j][t];
	ll res;
	if(t == 0) {
		res = max(memo(i+1, j, 1) + a[i], memo(i, j-1, 1) + a[j]);
	}
	else {
		res = min(memo(i+1, j, 0) - a[i], memo(i, j-1, 0) - a[j]);
	}
	return dp[i][j][t] = res;
}

int main() {
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n;
	for(int i=0; i<n; i++) cin >> a[i];
	memset(dp, -1, sizeof dp);
	cout << memo(0, n-1, 0) << endl;
	return 0;
}

Measured memory_bytes: 173952
#include <bits/stdc++.h>
 
using namespace std;
 
typedef vector<int> Pile;
typedef vector<Pile> Piles;
 
struct P { int p, h; P(int p, int h) : p(p), h(h) {} };
 
P get_pos(Piles &piles, int id)
{
    for (int i = 0; i < (int)piles.size(); i++) {
        for (int j = 0; j < (int)piles[i].size(); j++) {
            if (piles[i][j] == id) return P(i, j);
        }
    }
    return P(-1, -1);
}
 
void move(Piles &piles, int pos)
{
    int id = piles[pos].back();
    piles[pos].pop_back();
    piles.push_back(Pile(1, id));
}
 
int main()
{
    int M, a, b;
    while (cin >> M, M) {
        Piles piles(M);
        for (int i = 0; i < M; i++) {
            piles[i] = Pile(1, i+1);
        }
        while (cin >> a >> b, (a | b)) {
            auto p1 = get_pos(piles, a), p2 = get_pos(piles, b);
            if (b == 0 && p1.h == 0) continue;
            if (p1.p == p2.p && p1.h >= p2.h) continue;
             
            while (piles[p1.p].back() != a) {
                move(piles, p1.p);
            }
            piles[p1.p].pop_back();
            if (b == 0) {
                piles.push_back(Pile(1, a));
            } else {
                p2 = get_pos(piles, b);
                piles[p2.p].push_back(a);
            }
        }
        vector<int> res;
        for (auto &pile: piles) {
            if (pile.size() > 0) {
                res.push_back(pile.size());
            }
 
        }
        sort(res.begin(), res.end());
        for (int i = 0; i < (int)res.size(); i++) {
            cout << res[i] << endl;
        }
        cout << "end" << endl;
    }    
    return 0;
}

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

int main(int argc, char const *argv[]) {
  int n, x, sum, i, j, k;

  cin >> n >> x;

  while (!(n == 0 && x == 0)) {
    sum = 0;
    for (i = 1; i <= n; i++) {
      for (j = i + 1; j <= n; j++) {
        for (k = j + 1; k <= n; k++) {
          if (i + j + k == x) sum++;
        }
      }
    }
    cin >> n >> x;
    cout << sum << endl;
  }

  return 0;
}




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


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

    int p[1000];

    int cnt = 0;
    for(int i=0; i<1000; i++){
       int a = i / 100;
       int b = i / 10 % 10;
       int c = i % 10;

       int k=0;
       char tgt[3];
       tgt[0] = 48 + a;
       tgt[1] = 48 + b;
       tgt[2] = 48 + c;
       for(int j=0; j<str.size(); j++){
            if(str[j] == tgt[k]){
                    k++;
                    if( k > 2 ){
                        cnt ++;
                        break;
                    }
            }
       }
    }

    cout << cnt << endl;
    return 0;
}

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

int main(){
    ll a,b,n;
    cin>>a>>b>>n;
    ll x=min(b-1,n);
    cout<<a*x/b-x/b*a<<endl;
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

int main() {
  double r;
  cin>>r;
  printf("%lf %lf\n",r*r*M_PI,2*r*M_PI);
}


Measured memory_bytes: 3200
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define popb pop_back()
#define sz size()
#define y1 dfsdsfsdfsd
#define next fdsfsdfjkl
#define int long long
#define endl "\n"
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long long ll;
typedef unsigned long long ull;
double pi = acos(-1.0);
int mod = 1e9+7;
const double eps = (double)1e-9;
const ll INF = 1e18+7;
/////////////////////////////////////////
 
 
int n,k;
int a[100100]; 
main(){speed;
    cin>>n;
    
    for(int i=1;i<=n;i++){
        int x;
        cin>>x;
        a[x] = i;
    }
    
    for(int i=1;i<=n;i++) {
        cout<<a[i] <<" ";
    }
}

Measured memory_bytes: 1664
//object D {
object Main {
  import InOut._
  def main(args: Array[String]): Unit = {

    var x, k, d = nextLong
    x = Math.abs(x)
    val steps = Math.min(k, x / d)
    x -= steps * d
    k -= steps
    x -= (k % 2) * d

    out.println(Math.abs(x))

    out.flush()
  }
 
  final object InOut {
    val in = new java.io.BufferedReader(new java.io.InputStreamReader(System.in))
    val out = new java.io.PrintWriter(System.out, false)
    private[this] var tokenizer: java.util.StringTokenizer = _
    def nextToken: String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new java.util.StringTokenizer(in.readLine)
      tokenizer.nextToken
    }
    def nextInt = Integer.parseInt(nextToken)
    def nextLong = java.lang.Long.parseLong(nextToken)
    def nextBig = BigInt(nextToken)
    def nextInts(n: Int) = Array.fill(n) { nextInt }
    def nextLongs(n: Int) = Array.fill(n) { nextLong }
    def nextBigs(n: Int) = Array.fill(n) { nextBig }
    def nextLine = in.readLine
  }
}


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

using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define REP(NAME, NUM) for (size_t NAME = 0; NAME < (NUM); ++NAME)
#define BREP(NAME, NUM) for (size_t NAME = (NUM)-1; NAME >= 0; --NAME)
#define ALL(NAME) (NAME).begin(), (NAME).end()
#define VEC(TYPE, A, NAME, INIT) vector<TYPE> NAME(A, INIT)
#define VEC2(TYPE, A, B, NAME, INIT) vector<vector<TYPE>> NAME(A, vector<TYPE>(B, (INIT)))

int main()
{
	ull a, b, c;
	cin >> a >> b >> c;

	if( a == b && b == c )
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
  int a, b;
  cin >> a >> b;

  for (int i = a / 0.08; i < (a + 1) / 0.08; ++i) {
    if (static_cast<int>(i * 0.08) != a || static_cast<int>(i * 0.10) != b)
      continue;
    cout << i << endl;
    return EXIT_SUCCESS;
  }
  cout << -1 << endl;
}

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

int main()
{
	int n;
	cin >> n;
	deque<ll> a(n);
	for(auto &i:a)cin >> i;
	deque<ll> ans;
	sort(a.begin(),a.end());
	ans.push_back(a.back());
	a.pop_back();
	while(a.size())
	{
		vector<pair<int,int>> vp(4);
		vp[0] = make_pair(abs(ans.front()-a.front()),0);
		vp[1] = make_pair(abs(ans.front()-a.back()),1);
		vp[2] = make_pair(abs(ans.back()-a.front()),2);
		vp[3] = make_pair(abs(ans.back()-a.back()),3);
		sort(vp.begin(),vp.end(),greater<>());
		int od = vp.front().second;
		if(od==0)
		{
			ans.push_front(a.front());
			a.pop_front();
		}
		else if(od==1)
		{
			ans.push_front(a.back());
			a.pop_back();
		}
		else if(od==2)
		{
			ans.push_back(a.front());
			a.pop_front();
		}
		else
		{
			ans.push_back(a.back());
			a.pop_back();
		}
	}
	ll out = 0;
	for(int i = 0;i<n-1;i++)
	{
		out+= abs(ans[i]-ans[i+1]);
	}
	cout<<out<<endl;


}


Measured memory_bytes: 4464
#include<stdio.h>
int e,ta[100010],nt[200010],to[200010],c[200010],u[100010];
int MAX(int a,int b){return a<b?b:a;}
int f(int n,int s){
  u[s]=1;
  int r=0,m=0,i;
  for(i=ta[s];i+1;i=nt[i]){
    if(u[to[i]])continue;
    if(r==n)r++;
    c[i]=c[(i+(e-1))%(2*(e-1))]=r++;
    m=MAX(m,f(r-1,to[i]));
  }
  return MAX(m,r);
}   
int main(){
  int i,a,b;
  scanf("%d",&e);
  for(i=0;i<e;i++)ta[i]=-1;
  for(i=0;i<e-1;i++){
    scanf("%d %d",&a,&b);
    a--;
    b--;
    nt[i    ]=ta[to[i+e-1]=a];
    nt[i+e-1]=ta[to[i    ]=b];
    ta[b]=i+e-1;
    ta[a]=i    ;
  }
  printf("%d\n",f(-1,0));
  for(i=0;i<e-1;i++)printf("%d\n",c[i]+1);
  return 0;
}


Measured memory_bytes: 4864
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n, b, ans;
ll a[100005];
ll c[100005];
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	cin >> n;
	for (ll i = 0; i < n+1; i++){
		cin >> a[i];
		
	}
	for (ll i = 0; i < n; i++){
		cin >> c[i];
		}
	for (ll i = 0; i < n+1; i++){
		if (a[i] <= c[i]){
			c[i] -= a[i];
			ans += a[i];
			a[i] = 0; //good
			}else{
				ans += c[i];
				c[i] = 0;
				a[i] -= c[i];				
				}
		if (c[i] != 0){
			if (a[i+1] > c[i]){
				ans += c[i];
				a[i+1] -= c[i];
				}else{
					ans += a[i+1];
					a[i+1] = 0;
					}
			//a[i+1] -= c[i];
			//ans += a[i+1];
			c[i] = 0;
			
			}
		}
		cout << ans;
}

Measured memory_bytes: 1792
data Tree = Empty { contents :: (Int,Int)
                      ,maxCont :: (Int,Int)}| 
               Node { contents :: (Int,Int)
                     ,maxCont :: (Int,Int)
                     ,leftTree :: Tree
                     ,rightTree :: Tree}

empty :: Tree
empty = Empty (-1,-1) (-1,-1)

comp :: (Int,Int) -> (Int,Int) -> (Int,Int)
comp (a,b) (x,y)
  | b < y  = (x,y)
  | otherwise = (a,b)

update :: (Int,Int) -> Tree -> Tree
update (x,y) (Empty _ _) = Node (x,y) (x,y) empty empty
update (x,y) (Node (a,b) (c,d) left right)
  | x == a = Node
                (a,b+y)
                ((maxCont left) `comp` (a,b+y) `comp` (maxCont right))
                left
                right
  | x < a  = Node
                (a,b)
                ((maxCont left') `comp` (a,b) `comp` (maxCont right))
                left'
                right
  | x > a  = Node
                (a,b)
                ((maxCont left) `comp` (a,b) `comp` (maxCont right'))
                left
                right'
  where right' = update (x,y) right
        left' = update (x,y) left

format :: (Int,Int) -> String
format (a,b) = (show a) ++ " " ++ (show b)

main :: IO ()
main = do
  nq <- getLine
  let [n,q] = map (read :: String -> Int) $ words nq
      counter = q
      initTree = empty
  loopq counter initTree

loopq counter tree = do
  if counter <= 0
    then return ()
    else do
      av <- getLine
      let [a,v] = map (read :: String -> Int) $ words av
          tree' = update (a,v) tree
          ans = maxCont tree'
      putStrLn $ format ans
      loopq (counter - 1) tree'

Measured memory_bytes: 33824
import 'dart:io';

void main() {
  String n = stdin.readLineSync();
  int nLength = n.length;
  // print(nLength);
  int sum = 0;
  for (int i = 0; i < nLength; i++) {
    sum = sum + int.parse(n[i]);
  }
  // print(sum);
  if (sum % 9 == 0)
    print("Yes");
  else
    print("No");
}


Measured memory_bytes: 16444
import math

N = int(input())
P_str = input().split()
P = [int(p) for p in P_str]
Q_str = input().split()
Q = [int(q) for q in Q_str]

pnumber = [m for m in range(1, N+1)]
qnumber = [m for m in range(1, N+1)]

pnum = 1
qnum = 1

for i in range(N):
    pnum += pnumber.index(P[i])*math.factorial(N-i-1)
    pnumber.remove(P[i])
    
for i in range(N):
    qnum += qnumber.index(Q[i])*math.factorial(N-i-1)
    qnumber.remove(Q[i])

print(abs(pnum-qnum))

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

typedef long long int ll;
typedef long double ld;

#define rep(i,a,b) for(ll i=a;i<=b;++i)
#define rev(i,a,b) for(ll i=a;i>=b;i--)
#define pll pair<ll,ll>
#define vll vector<ll>
#define sll set<ll>
#define vpll vector<pll>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define ln length()
#define M 1000000007
ll n,m,a[100005];
vpll ch[100005];
pll p[100005];
int main(){
    cin>>n>>m;
    rep(i,1,n) cin>>a[i];
    rep(i,1,n-1){
        p[i]=mp(a[i],a[i+1]);
        ch[a[i]].pb(mp(i,1LL));
        ch[a[i+1]].pb(mp(i,2LL));
    }
    ll ans=0,ctbe=0;
    rep(i,1,n-1){
        if(p[i].F > p[i].S) {ctbe++;ans+=p[i].S;}
        else ans+=p[i].S-p[i].F;
    }
    ll mi=ans;

    rep(i,2,m){
        for(pll xp:ch[i-1]){
            if(xp.S == 2){
                ctbe--;
                ans--;
                if(p[xp.F].F<p[xp.F].S) ans+=(p[xp.F].S-p[xp.F].F);
                else ans+=(p[xp.F].S+m-p[xp.F].F);
            }
        }
        ans-=ctbe;
        for(pll xp:ch[i-1]){
            if(xp.S == 1){
                ctbe++;
            }
        }
        mi=min(mi,ans);
    }
    cout<<mi<<'\n';
}


Measured memory_bytes: 9216
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define Int int32_t
#define all(c) c.begin(), c.end()
#define FAST ios_base::sync_with_stdio(false) , cin.tie(NULL);
#define pii pair< int , int >
#define pb push_back
#define F first
#define S second
#define endl "\n"
#define bitcnt(n) __builtin_popcountll(n)
#define setpre(n) cout << fixed << setprecision(n)
#define tr(c) for(auto x : c )cout << x << " ";
#define ol(c , s , e ) for(int pos=s; pos<e ; pos++) cout << c[pos] << " ";
#define PI acos(-1)
const int M = 1000000007;
const int N=1e6+5;
const int INF = 1e18+5;

//#define rohit
#ifdef rohit
template<typename... T >
void bug(T... __VA_ARGS__) {
    ((cerr << __VA_ARGS__ << " ") , ...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", bug(__VA_ARGS__) , cerr << endl;
#endif

void solve()
{
    double a, b, h, m;
    cin >> a >> b >>  h >> m;
    double angleH = 0 , angleM = 0;
    angleH = 30.0*h + 360.0/(12.0*60.0)*m;
    angleM = 6*m;
    double angle = abs(angleH - angleM);
    double ans = sqrt(a*a + b*b - 2.0*a*b*cos((angle*PI)/180.0));
    setpre(12) << ans << endl;
}

signed main()
{
    FAST;
    //TODO:  check test cases.
    int tc=1;
//    cin >> tc;
    for(int t = 1 ; t <= tc ; t++)
    {
        solve();
    }
}

/*TODO: (Extra Cares)
 * 1)Sometimes long long creates MLE.
 * 2)Check whether int to long long typecasting is commented or not?
 * 3)Check overflows.
*/

Measured memory_bytes: 4304
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<typename S, typename T>
void xmin(S&a, T const&b){if(b<a) a=b;}
template<typename S, typename T>
void xmax(S&a, T const&b){if(b>a) a=b;}

signed main()
{
    #ifdef LOCAL_RUN
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false);
    int TTT; cin >> TTT; while(TTT--){
    #else
    cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false);
    #endif // LOCAL_RUN

    array<ll, 3> v;
    for(auto &e:v) cin >> e;
    ll ans = *max_element(v.begin(), v.end()) - *min_element(v.begin(), v.end());
    cout << ans << "\n";


    #ifdef LOCAL_RUN
    }
    #endif // LOCAL_RUN
    return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline

INF = 10 ** 18

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

dp = [INF] * (H + 1)
dp[0] = 0

for i in range(N):
    A, B = map(int, input().split())
    for j in range(H + 1):
        if j < A:
            dp[j] = min(dp[j], dp[0] + B)
        else:
            dp[j] = min(dp[j], dp[j - A] + B)
    
print (dp[H])

# for d in dp:
#     print (d)

Measured memory_bytes: 42220