akhauriyash/Code-Regression huggingface dataset:
import sys
sys.setrecursionlimit(1000000000)
import math
from fractions import gcd
def lcm(a, b): return a * b // gcd(a, b)
from itertools import count, permutations
from functools import lru_cache
from collections import deque, defaultdict
from pprint import pprint
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
N1097 = 10**9 + 7

def meg(f, ok, ng):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if f(mid):
            ok=mid
        else:
            ng=mid
    return ok

def get_inv(n, modp):
    return pow(n, modp-2, modp)

def factorials_list(n, modp):    # 10**6
    fs = [1]
    for i in range(1, n+1):
        fs.append(fs[-1] * i % modp)
    return fs

def invs_list(n, fs, modp):     # 10**6
    invs = [get_inv(fs[-1], modp)]
    for i in range(n, 1-1, -1):
        invs.append(invs[-1] * i % modp)
    invs.reverse()
    return invs

def comb(n, k, modp):
    num = 1
    for i in range(n, n-k, -1):
        num = num * i % modp
    den = 1
    for i in range(2, k+1):
        den = den * i % modp
    return num * get_inv(den, modp) % modp

def comb_from_list(n, k, modp, fs, invs):   
    return fs[n] * invs[n-k] * invs[k] % modp

#

class UnionFindEx:
    def __init__(self, size):
        #正なら根の番号、負ならグループサイズ
        self.roots = [-1] * size
    def getRootID(self, i):
        r = self.roots[i]
        if r < 0:   #負なら根
            return i
        else:
            r = self.getRootID(r)
            self.roots[i] = r
            return r
    def getGroupSize(self, i):
        return -self.roots[self.getRootID(i)]
    def connect(self, i, j):
        r1, r2 = self.getRootID(i), self.getRootID(j)
        if r1 == r2:
            return False
        if self.getGroupSize(r1) < self.getGroupSize(r2):
            r1, r2 = r2, r1
        self.roots[r1] += self.roots[r2]    #サイズ更新
        self.roots[r2] = r1
        return True

Yes = 'Yes'
No = 'No'

def main():
    N = ii()
    A = lmis()
    d = {}
    for a in A:
        if a in d:
            d[a] += 1
        else:
            d[a] = 1
    s = sum(v * (v-1) //2 for v in d.values())
    for a in A:
        v = d[a]
        if v <= 1:
            print(s)
        else:
            print(s - (v * (v-1))//2 + ((v-1)*(v-2))//2)


main()







Measured memory_bytes: 27608
#ANS-4
in_N,A,B = map(int,input().split())

count = 0
for i in range(in_N +1):
    sum_all = 0
    i_str = str(i)
    for j in range(len(i_str)):
        sum_all += int(i_str[j])
    if A<=sum_all:
        if sum_all<=B:
            count += i
            
print(count)

Measured memory_bytes: 3060
#include <iostream>
using namespace std;
 
int main(){
    int H,W;
    while (true){   
        cin>>H>>W;  
        if (H==0&&W==0) break;
        for ( int k=0; k<H; k++){
            for ( int r=0; r<W; r++){
                if((k+r)%2==1){
					cout<<".";
				}else{
					cout<<"#";
				}		
            }
        cout<<endl;
        }
        cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 3084
#include "bits/stdc++.h"

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;

using namespace std;
using ll = long long;

template<typename T=int>
T in(){T x; cin >> x; return (x);}

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

	int N=in();
	int val = N/100;
	if(N>100*val+10*val+val) val++;

	REP(i,3){
	cout << val;
	}
	cout << endl;
	return 0;
}


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

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

typedef long long LL;
typedef unsigned long UL;

using namespace std;

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

    vector<int> a(3);
    REP(i, 3) cin >> a[i];

    sort(a.begin(), a.end());

    cout << a[0] + a[1] + a[2] * 10 << endl;

    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

n = int(input())
value = [int(s) for s in input().split()]
cost = [int(t) for t in input().split()]

VnS = []

for i in range(n):
    if value[i]-cost[i] > 0:
        VnS.append(value[i] - cost[i])

VnS.sort(reverse=True)
print(sum(VnS))


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define int long long
using namespace std;
typedef pair<int,int> ii;

int occ[100005];

signed main(){
	//freopen("i.txt","r",stdin);
	ios_base::sync_with_stdio(false); cin.tie(0);
	
	int S = 0;
	int n; cin >> n; int arr[n];
	for(int i = 0;i < n;i++){
		cin >> arr[i];
		S ^= arr[i];
	}
	
	for(int i = 0;i < n;i++) cout << (S^arr[i]) << " ";
	
	
	
}



Measured memory_bytes: 5212
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<vector>
#define ll long long
using namespace std;

const int N=200005;

int n,tag;
ll ans;
int f[N];
bool vis[N];
char s[N];
vector<int> lev[27];

void add(int x,int w){
	for (;x<=n;x+=x&-x) f[x]+=w;
}

int query(int x){
	int s=0;
	for (;x;x-=x&-x) s+=f[x];
	return s;
}

int main(){
	int i,k,j;
	scanf("%s",s+1); n=strlen(s+1);
	for (i=1;i<=n;i++) lev[s[i]-'a'].push_back(i);
	for (i=0;i<26;i++) tag+=lev[i].size()&1;
	if (tag>1||(tag&&n%2==0)){
		printf("-1\n");
		return 0;
	}
	for (i=1;i<=n;i++) add(i,1);
	for (i=1;i<=n;i++)
		if (!vis[i]){
			j=lev[s[i]-'a'].size()-1;
			k=lev[s[i]-'a'][j]; lev[s[i]-'a'].pop_back();
			if (i==k) ans+=1ll*(query(n)-query(k))/2;
			else ans+=1ll*(query(n)-query(k));
			vis[i]=vis[k]=1;
			add(i,-1);
			add(k,-1);
		}
	printf("%lld\n",ans);
	return 0;
} 

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

using namespace std;

typedef long long int li;
typedef vector<li> vi;
typedef pair<li,li> pi;
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define B begin()
#define E end()
#define f(i,l,r) for(li i=l;i<=r;++i)
#define fr(i,l,r) for(li i=l;i>=r;--i)
#define u_map unordered_map
#define endl "\n"

li fastpow(li base,li exp,li M) 
{
    li res=1;
    while(exp>0) {
        if(exp&1)
            res=(res*base)%M;

        base=(base*base)%M;
        exp>>=1;
    }
    return res;
}

vi par;

li root(li a)
{
    while(a!=par[a])
    {
        par[a]=par[par[a]];
        a=par[a];
    }

    return a;
}

void unio(li a,li b)
{
    par[root(a)]=root(b);
}



    
int main()
{    
    

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

    li n;

    cin>>n;

    string s,t;

    li a;

    f(i,0,n-1)
    {
        cin>>a;
        s+=('0'+a);
    }

    f(i,0,n-1)
    {
        cin>>a;
        t+=('0'+a);
    }

    // cout<<s<<endl<<t;

    string tp1=s,tp2=s;

    li ans1=0,ans2=0;

    sort(tp1.B,tp1.E);
    tp2=tp1;

    while(tp1!=s)
    {
        next_permutation(tp1.B,tp1.E);
        ans1++;
    }

    while(tp2!=t)
    {
        next_permutation(tp2.B,tp2.E);
        ans2++;
    }

    cout<<abs(ans1-ans2);

    return 0;
}

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

int main()
{
  string SN;cin>>SN;
  int sum=0;long long N=0;
  for(int i=SN.size()-1;i>-1;i--)
  {
    N+=(SN[i]-'0')*pow(10,SN.size()-1-i);
    sum+=(SN[i]-'0');
  }
  int ans;
  ans=max((int)(SN[0]-'0'-1+(SN.size()-1)*9),sum);
  cout<<ans;
}

Measured memory_bytes: 3564
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

namespace MyProgram
{
    public class Program
    {	
        public static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int a = int.Parse(input[0]);
            int b = int.Parse(input[1]);
            int c = int.Parse(input[2]);
            
            bool ok = false;
            for(int i = a ; i <= a * b ; i += a)
            {
                if(i%b == c) ok = true;
            }
            if(ok) Console.WriteLine("YES");
            else Console.WriteLine("NO");
        }
    }
}

Measured memory_bytes: 11092
N, W = map(int, input().split())
L = [list(map(int, input().split())) for _ in range(N)]
dp = [[0 for _ in range(W+1)] for _ in range(N+1)]
for n in range(N):
  v, w = L[n]
  for i in range(1, W+1):
    if i >= w:
      dp[n+1][i] = max(dp[n][i], dp[n][i-w]+v)
    else:
      dp[n+1][i] = dp[n][i]
ans = 0
for i in dp:
  ans = max(ans, max(i))
print(ans)


Measured memory_bytes: 25732
#include <iostream>
#include <vector>
#include <string>

using namespace std;

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

	vector<bool> S(14, false), H(14, false), C(14, false), D(14, false);
	char suit;
	int num;

	while (n--)
	{
		cin >> suit >> num;

		switch (suit)
		{
		case 'S': S[num] = true; break;
		case 'H': H[num] = true; break;
		case 'C': C[num] = true; break;
		case 'D': D[num] = true; break;
		}
	}

	for (int i = 1; i <= 13; ++i)
		if (!S[i]) cout << "S " << i << endl;

	for (int i = 1; i <= 13; ++i)
		if (!H[i]) cout << "H " << i << endl;

	for (int i = 1; i <= 13; ++i)
		if (!C[i]) cout << "C " << i << endl;

	for (int i = 1; i <= 13; ++i)
		if (!D[i]) cout << "D " << i << endl;

	return 0;
}

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

#define mp make_pair
#define eb emplace_back
#define ff first
#define ss second

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#ifdef ONPC
mt19937 rnd(228);
#else
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#endif


const int MAXN = 100;
//#define int long long
const int INF = 1e9;

signed main()
{
    #ifdef FILEIO
      freopen("input.txt", "r", stdin);
      freopen("output.txt", "w", stdout);
    #endif

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

    int n, a, b, c;
    cin >> n >> a >> b >> c;
    vector<char> ans;
    string s;
    vector<string> ss(n);
    for (int i =0; i < n; i++) cin >> ss[i];
    for (int i =0; i < n; i++){
      s = ss[i];
      if (s == "AB"){
        if (a > b){
          a--;
          b++;
          ans.eb('B');
        } else if (b > a){
          b--;
          a++;
          ans.eb('A');
        } else {
          if (i < n-1 && ss[i+1] == "AC"){
            b--;
            a++;
            ans.eb('A');
          } else {
            b++;
            a--;
            ans.eb('B');
          }
        }
      }


      if (s == "AC"){
        if (a > c){
          a--;
          c++;
          ans.eb('C');
        } else if (c > a){
          c--;
          a++;
          ans.eb('A');
        } else {
          if (i < n-1 && ss[i+1] == "AB"){
            c--;
            a++;
            ans.eb('A');
          } else {
            c++;
            a--;
            ans.eb('C');
          }
        }
      }

      if (s == "BC"){
        if (b > c){
          b--;
          c++;
          ans.eb('C');
        } else if (c > b){
          c--;
          b++;
          ans.eb('B');
        } else {
          if (i < n-1 && ss[i+1] == "AB"){
            c--;
            b++;
            ans.eb('B');
          } else {
            c++;
            b--;
            ans.eb('C');
          }
        }
      }

      //cerr << i << '\n';

      if (a < 0 || b < 0 || c < 0){
        cout << "No\n";
        return 0;
      }
    }

    cout << "Yes\n";
    for (auto i : ans) cout << i << '\n';

    return 0;
}


Measured memory_bytes: 6696
from collections import deque
n,q=map(int, input().split())

L={i:deque() for i in range(n)}

for _ in range(q):
    *qi,=map(int, input().split( ))
    if qi[0]==0:
        t,x=qi[1],qi[2]
        L[t].append(x)
    elif qi[0]==1:
        print(*L[qi[1]])
    else:
        s,t=qi[1],qi[2]
        if len(L[s])<len(L[t]):
            L[t].extend(L[s])
            L[s]=deque()
        else:
            while L[t]:
                L[s].appendleft(L[t].pop())
            L[t]=L[s]
            L[s]=deque()



Measured memory_bytes: 30688
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll n;
  cin >> n;
  map<ll, ll> mp;
  rep(i, n) {
    ll a;
    cin >> a;
    mp[a]++;
  }
  ll ans = 0;
  for(auto v : mp) {
    ll x = v.first;
    ll k = v.second;
    if(x > k)
      ans += k;
    else
      ans += k - x;
  }
  cout << ans << endl;
}

Measured memory_bytes: 9436
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)

n, k = map(int, input().split())
a = list(map(int, input().split()))
g = a[0]
for x in a:
    g = gcd(g, x)
print(("IMPOSSIBLE", "POSSIBLE")[k <= max(a) and k % g == 0])

Measured memory_bytes: 14224
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  int a[100];
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  sort(a,a+n);
  cout<<a[n-1]-a[0]<<endl;
  return 0;
}

	   


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) REP(i, 0, n)
#define REP(i, l, r) for (int i = l; i < r; ++i)
#define int long long
#ifdef DEBUG
#define dout cout
#else
std::stringstream dout;
#endif
using namespace std;
typedef pair<int, int> P;
// other libs
signed main(int argc, char* argv[]) {
	int n, m;
	cin >> n >> m;
	vector<P> ab(n);
	rep(i, n) cin >> ab[i].first >> ab[i].second;
	sort(ab.begin(), ab.end(), [](P a, P b) {
		if (a.first != b.first)
			return a.first > b.first;
		else
			return a.second >= b.second;
	});
	int ans = 0;
	vector<int> memo;
	REP(i, 1, m + 1) {
		while (ab.size() != 0 && ab[ab.size() - 1].first <= i) {
			if (lower_bound(memo.begin(), memo.end(), ab[ab.size() - 1].second) == memo.end())
				memo.push_back(ab[ab.size() - 1].second);
			else
				memo.insert(lower_bound(memo.begin(), memo.end(), ab[ab.size() - 1].second), ab[ab.size() - 1].second);
			ab.pop_back();
		}
		if (memo.size() != 0) {
			ans += memo[memo.size() - 1];
			memo.pop_back();
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 2936
#include<bits/stdc++.h>
#define lg long long int
#define loop(i,s,e) for(lg i=s;i<=e;i++)
#define iloop(i,s,e) for(lg i=e;i>=s;i--)
#define pb push_back
#define mp make_pair
#define mod 1000000007


using namespace std;

lg min(lg a,lg b)
{return a<b?a:b;}
lg max(lg a,lg b)
{return a>b?a:b;}
lg lcm(lg a ,lg b)
{
    return (a*b)/__gcd(a,b);
}
lg n,m,k,ans;
int main()
{
    cin>>n;
    vector<lg>nums(n,0);
    ans = 0;
    for(lg i=0;i<n;i++)
    {
        cin>>nums[i];
        ans = nums[i]^ans;
    }
    for(lg i=0;i<n;i++)
    {
        lg num = nums[i]^ans;
        cout<<num<<" ";
    }
}


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

const int M = int(1e9 + 7);

signed main() {
  ios::sync_with_stdio(false);

  int N;
  cin >> N;

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

  vector<int> pre(N + 1); {
    for (int i = 0; i < N; ++i) {
      pre[i + 1] = pre[i] ^ A[i];
    }
    if (pre[N]) {
      static int dp[1 << 19][2][2][2];
      dp[1][0][1][1] = 1;
      for (int i = 1; i <= N; ++i) {
        for (int c = 0; c < 2; ++c) {
          if (pre[i] == 0) {
            (dp[i + 1][c][1][1] += dp[i][c][0][0]) %= M;
            (dp[i + 1][c][1][1] += dp[i][c][0][1]) %= M;
          } else if (pre[i] == pre[N]) {
            (dp[i + 1][c ^ 1][0][1] += dp[i][c][1][0]) %= M;
            (dp[i + 1][c ^ 1][0][1] += dp[i][c][1][1]) %= M;
          }
          (dp[i + 1][c][0][0] += dp[i][c][0][0]) %= M;
          (dp[i + 1][c][1][0] += dp[i][c][1][0]) %= M;
          (dp[i + 1][c][0][0] += dp[i][c][0][1]) %= M;
          (dp[i + 1][c][1][0] += dp[i][c][1][1]) %= M;
        }
      }
      int ans = (dp[N + 1][0][0][1] + dp[N + 1][1][0][1]) % M;
      cout << ans << endl;
      return 0;
    }
  }

  vector<int> pz(pre.size() + 1); {
    for (int i = 0; i < pre.size(); ++i) {
      pz[i + 1] = pz[i] + (pre[i] == 0);
    }
  }

  map<int, vector<int>> dp; {
    map<int, int> cnt;
    map<int, int> last;
    for (int i = 0; i < pre.size(); ++i) {
      if (pre[i]) {
        if (last.count(pre[i])) {
          int l = last.count(pre[i]) ? last[pre[i]] : 0;
          int cz = pz[i] - pz[l];
          if (cz) dp[pre[i]].push_back(cz);
        }
        ++cnt[pre[i]];
        last[pre[i]] = i;
      } else {
        for (auto it = cnt.begin(); it != cnt.end(); ++it) {
          dp[it->first].push_back(it->second);
        }
        cnt.clear();
      }
    }
  }

  int ans = 1; {
    for (int i = 1; i + 1 < pre.size(); ++i) {
      if (pre[i] == 0) ans = 2LL * ans % M;
    }
    for (auto it = dp.begin(); it != dp.end(); ++it) {
      auto s = it->second;
      vector<int> dpdp(2);
      dpdp[0] = 1;
      for (int i = 0; i < s.size(); ++i) {
        (dpdp[~i & 1] += 1LL * s[i] * dpdp[i & 1] % M) %= M;
      }
      (ans += dpdp[1]) %= M;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 51072
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <queue>
#include <algorithm>
#include <stack>
using namespace std;

int main(){
	int N;
	long long int l[100];
	scanf("%d",&N);
	l[0] = 2;
	l[1] = 1;
	for(int i = 2;i <= N;i++){
		l[i] = l[i - 1] + l[i - 2];
		}
	printf("%lld\n",l[N]);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define l_ength size
const int inf = (1<<30);
const int mod = 1000000007;
using ll = long long;
using namespace std;

const int MAX = 4000;
ll fact[MAX], fact_inv[MAX];
 
ll power(ll a, ll b){
	ll res=1;
	while(b>0){
		if(b&1) res=res*a%mod;
		a=a*a%mod;
		b>>=1;
	}
	return res;
}
 
ll comb(ll n, ll r){
	if( n < r ) return 0;
	else return (fact[n]*fact_inv[r])%mod*fact_inv[n-r]%mod;
}
 
int main(){
	ll n, k;
	cin >> n >> k;
	fact[0]=1;
	for( int i = 0; i < 3000; ++i ){
		fact[i+1]=fact[i]*(i+1)%mod;
	}
	fact_inv[3000]=power(fact[3000], mod-2);
	for( int i = 3000-1; i >= 0; --i ){
		fact_inv[i]=fact_inv[i+1]*(i+1)%mod;
	}
	/*
	ll a, b; cin >> a >> b;
	cout << comb(a, b) << endl;
	*/
	for( int i = 1; i <= k; ++i ){
		cout << comb(k-1, i-1) * comb(n-k+1, i) % mod << endl;
	}
	return 0;
}

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

int main() {
	long long int N, A, B, C, D, E;

	cin >> N >> A >> B >> C >> D >> E;

	long long int min_num = min(A, min(B, min(C, min(D, E))));


	long long int ans = 0;

	if (N % min_num == 0) {
		ans = N / min_num + 4;
	}
	else {
		ans = N / min_num + 5;
	}

	cout << ans;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // std::ifstream in("input.txt");
    // std::cin.rdbuf(in.rdbuf());
    ll n, m, v, p;
    cin >> n >> m >> v >> p;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    sort(all(a), greater<ll>());
    ll left = 0, right = n + 1;
    while((left + 1) < right) {
        ll middle = (left + right) / 2;
        // printf("left=%lld, right=%lld\n", left, right);
        if (middle >= n) {
            right = middle;
            // printf("skip2\n");
            continue;
        }
        ll mv = a[middle] + m;
        if (a[p - 1] > mv) {
            right = middle;
            // printf("skip\n");
            continue;
        }
        ll cnt = (p - 1) * m;
        reps(i, p - 1, middle) {
            cnt += max(0LL, mv - a[i]);
        }
        cnt += (n - middle - 1) * m;
        // printf("cnt=%lld, max=%lld\n", cnt, m * (v - 1));
        if (cnt >= (m * (v - 1))) left = middle;
        else right = middle;
    }
    cout << (left + 1) << endl;
    return 0;
}


Measured memory_bytes: 1024
from collections import deque
mod = 10**9+7
N,K = map(int,input().split())
Tree = [[] for _ in range(N+1)]
for i in range(N-1):
    ai,bi = map(int,input().split())
    Tree[ai].append(bi)
    Tree[bi].append(ai)
d = deque([1])
parent = [-1]*(N+1)
permutation = [1,K-2]
for i in range(K-3):
    permutation.append(permutation[-1]*(K-3-i)%mod)
while d:
    x = d.popleft()
    for y in Tree[x]:
        if parent[x] != y:
            parent[y] = x
            d.append(y)
    if x == 1:
        if len(Tree[x]) > K-1:
            ans = 0
        else:
            ans = 1
            for i in range(len(Tree[x])+1):
                ans *= K-i
                ans %= mod
    else:
        if len(Tree[x]) > K-1:
            ans = 0
        else:
            ans *= permutation[len(Tree[x])-1]
            ans %= mod
print(ans)

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

int main()
{
  int n;
  cin>>n;
  vector<int> m(n-1);
  vector<int> ans(n,0);
  for(int i=0;i<n-1;i++)
  {
    cin>>m.at(i);
    ans.at(m.at(i)-1)++;
  }
  for(int i=0;i<n;i++)
  {
    cout<<ans.at(i)<<endl;
  }
}

Measured memory_bytes: 4808
from collections import defaultdict

N, K = map(int, input().split())
A = list(map(int, input().split()))

memo_first = defaultdict(int)
memo_cnt = defaultdict(int)

current = 1
cnt = 1

while K != 0:
    if memo_first[current]==0:
        memo_first[current] = cnt
    if memo_first[current] != 0 & memo_cnt[current]==0:
        memo_cnt[current] = cnt - memo_first[current]
    if memo_cnt[current] != 0:
        roop = K // memo_cnt[current]
        K = K - roop * memo_cnt[current]
    current = A[current - 1]
    K -= 1
    cnt += 1

print(current)

Measured memory_bytes: 37548
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
 
using namespace std;
 
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define rep(i,n) REP(i, 0, n)
#define pb push_back
#define mp make_pair
#define all(r) (r).begin(),(r).end()
#define rall(r) (r).rbegin(),(r).rend()
#define fi first
#define se second
#define DBG(X) cout<<" "<<#X<<" : "<<X<<endl
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;

const int INF = 1e9;
const double EPS = 1e-8;
const int mod = 1e9 + 7;
const ll LINF = 1e18;

struct Input
{
	int n;char c;char str[1024];string s;ll l;
	int nextInt(){scanf("%d", &n);return n;}
	ll nextLong(){scanf("%lld", &l);return l;}
	char nextChar(){scanf("%c", &c);return c;}
	string next(){scanf("%s", str);return string(str);}
	string nextLine(){getline(cin, s);return s;}
};
Input in;


int main(){
	while(1){
		int n = in.nextInt(), w = in.nextInt();
		if(n == 0 && w == 0) break;
		vector<int> v(n), u(110, 0);
		int m = 0, h = 0;
		rep(i, n) {
			v[i] = in.nextInt();
			u[v[i] / w]++;
			m = max(m, v[i] / w);
			h = max(h, u[v[i] / w]);
		}
		double ans = 0.01;
		for(int i = 0; i < m; i++){
			ans += (double)(m - i) / m * (double) u[i] / h;
		}
		printf("%.15lf\n", ans);
	}
}

Measured memory_bytes: 1224
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 2e5 + 10;
#define fi first
#define se second
#define pb push_back
#define wzh(x) cerr<<#x<<'='<<x<<endl;
int t;

int main() {
  ios::sync_with_stdio(false);
  cin>>t;
  LL base=1,now=0;
  for(int i=1;i<=10000000;i++){
    if((now+base*7)%t==0)return cout<<i,0;
    now+=base*7;
    now%=t;
    base*=10;
    base%=t;
  }
  cout<<-1<<'\n';
  return 0;
}

Measured memory_bytes: 3664
n=input()
a=list(map(int,input().split()))
a.sort()
#print(a)
i=0
ans=0
while i!=len(a):
    x=a[i]
    x1=a.count(x)
    if (x>len(a)-i):
        ans=ans+len(a)-i
        break
    else:

        if x<x1:
            ans=ans+x1-x
        elif x>x1:
            ans=ans+x1
        else:
            pass
        i=i+x1
print(ans)

Measured memory_bytes: 14692
"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const S = arg[0].split("");
    
    for(let i=0; i<=200; i++) {
        S.pop();
        
        if(i % 2 === 0) {
            continue;
        }
        
        let mid = S.length / 2;
        
        if(S.slice(0, mid).join("") === S.slice(mid).join("")) {
            console.log(S.length);
            return;
        }
    }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <functional>
using namespace std;

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define rep(n, i) Rep(0, n-1, i)
#define MAX 200000
#define INF (ll)1e10
#define MOD 1000000007

typedef long long ll;
typedef pair<ll, ll> P;
typedef std::priority_queue<int> IntPrioQueue; //Z->A
typedef std::priority_queue<int, std::vector<int>, std::greater<int> > IntReversePrioQueue; //A->Z


int dx4[4]={1,0,-1,0};
int dy4[4]={0,1,0,-1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

void solve(void){
    int ss[3][3];
    rep(3, i) rep(3, j) {
        scanf("%d", &ss[i][j]);
    }
    bool flag = true;
    rep(2, j) {
        rep(2, i){
            if (ss[i+1][j] - ss[i][j] != ss[i+1][j+1] - ss[i][j+1]) flag = false;
        }
    }
    /*
    rep(2, i) {
        rep(2, j){
            if (ss[i][j] - ss[i][j+1] != ss[i+1][j] - ss[i+1][j+1]) flag = false;
        }
    }
    */
    if (flag) printf("Yes\n");
    else printf("No\n");
}

int main(void){
  solve();
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;
mt19937_64 mrand(chrono::steady_clock::now().time_since_epoch().count());
//mt19937_64 mrand(42);
#define ii for(int i=1;i<=n;++i)
#define ji for(int j=1;j<=n;++j)
#define jj for(int j=1;j<=m;++j)
#define ij for(int i=1;i<=m;++i)
#define sz(x) ((ll)x.size())
#define all(x) x.begin(),x.end()
#define al(x) x+1,x+1+n
#define asd cout<<"ok"<<endl;
#define asdd cout<<"okok"<<endl;
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vii vector<pair<int,int>>
#define prt(a, l, r) for(auto i=l;i<=r;++i) cout<<a[i]<<" ";cout<<endl;
#define pc(x) __builtin_popcount(x)
#define pb push_back
#define PS string qqwwee;cin>>qqwwee;
typedef pair<int,int> pii;

int p[5005],c[5005];
int main() {
    int n,k;
    cin>>n>>k;
    ll ans=-1e18;
    ii cin>>p[i];
    ii cin>>c[i];
    for(int i=1;i<=n;++i) {
        int cur=p[i];ll sum=c[cur];
        ll tmp=c[cur];
        vector<ll> v{c[cur]},pre{c[cur]};
        int cnt = 1, f = 0;
        while(cur != i) {
            if(cnt >= k) {f = 1; break;}
            cur = p[cur];
            sum += c[cur];
            v.push_back(c[cur]);
            pre.push_back(sum);
            tmp = max(tmp, sum);
            ++cnt;
        }
        if(!f) {
            for(int j=1;j<=min(2*(int)v.size(),k);++j) {
                int t=j/v.size(),r=j%v.size();
                tmp=max(tmp,t*sum+(r?pre[r-1]:0));
            }
            for(int j=max(1,k-5*(int)v.size());j<=k;++j) {
                int t=j/v.size(),r=j%v.size();
                tmp=max(tmp,t*sum+(r?pre[r-1]:0));
            }
        }
        ans = max(ans, tmp);
    }
    cout<<ans<<endl;
}

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

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

int H, W;
vector<string> Graph(21);

int solve(int i, int j, int k, int l) {
    if (Graph[i][j] == '#' || Graph[k][l] == '#') return 0;

    vector<vector<int>> dist(H, vector<int>(W, -1));  // -1: 未訪問
    queue<P> que;

    que.push(make_pair(i, j));  // スタート地点をプッシュ
    dist[i][j] = 0;

    while (!que.empty()) {
        P p = que.front();
        que.pop();
        for (int direction = 0; direction < 4; ++direction) {
            int nh = p.first + dx[direction];
            int nw = p.second + dy[direction];
            if (nh < 0 || nh >= H || nw < 0 || nw >= W) continue;
            if (dist[nh][nw] > -1) continue;
            if (Graph[nh][nw] == '#') continue;
            dist[nh][nw] = dist[p.first][p.second] + 1;
            if (nh == k && nw == l) {
                //ゴール
                return dist[k][l];
            }
            que.push(make_pair(nh, nw));
        }
    }
    return 0;
}

int main() {
    cin >> H >> W;
    rep(i, H) cin >> Graph.at(i);

    int ans = 0;
    rep(i, H) rep(j, W) rep(k, H) rep(l, W) {
        ans = max(ans, solve(i, j, k, l));
    }

    cout << ans << endl;
}


Measured memory_bytes: 3616
#include<stdio.h>
int main()
{
  int a[1000], n, i, j, k, v;
  scanf("%d", &n);
  for(k = 0; k < n; k++)
    {
      scanf("%d",&a[k]);
    }
  for(k = 0; k < n; k++)
    {
      printf("%d",a[k]);
      if(k+1 < n)
	{
	  printf(" ");
	}
    }
  printf("\n");
  for(i = 1; i < n; i++)
    {
      v = a[i];
      j = i - 1;
      while (j >= 0 && a[j] > v)
	{
	  a[j+1] = a[j];
	  j--;
	  a[j+1] = v;
	}
      for(k = 0; k < n; k++)
	{
	  printf("%d",a[k]);
	  if(k+1 < n)
	    {
	      printf(" ");
	    }
	}
      printf("\n");
    }
  return 0;
}



Measured memory_bytes: 2064
import math
import itertools

n, m, x = map(int, input().split(" "))
li = [list(map(int, input().split(" "))) for _ in range(n)]

_min = float("inf")

for i in range(n):
    for j in list(itertools.combinations(range(n), i + 1)):
        _sum = [0 for _ in range(m)]
        cost = 0
        for jj in j:
            cost += li[jj][0]
        for l in range(1, m + 1):
            for k in j:
                _sum[l - 1] += li[k][l]
        flg = True
        #print(_sum)
        for w in _sum:
            if x > w:
                flg = False
                break
        if flg:
            _min = min(_min, cost)
        # for k in range(j):
        #     print(li[])
        #     _sum += 1

if math.isinf(_min):
    print(-1)
else:
    print(_min)

Measured memory_bytes: 68808
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n,m,k;
    cin>>n>>m>>k;
    int arr[n][m];
     for(int i=0;i<n;i++) {
         for(int j=0;j<m;j++) {
             char c;
             cin>>c;
           //  cout<<c<<" ";
             if(c=='#') 
             arr[i][j]=0;
             else
             arr[i][j]=1;
         }
     }
     vector<pair<int,int>>v;
     for(int i=0;i<n;i++) {
         v.push_back(make_pair(i,1));
     }

     for(int i=0;i<m;i++) {
         v.push_back(make_pair(i,2));
     }
     int nn=v.size();
     int s=0;
        for (int i = 0; i < (1<<nn); i++) 
        { 
            vector<pair<int,int>>ans;
            int brr[n][m];
           for (int j=0;j<nn;j++) {
                if ((i & (1 << j)) > 0)  {
                    ans.push_back(v[j]);
                }
            }
            for(int a=0;a<n;a++) {
                for(int b=0;b<m;b++)
                brr[a][b]=arr[a][b];
            }
            for(int a=0;a<ans.size();a++) {
                 if(ans[a].second==1) {
                     for(int b=0;b<m;b++) {
                         brr[ans[a].first][b]=2;
                                         }
                 }
                 else {
                     for(int b=0;b<n;b++) {
                         brr[b][ans[a].first]=2;
                                         }
                
                 }
            }
            int x=0;
            for(int a=0;a<n;a++) {
                for(int b=0;b<m;b++) {
                    if(brr[a][b]==0)
                    x++;
                }
            }
            if(x==k)
            s++;

            

        }
        cout<<s;
}

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

typedef long long ll;
const ll INF = 1e9, MOD = 1e9 + 7;
const double EPS = 1e-9, PI = 3.141592653589793;
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define REPR(i,a,b) for(ll i=b;i>=a;i--)
#define repr(i,n) REPR(i,0,n)
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define fi first
#define se second
#define m_p make_pair

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

    ll n,k,num=0;
    cin >> n >> k;
    vector<ll> a(n),b(n);
    rep(i,n) cin >> a[i] >> b[i];
    vector<pair<ll,ll>> p(n);
    rep(i,n) p[i] = m_p(a[i],b[i]);
    sort(all(p));
    rep(i,n){
        num += p[i].se;
        if(num >= k){
            cout << p[i].fi << "\n";
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 3456
#define MOD 1000000007

#include <iostream>
#include <vector>
using namespace std;

long pow(long a, long b) {
	if (b == 0) return 1;
	long c = pow(a, b / 2);
	if (b % 2) c = a * c % MOD * c % MOD;
	else c = c * c % MOD;
	return c;
}

int main() {
	long n, k;
	cin >> n >> k;
	if (n < k) cout << 0;
	else {
		vector<long> a(n, 1), b(n, 1);
		for (int i = 1; i < n; i++) {
			a[i] = a[i - 1] * i % MOD;
			b[i] = pow(a[i], MOD - 2);
		}
		cout << a[n - 1] * b[n - k] % MOD * b[k - 1] % MOD;
	}
	cout << endl;
}


Measured memory_bytes: 3132
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws IOException {
		try (BufferedReader br = new BufferedReader(
				new InputStreamReader(System.in))) {

			String in = br.readLine();

			System.out.println(in.equals("Sunny")?"Cloudy"
							  :in.equals("Cloudy")?"Rainy"
							  :"Sunny");
		}
	}
}

Measured memory_bytes: 25336
#include<bits/stdc++.h>
using namespace std;
#define Q 1e5
int main(){
    string s, ans;
    int q, t, f;
    char c;
    deque<char> deq;
    cin >> s >> q;
    for(int i = 0; i < s.size(); i++){
        deq.push_back(s[i]);
    }
    t = 1;
    for(int i = 0; i < q; i++){
        int temp;
        cin >> temp;
        if(temp == 1){
            t *= -1;
        }
        else{
            cin >> f >> c;
            if(f == 1){
                if(t == 1){
                    deq.push_front(c);
                }
                else{
                    deq.push_back(c);
                }
            }
            else{
                if(t == 1){
                    deq.push_back(c);
                }
                else{
                    deq.push_front(c);
                }
            }
        }
    }
    while(!deq.empty()){
        if(t == 1){
            cout << deq.front();
            deq.pop_front();
        }
        else{
            cout << deq.back();
            deq.pop_back();
        }
    }
    cout << endl;
}

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

int main() {
  int x, y, a, b, c;
  cin >> x >> y >> a >> b >> c;

  priority_queue<int> A, B, C, D;

  rep(i, a) {
    int p;
    cin >> p;
    A.push(p);
  }

  rep(i, b) {
    int q;
    cin >> q;
    B.push(q);
  }

  rep(i, c) {
    int r;
    cin >> r;
    C.push(r);
  }

  rep(i, x) {
    D.push(A.top());
    A.pop();
  }

  rep(i, y) {
    D.push(B.top());
    B.pop();
  }

  ll sum = 0;
  rep(i, x + y) {
    if (C.top() > D.top() && !C.empty()) {
      sum += C.top();
      C.pop();
    } else {
      sum += D.top();
      D.pop();
    }
  }

  cout << sum << endl;

  return 0;
}


Measured memory_bytes: 5476
#include <algorithm>
#include <cstdio>
#include <set>
using namespace std;
typedef long long ll;
const int maxn=200010,INF=0x3f3f3f3f;
template <typename Tp> inline int getmin(Tp &x,Tp y){return y<x?x=y,1:0;}
template <typename Tp> inline int getmax(Tp &x,Tp y){return y>x?x=y,1:0;}
template <typename Tp> inline void read(Tp &x)
{
    x=0;int f=0;char ch=getchar();
    while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
    if(ch=='-') f=1,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    if(f) x=-x;
}
struct data{
	int x,y;
	bool operator < (const data &b)const{return x<b.x;}
}a[maxn];
int n,mx,mn,bmn=INF;
ll ans=1e18;
multiset<int> A,B;
int main()
{
	read(n);
	for(int i=1;i<=n;i++)
	{
		read(a[i].x);read(a[i].y);
		if(a[i].x>a[i].y) swap(a[i].x,a[i].y);
		getmax(mx,a[i].y);getmin(bmn,a[i].y);
		A.insert(a[i].x);B.insert(a[i].y);
	}
	sort(a+1,a+n+1);
	mn=a[1].x;//ans=(ll)(mx-bmn)*(a[n].x-mn);
	for(int i=1;i<=n;i++)
	{
		A.erase(A.find(a[i].x));
		B.insert(a[i].x);
		B.erase(B.find(a[i].y));
		A.insert(a[i].y);
	  	getmin(ans,(ll)(*A.rbegin()-*A.begin())*(*B.rbegin()-*B.begin()));
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 22528
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define P pair<int,int>
#define rep(i,n) for(int i=0;i<n;i++)
#define mod 1000000007;
//最大公約数
int gcd(int s,int b){
    if(b==0)return s;
    return gcd(b,s%b);
}
signed main(){
   int n,m;
   cin>>n>>m;
   if((n+m)%2==0){
       cout<<(n+m)/2<<endl;
   }
   else{
       cout<<"IMPOSSIBLE"<<endl;
   }
}


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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define PI 3.14159265358979
#define MOD 1000000007 // = 10^9 + 7

using namespace std;
using ll = long long;


void solve()
{
	int n;
	cin >> n;
	printf("%.7f\n", (n + 1) / 2 / (double)n);
}

int main()
{
	fastio;
	solve();

	return 0;
}

Measured memory_bytes: 3756
#include <iostream>
#include <string>
#include <string.h>
#include <map>
#include <set>
#include <algorithm>
#include <vector>
#include <queue>
#include <stdio.h>
#include <cstdio>
#include <math.h>
#include <cmath>
#include <sstream>
#include <cassert>
#include <functional>
#include <cfloat>
#include <climits>
#include <cstring>
#include <stack>
#include <time.h>
#include <complex>
using namespace std;
typedef long long int64;
#define forn(i,n) for(int i=0;i<(int)(n);i++)
#define ford(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define fore(i,a,n) for(int i=(int)(a);i<(int)(n);i++)
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define last(a) (int(a.size())-1)
#define all(a) a.begin(),a.end()
const double EPS=1E-9;
const int INF=1000000000;
const int64 INF64=(int64) 1E18;
const double PI=3.1415926535897932384626433832;
char a[5][5]; 
int main()
{
	forn(i,3)
		forn(j,3)
		{
  			cin>>a[i][j];
  		}
	cout<<a[0][0]<<a[1][1]<<a[2][2]<<endl; 
    return 0;
}

Measured memory_bytes: 256
def main():
    N = int(input())
    A, B = map(int, input().split())
    P = []
    p = list(map(int, input().split()))
    for l in p:
        P.append(l)
    count = 0
    while True:
        clear = False
        for p in P:
            if 1 <= p <= A:
                P.remove(p)
                clear = True
                break
        if not clear:
            break
        clear = False
        for p in P:
            if A + 1 <= p <= B:
                P.remove(p)
                clear = True
                break
        if not clear:
            break
        clear = False
        for p in P:
            if B + 1 <= p:
                P.remove(p)
                clear = True
                count += 1
                break
        if not clear:
            break
    print(count)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
//
//  main.cpp
//
 
#include <algorithm>
#include <array>
#include <assert.h>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
 
using namespace std;
 
using ll = long long;
using ull = unsigned long long;
 
template<typename T>
vector<T> make_vec_nd(T init, size_t size) {
	return vector<T>(size, init);
}
template<typename T, typename... Args>
auto make_vec_nd(T init, size_t size, Args... rest) {
	auto inner = make_vec_nd(init, rest...);
	return vector<decltype(inner)>(size, inner);
}

#define rep(i,a,b) for(ll i=(a);i<(b);i++)
#define rrep(i,a,b) for(ll i=(a)-1;i>=(b);i--)

int main() {
	ll N;
	cin >> N;
	vector<ll> As(N);
	vector<ll> Bs(N);
	ll sum = 0;
	ll b_mn = numeric_limits<ll>::max();
	rep(i,0,N) {
		ll A, B;
		cin >> A >> B;
		sum += A;
		if (A > B) {
			b_mn = min(b_mn, B);
		}
	}
	if (b_mn == numeric_limits<ll>::max()) {
		cout << 0 << endl;
	} else {
		cout << sum - b_mn << endl;
	}
}


Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<string>
#include<map>
using namespace std;
typedef long long ll;
int main(){
ll n;
  cin>>n;
  int flag=0;
  for(ll i=0;i<=25;i++){
  for(ll j=0;j<=15;j++){
  if(((i*4)+(j*7))==n){
    flag=1;
  break;
  }
  }
  }
  if(flag==1)
    cout<<"Yes";
  else
    cout<<"No";
return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,i;
  cin >> n;
 if(n%1000==0)
 {
 	cout << 0 << endl;
 }
  else
  {
    cout << 1000-(n%1000) << endl;
  }
} 

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

int main()
{
  string str;
  cin >> str;
  int count=0, i=0;
  while(str[i] != '\0')
  {
    if(str[i] == '1') count++;
    i++;
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define endl "\n"

#define rep(i,n) for (int i = 0; i < n; i++)
#define repd(i,n) for (int i = n-1; i >= 0; i--)
#define fo(i,a,b) for (int i = a; i < b; i++)
#define fod(i,a,b) for (int i = a; i >= b; i--)
#define umap unordered_map<int,int>
#define mii map<int,int>
#define pii pair<int,int>
#define vi vector<int>
#define vvi vector<vi>
#define vpii vector<pii>
#define pqMin priority_queue<int,vector<int>,greater<int>>
#define pqMax priority_queue<int>
#define pqpii priority_queue<pii>
#define all(v) v.begin(),v.end()
#define sortall(v) sort(all(v))
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define remax(a,b) a = max(a,b)
#define remin(a,b) a = min(a,b)
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define w(t) int t; cin>>t; while (t--)
#define out(x, y) cout << x << " " << y << endl
#define print(x) cout << x << endl
#define ps(x,y) fixed<<setprecision(y)<<x
#define pprint cout<<"Case #"<<tt<<": ";
const int mod = 1e9+7;
const int N = 2e5;
const int inf = 1e18;

int add(int a,int b){int res=(a+b)%mod;return (res<0)?res+mod:res;}
int mul(int a,int b){int res=(a*1LL*b)%mod;return (res<0)?res+mod:res;}
bool compare (int x, int y) { return x > y;}

struct Compare {
    bool operator () (pii A, pii B) {
        return A.first > B.first;
    }
};
 struct tri{
   int x,y,z;
 };
 struct cmp{
bool operator ()(tri a,tri b){
    if(a.x==b.x)
        return a.y>b.y;
    return a.x<b.x;

}};
bool comp(pii a,pii b){
    if(a.first>b.first) return true;
    else if(a.first==b.first) return a.second<b.second;
    else return false;

}
int binarySearch(vector<int>nums, int lo, int hi, int target) {
        while (lo < hi) {
            int mid = (lo + hi)/2;
            if (nums[mid] <= target) {
                lo = mid + 1;
            } else {
                hi = mid;
            }
        }
        return lo;
    }
void solve() {

    int t = 1;
    //cin >> t;
   while(t--){
        int n,d,i,x,y;
     cin>>n>>d;
     d=d*d;
     vi v(n);
     for(i=0;i<n;i++){
        cin>>x>>y;
        v[i]=(x*x)+(y*y);
     }
     sort(v.begin(),v.end());
     int ans=0;
    for(i=0;i<n;i++){
        if(v[i]>d){
            ans=i;
            break;
        }
    }
   if(v[n-1]<=d) cout<<n;
   else
    cout<<ans;
    }
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

   /* #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif*/

    solve();

    return 0;
}


Measured memory_bytes: 4748
#include<iostream>
#include<sstream>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<complex>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cassert>
using namespace std;

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define each(i,c) for(__typeof(c.begin()) i=c.begin();i!=c.end();i++)
#define pb push_back
#define mp make_pair
#define all(c) c.begin(),c.end()
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<endl

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf=(int)1e9;
const double EPS=1e-9, INF=1e12;

const int mod = (int)1e8 + 7;
int h, w, pw[11];
char in[12][12];
int dp[2][3][60000];

int main(){
	pw[0] = 1;
	rep(i, 10) pw[i + 1] = pw[i] * 3;
	
	cin >> h >> w;
	rep(i, h) cin >> in[i];
	
	int cur = 0, next = 1;
	dp[0][0][0] = 1;
	
	rep(i, h) rep(j, w){
		memset(dp[next], 0, sizeof(dp[next]));
		rep(l, 3) rep(u, pw[w]) if(dp[cur][l][u]){
			
			int tu = u / pw[j] % 3;
			
			if(in[i][j] == '.'){
				if(tu && l) continue;
				if(l == 0 || j < w - 1) (dp[next][l][u] += dp[cur][l][u]) %= mod;
				continue;
			}
			int rest = in[i][j] - '0' - tu - l;
			rep(nl, 3){
				int nu = rest - nl;
				if(nu < 0 || nu > 2) continue;
				if(nl == 0 || j < w - 1)
					(dp[next][nl][u + pw[j] * (nu - tu)] += dp[cur][l][u]) %= mod;
			}
		}
		swap(cur, next);
	}
	cout << dp[cur][0][0] << endl;
	
	return 0;
}

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

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

    long long ans;

    if (B-A<=2)
        ans=K+1;
    else
    {
        long long c=(K-(A-1))/2;
        if (c<0) c=0;
        ans=K+1-2*c+(B-A)*c;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
	int n, k, max;
	int[] c;
	StringBuffer a, b;
	
	
	void loop(int id, int br, int kk){
		if(kk==k+1) return;
		if(id==n){
			int ans = 0;
			int ten = 1;
			for(int i=0;i<n;i++){
				ans += c[i]*ten;
				ten *= 10;
			}
			ans += br*ten;
			max = Math.max(max, ans);
			return;
		}
		
		int p = a.charAt(id) - b.charAt(id) - br;
		if(p>=0){
			c[id] = p;
			loop(id+1,0,kk);
		}else{
			c[id] = p+10;
			loop(id+1,1,kk);
			loop(id+1,0,kk+1);
		}
	}
	
	
	void run(){
		Scanner sc = new Scanner(System.in);
		
		a = new StringBuffer(sc.next()).reverse();
		b = new StringBuffer(sc.next()).reverse();
		int dif = a.length()-b.length();
		for(int i=0;i<dif;i++) b.append(0);
		k = sc.nextInt();
		n = a.length();
		max = 0;
		c = new int[n];
		loop(0,0,0);
		System.out.println(max);
	}
	
	
	public static void main(String[] args) {
		new Main().run();
	}

}

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

using namespace std;

using ll = long long;
constexpr int inf = 1<<30;
constexpr int mo = 1e9+7;
constexpr ll infl = 1ll<<60;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int h,w,n;
    cin>>h>>w>>n;
    int ma = max(h,w);
    int num = (n+ma-1)/ma;
    
    cout << num << endl;
    return 0;
}

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

#define for_(i,a,b) for(int i=(a);i<(b);++i)
typedef long long lint;

string S;
lint n;

lint dfs(int i, vector< string > vs) {
	lint res = 0;
	if (i == n) {
		for (string s : vs) {
			stringstream ss(s);
			lint x; ss >> x;
			res += x;
		}
		return res;
	}
	for_(j,i,n) {
		string sub = S.substr(i, j - i + 1);
		stringstream ss(sub);
		vs.push_back(sub);
		res += dfs(j + 1, vs);
		vs.pop_back();
	}
	return res;
}

int main() {
	cin >> S;
	n = S.size();
	vector< string > vs;
	cout << dfs(0, vs) << endl;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import numpy as np
N = int(input())
x = np.zeros(N)
u = []
for i in range(N):
  xx, uu = input().split()
  x[i] = float(xx)
  u.append(uu)

sum = 0.0
for i in range(N):
  if(u[i] == 'JPY'):
    sum += x[i]
  else:
    sum += x[i]*380000.0

print(sum)


Measured memory_bytes: 21880
yohou = str(input())

yohou_list = list(yohou)

tenki = str(input())

tenki_list = list(tenki)

hi = 0

onaji = 0

while hi < 3 :
    if yohou_list[hi] == tenki_list[hi] :
        onaji+=1
    hi+=1

print(onaji)

Measured memory_bytes: 3060