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

using namespace std;

typedef double D;
typedef long long int LL;

#define st first
#define nd second
#define pb push_back
#define PLL pair <LL, LL>
#define PII pair <int, int>

const int N = 1e6 + 7;
const int MX = 1e9 + 7;
const LL INF = 1e18 + 9LL;

int n;
int tab[N];
int help[N];

int main(){
	scanf("%d", &n);
	for(int i = 1; i <= n; ++i)
		scanf("%d", &tab[i]),
		help[i] = tab[i] - i;
	
	sort(help + 1, help + n + 1);
	int b = help[(n + 1) / 2];
	
	LL res = 0LL;
	for(int i = 1; i <= n; ++i)
		res += abs(tab[i] - i - b);
	printf("%lld\n", res);
	return 0;
}

Measured memory_bytes: 5120
#include <stdio.h>
#include <stdlib.h>

int main(void){
  int n, place_sa, x, y;
  int yes_flag = 1;

  scanf("%d", &n);
  
  int zahyou[3*(n + 1)];
  
  for(int i = 0; i < 3; i++){
    zahyou[i] = 0;
  }

  for(int i = 1; i <= n; i++){
    scanf("%d %d %d", &zahyou[3*i+0], &zahyou[3*i+1], &zahyou[3*i+2]);
  }
  for(int i = n; i > 0; i--){
    x = zahyou[3*i+1] - zahyou[3*(i - 1)+1];
    place_sa = zahyou[3*i+0] - zahyou[3*(i - 1)+0];
    if(x < 0) {
        x = -x;
        }
    y = zahyou[3*i+2] - zahyou[3*(i - 1)+2];

    if(y < 0){ 
        y = -y;
        }
    if((place_sa % 2) != ((x + y) % 2) || (x + y) > place_sa){
      yes_flag = 0;
      break;
    }
  }
  if(yes_flag == 1){
    printf("Yes\n");
  }else{
    printf("No\n");
  }
  return 0;
}


Measured memory_bytes: 1280
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int T = sc.nextInt();

		int[] A = new int[N];

		for (int i = 0; i < N; ++i)
			A[i] = sc.nextInt();

		int maxDiff = 0;
		int min = A[0];

		for (int i = 0; i < N; ++i) {
			if (min > A[i])
				min = A[i];
			maxDiff = Math.max(A[i] - min, maxDiff);
		}

		int ans = 0;
		min = A[0];
		for (int i = 0; i < N; ++i) {
			min = Math.min(min, A[i]);
			if (maxDiff == A[i] - min) {
				++ans;
			}
		}
		System.out.println(ans);

	}
}


Measured memory_bytes: 46024
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();

        int[] a = new int[m];
        int[] b = new int[m];
        int[] c = new int[m];

        for (int i = 0; i < m; i++) {
            a[i] = sc.nextInt() - 1; // so that indices start at 0
            b[i] = sc.nextInt() - 1;
            c[i] = sc.nextInt();
        }

        int[][] dist = new int[n][n];

        // Initializing distances to be infinite (unless the two edges are equal).
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (i == j) {
                    dist[i][j] = 0;
                } else {
                    dist[i][j] = Integer.MAX_VALUE >> 1;
                }
            }
        }

        // Filling in the edges that were provided in the input data
        for (int i = 0; i < m; i++) {
            dist[a[i]][b[i]] = Math.min(dist[a[i]][b[i]], c[i]);
            dist[b[i]][a[i]] = Math.min(dist[b[i]][a[i]], c[i]);
        }

        // Dijkstra magic
        for (int k = 0; k < n; k++) {
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < n; j++) {
                    dist[i][j] = Math.min(dist[i][j], dist[i][k] + dist[k][j]);
                }
            }
        }

        // Counting edges NOT included in the shortest path
        int count = 0;
        for (int i = 0; i < m; i++) {
            if (dist[a[i]][b[i]] != c[i]) {
                count++;
            }
        }
        System.out.println(count);
    }
}


Measured memory_bytes: 26412
from collections import deque

def BFS_que_tree_2(list_tree,start1,start2,visited):
    visited[start1] = 1
    visited[start2] = -1
    q = deque([[start1,1],[start2,-1]])
    while q:
        start,color  = q.popleft()
        bfs_1step(list_tree,start,visited,q,tag=color)


def bfs_1step(list_tree,start,visited,q,tag=1):
    for node in list_tree[start]:  
        if visited[node] != 0:
            continue
        else:
            visited[node] = tag
            q.append([node,tag])
    return


n = int(input())
tr = [[] for i in range(n)]
for i in range(n-1):
    a,b = map(int,input().split())
    tr[a-1].append(b-1)
    tr[b-1].append(a-1)

visited = [0]*n
BFS_que_tree_2(tr,0,n-1,visited)
print("Fennec" if sum(visited) > 0 else "Snuke")


Measured memory_bytes: 24216
import { readFileSync } from "fs";

const read = () =>
  readFileSync(0, "utf8")
    .split("\n")
    .map((line) => line.split(" "));

const main = (input: string[][]) => {
  const [s1, s2, s3] = input[0];

  return `${s1[0]}${s2[0]}${s3[0]}`.toUpperCase();
};

console.log(main(read()));


Measured memory_bytes: 29224
S = input()
 
S1 = 10*int(S[0]) + int(S[1])
S2 = 10*int(S[2]) + int(S[3])
SepS = [S1, S2]
MM = [True,True]
 
for i in range(2):
  if SepS[i] < 1 or SepS[i] > 12:
    MM[i] = False
 
if MM[0] and MM[1]:
  print("AMBIGUOUS")
elif MM[0]:
  print("MMYY")
elif MM[1]:
  print("YYMM")
else:
  print("NA")

Measured memory_bytes: 3064
N=int(input())
A=list(map(int,input().split()))
i=0
division=1
if 0 in A:
    print(0)
else:
    for i in range(0,N):
        division=division*A[i]
        i+=1
        if division>10**18:
            print("-1")
            break
    if 0<division<=10**18:
        print(division)

Measured memory_bytes: 21476
#include<bits/stdc++.h>
#define lln long long int
#define llu unsigned lln
#define sc(n) scanf("%d",&n);
#define scl(n) scanf("%lld",&n);
#define scd(n) scanf("%lf",&n);
#define pf(res) printf("%d\n",res);
#define pfl(res) printf("%lld\n",res);
#define pfd(res) printf("%lf\n",res);
#define maxii 200005
using namespace std;
typedef pair<int,int> pii;
typedef pair<lln,lln> pll;
 vector<int> vi[maxii];
 vector<int>::iterator child;
typedef vector<lln> vl;
typedef vector<pii> vii;
typedef vector<pll> vll;


int arr[maxii];
int arr2[maxii];


int main()
{
   set<int>st;
   int a,b,c;
   cin>>a>>b>>c;
   st.insert(a);
   st.insert(b);
   st.insert(c);
   cout<<st.size();


}






Measured memory_bytes: 8288
#include<iostream>
#include<cmath>
#include<string>
#include<cstdlib>
#include<ctime>

using namespace std;

#define MODULE 1
#define RAND(min,max) (rand()%(max-min+1)+min)
#define LOG(log) cout<<#log<<" : "<<log<<endl;
#define DEBUG() {cout<<"DEBUG "<<num_debug<<endl; num_debug++;}
char num_debug = 0;

int compare_int(void* a, void* b);
class Math {
public :
	template<typename T> static T P(int n, int r) {
		T ans = 1;
		for (int i = 0; i < r; i++) {
			ans *= n - i;
		}
		return ans;
	}
public:
	template<typename T>static T C(int n, int r) {
		T nmr = 1;
		T dnm = 1;
		if (n - r < r)
			r = n - r;
		for (int i = 0; i < r; i++) {
			nmr *= n - i;
			dnm *= r - i;
		}
		return nmr / dnm;
	}
};

int main(void) {
	srand((unsigned)time(NULL));

	int a;
	scanf("%d", &a);
	//LOG(a);
	//LOG(pow(a, 2))
	printf("%d", (int)(a + pow(a, 2) + pow(a, 3)));

	return 0;
}


Measured memory_bytes: 4192
#include <bits/stdc++.h>
#define pb push_back
#define int long long
#define vi vector<int>
#define pi pair<int, int>
#define all(x) (x).begin(), (c).end()

using namespace std;

const int N = 2e5 + 5;



signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int h1, m1, h2, m2;
    cin >> h1 >> m1 >> h2 >> m2;
    int t1 = h1 * 60 + m1, t2 = h2 * 60 + m2;
    int k;
    cin >> k;
    if (t2 - t1 < k) {
        cout << 0;
        return 0;
    }
    cout << t2 - t1 - k;
    return 0;
}


Measured memory_bytes: 3656
#include <iostream>
#include <algorithm>
#include <iomanip>
using namespace std;
int main(void){
    int n, a[50];
    double s = 0;
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    sort(a, a+n);
    s = a[0];
    for(int i=1;i<n;i++){
        s = (s + a[i]) / 2;
    }
    cout << fixed << setprecision(16) << s << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    int c1=0;
    while(a>0&&c>0)
    {
        if(c1%2==0)
            c=c-b;
        else
            a=a-d;
        c1++;
    }
    if(a>0)
        cout<<"Yes";
    else
        cout<<"No";
    return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}

int main() {
    // メインプログラムここから
    ll n, m, ans;
    
    cin >> n >> m;
    
    if(n<m/2){
        ll x = m-n*2;
        ans = n + x/4;
    }else{
        ans = m/2;
    }
    
    cout << ans << endl;
    // ここまで
}

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

//input
//n m      (vertex,edge)
//a1 b1 c1 (from,to,cost)
//......
//am bm cm
//計算量O(N^3)
//zero-origin

#define rep(i,n) for(int i=0;i<(n);++i)
template<class T>void chmin(T&a,T b){if(a>b)a=b;}
typedef vector<vector<long>> graphs;
const long MAX_N = 1000;
const long INF = 1LL<<28;


void warshall_floyd(graphs&d,int n){
  rep(i,n) //経由
    rep(j,n) //開始
      rep(k,n) //終点
        chmin(d[j][k],d[j][i]+d[i][k]);
}


int main(){

  int n,m,r;
  cin>>n>>m>>r;
  vector<long> a(r);
  graphs d(n,vector<long>(n,INF));
  rep(i,r)cin>>a[i],a[i]--;
  rep(i,m){
    long A,B,C;
    cin>>A>>B>>C;
    A--;B--; //0-indexed
    d[A][B]=d[B][A]=C;
  }

  warshall_floyd(d,n);

  long ans=INF;
  sort(a.begin(),a.end());
  do{
    long res=0;
    rep(i,r-1)res+=d[a[i]][a[i+1]];
    chmin(ans,res);
  }while(next_permutation(a.begin(),a.end()));

  cout<<ans<<endl;

 
  return 0;
}


Measured memory_bytes: 512
from collections import deque

def solve():
    S = input()
    Q = int(input())
    length = len(S)
    reverse = False
    first,last = deque([]),deque([])
    
    for _ in range(Q):
        query = input().split()
        if len(query) == 1:
            reverse = reverse^1
            first,last = last,first
        else:
            T,F,C = query
            T = int(T)
            F = int(F)
            if F == 1:
                if reverse:
                    first.append(C)
                else:
                    first.appendleft(C)
            else:
                if reverse:
                    last.appendleft(C)
                else:
                    last.append(C)
                
            length += 1
    
    if length == 1:
        print(S)
    else:
        first = list(first)
        last = list(last)
        first = first[::-1] if reverse else first
        mid = list(S)[::-1] if reverse else list(S)
        last = last[::-1] if reverse else last
        # print(reverse,first,mid,last)
        print(''.join(first+mid+last))
        
solve()

Measured memory_bytes: 11116
#!/usr/bin/env python3

import numpy as np
from numba import njit

def main():
    k = int(input())
    print(getresult(k))

@njit("i4(i4, i4)", cache=True)
def gcd(x, y):
    if x < y:
        x, y = y, x  # x >= y
    while y > 0:
        r = x % y
        x = y
        y = r
    return x

@njit("i4(i4)", cache=True)
def getresult(k):
    res = 0
    for a in range(1, k + 1):
        for b in range(1, k + 1):
            for c in range(1, k + 1):
                res += gcd(gcd(a, b), c)
    return res

if __name__ == "__main__":
    main()


Measured memory_bytes: 106272
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.math.BigInteger;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int N = Integer.parseInt(br.readLine());
		for (int i = 0; i < N; i++) {
			String a = br.readLine();
			String b = br.readLine();
			if (a.length() > 80 || b.length() > 80) {
				System.out.println("overflow");
				continue;
			}
			BigInteger A = new BigInteger(a);
			BigInteger B = new BigInteger(b);
			BigInteger C = A.add(B);
			if (C.toString().length() > 80) {
				System.out.println("overflow");
				continue;
			}
			System.out.println(C);
		}

		if (br != null) {
			br.close();
			br = null;
		}
	}
}

Measured memory_bytes: 16940
n=int(input())
l=[0]*n
m=n**0.5
for x in range(1,int(m)):
    for y in range(1,int(m)):
        for z in range(1,int(m)):
            num=x**2+y**2+z**2+x*y+y*z+z*x
            if num<=n:
                l[num-1] += 1
for i in range(n):
    print(l[i])


Measured memory_bytes: 9564
n = int(input())
a = [int(item)-i for i,item in enumerate(input().split(),1)]
ans = 0
a.sort()

b = round((a[n//2-1]+a[n//2])/2) if n%2 == 0 else a[n//2]
for i in range(n): 
    ans += abs(a[i]-b)

print(ans)


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

int main() {
  int a,b;
  cin >> a >> b;
  cout << (((a- 2*b) > 0) ? (a- 2*b): 0 )<< endl;
}

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

using namespace std;

int main() {
	int a, b;
	cin>> a >> b;
	int c = a * b;
	if (c % 2 == 0) {
		cout << "Even" << endl;
	}
	if (c % 2 == 1) {
		cout << "Odd" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
typedef long long lint;
typedef unsigned int uint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
typedef unsigned long long ulint;
#define endl '\n'
#define fst first
#define sed second
#define pb push_back
#define mp make_pair
#define rint register int
#define SZ(x) (int((x).size()))
#define all(x) (x).begin(), (x).end()
#define reveal(x) cerr << #x << " = " << (x) << endl
#define rep(it, f, e) for (rint it = (f); it <= (e); ++it)
#define per(it, f, e) for (rint it = (f); it >= (e); --it)
#define repe(it, x) for (auto it = (x).begin(); it != (x).end(); ++it)
const int MAXN = 1e5 + 20;
const int SIZE = (1 << 18) + 5;
const lint INF = 1e18;
typedef pair<pii, int> Node;
#define L fst.fst
#define R fst.sed
#define C sed
Node path[MAXN];
struct Segment_tree {
	#define lson (root << 1)
	#define rson (root << 1 | 1)
	#define mid ((tree[root].sl + tree[root].sr) >> 1)
	struct Node {
		int sl, sr;
		lint tag, val;
		Node() {}
	}	tree[SIZE];
	inline void build(int root, int l, int r) {
		tree[root].sl = l;
		tree[root].sr = r;
		tree[root].tag = INF;
		tree[root].val = l == 1 ? 0 : INF;
		if (l == r) return;
		build(lson, l, mid);
		build(rson, mid + 1, r);
	}
	inline void pushdown(int root) {
		if (tree[root].tag != INF) {
			tree[lson].tag = min(tree[lson].tag, tree[root].tag);
			tree[lson].val = min(tree[lson].val, tree[lson].tag);
			tree[rson].tag = min(tree[rson].tag, tree[root].tag);
			tree[rson].val = min(tree[rson].val, tree[rson].tag);
			tree[root].tag = INF;
		}
	}
	inline lint query(int root, int l, int r) {
		if (l <= tree[root].sl && tree[root].sr <= r) {
			return tree[root].val;
		}
		pushdown(root);
		lint res = INF;
		if (l <= mid) res = query(lson, l, r);
		if (r > mid) res = min(res, query(rson, l, r));
		tree[root].val = min(tree[lson].val, tree[rson].val);
		return res;
	}
	inline void modify(int root, int l, int r, lint v) {
		if (l <= tree[root].sl && tree[root].sr <= r) {
			tree[root].tag = min(tree[root].tag, v);
			tree[root].val = min(tree[root].val, v);
			return;
		}
		pushdown(root);
		if (l <= mid) modify(lson, l, r, v);
		if (r > mid) modify(rson, l, r, v);
		tree[root].val = min(tree[lson].val, tree[rson].val);
	}
}	tr;
int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL), cout.tie(NULL);
	int n, m;
	cin >> n >> m;
	rep (i, 1, m) {
		cin >> path[i].L;
		cin >> path[i].R;
		cin >> path[i].C;
	}
	sort(path + 1, path + m + 1);
	tr.build(1, 1, n);
	rep (i, 1, m) {
		lint upd = tr.query(1, path[i].L, path[i].R);
		tr.modify(1, path[i].L, path[i].R, upd + path[i].C);
	}
	lint ans = tr.query(1, n, n);
	if (ans >= INF) ans = -1;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 7552
#include <iostream>
#include <cassert>
#include <climits>
#include <bitset>
#include <stack>
#include <queue>
#include <iomanip>
#include <limits>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string.h>
#include <tuple>
#include <time.h>
#include <random>

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P;

long long int INF = 3e18;
double Pi = 3.1415926535897932384626;

vector<ll> G[500005];
//vector<P> tree[500010];
priority_queue <ll> pql;
priority_queue <P> pqp;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
priority_queue <P,vector<P>,greater<P> > pqps;
//small priority queue
//top pop

int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
char dir[] = "DRUL";
//ll bit[500005];
//↓,→,↑,←


#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<(x)<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<(x);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define line cout << "----------" << endl;


ll mod = 1000000007;
ll rui(ll number1,ll number2){

    if(number2 == 0){
        return 1;
    }else{
        ll number3 = rui(number1,number2 / 2);
        number3 *= number3;
        number3 %= mod;
        if(number2%2==1){
            number3 *= number1;
            number3 %= mod;
        }
        return number3;
    }
}
ll gcd(ll number1,ll number2){

    if(number1 > number2){
        swap(number1,number2);
    }
    if(number1 == 0 || number1 == number2){
        return number2;
    }else{
        return gcd(number2 % number1,number1);
    }
}
void YES(bool condition){

    if(condition){
        p("YES");
    }else{
        p("NO");
    }
    return;
}
void Yes(bool condition){

    if(condition){
        p("Yes");
    }else{
        p("No");
    }
    return;
}
void Yay(bool condition){

    if(condition){
        p("Yay!");
    }else{
        p(":(");
    }
    return;
}

//ll fact[800005],rfact[800005];
/*
void c3_init(){
    fact[0] = rfact[0] = 1;
    for(ll i=1; i<=800000; i++){
        fact[i] = (fact[i-1]*i) % mod;
    }
	rfact[800000] = rui(fact[800000],mod - 2);
	for(ll i=800000; i>=1; i--){
	   rfact[i-1] = rfact[i] * i;
	   rfact[i-1] %= mod;
	}
	return;}
ll c3(ll n,ll r){
    return (((fact[n] * rfact[r]) % mod) * rfact[n-r]) % mod;}
*/

ll n,m,num,ans,a,b,c,d,e,g,h,w,i,j,k,q;
ll x[500005],y[500005],z[500005];
char s[500005],t[500005];
bool dame;

ll idx;
ll lookvs = 2,lookvt = 3;

void madd(ll s,ll t){
	x[idx] = s;
	y[idx++] = t;
	return;
}

void msadd(){
	madd(lookvs,lookvt);
	lookvt ++;
	if(lookvt > n){
		lookvs ++;
		lookvt = lookvs + 1;
	}
	return;
}

int main(){
	cin >> n >> k;
	if(k > (n - 1) * (n - 2) / 2){
		p(-1);
		return 0;
	}else{
		for(i=2;i<=n;i++){
			madd(1,i);
		}
		for(i=0;i<(n-1)*(n-2)/2-k;i++){
			msadd();
		}
	}
	p(idx);
	for(i=0;i<idx;i++){
		pe(x[i]);p(y[i]);
	}
	return 0;
}


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

int main() {
  string T;
  cin >> T;

  for (int i = 0; i < T.length(); i++) {
    if (T[i] == '?')
      T[i] = 'D';
  }
  cout << T << endl;

  return 0;
}



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

using namespace std;

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

    int a, b;
    cin >> a >> b;
    if (a < b) {
        cout << "0\n";
    } else {
        cout << "10\n";
    }
    cout.flush();
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
#include <set>
#include <math.h>
#define rep(i,a,b) for(int i=(a); i<(b); ++i)
typedef long long ll;
using namespace std;

int main() {
    int64_t a,b,n;
    cin >> a >> b >> n;
    int64_t m=0;
    if (n>=b-1) m=a*(b-1)/b;
    else m=a*n/b-a*(n/b);  
    cout << m << endl;
}

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

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		if(N > K){
			N -= ((N - K) + K - 1) / K * K;
		}
		Console.WriteLine(Math.Min(N, K - N));
		
		
		
		
		
	}
	long N,K;
	public Sol(){
		var d = rla();
		N = d[0]; K = d[1];
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


Measured memory_bytes: 11092
k = int(input())
a,b = input().split()
n = int(b)-int(a)+1
result = 0
for i in range(n):
    num = int(a) + i
    if num % k == 0:
        result = 1
if result == 0:
  print("NG")
elif result == 1:
  print("OK")

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

#define ll long long

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

	int n;
	cin >> n;
	vector<ll> a(n+1);
	for(int i=1; i<=n; i++)
		cin >> a[i];

	ll dpX[n+1][n+1], dpY[n+1][n+1];

	for(int i=1; i<=n; i++){
		dpX[i][i] = a[i];
		dpY[i][i] = -a[i];
	}

	for(int l=2; l<=n; l++)
		for(int i=1; i<=n-l+1; i++){
			int j = i+l-1;
			dpX[i][j] = max(dpY[i][j-1]+a[j], dpY[i+1][j]+a[i]);
			dpY[i][j] = min(dpX[i][j-1]-a[j], dpX[i+1][j]-a[i]);
		}

	cout << dpX[1][n] << endl;

	return 0;
}

Measured memory_bytes: 140160
#include <bits/stdc++.h>
#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define mod 1000000007
// #define mod 998244353
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s;
	cin >> s;
	int n = s.length();
	ll ans = 0;
	for (int i = n - 1; i >= 0; i--)
	{
		ll power = 1;
		for (int j = 1; j <= n - i; j++)
		{
			ll temp = (1 << max(0, n - i - j - 1));
			temp *= (1 << i);
			temp *= (s[i] - '0');
			temp *= power;
			ans += temp;
			// cout << temp << endl;
			power *= 10;
		}
		// cout << endl;
	}
	cout << ans << endl;
	return 0;
}

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

int main(){
  string s;
  cin >> s;
  string ans="No";
  rep(i,s.size()-1){
    if(s.at(i)!=s.at(i+1)) ans="Yes";
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
import java.util.*;
 
public class Main {
    public static void main(String args[]) {
       //値の取得
       Scanner sc = new Scanner(System.in);
       int[] time = new int[5];
       for(int i = 0; i < 5; ++i){
           time[i] = sc.nextInt();
       }
       
       int dish[] = new int[5];
       
       for(int i = 0; i < 5; ++i){
           if(time[i]%10==0){
               dish[i] = (time[i]/10)*10;
           }else{
               dish[i] = (time[i]/10)*10 +10;
           }
       }
       
       int max = 0;
       int total = 0; 
       for(int i = 0; i < 5; ++i) {
           if(Math.abs(dish[i] - time[i]) > max) {
               max = Math.abs(dish[i] - time[i]); 
           }
           
           total += dish[i];
       }
       System.out.println(total - max);
    }
}

Measured memory_bytes: 35712
#pragma GCC optimize("O3")

#include "bits/stdc++.h"

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for(int i = 0; i < (a); ++i)
#define pb push_back
#define sz size
#define f first
#define s second

ll mod=1e9+7;

vector<ll> g[100001];
ll vis[100001];
ll cnt=1;

void dfs(ll st, ll k, ll val)
{
    // if(st==5)
    // {
        // cout << "val: " << val << endl;
    // }
    vis[st]=1;
    cnt=(cnt*val)%mod;
    if(st==1)
    {
        F0R(i,g[st].size())
        {
            if(!vis[g[st][i]])
            {
                dfs(g[st][i],k,k-(i+1));
            }
        }
    }
    else
    {
        int ex=0;
        F0R(i,g[st].size())
        {
            if(!vis[g[st][i]])
            {
                dfs(g[st][i],k,k-(i+2)+ex);
            }
            else
                ex++;
        }
    }
}

int main()
{
    // freopen("input.txt", "r", stdin);
   //  freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll n, k;
    cin >> n >> k;
    ll first, second;
    FOR(i,1,n)
    {
        cin >> first >> second;
        g[first].pb(second);
        g[second].pb(first);
    }
    FOR(i,1,n+1)
    {
        sort(g[i].begin(),g[i].end());
    }
    FOR(i,1,n+1)
        vis[i]=0;
    dfs(1,k,k);
    cout << cnt;

    return 0;
}


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

int max(int x, int y);
int min(int x, int y);
int gcd(int x, int y);

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

	int ans;

	for (int i = gcd(a, b);k > 0;i--)
	{
		if (gcd(a, b) % i == 0)
		{
			ans = i;
			k--;
		}
	}

	cout << ans;

	return 0;
}

int max(int x, int y)
{
	int max;

	if (x < y)
		max = y;
	else
		max = x;

	return max;
}

int min(int x, int y)
{
	int min;

	if (x < y)
		min = x;
	else
		min = y;

	return min;
}

int gcd(int x, int y)
{
	int m;
	int gcd = 1;

	m = min(x, y);

	for (int i = 1;i <= m; i++)
	{
		if (x%i == 0 && y%i == 0)
			gcd = i;
	}

	return gcd;
}

Measured memory_bytes: 256
#include <algorithm>
#include<stdio.h>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include<stack>
#include <queue>
#include<map>
#include <set>
#include<math.h>
using namespace std;
#define int long long
#define ll long long
#define rep(i,n) for(ll i=0;i<n;++i)
#define loop(i,m,n) for(ll i=m;i<n;++i)
#define ggr getchar(); getchar();return 0;
#define pie 3.141592653589793238462643383279
#define elif else if
#define P pair<ll,ll>
const int inf = 1000000007;
int bin(int bina) {
	int ans = 0;
	for (int i = 0; bina > 0; i++)
	{
		ans = ans + (bina % 2) * pow(10, i);
		bina = bina / 2;
	}
	return ans;
}
bool prime(int n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int kai(int x) {
	if (x == 0)return 1;
	return kai(x - 1) * x % inf;
}
int mod_pow(int x, int y, int mod) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % mod;
		}
		x = x * x % mod;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	return kai(x)* mod_pow(kai(x - y), inf - 2, inf) % inf * mod_pow(kai(y), inf - 2, inf) % inf;
}
struct union_find {
	int par[200010], size_[200010];
	void init(int x) {
		rep(i, x) { par[i] = i; size_[i] = 1; }
	}
	int find(int x) {
		if (par[x] == x)return x;
		return par[x] = find(par[x]);
	}
	void unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y)return;
		if (size_[x] < size_[y]) {
			par[x] = y;
			size_[y] += size_[x];
		}
		else {
			par[y] = x;
			size_[x] += size_[y];
		}
	}
};
struct edge { int to, cost; };
int a[100010];
signed main() {
	int n;
	cin >> n;
	rep(i, n) {
		cin >> a[i];
	}
	sort(a, a + n);
	cout << a[n / 2] - a[(n / 2) - 1] << endl;
}



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

int main(){
    int n, a[300000];
    cin >> n;
    for(int i=0;i<n;++i) cin >> a[i];
    static int cnt[300001], ccnt[300001];
    for(int i=0;i<n;++i) ++cnt[a[i]];
    for(int i=0;i<=n;++i) ++ccnt[cnt[i]];

    int64_t sum[300002] = {0}, xsum[300002] = {0};
    for(int i=1;i<=n;++i){
        sum[i] = sum[i-1] + ccnt[i];
        xsum[i]= xsum[i-1]+ (int64_t)(i)*ccnt[i];
    }
    auto len = [&](int x){
        return (xsum[x-1] + x*(sum[n]-sum[x-1])) / x;
    };

    for(int k=1;k<=n;++k){
        int ok = 0, ng = n+1;
        while(ng-ok > 1){
            int mid = (ok+ng)/2;
            if(len(mid) < k) ng = mid;
            else ok = mid;
        }
        cout << ok << endl;
    }

    return 0;
}

Measured memory_bytes: 7936
const main = (input) => {
  const lines = input.trim().split("\n");
  const [N, M] = lines[0].split(' ').map(str => parseInt(str));
  const checkList = lines.slice(1).map(line => {
    const [s, c] = line.split(' ');
    return [parseInt(s - 1), c];
  });

  // 全探索
  // for (let i = 0; i < Math.pow(10, N); i++) {
  //   const strNum = i.toString();
  //   if (strNum.length == N && checkList.every(sc => strNum[sc[0]] === sc[1])) {
  //     console.log(strNum)
  //     process.exit(0);
  //   }
  // }
  // console.log(-1);

  // 順番に埋める
  let numList = Array(N).fill(-1);
  checkList.forEach(sc => {
    sc[1] = parseInt(sc[1]);
    if (numList[sc[0]] !== -1 && numList[sc[0]] !== sc[1]) {
      console.log(-1);
      process.exit(0);
    }
    numList[sc[0]] = sc[1]
  });

  if (N === 1) {
    if (numList[0] === -1) {
      console.log(0);
    } else {
      console.log(numList[0]);
    }
  } else {
    numList = numList.map((num, i) => {
      if (i === 0) {
        if (num === 0) {
          console.log(-1);
          process.exit(0);
        }
        if (num === -1) {
          return 1;
        }
      }
      if (num === -1) {
        return 0;
      }
      return num;
    })
    console.log(numList.join(""));
  }
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 7372
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    ll X[100010], L[100010];
    rep(i,0,N) cin >> X[i] >> L[i];
    vector<lpair> lp;
    rep(i,0,N) lp.push_back({X[i], L[i]});
    sort(lp.begin(), lp.end(), [](lpair l1, lpair l2){
        return l1.first + l1.second < l2.first + l2.second;
    });
    ll cnt = 0;
    ll val = lp[0].first + lp[0].second;
    rep(i,1,N){
        if(val > lp[i].first - lp[i].second){
            cnt++;
        }else{
            val = lp[i].first + lp[i].second;
        }
    }
    ll ans = N - cnt;
    print(ans);



    

}

Measured memory_bytes: 3956
import java.io.BufferedReader;
import java.io.InputStreamReader;
 
public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line = br.readLine();
        String answer = line.substring(0,4) + " " + line.substring(4);
        System.out.println(answer);
    }
}

Measured memory_bytes: 8148
import java.util.*;

public class Main{
	private static final Scanner scan = new Scanner(System.in);

	public static void main(String[] args){

		while(scan.hasNext()){
			int year = 2004;
			int mon = scan.nextInt();
			int day = scan.nextInt();
			if(mon == 0){
				break;
			}
			Calendar cal = Calendar.getInstance();
			cal.set(2004, mon - 1, day);
			int week = cal.get(Calendar.DAY_OF_WEEK);
			String s = "";
			switch(week){
				case Calendar.SUNDAY :
					s = "Sunday";
					break;
				case Calendar.MONDAY :
					s = "Monday";
					break;
				case Calendar.TUESDAY :
					s = "Tuesday";
					break;
				case Calendar.WEDNESDAY :
					s = "Wednesday";
					break;
				case Calendar.THURSDAY :
					s = "Thursday";
					break;
				case Calendar.FRIDAY :
					s = "Friday";
					break;
				case Calendar.SATURDAY :
					s = "Saturday";
					break;
				default :
					break;
			}
			System.out.printf("%s\n", s);
		}
	}
}

Measured memory_bytes: 27212
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define frn(i,a,b) for(ll i=a;i<b;i++)
#define forn(i,a,b) for(ll i=a;i<=b;i++)
#define frt(i,a,b) for(auto it=a;it!=b;it++)
#define MP make_pair
#define F first
#define S second
#define PB push_back
#define SQ(a) (a)*(a)
#define SUM(n) ((n)*(n+1))/2
#define SqSUM(n) ((n)*(n+1)*(2*n+1))/2
#define GMSUM(a,r,n) (a*pow(r,n)-a)/(r-1)
#define ciel(x, y) (((x) / (y)) + ((x) % (y) != 0))
#define tc(tt) \
    int tt;    \
    cin >> tt; \
    for (int _tt = 0; _tt < tt; _tt++)
#define input(v,n) for(ll i = 0 ; i<n ; i++) cin>>v[i]
#define output(v,n) for(ll i = 0 ; i<n ; i++) cout<<v[i]<<" "
#define endl '\n'
#define cout_p(x, p) cout << fixed << setprecision((p)) << x << endl
#define dbg(x) cerr << #x << "is" << (x) << endl
#define leadzero(a) __builtin_clz(a)      // count leading zeroes
#define trailzero(a) __builtin_ctz(a)     // count trailing zeroes
#define bitcount(a) __builtin_popcount(a) // count set bits (add ll)
const long long int md = 998244353;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pi;
typedef vector<ll> vi;
typedef vector<vector<ll, ll> > vvi;
    // typedef bitset<5> bst;
typedef priority_queue<int, vector<int>, greater<int>> min_heap;
typedef priority_queue<int, vector<int>> max_heap;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
    indexed_set;
const ll MAX = LONG_MAX;
const ll lrg = 1000000007;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll n,m;
    cin>>n>>m;
        ll mv=max(m,n);
        frn(i,0,mv)
        {
            cout<<min(m,n);
        }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <math.h>
#include <queue>
#include <deque>
typedef long long ll;
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 int INF = 1<<30;
using namespace std;

int dp[100010];

int main(){
	int n, k;
	cin >> n >> k;
	vector<int> H(n+1);
	H[0]= 0;
	for (int i = 1; i <=n; i++) cin >> H[i];
	for (int i = 0; i < 100010; i++) dp[i] = INF;
	dp[1] = 0;
	for (int i = 2; i <= n; i++) {
		for (int j = 1; j <= k && j<i; j++) {
			chmin(dp[i],dp[i-j] + abs(H[i]-H[i-j]));
		}
	}
	cout << dp[n] << endl;
	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>

#define repd(i,a,b) for (int i=(a);i<(b);++i)
#define rep(i,n) repd(i,0,n)
#define reprd(i,a,b) for (int i=(a);i>=(b);--i)
#define repr(i,n) reprd(i,n,0)
typedef long long ll;

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

using namespace std;

const ll BIG = 1000000007LL;

int inputValue(){
    int a;
    cin >> a;
    return a;
};

template<typename T>
void inputArray(T* p, int a){
    rep(i, a){
        cin >> p[i];
    }
};

template<typename T>
void inputVector(vector<T> * p, int a){
    rep(i, a){
        T input;
        cin >> input;
        p -> push_back(input);
    }
}

template <typename T>
void output(T a, int precision = 0) {
    if(precision > 0){
        cout << setprecision(precision)  << a << "\n";
    }
    else{
        cout << a << "\n";
    }
}

const int Max = 110;
ll N;

ll solve(ll n) {
    if (n % 2 != 0) return 0;

    ll base = 2;
    ll five = 0;
    rep(i, 27) {
        base *= 5LL;
        ll count = n / base;
        five += count;
    }
    return five;
}

int main(int argc, const char * argv[]) {
    cin >> N;
    
    output(solve(N));

    return 0;
}

Measured memory_bytes: 256
//@HelloElwin20190819
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;

int main() {
	
	int n;
	double ans = 0, a[1005];

	scanf("%d", &n);
	for (int i = 0; i < n; i++) scanf("%lf",  a + i);
	
	for (int i = 0; i < n; ++i) {
		ans = ans + 1 / a[i];
	}

	printf("%lf\n", 1 / ans);

	return 0;
}

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

int main()
{
    int a, n;  cin >> n;
    double ans = 0.0;

    rep(i,n) {
        cin >> a;
        ans += 1.0 / a;
    }

    ans = 1.0 / ans;
    cout << setprecision(16) << ans << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()

int main() {
  int n;
  cin >> n;
  priority_queue<int, vi, greater<int> > que;
  rep(i, n) {
    int a;
    cin >> a;
    que.push(a);
  }
  while (que.size() >= 2) {
    int div = que.top();
    que.pop();
    // cout << div << endl;
    vi tmp;
    while (!que.empty()) {
      int x = que.top();
      que.pop();
      int rem = x % div;
      if (rem > 0) {
        tmp.push_back(rem);
      }
    }
    for (auto& a : tmp) {
      que.push(a);
    }
    que.push(div);
  }
  int ans = que.top();
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1400
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int res = 30000;
		res = Math.min(res, a+b);
		res = Math.min(res, b+c);
		res = Math.min(res, c+a);
		System.out.println(res);
	}
}


Measured memory_bytes: 21844
H, W = list(map(int,input().split()))
A = [list(input()) for _ in range(H)]
NA = []
for a in A:
    if '#' in a:
        NA.append(a)
for i in range(W):
    ydel = True
    for j in NA:
        if j[i] == '#':
            ydel = False
            break
    if not ydel:
        continue
    for j in NA:
        j[i] = 'D'
for na in NA:
    nna = []
    for i in na:
        if i != 'D':
            nna.append(i)
    print(''.join(nna))

Measured memory_bytes: 3188
//Copyright(c)2017 Mstdream
#include<bits/stdc++.h>
using namespace std;

inline void splay(int &v){
	v=0;char c=0;int p=1;
	while(c<'0' || c>'9'){if(c=='-')p=-1;c=getchar();}
	while(c>='0' && c<='9'){v=(v<<3)+(v<<1)+c-'0';c=getchar();}
	v*=p;
}
const int N=10010;
int nxt[N],fir[N],sz,to[N],dp[N],v[N],n;
bitset<5005>a[N],b[N];
void add(int x,int y){
	nxt[++sz]=fir[x],fir[x]=sz,to[sz]=y;
}
void dfs(int x){
	if(fir[x]){
		dp[x]=1<<30;
		int tot=0;a[x][0]=1;
		for(int u=fir[x];u;u=nxt[u]){
			dfs(to[u]);
			b[x]=a[x]<<v[to[u]];
			b[x]|=a[x]<<dp[to[u]];
			a[x]=b[x];
			tot+=v[to[u]]+dp[to[u]];
		}
		bool f=0;
		for(int i=v[x];i>=0;i--){
			if(a[x][i]){
				f=1;dp[x]=tot-i;
				break;
			}
		}
		if(!f)puts("IMPOSSIBLE"),exit(0);
	}
}
int main(){
	splay(n);
	for(int i=2;i<=n;i++){
		int x;splay(x);
		add(x,i);
	}
	for(int i=1;i<=n;i++){
		splay(v[i]);
	}
	dfs(1);
	puts("POSSIBLE");
}

Measured memory_bytes: 3840
/*input

*/


//assic value of ('0'-'9') is(48 - 57) and (a-z) is (97-122) and (A-Z) is(65-90) and 32 for space
#include<bits/stdc++.h>
using namespace std;
#define ll          long long
#define pb          push_back
#define pii         pair<ll int,ll int>
#define vpii        vector< pii >
#define vi          vector<ll int>
#define vs			vector< string >
#define vvi         vector< vector< ll > >
#define inf			(ll)1e18
#define all(it,a)   for(auto it=(a).begin();it!=(a).end();it++) 
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define repr(i,a,b) for(ll int i=a;i>b;i--)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define mp          make_pair
#define whatis(x)   cout << #x << " is " << x << "\n";
#define graph(n)    adj(n,vector< ll > () )
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());


int solve()
{
	ll n;cin>>n;
	map<string,ll> sg;
	vi t(n);
	rep(i,0,n)
	{
		string s;cin>>s;
		cin>>t[i];
		sg[s]=i+1;
	}
	string x;cin>>x;
	all(it,sg)
	{
		if(it->F==x)
		{
			ll ans=0;
			rep(i,it->S,n) ans+=t[i];
			cout<<ans<<"\n";
			return 0;
		}
	}
	return 0;
}

int main()
{
	auto start = chrono::high_resolution_clock::now();

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

	ll test_cases=1;
	//cin>>test_cases;
	while(test_cases--)
		solve();

	auto stop = chrono::high_resolution_clock::now();
	auto duration = chrono::duration_cast<chrono::milliseconds>(stop-start);
	// cout<<"\nduration: "<<(double)duration.count()<<" milliseconds";
}

Measured memory_bytes: 256
def main():
    n = int(input())
    b = list(map(int,input().split()))
    f = []
    res = []
    while b:
        for i in range(len(b)):
            if i+1 == b[i]:
                f.append(i)
        if f:
            tg = max(f)
        else:
            print(-1)
            return False
        res.append(tg+1)
        b.pop(tg)
        f.clear()
    
    res.reverse()
    for r in res:
        print(r)

main()

Measured memory_bytes: 3064
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>

namespace IO {
    template <typename _T>
    inline bool read(_T& x) {
        x = 0;
        _T y = 1;
        char c = getchar();
        while ((c < '0' || '9' < c) && c != EOF) {
            if (c == '-')
                y = -1;
            c = getchar();
        }
        if (c == EOF)
            return false;
        while ('0' <= c && c <= '9')
            x = x * 10 + c - '0', c = getchar();
        x *= y;
        return true;
    }

    template <typename _T>
    inline _T input() {
        _T x = 0, y = 1;
        char c = getchar();
        while ((c < '0' || '9' < c) && c != EOF) {
            if (c == '-')
                y = -1;
            c = getchar();
        }
        if (c == EOF)
            return 0;
        while ('0' <= c && c <= '9')
            x = x * 10 + c - '0', c = getchar();
        x *= y;
        return x;
    }
};  // namespace IO
using namespace IO;

namespace modular {
    const int MOD = 1000000007;

    inline int add(int x, int y) { return (x += y) >= MOD ? x -= MOD : x; }

    inline void inc(int& x, int y) { (x += y) >= MOD ? x -= MOD : 0; }

    inline int mul(int x, int y) { return 1LL * x * y % MOD; }

    inline int qpow(int x, int y) {
        int ans = 1;
        for (; y; y >>= 1, x = mul(x, x))
            if (y & 1)
                ans = mul(ans, x);
        return ans;
    }
};  // namespace modular

#define MAX_N 2000007
#define reg register
#define FIN(s) freopen(s, "r", stdin)
#define FOUT(s) freopen(s, "w", stdout)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define rep(i, l, r) for (int i = l; i <= r; ++i)
#define lep(i, l, r) for (int i = l; i < r; ++i)
#define irep(i, r, l) for (int i = r; i >= l; --i)
#define ilep(i, r, l) for (int i = r; i > l; --i)
typedef long long ll;

int N;
char s[MAX_N], t[MAX_N];
std::queue<int> q;

inline void solve() {
    int j = N, tag = 0, ans = 0, las = N + 1;
    irep(i, N, 1) {
        while (j && (s[j] != t[i] || j > i))
            j--;
        if (!j)
            return puts("-1"), void();
        if (las == j) {
            while (!q.empty() && q.front() - tag >= i)
                q.pop();
        } else {
            tag++;
            if (i != j) {
                while (!q.empty() && q.front() - tag > i)
                    q.pop();
                q.push(j + tag);
                ans = std::max(ans, (int)q.size());
            }
        }
        las = j;
    }
    printf("%d\n", ans);
}

int main() {
#ifdef LOCAL
    FIN("in");
#endif
    read(N);
    scanf("%s%s", s + 1, t + 1);
    rep(i, 1, N) if (s[i] != t[i]) {
        solve();
        return 0;
    }
    puts("0");
    return 0;
}

Measured memory_bytes: 6272
use strict;
use warnings;
use utf8;

my ($N, $M) = split /\s/, <STDIN>;
my $min_r = (10 ** 5) + 1;
my $max_l = -1;
for (1 .. $M) {
    my ($l, $r) = split /\s/, <STDIN>;
    if ($r < $min_r) {
        $min_r = $r;
    }

    if ($max_l < $l) {
        $max_l = $l;
    }
}


#printf "%s %s\n", $max_l, $min_r;
my $x = $min_r - $max_l + 1;
printf "%s\n", $x < 0 ? 0 : $x;


Measured memory_bytes: 640
#include<cstdio>
#include<iostream>
#include<cmath>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;
int main()
{
    int a, b, c, d;
    cin>>a>>b>>c>>d;
    cout<<max(a*b, c*d);


    return 0;
}


Measured memory_bytes: 256
#![allow(unused_mut)]
#![allow(non_snake_case)]
#![allow(unused_macros)]
#![allow(unused_variables)]
#![allow(unused_imports)]
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($y: expr),+) => {
        ::std::cmp::max($x, max!($($y),+))
    };
}

macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($y: expr),+) => {
        ::std::cmp::min($x, max!($($y),+))
    };
}

use std::cmp;
use std::collections::{HashSet, BinaryHeap, VecDeque};
use std::iter::FromIterator;
fn main() {
    input! {
        N: usize,
        W: usize,
        bud: [(usize, usize); N]
    }

    let mut ww = bud[0].0;
    let mut weight_list = vec![BinaryHeap::new(); 4];
    for &(w, v) in bud.iter() {
        weight_list[w-ww].push(v);
    }

    let mut values = vec![Vec::new(); 4];
    for ind in 0..4 {
        values[ind].push(0);
        for _ in 0..weight_list[ind].len() {
            let next = values[ind].last().unwrap() + weight_list[ind].pop().unwrap();
            values[ind].push(next);
        }
    }

    let mut max = 0_usize;
    for n0 in 0..cmp::min(N+1, values[0].len()) {
        for n1 in 0..cmp::min(N-n0+1, values[1].len()) {
            for n2 in 0..cmp::min(N-n0-n1+1, values[2].len()) {
                for n3 in 0..cmp::min(N-n0-n1+1, values[3].len()) {
                    if W >= n0*ww + n1*(ww+1) + n2*(ww+2) + n3*(ww+3){
                        max = cmp::max(max, 
                            values[0][n0]+values[1][n1]+values[2][n2]+values[3][n3]); 
                    }
                }
            }
        }
    }
    println!("{}", max);
}


Measured memory_bytes: 4352