akhauriyash/Code-Regression huggingface dataset:
// #include C/C++ {
#include <bits/stdc++.h>
// }
using namespace std;
// #typedef {
typedef long long int64;
typedef pair <int, int> PII;
typedef pair <int64, int64> PLL;
// }

// #parameter{
#ifdef _DEBUG

#define TYPE decltype
#define RF(filename) {freopen((filename), "r", stdin);}
#define WF(filename) {freopen((filename), "w", stdout);}
#define DF(filename) {freopen((filename), "w", stderr);}
#define eprintf printf

#else

#define TYPE __typeof
#define RF(filename) {;}
#define WF(filename) {;}
#define DF(filename) {;}
#define eprintf(...)
#define fprintf(...)

#endif

// #define {
#define SZ(a) ((int)(a).size())
#define X first
#define Y second
#define MP make_pair
#define L(x) ((x)<<1)
#define R(x) ((x)<<1 | 1)
#define max3(x, y, z) (max(max((x), (y)), (z)))
#define min3(x, y, z) (min(min((x), (y)), (z)))
#define BIT(x, i) (((x) >> (i)) & 1)
#define ALL(it) (it).begin(), (it).end()
#define FILL(__space, __val) memset(__space, __val, sizeof(__space))
#define MOVE(__spaceTo, __spaceFrom) memmove(__spaceTo, __spaceFrom, sizeof(__spaceTo))
#define UNIQUE(__vector) sort(ALL(__vector)), __vector.resize(unique(ALL(__vector)) - __vector.begin())
#define FOR(it, c) for( TYPE((c).begin()) it = (c).begin(); it != (c).end(); it++)
/////////////////////////////////////////////////////////////
const double PI = acos(-1.0);
const double EPS = 1e-6;

#define MAX_N 100005
#define MAX_M 55
#define MOD (int)(1e9+7)
#define INF ((1 << 30) - 1)
#define BINF ((1LL << 62) - 1LL)
#define NONE -1
#define NIL 0
// }

/////////////////////////////////////////////////////////////
char solve(int x) {
	switch (x % 4) {
	case 0: return 'D';
	case 1: return 'A';
	case 2: return 'C';
	case 3: return 'B';
	}
	return 'E';
}
/////////////////////////////////////////////////////////////
int main() {
	RF("input.txt");
	// WF("output.txt");
	DF("err.txt");

	int N;
	scanf("%d", &N);
	int res = 0;
	while (N--) {
		int a;
		scanf("%d", &a);
		res ^= a;
	}
	puts(res == 0 ? "Yes" : "No");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#define double long double
using namespace std;

int main()
{
	int n;
	double xa, ya, ra, xb, yb, rb;
	
	cin >> n;
	while(n--){
		cin >> xa >> ya >> ra >> xb >> yb >> rb;
		//B in A
		if( hypotl(xa - xb, ya - yb) + rb < ra )
			cout << 2 << endl;
		//A in B
		else if( hypotl(xa - xb, ya - yb) + ra < rb )
			cout << -2 << endl;
		//A intersect B
		else if( hypotl(xa - xb, ya - yb) <= ra + rb )
			cout << 1 << endl;
		else
			cout << 0 << endl;
	}
	return 0;
}

Measured memory_bytes: 1244
#include <iostream>
#include <string>

using namespace std;
int main(void){
    // Your code here!
    string s,t,u;
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    if(a+b==c+d){
        cout<<"Balanced"<<endl;
    }
    else if(a+b>c+d){
        cout<<"Left"<<endl;
    }
    else{
        cout<<"Right"<<endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto& (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define sar(a,n) cout<<#a<<":";rep(pachico,n)cout<<" "<<a[pachico];cout<<endl
#define svec(v) cout<<#v<<":";rep(pachico,v.size())cout<<" "<<v[pachico];cout<<endl
#define svecp(v) cout<<#v<<":";each(pachico,v)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl
#define sset(s) cout<<#s<<":";each(pachico,s)cout<<" "<<pachico;cout<<endl
#define smap(m) cout<<#m<<":";each(pachico,m)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = 200005;

struct pair_hash {
    template <class T1, class T2>
    size_t operator() (const pair<T1, T2>& p) const {
        size_t lhs = hash<T1>()(p.first), rhs = hash<T2>()(p.second);
        return lhs^(rhs+0x9e3779b9+(lhs<<6)+(lhs>>2));
    }
};

vector<int> g[MAX_N];
int visit[MAX_N];
vector<int> G[MAX_N];
bool vis[MAX_N];

void dfs(int u, int kind){
    visit[u] = kind;
    each(v, g[u]){
        if(visit[v] < 0){
            dfs(v, kind);
        }
    }
}

class UF {
private:
    int sz; vector<int> par,nrank;
public:
    UF(){}
    UF(int node_size){ sz = node_size; par.resize(sz),nrank.resize(sz,0); rep(i,sz) par[i] = i; }
    int find(int x){ if(par[x] == x){ return x; }else{ return par[x] = find(par[x]); } }
    void unite(int x,int y)
    { x = find(x),y = find(y); if(x == y) return;
    	if(nrank[x] < nrank[y]) swap(x,y); par[y] = x; if(nrank[x] == nrank[y]) nrank[x]++; }
    bool same(int x,int y){ return find(x) == find(y); }
};

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, K, L;
    cin >> n >> K >> L;
    rep(i,K){
        int u,v;
        cin >> u >> v;
        g[u-1].pb(v-1), g[v-1].pb(u-1);
    }
    rep(i,n){
        visit[i] = -i-1;
    }
    int kind = 0;
    rep(i,n){
        if(visit[i] < 0){
            dfs(i, kind);
            kind++;
        }
    }
    UF uf(n);
    rep(i,L){
        int u,v;
        cin >> u >> v;
        uf.unite(u-1, v-1);
    }
    unordered_map<P, int, pair_hash> mp;
    rep(i,n){
        mp[P(visit[i], uf.find(i))]++;
    }
    rep(i,n){
        cout << mp[P(visit[i], uf.find(i))] << " ";
    }
    cout << "\n";
    return 0;
}


Measured memory_bytes: 25288
import java.util.Scanner;
 
class Main {
    public static void main(final String[] args) {
        Scanner sc = new Scanner(System.in);
 
        int n = sc.nextInt();
        int d = sc.nextInt();

        int ans = 0;
        if (n%(2*d+1) == 0) {
          ans = n/(2*d+1);
        } else { 
          ans = n/(2*d+1) + 1;
        }
        System.out.println(ans);
      }
}


Measured memory_bytes: 23764
// 天秤

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

int main(void) {
  int weight;
  
  while(cin >> weight) {
    vector<int> answer;
    for(int i = 10; i >= 0; --i) {
      if((1 << i) <= weight) {
        weight -= (1 << i);   // ビット演算を使用
        answer.push_back(1 << i);
      }
    }
    
    cout << answer[answer.size() - 1];
    for(int i = answer.size() - 2; i >= 0; --i) {
      cout << " " << answer[i];
    }
    cout << endl;
  }
}


Measured memory_bytes: 3096
import sys

B, W = map(int, sys.stdin.readline().split())
MOD = 10**9 + 7

L = B+W
fact = [1]*(L+1)
rfact = [1]*(L+1)
for i in range(L):
    fact[i+1] = r = fact[i] * (i+1) % MOD
    rfact[i+1] = pow(r, MOD-2, MOD)

rev2 = pow(2, MOD-2, MOD)

p = q = 0
base = 1
ans = ["%d\n" % rev2]
for i in range(1, B+W):
    base = rev2 * base % MOD
    if i-B >= 0:
        p = (p + (fact[i-1]*rfact[B-1]*rfact[i-B] % MOD)*base % MOD) % MOD
    if i-W >= 0:
        q = (q + (fact[i-1]*rfact[W-1]*rfact[i-W] % MOD)*base % MOD) % MOD
    ans.append("%d\n" % ((1-p+q)*rev2 % MOD))
sys.stdout.writelines(ans)

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

int main(){
    int a[10],n,i,j;

    scanf("%d",&n);

    for(i=0;i<n;i++)a[i]=0;
    while(1){
        for(i=0;i<n;i++){
            printf("%c",'a'+a[i]);
        }
        printf("\n");
        for(i=0;i<n;i++)if(a[i]!=i)break;
        if(i==n)break;
        i=n-1;
        while(1){
            for(j=0;j<i;j++){
                if(a[j]==a[i])break;
            }
            if(i!=j){
                break;
            }else{
                i--;
            }
        }
        a[i]++;
        for(i++;i<n;i++)a[i]=0;
    }
    return 0;
}

Measured memory_bytes: 1536
/*
	JAI JAGANNATH!
*/
//@Author : zanj0

#include<bits/stdc++.h>
using namespace std;

typedef long long int lli;

#define ff              first
#define ss              second
#define pb              push_back
#define MOD             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define w(x)            lli x; cin>>x; while(x--)

void zanj0()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

}
lli add(lli a, lli b) {
	return ((a % MOD) + (b % MOD)) % MOD;
}
lli mul(lli a, lli b) {
	return ((a % MOD) * (b % MOD)) % MOD;
}
void solve() {
	lli n;
	cin >> n;
	vector <lli> v(n);
	for (lli i = 0; i < n; i++) {
		cin >> v[i];
	}
	lli ret = 0;
	lli sum = 0 ;
	for (lli i = n - 1; i >= 0; i--) {
		ret = add(ret, (mul(v[i], sum)));
		sum = add(sum, v[i]);
	}
	cout << ret << endl;
}
int main()
{
	zanj0();
	solve();
	return 0;
}

Measured memory_bytes: 4780
#include <bits/stdc++.h>
#define FOR(k,m,n) for(int(k)=(m);(k)<(n);(k)++)
#define REP(k,n) FOR((k),0,(n))
using namespace std;
typedef long long ll;
typedef vector<ll> VLL;
const int MOD=1000000007;

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

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

    int f1 = 0, f400 = 0, f800 = 0, f1200 = 0, f1600 = 0, f2000 = 0, f2400 = 0, f2800 = 0;
    int f3200 = 0;

    REP(i, n){
        switch(a[i] / 400){
            case 0:
                f1 = 1;
                break;
            case 1:
                f400 = 1;
                break;
            case 2:
                f800 = 1;
                break;
            case 3:
                f1200 = 1;
                break;
            case 4:
                f1600 = 1;
                break;
            case 5:
                f2000 = 1;
                break;
            case 6:
                f2400 = 1;
                break;
            case 7:
                f2800 = 1;
                break;
            default:
                f3200++;
                break;
        }
    }

    int min = f1 + f400 + f800 + f1200 + f1600 + f2000 + f2400 + f2800;
    int max = min + f3200;

    if(min == 0){
        if(max > 0){
            min = 1;
        }
    }

    cout << min << " " << max << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner scnr = new Scanner(System.in);
		int n = scnr.nextInt();
		long result;
		if (n % 2 == 0) {
			result = n;
		} else {
			result = n * 2;
		}
		System.out.println(result);
	}
}

Measured memory_bytes: 23892
#include <bits/stdc++.h>
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) find(rng(v),x)!=v.end()
#define incls(s,c) s.find(c)!=string::npos
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bit(n,k) ((n>>k)&1) // nのk bit目
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vs = vector<string>;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using vp = vector<P>;
using vt = vector<T>;
const int mod = 1000000007;
const double EPS = 1e-9;
//const long double EPS = 1e-14;
const int INF = (1<<30)-1;
const ll LINF = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
inline int in() { int x; scanf("%d",&x); return x;}
//template<class T = int> inline T in() { T x; cin >> x; return (x);}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
char itoa(int n) { return n + '0';}
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main () {
  while(1) {
    int x, y;
    cin >> x >> y;
    if (x == 0 && y == 0) break;
    if (x > y) {
      int tmp = x;
      x = y;
      y = tmp;
    }
    printf("%d %d\n", x, y);
  }
  return 0;
}


Measured memory_bytes: 3212
#include "bits/stdc++.h"
using namespace std;
using ll=long long;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define ALL(s) s.begin(),s.end()
#define P pair<ll,ll>
#define vi vector<int>
#define vl vector<ll>
#define vvi vector<vector<int>>
#define vvl vector<vector<ll>>
#define print(n) cout<<n<<endl
const int M=100111;
const int mod=1000000007;
const int inf=1000000007;
const long long INF=1000000000000000007;
int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};
int ddx[8]={1,-1,0,0,1,-1,-1,1},ddy[8]={0,0,1,-1,1,-1,1,-1};

const int maxn=303;

int n,m,l,a,b,c;
ll d[maxn][maxn],tt[maxn][maxn];
void floyd(ll dp[303][303]){rep(k,1,n+1)rep(i,1,n+1)rep(j,1,n+1)dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j]);}

int main(){
	memset(d,INF,sizeof(d));
	cin>>n>>m>>l;
	rep(i,0,m){
		cin>>a>>b>>c;
		d[a][b]=d[b][a]=c;
	}
	floyd(d);
	memset(tt,INF,sizeof(tt));
	rep(i,1,n+1)rep(j,1,n+1)
		if(d[i][j]<=l)tt[i][j]=1;
	floyd(tt);
	int q,s,t;
	cin>>q;
	rep(i,0,q){
		cin>>s>>t;
		cout<<(tt[s][t]>=inf?-1:tt[s][t]-1)<<endl;
	}
}


Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string w, t;
    cin >> w;
    for (char &c: w) c = tolower(c);
    int ans = 0;
    while (cin >> t, t != "END_OF_TEXT") {
        for (char &c: t) c = tolower(c);
        if (w == t) {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


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

struct Rule {
    bool isPermit;
    string source;
    string destination;
};

struct Packet {
    string source;
    string destination;
    string message;
};

bool doesMatchAddress(string pattern, string address) {
    bool match = true;
    for (int i = 0; i < 8; i++) {
        if (pattern[i] != '?' && pattern[i] != address[i]) {
            match = false;
            break;
        }
    }
    return match;
}

int main() {
    while (true) {
        int n, m;
        cin >> n >> m;
        if ((n | m) == 0) {
            break;
        }
        Rule* rules = new Rule [n];
        for (int i = 0; i < n; i++) {
            string key;
            cin >> key;
            rules[i].isPermit = (key == "permit") ? true : false;
            cin >> rules[i].source >> rules[i].destination;
        }
        vector<Packet> legalPackets;
        while (m--) {
            string source, destination, message;
            cin >> source >> destination >> message;
            bool isLegal = false;
            for (int i = 0; i < n; i++) {
                if (doesMatchAddress(rules[i].source, source) && doesMatchAddress(rules[i].destination, destination)) {
                    isLegal = (rules[i].isPermit) ? true : false;
                }
            }
            if (isLegal) {
                Packet packet;
                packet.source = source;
                packet.destination = destination;
                packet.message = message;
                legalPackets.push_back(packet);
            }
        }
        cout << legalPackets.size() << endl;
        for (vector<Packet>::iterator it = legalPackets.begin(); it != legalPackets.end(); it++) {
            cout << it->source << " " << it->destination << " " << it->message << endl;
        }
        delete[] rules;
    }
}

Measured memory_bytes: 1048
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var (
	BufferSize = 20
)

func readLine(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

func scanStr(sc *bufio.Scanner) string {
	if !sc.Scan() {
		panic(nil)
	}
	return sc.Text()
}

func scanInt(sc *bufio.Scanner) int {
	if !sc.Scan() {
		panic(nil)
	}
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	buf := make([]byte, BufferSize)
	sc.Buffer(buf, BufferSize)
	sc.Split(bufio.ScanWords)

	s := scanStr(sc)

	var ans, tmp int
	for i := 0; i < len(s); i++ {
		switch s[i] {
		case 'A', 'C', 'G', 'T':
			tmp++
			if ans < tmp {
				ans = tmp
			}
		default:
			if ans < tmp {
				ans = tmp
			}
			tmp = 0
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <queue>
#include <stack>
#include <math.h>
#include <set>
#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define P pair<int,int>

#define MOD 1000000007
#define INF 2147483647
#define NINF (-2147483647-1)
#define LLINF 9223372036854775807
using ll = long long;
using namespace std;


int main() {
    int a, b, c, d, e, k;
    cin >> a >> b >> c >> d >> e >> k;
    if (e - a <= k) {
        cout << "Yay!" << endl;
    }
    else {
        cout << ":(" << endl;
    }
    getchar(); getchar();
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
 #define rep(i, n) for (int i = 0; i < (int)(n); i++)
 #define big 1000000007
#define all(a) sort((a).begin(),(a).end()) //ソートのマクロ
int main(){
    int x1,y1,x2,y2;
    cin>>x1>>y1>>x2>>y2;
    int x3,y3,x4,y4;
    int X=x2-x1,Y=y2-y1;
    x3=x2-Y;
    y3=y2+X;
    x4=x3-X;
    y4=y3-Y;
    cout<<x3<<" "<<y3<<" "<<x4<<" "<<y4<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

/*

*/

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

        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        double b = sc.nextDouble();
        long bb = Math.round(b * 100);
//        System.out.println(b * 100);
//        System.out.println(Math.floor(b * 100));
        long ans = a * bb / 100;

        System.out.println(ans);

    }
}

Measured memory_bytes: 37480
#include <iostream>
  
int main(){
  int N, x;
  std::cin >> N;
  for(int i=1; i <= 10; ++i){
    if(N <= 1000 * i){
		x=i;
       	std::cout << 1000 * x - N << std::endl;
  		return 0;
    }
  }
}

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

inline int read()
{
	int x=0,f=1,c=getchar();
	while(c<48) c=='-'&&(f=-1),c=getchar();
	while(c>47) x=x*10+c-'0',c=getchar();
	return x*f;
}

const int MAXN = 600005;
const int mod = 924844033;
std::vector<int> G[MAXN];
int fac[MAXN],ifac[MAXN],cnt[MAXN],sz[MAXN];
int f[MAXN],g[MAXN],rev[MAXN];
int n;

inline void addedge(int u,int v)
{
	G[u].push_back(v);
	G[v].push_back(u);
}

inline int qpow(int x,int k)
{
	int res=1;
	for(int i=k; i; i>>=1,x=1ll*x*x%mod)
		if(i&1) res=1ll*res*x%mod;
	return res;
}

inline void init(int n)
{
	for(int i=fac[0]=1; i<=n; ++i)
		fac[i]=1ll*fac[i-1]*i%mod;
	ifac[n]=qpow(fac[n],mod-2);
	for(int i=n; i; --i)
		ifac[i-1]=1ll*ifac[i]*i%mod;
}

inline int cat(int n,int k)
{return 1ll*fac[n]*ifac[k]%mod*ifac[n-k]%mod;}

inline void dfs(int x,int fa)
{
	sz[x]=1;
	for(int y : G[x])
		if(y^fa) dfs(y,x),sz[x]+=sz[y],++cnt[sz[y]];
	++cnt[n-sz[x]];
}

inline void ntt(int *a,int n,int op)
{
	for(int i=0; i<n; ++i) if(i<rev[i]) swap(a[i],a[rev[i]]);
	for(int i=1; i<n; i<<=1)
	{
		int rot=qpow(op==1?5:554906420,(mod-1)/(i<<1));
		for(int j=0; j<n; j+=i<<1)
			for(int k=0,w=1; k<i; ++k,w=1ll*w*rot%mod)
			{
				int x=a[j+k],y=1ll*w*a[j+k+i]%mod;
				a[j+k]=(x+y)%mod,a[j+k+i]=(x-y+mod)%mod;
			}
	}
	if(op==-1)
	{
		int inv=qpow(n,mod-2);
		for(int i=0; i<n; ++i) a[i]=1ll*a[i]*inv%mod;
	}
}

int main(int argc, char const *argv[])
{
	n=read();
	for(int i=1; i<n; ++i) addedge(read(),read());
	dfs(1,0); init(n);
	for(int i=1; i<=n; ++i) f[i]=1ll*cnt[i]*fac[i]%mod;
	for(int i=(reverse(f,f+n+1),0); i<=n; ++i) g[i]=ifac[i];
	int lim=1,l=0;
	for(; lim<=n<<1; lim<<=1,++l);
	for(int i=0; i<lim; ++i)
		rev[i]=(rev[i>>1]>>1)|((i&1)<<(l-1));
	ntt(f,lim,1),ntt(g,lim,1);
	for(int i=0; i<lim; ++i)
		f[i]=1ll*f[i]*g[i]%mod;
	ntt(f,lim,-1);
	reverse(f,f+n+1);
	for(int i=1; i<=n; ++i)
	{
		int t=1ll*ifac[i]*f[i]%mod;
		printf("%lld\n",(1ll*n*cat(n,i)%mod-t+mod)%mod);
	}
	return 0;
}

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

#define MOD 1000000007
#define rep(i, n) for(ll i=0; i < (n); i++)
#define ALL(v) v.begin(),v.end()
#define FOR(i, j, k) for(ll i=j;i<k;i++)
#define DUMP(i, v)for(ll i=0;i<v.size();i++)cout<<v[i]<<" "

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<ll, ll> P;
typedef long double ld;
struct Edge{ll from, to, cost;};
struct node{ll cost, to;
  bool friend operator>(node a, node b){
    return a.cost>b.cost;
  }
};

ll mod(ll a, ll mod){
  ll res = a%mod;
  if(res<0)res=res + mod;
  return res;
}

ll modpow(ll a, ll n, ll mod){
  ll res=1;
  while(n>0){
    if(n&1) res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll modinv(ll a, ll mod){
  return modpow(a, mod-2, mod);
}

ll gcd(ll a, ll b){
  ll r = a%b;
  if(r==0) return b;
  else return gcd(b, a%b);
}

bool is_prime(ll n){
  ll i = 2;
  if(n==1)return false;
  if(n==2)return true;
  bool res = true;
  while(i*i <n){
    if(n%i==0){
      res = false;
    }
    i = i+1;
  }

  //if(i==1)res = false;
  if(n%i==0)res=false;
  return res;
}


/**************************************
** A main function starts from here  **
***************************************/
int main(){
  ll N;
  cin >> N;
  map<ll, ll> num;
  rep(i, N){
    ll tmp;cin >> tmp;
    num[tmp]++;
  }
  if(N%2==0){
    bool ans=true;
    for(ll i=N-1;i>=1;i=i-2){
      ans = ans and num[i]==2;
    }
    if(!ans){
      cout << 0;
      return 0;
    }
    cout << modpow(2, N/2, MOD);
  }else{
    bool ans=true;
    for(ll i=N-1;i>=0;i=i-2){
      if(i!=0){ans = ans and num[i]==2;}
      else{ ans = ans and num[i]==1;}
    }
    if(!ans){
      cout << 0;
      return 0;
    }
    cout << modpow(2, (N-1)/2, MOD);
    
  }
  return 0;
}


Measured memory_bytes: 4224
#include<bits/stdc++.h>
#define ull unsigned long long int
using namespace std;

/*ll power(ll x,ll y)
{
    ll res = 1;
    while(y>0){
        if(y&1)
            res *= x;
        y>>=1;
        x*=x;
    }
    return res;
}*/

//int a[1010][1010];

int main()
{
    int a,b;
    cin>>a>>b;
    if(b==1)
    {
        cout<<0<<'\n';
        return 0;
    }
    int val=a;
    int ans=1;
    for(int i=1;;i++){
            if(b>val)
            {
                ans++;
                val+=(a-1);
            }
            else
                break;
    }
    cout<<ans<<'\n';
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define INF 2000000000
#define MOD 1000000007
#define EPS (1e-10)

using namespace std;

int main(int argc, char *argv[]) {
	int N; cin >> N;

	int ans = ((N % 1000) * 1000 + 1000) - N;
	cout << ans % 1000 << endl;

	return 0;
}


Measured memory_bytes: 3668
#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i, x, n) for(int i = x; i >= n; i--)
#define rrep(i, n) RREP(i,0,n)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define pb push_back
#include<iostream>
using namespace std;

const int mod=1e9+7,INF=1<<30;
const double EPS=1e-12,PI=3.1415926535897932384626;

const int MAX_N = 2003;

int N,K,c[MAX_N][MAX_N],s[MAX_N][MAX_N];

void prepare(){
  REP(x,1,2*K+2)
    REP(y,1,2*K+2) s[x][y] = c[x][y] + s[x-1][y] + s[x][y-1] - s[x-1][y-1];
}

int query(int x1,int y1,int x2,int y2){
  // return sum(x1<=x<=x2,y1<=y<=y2)
  if(x1>x2||y1>y2) return 0;
  else return s[x2][y2] - s[x1-1][y2] - s[x2][y1-1] + s[x1-1][y1-1];
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> N >> K;
  fill(c[0],c[MAX_N-1],0);
  rep(i,N){
    int x,y; char cc;
    cin >> x >> y >> cc;
    if(cc=='B') x += K;
    x %= (2*K); y %= (2*K);
    c[x+1][y+1]++;
  }
  prepare();
  int ans = -INF;
  REP(x,1,K+1) REP(y,1,K+1){
    int temp = query(x,y,x+K-1,y+K-1) + query(x+K,y+K,2*K,2*K) + query(1,1,x-1,y-1)
               + query(x+K,1,2*K,y-1) + query(1,y+K,x-1,2*K);
    ans = max(ans,max(temp,N-temp));
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 31616
n = int(input())
s = input()
s1 = [False for i in range(10)]
s2 = [False for i in range(100)]
s3 = [False for i in range(1000)]


for c in s:
    a = int(c)

    for i in range(100):
        if s2[i]:
            s3[10 * i + a] = True
    for i in range(10):
        if s1[i]:
            s2[10 * i + a] = True
    s1[a] = True

print(sum(s3))

Measured memory_bytes: 3064
//#include <ext/pb_ds/assoc_container.hpp>
#include <bits/stdc++.h>
using namespace std;
//using namespace __gnu_pbds;
//template <class c, class cmp = less<c> > using ordered_set = tree<c, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...) 
#endif
template<class T> ostream& operator<<(ostream &os, vector<T> V) {os << "[ "; for(auto v : V) os << v << " "; return os << "]";}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {return os << "(" << P.first << "," << P.second << ")";}
template <typename T,typename U>pair<T,U> operator+(const pair<T,U> & l,const std::pair<T,U> & r) { return {l.first+r.first,l.second+r.second};}
typedef long long int ll;
const ll mod =1e9+7;
const int maxn = 100002;
#define endl '\n'
#define int ll
#define ld long double
#define all(x) (x).begin(),(x).end()

int32_t main()
{ 
   IOS


  int n,m,k;
  cin>>n>>m>>k;
  int a[n+1] = {0};
  int b[m+1] = {0};
  for(int i = 1;i<=n;i++){
    cin>>a[i];
    a[i]+=a[i-1];
  }

  for(int i = 1;i<=m;i++) cin>>b[i],b[i]+=b[i-1];
  int ans = 0;
  for(int i = 0;i<=n;i++){
    int now = a[i];
    if(now>k) break;
    int u = lower_bound(b,b+m+1,k-now) - b;
    if(u == m+1){
      ans = max(ans,i+m);
    }
    else if(b[u]>k-now){
      ans = max(ans,i+u-1);
    }
    else{
      ans = max(ans,i+u);
    }
  }
  cout<<ans<<endl;



  
}

Measured memory_bytes: 6784
import numpy as np
from numpy.fft import rfft, irfft
from itertools import cycle

mod = 10 ** 9 + 7
S = input()

mat = []
for i in range(6):
    w = np.zeros(13)
    for j in range(10):
        w[(10 ** i * j) % 13] += 1
    mat.append(rfft(w))

ress = [[(10 ** i * j) % 13 for j in range(10)] for i in range(6)]


state = np.zeros(13)
state[0] = 1
state = rfft(state)

res = 5
for keta, s in zip(cycle(range(6)), reversed(S)):
    if s == "?":
        state = state * mat[keta]
    else:
        res -= ress[keta][int(s)]

    if state[0] >= 2 ** 50:
        state = np.round(irfft(state, 13))
        state = rfft(np.remainder(state, mod))


state = irfft(state, 13)
print(int(np.round(state[res % 13])) % mod)


Measured memory_bytes: 14736
if __name__ == '__main__':
    s = input()
    for i in range(len(s) - 1):
        if s[i] == s[i + 1]:
            print("{} {}".format(i + 1, i + 2))
            exit(0)
    for i in range(len(s) - 2):
        if s[i] == s[i + 2]:
            print("{} {}".format(i + 1, i + 3))
            exit(0)
    print("-1 -1")


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

#define REP(i,n) for(ll i=0; i<(ll)(n); i++)
#define FOR(i,n,m) for (ll i=n; i<(ll)(m); i++)
#define pb push_back
#define INF 1000000007LL
#define all(a) (a).begin(),(a).end()

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

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

ll N, X;

ll dfs(ll a, ll b) {
    if (a > b) swap(a,b);
    if (b%a!=0) {
        return 2 * (ll)(b/a) * a + dfs(a,b%a);
    }
    return 2 * b - a;
}

int main(){
    ios::sync_with_stdio(false);
    cin >> N >> X;
    ll Y = N - X;
    cout << dfs(X,Y) + X + Y << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
  char s[2048];
  int i;
  fgets(s, sizeof(s), stdin);
  for(i = 0;s[i] != '\0';i++){
    if('a' <= s[i] && s[i] <= 'z') s[i] += 'A' - 'a';
    else if('A' <= s[i] && s[i] <= 'Z') s[i] += 'a' - 'A';
  }

  printf("%s",s);
  return 0;
}


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

ll comb(int n, int r) {
  vector<vector<long long>> v(n + 1,vector<long long>(n + 1, 0));
  for (int i = 0; i < v.size(); i++) {
    v[i][0] = 1;
    v[i][i] = 1;
  }
  for (int j = 1; j < v.size(); j++) {
    for (int k = 1; k < j; k++) {
      v[j][k] = (v[j - 1][k - 1] + v[j - 1][k]);
    }
  }
  return v[n][r];
}

int main()
{
    int n, p;
    cin >> n >> p;
    int e = 0;
    int o = 0;
    rep(i, n) {
        int a;
        cin >> a;
        if(a % 2) ++o;
        else ++e;
    }
    if(o == 0 && p == 1) {
        cout << 0 << endl;
        return 0;
    }
    else if(o == 0 && p == 0) {
        ll l = 1;
        rep(i, n) {
            l *= 2;
        }
        cout << l << endl; 
        return 0;
    }
    ll ans = 0;
    ll k = 1;
    rep(i, e) {
        k *= (ll) 2;
    }
    ll t = 0;
    for(int i = 1; i <= o; i += 2) {
        t += comb(o, i);
    }
    ans = k * t;
    if(p) {
        cout << ans << endl;
    }
    else {
        ll s = 1;
        rep(i, n) {
            s *= (ll) 2;
        }
        cout << s - ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3624
#!/usr/bin/env python
# -*- coding: utf-8 -*-

while True:
    N,M = map(int,input().split())
    if N == 0 and M == 0:
        break
    r = int(input())
    user = [[0 for i in range(1260+1)] for j in range(M+1)]
    for i in range(r):
        t,n,m,s = map(int,input().split())
        if s == 1:
            user[m][t] += 1
        else:
            user[m][t] -= 1

    q = int(input())
    for i in range(q):
        ts,te,m = map(int,input().split())
        if user[m][0] == 0:
            for j in range(540,1261):
                user[m][j] += user[m][j-1]
            user[m][0] = 1
        print(sum([1 for j in range(ts,te) if user[m][j] > 0]))

Measured memory_bytes: 164072
#include<stdio.h>
int isprime(int x)
{
    int i;
    if(
        x==2||
        x==3||
        x==5||
        x==7||
        x==11||
        x==13||
        x==17||
        x==19
        )return 1;
    else if(
        x==1||
        x%2==0||
        x%3==0||
        x%5==0||
        x%7==0||
        x%11==0||
        x%13==0||
        x%17==0||
        x%19==0
    )return 0;
    else if(x<100000){
        for(i=23;i<x;i+=2){
            if(x%i==0)return 0;
        }
    }
    else if(x>=100000){
        for(i=23;i*i<x;i+=2){
            if(x%i==0)return 0;
        }
    }
    return 1;
}

int main()
{
    int a,b,c=0,i;
    scanf("%d",&a);
    for(i=0;i<a;i++){
        scanf("%d",&b);
        c+=isprime(b);
    }
    printf("%d\n",c);
    return 0;
}

Measured memory_bytes: 596
#include<iostream>
#include<vector>
#include<algorithm>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

int GCD(int x, int y) {
	if (x % y == 0) {
		return y;
	}
	else {
		return(GCD(y, x % y));
	}
}

int main(void) {
	
	int K, sum = 0;
	cin >> K;
	
	for (int a = 1; a <= K; a++) {
		for (int b = 1; b <= K; b++) {
			int tmp = GCD(a, b);
			for (int c = 1; c <= K; c++) {
				sum += GCD(tmp, c);
			}
		}
	}

	cout << sum << endl;
	return 0;

}

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

class Program
{
    static void Main(string[] args)
    {
        var nab = Console.ReadLine().Split().Select(long.Parse).ToArray();
        var n = nab[0];
        var a = nab[1];
        var b = nab[2];

        var ans = (n / (a + b)) * a;

        var mod = n % (a + b);
        ans += Math.Min(mod, a);

        Console.WriteLine(ans);
    }
}


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

class HashTable(list):
    def __init__(self, length):
        list.__init__(self)
        self.length = length
        self[:] = [None] * length

    def h(self, key, i):
        h1 = key % self.length
        h2 = 1 + (key % (self.length - 1))
        return (h1 + i*h2) % self.length

    def insert(self, key):
        i = 0
        while True:
            h1 = key % self.length
            h2 = 1 + (key % (self.length - 1))
            j = (h1 + i*h2) % self.length
            #j = self.h(key, i)
            if self[j] is None:
                self[j] = key
                return j
            else:
                i += 1
    
    def search(self, key):
        i = 0
        while True:
            h1 = key % self.length
            h2 = 1 + (key % (self.length - 1))
            j = (h1 + i*h2) % self.length
            #j = self.h(key, i)
            if self[j] == key:
                return j
            elif self[j] is None or i >= self.length:
                return None
            else:
                i += 1

def getNum(char):
    char2num = str.maketrans("ACGT", "1234")
    return int(char.translate(char2num), 5)

if __name__ == '__main__':

    n = int(input())
    T = HashTable(1046527)
    C = [input().split(" ") for i in range(n)]
    
    for command, char in C:
        num = getNum(char)
        if command[0] == "i":
            T.insert(num)
        else:
            if T.search(num) is None:
                print("no")
            else:
                print("yes")


Measured memory_bytes: 316348
#include <iostream>
#include <stdio.h>
#include <array>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <algorithm>
#include <map>
#include <cmath>
#include <stdlib.h>
#include <string.h>
#include <stack>

using namespace std;

typedef double db;
typedef long long ll;
typedef pair<int, int> PII;

int a, b;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define REP1(i,n) FOR(i,1,n)
#define MAX(a,b) a>b? a:b
#define MIN(a,b) a>b? b:a


const int MOD = 1e9 + 7;
const ll INF=1e10;
const db PI = acos(-1.0);
const db EPS = 1e-10;


ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }


ll MAXX(vector<ll> a,ll k) {
	ll max = 0;
	REP(i, k) {
		if (a[i] >= max) max = a[i];
	}
	return max;
}

ll MINN(vector<ll> a,ll k) {
	ll min = INF;
	REP(i, k) {
		if (a[i] <= min)min = a[i];
	}
	return min;
}

ll SUM(vector<ll> a, ll k) {
	ll sum = 0;
	REP(i, k) {
		sum += a[i];
	}
	return sum;
}

db AVE(vector<ll> a, ll k) {
	db ave = SUM(a,k)/(db)k;
	return ave;
}

db VAR(vector<ll> a, ll k) {
	db ave,ave2,var;
	db sum = 0;
	REP(i, k) {
		sum += a[i] * a[i];
	}
	ave2 =sum/ k;
	ave = AVE(a,k);
	ave = pow(ave,2);
	var = ave2 - ave;
	return var;
}


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;
}


void prime(int k) {
	int cnt = 0;
	for (int i = 2;i<k;i++) {
		if (k % i == 0) { cnt++; }
	}
	if (cnt == 0) cout << k << "は素数です。" << endl;
	else cout << k << "は素数ではありません。" << endl;
}


int main() {
	int a, b, c, x,ans,cnt=0;
	cin >> a >> b >> c >> x;
	
	a = MIN(a, x / 500);
	b = MIN(b,x/100);
	c = MIN(c, x / 50);
	for (int i = a;i>=0;--i) {
		for (int j = b;j >= 0;--j) {
			for (int k = c;k >= 0;--k) {
				ans = i * 500 + j * 100 + k * 50;
				if (ans == x)cnt++;
			}
		}

	}
	cout << cnt;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <climits>
using namespace std;
 
vector<long long> dijkstra(int n, int s, const vector<vector<pair<long long, int>>> &G) {
    priority_queue<pair<long long, int>, vector<pair<long long, int>>, greater<pair<long long, int>>>
        que;
    vector<long long> d(n, 1LL << 60);
    d[s] = 0;
    que.push(pair<long long, int>(0, s));
    while (!que.empty()) {
        pair<long long, int> p = que.top();
        que.pop();
        int v = p.second;
        if (d[v] < p.first) continue;
        for (int i = 0; i < G[v].size(); i++) {
            pair<long long, int> e = G[v][i];
            if (d[e.second] > d[v] + e.first) {
                d[e.second] = d[v] + e.first;
                que.push(pair<long long, int>(d[e.second], e.second));
            }
        }
    }
    return d;
}
 
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<vector<pair<long long, int>>> G(N);
    for(int i=0; i<N-1; i++){
        int a, b, c;
        cin >> a >> b >> c;
        a--; b--;
        G[a].push_back(make_pair(c, b));
        G[b].push_back(make_pair(c, a));
    }
    int Q, K;
    cin >> Q >> K;
    K--;
    vector<long long> d = dijkstra(N, K, G);
    for(int i=0; i<Q; i++){
        int x, y;
        cin >> x >> y;
        x--; y--;
        cout << d[x] + d[y] << endl;
    }
 
    return 0;
}

Measured memory_bytes: 11120
A,B =map(int,input().split())
hih=0
num=1
test=1
S=str(input())
S= list(S)
for s in S:
    if num==A+1 and s=="-":
        hih=1
    if num!=A+1 and s=="-":
        test=0
        
    
    num+=1
if hih==1 and test==1:
    print("Yes")
else:
    print("No")

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

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'

//↓0-originか1-originでn回繰り返し
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   //0-origin昇順
#define rep1(i,n) for(int i = 1; i <= ((int)(n)); i++) //1-origin昇順
#define rrep(i,n) for(int i = ((int)(n)-1); i >= 0; i--)  //0-origin降順
#define rrep1(i,n) for(int i = ((int)(n)); i >= 1; i--)   //1-origin降順
//rep2 -> 第二引数 m から n 回繰り返し ex) m=5 n=3 なら i=5,i=6,i=7 まで
#define rep2(i,m,n) for(int i = ((int)(m)); i < ((int)(n))+((int)(m)); i++)
#define SIZE(x) ((int)((x).size()))
#define all(x) (x).begin(),(x).end()
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii; //2次元配列
typedef vector<ll> vll;
typedef vector<string> vs;
typedef pair<int,int> PII;
template<class T,class U> inline bool chmax(T &a, const U &b){if(a<b){a=b;return 1;}return 0;}
template<class T,class U> inline bool chmin(T &a, const U &b){if(a>b){a=b;return 1;}return 0;}

/* 円周率は M_PI を使おうね */
const ll infll = (1LL<<62)-1;
const int inf = (1<<30)-1;

/*FUNCs=================================================*/


/*MAIN==================================================*/
signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化
    //cout << fixed << setprecision(10);

    int n;
    while(cin >> n) {
        if(n==0) break;
        string l;
        ll p, a,b,c,d,e,f,s,m;
        priority_queue<pair<ld, string>, vector<pair<ld,string>>, greater<pair<ld,string>>> que;
        rep(i,n) {
            cin >> l >> p>>a>>b>>c>>d>>e>>f>>s>>m;
            ll time = a+b+c+d+e + (m-1)*(d+e);
            ll price = f*s*m - p;
            long double eff = (ld)price / (ld)time;
            eff *= (-1);
            que.emplace(eff,l);
        }

        while(que.size()) {
            string ans;
            ld q;
            tie(q, ans) = que.top(); que.pop();
            cout << ans << '\n';
            //debug(q);
        }

        cout << '#' << '\n';
    }
}


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

void solve() 
{
   int n;cin>>n;
   cout<<(1000-(n%1000)==1000?0:1000-(n%1000))<<endl; 
}

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

Measured memory_bytes: 3652
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <limits.h>
using namespace std;
int main(void)
{
    int N, K;
    cin >> N >> K;
    
    vector<int> X(N);
    vector<int> p, m;
    int zero_count = 0;
    
    for(int i = 0;i < N;i++)
    {
        cin >> X[i];
        
        if(X[i] > 0)
        {
            p.push_back(X[i]);
        }
        else if(X[i] < 0)
        {
            m.push_back(X[i] * -1);
        }
        else
        {
            zero_count++;
        }
    }
    
    if(zero_count >= K)
    {
        cout << 0 << endl;
        return 0;
    }
    
    long long ans = LLONG_MAX;
    
    K -= zero_count;
    
    sort(m.begin(), m.end());
    
    for(int i = 0; i <= K;i++)
    {
        if(p.size() < i || m.size() < (K - i))
        {
            continue;
        }
        
        long long point = 0;
        long long pp = 0, mp = 0;
        if(i != 0)
        {
            pp = p[i - 1];
        }
        
        if(K - i != 0)
        {
            mp = m[K - i - 1];
        }
        
        if(pp < mp)
        {
            pp *= 2;
        }
        else
        {
            mp *= 2;
        }
        
        point += pp + mp;
        
        if(point < ans)
        {
            ans = point;
        }
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 1404
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdlib>
using namespace std;
typedef long long  LL; 
const int MAXN=300;
LL b,a[MAXN],c;
int n,m; 
LL gcd(LL a,LL b){
	if (!b) return a;
	else return gcd(b,a%b); 
} 
int main()
{
	while (cin>>n,n){

		m=0;c=-1; 
		for (int i=0;i<n*(n+1)/2;i++){
			cin>>b; 
			if (b%2==0) a[m++]=b;	
			else{
				if (c==-1) c=b;
				else if (b<c) c=b; 
			}			
		} 
		LL t; 
		sort(a,a+m);
	
			LL u=a[0]/gcd(a[0],c);
			c/=gcd(a[0],c); 
			LL v=a[1]/c;
			t=(LL)(sqrt(u*v)); 
	
		for (int i=0;i<m;i++){
			a[i]/=t;	
		} 
		cout<<t<<'\n';

		for (int i=0;i<m-1;i++)cout<<a[i]<<" ";
		cout<<a[m-1]<<'\n'; 
	} 
	return 0; 
} 

Measured memory_bytes: 1188
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <queue>
#include <cstring>
#include <string>
#include <stack>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>
#include <ctime> 
using namespace std;

#define pb push_back
#define All(a) a.begin(), a.end()
#define met(a, b) memset(a, b, sizeof(a))
#define rep1(i, l, r) for(int i = l; i <= r; ++i)
#define rep2(i, l, r) for(int i = l; i < r; ++i) 
#define per(i, r, l) for(int i = r; i >= l; --i)
typedef long long ll;
typedef double db;
typedef long double ldb;
const int NIL = -1;
const int oo = 0x3f3f3f3f;
const ll INF = 2e18;
const db eps = 1e-8;
const db PI = acos(-1.0);

inline int read(void)
{
	int x = 0, f = 1; char ch = getchar();
	while(ch < '0' || ch > '9')	{ if(ch == '-') f = -1; ch = getchar(); } 
	while(ch >= '0' && ch <= '9') {	x = (x << 1) + (x << 3) + ch - '0';	ch = getchar();	}
	return x * f;
}

inline void write(int x)
{
	if(x < 0) { putchar('-'); x = -x; }
    if(x >= 10) write(x/10); 
	putchar(x%10+'0'); 
}

int main(void)
{
	int n = read(), i = read();
	printf("%d", n - i + 1); 
	
	return 0;
} 

Measured memory_bytes: 256
#include<cstdio>
#include<vector>
#include<complex>
#include<algorithm>
#include<cstdlib>
#include<ctime>
using namespace std;
typedef complex<double> C;
#define cx real()
#define cy imag()
const double EPS = 1e-7;

bool isEqual(double a, double b) { return abs(a-b) < EPS; }
double dot(C a, C b) { return a.cx * b.cx + a.cy * b.cy; }
double det(C a, C b) { return a.cx * b.cy - a.cy * b.cx; }
bool isParallel(C a1, C a2, C a3) { return isEqual(0, det(a1-a3, a2-a3)); }

int n, k, x, y;
C c[3000];

int main() {
  srand((unsigned int)time(NULL));
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; i++) scanf("%d%d", &x, &y), c[i] = C(x, y);
  for (int i = 0; i < 300000; i++) {
    int a = rand() % n, b = rand() % n;
    if (a == b) { i--; continue; }
    int counter = 0;
    for (int i = 0; i < n; i++) {
      if (i == a || i == b) counter++;
      else if (isParallel(c[i], c[a], c[b])) counter++;
    }
    if (counter >= k) {
      printf("1\n");
      return 0;
    }
  }
  printf("0\n");
}



Measured memory_bytes: 2684
//#include <bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#include<cstring>
#include<bitset>
#include<stack>

#define X first
#define Y second
#define PB push_back
#define MP make_pair
#define scd(a) scanf("%d",&a)
#define scdd(a,b) scanf("%d%d",&a,&b)
#define scddd(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define ALL(x) x.begin(),x.end()
#define mst(var,val) memset(var,val,sizeof(var))
#define IOS ios::sync_with_stdio(false);cin.tie(0)
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ls rt<<1
#define rs rt<<1|1
#ifdef local
#define dbg(a) cout << #a": " << a << endl;
#else
#define dbg(a)
#endif // loacl


using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <double, double> pdd;
const ll inf=0x3f3f3f3f;
const long long INF=0x3f3f3f3f3f3f3f3fLL;
const double PI=acos(-1.0);
const long double eps=1e-6;
const int mod=1e9+7;
const int maxn=20;
const int N=1e5+10;
const int M=N<<1;
const ll mm=(1LL<<32);

template <class T>
inline void read(T &x) {
    x = 0;
    char c = getchar();
    bool f = 0;
    for (; !isdigit(c); c = getchar()) f ^= c == '-';
    for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48);
    x = f ? -x : x;
}

template <class T>
inline void write(T x) {
    if (x < 0) {
        putchar('-');
        x = -x;
    }
    T y = 1;
    int len = 1;
    for (; y <= x / 10; y *= 10) ++len;
    for (; len; --len, x %= y, y /= 10) putchar(x / y + 48);
}
ll qpow(ll a,ll b,ll MOD)
{
    ll ans=1;
    while(b)
    {
        if(b&1) ans=(ans*a)%MOD;
        b>>=1;
        a=(a*a)%MOD;
    }
    return ans;
}


struct Point{
    int x,y;
}p[105];
bool cmp(const Point &a,const Point &b)
{
    return atan2(a.y,a.x)<atan2(b.y,b.x);
}
int nx[105];
int main()
{
#ifdef local
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
#endif // local
    IOS;
    int n;cin>>n;
    rep1(i,n) cin>>p[i].x>>p[i].y;
    rep1(i,n) nx[i]=i+1;nx[n]=1;
    sort(p+1,p+1+n,cmp);
    ll ans=0;
    for(int i=1;i<=n;++i)
    {
        ll x=p[i].x,y=p[i].y;
        ans=max(ans,x*x+y*y);
        for(int j=nx[i];j!=i;j=nx[j])
        {
            x+=p[j].x;y+=p[j].y;
            ans=max(ans,x*x+y*y);
        }
    }
    double sum=1.0*sqrt(ans);
    printf("%.10f\n",sum);
    return 0;
}



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

int main(void){
  int N;
  cin>>N;
  bool flag1 = false;
  bool flag2 = false;
  bool flag3 = false;
  
  for(int i=0;i<N;i++){
    int D1,D2;
    cin>>D1>>D2;
    if(D1 == D2){
     if(flag1){
       if(flag2){
        flag3=true; 
       }else{
         flag2=true;
       }
     }else{
       flag1=true;
     }
    }else{
      flag1=flag2=false;
    }
  }
  if(flag3){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  
  return 0; 
}

Measured memory_bytes: 3632