akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ll long long int
#define M 1000000007
#define mod 998244353
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define pi pair<ll,ll>
#define endl "\n"
using namespace std;
const ll N=500010;


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

    string s;
    cin>>s;
    reverse(s.begin(),s.end());
    ll ar[2020]={0};
    ar[0]=1;
    ll x=0;
    ll ans=0;
    ll p=1;
    for(ll i=0;i<s.size();++i)
    {
        p=(10*p)%2019;
        x=x%2019+((s[i]-'0')*p)%2019;
        x=x%2019;
        ans+=ar[x];
        ar[x]+=1;
    }
    cout<<ans;

    return (0);
}


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

int main() {
  int x1, y1, x2, y2;
  cin >> x1 >> y1 >> x2 >> y2;

  int x = x2 - x1, y = y2 - y1;
  int x3 = x2 - y, y3 = y2 + x;
  int x4 = x1 - y, y4 = y1 + x;

  cout << x3 << ' ' << y3 << ' ' << x4 << ' ' << y4 << endl;
}


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

struct item
{
    int w;
    int v;

};

long long int knapsack(vector<item> arr,int c,int n)
{
    long long int dp[n+1][c+1];
    memset(dp,0,sizeof dp);
    for(int i=0;i<=n;i++)
    {
        dp[i][0]=0;
    }
    for(int i=0;i<=c;i++)
    {
        dp[0][i]=0;
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=c;j++)
        {

            if(j>=arr[i-1].w)
                dp[i][j]=max(dp[i-1][j],arr[i-1].v+dp[i-1][j-arr[i-1].w]);
            else
                dp[i][j]=dp[i-1][j];
        }
    }
    return dp[n][c];
}
int main()
{
    int n;
    cin>>n;
    int c;
    cin>>c;
    vector<item> arr;
    for(int i=0;i<n;i++)
    {
        int w,v;
        cin>>w>>v;
        item t;
        t.w=w;
        t.v=v;
        arr.push_back(t);
    }
    cout<<knapsack(arr,c,n);
    return 0;
}


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

using namespace std;
using ll = long long;

void calc(ll a, ll b) {
  if (a == b || a + 1 == b) {
    printf("%lld\n", 2 * a - 2);
    return;
  }

  ll r = sqrt(a * b);
  if (r * r == a * b) --r;

  if (r * (r + 1) >= a * b) {
    printf("%lld\n", 2 * r - 2);
    return;
  }

  printf("%lld\n", 2 * r - 1);
}

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

  for (int i = 0; i < q; ++i) {
    ll a, b;
    scanf("%lld%lld", &a, &b);
    if (a > b) swap(a, b);
    calc(a, b);
  }
}


Measured memory_bytes: 256
#include <iostream>

int main() {
    int A, B;
    std::cin >> A >> B;
    int result = 0;
    if (A >= B) {
        result = A;
        --A;
    } else {
        result = B;
        --B;
    }
    std::cout << result + std::max(A, B) << std::endl;
    return 0;
}


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

using namespace std;

#ifdef NeverBeRed
#include "debug.h"
#else
#define debug(...) 9715
#endif
typedef long long ll;
typedef long double ld;
typedef complex<ld> point;
#define F first
#define S second

const int mod = 998244353;
int dp[2][3005][3005];

inline void add(int &x, int y)
{
	x += y;
	if (x >= mod)
		x -= mod;
}

int main()
{
	#ifdef TurnRed
		//freopen("a.in", "r", stdin);
		//freopen("a.out", "w", stdout);
	#endif

	ios_base::sync_with_stdio(0), cin.tie(0);

	int a, b, c, d;
	cin >> a >> b >> c >> d;
	dp[0][a][b] = 1;
	for (int i = a; i <= c; ++i)
		for (int j = b; j <= d; ++j)
		{
			add(dp[0][i][j+1], dp[1][i][j]);
			add(dp[1][i+1][j], (ll)j * dp[1][i][j] % mod);
			add(dp[0][i][j+1], (ll)i * dp[0][i][j] % mod);
			add(dp[1][i+1][j], (ll)j * dp[0][i][j] % mod);
		}

	add(dp[0][c][d], dp[1][c][d]);
	cout << dp[0][c][d] << "\n";

	return 0;
}


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

int main(void){
    int k,x,i;
    scanf("%d%d",&k,&x);
    for(i=x-k+1;i<=x+k-1;i++){
        printf("%d ",i);
    }
    return 0;
}

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

int main()
{
	int n;
	cin >> n ;
	
	vector<int> a(n) ;
	for(int& x : a) cin >> x ;

	for(int x : a)
	{
		if(x % 2 == 0 && (x % 3 != 0 && x % 5 != 0))
		{
			cout << "DENIED\n" ;
			return 0;
		}
	}
	cout << "APPROVED\n" ;
	return 0 ;
}


Measured memory_bytes: 256
import static java.lang.Math.pow;
import java.util.*;

class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int a = in.nextInt();
        boolean b = false;
        for (int i = 1; i <= 9; i++) {
            for (int j = 1; j <= 9; j++) {
                if (i * j == a) {
                    b = true;
                }
            }
        }
        if (b == true) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace std;
int main(){
	int cont=0;
	int N; cin>>N;
	string S;
	cin>>S;
	
	for(int i=0;i<N-2;i++){
		if(S[i]=='A'&&S[i+1]=='B'&&S[i+2]=='C'){
			cont++;
			i=i+2;
		}
	}
	cout<<cont<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define RI register int
int vis[100005], ans[100005], head[100005], tot;
struct Edges {
	int to, next, val;
} e[200005];
std :: queue <int> q;

inline void addedge(int from, int to, int val) {
	e[++tot] = (Edges){to, head[from], val};
	head[from] = tot;
	e[++tot] = (Edges){from, head[to], val};
	head[to] = tot;
}

int main() {
	int n; scanf("%d", &n);
	for (RI i = 1, x, y, z; i < n; ++i)
		scanf("%d %d %d", &x, &y, &z), addedge(x, y, z);
	q.push(1);
	while (!q.empty()) {
		int t = q.front(); q.pop();
		for (RI i = head[t]; i; i = e[i].next)
			if (!vis[e[i].to]) {
				vis[e[i].to] = 1;
				ans[e[i].to] = ans[t] ^ (e[i].val & 1);
				q.push(e[i].to); 
			}
	}
	for (RI i = 1; i <= n; ++i)
		printf("%d\n", ans[i]);
	return 0;
}

Measured memory_bytes: 3968
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define ll long long
#define pii pair<int,int>
#define forn(i,n) for(int i=0; i<(int)n; i++)
ll power(ll x,ll n);
bool isprime(ll n);
ll mod=1e9+7;


void test_case()
{
    ll a,b;
    cin>>a>>b;
    cout<<a*b;
}

int main()
{
    fastio
//    int t;
//    cin>>t;
//    while(t--)
    test_case();
}
ll power(ll x,ll n)
{
    ll ans=1;
    while(n>0) {
        if(n&1)
            ans*=x;
        n>>=1;
        x*=x;
    }
    return ans;
}

bool isprime(ll n)
{
    if(n==2 || n==3)
        return true;
    if(n<=1 || n%2==0 || (n%6!=1 && n%6!=5))
        return false;
    for(int i=3;i*i<=n;i+=2) {
        if(n%i==0)
            return false;
    }
    return true;
}


Measured memory_bytes: 3644
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <sstream>
#include <map>

using namespace std;

pair<int,vector<string>> solve(int t, int n){
    stringstream ss;
    ss << n;
    string s = ss.str();
    int l=s.size();
    map<int,vector<vector<string>>> ans;

    if(n <= t){
        ans[n] = {{s}};
    }
    for(int mask=1;mask<1<<(l-1);mask++){
        // {
        //     bool ok=true;
        //     for(int i=0;i<l-1;i++){
        //         if(mask>>i & 1){
        //             if(s[i+1]=='0'){
        //                 ok = false;
        //             }
        //         }
        //     }
        //     if(!ok) continue;
        // }
        vector<string> v = {""};
        v[0] += s[0];
        for(int i=0;i<l-1;i++){
            if(mask>>i & 1){
                v.push_back("");
            }
            v.back() += s[i+1];
        }
        int sum=0;
        for(int i=0;i<v.size();i++){
            sum += atoi(v[i].c_str());
        }
        if(sum <= t){
            ans[sum].push_back(v);
        }
    }


    if(ans.size()==0){
        return make_pair(-1,vector<string>{"error"});
    }
    else if(ans.rbegin()->second.size()>1){
        // for(int i=0; i<ans.rbegin()->second.size();i++){
        //     cout << " ";
        //     for(int j=0;j<ans.rbegin()->second[i].size();j++){
        //         cout << ans.rbegin()->second[i][j] << " ";
        //     }
        //     cout << endl;
        // }
        return make_pair(-1,vector<string>{"rejected"});
    }
    return make_pair(ans.rbegin()->first,*ans.rbegin()->second.begin());
}

int main(){
    int t,n;
    while(cin>>t>>n && t){
        auto a = solve(t,n);
        if(a.first!=-1){
            cout << a.first << " ";
            for(int i=0;i<(int)a.second.size();i++){
                cout << a.second[i] << (i+1==a.second.size() ? "\n" : " ");
            }
        }else{
            cout << a.second[0] << endl;
        }
    }
}

Measured memory_bytes: 1252
#!/usr/bin/env python
 
import sys
 
n= int(sys.stdin.readline())
ai = [ int(x) for x in sys.stdin.readline().split() ]

a = list(set(ai))
na= len(a)
ans= "No"
if na==1 and a[0]==0: ans="Yes"
elif na==2 and 0 in a:
    x= a[0]
    if x==0: x= a[1]
    if ai.count(x)==2*ai.count(0): ans= "Yes"
elif na==3:
    x,y,z= a
    if x^y^z: pass
    else:
        n,l,m= [ ai.count(i) for i in a ]
        if n==l==m: ans="Yes"
#
print( ans )


Measured memory_bytes: 14104
N = gets.to_i
as, bs = [], []
N.times do |i|
    as[i], bs[i] = gets.split.map(&:to_i)
end

ans = 0
(N-1).downto(0) do |i|
    as[i] += ans
    ans += (bs[i] - as[i] % bs[i]) % bs[i]
end

puts ans

Measured memory_bytes: 3440
def solve(X, Y, Z, V, E, A):
    dp = [[0.0] * 6001 for _ in range(Y + max(V) + 1)]
    dp[0][0] = 1.0
    for i in range(Y):
        for j in range(5001):
            if dp[i][j] <= 0.0:
                continue
            for k in V:
                t = i + k
                if t > Y:
                    dp[Y][j] += dp[i][j]/X
                elif E[t] == 1:
                    dp[min(Y, t+A[t])][j] += dp[i][j]/X
                else:
                    dp[t][max(0, j+A[t])] += dp[i][j]/X

    s = 0
    for i in range(5001):
        if dp[Y][i] <= 0.0:
            continue
        s += i * dp[Y][i]
    print(int(s))

if __name__ == "__main__":
    import sys

    while True:
        X, Y, Z = map(int, input().split())
        if X | Y | Z == 0:
            sys.exit()
        V = list(map(int, input().split()))
        E = [0] * 100
        A = [0] * 100
        for _ in range(Z):
            n, e, a = map(int, input().split())
            E[n] = e
            if e == 3:
                A[n] = -a
            else:
                A[n] = a
        solve(X, Y, Z, V, E, A)

Measured memory_bytes: 10736
a=int(input())
b=[input() for i in range(a)]
c=int(input())
d=[input() for i in range(c)]
 
yen=0
for i in set(b):
    num=b.count(i)
    num2=d.count(i)
    yen=max(yen,num-num2)
print(yen)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <set>

using namespace std;

int main(void){
	int n,in;
	int array[] = {4,9,4};
	while(cin>>n,n!=0){
		vector<vector<int> > summer(n,vector<int>(5));
	//	cout<<n<<endl;
		for(int i = 0 ; i < n ; i ++){
			int sum = 0;
			for(int j = 0 ; j < 4 ; j ++){
				cin>>in;
				if(j!=0)summer[i][4] += in * array[j-1];
				summer[i][j] = in;
			}
		}
		int array1[4];
		for(int i = 0 ; i < 4 ; i ++)cin>>array1[i];
	/*
		for(int i = 0 ; i < n ; i ++)
			for(int j = 0 ; j < 5 ; j ++)
				cout<<summer[i][j]<<(j==4?'\n':' ');
	// */
		bool miyaziri = true;
		for(int i = 0 ; i < n ; i ++){
			for(int j = 0 ; j < 4 ; j ++){
				if(summer[i][j+1] > array1[j])j = 4;
				//cout<<summer[i][j+1]<<" "<<array1[j]<<endl;
				if(j == 3){
					cout<<summer[i][0]<<endl;
					miyaziri = false;
				}
			}
		}	
		if(miyaziri)cout<<"NA"<<endl;
	}
}

Measured memory_bytes: 1268
import math
n = int(input())
g = 10 ** 15
a = math.floor(math.sqrt(n))
for i in range(1, a + 1):
    b = math.floor(n / i)
    if i * b == n:
        f = i + b - 2
        if g >= f:
            g = f
print(g)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
long long a,b,c;
int main()
{
    cin>>a>>b>>c;
    if(b>=a)
    {
        cout<<1<<endl;
        return 0;
    }
    if(c>=b)
    {
        cout<<-1<<endl;
        return 0;
    }
    cout<<((a-b)/(b-c)+((a-b)%(b-c)>=1))*2+1<<endl;
    return 0;
}

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

// typedef
// -----------------------------------------------------------------------------
typedef long long ll;
typedef long double ld;

// container util
// -----------------------------------------------------------------------------
#define ALL(c)  (c).begin(),(c).end()
#define SZ(c) ((ll)(c).size())
#define MAX(c) *max_element(ALL(c))
#define MIN(c) *min_element(ALL(c))
#define SORT(c) sort((c).begin(),(c).end())

// repetition
// -----------------------------------------------------------------------------
#define FOR(i, a, b) for(int i= (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

// constant
// -----------------------------------------------------------------------------
const int INF = 1e9;
const int MOD = 1e9 + 7;
const double EPS = 1e-9;
const double PI = acos(-1.0);

// debug
// -----------------------------------------------------------------------------
#define DUMP(x)  cerr << #x << " = " << (x) << endl


int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);
    ll N, A, B, C, D, E; cin >> N >> A >> B >> C >> D >> E;

    ll t1 = (N % A == 0) ? N / A : N / A + 1;

    ll t2 = (N % B == 0) ? N / B + 1 : N / B + 2;
    t2 = max(t1 + 1, t2);

    ll t3 = (N % C == 0) ? N / C + 2 : N / C + 3;
    t3 = max(t2 + 1, t3);

    ll t4 = (N % D == 0) ? N / D + 3 : N / D + 4;
    t4 = max(t3 + 1, t4);

    ll t5 = (N % E == 0) ? N / E + 4 : N / E + 5;
    t5 = max(t4 + 1, t5);

    cout << t5 << "\n";
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define reps(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; --i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define repc2(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define inf 2e9
#define linf 9000000000000000000ll
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int h, w;
int b_num, w_num;

bool seen[59][59];
int dist[59][59], M[59][59];
const int dx[] = {-1, 0, 0, 1};
const int dy[] = {0, -1, 1, 0};

void bfs(int sx, int sy) {
    queue<pair<int, int>> qu;
    qu.push(make_pair(sx, sy));
    seen[sy][sx] = true;
    while (!qu.empty()) {
        int ux = qu.front().first, uy = qu.front().second;
        qu.pop();
        rep(i, 4) {
            int nx = ux + dx[i], ny = uy + dy[i];
            if (nx >= 0 && nx < w && ny >= 0 && ny < h) {
                if (!seen[ny][nx] && M[ny][nx] == 0) {
                    seen[ny][nx] = true;
                    dist[ny][nx] = dist[uy][ux] + 1;
                    qu.push(make_pair(nx, ny));
                }
            }
        }
    }
}

int main() {
    cin >> h >> w;
    rep(y, h) rep(x, w) {
        char c;
        cin >> c;
        if (c == '.') {
            w_num++;
        } else {
            b_num++;
            M[y][x]++;
        }
    }
    bfs(0, 0);
    if (dist[h - 1][w - 1] == 0)
        cout << -1 << endl;
    else
        cout << (h * w - b_num - dist[h - 1][w - 1] - 1) << endl;
    return 0;
}

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

int main(){
    int N, idx ;
    cin >> N ;
    int A[N] = {0};
    rep(i,N-1){
        cin >> idx ;
        A[idx-1]++ ;
    }
    rep(i,N) cout << A[i] << endl;
}

Measured memory_bytes: 4412
N, K = map(int, input().split())
D    = list(map(str, input().split()))

for i in range(N, N*1000):
    A    = list(str(i))
    flag = True
    for a in A:
        if ( a in D ):
            flag = False
    if( flag == True):
        print(i)
        break

Measured memory_bytes: 3060
nl = lambda: list(map(int, input().split()))
sl = lambda: input().split()
n = lambda: int(input())
s = lambda: input()

Sa = s()
Sb = s()
Sc = s()

next_c = Sa[0]
Sa = Sa[1:]

cards = {}
cards['a'] = Sa
cards['b'] = Sb
cards['c'] = Sc

while True:
    if len(cards[next_c]) == 0:
        print(next_c.upper())
        break

    next_s = cards[next_c]
    cards[next_c] = next_s[1:]
    next_c = next_s[0]


Measured memory_bytes: 3064
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
#define MOD @
#define ADD(X,Y) ((X) = ((X) + (Y)%MOD) % MOD)
typedef long long i64; typedef vector<int> ivec; typedef vector<string> svec;

int Q;
i64 A[110], M[110];

i64 modpow(i64 a, i64 p, i64 M)
{
	if (p == 0) return 1 % M;
	i64 tmp = modpow(a, p / 2, M);
	tmp = tmp * tmp % M;
	if (p % 2 == 1) tmp = tmp * a % M;
	return tmp;
}
i64 gcd(i64 a, i64 b)
{
	return b == 0 ? a : gcd(b, a % b);
}

i64 solve(i64 a, i64 m)
{
	if (a == 0) {
		return m;
	}
	a %= m;

	if (gcd(a, m) != 1) {
		i64 lf = 1;
		for (int i = 0; i < 32; ++i) {
			if (lf % m == i % m) {
				return i;
			}
			lf = lf * a % m;
		}

		i64 g = gcd(a, m);
		i64 ad = a / g, md = m / g;
		i64 h = g;

		for (;;) {
			i64 aux = gcd(g, md);
			if (aux == 1) break;
			h *= aux;
			md /= aux;
		}

		return solve(modpow(a, h, m), md) * h;
	}
}

i64 euler(int a)
{
	int ret = 1;
	for (int i = 2; i * i <= a; ++i) {
		if (a % i == 0) {
			a /= i;
			ret *= i - 1;
			while (a % i == 0) {
				a /= i;
				ret *= i;
			}
		}
	}
	if (a > 1) ret *= a - 1;
	return ret;
}

i64 tower(i64 a, i64 m) {
	if (m == 1) {
		return 0;
	}
	i64 e = euler(m);
	i64 ret = modpow(a, 30 * e + tower(a, e), m);
	//printf("%lld %lld %lld\n", a, m, ret);
	return ret;
}

i64 extgcd(i64 a, i64 b, i64 m)
{
	if (a == 0) return 0;

	i64 g = gcd(a, m);
	if (g != 1) {
		if (b % g != 0) puts("><");
		return extgcd(a / g, b / g, m / g);
	}

	i64 s = m, t = 0;
	while (a != 1) {
		i64 k = s / a;
		i64 s2 = a;
		i64 t2 = b;

		//printf("%lld %lld %lld\n", a, b, m);
		a = s - a * k;
		b = (t + m - b * k % m) % m;
		s = s2;
		t = t2;
	}
	//printf("%lld %lld %lld\n", a, b, m);

	return (m - b) % m;
}

i64 solve2(i64 a, i64 m) {
	if (a == 0) return m;

	i64 p = euler(m);
	i64 mm = tower(a, m);
	i64 mp = tower(a, p);
	//printf("mm:%lld p:%lld mp:%lld\n", mm, p, mp);
	if (mm == 0 && mp == 0) return m * p;

	i64 x = extgcd(m % p, (mm - mp + p) % p, p);
	//printf("%lld\n", x);
	return x * m + mm;
}

int main()
{
	scanf("%d", &Q);
	for (int i = 0; i < Q; ++i) {
		scanf("%lld%lld", A + i, M + i);
		
		i64 ans = solve2(A[i] % M[i], M[i]);
		printf("%lld\n", ans);
		//printf("%lld %lld\n", ans % M[i], modpow(A[i], ans, M[i]));
	}
	return 0;
}


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

int main(){
	char a[800],b[800],wa[801],count;
	int N,i,ea,eb,c;
	
	scanf("%d",&N);
	while(N--){
		scanf(" %s ",a);
		scanf(" %s ",b);
		
		for(i=0;i<800;i++){
			if(a[i]=='\0')break;
		}
		ea=i;
		for(i=0;i<800;i++){
			if(b[i]=='\0')break;
		}
		eb=i;
		c=(ea<eb ? eb:ea);
		memset(wa,'0',sizeof(wa));
		wa[c+1]='\0';
		count=0;
		if(ea>eb){
			for(i=ea-1;i>=ea-eb;i--){
				wa[i+1]=a[i]-'0'+b[i-ea+eb]+count;
				count=0;
				if(wa[i+1]>=58){
					wa[i+1]=wa[i+1] - 10;
					count=1;
				}

			}
			
			for(i=ea-eb-1;i>=0;i--){
				wa[i+1]=a[i]+count;
				count=0;
				if(wa[i+1]>'9'){
					wa[i+1]=wa[i+1]-10;
					count=1;
				}
			}
		}else{
			for(i=eb-1;i>=eb-ea;i--){
				wa[i+1]=b[i]+a[i-eb+ea]+count-'0';
				count=0;
				if(wa[i+1]>=58){
					wa[i+1]=wa[i+1]-10;
					count=1;
				}

			}
			for(i=eb-ea-1;i>=0;i--){
				wa[i+1]=b[i]+count;
				count=0;
				if(wa[i+1]>'9'){
					wa[i+1]=wa[i+1]-10;
					count=1;
				}
			}
		}
		wa[0]=count+'0';
		if(wa[0]=='0'){
			for(i=0;i<=c;i++){
				wa[i]=wa[i+1];
			}
			c=c-1;
		}
		if(c>79){
			printf("overflow\n");
		}else{
			printf("%s\n",wa);
		}
	}
	return 0;
}

Measured memory_bytes: 0
h,w = map(int,input().split())
S = ["."*(w+2)]

for i in range(h):
    S.append("."+input()+".")
    
S.append("."*(w+2))

ans = "Yes"

for i in range(1,h+1):
    for j in range(1,w+1):
        if S[i][j] == "#":
            if S[i-1][j] != "#":
                if S[i][j-1]!="#" and S[i][j+1]!="#":
                    if S[i+1][j] != "#":
                        ans = "No"
                        break
                    
print(ans)

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

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define popb pop_back()
#define sz size()
#define y1 dfsdsfsdfsd
#define next fdsfsdfjkl
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long long ll;
typedef unsigned long long ull;
double pi = acos(-1.0);
const int inf = 1e9+7;
const ll INF = 1e18+7;
/////////////////////////////////////////



int n,m;

vector<int> d;
vector<int> find_dividers(int x) {
    vector<int> dividers;

    for (int i = 1; i <= sqrt(x); i++) {
        if (x % i == 0) {
            dividers.push_back(i);


            if (i * i != x) {
                dividers.push_back(x / i);
            }
        }
    }

    return dividers;
}
int main(){speed;
    cin>>n>>m;

    d  = find_dividers(m);

    int ans = -1;
    for(int i=0;i<d.sz;i++)
    {
       // cout<<d[i]<<" ";
        int x = m / d[i];

        if(x>=n) ans = max(ans,d[i]);
    }
    cout<<ans;
}


Measured memory_bytes: 256
import std.stdio, std.conv, std.string;

void main()
{
  while ( true ) {
	immutable int n = to!int( readln().strip() );
	if ( n == 0 ) break;

	int count = 0;
	bool right = false;
	bool left = false;
	bool isUp = false;
	foreach ( s; split( readln() ) ) {
	  switch ( s ) {
	  case "lu":
		left = true;
		break;
	  case "ld":
		left = false;
		break;
	  case "ru":
		right = true;
		break;
	  case "rd":
		right = false;
		break;
	  default :
	  }
	  if ( isUp && !right && !left ) {
		isUp = false;
		count++;
	  } else if ( !isUp && right && left ) {
		isUp = true;
		count++;
	  }
	}
	writeln( count );
  }
}

Measured memory_bytes: 1508
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <algorithm>
#include <cmath>
#include <vector>
#include <regex> //正規表現
#include <map>
#include <set>
#include <cassert> //assart
using namespace std;
#define ll long long int
#define FOR(i,min,max) for(int i=(min);i<(max);i++)
#define FOReq(i,min,max) for(int i=(min);i<=(max);i++)
#define FORREV(i,max,min) for(int i=(max)-1;i>=(min);i--)
const int  MOD=1e9+7;
const int  INF=2000000000;
const int INF2=  10000000;
const double  Micro=1e-5;

int UnUsedVariable(){
    if(INF || Micro || MOD || INF2){;}
    return 0;
}

#define pf printf
#define sf scanf
#define inarray(array,min,max) FOR(i,min,max){cin>>array[i];}
#define inarrayW(arrayA,arrayB,min,max) FOR(i,min,max){cin>>arrayA[i]>>arrayB[i];}
inline int isEven(int x){return x%2==0;}
inline int isOdd (int x){return x%2==1;}
#define br printf("\n");
#define OutputAndReturn0(x) {cout<<(x)<<endl;return 0;}

int printintN(int array[],const int num){
    for(int i=0;i<num;i++){printf("%d ",array[i]);}
    br;
    return 0;
}


//#define int long long int

/*
 1.困った時こそ冷静に問題文を見直す！制約条件を見ろ！乱択アルゴリズムとかO(N^3)とか！
 2.一度に大量のことをやろうとしない。デバッグしやすいように細かく！
 3.プログラミングは半分数学だし、もう半分は数学ではない！
 4.できない問題はできない！！！！！
 */

int experiment(){
    int N;cin>>N;
    int sum=0;
    int W[N];
    FOR(i, 0, N){
        cin>>W[i];
        sum+=W[i];
    }
    //cout<<sum<<"\n";
    int partsum=0;
    int ans=INF;
    FOR(i, 0, N){
        partsum+=W[i];
        ans=min(ans,abs(sum-2*partsum));
    }
    OutputAndReturn0(ans);
    return 0;
}
signed main(){
    assert(1);
    experiment();
    return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
#include <cmath>
#include <numeric>
#include <iomanip>

using namespace std;
long long a[100000];
vector <int> edges[100000];
bool used[100000];
bool used_in_ans[100000];

int dfs(int cur){
    used[cur] = true;
    int ret = cur;
    long long ret_a = a[cur];
    for(int i = 0; i < edges[cur].size(); i++){
        int next = edges[cur][i];
        if(!used[next]){
            int tmp = dfs(next);
            if(ret_a > a[tmp]){
                ret = tmp;
                ret_a = a[tmp];
            }
        }
    }
    return ret;
}

int main(){
    int N;
    int M;
    cin >> N >> M;
    for(int i = 0; i < N; i++){
        cin >> a[i];
    }
    for(int i = 0; i < M; i++){
        int x;
        int y;
        cin >> x >> y;
        edges[x].push_back(y);
        edges[y].push_back(x);
    }
    
    int cc_num = 0;
    long long ans = 0;
    for(int i = 0; i < N; i++){
        if(!used[i]){
            cc_num ++;
            int min_ind = dfs(i);
            used_in_ans[min_ind] = true;
            ans += a[min_ind];
        }
    }

    if(N < 2 * (cc_num - 1)){
        cout << "Impossible" << endl;
        return 0;
    }
    if(cc_num == 1){
        cout << 0 << endl;
        return 0;
    }
    int used_num = cc_num;
    vector <pair <long long, int> > a_ind;
    for(int i = 0; i < N; i++){
        a_ind.push_back(make_pair(a[i], i));
    }
    sort(a_ind.begin(), a_ind.end());
    for(int i = 0; i < N; i++){
        if(used_num >= 2 * (cc_num - 1)){
            break;
        }
        if(!used_in_ans[a_ind[i].second]){
            ans += a_ind[i].first;
            used_num ++;
        }
        
    }
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 8948
#include <iostream>
#include <cmath>
#include <tr1/unordered_map>

using namespace std;

#define fi first
#define se second

typedef pair<double, double> P;
int N;
P h, d, cs[20];

#define SQ(x) ((x)*(x))

inline double getDist(P a, P b) {
  return sqrt(SQ(a.fi-b.fi) + SQ(a.se-b.se));
}

double dist[22][22];

using namespace tr1;
unordered_map<int, double> mp;

bool dfs(int S, int now, double cost) {
  
  if(S == (1<<N)-1) {
    return true;
  }
  
  for(int i=0; i<N; i++) {
    if(S >> i & 1) continue;
    if(dist[i][N+1] <= cost + dist[now][i]) return false;
  }
  
  for(int i=0; i<N; i++) {
    if(S >> i & 1) continue;
    if(mp.count(S+(1<<i)) && mp[S+(1<<i)] <= cost+dist[now][i]) continue;
    mp[S+(1<<i)] = cost+dist[now][i];
    if(dfs(S+(1<<i), i, cost+dist[now][i])) return true;
  }
  
  return false;
}

bool solve() {
  
  mp.clear();
  
  for(int i=0; i<N; i++) {
    for(int j=i+1; j<N; j++) {
      dist[i][j] = dist[j][i] = getDist(cs[i], cs[j]);
    }
    dist[i][N] = dist[N][i] = getDist(cs[i], h);
    dist[i][N+1] = dist[N+1][i] = getDist(cs[i], d);
  }
  
  for(int i=0; i<N; i++) {
    if(dist[i][N+1] <= dist[i][N]) continue;
    if(dfs(1<<i, i, dist[N][i])) return true;
  }
  return false;
}

int main() {
  
  while(cin >> N >> h.fi >> h.se >> d.fi >> d.se && (N)) {
    for(int i=0; i<N; i++) {
      cin >> cs[i].fi >> cs[i].se;
    }
    
    cout << (solve() ? "YES" : "NO") << endl;
  }
  
  return 0;
}

Measured memory_bytes: 15152
n,a,b,c = map(int, input().split())
l = [int(input()) for _ in range(n)]
answer = a+b+c
def Base_10_to_n(X, n):
    if (int(X/n)):
        return Base_10_to_n(int(X/n), n)+str(X%n)
    return str(X%n)
  
for i in range(1, 4**n):
  aa = []
  bb = []
  cc = []
  four = list(str(Base_10_to_n(i,4).zfill(n)))
  
  if four.count("1")==0 or four.count("2")==0 or four.count("3") ==0:
    continue
  for index,f in enumerate(four) :
    if f == "0": #使わない
      continue
    elif f == "1":
      aa.append(l[index])
    elif f == "2":
      bb.append(l[index])
    elif f == "3":
      cc.append(l[index])
    else:
      break
  cur = (len(aa)-1)*10+abs(a-sum(aa))+(len(bb)-1)*10+abs(b-sum(bb))+(len(cc)-1)*10+abs(c-sum(cc))
  answer = min(answer, cur)


  
print(answer)
    
  

Measured memory_bytes: 3188
#![allow(unused_macros)]
#![allow(dead_code)]
#![allow(unused_imports)]

use itertools::Itertools;
use text_io::*;

fn main() {
    const U_INF: usize = 1 << 50;
    const I_INF: isize = 1 << 50;

    let s: String = read!();
    let t: String = read!();
    let s = s.chars().collect_vec();
    let t = t.chars().collect_vec();

    let mut dp = vec![vec![0; t.len() * 2]; s.len() * 2];

    for i in 1..=s.len() {
        for j in 1..=t.len() {
            if s[i - 1] == t[j - 1] {
                dp[i][j] = dp[i][j].max(dp[i - 1][j - 1] + 1);
            } else {
                dp[i][j] = dp[i][j].max(dp[i][j - 1]).max(dp[i - 1][j]);
            }
        }
    }


    let mut i = s.len();
    let mut j = t.len();
    let mut res = "".to_string();
    loop {
        let a = dp[i][j];
        if a == 0 {
            break;
        } else if a == dp[i][j - 1] {
            j -= 1;
            continue;
        } else if a == dp[i - 1][j] {
            i -= 1;
            continue;
        } else {
            res.push(s[i - 1]);
            i -= 1;
            j -= 1;
        }
    }

    let res = res.chars().rev().collect::<String>();
    println!("{}", res);
}


Measured memory_bytes: 142996
#include <cstdio>
#include <cstdlib>
#include <cstring>

int main(){
	char a[20],b[20],c[20];

	scanf("%s %s %s",a,b,c);

	if(a[strlen(a)-1]==b[0]&&b[strlen(b)-1]==c[0]){
		printf("YES\n");
	}else{
		printf("NO\n");
	}

	return 0;
}


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

namespace AtTest.D_Challenge
{
    class ABC_074
    {
        static void Main(string[] args)
        {
            Method(args);
            Console.ReadLine();
        }

        static void Method(string[] args)
        {
            int n = ReadInt();
            var distances = new long[n * (n - 1) / 2][];
            int itr = 0;
            for (int i = 0; i < n; i++)
            {
                long[] dist = ReadLongs();
                for (int j = i + 1; j < n; j++)
                {
                    distances[itr] = new long[3] { dist[j], i, j };
                    itr++;
                }
            }
            distances = distances.OrderBy(a => a[0]).ToArray();
            var tempDists = new long[n, n];
            for(int i = 0; i < n; i++)
            {
                for(int j = 0; j < n; j++)
                {
                    if (i != j)
                        tempDists[i, j] = -1;
                }
            }

            long res = 0;
            for (int i = 0; i < distances.Length; i++)
            {
                long minDist = long.MaxValue;
                int start = (int)distances[i][1];
                int goal = (int)distances[i][2];
                for(int j = 0; j < n; j++)
                {
                    if (tempDists[start, j] == -1
                        || tempDists[j, goal] == -1) continue;

                    long dist = tempDists[start, j] + tempDists[j, goal];
                    minDist = Math.Min(minDist, dist);
                }
                if (minDist > distances[i][0])
                {
                    tempDists[start, goal] = distances[i][0];
                    tempDists[goal,start] = distances[i][0];
                    res += distances[i][0];
                }
                else if (minDist == distances[i][0])
                {
                    tempDists[start, goal] = distances[i][0];
                    tempDists[goal,start] = distances[i][0];
                }
                else if (minDist < distances[i][0])
                {
                    Console.WriteLine(-1);
                    return;
                }
            }
            /*for(int i = 0; i < n; i++)
            {
                for(int j = 0; j < n; j++)
                {
                    Console.Write(tempDists[i, j] + " ");
                }
                Console.WriteLine();
            }*/
            Console.WriteLine(res);
        }

        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


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

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

    int n;
    cin >> n;
    vector<int> p(n);
    REP(i, n){
        cin >> p[i];
        p[i]--;
    }

    int ans = 0;
    REP(i, n - 1){
        if(i == p[i]){
            swap(p[i], p[i + 1]);
            ans++;
        }
    }
    if(p[n - 1] == n - 1) ans++;

    cout << ans << endl;


    return 0;
}

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

int A,B;
vector<int>a,b;
int main(){
    cin>>A>>B;
    a.resize(A);b.resize(B);
    for(int i=0;i<A;i++)cin>>a[i];
    for(int i=0;i<B;i++)cin>>b[i];

    int ma=0;

    for(int i=0;i<B;i++){
        int cnt=0,cur=0;
        for(int j=i;j<B;j++){
            while(cur<A&&a[cur]!=b[j])cur++;
            if(cur==A)continue;
            cnt++;
            cur++;
        }
        ma=max(ma,cnt);
    }

    cout<<ma<<endl;
    return 0;
}

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

int main() {
  int r, g, b, n;
  cin >> r >> g >> b >> n;
  long long ans=0;
  for (int i=0; i<=3000; i++) {
    for (int j=0; j<=3000; j++) {
      long long sum=n-r*i-g*j;
      if (sum%b==0 && sum>=0) ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define VS vector<string>
#define VB vector<bool>
#define VP vector<pair<ll,ll>>
#define VVL vector<vector<ll>>
#define VVP vector<vector<pair<ll,ll>>>
#define PL pair<ll,ll>
#define ALL(v) (v).begin(), (v).end()


int main() {
    string S;
    cin>>S;
    bool f=true;
    rep(i,0,S.size()){
        ll j=i+1;
        if(S[i]=='R'&&j%2==1)continue;
        else if(S[i]=='L'&&j%2==0)continue;
        else if(S[i]=='U'||S[i]=='D')continue;
        else f=false;
    }
    cout<<(f ? "Yes":"No")<<endl;
    return 0;
}

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

typedef long long ll;
typedef pair<ll, ll> pll;
const ll mod=1000000007;
const char nl='\n';


ll N,tw;
ll W[110],V[110], dp[110][100010]={0};



ll rec(ll w, ll cur){
    if(w==0 || cur==0) return 0;
    if(dp[cur][w]!=0) return dp[cur][w];
    if(w-W[cur]<0) return rec(w, cur-1);

    return dp[cur][w]=max(V[cur]+rec(w-W[cur],cur-1), rec(w, cur-1));
}

void solve()
{
    ll i,j,k,l,m,n,u,v,x,y,z,q,p,h;
    cin>>N>>tw;
    for(i=1;i<=N;i++) cin>>W[i]>>V[i];
    cout<<rec(tw, N);
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t = 1;
//    cin >> t;
	while (t--)
	{
		solve();
	}
	return 0;
}


Measured memory_bytes: 70108
#ifndef CLASS_DISJOINT_SET
#define CLASS_DISJOINT_SET

#include <cstddef>

class disjoint_set {
private:
	std::size_t n, * par, * sz;
public:
	disjoint_set() : n(0) {};
	disjoint_set(std::size_t n_) : n(n_) { par = new std::size_t[n]; sz = new std::size_t[n]; for (std::size_t i = 0; i < n; ++i) par[i] = i, sz[i] = 1; }
	~disjoint_set() { delete[] par; delete[] sz; }
	disjoint_set& operator=(const disjoint_set& ds) { n = ds.n; par = new std::size_t[n]; sz = new std::size_t[n]; for (std::size_t i = 0; i < n; ++i) par[i] = ds.par[i], sz[i] = ds.sz[i]; }
	std::size_t size() const { return n; }
	std::size_t size(std::size_t vert) { return sz[root(vert)]; }
	std::size_t root(std::size_t vert) {
		// path halving
		while (par[vert] != vert) {
			par[vert] = par[par[vert]];
			vert = par[vert];
		}
		return vert;
	}
	void link(std::size_t vertx, std::size_t verty) {
		vertx = root(vertx);
		verty = root(verty);
		if (vertx == verty) return;
		if (sz[vertx] > sz[verty]) sz[vertx] += sz[verty], sz[verty] = 0, par[verty] = vertx;
		else sz[verty] += sz[vertx], sz[vertx] = 0, par[vertx] = verty;
	}
	bool connected(std::size_t vertx, std::size_t verty) {
		return root(vertx) == root(verty);
	}
};

#endif // CLASS_DISJOINT_SET

#include <cmath>
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	int N, M, K;
	cin >> N >> M >> K;
	vector<int> A(M), B(M), C(K), D(K);
	for (int i = 0; i < M; ++i) {
		cin >> A[i] >> B[i];
		--A[i], --B[i];
	}
	for (int i = 0; i < K; ++i) {
		cin >> C[i] >> D[i];
		--C[i], --D[i];
	}
	disjoint_set uf(N);
	for (int i = 0; i < M; ++i) {
		uf.link(A[i], B[i]);
	}
	vector<int> cand(N, 0);
	long long ans = 0;
	for (int i = 0; i < N; ++i) {
		int sz = uf.size(i);
		cand[i] += sz - 1;
	}
	for (int i = 0; i < M; ++i) {
		--cand[A[i]];
		--cand[B[i]];
	}
	for (int i = 0; i < K; ++i) {
		if (uf.root(C[i]) == uf.root(D[i])) {
			--cand[C[i]];
			--cand[D[i]];
		}
	}
	for (int i = 0; i < N; ++i) {
		if (i) cout << ' ';
		cout << cand[i];
	}
	return 0;
}

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

int main() {
  int N,A;
  cin>>N;
  
  vector<int> vec(N);
  
  rep(i,N-1){cin >> A;
          vec.at(A-1)++;}
  rep(i,N){cout<<vec.at(i)<<endl;}
}

Measured memory_bytes: 3980
/*数字列Sを文字列として読み込む、また配列の終わりは'\0'で判断できるのでそれでfor文を回す*/
/*これを行うことで4桁の数字を一つずつの数字に分解する部分の工程が必要なくなるのでスマートだ*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <stdbool.h>
#define LL long long
#define INF 1<<31-1
#define MIN(x,y) ((x)<(y)?(x):(y))
#define MAX(x,y) ((x)<(y)?(y):(x))

int main()
{
    char s[10];
    scanf("%s", s);
    
    for(int i = 0; s[i+1] !='\0'; i++){
        if(s[i] == s[i+1]) {printf("Bad\n"); return 0;}
    }
    printf("Good\n");
    
    return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
#include <math.h>

double jijo(double a){
	return a*a;
}

int main(){
	int n,i;
	double x1, y1, x2, y2, x3, y3;
	double a1, a2, b1, b2;
	double x, y, d;

	scanf("%d", &n);
	for(i = 0; i < n; i++){
		scanf("%lf %lf %lf %lf %lf %lf", &x1, &y1, &x2, &y2, &x3, &y3);
		

		if(y1==y2){y1+=0.0000001;}

		a1 = (x2-x1)/(y1-y2);
		b1 = (y1+y2)/2.0 - a1*(x1+x2)/2.0;
		if(y1==y3){y1+=0.0000001;}
		a2 = (x3-x1)/(y1-y3);
		b2 = (y1+y3)/2.0 - a2*(x1+x3)/2.0;
		
		x = (b2-b1)/(a1-a2);
		y = a1*x + b1;
		d = sqrt(jijo(x1-x) + jijo(y1-y));
		printf("%.3lf %.3lf %.3lf\n", x, y, d);
	}
	return 0;
}

Measured memory_bytes: 664
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define IOS                  \
    ios::sync_with_stdio(0); \
    cin.tie(0);              \
    cout.tie(0)
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define repd(i, a, b) for (int i = a; i >= (b); --i)
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
template <typename H>
bool chmin(H &v1, const H v2)
{
    if (v1 > v2)
    {
        v1 = v2;
        return true;
    }
    return false;
}
template <typename H>
bool chmax(H &v1, const H v2)
{
    if (v1 < v2)
    {
        v1 = v2;
        return true;
    }
    return false;
}
typedef long long ll;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fll;
const ll m = 1e9 + 7;

int main()
{
    int n;
    cin >> n;
    if (n <= 1)
        cout << 0 << endl;
    else if (n >= 2)
    {
        ll m10 = 1;
        ll m8 = 1;
        ll m9 = 1;
        rep(i, 0, n)
        {
            m10 = m10 * 10 % m;
            m8 = m8 * 8 % m;
            m9 = m9 * 9 % m;
        }
        cout << (m10 - m8 - (m9 - m8) * 2 + 3 * m) % m << endl;
    }
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long n,d,k=1;
    long long minx=10000;
    cin>>n;
    while(1){
        d=n/k%1000;
        if(d<100){
            break;
        }
        else if(abs(753-d)<minx){
            minx=abs(753-d);
        }
        k*=10;
        
    }
    cout<<minx<<endl;
    return 0;
}


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

int main() {
    
    long long int n,i,j,flag=0;
    cin>>n;
    for(i=1;i<10;i++)
    {
        for(j=i;j<10;j++)
        {
            if(n==i*j)
            {
                flag=1;break;
            }
        }
    }
    if(flag==1)
    {
        cout<<"Yes";

    }
    else
    {
    cout<<"No";
    }

    
}
    


Measured memory_bytes: 256
from heapq import heappush, heappop
import sys
sys.setrecursionlimit(10 ** 7)
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


n,q=map(int,readline().split())

stx=[[int(x) for x in readline().split()] for _ in range(n)]
event=[]
for s,t,x in stx:
    event.append((s-x,1,x))
    event.append((t-x,-1,x))

for i in range(q):
    event.append((int(readline()),2,i))
event.sort()

ans=[0]*q

stop=set()
hq=[]
for t,op,x in event:
    if op==1:
        heappush(hq,x)
        stop.add(x)
    elif op==-1:
        stop.remove(x)

    else:
        while hq and hq[0] not in stop:
            heappop(hq) 
        ans[x]=hq[0] if hq else -1
    
for x in ans:
    print(x)

Measured memory_bytes: 133912
#include <bits/stdc++.h>
using namespace std;
#define REP(i,N) for(i=0;i<N;i++)
#define INF 1e9
typedef long long ll;
typedef pair<int,int> P;

int main(void){
  int N,M,Q;cin >> N >> M >> Q;
  int i,j,k;
  P input[M];
  vector<vector<int> > Comp(N,vector<int>(N,0));
  vector<vector<int> > c(N,vector<int>(N,0));
  REP(k,M){
    int x,y;
    cin >> x >> y; 
    int i = x-1,j = y-1;
    Comp[i][j]++;
  }
  REP(i,N){
    c[i][0] = Comp[i][0];
    for(j=1;j<N;j++){
      c[i][j] = c[i][j-1]+Comp[i][j];
    }
  }
  vector<int> ans;
  REP(k,Q){
    int l,r;
    cin >> l >> r;
    l--;r--;
    int sum = 0;
    for(i=l;i<=r;i++){
      sum += c[i][r] - c[i][l-1];
    }
    ans.push_back(sum);
  }
  REP(i,ans.size()) cout << ans[i] << endl;
  return 0;
}


Measured memory_bytes: 4988
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <queue>
#include <unordered_map>
#include <stack>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;

using namespace std;

template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

#define INF 1000000
vector<int> ds(100, INF);
vector<int> fs(100);
int t = 0;

vector<vector<int>> edges;
bool dfs(int now){
    if(ds[now] != INF)
        return false;
    t++;
    ds[now] = t;
    for(auto it = edges[now].begin(); it != edges[now].end();it++) {
        bool flag = dfs(*it);
        // t++;
    }
    // if(edges[now].size() == 0)
    t++;
    fs[now] = t;
    return true;
}

int check(int n) {
    rep(i, n) {
        if(ds[i] == INF)
            return i;
    }
    return -1;
}

int main(){
    int n; cin >> n;
    vector<int> tmp;
    rep(i, n) {
        edges.push_back(tmp);
        int id, num; cin >> id >> num;
        rep(j, num) {
            int dst; cin >> dst;
            dst--;
            edges[i].push_back(dst);
        }
        // sort(edges[i].rbegin(), edges[i].rend());
    }
    dfs(0);
    while(check(n) != -1) {
        dfs(check(n));
    }
    rep(i, n) {
        cout << i + 1 << " " << ds[i] << " " << fs[i] << endl;
    }
}



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

int selection(int *r, int n);



int main(){
    int n,c;
    int r[1000];
    cin>>n;
    for(int i=0;i<n;i++) cin>>r[i];
    c=selection(r,n);
    for(int j=0;j<n;j++){
        if(j!=n-1)cout<<r[j]<<' ';
        else cout<<r[n-1]<<endl;
    }
    cout<<c<<endl;

    
}




int selection(int *r, int n){
    int minj,tmp;
    int c=0;
    int flag=1;
    for(int i=0;i<n;i++){
        minj=i;
        flag=1;
        for(int j=i;j<n;j++){
            if(r[minj]>r[j]){
                minj=j;
                if(flag){
                    c++;
                    flag=0;
                }
            }
        }
        tmp=r[minj];
        r[minj]=r[i];
        r[i]=tmp;
    }
    return c;
}



Measured memory_bytes: 3124
n = int(input())
p = [0] * (n + 1)
for i in range(n):
    p[int(input())] = i

maxSet = 0

temp = 1
i = 2
while i <= n:
    if p[i - 1] < p[i]:
        temp += 1
        i += 1
    else:
        maxSet = max(maxSet, temp)
        temp = 1
        i += 1
maxSet = max(maxSet, temp)
print(n - maxSet)


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

typedef long long ll;
using namespace std;

int main() {
    ll n;
    cin >> n;
    if (n == 2) {
        cout << 1 << endl;
        return 0;
    }
    ll ans = 2;
    vector<ll> nums;
    for (ll i = 2; i * i <= n; i++) {
        if (n % i == 0) {
            ll t = n;
            while (t % i == 0)
                t /= i;
            if (t % i == 1)
                ans++;
        }
        if (n % i == 1) {
            if (i * i == n - 1) {
                ans++;
            } else if (i * i < n - 1) {
                ans += 2;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
h, w, d = map(int, input().split())
X = [None for k in range(h*w)]
for i in range(h):
    *A, = map(int, input().split())
    for j in range(w):
        X[A[j]-1] = (i, j)
D = []
for k in range(h*w):
    if k < d:
        D.append(0)
    else:
        x0, y0 = X[k]
        x1, y1 = X[k-d]
        D.append(D[k-d]+abs(x0-x1)+abs(y0-y1))
q = int(input())
for _ in range(q):
    l, r = map(int, input().split())
    print(D[r-1]-D[l-1])


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

int main(void) {
    string a, b;
    cin >> a >> b;
    if (a.size() > b.size()) {
        cout << "GREATER" << endl;
        return 0;
    }
    if (a.size() < b.size()) {
        cout << "LESS" << endl;
        return 0;
    }
    {
        for (int i = 0; i < (int)a.size(); i++) {
            if (a.at(i) > b.at(i)) {
                cout << "GREATER" << endl;
                return 0;
            }
            if (a.at(i) < b.at(i)) {
                cout << "LESS" << endl;
                return 0;
            }
        }
        cout << "EQUAL" << endl;
    }
    return 0;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string a,b;
  int cnt=0;
  	cin>>a>>b;
  	for(int i=0;i<a.size();i++)
    {
      if(a[i]==b[i])
        cnt++;
      else
        break;
    }
  if(cnt==a.size()&&a.size()==b.size()-1)
    cout<<"Yes";
  else
    cout<<"No";
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> P;
map <int,bool> mp;
vector<int> V;
list<int> L;
stack<int> S;
queue<int> Q;
deque<int> dq;
#define INF (1<<30)
#define INFLL (1ll<<60)
#define EPS (1e-10)
static const int MAX=1e4;
static const int MOD=1e9+7;
static const int NMAX=50;
static const int MMAX=50;
int K,N,d,n;

map<int,int> mp2;
void cuntDigit(int n){
    mp2.clear();
    while(n){
        mp2[n%10]++;
        n/=10;
    }
}

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

    cin>>N>>K;
    for(int i=0;i<K;i++){
        cin>>d;
        mp[d]=true; //嫌いならtrue
    }
    
    int n=1;
    while(1){
        cuntDigit(n);
        bool flag=false;
        for(auto p1:mp2){
            if(mp[p1.first])flag=true; //嫌いリストにあったらtrue
        }
        if(n>=N&&!flag)break;
        n++;
    }
    cout<<n<<"\n";
    
    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 a = sc.nextInt();
        int b = sc.nextInt();

        System.out.println(a*a-b);
    }

    public static void printArray(int[] array){
        for(int i=0; i<array.length; i++){
            if(i == array.length){
                System.out.println(array[i]);
            } else {
                System.out.print(String.format("%d ", array[i]));
            }
        }
    }
}


Measured memory_bytes: 21844