akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

int main()
{
    ios_base::sync_with_stdio(NULL);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n;
    cin>>n;
    ll x;
    cin>>x;
    ll m;
    cin>>m;
    ll prev=x;
    ll sum=x;
    map<ll,ll> mp;
    mp[x]=1;
    vector<ll> tmp;
    tmp.push_back(x);
    ll req;
    int id;
    for(ll i=2; i<=n; i++)
    {
        prev=(prev*prev)%m;
        tmp.push_back(prev);
        if(prev==0)
        {
            break;
        }
        if(mp[prev]==1)
        {
            id=i;
            req=prev;
            break;
        }
        sum +=prev;
        mp[prev]=1;
        //getchar();
    }
    tmp.pop_back();
    reverse(tmp.begin(),tmp.end());
    while(tmp.size() && tmp.back()!=req)
    {
        tmp.pop_back();
    }
    reverse(tmp.begin(),tmp.end());
    if(tmp.size())
    {
        id--;
        ll op=0;
        for(int i=0;i<tmp.size();i++)
        {
            op += tmp[i];
        }
        ll baki=n-id;
        ll sz=tmp.size();
        ll ex=baki/sz;
        sum += (op*ex);
        ex=baki%sz;
        for(int i=0;i<ex;i++)
        {
            sum += tmp[i];
        }
    }
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 6724
import itertools
D, G = map(int,input().split())
PC = [list(map(int,input().split())) for _ in range(D)]
result = 10**18
for s in itertools.product(range(3), repeat = D):
    s = list(s)
    t = sorted(s, reverse=True)
    idx = 0
    SUM = 0
    ans = 0
    while True:
        if G <= SUM:
            break
        if idx == D:
            ans = 10**18
            break
        if t[idx] == 2:
            SUM += PC[s.index(2)][0] * 100 * (s.index(2)+1) + PC[s.index(2)][1]
            ans += PC[s.index(2)][0]
            s[s.index(2)] = 4
        elif t[idx] == 1:
            if G-SUM >= PC[s.index(1)][0] * 100 * (s.index(1)+1):
                SUM += (PC[s.index(1)][0]-1) * 100 * (s.index(1)+1)
                ans += PC[s.index(1)][0]-1
                s[s.index(1)] == 4
            else:
                if (G-SUM) % (100*(s.index(1)+1)) == 0:
                    ans += (G-SUM) // (100 * (s.index(1)+1))
                    break
                else:
                    ans += ((G-SUM) // (100 * (s.index(1)+1))) + 1
                    break
        idx += 1
    result = min(result, ans)
print(result)


Measured memory_bytes: 3064
n = int(input())
a_list = list(map(int,input().split()))
q = int(input())
ans = sum(a_list)
import collections
counter = collections.Counter(a_list)
for i in range(q):
  b,c = map(int,input().split())
  counter[c] += counter[b]
  ans = ans + ((c-b) * counter[b])
  counter[b] = 0
  
  print(ans)
  


Measured memory_bytes: 23848
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
inline int read()
{
	int x=0,f=1;char c=getchar();
	while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
	while(isdigit(c))x=x*10+c-'0',c=getchar();
	return x*f;
}
int a,b,c;
int main()
{
	a=read(),b=read(),c=read();
	if(a==b)printf("%d\n",c);
	else if(b==c) printf("%d\n",a);
	else if(c==a) printf("%d\n",b);
	return 0; 
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
  using namespace std;
#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) int ab;cin>>ab;(p).push_back(ab);
#define vecpl2(p) long long ab;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define set0(k,n) for(int nn=0;nn<(n);nn++){ (k).push_back(0); }
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define vecsize(b,size) vector<int> (b)((size));
#define pb(b,a) (b).push_back((a));

 		
int main() {

int N,M,Q;
cin>>N>>M>>Q;
int field[N+2][N+2];
map<int,int> c;
fx(N+2){
	fy(N+2){
		field[x][y]=0;
	}
}

fx(M){
int a,b;
	cin>>a>>b;
	field[a][b]++;

}

fx(Q){
	int a,b;
	cin>>a>>b;
	if(c[a*1000+b]>0){
	 ce(c[a*1000+b])
      }else{
	int ans=0;
	fyg(b+1,a){
		fzg(b+1,y){
			ans+=field[y][z];
		}
	}
	ce(ans)
c[a*1000+b]=ans;
     }
}

	
}

Measured memory_bytes: 4992
let N = Int(readLine()!)!

var dp: [[Int]] = .init(repeating: .init(repeating: 0, count: N), count: N)

let a = readLine()!.split(separator: " ").map { Int($0)! }

for i in 0..<N {
  dp[i][i] = a[i]
}

for l in 1..<N {
  for row in 0..<N-l {
    let col = row + l
    dp[row][col] = max(a[row] - dp[row + 1][col], a[col] - dp[row][col - 1])
  }
}
print(dp[0][N-1])

Measured memory_bytes: 78740
#include <stdio.h>
#include <string.h>
int main(void) {
  char s[1000];
  scanf("%s", s);
  int i, flag = 0;
  for (i = 0; i < strlen(s); i++) {
    if (i % 2 == 0) {
      switch (s[i]) {
        case 'R':
          break;
        case 'U':
          break;
        case 'D':
          break;
        default:
          flag = 1;
          break;
      }
    } else {
      switch (s[i]) {
        case 'L':
          break;
        case 'U':
          break;
        case 'D':
          break;
        default:
          flag = 1;
          break;
      }
    }
  }
  if (flag == 0) {
    puts("Yes");
  } else {
    puts("No");
  }
}


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

class Hash {
private:
	static const int MOD = 1046527;
	
	int my_ctoi(char c) {
		if (c == 'A') return 0;
		if (c == 'C') return 1;
		if (c == 'G') return 2;
		if (c == 'T') return 3;
		return 4;
	}
	
	int getKey(const string& str) {
		int key = 0;
		size_t len = str.size();
		for (size_t i = 0; i < len; ++i) key = 5 * key + my_ctoi(str[i]);
		return key;
	}
	
	int hash1(int key) {
		return key % MOD;
	}
	
	int hash2(int key) {
		return 1 + (key % (MOD - 1));
	}
	
public:
	Hash() {}
	
	int getHash(const string& str, int collision_count) {
		int key = getKey(str);
		return (hash1(key) + collision_count * hash2(key)) % MOD;
	}
};

class Dictionary {
private:
	string NIL;
	vector< string > table;
	
	Hash hash;
	
public:
	Dictionary() {
		NIL = "#";
		table.assign(1046527, NIL);
	}
	
	void insert(string& str) {
		int collision_count = 0;
		
		while (1) {
			int hs = hash.getHash(str, collision_count);
			
			if (table[hs] == NIL) {
				table[hs] = str;
				break;
			} else {
				++collision_count;
			}
		}
	}
	
	bool find(string& str) {
		int collision_count = 0;
		
		while (1) {
			int hs = hash.getHash(str, collision_count);
			
			if (table[hs] == str) {
				return true;
			} else if (table[hs] == NIL) {
				return false;
			} else {
				++collision_count;
			}
		}
	}
};

int main() {
	Dictionary dict;
	
	int n;
	cin >> n;
	
	char buf1[128], buf2[128];
		
	for (int i = 0; i < n; ++i) {
		scanf("%s %s", buf1, buf2);
		
		string op(buf1), str(buf2);
		
		if (op == "insert") {
			dict.insert(str);
		}
		
		if (op == "find") {
			if (dict.find(str)) puts("yes");
			else puts("no");
		}
	}
}

Measured memory_bytes: 35916
import numpy as np

K,X = map(int, input().split())

S = np.arange(X-K+1, X+K)

if X-K+1 >= -1000000:
    if X+K-1 <= 1000000:
        print(*S)
    else:
        print(*np.arange(X-K+1, 1000001))
else:
    if X+K-1 <= 1000000:
        print(*np.arange(-1000000, X+K))
    else:
        print(*np.arange(-1000000, 1000001))    

Measured memory_bytes: 21272
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h>
int main(int argc, char const *argv[])
{
    char N[200001];
    scanf("%s", N);
    int count = 0;
    for (int i = 0; N[i] != '\0'; i++)
    {
        count += N[i] - '0';
    }
    if (count % 9 == 0)
    {
        puts("Yes");
    }
    else
    {
        puts("No");
    }

    return 0;
}


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

//#define debug

typedef long long ll;
vector<ll> w, v;
map<ll, vector<ll> > mp;
vector<vector<ll> > vv;
vector<ll> vw;
int N;
ll W;

void solve(int cur, int total, ll sum_w, ll sum_v, ll & ans){
    if(cur==total){
        ans=max(ans, sum_v);
        return ;
    }
    for(int i=0; i<vv[cur].size(); ++i){
        if(i*1ll*vw[cur]+sum_w>W)
            break;
        solve(cur+1, total, i*1ll*vw[cur]+sum_w, sum_v+vv[cur][i], ans);
    }
}


int main(){
#ifdef debug
    freopen("test.in", "r", stdin);
#endif
    cin>>N>>W;
    w.resize(N); v.resize(N);
    for(int i=0; i<N; ++i){
        cin>>w[i]>>v[i];
        mp[w[i]].push_back(v[i]);
    }
    for(map<ll, vector<ll> >::iterator it=mp.begin(); it!=mp.end(); ++it){
        sort(it->second.begin(), it->second.end());
        reverse(it->second.begin(), it->second.end());
    }
    for(map<ll, vector<ll> >::iterator it=mp.begin(); it!=mp.end(); ++it){
        vw.push_back(it->first);
        vv.push_back(vector<ll>(it->second.size()+1, 0));
        for(int i=0; i<it->second.size(); ++i){
            vv.back()[i+1]=vv.back()[i]+it->second[i];
        }
    }
    ll ans=0;
    solve(0, vv.size(), 0, 0, ans);
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cfloat>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define int long long
#define ll long long
#define eps LDBL_EPSILON
#define mod (ll)1000000007
#define INF LLONG_MAX/10
#define P pair<int,int>
#define prique priority_queue
using namespace std;
int n, m, a[310][310], b[310], c[310];
signed main() {
	cin >> n >> m;
	rep(i, n) {
		REP(j, m)cin >> a[i][j];
	}
	REP(i, m)b[i] = true;
	int ans = INF;
	rep(i,m) {
		REP(j, m)c[j] = 0;
		rep(j, n) {
			REP(k, m) {
				if (b[a[j][k]]) {
					c[a[j][k]]++;
					break;
				}
			}
		}
		int cnt = 0, tar = -1;
		REP(j, m) {
			if (cnt < c[j]) {
				cnt = c[j];
				tar = j;
			}
		}
		ans = min(ans, cnt);
		if (tar != -1)b[tar] = false;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
template <long long mod>
class Combination
{
    std::vector<long long> fact, finv, inv;
public:
    Combination(int sz)
    {
        fact.resize(sz);
        finv.resize(sz);
        inv.resize(sz);
        fact[0] = 1;
        for (int i = 1; i < sz; ++i)
        {
            fact[i] = fact[i - 1] * i % mod;
        }
        inv[0] = 0;
        inv[1] = 1;
        for (int i = 2; i < sz; ++i)
        {
            inv[i] = mod - inv[mod % i] * (mod / i) % mod;
        }
        finv[0] = 1;
        for (int i = 1; i < sz; ++i)
        {
            finv[i] = finv[i - 1] * inv[i] % mod;
        }
    }
    long long C(long long n, long long k)
    {
        if (n < k)
            return 0;
        if (n < 0 || k < 0)
            return 0;
        return (fact[n] * finv[k] % mod) * finv[n - k] % mod;
    }
    long long P(long long n, long long k)
    {
        if (n < k)
            return 0;
        if (n < 0 || k < 0)
            return 0;
        return fact[n] * finv[n - k] % mod;
    }
    long long H(long long n, long long k)
    {
        return this->C(n + k - 1, k);
    }
    long long getfact(int i)
    {
        return fact[i];
    }
    long long getinv(int i)
    {
        return inv[i];
    }
    long long getfinv(int i)
    {
        return finv[i];
    }
};
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const ll MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;
template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}
template<typename T1, typename T2>
ostream& operator<<(ostream &os, const pair<T1, T2> p) {
  os << p.first << ":" << p.second;
  return os;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  Combination<MOD> comb(1000000);
  ll n, k; cin >> n >> k;
  ll ans = 0;
  for(int i=0;i<=min(n-1, k);++i) {
    ans += comb.C(n, i) * comb.C(n-1, i) % MOD;
    ans %= MOD;
  }
  cout << ans << endl;
}


Measured memory_bytes: 25728
N,K,S = map(int,input().split())
if S != 10**9:
    for _ in range(K):
        print(S,end=' ')
    for _ in range(N - K):
        print(10**9,end = ' ')
  
else:
    for _ in range(K):
        print(10**9,end = ' ')
    for _ in range(N - K):
        print(1,end=' ')
print()

Measured memory_bytes: 75416
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;
ll MOD=1000000007;

 
int main() {
    ll n,k;
    cin >> n >> k;
    ll ans=0;
    ll c=0,cc=0;
    rep(i,n+1){
        c+=i;
        cc+=n-i;
        if (i+1>=k){
            ans=(ans+cc-c+1)%MOD;
        }
    }
    cout << ans << endl;
}

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

int main(){
	int n;
	while(cin>>n,n){
		int ans=0;
		int head=1,tail=2,sum=1;
		while(head<n){
			while(sum<n)sum += tail++;
			if(sum==n)ans++;
			sum -= head++;
		}
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 1160
a,b,c =map(int, input().split())
if a<b and b<c:
  print(a,b,c)
elif a>b:
  if b>=c:
    a,c = c,a
    print(a,b,c)
  else:
    a,b = b,a
    b,c = c,b
    print(a,b,c)
else:
  if a>c:
    a,b = b,a
    a,c = c,a
    print(a,b,c)
  else:
    b,c = c,b
    print(a,b,c)


Measured memory_bytes: 5596
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <numeric>
#include <tuple>
#include <stack>

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define print(s) cout << s << endl
typedef long long ll;
using namespace std;

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int main() {
	int a,b,c; cin >> a >> b >> c;
	if (a==b){
		cout << c << endl;
	}else if (b == c){
		cout << a << endl;
	}else {
		cout << b << endl;
	}
}

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

/* メモリ食い過ぎ注意 */
#define int long long

typedef long long ll;

int euclid(int a, int b)
{
    if (a < b)
        euclid(b, a);
    if (b == 0)
        return a;
    int r;
    while ((r = a % b))
    {
        a = b;
        b = r;
    }
    return b;
}

/* define const */
const ll INF = (1ll << 60);
const ll MOD = (ll)1e9 + 7;
/* end defineing */

signed main()
{
    ll a, b, x;
    cin >> a >> b >> x;

    if (a % x == 0)
        cout << b / x - a / x + 1 << endl;
    else
        cout << b / x - a / x << endl;
}


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

using namespace std;

#define PB push_back
#define f first
#define s second
#define what_is(x) cerr << #x << " is " << x << endl;

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

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n;
    cin >> n;
    ll arr[n];
    for(int i=0; i<n; i++)
    {
        cin >> arr[i];
    }
    sort(arr, arr+n);
    for(int i=0; i<n; i++)
    {
        if(arr[i] == 0)
        {
            cout << 0;
            return 0;
        }
    }
    ll prod = 1;
    for(int i=0; i<n; i++)
    {
        if(prod > (long double) 1e18/arr[i])
        {
            cout << -1;
            return 0;
        }
        prod *= arr[i];
    }
    cout << prod;
    return 0;
}


Measured memory_bytes: 4416
#include<cstdio>
using namespace std;
int n;
long long a,b,h[100010];
bool check(long long x)
{
	long long now=x;
	//ay+b(x-y)>=h
	//bx+(a-b)y>=h
	for (int i=1;i<=n;i++)
	{
		if (b*x>=h[i]) continue;
		long long t=h[i]-b*x;
		now-=t/(a-b);
		if (t%(a-b)!=0) now--;
		if (now<0) return 0;
	}
	return 1;
}
int main()
{
	int i;
	scanf("%d%lld%lld",&n,&a,&b);
	for (i=1;i<=n;i++) scanf("%lld",&h[i]);
	long long l=0,r=0;
	for (i=1;i<=n;i++) r+=h[i]/a+1;
	while (l<r)
	{
		long long mid=(l+r)/2;
		if (check(mid)) r=mid;
		else l=mid+1;
	}
	printf("%lld\n",l);
}

Measured memory_bytes: 896
import java.util.Scanner;

public class Main{
  static long count = 0;

  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    long K = sc.nextInt();
    long A = sc.nextInt();
    long B = sc.nextInt();
    if(A+2>=B || K<=1 || K<=A){
      System.out.println(1+K);
    }
    else{
      count = count + B;
      K = K - (A+1);
      if(K==1){
        System.out.println(count+1);
      }
      else{
        if(K%2==0){
          count = count + (K/2)*(B-A);
          System.out.println(count);
        }
        else{
          count = count + (K/2)*(B-A) + 1;
          System.out.println(count);
        }
      }
    }

  }



}


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

int main() {
  int a[45];
  a[0] = a[1] = 1;

  int n; cin >> n;

  for (int i = 2; i <= n; i++)
    a[i] = a[i-1] + a[i-2];

  cout << a[n] << endl;
}

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

typedef long long ll;
const long long LINF = 1LL << 60;
const long long LMINF = 1LL << 63;
const int INF = 1 << 30;

#define REP(i,n) for(int i = 0;i < n;++i)
#define REPS(i,x) for(int i = 1;i <= (int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i >= 0;i--)
#define RREPS(i,x) for(int i=((int)(x));i > 0;i--)
#define PB push_back
#define F first
#define S second
#define MP make_pair
#define ALL(obj) (obj).begin(),(obj).end()
#define debug(x) cerr << #x << ": " << x << "\n"

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



int main(){
    ios::sync_with_stdio(false);cin.tie(0);
    int n,x,t;
    cin >> n >> x >> t;
    int ans;
    if(n % x != 0){
       ans = ((n / x) + 1) * t;
    }else{
        ans = (n / x) * t;
    }

    cout << ans << endl;
    return 0;
}

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

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

	int N;
	cin >> N;
	int ans = (N+1) / 2;
	cout << ans << endl;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define _ << ' ' <<
using namespace std;
using ll = long long;

int n;

ll f(vector<ll> a, int d)
{
    ll pref = 0; ll sol = 0;
    for (int i = 0; i < n; ++i)
    {
        if ((d + i) % 2)
        {
            if (pref + a[i] <= 0)
            {
                ll t = -pref + 1;
                sol += abs(t - a[i]);
                a[i] = t;
            }
        }
        else
        {
            if (pref + a[i] >= 0)
            {
                ll t = -pref - 1;
                sol += abs(t - a[i]);
                a[i] = t;
            }
        }
        pref += a[i];
    }
    return sol;
}

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

    cout << min(f(a, 0), f(a, 1));
}


Measured memory_bytes: 2560
#include <stdio.h>

int main (void){
	
	int N;
	int A,B;
	int X;
	
	scanf("%d",&N);
	
	if( N == 1 ){
		printf("Hello World\n");
	}else if( N == 2 ){
		scanf("%d%d",&A,&B);
		X = A + B;
		printf("%d\n",X);
	}
	
}

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

const int M = 1000005;

int main() {
  string S;
  cin >> S;
  set<string> s;
  int n = S.length();
  if(n == 1){
    cout << "1¥n";
    return 0;
  }
  if(n == 2){
    if(S[0] == S[1]){
      cout << "1¥n";
    }else{
      cout << "2¥n";
    }
    return 0;
  }

  int dp[n];

  dp[0] = 1;

  if(S[0] == S[1]){
    dp[1] = 1;
  }else{
    dp[1] = 2;
  }

  if(S[0] != S[1] && S[1] != S[2]){
    dp[2] = 3;
  }else{
    dp[2] = 2;
  }

  for(int i = 3; i < n; i++){
    if(S[i-1] == S[i]){
      dp[i] = dp[i-3]+2;
    }else{
      dp[i] = dp[i-1]+1;
    }
  }
  cout << dp[n-1] << endl;
}



Measured memory_bytes: 4484
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <cstdint>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

using ll =  long long;
using Pll = pair<ll, ll>;
using Pii = pair<int, int>;

constexpr ll MOD = 1000000007;
constexpr long double EPS = 1e-10;
constexpr int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int n;
    cin >> n;

    cout << (n-1)/2 << endl;

}


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

#define fr(i,n) _back
#define pb	push_back
#define eb	emplace_back
#define mk	make_pair
#define fi	first
#define se	second
#define endl	'\n'

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<ii> vii;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1.0);

const int T = 1e3 + 3;
vector<int> g[T];
int sob[T][T];
int cor[T][T];
int pai[T][T];
int dist[T][T];
int n,m;
int ori;

void dfs(int u) {
    cor[ori][u] = 1;

    for(int v : g[u]) {
        if(!cor[ori][v]) {
            pai[ori][v] = u;
            dist[ori][v] = dist[ori][u] +1;
            dfs(v);
        }
        else if(v == ori and cor[ori][v] == 1)
            if(dist[ori][u] < sob[ori][u])
                sob[ori][u] = dist[ori][u];

    }

    cor[ori][u] = 2;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin >> n >> m;
    memset(sob, INF, sizeof sob);

    for(int i = 0; i < m; i++) {
        int a,b;cin >> a >> b;
        g[a].pb(b);
    }

    for(int i = 1; i <= n; i++) {
        ori = i, dfs(i);
    }

    int a = 0, b = 0;
    int best = INF;

    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= n; j++) {
            if(sob[i][j] != INF) {
                if(sob[i][j] < best) {
                    best = sob[i][j];
                    a = i;
                    b = j;
                }
            }
        }
    }

    if(!a) { cout << -1 << endl; return 0; }
    vector<int> ans;
    while(a != b) { ans.pb(b); b = pai[a][b]; }
    ans.pb(a);
    cout << ans.size() << endl;
    for(auto x : ans) cout << x << endl;

    return 0;
}


Measured memory_bytes: 16128
#テストファイルで実行する時
import sys
if sys.platform =='ios':
    sys.stdin=open('input_file.txt')

n,m,x1,y1 = map(int,input().split())
x = list(map(int,input().split()))
y = list(map(int,input().split()))

#xというリストにx1という数字を追加する
x.append(x1)
y.append(y1)

x.sort()
y.sort()

if x[len(x)-1]<y[0]:
	print('No War')
else:
	print('War')


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

#define debug(n) cerr << #n << ':' << n << endl;

using namespace std;

using  ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<double, double>;
using  vi = vector<int>;
using  vl = vector<ll>;
using  vd = vector<double>;
template<class T,class U>
using umap = unordered_map<T,U>;
template<class T>
using uset = unordered_set<T>;

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

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

template<class T>
inline void putv(const vector<T>&v,char c = '\n'){
  for(auto&&e:v){
    cout << e << c;
  }
}

template<class T>
inline void readv(vector<T>&v){
  if(v.empty()){
    cerr << "void readv(vector<T>&v) v.empty()\n";
  }
  for(auto&&e:v){
    cin >> e;
  }
}

int main(){
  int n,m;cin >> n >> m;
  vector<vector<int>> vv(m+1);
  for(int i = 0; i < n; ++i){
    int a,b; cin >> a >> b;
    if(m-a < 0)continue;
    vv[m-a].push_back(b);
  }

  ll ans = 0;

  priority_queue<int> pq;
  for(int i = m; i >= 0; --i){
    for(auto&&e:vv[i]){
      pq.push(e);
    }
    if(pq.empty()) continue;
    ans += pq.top();
    pq.pop();
  }

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 5632
func readInts() -> [Int] {
    return readLine()!.split(separator: " ").map { Int($0)! }
}

func main() {
    let count = Int(readLine()!)!
    var ints = readInts()
    
    var a = 0
    var b = 0
    var isA = true
    for _ in 1...count {
        guard let max = ints.max(), let maxIndex = ints.firstIndex(of: max) else {
            break
        }
        if isA {
            a += max
        } else {
            b += max
        }
        ints.remove(at: maxIndex)
        isA.toggle()
    }
    
    print("\(a - b)")
}

main()


Measured memory_bytes: 8252
#include <iostream>
#include <queue>

using namespace std;

#define MAX(a, b)	(((a) < (b)) ? (b) : (a))


int main()
{
	int N;
	int M;
	cin >> N;
	cin >> M;

	priority_queue<int> A;
	for (int i = 0; i < N; i++) {
		int val;
		cin >> val;
		A.push(val);
	}

	for (int i = 0; i < M; i++) {
		int hangaku = (A.top() / 2);
		A.pop();
		A.push(hangaku);
	}

	long long int sum = 0;
	while (!A.empty()) {
		sum += A.top();
		A.pop();
	}
	cout << sum;

	return 0;

}


Measured memory_bytes: 892
main :: IO ()                                                                                                              
main = do                                                                                                                  
  [a,b] <- map read . words <$> getLine                                                                                    
  s <- getLine                                                                                                             
  let t = takeWhile (/='-') s                                                                                              
      u = takeWhile (/='-') . tail . dropWhile (/='-') $ s                                                                 
                                                                                                                           
  putStrLn $ if length t == a && length u == b then "Yes" else "No"

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

int main() {
  int n;
  string s, t;
  cin >> n >> s >>t;
  string ans = "";
  for(int i = 0; i < n; i++){
    ans += s[i];
    ans += t[i];
  }
  cout << ans;
}



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

#define rep(i,n) for(int i=0 ; i<(n) ; i++)
#define repr(i,n) for(int i=(n) ; i>=0 ; i--)
#define ALL(x) (x).begin(),(x).end()

using ll = long long;
using ull = unsigned long long;
 
const ll INF = 1LL<<60;
const int MINF = 1e9;
const int MOD = 1e9+7;

using vi = vector<int>;
using vii = vector<vi>;

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

template<typename T>
T GCD(T a,T b){ return b ? GCD(b,a%b) : a ;}
template<typename T>
T LCM(T a,T b){ return a*b / GCD(a,b) ;}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    ll n,m;cin >> n >> m;
    if(n == 1 && m == 1){
        cout << 1 << endl;
        return 0;
    }else if(n == 1 || m == 1){
        cout << (n==1 ? m-2 : n-2) << endl;
        return 0;
    }else{
        cout << (n-2)*(m-2) << endl;
    }
    return 0;
}

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

const string w[4]={"dream","dreamer","erase","eraser"};

int main(){
  string s;
  cin>>s;
  for(int i=s.length()-1;0<i;){
    bool f=false;
    for(int j=0;j<4;++j){
      bool flag=true;
      for(int k=0;k<w[j].length();++k){
        if(s[i-k]!=w[j][w[j].length()-1-k]){
          flag=false;
          break;
        }
      }
      if(!flag){
        continue;
      }
      i-=w[j].length();
      f=true;
      break;
    }
      
    if(!f){
      cout<<"NO";
      return 0;
    }
  }
  cout<<"YES";
  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
// iostream is too mainstream
#include <cstdio>
// bitch please
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <cmath>
#include <iomanip>
#include <time.h>
#define dibs reserve
#define OVER9000 1234567890
#define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
#define tisic 47
#define soclose 1e-8
#define chocolate win
// so much chocolate
#define patkan 9
#define ff first
#define ss second
#define abs(x) ((x < 0)?-(x):x)
#define uint unsigned int
#define dbl long double
#define pi 3.14159265358979323846
using namespace std;
// mylittledoge

#ifdef DONLINE_JUDGE
	// palindromic tree is better than splay tree!
	#define lld I64d
#endif

int main() {
	cin.sync_with_stdio(0);
	cin.tie(0);
	cout << fixed << setprecision(10);
	int N;
	cin >> N;
	vector<int> P;
	for(int i =2; i <= 2200; i++) {
		bool isP =true;
		for(int j =2; j < i; j++) if(i%j == 0) isP =false;
		if(isP) P.push_back(i);}
//	cout << P.size() << "\n";
	map< pair<long long,long long>,int> M;
	for(int i =0; i < N; i++) {
		long long x;
		cin >> x;
		long long y =x, z =1;
		ALL_THE(P,it) {
			if(*it > x) break;
			if(x%(*it) != 0) continue;
			long long a =1LL*(*it)*(*it)*(*it);
			while(x%a == 0) {
				x /=a;
				y /=a;}
			int pa =0;
			while(x%(*it) == 0) {x /=*it; pa++;}
			if(pa == 2) z *=(*it);
			if(pa == 1) z *=1LL*(*it)*(*it);
			z =min(z,1LL<<35);}
		if(x > 1) {
			long long s =sqrt(x);
			while(s > 0 && s*s > x) s--;
			while(s*s < x) s++;
			if(s*s == x) z *=s;
			else z *=x*x;}
		z =min(z,1LL<<35);
		M[make_pair(y,z)]++;}
	int ans =0;
	if(M[make_pair(1LL,1LL)] > 0) ans++;
	ALL_THE(M,it) if(it->ff.ff > 0) {
		auto jt =M.find(make_pair(it->ff.ss,it->ff.ff));
		if(jt == M.end()) ans +=it->ss;
		else if(it->ff.ff > it->ff.ss) ans +=max(it->ss,jt->ss);
		}
	cout << ans << "\n";
	return 0;}

// look at my code
// my code is amazing


Measured memory_bytes: 6528
#include <bits/stdc++.h>
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define codefor int test;cin>>test;while(test--)
#define vec_input(v) for(auto it=v.begin();it!=v.end();it++){cin>>*it;}
#define vec_output(v) for(auto it=v.begin();it!=v.end();it++){if(it!=v.begin())cout<<" ";cout<<*it;}cout<<endl;
#define vec_debug(v) for(auto it=v.begin();it!=v.end();it++){cerr<<*it<<" ";}cerr<<endl;
#define yn(ans) cout<<(ans?"Yes":"No")<<endl
#define YN(ans) cout<<(ans?"YES":"NO")<<endl
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;

int main(){
    int n;
    cin>>n;
    vector<ll> vec(n);
    vec_input(vec);
    sort(rall(vec));
    ll ans=vec[0];
    for(int i=1;i<n/2;i++){
        ans+=2*vec[i];
    }
    if(n%2==1)ans+=vec[n/2];
    cout<<ans<<endl;
}

Measured memory_bytes: 4852
/*
    written by Pankaj Kumar.
    country:-INDIA
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll ;
typedef set<pair<int,int>> spi;
typedef set<pair<ll,ll>> spl;
typedef vector<pair<int,int>> vpi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<pair<ll,ll>> vpl;
typedef vector<string> vs;
typedef map<ll,ll> ml;
typedef set<string> ss;
typedef set<char>sc;
typedef set<int> si;
typedef set<ll> sl;
#define pan cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);
// define values.
#define mod 1000000007
#define phi 1.618
/* Bit-Stuff */
#define get_set_bits(a) (__builtin_popcount(a))
#define get_set_bitsll(a) ( __builtin_popcountll(a))
#define get_trail_zero(a) (__builtin_ctz(a))
#define get_lead_zero(a) (__builtin_clz(a))
#define get_parity(a) (__builtin_parity(a))
/*  Abbrevations  */
#define ff first
#define ss second
#define mp make_pair
#define line cout<<endl;
#define pb push_back
#define Endl "\n"
// loops
#define loop(i,start,end) for(ll i=ll(start);i<ll(end);i++)
#define loop0(num) for(ll i=0;i<ll(num);i++)
#define forin(arr,n) for(ll i=0;i<n;i++) cin>>arr[i];
// Some print
#define no cout<<"NO"<<endl;
#define yes cout<<"YES"<<endl;
#define cc ll test;cin>>test;while(test--)
// sort
#define all(V) (V).begin(),(V).end()
#define srt(V) sort(all(V))
#define srtGreat(V) sort(all(V),greater<ll>())
// function

ll power(ll x,ll y)
{
    ll res=1;
    while(y>0)
    {
        if(y%2==1)res*=x;
        y/=2; x*=x;
    }
    return res;
}
/* ascii value 
A=65,Z=90,a=97,z=122
*/
/*  -----------------------------------------------------------------------------------*/
ll solve()
{
    ll n;
    cin>>n;
    ll ans=0,sum=0;
    ll temp=0;
    for(ll i=0;i<n;i++)
    {
        cin>>temp;
        ans+=sum*temp;
        sum+=temp;
        ans%=mod;
        sum%=mod;
    }
    cout<<ans<<endl;
    return 0;
}

int main()
{
    //freopen("input.txt"a, "r", stdin);
    // cc
    // {
        solve();
    // }
}


Measured memory_bytes: 3556
#include<bits/stdc++.h>
#define ll long long
#define dbg1(x) cerr<<#x<<"="<<(x)<<" "
#define dbg2(x) cerr<<#x<<"="<<(x)<<"\n"
#define dbg3(x) cerr<<#x<<"\n"
using namespace std;
#define reg register
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}
    return x*f;
}
ll ans,A,B,C,X,Y;
ll val(ll i){return i*2ll*C+max(X-i,0ll)*A+max(Y-i,0ll)*B;}
int main()
{
	A=read(),B=read(),C=read(),
	X=read(),Y=read();
	reg int i;
	ans=val(0);
	for(i=1;i<=X||i<=Y;++i)
		ans=min(ans,val(i));
	return 0*printf("%lld\n",ans);
}

Measured memory_bytes: 256
#include <iostream>
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define pii std::pair<int,int>
#define pli std::pair<ll,int>
#define pil std::pair<int,ll>
#define psi std::pair<string,int>
#define pll std::pair<ll,ll>
#define pci std::pair<char,int>
#define sll(x) scanf("%lld",&x)
#define prll(x) printf("%lld ",x)
#define pri(x) printf("%d ",x)
#define si(x) scanf("%d",&x)
#define pb push_back
#define vll std::vector<ll>
#define vpi std::vector<std::pair<int,int>>
#define vi std::vector<int>
#define vvi std::vector<std::vector<int>>
#define vvpil std::vector<std::vector<std::pair<int,ll>>>
#define vlpii std::vector<std::list<pii>>
#define vlpil std::vector<std::list<pil>>
#define li std::list<int>
#define lpil std::list<pil>
#define Endl printf("\n")
#define vli vector<list<int>>
#define vvll vector<vector<ll>>
#define mp make_pair
#define x first
#define y second
#define ma 100000000
#define imie(...) "[" << #__VA_ARGS__": " << (__VA_ARGS__) << "] "
const ll  INF=10000000000000;
const ll mod = 1e9 + 7;
using namespace std;
void add(int& a , int b){
	a += b;
	if(a >= mod) a -= mod;
}
ll mul(ll a , ll b){
	return (a * b) % mod;
}

int main(){
	IOS;
	int n ; cin >> n ;
	map<vector<int> , ll> maap ;
	string s ;
	for(int i = 0 ; i < n ; i++){
		cin >> s;
		vi occ(26 , 0) ;
		for(int i = 0 ; i <  10 ; i++){
			occ[(int)s[i] - (int)'a']++ ;
		}
		maap[occ]++ ;
	}
	ll ans = 0 ;
	for(map<vi , ll> :: iterator i = maap.begin() ; i != maap.end() ; i++){
		ll x = i -> second;
		ans += x * (x - 1) / 2 ;
	}
	cout << ans << endl ;
	
	return 0;
}


Measured memory_bytes: 19072
#include<iostream>
#include<algorithm>
#include<iomanip>
#include<string>
#include<vector>

typedef unsigned long long ULL;
typedef long long LL;

using namespace std;

template<class T> void swap(T &a, T &b ){
    T temp;
    temp = a;
    a = b;
    b = temp;   
}

int main(){
    int N;
    int *L;
    int i,j,k;
    ULL count=0;

    cin >> N;
    L = new int[N];
    for(i=0;i<N;i++){
        cin >> L[i];
    }
    sort(L,L+N,std::greater<int>());
   for(i=0;i<N-2;i++){
       for(j=i+1;j<N-1;j++){
           for(k=j+1;k<N;k++){
               if( L[i] >= L[j] + L[k]){
                   break;
               }
               count++;
           }
       }
   }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
from collections import deque
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np
# from numpy import cumsum  # accumulate
import copy

def grid_wall(grid, h, w, wall='#'):
    G = [[wall]*(w+2) for _ in range(h+2)]
    for hi in range(h):
        G[hi+1][1:w+1] = grid[hi]
    return G

def solve():
    H, W = MI()
    g = [[] for _ in range(H)]
    start = []
    white_cnt = 0
    for i in range(H):
        line = LS()
        for j, l in enumerate(line):
            if l == '.': white_cnt = white_cnt + 1
            else: start.append((i+1, j+1))
        g[i] = line

    if white_cnt == 0:
        print(0)
        return 

    G = grid_wall(g, H, W, 'x')
    move = [(0, 1), (0, -1), (1, 0), (-1, 0)]
    ans = 0
    while 1:
        next = []
        for x, y in start:
            for dx, dy in move:
                nx, ny = x+dx, y+dy
                if G[nx][ny] == 'x': continue
                elif G[nx][ny] == '#': continue
                elif G[nx][ny] == '.':
                    white_cnt -= 1
                    G[nx][ny] = '#'
                    next.append((nx, ny))
        ans += 1
        # print(G)
        if white_cnt <= 0:
            print(ans)
            return
        start = next[:]



if __name__ == '__main__':
    solve()


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

int main() {
  int N = 0;
  cin >> N;
  vector<int64_t> L(87);
  L.at(0) = 2;
  L.at(1) = 1;
  for (int i = 2; i <= N; i++){
      L.at(i) = L.at(i-1) + L.at(i-2);
    }
  cout << L.at(N);
}

Measured memory_bytes: 256
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_C main
#include "bits/stdc++.h"
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
using psi = pair<string, int>;
// functions

#endif


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

    int N; cin >> N;
    vi h(N+1, -1); REP(i, N) cin >> h[i];

    //vector<pii> lr; // [l,r)
    vector<int> dh;
    int i = 0;
    while(true) {
        if (h[i] > 0) {
            int l = i;
            int r = i;
            int lo = INF;
            while(h[r]>0) {
                lo = min(lo, h[r]);
                r++;
            }
            //lr.push_back(pii(l, r));
            dh.push_back(lo);
            for (int j = l; j < r; j++) h[j] -= lo;
        } else {
            i++;
        }

        if (i >= N) break;
    }

    int ans = 0;
    for (int i : dh) ans += i;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.*;

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

        int N = sc.nextInt();
        String S = sc.next();

        /*
        int count = 0;

        for(int i=0; i<N-2; i++) {
            if(S.charAt(i) == 'A'){
                if(S.charAt(i+1) == 'B') {
                    if(S.charAt(i+2) == 'C') {
                        count++;
                        i += 2;
                    }
                }
            }
        }*/

        //賢い方法
        int count = (N - S.replace("ABC", "").length()) / 3;

        System.out.println(count);
        
    }
}

Measured memory_bytes: 21844
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <tuple>
#include <algorithm>
#include <map>
using namespace std;
#define REP(n) for(int i=0;i<n;i++)

#define INF_32 0x7fffffff;

int main() {
	long long S;
	cin >> S;

	int ans = INF_32;
	while (S >= 100) {
		long long tmp = S % 1000;
		S = S / 10;

		ans = min(ans,abs((int)(753 - tmp)));
	}
	

	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
import random
import time
import copy
from operator import itemgetter
time0=time.time()

D=int(input())
C=[0]+list(map(int,input().split()))
S=[0]+[[0]+list(map(int,input().split())) for i in range(D)]


CI=sorted([(v,i) for i,v in enumerate(C)],key=itemgetter(0),reverse=True)
CHO=[i for v,i in CI[:5]]

CHOICES=[[0]]
for i in range(1,D+1):
    SI=sorted([(v,i) for i,v in enumerate(S[i])],key=itemgetter(0),reverse=True)
    CHOICES.append([i for v,i in SI[:5]])
    
ANS=0
T=[0]
LAST=[0]*27
for day in range(1,D+1):
    SCORE=[-1<<30]*27
    for j in range(1,27):
        SC=0
        SC+=S[day][j]

        for k in range(1,27):
            if j==k:
                continue
            SC-=C[k]*(day-LAST[k])
        SCORE[j]=SC

    choose=SCORE.index(max(SCORE))
    T.append(choose)
    LAST[choose]=day

ANS=0
LAST=[[0]*27 for i in range(D+1)]
for day in range(1,D+1):
    for j in range(1,27):
        LAST[day][j]=LAST[day-1][j]
    t=T[day]
    ANS+=S[day][t]
    LAST[day][t]=day

    for j in range(1,27):
        ANS-=C[j]*(day-LAST[day][j])

MAX=ANS
MAXT=copy.deepcopy(T)
d=0
after_t=0

while time.time()-time0<1.8:
    BT=copy.deepcopy(T)
    BLAST=copy.deepcopy(LAST)
    BANS=ANS
    
    d=random.randint(1,D)
    after_t=random.choice(CHO+CHOICES[d])

    before_t=T[d]

    ANS+=S[d][after_t]-S[d][before_t]

    T[d]=after_t

    memolast=[]

    for day in range(d,D+1):
        if T[day]!=before_t:
            ANS+=C[before_t]*(day-LAST[day][before_t])
            memolast.append((day,before_t,LAST[day][before_t]))
            LAST[day][before_t]=LAST[day-1][before_t]
            ANS-=C[before_t]*(day-LAST[day][before_t])
        else:
            break

    ANS+=C[after_t]*(d-LAST[d][after_t])
    memolast.append((d,after_t,LAST[d][after_t]))
    LAST[d][after_t]=d

    for day in range(d+1,D+1):    
        if T[day]!=after_t:
            ANS+=C[after_t]*(day-LAST[day][after_t])
            memolast.append((day,after_t,LAST[day][after_t]))
            LAST[day][after_t]=LAST[day-1][after_t]
            ANS-=C[after_t]*(day-LAST[day][after_t])

    if ANS*1000<MAX*999:
        T=BT
        ANS=BANS
        for dd,tt,ll in memolast:
            LAST[dd][tt]=ll
    elif ANS>MAX:
        MAX=ANS
        MAXT=copy.deepcopy(T)

print(*MAXT[1:])


Measured memory_bytes: 179408
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define endl "\n"
#define mod 1000000007
#define fastio std::ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define deb(x) cout<<#x<<" "<<x<<endl;

int main()
{
	fastio;
	ll a,b;
	cin>>a>>b;
	ll res = a;
	ll count = 1;
	while (res<b) {
		count++;
		res = res + a - 1;
	}
	if(b==1) count = 0;
	std::cout << count << '\n';
}


Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <map>
#include <deque>
#include <algorithm>
#include <set>
#include <string>
#include <math.h>
#include <stdio.h>
#include<iomanip>


#define ll long long
using namespace std;
//const ll MOD = (int) 10e9 + 7;

/*ll dp[100001];
vector<vector<ll>>adj;
ll dfs(ll node)
{
    if (dp[node] != -1)
        return dp[node];

    ll ans = 0;
    for (int i = 0; i < adj[node].size(); i++)
    {
        ans = max(dfs(adj[node][i]) + 1, ans);

    }
    return dp[node] = ans;
}
*/
ll factorial(ll n)
{
    if (n == 1 || n == 0)
        return 1;

    return n * factorial(n - 1);
}


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin >> n;
    double arr[n];
    double dp[n + 1][n + 1];
    double tile[n];
    for (ll i = 0; i <= n; i++)
    {
        if (i != n){
            cin >> arr[i];
            tile[i] = 1 - arr[i];
            if (i != 0)
                tile[i] *= tile[i - 1];
        }

        for (ll j = 0; j <= n; j++)
        {
            if (j == 0)
                dp[i][j] = 1;
            else
                dp[i][j] = 0;
        }
    }
    dp[0][0] = 1;
    for (ll i = 1; i <= n; i++)
    {
        for (ll j = 1; j <= i; j++)
        {
            if (j != 1)
                dp[i][j] = dp[i-1][j-1] * arr[i - 1] + dp[i - 1][j] * (1 - arr[i - 1]);

            else if (j == 1 && i != 1)
                dp[i][j] += (arr[i - 1] * tile[i - 2]) + (dp[i - 1][j] * (1 - arr[i - 1]));

            else
                dp[i][j] = arr[i - 1];
        }
    }
    double ans = 0;
    for (ll i = ceil(n / 2.0); i <= n; i++)
    {
        ans+=dp[n][i];
    }
    std::cout<<std::fixed;
    std::cout<<std::setprecision(10)<<ans;
    return 0;
}


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

#define ll long long
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define x first
#define y second

bool ok(int a,int b,int c){
	if (a+b<=c) return false;
	if (a+c<=b) return false;
	if (b+c<=a) return false;
	return true;
}

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

	int n;
	cin>>n;
	int a[2001];
	for (int i=0; i<n; i++)
		cin>>a[i];
	sort(a,a+n);
	ll ans=0;
	for (int i=0; i<n; i++){
		for (int j=i+1; j<n; j++){
			int l=0,r=n;
			while (l+1<r){
				int mid=(l+r)/2;
				if (a[i]+a[j]>a[mid]) l=mid;
				else r=mid;
			}
			ans+=r-j-1;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {


    val (n, k, q) = readLine()!!.split(" ").map(String::toInt)

    val alist = mutableListOf<Int>()
    repeat(q) {
        alist += readLine()!!.toInt()
    }

    println(abc141c(n, k, alist))
}

fun abc141c(n: Int, k: Int, alist: MutableList<Int>): Any? {

    val result = mutableListOf<String>()

    val tmpMap = mutableMapOf<Int, Int>()

    for (hito in alist) {
        val value = tmpMap[hito]
        if (value != null) {
            tmpMap[hito] = value + 1
        } else {
            tmpMap[hito] = 1
        }
    }

    repeat(n) {
        if (k - alist.size + (tmpMap[it + 1] ?: 0) > 0) {
            result += "Yes"
        } else {
            result += "No"
        }
    }

//    repeat(n) {
//        val index = it + 1
//
//        var point = k
//        for (a in alist) {
//
//            if (a != index) {
//                point -=1
//            }
//
//            if (point == 0) {
//                result += "No"
//                break
//            }
//        }
//
//        if (point > 0) {
//            result += "Yes"
//        }

//        if (k - huseikai <= 0) {
//            result += "No"
//        } else {
//            result += "Yes"
//        }
//    }
    return result.joinToString("\r\n")
}


Measured memory_bytes: 49612