akhauriyash/Code-Regression huggingface dataset:
#[allow(unused_imports)]
use std::io::*;
#[allow(unused_imports)]
use std::str::*;
#[allow(unused_imports)]
use std::collections::*;

#[allow(dead_code)]
fn read<T: FromStr>(s: &mut StdinLock) -> T {
    let s = s.by_ref().bytes().map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.parse::<T>().ok().unwrap()
}

#[allow(unused_macros)]
macro_rules! p {
    ($x:expr) 
    => (println!("{}", $x));
    ($x:expr, $y:expr)
    => (println!("{} {}", $x, $y));
    ($x:expr, $y:expr, $z:expr) 
    => (println!("{} {} {}", $x, $y, $z));
}

#[allow(unused_macros)]
macro_rules! pl {
    ($x:expr) 
    => (println!("{}", $x));
    ($x:expr, $y:expr)
    => (println!("{}\n{}", $x, $y));
    ($x:expr, $y:expr, $z:expr) 
    => (println!("{}\n{}\n{}", $x, $y, $z));
}

fn main() {
    let s = stdin();
    let mut s = s.lock();
    let s = &mut s;

    let n: i32 = read(s);
    p!(24 + 24 - n);
}

Measured memory_bytes: 4352
#include <iostream>

using namespace std;

int main() {
    int A, B, K, i;
    cin >> A >> B >> K;
    for (i = min(A, B); K; i--) {
        if (A % i == 0 & B % i == 0) {
            K--;
        }
    }
    cout << i + 1 << endl;
}

Measured memory_bytes: 888
def InS(): return input()


def InL(): return list(map(int, input().split()))


def InI(): return int(input())


H, N = InL()

x = InL()

y = sum(x)

if H > y:
    print("No")
else:
    print("Yes")

# x = -(-H // A)
# print(x)


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

using namespace std;

const int N = 2 * 1000 + 17;
const int MOD = 1000 * 1000 * 1000 + 7;

int n, m;
vector<int> g[N];
int p[N];

bool read() {
    if (!(cin >> n >> m))
        return false;

    for (int i = 0; i < m; ++i) {
        int nn;
        cin >> nn;

        for (int j = 0; j < nn; ++j) {
            int x;
            cin >> x;
            g[i].emplace_back(x - 1);
        }
    }

    for (int i = 0; i < m; ++i)
        cin >> p[i];

    return true;
}

void solve() {
    auto ans = 0;

    for (int mask = 0; mask < (1 << n); ++mask) {
        auto res = 0;

        for (int i = 0; i < m; ++i) {
            auto cur = 0;

            for (auto j : g[i])
                cur ^= (1 & (mask >> j));

            res |= (cur ^ p[i]);
        }

        ans += (res ^ 1);
    }

    cout << ans << endl;
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    while (read())
        solve();

    return 0;
}



Measured memory_bytes: 256
import java.util.*;

public class Main{
      public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            String str1 = sc.next();
            String str2 = sc.next();
            String str3 = sc.next();
            String[] str1a = str1.split("");
            String[] str2a = str2.split("");
            String[] str3a = str3.split("");
            if(str2a[0].equals(str1a[str1a.length-1]) && str3a[0].equals(str2a[str2a.length-1])){
              System.out.println("YES");
            } else {
              System.out.println("NO");
            }
          }
}

Measured memory_bytes: 23636
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] p = new int[n];
        int[] q = new int[n];
        for (int i = 0;i<n;i++) {
            p[i] = sc.nextInt();
        }
        for (int i = 0;i<n;i++) {
            q[i] = sc.nextInt();
        }

        int[] memo = new int[9];
        memo[1] = 1;
        memo[2] = 2;
        for (int i = 3; i< 9;i++) {
            memo[i]= i * memo[i-1];
        }

        int a = getNum(n, p, memo);
        int b = getNum(n, q, memo);
        System.out.println(Math.abs(a - b ));
    }
    
    private static int getNum(int n, int[] p, int[] memo){
        int a =0;
        Set<Integer> used = new HashSet<>();
        for (int i = 0;i < n;i++) {
            int pre = 0;
            used.add(p[i]);
            for (int j = 1;j <= p[i]; j++) {
                if (!used.contains(j)) pre++;
            }
            if (pre > 0) a += (pre) * (memo[n-i-1]);
        }
        return a;
    }
}

Measured memory_bytes: 22996
// Bismillahirrahmanirrahim
#include<bits/stdc++.h>
using namespace std;
vector<int> vec;
#define PI 3.14159265
int main() {
		double a, b,x;cin >> a >> b >>x;
		double k = a*a*a/(2*a*a*b-2*x);
		double res = atan(a*a*a/(2*a*a*b-2*x));
		if(x < a*a*b/2) res = atan(2*x/(a*b*b));
		cout << setprecision(9) <<  90- res*180.0/PI << endl;

}


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

int main(){
    int A, B;
    cin >> A >> B;
    string S;
    cin >> S;
    
    if(S[A] != '-'){
        cout << "No" << endl;
    }
    else{
        int cnt=0;
        for(int i=0; i<S.length(); i++){
            if(S[i]=='-') cnt++;
        }
        
        if(cnt!=1) cout << "No" << endl;
        else cout << "Yes" << endl;
    }
    
}


Measured memory_bytes: 256
#include <iostream>
 
using namespace std;
 
typedef long long ll;
 
const ll MOD = 1e9+7;
const int MAX_H = 110, MAX_W = 10;
 
 
int main(int argc, char const *argv[])
{
	int H, W, K;
	cin >> H >> W >> K;
	K--;
	ll dp[MAX_H][MAX_W];
	fill(dp[0], dp[H+1], 0);
 
	dp[0][0] = 1;
 
	for (int h = 0; h < H; ++h) {
		for (int b = 0; b < (1 << (W-1)); ++b) {
			bool adjacent = false;
			for (int i = 0; i < W-2; ++i){
				if ((b >> i)%4 == 3) adjacent = true;
			}
 
			if (adjacent) continue;
 
			int to[MAX_W];
			for (int i = 0; i < W; ++i) to[i] = i;
 
			for (int i = 0; i < W-1; ++i) {
				if ((b>>i)&1) swap(to[i], to[i+1]);
			}
			for (int i = 0; i < W; ++i) {
				dp[h+1][to[i]] += dp[h][i];
				dp[h+1][to[i]] %= MOD;
			}
		}
	}
 
	cout << dp[H][K] << endl;
	
	return 0;
}

Measured memory_bytes: 256
//by xiqiao
#include<bits/stdc++.h>
#define maxn 100005
using namespace std;
typedef long long ll;
vector <int> v[maxn];
int is[maxn],d[maxn];
int n;
int main(){
	//freopen("1.in","r",stdin);
	scanf("%d",&n);
	for(int i=1;i<n;i++){
		int x,y;scanf("%d%d",&x,&y);
		v[x].push_back(y);v[y].push_back(x);
		d[x]++;d[y]++;

	}
	queue <int> q;
	for(int i=1;i<=n;i++){
		if(d[i]==1)q.push(i);
	}
	while(!q.empty()){
		int x=q.front();q.pop();
		if(is[x])continue;
		if(d[x]==1){
			int y;
			for(int i=0;i<(int)v[x].size();i++){
				if(!is[v[x][i]]){
					y=v[x][i];break;
				}
			}
			is[y]=1;is[x]=2;//cout<<y<<" "<<x<<endl;
			for(int i=0;i<(int)v[y].size();i++){
				d[v[y][i]]--;
				if(d[v[y][i]]==1){
					q.push(v[y][i]);
				}
			}
		}
	}
	int now=1;
	for(int i=1;i<=n;i++){
		if(is[i]==0){
			is[i]=now;
			if(now==1)now=2;else now=1;
		}
	}
	for(int i=1;i<=n;i++){
		int flag=1;
		if(is[i]==2)continue;
		for(int j=0;j<(int)v[i].size();j++){
			if(is[v[i][j]]==2){
				flag=0;break;
			}
		}
		if(flag){
			puts("First");
			return 0;
		}
	}
	puts("Second");
	return 0;
}

Measured memory_bytes: 6784
a,b =map(int, input().split())
s =input()
 
def main(a,b,s):
  if len(s) != a+1+b :
    return 'No'
 
  for n,i in enumerate(s) :
    if n == a :
      
      if i != '-' :
        return 'No'
    else :
      try :
        int(i)
      except :
        return 'No'
  return 'Yes'
              
print(main(a,b,s))

Measured memory_bytes: 3060
#pragma GCC optimize ("O3")
// #pragma GCC target ("avx")
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define NDEBUG
#define eprintf(...) do {} while (0)
#endif
#include<cassert>

using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) {
    for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }
    putchar('\n');
}

char s[111];

LL read() {
    scanf("%s", s);
    int n = strlen(s);

    int dot = n; 
    REP (i, n) if (s[i] == '.') dot = i;
    LL a = 0;
    REP (i, dot) a = a * 10 + (s[i] - '0');
    REP (i, 9) {
	a = a * 10;
	if (dot+1+i < n) {
	    a += s[dot+1+i] - '0';
	}
    }
    return a;
}

int N;
LL A[200011];

struct TF {
    int two, five;

} tf[200011];

int C[20][20];

void MAIN() {
    scanf("%d", &N);
    REP (i, N) A[i] = read();

    REP (i, N) {
	tf[i].two = 0;
	tf[i].five = 0;
	LL m = A[i];
	while (m % 2 == 0) {
	    tf[i].two++;
	    m /= 2;
	}
	while (m % 5 == 0) {
	    tf[i].five++;
	    m /= 5;
	}
    }

    LL ans = 0;
    for (int i=N; i--;) {
	int two = tf[i].two;
	int five = tf[i].five;
	REP (t, 19) if (t + two >= 18) REP (f, 19) if (f + five >= 18) {
	    ans += C[t][f];
	}


	C[min(18, two)][min(18, five)]++;
    }

    printf("%lld\n", ans);
}

int main() {
    int TC = 1;
//    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}



Measured memory_bytes: 6808
#include <iostream> // cin, cout, cerr
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota
#include <cstdio> // printf, scanf
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <iomanip> // cout<<setprecision(n)
#include <functional> // function<void(int)>
#include <cmath>
#include <cassert>
#include <bitset>
#include <stack>

#ifdef DEBUG
#include "debug.hpp"
#else
#define debug(...)
#endif

#define int long long // at least int64 > 9*10^18
#define EL '\n'
#define rep(i,n) for(int i = 0; i < (n); i++)
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
using Graph = std::vector<std::vector<int> >;
const int INF = 1e17;
/* libraries */

struct HLD
{
	using Graph = std::vector<std::vector<int> >;
	std::vector<int> sz, in, out, par, nxt;
	Graph g, u_g;
	HLD(int n, Graph& u_g, int root=0) : sz(n),in(n),out(n),par(n),nxt(n),u_g(u_g),g(n,std::vector<int>()) {
		dfs_tree(root);
		dfs_sz(root);
		dfs_hld(root);
	}
	void dfs_tree(int v,int p=-1) {
		par[v]=p;
		for(int to:u_g[v]) {
			if(to==p) continue;
			g[v].emplace_back(to);
			dfs_tree(to,v);
		}
	}
	void dfs_sz(int v) {
		sz[v]=1;
		for(int& to:g[v]) {
			dfs_sz(to);
			sz[v]+=sz[to];
			if(sz[to]>sz[g[v][0]]) std::swap(to,g[v][0]);
		}
	}
	int t=0;
	void dfs_hld(int v) {
		in[v]=t++;
		for(int to:g[v]) {
			nxt[to] = (to==g[v][0]) ? nxt[v] : to;
			dfs_hld(to);
		}
		out[v]=t;
	}
	int LCA(int a, int b) {
		while(nxt[a]!=nxt[b]) {
			if(in[a]>in[b]) std::swap(a,b);
			b=par[nxt[b]];
		}
		if(in[a]>in[b]) std::swap(a,b);
		return a;
	}
};


signed main() {
	int n;
	std::cin >> n;
	std::vector<int> c(n);
	rep(i,n) std::cin >> c[i];
	rep(i,n) c[i]--;
	Graph g(n);
	rep(i,n-1) {
		int a,b;
		std::cin >> a >> b;
		a--;b--;
		g[a].emplace_back(b);
		g[b].emplace_back(a);
	}
	HLD hld(n,g);
	std::vector<int> ans(n,(n+1)*n/2);
	std::vector<std::stack<int> > d(n);
	rep(i,n) d[i].emplace(n);
	auto dfs = [&] (auto f, int i, int par) -> void {
		int col=c[i];
		int o = d[col].top(); d[col].pop();
		o-=hld.sz[i];
		d[col].emplace(o);
		for(int to : g[i]) {
			if(to==par) continue;
			d[col].emplace(hld.sz[to]);
			f(f,to,i);
		}
		for(int to : g[i]) {
			if(to==par) continue;
			int o = d[col].top(); d[col].pop();
			ans[col]-=o*(o+1)/2;
		}
	};
	dfs(dfs,0,-1);
	rep(i,n) {
		int o=d[i].top();
		ans[i]-=o*(o+1)/2;
	}
	rep(i,n) print(ans[i]);
	return 0;
}


Measured memory_bytes: 214068
#include <bits/stdc++.h>
using namespace std;
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define in(x,y,h,w) x >= 0 && x < h && y >= 0 && y < w

#define int long long
//typedef    long long          ll;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      P;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;
 
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

signed main(){
	char ans[100][100];
	int n = 100,m = 100,a,b;
	cin >> a >> b;
	for(int i = 0;i < n;i++){
		for(int j = 0;j < m;j++){
			if(j < m / 2) ans[i][j] = '.';
			else ans[i][j] = '#';
		}
	}
	for(int i = 0;i < a - 1;i++) ans[(i / 15) * 2][i % 15 * 2 + m / 2 + 1] = '.';
	for(int i = 0;i < b - 1;i++) ans[(i / 15) * 2][i % 15 * 2 + 1] = '#';
	cout << n << " " << m << endl;
	for(int i = 0;i < n;i++){
		for(int j = 0;j < m;j++) cout << ans[i][j];
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i < n; i++)
#define c(ans) cout << (ans) << '\n'
using namespace std;
int n, m, a = 0,b,c;string s, t;
int main(void) {
	cin >> n >> m;
	vector<int> k(n);
	rep(i, n) k[i] = i + 1;
	bool v[10][10];
	rep(i, 10) {
		rep(j, 10) {
			v[i][j] = false;
		}
	}
	rep(i, m) {
		cin >> b >> c;
		v[b][c] = true;
		v[c][b] = true;
	}
	do {
		bool g = true;
		rep(i, n - 1) {
			if (!v[k[i]][k[i + 1]])
				g = false;
		}
		if (g) ++a;
	} while (next_permutation(k.begin() + 1, k.end()));
	c(a);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define mod 1000000007
using ll = long long;
using namespace std;
int all = 0;
int check(vvi &root, int current, int checked){
  if(checked == all) return 1;
  int total = 0;
  for(int num : root[current]){
    if(!(checked & (1 << num))){
      checked |= (1 << num);
      total += check(root, num, checked);
      checked &= ~(1 << num);
    }
  }
  return total;
}
int main(){
  int n,m;
  cin >> n >> m;
  vvi root(n);
  rep(i, m){
    int a,b;
    cin >> a >> b;
    a--; b--;
    root[a].push_back(b);
    root[b].push_back(a);
  }
  rep(i, n){
    all++;
    all <<= 1;
  }
  all >>= 1;
  int checked = 1;
  cout << check(root, 0, checked) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define all(a) a.begin(), a.end()
#define sz(a) (int)a.size()
#define x first
#define y second
#define debug(...) cout << "[" << #__VA_ARGS__ << ": " << __VA_ARGS__ << "]\n"
#define rd() abs((int)rng())
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int>pii;
const int maxn = 2e5 + 100;
const int mod = 1e9 + 7;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
int n, m, a, b;
ll fac[maxn], inv[maxn];
ll pwr(ll a, ll pw)
{
    ll ret = 1;
    while(pw > 0)
    {
        if(pw & 1)
            ret = ret * a % mod;
        a = a * a % mod;
        pw >>= 1;
    }
    return ret;
}
ll modinv(ll a)
{
    return pwr(a, mod - 2);
}
ll ways(int x, int y, int xx, int yy)
{
    return fac[xx - x + yy - y] * inv[xx - x] % mod * inv[yy - y] % mod;
}
int main()
{
    ios_base::sync_with_stdio(false), cin.tie(0);
    fac[0] = 1, inv[0] = 1;
    for(ll i = 1; i < maxn; i++)
    {
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = modinv(fac[i]);
    }
    cin >> n >> m >> a >> b;
    a = n - a + 1;
    ll ans = ways(1, 1, n, m), sub = 0;
    for(int i = 1; i <= b; i++)
        sub = (sub + ways(1, 1, a - 1, i) * ways(a, i, n, m) % mod) % mod;
    cout << (ans - sub + mod) % mod << "\n";
    return 0;
}


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

using namespace std;

int main(){
  string s,t,u;
  int a,b;
  cin >> s >> t >> a >> b >> u;
  if(s == u)cout << a-1 << " " << b;
  else cout << a << " " << b-1;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cassert>
#include <algorithm>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <set>
#include <map>
#include <iomanip>
#include <math.h>
#include <unordered_map>
#include <unordered_set>
#include <queue>

#define REP(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define DB(x) cerr << #x << ": " << x << endl;
#define pb push_back
#define mp make_pair
#define fi first
#define se second

using namespace std;

typedef long long LL;
typedef long double LD;

const int MAXN = 100000;
const int MOD = 1000 * 1000 * 1000 + 7;

void solve();

int main()
{
    auto start = clock();
    cout.sync_with_stdio(0);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;

#ifdef HOME
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif

    int t = 1;
    //cin >> t;
    while (t--) {
        solve();
    }

    cerr << "\nTime: " << (clock() - start) / 1.0 / CLOCKS_PER_SEC << "\n";

    return 0;
}

void solve()
{
    int n;
    cin >> n;
    vector<int> a(n + 1, 0);
    LL ans = 0;
    REP(i, n) {
        cin >> a[i];
        if (a[i] > 2) {
            int delta = (a[i] - 1) / 2;
            ans += delta;
            a[i] -= 2 * delta;
        }
        assert(a[i] <= 2);
    }
    REP(i, n) {
        if (a[i] > 0) {
            if (a[i] == 1 && a[i + 1] > 0) {
                --a[i];
                --a[i + 1];
                ++ans;
            } else if (a[i] == 2) {
                a[i] = 0;
                ++ans;
            }
        }
        //DB(a[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define LLINF 9223372036854775807
#define MOD ll(1e9+7)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr<<#x<<": "<<x<<endl


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

    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            if(i<b && j<a){
                cout << 1;
            }else if(i>=b && j>=a){
                cout << 1;
            }else{
                cout << 0;
            }
        }
        cout << endl;
    }

    return 0;
}


Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int t=0;
	char a;
	while(a!='\n')
	{
		a=getchar();
		if(a=='C')
		t=1;
		if(a=='F'&&t==1)
		{
			printf("Yes");
			return 0;
		}
	}
	printf("No");
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define Yes(n) cout << ((n) ? "YES" : "NO") << endl
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort(ALL(V))

//vector<string> split(string,string);

//template<typename T>
//void swap(T*,T*);
char ToUpper (char cX) { return toupper(cX); }

int main()
{
    int a,b,c;
    cin >> a >> b >> c;
    if(b - a == c - b)
        Yes(true);
    else
    {
        Yes(false);
    }
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PI 3.14159265359
#define NIL (-1)
#define LL long long
using namespace std;
const int64_t MOD = 1e9 + 7;

int main() {
	int A, B, C, D;
	cin >> A >> B >> C >> D;

	int n, m;
	n = A + B;
	m = C + D;

	string s;
	if (n == m) {
		s = "Balanced";
	}
	else if (n > m) {
		s = "Left";
	}
	else {
		s = "Right";
	}

	cout << s << endl;
}

Measured memory_bytes: 3608
import java.util.Queue;
import java.util.*;
 
public class Main{
     public static void main(String[] wjy){
            Scanner in = new Scanner(System.in);
            Queue<String[]> input = new ArrayDeque<String[]>();
            int num = Integer.parseInt(in.next()) ;
            int quan = Integer.parseInt(in.next());  
            for (int i=0;i<num;i++) {
                String[] a = new String[2];
                a[0] = in.next();
                a[1] = in.next();
                input.add(a);
            }
            in.close();
            int calculate = 0;
            while (!input.isEmpty()){
                 String[] k = input.remove();
                 String name =(String) k[0];
                 int time =Integer.parseInt(k[1]);
                 if (time<=quan){
                    calculate=calculate+time;
                    System.out.println(name +" "+calculate);
                 }
                 else{
                    k[1]=Integer.toString((time-quan));
                    input.offer(k);
                    calculate=calculate+quan;
                 } 
            }   
     }
}


Measured memory_bytes: 74660
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define debug(n,v) cout<<#v<<":";for(int i=0;i<n;i++)cout<<v[i]<<" ";cout<<endl; 
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
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 n;
vector<vector<int>> g;
int dfs(int v){
    if(g[v].empty()) return 1;
    vector<int> vec;
    for(auto x:g[v]){
        vec.push_back(dfs(x));
    }
    sort(ALL(vec),greater<int>());
    int ret=0;
    for(int i=0;i<vec.size();i++){
        ret=max(ret,i+1+vec[i]);
    }
    return ret;
}

int main(){
    cin>>n;
    g.resize(n);
    for(int i=1;i<n;i++){
        int t;cin>>t;t--;
        g[t].push_back(i);
    }
    cout<<(dfs(0)-1)<<endl;
    return 0;
}

Measured memory_bytes: 13568
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n;
		String[] name = new String[1000];
		int[][] pqr = new int[1000][3];
		while ((n = in.nextInt()) != 0) {
			for (int i = 0; i < n; i++) {
				name[i] = in.next();
				pqr[i][0] = in.nextInt();
				pqr[i][1] = in.nextInt();
				pqr[i][2] = in.nextInt();
			}
			int P = in.nextInt();
			int Q = in.nextInt();
			int R = in.nextInt();
			int C = in.nextInt();
			boolean isNA = true;
			for (int i = 0; i < n; i++) {
				if (pqr[i][0] <= P && pqr[i][1] <= Q && pqr[i][2] <= R
						&& (pqr[i][0] + pqr[i][2]) * 4 + pqr[i][1] * 9 <= C) {
					System.out.println(name[i]);
					isNA = isNA && false;
				}
			}
			if (isNA) {
				System.out.println("NA");
			}
		}
	}
}

Measured memory_bytes: 64280
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int mod = 1e9+7;
const int MAX = 510000;
const int V = 100005;
ll dy[8] = {1,0,-1,0,1,-1,1,-1};
ll dx[8] = {0,1,0,-1,1,-1,-1,1};
const double pi = acos(-1);
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << endl;}
#define INT_MAX 1e9+7

int main(){
    ll n,m; cin >> n >> m;
    vpl v(m);
    rep(i,m) cin >> v[i].second >> v[i].first;
    sort(all(v));
    vl cut;
    rep(i,m){
        if(cut.empty()){
            cut.push_back(v[i].first);
            continue;
        }
        if(v[i].second >= cut.back()) cut.push_back(v[i].first);
    }
    cout << cut.size() << endl;
}


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

using ll = long long;
using ld = long double;
using Graph = vector<vector<int>>;

int main(void)
{
    ll n,m;
    cin >> n >> m;
    Graph g(n+1);
    for(int i=0;i<m;i++)
    {
        ll a,b;
        cin >> a >> b;
        //a--,b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    vector<int> direct(n+1,-1);
    queue<int> que;

    direct[0]=0;
    direct[1]=0;
    que.push(1);

    while(!que.empty())
    {
        int v = que.front();
        que.pop();

        for(int nv:g[v])
        {
            if(direct[nv] != -1) continue;

            direct[nv] = v;
            que.push(nv);
        }
    }
    cout << "Yes" << endl;
    for(int i=1;i<n;i++)
    {
        cout << direct[i+1] << endl;
    }
    return 0;
}


Measured memory_bytes: 10328
#include<bits/stdc++.h>
#define inf 0x7fffffff
#define RG register
#define inf 0x7fffffff
#define mkp make_pair
#define maxn 100205
typedef unsigned int U;
using namespace std;
typedef long long ll;
const ll mod = 998244353;
const  double eps = 1e-8;
const double pi = acos(-1);
inline ll read(){
    ll x = 0, f = 1;
    char ch = getchar();
    while(ch > '9' || ch < '0') {if(ch == '-') f = -1;ch = getchar();}
    while(ch >= '0' && ch <= '9'){x = x *10 + ch -'0';ch = getchar();}
    return x * f;
}
int n,m;
char s[1000005];
int main(){
	int i,j;
	//freopen("a.out","r",stdin);
	//freopen("a.ans","w",stdout);
	scanf("%s",s+1);
	n=strlen(s+1);
	int cnt=0;
	for(i=1;i<=n;i++){
		if(s[i]!=s[i-1]) cnt++;
	}
	printf("%d\n",cnt-1);
	return 0;
}

Measured memory_bytes: 3856
#include <iostream>
#include <vector>
#include <set>
#include <array>
#include <list>
#include <string>
#include <algorithm>
#include <queue>
#include <numeric>

using namespace std;

int main() {

	int N;

	cin >> N;

	vector<int> L(N);

	for (auto& l : L) cin >> l;

	sort(L.begin(), L.end());

	int sum = accumulate(L.begin(), L.end() - 1, 0);

	if (L.back() >= sum)
		cout << "No" << endl;
	else
		cout << "Yes" << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <cmath>
#include <climits>
#include <cstdio>
#include <iomanip>
#include <utility>

using namespace std;
typedef long long int ll;

#define SP(x) setprecision((int)x)
#define ALL(v) v.begin(),v.end()

int main(int argc, char const *argv[])
{
    ll n;
    cin >> n;
    string s;
    cin >> s;
    ll ans = 0;
    ll _max = 0;
    for (ll i = 0; i < n; i++)
    {
        ans = s[i] == 'I' ? ans + 1 : ans - 1;
        _max = max(ans, _max);
    }
    cout << _max << endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <math.h>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define REP(i, n) for(int i = 0; i < n; ++i)

using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;

int main()
{
	int a, b, c, k; cin >> a >> b >> c >> k;
	int need = 0;
	while (a >= b)
	{
		b *= 2;
		++need;
	}
	while (b >= c)
	{
		c *= 2;
		++need;
	}
	cout << (need <= k ? "Yes\n" : "No\n");
}

Measured memory_bytes: 3668
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define fi first
#define se second
#define rep(i,s,n) for(int i = s;i<n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
const ll MOD=1000000007,INF=1ll<<60;
int dx[]={0,0,1,-1},dy[]={-1,1,0,0};

int A,B,C,D,E,N,M,K;
string s,t;

signed main() {
    IOS();
    cin>>A>>B>>C>>D>>E>>N;
    if(E-A>N){
        cout<<":("<<endl;
        return 0;
    }else{
        cout<<"Yay!"<<endl;
        return 0;
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
    long long MOD = 1000000007LL;
    int n, x;
    cin >> n >> x;
    vector <int> s;
    for (int i = 0; i < n; i++) {
        int t;
        cin >> t;
        s.push_back(t);
    }
    sort(s.begin(), s.end());

    vector <long long> m1(x + 1);
    m1[x] = 1;
    for (int i = n - 1; i >= 0; i--) {
        vector <long long> m2(x + 1);
        for (int m = 0; m <= x; m++) {
            long long t = m1[m];
            int v = m % s[i];
            m2[v] = (m2[v] + t) % MOD;
            m2[m] = (m2[m] + t * i) % MOD;
        }
        m1 = m2;
    }
    long long ret = 0;
    for (int m = 0; m <= x; m++) {
        long long t = m1[m];
        ret = (ret + m * t) % MOD;
    }
    cout << ret << endl;
    return 0;
}


Measured memory_bytes: 1792
N,T = map(int,input().split())
t = list(map(int,input().split()))

time = T
ans = 0

for i in range(1,N):
    if time >= t[i]:
        ans += t[i] - t[i-1]
        time = t[i] + T
    else:
        ans += T
        time = t[i] + T
        
print(ans+T)

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

int main(int argc, char** argv){
	unsigned char s[201] = {};
	unsigned char p[101] = {};
	int len;

	// Input
	scanf("%100s",s);
	len = strlen(s);
	memcpy(s+len,s,len);
	scanf("%100s",p);

	// Judge & Output
	if( strstr(s,p) != NULL ){
		printf("Yes\n");
	} else {
		printf("No\n");
	}

	return 0;
}

Measured memory_bytes: 544
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 n = sc.nextInt();
			
			if(n == 0){
				break;
			}
			
			boolean[][] jewels = new boolean[21][21];
			
			for(int i = 0; i < n; i++){
				final int x = sc.nextInt();
				final int y = sc.nextInt();
				
				jewels[y][x] = true;
			}
			
			final int m = sc.nextInt();
			
			int sx = 10, sy = 10;
			int count = 0;
			
			for(int i = 0; i < m; i++){
				int dx = 0, dy = 0;
				
				String str = sc.next();
				
				if("N".equals(str)){
					dy = 1;
				}else if("S".equals(str)){
					dy = -1;
				}else if("W".equals(str)){
					dx = -1;
				}else if("E".equals(str)){
					dx = 1;
				}
				
				final int len = sc.nextInt();
				
				for(int j = 0; j < len; j++){
					sx += dx;
					sy += dy;
					
					if(jewels[sy][sx]){
						count++;
						jewels[sy][sx] = false;
					}
				}
			}
			
			if(count == n){
				System.out.println("Yes");
			}else{
				System.out.println("No");
			}
		}
		
	}

}

Measured memory_bytes: 12000
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;

int main () {
  string s;

  cin >> s;
  string ans = "";
  
  for (int i = 0; i < s.length(); i++){
    if (s[i] == '0'){
      ans += "0";
    }else if (s[i] == '1'){
      ans += "1";
    }else{
      if(ans.size() != 0){
        ans.erase(ans.size()-1, 1);
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(LL i=0;i<N;++i)
typedef long long int LL;

int main()
{
	LL N;
	in >> N;
	std::vector<LL>P(N), Q(N);
	rep(i, N) in >> P[i];
	rep(i, N) in >> Q[i];

	LL a, b, cnt = 1;
	std::vector<LL>r(N);
	rep(i, N) r[i] = i + 1;
	do
	{
		bool f1 = true, f2 = true;
		rep(i, N)
		{
			if (P[i] != r[i]) f1 = false;
			if (Q[i] != r[i]) f2 = false;
		}
		if (f1) a = cnt;
		if (f2) b = cnt;
		++cnt;
	} while (std::next_permutation(r.begin(), r.end()));

	out << std::abs(a - b) << std::endl;
}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#include<map>
#include<iostream>
#include<deque>
#include<algorithm>
#include<string>
#include<cctype>
#include<iomanip>
#include<vector>
#include<queue>
#include<math.h>
#include<bitset>
#include<random>
#include<set>
using namespace std;
using ll = __int64_t;
using lll = __int128_t;
typedef pair<ll,ll> P;
#define REP(i,b,e) for(ll i=(ll)b;i<(ll)e;i++)
#define rep0(i,n) REP(i,0ll,n)
#define rep1(i,n) REP(i,1ll,n+1)
const ll longinf=1ll<<60;
const int inf=(1<<30)-1;
const ll mod=1e9+7;


int main(){
      int n;
      cin>>n;
      int pow2n=(1<<n);
      multiset<int> notchoose;
      multiset<int> choosed;
      multiset<int> horyuu;
      rep0(i,pow2n){
            int s;
            cin>>s;
            notchoose.insert(-s);
      }
      notchoose.insert(1);
      auto itr=notchoose.begin();
      choosed.insert(*itr);
      notchoose.erase(itr);
      for(int i=0;i<n;i++){
            int pow2i=(1<<i);
            auto bitr=choosed.begin();
            auto eitr=choosed.end();
            for(auto itr=bitr;itr!=eitr;itr++){
                  ll pos=*itr;
                  auto korosu=notchoose.lower_bound(pos+1);
                  horyuu.insert(*korosu);
                  notchoose.erase(korosu);
                  if(*korosu>0){
                        cout<<"No"<<endl;
                        return 0;
                  }
            }
            bitr=horyuu.begin();
            eitr=horyuu.end();
            for(auto itr=bitr;itr!=eitr;itr++){
                  choosed.insert(*itr);
                  horyuu.erase(itr);
            }
      }
      cout<<"Yes"<<endl;

      return 0;
}


Measured memory_bytes: 13440
// "header" {{{
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <string>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <tuple>
#include <iomanip>

using namespace std;

#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define pii pair<int,int> 
#define int int64_t
#define Fixed fixed << setprecision(10)
#define moke_pair make_pair
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const long long mod = 1000000007;

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

template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

template <class T> using min_heap = priority_queue<T,vector<T>,greater<T> >;
template <class T> using max_heap = priority_queue<T>;
template <class T,class U> using umap = unordered_map<T,U>;

inline int64_t updiv(int64_t n,int64_t d){
    return ((n + d -1) / d);
}
/*
inline double Sqrt( const double &x) 
{
	double         xHalf = 0.5 * x;
	int64_t  tmp   = 0x5FE6EB50C7B537AAl - ( *(int64_t*)&x >> 1);
	double         xRes  = * (double*)&tmp;

	xRes *= ( 1.5 - ( xHalf * xRes * xRes ) );
	xRes *= ( 1.5 - ( xHalf * xRes * xRes ) );
	xRes *= ( 1.5 - ( xHalf * xRes * xRes ) );
	xRes *= ( 1.5 - ( xHalf * xRes * xRes ) );
	return xRes * x;
}
*/
// }}}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n;
    cin >> n;
    vector<vector<int> > dp(n+1,vector<int>(3));
    
    reps(i,n){
        int a,b,c;
        cin >> a >> b >> c;
        dp[i][0] = max(dp[i-1][1] + a,dp[i-1][2] + a);
        dp[i][1] = max(dp[i-1][0] + b,dp[i-1][2] + b);
        dp[i][2] = max(dp[i-1][0] + c,dp[i-1][1] + c);
    }

    cout << max({dp[n][0],dp[n][1],dp[n][2]}) << '\n';

    return 0;
}


Measured memory_bytes: 5760
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {


    public static void main(String[] args) throws IOException {
        Scanner s = new Scanner(System.in);
        int n =  s.nextInt();
        String word = s.next();

        word = word.replace("ABC"," ");
        word = word.replace(" ","");
        System.out.println((n-word.length())/3);

    }




}


class Scanner
{
    StringTokenizer st;
    BufferedReader br;

    public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}

    public String next() throws IOException
    {
        while (st == null || !st.hasMoreTokens())
            st = new StringTokenizer(br.readLine());
        return st.nextToken();
    }

    public int nextInt() throws IOException {return Integer.parseInt(next());}

    public long nextLong() throws IOException {return Long.parseLong(next());}

    public String nextLine() throws IOException {return br.readLine();}

    public double nextDouble() throws IOException
    {
        String x = next();
        StringBuilder sb = new StringBuilder("0");
        double res = 0, f = 1;
        boolean dec = false, neg = false;
        int start = 0;
        if(x.charAt(0) == '-')
        {
            neg = true;
            start++;
        }
        for(int i = start; i < x.length(); i++)
            if(x.charAt(i) == '.')
            {
                res = Long.parseLong(sb.toString());
                sb = new StringBuilder("0");
                dec = true;
            }
            else
            {
                sb.append(x.charAt(i));
                if(dec)
                    f *= 10;
            }
        res += Long.parseLong(sb.toString()) / f;
        return res * (neg?-1:1);
    }

    public boolean ready() throws IOException {return br.ready();}


}

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

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

int main() {
        ios_base:: sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
        long long a, b, c, d;
        cin >> a >> b >> c >> d;
        a--;
        long long lcm = (c * d) / gcd(c, d); 
        long long to_sub = a / c + a / d - a / lcm;
        long long tot = b / c + b / d - b / lcm;
        cout << b - a - tot + to_sub;
        return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
const int maxn = 1e5 + 5;
int ABS(int x){return x>=0?x:-x;}
int x[maxn], y[maxn], t[maxn];
int main(){
    int n;
    cin>>n;
    for(int i = 1; i <= n; i++){
        scanf("%d%d%d",&t[i],&x[i],&y[i]);
    }
    x[0] = y[0] = t[0] = 0;
    for(int i = 1; i <= n; i++){
        int s = ABS(x[i] - x[i - 1]) + ABS(y[i] - y[i - 1]) - t[i] + t[i - 1];
        if(s > 0 || s % 2){
            cout<<"No"<<endl;return 0;
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}


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

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

  vector<int> h(n);
  for(int i = 0; i < n; ++i) {
    cin >> h[i];
  }

  bool isYes = true;
  h[0]--;
  for(int i = n - 1; i > 0; --i) {
    if(h[i - 1] - 1 == h[i]){
      h[i - 1]--;
    }
    if(h[i - 1] > h[i]){
      isYes = false;
    }


  }

  if(isYes){
    cout << "Yes" << endl;
  }
  else cout << "No" << endl;

}

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

int32_t main(){
    ios::sync_with_stdio(0),cin.tie(0);
    int n;
    cin >> n;
    int f[100009]={0},sum=0;
    for(int i=0;i<n;i++){
        int x;
        cin >> x;
        sum+=x,f[x]++;
    }
    int q;
    cin >> q;
    while(q--){
        int b,c;
        cin >> b >> c;
        sum-=b*f[b];
        sum+=c*f[b];
        f[c]+=f[b],f[b]=0;
        cout << sum << '\n';
    }
}

Measured memory_bytes: 4428
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef long  l;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
const int INF=1000000001;
const double PI=3.141592653589;
const ll LMAX=1000000000000001;
ll gcd(ll a,ll b){if(a<b)swap(a,b);while((a%b)!=0){a=b;b=a%b;}return b;}
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};



int main(){
  int n; cin>>n;
  vector<ll> a(n);
  rep(i,n) cin>>a[i];


  ll ans=LMAX;
  rep(j,2){
    ll sum=0;
    ll c=0;
    bool F;
    if(j==0) F=1;
    else F=0;
    rep(i,n){
      if(F){
        if(sum+a[i]<0) sum+=a[i];
        else{
          c+=abs(sum+a[i])+1;
          sum=-1;
        }
        F=0;
      }else{
        if(sum+a[i]>0) sum+=a[i];
        else{
          c+=abs(sum+a[i])+1;
          sum=1;
        }
        F=1;
      }
    }
    ans=min(ans,c);
  }

  cout<<ans<<endl;

  return 0;
}


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

# 最初のモンスター総数
mons_n = sum(A)

# 各勇者について
for i in range(N):
    # 余力
    power = B[i]
    # A[i]で出来る限り倒す時の撃破数
    temp = min(A[i], power)
    A[i] -= temp
    power -= temp

    # 余力でA[i+1]で限界まで戦う
    A[i + 1] -= min(A[i + 1], power)

print(mons_n - sum(A))


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

int main(){
  int n;
  cin >> n;
  int a[n];
  for(int i=0;i<n;i++) cin >> a[i];
  int ans=0;
  int count[100001];
  for(int i=0;i<100001;i++) count[i]=0;
  for(int i=0;i<n;i++){
    if(a[i]>100000){
      ans++;
    }
    else{
      count[a[i]]++;
    }
  }
  for(int i=0;i<100001;i++){
    if(count[i]>=i){
      ans+=count[i]-i;
    }
    else{
      ans+=count[i];
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024
#include<iostream>

using namespace std;

int main(){
	int x,a,b;
	cin >> x >> a >> b;
	if (abs(x-a) >  abs(x-b)){
		cout << "B" << endl;
	}else if(abs(x-a) < abs(x-b)){
		cout << "A" << endl;
	}
	return 0;
}

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

int main() {
    string S; cin >> S;
    int g = 0, p = 0;
    int pable = 0;

    int score = 0;
    char mine;
    rep(i, S.size()) {
        char yours = S.at(i);
        if (pable >= S.size() - i) {
            mine = 'p';
        } else {
            mine = yours;
        }
        if (yours == 'p') {
            if (mine == 'g') score--, pable++;
            else pable--;
        } else {
            if (mine == 'g') pable++;
            else score++, pable--;
        }
    }
    cout << score << endl;
}


Measured memory_bytes: 512
#!/usr/bin/python3
# -*- coding:utf-8 -*-

MAX = 10**9 + 7

def pow_mod_p(n, k, p):
  x = 1
  while k:
    if k % 2 == 1:
      x *= n
      x %= p
    n **= 2
    n %= p
    k >>= 1
  return x

def comb_mod_p(n, k, p):
  x = 1
  for ik in range(k):
    x *= ((n-ik) * pow_mod_p(ik+1, p-2, p))
    x %= p
  return x

def main():
  x, y = map(int, input().strip().split())
  m = (2*x -   y)/3
  k = ( -x + 2*y)/3
  if m - int(m) != 0 or k - int(k) != 0 \
     or m < 0 or k < 0 :
    print(0)
    return 
  m, k = map(int, [m, k])
  if m < k:
    m, k = k, m
  print(comb_mod_p((m+k), k, MAX))
  
  
if __name__=='__main__':
  main()



Measured memory_bytes: 41068
N,C = [int(x) for x in input().split()]
D = [[int(x) for x in input().split()]for _ in range(C)]
C_grid = [[int(x) for x in input().split()] for _ in range(N)]
li=[[0]*C for _ in range(3)]
for i,s in enumerate(C_grid):
    for j,c in enumerate(s):
        li[(i+j)%3][c-1] += 1
ans = float('inf')
for x in range(C):
    for y in range(C):
        for z in range(C):
            diff = 0
            if(x==y or y==z or x==z):
                continue
            for i in range(C):
                diff += li[0][i]*D[i][x]
                diff += li[1][i]*D[i][y]
                diff += li[2][i]*D[i][z]
            ans = min(diff,ans)
print(ans)


Measured memory_bytes: 5492
#include<stdio.h>

int main(void){
int A, B, C, X, Y;
int money;
   //do{
      scanf("%d", &A);
      scanf("%d", &B);
      scanf("%d", &C);
      scanf("%d", &X);
      scanf("%d", &Y);
   //}while(A < 1 || A > 5000 || B < 1 || B > 5000 || C < 1 || C > 5000 ||
      //X < 1 || X > 100000 || Y < 1 || Y > 100000);


      if(A+B<C*2){
   		while(X*Y){
   			X--,Y--;
   			money+=A+B;
   		}
   		if(X+Y==0){;}
   		else if((A*X+B*Y)<(C*2)*(X>Y?X:Y)){
   			money+=A*X+B*Y;
   		}
   		else{
   			money+=(C*2)*(X>Y?X:Y);
   		}
   	}
   	else{
   		while(X*Y){
   			X--,Y--;
   			money+=C*2;
   		}
   		if(X+Y==0){;}
   		else if((A*X+B*Y)<(C*2)*(X>Y?X:Y)){
   			money+=A*X+B*Y;
   		}
   		else{
   			money+=(C*2)*(X>Y?X:Y);
   		}
   	}

   printf("%d", money);





}

Measured memory_bytes: 128
/* AOJ 0046
 *
 * http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0046
 *
 */

#include <stdio.h>
#include <float.h>

int main(){
    float high;
    float low;
    float input;

    high = 0.0;
    low = FLT_MAX;

    while(scanf("%f", &input)==1){
        if(input > high){
            high = input;
        }
        if(input < low ){
            low = input;
        }
    }
    printf("%0.1f\n", high - low);

    return 0;
}

Measured memory_bytes: 0
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.stdlib, std.datetime;

immutable int N = 26;
//immutable int D = 365;
int D;
long[] C;
long[][] S;

void main() {
    auto stattime = Clock.currTime();
    D = readln.chomp.to!int;
    C = readln.split.map!(to!long).array;
    S = iota(D).map!(_ => readln.split.map!(to!long).array).array;

    auto ans = gen_initital_ans();
    auto score = calc_score(ans);

    while ((Clock.currTime - stattime).total!"msecs" < dur!"msecs"(1980).total!"msecs") {
        auto idx = uniform(0, D);
        auto next = uniform(0, N);
        auto cur = ans[idx];

        ans[idx] = next;
        auto next_score = calc_score(ans);
        if (next_score >= score) {
            score = next_score;
        } else {
            ans[idx] = cur;
        }
    }

    ans.each!(a => writeln(a+1));
}

int[] gen_initital_ans() {
    auto ans = new int[](D);
    auto prev = new int[](N);
    prev[] = -1;

    foreach (i; 0..D) {
        int best_idx = -1;
        long best_score = -(1L << 59);
        foreach (j; 0..N) {
            long minus = (i - prev[j]) * C[j];
            long plus = S[i][j];
            long score = minus + plus;
            if (score >= best_score) {
                best_score = score;
                best_idx = j;
            }
        }
        ans[i] = best_idx;
        prev[best_idx] = i;
    }
    return ans;
}

long calc_score(const ref int[] ans) {
    auto prev = new int[](N);
    long score = 0;
    foreach (i, a; ans) {
        score += S[i][a];
        score -= decrease(C[a], prev[a], i.to!int);
        prev[a] = i.to!int;
    }
    foreach (a; 0..26) {
        score -= decrease(C[a], prev[a], D-1);
    }
    return score;
}

long decrease(long c, int prev, int cur) {
    return (cur - prev - 1) * (cur - prev) / 2 * c;
}


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

int main(){
    int n;
    cin >> n;
    vector<pair<ll, ll>> limit;
    for(int i=0; i<n; i++){
        ll a,b;
        cin >> a >> b;
        pair<ll, ll> p = make_pair(b,a);
        limit.push_back(p);
    }
    sort(limit.begin(), limit.end());
    bool possible = true;
    ll count = 0;
    for(int i=0; i<n; i++){
        pair<ll, ll> q;
        q = limit.at(i);
        count += q.second;
        if(count > q.first){
            possible = false;
            break;
        }
    }
    if(possible) cout << "Yes" << endl;
    else cout << "No" << endl;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e8;

//マクロ定義
#define vvint(vec,n,m,l) vector<vector<int>> vec(n, vector<int>(m,l));	// lで初期化
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>
#define pint pair<int,int>
#define rep(i,a) for(int i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")				//デバッグ用

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

	int n;
    cin>>n;
    cout<<n*n*n<<endl;
    

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
long double a,b,c;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>a>>b>>c;
    long long ans=a+b;
    long double aa=sqrt(a),bb=sqrt(b);
    ans+=aa*bb*2;
    if (ans<c){
        cout<<"Yes";
    }
    else cout<<"No";
}

Measured memory_bytes: 256