akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>   
using namespace std;   
typedef long long ll;
int main()  
{   
    cin.tie(0); ios::sync_with_stdio(false);  
	//freopen("input.txt", "rt", stdin);
	ll n; cin >> n;
	ll C[501];
	ll S[501];
	ll F[501];
	for (int i = 1; i <= n - 1; i++)
		cin >> C[i] >> S[i] >> F[i];

	for (int i = 1; i <= n; i++) {
		ll x = 0;
		for (int j = i; j <= n-1; j++) {
			if (x <= S[j])
				x = S[j];
			else if (x % F[j] != 0)
				x = (x/F[j]+1) * F[j];
			//cout <<"x: " << x << endl;
			x += C[j];
			//cout << "x+c[j] " << x << endl;
		}
		cout << x << endl;
	}
	

	return 0;   
}  

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <cstdio>
#include <cmath>
using namespace std;

#define rep(i, n) for(int i = 0; i < (n); i++)
using ll = long long;

const int mod = 2019;

int main(){
  int l, r;
  cin >> l >> r;
  vector<int> a(mod, 0);
  for(int i = l; i <= r; i++){
    int tmp = i%mod;
    if(a[tmp] == 2)
      break;
    else
      a[tmp]++;
  }
  int ans = mod;
  for(int i = 0; i < mod; i++){
    if(!a[i])
      continue;
    for(int j = i; j < mod; j++){
      if(j == i && a[j] < 2)
        continue;
      if(!a[j])
        continue;
      if(i*j%mod < ans)
        ans = i*j%mod;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

signed main(){
	int n;cin>>n;
	int Min=INT_MAX;
	for(int i=1;i<n;i++){
		int a=i,b=n-i;
		int c=0;
		while(a){
			c+=a%10;
			a/=10;
		}
		while(b){
			c+=b%10;
			b/=10;
		}
		Min=min(Min,c);
	}
	cout<<Min<<endl;
}

Measured memory_bytes: 764
#include<iostream>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int main()
{
    int h,a,ans=0;
    cin>>h>>a;
    while (h>0)
    {
        h-=a;
        ans++;
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {

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

		while(true){
			final int q1 = sc.nextInt();
			
			if(q1 == 0){
				break;
			}
			
			final int b  = sc.nextInt();
			final int c1 = sc.nextInt();
			final int c2 = sc.nextInt();
			final int q2 = sc.nextInt();
			
			boolean solved = false;
			int max_buy = 0;
			
			for(int buy = 1; buy <= q2; buy++){
				final int rest_money = b - buy * c1;
				
				if(rest_money < 0){
					break;
				}
				
				final int buy_normal = rest_money / c2;
				
				if(buy_normal + buy < q1){
					continue;
				}
				
				solved = true;
				max_buy = buy;
			}
			
			if(solved){
				System.out.println(max_buy + " " + ((b - max_buy * c1) / c2));
			}else{
				System.out.println("NA");
			}
		}
	}
}

Measured memory_bytes: 18208
#include <bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
  
int main() {
  int n;
  cin >> n;
  if(n < 1200){
    cout << "ABC";
  }
  else if(n < 2800){
    cout << "ARC";
  }
  else{
    cout << "AGC";
  }
 
  return 0;
}



Measured memory_bytes: 256
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby
    #from itertools import product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    h,w,d = map(int, input().split())
    a = [list(map(int, input().split())) for _ in range(h)]

    zahyou = [[] for _ in range(d)]
    for x in range(h):
        for y in range(w):
            b = a[x][y] % d
            zahyou[b].append([a[x][y], x, y])

    mp = [[] for _ in range(d)]
    for i in range(d):
        xy = zahyou[i]
        xy.sort()
        mp[i].append(0)
        cx, cy = xy[0][1:]
        for j in range(1, len(xy)):
            mp[i].append(abs(xy[j][1]-cx)+abs(xy[j][2]-cy))
            cx, cy = xy[j][1:]
        mp[i] = list(accumulate(mp[i]))
    
    q = int(input())
    for _ in range(q):
        l, r = map(int, input().split())
        amari = l % d
        l = (l-1) // d
        r = (r-1) // d
        print(mp[amari][r] - mp[amari][l])

if __name__ == '__main__':
    main()

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

const int MAXN = 1.1e5;
int N;
set<int> adj[MAXN];

int par[MAXN];
int getpar(int a) {
	return par[a] == -1 ? a : (par[a] = getpar(par[a]));
}

int main() {
	ios::sync_with_stdio(0), cin.tie(0);
	cin >> N;
	for (int i = 0; i < N-1; i++) {
		int a, b; cin >> a >> b;
		adj[a].insert(b);
		adj[b].insert(a);
	}
	vector<pair<int, int>> todos;
	for (int i = 0; i < N-1; i++) {
		int a, b; cin >> a >> b;
		if (adj[a].count(b)) {
			todos.emplace_back(a, b);
		} else {
			adj[a].insert(b);
			adj[b].insert(a);
		}
	}

	for (int i = 1; i <= N; i++) par[i] = -1;
	int numEdges = 0;
	while (!todos.empty()) {
		int a, b; tie(a, b) = todos.back();
		todos.pop_back();
		a = getpar(a);
		b = getpar(b);
		if (a == b) continue;
		numEdges++;

		if (adj[a].size() > adj[b].size()) {
			swap(a, b);
		}
		adj[a].erase(b);
		adj[b].erase(a);
		par[a] = b;
		for (int c : adj[a]) {
			adj[c].erase(a);
			if (adj[b].count(c)) {
				todos.emplace_back(b, c);
			} else {
				adj[b].insert(c);
				adj[c].insert(b);
			}
		}
		set<int>().swap(adj[a]);
	}
	cout << (numEdges == N-1 ? "YES" : "NO") << '\n';

	return 0;
}


Measured memory_bytes: 26624
import java.io.CharArrayReader;
import java.lang.reflect.Array;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String n = sc.next();
        if(Character.isUpperCase(n.charAt(0)))System.out.println('A');
        else System.out.println('a');
    }
}


Measured memory_bytes: 35628
import java.util.*

val sc = Scanner(System.`in`)
val A = sc.nextInt()
val B = sc.nextInt()
val S:String = sc.next()

fun main(args: Array<String>) {
    var flg = false

    for (i in 0 until S.length) {
        if (i == A) {
            if (S[i] != '-') {
                flg = true
            }
        } else {
            if (S[i] == '-') {
                flg = true
            }
        }
    }
    println(arrayOf("Yes","No")[if (flg) 1 else 0])
}


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

#define pb push_back
#define ff first
#define ss second

const long long MAXN = 1e5 + 21, inf = 1e18 + 21, LG = 20;

int n, l;
int a[MAXN];
pair <int, int> dp[MAXN];

int main() {
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    cin >> n >> l;
    for (int i = 0; i < n; i++)
        cin >> a[i];
    for (int i = 1; i < n; i++)
        dp[i] = make_pair(a[i] + a[i - 1], i);
    sort(dp + 1, dp + n);

    if (l > dp[n - 1].ff)
        return cout << "Impossible" << '\n', 0;

    cout << "Possible" << '\n';
    
    for (int i = 1; i < dp[n - 1].ss; i++)
        cout << i << '\n';

    for (int i = n - 1; i >= dp[n - 1].ss; i--)
        cout << i << '\n';
    
    return 0;
}


Measured memory_bytes: 2048
N = gets.to_i
digit = N.to_s.length

arr = [3, 5, 7]
ans = 0
(3..digit).each do |d|
    (3**d).times do |trits|
        use = []
        sum = 0
        d.times do |i|
            sum *= 10
            num = arr[trits % 3]
            use[num] = true
            sum += num
            trits /= 3
        end
        if arr.all?{|i| use[i]} && sum <= N
            ans += 1
        end
    end
end
puts ans

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

int main() {

  int x,a,b;
  cin >> x >> a >> b;
  int ansa = x-a;
  int ansb = x-b;
  
  if(ansa<0){
   ansa = a-x;
  }
  if(ansb<0){
   ansb = b-x;
  }
  if(ansa<ansb){
    cout << "A" << endl;
  }else{
    cout << "B" << endl;
  }
}


Measured memory_bytes: 256
// in case of multiple test cases and N=1e5 don't intialize arrays as global except for graph vector-array
// always check whether or not you are doing mod of a negative number
// always use 1LL instead of 1
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
 
using namespace __gnu_pbds;
using namespace std;

// using long doubles saves you from corner cases but is very time consuming
#define double      	long double
#define int         	long long
#define pb          	push_back
#define pii         	pair<int,int>
#define vi          	vector<int>
#define vii         	vector<pii>
#define mi          	map<int,int>
#define mii         	map<pii,int>
#define all(a)      	(a).begin(),(a).end()
#define sz(x)       	(int)x.size()
// just comment the line below in case of interactive problems
#define endl        	"\n"
#define repp(i,a,b) 	for(int i=a;i<b;i++)
#define rep(i,a,b) 		for(int i=a;i<=b;i++)
#define brep(i,a,b)     for(int i=a;i>=b;i--)
#define deb1(x)      	cout << #x << "=" << x << endl
#define deb2(x, y)  	cout << #x << "=" << x << "," << #y << "=" << y << endl
#define deb3(x, y, z)  	cout << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define trace(v) 		for(auto it=v.begin();it!=v.end();it++)cout<<*it<<" ";cout<<endl;
#define tracearr(a,l,r) for(int iii=l;iii<=r;iii++)cout << a[iii] << " ";cout << endl;
#define PI          	3.1415926535897932384626
#define F 				first
#define S 				second
#define clr(x,y) 		memset(x, y, sizeof(x))
#define IOS         	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);


typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
// *s.find_by_order(1) - gives the 2nd samllest element in set
// s.order_of_key(x)   - gives the number of elements in the set which are strictly smaller than x


const int N=1e5 + 5;


int32_t main()
{
	IOS;
	int T=1;
	//cin >> T;
	// int numOfSetBits = __builtin_popcountll(n);
	std::cout << std::fixed << std::setprecision(12);
	while(T--)
	{
		int n;
		cin >> n;
		int ans = 0;
		rep(i,1,n-1)
			ans += (n-1)/i;
		cout << ans; 
	}
}

Measured memory_bytes: 3648
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <math.h>
#include <algorithm>
#include <cstring>
 
using namespace std;
 
int main() {
  int D,N;
  cin >> D >> N;
  long int X = pow(100,D);
  if(N==100)
    N++;
  long int Y = N*X;
  cout << Y;
  return 0;
}

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

int main() {
  int N; 
  cin >> N;
  int A[N];
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  
  pair<int, int> school[N];
  for (int i = 0; i < N; i++) {
    school[i].first = A[i];
    school[i].second = i + 1;
  }
  
  sort(school, school + N);
  
  for (int i = 0; i < N - 1; i++) {
    cout << school[i].second << " ";
  }
  cout << school[N - 1].second << endl;
}

Measured memory_bytes: 2048
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
	int x, y;
	cin >> x;
	cin >> y;

	while (y != 0){
		if (y > x){
			swap(x, y);
		}
		int bx = x;
		int by = y;
		x = by;
		y = bx%y;
	}
	cout << x << endl;
}

Measured memory_bytes: 3044
#include <stdio.h>
#include <string>
#include <iostream>
#include <iomanip>
#include <map>
#include <algorithm>
#include <vector>
#include <math.h>
#define INF 1000000007
using namespace std;

int main(void) {
	int n,m,q;
	cin >> n >> m >> q;
	int l,r,train[501][501];
	for(int i=0; i<=n; i++){
		for(int j=0; j<=n; j++){
		train[i][j]=0;
		}
	}
	for(int i=0; i<m; i++){
		cin >> l >> r;
		train[l][r]++;
	}
	for(int i=1; i<=n; i++)for(int j=1; j<=n; j++)train[i][j]+=train[i][j-1];
	for(int i=1; i<=n; i++)for(int j=1; j<=n; j++)train[i][j]+=train[i-1][j];
	for(int i=0; i<q; i++){
		cin >> l >> r;
		cout << train[r][r]+train[l-1][l-1]-train[l-1][r]-train[r][l-1] << endl;
	}
	return 0;
}

Measured memory_bytes: 1920
#include <bits/stdc++.h> 
using namespace std; 
#define ll long long int
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define vll vector<ll>
#define all(v) v.begin(),v.end()
#define INF ll(1e18)
#define MOD 1000000007

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

 ll n,m,c,i,j;
  cin>>n>>i>>j;
 	c=i/n;
 	if(i%n==0)
 		cout<<"OK\n";
 	else if((c+1)*n<=j)
 		cout<<"OK\n";
 	else 
 		cout<<"NG\n";
}

Measured memory_bytes: 3604
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

//#define LOCAL 0
//#ifdef LOCAL
//#define DEBUG(s) cout << (s) << endl
//#define dump(x)  cerr << #x << " = " << (x) << endl
//#define BR cout << endl;
//#else
//#define DEBUG(s) do{}while(0)
//#define dump(x) do{}while(0)
//#define BR
//#endif


//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30)
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007
//ここから編集する


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


    [] {
        [] {
            [] {
                int N;

                cin >> N;
                vector<int> a(N);
                rep(i, 0, N) {
                    cin >> a[i];
                }

                sort(all(a));
                reverse(all(a));

                int ant = 0;
                int bom = 0;

                rep(i, 0, N) {
                    if (i % 2)bom += a[i];
                    else ant += a[i];
                }
                cout << ant - bom << endl;
            }();

        }();
    }();

    return 0;
}


Measured memory_bytes: 888
use proconio::input;
use std::cmp::min;
use std::cmp::Reverse;
use std::collections::BinaryHeap;

fn main(){
    input! {
        n : usize,
        m : usize,
        s : usize
    };
    let max_s = 50 * n;
    let mut dist = vec![vec![1i64 << 60; max_s + 1]; n];
    let mut g : Vec<Vec<(usize, usize, i64)>> = vec![Vec::new(); n];
    for _ in 0..m {
        input! {
            u : usize,
            v : usize,
            a : usize,
            b : i64
        }
        g[u-1].push((v-1, a, b));
        g[v-1].push((u-1, a, b));
    }
    input! {
        c : [(usize, i64); n]
    };
    let mut res = vec![1i64 << 60; n];
    let mut qu = BinaryHeap::<Reverse<(i64, usize, usize)>>::new();
    qu.push(Reverse((0, 0, min(max_s, s))));
    dist[0][min(max_s, s)] = 0;
    while !qu.is_empty() {
        let Reverse((cur_cost, cur_pos, cur_s)) = qu.pop().unwrap();
        res[cur_pos] = min(res[cur_pos], cur_cost);
        let charge_s = min(max_s, cur_s + c[cur_pos].0);
        if cur_cost + c[cur_pos].1 < dist[cur_pos][charge_s] {
            dist[cur_pos][charge_s] = cur_cost + c[cur_pos].1;
            qu.push(Reverse((dist[cur_pos][charge_s], cur_pos, charge_s)));
        }
        for &(next_pos, next_s, next_cost) in &g[cur_pos] {
            if cur_s < next_s { continue; }
            if cur_cost + next_cost < dist[next_pos][cur_s - next_s] {
                dist[next_pos][cur_s - next_s] = cur_cost + next_cost;
                qu.push(Reverse((dist[next_pos][cur_s - next_s], next_pos, cur_s - next_s)));
            }
        }
    }
    for i in 1..n { println!("{}", res[i]); }
}

Measured memory_bytes: 4736
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include <string.h>

int main(void) {
	int n;
	char str[1001] = "";
	char command[10] = "";
	char command_word1[10] = "print";
	char command_word2[10] = "reverse";
	char command_word3[10] = "replace";

	char replace[1000] = "";

	scanf("%s", str);
	scanf("%d", &n);
	

	for (int i = 0; i < n; i++) {
		scanf("%s", command);

		if (strcmp(command, command_word1) == 0) {
			//print
			int start, end;
			scanf("%d %d", &start, &end);

			for (; start <= end; start++) {
				printf("%c", str[start]);
			}
			printf("\n");
		}

		else if (strcmp(command, command_word2) == 0) {
			//reverse
			int start, end;
			char temp;
			scanf("%d %d", &start, &end);

			for (; start <= end; start++, end--) {
				temp = str[start];
				str[start] = str[end];
				str[end] = temp;
			}
		}

		else if (strcmp(command, command_word3) == 0) {
			//replace
			int start, end;
			scanf("%d %d %s", &start, &end, replace);

			for (int j = 0; start <= end; j++, start++) {
				str[start] = replace[j];
			}
		}
	}
	return 0;
}


Measured memory_bytes: 2108
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <set>
#include <sstream>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort(ALL(x))
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){

    std::fill( (T*)array, (T*)(array+N), val );
}

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

bool IsPrime(ll num){
    if(num < 2) return false;
    else if(num == 2) return true;
    else if(num % 2 == 0) return false;
    double sqrtNum = sqrt(num);
    for(ll i = 3; i <= sqrtNum; i += 2){
        if(num%i==0) return false;
    }
    return true;
}


signed main(){
  int n; cin>>n;
  VI a(n),b(n),c(n);
  rep(i,n) cin>>a[i]; rep(i,n) cin>>b[i]; rep(i,n) cin>>c[i];
  sort(ALL(a)); sort(ALL(b)); sort(ALL(c));
  ll idx = 0; VL d(n);
  rep(i,n){
    while(b[i]>a[idx]&&idx<n){
      idx++;
    }
    d[i] = idx;
  }
  rep(i,n) cerr << d[i] << endl;
  ll cnt = 0;
  idx = 0;
  ll ans = 0;
  rep(i,n){
    while(c[i]>b[idx]&&idx<n){
      cnt += d[idx];
      idx++;
    }
    cerr << cnt << endl;
    ans += cnt;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 2304
#include<iostream>
#include<unordered_map>
#include<algorithm>
#include<vector>
#include<string>
#include<string.h>
#include<unordered_set>
#include<map>
#include<queue>
#include<iomanip>
#include<tgmath.h>







/*
_
_._ _..._ . - ',     _.._(`))
'-. `     ' / -._. - '    ', /
)         \            '.
/ _    _ | \
| a    a    /              |
\   . - .;
'-('' ).-', '       ;
'-;           |      .'
\           \    /
| 7.__  _. - \   \
| |  |  ``/ / `  /
/, _|  |   /, _/   /
/, _ / '`-'
*/
using namespace std;




int main() 
{
    int x;
    cin >> x;
    long long happy = 0;
    happy = (x / 500) * 1000;
    x -= (x / 500) * 500;
    happy += (x / 5) * 5;
    cout << happy;

}
    


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import numpy as np

def mapper(x): 
    if x >= 3200:
        return -1;
    else:
        return x // 400

n = input()
stage = np.array(list(map(int, input().split())))

r = np.count_nonzero(np.vectorize(mapper)(stage) == -1)
s = len(set(np.vectorize(mapper)(stage).tolist())-set([-1]))

print(max(s,1), s+r)


Measured memory_bytes: 12504
object Main extends App {
	val N = scala.io.StdIn.readInt
	val x = scala.io.StdIn.readLine

	val a: Array[Int] = new Array(N)
	val b: Array[Int] = new Array(9)

	for(i <- 0 until N){
		a(i) = x.split(" ")(i).toInt
	}

	def find(x: Int):Int = {
		if(1<=x && x<=399){
			return 0;
		}else if(400<=x && x<=799){
			return 1;
		}else if(800<=x && x<=1199){
			return 2;
		}else if(1200<=x && x<=1599){
			return 3;
		}else if(1600<=x && x<=1999){
			return 4;
		}else if(2000<=x && x<=2399){
			return 5;
		}else if(2400<=x && x<=2799){
			return 6;
		}else if(2800<=x && x<=3199){
			return 7;
		}else{
			return 8;
		}
	}

	for(i<- 0 until N){
		val t = find(a(i))

		b(t) = b(t) + 1;
	}

	var count = 0

	for(i<- 0 to 7){
		if(b(i) != 0) count = count + 1
	}

	if(b(8) == 0){
		println(count + " " + count)
	}else if(count == 0){
		val u = count + b(8)
		println("1 " + u)
	}else if(count == 0 && b(8) == 0){
		println("0 0")
	}else{
		val u = count + b(8)
		println(count + " " + u)
	}
	
}

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

#define rep(i,n) for(int i = 0; i < n; i++)
#define REP(i,n) for(int i = 1; i < n; i++)
#define per(i,n) for(int i = n; i >= 0; i--)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
#define fi first
#define se second
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
using vs = vector<string>;
using vb = vector<bool>;
using vc = vector<char>;
using vcc = vector<vc>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
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; }

bool ch(vector<P> v) {
  int d = 0, mn = 0;
  for(P p : v) {
    mn = min(mn, d + p.fi);
    d += p.se;
  }
  if(mn < 0) return false;
  else return true;
}

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

  int n;
  cin >> n;
  vector<P> ls, rs;
  int tot = 0;
  rep(i,n) {
    string s;
    cin >> s;
    int d = 0, mn = 0;
    rep(j,sz(s)) {
      if(s[j] == '(') d++;
      else d--;
      mn = min(d, mn);
    }
    if(d >= 0) ls.emplace_back(mn, d);
    else rs.emplace_back(mn-d, -d);
    tot += d;
  }
  sort(rall(ls));
  sort(rall(rs));
  YesorNo(ch(ls) && ch(rs) && tot == 0);
}

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

using namespace std;

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

  vector<long long> C(N);
  vector<vector<long long> > A(N);
  for (int i = 0; i < N; ++i) {
    A[i].resize(M);
    cin >> C[i];
    for (int j = 0; j < M; ++j) {
      cin >> A[i][j];
    }
  }


  long long ret = 10000000000;
  long long lim = pow(2, N);
  for (int i = 0; i < lim; ++i) {
    vector<long long> u(M);
    long long cost = 0;
    for (int j = 0; j < N; ++j) {
      if ((i >> j) & 1) {
        cost += C[j];
        for (int k = 0; k < M; ++k) {
          u[k] += A[j][k];
        }
      }
    }
    bool okay = true;
    for (int j = 0; j < M; ++j) {
      if (u[j] < X) {
        okay = false;
        break;
      }
    }
    if (okay)
      ret = min(ret, cost);
  }

  if (ret == 10000000000)
    cout << -1 << endl;
  else
    cout << ret << endl;

  return 0;
}

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

using namespace std;

int n;

double cnt;

int a[105];

int main(void)

{

	cin >> n;

	for (int i = 0; i < n; i++)

	{

		cin >> a[i];

	}

	for (int i = 0; i < n; i++)

	{

		cnt += 1.0 / a[i];

	}

	cout << 1 / cnt << endl;

	return 0;

}


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

ll f(ll n){
    if(n%4==0) return n;
    if(n%4==1) return 1;
    if(n%4==2) return n^1;
    if(n%4==3) return 0;
}

int main(){
    ll a, b;
    cin >> a >> b;
    if(a==0){
        cout << (f(b)^0) << endl;
    }else{
        cout << (f(b)^f(a-1)) << endl;
    }
    return 0;
    // ll a, b;
    // cin >> a >> b;
    // ll num = b-a+1;

    // if(a==b){
    //     cout << a << endl;
    //     return 0;
    // }

    // ll out = 0;
    // rep(i, 41){
    //     // cout << out << endl;
    //     ll tmp1 = num / pow(2, i+1);
    //     ll rem = num - tmp1 * pow(2, i+1);
    //     // cout << rem << endl;
    //     if(rem!=0){
    //         ll tmp2 = a / pow(2, i+1);
    //         ll rem2 = a - tmp2 * pow(2, i+1);
    //         int tmp=0;
    //         if(rem2 >= pow(2, i)){
    //             if(rem2+rem-1 <= pow(2, i+1)-1){
    //                 tmp = rem;
    //             }else{
    //                 tmp = (pow(2, i+1)-rem2);
    //             }
    //         }else{
    //             if(rem2+rem-1-pow(2, i)>0){
    //                 tmp = rem2+rem-pow(2, i);
    //             }
    //         }
    //         cout << tmp << endl;
    //         tmp = tmp%2;
    //         out += pow(2, i)*tmp;
    //     }    
    // } 
    // cout << out << endl;
    // return 0;

}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>

using namespace std;

//#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ; //何もしない文
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size()) //unsignedのサイズをint型に変換
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const LL MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

inline LL add(LL x,LL y)
{
    return (x + y)%MOD;
}

inline LL sub(LL x,LL y)
{
    return (x+MOD-y)%MOD;
}

inline int mul(int x,int y)
{
    return (LL)x*y%MOD;
}

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    LL n,m; cin>>n>>m;
    vector<LL> x(n),y(m);
    REP(i,n) cin>>x[i];
    REP(j,m) cin>>y[j];

    LL el1=0,el2=0;
    REP(k,n)
    {
        //if(k*x[k] > 0){
            el1 = add(el1, k*x[k]);
        //}
        //else el1 = sub(el1,k*x[k]);

        //if(el1 < 0) el1 += MOD;
        //if((n-k-1LL)*x[k] > 0){
            el1 = sub(el1, (n-k-1LL)*x[k]);
        //}
        //else el1 = add(el1,(n-k-1LL)*x[k]);
        //if(el1 < 0) el1 += MOD;
    }
    dump(el1)
    REP(k,m)
    {
        //if(k*y[k] > 0){
            el2 = add(el2, k*y[k]);
        //}
        //else el2 = sub(el1,k*y[k]);


        el2 = sub(el2, (m-k-1LL)*y[k]);
        //if(el2 < 0) el2 += MOD;

    }
    dump(el2)
    LL ans = el1 * el2 % MOD;
    //if(ans < 0) ans += MOD;
    cout << ans << endl;

}

Measured memory_bytes: 1792
#include <stdio.h>
#include <string.h>

int main(void)
{
    char A[1001];
    char B[1001];
    int len_a, len_b;
    int i, j;
    int flag;
    
    scanf("%s%s", A, B);
    
    len_a = strlen(A);
    len_b = strlen(B);
    
    flag = 0;
    for (i = 0; i < len_a - len_b + 1; i++){
        for (j = 0; j < len_b; j++){
            if (B[j] == '_'){
                continue;
            }
            if (B[j] != A[i + j]){
                break;
            }
        }
        if (j == len_b){
            flag = 1;
            break;
        }
    }
    
    if (flag == 0){
        printf("No\n");
    }
    else {
        printf("Yes\n");
    }
    
    return (0);
}



Measured memory_bytes: 2112
S = input()
T = input()
lt = len(T)
ans_min = len(T)
for i in range(len(S)-lt+1):
    s_tmp = S[i: i + lt]
    ans_tmp = 0
    for j in range(lt):
        if s_tmp[j] != T[j]:
            ans_tmp += 1
    ans_min = min(ans_min, ans_tmp)
print(ans_min)


Measured memory_bytes: 9044
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30
#define pb push_back
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int main() {
	int n, m;
	while(cin >> n && n) {
		vector<P> v(n);
		rep(i, n) cin >> v[i].first >> v[i].second;

		cin >> m;
		vector<P> p(m);
		rep(i, m) cin >> p[i].first >> p[i].second;

		sort(v.begin(), v.end());
		sort(p.begin(), p.end());

		vector<P> d(n);
		rep(i, n) {
			d[i].first = v[i].first - v[0].first;
			d[i].second = v[i].second - v[0].second;
		}

		int a = 0, b = 0;
		rep(i, m) {
			bool flag = true;

			rep(j, n) {
				P t(p[i].first + d[j].first, p[i].second + d[j].second);
				if(binary_search(p.begin(), p.end(), t)) continue;
				flag = false;
			}

			if(flag) {
				a = p[i].first - v[0].first;
				b = p[i].second - v[0].second;
			}
		}

		cout << a << " " << b << endl;
	}

	return 0;
}

Measured memory_bytes: 1212
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
const int M=1e5+5;
struct stu{
	int id;
	int val;
	stu(){
	}
	stu(int a,int b){
		id=a;
		val=b;
	}
	bool operator < (const stu &s)const{
		return val<s.val;
	}
};
int n,num;
int a[M];
vector<stu>v;
int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>num;
		v.push_back(stu(i+1,num));
	}
	sort(v.begin(),v.end());
	for(int i=0;i<v.size()-1;i++)
	{
		cout<<v[i].id<<" ";
	}
	cout<<v[v.size()-1].id<<endl;
	return 0;
}

Measured memory_bytes: 1780
#include<iostream>
#include<cstdio>
#include<cmath>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define INF 1e6
using namespace std;

int main(){
	int n,m;
	while(cin>>n>>m,n||m){
		double dt[n][n],dp[m][n];
		rep(i,n)rep(j,n)cin>>dt[i][j];
		rep(i,m)rep(j,n)dp[i][j]=-1*INF;
		rep(i,n)dp[0][i]=1.0;
		rep(i,m-1){
			rep(j,n){
				rep(k,n){
					dp[i+1][k]=max(dp[i+1][k],dp[i][j]*dt[j][k]);
				}
			}
		}
		double ans=-1;
		rep(i,n)ans=max(ans,dp[m-1][i]);
		printf("%.2f\n",ans);
	}
	return 0;
}

Measured memory_bytes: 1332
#include <algorithm>
#include <array>
#include <cassert>
#include <iostream>
#include <vector>
using namespace std;

template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename T, size_t size> ostream& operator<<(ostream &os, const array<T, size> &arr) { os << '{'; string sep; for (const auto &x : arr) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }

void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }

#ifdef NEAL_DEBUG
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif


int main() {
    ios::sync_with_stdio(false);
#ifndef NEAL_DEBUG
    cin.tie(nullptr);
#endif

    int N;
    cin >> N;
    vector<int> A(N + 1);

    for (auto &a : A)
        cin >> a;

    auto &&fail = [] {
        cout << -1 << '\n';
        exit(0);
    };

    vector<int64_t> A_suffix(N + 2, 0);

    for (int i = N; i >= 0; i--)
        A_suffix[i] = A_suffix[i + 1] + A[i];

    int64_t nodes = 1, answer = 0;

    for (int d = 0; d <= N; d++) {
        answer += nodes;

        if (nodes < A[d])
            fail();

        nodes -= A[d];
        nodes = min(2 * nodes, A_suffix[d + 1]);
    }

    if (nodes > 0)
        fail();

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


Measured memory_bytes: 4800
from collections import defaultdict
mod = 10**9 + 7

n = int(input())
cnt = {}
cnt[3] = defaultdict(lambda: 0)

def ok_quad(s):
  if 'AGC' not in s and 'AGC' not in s[1]+s[0]+s[2]+s[3] and 'AGC' not in s[0]+s[2]+s[1]+s[3] and 'AGC' not in s[0]+s[1]+s[3]+s[2]:
    return True
  else:
    return False
l = list('AGCT')
i = 3
for c1 in l:
  for c2 in l:
    for c3 in l:
      s = c1 + c2 + c3
      if s != 'AGC' and s != 'GAC' and s != 'ACG':
        cnt[i][s] += 1

for nn in range(4,n+1):
  cnt[nn] = defaultdict(lambda: 0)
  for ss in cnt[nn-1].keys():
    for c in l:
      sq = ss + c
      if ok_quad(sq):
        st = sq[1:]
        cnt[nn][st] += cnt[nn-1][ss] % mod

sm = sum(cnt[n].values()) % mod
print(sm)



Measured memory_bytes: 4204
#include<stdio.h>
int main(void){
    int N,i,I;
    double n;
    scanf("%d",&N);
    n=N/1.08;
    i=n;
    I=i*1.08;
    if (I==N) {
        printf("%d\n",i);
        return 0;
    }
    i=n+1;
    I=i*1.08;
    if(I==N){
        printf("%d\n",i);
        
    }
    else{
        printf(":(\n");
    }
    return 0;
}


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

using namespace std;

int main(){
	long long N;
  	cin >> N;
  	string rev = "";
  	while(N){
      --N;
      rev += (char)('a' + (N%26));
      N /= 26;
    }
  	reverse(rev.begin(),rev.end());
  	cout << rev << endl;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define mod 998244353 //((int)1e9+7)
#define lim 1000000000000000007
#define lim1 18446744073709551615  //Unsigned
#define sq(a) ((a)*(a))
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define mms(v,i) memset(v,i,sizeof(v))
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define REP(i,a,b) for (int i = a; i <= b; i++)
#define REPN(i,a,b) for (int i = a; i >= b; i--)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int,int> pi;
typedef pair<ll,ll> PL;
typedef pair<ll,int> PLI;
typedef pair<int,ll> PIL;
typedef pair<int,pair<int,int> > pii;
typedef pair<double,double> pdd;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
ll power(ll a,ll b) {
   ll res=1;
   while(b){
      if(b%2==1) res=(res*a)%mod;
      a=(a*a)%mod;
      b>>=1;
   }
   return res;
}
ll gcdll(ll a,ll b) {
    if (b==0) return a;
    return gcdll(b,a%b);
}
int gcd(int a,int b) {
    if (b==0) return a;
    return gcd(b,a%b);
}

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

const int N = (int)2e5+5;
const int M = (int)3e3+5;
const int Q = 102;
const int logN = 19;

const double pie = acos(-1);

int dp[M][M];
void solve() {
    dp[0][0] = 1;
    int n,s,a;
    cin>>n>>s;
    REP(i,1,n) {
        cin>>a;
        REP(j,0,s) {
            dp[i][j] = 2*dp[i-1][j]%mod;
            if(j>=a) dp[i][j] = (dp[i][j] + dp[i-1][j-a])%mod;
        }
    }
    cout<<dp[n][s];
}
int main() {
    //freopen("output.txt","r",stdin);
    //freopen("output.txt","w",stdout);

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

    int T=1;
    //cin>>T;
    REP(TC,1,T) {
        //cout<<"Case #"<<TC<<": ";
        solve();
        cout<<"\n";
    }
}


Measured memory_bytes: 38864
#include<bits/stdc++.h>
using namespace std;
#define uld unsigned long long
#define int long long
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)



signed main(){
    FAST;
    int n=5;
    int a[n];
    cin>>a[0]>>a[1]>>a[2]>>a[3]>>a[4];
    for(int i=0; i<n; i++){
        if(a[i]==0) {cout<<i+1<<endl; break;}
    }
}


Measured memory_bytes: 3608
n,q=map(int,input().split())
s=input()
    
dp =[0 for j in range(n)]


for j in range(n):
    t=0
    if s[j]=="C" and j!=0:
        if s[j-1]=="A":
            t=1

    dp[j]=dp[j-1]+t
        

for i in range(q):
    l,r=map(int,input().split())
    print(dp[r-1]-dp[l-1])

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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define repr(i,n) for(int i=(int)(n-1);i>=0;i--)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout << #x" = " << x << endl
#define print(x) cout << x << endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<int, P> PIP;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;
typedef set<int> S;

#define INF INT_MAX/3
#define MAX_N 1000000001

int kakezan(string n, int times) {
    if (n.size() == 1) return times;
    int maxi = 0;
    repl(i, 1, n.size()) {
        int a = stoi(n.substr(0, i)), b = stoi(n.substr(i, n.size() - i));
        maxch(maxi, a * b);
    }
    return kakezan(to_string(maxi), times + 1);
}


int main(){
    cin.sync_with_stdio(false);
    int q;
    cin >> q;
    rep(i, q) {
        string n;
        cin >> n;
        cout << kakezan(n, 0) << endl;
    }

    return 0;
}

Measured memory_bytes: 3268
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
int main()
{
    int N, L;
    cin >> N >> L;
    vector<string> S(N);
    rep(i, N)
    {
        cin >> S[i];
    }
    sort(all(S));
    rep(i, N)
    {
        cout << S[i];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
from math import sqrt

n = int(input())

def factorize(n):    
    A = set()
    
    for i in range(1, int(sqrt(n)) + 1):
        if n % i == 0:
            A.add(i)
            A.add(n // i)

    return A

A = factorize(n)
ans = 0

for a in A:
    q = n // a
    m = a - 1
    if q < m:
        ans += m

print(ans)

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

class cake {
public:
    int b, w, d;
    cake(int birth, int width, int depth)
        : b(birth), w(width), d(depth) {}
    bool operator<(const cake& r) const {
        if(b != r.b) return b < r.b;
        else return w*d < r.w*r.d;
    }
};

bool compare_area(const cake& r, const cake& l) {
    return r.w*r.d < l.w*l.d;
}

int main(void){
    vector<cake> C;
    int n, w, d, p, s;
    while(cin >> n >> w >> d && w && d) {
        C.clear();
        C.push_back(cake(0, w, d));
        rep(i, n) {
            cin >> p >> s;
            p--;
            sort(C.begin(), C.end());
            s = s%(C[p].w+C[p].d);
            if(s < C[p].w) {
                C.push_back(cake(i+1, C[p].w-s, C[p].d));
                C[p] = cake(i+1, s, C[p].d);
            } else {
                s -= C[p].w;
                C.push_back(cake(i+1, C[p].w, C[p].d-s));
                C[p] = cake(i+1, C[p].w, s);
            }
        }
        sort(C.begin(), C.end(), compare_area);
        rep(i, n) cout << C[i].w*C[i].d << " ";
        cout << C[n].w*C[n].d << endl;
    }
}

Measured memory_bytes: 1204
//標準関数をすべてインクルードする。
#include <bits/stdc++.h>
using namespace std;
map <long long, long long> M;

long long f(long long h, long long n){

    if(M.count(h) == 1) return M[h];
    M[h] = 2 * f(h /2, n) + 1;

    return M[h];
}

int main(){
    //cin coutを高速化
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	std::cout.tie(0);

    long long h;
    cin >> h;
    long long res = 0;
    M[0] = 0;
    M[1] = 1;
    if (h != 0)
        res = f(h, 0);

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int N_MAX=200001;
int p=998244353;
typedef long long ll;
typedef pair<int,int> P;
int main()
{
  int n,k,i,j;
  P l[10];
  ll res;
  ll r[N_MAX];
  cin >> n >> k;
  for(i=0;i<k;i++)
    cin >> l[i].first >> l[i].second;
  r[0]=0;
  r[1]=1;
  for(i=2;i<=n;i++){
    r[i]=r[i-1];
    for(j=0;j<k;j++){
      if(i-l[j].first>=0)
        r[i]+=r[i-l[j].first];
      if(i-l[j].second>0)
        r[i]-=r[i-l[j].second-1];
    }
    r[i]%=p;
  }
  res=(r[n]-r[n-1])%p;
  if(res<0)
    res+=p;
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 5156
import sys
readline = sys.stdin.readline
write = sys.stdout.write
def solve():
    ipt = readline()
    if ipt == "0\n":
        return False
    q1, b, c1, c2, q2 = map(int, ipt.split())
    for p1 in range(q2, 0, -1):
        b1 = b - p1*c1
        if b1 < 0:
            continue
        p2 = b1 // c2
        if p1 + p2 >= q1:
            write("%d %d\n" % (p1, p2))
            break
    else:
        write("NA\n")
    return True
while solve():
    ...



Measured memory_bytes: 5608
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
using namespace std;
int main(void){
    int n,k;
    int num =1;
    cin >> n >> k;
    rep(i, n){
        num = min(num*2, num+k);
    }
    cout << num << endl;
}

Measured memory_bytes: 256
a, v = map(int, input().split())
b, w = map(int, input().split())
t = int(input())

ds = v - w

if ds <= 0: # 逃げている方が早い
    print("NO")
else:
    dd = abs(a-b)

    dt = float(dd)/float(ds)

    if dt <= t:
        print("YES")
    else:
        print("NO")

Measured memory_bytes: 9188
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <ctime>
#include <map>
#include <stack>
#include <sstream>

using namespace std;

int main(void)
{
	int a, b, h;
	cin >> a;
	cin >> b;
	cin >> h;

	cout << ((a + b)*h) / 2 << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd_(ll a,ll b){if(a%b==0)return b;return gcd_(b,a%b);}
ll lcm_(ll a,ll b){ll c=gcd_(a,b);return ((a/c)*(b/c)*c);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e16)+ll(7);
const ll MOD=1000000007LL;
#define out(a) cout<<fixed<<setprecision((a))
//tie(a,b,c) = make_tuple(10,9,87);
#define pop_(a) __builtin_popcount((a))
ll keta(ll a){ll r=0;while(a){a/=10;r++;}return r;}



int main(){

  ll a,b;
  cin >> a;
  b = a + a*a + a*a*a;
  cout << b << endl;
}




Measured memory_bytes: 3652
n = int(input())
list_AB = [ list(map(int,input().split(" "))) for _ in range(n)]
mins = []
maxs = []
for a, b in list_AB:
    mins.append(a)
    maxs.append(b)

mins.sort()
maxs.sort()

if n % 2 == 1:
    ans = maxs[n//2] - mins[n//2] + 1
else:
    small = mins[n//2] + mins[n//2-1]
    large = maxs[n//2] + maxs[n//2-1]
    ans = large - small +1

print(ans)

Measured memory_bytes: 49348
import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter

val br = BufferedReader(InputStreamReader(System.`in`))
val out = PrintWriter(System.out)

fun main() {
    br.use { out.use {
        solve()
        out.flush()
    } }
}

fun solve() {
    val (x1, y1, x2, y2) = readIntegerList()
    val x3 = x2 + (y1 - y2)
    val y3 = y2 + (x2 - x1)
    val x4 = x1 + (y1 - y2)
    val y4 = y1 + (x2 - x1)
    out.println("$x3 $y3 $x4 $y4")
}

fun readInteger() = Integer.parseInt(br.readLine())
fun readLong() = java.lang.Long.parseLong(br.readLine())
fun readStringList() = br.readLine()!!.split(' ')
fun readIntegerList() = readStringList().map(Integer::parseInt)
fun readLongList() = readStringList().map(java.lang.Long::parseLong)
fun readDoubleList() = readStringList().map(java.lang.Double::parseDouble)


Measured memory_bytes: 36360
/// 1:55 PM 25/04/20
/// Author: t_bone_289 (An Immature Programmer.... I'm still developing !!)
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
#define pll pair<ll,ll>
#define fi first
#define se second
#define mp make_pair
#define pb emplace_back
#define endl '\n'
#define M 1000000007
#define error(x) cout << #x << " = " << x << endl;
#define pi 3.14159265358979323846
typedef long long ll;
typedef long double ld;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

template<typename T>
void ContainerError(T &v);

ll powmod(ll base, ll exp, ll MOD);

ll mpow(ll base, ll exp);

ll gcd(ll a, ll b);

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    ll n,m;
    cin >> n>> m;
    if(m>=n) {
        cout<<"unsafe";
    } else
    {
        cout << "safe";
    }
    return 0;
}

template<typename T>
void ContainerError(T &v) {
    cout << "{";
    for (auto &x:v) { cout << x << ','; }
    cout << "}" << endl;
    return;
}

ll powmod(ll base, ll exp, ll MOD) {
    ll res = 1;
    while (exp > 0) {
        if (exp % 2 == 1) res = (res * base) % MOD;
        base = (base * base) % MOD;
        exp /= 2;
    }
    return (res % MOD);
}

ll mpow(ll base, ll exp) {
    ll res = 1;
    while (exp > 0) {
        if (exp % 2 == 1) res = (res * base);
        base = (base * base);
        exp /= 2;
    }
    return (res);
}

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



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

#define rep3(i, s, n ,a) for (int i = (s); i < (int)(n); i+=a)
#define rep2(i, s, n) rep3(i, s, n, 1)
#define rep(i, n) rep2(i, 0, n)

#define MOD 1000000007

int main(){
    int n, k;
    cin >> n >> k;
    vector<long> rui;
    long sum = 0;
    rep(i, n+1){
        sum += i;
        //sum %= MOD;
        rui.push_back(sum);
    }
    long ans=0;
    rep2(i, k, n+1){
        long big, little;
        big = rui[n] - rui[n-i];
        little = rui[i-1];
        ans = ans + big - little + 1 % MOD; 
    }
    ans++;
    ans %= MOD;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5368