akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define FOR(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
using namespace std;

const string ord = "abcd";

int f(string &s, string &p, int &i) {
    REP (j, 4) if (s[i] == ord[j]) {
        ++i;
        return (p[j] - '0');
    }
    ++i;
    if (s[i] == '+') {
        int res = 0;
        ++i;
        while (s[i] != ']') {
            res |= f(s, p, i);
        }
        ++i;
        return res;
    } else if (s[i] == '*') {
        int res = (1 << 30) - 1;
        ++i;
        while (s[i] != ']') {
            res &= f(s, p, i);
        }
        ++i;
        return res;
    } else {
        int res = 0;
        ++i;
        while (s[i] != ']') {
            res ^= f(s, p, i);
        }
        ++i;
        return res;
    }
}

int dfs(int idx, string s, string p, int hash) {
    if (idx == 4) {
        int i = 0;
        return (f(s, p, i) == hash);
    }
    int res = 0;
    REP (i, 10) {
        res += dfs(idx + 1, s, p + string(1, char(i + '0')), hash);
    }
    return res;
}

void _main() {
    string s;
    while (cin >> s, s != ".") {
        string p;
        cin >> p;
        int i = 0, hash = f(s, p, i);
        cout << hash << " " << dfs(0, s, "", hash) << endl;
    }
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    _main();
    return 0;
}


Measured memory_bytes: 3084
#include <bits/stdc++.h>
using namespace std;
using P = pair<int,int>;

int main(){
  int d;
  cin >> d;
  vector<int> c26(26);
  vector<vector<int>> si(d, vector<int>(26));
  for(int i=0; i<26; ++i) cin >> c26[i];
  for(int i=0; i<d; ++i) for(int j=0; j<26; ++j) cin >> si[i][j];
  
  vector<vector<int>> koho(d);
  for(int i=0; i<26; ++i){
    int hindo;
    if(c26[i] <=10) hindo = 50;
    else if(c26[i] <=20) hindo = 20;
    else if(c26[i] <=40) hindo = 15;
    else if(c26[i] <=60) hindo = 10;
    else hindo = 5;
    
    int j = 0;
    while(j<d-1){
      int cnt = 0;
      int mxday = min(j+hindo, d-1);
      for(int k=mxday; k>j; --k){
        if(si[k][i] >= 16000){
          koho[k].push_back(i);
          ++cnt;
          for(int l=j+1; l<=k; ++l){
            si[l][i] += (l-j) *(l-j) *c26[i];
          }
          j = k;
          break;
        }
      }
      if(cnt == 0){
        for(int l=j+1; l<=mxday; ++l){
          si[l][i] += (l-j) *(l-j) *c26[i];
        }
        if(mxday != d-1) koho[mxday].push_back(i);
        j = mxday;
      }
    }
  }
  
  vector<int> ans(d);
  for(int i=0; i<d; ++i){
    vector<P> koho2(0);
    if(koho[i].size() == 0){
      for(int j=0; j<26; ++j){
        koho2.push_back(make_pair(si[i][j], j));
      }
    }else{
      for(int n: koho[i]){
        koho2.push_back(make_pair(si[i][n], n));
      }
    }
    sort(koho2.begin(),koho2.end());
    reverse(koho2.begin(),koho2.end());
    ans[i] = koho2[0].second;
  }
  for(int i=0; i<d; ++i){
    cout << ans[i]+1 << endl;
  }
}


Measured memory_bytes: 3712
#include<bits/stdc++.h>
using namespace std;
#define sz 100005

long long int mp[sz];
int main(){

    long long int a,b,q,n,i;
    long long int sum=0;
    cin>>n;
    for(i=1; i<=n; i++){
        cin>>a;
        mp[a]++;
        sum+=a;
    }

    cin>>q;
    while(q--){
        cin>>a>>b;
        sum-=(a*mp[a]);
        sum+=(b*mp[a]);
        mp[b]+=mp[a];
        mp[a]=0;
        cout<<sum<<endl;
    }
    return 0;
}


Measured memory_bytes: 4392
import java.util.*;

class Main {
	Scanner sc = new Scanner(System.in);

	public void run() {
		Integer[] vals = new Integer[5];
		for (int i = 0; i < vals.length; i++) {
			vals[i] = sc.nextInt();
		}
		Arrays.sort(vals, new Comparator<Integer>() {
			@Override
			public int compare(Integer o1, Integer o2) {
				return o2 - o1;
			}
		});
		ln(join(vals," "));
	}

	public static String join(Object[] array, String separator) {
		StringBuilder str = new StringBuilder(array[0] + "");
		for (int i = 1; i < array.length; i++) {
			str.append(separator).append(array[i] + "");
		}
		return str.toString();
	}
	public static void main(String[] args) {
		new Main().run();
	}

	public static void pr(Object o) {
		System.out.print(o);
	}

	public static void ln(Object o) {
		System.out.println(o);
	}

	public static void ln() {
		System.out.println();
	}
}

Measured memory_bytes: 12000
#include<bits/stdc++.h>
using namespace std;
#define ms(x,y) memset(x, y, sizeof(x))
#define lowbit(x) ((x)&(-x))
#define sqr(x) ((x)*(x))
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;


void run_case() {
    LL n, k, q;
    cin >> n >> k >> q;
    vector<LL> a(n+1);
    for(int i = 0; i < q; ++i) {
        int x; cin >> x;
        a[x]++;
    }
    for(int i = 1; i <= n; ++i) cout << (k-q+a[i] > 0?"Yes":"No") << "\n";
    
}


int main() {
    //freopen("input", "r", stdin);
    ios::sync_with_stdio(false), cin.tie(0);
    cout.flags(ios::fixed);cout.precision(9);
    //int t; cin >> t;
    //while(t--)
    run_case();
    cout.flush();
    return 0;
}


Measured memory_bytes: 3992
import java.util.Scanner;
class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n=sc.nextInt();
    String s=sc.next();
    int count=0;
    for(int i=0;i<n-2;i++) {
        if(s.charAt(i)=='A' && s.charAt(i+1)== 'B' && s.charAt(i+2)=='C') {
            count++;
        }
    }
    System.out.println(count);
}
}


Measured memory_bytes: 25684
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan=new Scanner(System.in);
		String S=scan.next();
		if(S.charAt(4)==S.charAt(5) && S.charAt(2)==S.charAt(3))
		{
			System.out.println("Yes");
		}
		else
		{
			System.out.println("No");
		}

	}

}


Measured memory_bytes: 35568
#include <iostream>

using namespace std;
void swap(int &a,int &b){
  int tmp = a;
  a = b;
  b = tmp;
}
int main(int argc, char const *argv[]) {
  int count;
  cin >> count;
  int *a = new int[count];
  for (int i = 0; i < count; i++) {
    cin >> a[i];
  }
  int swap_count = 0;
  for (int i = 0; i < count; i++) {
    for (int j = count - 1; j > 0; j--) {
      if( a[j] < a[j - 1]){
        swap(a[j], a[j - 1]);
        swap_count++;
      }
    }
  }
  for(int i = 0; i < count; i++){
    cout << a[i];
    if (i == count - 1){
      cout << endl;
    }else{
      cout << " ";
    }
  }
  cout << swap_count << endl;
  delete [] a;
  return 0;
}

Measured memory_bytes: 3096
n = int(input())
count = 0

a, b, ab = 0, 0, 0
for _ in range(n):
    s = input()
    if s[-1] == "A" and s[0] == "B":
        ab += 1
    if s[-1] == "A":
        a += 1
    if s[0] == "B":
        b += 1


    for i in range(len(s)-1):
        if s[i:i+2] == "AB":
            count += 1

count += min(a, b)
if max(a, b) == ab and ab != 0:
    count -= 1

print(count)

Measured memory_bytes: 46040
from collections import defaultdict

ps = []
for i in range(2, 1000):
    is_p = True
    for j in range(2, i):
        if i % j == 0:
            is_p = False
            break
    if is_p:
        ps.append(i)

def factorization(n):
    arr = defaultdict(int)
    temp = n
    for i in ps:
        if i > int(-(-n**0.5//1))+1:
            break
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr[i] = cnt
    if temp!=1:
        arr[temp] = 1
    if arr==[]:
        arr[n] = 1
    return arr


aa = defaultdict(int)

n = int(input())
a = list(map(int, input().split()))

fs = [[]] * 1000001
for i in a:
    if not fs[i]:
        fs[i] = factorization(i)

for i in a:
    for k, v in fs[i].items():
        aa[k] = max(aa[k], v)


mod = 10 ** 9 + 7
t = 1
for k, v in aa.items():
    t = (t * (k ** v)) % mod
ans = 0
for i in a:
    ans += t * pow(i, mod - 2, mod)
    ans %= mod
print(ans)


Measured memory_bytes: 87020
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int arr[n+2];
    int dp[n+2]={0};
    
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    dp[0]=0;
    dp[1]=abs(arr[0]-arr[1]);
    for(int i=2;i<n;i++)
    {
        dp[i] = min( dp[i-1]+abs(arr[i-1]-arr[i]) , dp[i-2]+abs(arr[i-2]-arr[i]));
    }
    
    cout<<dp[n-1]<<endl;
}

Measured memory_bytes: 1024
N=int(input())
import sys
input=sys.stdin.readline
inf=10**20
dd = {
        'R':[-inf]*3,
        'L':[inf]*3,
        'U':[-inf]*3,
        'D':[inf]*3,
        }
for _ in range(N):
    x, y, d = input().split()
    x, y = int(x), int(y)
    if d == 'R':
        dd['R'][0] = max(x, dd['R'][0])
        dd['L'][1] = min(x, dd['L'][1])
        dd['U'][2] = max(y, dd['U'][2])
        dd['D'][2] = min(y, dd['D'][2])
    elif d == 'L':
        dd['L'][0] = min(x, dd['L'][0])
        dd['R'][1] = max(x, dd['R'][1])
        dd['U'][2] = max(y, dd['U'][2])
        dd['D'][2] = min(y, dd['D'][2])
    elif d == 'U':
        dd['R'][2] = max(x, dd['R'][2])
        dd['L'][2] = min(x, dd['L'][2])
        dd['U'][0] = max(y, dd['U'][0])
        dd['D'][1] = min(y, dd['D'][1])
    elif d == 'D':
        dd['R'][2] = max(x, dd['R'][2])
        dd['L'][2] = min(x, dd['L'][2])
        dd['U'][1] = max(y, dd['U'][1])
        dd['D'][0] = min(y, dd['D'][0])

tls = []
for d in "RLUD":
    m = -1 if d in 'RU' else 1
    t1 = -m*(dd[d][1] - dd[d][2])
    t2 = -m*(dd[d][2] - dd[d][0])
    t3 = m*float(dd[d][0] - dd[d][1])/2
    #print(d, m, t1,t2,t3)
    if t1 < t3 and t3 < t2:
        if t1 > 0:
            tls.append((0, m, dd[d][1], d))
        if t2 > 0:
            tls.append((max(0, t1), 0, dd[d][2], d))
        tls.append((max(0, t2), -m, dd[d][0], d))
    else:
        if t3 > 0:
            tls.append((0, m, dd[d][1], d))
        tls.append((max(0, t3), -m, dd[d][0], d))

tls.sort()
btl = 0
r = 10**20
for t, a, b, d in tls:
    if btl > 10**10:
        btl = inf
        break
    if t != btl:
        a1=(dd['R'][0] - dd['L'][0])
        a2=(dd['U'][0] - dd['D'][0])
        b1=(dd['R'][1] - dd['L'][1])
        b2=(dd['U'][1] - dd['D'][1])
        r = min(r, (a1*t+b1)*(a2*t+b2))
        r = min(r, (a1*btl+b1)*(a2*btl+b2))
        #print(t, btl, dd['R'], dd['L'], dd['U'], dd['D'], r)
    dd[d] = (a, b)
    btl = t
if btl < inf:
    t = inf
    a1=(dd['R'][0] - dd['L'][0])
    a2=(dd['U'][0] - dd['D'][0])
    b1=(dd['R'][1] - dd['L'][1])
    b2=(dd['U'][1] - dd['D'][1])
    r = min(r, (a1*t+b1)*(a2*t+b2))
    r = min(r, (a1*btl+b1)*(a2*btl+b2))
#print(t, btl, dd['R'], dd['L'], dd['U'], dd['D'])

print(r)
#print(tls)


Measured memory_bytes: 51816
h , w , n = map(int,input().split())
sr , sc = map(int,input().split())
s = input()
t = input()
scou = [0,0,0,0] 
tcou = [0,0,0,0]
hou = {"L":0,"R":1,"U":2,"D":3}
for i in range(n):
    scou[hou[s[i]]] += 1
    if sc - scou[0] + tcou[1] <= 0:
        print("NO")
        exit()
    if sc + scou[1] - tcou[0] >= w + 1:
        print("NO")
        exit()
    if sr - scou[2] + tcou[3] <= 0:
        print("NO")
        exit()
    if sr + scou[3] - tcou[2] >= h + 1:
        print("NO")
        exit()
    
    tcou[hou[t[i]]] += 1
    if sc - tcou[0] + scou[1] <= 0:
        tcou[0] -= 1
    if sc + tcou[1] - scou[0] >= w+1:
        tcou[1] -= 1
    if sr - tcou[2] + scou[3] <= 0:
        tcou[2] -= 1
    if sr + tcou[3] - scou[2] >= h+1:
        tcou[3] -= 1

print("YES")

Measured memory_bytes: 9764
#include<iostream>
#include<iomanip>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<set>
using namespace std;
string s;
int bj=-1;
int main() {
	cin>>s;
	for(int i=0;i<s.length();i++)if(s[i]=='C'){
		bj=i;
		break;
	}
	
	if(bj==-1){
		puts("No");
		return 0;
	}
	for(int i=bj;i<s.length();i++)if(s[i]=='F'){
		puts("Yes");
		return 0;
	} 
    puts("No");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>

#include <atcoder/dsu>
#include <atcoder/fenwicktree>
#include <cstdio>

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

using namespace std;
typedef long long ll;

using namespace atcoder;

int main()
{
    ll n, q;
    ll ans = 0;
    scanf("%lld %lld", &n, &q);
    vector <ll> A(n, 0);
    for (int i = 0; i < n; i ++){
        scanf("%lld", &A.at(i));
    }
    fenwick_tree<ll> fw(n);
    FOR(i,0,n) {
        fw.add(i,A[i]);
    }
    FOR(i,0,q) {
        ll t;
        scanf("%lld", &t);
        if (t==0) {
            ll p, x;
            scanf("%lld %lld", &p, &x);  
            fw.add(p, x);
        } else {
            ll l, r;
            scanf("%lld %lld", &l, &r);
            ans = fw.sum(l, r);
            printf("%lld\n", ans);  
        }
    }
    return 0;
}

Measured memory_bytes: 12140
n,m=map(int,input().split())
li=[list(map(int,input().split())) for i in range(m)]

ans=[]

for i in range(m) :
  temp=li[i]
  ans.append(temp[0])
  ans.append(temp[1])
for i in range(n) :
  print(ans.count(i+1))

Measured memory_bytes: 3060
#include <iostream>
#include <bits/stdc++.h>
#define lli long long int
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    lli m, r,i,j,n,x;
    cin>>n;
    lli a[n-1];
    lli b[n]={0};
    for(i=0;i<n-1;i++){
        cin>>a[i];
        b[a[i]-1]++;
    }
    for(i=0;i<n;i++){
        cout<<b[i]<<" ";
    }
}

Measured memory_bytes: 6760
h = int(input())
w = int(input())
n = int(input())

count = 0
if h > w:
    count = int(n / h)
    if n % h != 0:
        count += 1
else:
    count = int(n / w)
    if n % w != 0:
        count += 1
print(count)

Measured memory_bytes: 3060
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;

class Program
{
    const string Yes = "Yes";
    const string No = "No";
    const char White = '.';
    const char Black = '#';
    const long Mod = 1000000007;

    static void Main(string[] args) {
        checked {
#if DEBUG
            MyDebugger.Test(process, "../TextFile1.txt");
            //TestCaseMaker.MakeTestCase1("../TextFile2.txt");
            //MyDebugger.Test(process, "../TextFile2.txt");
#else
            object ret = process(new StreamReader(Console.OpenStandardInput()));
            if(ret != null) Console.WriteLine(ret);
#endif
        }
    }

    static object process(TextReader input) {
        var spl = input.ReadLine().Split(' ');
        var n = int.Parse(spl[0]);
        var m = int.Parse(spl[1]);

        var loads = new List<int>[n];
        
        for(int i=0; i<n; i++) {
            loads[i] = new List<int>();
        }
        for(int i=0; i<m; i++) {
            spl = input.ReadLine().Split(' ');
            var a = int.Parse(spl[0]) - 1;
            var b = int.Parse(spl[1]) - 1;

            loads[a].Add(b);
            loads[b].Add(a);
        }

        exited = new HashSet<int>();

        int co = 0;
        for(int i=0; i<n; i++) {
            if (!exited.Contains(i)) {
                co++;
                Search(loads, i);
            }
        }

        return co-1;
    }

    static HashSet<int> exited;

    static void Search(List<int>[] loads, int p) {

        //探索終了判定
        if (exited.Contains(p)) {
            return;
        }
        exited.Add(p);

        //次の再帰
        foreach (var ne in loads[p]) {
            Search(loads, ne);
        }
        return;
    }

    static long[] ToIntArray(string strs, int n) {
        var ret = new long[n];
        var spl = strs.Split(' ');
        for (int i = 0; i < n; i++)
            ret[i] = long.Parse(spl[i]);
        return ret;
    }
}


Measured memory_bytes: 50536
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		char[] s1 = br.readLine().toCharArray();
		char[] s2 = br.readLine().toCharArray();
		br.close();

		int mod = 1000000007;
		long ans = 1;
		for (int i = 0; i < n; i++) {
			if (s1[i] == s2[i]) {
				if (i == 0) {
					ans = ans * 3;
				} else {
					if (s1[i - 1] == s2[i - 1]) {
						ans = ans * 2 % mod;
					}
				}
			} else {
				if (i == 0) {
					ans = ans * 6;
				} else {
					if (s1[i - 1] != s1[i]) {
						if (s1[i - 1] == s2[i - 1]) {
							ans = ans * 2 % mod;
						} else {
							ans = ans * 3 % mod;
						}
					}
				}
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 23380
//---------------------------------------------------------------
#include <bits/stdc++.h>
using namespace std;
#include <iostream>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <math.h>
#include <sstream>
#include <numeric>
#include <cctype>
#include <bitset>
#include <cassert>
#include<algorithm>
//---------------------------------------------------------------
#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 rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define SIZE 100005
#define INF 1e18
#define all(x) x.begin(),x.end()
#define fi first
#define se second
#define vec vector
using pint = pair<int,int>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
//---------------------------------------------------------------
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; }
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const double pi = acos(-1);
const int mod = 1000000007;
struct mint {
int64_t x;
mint(int64_t 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 { return mint(*this) += a;}
mint operator-(const mint a) const { return mint(*this) -= a;}
mint operator*(const mint a) const { return mint(*this) *= a;}
mint pow(int64_t t) const {if (!t) return 1;mint a = pow(t>>1);a *= a;if (t&1) a *= *this;return a;}
mint inv() const { return pow(mod-2);}
mint& operator/=(const mint a) { return *this *= a.inv();}
mint operator/(const mint a) {return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
//---------------------------------------------------------------

//↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓


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

    int n;
    cin>>n;
    if(n==0){
        cout<<0<<endl;
        return 0;
    }
    
    string ans;
    while(n!=0){

        if(n%2!=0){
            ans = '1' + ans;
            --n;
        }else{
            ans = '0' + ans;
        }

        n/=(-2);
    }

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

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y);
#define chmin(x,y) x = min(x,y);
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};
const int INF = 1001001001;



int main() {
    int n;
    cin >> n;
    if (n == 1) cout << "Hello World" << endl;
    else {
        int a, b;
        cin >> a >> b;
        cout << a+b << endl;
    }
    return 0;
}

Measured memory_bytes: 3564
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>

int main(void){

    long long X, A, B;

    scanf("%lld%lld%lld", &X, &A, &B);

    if(B - A <= 0){
        printf("delicious\n");
    }else if(B - A <= X){
        printf("safe\n");
    }else{
        printf("dangerous\n");
    }

    return 0;
}

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

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

    int p_x = 0, p_y = 0, p_t = 0;
    for (int i = 0; i < n; i++) {
        int t, x, y;
        cin >> t >> x >> y;

        int dx = abs(x - p_x);
        int dy = abs(y - p_y);
        int dt = abs(t - p_t);

        if (dx + dy > dt || (dx + dy) % 2 != dt % 2) {
            cout << "No" << endl;
            return 0;
        }

        p_x = x;
        p_y = y;
        p_t = t;
    }

    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
  private static Scanner sc;

  public static void main(String[] args) {
    sc = new Scanner(System.in);
    new Main().solve();
  }


  private void solve() {
    int r = sc.nextInt();
    if (r < 1200) {
      System.out.println("ABC");
    } else if (r < 2800) {
      System.out.println("ARC");
    } else {
      System.out.println("AGC");
    }
  }
}



Measured memory_bytes: 21844
#Union Find
#xの根を求める
def find(x):
    if par[x] < 0:
        return x
    else:
        par[x] = find(par[x])
        return par[x]
#xとyの属する集合の併合
def unite(x,y):
    x = find(x)
    y = find(y)
    
    if x == y:
        return False
    else:
        #sizeの大きいほうがx
        if par[x] > par[y]:
            x,y = y,x
        par[x] += par[y]
        par[y] = x
        return True

#xとyが同じ集合に属するかの判定
def same(x,y):
    return find(x) == find(y)

#xが属する集合の個数
def size(x):
    return -par[find(x)]

N,M = map(int,input().split())
A=[]
B=[]
for i in range(0,M,1):
    a,b=map(int,input().split())
    A.append(a)
    B.append(b)
#初期化
#根なら-size,子なら親の頂点
par = [-1]*(N+1)

ans = []
tmpans = N*(N-1)//2
for i in range(M-1,-1,-1):
    ans.append(tmpans)
    if same(A[i],B[i]):
        tmpans = tmpans
    else:
        tmpans -= size(A[i])*size(B[i])
        unite(A[i],B[i])

for i in range(M-1,-1,-1):
    print(ans[i])

Measured memory_bytes: 93408
n = int(input())
li = [list(map(int,input().split())) for i in range(n)]

li.sort(key=lambda x: x[2])
a,b,c = li[-1]
for x in range(101):
    for y in range(101):
        h = abs(x-a) + abs(y-b) + c
        if all(k == max(h-abs(x-i)-abs(y-j),0) for i,j,k in li):
            print(x,y,h)
            exit()

Measured memory_bytes: 3064
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<stdbool.h>
typedef long long ll;
#define elif else if
#define mod 1000000007

ll maxx(ll a, ll b)
{
	return (a>b)?a:b;
}
int main(void)
{
	ll n;
	scanf("%lld",&n);
	ll arr[n][3];
	for(ll i = 0;i<n;i++)
	{
		scanf("%lld %lld %lld",&arr[i][0],&arr[i][1],&arr[i][2]);
	}

	ll dp[n][3],ans;
	memset(dp,0,sizeof(dp));
	dp[0][0] = arr[0][0];
	dp[0][1] = arr[0][1];
	dp[0][2] = arr[0][2];
	for(ll i = 1;i<n;i++)
	{
		dp[i][0] = arr[i][0] + maxx(dp[i-1][1],dp[i-1][2]);
		dp[i][1] = arr[i][1] + maxx(dp[i-1][0],dp[i-1][2]);
		dp[i][2] = arr[i][2] + maxx(dp[i-1][1],dp[i-1][0]);
	}
	// ans = maxx
	ans = maxx(dp[n-1][0],maxx(dp[n-1][1],dp[n-1][2]));
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 4864
#include<bits/stdc++.h>
using namespace std;
long long a,cnt,ans=INT_MAX,n;
int main(){
    scanf("%lld",&n);
    for(int i=0;i<n;i++){
        scanf("%lld",&a);
        cnt=0;
        while(a%2==0){
            a/=2;
            cnt++;
        }
        ans=min(ans,cnt);
    }
    printf("%lld",ans);
    return 0;
}

Measured memory_bytes: 256
// inputに入力データ全体が入る
function Main(input) {
    var a = input[0]-0;
    var b = input[1]-0;
    var h = input[2]-0;
    console.log((a+b)*h/2)
}

Main(require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n"));

Measured memory_bytes: 7372
package main

import (
	"fmt"
	"math"
)

func main() {
	var a, b, x float64
	ok := float64(0)
	ng := math.Pi / 2

	fmt.Scan(&a)
	fmt.Scan(&b)
	fmt.Scan(&x)

	for i := 0; i < 100; i++ {
		mid := (ok + ng) / 2
		if f(a, b, mid) >= x {
			ok = mid
		} else {
			ng = mid
		}
	}

	fmt.Println(ok * 180 / math.Pi)
}

func f(a, b, theta float64) float64 {
	if a*math.Tan(theta) <= b {
		return a*a*b - a*a*a*math.Tan(theta)/2
	} else {
		return a * b * b / (2 * math.Tan(theta))
	}
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main(void){
    
    //*
    int a, b;
    cin >> a >> b ;
    //*/
    
    /*
    vector<int> a(3);
    cin >> a.at(0) >> a.at(1) >> a.at(2) ;
    
    sort(a.begin(), a.end());
    */
    
    /*
    if( a % 10 == 9 || a / 10 % 10 == 9 ){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    */
    
    cout << a * a - b << endl;

    return 0; 
}


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

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> VI;
typedef vector<VI> VVI;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = numeric_limits<int>::max() / 2;
const int NEG_INF = numeric_limits<int>::min() / 2;
const ll MOD = 1000000007;

int binsearch_lower_bound(vector<int>& vec, int val) {
  int low = 0;            // ???????????????
  int high = vec.size();  // ???????????????????§£???????????° [low, high] ??????????????¨??????
  while (low < high) {
    int mid = (low + high) / 2;  // ??????????????????????£???§????????????????????????????????????
                                 // ??????????????? mid=low+(high-low)/2 ??¨????????????
    int midval = vec[mid];       // ????????§??????

    // ?§£?????????????????????
    if (midval < val) low = mid + 1;
    else high = mid;
  }
  return low;
}

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

  int n,t;
  cin >> n >> t;
  std::vector<int> v;
  for(int i=0;i<n;i++){
    int d;
    cin >> d;
    v.push_back(d);
  }
  sort(v.begin(),v.end());
  ll res=1;
  for(int i=1;i<n;i++){
    if(v[i-1]>=v[i]-t){
      int idx=binsearch_lower_bound(v,v[i]-t);
      res = (res*(i-idx+1))%MOD;
    }
  }
  cout << res << endl;
}

Measured memory_bytes: 3532
#include<iostream>
#include<cmath>
#include<string>
#include<queue>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#define P pair<long long, long long>


using namespace std;
const long long int MOD=1e9+7;

int main(){
  int n, a[1009];
  cin >> n;
  for(int i=0;i<n;i++)cin >> a[i];
  bool yes=true;
  for(int i=0;i<n;i++){
    if(a[i]%2==0){
      if(!(a[i]%3==0 || a[i]%5==0)){
        yes=false;
      }
    }
  }
  cout << (yes?"APPROVED":"DENIED") << endl;
}


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

int main(){
int n; cin >> n;
vector<pair<double,double>> xy(n);
rep(i,n) {
  cin >> xy[i].first;
  cin >> xy[i].second;
}
double k=(n*(n-1))/2;
vector<double> ans(k); int o=0;
rep(i,n){
    rep(j,i){
        ans[o]=sqrt(pow(xy[i].first-xy[j].first,2.0)+pow(xy[i].second-xy[j].second,2.0));
        o++;
    }
}
int ka=1; double kak=1;
//rep(i,n-2) ka*=(n+1);
rep(i,n) kak*=n+1;
double an=0;
rep(i,k) an+=ans[i]*2.0/n;
printf("%.16lf",an);
return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
int n,num[N];
struct Node{int app,val;}js[N],os[N];
bool cmp(Node x,Node y){return x.app>y.app;}
int main()
{		scanf("%d",&n);for(int i=1;i<=n;i++) scanf("%d",&num[i]);for(int i=1;i<=N;i++)js[i].val=i,os[i].val=i;
    for(int i=1;i<=n;i++)if(i%2==1)js[num[i]].app++;else os[num[i]].app++;
    sort(js+1,js+1+N,cmp);
    sort(os+1,os+1+N,cmp);
    if(js[1].val==os[1].val) 	if(js[1].app+os[2].app>js[2].app+os[1].app) printf("%d",max(0,n-js[1].app-os[2].app));
       else printf("%d",max(0,n-js[2].app-os[1].app));
    else printf("%d",max(0,n-js[1].app-os[1].app));
    return 0;
}


Measured memory_bytes: 2176
#include <cstdio>

#define X 0
#define Y 1
#define C 2
#define SIKI1 0
#define SIKI2 1
#define LEFT  0
#define RIGHT 1

int main(){
	double A[3][3][3];
	double n[6];

	while ( scanf("%lf %lf %lf %lf %lf %lf",&n[0],&n[1],&n[2],&n[3],&n[4],&n[5]) != EOF ){
		//ÏÌú»
		for (int i=0 ; i<=RIGHT ; i++){
			for (int j=0 ; j<=SIKI2 ; j++){
				for (int k=0 ; k<=C ; k++){
					A[i][j][k] = 0;
				}
			}
		}

		//lÌãü
		A[LEFT][SIKI1][X]  = n[0];
		A[LEFT][SIKI1][Y]  = n[1];
		A[RIGHT][SIKI1][C] = n[2];
		A[LEFT][SIKI2][X]  = n[3];
		A[LEFT][SIKI2][Y]  = n[4];
		A[RIGHT][SIKI2][C] = n[5];

		//®PÌXð¶Ó©çEÓÖÚ·é
		A[ RIGHT ][ SIKI1 ][ X ]  += (-1.0)*(A[ LEFT ][ SIKI1 ][ X ]);
		A[ LEFT  ][ SIKI1 ][ X ]  = 0;

		//®PÌ¼ÓðYÌWÅé		
		A[ RIGHT ][ SIKI1 ][ X ]  /= A[ LEFT ][ SIKI1 ][ Y ];
		A[ RIGHT ][ SIKI1 ][ C ]  /= A[ LEFT ][ SIKI1 ][ Y ];
		A[ LEFT  ][ SIKI1 ][ Y ]  = 1;

		//®QÌYÉãüµÄ®Qð(ax = b)Ì`É·é
		int a = A[ LEFT ][ SIKI2 ][ Y ];
		A[ LEFT  ][ SIKI2 ][ X ]  += a * A[ RIGHT ][ SIKI1 ][ X ];
		A[ LEFT  ][ SIKI2 ][ Y ]   = 0;
		A[ RIGHT ][ SIKI2 ][ C ]  += a * A[ RIGHT ][ SIKI1 ][ C ] * (-1.0);
		//XYÌðªÜé
		double answerX = A[ RIGHT ][ SIKI2 ][ C ] / A[ LEFT ][ SIKI2 ][ X ];
		double answerY = (n[2] + n[0]*answerX*(-1.0))/n[1];
		
		//¬æSÊðlÌÜü·é
		if ( (((int)(answerX*10000))%10) >= 5){
			answerX += 0.001;
		}
		if ( (((int)(answerY*10000))%10) >= 5){
			answerY += 0.001;
		}
		if (answerX==-0.0){
			answerX = 0;
		}
		
		//ðÌoÍ
		printf("%.3f %.3f\n", answerX , answerY);
	}

	return 0;
}

Measured memory_bytes: 0
#include <vector>
#include <math.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <deque>
#include <map>

typedef long long ll;
#define rep(i, a, n) for(int i = a; i<n; i++)
#define ALL(a) begin(a), end(a)
#define mii map<int, int>
#define msi map<string, int>
#define vi vector<int>
#define vl vector<ll>
#define MOD 1000000007
#define INF 1e9
#define showVector(v) rep(i,0,v.size()){p(v[i]);p(" ")} pl("")
# define p(s) std::cout << s ;
# define pl(s)  std::cout << s << endl;
using namespace std;

int main() {
    string S;
    cin >> S;
    int count = 0;
    int mx = -1;
    rep(i, 0, S.length()) {
        if (S[i] == 'A' || S[i] == 'C' || S[i] == 'G' || S[i] == 'T') {
            ++count;
        } else {
            mx = max(mx, count);
            count = 0;
            continue;
        }
        mx = max(mx, count);
    }
    cout << mx << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;
using ll = long long;

void print_ans(bool flag){
    if(flag){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }   
}

int main(){
    string w;
    cin >> w;
    bool ans = true;
    if(w.size() % 2 == 1){
        ans = false;
    } else {
        sort(begin(w), end(w));
        for(int i = 0; i < w.size()-1; i+=2){
            ans &= w[i] == w[i+1];
        }
    }
    print_ans(ans);
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
class Program{
    static void Main(string[] args){
    var N = int.Parse(Console.ReadLine());
    List<string> S=new List<string>();
    List<int> P=new List<int>();
    //List<int> I=new List<int>();
    //int[,] P=new int[N,2];
    for(int i=0;i<N;i++){
        var vals = Console.ReadLine().Split().ToList();
        S.Add(vals[0]);
        //P[i,0]=Convert.ToInt32(vals[1]);
        //P[i,1]=i;
        P.Add(Convert.ToInt32(vals[1]));
        //I.Add(i);
    }
    var xy = S.Zip(P, (x, y) => new { x, y })
    .OrderBy(p => p.x)
    .ThenByDescending(p => p.y)
    .ToArray(); 
    for(int i=0;i<N;i++){
        int num = P.IndexOf(xy[i].y) + 1;
        Console.WriteLine(num);
    }
    }
}

Measured memory_bytes: 11744
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int tmp = 1;
		if(n == tmp){
			System.out.println("1");
		}else{
			while(tmp <= n){
				tmp *= 2;
			}
			System.out.println(tmp/2);
		}


 	}
}




Measured memory_bytes: 35676
#include<iostream>
#include<map>
#include<algorithm>
using namespace std;

#define EPS (1e-8)
#define INF (1e8)
int H,W;
string t[100];
bool visited[100][10];
bool visited2[100][10];
bool ans;
int cx,cnt;
double l,r;

void rec(int y,int x){
    if(visited[y][x])return;
    visited[y][x]=true;
    cx+=x;cnt++;
    if(y>0&&(t[y][x]==t[y-1][x]||t[y-1][x]!='.'))rec(y-1,x);
    if(y+1<H&&t[y][x]==t[y+1][x])rec(y+1,x);
    if(x>0&&t[y][x]==t[y][x-1])rec(y,x-1);
    if(x+1<W&&t[y][x]==t[y][x+1])rec(y,x+1);
}

void rec2(int y,int x){
    if(visited2[y][x])return;
    visited2[y][x]=true;
    if(t[y][x]!=t[y+1][x]&&t[y+1][x]!='.'){
        l=min(l,x-0.5);
        r=max(r,x+0.5);
    }
    if(y>0&&t[y][x]==t[y-1][x])rec2(y-1,x);
    if(y+1<H&&t[y][x]==t[y+1][x])rec2(y+1,x);
    if(x>0&&t[y][x]==t[y][x-1])rec2(y,x-1);
    if(x+1<W&&t[y][x]==t[y][x+1])rec2(y,x+1);
}

void init(){
    ans=true;
    for(int i=0;i<100;i++)
        for(int j=0;j<10;j++)
            visited[i][j]=visited2[i][j]=false;
}

int main(){
    while(1){
        cin>>W>>H;
        if(H==0&&W==0)break;
        for(int i=0;i<H;i++)cin>>t[i];
        t[H]="0000000000";
        init();
        for(int i=0;i<H;i++){
            for(int j=0;j<W;j++){
                if(visited2[i][j]||t[i][j]=='.')continue;
                for(int k=0;k<H;k++)
                    for(int l=0;l<W;l++)
                        visited[k][l]=false;
                cx=cnt=0;
                rec(i,j);
                l=INF,r=-INF;
                rec2(i,j);
                double d=(double)cx/(double)cnt;
                if(d<l+EPS || r-EPS<d)ans=false;
            }
        }
        cout<<(ans?"STABLE":"UNSTABLE")<<endl;
    }
    return 0;
}



Measured memory_bytes: 3196
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner scan = null;
		try{
			scan = new Scanner(System.in);
			while(true){
				int n = scan.nextInt();
				int x = scan.nextInt();
				if(n == 0 && x == 0 )break;
				int counter =0;
				for(int i = 1 ;i <= n;i++){
					for(int j = i +1 ; j <= n ; j++){
						for(int k = j + 1; k <= n ; k++){
							if(i + j + k == x)counter++;
						}
					}
				}
				System.out.println(counter);
			}
		}finally{
			if(scan !=null)scan.close();
		}
	}
}

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

int N,W;
int main(){
	while(cin >> N >> W && N>0){
		vector<pair<int,int> > things;
		for(int i=0;i<N;i++){
			int v,w;
			cin >> v >> w;
			things.push_back(make_pair(v,w));
		}
		int V[N+1][W+1] = {{0}};
		for(int i=0;i<N+1;i++){
			for(int j=0;j<W+1;j++){
				if(i==0 || j==0){
					V[i][j] = 0;
				}else if(things[i-1].second>j){
					V[i][j] = V[i-1][j];
				}
				else{
					V[i][j] = max(things[i-1].first + V[i][j-things[i-1].second] , max(things[i-1].first + V[i-1][j-things[i-1].second] , V[i-1][j]));
				}
			}
		}
		cout << V[N][W] << endl;
	}
}

#if 0
所要時間は合計で60分くらい。最初はO(NW^2)解法でTLEだった。改めて漸化式を考え直したら正解にたどり着けた。
#endif


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

int main() {
  int N,M;
  cin >> N;
  M=N*100/108;
  if (M*108/100==N) {
    cout << M << endl;
  }
  if ((M+1)*108/100==N) {
    cout << M+1 << endl;
  }
  if (M*108/100!=N&&(M+1)*108/100!=N) {
    cout << ":(" << endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
priority_queue<int,vector<int>,greater<int> > k;
int main(){
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	k.push(a),k.push(b),k.push(c);
	a=k.top();k.pop();
	b=k.top();k.pop();
	c=k.top();k.pop();
	if(a+b==c) printf("Yes\n");
	else printf("No\n");	
}

Measured memory_bytes: 256
def contains(a, b, n, m):
    def eq(i, j):
        for row in range(m):
            if b[row] != a[i + row][j:j+m]:
                return False
        return True

    for i in range(n - m + 1):
        for j in range(n - m + 1):
            if eq(i, j):
                return True
    return False


if __name__ == '__main__':
    n, m = list(map(int, input().split()))
    a = [list(input()) for _ in range(n)]
    b = [list(input()) for _ in range(m)]
    print('Yes') if contains(a, b, n, m) else print('No')

Measured memory_bytes: 3064
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt(), b = sc.nextInt(), x = sc.nextInt();
		sc.close();
		String ans[] = {"YES", "NO"};
		int an = 0;
		if(a > x)an = 1;
		if(a + b < x)an = 1;
		System.out.println(ans[an]);
	}

}


Measured memory_bytes: 20948
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <ios> 
#include <vector>
#include <string>
#include <algorithm>
//#include <functional>
#include <queue>
//#include <stack>
//#include <set>
#include <cmath>
//#include <bitset>
#include <map>
using namespace std;
typedef long long ll;

int main() {
  ll r,D;
  ll x[11];
  cin >> r >> D;
  cin >> x[0];
  for(int i=1; i<11; i++){
    x[i] = x[i-1]*r -D;
    cout << x[i] << endl;
  }
   

}


Measured memory_bytes: 256
// IO library
#include <cstdio>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>

// container library
#include <deque>
#include <list>
#include <map>
#include <set>
#include <string>
#include <vector>

// namespace
using namespace std;

// typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<VB> VVB;

// container
#define EACH(i, c) for (auto i = (c).begin(); i != (c).end(); i++)
#define SORT(c) sort((c).begin(), (c).end())
#define GSORT(c) sort((c).begin(), (c).end(), greater<decltype((c).front())>())
#define SZ(x) ((int)(x).size())
#define MEMSET(c, v) memset((c), v, sizeof(c))

// repetition
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define NREP(i, n) FOR(i, 1, n + 1)
#define RFOR(i, a, b) for (int i = (a); i >= (b); i--)
#define RREP(i, n) RFOR(i, n, 0)
#define RNREP(i, n) RFOR(i, n, 1)

// constant
// const ll MOD = 1e9 + 7;
// const int INF = 1e9;
// const ll INF = 1e15;
// const int dx[4] = {0, -1, 1, 0};
// const int dy[4] = {-1, 0, 0, 1};
// const int dx[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
// const int dy[8] = {-1, -1, -1, 0, 0, 1, 1, 1};

// debug
#define test(x) cout << #x << " = " << x << endl

// answer output
#define Yes(c) cout << ((c) ? "Yes" : "No") << endl;
#define YES(c) cout << ((c) ? "YES" : "NO") << endl;
#define possible(c) cout << ((c) ? "possible" : "impossible") << endl;
#define POSSIBLE(c) cout << ((c) ? "POSSIBLE" : "INPOSSIBLE") << endl;


// --------------------------------------------------------


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

  int N, oddn = 0, q4n = 0;
  cin >> N;
  REP(i, N) {
    int a;
    cin >> a;
    if (a % 2 == 1) {
      oddn++;
    } else if (a % 4 == 0) {
      q4n++;
    }
  }

  Yes((oddn <= q4n) || (oddn + q4n == N && oddn - q4n <= 1));
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define N 40001
using namespace std;
typedef long long ll;
struct po{ll h,a,d,s;};
 
ll n;
po A[N];
ll hp,a,d,s,sum;
bool compare(po x,po y){
  if(a-x.d<=0||a-y.d<=0)return 0;
 
  ll cnt1=1+(x.h-1)/(a-x.d),cnt2=1+(y.h-1)/(a-y.d);
  ll X=cnt1*(x.a-d)+(cnt1+cnt2)*(y.a-d);
  ll Y=cnt2*(y.a-d)+(cnt1+cnt2)*(x.a-d);
  return X<Y;
}
 
 
ll solve(){
  sort(A,A+n,compare);
  for(int i=0;i<n;i++){
    po t=A[i];
    if(hp<=0)return -1;
    if(a-t.d<=0) return -1;
    ll cost=((t.h-1)/(a-t.d))*sum;
    sum-=t.a-d;
    hp-=(cost+sum);
     
  }
  if(hp<=0)return -1;
  return hp;
}
 
int main(){
  cin>>n;
  cin>>hp>>a>>d>>s;
   
  ll ofs=0;
  for(int i=0;i<n;i++){
    po &t=A[i];
    cin>>t.h>>t.a>>t.d>>t.s;
    if(t.a-d<=0){n--,i--;continue;};
    if(t.s>s) ofs+=(t.a-d);
    sum+=(t.a-d);
  }
   
  ll H = hp;
  hp-=ofs;
  ll ans= H-solve();
  if(H<ans)cout<<-1<<endl;
  else cout<<ans<<endl;
 
  return 0;
}

Measured memory_bytes: 4276
#include <bits/stdc++.h>
using namespace std;
 
int n, k, a=1;
 
int main () {
    cin >> n >> k;
    for (int i = 1; i <= n; i++){
        if (a+k<2*a) {
          a += k;
        }else{
          a *= 2;
          }
    }
    cout << a << endl;
}

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

int main() {
  
  int N;
  int A[199];
  int counter = 0;
  bool odd_exist = false;
  
  cin >> N;
  
  for (int i = 0; i < N; i++) { cin >> A[i]; }
  
  while(true){
    
  	for (int i = 0; i < N; i++) {
       	if (A[i] % 2 != 0 ) {
       		odd_exist = true;
        	break;
        }
    }
	if (odd_exist == true) break;
  	
    counter++;
    for (int i = 0; i < N; i++) { A[i] = A[i] * 0.5;}  
  }
  
  cout << counter << endl;
  return 0;
}


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

using namespace std;

int ans, N, M, K, dp[4017][4017];
const int mod = 1e9 + 7;

void adto (int &x, int y) {x += y; if (x >= mod) x -= mod;}

int main ()
{
scanf ("%d %d %d", &N, &M, &K), M --;
for (int j=1; j<K; j++)
    dp[1][j] = 1;
for (int i=2; i * (K - 1) <= N + M; i++)
    for (int j=0; j<=N + M; j++)
        for (int k=0; k<=j && k<K; k++)
            adto (dp[i][j], dp[i - 1][j - k]);
for (int Q=1; Q * (K - 1) <= N + M; Q++)
    for (int S=1; S<=N; S++)
        if (S % (K - 1) == N % (K - 1) && Q * (K - 1) >= S && Q * (K - 1) - S <= M)
            adto (ans, dp[Q][S]);
printf ("%d\n", ans);
return 0;
}


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

const ll 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 { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= 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 { return mint(*this) /= a;}
};

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

int main(){
    ll n;
    cin >> n;
    map<P, P> mp;
    ll zero=0;
    rep(i, n){
      ll x, y;
      cin >> x >> y;
      if(x==0&&y==0){zero++; continue;}
      ll g = gcd(x,y);
      x/=g; y/=g;
      if(y<0){x=-x;y=-y;}
      if(y==0&&x<0){x=-x;y=-y;}
      bool rot90=(x<=0);
      if(rot90){
        ll tmp = x;
        x=y;y=-tmp;
      }
      if(rot90)mp[P(x,y)].first++;
      else mp[P(x,y)].second++;
    }

    mint ans = 1;
    for(auto p:mp){
      int s = p.second.first;
      int t = p.second.second;
      mint now = 1;
      now += mint(2).pow(s)-1;
      now += mint(2).pow(t)-1;
      ans *= now;
    }
    ans -= 1;
    ans += zero;
    cout << ans.x << endl;
    return 0;
}

Measured memory_bytes: 19212
function Main(input) {
  input = input.split("\n");

  let hasSeven = false;
  for(let i = 0; i < input[0].length; i++){
    if(input[0][i] === '7') {
      hasSeven = true;
      break;
    }
  }
    if(hasSeven){
      console.log("Yes");
    } else {
      console.log("No");
    }
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 30012
#include<stdio.h>
int main(void)
{
	int N[4],count[10];
	for (int i = 0; i < 10; i++) {
		count[i] = 0;
	}
	for (int i = 0; i < 4; i++) {
		scanf("%d", &N[i]);
		count[N[i]]++;
	}
	if (count[1] == 1 && count[4] == 1 && count[7] == 1 && count[9] == 1) {
		printf("YES");
	}
	else {
		printf("NO");
	}
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main()
{
  int a,b,c,d;
  cin>>a>>b>>c>>d;

  while(1)
  {
    c =c - b;
    if(a <= 0 || c <= 0)
    {
      break;
    }
    a = a - d;
  }
  if (a <= 0)
  {
    cout << "No" <<endl;
  }
  else
  {
    cout << "Yes" <<endl;
  }
    return 0;
}

Measured memory_bytes: 3632
n = int(input())
lst =[]
for i in range(n):
	a,b = list(map(int, input().split()))
	tmp = []
	tmp.append(a)
	tmp.append(b)
	lst.append(tmp)


rng = []
for j in range(n):
	c = lst[j][0] - lst[j][1]
	d = lst[j][0] + lst[j][1]
	tmp = []
	tmp.append(c)
	tmp.append(d)
	rng.append(tmp)

rng.sort(key=lambda x:x[1])

ct = 1
rngmax = rng[0][1]
nowmin = rng[0][0]
for k in range(1,n):
	nowmin = rng[k][0]
	if nowmin < rngmax:
		continue
	else:
		rngmax = rng[k][1]
		ct += 1
print(ct)


Measured memory_bytes: 42792
fn main() {
    let mut buff = String::new();
    std::io::stdin().read_line(&mut buff).ok();
    let r: i32 = buff.trim().parse().unwrap();

    let mut buff = String::new();
    std::io::stdin().read_line(&mut buff).ok();
    let g: i32 = buff.trim().parse().unwrap();

    println!("{}", 2 * g - r);
}

Measured memory_bytes: 4352
#include<iostream>
#include<vector>
#include<iostream>

using namespace std;

int main(){

    int Q;
    cin>> Q;
    int C[Q], A[Q], N[Q];
    for(int i=0; i<Q; i++){
        cin>> C[i]>> A[i]>> N[i];
    }

    for(int i=0; i<Q; i++){
        int ans=0;
        int c=C[i], a=A[i], n=N[i];
        int mi=min(c, min(a, n));
        ans+=mi;
        c-=mi; a-=mi; n-=mi;
        int m=min((int)c/2, a);
        ans+=m;
        c-=m*2; a-=m;
        ans+=(int)c/3;

        cout<< ans<< endl;
    }

    return 0;
}

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

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

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

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

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


/*MAIN==================================================*/
signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化
    cout << fixed << setprecision(15);
    
    int n; cin >> n;
    vi x(n), y(n);
    vi p(n);
    rep(i,n) p[i] = i;
    rep(i,n) cin >> x[i] >> y[i];

    double answer = 0;
    do {
        double cnt = 0;
        for(int i = 0; i < n-1; ++i) {
            int a = p[i];
            int b = p[i+1];

            cnt += (sqrt((x[a]-x[b])*(x[a]-x[b]) + (y[a]-y[b])*(y[a]-y[b])));
        }
        answer += cnt;
    }while(next_permutation(all(p)));

    double q = 1;
    for(int i= 1; i <= n; i++) {
        q *= i;
    }

    cout << answer/q << '\n';
}

Measured memory_bytes: 256
package main

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

func main() {
	var wtr = bufio.NewWriter(os.Stdout)
	var N int
	var t int
	fmt.Scan(&N)
	m := make(map[int]int)
	for i := 0; i < N; i++ {
		fmt.Scan(&t)
		m[t] = i + 1
	}
	for i := 1; i < N+1; i++ {
		if i != 1 {
			fmt.Fprintf(wtr, " ")
		}
		fmt.Fprintf(wtr, "%d", m[i])
	}

	_ = wtr.Flush()
}

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

int main() {
    int n;
    cin >> n;
    vector<ll> a(n);
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    ll ans = 0;
    for (int i = 1; i < n; i++)
    {
        if (a[i-1] > a[i]) {
            ans += a[i-1] - a[i];
            a[i] += a[i-1] - a[i];
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4840