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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    ll K, A, B;
    cin >> K >> A >> B;
    ll margin = B - A;
    ll ans = 1 + K;
    ll tmp = K - A + 1;
    if (tmp % 2) {
        ans = max(ans, 1 + A + (B - A) * (tmp / 2));
    } else {
        ans = max(ans, A + (B - A) * (tmp / 2));
    }
    cout << ans << '\n';
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    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)
#define REPr(i,n) for(int i=(n)-1;i>=0; --i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define FORqr(i, m , n) for(int i = (n);i >=(m);--i)
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define SCLLD(n) scanf("%lld",&n)
#define SCLLD2(m,n) scanf("%lld%lld",&m,&n)
#define SCLLD3(m,n,k) scanf("%lld%lld%lld",&m,&n,&k)
#define PB push_back
#define MP make_pair
#define ARSCD(A,N) REP(i,N){SCD(A[i]);}
#define ARSCD1(A,N) FORq(i,1,N){SCD(A[i]);}
#define VSCD(v,N) REP(i,N){int (x); SCD(x); v.PB(x);}
#define VSCLLD(v,N) REP(i,N){long long (x); SCLLD(x); v.PB(x);}
#define PRINTD(n) printf("%d\n",n)
#define PRINTLLD(n) printf("%lld\n",n)
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x,S) (S.count(x) != 0)
#define M0(x) memset(x,0,sizeof(x))
#define FILL(x,y) memset(x,y,sizeof(x))
#define MM(x) memset(x,-1,sizeof(x))
#define ALL(x) (x).begin(),(x).end()
using namespace std;
typedef pair<int,int> PII;
typedef pair<long long,long long> PLL;
typedef vector<int> VI;
typedef vector < VI > VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
///////////////////////////////////////////////
const ll MOD = 1000000007;
ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
///////////////////////////////////////////////
int main(){
    ll A,B,K;
    cin >> A >> B >> K;
    REP(i,K){
        if (i % 2 == 0){
            if (A % 2 == 1) A--;
            B = A/2 + B;
            A = A/2;

        }else{
            if (B % 2 == 1) B--;
            A = B/2 + A;
            B = B/2;
        }
    }

    cout << A << " " << B << endl;
}






Measured memory_bytes: 256
N = int(input())
AC = TLE = WA = RE = 0

for _ in range(N):
    user = input()
    if user == "AC":
        AC += 1
    elif user == "TLE":
        TLE += 1
    elif user == "WA":
        WA += 1
    elif user == "RE":
        RE += 1
print("AC x {} \nWA x {} \nTLE x {} \nRE x {}".format(AC, WA, TLE, RE))


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

#define vint vector<int>
#define vvint vector<vint>
#define sint stack<int>
#define qint queue<int>
#define rep(i, n) for(int i=0;i<(int)(n);i++) // 繰り返し処理
#define all(x) (x).begin(),(x).end() // 全体 こんな感じで使う→sort(all(a));
#define ct(a) cout << a << endl
#define iceil(a,b) (a+(b-1))/b //int ceil : 繰り上げの割り算 通常のceilではceil((7.0/2.0))のようにしなければならなかった。
#define ld long double
vint CinLine(int N){vint v(N);for(int i=0;i<N;i++){cin >> v.at(i);}return v;}//cin line 連続でvectorに格納
void CoutLine(vint v){for(int i=0;i<v.size()-1;i++){cout<<v.at(i)<<" ";}cout << v.at(v.size()-1)<<endl;}



ld getSqrtl(ld x1,ld y1,ld x2,ld y2){
}

int main() {
    int a,b;
    cin >> a >> b;
    ct(a*b);
}



Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;

struct era{
    string eraname;
    int year,order;
};

int main(){
    while(1){
        int n,q;
        cin >> n >> q;
        if(n==0 && q==0) break;
        vector<era> eras(n);
        vector<int> year(q);
        rep(i,n) cin >> eras[i].eraname >> eras[i].order >> eras[i].year;
        rep(i,q) cin >> year[i];


        rep(i,q){
            string ans = "Unknown";
            int y = -1;
            int mn = INF;
            rep(j,n){
                if(year[i] > eras[j].year || eras[j].order - eras[j].year + year[i] <= 0) continue;

                if(eras[j].year - year[i] < mn){
                    mn = eras[j].year - year[i];
                    y = eras[j].order - eras[j].year + year[i];
                    ans = eras[j].eraname;
                }
            }

            cout << ans;
            if(y!=-1) cout << " " << y << endl;
            else cout << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3224
#include<bits/stdc++.h>
using namespace std;
int n, a[100005], x, tot;
int cmp(int a, int b){
	return a>b;
}
int main(){
	cin>>n;
	a[0]=2e9;
	for(int i=1;i<=n;i++){
		scanf("%d", &x);
		if(x<=a[tot]) a[++tot]=x;
		else *upper_bound(a+1, a+tot+1, x, cmp)=x;
	}
	cout<<tot;
} 

Measured memory_bytes: 640
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

n = int(input())
prev_time = 0
prev_point = (0, 0)
for i in range(n):
    t, x, y = map(int, input().split())
    dist = abs(x - prev_point[0]) + abs(y - prev_point[1])
    if dist > (t - prev_time):
        print('No')
        sys.exit(0)

    if (t - prev_time) % 2 != dist % 2:
        print('No')
        sys.exit(0)
    prev_time = t
    prev_point = (x, y)
print('Yes')


Measured memory_bytes: 73944
n = int(input())
r = [int(input()) for i in range(n)]

m = r[n-1]
ans = -10**10
for i in range(n-2, -1, -1):
    t = m-r[i]
    if t > ans:
        ans = t
    if r[i] > m:
        m = r[i]
print(ans)



Measured memory_bytes: 13600
H, W, K = parse.(Int64, split(readline()))

function init(H::Int64, W::Int64, K::Int64)
    mat = zeros(Int64, (H, W))
    for i in 1:H
        input = readline()
        for j in 1:W
            if input[j] == '#'
                mat[i, j] = 1
            end
        end
    end
    return mat
end

function plus_row(S::Array{Int64,2}, row::Int64, col_max::Int64)
    for i in 1:col_max
        S[row, i] = 2
    end
end

function plus_col(S::Array{Int64,2}, col::Int64, row_max::Int64)
    for i in 1:row_max
        S[i, col] = 2
    end
end

function count_black(S::Array{Int64, 2}, H::Int64, W::Int64)
    count = 0
    for i in 1:H
        for j in 1:W
            if S[i, j] == 1 
                count += 1
            end
        end
    end
    return count
end

function rep_set(A::Array{Int64, 1}, count::Int64)
    for i in 1:6
        if ((count-1) % (2^i)) >= (2^(i-1))
            A[i] = 1
        else
            A[i] = 0
        end
    end
    return A
end

function renew(S::Array{Int64, 2}, H::Int64, W::Int64, rep_H::Array{Int64,1}, rep_W::Array{Int64,1})
    for i in 1:H
        if rep_H[i] == 1 
            plus_row(S, i, W)
        end
    end
    for i in 1:W
        if rep_W[i] == 1
            plus_col(S, i, H)
        end
    end
end

function reset(S::Array{Int64, 2}, init_S::Array{Int64, 2}, H::Int64, W::Int64)
    for i in 1:H
        for j in 1:W
            S[i, j] = init_S[i, j]
        end
    end
end

function main(H::Int64, W::Int64, K::Int64)
    mat      = init(H, W, K)
    init_mat = zeros(Int64, (H, W))
    reset(init_mat, mat, H, W)
    H_max = 2^H
    W_max = 2^W
    rep_H = zeros(Int64, 6)
    rep_W = zeros(Int64, 6)
    ans = 0
    for h in 1:H_max
        rep_H = rep_set(rep_H, h)
        for w in 1:W_max
            rep_W = rep_set(rep_W, w)
            renew(mat, H, W, rep_H, rep_W)
            count = count_black(mat, H, W)
            if count == K
                ans += 1
            end
            reset(mat, init_mat, H, W)
        end
    end

    println(ans)
end
main(H, W, K)


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

int main() {
    int a, p;
    cin >> a >> p;

    int ans = floor((a*3 + p) / 2);

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ALL(obj) obj.begin(),obj.end()
#define pb(obj) push_back(obj)
#define REP(i,N) for(int i=0;i<N;i++)
typedef long long ll;
const ll MOD=1000000007;
int main(){
	cin.tie(0);
    ios::sync_with_stdio(false);
	ll L,R;
    cin>>L>>R;
    ll l,r;
    l=L%2019;
    r=R%2019;
    if(r<=l){cout<<0<<endl;exit(0);}
    else{
        if(R-L>2019){cout<<0<<endl;exit(0);}
        int sub=2018;
        for(int i=l;i<r;i++){
            for(int j=i+1;j<=r;j++){
                sub=min(sub,(i*j)%2019);
            }
        }
        cout<<sub<<endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<vector>
#include<queue>
#include<string>
#include<stack>
#include<algorithm>
#include<memory.h>
#include<set>
#include<map>
#include<cmath>
#include<iomanip>
using namespace std;
typedef long long ll;
#define se second
#define fi first
#define pb push_back
const int N = 1e6,M=1e9+7;
string s;
int f[N];
int main() { 
	
	cin >> s;
	for (int i = 0;i < s.size();i++) {
		f[s[i] - 'a']++;
	}
	string ans = "";
	if (s.size() < 26) {
		ans = s;
		for (int i = 0;i < 26;i++) {
			if (!f[i]) {
				ans += char(i + 'a');
				break;
			}
		}
		cout << ans << endl;
	}
	else {
		for (int i = s.size() - 1;i >= 0;i --) {
			char c = 'z';
			bool y = 0;
			for (int j = i + 1;j < s.size();j++) {
				if (s[j] > s[i]) {
					c = min(c, s[j]);
					y = 1;
				}
			}
			if (y) {
				for (int k = 0;k < i;k++)ans += s[k];
				ans += c;
				cout << ans << endl;
				return 0;
			}
		}
		cout << -1;
		return 0;

	}

}


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>

char wall[9][6],x,y,dir;

int check(int y,int x){
	if(y<0 || y>8 || x<0 || wall[y][x]!='1')return 0;
	else return 1;
}

int nextdir(){
	int i;
	for(i=1;i<4;i++){
		switch((dir+i)%4){
			case 0:
			if(check(y*2,x-1)==1){printf("L");x--;return 2;}
			break;
			case 1:
			if(check(y*2-1,x)==1){printf("U");y--;return 3;}
			break;
			case 2:
			if(check(y*2,x)==1){printf("R");x++;return 0;}
			break;
			case 3:
			if(check(y*2+1,x)==1){printf("D");y++;return 1;}
			break;
		}
	}
}

int main(void){
	for(y=0;y<9;y++)scanf("%s",wall[y]);
	x=0,y=0;dir=0;

	while(1){
		dir=nextdir();
		if(x==0 && y==0)break;
	}

	printf("\n");

	return 0;
}

Measured memory_bytes: 524
#include <iostream>
#include <stack>
#include <vector>

int main() {
    int n, q;
    std::cin >> n >> q;

    std::vector<std::stack<int>> stacks;
    stacks.resize(n);
    for (int i = 0; i < q; ++i) {
        int kind;
        std::cin >> kind;

        int t;
        switch (kind) {
            case 0:
                int x;
                std::cin >> t >> x;
                stacks[t].push(x);
                break;
            case 1:
                std::cin >> t;
                if (stacks[t].size() != 0)
                    std::cout << stacks[t].top() << std::endl;
                break;
            case 2:
                std::cin >> t;
                if (stacks[t].size() != 0) stacks[t].pop();
                break;
            default:
                std::cerr << "strange kind" << std::endl;
        }
    }
}


Measured memory_bytes: 4336
"""    Arnab Chanda    """

from collections import defaultdict, deque
from itertools import permutations
from sys import stdin,stdout
from bisect import bisect_left, bisect_right
from copy import deepcopy
import heapq

int_input=lambda : int(stdin.readline())
string_input=lambda : stdin.readline().split()
multi_int_input =lambda : map(int, stdin.readline().split())
multi_input = lambda : stdin.readline().split()
list_input=lambda : list(map(int,stdin.readline().split()))
string_list_input=lambda: list(string_input())
MOD = pow(10,9)+7

n = int_input()

map = {
    'AC':0,
    'WA':0,
    'TLE':0,
    'RE':0
}

for i in range(n):
    ver = input()

    map[ver] += 1

for k in map:
    print(k+" x "+str(map[k]))

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

using namespace std;

const int DIM = 2e5 + 7;

#define int long long

int c[DIM];

vector <int> v[DIM];

void dfs(int nod, int dad = 0)
{
	for(auto i : v[nod])
		if(i != dad)
		{
			c[i] += c[nod];
			dfs(i, nod);
		}
}

main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n, q;
	cin >> n >> q;
	
	for(int i = 1; i < n; i++)
	{
		int x, y;
		cin >> x >> y;
		
		v[x].push_back(y);
		v[y].push_back(x);
	}
	
	for(int i = 1; i <= q; i++)
	{
		int x, y;
		cin >> x >> y;
		
		c[x] += y;
	}
	
	dfs(1);
	
	for(int i = 1; i <= n; i++)
		cout << c[i] << ' ';
}

Measured memory_bytes: 24320
#include <bits/stdc++.h>
 
using namespace std;
 
#define f0r(a, b) for (long long a = 0; a < (b); a++)
#define f1r(a, b, c) for (long long a = (b); a < (c); a++)
#define f0rd(a, b) for (long long a = (b); a >= 0; a--)
#define f1rd(a, b, c) for (long long a = (b); a >= (c); a--)
#define ms(arr, v) memset(arr, v, sizeof(arr))
#define pb push_back
#define mp make_pair
#define f first
#define s second
using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vpl = vector<pll>;
 
void fio() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); 
  cout.tie(0);
}
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const long double pi = 3.14159265358979323846;



void solve() {
  ll n; cin >> n;

  ll mat[n][n];
  f0r(i, n) f0r(j, n) cin >> mat[i][j];

  ll v = n * (n - 1) / 2;
  pair<ll, pll> dists[v];
  ll c = 0;
  f0r(i, n) f0r(j, i) {
    dists[c++] = mp(mat[i][j], mp(i, j));
  }
  sort(dists, dists + v);

  ll ans = 0;
  f0r(i, v) {
    pair<ll, pll> k = dists[i];
    pll p = k.s;
    bool cur = 0;
    f0r(j, n) {
      if (j == p.f || j == p.s) continue;
      if (mat[p.f][j] + mat[j][p.s] < mat[p.f][p.s]) {
        cout << -1 << '\n';
        return;
      } else if (mat[p.f][j] + mat[j][p.s] == mat[p.f][p.s]) {
        cur = 1;
      }
    }
    if (!cur) ans += mat[p.f][p.s];
  }
  cout << ans << '\n';
}
 
int main() {
  fio();
  
  int T = 1;
  // cin >> T;
  while (T--) solve();
} 

Measured memory_bytes: 5416
#include <bits/stdc++.h>
#define INF 1e9
using namespace std;

bool chmin(int& a, int b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
int dp[50][500][500];
int main() {
    int N, Ma, Mb;
    cin >> N >> Ma >> Mb;
    vector<int> a(N), b(N), c(N);
    for (int i = 0; i < N; i++) {
        cin >> a[i] >> b[i] >> c[i];
    }

    for (int i = 0; i < 50; i++) {
        for (int j = 0; j < 500; j++) {
            for (int k = 0; k < 500; k++) {
                dp[i][j][k] = INF;
            }
        }
    }
    dp[0][0][0] = 0;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j <= 400; j++) {
            for (int k = 0; k <= 400; k++) {
                if (dp[i][j][k] == INF) continue;
                chmin(dp[i + 1][j + a[i]][k + b[i]], dp[i][j][k] + c[i]);
                chmin(dp[i + 1][j][k], dp[i][j][k]);
            }
        }
    }
    int ans = INF;
    for (int i = 0; i < 500; i++) {
        for (int j = 0; j < 500; j++) {
            if (double(Ma) / double(Mb) == double(i) / double(j) &&
                dp[N][i][j] != INF)
                chmin(ans, dp[N][i][j]);
        }
    }
    if (ans == INF) {
        cout << -1 << endl;
    } else {
        cout << ans << endl;
    }
}

Measured memory_bytes: 49152
parseint(x) = parse(Int, x)
readint() = readline() |> parseint
readstr() = readline() |> chomp
readstrlist(n) = [readstr() for _ = 1:n]

function encode(s)
    code::BigInt = 0
    for c in s
        code += BigInt(11) ^ (c - 'a')
    end
    code
end

c2(n) = (n*(n-1))>>1

function main()
    n = readint()
    s = readstrlist(n)
    s = encode.(s)
    sort!(s)
    append!(s, -1)
    ans = 0
    num = 1
    for i = 1:n
        if s[i] == s[i+1]
            num += 1
        else
            ans += c2(num)
            num = 1
        end
    end
    println(ans)
end

main()



Measured memory_bytes: 178168
#include <stdio.h>

int main(){
	int n, k[10001], i, a, o;
	scanf("%d", &n);
	while(n != 0){
		o = 0;
		a = n;
		for(i = 0; i < n; i++){
			scanf("%d", &k[i]);
			if(k[i] >= 2){
				o = 1;
			} else if(k[i] == 0){
				a--;
			}
		}
		a++;
		if(o == 1){
			printf("%d\n", a);
		} else {
			printf("NA\n");
		}
		scanf("%d", &n);
	}
	return 0;
}

Measured memory_bytes: 648
function main(input: string) {
  const s: string = input.split("\n")[0];
  let sum: number = 0;
  for (let start: number = 0; start < s.length; start += 1) {
    for (let end: number = start + 1; end <= s.length; end += 1) {
      const dist: number = start === 0 || s.length - end === 0 ? 1 : 2;
      const multi: number = Math.ceil(
        Math.pow(2, s.length - 2) / Math.pow(2, end - start - 1) / dist
      );
      sum += Number(s.slice(start, end)) * multi;
    }
  }
  console.log(sum);
}

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


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

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




Measured memory_bytes: 3092
N, A, B = map(int, input().split())

ans = 0

if A > B:
    pass
elif A == B:
    ans = 1
else:
    if N == 1:
        pass
    else:
        ans = B * (N - 1) + A - (A * (N - 1) + B) + 1

print(ans)


Measured memory_bytes: 2940
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cassert>
#define iter(c) __typeof__((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();++i)
using namespace std;


/*
int existe(long  key,vector<long>& vec){
  int cnt = 0;
  foreach(i,vec){
    if(*i == key){
      return cnt;
    }
    cnt++;
  }
  return -1;
}
*/

int main(){
  int N,M;
  vector<int> vec;
  map<int,bool> exist;
  exist.clear(),vec.clear();

  cin >> N >> M;
  
  for(int j=0;j<N;j++){
    int job;
    cin >> job;
  
   if(exist[job]){
     foreach(i,vec){
     	if((*i) == job){
	  vec.erase(i);
     	  vec.push_back(job);
     	  break;
     	}
     }
      
    }
    else if(vec.size() < M){
      exist[job] = true;  
      vec.push_back(job);
    }
    else if(vec.size() >= M){      
      //cout << "vec = " << *vec.begin() << endl;
      exist[*vec.begin()] = false;
      vec.erase(vec.begin());
      vec.push_back(job);
      exist[job] = true;
    }
    else {
    }
  }
 
  //assert(vec.size() <= M);
  //cout << vec.size() << endl;
  for(int i=(int)vec.size()-1;i>=0;i--){
    cout << *(vec.begin()+i) << endl;
  }


  return 0;
}

Measured memory_bytes: 5880
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;
int main(){
	ios::sync_with_stdio(false);
	int n;
	while(scanf("%d",&n)!=EOF)
	{
		int i,j,sum,count=0;
		for(i=n;i>=1;i--)
		{
			if(i%2==0)
			    continue;
			sum=0;
			for(j=1;j<=i;j++)
			{
		    	if(i%j==0)
		        	sum++;
			}
	    	if(sum/2==4)
	    	{
		       count++;
			}
		}
		printf("%d\n",count);
	}
	return 0;
}


Measured memory_bytes: 256
n,m=map(int,input().split())
s=set()
for i in range(1,int(m**0.5)+1):
    if m%i==0:
        s.add(i)
        s.add(m//i)
s=sorted(s,reverse=True)
for i in range(len(s)):
    if s[i]<n:
        print(m//s[i-1])
        break
else:print(m)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn = 100005;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n;
    cin >> n;
    int a = 0, b = 0, c = 0, d = 0;
    for(int i=1;i<=n;i++){
        string s;
        cin >> s;
        if(s[0] == 'A')a++;
        if(s[0] == 'W')b++;
        if(s[0] == 'T')c++;
        if(s[0] == 'R')d++;
    }
    cout << "AC x " << a << endl;
    cout << "WA x " << b << endl;
    cout << "TLE x " << c << endl;
    cout << "RE x " << d << endl;
    return 0;
}


Measured memory_bytes: 3604
from collections import defaultdict

N, M = map(int, input().split())

d = defaultdict(int)
for i in range(2, M+1):
    while M % i == 0:
        d[i] += 1
        M //= i
    if M == 1:
        break


def cmb(n, r, mod):
    if (r < 0 or r > n):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod


mod = 10**9+7  # 出力の制限
n = 100100
g1 = [1, 1]  # 元テーブル
g2 = [1, 1]  # 逆元テーブル
inverse = [0, 1]  # 逆元テーブル計算用テーブル

for i in range(2, n + 1):
    g1.append((g1[-1] * i) % mod)
    inverse.append((-inverse[mod % i] * (mod//i)) % mod)
    g2.append((g2[-1] * inverse[-1]) % mod)


ans = 1
for v in d.values():
    # print(v, cmb(v+N, N, mod))
    ans *= cmb(v+N-1, N-1, mod)

print(ans % mod)


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

signed
main(){
		int m;
		cin >> m;
		
		for(int i=0;i<m;i++){
				string s;
				cin >> s;
				int ans = 0;
				map<string,int> exist;
				for(int j=1;j<s.size();j++){
						//切ったsをspfi,spseに
						vector<string> spfi(2), spse(2);
						string fi = s.substr(0,j);
						string se = s.substr(j);
						spfi[0] = fi;
						reverse(fi.begin(), fi.end());
						spfi[1] = fi;
					    spse[0] = se;
						reverse(se.begin(), se.end());
						spse[1] = se;
						
						for(int a=0;a<2;a++){
								for(int b=0;b<2;b++){
										string  tmp  = spfi[a] + spse[b];
										string  tmp2  = spse[b] + spfi[a];
										exist[tmp] = 1;
										exist[tmp2] = 1;
								}
						}
				}
				
				cout << exist.size() << endl;
		}

}


Measured memory_bytes: 3300
#include<bits/stdc++.h>
using namespace std;
string to_string(const string& s) {
	return '"' + s + '"';
}
string to_string(const bool b) {
	return (b ? "true" : "false");
}
string to_string(const char* s) {
	return to_string((string)s);
}
string to_string(const char c) {
	string s = "'";
	s += c;
	s += "'";
	return s;
}
template<class T, class U>
string to_string(const pair<T, U>& p) {
	string s = "(";
	s += to_string(p.first);
	s += ", ";
	s += to_string(p.second);
	s += ")";
	return s;
}
template<class T>
string to_string(const T& a) {
	bool first = true;
	string s = "{";
	for (const auto& x : a) {
		if(!first){
			s += ", ";
		}
		first = false;
		s += to_string(x);
	}
	s += "}";
	return s;
}
void debug_out() {cerr << '\n';}
template<class Head, class... Tail>
void debug_out(Head head, Tail... tail) {
	cerr << ' ' << to_string(head);
	debug_out(tail...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "] = ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif
using ll = long long;
using ld = long double;
const int mod = 1e9 + 7;
const int inf = 1e9 + 100;
const ll inf64 = 7e18l;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(20);
	ll n, a, b;
	cin >> n >> a >> b;
	vector<ll> cnt(2);
	ll q = n / (a + b);
	ll rem = n % (a + b);
	cnt[0] = q * a;
	cnt[1] = q * b;
	ll p = min(rem, a);
	cnt[0] += p;
	rem -= p;
	cnt[1] += rem;
	cout << cnt[0] << '\n';
 	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

const int N = 502;

int n, k;
int arr[N];

bool check(int a)
{
  deque<int> v;
  for(int i = 0 ; i < n ; i++){
    int r = arr[i] % a;
    if(r){
      v.push_back(r);
    }
  }
  sort(rall(v));
  int cnt = 0;
  while(sz(v)){
    int x = v.front();
    int y = v.back();
    int z = a - x;
    if(z > y){
      v.front() += v.back();
      cnt += v.back();
      v.pop_back();
    }else{
      v.pop_front();
      v.back() -= z;
      cnt += z;
      if(!v.back())
        v.pop_back();
    }
  }
  // cout << a << " " << cnt << endl;
  return cnt <= k;
}

int main()
{
  while(cin >> n >> k){
    int sum = 0;
    for(int i = 0 ; i < n ; i++){
      cin >> arr[i];
      sum += arr[i];
    }
    int ans = 1;
    for(int cur = 1 ; cur * cur <= sum ; cur++){
      if(sum % cur == 0){
        if(check(cur) && cur > ans)
          ans = cur;
        int d = sum / cur;
        if(d != cur && check(d) && d > ans)
          ans = d;
      }
    }
    cout << ans << endl;
  }
  return 0;
}


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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define lcm(a, b) (a)/__gcd((a),(b))*(b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 200005;

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

vector<int> Div(int n) {
    vector<int> ret;
    for(int i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);

            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

void dfs(int now, int from);

vector<int> graph[SIZE];

int color[SIZE];
map<P, int> mp;

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

    int n;
    cin >> n;
    int m = n - 1;
    for(int i = 1; i <= n; ++i) {
        color[i] = -1;

    }

    while(m--) {
        int a, b, c;
        cin >> a >> b >> c;
        graph[a].pb(b);
        graph[b].pb(a);
        mp[MP(a, b)] = c;
    }

    dfs(1, -1);
    for(int i = 1; i <= n; ++i) {
        cout << color[i] << endl;

    }
    return 0;
}

void dfs(int now, int from) {
    if(color[now] != -1) {
        return;

    }
    if(from == -1) {
        color[now] = 0;

    } else {
        int a, b;
        a = now, b = from;
        if(a > b) swap(a, b);
        if(mp[MP(a, b)] % 2 == 0) {
            color[now] = color[from];

        } else {
            color[now] = (color[from] ^ 1) & 1;

        }

    }

    for(int i = 0; i < graph[now].size(); ++i) {
        dfs(graph[now][i], now);

    }

    return;
}


Measured memory_bytes: 18944
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		for(int i = 0; i < s.length(); i++) {
			if(s.indexOf(s.charAt(i), i+1) != -1) {
				System.out.print("no");
				break;
			}
			if(i == s.length()-1) {
				System.out.print("yes");
			}
		}
	}
}


Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define flash ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define lb lower_bound
#define ub upper_bound
#define endl '\n'
#define rep(n) for(ll j=1;j<=n;j++)
#define loope(i,a,b) for(ll i=a;i<=b;i++)
#define loopne(i,a,b) for(ll i=a;i<b;i++)
ll a[303]={0};
 ll n=0;
long double dp[305][305][305];
 ll visited[305][305][305]={0};
long double ex(ll a,ll b,ll c)
{
  if(a==0&&b==0&&c==0)
    return 0;
    if(visited[a][b][c]==1)
    return(dp[a][b][c]);
    long double ansx=0;
    long double ansy=0;
    long double ansz=0;
    if(a>0)
    ansx=a*ex(a-1,b,c)+a;
    if(b>0)
    ansy=b*ex(a+1,b-1,c)+b;
    if(c>0)
    ansz=c*ex(a,b+1,c-1)+c;
    dp[a][b][c]=(ansx+ansy+ansz+n-a-b-c)/(a+b+c);
    visited[a][b][c]=1;
    return(dp[a][b][c]);
}
int main()
{
    ll c1=0,c2=0,c3=0;
    flash
    cin>>n;
    rep(n)
    {
        ll x;
        cin>>x;
        a[j]=x;
        if(x==1)
        c1++;
        if(x==2)
        c2++;
        if(x==3)
        c3++;
    }
  
    cout<<fixed<<setprecision(9)<<ex(c1,c2,c3);
  return 0;
    
}

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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
typedef long long ll;
const int INT_INF = 1e9;
const ll INF = 1LL << 30;
const ll MOD = 1e9 + 7;


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

    map<ll, ll> m;
    for(int i = 1; i <= n; i++){
        m[i % k]++;
    }

    ll r = k / 2;
    if(k % 2 == 0) cout << m[0] * m[0] * m[0] + m[r] * m[r] * m[r] << endl;
    else cout << m[0] * m[0] * m[0] << endl;
}


Measured memory_bytes: 6528
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for(ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) begin(x), end(x)
using namespace std;
using ll = long long;
constexpr ll Mod = 998244353;
constexpr ll mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;
const double PI = acos(-1);
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
    return a < b && (a = b, true);
}
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
    return a > b && (a = b, true);
}
/*-------------------------------------------*/

#include <atcoder/dsu>
using namespace atcoder;

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

    int n, q;
    cin >> n >> q;
    dsu d(n);
    while(q--) {
        int t, u, v;
        cin >> t >> u >> v;
        if(t == 0)
            d.merge(u, v);
        else
            cout << d.same(u, v) << "\n";
    }

    return 0;
}

Measured memory_bytes: 3956
s=input()
ans="AC"
if s[0]!='A' or s[-1]=='C' or s[1]<'a':ans="WA"
else:
    count=0
    for i in range(2,len(s)):
        if s[i]<'a':
            if s[i]=='C':count+=1
            else:count+=2
    if count!=1:ans="WA"
print(ans)


Measured memory_bytes: 61752
import sys
A,B = map(int,input().split())
S = input()
S = [c for c in S]
for i in range(A+B+1):
    if i == A:
        if S[i] != '-':
            print('No')
            sys.exit()
    else:
        if S[i] == '-':
            print('No')
            sys.exit()
print('Yes')

Measured memory_bytes: 3060
import sys

def solve(n, w):
    w_all = sum(w)
    diff_pre = w_all
    s = 0
    for i in range(n-1):
        s += w[i]
        diff = abs(w_all - 2*s)
        if diff_pre <= diff:
            return diff_pre
        diff_pre = diff
    return diff_pre


if __name__ == '__main__':

    n = sys.stdin.readline().strip()
    w = map(int, sys.stdin.readline().strip().split(" "))
    print solve(int(n), w)

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

int main()
{
    int n;
    cin>>n;
    int ans=0;
    while(n--){
        int l,r;
        cin>>l>>r;
        ans+=r-l+1;
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
#define rer(i, a, b) for(ll i = ll(a) - 1; i >= ll(b); i--)
#define sz(v) (int)(v).size()
#define pb push_back
#define sc second
#define fr first
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
using namespace std;
typedef long long int ll;
typedef pair <int, int> P;

const ll MOD=1000000007;
int d[5];
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    rep(i,0,3){
        int a,b;
        cin>>a>>b;
        d[a]++;
        d[b]++;
    }
    rep(i,1,5){
        if(d[i]==3){
            cout <<"NO"<<"\n";
            return 0;
        }
    }
    cout <<"YES"<<"\n";
}

Measured memory_bytes: 256
#include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>

using namespace std;

int main(){
	int dp[10000];
	int n;
	dp[0]=1;
	dp[1]=1;
	cin >> n;
	for(int i=2;i<=n;i++){
		dp[i] = dp[i-1]+dp[i-2];
	}
	cout << dp[n] << endl;
	return 0;
}

Measured memory_bytes: 1168
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
using namespace std;

typedef istringstream ISS;
typedef ostringstream OSS;
typedef vector<string> VS;
typedef int INT;
typedef vector<INT> VI;
typedef vector<VI> VVI;
typedef pair <INT, INT> II;
typedef vector <II> VII;

template<class T> ostream& operator << ( ostream& os, vector<T> v ) {
    for ( typename vector<T>::iterator it_i = v.begin(); it_i != v.end(); ++it_i ) {
        os << *it_i << ", ";
    }
    return os;
}


int n, m, p;
int X[101];

int solve() {
    int sum = accumulate( X, X+n, 0 ) * 100;
    if ( p ) sum -= sum * p / 100.0;
    return !X[m] ? 0 : sum / X[m];
}

int main() {
    while ( cin >> n >> m >> p ) {
        if ( n == 0 && m == 0 && p == 0 ) break;
        m --;
        for ( int i = 0; i < n; ++ i ) {
            cin >> X[i];
        }
        cout << solve() << endl;
    }
    return 0;
}

Measured memory_bytes: 0
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cassert>
#include <vector>
#include <map>
using namespace std;

typedef pair <long long, long long> pii;

const long long MAX_N = 2e5 + 10;
long long n, ans;
long long Arr[MAX_N];

int main() {
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n;
	for (long long i = 0; i < n; i++)
		cin >> Arr[i];

	if (Arr[0]) {
		cout << "-1\n";
		return 0;
	}

	for (int i = 1; i < n; i++)
		if (Arr[i - 1] + 1 < Arr[i]) {
			cout << "-1\n";
			return 0;
		}

	long long tmp = 0;
	for (long long i = 1; i < n; i++) {
		tmp++;

		if (Arr[i] == 0) {
			tmp = 0;
			continue;
		}
		if (Arr[i] == 1) {
			ans++;
			tmp = 1;
			continue;
		}

		if (Arr[i] == tmp) {
			ans++;
			continue;
		}

		tmp = Arr[i];
		ans += Arr[i];
	}

	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 1920
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll N=2e5+1e3;

ll read()
{
	ll s=0;
	char c=getchar(),lc='+';
	while (c<'0'||'9'<c) lc=c,c=getchar();
	while ('0'<=c&&c<='9') s=s*10+c-'0',c=getchar();
	return lc=='-'?-s:s;
}
void write(ll x)
{
	if (x<0)
	{
		putchar('-');
		x=-x;
	}
	if (x<10) putchar(x+'0');
	else
	{
		write(x/10);
		putchar(x%10+'0');
	}
}
void print(ll x,char c='\n')
{
	write(x);
	putchar(c);
}
ll a[N];

int main()
{
	ll n=read(),k=read(),ans=0;
	for (ll i=1;i<=n;i++) a[i]=read();
	sort(a+1,a+1+n);
	for (ll i=1;i<=n-k;i++) ans+=a[i];
	print(ans);

	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
using ll = long long;
using namespace std;

ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }
//sort(a, a + N, greater<ll>())   // descend
//sort(a, a+N)                    //  ascend

/**
void comb(vector<vector <ll> > &v) {
	rep (i,0,v.size()) {
		v[i][0] = 1;
		v[i][i] = 1;
	}
	rep (k,1,v.size()) {
		rep (j,1,k) {
			v[k][j] = (v[k - 1][j - 1] + v[k - 1][j]);
		}
	}
}
/*main内でnCn~nC0 生成 **
vector<vector<ll> > v(n + 1, vector<ll>(n + 1, 0));
comb(v);
*/

int main() {
    int n,d;
    cin >> n >> d;
    int x[n][d];
    for(int i=0; i<n; i++){
        for(int j=0; j<d; j++){
            cin >> x[i][j];
        }
    }
    int cnt=0;

    for(int i=0; i<n-1; i++){
        for(int j=i+1; j<n; j++){
            long double ans = 0.0;
            for(int l=0; l<d; l++){
                ans += pow(abs(x[i][l]-x[j][l]),2);

            }
    
            ans = sqrt(ans);
            ll ians = ans;
            if(!(ans-ians)){
                cnt++;
            }
       
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
/*問題文
今、日本は 9 月 9 日です。 二桁の整数 N が与えられるので、十進法で N に 9 が含まれるか答えてください。

制約
10≦N≦99
入力
入力は以下の形式で標準入力から与えられる。

N
出力
9 が含まれるとき Yes 、含まれないとき No を出力せよ。
*/

#include <stdio.h>
//#include <stdlib.h>


int main(){
  int N;

  scanf("%d", &N);
  if(N%10 == 9 ||N / 10 == 9 ){
    printf("Yes");
  }else
  {
    printf("No");
    }

  return 0;
}


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

int main() {

    int N , K;
    string S;
    cin >> N >> K;
    cin >> S;

    switch(S[K-1]){
        case 'A': S[K-1] = 'a';
            break;
        case 'B': S[K-1] = 'b';
            break;
        case 'C': S[K-1] = 'c';
            break;
    }

    cout << S << endl;

}

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

using namespace std;

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

	int tmp = min(a, k);
	int ans = tmp;
	k -= tmp;
	tmp = min(b, k);
	k -= tmp;
	tmp = min(c, k);
	ans -= tmp;

	printf("%d\n", ans);

}


Measured memory_bytes: 3728
#include<iostream>
#include<string>
using namespace std;
string S; int n;
bool solve(int p) {
	int II = 0, OO = 0, RR = 0;
	for (int i = n - 1; i >= 0; i--) {
		if (S[i] == 'I' && II < p)II++;
		else if (S[i] == 'O' && II > OO && OO < p)OO++;
		else if (RR < OO && S[i] != 'O') RR++;
	}
	if (RR == p)return true;
	return false;
}
int main() {
	cin >> n >> S;
	int L = 0, R = n, M;
	while (true) {
		M = (L + R) / 2; bool p1 = solve(M), p2 = solve(M + 1);
		if (p1 == true && p2 == false) { cout << M << endl; break; }
		if (p1 == false)R = M; if (p2 == true)L = M;
	}
	return 0;
}

Measured memory_bytes: 3904
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define all(v) begin(v), end(v)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000
#define int long long int

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};
int const MOD = 1000000007;
ll mod_pow(ll x, ll n) {return (!n)?1:(mod_pow((x*x)%MOD,n/2)*((n&1)?x:1))%MOD;}
int madd(int a, int b) {return (a + b) % MOD;}
int msub(int a, int b) {return (a - b + MOD) % MOD;}
int mmul(int a, int b) {return (a * b) % MOD;}
int minv(int a) {return mod_pow(a, MOD-2);}
int mdiv(int a, int b) {return mmul(a, minv(b));}

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

struct Elem {
    string l;
    int p, a, b, c, d, e, f, s, m;
    double inc;
    void calc() {
        int tm = a + b + c + m * (d + e);
        int sum = s * m * f;
        inc = (double)(sum - p) / tm;
    }
};

bool operator>(const Elem &a, const Elem &b) {
    return a.inc != b.inc ? a.inc > b.inc : a.l < b.l;
}

signed main() {
    int n;
    while(cin >> n, n) {
        vector<Elem> vs(n);
        rep(i,0,n) {
            cin >> vs[i].l >> vs[i].p >> vs[i].a >> vs[i].b;
            cin >> vs[i].c >> vs[i].d >> vs[i].e;
            cin >> vs[i].f >> vs[i].s >> vs[i].m;
            vs[i].calc();
        }
        sort(vs.begin(), vs.end(), greater<Elem>());
        rep(i,0,n) cout << vs[i].l << endl;
        printf("#\n");
    }
    return 0;
}

Measured memory_bytes: 3172
#include<iostream>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
using ll = long long;
using P = pair<int, int>;
#include<algorithm>
#include<math.h>
#include<map>
#include<queue>
#include<string>

int main() {
	int a;
	string s;
	cin >> a >> s;
	if (a >= 3200) {
		cout << s;
	}
	else {
		cout << "red";
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}
int H,W,A,B;
char s[1010][1010];
int main(){
	cin>>H>>W>>A>>B;
	rep(i,H) rep(j,W) s[i][j] = '.';
	rep(i,H) rep(j,W/2){
		s[i][j*2] = '<';
		s[i][j*2+1] = '>';
		A--;
	}
	if(W%2==1){
		rep(i,H/2){
			s[i*2][W-1] = '^';
			s[i*2+1][W-1] = 'v';
			B--;
		}
	}
	if(A>0){
		puts("NO");
		return 0;
	}
	if(B<=0) goto done;

	rep(i,H/2) rep(j,W/2){
		s[i*2][j*2] = '^';
		s[i*2][j*2+1] = '^';
		s[i*2+1][j*2] = 'v';
		s[i*2+1][j*2+1] = 'v';
		A += 2;
		B -= 2;
		if(B<=0){
			if(B==-1 && A==1 && H%2==1 && W%2==1 && H>1 && W>1){
				s[i*2][j*2] = '<';
				s[i*2][j*2+1] = '>';
				s[i*2+1][j*2] = '<';
				s[i*2+1][j*2+1] = '>';
				A -= 2;
				B += 2;
				s[H-2][W-3] = '^';
				s[H-2][W-2] = '.';
				s[H-1][W-3] = 'v';
				s[H-1][W-2] = '<';
				s[H-1][W-1] = '>';
				A++;
				B--;
			}
			goto done;
		}
	}

	done:


	if(A>0 || B>0){
		puts("NO");
		return 0;
	}

	rep(i,H) rep(j,W){
		if(s[i][j]=='<' && A<0){
			A++;
			s[i][j] = s[i][j+1] = '.';
		}
		if(s[i][j]=='^' && B<0){
			B++;
			s[i][j] = s[i+1][j] = '.';
		}
	}
	puts("YES");
	rep(i,H){
		rep(j,W) cout<<s[i][j];
		puts("");
	}
}


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

#define ld			long double
#define int         long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define MOD         1000000007
#define sd(t) 		scanf("%d",&(t))
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define hii 		cout << "hii" << endl
#define okay 		cout << "okay" << endl
#define hey 		cout << "hey" << endl

template <class T> ostream& operator << (ostream &os, const vector<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T> ostream& operator << (ostream &os, const set<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T, class S> ostream& operator << (ostream &os, const pair<T, S> &v) { os << v.first << ' ' << v.second; return os; }
template <class T, class S> ostream& operator << (ostream &os, const unordered_map<T, S> &v) { for (auto i : v) os << '(' << i.first << "=>" << i.second << ')' << ' '; return os; } 
 
 
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <class Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << endl; }
    template <class Arg1, class... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args) {
        const char* sep = strchr(names + 1, ',');
        cerr.write(names, sep - names) << " : " << arg1 << "  ";
        __f(sep + 1, args...);
    }
#else
#define trace(...) 0
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#endif // ifndef ONLINE_JUDGE

void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

clock_t time_p=clock();
void starboy1299()
{
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}

const int N = 3e5+5;
int arr[N];
int dp[N];
int n;
int f(int idx){
	if(idx==n-1){
		return 0;
	}

	if(idx >= n) return 1e10;
	if(dp[idx]!=-1) return dp[idx];
	int ans = 1e10;

	if(idx+1 < n){
		ans = min(ans, abs(arr[idx+1]-arr[idx]) + f(idx+1));
	}

	if(idx+2 < n){
		ans = min(ans, abs(arr[idx+2]-arr[idx]) + f(idx+2));
	}

	return dp[idx] = ans;
}

void solve()
{
	// int n;
	cin >> n;
	memset(dp, -1, sizeof(dp));
	rep(i, 0, n) cin >> arr[i];

	cout << f(0) << endl;
}			 

int32_t main(){
	fast();
    int t = 1;
    // cin>> t;
    while(t--){
    	solve();
    }
	starboy1299();
}




Measured memory_bytes: 7424
use proconio::input;

fn main() {
    input! {
        n: String,
    }
    let mut s = n.chars().rev();
    match s.next(){
        Some(x) => {
            match x.to_digit(10).unwrap() {
                2|4|5|7|9 => println!("hon"),
                0|1|6|8 => println!("pon"),
                _ => println!("bon")
            }
        }
        None => {},
    }
}


Measured memory_bytes: 2052
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
 
int main()
{
    int i, n;
    short a[101];
 
    scanf("%d", &n);
    for (i = 0; i < n; i++) scanf("%d", &a[i]);
    if (n >= 1) printf("%d", a[n - 1]);
    for (i = n - 2; i >= 0; i--) printf(" %d", a[i]);
    putchar('\n');
    return 0;
}


Measured memory_bytes: 2104
#include <bits/stdc++.h>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)
#define ALL(x)      begin(x),end(x)

using namespace std;
using vecint = vector<int>;
using ll = int64_t;

int main()
{
  int a,b,c;
  cin>>a>>b>>c;
  int sub=a-b;
  cout<<max(0, c-sub)<<endl;
  return 0;
}


Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let mut s = read::<String>().chars().collect::<Vec<_>>();
    let mut t = read::<String>().chars().collect::<Vec<_>>();
    s.sort();
    t.sort();
    t.reverse();
    if s < t {
        println!("Yes");
    } else {
        println!("No");
    }
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 4352
h, w = map(int, input().split())
data = [list(input()) for _ in range(h)]

cnt_l, cnt_r, cnt_u, cnt_d = [[0] * w for _ in range(h)], [[0] * w for _ in range(h)], [[0] * w for _ in range(h)], [[0] * w for _ in range(h)]

for i in range(h):
    for j in range(w):
        if data[i][j] == "#":
            cnt_l[i][j] = 0
        else:
            cnt_l[i][j] = cnt_l[i][j - 1] + 1
    
        if data[i][w - j - 1] == "#":
            cnt_r[i][w - j - 1] = 0
        else:
            if j == 0:
                cnt_r[i][w - j - 1] = 1
            else:
                cnt_r[i][w - j - 1] = cnt_r[i][w - j] + 1

for j in range(w):
    for i in range(h):
        if data[i][j] == "#":
            cnt_u[i][j] = 0
        else:
            cnt_u[i][j] = cnt_u[i - 1][j] + 1

        if data[h - i - 1][j] == "#":
            cnt_d[h - i - 1][j] = 0
        else:
            if i == 0:
                cnt_d[h - i - 1][j] = 1
            else:
                cnt_d[h - i - 1][j] = cnt_d[h - i][j] + 1

ans = 0
for i in range(h):
    for j in range(w):
        total= cnt_l[i][j] + cnt_r[i][j] + cnt_u[i][j] + cnt_d[i][j] - 3
        ans = max(ans, total)

print(ans)

Measured memory_bytes: 359420