akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ll long long
#define endl "\n"
#define pb push_back
#define ms(v,x) memset(v,x,sizeof(v))
#define ff first
#define ss second
#define td(v) v.begin(),v.end()
#define rep(i,a,n) for (int i=(a);i<(n);i++)
#define pii pair<int,int>
#define pll pair<ll,ll>
using namespace std;

void solve(){
	int k,a,b;
	cin >> k >> a >> b;
	int x = a % k;
	if(x==0 or a+(k - x) <= b){
		cout << "OK" << endl;
	}
	else cout << "NG" << endl;
}
int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);  
    int t=1,l=1;
   	//cin >> t;
    while(t--){
    	solve();
    }    
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define Online
#define nowtime (double)clock()/CLOCKS_PER_SEC
void tie()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
}
int main()
{
	tie();
	#ifndef Online
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
	#endif
	string s;
	cin>>s;
	if(s[s.size()-1]=='s') s+="es";
	else s+='s';
	cout<<s; 
	#ifndef Online
	fclose(stdin);
	fclose(stdout);
	#endif
	return 0;
}


Measured memory_bytes: 3652
/*

    author : s@if

*/

#include<bits/stdc++.h>
using namespace std;
#define NIL -1
#define fi first
#define sec second
#define MAX INT_MAX
#define INF 99999999
#define ll long long
#define PI acos(-1.0)
#define MOD 1000000007
#define PLL pair<ll,ll>
#define PII pair<int,int>
#define ull unsigned long long
#define triplell pair<pair<ll,ll> , ll>
#define triple pair<pair<int,int> , int>
#define For(i,n) for(int i=0;i<(int)n;i++)
#define Forn(i,a,b) for(int i=(int)a;i<=(int)b;i++)
#define forba(i,a,b) for(int i=(int)b;i>=(int)a;i--)

bool Check(int N , int pos)	{	return (bool) (N & (1<<pos));}
int Set(int N, int pos) {	return N = N | (1<<pos);}

int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};
int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};
int hr[]={-2,-2,-1,+1,+2,+2,-1,+1};
int hc[]={+1,-1,+2,+2,-1,+1,-2,-2};
int dx[]={+1,-1,+0,+0};
int dy[]={+0,+0,+1,-1};

const int MAXN = (int)1e5+9;

int main()
{
/*	freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);  */
    
    int i,j,k,l,m,n,p,q,x,y,u,v,r,tc,t;
    
    cin>>n;
    
    int a1[n+9] , a2[n+9];
    
    For(i,n)
    {
    	cin>>a1[i];
	}
	For(i,n)
	{
		cin>>a2[i];
	}
	
	int ans = 0;
	
	For(i,n)
	{
		if(a1[i]>a2[i])
		{
			ans+=a1[i]-a2[i];
		}
	}
	
	cout<<ans<<endl;
    
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static Scanner scan = new Scanner(System.in);
	public static void main(String[] args) {
		int N = scan.nextInt();
		String S = scan.next();
		StringBuffer ans = new StringBuffer();
		for (int i = 0; i < S.length(); i++) {
			char temp = S.charAt(i);
			char ansTemp;
			if (temp + N > 'Z') {
				ansTemp = (char)(temp + N - 26);
			} else {
				ansTemp = (char)(temp + N);
			}
			ans = ans.append(ansTemp);
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 21972
#include <iostream>
#include <string>
#include <math.h>
using namespace std;
 
int main()
{
  int N ;
  cin >> N ;
int a[N+1] ;
  int b[N+1] ;
for(int i=1; i<N+1; i++)  {
  cin >> a[i];
  b[i]=0 ;
}
  
for(int i=1; i<N+1; i++){
  
while( ((a[i])%2)==0 ){
  a[i]=a[i]/2 ;
 b[i]++;
} 

}
  
  for(int i=1; i<N+1; i++)  {
 b[i+1]=b[i+1]+b[i] ;
}
  
    cout << b[N] << endl;

    return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 998244353
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int main(){
  int a,b,c;cin>>a>>b>>c;
  int ans;
  ans=a+b;
  if(ans>b+c) ans=b+c;
  if(ans>a+c) ans=a+c;
  cout<<ans<<endl;

}


Measured memory_bytes: 256
//
#include<bits/stdc++.h>
#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define ld long double
#define rep(i, l, r) for (int i = (l); i < (r); i++)
#define repb(i, r, l) for (int i = (r); i > (l); i--)
#define sz(a) (int)a.size()
#define fi first
#define se second
#define mp(a, b) make_pair(a, b)
#define rank qwertyuio
#define next dfghjk
#define prev fhsgfhjf
#define plus fsghsf
#define minus ytryr
  
using namespace std;
  
inline bool setmin(int &x, int y) { return (y < x) ? x = y, 1 : 0; }
inline bool setmax(int &x, int y) { return (y > x) ? x = y, 1 : 0; }
inline bool setmin(ll &x, ll y) { return (y < x) ? x = y, 1 : 0; }
inline bool setmax(ll &x, ll y) { return (y > x) ? x = y, 1 : 0; }
  
const int N = 100000;
const int inf = (int)1e9 + 1;
const ll big = (ll)1e18 + 1;
const int P = 239;
const int P1 = 31;
const int P2 = 57;
const int MOD = (int)1e9 + 7;
const int MOD1 = (int)1e9 + 9;
const int MOD2 = 998244353;
const ld eps = 1e-9;
const double pi = atan2(0, -1);
const int ABC = 26;
 
deque<int> next_good(deque<int> s) {
    int p = sz(s) - 1;
    while (p >= 0 && s[p] == 9) {
        s[p] = 0;
        p--;
    }
    if (p == -1) {
        s.push_front(1);
    } else {
        s[p]++;
    }
    while (true) {
        int b = -1;
        rep(i, 0, sz(s) - 1) {
            if (abs(s[i] - s[i + 1]) > 1) {
                b = i;
                break;
            }
        }
        if (b == -1) {
            break;
        }
        if (s[b + 1] > s[b]) {
            s[b]++;
        }
        int lll = max(s[b] - 1, 0);
        rep(i, b + 1, sz(s)) {
            s[i] = lll;
            lll = max(lll - 1, 0);
        }
    }
    return s;
}
 
int main()
{

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.precision(20);
    cout << fixed;

    int k;
    cin >> k;
    deque<int> ans = {0};
    rep(i, 0, k) {
        ans = next_good(ans);
    }
    for (int i : ans) {
        cout << i;
    }
    cout << "\n";
    return 0;
}
 

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

int main() {
    string S, C, D;
    cin >> S;
    for (int i=0; i<S.length(); i++){
        if (S[i]=='A'){
            C=S.substr(i);
            break;
        }
    }
    reverse(C.begin(), C.end());
    for (int i=0; i<C.length(); i++){
        if (C[i]=='Z'){
            D=C.substr(i);
            break;
        }
    }
    cout << D.length() << endl;
}


Measured memory_bytes: 900
N, M = map(int, input().split())

ab = []
cd = []
for _ in range(N):
    a, b = map(int, input().split())
    ab.append([a, b])
for _ in range(M):
    c, d = map(int, input().split())
    cd.append([c, d])

for a, b in ab:
    near = 10**32
    for i, n in enumerate(cd):
        tmp = abs(a-n[0])+abs(b-n[1])
        if near == tmp:
            continue
        near = min(near, tmp)
        if near == tmp:
            ans = i + 1
    print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main(){
  int W,a,b;
  cin >> W >> a >> b;
  if(abs(a-b) <= W){
    cout << 0 << endl;
  }else{
    cout << min(abs(b+W-a),abs(a+W-b)) << endl;
  }
}

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

using namespace std;

typedef long long ll; 

int main(void) {
  int n;
  cin >> n;

  vector < pair<ll, ll> > ps;

  for (int i = 0; i < n; i++) {
    ll tx, ty; cin >> tx >> ty;

    ps.push_back(make_pair(tx, ty));

  }

  vector< pair<ll, ll> > rs;

  for (int i = 0; i < n; i++)
  {
    pair<int ,int> st = ps[i];
    for (int j = 0; j < n; j++) {
      if (i != j) {
        pair<ll, ll> sc = ps[j];
        pair<ll, ll> r = make_pair(sc.first - st.first, sc.second - st.second);
        rs.push_back(r);
      }
    }
  }

  int m = 0;
  for (int i = 0; i < rs.size(); i++) {
    pair<ll, ll> cur = rs[i];
    //cout << cur.first << ", " << cur.second << endl;
    int cnt = 1;
    for (int j = 0; j < rs.size(); j++) {
      if (i != j && cur == rs[j]) {
        cnt++;
      }
    }
    m = max(m, cnt);
  }

  cout << n - m << endl;

  return 0;
}

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

using namespace std;

char a[52],b[52];

int main(){
	cin>>a;
	cin>>b;
	int la=strlen(a),lb=strlen(b);
	int l=min(la,lb),ll=max(la,lb);
	for(int i=0;i<=l-1;i++)
		cout<<a[i]<<b[i];
	if(la>lb)
		for(int i=l;i<=ll-1;i++)
			cout<<a[i];
	else for(int i=l;i<=ll-1;i++)
			cout<<b[i];
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

#define N	5000
#define MD	1000000007

long long power(int a, int k) {
	long long b = a, p = 1;

	while (k) {
		if (k & 1)
			p = p * b % MD;
		b = b * b % MD;
		k >>= 1;
	}
	return p;
}

int main() {
	static char cc[N + 1];
	static int dp[N + 1], dq[N + 1];
	int n, m, i, j;

	scanf("%d%s", &n, cc), m = strlen(cc);
	dp[0] = 1;
	for (i = 1; i <= n; i++) {
		for (j = 0; j <= i; j++)
			dq[j] = (j == 0 ? dp[0] + dp[1] : dp[j - 1] * 2LL + (j + 1 < i ? dp[j + 1] : 0)) % MD;
		for (j = 0; j <= i; j++)
			dp[j] = dq[j];
	}
	printf("%lld\n", dp[m] * power((MD + 1) / 2, m) % MD);
	return 0;
}


Measured memory_bytes: 1772
#include <iostream>
#include <map>
#include <set>
#include <string>
#include<string.h>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
#include <cctype>
using namespace std;
typedef long long ll;
const int maxn=60;
int a[maxn],b[maxn],c[maxn],d[maxn];
int A[maxn];
int ans=0;
int n,m,q;

void check(){
	int now=0;
	for(int i=1;i<=q;i++){
//		printf("%d %d %d %d\n",A[b[i]],A[a[i]],c[i],A[b[i]]-A[a[i]]);
		if(A[b[i]]-A[a[i]]==c[i]){
			now+=d[i];
		}
	}
	ans=max(now,ans);
}


void dfs(int now,int val){
	A[now]=val;
	if(now==n){
		check();
		return;
	}
	for(int i=val;i<=m;i++){
		dfs(now+1,i);
	}
	return;
} 

int main(){
	scanf("%d%d%d",&n,&m,&q);
	for(int i=1;i<=q;i++){
		scanf("%d%d%d%d",&a[i],&b[i],&c[i],&d[i]);
	}
	dfs(1,1);
	printf("%d\n",ans);
	return 0;
} 

Measured memory_bytes: 3812
#include <stdio.h>
int main()
{
  double r,c;
  c=3.14159265358979323846;
  scanf("%lf",&r);
  if(r>0 && r<10000)printf("%.6f %.6f\n",(double)r*r*c,(double)r*2*c);
  return 0;
}

Measured memory_bytes: 652
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#pragma warning(disable:4786)
#pragma warning(disable:4996)
#include <ctime>
#include<list>
#include <numeric>
#include<bitset>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<functional>
#include<string>
#include<cstring>
#include<cstdlib>
#include<queue>
#include<utility>
#include<fstream>
#include<sstream>
#include<cmath>
#include<stack>
#include<assert.h>
#include<unordered_map>
#include<unordered_set>
using namespace std;

#define MEM(a, b) memset(a, (b), sizeof(a))
#define CLR(a) memset(a, 0, sizeof(a))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define ABS(X) ( (X) > 0 ? (X) : ( -(X) ) )
#define S(X) ( (X) * (X) )
#define SZ(V) (int )V.size()
#define FORN(i, n) for(int i = 0; i < n; i++)
#define FORAB(i, a, b) for(int i = a; i <= b; i++)
#define ALL(V) V.begin(), V.end()
#define IN(A, B, C)  ((B) <= (A) && (A) <= (C))
#define AIN(A, B, C) assert(IN(A, B, C))

//typedef int LL;
typedef long long int LL;
//typedef __int128 LL;
//typedef __int64 LL;

typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef pair<long double, long double> PDD;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII > VP;
typedef vector<double> VD;
typedef vector<LL> VL;
typedef long double ld;

int n, m;
int par[100005];
VI V[100005];
int in[100005];

void solve(int ks) {
	scanf("%d %d", &n, &m);
	m += n - 1;
	for (int i = 1; i <= m; i++) {
		int u, v;
		scanf("%d %d", &u, &v);
		V[u].push_back(v);
		in[v]++;
	}

	queue<int> Q;
	for (int i = 1; i <= n; i++) {
		if (in[i] == 0) {
			Q.push(i);
		}
	}
	while (!Q.empty()) {
		int u = Q.front();
		Q.pop();
		for (int v : V[u]) {
			in[v]--;
			par[v] = u;
			if (in[v] == 0) {
				Q.push(v);
			}
		}
	}
	for (int i = 1; i <= n; i++) {
		printf("%d\n", par[i]);
	}
}

int main()
{
#ifdef LOCAL
	double start_time = clock();
	freopen("C:\\Home\\ContestCodes\\sample.in", "r", stdin);
	//	freopen("out.out", "w", stdout);
#endif

	if (0) {
		int T;
		scanf("%d", &T);
		for (int ks = 1; ks <= T; ks++) solve(ks);
	}
	else {
		solve(0);
	}

#ifdef LOCAL
	double end_time = clock();
	fprintf(stderr, "Time = %lf\n", (end_time - start_time) / CLOCKS_PER_SEC);
#endif

	return 0;
}


Measured memory_bytes: 7040
fun main(args: Array<String>) {
    val n = readInputLine().toInt()
    val aListRev = readInputLine().split(" ").map { it.toInt() }.reversed()

    var ansSet = mutableSetOf<Int>()

    for ((i, a) in aListRev.withIndex()) {
        if ((n - i) * 2 > n) {
            if (a == 1) {
                ansSet.add(n - i)
            }
        } else {
            var adder = a == 1
            for (j in (n - i)..n step (n - i)) {
                adder = ansSet.contains(j) xor adder
            }
            if (adder) {
                ansSet.add(n - i)
            }
        }
    }
    
    println(ansSet.size)
    
    for (i in ansSet) {
        println(i)
    }
}

fun readInputLine(): String {
    return readLine()!!
}


Measured memory_bytes: 97652
import itertools, math, collections, sys
input = sys.stdin.readline
H, W, K = [int(_) for _ in input().split()]
A = [input() for _ in range(H)]
for h, w in itertools.product(range(H), range(W)):
    if A[h][w] == 'S':
        break
visited = [[False] * W for _ in range(H)]
#ans = min([h, H - 1 - h, w, W - 1 - w])
res = K - 1
Q = collections.deque([[h - 1, w, res], [h + 1, w, res], [h, w - 1, res],
                       [h, w + 1, res]])
sH = set([h])
sW = set([w])
while Q:
    h, w, res = Q.popleft()
    if 0 <= h < H and 0 <= w < W and A[h][w] == '.' and not visited[h][w]:
        visited[h][w] = True
        #ans = min([ans, h, H - 1 - h, w, W - 1 - w])
        sH.add(h)
        sW.add(w)
        if res:
            res -= 1
            Q += [[h - 1, w, res], [h + 1, w, res], [h, w - 1, res],
                  [h, w + 1, res]]
#print(1 + math.ceil(ans / K))
print(1 +
      math.ceil(min([min(sH), H - 1 - max(sH),
                     min(sW), W - 1 - max(sW)]) / K))


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

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
const int INF_N = 1e+9;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

//逆元(Eucledean algorithm)
ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

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




void solve() {
    int n, m; cin >> n >> m;
    cout << n-m+1 << endl;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout << fixed << setprecision(10);
  //init_f();
  //init();
  //int t; cin >> t; rep(i, t)solve();
  solve();
//   stop
    return 0;
}


Measured memory_bytes: 7708
#include<iostream>

using namespace std;

long gcd(long x,long y)
{
  if(y<1)
    return x;
  else
    return gcd(y, x%y);
}

int main()
{
  long long int A, B;
  cin >> A >> B;

  long i;
  long div = gcd(A,B);
  long count=0;
  for(i=2;i*i<=div;i++)
    {
      if(div % i == 0)
	{
	  count++; 
	  while(div%i==0)
	      div/=i;
        }
    }

  if(div>1)//最後の素因数になったら、自分自身で＋１
    count++;
  cout << count+1 << endl;
  
  return 0;
}
      


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int N;
  cin>>N;
  vector<int> vec(N);
  int count=0;
  for(int i=0;i<N;i++)
  {
    cin>>vec.at(i);
  }
  for(int i=1;i<N-1;i++)
  {
    if((vec.at(i-1)<vec.at(i)&&vec.at(i)<vec.at(i+1))||(vec.at(i-1)>vec.at(i)&&vec.at(i)>vec.at(i+1)))
    {
       count++;
    }
  }
  cout<<count<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
    ~debug() { cerr << endl; }
    eni(!=) cerr << boolalpha << i; ris; }
    eni(==) ris << range(begin(i), end(i)); }
    sim, class b dor(pair < b, c > d) {
    ris << "(" << d.first << ", " << d.second << ")";
    }
    sim dor(rge<c> d) {
    *this << "[";
    for (auto it = d.b; it != d.e; ++it)
        *this << ", " + 2 * (it == d.b) << *it;
    ris << "]";
    }
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
 
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<long double> vld;
typedef long long ll;
typedef long double ld;
#define PI 3.14159265358979323846
#define sqr(a) ((a) * (a))
#define len(V) (int)V.size()
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'
#define fix(a) fixed << setprecision(a)
#define readv(x) for(auto &_ : (x)) {cin >> _;}
#define printv(x) for(auto &_ : (x)) {cout << _ << ' ';} cout << endl
#define EPS 1e-6
#define MAXN 100047


void solve(){
	string s; cin >> s;
	
	int res = MAXN;
	FOR(i, 100, 1000){
		if (s.find(to_string(i)) != -1){
			if (abs(i - 753) < res) res = abs(i - 753);
		}
	}
	
	cout << res << endl;
}

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	
	solve();
	
	return 0;
}


Measured memory_bytes: 3660
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
typedef long long cc;

cc N, K, Ans = 0, i, j, k, D, X[20][20], sub;
double judge=0, judge2 = 0, judge3 = 0;

string S;


int main() {
	cin >> N >> D;
	for (i = 0; i < N; i++) {
		for (j = 0; j < D; j++)
			cin >> X[i][j];
	}
	for (i = 0; i < N-1; i++) {
		for (j = i + 1; j < N; j++) {
			judge = 0;
			for (k = 0; k < D; k++) {
				judge += (X[i][k] - X[j][k])*(X[i][k] - X[j][k]);
			}
			judge2 = sqrt(judge);
			sub = judge2;
			judge2 -= sub;
			if (judge2 == 0)
				Ans += 1;
		}
	}
		cout << Ans << endl;
		
		return 0;
}

Measured memory_bytes: 256
import sys
def sieve(m):
    N=range(1,m+2,2)
    r=int(m**.5)
    h=len(N)
    N[0]=0
    for i in range(h):
        x=N[i]
        if x>r: break
        if x and i+x<h: N[i+x:h:x]=[0]*((h-1-i-x)/x+1)
    return N
def f0056(n):
    x=0
    if n<4:x=0
    elif n==4:x=1
    elif n%2==1:
        if S[(n-2)/2]: x=1
    else:
        a=n/2
        for e in PRIMES:
            if e>a: break
            if S[(n-e)/2]: x+=1
    return x
 
S=sieve(50000)
PRIMES=filter(None,S)
for n in sys.stdin:
    n=int(n)
    if n==0: break
    print f0056(n)

Measured memory_bytes: 5828
#include<bits/stdc++.h>
#define int long long
using namespace std;
static const int INF = 1ll<<60;

struct edge{
    int to,cap,rev;
};

vector<edge> G[1005];
int itr[1005],level[1005];


void add_edge(int from,int to,int cap){
    G[from].push_back((edge){to,cap,(int)G[to].size()});
    G[to].push_back((edge){from,0,(int)G[from].size()-1});
}

void bfs(int s){
    memset(level,-1,sizeof(level));
    queue<int> que;
    level[s]=0;
    que.push(s);
    while(!que.empty()){
        int v=que.front();
        que.pop();
        for(int i=0;i<G[v].size();++i){
            edge &e=G[v][i];
            if(e.cap>0&&level[e.to]<0){
                level[e.to]=level[v]+1;
                que.push(e.to);
            }
        }
    }
}

int dfs(int from,int to,int cf){
    if(from==to)return cf;
    for(int i=0;i<G[from].size();++i){
        edge &e=G[from][i];
        if(level[e.to]>level[from]&&e.cap>0){
            int d=dfs(e.to,to,min(cf,e.cap));
            if(d>0){
                e.cap-=d;
                G[e.to][e.rev].cap+=d;
                return d;
            }
        }
    }
    return 0;
}

int max_flow(int from,int to){
    int fl=0,tf;
    while(1){
        bfs(from);
        if(level[to]<0)return fl;
        memset(itr,0,sizeof(itr));
        while((tf=dfs(from,to,INF))>0)fl+=tf;
    }
}




signed main(){
    int V,E;
    cin>>V>>E;
    for(int i=0;i<E;++i){
        int a,b,c;
        cin>>a>>b>>c;
        add_edge(a,b,c);
    }
    cout<<max_flow(0,V-1)<<endl;
}

Measured memory_bytes: 3136
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using Map = map<string,ll>;



int main(){
	ll N;
	cin >> N;
	ll K;
	cin >> K;
	ll Q;
	cin >> Q;	
	vector<ll> point(N+1,0);
	vector<ll> A(Q,0);
	for(ll i=0;i<Q;i++){
		cin>>A[i];
		point[A[i]]++;
	;}
	for(ll i=1;i<N+1;i++){
		if(Q-point[i]<K)cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	;}



return 0;
}  



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

#define IOS          ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl         "\n"
#define int          long long
#define all(v)       v.begin(),v.end()
#define sz(v)        (int)v.size()
#define pii          pair<int,int>
#define fi           first
#define se           second
#define forn(i,a,b)  for(int i=a;i<b;i++)
#define deb(x)       cout << #x << ' ' << x << endl
#define clock        cerr << 1000 * (double)clock() / (double)CLOCKS_PER_SEC << "ms" << endl;

void INPUT() {
	#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}
const int N = 1e5 + 5;

int w[105], v[105];
int cache[105][N];
int n, tw;

int dp(int idx, int val) {
	if (val == 0) return 0;
	if (val < 0 || idx == n) return (int)1e15;
	int &ans = cache[idx][val];
	if (ans != -1) return ans;
	ans = min(dp(idx + 1, val), w[idx] + dp(idx + 1, val - v[idx]));
	return ans;
}

int32_t main(){
    IOS //INPUT();
    cin >> n >> tw;
    forn(i, 0, n) cin >> w[i] >> v[i];
    memset(cache, -1, sizeof(cache));
    int ans = 0;
    forn(i, 1, 1e5 + 1) {
    	int mwt = dp(0, i);
    	if (mwt <= tw) ans = i;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 82304
#include <stdio.h>
#define n 36

struct Card{
    
  char suit;
  char value;
};

void BubbleSort(struct Card C[],int N){
  int i,j;
  struct Card a;

  for(i=0;i<N;i++){
    for(j=N-1;j>=i+1;j--){
      if(C[j].value < C[j-1].value){
        a = C[j];
        C[j] = C[j-1];
        C[j-1] = a;
      }
    }
  }
}

void SelectionSort(struct Card C[],int N){
  int i,j,minj;
  struct Card a;

  for(i=0;i<N;i++){
    minj = i;
    for(j=i;j<N;j++){
      if(C[j].value < C[minj].value){
        minj = j;
      }
    }
    a = C[i];
    C[i] = C[minj];
    C[minj] = a;
  }
}

int isStable(struct Card C1[],struct Card C2[],int N){
  int i,j;

  for(i=0;i<N;i++){
    if(C1[i].suit != C2[i].suit)return 0;
  }
  return 1;
}
  /*for(i=0;i<N;i++){                                                           
    for(j=i+1;j<N;j++){                                                         
      for(a=0;a<N;a++){                                                         
        for(b=a+1;b<N;b++){                                                     
        if(in[i] == in[j] && )*/
int main(){
  struct Card C1[101],C2[101];
  int i,N;
  scanf("%d\n",&N);
  for(i=0;i<N;i++){
    if(i!=N-1)scanf("%c%c ",&C1[i].suit,&C1[i].value);
    else scanf("%c%c",&C1[i].suit,&C1[i].value);
  }

  for(i=0;i<N;i++)C2[i] = C1[i];

  BubbleSort(C1,N);
  SelectionSort(C2,N);

  for(i=0;i<N;i++){
    if(i)printf(" ");
    printf("%c%c",C1[i].suit,C1[i].value);
  }
  printf("\nStable\n");
  for(i=0;i<N;i++){
    if(i)printf(" ");
    printf("%c%c",C2[i].suit,C2[i].value);
 }
  if(isStable(C1,C2,N)){
    printf("\nStable\n");
  }
  else printf("\nNot stable\n");

  return 0;
}



Measured memory_bytes: 2108
// テンプレートマッチング

#include <bits/stdc++.h>

#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, m, n) for(int i = (m); i < (int)(n); ++i)
#define ALL(x) (x).begin(), (x).end()

#ifdef LOCAL
  #define eprintf(...) fprintf(stdout, __VA_ARGS__)
#else
  #define eprintf(...) 0
#endif

using namespace std;

bool check(const vector<string> &va, const vector<string> &vb, int x, int y) {
  bool result = true;
  REP(ty, vb.size()) {
    REP(tx, vb[0].size()) {
      if(vb[ty][tx] != va[y+ty][x+tx]) {
        result = false;
        break;
      }
    }
  }
  return result;
}

void printall(vector<string> &vs) {
  REP(ty, vs.size()) {
    REP(tx, vs[0].size()) {
      cout << vs[ty][tx];
    }
    cout << endl;
  }
}

int main() {
  int n, m;
  cin >> n >> m;
  vector<string> va(n);
  vector<string> vb(m);
  REP(i, n) {
    cin >> va[i];
  }
  REP(i, m) {
    cin >> vb[i];
  }
  /*
  printall(va);
  cout << endl;
  printall(vb);
  */

  REP(ty, va.size() - vb.size() + 1) {
    REP(tx, va[0].size() - vb[0].size() + 1) {
      bool result = check(va, vb, tx, ty);
      eprintf("check x,y,r:%d,%d,%d\n", tx, ty, result);
      if(result) {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;

  return 0;
}


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

int A[3005], N;

const int64_t mod = 998244353;

int64_t DP[4000][4000];

int64_t f(int i, int s) {
	if (i == N) {
		if (s == 0) return 1;
		else return 0;
	}
	if (DP[i][s] != -1) return DP[i][s];
	int64_t ans = (2*f(i+1, s))%mod;
	if (A[i] <= s)  {
		ans += f(i+1, s-A[i]);
		ans %= mod;
	}
	return DP[i][s] = ans;
}


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

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

	memset(DP, -1, sizeof DP);

	cout << f(0, S) << endl;

}

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

int main() {
  int N;
  cin >> N;
  int sum=0;
  
  for(int i=0;i<N;i++){
    int l,r;
    cin >> l >> r;
    sum +=r-l+1;
  }
  cout << sum <<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.awt.image.BandedSampleModel;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class Main {


    public static void main(String args[])
    {
        Scanner sc=new Scanner(System.in);
        int a=sc.nextInt();
        int ans=a+a*a+a*a*a;
        System.out.println(ans);

    }
}


Measured memory_bytes: 35712
N=int(input())
A=list(map(int,input().split()))

mx=max(A)
f=[True]*(mx+1)
chk=[0]*(mx+1)

for a in A:
    chk[a]+=1

for a in A:
    cnt=2
    while a*cnt<=mx:
        f[a*cnt]=False
        cnt+=1
ans=0
for a in A:
    if f[a]==True and chk[a]<=1:
        ans+=1
print(ans)


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

#define debug(x) cout << #x << ": " << (x) << endl

int main(int argc, char *argv[]) {
  long long X, Y;
  cin >> X >> Y;
  cout << (abs(X - Y) > 1 ? "Alice" : "Brown") << endl;
  return 0;
}


Measured memory_bytes: 256
#define ONLINE_JUDGE
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
const ll INF=1001001001;
const ll LINF=1001001001001001001;
const ll D4[]={0,1,0,-1,0};
const ll D8[]={0,1,1,0,-1,-1,1,-1,0};
#define _overload3(_1,_2,_3,name,...) name
#define _rep2(i,n) for(ll i=0;i<(n);++i)
#define _rep3(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,_rep3,_rep2)(__VA_ARGS__)
#define _repe2(i,n) for(ll i=0;i<=(n);++i)
#define _repe3(i,a,b) for(ll i=(a);i<=(b);++i)
#define repe(...) _overload3(__VA_ARGS__,_repe3,_repe2)(__VA_ARGS__)
#define _rrep2(i,n) for(ll i=(n)-1;i>=0;i--)
#define _rrep3(i,a,b) for(ll i=(b)-1;i>=(a);i--)
#define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
template<class T>
bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>
bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
template<class T>
using pq=priority_queue<T,vector<T>,greater<T>>;

ll N;
vl a;
vl u;
vl v;

void solve();

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cin >> N;
    a = vl(N);
    for(int i = 0; i < N; ++i){
        cin >> a[i];
    }
    u = vl(N-1);
    v = vl(N-1);
    for(int i = 0; i < N-1; ++i){
        cin >> u[i];
        cin >> v[i];
    }
    solve();
}

// 2 <= N <= 2 × 10^5
// 1 <= a_i <= 10^9
// 1 <= u_i , v_i <= N
// u_i != v_i
// 与えられるグラフは木である。
// 入力はすべて整数である。

vvl g;
vl ans;
vl d;

void dfs(ll x,ll p=-1){
    ll idx=lower_bound(all(d),a[x])-d.begin();
    ll bak=d[idx];
    d[idx]=a[x];
    ans[x]=lower_bound(all(d),LINF)-d.begin();
    for(ll to:g[x]){
        if(to==p)continue;
        dfs(to,x);
    }
    d[idx]=bak;
}

// ll N, vl a, vl u, vl v
// N 行出力せよ。k 行目には、頂点 1 から頂点 k までの最短パス上の頂点に書かれている整数を頂点 1 に近い方から順に並べた数列の最長増加部分列の長さを出力せよ。
void solve(){
    g.resize(N);
    ans.resize(N);
    d.resize(N+1,LINF);
    rep(i,N-1){
        g[u[i]-1].push_back(v[i]-1);
        g[v[i]-1].push_back(u[i]-1);
    }

    dfs(0);
    rep(i,N){
        cout<<ans[i]<<endl;
    }
}


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

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

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

using ll=long long;
#define int ll

#define FOR(i,a,b) for(int i=int(a);i<int(b);i++)
#define REP(i,b) FOR(i,0,b)
#define MP make_pair
#define PB push_back
#define ALL(x) x.begin(),x.end()
#define REACH cerr<<"reached line "<<__LINE__<<endl
#define DMP(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl
#define ZERO(x) memset(x,0,sizeof(x))

using pi=pair<int,int>;
using vi=vector<int>;
using ld=long double;

template<class T,class U>
ostream& operator<<(ostream& os,const pair<T,U>& p){
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator <<(ostream& os,const vector<T>& v){
	os<<"[";
	REP(i,(int)v.size()){
		if(i)os<<",";
		os<<v[i];
	}
	os<<"]";
	return os;
}

int read(){
	int i;
	scanf("%lld",&i);
	return i;
}

void printSpace(){
	printf(" ");
}

void printEoln(){
	printf("\n");
}

void print(int x,int suc=1){
	printf("%lld",x);
	if(suc==1)
		printEoln();
	if(suc==2)
		printSpace();
}

string readString(){
	static char buf[3341919];
	scanf("%s",buf);
	return string(buf);
}

char* readCharArray(){
	static char buf[3341919];
	static int bufUsed=0;
	char* ret=buf+bufUsed;
	scanf("%s",ret);
	bufUsed+=strlen(ret)+1;
	return ret;
}

template<class T,class U>
void chmax(T& a,U b){
	if(a<b)
		a=b;
}

template<class T,class U>
void chmin(T& a,U b){
	if(a>b)
		a=b;
}

template<class T>
T Sq(const T& t){
	return t*t;
}

const int inf=LLONG_MAX/3;

void Yes(){
	cout<<"Yes"<<endl;
	exit(0);
}
void No(){
	cout<<"No"<<endl;
	exit(0);
}

string waf="RYGB";
char ans[514][514];

signed main(){
	int h=read(),w=read(),d=read();
	REP(i,h)REP(j,w){
		int s=((i+j)/d)%2,t=((i+w-j)/d)%2;
		ans[i][j]=waf[s*2+t];
	}
	REP(i,h)
		printf("%s\n",ans[i]);
}

Measured memory_bytes: 768
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
    int N, K, x, ans = 0;
    cin >> N >> K;
    for (int i = 0; i < N; i++) {
        cin >> x;
        ans += 2 * min(x, K - x);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class Main {

	public static void main(String[] args) {
		FastScanner scan = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		int a = scan.nextInt();
		int b = scan.nextInt();

		if((a * b) % 2 == 0) {
			out.print("No");
		}else {
			out.print("Yes");
		}
		out.flush();
	}
}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
			throw new NumberFormatException();
		return (int) nl;
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}


Measured memory_bytes: 21332
#include<stdio.h>
#include<string.h>
#include<math.h>
#include <stdlib.h>

long long lmp(long long a, long long b) {
	long long upper, lower, r;

	if (a >= b)upper = a, lower = b;
	else upper = b, lower = a;
	r = upper % lower;
	if (r) lmp(lower, r);
	else return lower;
}

int main(void) {
	long long a, b, c, d;
	long long ans = 0;
	long long lcp_cd;

	scanf("%lld %lld %lld %lld", &a, &b, &c, &d);
	lcp_cd = c * d / lmp(c, d);
	//printf("lmp_cd=%lld\n", lcp_cd);

	ans += b / c;
	ans += b / d;
	ans -= b / lcp_cd;

	ans -= (a - 1) / c;
	ans -= (a - 1) / d;
	ans += (a - 1) / lcp_cd;

	printf("%lld", b - a + 1 - ans);
	return 0;
}

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

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

long long MOD = 1000000000 + 7;

vector<ll> a;

int main(){
  cout << setprecision(10);

  int N;
  cin >> N;

  a.assign(N, 0);
  for(int i = 1; i <= N; i++){
    ll tmp;
    cin >> tmp;
    a[i-1] = tmp - i;
  }
  sort(a.begin(), a.end());

  ll ans = 0;
  ll b;
  if(N%2 == 0){
    b = a[N/2];
  } else { 
    b = a[N/2];
  }

  for(int i = 0; i < N; i++){
    ans += abs(a[i] - b);
  }

  cout << ans << endl;
}


Measured memory_bytes: 1792
#include<cstdio>
#include<vector>
using namespace std;

int main() {
    int n;
    scanf("%d", &n);
    vector<int> tmp;
    int sum = 0;
    for(int i = 0 ; i < n;  i++) {
        int x;
        scanf("%d", &x);
        tmp.push_back(x);
        sum += x;
    }
    bool get = true;
    for(auto e: tmp) {
        if(sum-e <= e) {
            get = false;
            break;
        }
    }
    if(get) puts("Yes");
    else puts("No");
    return 0;
}


Measured memory_bytes: 256
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N,x = MI()
    A=LI()
    ans = 0
   
    for i in range(N-1):
      if A[i]+A[i+1]>x:
        s=A[i]+A[i+1]
        A[i+1]-=min(A[i+1],s-x)
        ans += max(0,s-x)

    print(ans)
if __name__ == '__main__':
    main()


Measured memory_bytes: 59792
/// Thank you tanakh!!!
/// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

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

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

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

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

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

fn f(b: usize, mut n: usize) -> usize {
    let mut res = 0;
    while n > 0 {
        res += n % b;
        n /= b;
    }
    res
}

fn main() {
    input!(n: usize, s: usize);

    for b in 2..1000000 {
        if f(b, n) == s {
            println!("{}", b);
            return;
        }
    }

    // s =p+q, n=pb + q
    if n > s {
        for p in (1..1000000).rev() {
            if (n - s) % p != 0 {
                continue;
            }
            let b = (n - s) / p + 1;
            if f(b, n) == s {
                println!("{}", b);
                return;
            }
        }
    }

    if s == 1 {
        println!("{}", n);
    } else if n == s {
        println!("{}", n + 1);
    } else {
        println!("{}", -1);
    }
}


Measured memory_bytes: 4476
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int N,M,ac;
pair<int,int>AB[1<<17];
vector<pair<int,int> >G[1<<17];
bool used[2<<17],vis[1<<17];
bool dfs(int u)
{
	int b=(u&&AB[u-1].second)^(u<N&&AB[u].second);
	vis[u]=true;
	for(pair<int,int>e:G[u])
	{
		int v=e.first;
		if(!vis[v]&&dfs(v))
		{
			b++,ac++;
			used[e.second]=true;
		}
	}
	return b%2;
}
main()
{
	cin>>N>>M;
	for(int i=0;i<N;i++)cin>>AB[i].first>>AB[i].second;
	sort(AB,AB+N);
	for(int i=0;i<M;i++)
	{
		int L,R;cin>>L>>R;
		L=lower_bound(AB,AB+N,make_pair(L,0))-AB;
		R=upper_bound(AB,AB+N,make_pair(R,2))-AB;
		G[L].push_back({R,i});
		G[R].push_back({L,i});
	}
	for(int i=0;i<=N;i++)if(!vis[i]&&dfs(i))
	{
		cout<<-1<<endl;
		return 0;
	}
	cout<<ac<<endl;
	for(int i=0;i<M;i++)if(used[i])cout<<i+1<<endl;
}

Measured memory_bytes: 14464
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


int A, B, Q;

long long s[111111], t[111111], x;


long long min_cost(long long* a, int A, long long x)
{
  auto it = std::lower_bound(a, a + A, x);

  if (it == a) {		// west bound
    return *it - x;
  }
  else if (it == a + A) {	// east bound
    return x - it[-1];
  }
  else {
    assert(it[0] - x >= 0);
    assert(x - it[-1] >= 0);
    
    return std::min(it[0] - x, x - it[-1]);
  }
}


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

  std::cout << std::fixed << std::setprecision(6);
  std::cerr << std::fixed << std::setprecision(6);

  std::cin >> A >> B >> Q;

  for (int i = 0; i < A; i ++)
    std::cin >> s[i];

  for (int i = 0; i < B; i ++)
    std::cin >> t[i];

  for (int i = 0; i < Q; i ++) {
    long long cm = INF;

    std::cin >> x;

    auto it = std::lower_bound(s, s + A, x);

    if (it == s) {		// west bound
      cm = std::min(*it - x + min_cost(t, B, *it), cm);
    }
    else if (it == s + A) {	// east bound
      cm = std::min(x - it[-1] + min_cost(t, B, it[-1]), cm);
    }
    else {
      assert(x - it[-1] >= 0);
      assert(it[0] - x >= 0);
      
      cm = std::min(
        std::min(x - it[-1] + min_cost(t, B, it[-1]),
                 it[0] - x + min_cost(t, B, it[0])),
        cm);
    }

    it = std::lower_bound(t, t + B, x);

    if (it == t) {		// west bound
      cm = std::min(*it - x + min_cost(s, A, *it), cm);
    }
    else if (it == t + B) {	// east bound
      cm = std::min(x - it[-1] + min_cost(s, A, it[-1]), cm);
    }
    else {
      assert(x - it[-1] >= 0);
      assert(it[0] - x >= 0);
      
      cm = std::min(
        std::min(x - it[-1] + min_cost(s, A, it[-1]),
                 it[0] - x + min_cost(s, A, it[0])),
        cm);
    }

    std::cout << cm << std::endl;
  }

  return 0;
}


Measured memory_bytes: 2944
#include<bits/stdc++.h>
#pragma warning(disable:4996)
using namespace std;
using ll = long long;
const int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
//#define int long long
const int INF = numeric_limits<int>::max();
signed main() {
	string s;
	cin >> s;
	vector<int>s_c(10000, INF);
	for (int i =0; i < s.size(); i++) {
		if (s_c[s[i]] == INF) {
			s_c[s[i]] = 1;
		}
		else {
			s_c[s[i]]++;
		}
	}
	sort(s_c.begin(), s_c.end());
	string t;
	cin >> t;
	vector<int>t_c(10000, INF);
	for (int i = 0; i < t.size(); i++) {
		if (t_c[t[i]] == INF) {
			t_c[t[i]] = 1;
		}
		else {
			t_c[t[i]]++;
		}
	}
	sort(t_c.begin(), t_c.end());
	if (s_c == t_c) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;

}


Measured memory_bytes: 900
#include<bits/stdc++.h>
using   namespace      std;
typedef long long      LL;
typedef vector<int>    VI;
typedef pair<int,int>  PII;

int main(){

	int n;
	cin>> n;
	int ar[n], flag[n];
	memset(flag, 0, sizeof flag);

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

		for(int j = i - 1; j >= 0; j--){
			if(ar[j] > ar[j + 1] + 1){
				cout<< "No"<< endl;
				return 0;
			}

			else if(ar[j] == ar[j + 1] + 1){
				if(flag[j]){
					cout<< "No"<< endl;
					return 0;
				}
				else{
					ar[j]--;
					flag[j] = 1;
				}
			}

			else 
				break;
		}
	}

	for(int i = 1; i< n; i++){
		if(ar[i - 1] > ar[i]){
			cout<< "No"<< endl;
			return 0;
		}
	}

	cout<< "Yes"<< endl;

	return 0;
}

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

using namespace std;

int main()
{
	int n,k;
	int x[100];
	int ans=0;
	
	cin>>n;
	cin>>k;
	for(int i=0;i<n;i++)
	{
		cin>>x[i];
	}
	for(int i=0;i<n;i++)
	{
		if(k-x[i]<x[i])
		{
			ans += (k-x[i])*2;
		}else{
			ans += x[i]*2;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long k = sc.nextLong();
        int[] a = new int[n];
        long[] b = new long[n];
        for(int i = 0; i < n; i++){
            a[i] = sc.nextInt();
            b[i] = sc.nextInt();
        }
        HashMap<Integer, Long> hm = new HashMap<Integer, Long>();
        for(int i = 0; i < n; i++){
            if(hm.containsKey(a[i])){
                hm.put(a[i], hm.get(a[i]) + b[i]);
            } else {
                hm.put(a[i], b[i]);
            }
        }
        List<Integer> sortedKeys = new ArrayList<Integer>(hm.keySet());


        Collections.sort(sortedKeys);
        long cout = 0;
        for(int key : sortedKeys){
            cout += hm.get(key);
            if(cout >= k){
                System.out.println(key);
                break;
            }
        }
    }
}

Measured memory_bytes: 65604
maxx = 2000001
maxnum = 10010

n=int(input())
A=[int(x) for x in input().split()]  

B = [0] * n
C = [0] * maxnum

for a in A:
	C[a] += 1


for i in range(1,len(C)):
	C[i] += C[i-1]

for j in reversed(range(0,len(A))):
	B[C[A[j]]-1] = A[j]
	C[A[j]] -= 1

print(*B)




Measured memory_bytes: 224208