akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define int long long
#define vec(a,n) vector<int> (a)((n));
#define Vec(a,n) vector<string> (a)((n));
#define twovec(a,n,m) vector<vector<int>> a(n,vector<int>(m,0));
#define Twovec(a,n,m) vector<vector<double>> a(n,vector<double>(m,0));
#define P pair<int,int>
#define All(a) (a).begin(),(a).end()
#define Sort(a) sort(All(a));
#define Reverse(a) sort((a).rbegin(),(a).rend());
#define PQ(n) priority_queue<P,vector<P>,greater<P>> (n)
#define pq(n) priority_queue<int> (n)
#define print(a) cout << (a) << endl;
#define printD(a) cout << setprecision(10) << ans << endl;
using namespace std;
int max_int = 1000000007;
void Debug(auto a);
int nibul(auto a,auto b);
int nibuu(auto a,auto b);
void input(vector<int>& a,int n);

int n,m;


struct UnionFind {
    vector<int> par; // 親ノード
    vector<int> rank; // ランク

    UnionFind(int n = 1) {
        init(n);
    }

    void init(int n = 1) {
        par.resize(n); rank.resize(n);
        for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0;
    }

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

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y);
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        return true;
    }
};


int judge(string a,int piv,string b){
	REP(i,b.size()){
		if(a[piv+i] != b[i]){
			return 1;
		}
	}
	return 0;
}

signed main(){
	cin >> n;
	vec(a,n+1);
	vec(b,n);
	REP(i,n+1){
		cin >> a[i];
	}
	REP(i,n){
		cin >> b[i];
	}
	int ans = 0;
	REP(i,n){
		if(a[i]>b[i]){
			ans += b[i];
		}
		else{
			ans += a[i];
			b[i] -= a[i];
			ans += min(b[i],a[i+1]);
			a[i+1] = max((int)0,a[i+1]-b[i]);
		}
	}
	print(ans)

    return 0;
}

void Debug(auto a){
    cout << "{ ";
    for(auto b: a){
        cout << b << " ";
    }
    cout << "}" << endl;
}
int nibul(auto a,auto b){
    int x = lower_bound(All(a),b) - a.begin();
    //key以上の初めてのitr
    return x;
}
int nibuu(auto a,auto b){
    int x = upper_bound(All(a),b) - a.begin();
    //key以下の最後のitr
    return x-1;
}

void input(vector<int>& a,int n){
    REP(i,n){
        cin >> a[i];
    }
}


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

#define llint long long int

using namespace std;

int main(){
    int K, N;

    cin >> K >> N;

    vector<int> A(N);

    for(int i = 0; i < N; i ++){
        cin >> A[i];
    }
    int max = A[0] + K - A[N - 1];

    for(int i = 1; i < N; i ++){
        int temp = A[i] - A[i - 1];

        if(temp > max){
            max = temp;
        }
    }
    cout << K - max << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int main(){
  string s;
  cin >> s;
  for(int i = 0;i < s.size() - 1;i++){
    if(i < s.size() - 2){
      if(s[i] == s[i + 2]){
        cout << i + 1<< " " << i + 3 << endl;
        return 0;
      }
    }
    if(s[i] == s[i + 1]){
      cout << i + 1 << " " << i + 2 << endl;
      return 0;
    }
  }
  cout << -1 << " " << -1 << endl;
}

Measured memory_bytes: 512
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.buffer.readline().split()]
def I(): return int(sys.stdin.buffer.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n = I()
    v = [[] for i in range(n)]
    for i in range(n-1):
        a,b = LI()
        a -= 1
        b -= 1
        v[a].append(b)
        v[b].append(a)
    q = [0]
    q2 = []
    s = [0]*n
    e = [0]*n
    e[0] = 1
    while q:
        x = q.pop()
        for y in v[x]:
            if not e[y]:
                s[x] += 1
                e[y] = 1
                q.append(y)
                q2.append((y,x))

    while q2:
        y,x = q2.pop()
        e[x] += e[y]/s[x]
    ans = [None]*n
    ans[0] = e[0]
    q.append((0,s[0],e[0]))
    while q:
        x,sx,ex = q.pop()
        nsx = sx-1
        for y in v[x]:
            if ans[y] is None:
                sy,ey = s[y],e[y]
                nex = ((ex-1)*sx-ey)/nsx+1 if nsx else 1
                nsy = sy+1
                ans[y] = ney = ((ey-1)*sy+nex)/nsy+1
                q.append((y,nsy,ney))

    for i in ans:
        print(i-1)
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 106096
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define endl '\n'
#define int long long


int32_t  main()
{
    IOS;  
    string s;
    cin>>s;
    if(s=="ABC")
        s="ARC";
    else
        s="ABC";
    cout<<s;
}

Measured memory_bytes: 3648
import java.io.BufferedInputStream



// Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
fun main(args: Array<String>) {
    fun StringArray(size: Int, init: (Int) -> String = { "\u0000" }): Array<String> {
        return Array<String>(size, init)
    }
    fun iterateTokens(): Iterator<String> {
        val reader = BufferedInputStream(System.`in`).bufferedReader()
        val iterator = reader.lineSequence()
                .map { it.split(" ") }
                .reduce { left, right -> left + right }
                .iterator()
        return iterator
    }
    val tokens = iterateTokens()
    val A = tokens.next().toLong()
    val B = tokens.next().toLong()
    val C = tokens.next().toLong()
    val D = tokens.next().toLong()
    solve(A, B, C, D)
}

fun <T : Comparable<T>> maxOf(a: T, b: T): T = if (a > b) a else b
fun <T : Comparable<T>> minOf(a: T, b: T): T = if (a < b) a else b

fun gcd(a: Long, b: Long): Long{
    fun _gcd(m: Long, n: Long): Long = if (m == 0L) n else _gcd(n % m, m)
    val m = minOf(a, b)
    val n = maxOf(a, b)
    return _gcd(m, n)
}

fun divsCount(start: Long, end: Long, mod: Long): Long{
    return (end / mod) - (start - 1) / mod
}

fun solve(A: Long, B: Long, C: Long, D: Long){
    val ans = B - A + 1L - divsCount(A, B, C) - divsCount(A, B, D) + divsCount(A, B, (C*D)/gcd(C, D))
    println(ans)
    return
}



Measured memory_bytes: 35456
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, begin, end) for(ll i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(ll i=(begin)-1;i>=(end);i--)
#define IREP(i, n) IFOR(i,n,0)
#define SORT(a) sort(a.begin(), a.end())
#define ISORT(a) sort(a.begin(), a.end(),greater<ll>())
#define REVERSE(a) reverse(a.begin(), a.end())
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) cout << #v << "=(" << v[0]; FOR(i_debug, 1, v.size()){ cout << "," << v[i_debug]; } cout << ")" << endl;
#define mdebug(m) cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;}
#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))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)

#define ll long long
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define INF 1000000000000000000

using vec = vector<ll>;
using mat = vector<vec>;
using Pii = pair<ll, ll>;
using PiP = pair<ll, Pii>;
using PPi = pair<Pii, ll>;
using bvec = vector<bool>;
using Pvec = vector<Pii>;


template<typename T> void readv(vector<T> &a) { REP(i, a.size()) cin >> a[i]; }
void readv_m1(vector<int> &a) { REP(i, a.size()) {cin >> a[i]; a[i]--;} }

ll mod = 1000000007;

int main()
{
	// 入力
	ll N, Q;
	cin >> N >> Q;
	// vector<ll> dist(N+1,-1);
	vector<vector<ll>> childdist(N);
	stack<ll> stack;
	ll a, b;
	REP(i, N - 1) {
		cin >> a >> b;
		a--;
		b--;
		childdist[a].emplace_back(b);
		childdist[b].emplace_back(a);
	}

	// vdebug(childdist[1]);

	vec x(N, 0);
	REP(i, Q) {
		ll p, xll;
		cin >> p;
		p--;
		cin >> xll;
		x[p] += xll;
	}

	// vdebug(x);

	vec ans(N, -1);

	// dist[1] = 0;
	stack.push(0);
	bool pop = false;
	ll ver = -1;
	ll addcnt = x[0];
	ll addcntrecent = x[0];
	ans[0] = addcnt;
	vector<ll> init(N, 0);
	while (stack.empty() == false) {
		ver = stack.top();
		// debug(ver);
		// debug(addcnt);
		ans[ver] = addcnt;
		addcntrecent = x[ver];
		pop = true;
		FOR(i, init[ver], childdist[ver].size()) {
			init[ver]++;
			if (ans[childdist[ver][i]] == -1) {
				stack.push(childdist[ver][i]);
				addcnt += x[childdist[ver][i]];
				addcntrecent = x[childdist[ver][i]];
				pop = false;
				break;
			}
		}
		if (pop) {
			stack.pop();
			addcnt -= addcntrecent;
		}
		// if(stack.empty()==false) cout<<"pop "<<stack.top()<<endl;
		// cout<<"while"<<endl;
		// if(stack.empty()==false) cout<<"whiletop"<<stack.top()<<endl;
	}

	FOR(i, 0, N - 1) {
		cout << ans[i]  << " ";
	}
	cout << ans[N - 1] << endl;

	return 0;

}

Measured memory_bytes: 20480
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define test lli t;cin>>t;while(t--)
#define vll vector<lli>
#define mll map<lli,lli>
#define vvll vector<vector<lli>>
#define vpll vector<pair<lli,lli>>
#define vvpll vector<vector<pair<lli,lli>>>
#define mpll map<pair<lli,lli>,lli>
#define pll pair<lli,lli>
#define sll stack<lli>
#define qll queqe<lli>
#define pb push_back
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define ff first
#define ss second
#define mod 1000000007
#define ma 1000000000000000000
#define mi -1000000000000000000
int main()
{
  #ifndef ONLINE_JUDGE
	freopen("input1.txt", "r", stdin);
	freopen("output1.txt", "w", stdout);
#endif
  fastio
  lli a[100000]={0};
  lli i,n,x,y,z;
  cin>>n;
  for(x=1;x<=100;x++)
  {
  	for(y=1;y<=100;y++)
  	{
  		for(z=1;z<=100;z++)
  		{
  			a[x*x+y*y+z*z+x*y+y*z+z*x]++;
  		}
  	}
  }
  for(i=1;i<=n;i++)
  	cout<<a[i]<<endl;
	return 0;
}

Measured memory_bytes: 4336
import java.util.Arrays;
import java.util.*;
public class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
      int a = sc.nextInt();
      int b = sc.nextInt();
      String ans = "Yes";
      if((a*b)%2==0){
        ans = "No";
      }
      System.out.println(ans);
    }
}


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

int main()
{
    ll n;ll ans = 1;
    cin>>n;
    for(ll i = n;i>=1;i--)
    {
        ans*=i;
        ans%= 1000000007;
    }
    cout<<ans<<endl;
    return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
#define rep(i, n) for(int i=0; i<n; ++i)
#define REP(i, n) for(int i=1; i<=n; ++i)
#define all(obj) (obj).begin(), (obj).end()
using P = pair<int, int>;
const int inf = 1e9;
const ll INF = 1e18;
const ll MOD = 1e9+7;
const ll MAX = 1e9+7;
const double pi = 3.14159265;

int main(){
    double r; cin >> r;
    cout << setprecision(10) << 2 * pi * r << endl;
    return 0;
}

Measured memory_bytes: 3808
#include <bits/stdc++.h>
typedef long long int lld;
typedef unsigned long long int llu;
#define INF (lld)(9223372036854775807)
#define IINF (int)(2147483647)

using namespace std;

int main(void) {
  lld n, m;
  cin >> n >> m;
  cout << (n * m) << "\n";
}

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

using namespace std;

//#define FILE_IO

typedef long long LL;

int N, K;
int v[100005];
LL sum[100005], pls[100005];
LL ans;

int main()
{
    #ifdef FILE_IO
    freopen("1.in", "r", stdin);
    freopen("1.out", "w", stdout);
    #endif

    scanf("%d%d", &N, &K);
    for(int i = 1; i <= N; i++)
    {
        scanf("%d", &v[i]);
        sum[i] = sum[i - 1] + v[i];
        pls[i] = pls[i - 1] + max(0, v[i]);
    }

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

    printf("%lld\n", ans);

    return 0;
}


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

using namespace std;

using ll = long long;
constexpr ll MOD = 1e9 + 7;
constexpr ll INF = 1e18;
template <typename T>
T gcd(T x, T y) {
    return x ? gcd(y % x, x) : y;
}
int main() {
    ll n, m, i, j, k;
    cin >> n >> k;
    if(n>=k){
        n%=k;
    }
    cout << min(n,k-n) << endl;
    return 0;
}

Measured memory_bytes: 256
while true
    n,x = gets.chomp.split.map(&:to_i)
    break if n.zero? && x.zero?
    count = 0
    for i in 1..n
        for j in (i+1)..n
            for k in (j+1)..n
                count += 1 if x == i + j + k
            end
        end
    end
    puts count
end

Measured memory_bytes: 6108
#include<bits/stdc++.h>
#define N 505 
using namespace std;
inline int read(){
	int ans=0;
	char ch=getchar();
	while(!isdigit(ch))ch=getchar();
	while(isdigit(ch))ans=(ans<<3)+(ans<<1)+(ch^48),ch=getchar();
	return ans;
}
int h,w,a[N][N],pos[N];
bool vis[N][N],is[N][N];
struct Node{int a,b,c,d;};
vector<Node>q;
int main(){
	h=read(),w=read();
	for(int i=1;i<=h;++i){
		for(int j=1;j<=w;++j)a[i][j]=read();
		for(int j=1;j<w;++j)if(a[i][j]&1)a[i][j+1]++,q.push_back((Node){i,j,i,j+1});
	}
	for(int i=1;i<h;++i)if(a[i][w]&1)a[i+1][w]++,q.push_back((Node){i,w,i+1,w});
	cout<<q.size()<<'\n';
	for(int i=0;i<q.size();++i)cout<<q[i].a<<' '<<q[i].b<<' '<<q[i].c<<' '<<q[i].d<<'\n';
	return 0;
}

Measured memory_bytes: 5232
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <utility>
#include <map>

#define loopup(var,l,r) for(var=l;var<r;var++)
#define loopdown(var,r,l) for(var=r;var>=l;var--)
#define ll long long
#define mp(x,y) makepair(x,y)
#define br cout<<"\n"
#define mod 1000000007

using namespace std;

void solve(){
    int i,j,h,w;
    int dp[1001][1001];
    char arr[1001][1001];
    char dot,dash;
    dot = '.';
    dash = '#';
    cin>>h>>w;
    loopup(i,1,h+1){
        loopup(j,1,w+1){
            cin>>arr[i][j];
        }
    }
    dp[1][1] = 1;
    loopup(i,2,w+1) {
        if(arr[1][i-1] == dot && arr[1][i] == dot) {
            dp[1][i] = dp[1][i-1];
        } else {
            dp[1][i] = 0;
        }
    }
    loopup(i,2,h+1) {
        if(arr[i-1][1] == dot && arr[i][1] == dot) {
            dp[i][1] = dp[i-1][1];
        } else {
            dp[i][1] = 0;
        }
    }
    loopup(i,2,h+1) {
        loopup(j,2,w+1) {
            if(arr[i][j] == dash) {
                dp[i][j] = 0;
            } else {
                dp[i][j] = (1ll*dp[i][j-1] + dp[i-1][j]) % mod;
            }
        }
    }
    cout<<dp[h][w];
    br;
}

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



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

int main(){
  int A[3][3];
  for(int i = 0; i < 3; ++i)
    for(int j = 0; j < 3; ++j)
      cin >> A[i][j];
  int N;
  cin >> N;
  for(int i = 0; i < N; ++i){
    int b;
    cin >> b;
    for(int j = 0; j < 3; ++j){
      for(int k = 0; k < 3; ++k){
        if(A[j][k] == b)
          A[j][k] = 0;
      }
    }
  }
  bool bingo = false;
  int d1 = 0, d2 = 0;
  for(int i = 0; i < 3; ++i){
    int v = 0, h = 0;
    d1 += A[i][i];
    d2 += A[i][2-i];
    for(int j = 0; j < 3; ++j){
      v += A[i][j];
      h += A[j][i];
    }
    if(v == 0 or h == 0){
      bingo = true;
    }
  }
  if(d1 == 0 or d2 == 0)
    bingo = true;
  if(bingo) puts("Yes");
  else puts("No");
}


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

int main() {
	int n;
	cin >> n;
	int a[n];
	long long sum = 0, odd = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		sum += a[i];
		if (i % 2)
			odd += a[i];
	}
	sum /= 2;
	int temp = sum - odd;
	cout << temp * 2;
	for (int i = 0; i < n - 1; i++) {
		temp = a[i] - temp;
		cout << " " << temp * 2;
	}
	cout << endl;
}


Measured memory_bytes: 1664
#include <string>
#include <iostream>

using namespace std;

long long a, b;

int digit(long long n)
{
	return to_string(n).size();
}

long long sumsize(long long n)
{
	long long t = 1, sum = 0;

	while (t <= n)
	{
		if (t * 10 > n)
		{
			sum += (n - t + 1) * digit(t);
		}
		else
		{
			sum += t * 9 * digit(t);
		}

		t *= 10;
	}

	return sum;
}

string solve()
{
	// 1. Binary Search

	int rep = 40;

	long long l = 0;
	long long r = (1LL << rep);
	long long m;

	for (int i = 0; i <= rep; i++)
	{
		m = (l + r) / 2;

		if (sumsize(m) >= a)
		{
			r = m;
		}
		else
		{
			l = m;
		}
	}


	// 2. Solve

	string S;

	for (long long i = m + 1; S.size() < b; i++)
	{
		if (i == m + 1)
		{
			int r = a - sumsize(m) - 1;

			S += to_string(i).substr(r, digit(i) - r);
		}
		else
		{
			S += to_string(i);
		}
	}

	return S.substr(0, b);
}

int main()
{
	while (true)
	{
		cin >> a >> b;

		if (a == 0 && b == 0) { break; }

		cout << solve() << endl;
	}

	return 0;
}

Measured memory_bytes: 3140
#include <stdio.h>

int main (void){
  int A,B,C;
  scanf("%d %d %d",&A,&B,&C );
  if (A==B){
    printf("%d",C);
  }
  if (A==C){
    printf("%d",B);
  }
  if(B==C){
    printf("%d",A);
  }
  return 0;
}


Measured memory_bytes: 128
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>

#define FOR(i, a, b) for(int (i)=(a); (i)<(b); (i)++)
#define IFOR(i, a, b) for(int (i)=(a);(i)<=(b);(i)++)
#define RFOR(i, a, b) for(int (i)=(a);(i)>=(b);(i)--)

using namespace std;

int main() {
    int w, a, b;
    cin >> w >> a >> b;
    if (a + w < b) {
        cout << b - a - w << endl;
    }
    else if (b + w < a) {
        cout << a - b - w << endl;
    }
    else {
        cout << 0 << endl;
    }
    return 0;
}

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

int Roman_to_Arabia(char c){
	if (c == 'I')return 1;
	else if (c == 'V')return 5;
	else if (c == 'X')return 10;
	else if (c == 'L')return 50;
	else if (c == 'C')return 100;
	else if (c == 'D')return 500;
	else if (c == 'M')return 1000;
	else return 0;
}

int main(){
	string roman;
	int num;

	while (cin >> roman){
		num = 0;

		for (int i = 0; i < roman.size(); ++i){

			if (Roman_to_Arabia(roman[i]) < Roman_to_Arabia(roman[i + 1]))
				num -= Roman_to_Arabia(roman[i]);
			else
				num += Roman_to_Arabia(roman[i]);			
		}
		cout << num << endl;
	}
	return 0;
}

Measured memory_bytes: 1180
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
using ll = long long;
int main(void){
   int N;
   cin>>N;
   int sum=0;
   vector<int> D(N);
   rep(i,N){
       cin>>D[i];
       sum+=D[i];
   }
   int ans=0;
   rep(i,N-1){
       ans+=D[i]*(sum-D[i]);
       sum-=D[i];
   }
    cout<<ans<<endl;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
//using namespace __gnu_pbds;

#define LL       long long
#define PR       pair<LL, LL>
#define READ(f)  freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)

const int N = 3e5 + 5;
const int MOD = 1e9 + 7;
const double PI = 2 * acos(0.0);
//template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

int main() {
//    ios::sync_with_stdio(false);
//    cin.tie(0);
    int n, m;
    cin >> n >> m;
    int sum = 0;
    for (int i = 0; i < m; i++) {
        int x;
        cin >> x;
        sum += x;
    }
    int ans = n - sum;
    if (ans < 0) {
        ans = -1;
    }
    cout << ans << '\n';
    return 0;
}


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

using namespace std;

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

const ll INF=1LL<<31;

int main(){
    ll n,d,x;
    cin >> n >> d >> x;
    ll ans=x;
    vector<ll> a(n);
    rep(i,n){
        cin >> a[i];
        ans+=((d-1)/a[i]+1);
    }
    cout << ans << endl;
} 

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mit map<int,int>::iterator
#define sit set<int>::iterator
#define itrm(g,x) for(mit g=x.begin();g!=x.end();g++)
#define itrs(g,x) for(sit g=x.begin();g!=x.end();g++)
#define ltype int
#define rep(i,j,k) for(ltype(i)=(j);(i)<=(k);(i)++)
#define rap(i,j,k) for(ltype(i)=(j);(i)<(k);(i)++)
#define per(i,j,k) for(ltype(i)=(j);(i)>=(k);(i)--)
#define pii pair<int,int>
#define fi first
#define se second
#define mpr make_pair
#define pb push_back
#define fastio ios::sync_with_stdio(false)
const int inf=0x3f3f3f3f,mod=1000000007;
const double pi=3.1415926535897932,eps=1e-6;
int n,dis[205];int s[205][205];bool col[205],vis[205];char tmp[205];
queue<int> q;
bool check(int x){
    vis[x]=1;
    rep(i,1,n) if(s[x][i]==1){
        if(vis[i]) {
            if(col[i]==col[x]) return 0;
            continue;
        }
        else {
            col[i]=col[x]^1;
            if(!check(i)) return 0;
        }
    }
    return 1;
}
int main()
{
    scanf("%d",&n);
    rep(i,1,n){
        scanf("%s",tmp+1);
        rep(j,1,n) if(tmp[j]=='1') s[i][j]=1;else s[i][j]=inf;
    }
    if(!check(1)) {puts("-1");return 0;}
    rep(k,1,n)
    rep(i,1,n)
    rep(j,1,n) s[i][j]=min(s[i][j],s[i][k]+s[k][j]);
    int ans=0;
    rep(i,1,n) rep(j,1,n) if(s[i][j]!=inf&&i!=j) ans=max(ans,s[i][j]);
    printf("%d",ans+1);
    return 0;
}

Measured memory_bytes: 384
process.stdin.resume();
process.stdin.setEncoding('utf8');
 
var lines = [];
var reader = require('readline').createInterface({
    input: process.stdin,
    output: process.stdout
});
reader.on('line', (line) => {
    // ここで入力を処理する
    lines.push(line);
});
var half_ary = (ary)=>{
 // console.log(ary)
  var ct = 0;
  for(var i in ary){
    if((ary[i] % 2) != 0){
      ++ct
    }
      }
 // console.log(ct)
    if(ct == 0){
      var b = []
      for(var j in ary){
        b.push(1*ary[j]/2)
      }      
      return b
    }else{
      return false;
    }

}
reader.on('close', () => {
  var a = lines[1].split(" ");
  //console.log(a)
  var cnt = 0;
  var cnt_fn = (ary) =>{
    var c = half_ary(ary)
    if(c){
      ++cnt
      cnt_fn(c)
    }else{
      console.log(cnt)
    }
    
  }

    cnt_fn(a)
  

 // console.log(cnt)

//console.log(1*lines[0]+1*lines[1].split(' ')[0]+1*lines[1].split(' ')[1]+" "+lines[2])
});

Measured memory_bytes: 7628
#include<bits/stdc++.h>
using namespace std;
int main () {
  int N, M;
  cin >> N >> M;
  vector<int>A(N);
  int sum = 0;
  for (int i = 0; i < N; i ++) {
    cin >> A[i];
    sum += A[i];
  }
  sort(A.begin(), A.end());
  int k = A[N - M] * M * 4;
  cout << (k < sum ? "No" : "Yes") << endl;
}


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

using namespace std;

const int mod = 1e9 + 7;
const int N = 2e5 + 4;

long long pf[N], sf[N];

int main() {
    int n, k;
    cin >> n >> k;
    for (int i = 1; i <= n; i++) {
        pf[i] = pf[i - 1] + i;
    }
    for (int i = n; i >= 0; i--) {
        sf[i] = sf[i + 1] + i;
    }
    int ans = 0;
    for (int i = k; i <= n + 1; i++) {
        long long mn = pf[i - 1], mx = sf[n - i + 1];
        int ret = (mx - mn + 1) % mod;
        ans = (ans + ret) % mod;
    }
    cout << ans << endl;
}


Measured memory_bytes: 6772
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<ll, ll>;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }
struct FastIO {FastIO() { cin.tie(0); ios::sync_with_stdio(0); }}fastiofastio;
#ifdef DEBUG_ 
#include "../program_contest_library/memo/dump.hpp"
#else
#define dump(...)
#endif
const ll INF = 1LL<<60;

int main(void) {
    ll x;
    cin >> x;

    ll ret = x/500*1000;
    x %= 500;
    ret += x/5*5;
    cout << ret << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define mkp(a, b) make_pair(a, b)
#define pb(t) push_back(t)
#define ft first
#define sc second
#define pt(num) cout << num << "\n"
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define chmax(a, b) (a<b ? a=b : 0)
#define chmin(a, b) (a>b ? a=b : 0)
#define INF 1000000000000000000
#define MOD 1000000007LL
#define MAX 101010
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef map<ll, ll> Map;



int main(void) {
    ll a, b, k;
    cin >> a >> b >> k;
    ll cnt=0;
    ll i;
    for(i=min(a, b); i>=1; i--) {
        if(a%i==0 && b%i==0) {
            cnt++;
        }
        if(cnt==k) {
            pt(i);
            return 0;
        }
    }
    
    
    
}





Measured memory_bytes: 256
n = int(input())
x = list(map(float,input().split()))
y = list(map(float,input().split()))
D = []
p1 = 0
p2 = 0
p3 = 0
pi = 0
pimax = 0

for i in range(n):
    p1 = p1 + abs(x[i]-y[i])
    p2 = p2 + pow(abs(x[i]-y[i]),2)
    p3 = p3 + pow(abs(x[i]-y[i]),3)
    pi = abs(x[i] - y[i])
    if pimax < pi:
        pimax = pi
D.append(p1)
D.append(pow(p2,1/2))
D.append(pow(p3,1/3))
D.append(pimax)

for i in D:
    print(i)


Measured memory_bytes: 5664
N,M=map(int,input().split())
A=list(map(int,input().split()))
pop = 1/(4*M)*sum(A)
lis = []
for i in A:
    if i>=pop:
        lis.append(i)
if len(lis)>=M:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 2940
n = int(input()) - 1
s = list(map(int, input().split()))
ans = 0
for i in range(1,(n+1)//2):
  tmp = 0
  if (n % i):
    for a,b in zip(s[n-i:i:-i],s[i::i]):
      tmp += a+b
      ans = max(ans,tmp)
  else:
    for k,(a,b) in enumerate(zip(s[n-i::-i],s[i::i]),1):
      if n <= 2*k*i:
        break
      tmp += a+b
      ans = max(ans,tmp)
print(ans)


Measured memory_bytes: 63216
//#pragma GCC optimize("O3")
//#pragma GCC target("avx2")
// 293206GT
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <unordered_set>
#include <stack>
#include <string>
#include<algorithm>
#include <random>
#include <bitset>
#include <chrono>

typedef long long ll;

using namespace std;
#define put(a) cout << (a) << '\n'
#define sqr(x) (x) * (x)
typedef pair<ll, ll> pii;
typedef long double ld;

typedef pair<ld, ld> pld;
#define rep(x, y, a) for (int x = (y); x < (int)(a); ++x)
#define all(a) a.begin(), a.end()
#define chkmax(a, b) a = max(a, (b))
#define chkmin(a, b) a = min(a, (b))
#define prev asasdasd
#define next aasdasda
#define left asdasdasdasd
#define right asnabsdkasdl
#define rank asdasdknlasd
#define move asdasdas

typedef vector<ll> vi;
typedef vector<pii> vpii;
namespace IO {
    template<class A, class B>
    ostream &operator<<(ostream &out, pair<A, B> &a) {
        out << a.first << " " << a.second;
        return out;
    }

    template<class A, class B>
    ostream &operator<<(ostream &out, vector<pair<A, B>> &a) {
        for (pair<A, B> x: a)
            out << x.first << " " << x.second << '\n';
    }

    template<class A>
    ostream &operator<<(ostream &out, vector<A> &a) {
        for (A x: a) out << x << ' ';
        return out;
    }

    template<class A, class B>
    istream &operator>>(istream &in, pair<A, B> &a) {
        in >> a.first >> a.second;
        return in;
    }

    template<class A>
    istream &operator>>(istream &in, vector<A> &a) {
        for (A &x: a) in >> x;
        return in;
    }
}
using namespace IO;

void solve() {
    string s;
    cin >> s;
    int n = s.size();
    int res = 0;
    const int K = 2019;
    vi mods(K, 0);
    int ans = 0;
    rep(i, 0, n) {
        vi new_mods(K, 0);
        rep(j, 0, K) {
            new_mods[(j * 10 + s[i]-'0') % K] += mods[j];
        }
        ++new_mods[s[i] - '0'];
        mods = new_mods;
        ans += mods[0];
    }
    put(ans);
}


signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout.precision(30);
//    freopen("input.txt", "r", stdin);
    int t = 1;
//    cin >> t;
    while (t--) solve();
}


Measured memory_bytes: 3772
#include<bits/stdc++.h>
using namespace std;
long long n,m,t;
int main(){
	scanf("%lld",&n);
	m=sqrt(n);
	if(m*m==n){
		cout<<2*m-2<<endl;
		return 0;
	}else{
		for(int i=m;i>=1;i--){
			t=n/i;
			if(t*i==n){
				cout<<i+t-2<<endl;
				break;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#include<stdio.h>
#define debug(x) cout << '>' << #x << ':' << x << endl;

#define nitro ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
const int mod = 1e9+7;
using namespace std;
using ll = long long int;
const ll invmod = 998244353; 

ll fastpow(ll base, ll exp, ll mod)
{
	ll ans = 1ll;
	while(exp > 0)
	{
		if(exp & 1)
		{
			ans = ((ans%mod) * (base%mod)%mod);
		}
		exp /= 2;
		base = ((base%mod) * (base%mod)%mod);
	}
	return ans;
}

int main()
{
	

	//freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
	//clock_t time_req;time_req = clock(); 
	string s, k;
	cin >> s >> k;
	bool flag = true;
	for(int i = 0; i < s.size(); i++)
	{
		if(s[i] != k[i]) flag = false;
	}
	if(flag) cout << "Yes" << '\n';
	else cout << "No" << '\n';

	//time_req = clock()- time_req;cout << "Time Complexity:"<< \n'<<(float)time_req/CLOCKS_PER_SEC << " seconds" << endl; 
	return 0;
 }

  	

Measured memory_bytes: 3628
#include<iostream>
#include<queue>
#include<map>
#define LEN 100
#define BASE 25

using namespace std;

int maps[LEN][LEN];
int off[LEN][LEN];

//int checker[4];
//int ncheck[4];

map<int, int> points[LEN];

class State {
public:
	char where;
	int enemy;
	int budget;
	//int check[4];
	State() {}
	//	State() {check[0]=0;check[1]=0;check[2]=0;check[3]=0;}
	State(char w, int e, int b ) {
		where = w;
		enemy = e;
		budget = b; 
		/*
		check[0] = ncheck[0];
		check[1] = ncheck[1];
		check[2] = ncheck[2];
		check[3] = ncheck[3];
		*/
	}
};


inline bool operator< ( const State& a, const State& b) {
	if( a.enemy == b.enemy )
		return a.budget > b.budget;
	return a.enemy < b.enemy;
}

inline bool operator> ( const State& a, const State& b) {
	if ( a.enemy == b.enemy )
		return a.budget < b.budget;
	return a.enemy > b.enemy;
}

priority_queue<State, vector<State>, greater<State> > status;
/*
inline void copy ( State now ) {
	checker[0] = now.check[0];
	checker[1] = now.check[1];
	checker[2] = now.check[2];
	checker[3] = now.check[3];
}

inline void ncopy ( ) {
	ncheck[0] = checker[0];
	ncheck[1] = checker[1];
	ncheck[2] = checker[2];
	ncheck[3] = checker[3];
}

inline bool check ( int i ) {
	return 0 == ((1<<(i%25)) & checker[i/BASE]);
}

inline void add ( int i ) {
	ncheck[i/BASE] = ((1<<(i%25)) | checker[i/BASE]);
}
*/
inline void insert ( int i, int e, int b ) {
	
	map<int,int>::iterator itr = points[i].find(e);
	if ( itr == points[i].end() ) {
		points[i][e] = b;
		status.push(State(i,e,b));
	} else if ( (*itr).second < b ) {
		(*itr).second = b;
		status.push(State(i,e,b));
		int min = b;
		while ( itr != points[i].end() ) {
			if ( (*itr).second > min ) {
				min = (*itr).second;
			} else if ( (*itr).second <= min ) {
				(*itr).second = min;
			}
			itr++;
		}
	}
}

int main () {


	while ( true ) {
		int n,m,l;
		cin >> n >> m >> l;

		if ( n == 0 )
			break;

		for ( int i=0; i<n; i++ ) {
			for ( int j=0; j<n; j++ ) {
				maps[i][j] = -1;
				off[i][j] = 0;
			}
			points[i].clear();
		}

		for ( int i=0; i<m; i++ ) {
			int a,b,d,e;
			cin >> a >> b >> d >> e;

			maps[a-1][b-1] = maps[b-1][a-1] = d;
			off[a-1][b-1] = off[b-1][a-1] = e;
		}
	/*
		for ( int i=0; i<4; i++ ) {
			ncheck[i] = 0;
			checker[i] = 0;
		}
	*/
		priority_queue<State, vector<State>, greater<State> > empty;
		status = empty;

		//ncheck[0] = 1;
		status.push(State(0,0,l));
		int count = 0;
		while(!status.empty()) {
			State now = status.top();
			status.pop();
			if ( now.where == n-1 ) {
				cout << now.enemy << endl;
				break;
			}

			//copy(now);

			for ( int i=0; i<n; i++ ) {
				if ( maps[now.where][i] > 0 ) {
				/*
					if ( check( i ) ) {
						ncopy();
						add(i);
						*/
						int e, b;
						if ( off[now.where][i] == 0 ) {
							e = now.enemy;
							b = now.budget;
							insert(i,e,b);
						} else {
							if ( now.budget - maps[now.where][i] >= 0 ) {
								e = now.enemy;
								b = now.budget - maps[now.where][i];
								insert(i,e,b);
							}
							e = now.enemy + off[now.where][i];
							b = now.budget;
							insert(i,e,b);
						}
//					}
				}
			}
		}
	}
}

		

Measured memory_bytes: 31000
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#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))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0};

const ll INF = 1LL << 50;

bool chk(string s) {
  ll n = (ll)s.size();
  ll n2 = n / 2;
  bool ret = true;
  rep(i, n2) {
    if(s[i] != s[n-1-i]){
      ret = false;
      break;
    }
  }
  return ret;
}

int main() {
  double l;
  cin >> l;
  double ans = (l / 3) * (l / 3) * (l / 3);
  printf("%.15f\n", ans);
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
//#include <atcoder/all>
#define ll long long int
#define vec vector<ll>
#define mat vector<vector<ll>>

using namespace std;
//using namespace atcoder;

const ll mod=1000000007;
const ll inf=LONG_LONG_MAX;
ll dx4[4]={1,0,-1,0};
ll dy4[4]={0,-1,0,1};
ll dx8[8]={1,0,-1,1,-1,1,0,-1};
ll dy8[8]={1,1,1,0,0,-1,-1,-1};

ll powmod(ll a,ll n,ll m) {
    if(n == 0)
        return 1;

    if(n % 2 ==0){
        ll r = powmod(a,n/2,m);
        return r*r % m;
    }

    return a*powmod(a,n-1,m)%m;
}

ll factmod(ll a,ll b,ll m) {
  if(a<b)return 0;
  ll s=1;
  while(a>=b){
    s = s*a % m;
    a -= 1;
  }
  return s;
}

ll modinv(ll a, ll m) {
  ll b = m, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    a -= t * b; swap(a, b);
    u -= t * v; swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}

ll combmod(ll a,ll b,ll m){
  if(b==0)return 1;
  ll c=factmod(a,a-b+1,m);
  ll d=modinv(factmod(b,1,m),m);
  ll e=(c*d)%m;
  return e;
}

void modsum(ll &a,ll b,ll m){
  a+=b;
  a%=m;
}

void modsub(ll &a,ll b,ll m){
  a-=b;
  a+=m;
  a%=m;
}

void modmul(ll &a,ll b,ll m){
  a*=b;
  a%=m;
}

void modquo(ll &a,ll b,ll m){
  a*=modinv(b,m);
  a%=m;
}

int main(){

  ll n,k;
  cin >> n >> k;

  ll r=1;
  while(r*r<=n){
    r++;
  }
  r--;
  
  mat dp1(k+1,vec(r+1,0));//k番目がi(1<=i<=sqrt(n))なものの個数。nが平方数のときは1<=i<=sqrt(n)-1
  mat dp2(k+1,vec(r+1,0));//k番目がf(i)の元なものの個数。ここでf(i)とは、n/j=iとなるようなjの集合
  
  //cout << 5 << endl;
  
  vec a(r+1);//f(i)の大きさ
  ll b=n;
  for(ll i=1;i<=r;i++){
    ll right,l,h;
    right=b;
    l=r;
    while(abs(right-l)>1){
      h=(right+l)/2;
      if(n/h<=i)right=h;
      else l=h;
      //cout << right << " " << l << endl;
    }
    a[i]=b-right+1;
    b=right-1;
  }

  if(n/r==r)a[r]--;

  for(ll i=1;i<=r;i++){
    if(i<=r)dp1[1][i]=1;
    dp2[1][i]=a[i];
  }

  for(ll i=1;i<k;i++){
    vec s1(r+1),s2(r+1);
    for(ll j=0;j<r;j++)s1[j+1]=(s1[j]+dp1[i][j+1])%mod;
    for(ll j=0;j<r;j++)s2[j+1]=(s2[j]+dp2[i][j+1])%mod;
    for(ll j=1;j<=r;j++){
      dp1[i+1][j]=(s1[r]+s2[r]-s2[j-1]+2*mod)%mod;
    }
    for(ll j=1;j<=r;j++){
      dp2[i+1][j]=(s1[j])*a[j]%mod;
    }
  }

  ll ans=0;
  for(ll i=1;i<=r;i++){
    if(i<=r)modsum(ans,dp1[k][i],mod);
    modsum(ans,dp2[k][i],mod);
  }

  cout << ans << endl;
  // for(ll i=1;i<=r;i++)cout << dp1[1][i] << endl;
  // for(ll i=1;i<=r;i++)cout << dp2[1][i] << endl;

  //for(ll i=1;i<=r;i++)cout << a[i] << endl;

  return 0;
}

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

#define ll long long
#define tc(t) int t;cin >> t; while(t--)
#define pb push_back
#define fi first
#define se second
#define debug1(x) cerr << #x << " = " << x << '\n';
#define debug2(x, y) cerr << #x << " = " << x << "   " << #y << " = " << y << "\n";
#define _ ios_base::sync_with_stdio(0);cin.tie(NULL);

vector<ll> v;

void bfs(ll x, ll num)
{
	// Create a queue and enqueue 'i' to it
	queue<ll> q;
	q.push(num);

	// Do BFS starting from i
	while (!q.empty()) {
		num = q.front();
		q.pop();

		if (num <= x) {
			//cout << num << " ";
			v.pb(num);
			ll last_dig = num % 10;

			// If last digit is 0, append next digit only
			if (last_dig == 0) {
				q.push((num * 10) + (last_dig + 1));
				q.push((num * 10) + (last_dig ));
			}

			// If last digit is 9, append previous digit only
			else if (last_dig == 9) {
				q.push((num * 10) + (last_dig - 1));
				q.push((num * 10) + (last_dig ));
			}

			// If last digit is neighter 0 nor 9, append both
			// previous and next digits
			else {
				q.push((num * 10) + (last_dig - 1));
				q.push((num * 10) + (last_dig + 1));
				q.push((num * 10) + (last_dig ));
			}
		}
	}
}

// Prints all jumping numbers smaller than or equal to
// a positive number x
void printJumping(ll x)
{

	for (ll i = 1; i <= 9 && i <= x; i++)
		bfs(x, i);
}

void solve() {
    ll k;
    cin >> k;
    printJumping(3234566669LL);
    k--;
    sort(v.begin(), v.end());

    cout << v[k];
}

int main() {_
    int t = 1;
    //cin >> t;
    // Please remember to uncomment for taking test cases
    for(int i = 1; i<=t; i++) {
        solve();
    }
    return 0;
}


Measured memory_bytes: 1636
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  vector<int> a(n), b(n), c(n-1);
  for(int i; i < n; i++) cin >> a.at(i);
  for(int i; i < n; i++) cin >> b.at(i);
  for(int i; i < n-1; i++) cin >> c.at(i);
  int ans;
  for(int i; i < n-1; i++){
    ans += b.at(a.at(i)-1);
    if(a.at(i+1) == a.at(i)+1) ans += c.at(a.at(i)-1);
  }
  ans += b.at(a.at(n-1)-1);
  cout << ans << endl;
}

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  int r, s, p;
  cin >> r >> s >> p;
  auto Point = [&](char c) {
    if (c == 'r') return r;
    if (c == 'p') return p;
    if (c == 's') return s;
  };
  string ss;
  cin >> ss;
  auto Win = [&](char c) {
    if (c == 'r') return 'p';
    if (c == 'p') return 's';
    if (c == 's') return 'r';
  };
  string t;
  for (int i = 0; i < n; i++) {
    t += Win(ss[i]);
  }
  int ans = 0;
  for (int i = 0; i < k; i++) {
    int cnt = 0;
    for (int j = i; j < n; j += k) {
      if (j == i) {
        cnt = 1;
      } else {
        if (t[j] == t[j - k]) {
          ++cnt;
        } else {
          cnt = 1;
        }
      }
      if (cnt % 2 == 1) {
        ans += Point(t[j]);
      }
    }
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<functional>
#include<map>
#include<unordered_set>
using namespace std;
//int p = 998244353;
int p = 1000000007;
#define int long long
#define vel vector<long long>
#define vvel vector<vel>
#define rep(i,n) for(int i=0;i<n;i++)
#define sor(v) sort(v.begin(),v.end())
#define mmax(a,b) a=max(a,b)
#define mmin(a,b) a=min(a,b)
#define mkp make_pair
#define pin pair<int,int>
#define qin pair<int,pin>
#define V vector
#define Endl endl
#define veb vector<bool>
#define rev(s) reverse(s.begin(),s.end())
int max_kai = 150000;
vel kai(max_kai, 1);
vel inv_kai;
int rui(int a, int n) {
	if (n == 0) { return 1; }
	int x = rui(a, n / 2);
	x *= x; x %= p;
	if (n % 2 == 1) { x *= a; x %= p; }
	return x;
}
int inv(int a) { return rui(a, p - 2); }
void make_kai() {
	for (int i = 1; i < max_kai; i++) { kai[i] = kai[i - 1] * i; kai[i] %= p; }
	inv_kai = kai;
	rep(i, max_kai) { inv_kai[i] = inv(kai[i]); }
}
int nCr(int n, int r) {
	int a = kai[n] * inv_kai[r]; a %= p;
	a *= inv_kai[n - r]; a %= p;
	return a;
}
vel pa;
int root(int x) {
	if (pa[x] == -1) { return x; }
	int ans = root(pa[x]); pa[x] = ans;
	return ans;
}
void marge(int x, int y) {
	x = root(x);
	y = root(y);
	if (x != y) {pa[x] = y;}
}
#define lower(h,val) lower_bound(h.begin(),h.end(),val)-h.begin()
#define upper(h,val) upper_bound(h.begin(),h.end(),val)-h.begin()
int num_lp(int a, vel &nex) {
	unordered_set<int> se;
	int ans = 0;
	while (true) {
		if (se.find(a) != se.end()) {
			break;
		}
		se.insert(a);
		a = nex[a];
		ans++;
	}
	return ans;
}
int find_cr(int a, vel &nex) {
	unordered_set<int> se;
	while (true) {
		if (se.find(a) != se.end()) {break;}
		se.insert(a);
		a = nex[a];
	}
	return num_lp(a, nex);
}
int inf = 2000000000;
vvel dp;
int solve(vvel &sum, int i, int j, bool is_f) {
	int h = sum.size(); h--;
	int w = sum[0].size();
	if (i == h || j == w) { return 0; }
	if (dp[i][j] == inf) {
		int ans1 = solve(sum, i + 1, j, !is_f);
		int ans2 = solve(sum, i, j + 1, !is_f);
		ans2 += sum[i][j];
		if (is_f) {
			dp[i][j] = min(ans1, ans2);
		}
		else {
			dp[i][j] = max(ans1, ans2);
		}
	}
	return dp[i][j];
}
int rui10(int a) {
	if (a == 0) { return 1; }
	return 10 * rui10(a - 1);
}
int gcd(int a, int b) {
	if (a < b) { swap(a, b); }
	if (b == 0) { return a; }
	return gcd(b, a%b);
}
vel mul(vel &a, vel &b) {
	int n = a.size();
	vel c(n,-1);
	rep(i, n) {
		rep(j, n) {
			if (a[i] >= 0 && b[j] >= 0) {
				mmax(c[(i + j) % n], a[i] + b[j]);
			}
		}
	}
	return c;
}
vel rui(vel &a, int n) {
	if (n == 1) { return a; }
	vel b = rui(a, n / 2);
	b = mul(b, b);
	if (n % 2 == 1) {
		b = mul(b, a);
	}
	return b;
}
signed main(){
	vel v = { 1,5,10,50,100,500 };
	int sum = 0;
	rep(i, 6) { int x; cin >> x; sum += x * v[i]; }
	if (sum >= 1000) { cout << 1 << endl; }
	else { cout << 0 << endl; }
	return 0;
}


Measured memory_bytes: 3724
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<stack>
#include<cstdlib> 
using namespace std;
string a;
int main(){
	string s;
	cin>>s;
	for(int i=0;i<s.size();i++){
		if(i%2==0){
			cout<<s[i];
		}
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 512
import numpy as np
N,K = (int(x) for x in input().split())
p1 = np.array(list(map(int, input().split())))
s1 = p1.cumsum()
s2 = np.append(0, s1)
p2 = np.array([(s2[i+K] - s2[i]) for i in range(N-K+1)])
max = np.amax(p2)
print((max+K) / 2)

Measured memory_bytes: 33932
#include <cstdio>
#include <algorithm>

using  namespace std;

int main()
{
	int n,k;
	scanf("%d %d",&n,&k);

	int h[n];
	for(int i=0;i<n;i++) scanf("%d",&h[i]);

	sort(h,h+n);

	int ans=1000000000;
	for(int i=0;i<n-k+1;i++){
		if(h[i+k-1]-h[i]<ans) ans=h[i+k-1]-h[i];
	}

	printf("%d\n",ans);

	return 0;
}


Measured memory_bytes: 512
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;
import java.util.Set;

public class Main {

    public static final int MOD = 1000000007;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        long k = Long.parseLong(sc.next());
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = Integer.parseInt(sc.next()) - 1;
        }
        Set<Integer> set = new HashSet<>();
        int idx = 0;
        int loopIdx = 0;
        List<Integer> list = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            if (set.contains(idx)) {
                loopIdx = list.indexOf(idx);
                break;
            } else {
                set.add(idx);
                list.add(idx);
                idx = a[idx];
            }
        }
        if (list.size() > k) {
            System.out.println(list.get((int)k) + 1);
        } else {
            int ans = 0;
            ans = (int)((k - loopIdx) % (list.size() - loopIdx));
            System.out.println(list.get(loopIdx + ans) + 1);
        }
    }
}

Measured memory_bytes: 73960
N=int(input()) # 足場の数
H=list(map(int,input().split(" "))) # 足場の高さ
C=[0 for _ in range(N)] # 各足場までの最小コスト

for i in range(1,N):
    if i==1: # 2つ目のは1つ目から移るしかない
        C[1]=C[0]+abs(H[1]-H[0])
    else: # 3つ目以降
        C[i]=min(C[i-1]+abs(H[i]-H[i-1]),C[i-2]+abs(H[i]-H[i-2]))

print(C[-1]) # 最後の足場に行く最小コスト

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

int combination(int);

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n, m;
	cin >> n >> m;
	cout << combination(n) + combination(m) << "\n";
}

int combination(int k) {
	if (k == 0 || k == 1) {
		return 0;
	}
	else if (k >= 2) {
		return k * (k - 1) / 2;
	}
}


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

int main() {
  int n,m,l,sum=0, flag=1;
  cin>>n>>m;
  rep(i,n){
    cin>>l;
    sum+=l;
    if(sum>m)
      break;
    else
      flag++;
  }
  
  cout<<flag<<endl;
    
  
  
}

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

using namespace std;

int main(){
	int n=0;
	char a[8],b[8];
	int A[8],B[8];

	int ans1=0,ans2=0,sum=0;

	cin >> n;

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

		for(int j=0;j<8;j++){
			A[j] = static_cast<int>(a[j]);
		}	

		sort(A,A+8);

		for(int j=0;j<8;j++){
			B[j] = A[7-j];
		}

		for(int j=0;j<8;j++){
			a[j] = static_cast<char>(A[j]);
			b[j] = static_cast<char>(B[j]);
		}	

		ans1 = atoi(b);
		ans2 = atoi(a);
		sum = ans1-ans2;

		cout << sum << endl;

	}

	return 0;			
	}

Measured memory_bytes: 1184