akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
using namespace std; using ll = long long; using ld = long double;  using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
const ld PI = 3.1415926535897932;
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define rep1(n) for(ll i=0;i<n;++i)
#define rep2(i,n) for(ll i=0;i<n;++i)
#define rep3(i,a,b) for(ll i=a;i<b;++i)
#define rep4(i,a,b,c) for(ll i=a;i<b;i+=c)
#define rep(...) overload4(__VA_ARGS__,rep4,rep3,rep2,rep1)(__VA_ARGS__)
#define mp make_pair
#define mt make_tuple
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define ULL(...) ull __VA_ARGS__;in(__VA_ARGS__)
#define STR(...) string __VA_ARGS__;in(__VA_ARGS__)
#define CHR(...) char __VA_ARGS__;in(__VA_ARGS__)
#define DBL(...) double __VA_ARGS__;in(__VA_ARGS__)
#define LD(...) ld __VA_ARGS__;in(__VA_ARGS__)
void in() {}
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail>
void debug_out(Head h, Tail... t) {
	cerr << " " << h;
	if (sizeof...(t) > 0) cerr << " :";
	debug_out(t...);
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> vec) {
	for (size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	return os;
}
ll ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.first > secondElof.first;
}
//**Snippetリスト**//
//rep, vin, all, iteLoop//
//bitSearch, bitList, nod, gcdlcm, isPrime, primeFactorize, Npow, divisor, modinv, dfs, bfs, eratos//
//dijkstra, WarshallFloyd, BellmanFord, UnionFind, COM, digitDP ,RMQ//
ll i, j, k, l; ll N, M, K, H, W, L, X, Y, Z, R, Q;
ll MOD = 1000000007; ll INF = 1LL << 62; ll ans = 0; ll z = 0, o = 1;
vl flag, color, D; vll path;
//***********//
vl bitList(ll n, ll k, ll f) {
	vl bitList(k);
	for (ll i = 0; i < k; i++) {
		bitList[i] = f % n;
		f /= n;
	}
	return bitList;
}
int main() {
	cin >> N >> M >> X;
	vl C(N);
	vll A(N, vl(M, 0));
	for (i = 0; i < N; i++) {
		cin >> C[i];
		for (j = 0; j < M; j++) {
			cin >> A[i][j];
		}
	}
	ans = INF;
	for (k = 0; k < pow(2,N); k++) {
		vl P = bitList(2, N, k);
		ll pre = 0;
		vl Q(M);
		for (i = 0; i < N; i++) {
			if (P[i]) {
				pre += C[i];
				for (j = 0; j < M; j++) {
					Q[j] += A[i][j];
				}
			}
		}
		ll valid = 1;
		for (i = 0; i < M; i++) {
			if (Q[i] < X) {
				valid = 0;
			}
		}
		if (valid) ans = min(ans, pre);
	}
	if (ans == INF) cout << -1;
	else cout << ans;
}

Measured memory_bytes: 4112
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> lpair;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    string S;
    cin >> S;
    ll ans = 1;
    rep(i,0,N-1){
        if(S[i] != S[i+1]) ans++;
    }
    print(ans);



}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main(){
    int a, b, c, d, e, zikan, hun, ans=0;
    cin >> a >> b >> c >> d >> e;
    zikan=c-a;
    hun=d-b;
    hun+=zikan*60;
    ans=hun-e;
    cout << ans <<endl;
    return 0;
}

Measured memory_bytes: 3636
/*
 Σf(x) = Σ(max(x)-min(x)) = Σ max(x) - Σ min(x)
 まず入力をソートする
 N = 7, K = 4
 {1 , 2 , 3 , 4 , 4 , 5 , 6}
 ここで,5が最大値になる集合のパターンは
 5以下の数から集合を選んだ場合になる、そのパターンの数はcombination(5,3)
 最小の場合は、これをreverseでソートする.
 ※※※※※※ combination=nCk ※※※※※※
 これはライブラリを使う。
*/

#include <algorithm>
#include <cassert>
#include <iostream>
#include <vector>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x;  // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod - 2); }
  mint& operator/=(const mint a) { return (*this) *= a.inv(); }
  mint operator/(const mint a) const {
    mint res(*this);
    return res /= a;
  }
};

// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
  vector<mint> fact, ifact;
  combination(int n) : fact(n + 1), ifact(n + 1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n] * ifact[k] * ifact[n - k];
  }
};

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  REP(i, N) cin >> A[i];

  sort(all(A));
  combination c(N + 5);

  mint maxSum = 0, minSum = 0;
  REP(i, N) { maxSum += c(i, K - 1) * A[i]; }
  reverse(all(A));
  REP(i, N) { minSum += c(i, K - 1) * A[i]; }

  mint ans = maxSum - minSum;
  cout << ans.x << endl;
  return 0;
}

Measured memory_bytes: 2176
#include<stdio.h>
int main(){
	int W,H,x,y,r;
	scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
	if(0<=x&&0<=y&&0<=x+r&&0<=y+r&&W>=x+r&&H>=y+r){
		printf("Yes\n");
	}else{
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 584
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sstream>
#include <iostream>
#include <math.h>
#include <time.h>
#include <unistd.h>
#include <algorithm>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <string>
 
#ifndef ONLINE_JUDGE
	#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#else
	#define DEBUG(x) do {} while(0);
#endif
 
#define pb push_back
#define mp make_pair
#define ALL(x) (x).begin(), (x).end()
#define PER(i, N) for(int (i) = (N)-1; (i) >= 0; (i)--)
#define REP(i, N) for(int (i) = 0; (i) < (int)(N); (i)++)
 
using namespace std;
typedef long long ll;
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }

template <typename T, typename U> std::istream&operator>>(std::istream&i, pair<T,U>&p) {i >> p.x >> p.y; return i;}
template<typename T>std::istream&operator>>(std::istream&i,vector<T>&t) {for(auto&v:t){i>>v;}return i;}
template <typename T, typename U> std::ostream&operator<<(std::ostream&o, const pair<T,U>&p) {o << p.x << ' ' << p.y; return o;}
template<typename T>std::ostream&operator<<(std::ostream&o,const vector<T>&t) {if(t.empty())o<<'\n';for(size_t i=0;i<t.size();++i){o<<t[i]<<" \n"[i == t.size()-1];}return o;}
template<typename T> using minheap = priority_queue<T, vector<T>, greater<T>>;
template<typename T> using maxheap = priority_queue<T, vector<T>, less<T>>;
template<typename T> T gcd(T a,T b) { if (a<b) swap(a,b); return b?gcd(b,a%b):a; }

ll n,k;

bool islunlun(ll num) {
	stringstream ss;
	ss << num;
	string S = ss.str();
	REP(i, S.size()-1) {
		if(abs(S[i]-S[i+1]) > 1)
			return false;
	}
	return true;
}
vector<ll> all;
void gen(ll n) {
	if(n > 3234566667LL)
		return;
	all.pb(n);
	int last = n%10;
	if(last > 0)
		gen(n*10+last-1);
	gen(n*10+last);
	if(last < 9)
		gen(n*10+last+1);
}

void solve(istream& cin, ostream& cout) {
	cin >> k;
	ll X = 1;
	int c = 1;
	REP(start, 9)
		gen(start+1);
	sort(ALL(all));
	cout << all[k-1]<< endl;
//	cout << X << endl;
}


int main() {
    ios_base::sync_with_stdio(false);
	cin.tie(nullptr); cout.tie(nullptr);
	solve(cin, cout);
	/*
	{
		istringstream instr("2\n2\n14");
		solve(instr, cout);
	}
 */
	return 0;
}


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

int main(){
    int N;
    double a; string b;
    vector<double> x[N-1];
    vector<string> u[N-1];
    double sum=0;
    
    cin >> N;
    for (int i=0;i < N;i++){
        cin >> a >> b;
        if (b=="JPY"){
        sum+=double(a);
        }else{
        sum+=double(a)*380000.0;
        }   
        
    }

    cout << sum << endl;
    
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define pb push_back
#define lli long long int
#define MAX 1e16


using namespace std;






int main() {
    
    lli n,m,temp;
    cin>>n;
    bool ans = true;
    map<lli,lli> m1,m2;
    
    for(int i=0;i<n;i++){
        cin>>temp;
        m1[temp]++;
    }
    
    cin>>m;
    
    for(int i=0;i<m;i++){
        cin>>temp;
        if(m1[temp]!=0){
            m1[temp]--;
        }else{
            ans = false;
        }
    }
    
    
    if(ans)
        cout<<"YES"<<endl;
    else
        cout<<"NO"<<endl;
	
}


Measured memory_bytes: 12800
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long

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

    ll n,k;
    cin>>n>>k;
    ll rem = n%k;
    cout<< min(rem,k-rem) << "\n";

    return 0;
}

Measured memory_bytes: 3596
#define _USE_MATH_DEFINES 
#include <iomanip> 
#include <cmath>  
#include<iostream>
#include <fstream>
#include<vector>
#include<algorithm>
#include<bitset>
#include<map>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define repi(i,a,b) for(ll i = (ll)(a) ; i < (ll)(b) ; i++)
#define repd(i,a,b) for(ll i = (ll)(a) ; i > (ll)(b) ; i--)
#define rd(x) cin >> x
#define wr(x)  cout << x
#define wrln(x) cout << x << endl


int main() {
	int a, b, c, t;
	cin >> a >> b >> c;
	t = a * 100 + b * 10 + c;
	if (t % 4 == 0)wrln("YES");
	else wrln("NO");
	return 0;
}

Measured memory_bytes: 256
open System

// prelude
let readStr () = stdin.ReadLine()

let read f () = readStr() |> f
let reads f () = readStr().Split() |> Array.map f

let pair = function
| [|a; b|] -> (a, b)
| _ -> failwith "owatta"

let triple = function
| [|a; b; c|] -> (a, b, c)
| _ -> failwith "owatta"

let readPair f g () =
  let (a,b) = readStr().Split() |> pair
  (f a, g b)

let readTriple f g h () =
  let (a,b,c) = readStr().Split() |> triple
  (f a, g b, h c)

let inc n = n + 1
let dec n = n - 1

let inline flip f a b = f b a
let rec fix f = fun x -> (f (fix f)) x

module Option =
  let getOr defaultValue = function
  | Some x -> x
  | None -> defaultValue

module Array =
  let modify (arr: _ []) i f =
    arr.[i] <- f arr.[i]

module Array2D =
  let modify (arr: _ [,]) i j f =
    arr.[i, j] <- f arr.[i, j]

// start
let N = read int ()
let A = reads int ()

A
|> Array.sort
|> Array.fold (fun st x ->
  match st with
  | (y,c)::l -> if y=x then (y,c+1)::l else (x,1)::(y,c)::l
  | [] -> [(x,1)]
) []
|> List.map (snd >> (fun n -> ((n-1)%2)+1))
|> List.fold (fun (n,m) x -> if x=1 then (n,m+1) else (n+1,m)) (0,0)
|> fun (n,m) -> m + (n/2)*2
|> printfn "%A" 


Measured memory_bytes: 30416
#include <bits/stdc++.h>
#define rep(i, n) for (lli i = 0; i < (n); i++)
#define rrep(i, n) for (lli i = (n)-1; i >= 0; i--)
using namespace std;
using lli = long long int;
int main() {
    int n;
    cin >> n;
    vector<string> s(n);
    rep(i,n)cin >> s[i];
    int ans = 0;
    int count[4] = {};
    rep(i,n){
        rep(j,s[i].size() - 1){
            if(s[i][j] == 'A' && s[i][j+1] == 'B'){
                ans++;
            }
        }
        if(s[i][0] == 'B' && s[i][s[i].size()-1] == 'A')count[0]++;
        else if(s[i][0]=='B')count[1]++;
        else if(s[i][s[i].size()-1] == 'A')count[2]++;
        else count[3]++;
    }
    if(count[0]){
        ans += count[0]-1;
        if(count[1]){
            ans++;
            count[1] -= 1;
        }
        if(count[2]){
            ans++;
            count[2] -= 1;
        }
        ans += min(count[1],count[2]);
    }else {
        ans += min(count[1],count[2]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define int long long
#define fi first
#define se second
using namespace std;
typedef pair<int, int> P;

int n;
int a[51];

bool f(int m){
    int cnt = 0;
    rep(i, 0, n){
        int tmp = (a[i] + m + 1) / (n + 1);
        cnt += tmp;
    }
    // cout << cnt << endl;
    return cnt <= m;
}

signed main(){
    cin >> n;
    bool g = true;
    rep(i, 0, n){
        cin >> a[i];
        if(a[i] >= n) g = false;
    }
    if(g){
        cout << 0 << endl;
        return 0;
    }
    int ng = 0, ok = 5 * 1e17;

    rep(i, 0, 100){
        int mid = (ng + ok) / 2;
        // int mid = i;
        if(f(mid)){
            ok = mid; //o("ok " << mid);
        }else{
            ng = mid; //o("ng " << mid);
        }
    }
    int ans = ok;
    rep(i, max((int)1, ok - 1000000), ok){
        if(f(i)){
            ans = i; break;
        }
    }
    cout << ans << endl;
}



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

#define pb push_back
#define ll long long
#define maxn 100005
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define ms(i) memset(i,0,sizeof(i));
#define ms1(i) memset(i,-1,sizeof(i));
#define F first
#define S second
const int mod = 1e9+7;
ll pm(int x){
    ll p = mod - 2;
    ll now = x;
    ll ret = 1;
    while(p){
        if(p&1){
            ret *= now;
            ret %= mod;
        }
        now *= now;
        now %= mod;
        p >>= 1;
    }
    return ret;
}
ll C(int x,int k){
    ll pre[x+5] = {};
    pre[0] = 1;
    f1(x){
        pre[i] = pre[i-1] * i % mod;
    }
    ll ret = pre[x] * pm(pre[k]) % mod * pm(pre[x-k]) % mod;
    return ret;
}
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
    int x, y;
    cin >> x >> y;
    int tx = -1 , ty = -1;
    f(x/2+1){
        int lx = x - i * 2;
        int ly = y - i;
        if(ly == lx * 2){
            tx = i;
            ty = lx;
            break;
        }
    }
    if(tx == -1){
        cout << 0 << endl;
        exit(0);
    }
    cout << C(tx+ty,tx) << endl;
}


Measured memory_bytes: 5504
#include <stdio.h>

int main(void) {
  int a,b;
  scanf("%d%d",&a,&b);
  if(a<=12 && 6<=a) {
    printf("%d\n",b/2);
  }else if(a<6){
    printf("0\n");
  }else{
    printf("%d\n",b);
  }
  return 0;
}

Measured memory_bytes: 128
// https://atcoder.jp/contests/abc090/tasks/abc090_b

#include <bits/stdc++.h>
#define REP(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define REPR(i, n) for (int(i) = (n); (i) >= 0; (i)--)
#define FOR(i, m, n) for (int(i) = (m); (i) < (n); i++)
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;

int main()
{
  /* Magic word */
  // cin.tie(0);
  // ios::sync_with_stdio(false);
  /* ---------- */

  int a, b;

  cin >> a >> b;

  int cnt = 0;
  FOR(i, a, b + 1)
  {
    string s = to_string(i);
    if (s[0] == s[4] && s[1] == s[3])
      cnt++;
  }

  cout << cnt << '\n';

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int a,b,c;

int main(void){
	register int i;
	scanf("%d%d%d",&a,&b,&c);
	for(i=1;i<b;i++)
		if(a*i%b==c)
			return puts("YES"),0;
	puts("NO");
	return 0;
}

Measured memory_bytes: 128
#include<stdio.h>

void gcd(int,int);

int main (){

  int n,m;
  scanf("%d %d",&n,&m);
  gcd(n,m);
  
  
}
void gcd(int n,int m){
  int v = n<m ? n:m;
  int r;
  while(m > 0){
    r = n%m;
    n = m;
    m = r;
  }
  printf("%d\n",n);
 
}



Measured memory_bytes: 2044
/// >>In The Name Of God
/// >>ALIREZANA

#include <bits/stdc++.h>
#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define sz(x) (int)(x).size()
#define smin(x,y) (x) = min(x,y)
#define smax(x,y) (x) = max(x,y)
#define all(x) (x).begin(),(x).end()
#define _ ios_base::sync_with_stdio(0)\
                ,cin.tie(0),cout.tie(0);

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;

int main()
{_
  int a, b;
  cin >> a >> b;
  if(a < b)
    cout << 0;
  else
    cout << 10;
  return 0;
}


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

typedef long long ll;

const int MOD = 1000000007;
int D[1000010];
ll S[1000010];

int main() {
  int n; scanf("%d", &n);
  D[0] = 1; D[1] = n;
  S[0] = 1; S[1] = n + 1;
  for(int i=2;i<=n;i++){
    D[i] = ((ll)(n-1) * (i-2) + (ll)(n - i + 1) * n + D[i-1] + (i>=3?S[i-3]:0)) % MOD;
    S[i] = (S[i-1] + D[i]) % MOD;
  }
  printf("%d\n", D[n]);
  return 0;
}


Measured memory_bytes: 11904
n = int(input())
v = list(map(int, input().split()))

v1 = list(sorted(v))
v2 = list(reversed(v1))
k = 0

for i in range(n):
  k += v2[i] * (2 ** ( -i - 1))

k += v2[n - 1] * (2 ** ( -n)) 

print(k)

Measured memory_bytes: 3060
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    n,m = LI()
    if n == 1:
        return 1
    e = collections.defaultdict(list)
    for _ in range(n-1):
        a,b = LI_()
        e[a].append(b)
        e[b].append(a)

    rr = [None] * n

    fm = [None] * n
    def f(i,p):
        r = 1
        for c in e[i]:
            if c != p:
                r *= f(c,i) + 1
                r %= m
        fm[i] = r
        return r

    def g(i,p,pp):
        l = len(e[i])
        v = e[i]
        ta = [(pp if u==p else (fm[u] if not fm[u] is None else f(u,i))) + 1 for u in v]

        if l == 1:
            rr[i] = ta[0] % m
            return

        aa = [None] * l
        aa[0] = ta[0]
        for j in range(1,l):
            aa[j] = aa[j-1] * ta[j] % m

        ba = [None] * l
        ba[-1] = ta[-1]
        for j in range(l-2,-1,-1):
            ba[j] = ba[j+1] * ta[j] % m

        rr[i] = ba[0] % m
        if v[0] != p:
            g(v[0],i,ba[1])
        for j,u in enumerate(v[1:-1]):
            if u != p:
                g(u,i,aa[j]*ba[j+2]%m)
        if v[-1] != p:
            g(v[-1],i,aa[-2])

    def h(i):
        l = len(e[i])
        v = e[i]
        ta = [(fm[u] if not fm[u] is None else f(u,i)) + 1 for u in v]

        if l == 1:
            rr[i] = ta[0] % m
            g(v[0],i,1)
            return

        aa = [None] * l
        aa[0] = ta[0]
        for j in range(1,l):
            aa[j] = aa[j-1] * ta[j] % m

        ba = [None] * l
        ba[-1] = ta[-1]
        for j in range(l-2,-1,-1):
            ba[j] = ba[j+1] * ta[j] % m

        rr[i] = ba[0] % m
        g(v[0],i,ba[1])
        for j,u in enumerate(v[1:-1]):
            g(u,i,aa[j]*ba[j+2]%m)
        g(v[-1],i,aa[-2])

    h(1)


    return '\n'.join(map(str, rr))



print(main())




Measured memory_bytes: 215292
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();

    int num = 1;
    int ans = 0;
    for (int i = 0; i < 100; i++) {
      if(num>=B) break;
      num = num -1 +A;
      ans++;
    }

    System.out.println(ans);

  }

}


Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace std;
const int N=105;
int n;char a[N];int c1,c2;
int main(){
    ios::sync_with_stdio(false);cin>>n>>a+1;
    for(int i=1;i<=n;++i)if(a[i]=='R')++c1;else ++c2;
    if(c1>c2)cout<<"Yes"<<"\n";
    else cout<<"No"<<"\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)n; i++)
int main()
{
  int a, b;
  cin >> a >> b;
  int numa = 0;
  int numb = 0;
  // cout << a << b << endl;
  for (int i = 0; i < 30; i++)
  {
    numa = a + (i - 1)*(a - 1);
    // cout << numa << b << endl;
    if (numa >= b)
    {
      cout << i << endl;
      return 0;
    }
  }
}


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

int main(){
    ll n,k;
    cin >> n >> k;
    vector<int> flgnum(41,0);
    vector<int> flgk(41,0);
    rp(j,41){
        flgk[j] += k%2ll;
        k/=2ll;
    }
    rp(i,n){
        ll a;
        cin >> a;
        rp(j,41){
            flgnum[j] += a%2ll;
            a/=2ll;
        }
    }
    /*for(auto i: flgnum){
        cout << i << " ";
    }
    cout << endl;*/
    ll sum=0ll;
    bool saidai=true;
    for(int i=40; i>=0; i--){
        if(saidai){
            if(flgk[i]==0){
                sum += (ll)flgnum[i]*(1ll<<i);
                //cout << sum << endl;
            }
            else{
                if(flgnum[i]<n-flgnum[i]){
                    sum += (ll)(n-flgnum[i])*(1ll<<i);
                }
                else{
                    saidai=false;
                    sum += (ll)flgnum[i]*(1ll<<i);
                }
            }
        }
        else{
            if(flgnum[i]<n-flgnum[i]){
                sum += (ll)(n-flgnum[i])*(ll)(1ll<<i);
            }
            else{
                sum += (ll)flgnum[i]*(ll)(1ll<<i);
            }
        }
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void) {
        int H, W, i, j;
        while(1) {
                scanf("%d %d", &H, &W);
                if(H==0 && W==0) {
                        break;
                }
                for(i=0;i<H;i++) {
                        for(j=0;j<W;j++) {
                                if(i==0 || j==0 || i==H-1 || j==W-1) {
                                        printf("#");
                                } else {
                                        printf(".");
                                }
                        }
                        printf("\n");
                }
                printf("\n");
        }
        return 0;
}

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

const int N=10;
int n,a[N],k;

int main()
{
	n=5;int i,j;
	for(i=1;i<=n;++i) scanf("%d",&a[i]);
	scanf("%d",&k);
	for(i=1;i<=n;++i)
	{
		for(j=1;j<i;++j)
			if(a[i]-a[j]>k)
			{
				printf(":(\n");
				return 0;
			}
	}
	printf("Yay!\n");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
string s;
int main(){
	cin>>s;
	int a=0; 
	for (int i=0;i<s.size();i++){
		a+=s[i]-'0';
		a%=9;
	}
	if (a==0)cout<<"Yes";
	else cout<<"No";
	return 0;
}

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

int main() {
    int64_t N, sum = 0;
    cin >> N;
    int A[N];
    rep(i, N) {
        cin >> A[i];
        sum += A[i];
    }
    int64_t oneMove = N * (N + 1) / 2;
    if (sum % oneMove) {
        cout << "NO" << endl;
        return 0;
    }
    int64_t k = sum / oneMove, cnt = 0;
    rep(i, N) {
        int d = A[(i+1)%N] - A[i] - k;
        if (d % N) {
            cout << "NO" << endl;
            return 0;
        }
        cnt += abs(d / N);
    }
    puts(cnt == k ? "YES" : "NO");
}

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

const int inf = 1001001001;

int main() {
    int n;
    cin >> n;
    
    vector<int> r(n);
    for (auto &i : r) cin >> i;
    
    reverse(r.begin(), r.end());
    
    int maxv = -inf;
    int ans = -inf;
    for (auto i : r) {
        ans = max(ans, maxv - i);
        maxv = max(maxv, i);
    }
    
    cout << ans << endl;
}

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

using namespace std;
typedef long long ll;

#define MOD (long long)(1e9+7)
#define INF (1LL<<60)
#define rep(i,n) for(ll i = 0; i < (n); i++)
#define rep1(i,n) for(ll i = 1; i <= (n); i++)

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


// 最大公約数
ll gcd(ll a, ll b)
{
  if(b == 0) return a;
  return gcd(b, a % b);
}

// mod m におけるa の逆元
ll modinv(ll a, ll m) {
  ll b = m, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    a -= t * b; swap(a, b);
    u -= t * v; swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}

// 素因数分解
vector<pair<ll, ll>> prim;
void pf(ll n)
{
  ll s = sqrt(n);
  ll r = 0;
  for(ll i = 2; i <= s; i++) {
    if((n % i) == 0) {
      r = 0;
      do {
	r++;
	n = n / i;
      } while((n % i) == 0);
      prim.push_back({i, r});
    }
  }
  if(n > s) {
    prim.push_back({n, 1});
  }
}

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

  vector<ll> a(N); rep(i, N) cin >> a[i];
  map<ll, ll> c0, c1;
  vector<pair<ll, ll>> vp0, vp1;
  ll ans = 0;

  rep(i, N) {
    if(i % 2 == 0) {
      c0[a[i]] ++;
    } else {
      c1[a[i]] ++;
    }
  }

  for(auto itr : c0) {
    vp0.push_back(make_pair(itr.second, itr.first));
  }
  for(auto itr : c1) {
    vp1.push_back(make_pair(itr.second, itr.first));
  }
  sort(vp0.begin(), vp0.end(), greater<pair<ll,ll>>());
  sort(vp1.begin(), vp1.end(), greater<pair<ll,ll>>());

  if(vp0[0].second == vp1[0].second) {
    if(vp0[0].first == vp1[0].first) {
      ans = N - vp0[0].first - max(vp0[1].first, vp1[1].first);
    } else {
      if(vp0[0].first > vp1[0].first) {
	ans = N - vp0[0].first - vp1[1].first;
      } else {
	ans = N - vp1[0].first - vp0[1].first;
      }
    }
  } else {
    ans = N - vp0[0].first - vp1[0].first;
  }
  cout << ans << endl;
}


int main(void)
{
  // ll t; cin >> t; rep(i, t)
  solve();
}


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

#define PI 3.141592653589
#define ll long long int
#define ld long double
#define vi vector<int>
#define vl vector<ll>
#define ii pair<int,int>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define pll pair<ll,ll>
#define vv vector
int MOD=1e9+7;
ll power(ll a, ll b){//a^b
    ll res=1;
    a=a%MOD;
    while(b>0){
        if(b&1){res=(res*a)%MOD;b--;}
        a=(a*a)%MOD;
        b>>=1;
    }
    return res;
}
ll fermat_inv(ll y){return power(y,MOD-2);}
ll gcd(ll a, ll b){return (b==0)?a:gcd(b,a%b);}
ll min(ll a,ll b){return (a>b)?b:a;}
ll max(ll a,ll b){return (a>b)?a:b;}
bool prime[1000001];
vi primes;
void SieveOfEratosthenes(int n) 
{ 
    memset(prime, true, sizeof(prime)); 
    for (int p=2; p*p<=n; p++) 
    { 
        if (prime[p] == true) 
        { 
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
    for(int p=2;p<1000001;p++)
        if(prime[p])
            primes.pb(p);
}

ll dp[405][405];
ll pre[405];
ll n;

ll solve(int l,int r){
    if(dp[l][r]!=-1)
        return dp[l][r];
    if(l==r){
        dp[l][r]=0;
        return dp[l][r];
    }
    dp[l][r]=LLONG_MAX;
    for(int i=l;i<r;i++){
        dp[l][r]=min(solve(l,i)+solve(i+1,r),dp[l][r]);
    }
    dp[l][r]+=pre[r]-pre[l-1];
    return dp[l][r];
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif

	int t=1;
	//cin>>t;
	//SieveOfEratosthenes(1000000);
    while(t--){
        cin>>n;
        ll a[n];
        for(int i=0;i<n;i++)
            cin>>a[i];
        for(int i=0;i<=400;i++){
            for(int j=0;j<=400;j++)
                dp[i][j]=-1;
        }
        pre[0]=0;
        for(int i=1;i<=n;i++){
            pre[i]=pre[i-1]+a[i-1];
        }
        cout<<solve(1,n)<<'\n';
        
    }
}

Measured memory_bytes: 4936
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include<stack>
#include <queue>
#include<map>
#include <set>
using namespace std;
#define int long long
#define ll long long
#define rep(i,n) for(ll i=0;i<n;++i)
#define loop(i,m,n) for(ll i=m;i<n;++i)
#define ggr getchar(); getchar();return 0;
#define pie 3.141592653589793238462643383279
#define INF 1000000007
int bin(int bina) {
	int ans = 0;
	for (int i = 0; bina > 0; i++)
	{
		ans = ans + (bina % 2)*pow(10, i);
		bina = bina / 2;
	}
	return ans;
}
bool prime(int n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int jo(int n) {
	int ans = 1;
	rep(i, n) {
		ans *= 2;
	}
	return ans;
}

signed main() {
	string s;
	cin >> s;
	rep(i, s.size()) {
		if (i == 3) {
			cout << 8;
		}
		else cout << s[i];
	}
	cout << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main() {
	int N, M;
	long long int Ans;
	scanf("%d %d", &N, &M);
	Ans = M;
	for (int i = 1; i < N; i++) {
		Ans *= (M - 1);
	}
	printf("%lld", Ans);
	return 0;
}

Measured memory_bytes: 128
#include<iostream>  
#include<string>  
using namespace std;  
int main()  
{  
    string str;  
    while(cin>>str){  
        int _min=str.size(),n=str.size();  
        for(int i=1;i<n;i++){  
            if(str[i]!=str[i-1]){  
                _min=min(_min,max(i,n-i));  
            }  
        }  
        cout<<_min<<endl;  
    }  
    return 0;  
}  

Measured memory_bytes: 512
// Problem : G - Longest Path
// Contest : Educational DP Contest
// URL : https://atcoder.jp/contests/dp/tasks/dp_g
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cp-editor)

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second
#define pb push_back
#define maxm 1e18
#define minm -1e18
#define pr pair<ll,ll>
#define mod 1000000007
vector<ll> dp(100001,-1);

void dfs(vector<ll> graph[],ll start)
{
	if(dp[start]!=-1)
		return;
	dp[start]=0;
	for(auto x:graph[start])
	{
		dfs(graph,x);
		dp[start]=max(dp[start],dp[x]+1);
	}
}

void solve()
{
	ll n,m,i,ans=0,a,b;
	cin>>n>>m;
	vector<ll> graph[n+1];
	for(i=0;i<m;i++)
	{
		cin>>a>>b;
		graph[a].pb(b);
	}
	for(i=1;i<=n;i++)
		dfs(graph,i);
	for(i=1;i<=n;i++)
		ans=max(ans,dp[i]);
	cout<<ans<<endl;
}
 
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
    	ll t=1;
	//cin>>t;
	while(t--)
	{
		solve();
	}
	return 0;
}


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

int main()
{
    int n;
    cin >> n;
    map<int, int> m;
    rep(i, n)
    {
        int a;
        cin >> a;
        m[a] = i + 1;
    }
    for (int i = 1; i <= n; i++)
    {
        if (i == n)
        {
            cout << m[i] << endl;
        }
        else
        {
            cout << m[i] << " ";
        }
    }
}

Measured memory_bytes: 5504
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using vec=vector<ll>;
using mat=vector<vec>;
#define For(i,a,b) for(i=a;i<b;i++)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define mod 1000000007
using datas=pair<ll,ll>;
using tdata=pair<datas,ll>;

long mmid(long a,long b,long c){return a<b?(b<c?b:max(a,c)):(b>c?b:min(a,c));}

ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}

ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}

ll modncrlistp[200000],modncrlistm[200000];

ll modncrs(ll n,ll r){
  ll i,j;
  if(modncrlistp[n]==0){
    for(i=n;i>=0;i--){
      if(modncrlistp[i])break;
    }
    if(i<0){
      modncrlistp[0]=1;
      rep1(i,n+1){
        modncrlistp[i]=(modncrlistp[i-1]*i)%mod;
      }
    }else{
      For(j,i+1,n+1){
        modncrlistp[j]=(modncrlistp[j-1]*j)%mod;
      }
    }
  }
  if(modncrlistm[n]==0){
    for(i=n;i>=0;i--){
      if(modncrlistm[i])break;
    }
    if(i<0){
      modncrlistm[0]=1;
      rep1(i,n+1){
        modncrlistm[i]=(modncrlistm[i-1]*modinv(i))%mod;
      }
    }else{
      For(j,i+1,n+1)modncrlistm[j]=(modncrlistm[j-1]*modinv(j))%mod;
    }
  }
  return (((modncrlistp[n]*modncrlistm[r])%mod)*modncrlistm[n-r])%mod;
}

ll modncr(ll n,ll r){
  if(r*2>n)return modncr(n,n-r);
  ll i,plus=1;
  rep(i,r){
    plus=(plus*(n-i))%mod;
    plus=moddevide(plus,i+1);
  }
  return plus;
}

ll euclidean_gcd(ll a, ll b) {
  if(a<b) return euclidean_gcd(b, a);
  ll r;
  while ((r=a%b)){a=b;b=r;}
  return b;
}

ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}

void printmap(vector<ll>& a,ll H,ll W){
  ll i,j;
  For(i,0,H+2){
    For(j,0,W+2){cout<<a[i*(W+2)+j];}
    cout<<endl;
  }
}
void inputmap(vector<ll>& a,ll H,ll W){
  ll i,j;
  string ss;
  For(i,1,H+1){
    cin>>ss;
    For(j,1,W+1){
      if(ss[j-1]=='#'){
        a[i*(W+2)+j]=1;
      }else{
        a[i*(W+2)+j]=0;
      }
    }
  }
}

int main(){
  ll i,N,K,a,b,cnt=0,ans=0;
  cin>>N>>K;
  vector<datas> ntlist(N);
  rep(i,N){
    cin>>a>>b;
    ntlist[i]=datas(b,a);
  }
  vrsort(ntlist);

  vec flavor(N+1,0),se(N+1,0);
  priority_queue<ll,vec,greater<ll>> que;
  rep(i,K){
    a=ntlist[i].second;
    b=ntlist[i].first;
    if(se[a]){
      que.push(b);
    }else{
      se[a]=1;
      cnt++;
    }
    ans+=b;
  }
  flavor[cnt]=ans+cnt*cnt;
  For(i,K,N){
    if(que.empty())break;
    a=ntlist[i].second;
    b=ntlist[i].first;
    if(se[a]==0){
      ans+=b;
      se[a]=1;
      ans-=que.top();que.pop();
      cnt++;
      flavor[cnt]=ans+cnt*cnt;
    }
  }
  ans=0;
  while(flavor[cnt]){
    ans=max(ans,flavor[cnt]);
    cnt--;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3964
#include <iostream>
#include <vector>
#include <algorithm>
// #include <ctime>

using namespace std;

typedef unsigned long long ull;
const ull MOD = 1000000007;
const int MAX_N = 100000;
ull fact[MAX_N + 1];

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

	ull ans;
//	clock_t wholetime = 0;
	// 都合上、0! = 0とする
	fact[0] = 0;
	fact[1] = 1;
	for (int i = 2; i < MAX_N + 1; i++){
		fact[i] = (fact[i - 1] * i) % MOD;
	}

	while (1){
		int N, R;
		cin >> N;
		if (N == 0) break;

		vector<int> word(N);
		for (int i = 0; i < N; i++) word[i] = i;
		word.push_back(0);
		ans = 0;
		cin >> R;

		vector<int> s(2*R+2, 0);
		s[2 * R + 1] = N;
		for (int i = 0; i < R; i++){
			cin >> s[i] >> s[i+R];
			s[i]--; s[i+R]--;

			s.push_back(s[i] + 1);
			s.push_back(s[i+R] + 1);

			// xor swap
			word[s[i]] ^= word[s[i+R]];
			word[s[i+R]] ^= word[s[i]];
			word[s[i]] ^= word[s[i+R]];
		}

//		clock_t st = clock();
		sort(s.begin(), s.end());
		s.erase(unique(s.begin(), s.end()), s.end());

		for (int i = 0, R = s.size() - 1; i < R; i++){
			ull tmp = 0;
			int si = s[i], sip = s[i+1];
			for (int j = si; j < sip; j++){
				tmp = (tmp + fact[N - j - 1]) % MOD;
			}
			tmp = (tmp * word[si]) % MOD;
			ans =(ans + tmp) % MOD;
//			cout << ans << ",";
			// 値を詰める
			int dif = sip - si;
			for (int j = i + 1; j < R; j++){
				word[s[j]] -= (word[s[j]] > word[si] ? dif : 0);
			}
		}
//		clock_t ed = clock();
//		wholetime += (ed - st);
		cout << ans << endl;
	}

//	cout << (double)wholetime / CLOCKS_PER_SEC << endl;
	return 0;
}

Measured memory_bytes: 2788
package main

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

func main() {
	var n, z, w int
	fmt.Scan(&n, &z, &w)
	a := scanInts(n)

	var diff int
	if n > 1 {
		if math.Abs(float64(a[n-1]-w)) < math.Abs(float64(a[n-1]-a[n-2])) {
			diff = a[n-1] - a[n-2]
		} else {
			diff = a[n-1] - w
		}
	} else {
		diff = a[0] - w
	}

	result := math.Abs(float64(diff))
	fmt.Print(int(result))
}

func scanInts(n int) []int {
	input := make([]int, n)
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	for i := 0; i < n; i++ {
		if sc.Scan() {
			in, err := strconv.Atoi(sc.Text())
			if err != nil {
				panic(err)
			}
			input[i] = in
		}
	}
	return input
}


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

using namespace std;

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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v; return v;}

typedef long long ll;

int main(){
    char a, b;
    cin >> a >> b;

    if(a == 'H'){
        if(b == 'H'){
            cout << "H" << endl;
        }else{
            cout << "D" << endl;
        }

    }else{
        if(b == 'H'){
            cout << "D" << endl;
        }else{
            cout << "H" << endl;
        }
    }

    return 0;
}

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

int main()
{
    int N;
    bool Y = false;
    cin >> N;
    string color;

    for (int i = 0; i < N; i++){
        cin >> color;
        if(color == "Y")
            Y = true;
    }

    if(Y)
        cout << "Four";
        else{
            cout << "Three";
        }
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
    int tyukan[999], kimatu[999], saite[999], a=0, b;
    while(1){
        scanf("%d %d %d",&tyukan[a] ,&kimatu[a], &saite[a]);
        if(tyukan[a] == -1 && kimatu[a] == -1 && saite[a] == -1)break;
        a++;
    }
    for(b = 0; b < a; b++){
        if(tyukan[b] == -1 || kimatu[b] == -1){
            printf("F\n");
        }else if(tyukan[b]+kimatu[b]<30){
            printf("F\n");
        }else if(tyukan[b]+kimatu[b]<50){
            if(saite[b]>=50){
                printf("C\n");
            }else{
                printf("D\n");
            }
        }else if(tyukan[b]+kimatu[b]<65){
            printf("C\n");
        }else if(tyukan[b]+kimatu[b]<80){
            printf("B\n");
        }else{
            printf("A\n");
     
     
        }
    }
return 0;
}

Measured memory_bytes: 596
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define MOD 1000000007
using namespace std;

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

int main() {
    int P, Q, R;
    cin >> P >> Q >> R;
    int maximum = max(P, max(Q, R));
    cout << P + Q + R - maximum << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define pi pair<ll,ll>
#define pii pair<ll,pi>
#define pb push_back
#define mk make_pair
const int siz = 1e5 + 7;
vector<pi>adj[siz];
ll dis[siz];
bool vis[siz];
int n;
void dfs(int v) {
	vis[v] = true;
	for (auto k : adj[v]) {
		if (!vis[k.fi]) {
			vis[k.fi] = true;
			dis[k.fi] = max(dis[k.fi], dis[v] + k.se);
			dfs(k.fi);
		}
	}
}

int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> n;
	for (int i = 0; i <= siz; i++)vis[i] = false;
	for (int i = 0; i < n - 1; i++) {
		ll u, v, w;
		cin >> u >> v >> w;
		adj[u].pb(mk(v, w));
		adj[v].pb(mk(u, w));
	}
	dfs(1);
	for (int i = 1; i <= n; i++) {
		if (dis[i] & 1)
			cout << "1" << endl;
		else
			cout << "0" << endl;
	}
}



Measured memory_bytes: 9472
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
constexpr int MOD = 1000000007;
constexpr int INF = 2147483647;
void yes(bool expr) {
  cout << (expr ? "Yes" : "No") << "\n";
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    lint N;
    cin >> N;
    vector<string> A(N);
    REP(i, N) cin >> A[i];
    vector<lint> last(N);
    vector<lint> minus(N);
    lint sum = 0;
    REP(i, N) {
        lint now = 0;
        lint mi = 0;
        REP(j, A[i].size()) {
            if(A[i][j] == '(') {
                now++;
            } else {
                now--;
                if(now < mi) mi = now;
            }
        }
        sum += now;
        last[i] = now;
        minus[i] = mi;
    }
    if(sum != 0) {
        cout << "No" << endl;
        return 0;
    }
    vector<pair<lint, lint>> plus;
    REP(i, N) {
        if(last[i] >= 0) plus.push_back(make_pair(last[i], minus[i]));
    }
    sort(plus.begin(), plus.end(), [](auto const &a, auto const &b) { return a.second != b.second ? a.second > b.second : a.first > b.first; });
    sum = 0;
    REP(i, plus.size()) {
        if(sum < -plus[i].second) {
            cout << "No" << endl;
            return 0;
        }
        sum += plus[i].first;
    }
    vector<pair<lint, lint>> mi;
    REP(i, N) {
        if(last[i] < 0) mi.push_back(make_pair(-last[i], minus[i]-last[i]));
    }
    sort(mi.begin(), mi.end(), [](auto const &a, auto const &b) { return a.second != b.second ? a.second > b.second : a.first > b.first; });
    sum = 0;
    REP(i, mi.size()) {
        //cout << mi[i].first << endl;
        if(sum < -mi[i].second) {
            cout << "No" << endl;
            return 0;
        }
        sum += mi[i].first;
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 70296
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define int long long

signed main(){
    int N;
    cin>>N;
    bool check=true;
    REP(i,N+1){
        int d=i*1.08;
        if(d==N){
            cout<<i<<endl;
          	check=false;
            break;
        }
    }
    if(check) cout<<":("<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
using ll = long long;
 
#define rep(i, a) for (int i = 0; (i) < (int) (a); (i)++)
#define reps(i, a, b) for (int i = (int) (a); (i) < (int) (b); (i)++)
#define rrep(i, a) for (int i = (int) a-1; (i) >= 0; (i)--)
#define rreps(i, a, b) for (int i = (int) (a)-1; (i) >= (int) (b); (i)--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x
#define TRUE__  "Yes"
#define FALSE__ "No"
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}
#define RS resize
#define CINV(v, N) do {\
	v.RS(N);\
	rep(i, N) cin >> v[i];\
} while (0);
#define RCINV(v, N) do {\
	v.RS(N);\
	rrep(i, N) cin >> v[i];\
} while (0);

#define int ll
 
#define MOD 1000000007
void init();
void solve();

signed main()
{
    init();
    solve();
}

int N;
vector<int> A;

void init()
{
    cin >> N;
    CINV(A, N);
    reverse(all(A));
}

inline bool check(int i, int& ma, int& mi) {
    int x = A[i];
    mi = (mi + x - 1) / x * x;
    ma = ma / x * x + x - 1;
    return ma >= mi;
}

void solve()
{
    int ma = 2, mi = 2;
    rep(i, N) {
        if (!check(i, ma, mi)) {
            cout << -1 << endl;
            return;
        }
    }
    cout << mi << " " << ma << endl;
}



Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int a[1000000];
int main()
{
    int k,s;
    cin>>k>>s;
    for(int i=0;i<=k;i++)
    {
        for(int j=0;j<=k;j++)
        {
            a[5000+i+j]++;
        }
    }
    int sum=0;
    for(int i=0;i<=k;i++)
    {
        int pos=s-i;
        if(pos<0)
        {
            continue;
        }
        sum+=a[5000+pos];
    }
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> pip;
typedef pair<pll, pll> P;
const ll INF = 1ll<<30;
const ll MOD = 1000000007;
const double EPS = 1e-9;
const bool debug = 0;
//---------------------------------//

int N, K;
int V[50];

int main() {
	cin >> N >> K;
	REP(i, N) scanf("%d", V + i);
	
	ll ans = 0;
	for (int i = min(N, K); i >= 0; i--) { // c(A) + c(B)
		REP(j, i + 1) { // c(A)
			vector<int> v;
			REP(k, j) v.push_back(V[k]);
			REP(k, i - j) v.push_back(V[N - 1 - k]);
			sort(ALL(v));
			int cnt = K - i;
			ll cur = 0;
			REP(k, v.size()) {
				if (v[k] < 0 && cnt > 0) cnt--;
				else cur += v[k];
			}
			chmax(ans, cur);
		}
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 256
{-# LANGUAGE BangPatterns #-}
import Control.Monad
import Data.Maybe
import Debug.Trace
import Data.List
import qualified Data.Map.Strict as Map
import qualified Data.IntMap.Strict as IntMap
import qualified Data.Set as Set
import qualified Data.IntSet as IntSet
import Data.Functor
import Data.Array
-- import Data.Array.Unboxed
import Control.Monad.ST
import Data.Array.ST

main :: IO ()
main = do
  (n:m:_) <- map read . words <$> getLine :: IO [Integer]
  as <- replicateM (fromInteger m) $ readLn :: IO [Integer]
  print $ solve n m as

solve n m as = foldl' modmul 1 $ map f diffs
  where
    sorted = (sort as) ++ [n + 1]
    -- padZero = if head sorted == 1 then sorted else (0:sorted)
    padZero = (-1):sorted
    -- padN = if last sorted == n then padZero else padZero ++ [fromIntegral n + 1]
    diffs = zipWith (\x y -> x - y - 1) (drop 1 padZero) padZero
    -- arr = listArray (1, n) as
    -- dp = listArray (1, n) $ map f [1..n]
    c = listArray (1, n) $ map f [1..n]
    f 0 = 0
    f 1 = 1
    f 2 = 1
    f 3 = 2
    f i = c!(i - 1) + c!(i - 2)
    -- f 3 = 2
    -- f 4 = 3
    -- f 5 = 4
    -- f i = let j = i `div` 2 in (c!j) `modmul` (c!(i - j + 1))



divConst = 10^9 + 7 :: Integer
modadd x y = (x + y) `mod` divConst
modsub x y = (x - y) `mod` divConst
modmul x y = ((x `mod` divConst) * (y `mod` divConst)) `mod` divConst
moddiv x y = modmul x (power y (divConst - 2))
power x y
  | y == 0 = 1
  | y == 1 = x `mod` divConst
  | y `mod` 2 == 0 = (power x (y `div` 2))^2 `mod` divConst
  | otherwise = (power x (y `div` 2))^2 * x `mod` divConst

-- 階乗 n!
factorial :: Integer -> Integer
factorial n = foldr modmul 1 [1..n]

-- n! / m!
fact :: Integer -> Integer -> Integer
fact n m = foldr modmul 1 [(m+1)..n]


-- nCk = n! / (k! * (n - k)!)
-- n個からk個えらぶ
select :: Integer -> Integer -> Integer
select n k = foldl' moddiv (fact n (n - k)) [1..k]

-- 組み合わせ nHc = (n + c - 1)!/(n! * (c - 1)!)
-- n個のボールとc枚の仕切り板
combination :: Integer -> Integer -> Integer
combination n c = foldl' moddiv (fact (n + c - 1) (c - 1)) [1..n]
  

Measured memory_bytes: 562940