akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>

using namespace std;
int a[1024];
int b[10];
int main()
{
	int n;
	scanf("%d",&n);
	memset(b,0,sizeof(b));
	int ans=0;
	for(int i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
        if(a[i]>=1&&a[i]<=399)
        {
        	b[0]++;
		}else if(a[i]>=400&&a[i]<=799)
		{
			b[1]++;
		}else if(a[i]>=800&&a[i]<=1199)
		  b[2]++;
		  else if(a[i]>=1200&&a[i]<=1599)
		  b[3]++;
		  else if(a[i]>=1600&&a[i]<=1999)
		  b[4]++;
		  else if(a[i]>=2000&&a[i]<=2399)
		  b[5]++;
		  else if(a[i]>=2400&&a[i]<=2799)
		  b[6]++;
		  else if(a[i]>=2800&&a[i]<=3199)
		  b[7]++;
		  else if(a[i]>=3200)
		  ans++;
	}
	int mn=0;
	for(int i=0;i<8;i++)
	  if(b[i]>0)
	  mn++;
	if(mn==0)
	printf("1 %d\n",mn+ans);
	else
	printf("%d %d\n",mn,mn+ans);
	return 0;
}

Measured memory_bytes: 256
N = int(input())
spot = list(map(int,(input()).split()))
cost = []
cost1 = []

spot = [0] + spot + [0]

for i in range(N+1):
    cost.append(abs(spot[i+1]-spot[i]))

for i in range(N):
    cost1.append(abs(spot[i+2]-spot[i]))

costsum = 0
for i in cost:
    costsum += i

for i in range(1,N+1):
    prisum = costsum
    prisum = prisum - cost[i-1] - cost[i] + cost1[i-1]
    print(prisum)


Measured memory_bytes: 16688
import sys

n,a,b,c = map(int,input().split())

abc = {"A":a,"B":b,"C":c}

s = [input() for _ in range(n)]

ans = [None]*n
i = 0
while i <n:
    x = s[i][0]
    y = s[i][1]
    if abc[x] == 0 and abc[y] ==0:
        print("No")
        sys.exit()
    elif abc[x] == 1 and abc[y] ==1 and i<n-1:
        if s[i] == s[i+1]:
            ans[i] = x
            ans[i+1] = y
            i += 1
        elif x in s[i+1]:
            ans[i] = x
            abc[x] += 1
            abc[y] -= 1
        else:
            ans[i] = y
            abc[x] -= 1
            abc[y] += 1
    else:
        if abc[x]<=abc[y]:
            ans[i] = x
            abc[x] += 1
            abc[y] -= 1
        else:
            ans[i] = y
            abc[x] -= 1
            abc[y] += 1
    i += 1
    
print("Yes")
print("\n".join(ans))

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

using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=s;i<n;i++)
#define all(a) (a).begin(),(a).end()

struct dice {
    int d[6], f[6];

    void rotation(char com){
        if(com == 'E'){
            int tmp = d[0];
            d[0] = d[3];
            d[3] = d[5];
            d[5] = d[2];
            d[2] = tmp;
        }
        else if(com == 'S'){
            int tmp = d[4];
            d[4] = d[5];
            d[5] = d[1];
            d[1] = d[0];
            d[0] = tmp;
        }
        else if(com == 'N'){        
            int tmp = d[0];
            d[0] = d[1];
            d[1] = d[5];
            d[5] = d[4];
            d[4] = tmp;
        }
        else if(com == 'W'){
            int tmp = d[0];
            d[0] = d[2];
            d[2] = d[5];
            d[5] = d[3];
            d[3] = tmp;        
        }
        else if(com == 'R'){
            int tmp = d[3];
            d[3] = d[1];
            d[1] = d[2];
            d[2] = d[4];
            d[4] = tmp;
        }
    }

    int guess(int U, int F){
        int cnt = 0;
        while(U != d[0]){
            if(cnt % 2)rotation('N');
            else rotation('W');

            if(cnt > 10)return -1;
            cnt++;
        }

        while(F != d[1]){
            rotation('R');
            cnt++;
            if(cnt > 20)return -1;
        }

        return d[2];
    }

    bool same_dice(){
        rep(i,6){
            if(i%2)rotation('N');
            else rotation('W');

            rep(j,4){
                rotation('R');
                bool same = true;
                rep(k,6)if(d[k] != f[k])same = false;
                if(same)return true;
            }
        }
        return false;
    }
};

int main(){
    dice D;    
    rep(i,6)cin >> D.d[i];
    rep(i,6)cin >> D.f[i];

    cout << ((D.same_dice())? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 3100
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
using namespace std;

int main() {
	int n, a, b;
	string s, t;
	int p[1 << 25], q[1 << 25];
	cin >> s;
	a = 0;
	for (int i = 0;i < s.size();i++) {
		if (s[i] == '+')a++;
		else a--;
	}
	cout << a << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  while(1){
  int n,m[101],j,s;
  char st[52];
  string str,ans;
  for(int i=1;i<27;i++) st[i]='A'+i-1;
  for(int i=27;i<53;i++)st[i]='a'+i-27;
  cin>>n;
  if(n==0)break;
   for(int i=0;i<n;i++)cin>>m[i];
  cin>>str;
  j=0;
  for(int i=0;i<str.size();i++){
    if(str[i]>='A' && str[i]<='Z') s=str[i]-'A'+1;
    else s=str[i]-70;
        s-=m[j];
	if(s<=0) s+=52;
	ans+=st[s],j++;    
    if(j>n-1) j=0;
  }
  cout<<ans<<endl;
  }
    return 0;
}
  

Measured memory_bytes: 1208
#WA
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
diff = [0]*n

neg = 0
cnt = 0
for i in range(n):
    x = a[i]-b[i]
    diff[i] = x
    if x < 0:
        cnt += 1
        neg += x

if sum(diff)<0:
    print(-1)
    exit()

for x in sorted(diff, reverse=True):
    if neg >= 0:
        break
    cnt += 1
    neg += x

print(cnt)


Measured memory_bytes: 19536
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
string s;
int main(){
	int N,cnt[26]={},c[10]={};
	cin>>N;
	cin>>s;
	rep(i,N/2+1) cnt[s[i*2]-'a']++;
	rep(i,26) c[cnt[i]]++;
	int a=-1;
	rep1(i,9) if(c[i]){
		if(i==1) a+=2*c[i];
		else{
			if(c[i]==1) a+=4;
			else a+=2*c[i]+4;
		}
	}
	cout<<a<<endl;
}

Measured memory_bytes: 3196
#include<stdio.h>
int selectionSort(int A[],int n){
  int i,j,minj,c=0,tmp;
  for(i=0;i<n-1;i++){
    minj=i;
    for(j=i;j<n;j++){
      if(A[j]<A[minj]){
	minj=j;
      }
    }
	tmp=A[i];
	A[i]=A[minj];
	A[minj]=tmp;
    if(i!=minj) c++;
    }
  return c;
}

int main(){
  int i,j,A[100],c,n;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  c=selectionSort(A,n);
  for(i=0;i<n;i++){
    if(i>0) printf(" ");
    printf("%d",A[i]);
  }
  printf("\n");
  printf("%d\n",c);
  return 0;
  
}
  



Measured memory_bytes: 2084
'use strict'
let maxnum = 10e9 //Math.pow(10,9)
function countingSort(arr) {
  let sorted = []
  let tmp = [] //Array.apply(null, { length: maxnum + 1 }).map(v => 0)
  // console.log(tmparr.length)
  for (let i in arr) {
      if (tmp[arr[i]]) tmp[arr[i]] += 1
      else tmp[arr[i]] = 1
  }
  for (let i in tmp) {
    while (tmp[i] > 0) {
      sorted.push(~~i)
      tmp[i]--
    }
  }
  return sorted
}

function main(input) {
  input = input.split(/\n|\s/).map(v => ~~v)
  const n = input.shift()
  const arr = input.slice(0, -1)
  //   let sorted =  [...arr].slice(0)
  //   mergeSort(sorted, 0, n) //arr.slice(0).sort((a, b) => a - b) //countingSort(arr)
  const sorted = countingSort([...arr])
  //   const sorted = [...arr].sort((a, b) => a - b) //countingSort(arr)
  const mid = sorted[n / 2]
  const mid2 = sorted[n / 2 - 1]
  //   console.log(arr, sorted, mid)

  const ans = []
  for (let i = 0; i < n; i++) {
    ans.push(arr[i] < mid ? mid : mid2)
  }
  console.log(ans.join('\n'))
}

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


Measured memory_bytes: 129988
#include <bits/stdc++.h>
#define arep(a,i,n) for(ll i=(a);i<(n);i++)
#define rep(i,n) for(ll i=0;i<(n);i++)
#define cinf(x,n) for(ll i=0;i<(n);i++)cin>>x[i];
#define coutf(x,n) for(ll i=0;i<(n);i++)cout<<x[i]<<endl;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

ll mod = 1000000007;

using namespace std;

ll fact(ll num){
	ll f=1;
	while(num){
		f*=num%mod;
		f%=mod;
		num--;
	}
	return f;
}

int main(){
	ll n,m;
	cin >> n >> m;
	if(n-m==0)
		cout << fact(n)*fact(m)%mod*2%mod << endl;
	else if(n-m==1||n-m==-1)
		cout << fact(n)*fact(m)%mod << endl;
	else
		cout << 0 << endl;
}

Measured memory_bytes: 3588
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define REP(i, n)  FOR(i, 0, n)
#define ASC(c) sort((c).begin(), (c).end())
#define DESC(c) sort((c).begin(), (c).end(), greater<int>())

#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define DEBUG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

typedef long long ll;
typedef unsigned long long ull;
struct edge { int u, v; ll w; };
 
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
    string s; cin >> s;
    char prev;
    string ans = "Good";
    for (auto c: s) {
        if (c == prev) {
            ans = "Bad";
            break;
        }
        prev = c;
    }
    cout << ans << endl;
}


Measured memory_bytes: 760
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define at(x,i) get<i>(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
ll modfac(ll a){
    ll ans=1;
    while(a>1){
        ans*=a;
        ans%=1000000007;
        a--;
    }
    return ans;
}
ll modinv(ll a,ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
}
struct UnionFind {
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) {}

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool same(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};
ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
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(){
    ll n,q;cin >> n >>q;
    UnionFind uf(n);
    rep(i,q){
        ll a,b,c;cin >> a >> b >>c;
        if(!a)uf.merge(b,c);
        if(a){
            if(uf.same(b,c))cout <<1 <<endl;
            else cout <<0 <<endl;
        }
    }
}


Measured memory_bytes: 3136
#include <iostream>

using namespace std;

int main () {
  int num;
  cin >> num;
  int count = 0;
  while (num) {
    if (num % 10 == 7) {
      cout << "Yes\n";
      count = 1;
      break;
    }
    num /= 10;
  }
  if (!count) {
    cout << "No\n";
  }
  return 0;
}


Measured memory_bytes: 3532
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		solve();
	}

	private static final void solve() {
		try (Scanner cin = new Scanner(System.in)) {
			while (cin.hasNext()) {
				System.out.println("ABC" + cin.next());
			}
		} finally {
		}
	}
}


Measured memory_bytes: 22740
N, M = map(int, input().split())
S = [0] * N
r,w = 0,0
for i in range(M):
	p, s = input().split()
	if S[int(p)-1] >= 0:
		if s == 'AC':
			r+=1
			w+=S[int(p)-1]
			S[int(p)-1] = -1
		else:
			S[int(p)-1] = S[int(p)-1] + 1
print(r,w)

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

int n;

int check(int i,int sum,int cnt)
{
  //  cerr<<i<<" "<<sum<<endl;

  if(sum==n)
    return 1;
  if(sum+(i*i)>n || cnt<=0)
    return 0;
  int ans=0;
  ans+=check(i,sum+(i*i),cnt-1);
  ans+=check(i+1,sum,cnt);
  return ans;
}

int main()
{
  for(;cin>>n,n;)
    {
      cout<<check(1,0,4)<<endl;
    }


}

Measured memory_bytes: 1160
(defun straddlep (a b)
  (and (< a 0)
       (>= b 0)))

(defun hoge (a b c d)
  (cond
    ((and (>= a 0) (>= c 0)) (* b d))
    ((and (< b 0) (< d 0)) (* a c))
    ((and (>= a 0) (< d 0)) (* a d))
    ((and (< b 0) (>= c 0)) (* b c))
    ((and (straddlep a b) (>= c 0)) (* b d))
    ((and (straddlep a b) (< d 0)) (* a c))
    ((and (>= a 0) (straddlep c d)) (* b d))
    ((and (< b 0) (straddlep c d)) (* a c))
    (t (let ((ac (* a c))
             (bd (* b d)))
         (if (> ac bd) ac bd)))))

(let ((a (read))
      (b (read))
      (c (read))
      (d (read)))
  (format t "~a" (hoge a b c d)))


Measured memory_bytes: 24420
import java.util.*;
import static java.lang.Integer.*;
import static java.lang.System.*;
import static java.lang.Math.*;

public class Main {
	public static void main(String[] args) {
		int i,j;
		Scanner sc = new Scanner(in);
		int n = parseInt(sc.next());
		int x0 = parseInt(sc.next());
		int[] x = new int[n];
		int[] d = new int[n];
		x[0] = parseInt(sc.next());
		d[0] = abs(x[0]-x0);
		for(i=1;i<n;i++) {
			x[i] = parseInt(sc.next());
			d[i] = abs(x[i]-x[i-1]);
		}
		sc.close();
		int dd = d[0];
		for(i=1;i<n;i++) {
			dd = gcd(dd, d[i]);
			if(dd==1) break;
		}
		out.println(dd);
	}
	public static int gcd(int a, int b) {
		int tmp;
		while(a%b!=0) {
			tmp=b;
			b=a%b;
			a=tmp;
		}
		return b;
	}
}


Measured memory_bytes: 43852
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <climits>
#include <numeric>
#include <cmath>
#include <queue>
#include <sstream>
#include <string.h>
#include <bitset>
#include <stack>

using namespace std;
typedef long long ll;

int main() {
  int N, M;
  cin >> N >> M;
  
  int maxs = 0, mine = INT_MAX;
  for (int i = 0; i < M; i++) {
    int s, e;
    cin >> s >> e;
    maxs = max(maxs, s);
    mine = min(mine, e);
  }
  
  int ans = mine - maxs + 1;
  cout << max(ans, 0) << endl;
  return 0;
}


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

int v[200005];
int o[200005];

int main(){
    int n;
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> v[i];
        o[i] = v[i];
    }
    sort(o, o+n);
    for(int i = 0; i < n; i++){
        if( v[i] <= o[ (n-2)/2 ] ) printf("%d\n", o[ (n-2)/2 +1 ]);
        else printf("%d\n", o[ (n-2)/2 ]);
    }
}


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

int main() {
  string s, t;
  cin >> s >> t;
  int N = s.size();
  int A = t.size();
  int match = 0;
  for (int i = 0; i < N-A+1; i++) {
    string ss = s.substr(i,A);
    int mh = 0;
    for (int j = 0; j < A; j++) {
      if (ss[j] == t[j]) mh += 1;
    }
    match = max(mh,match);
  }
  cout << A-match << endl;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define range(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, b) for (int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x) cerr << #x << " = " << (x) << endl;
#define int long long
using namespace std;

template <typename X, typename T>
auto vectors(X x, T a) {
	return vector<T>(x, a);
}
template <typename X, typename Y, typename Z, typename... Zs>
auto vectors(X x, Y y, Z z, Zs... zs) {
	auto cont = vectors(y, z, zs...);
	return vector<decltype(cont)>(x, cont);
}

template <typename T>
ostream& operator<<(ostream& os, vector<T>& v) {
	rep(i, v.size()) { os << v[i] << (i == v.size() - 1 ? "" : " "); }
	return os;
}
template <typename T, typename S>
ostream& operator<<(ostream& os, pair<T, S>& p) {
	os << '(' << p.first << ',' << p.second << ')';
	return os;
}
template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
	for (T& x : v) { is >> x; }
	return is;
}

signed main() {
	int n, W;
	cin >> n >> W;
	
	vector<int> dp(W + 1, 0);
	rep(i,n){
		int w, v;
		cin >> w >> v;
		for (int j = W - w; j >= 0; j--) {
			dp[j + w] = max(dp[j + w], dp[j] + v);
		}
	}
	cout << dp.back() << endl;
}


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

class DisjoinSet{
    public:
    vector<int> rank,p;
    
    DisjoinSet(){}
    DisjoinSet(int size){
        rank.resize(size,0);
        p.resize(size,0);
        for(int i=0;i<size;i++)makeSet(i);
    }
    
    void makeSet(int x){
        p[x]=x;
        rank[x]=0;
    }
    
    bool same(int x,int y){
        return findSet(x)==findSet(y);
    }
    
    void unite(int x,int y){
        link(findSet(x),findSet(y));
    }
    
    void link(int x,int y){
        if(rank[x]>rank[y]){
            p[y]=x;
        }else{
            p[x]=y;
            if(rank[x]==rank[y]){
                rank[y]++;
            }
        }
    }
    
    int findSet(int x){
        if(x!=p[x]){
            p[x]=findSet(p[x]);
        }
        return p[x];
    }
};

int main(void){
    int n,a,b,q;
    int t;
    
    cin>>n>>q;
    DisjoinSet ds=DisjoinSet(n);
    
    for(int i=0;i<q;i++){
        cin>>t>>a>>b;
        if(t==0)ds.unite(a,b);
        else if(t==1){
            if(ds.same(a,b))cout<<1<<endl;
            else cout<<0<<endl;
        }
    }
    return 0;
}



Measured memory_bytes: 3176
#include<iostream>

using namespace std;

int main()
{
  int n, m = 0;
  int num[3];
  cin >> n;
  for(int i = 0; i < n; i++)
  {
    cin >> num[i];
    m = max(m, num[i]);
  }
  for(int i = 1; i < m / 2 + 1; i++)
  {
    bool b = true;
    for(int j = 0; j < n; j++)
      b &= !(num[j] % i);
    if(b)
      cout << i << endl;
  }
}

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

using namespace std;

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

    string s;
    int n, ans = 2e9;
    cin >> n >> s;
    int preW[n], preE[n];

    preW[0] = (s[0] == 'W');
    preE[0] = (s[0] == 'E');

    for (int i = 1; i < n; i++) {
        preW[i] = (s[i] == 'W');
        preE[i] = (s[i] == 'E');

        preW[i] += preW[i - 1];
        preE[i] += preE[i - 1];
    }

    for (int i = 0; i < n; i++)
        ans = min(ans, (i ? preW[i - 1] : 0) + (preE[n - 1] - preE[i]));

    cout << ans << '\n';

    return 0;
}

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

#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define trav(a, x) for (auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int main() {
	cin.sync_with_stdio(false);
	cin.exceptions(cin.failbit);
	int N;
	cin >> N;
	vector<ll> A(N), B(N);
	rep(i,0,N) {
		cin >> A[i] >> B[i];
	}
	ll added = 0;
	for (int i = N; i--;) {
		ll y = (A[i] + added) % B[i];
		if (y != 0) {
			added += B[i] - y;
		}
	}
	cout << added << endl;
	exit(0);
}

Measured memory_bytes: 1920
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <numeric>
typedef long long Int;
#define rep(i,a,b) for(Int i=a;i<b;++i)
#define rrep(i,a,b) for(Int i=a;i>=b;--i)
using namespace std;

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

    string s; cin >> s;
    Int res = LLONG_MAX;
    rep(i, 0, s.size()-2) {
        Int num = stoll(s.substr(i, 3));
        res = min(res, abs(753-num));
    }

    cout << res << endl;
}


Measured memory_bytes: 256
get_number(Number) :-
    get_string(String),
    number_string(Number, String).

get_string(String) :-
    current_input(Input),
    read_string(Input, ' \n', '', _, String).

/* memo
    code(int)
    string_code(1, S, C), (C: code)
    char_code(X, Y) (X: char, Y: code)
    string_chars(S, S2) (S: string, S2: [char])

    f(0, [], []).
    f(Z, [X|Xs], [Y|Ys]) :- X = Y, f(Z1, Xs, Ys), Z is Z1 + 1.
    f(Z, [_|Xs], [_|Ys]) :- f(Z, Xs, Ys).
*/

main :-
    get_number(A),
    get_number(P),
    X is (A * 3 + P) div 2,
    writeln(X).


Measured memory_bytes: 8128
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
static const double EPS = 1e-5;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)

int main(void){
  int n,id,u,a,p;
  while(cin>>n){
    if(n==0) break;
    vector<pair<PII,int> > data;
    map<int,int> t;
    int team[1001]={0};
    REP(i,n){
      cin>>id>>u>>a>>p;
      t[id] = u;
      data.push_back(pair<PII,int>(PII(-a,p),id));
    }
    sort(data.begin(),data.end());
    int select=0;
    REP(i,data.size()){
      pair<PII,int> d = data[i];
      int id = d.second;
      int univ = t[id];
      int count = team[univ]; 
      if((select<10&&count<3)
          ||(select<20&&count<2)
          ||(select<26&&count<1)){
        team[univ]++;
        select++;
        cout<<id<<endl;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 0
while 1:
    s1 = input().split('\"')
    if s1[0] == '.': break
    s2 = input().split('\"')

    jdg = 1
    cnt_d = 0

    if len(s1) != len(s2): print("DIFFERENT")
    else:
        l = len(s1)
        i = 0
        while i < l:
            if s1[i] != s2[i]:
                cnt_d += 1
                if cnt_d == 1 and i % 2 == 1:
                    jdg = 1
                else:
                    jdg = 0
                    break
            i += 1

        if jdg == 1 and cnt_d == 1: print("CLOSE")
        elif jdg == 0 or cnt_d > 1: print("DIFFERENT")
        else: print("IDENTICAL")


Measured memory_bytes: 5584
import sys
s=p=0
for l in sys.stdin:
	if l.strip()=="":
		s=p=0
		continue
	if s==5:continue
	t=int(l)
	c=l.count("1")
	if c==4:
		s=5
		print"C"
	if s==1:
		if c==1:print"B"
		elif t/p==1:print"F"
		else: print"D"
		s=5
	elif s==2:
		if p>t:print"E"
		elif p==t:print"A"
		else: print"G"
		s=5
	else:
		p=t
		s=c

Measured memory_bytes: 4228
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
using namespace std;

static const int INF=1e9;
typedef long long ll;

bool compare_by_second(pair<string, int> a,pair<string, int> b)
{
    if(a.second != b.second){
        return a.second > b.second;
    }else{
        return a.first < b.first;
    }    
}

int main(){
    int N; cin >> N;
    pair<string,pair<int,int> > res[N];
    for(int i=0;i<N;i++){
        string S;
        int P;
        cin >> S >> P;
        res[i]=make_pair(S,make_pair(P,i+1));
    }
    sort(res,res+N);
    for(int i=0;i<N;i++){
        for(int j=i+1;j<N;j++){
            if(res[i].first==res[j].first){
                if(res[i].second.first<res[j].second.first){
                    swap(res[i],res[j]);
                }
            }
        }
    }
    for(int i=0;i<N;i++){
        cout << res[i].second.second << endl;
    }

}


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

int main(){
    int n;
    cin >> n;
    vector<pair<double, double>> p(n);
    rep(i,n){
        double x, y;
        cin >> x >> y;
        p[i] = make_pair(x, y);
    }
    double ans = 0;
    sort(p.begin(), p.end());
    do{
        rep(i,n-1){
            double dx = abs(p[i+1].first - p[i].first);
            double dy = abs(p[i+1].second - p[i].second);
            ans += (double) sqrt(dx*dx + dy*dy);
        }
    }while(next_permutation(p.begin(),p.end()));
    double waru = 1;
    for(int i=1; i<=n; i++) waru *= i;
    cout<<fixed<<setprecision(10);
    cout << ans/waru << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define pb push_back
#define sz(x) (int)(x).size()
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;


int main() {
  int n, W;
  cin >> n >> W;
  vi w(n+10);
  vl v(n+10);
  rrep(i,n){
    cin >> w[i] >> v[i];
  }
  
  ll dp[n+10][W+10];
  rep(i,W+1){
    dp[0][i]=0;
  }
  rrep(i,n){
    rep(j,W+1){
      if(j>=w[i]){
        dp[i][j] = max(dp[i-1][j], dp[i-1][j-w[i]]+v[i]);
      }
      else dp[i][j] = dp[i-1][j];
    }
  }
  cout << dp[n][W] << endl;
  return 0;
}

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

lli w, h, n;

int main(void){
	cin >> w >> h >> n;
	lli l, r, u, d;
	l = d = 0;
	r = w;
	u = h;
	rep(i, n){
		lli a, x, y;
		cin >> x >> y >> a;
		if(a == 1){
			l = max(l, x);
		}else if(a == 2){
			r = min(r, x);
		}else if(a == 3){
			d = max(d, y);
		}else{
			u = min(u, y);
		}
	}
	//cout << l << " " << r << " " << d << " " << u << endl;
	if(l > r || d > u) cout << 0 << endl;
	else cout << (r-l)*(u-d) << endl;
	return 0;
}


Measured memory_bytes: 3508
n = input()
k = int(input())
keta = len(n)


dp_small = [ [0]*5 for _ in range(keta+1)]
dp_same = [ [0]*5 for _ in range(keta+1)]

dp_small[0][0] = 0
dp_same[0][0] = 1

for i in range(keta):
    num = int(n[i])
    for j in range(4):
        dp_small[i+1][j+1] += dp_small[i][j] * 9
        dp_small[i+1][j] += dp_small[i][j]
        if num != 0:
            dp_small[i+1][j+1] += dp_same[i][j]*(num-1)
            dp_small[i+1][j] += dp_same[i][j]

        if num == 0:
            dp_same[i+1][j] += dp_same[i][j]
        else:
            dp_same[i+1][j+1] += dp_same[i][j]

print(dp_same[-1][k]+dp_small[-1][k])

Measured memory_bytes: 62096
s = str(input())

t = 0
a = list()
p = 0
for x in s:
    if x == "0":
        if p==0:
            a.append("0")
        else:
            a[t] = "0"
            p -= 1
        t +=1
    elif x == "1":
        if p==0:
            a.append("1")
        else:
            a[t] = "1"
            p-=1
        t +=1
    elif x == "B":
        if t != 0:
            t -=1
            p+=1

i = 0
ans = str()
while i < t:
    ans += a[i]
    i +=1
print(ans)


Measured memory_bytes: 3064
import java.util.*;
import java.io.*;
import static java.lang.Math.*;

class Main {

    public static void main( final String[] args ) {

	final Scanner stdin = new Scanner( System.in );

	while ( true ) {

	    final int x = stdin.nextInt();
	    final int h = stdin.nextInt();

	    if ( x == 0 && h == 0 ) {
		break;
	    }

	    final double S = x * x + 2.0 * x * sqrt( h * h + 0.25 * x * x );
	    
	    System.out.println( S );	    
	}	
    }    
}

Measured memory_bytes: 17156
from math import sqrt
n=int(input())
p=[list(map(int,input().split())) for i in range(n)]
l=[]
m=1
for i in range(n):
    m*=i+1
    for j in range(i+1,n):
        r=sqrt((p[i][0]-p[j][0])**2+(p[i][1]-p[j][1])**2)
        l.append(r)

a=(n-1)*m//len(l)
print((sum(l)*(a))/m)


Measured memory_bytes: 3064
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define inf 1e+9
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }

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

    int p,q,r,min=inf;
	cin >> p >> q >> r;

	
	if(p+q<min){
		min = p+q;
	}
	if(r+q<min){
		min = r+q;
	}
	if(p+r<min){
		min = p+r;
	}
	
	cout << min << endl;
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
#define rep(i,n) for(long long i=0; i<n; i++)
#define Rep(i,n) for(long long i=1; i<n; i++)
#define ll long long
#include <math.h>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <queue>
#include <set>
#include <vector>


using namespace std;
#define PI acos(-1)
using P =pair<int,int>;

ll f(ll x,ll c,ll d){
    ll res =x;
    res -=x/c;
    res -=x/d;
    res+= x/lcm(c,d);
    return res;
}

vector<int> to[100005];
const ll inf =100000000;

vector<ll>a,b,c,d;
ll n,m,q;
ll ans=0;
void bfs(vector<ll> v){
   if(v.size()==n+1) {
       ll sum=0;
       rep(i,q){
           if(v[b[i]]-v[a[i]]==c[i])sum+=d[i];
       }
       ans=max(ans,sum);
       return;
   }
   v.push_back(v.back());
   bfs(v);
   while(v.back()<m){
       v.back()++;
       bfs(v);
   }
}

int main(){
string s;
cin>>s;
ll sum=0;
rep(i,s.size()){
    sum+=s[i]-'0';
}
if(sum%9==0)cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}


Measured memory_bytes: 6076
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
#define tmax(a,b,c) max(a,max(b,c))
#define tmin(a,b,c) min(a,min(b,c))
#define pb push_back
using namespace std;
using ll = long long;
using P = pair<int,int>;
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;}
const int inf = 1001001001;

int main() {
    double l;
    cin >> l;
    double edge = l/3.0;
    double ans = edge*edge*edge;
    printf("%.8f",ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef pair<ll,ll> P;
struct edge{ll to, cost;};
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define INF 1000000000000
#define ALL(a)  (a).begin(),(a).end()

vector<int> v;

void rekkyo(int n, int r){
    if(n == 0) {
        v.push_back(r);
        return ;
    }
    rekkyo(n-1,r * 10 + 3);
    rekkyo(n-1,r * 10 + 5);
    rekkyo(n-1,r * 10 + 7);
}

int main(){
    ll n;
    ll ans = 0;
    cin >> n;
    for(int i = 0; i <= 9; i++){
        rekkyo(i,0);
    }
    for(int i = 0; i < v.size(); i++){
        bool th,fi,se;
        th = false,fi = false,se = false;
        string hoge = to_string(v[i]);
        for(int j = 0; j < hoge.length(); j++){
            char fuga = hoge[j];
            if(fuga == '3'){
                th = true;
            }
            else if(fuga == '5'){
                fi = true;
            }
            else if(fuga == '7'){
                se = true;
            }
        }
        if(th && fi && se && v[i] <= n) ans++;
    }
    cout << ans << endl;

}

Measured memory_bytes: 512
#include <algorithm>
#include <complex>
#include <cassert>
#include <vector>
using namespace std;
const double eps = 1e-10;
#define EQ(a, b) (abs((a) - (b)) < eps)
using P = complex<double>;      // position
struct L : vector<P> {
    L(const P &a = P(), const P &b = P()) {
        emplace_back(a); emplace_back(b);
    }
};
ostream &operator<<(ostream &os, P p) { return os << real(p) << " " << imag(p); }
double dot(const P &a, const P &b) { return real(conj(a) * b); }
double cross(const P &a, const P &b) { return imag(conj(a) * b); }

enum CCW_RESULT { CCW = +1, CW = -1, BEHIND = +2, FRONT = -2, ON = 0 };
int ccw(P a, P b, P c) {
    b -= a; c -= a;
    if (cross(b, c) > eps) return CCW;      // counter clockwise
    if (cross(b, c) < -eps) return CW;      // clockwise
    if (dot(b, c) < 0) return BEHIND;       // c--a--b on line
    if (norm(b) < norm(c)) return FRONT;    // a--b--c on line | a=b
    return ON;                              // on segment | a=c | b=c
}
P crosspointLL(const L &l, const L &m) {
    double A = cross(l[1] - l[0], m[1] - m[0]);
    double B = cross(l[1] - l[0], l[1] - m[0]);
    if (abs(A) < eps && abs(B) < eps) return m[0];  // same line
    assert(abs(A) > eps);
    return m[0] + B / A * (m[1] - m[0]);
}

#include <iostream>
#include <iomanip>
int main() {
    cout << fixed << setprecision(10);
    int q; cin >> q;
    while (q--) {
        vector<P> ps;
        for (int i = 0; i < 4; i++) {
            int x, y; cin >> x >> y;
            ps.emplace_back(x, y);
        }
        P p = crosspointLL(L(ps[0], ps[1]), L(ps[2], ps[3]));
        cout << p << endl;
    }
    return 0;
}


Measured memory_bytes: 3272
N, M = map(int,input().split()) # 複数の数字を変数に格納
List = [list(map(str,input().split())) for i in range(M)]

ac = [0]*N
wa = [0]*N

for i in range(M):
    num = int(List[i][0])-1
    result = List[i][1]
    if ac[num] == 0:
        if result == 'AC':
            ac[num] = 1
        else:
            wa[num] += 1

total_ac = 0
total_wa = 0

for i in range(N):
    if ac[i] == 1:
        total_ac += ac[i]
        total_wa += wa[i]
    
print(total_ac, total_wa)

Measured memory_bytes: 33676
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;

using ll = long long;

int main()
{
    string n;
    cin >> n;
    for (int i = 0; i < n.size(); i++) {
        if (n[i] == '7') {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
ll h[201000];
ll a[201000];
struct SegmentTree
{
private:
    int n;
    vector<ll> node;

public:
    SegmentTree(int sz)
    {
        n = 1;
        while (n < sz)
            n *= 2;
        node.resize(2 * n - 1, 0);
        for (int i = 0; i < sz; i++)
            node[i + n - 1] = 0;
        for (int i = n - 2; i >= 0; i--)
            node[i] = max(node[2 * i + 1], node[2 * i + 2]);
    }

    void update(int x, ll val)
    {
        x += (n - 1);
        node[x] = val;
        while (x > 0)
        {
            x = (x - 1) / 2;
            node[x] = max(node[2 * x + 1], node[2 * x + 2]);
        }
    }

    ll getmax(int a, int b, int k = 0, int l = 0, int r = -1)
    {
        if (r < 0)
            r = n;
        if (r <= a || b <= l)
            return 0;
        if (a <= l && r <= b)
            return node[k];

        ll vl = getmax(a, b, 2 * k + 1, l, (l + r) / 2);
        ll vr = getmax(a, b, 2 * k + 2, (l + r) / 2, r);
        return max(vl, vr);
    }
};
int main()
{
    ll n;
    cin >> n;
    SegmentTree segtree(n+10);
    rep(i,n){
        cin >> h[i];
    }
    rep(i,n){
        cin >> a[i];
    }
    rep(i,n){
        ll tmp = segtree.getmax(0,h[i]);
        segtree.update(h[i],tmp+a[i]);
    }
    cout << segtree.getmax(0,n+1) << endl;
    return 0;
}

Measured memory_bytes: 7424
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define forever for (;;)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
template<typename A> using V = std::vector<A>;
template<typename A> using F = std::function<A>;
template<typename A, typename B> using P = std::pair<A, B>;
using pii = P<int, int>;
using vi = V<int>;
using vd = V<double>;
using vs = V<std::string>;
using vpii = V<pii>;
using vvi = V<vi>;
using vvpii = V<vpii>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979;
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int n) { return n & 1; }
constexpr bool even(const int n) { return ~n & 1; }
template<typename T> std::istream &operator>>(std::istream &is, std::vector<T> &v) { for (T &x : v) is >> x; return is; }
template<typename A, typename B> std::istream &operator>>(std::istream &is, std::pair<A, B> &p) { is >> p.first; is >> p.second; return is; }
using namespace std;
// clang-format on

main {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> g(n, vector<int>(n));
  while (m--) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    g[a][b] = g[b][a] = true;
  }
  int c = 0;
  function<void(int, int)> dfs = [&](int v, int visited) {
    if (visited & (1 << v)) return;
    visited |= 1 << v;
    if (visited == (1 << n) - 1) c++;
    for (int u = 0; u < n; u++) {
      if (g[v][u]) dfs(u, visited);
    }
  };
  dfs(0, 0);
  cout << c << endl;
}


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


int main(){
  ll N,K;
  cin >> N >> K;
  
  vector <ll> h(N);
  vector <ll> coudp(N+1,INT_MAX);
  coudp.at(0)=0;
  
  rep(i,N)
    cin >> h.at(i);
  
  for(int i=1;i<N;i++){
    
    rep(j,K){
      if(i-j-1>=0){
        
        coudp.at(i)=min(coudp.at(i-j-1)+zettaichi(h.at(i),h.at(i-j-1)),coudp.at(i));
       // cout << i << coudp.at(i) << endl;
        
        
      }
    }
  
  }
  
  cout << coudp.at(N-1) << endl;
  
  }

  
  
  
  

int zettaichi(int h1,int h2){
  
  if(h1>h2)
    return h1-h2;
  else
    return h2-h1;
 
}






Measured memory_bytes: 1792
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <ctime>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <numeric>
#include <cassert>
using namespace std;
static const double EPS = 1e-10;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define all(a) a.begin(),a.end()
#define mp(a,b,c) make_pair(make_pair(a,b),c)
#define pb(a) push_back(a)
#define SS stringstream
#define DBG1(a) rep(_X,sz(a)){printf("%d ",a[_X]);}puts("");
#define DBG2(a) rep(_X,sz(a)){rep(_Y,sz(a[_X]))printf("%d ",a[_X][_Y]);puts("");}
#define bitcount(b) __builtin_popcount(b)
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)

#define delete(a,n) a.erase(remove(all(a),n),a.end())
template<typename T, typename S> vector<T>& operator<<(vector<T>& a, S b) { a.push_back(b); return a; }
template<typename T> void operator>>(vector<T>& a, int b) {while(b--)if(!a.empty())a.pop_back();}
bool isprime(int n){ if(n<2)return false;  for(int i=2;i*i<=n;i++)if(n%i==0)return false;  return true;} 
ll b_pow(ll x,ll n){return n ? b_pow(x*x,n/2)*(n%2?x:1) : 1ll;}
string itos(int n){stringstream ss;ss << n;return ss.str();}
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define ALL(c) (c).begin(), (c).end()

typedef unsigned int uint;
int in() {
    int x = 0, c;
    for (; (uint)((c = getchar()) - '0') >= 10; ) { if (c == '-') return -in(); if (!~c) throw ~0; }
    do { x = (x << 3) + (x << 1) + (c - '0'); } while ((uint)((c = getchar()) - '0') < 10);
    return x;
}

string s;
int n,c;

int answer = -1;

int dfs(int r){
	if( answer != -1 ) return 0;
	if( r == 0 ){
		string rs = s;
		reverse(rs.begin(),rs.end());
		int v = atoi((s+(c<0?"":string(1,c+'0')+rs)).c_str());
		if( isprime(v) ){
			answer = max(answer,v);
		}
		return 0;
	}
	for(int i = 9 ; i >= 0 + (r==n) ; i--){
		s[n-r] = '0' + i;
		dfs(r-1);
	}
} 
int main(){
	cin >> n >> c;
	if( c < 0 ){
		if( n == 1 ){
			cout << 11 << endl;
		}else{
			cout << string(2*n,'9') << endl;
		}
	}else{
		s = string(n,'~');
		dfs(n);
		if( answer == -1 ){
			cout << string(n,'9') << c << string(n,'9') << endl;
		}else{
			cout << answer << endl;
		}
	}
}

Measured memory_bytes: 1228
#include <iostream>

using namespace std;

int main() {
	int n, k;
	cin >> n >> k;
	int a[n];
	for (int i = 0; i < n; i++) 
		cin >> a[i];
	bool dp[k + 1] = {0};
	for (int i = 1; i <= k; i++) {
		for (int j = 0; j < n; j++) {
			if (i - a[j] < 0) continue;
			if (!dp[i - a[j]]) dp[i] = 1;
		}
	}
	if (dp[k])
		cout << "First" << endl;
	else
		cout << "Second" << endl;
}


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

#define INF 1000000007
#define LINF 1000000000000000007

using namespace std;

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


int n, p[101][11];
bool f[101][10];

int main(){
	cin >> n;
	for(int i = 0; i < n; i++){
		for(int j = 0; j < 10; j++){
			cin >> f[i][j];
		}
	}
	for(int i = 0; i < n; i++){
		for(int j = 0; j <= 10; j++){
			cin >> p[i][j];
		}
	}
	
	int ans = -INF;
	for(int i = 1; i < (1 << 10); i++){
		int c = 0;
		for(int j = 0; j < n; j++){
			int cnt = 0;
			for(int k = 0; k < 10; k++){
				if((i >> k) & 1 && f[j][k]) cnt++;
			}
			c += p[j][cnt];
		}
		ans = max(ans, c);
	}
	
	cout << ans << endl;
	
	return 0;
}

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

int main(){
	string s;
	cin>>s;
	if(s=="SUN"){
		cout<<7<<endl;
	}else if(s=="MON"){
		cout<<6<<endl;
	}else if(s=="TUE"){
		cout<<5<<endl;
	}else if(s=="WED"){
		cout<<4<<endl;
	}else if(s=="THU"){
		cout<<3<<endl;
	}else if(s=="FRI"){
		cout<<2<<endl;
	}else{
		cout<<1<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
using namespace std;


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

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
	stringstream ss;
	ss << f;
	ss >> t;
}


#define REP(i,n) for(int i=0;i<int(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define RALL(v) (v).rbegin(),(v).rend()
#define PB push_back


#define MOD 1000000009LL
#define EPS 1e-8

#define NMAX 44
int F[NMAX];

void initialize(){
	for( int i = 0; i < NMAX;  i++ ){
		F[i] = 0;
	}
}

int fibonacci(int n){
	if( n == 0 || n == 1 ) return 1;
	if( F[n] != 0) return F[n];
	return F[n] = fibonacci( n - 1 ) + fibonacci( n - 2);
}

int main(){
	int n;
	scanf("%d", &n);
	int ans = fibonacci(n);
	printf("%d\n", ans);
	return 0;
}

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

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

"""
"""

def warshall_floyd(d):
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d

n,m,l = LI()

dist = [[inf]*n for _ in range(n)]
dist2 = [[inf]*n for _ in range(n)]

for i in range(n):
    dist[i][i] = 0
    dist2[i][i] = 0
for _ in range(m):
    a,b,c = LI()
    dist[a-1][b-1] = c
    dist[b-1][a-1] = c

dist = warshall_floyd(dist)

for i in range(n):
    for j in range(n):
        if dist[i][j] > l:
            dist2[i][j] = inf
        else:
            dist2[i][j] = 1

dist2 = warshall_floyd(dist2)
q = I()
ans = []
for _ in range(q):
    s,t = LI()
    if dist2[s-1][t-1] == inf:
        print(-1)
    else:
        print(dist2[s-1][t-1]-1)



Measured memory_bytes: 127580
from collections import Counter
N=int(input())
S=[input() for _ in range(N)]
dic = dict(Counter(S))

def kind(a):
  b=dic.get(a)
  if b!=None:
    return(b)
  else:
    return(0)

print('AC x',kind('AC'))
print('WA x',kind('WA'))
print('TLE x',kind('TLE'))
print('RE x',kind('RE'))

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

//ベクトルが白のみか判定
bool Iswhite_v (vector<char> v){
  bool iswhite = false;
  int counter = 0;
  for(char x:v){
   if (x == '.'){
    counter++;
   }
  }
  if(v.size() == counter){
   iswhite = true; 
  }
  return iswhite;
}

//行列のj列を取り出す
vector<char> row_take(int j,vector<vector<char>> a){
  int x = a.size();
  int y = a.at(0).size();
  vector<char> r(x);
  if (j>y){
   cout << "Impossible" << endl;
    return {};
  }
  for(int i =0;i<x;i++){
   r.at(i) = a.at(i).at(j); 
  }
  return r;
}

//白のみの行の判定
bool Iswhite_l(vector<vector<char>> a){
  int x = a.size();
  int y = a.at(0).size();
  for (int i = 0 ; i <x ;i++){
    if(Iswhite_v(a.at(i))){
      return true;
    }
  }
  return false;
}

//白のみの列判定
bool Iswhite_r(vector<vector<char>> a){
  int x = a.size();
  int y = a.at(0).size();
  vector<char> row(x);
  for (int j = 0 ; j <y ;j++){
    row = row_take(j,a);
    if(Iswhite_v(row)){
      return true;
    }
  }
  return false;
}

//白のみの行を消す
vector<vector<char>> vanish_white_l(vector<vector<char>> a){
  int y = a.at(0).size();
  vector<vector<char>> b = a;
  while(Iswhite_l(b)){
   for(int i= 0;i<b.size();i++){
    if(Iswhite_v(b.at(i))){
      b.erase(b.begin()+i);
      break;
    }
   }
  }
  return b;
}

//白のみの列を消す
vector<vector<char>> vanish_white_r(vector<vector<char>> a){
  int x = a.size();
  vector<vector<char>> b = a;
  while(Iswhite_r(b)){
   for(int j= 0;j<b.at(0).size();j++){
    if(Iswhite_v(row_take(j,b))){
      for(int i = 0;i<x;i++){
       b.at(i).erase(b.at(i).begin()+j); 
      }
      break;
    }
   }
  }
  return b;
}

void mat_out( vector<vector<char>> a ){
  int x = a.size();
  int y = a.at(0).size();
  for (int i = 0;i<x;i++){
   for(int j = 0;j<y;j++){
    cout << a.at(i).at(j);
     if(j == y-1){
      cout << "" <<endl; 
     }
   }
  }
}
 
int main() {
  int H,W;
  cin >> H >> W;
  vector<vector<char>> R(H,vector<char>(W));
  for(int i = 0; i<H;i++){
    for(int j = 0;j<W;j++){
     cin >> R.at(i).at(j); 
    }
  }
  while (Iswhite_r(R)||Iswhite_l(R)){
   R = vanish_white_l(R);
   R = vanish_white_r(R);
  }
  //表を表示
  mat_out(R);
}

Measured memory_bytes: 256
L = []
m, f, r = map(int, input().split())
while not(m == -1 and f == -1 and r == -1):
 L.append([m, f, r])
 m, f, r = map(int, input().split())
 
for i in L:
 if i[0] == -1 or i[1] == -1:
  print("F")
 elif i[0] + i[1] >= 80:
  print("A")
 elif i[0] + i[1] >= 65:
  print("B")
 elif i[0] + i[1] >=  50:
  print("C")
 elif i[0] + i[1] >= 30 and i[2] >=50:
  print("C")
 elif i[0] + i[1] >= 30:
  print("D")
 else:
  print("F")

Measured memory_bytes: 7660
import sys
input = sys.stdin.readline
 
def I(): return int(input())
def S(): return str(input())
def MI(): return map(str, input().split("\n"))
def LI(): return list(map(str, input().split()))

N = I()
c0 = c1 = c2 = c3 = 0
for i in range(N):
  
  ans = S().rstrip('\n')
  if ans == "AC":
    c0 += 1
  elif ans == "WA":
    c1 += 1
  elif ans == "TLE":
    c2 += 1
  elif ans == "RE":
    c3 += 1

print(f"AC x {c0}\nWA x {c1}\nTLE x {c2}\nRE x {c3}\n")

Measured memory_bytes: 73864