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

#define ll long long int
#define vi vector<int>
#define vc vector<char>
#define vl vector<ll>
#define vii vector<pair<int,int>>
#define vll vector<pair<ll,ll>>
#define pb push_back
#define el '\n'
#define N 1000000007
#define re return
#define PI 3.14159265
#define take(a,n) for(int i=0;i<(n);i++) cin>>(a)[i]
#define out(a,n) for(int i=0;i<n;i++) cout<<a[i]<<" ";
#define all(a) (a).begin(),(a).end()
#define forup(i,n) for(int (i)=0;i<(n);(i)++)
#define ford(i,n) for(int (i)=(n)-1;i>=0;(i)--)
using namespace std;


ll poww(ll a,ll b)
{
  ll ans=1;
  for(int i=1;i<=b;i++)
  {
    ans*=a;
  }
  return ans;
}


int max(int a,int b,int c)
{
  if(a>=b && a>=c) return a;
  if(b>=a && b>=c) return b;
  return c;
}


int main()
{
  ll n,q;
  //cin>>n>>q;
  string s,t;
  cin>>s>>t;
  vi cs[26];
  forup(i,s.length())
    cs[s[i]-'a'].pb(i);
  forup(i,t.length())
    if(!cs[t[i]-'a'].size()){cout<<"-1";re 0;}

  ll ans=-1;
  n=s.length();
  if(n==1) {cout<<t.length(); re 0;}

  forup(i,t.length())
  {
    ll temp=ans/n;
    //cout<<temp<<endl;
    while(ans>=temp*n+cs[t[i]-'a'][cs[t[i]-'a'].size()-1]) temp++;
    //cout<<temp<<" ";

    ll low=0,high=cs[t[i]-'a'].size()-1;
    while(low<high)
    {
      ll mid=low + (high-low)/2;
      if(ans>=temp*n+cs[t[i]-'a'][mid]) {low=mid+1;}
      else high=mid;
    }
    ans=temp*n+cs[t[i]-'a'][low];

    /*

    for(auto x:cs[t[i]-'a'])
    {
      if(x+temp*n>ans) {ans=x+temp*n;break;}
    }


    */
  }

  cout<<ans+1;
  re 0;

}


Measured memory_bytes: 1216
import sys
import heapq
input = sys.stdin.buffer.readline


def dijkstra(adj, start):
    # adj: [[to, cost] * vertices], 0th index must be empty
    dist = [float('inf')] * len(adj)
    dist[start] = 0
    q = []
    heapq.heappush(q, (0, start))
    while q:
        min_dist, v_from = heapq.heappop(q)
        if min_dist > dist[v_from]:
            continue
        v_tos = adj[v_from]
        for v_to, cost in v_tos:
            if min_dist + cost < dist[v_to]:
                dist[v_to] = min_dist + cost
                heapq.heappush(q, (dist[v_to], v_to))
    return dist


N, M = map(int, input().split())
adj = [[] for _ in range(N+1)]
for _ in range(M):
    L, R, C = map(int, input().split())
    adj[L].append((R, C))
for i in range(2, N+1):
    adj[i].append((i-1, 0))

dist = dijkstra(adj, 1)
# print(adj)
if dist[N] < 10**20:
    print(dist[N])
else:
    print(-1)


Measured memory_bytes: 81092
#include <cmath>
#include <queue>
#include <cstdio>
#include <string>
#include <vector>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <functional>
#pragma warning(disable : 4996)
using namespace std;
int N, M, a, b, d[2009][2009]; vector<int> G[2009], H[2009][2009];
int main() {
	cin >> N >> M;
	for (int i = 0; i < N - 1; i++) {
		cin >> a >> b; a--, b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	for (int i = 0; i < N; i++) {
		fill(d[i], d[i] + N, -1); d[i][i] = 0;
		queue<int> que; que.push(i);
		while (!que.empty()) {
			int u = que.front(); que.pop();
			for (int e : G[u]) {
				if (d[i][e] == -1) {
					d[i][e] = d[i][u] + 1;
					que.push(e);
				}
			}
		}
	}
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			H[i][d[i][j]].push_back(j);
		}
	}
	int ret = 0;
	for (int i = 0; i < N; i++) {
		int res = 0;
		for (int j = 0; j < N; j++) {
			if (d[i][j] <= M / 2) res++;
		}
		if (M % 2 == 1) {
			int res1 = 0;
			for (int j : G[i]) {
				int res2 = 0;
				for (int k: H[j][M / 2]) {
					if (d[i][k] > M / 2) res2++;
				}
				res1 = max(res1, res2);	
			}
			res += res1;
		}
		ret = max(ret, res);
	}
	cout << N - ret << endl;
	return 0;
}

Measured memory_bytes: 204416
n,k = map(int,input().split())
s = input()
ls =[]
p = s[0]
cnt = 1
for i in range(1,n):
    if p != s[i]:
        ls.append((p,cnt))
        cnt = 0
    cnt += 1
    p = s[i]
ls.append((p,cnt))

l = len(ls)
ans = 0
for i in range(k):
    idx = 2*i+1
    if idx >l-1:break
    if idx == l-1:
        ans+=1
        break
    ans +=2
for w,c in ls:
    ans+=c-1
print(ans)


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

int main()
{
	int n;
	cin >> n;
	vector<long double> xs(n), ys(n);
	for (auto &x : xs)
	{
		cin >> x;
	}
	for (auto &y : ys)
	{
		cin >> y;
	}
	vector<long double> ps(4, 0);
	for (int i = 0; i < n; i++)
	{
		ps[0] += abs(xs[i] - ys[i]);
	}
	for (int i = 0; i < n; i++)
	{
		ps[1] += (xs[i] - ys[i]) * (xs[i] - ys[i]);
	}
	ps[1] = sqrt(ps[1]);
	for (int i = 0; i < n; i++)
	{
		ps[2] += abs((xs[i] - ys[i]) * (xs[i] - ys[i]) * (xs[i] - ys[i]));
	}
	ps[2] = pow(ps[2], 1.0 / 3);
	for (int i = 0; i < n; i++)
	{
		ps[3] = max(ps[3], abs(xs[i] - ys[i]));
	}
	for (auto &p : ps)
	{
		cout << fixed << setprecision(20) << p << endl;
	}
	return 0;
}


Measured memory_bytes: 3412
n, m = map(int, input().split())
C = [0]*(n+1)
C[1] = 1
D = [1]*(n+1)
for _ in range(m):
  x, y = map(int, input().split())
  if C[x]:
    C[y] = 1
    if D[x] == 1:
      C[x] = 0
  D[x] -= 1
  D[y] += 1
ans = sum(C)
print(ans)

Measured memory_bytes: 10376
#include <stdio.h>
#include <cmath>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
int a[20];
int n;

bool DFS(int k, int m, double r){
	int s=ceil(a[k]*(1-r));
	if(s==0)s=1;
	int e=ceil(a[k]*(1+r));
	for(int p=((s-1)/m+1)*m;p<e;p+=m)
		if(k==n-1)return true;
		else if(DFS(k+1,p,r))return true;
	return false;
}

int main(){
	scanf("%d",&n);
	REP(i,n)scanf("%d",a+i);
	double u=1.0, l=0.0;
	REP(i,30){
		double m=(u+l)*0.5;
		if(DFS(0,1,m))u=m;
		else l=m;
	}
	printf("%.9f\n",u);
	return 0;
}

Measured memory_bytes: 1076
#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>;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1LL << 60;





ll happy(vector<P> c){
    int cn = c.size();
    rep(i,cn) c[i].first = min(c[i].first, cn); //cnまでしかみないので同等
    
    vector<vector<int>> carray(cn+1);
    rep(i,cn) carray[c[i].first].push_back(-c[i].second);

    priority_queue<int> ok;
    for(int i = 1; i<= cn; ++i){
        for(int x : carray[i]) ok.push(x);
        while(ok.size() > i) ok.pop();
    }
    ll h=0;
    while(ok.size()>0){
        h += -ok.top();
        ok.pop();
    }
    return h;

}



void solve(){
    int N; cin >> N;
        //vector<int> K(N),L(N),R(N);
        vector<P> mae, ato;
        int Ki,Li,Ri;
        ll ans = 0;
        rep(i,N){
            cin >> Ki >> Li >> Ri;
            if( Li > Ri ){
                mae.emplace_back(Ki,Li-Ri);
            }else {
                ato.emplace_back(N-Ki,Ri-Li);
            }
            ans += min(Li,Ri);
        }

        ans += happy(mae);
        ans += happy(ato);
        cout << ans << endl;

    
}

//---main---------------------------------------------
int main(){
    //main
    int T;
    cin >> T;
    rep(ti,T) solve();

    return 0;
}

Measured memory_bytes: 10568
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	vector<int> v;
	multiset<int> s;
	for(int i=1;i<=n;i++)
	{
		int x;
		cin>>x;
		s.insert(x);
		v.push_back(x);
	}
	for(int i=0;i<n;i++)
	{
		int temp=v[i];
		s.erase(s.find(temp));
		auto it=s.end();
		it--;
		cout<<*it<<endl;
		s.insert(temp);
	}
	return 0;
}

Measured memory_bytes: 11764
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mod 1000000007
#define ff first
#define ss second
#define endl '\n'
using namespace std;
const ll inf=1e18+7 ;
/*ll power(ll x,ll y)
{
    ll res=1;
    while(y>0)
    {
        if(y%2==1)
            res=(res*x)%mod;
        x=(x*x)%mod;
        y=y/2;
    }
    return res;
}*/
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
   ll i,j,m,n,s=0;
   cin>>n;
   ll arr[n];
   for(i=0;i<n;i++)
    cin>>arr[i];
   for(i=0;i<n;i++)
    for(j=i+1;j<n;j++)
    s=s+arr[i]*arr[j];
   cout<<s<<endl;
}


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

int main() {
    int n, l;
    cin >> n >> l;
    string s[100];
    rep(i, n) cin >> s[i];
    sort(s, s + n);
    string ans = "";
    rep(i, n) ans += s[i];
    cout << ans << endl;
    return 0;
}

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

int main() {
    ll n, k, s;
    cin >> n >> k >> s;

    rep(i, n) {
        if (i < k)
            cout << s;
        else {
            if (s == 1e9)
                cout << 1;
            else
                cout << s + 1;
        }
        if (i != n - 1) cout << ' ';
    }
    cout << endl;

    return 0;
}


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

/* macro */
#define rep(i,a,b) for(int i=a;i<b;i++)
#define revrep(i,a,b) for(int i = a; i > b; i--)
#define int long long
#define exist(s,e) ((s).find(e)!=(s).end())
#define all(v) (v).begin(), (v).end()
#define each(s,itr) for(auto (itr) = s.begin(); (itr) != s.end(); (itr)++)
#define sum(v) accumulate(all(v), (0LL))
#define pb push_back


/* alias */
template<class T> using vec = vector<T>;
typedef vector<int> vi;
typedef pair<int, int> pi;


/* constant */
const int inf = 1000100010010010;
const int mod = 1e9 + 7;
int dx[8]={1,0,-1,0,-1,1,-1,1};
int dy[8]={0,1,0,-1,-1,-1,1,1};


/* io_method */
int input(){int tmp;cin >> tmp;return tmp;}
string raw_input(){string tmp;cin >> tmp;return tmp;}
string readline(){string s;getline(cin, s);return s;}
template<class T> void printx(T n){cout << n;}
template<class T, class U> void printx(pair<T, U> p){cout << "(" << p.first << "," << p.second << ")";}
template<class T> void printx(vector<T> v){cout << "{";rep(i,0,v.size()){printx(v[i]);if(i != v.size()-1)printx(",");}cout << "}";}
template<class T> void print(T n){printx(n);cout << endl;}
template<class T> void print(set<T> s){cout << "{";each(s, e){if(e != s.begin()) printx(",");printx(*e);}cout << "}" << endl;}
template<class T, class U> void print(map<T, U> mp){cout << "{";each(mp, e){cout << "(" << e -> first << "," << e -> second << ")";}cout << "}" << endl;}


/* general_method */
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class T>auto cut(T &a, int l, int r){return T(a.begin()+l, a.begin()+r);}

/* main */



signed main(){


    cin.tie(0);
    ios::sync_with_stdio(false);

    int n, h, w; cin >> n >> h >> w;

    print((n - h + 1) * (n - w + 1));


    



    


    

}



Measured memory_bytes: 256
D, G = map(int, input().split())
p, c = [], []
for i in range(D):
    a, b = map(int, input().split())
    p.append(a)
    c.append(b)

res = 1 << 29
for bit in range(1 << D):
    score, num = 0, 0
    for i in range(D):
        if bit >> i & 1: # bit & (i << i)
            score += c[i] + p[i] * 100 * (i + 1)
            num += p[i]
    if score >= G:
        res = min(res, num)
    else:
        for j in range(D - 1, -1, -1):
            if bit >> j & 1: # bit & (i << i)
                continue
            for k in range(p[j]):
                if score >= G:
                    break
                score += 100 * (j + 1)
                num += 1
        res = min(res, num)
print(res)

Measured memory_bytes: 42224
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
#define F(i,a,b) for(int i=int(a);i<=int(b);i++)
#define endl "\n"
#define ios std::ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define out(x) cout<<x<<endl,exit(0);
#define pb push_back
#define all(v) v.begin(),v.end()
#define I first
#define S second

const int N=1e5+9;
int dp[N][3];

int main(){
	ios;
	int n,a,b,c;
	cin>>n;

	F(i,1,n){
		cin>>a>>b>>c;
		dp[i][0]=max(dp[i-1][1],dp[i-1][2])+a;
		dp[i][1]=max(dp[i-1][0],dp[i-1][2])+b;
		dp[i][2]=max(dp[i-1][0],dp[i-1][1])+c;
	}

	cout<<max(max(dp[n][0],dp[n][1]),dp[n][2]);
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
int main ()
{
	int k;
	string s;
	cin>>k>>s;
	if(k>=s.size())
	{
		cout<<s;
		return 0;
	}
	s.erase(k,k-s.size());
	s+="...";
	cout<<s;
	return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define lli long long int
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define test lli t;cin>>t;while(t--)
#define arrin lli n;cin>>n;lli a[n];for(lli i=0;i<n;i++)cin>>a[i]
#define floop for(lli i=0;i<n;i++)
#define mod 1000000007
#define defvec vector<lli>v
#define ub upper_bound
#define pb push_back
#define bs binary_search
using namespace std;

int main() {
   
    int n,x,e=0,o=0,sum=0;
	    cin>>n>>x;
	   lli z=n*x;
	   cout<<z<<endl;
	    
}


Measured memory_bytes: 3604
using System;
using System.Linq;

class Program
{
    public static void Main(string[] args) {
        double[] s = Console.ReadLine().Split().Select(double.Parse).ToArray();
        double a = s[0];
        double b = s[1];
        double angle = s[2]*(Math.PI / 180);
        double h = b * Math.Sin(angle);
        double c = Math.Sqrt(a*a + b*b - 2*a*b*Math.Cos(angle));
        Console.WriteLine("{0}\n{1}\n{2}", h*a/2, a+b+c, h);
    }
}


Measured memory_bytes: 16432
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

void solve(int h, int w){

    vector<string> G(h);
    vector<vector<char>> out(h, vector<char>(w, 0));
    array<int, 4> dy{0, 1, 0, -1}, dx{-1, 0, 1, 0};
    string D = "WSEN";
    for (int i = 0; i < h; ++i) {
        cin >> G[i];
    }
    for (int t = 0; t <= 180; ++t) {
        int cnt = 0;
        for (int i = 0; i < h; ++i) {
            for (int j = 0; j < w; ++j) {
                for (int k = 0; k < 4; ++k) {
                    if(G[i][j] == D[k]) cnt++;
                }
            }
        }
        if(!cnt){
            cout << t << "\n";
            return;
        }
        for (int y = 0; y < h; ++y) {
            for (int x = 0; x < w; ++x) {
                for (int i = 0; i < 4; ++i) {
                    if(G[y][x] == D[i]){
                        for (int j = 3; j < 7; ++j) {

                            int dir = (i+j)&3;
                            if(G[y+dy[dir]][x+dx[dir]] == '.' || G[y+dy[dir]][x+dx[dir]] == 'X'){
                                G[y][x] = D[dir];
                                i = 10;
                                break;
                            }
                        }
                    }
                }
            }
        }
        for (int dir = 0; dir < 4; ++dir) {
            for (int y = 0; y < h; ++y) {
                 for (int x = 0; x < w; ++x) {
                    if(G[y][x] == D[dir]){
                        if(G[y+dy[dir]][x+dx[dir]] == '.'){
                            G[y+dy[dir]][x+dx[dir]] = G[y][x]-'A'+'a';
                            G[y][x] = '|';
                        }else if(G[y+dy[dir]][x+dx[dir]] == 'X'){
                            G[y][x] = '|';
                            G[y+dy[dir]][x+dx[dir]] = '$';
                        }
                    }
                }
            }
        }
        for (int i = 0; i < h; ++i) {
            for (int j = 0; j < w; ++j) {
                if(islower(G[i][j])){
                    G[i][j] = G[i][j]-'a'+'A';
                }else if(G[i][j] == '$'){
                    G[i][j] = 'X';
                }else if(G[i][j] == '|'){
                    G[i][j] = '.';
                }
            }
        }

    }
    puts("NA");
}

int main() {
    int w, h;
    while(cin >> w >> h, h){
        solve(h, w);
    }
    return 0;
}



Measured memory_bytes: 3004
n,a,b = map(int, input().split())
x = list(map(int, input().split()))
x = [x[0]]+x

ans = 0
for i in range(1,n+1):
  if (x[i]-x[i-1])*a < b: ans += (x[i]-x[i-1])*a
  else: ans += b
print(ans)

Measured memory_bytes: 14252
#include <iostream>

using namespace std;


int main(){ 
	int n;
	cin >> n;
	int stu[n];
	for(int i = 0; i < n; i++) cin >> stu[i];
	
	int num[n];
	for(int i = 0; i < n; i++) num[stu[i]-1] = i+1;
	for(int i = 0; i < n; i++) cout << num[i] << " ";
	cout << endl;
	return 0;
}


Measured memory_bytes: 4308
#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 1234567890123456789LL
#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

typedef long long cat;

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

struct fin {
	vector<int> T;
	fin() {}
	fin(int N) {T.resize(N+10, 0);}

	int lastone(int x) {return x&(x^(x-1));}

	void put(int pos, int val) {
		for(int i = pos+1; i < (int)T.size(); i += lastone(i)) T[i] = max(T[i], val);
	}

	int get(int pos) {
		int ret = 0;
		for(int i = pos+1; i > 0; i -= lastone(i)) ret = max(ret, T[i]);
		return ret;
	}
};

int main() {
	cin.sync_with_stdio(0);
	cin.tie(0);
	cout << fixed << setprecision(13);
	int P[2][2];
	int N;
	cin >> P[0][0] >> P[0][1] >> P[1][0] >> P[1][1];
	if(P[0][0] > P[1][0]) {
		swap(P[0][0], P[1][0]);
		swap(P[0][1], P[1][1]);
	}
	bool swp = (P[0][1] > P[1][1]);
	cin >> N;
	vector< pair<int,int> > A;
	map<int, int> M;
	for(int i = 0; i < N; i++) {
		int x, y;
		cin >> x >> y;
		if(x < P[0][0] || x > P[1][0]) continue;
		if(y < min(P[0][1], P[1][1]) || y > max(P[0][1], P[1][1])) continue;
		A.push_back(make_pair(x, y));
		M[y] = 0;
	}
	N = A.size();
	int m = 0;
	ALL_THE(M, it) it->ss = m++;
	for(int i = 0; i < N; i++) A[i].ss = swp ? (m-1-M[A[i].ss]) : M[A[i].ss];
	sort(begin(A), end(A));
	fin F(m);
	vector<int> cnt(N, 1);
	int mxcnt = 0;
	for(int i = 0; i < N; i++) {
		cnt[i] = 1+F.get(A[i].ss);
		F.put(A[i].ss, cnt[i]);
		mxcnt = max(mxcnt, cnt[i]);
	}
	dbl ans = abs(P[1][0]-P[0][0])*100. + abs(P[1][1]-P[0][1])*100. + mxcnt * (pi*5-20);
	if(mxcnt == min(abs(P[1][0]-P[0][0])+1, abs(P[1][1]-P[0][1])+1)) ans += pi*5;
	cout << ans << "\n";
	return 0;}

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


Measured memory_bytes: 12784
#include <iostream>
#include <fstream>
#include <typeinfo>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<25;
const double pi=acos(-1);
const double eps=1e-8;
const vi emp;

string s;
vi a;
int n;

int main(){
	cin>>s>>n;
	a=vi(s.size());
	for(int i=0;i<s.size();i++) a[i]=(int)('z'-s[i])+1;
	for(int i=0;i<s.size();i++){
		if(!n) break;
		if(n>=a[i]&&s[i]!='a'){
			s[i]='a';
			n-=a[i];
		}
	}
	n%=26;
	s[s.size()-1]+=n;
	if(s[s.size()-1]>'z') s[s.size()-1]-=26;
	cout<<s<<endl;
}

Measured memory_bytes: 896
import sys

def solve():
    input = sys.stdin.readline
    S = input().strip("\n")
    zero, one = 0, 0
    for i in range(len(S)):
        if S[i] == "0": zero += 1
        else: one += 1
    print(2 * min(zero, one))

    return 0

if __name__ == "__main__":
    solve()

Measured memory_bytes: 3188
#include <stdio.h>

int K, S;
int ans = 0;

int main(void)
{
	scanf("%d%d", &K, &S);

	for (int X = 0; X <= K; ++X)
	{
		for (int Y = 0; Y <= K; ++Y)
		{
			int Z = S - (X + Y);
			if (Z < 0)
			{
			}
			else if (Z > K)
			{
			}
			else if (X + Y + Z == S)
			{
				++ans;
			}
		}
	}

	printf("%d\n", ans);
	return 0;
}

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

bool solve() {
  int N, M; cin >> N >> M;
  vector<vector<int>> g(N);
  vector<vector<int>> d(N);
  for (int i = 0; i < M; i++) {
    int a, b, c; cin >> a >> b >> c; a--, b--;
    g[a].push_back(b);
    g[b].push_back(a);
    d[a].push_back(c);
    d[b].push_back(-c);
  }
  vector<int> z(N, INT_MAX);
  auto dfs = [&](auto&& f, int now, int D) -> bool {
    if (z[now] != INT_MAX) return z[now] == D;
    z[now] = D;
    for (size_t i = 0; i < g[now].size(); i++) {
      if (!f(f, g[now][i], D + d[now][i])) return false;
    }
    return true;
  };
  for (int i = 0; i < N; i++) {
    if (z[i] != INT_MAX) continue;
    if (!dfs(dfs, i, 0)) return false;
  }
  return true;
}

int main() {
  cout << (solve() ? "Yes" : "No") << endl;
}


Measured memory_bytes: 15104
#define _CRT_SECURE_NO_WARNINGS // #pragma warning(disable:4996)
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <functional>
#include <sstream>
#include <cmath>
#include <set>
#include <map>
#include <stack>
using namespace std; 

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>=(b);i--)
#define pb push_back
#define mp(a,b) make_pair(a,b)
#define all(a) a.begin(),a.end()
#define len(x) ((int)(x).size())
#define tmax(a,b,c) max((a),max((b),(c)))
#define tmin(a,b,c) min((a),min((b),(c)))
#define debug(x) cerr << #x << " is " << x << endl;

typedef pair<int, int> Pii;
typedef map<int, int> Mii;
typedef vector<int> Vi;
typedef long long ll;
const int inf = 2e9;
const ll ll_inf = 1e17;
const int mod = 1e9 + 7;
const long double eps = 1e-10;

int main()
{
	string s;
	cin >> s;
	map<int, bool> m;
	rep(i,0,len(s)) {
		if (s[i] == 'N') m[0]++;
		else if (s[i] == 'S') m[1]++;
		else if (s[i] == 'E') m[2]++;
		else m[3]++;
	}

	if (m[0]==m[1] && m[2]==m[3]) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<queue>
#include<vector>
#include<string.h>
#include<algorithm>
#include<cmath>
#include<map>

using namespace std;

int i,j,k;

int main()
{
  for(i=1;i<=5;i++)
  {
    cin>>j;
    if(j==0)
    {
      cout<<i;
      return 0;
    }
  }
}

Measured memory_bytes: 3632
# coding: utf-8
# Your code here!
n,m = [int(i) for i in input().split()]
x = [int(i) for i in input().split()]
x.sort()

y=[x[i+1] -x[i] for i in range(m-1)]
y.sort()
print(sum(y[:max(m-n,0)]))

Measured memory_bytes: 13832
import           Control.Monad
import qualified Data.ByteString.Char8 as BS
import           Data.Char
import           Data.Foldable
import           Data.Maybe
import qualified Data.Sequence         as Seq

readInt = fst . fromJust . BS.readInt
getInt = readInt <$> BS.getLine

main = do
  n <- getInt

  let dfs s mx | Seq.length s == n = putStrLn $ toList s
               | otherwise =
                   forM_ ['a'..mx] $ \c ->
                     dfs (s Seq.|> c) (if c == mx
                                        then chr (ord mx + 1)
                                        else mx)
  dfs (Seq.fromList "") 'a'

Measured memory_bytes: 2172
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define pb push_back
#define INF 0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f
#define endl '\n'
#define ll long long
#define int long long
#define f first
#define s second
#define FAST cin.tie(0), cout.tie(0), ios::sync_with_stdio(0)
#define debug(x) cout << "DEBUG " << x << endl
#define debug2(x, y) cout << "DEBUG " << x << " " << y << endl
#define debug3(x, y, z) cout << "DEBUG " << x << " " << y << " " << z<< endl
#define debug4(x, y, z, o) cout << "DEBUG " << x << " " << y << " " << z<< " " << o << endl
using namespace std;
typedef pair<ll, ll> pii;
typedef vector<vector<ll>> mat;
const ll mod = 1e9+7;
const int MAXN = 1e6+5;



int32_t main() {
	int n;
	cin >> n;
	vector<int> v(n);
	for(int &i : v)
		cin >> i;
	int ans = 0;
	for(int i = 0; i < n; i++)
		for(int j = i+1; j < n; j++)
			ans += v[i] * v[j];
	cout << ans << endl;
}


Measured memory_bytes: 3616
N = input()
L=list(map(int,input().split()))
import itertools
ans=0
for l in itertools.combinations(L, 3):
    if l[0]+l[1]>l[2] and l[0]+l[2]>l[1] and l[1]+l[2]>l[0]:
        if l[0]!=l[1] and l[1]!= l[2] and l[0]!=l[2]:
            ans+=1
print(ans)

Measured memory_bytes: 67668
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long int;
using ull = unsigned long long int;
using P = pair<int, int>;
using P3 = pair<int,P>;
using PP = pair<P ,P>;
constexpr ll MOD = ll(1e9+7);
constexpr int IINF = INT_MAX;
constexpr ll LLINF = LLONG_MAX;
constexpr int MAX_N = int(1e6) + 5;
constexpr double EPS = 1e-8;
constexpr int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(), (v).end()

int n, m;
vector<vector<P> > g;
vector<ll> mask;

bool dfs(int now, int pre, int dst, int id){
    if(now == dst){
        return true;
    }
    for(auto e : g[now]){
        int nxt = e.first;
        if(nxt == pre) continue;
        if(dfs(nxt, now, dst, id)){
            mask[id] |= 1LL<<e.second;
            return true;
        }
    }
    return false;
}

int main(){
    cin >> n;
    g.resize(n);
    for(int i=0;i<n-1;i++){
        int a, b;
        cin >> a >> b;
        a--; b--;
        g[a].push_back(P(b,i));
        g[b].push_back(P(a,i));
    }
    cin >> m;
    mask.resize(m);
    for(int i=0;i<m;i++){
        int u, v;
        cin >> u >> v;
        u--; v--;
        dfs(u, -1, v, i);
    }
    ll r = 0;
    for(int S=1;S<(1<<m);S++){
        int k=0, c=0;
        ll t = 0LL;
        for(int i=0;i<m;i++){
            if((S>>i)&1){
                k++;
                t |= mask[i];
            }
        }
        for(int i=0;i<n-1;i++){
            if((t>>i)&1LL) c++;
        }
        r += (1LL<<(n-1-c))*((k&1)?1:-1);
    }
    cout << (1LL<<(n-1))-r << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define MOD (1000000007)
#define INF (1e9)
#define INFL (1e18)
 
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
template<class T>using arr=vector<vector<T>>;
template<class T>void pr(T x){cout << x << endl;}
template<class T>void prvec(vector<T>& a){rep(i, a.size()-1){cout << a[i] << " ";} cout << a[a.size()-1] << endl;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int n;
vector<int> a;
vector<bool> seen;
bool flag;

void is_reach(int s, int k){
    if(k==n+2) {
        flag = true;
        return;
    }
    seen[k] = true;
    FOR(i, 1, s+1){
        if(seen[k+i]) continue;
        if(k+i > n+2) break;
        if(a[k+i]==0){
            is_reach(s, k+i);
        }
    }
}

int main()
{
    cin >> n;
    a.resize(n+3);
    seen.resize(n+3);
    // vector<int> pos;
    rep(i, n){
        cin >> a[i+1];
    }
    a[n+2] = 0;

    FOR(i, 1, n+2){
        flag = false;
        seen.assign(n+3, false);
        is_reach(i, 0);
        if(flag) {
            pr(i);
            return 0;
        }
    }
    return 0;}


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

using namespace std;

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

const int INF = 1000000000;
const ll LINF = (ll) 4000000000000000000;
const ll MOD = (ll) 1000000007;
const double PI = acos(1.0);
const int limit = 100010;

#define REP(i,m,n) for(ll i = m; i < (ll)(n); i++)
#define rep(i,n) REP(i, 0, n)
#define MP make_pair
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define NP(v) next_permutation(v.begin(),v.end())
#define smaller_queue  priority_queue <ll, vector<ll>, greater<ll> >
//------------------------------------------------------

int main() {
    int h[10];
    rep(i, 10) cin >> h[i];
    sort(h, h + 10);
    reverse(h, h + 10);
    rep(i, 3) cout << h[i] << endl;

    return 0;
}



Measured memory_bytes: 3044
#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define be begin()
#define en end()
#define le length()
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define fastIO                        \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL)
#define c(a) cout << a << "\n";
#define endl '\n'
const int MOD = 1e9 + 7;
const int N = 1e6 + 6;
vector<ll> g[N];
int main()
{

    ll n;
    cin >> n;
    ll sum = n * (n + 1) / 2;
    ll p = n / 3;
    sum -= 3 * ((p * (p + 1)) / 2);
    p = n / 5;
    sum -= 5 * ((p * (p + 1)) / 2);
    p = n / 15;
    sum += 15 * ((p * (p + 1)) / 2);
    //sum += 15 * (n / 15);
    c(sum)

        return 0;
}

Measured memory_bytes: 27120
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
ll mod=1e9+7;

int main(){
  int N,K;
  string s;
  cin>>N>>K>>s;
  int b(0);
  for (int i(0);i<N;i++){
    if (s[i]=='L'){
      if (i!=0&&s[i-1]=='L')b++;
    }else{
      if(i!=N-1&&s[i+1]=='R')b++;
    }
  }
  if (b+K*2 <=N-1){
    cout << b + K*2<< endl;
  }else{
    cout << N-1 << endl;
  }
  return 0;
}



Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <numeric>
using namespace std;
#define ll long long
#define mod  1000000007
#define rep(i, n) for (int i = 0; i < n; ++i)
using Graph = vector<vector<int>>;
#define grepq priority_queue<double, std::vector<double>, std::greater<double>>
#define all(v) v.begin(),v.end()
#define PI acos(-1)

const ll INF = 10010001010;
const int inf = 2000000000;
ll lcm(ll a, ll b)
{
    return a * b / __gcd(a, b);
}

typedef tuple<string, int, int> TUP;

bool tuplesort(const TUP &right, const TUP &left)
{
    if (get<0>(right) != get<0>(left))
    {
        return get<0>(left) < get<0>(right);
    }
    if (get<1>(left) != get<1>(right))
    {
        return get<1>(left) > get<1>(right);
    }
    return get<2>(left) < get<2>(right);
}

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

int main(){
    ll N,M;
    cin >> N >> M;
    if(abs(N-M) > 1){
        cout << 0 << endl;
    }
    else{
        ll sum = 1;
        for (int i = 0; i < N; i++)
        {
            sum = sum * (i+1) % mod;
        }
        for (int i = 0; i < M; i++)
        {
            sum = sum * (i+1) % mod;
        }
        if (N == M)
        {
            sum = sum * 2 % mod;
        }
        cout << sum << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const double pi = acos(-1);

const ll MAX_V = 50;
const ll MAX_S = MAX_V*50+5;

struct Edge {
    ll to, a, b;
    Edge(ll to, ll a, ll b):to(to),a(a),b(b) {}
};

struct Data {
    ll v, s, x;
    Data(ll v, ll s, ll x):v(v),s(s),x(x) {}
    bool operator<(const Data& a) const {
        return x > a.x;
    }
};

int main() {
    ll n, m, s;
    cin >> n >> m >> s;
    chmin(s, MAX_S);
    
    vector<vector<Edge>> G(MAX_V);
    rep(i, m) {
        ll u, v, a, b;
        cin >> u >> v >> a >> b;
        u--;  v--;
        G[u].emplace_back(v, a, b);
        G[v].emplace_back(u, a, b);
    }

    vvl dp(MAX_V, vl(MAX_S+10, INF));
    priority_queue<Data> Q;
    auto push = [&](ll v, ll s, ll x) {
        if(s < 0) {
            return;
        }
        if(dp[v][s] <= x) {
            return;
        }
        dp[v][s] = x;
        Q.emplace(v, s, x);
    };

    vl c(n), d(n);
    rep(i, n) {
        cin >> c[i] >> d[i];
    }

    push(0, s, 0);
    while(!Q.empty()) {
        Data hoge = Q.top();  Q.pop();
        ll v = hoge.v, s = hoge.s, x = hoge.x;
        if(dp[v][s] != x) {
            continue;
        }
        ll ns = min(s + c[v], MAX_S);
        push(v, ns, x + d[v]);
        for(Edge e : G[v]) {
            push(e.to, s - e.a, x + e.b);
        }
    }

    exrep(i, 1, n-1) {
        ll ans = INF;
        rep(j, MAX_S+10) {
            chmin(ans, dp[i][j]);
        }
        out(ans);
    }
    
    re0;
}

Measured memory_bytes: 7292
#include <algorithm>
#include <array>
#include <vector>
#include <iostream>
#include <string>
#include <functional>

using namespace std;


int main() {
	string S;
	cin >> S;
	int sum = 0;
	for (int i = 0; i < S.length(); i++) {
		sum += S[i] - '0';
	}

	cout << ((stoi(S) % sum == 0) ? "Yes" : "No") << endl;
	return 0;
}

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

int main(void)
{
    int n;
    int a;
    int sum = 0;
    cin >>n;
    while(n--)
    {
        cin >> a;
        while(a%2 == 0)
        {
            sum++;
            a/=2;
        }
    }
    cout << sum <<endl;
    return 0;
}


Measured memory_bytes: 256
//   _/                _/                 _/_/_/   _/
//_/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
// _/     _/    _/   _/     _/    _/  _/_/_/     _/
//_/     _/    _/   _/     _/    _/  _/    _/   _/
// _/_/   _/_/       _/_/   _/_/      _/_/     _/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=2e9;
const ll INF=5e18;
typedef pair<int,int> P;
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  string s,t,u;
  int a,b;
  cin >> s >> t >> a >> b >> u;
  if(s==u) {
    cout << a-1 << " " << b << endl;
  }
  else {
    cout << a << " " << b-1 << endl;
  }
}

Measured memory_bytes: 256
N, M = [int(_) for _ in input().split()]
T = [[int(_) for _ in input().split()] for i in range(M)]

E = []
for a, b, c in T:
    E.append((a - 1, b - 1, c))

min_V = -1000000000 * 2000
scores = [min_V] * N
scores[0] = 0

for i in range(N):
    for a, b, c in E:
        if scores[b] >= scores[a] + c:
            continue
        scores[b] = scores[a] + c

ans = scores[N - 1]

for a, b, c in E:
    if scores[b] >= scores[a] + c:
        continue
    scores[b] = scores[a] + c

if ans != scores[N-1]:
    print("inf")
else:
    print(scores[N - 1])


Measured memory_bytes: 3700
while True:
    n,x = map(int,input().split())
    if n == x == 0:
        break
    
    d = 0
    for i in range(1,n+1):
        for j in range(i+1,n+1):
            k = x-(i+j)
            if k >= 1 and k<= n and k > j:
                d += 1
    
    print(d)
        
    


Measured memory_bytes: 5592
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(void){
	string s; cin>>s;
	for(int i=0;i<3;i++){
		if(s[i]==s[i+1]){
			cout<<"Bad"<<endl;
			return 0;
		}
	}
	cout<<"Good"<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i < (n); i++)
typedef double D;      // ??§?¨?????????????double???long double?????????
typedef complex<D> P;  // Point
typedef pair<P, P> L;  // Line
typedef vector<P> VP;
const D EPS = 1e-9;    // ?¨±??????????????????????????£????????????
#define X real()
#define Y imag()
#define LE(n,m) ((n) < (m) + EPS)
#define GE(n,m) ((n) + EPS > (m))
#define EQ(n,m) (abs((n)-(m)) < EPS)
 
// ?????????dot(a,b) = |a||b|cos??
D dot(P a, P b) {return (conj(a)*b).X; }
 
// ?????????cross(a,b) = |a||b|sin??
D cross(P a, P b) {  return (conj(a)*b).Y;}
 
// ??????????????????
int ccw(P a, P b, P c) {
  b -= a;  c -= a;
  if (cross(b,c) >  EPS) return +1;  // counter clockwise
  if (cross(b,c) < -EPS) return -1;  // clockwise
  if (dot(b,c)   < -EPS) return +2;  // c--a--b on line
  if (norm(b) < norm(c)) return -2;  // a--b--c on line or a==b
  return 0;                          // a--c--b on line or a==c or b==c
}
// ????????¨??????
bool isecSS(P a1, P a2, P b1, P b2) {
  return ccw(a1, a2, b1)*ccw(a1, a2, b2) <= 0 &&
         ccw(b1, b2, a1)*ccw(b1, b2, a2) <= 0;
}
 
// ????????¨???
bool isecSP(P a1, P a2, P b) {
  //return !ccw(a1, a2, b);
   return abs(a1 - b) + abs(a2 - b) - abs(a2 - a1) < EPS;  //Perfective
}
P proj(P a1, P a2, P p) {
  return a1 + dot(a2-a1, p-a1)/norm(a2-a1) * (a2-a1);
}
D distSP(P a1, P a2, P p) {
  P r = proj(a1, a2, p);
  if (isecSP(a1, a2, r)) return abs(r-p);
  return min(abs(a1-p), abs(a2-p));
}
 
D distSS(P a1, P a2, P b1, P b2) {
  if (isecSS(a1, a2, b1, b2)) return 0;
  return min(min(distSP(a1, a2, b1), distSP(a1, a2, b2)),
             min(distSP(b1, b2, a1), distSP(b1, b2, a2)));
}
#define F first
#define S second
typedef pair<L,D>PP;
int main(){
  int n;
  D a1,a2,a3,a4,a5;
  while(cin>>n,n){
    L st;
    D ans=1e15;
    vector<PP>v;
    cin>>a1>>a2>>a3>>a4;
    st=L(P(a1,a2),P(a3,a4));
    rep(i,n){
      cin>>a1>>a2>>a3>>a4>>a5;
      v.push_back(PP(L(P(a1,a4),P(a3,a4)),a5));
      v.push_back(PP(L(P(a1,a2),P(a3,a2)),a5));
      v.push_back(PP(L(P(a3,a2),P(a3,a4)),a5));
      v.push_back(PP(L(P(a1,a2),P(a1,a4)),a5));
      if(ccw(P(a1,a2),P(a1,a4),st.F)==ccw(P(a1,a4),P(a3,a4),st.F)&&ccw(P(a3,a4),P(a3,a2),st.F)==ccw(P(a3,a2),P(a1,a2),st.F)&&ccw(P(a1,a4),P(a3,a4),st.F)==ccw(P(a3,a4),P(a3,a2),st.F))ans=0;
      if(ccw(P(a1,a2),P(a1,a4),st.S)==ccw(P(a1,a4),P(a3,a4),st.S)&&ccw(P(a3,a4),P(a3,a2),st.S)==ccw(P(a3,a2),P(a1,a2),st.S)&&ccw(P(a1,a4),P(a3,a4),st.S)==ccw(P(a3,a4),P(a3,a2),st.S))ans=0;
    }
    rep(i,v.size()){
      D dist=distSS(v[i].F.F,v[i].F.S,st.F,st.S);
      if(dist<=v[i].S)ans=min(ans,dist);
      else ans=min(ans,(dist*dist+v[i].S*v[i].S)/(2*v[i].S));
    }
    printf("%.9f\n",ans);
  }
}

Measured memory_bytes: 3296
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cassert>
#define PB push_back
#define MP make_pair
#define sz(v) (in((v).size()))
#define forn(i,n) for(in i=0;i<(n);++i)
#define forv(i,v) forn(i,sz(v))
#define fors(i,s) for(auto i=(s).begin();i!=(s).end();++i)
#define all(v) (v).begin(),(v).end()
using namespace std;
typedef long long in;
typedef vector<in> VI;
typedef vector<VI> VVI;
in p2(in x){
  return 1LL<<x;
}
VI a,b;
in wy(in us, in fd, in ld){
  in sm=0;
  if(us==0)
    sm+=p2(ld+1);
  in acov=0;
  for(in i=0;i<=ld;++i)
    acov+=a[i];
  in noncov=0;
  for(in i=ld+1;i<=fd;++i)
    noncov+=a[i];
  if(noncov>0 || us==1)
    sm+=p2(ld+1-acov);
  for(in i=fd;i>=ld+1;--i){
    if(a[i]==0){
      sm+=p2(i);
    }
  }
  in pcov=acov;
  if(noncov>0 || us==1){
    acov=0;
    for(in i=ld;i>=0;--i){
      acov+=a[i];
      if(a[i]==0 && pcov!=acov){
	in lft=pcov-acov;
	sm+=p2(i)-p2(i-lft);
      }
    }
  }
  return sm;
}
int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  in ta,tb;
  cin>>ta>>tb;
  forn(i,61){
    a.PB(!!(ta&p2(i)));
    b.PB(!!(tb&p2(i)));
  }
  in c=60;
  while(c>=0 && a[c]==b[c])
    --c;
  if(c==-1){
    cout<<1<<endl;
    return 0;
  }
  in sm=0;
  sm+=wy(1,c-1,-1);
  in d=c-1;
  while(d>=0 && b[d]==0)
    --d;
  sm+=wy(0,c-1,d);
  cout<<sm<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define P pair<ll,ll>
#define Graph vector<vector<ll>>
#define INF (1ll<<60)
#define mod 1000000007
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 ans;
	rep(i,5){
		ll a;
		cin>>a;
		if(a==0) ans=i+1; 
	}

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

Measured memory_bytes: 3584
from collections import defaultdict
n, m = map(int, input().split())
a = list(map(int, input().split()))

s = [0] * (n+1)
for i in range(n):
    s[i+1] = (s[i] + a[i] ) % m
d = defaultdict(int)
for xx in s:
    d[xx] += 1

ans = 0
for k in d.keys():
    if 2 <= d[k]:
        ans += d[k] * (d[k]-1) // 2
print(ans)

Measured memory_bytes: 16528
#include<bits/stdc++.h>
using namespace std;
int main(void){
  int n; cin>>n;
  vector<int> a(n);
  for(int i=0; i<n; ++i){ cin>>a[i]; a[i]-=i+1;}
  sort(a.begin(),a.end());
  long long res=0,sum=(n%2==1? a[(n-1)/2]:(a[(n-1)/2]+a[(n-1)/2+1])/2);
  for(int i=0; i<n; ++i) res+=abs(a[i]-sum);
  cout<<res<<endl;
  return 0;
}

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

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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repto(i, n) for(int i = 0; i <= (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define mp make_pair
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }

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

  int N;
  ll D;
  cin >> N >> D;
  int cnt = 0;
  rep (i, N) {
    ll X, Y;
    cin >> X >> Y;
    if (X*X+Y*Y<=D*D)
      cnt++;
  }
  cout << cnt << endl;
}


Measured memory_bytes: 3620
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC104.Task3
{
    class Program
    {
        static void Main(string[] args)
        {
            var line1 = Console.ReadLine().Split(' ');
            long d = Int64.Parse(line1[0]);
            long g = Int64.Parse(line1[1]);

            var ps = new List<long>();
            var cs = new List<long>();

            long count = 0;

            for (var i = 0; i < d; i++)
            {
                var s = Console.ReadLine().Split(' ');
                var p = Int64.Parse(s[0]);
                ps.Add(p);
                cs.Add(Int64.Parse(s[1]));
                count += p;
            }

            var result = Solve(d, g, count, ps, cs);
            Console.WriteLine(result);
        }

        static long Solve(long d, long g, long count, List<long> ps, List<long> cs)
        {
            long minCount = count;
            var table = new long[d + 1, count + 1];

            for (var j = 0; j <= count; j++)
            {
                table[0, j] = 0;
            }

            for (var i = 1; i <= d; i++)
            {
                for (var j = 0; j <= count; j++)
                {
                    if (j <= ps[i - 1])
                    {
                        table[i, j] = Math.Max(table[i - 1, j], Score(j, i, ps, cs));
                    }
                    else
                    {
                        table[i, j] = Math.Max(table[i - 1, j], table[i - 1, j - ps[i - 1]] + Score(j, i, ps, cs));
                    }
                    // Trace(i, j, table[i, j]);
                    if (table[i, j] >= g)
                    {
                        minCount = Math.Min(minCount, j);
                    }
                }
            }
            return minCount;
        }

        static long Score(int i, int row, List<long> ps, List<long> cs)
        {
            var maxNum = ps[row - 1];
            if (i >= maxNum)
            {
                return maxNum * row * 100 + cs[row - 1];
            }
            else
            {
                return i * row * 100;
            }
        }

        static void Trace(long i, long j, long v)
        {
            Console.WriteLine("({0},{1}) = {2}", i, j, v);
        }
    }
}


Measured memory_bytes: 11252
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<vector>
#include<list>
#include<algorithm>
#include<math.h>
#include<map>
#include<iomanip>
#include<functional>
#include<limits>
#include <unordered_map>
#include <numeric>
#include <array>
#include <queue>
#include <chrono>
#include <random>
#include <fstream>


using namespace std;
using  ull = unsigned long long int;

#define rep(i,n,m) for(long long int i=n;i<(long long int)(m);i++)
#define INF (1<<29)
#define MD 1000000007

int main() {
	int N, M,sum=0;
	cin >> N;
	vector<string>all;
	vector<string>blue(N);
	rep(i, 0, N) {
		cin >> blue[i];
		all.push_back(blue[i]);
	}
	cin >> M;
	vector<string>red(M);
	rep(i, 0, M) {
		cin >> red[i];
		all.push_back(red[i]);
	}

	std::sort(all.begin(), all.end());
	all.erase(unique(all.begin(), all.end()), all.end());


	rep(i, 0, all.size()) {
		int add = 0;
		int sub = 0;

		rep(j, 0, N) {
			if (all[i] == blue[j])add++;
		}

		rep(j, 0, M) {
			if (all[i] == red[j])sub++;
		}

		sum = max(sum, (add - sub));
	}

	cout << sum << endl;


	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define NMAX 2000000
#define AMAX 10000
int n=AMAX;
void CountingSort(unsigned short *,unsigned short *,int);
int main(){
  int i;
  unsigned short *A;
  unsigned short *B;
  int k;
  

  scanf("%d",&k);

  A=malloc(sizeof(short)*k+1);
  B=malloc(sizeof(short)*k+1);
  
  for(i=0;i<k;i++){
    scanf("%hu",&A[i+1]);
  }
  //  printf("ok1\n");
  CountingSort(A,B,k);
  return 0;
}

void CountingSort(unsigned short *A,unsigned short *B,int k){
  int i,j;
  int C[AMAX+1];
  //printf("ok2\n");
  for(i=0;i<=AMAX;i++){
    C[i]=0;
  }
  //printf("ok3\n");
  for(j=0;j<k;j++){
    C[A[j+1]]++;
  }
  //printf("ok4\n");
  for(i=1;i<=AMAX;i++){
    C[i]=C[i]+C[i-1];
  }
  //printf("ok5\n");
  for(j=1;j<=k;j++){
    B[C[A[j]]]=A[j];
    C[A[j]]--;
  }
  //printf("ok6\n");
  for(i=1;i<=k;i++){
    if(i>1)
      printf(" ");
    printf("%d",B[i]);
  }
  printf("\n");
}




Measured memory_bytes: 9552
#include <map>
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;
string S[100], T[100]; int val, cnt, size_;
map<string, vector<int> > M;
int main() {
	while(cin >> S[cnt++]) {
		scanf("%d", &val);
		M[S[cnt - 1]].push_back(val);
	}
	sort(S, S + cnt);
	T[size_++] = S[0];
	for(int i = 1; i < cnt; i++) {
		if(S[i - 1] != S[i]) {
			T[size_++] = S[i];
		}
	}
	for(int i = 1; i < size_; i++) {
		printf("%s\n", T[i].c_str());
		sort(M[T[i]].begin(), M[T[i]].end());
		for(int j = 0; j < M[T[i]].size(); j++) {
			if(j) printf(" ");
			printf("%d", M[T[i]][j]);
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 3272
function Main(input) {
  input = input.split("\n");
  var a = input[0].split('');
  var ans = 0
  for(var i=0; i<a.length; i++) {
    if(a[i] === "+") ans+=1
    if(a[i] === "-") ans-=1
  } 
  console.log(ans);

}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
class R:
    def __init__(self, a, b):
        self.a = a
        self.b = b

n, m = map(int, input().split())

h = list(map(int, input().split()))

t = [True] * n
for i in range(m):
    a, b = map(int,input().split())

    if h[a - 1] < h[b - 1]:
        t[a - 1] = False
    elif h[a - 1] > h[b - 1]:
        t[b - 1] = False
    else:
        t[a - 1] = False
        t[b - 1] = False

ans = 0
for i in t:
    if i == True:
        ans += 1
print(ans)

Measured memory_bytes: 20012
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
using ll = long long int;

int main(){
    ll n;
    cin >> n;
    ll ans = (n + 1) - 2;

    for(ll i = 2; i * i <= n; i++){
        if (n % i == 0){
            ll p = n / i;
            ans = min(ans, (p + i) - 2);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3148