akhauriyash/Code-Regression huggingface dataset:
o[256],z[257];main(N,S,A,C,s,a,c,r,i){for(;scanf("%d",&N),N;printf("%d %d %d\n",S,A,C)){
	double H=999,h,n=N;
	for(i=1;i<=N;i++)scanf("%d",z+i);
	for(s=0;s<16;s++)for(a=0;a<16;a++)for(c=0;c<16;c++){
		for(r=s,h=0,i=1;i<=N;i++)o[(z[i]+(r=(a*r+c)%256))%256]++;
		for(i=0;i<256;i++)if(o[i])h-=o[i]/n*log(o[i]/n),o[i]=0;
		if(h+1e-9<H)H=h,S=s,A=a,C=c;
	}
}exit(0);}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#define rep(i, n)   for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

struct point{
    int x;
    int y;
    int cost;
    point(){
        x = 0;
        y = 0;
        cost = 0;
    }
    point(int x, int y, int cost = 0){
        this->x = x;
        this->y = y;
        this->cost = cost;
    }
    bool operator < (const point &a) const{
        return cost < a.cost;
    }
    bool operator > (const point &a) const{
        return cost > a.cost;
    }
    void print(){
        printf("x:%2d y:%2d cost:%3d\n", x, y, cost);
    }
};

vector<vector<char>>g;
int h, w;

int Dijkstra(point c, point d){
    priority_queue<point, vector<point>, greater<point>>que;
    que.push(c);
    int dx[4] = {0, 1, 0, -1};
    int dy[4] = {1, 0, -1, 0};
    vector<vector<bool>>visited(h, vector<bool>(w, false));
    while(!que.empty()){
        point now = que.top();  que.pop();
        if(visited[now.y][now.x])   continue;
        visited[now.y][now.x] = true;
        if(now.x == d.x && now.y == d.y)    return now.cost;
        point next;
        rep(i, 4){
            next = now;
            next.x += dx[i];
            next.y += dy[i];
            if(next.x < 0 || next.x >= w || next.y < 0 || next.y >= h)  continue;
            if(g[next.y][next.x] == '#')    continue;
            if(visited[next.y][next.x])     continue;
            que.push(next);
        }
        /*
         * warp
         */
        rep(i, 5)   rep(j, 5){
            next = now;
            next.x += i-2;
            next.y += j-2;
            if(next.x < 0 || next.x >= w || next.y < 0 || next.y >= h)  continue;
            if(g[next.y][next.x] == '#')    continue;
            if(visited[next.y][next.x])     continue;
            que.push(point(next.x, next.y, now.cost+1));
        }
    }
    return -1;
}

int main(){
    cin >> h >> w;
    g.resize(h);
    rep(i, h)   g[i].resize(w);
    point c;    cin >> c.y >> c.x;
    c.x--;  c.y--;
    point d;    cin >> d.y >> d.x;
    d.x--;  d.y--;
    rep(i, h)   rep(j, w)   cin >> g[i][j];
    cout << Dijkstra(c, d) << endl;
}


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

int main()
{
    int n = 0;
  cin >>n;
    vector<int> d(n);
    for (int i = 0; i < n; i++)
    {
        cin >> d[i];
    }
    sort(d.begin(), d.end());
    int sa = 0;
    sa = d[n / 2 ] - d[n / 2-1];
    cout << sa << endl;
}


Measured memory_bytes: 640
import java.util.Scanner;
 
class Main {
	int n;
	int[] h;
	int[] cost;
	
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		Main m = new Main(sc);
		m.solve();
	}
	Main(Scanner sc){
		n = sc.nextInt();
		h = new int[n];
		cost = new int[n];
		for(int i = 0; i < n;i++){
			h[i] = sc.nextInt();
			cost[i] = Integer.MAX_VALUE;
		}
		cost[0] = 0;
	}
	int cntString(String str,char target){
		int cnt = 0;
		for(char s : str.toCharArray()){
			if(s == target){
				cnt++;
			}
		}
		return cnt;
	}
	void solve(){
		for(int i = 0;i < n-1;i++){
			cost[i+1] = Math.min(cost[i+1], cost[i] + Math.abs(h[i]-h[i+1]));
			if(i+2<n){
				cost[i+2] = Math.min(cost[i+2], cost[i] + Math.abs(h[i]-h[i+2]));
			}
		}
		System.out.println(cost[n-1]);
	}
}


Measured memory_bytes: 63300
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef pair<string, string> SS;

const int maxn = 500550;
const int inf = 0x3f3f3f3f;
const int mod = 998244353;
const ll linf = 2e18;
#define debug(x) cout << #x << " " << x << "\n";
int n, m;
ll v[maxn], w[maxn], G[maxn];

int main()
{
    ios::sync_with_stdio(0);
    int i, j, k;

    cin >> n >> m >> k;
    for (i = 0; i < n; i++)
        cin >> v[i];
    for (i = 0; i < m; i++)
    {
        cin >> w[i];
        if (i > 0)
            G[i] = w[i] + G[i - 1];
        else
            G[i] = w[i];
    }
    ll x = 0, y, ans = upper_bound(G, G + m, k) - G;
    for (i = 0; i < n; i++)
    {
        x += v[i];
        y = k - x;
        if (y < 0)
            break;
        j = upper_bound(G, G + m, y) - G;
        //debug(j);
        ans = max(ans, i + j + 1ll);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 8328
/*
AtCoder Library Practice Contest - A - Disjoint Set Union
https://atcoder.jp/contests/practice2/tasks/practice2_a
*/


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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<string, string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef vector<ll> vl;
typedef vector<vl> vvl;

double EPS=1e-9;
int INF=1000000005;
long long INFF=1000000000000000005ll;
double PI=acos(-1);
int dirx[8]={ -1, 0, 0, 1, -1, -1, 1, 1 };
int diry[8]={ 0, 1, -1, 0, -1, 1, -1, 1 };
const ll MOD = 1000000007;

#define DEBUG fprintf(stderr, "====TESTING====\n")
#define VALUE(x) cerr << "The value of " << #x << " is " << x << endl
#define OUT(x) cout << x << endl
#define OUTH(x) cout << x << " "
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define READ(x) for(auto &(z):x) cin >> z;
#define FOR(a, b, c) for (int(a)=(b); (a) < (c); ++(a))
#define FORN(a, b, c) for (int(a)=(b); (a) <= (c); ++(a))
#define FORD(a, b, c) for (int(a)=(b); (a) >= (c); --(a))
#define FORSQ(a, b, c) for (int(a)=(b); (a) * (a) <= (c); ++(a))
#define FORC(a, b, c) for (char(a)=(b); (a) <= (c); ++(a))
#define EACH(a, b) for (auto&(a) : (b))
#define REP(i, n) FOR(i, 0, n)
#define REPN(i, n) FORN(i, 1, n)
#define MAX(a, b) a=max(a, b)
#define MIN(a, b) a=min(a, b)
#define SQR(x) ((ll)(x) * (x))
#define RESET(a, b) memset(a, b, sizeof(a))
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ALL(v) v.begin(), v.end()
#define ALLA(arr, sz) arr, arr + sz
#define SIZE(v) (int)v.size()
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define SORTA(arr, sz) sort(ALLA(arr, sz))
#define REVERSEA(arr, sz) reverse(ALLA(arr, sz))
#define PERMUTE next_permutation
#define TC(t) while (t--)
#define FAST_INP  ios_base::sync_with_stdio(false);cin.tie(NULL)


void solve() {

}

int main()
{
    FAST_INP;
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt","r", stdin);
    // freopen("output.txt","w", stdout);
    // #endif

//    int tc; cin >> tc;
//    TC(tc) solve();
	int n, q, t, u, v;
	cin >> n >> q;
	dsu d = dsu(n);
	REP(i,q){
		cin >> t >> u >> v;
		if(t==0) d.merge(u,v);
		else {
			OUT(d.same(u,v));
		}
	}

    return 0;
}


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

using namespace std;

struct edge {
    int to;
    int cost;
    edge(int a, int b) : to(a), cost(b) {}
};

vector<vector<edge>> e;
int N;

pair<int, int> dfs(int p, int par = -1)
{
    pair<int, int> res = make_pair(0, p);
    for (auto x : e[p]) {
        if (x.to == par) continue;
        auto t = dfs(x.to, p);
        t.first += x.cost;
        res = max(res, t);
    }
    return res;
}

int main()
{
    cin >> N;
    e.resize(N);
    for (int i = 0; i < N-1; i++) {
        int s, t, w;
        cin >> s >> t >> w;
        e[s].emplace_back(t, w);
        e[t].emplace_back(s, w);
    }
    auto res = dfs(0);
    res = dfs(res.second);
    cout << res.first << endl;
}


Measured memory_bytes: 15872
#include <stdio.h>

int main(void)
{
	float ax, bx, cx, dx;
	float ay, by, cy, dy;
	float abx, aby, cdx, cdy, ab, cd;
	int n, i;
	
	scanf("%d", &n);
	
	
	for (i = 0; i < n; i++){
		
		scanf("%f%f%f%f%f%f%f%f", &ax, &ay, &bx, &by, &cx, &cy, &dx, &dy);
		
		abx = bx - ax;
		aby = by - ay;
		cdx = dx - cx;
		cdy = dy - cy;
		
		ab = aby / abx;
		cd = cdy / cdx;
		
		if (ab == cd)printf("YES\n");
		else printf("NO\n");
	}
	
	return 0;
}

Measured memory_bytes: 616
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

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

using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repr(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	unsigned r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
map<ll, ll> prime_factor(ll n) {
	map<ll, ll> ret;
	for (ll i = 2; i * i <= n; i++) {
		while (n % i == 0) {
			ret[i]++;
			n /= i;
		}
	}
	if (n != 1) ret[n] = 1;
	return ret;
}

const long long MOD = 1000000007;
//const long long MOD = 998244353;
const long long INF = 1LL << 60;



const long double PI = 3.14159265359;
const int MAX_N = 100010;


signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	string s; cin >> s;
	int n = s.size();
	rep(bit, 1 << (n - 1)) {
		int now = 0;
		rep(i, n) {
			if (i == 0) {
				now += s[i] - '0';
			}
			else {
				if (bit & (1 << (i-1))) {
					now += s[i] - '0';
				}
				else {
					now -= s[i] - '0';
				}
			}
		}
		if (now == 7) {
			rep(i, n) {
				if (i == 0) {
					cout << s[i];
				}
				else {
					if (bit & (1 << (i-1))) {
						cout << "+" << s[i];
					}
					else {
						cout << "-" << s[i];
					}
				}
			}
			cout << "=7" << endl; return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 256
S = list(input())
ans = [0]*len(S)
R = 1
r = 0
L = 0
l = 0
for i in range(1,len(S)):
  if S[i-1] == "R" and S[i-1] == S[i]:
    R += 1
  elif S[i-1] == "R" and S[i] == "L":
    L += 1
    r = i-1
    l = i
  elif S[i-1] == "L" and S[i] == "L":
    L += 1
  elif (S[i-1] == "L" and S[i] == "R"):
    ans[r] += (R+1) //2 + L//2
    ans[l] += R //2 + (L+1)//2
    R = 1
    L = 0
  if i == len(S)-1:
    ans[r] += (R+1) //2 + L//2
    ans[l] += R //2 + (L+1)//2
    
print(*ans)
    
  
  


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

using namespace std;

int main(){
    int n;
    long long a, b, x;
    long long res = 0, curp = 0;
    cin >> n >> a >> b;
    for(int i = 0; i < n; i ++){
        cin >> x;
        if(!i){
            curp = x;
            continue;
        }
        long long d = x - curp;
        res += min(a * d, b);
        curp = x;
    }
    cout << res << endl;
}


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

#define REP(i,n) for (int i=0;i<(n);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)

using namespace std;

int main() {
    int D, G;
    cin >> D >> G;
    vector<int> p(D), c(D);
    REP(i, D) cin >> p[i] >> c[i];
    int result = INT_MAX;
    REP(b, 1 << D) {
        int score = 0;
        int solved = 0;
        REP(i, D) {
            if (b & 1 << i) {
                score += 100 * (i + 1) * p[i] + c[i];
                solved += p[i];
            }
        }
        RREP(i, D) {
            if (score >= G) {
                break;
            }
            if ((b & 1 << i) == 0) {
                int point = 100 * (i + 1);
                int to_solve = min((G - score + point - 1) / point, p[i] - 1);
                score += point * to_solve;
                solved += to_solve;
            }
        }
        if (score >= G) {
            result = min(result, solved);
        }
    }
    cout << result << endl;
    return 0;
}

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

using namespace std;
using namespace std::chrono;

#define rep(i,a,b) for(int i = a;i<(b);++i)
#define trav(a,v) for(auto& a : v)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;

ll big = 1000000007ll;
ll big2 = 1000000009ll;
ll n,m,T,k,q,p,x;


int main()
{
   // freopen("input.txt","r",stdin);
    //freopen("autput.txt","w",stdout);
    ll a,b,c,d,e;

    string s;
    ll F[200001] = {0};
    cin >> s;
    ll ans = 0;
    for(ll c1 = 0; c1 < s.length(); c1++){
        a = ll(s[c1])-ll('a');
        ans += c1-F[a];
        F[a]++;
    }
    cout << ans+1 << "\n";
    return 0;
}


Measured memory_bytes: 2180
#include <atcoder/convolution>
#include <iostream>
#include <vector>
using ll = long long;
#define rep(i, j, n) for (int i = 0; i < n; ++i)
using namespace std;
constexpr int MOD = 998244353;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n), b(m);
  rep(i, 0, n) cin >> a[i];
  rep(i, 0, m) cin >> b[i];
  auto c = atcoder::convolution<MOD>(a, b);
  rep(i, 0, n + m - 1) cout << c[i] << '\n';
  return 0;
}

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

const int N = 150, M = 1e5+100;
long long mem[N][M], n, w, arrW[M], V[M];

long long DP(int i, int we){

    if(we > w || i >= n)
        return 0;
    if(mem[i][we] != -1)
        return mem[i][we];

    long long op1 = we +arrW[i] <= w ? (DP(i+1, we + arrW[i]) + V[i]) : 0;  //Take
    long long op2 = DP(i+1, we);  //Leave
    return mem[i][we] = max(op1, op2);
}

int main() {
    memset(mem, -1, sizeof(mem));
    scanf("%d %d",&n, &w);
    for(int i = 0 ; i < n ; ++i) {
    	scanf("%d", arrW + i);
    	scanf("%d", V + i);
    }
    //for(int i = 0 ; i < w ; ++i)    scanf("%d", V + i);
    printf("%lld", DP(0, 0));

    return 0;
}

Measured memory_bytes: 117504
use std::io::*;
use std::str::FromStr;
use std::cmp;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();

    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: usize = read();
    let mut a: [usize; 20] = [0; 20];
    //有向グラフ -1：未証言、0：不親切な人と証言、1：正直者と証言
    let mut g: [[i16; 15]; 15] = [[-1; 15]; 15];

    for i in 0..n {
        a[i] = read();
        for _j in 0..a[i] {
            let x: usize = read();
            let y = read();
            let x = x - 1;
            g[i][x] = y;
        }
    }

    let mut ans = 0; 
    let mut bits: u16 = 0;
    while bits < (1 << n) { //2^n
        //1人につき正直者か不親切な人いずれかを1bitで割り当てる
        //3人なら3bitで表現でき、全パターン(bit)探索する場合
        //3bitは000,001,010,011,100,101,111の7パターン
        //これは、1<<3=0b1000=8となるので 
        // { i = 0 ;i < (1 << 3); i++}
        //でループさせれば全bit探索できる。
        //println!("bits:{:0>8b}, 1<<n:{:0>8b}", bits, 1<<n);

        // 1なら正直者とする
        //dの中に正直者と不親切の割当を入れる。 bitsの立っているパターンと同値
        let mut d = vec![0; n];
        for i in 0..n {
            if ((bits >> i) & 1) == 1 {
                d[i] = 1;
            }
        }
        //println!("bits:{:0>3b}, vec:{:?}", bits, d);

        let mut ok: bool = true;
        for i in 0..n {
            //証言に矛盾がないか判定する
            //正直者と仮定した人に対して証言をチェックする
            if d[i] == 1 {
                for j in 0..n {
                    if g[i][j] == -1 { continue; }
                    if g[i][j] != d[j]  { ok = false; } 
                }
            }
        }
        if ok { 
            ans = cmp::max(ans, bits.count_ones());
        }

        bits += 1;
    }
    println!("{}", ans);
}


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

int main(){
    string security_code;
    cin >> security_code;

    if (security_code[0] == security_code[1]){
        cout << "Bad" << endl;
        return 0;
    }
    if (security_code[1] == security_code[2]){
        cout << "Bad" << endl;
        return 0;
    }
    if (security_code[2] == security_code[3]){
        cout << "Bad" << endl;
        return 0;
    }

    cout << "Good" << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

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

        long n = sc.nextLong();

        System.out.println(check("0", n));
    }

    static int check(String s, long i) {
        int cnt = 0;
        if (Long.parseLong(s) > i)
            return 0;

        if (s.contains("7") && s.contains("5") && s.contains("3"))
            cnt++;
        cnt += check(s + "7", i);
        cnt += check(s + "5", i);
        cnt += check(s + "3", i);
        return cnt;
    }
}


Measured memory_bytes: 34132
#include<stdio.h>
int main()
{
	int n,day,x,i,y,k=0;
	scanf("%d%d%d",&n,&day,&x);
	for(i=0;i<n;i++){
		scanf("%d",&y);
		k+=(day-1)/y+1;
	}
	printf("%d",k+x);
	 return 0;


}

Measured memory_bytes: 128
# https://atcoder.jp/contests/abc103/tasks/abc103_d

import sys
input = sys.stdin.readline

N, M = map(int, input().split())
schedule = []
for i in range(M):
    start, end = map(int, input().split())
    schedule.append((start, end))               # schedule = (始点、終点)

schedule = sorted(schedule, key=lambda x: x[1])
ans = 0
end = -10**12                                   # 始点の最小値

for i in range(M):
    if end <= schedule[i][0]:                   # 重複が OK ならば等号を加える
        end = schedule[i][1]                    # 終点でソートされているので、自動的に可能な中で最速の終点が選ばれている
        ans += 1

print(ans)

Measured memory_bytes: 85932
n=int(input())
a=[0]*n
for i in range(n):
    a[i]=int(input())
dp=[0]*10001
dp[0]=1
for i in range(n):
    for j in range(10000,-1,-1):
        if dp[j]>0:
            dp[j+a[i]]+=1
f=0
for i in range(10000,-1,-1):
    if dp[i]>0 and i%10!=0:
        print(i)
        f=1
        break
if f==0:
    print(0)

Measured memory_bytes: 40300
import java.util.Scanner;

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

		String s = sc.next();

		System.out.println(solve(s));
	}

	private static int solve(String s) {

		int count = 0;

		for (int i = 0; i < s.length()-1; i++) {
			if (s.charAt(i) == 'W' && s.charAt(i+1) == 'B') {
				count++;
			}
			else if(s.charAt(i) == 'B' && s.charAt(i+1) == 'W') {
				count++;
			}
		}

		return count;
	}
}


Measured memory_bytes: 26128
def gcd(a, b):
    while b > 0:
        a, b = b, a % b
    return a


def divisor(a):
    res = set()
    for i in range(1, int(a * 0.5 + 1) + 1):
        if a % i == 0:
            res.add(i)
            res.add(a // i)
    return sorted(res)


a, b, k = map(int, input().split())
ans = divisor(gcd(a, b))[-k]
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
 
using ll=long long;
 
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define pb push_back
#define eb emplace_back
#define a first
#define b second
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
const ll MOD = 1e9 + 7;


int main() {
    int n; ll h;
    cin >> n >> h;
    vector<int> bs;
    ll maxa = 0; 
    rep(i, n) {
        ll a, b; cin >> a >> b;
        maxa = max(a, maxa);
        bs.push_back(b); 
    }
    sort(all(bs), greater<int>());
    int cnt = 0; 
    rep(i, n) {
        if (bs[i] < maxa) break;
        h -= bs[i];
        ++cnt;
        if (h <= 0) break;
    } 
    if (h > 0) cnt += (h+maxa-1) / maxa; 
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 892
#include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <utility>
#include <map>
#include <stack>
#include <set>
#include <vector>
#include <queue>
#include <deque>
#define x first
#define y second
#define mp make_pair
#define pb push_back
#define LL long long
#define Pair pair<int,int>
#define LOWBIT(x) x & (-x)
using namespace std;

const int MOD=1e9+7;
const int INF=484848;
const int magic=348;

int n;
vector<int> v[1048];
int son[1048][5048],dp[1048];
int p[1048];

void dfs(int cur)
{
	int i,j;
	for (i=0;i<v[cur].size();i++) dfs(v[cur][i]);
	for (i=0;i<int(v[cur].size());i++)
		for (j=0;j<=5000;j++)
		{
			son[i+1][j]=INF;
			if (j>=p[v[cur][i]]) son[i+1][j]=min(son[i+1][j],son[i][j-p[v[cur][i]]]+dp[v[cur][i]]);
			if (j>=dp[v[cur][i]]) son[i+1][j]=min(son[i+1][j],son[i][j-dp[v[cur][i]]]+p[v[cur][i]]);
		}
	dp[cur]=son[int(v[cur].size())][p[cur]];
}

int main ()
{
	int i,j,x;
	scanf("%d",&n);
	for (i=2;i<=n;i++)
	{
		scanf("%d",&x);
		v[x].pb(i);
	}
	for (i=1;i<=n;i++) scanf("%d",&p[i]);
	dfs(1);
	if (dp[1]<INF) printf("POSSIBLE\n"); else printf("IMPOSSIBLE\n");
	return 0;
}

Measured memory_bytes: 20736
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'
const int INF=1e9+5;
const int N=2e3+5;
const int mod=998244353;

void max_self(int& a,int b){
	if(a<b) a=b;
}

void min_self(int& a,int b){
	if(b<a) a=b;
}

string s[3];
bool ok[3][3][N];

bool ask(int i,int j,int k){
	if(k>=(int)s[i].size()) return 1;
	return ok[i][j][k];
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	for(int i=0;i<3;++i) cin>>s[i];
	sort(s,s+3);
	int ans=INF;
	do{
		for(int i=0;i<3;++i){
			for(int j=0;j<3;++j){
				for(int k=0;k<(int)s[i].size();++k){
					if(i>=j) continue;
					bool check=1;
					for(int ni=k;ni<(int)s[i].size();++ni){
						int nj=ni-k;
						if(nj>=(int)s[j].size()) break;
						if(s[i][ni]=='?'||s[j][nj]=='?') continue;
						if(s[i][ni]!=s[j][nj]) check=0;
					}
					ok[i][j][k]=check;
				}
			}
		}
		for(int i=0;i<N;++i){
			for(int j=0;j<N;++j){
				if(!ask(0,1,i)) continue;
				if(!ask(1,2,j)) continue;
				if(!ask(0,2,i+j)) continue;
				int cur=0;
				max_self(cur,(int)s[0].size());
				max_self(cur,i+(int)s[1].size());
				max_self(cur,i+j+(int)s[2].size());
				min_self(ans,cur);
			}
		}
	}
	while(next_permutation(s,s+3));
	cout<<ans;
	return 0;
}


Measured memory_bytes: 256
a,b = map(int,input().split())
if a == 0:
    if b > 1988:
        print("H{}".format(b-1988))
    elif b > 1925:
        print("S{}".format(b-1925))
    elif b > 1911:
        print("T{}".format(b-1911))
    else:
        print("M{}".format(b-1867))
elif a == 1:
    print(b+1867)
elif a == 2:
    print(b+1911)
elif a == 3:
    print(b+1925)
else:
    print(b+1988)


Measured memory_bytes: 5596
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main()
{
    const int dirx[4] = {  1,  0, -1,  0 };
    const int diry[4] = {  0,  1,  0, -1 };

    while(true){
        int w, h;
        cin >> w >> h;
        if ( w == 0  &&  h == 0 )
            break;

        vector<string> wall(2*h-1); //このような場合はそのまま文字列として保存
        cin.ignore();
        for ( int i=0; i<2*h-1; i++ )
            getline( cin, wall[i] );

        vector<vector<int> > dist( h, vector<int>( w, 0 ) );
        dist[0][0] = 1;

        for ( int d=1; d<w*h; d++ ){
          for ( int y=0; y<h; y++ ){
            for ( int x=0; x<w; x++ ){
              if ( dist[y][x] == d ){
                for ( int r=0; r<4; r++ ){
                  int tx = x + dirx[r];
                  int ty = y + diry[r];

                  if ( 0 <= tx  &&  tx < w  &&
                       0 <= ty  &&  ty < h  &&
                      wall[ty+y][tx+x] == '0'  &&
                      dist[ty][tx] == 0 ){
                    dist[ty][tx] = d + 1;
                  }
                }
              }
            }
          }
        }

        cout << dist[h-1][w-1] << endl;
    }
}



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

int main() {
  vector<vector<int>> c(3, vector<int>(3));

  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
      cin >> c[i][j];
      //cout << c[i][j];
    }
  //  cout<<endl;
  }
  int a2,a3,b1,b2,b3;
  for (int a1=0;a1<=c[0][0];a1++){
    b1 = c[0][0]-a1;
    b2 = c[0][1]-a1;
    b3 = c[0][2]-a1;
    a2 = c[1][0]-b1;
    a3 = c[2][0]-b1;
    if(a2+b2==c[1][1] && a3+b2==c[2][1] && a2+b3==c[1][2] && a3+b3==c[2][2]){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No"<<endl;

}


Measured memory_bytes: 256
#include <stdio.h>
int main(void) {

int al[30] = {0};
char b[2000]= {0};
int i,j,n;

i=0;

while( scanf("%c",&b[i]) != EOF) {

    if (b[i] >= 'A' && 'Z' >= b[i] ) {
        n = b[i] - 'A';
        al[n] += 1;
    } 
    else if(b[i] >=  'a' && b[i] <= 'z' ) {
        n = b[i] - 'a';
        al[n] += 1;
    }
    i=i+1;
}

for(j=97; j<=122; j++) {
    n = j - 'a';
    printf("%c : %d\n",j,al[n]);
}

return 0;
}


Measured memory_bytes: 2100
import java.util.*;

class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] X = new int[N];
		long ans=Long.MAX_VALUE;
		
		for (int i=0; i<N; i++) {
			X[i] = sc.nextInt();
		}
		
		for (int i=1; i<101; i++) {
			long min = 0;
			
			for (int j=0; j<N; j++) {
				min += (X[j]-i)*(X[j]-i);
			}
			ans = Math.min(ans, min);
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 25044
r=[]
for i in range(230):
    A=i-125
    for j in range(230):
        B=j-125
        r.append((A**5-B**5,A,B))
r.sort()

target=int(input())
lwbd = 0
upbd = len(r)


while lwbd<=upbd:
    middle = lwbd + (upbd-lwbd)//2
    if(r[middle][0]==target):
        break
    elif r[middle][0]>target:
        upbd = middle -1
    else:
        lwbd = middle +1
print(r[middle][1],r[middle][2])

Measured memory_bytes: 15772
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

// #define DEBUG_MODE
#ifdef DEBUG_MODE
#define dump(x) cout << #x << " : " << x << endl
#define LINE cout << "line : " << __LINE__ << endl
#define dumpV(v) cout << #v << " : ["; for(auto& t : v) cout << t << ", "; cout<<"]" << endl
#define STOP assert(false)
#else
#define dump(x) ;
#define LINE     ;
#define dumpV(v);
#define STOP     ;
#endif
#define mp make_pair

namespace std{
  template<class S,class T>
  ostream &operator <<(ostream& out,const pair<S,T>& a){
    out<<'('<<a.fi<<", "<<a.se<<')';
    return out;
  }
}


template<typename T>
struct BIT{
    vector<T> s;
    int n;
    BIT(int n_) : n(n_+1), s(n_+1) {};
    T sum(int i) {
        ++i;
        T ret = 0;
        while(i > 0) {
            ret += s[i];
            i -= i & -i;
        }
        return ret;
    }
    // [l, r)
    T query(int l, int r) {
        return sum(r-1) - sum(l-1);
    }
    void add(int i, T x) {
        ++i;
        while(i <= n) {
            s[i] += x;
            i += i & -i;
        }
    }
    void update(int i, T x) {
        add(i, x-query(i, i+1));
    }
};

int main(){
    string s;
    cin >> s;
    int n = s.size();
    map<char, deque<int>> mp;
    rep(i, n) mp[s[i]].push_back(i);
    {
        int odd = 0;
        REP(c, 'a', 'z'+1) {
            if(mp.count(c)) odd += (mp[c].size()%2);
        }
        if(odd > 1) {
            cout << -1 << endl;
            return 0;
        }
    }
    BIT<int> bit(n);
    ll ans = 0LL;
    rep(i, n) bit.add(i, 1LL);
    for(auto& c : s) {
        dump(c);
        auto& d = mp[c];
        int len = bit.query(0, n);
        if(len == 0) break;
        if(d.size() == 1) {
            int i = d.front();
            d.pop_front();
            int x = bit.query(0, i+1);
            ans += abs((len+1)/2 - x);
            bit.add(i, -1);
        }
        else if(d.size() > 0) {
            int i = d.front(), j = d.back();
            d.pop_front(); d.pop_back();
            int x = bit.query(0, i+1);
            int y = bit.query(0, j+1);
            dump(pii(i, x));
            dump(pii(j, y));
            assert(x == 1);
            ans += len - y;
            bit.add(i, -1);
            bit.add(j, -1);
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main()
{
    long long A, V, B, W;
    cin >> A >> V >> B >> W;
    long long T;
    cin >> T;
    long long D1 = abs(A - B);
    long long D2 = (V - W) * T;
    cout << (D1 <= D2 ? "YES" : "NO") << endl;
    return 0;
}

Measured memory_bytes: 3612
/*
 * a.c
 *
 *  Created on: 2014/06/27
 *      Author: nana
 */


#include<stdio.h>

int left(int i){
	return 2*i;
}
int right(int i){
	return 2*i+1;
}
int parent(int i){
	return i/2;
}

int main(){

	int i,heapSize;;
	int a[250];

	scanf("%d",&heapSize);
	for(i=1;i<=heapSize;i++){
		scanf("%d",&a[i]);
	}

	for(i=1;i<=heapSize;i++){
		printf("node %d: key = %d, ",i,a[i]);
		if(parent(i)!=0){
			printf("parent key = %d, ",a[parent(i)]);
		}
		if(left(i)<=heapSize){
			printf("left key = %d, ",a[left(i)]);
		}
		if(right(i)<=heapSize){
			printf("right key = %d, ",a[right(i)]);
		}
		printf("\n");
	}

	return 0;
}

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

int main()
{
    int N, s = 0, i = 0;
    string F = "Yes";
    cin >> N;
    vector<int> H(N);
    while (i < N)
    {
        cin >> H.at(i);
        i++;
    }
    while (s < N)
    {
        if (s > 0)
        {
            if (H.at(N - s - 1) - H.at(N - s) >= 2)
            {
                F = "No";
                break;
            }
            else if (H.at(N - s - 1) - H.at(N - s) == 1)
            {
                H.at(N - s - 1) = H.at(N - s - 1) - 1;
            }
        }
        s++;
    }
    cout << F << endl;
}

Measured memory_bytes: 640
#[allow(unused_imports)]
use itertools::Itertools;
#[allow(unused_imports)]
use num::*;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::collections::*;

fn solve() {
    input! {
        h: usize, w: usize, k: usize,
        grid: [Chars; h]
    };

    let mut res = 0;
    for hbits in 0..1 << h {
        for wbits in 0..1 << w {
            let mut count = 0;
            for h in 0..h {
                let hng = (hbits >> h) & 1 == 1;
                for w in 0..w {
                    let wng = (wbits >> w) & 1 == 1;
                    if !hng && !wng && grid[h][w] == '#' {
                        count += 1;
                    }
                }
            }
            if count == k {
                res += 1;
            }
        }
    }
    println!("{}", res);
}

fn main() {
    std::thread::Builder::new()
        .name("big stack size".into())
        .stack_size(256 * 1024 * 1024)
        .spawn(|| {
            solve();
        })
        .unwrap()
        .join()
        .unwrap();
}


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

#define MAX 100000

vector<int> G[MAX];
int N;
bool visited[MAX];
int prenum[MAX], parent[MAX], lowest[MAX], timer;

void dfs(int current, int prev){
    prenum[current] = lowest[current] = timer;
    timer++;
    
    visited[current] = true;
    
    int next;
    
    for(int i = 0; i < G[current].size(); i++){
        next = G[current][i];
        if(!visited[next]){
            parent[next] = current;
            
            dfs(next, current);
            
            lowest[current] = min(lowest[current], lowest[next]);
        }
        else if(next != prev){
            lowest[current] = min(lowest[current], prenum[next]);
        }
    }
}

void art_points(){
    for(int i = 0; i < N; i++) visited[i] = false;
    timer = 1;
    
    dfs(0, -1);
    
    set<int> ap;
    int np = 0;
    for(int i = 1; i < N; i++){
        int p = parent[i];
        if(p == 0) np++;
        else if(prenum[p] <= lowest[i]) ap.insert(p);
    }
    if(np > 1) ap.insert(0);
    for(set<int>::iterator it = ap.begin(); it != ap.end(); it++){
        cout << *it << endl;
    }
}

int main(){
    int m;
    cin >> N >> m;
    
    for(int i = 0; i < m; i++){
        int s, t;
        cin >> s >> t;
        G[s].push_back(t);
        G[t].push_back(s);
    }
    art_points();
    
    return 0;
}


Measured memory_bytes: 6900
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  string S=to_string(N);
  int sum=0;
  for(int i=0;i<S.size();i++){
    sum=sum+(S.at(i)-'0');
  }
  if(N%sum==0){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}


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

const long long INF = 1LL << 60;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } else { return false; } }

int main() {
  int N, K;
  cin >> N >> K;

  long long h[110000];
  for (int i = 0; i < N; i++) {
    cin >> h[i];
  }

  long long dp[110000];
  for (int i = 1; i < N; i++) dp[i] = INF;
  dp[0] = 0;
  for (int i = 1; i < N; i++) {
    for (int j = 1; 0 <= (i - j) && j <= K; j++) {
      chmin(dp[i], dp[i - j] + abs(h[i] - h[i - j]));
    }
  }
  cout << dp[N - 1] << endl;

  return 0;
}


Measured memory_bytes: 1792
a = [0] * 4001
for i in range(2001):a[i] = a[4000 - i] = (i + 3) * (i + 2) * (i + 1) // 6 - 4 * a[i - 1001] * (i > 999)
while 1:
    try:print(a[int(input())])
    except:break


Measured memory_bytes: 5632
alphabets = {}
alphabets_num = {}
vartexs = []
fail_check = {}

class Vartex():
    def __init__(self, string):
        global alphabets
        self.ID = string
        self.link = []
        self.arrival = 0
        alphabets[string[0]].append(self)
        alphabets_num[string[0]] += 1
        return

    def register(self, new_vartex):
        self.link.append(new_vartex)
        return

def check_all(vartexs):
    for content in vartexs:
        if not content.arrival:
            return False
    return True

def dfs(start_vartex):
    global vartexs
    start_vartex.arrival = 1
    for link_vartex in start_vartex.link:
        if link_vartex.arrival:
            if check_all(vartexs):
                return True
            else :
                continue
        else:
            if dfs(link_vartex):
                return True
            else:
                continue
    start_vartex.arrival = 0
    return False


while True:
    alphabets = {}
    alphabets_num = {}
    vartexs = []
    fail_check = {}
    for al in range(ord("a"), ord("z")+1):
        alphabets[chr(al)] = []
        alphabets_num[chr(al)] = 0
        fail_check[chr(al)] = 0

    s = raw_input()
    if s == '':
        continue

    n = int(s)

    if not n:
        break

    for x in range(n):
        vartexs.append(Vartex(raw_input()))
    
    for x in range(n):
        vartex = vartexs[x]
        string = vartex.ID
        fail_check[string[-1]] += 1
        for content in alphabets[string[-1]]:
            vartex.register(content)
    
    if alphabets_num != fail_check:
        print "NG"
    else :
        start = vartexs[0]
        if dfs(start):
            print "OK"
        else:
            print "NG"

Measured memory_bytes: 56932
N = int(input())
l = []

for i in range(N):
    l.append(''.join(sorted(input())))

l.sort()
count = ans = 0

for i in range(N-1):
    if (l[i] == l[i+1]):
        count += 1
        ans += count
    else:
        count = 0

print(ans)

Measured memory_bytes: 10640
#ifdef DEBUG_IS_VALID
#define DEB 1
#define _LIBCPP_DEBUG 0
#else
#define DEB 0
#define NDEBUG
#endif

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

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(Int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i, x, n) for(Int i = x; i >= n; i--)
#define rrep(i, n) RREP(i,n,0)
#define pb push_back
#define fi first
#define se second
#pragma GCC optimize ("-O3")

using namespace std;

#define DUMPOUT cout
#define dump(...) if(DEB) DUMPOUT<<"  "<<#__VA_ARGS__<<" :["<<__LINE__<<":"<<__FUNCTION__<<"]"<<endl<<"    "; if(DEB) dump_func(__VA_ARGS__)
template<typename T1,typename T2>ostream& operator << (ostream& os, pair<T1,T2> p){cout << "(" << p.first << ", " << p.second << ")"; return os;}
template<typename T>ostream& operator << (ostream& os, vector<T>& vec) { os << "{"; for (int i = 0; i<vec.size(); i++) os << vec[i] << (i + 1 == vec.size() ? "" : ", "); os << "}"; return os; }
template<typename T>ostream& operator << (ostream& os, set<T>& st){cout << "{"; for(auto itr = st.begin(); itr != st.end(); itr++) cout << *itr << (next(itr)!=st.end() ? ", " : ""); cout << "}"; return os;}
template<typename T1,typename T2>ostream& operator << (ostream& os, map<T1,T2> mp){cout << "{"; for(auto itr = mp.begin(); itr != mp.end(); itr++) cout << "(" << (itr->first) << ", " << (itr->second) << ")" << (next(itr)!=mp.end() ? "," : ""); cout << "}"; return os; }

void dump_func(){DUMPOUT << endl;}
template <class Head, class... Tail>void dump_func(Head&& head, Tail&&... tail){ DUMPOUT << head; if (sizeof...(Tail) == 0) { DUMPOUT << " "; } else { DUMPOUT << ", "; } dump_func(std::move(tail)...);}
template<class T> inline bool chmax(T& a,T const& b){if(a>=b) return false; a=b; return true;}
template<class T> inline bool chmin(T& a,T const& b){if(a<=b) return false; a=b; return true;}
void solve();
int main(void) {
  std::cout << std::fixed << std::setprecision(15);
  solve();
	return 0;
}

using Int = long long;
using ll = long long;
using P = pair<Int,Int>;
using vi = vector<Int>;
using vvi = vector<vi>;
using vp = vector<P>;
using vvp = vector<vp>;

const Int INF = (1LL<<50);

void solve(){
  Int N, M, X;
  cin >> N >> M >> X;
  vi a(M);
  rep(i, M) cin >> a[i];
  Int pos = lower_bound(ALL(a), X) - a.begin();
  cout << min(pos, M - pos) << endl;
}

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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int main() {

    int x, y; cin >> x >> y;

    if ((y - 2 * x) % 2 == 0 && (y - 2 * x) / 2 >= 0 && (4 * x - y) % 2 == 0 && (4 * x - y) / 2 >= 0) {
        puts("Yes");
    } else {
        puts("No");
    }
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define debug(x) cerr << #x << " " << x << '\n'
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
const int INF = 0x3f3f3f3f, N = 2e5 + 5;
const ll LINF = 1e18 + 5;
int n, a, b;
constexpr int mod = 1e9 + 7;
ll powmod(ll a, ll b)
{
	ll ans = 1;
	while(b)
	{
		if(b&1) ans = ans*a%mod;
		a = a*a%mod;
		b >>= 1;
	}
	return ans;
}
ll inv(ll a) { return powmod(a, mod-2); }
ll comp(int n, int m)
{
	ll res = 1;
	for(int i=0; i<m; i++)
	{
		res = res*(n-i)%mod;
		res = res*inv(i+1)%mod;
	}
	return res;
}
int main()
{
 	ios::sync_with_stdio(false);
 	cin.tie(0);
 	cin >> n >> a >> b;
 	ll ans = (comp(n, a)+comp(n, b))%mod;
 	ans = (powmod(2, n) - 1 - ans + mod)%mod;
 	ans = (ans + mod)%mod;
 	cout << ans;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007
#define MAX 100000
void inarray(int a[], int n){
    for(int i = 0; i < n; i++) cin >> a[i];
}

int main(){
    double L; cin >> L;
    double h = L/3;
    printf("%.10f\n",h*h*h);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long; using P = pair<int,int>;
using vl = vector<ll>; using vvl = vector<vl>;
#define mp make_pair
#define pb push_back
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,n) for (int i=(n-1);i >= 0;i--)
#define all(v) v.begin(),v.end()
#define sz(v) (int)((v).size())
#define MAX(v) *max_element(all(v))
#define MIN(v) *min_element(all(v))
#define Sort(v) sort(all(v))
#define Rev(v) reverse(all(v))
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
#define VEC(type,name,size) vector<type> name(size);in(name)
#define vv(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define VV(type,name,h,w) vector<vector<type>>name(h,vector<type>(w));in(name)
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cout << H << " ";
    debug_out(T...);
}
#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...) 
#endif
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
    for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
    return os;
}
inline void IN(void){return;}
template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){cin >> first;IN(rest...);return;}
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;}
const ll INF = 1LL << 60;
const ll mod = 1000000007;
const int dx[8] = {1,0,-1,0,1,1,-1,-1}; const int dy[8] = {0,1,0,-1,1,1,-1,-1};

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    int a;cin >> a;
    cout << a+a*a+a*a*a << endl;
}

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

#define in(v) cin>>v;
#define out(v) cout<<v<<"\n"

int main() {
  int a, b;
  scanf("%d%d", &a, &b);
  if (a % b == 0)
    printf("-1\n");
  else
    printf("%lld\n", (long long)a*(b+1));

  return 0;
}


Measured memory_bytes: 256
pub struct Poper<'a> {
	iter: std::str::SplitWhitespace<'a>,
}

impl<'a> Poper<'a> {
	pub fn new(iter: std::str::SplitWhitespace) -> Poper {
		Poper { iter: iter }
	}
	pub fn read<T: std::str::FromStr>(&mut self) -> T
	where
		<T as std::str::FromStr>::Err: std::fmt::Debug,
	{
		self.iter.next().unwrap().parse().unwrap()
	}
}

fn main() {
	let input = {
		use std::io::Read;
		let mut s = String::new();
		std::io::stdin().read_to_string(&mut s).unwrap();
		s
	};
	let mut iter = Poper::new(input.split_whitespace());
	let l: u64 = iter.read();
	let r: u64 = iter.read();

	let mut m = 2019;
	'top: for i in l..r {
		for j in i + 1..r + 1 {
			let t = (i * j) % 2019;
			if t < m {
				m = t;
				if 0 == m {
					break 'top;
				}
			}
		}
	}
	println!("{}", m);
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
//#include<iostream>
//#include<cstdio>
//#include<cstring>
//#include<string>
//#include<queue>
//#include<cmath>
//#include<algorithm>
//#define debug1 cout<<"?"<<endl;
//#define debug2 cout<<"?"<<i<<endl;
#define PII pair<int,int>
typedef long long ll;
const int maxn=3e5+9;
const double pi=acos(-1);
const int mod=1e9+7;
const int INF=0x3f3f3f3f;
const double ep=1e-7;
using namespace std;
int main()
{
	ll k,q,i,d[maxn]={0};
	scanf("%lld%lld",&k,&q);
	for(i=0;i<k;i++)scanf("%lld",&d[i]);
	while(q--)
	{
		ll n,a,m,b[maxn]={0},sum=0;
		scanf("%lld%lld%lld",&n,&a,&m);
		a%=m;n--;
		for(i=0;i<k;i++)b[i]=d[i]%m,sum+=b[i];
		ll tot=0;//1-n有多少个数c[i]为0 
		for(i=0;i<k;i++)if(!b[i])tot+=(n/k)+(i<n%k); 
		ll an=sum*(n/k)+a;
		for(i=0;i<n%k;i++)an+=b[i];
		tot+=an/m;
		printf("%lld\n",n-tot);
	}
}

Measured memory_bytes: 5120
ar = list(input())
g = 0
p = 0
count = 0
for a in ar:
    if a == "g" and p + 1 <= g:
        count += 1
        p += 1
    elif a == "g" and p == g:
        g += 1
    elif a == "p" and p + 1 <= g:
        p += 1
    elif a == "p" and p == g:
        count -= 1
        g += 1
print(count)

Measured memory_bytes: 3956
using System;

class B{
  static void Main(){
    int N = int.Parse(Console.ReadLine());
    int temp = 1;
    int ans = 0;
    for (int i = 0; i < 10; i++){
      if (temp * 2 > N){
        ans = temp;
        break;
      }
      else {
        temp *= 2;
      }
    }
    Console.WriteLine(ans);
  }
}

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

class Program
{
	static void Main() => new Program().Solve();

	void Solve()
	{
		Console.ReadLine();
		var a = ReadLongArray();
		if (a.Contains(0L)) {
			Console.WriteLine(0);
			return;
		}
		try {
			var z = 1L;
			foreach (var x in a) {
				z = checked(z * x);
			}
			Console.WriteLine(z > 1000000000000000000L ? -1L : z);
		} catch {
			Console.WriteLine(-1);
		}
	}

	#region Console.Read 関係
	long[] ReadLongArray() => Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
	long ReadLong() => long.Parse(Console.ReadLine());
	#endregion
}


Measured memory_bytes: 42540
#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>
#include<cstdio>
using namespace std;
string a[100000];
int main(){
    long long n;
    cin>>n;
    long long ans=0;
    for(long long i=0;i<n;i++){
        cin>>a[i];
        std::sort(a[i].begin(),a[i].end());
    }
    sort(a,a+n);
    long long z[100000]={0},cnt=0;
    for(long long  i=0;i<n;i++){
        if(i==0){
            z[cnt]=1;
            continue;
        }
        if(a[i]==a[i-1]){
            z[cnt]++;
        }
        else{
            cnt++;
            z[cnt]++;
        }
    }

    for(long long  i=0;i<=cnt;i++){
        ans+=((z[i]*(z[i]-1))/2);
    }
    cout<<ans;
}


Measured memory_bytes: 8064
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)

using namespace std;

int main(){

	int x,y,s;
	vector<int> vx;
	vector<int> vy;
	vector<int> vs;

	while(1){
		cin>>x>>y>>s;
		if(x==0 && y==0 && s==0) break;
		vx.push_back(x);
		vy.push_back(y);
		vs.push_back(s);
	}

	for(int l=0; l<vx.size(); l++){
		int ans = -1;
		for(int i=1; i<1000; i++){
			for(int j=1; j<1000; j++){
				if((i*(100+vx[l]))/100 + (j*(100+vx[l]))/100 != vs[l]) continue;
				ans = max(ans , (i*(100+vy[l]))/100 + (j*(100+vy[l]))/100);
			}
		}
		cout<<ans<<endl;
	}

	return 0;
}

Measured memory_bytes: 3048