akhauriyash/Code-Regression huggingface dataset:
// Aizu Vol-5 0571: JJOOII
// 2017.9.1 bal4u@uu

#include <stdio.h>

char s[1000005];

int main()
{
	int j, o, i, ans;
	char *p;

	scanf("%s", s), p = s, j = o = i = ans = 0;
	while (*p) {
		if (*p++ != 'J') continue;
		j = 1;
		while (*p == 'J') j++, p++;
		if (*p != 'O') continue;
		p++, o = 1;
		while (*p == 'O') o++, p++;
		if (*p != 'I') continue;
		p++, i = 1;
		while (*p == 'I') i++, p++;
		if (j >= o && i >= o && o > ans) ans = o;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 1516
import java.util.*;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		long x = sc.nextLong();
		long r;
		long a = n,b = x;
		while( (r = a % b) != 0 ) {
            a = b;
            b = r;
        }
        if(b != 0){
        	n /= b;
			System.out.println((3*n-3)*b);
		}else{
			System.out.println(3*n-3);
		}
	}
}


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

#define int unsigned long long

using namespace std;

const long double EPS = 1e-9;

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int A;
long double B;
cin >> A >> B;
B*=100.0;
B+= EPS;
int T = B;
A *= T;

    cout << A/100<< '\n';

    return 0;
}


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

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)

using ll = long long;
using P = std::tuple<int,int,int>;
using PP = std::tuple<int,int>;

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

int N, M;
vector<P> G[10100];
vector<PP> G2[10100];
int di[10100];

void dijkstra(){
    priority_queue<PP, std::vector<PP>, std::greater<PP>> qu;

    std::fill(di, di+10100, 1001001001);
    di[1] = 0;
    qu.emplace(0, 1);

    while(!qu.empty()){
        int dd, v;
        tie(dd, v) = qu.top();
        qu.pop();

        if(di[v] < dd){
            continue;
        }

        for(auto& p : G[v]){
            int u, d;
            tie(u, d, ignore) = p;

            if(di[u] > dd + d){
                di[u] = dd + d;
                qu.emplace(di[u], u);
            }
        }
    }
}

void makeG2(){
    for(int i=1;i<=N;++i){
        for(auto& p : G[i]){
            int v, d, c;
            tie(v, d, c) = p;

            if(di[v] == di[i] + d){
                G2[v].emplace_back(i, c);
            }
        }
    }
}

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

    while(true){
        std::cin >> N >> M;
        if(N == 0){return 0;}

        for(int i=1;i<=N;++i){
            G[i].clear();
            G2[i].clear();
        }
        
        for(int i=0;i<M;++i){
            int u, v, d, c;
            std::cin >> u >> v >> d >> c;

            G[u].emplace_back(v, d, c);
            G[v].emplace_back(u, d, c);
        }

        dijkstra();
        makeG2();

        int res = 0;
        for(int i=2;i<=N;++i){
            int mn = 252521;
            for(auto& p : G2[i]){
                mn = min(mn, snd(p));
            }

            res += mn;
        }
    
        printf("%d\n", res);
    }
}

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

using namespace std;

const int N = 2e5 + 100;

inline int rd() {
  int s = 0, w = 1; char c = getchar();
  while (c < '0' || c > '9') { if (c == '-') w = -1; c = getchar(); }
  while (c >= '0' && c <= '9') s = (s << 3) + (s << 1) + c - '0', c = getchar();
  return s * w;
}

int n, a[N], mn = 0x3f3f3f3f, mx;
bool b[N];

inline bool chk(int x) {
  int tot[2]; tot[0] = tot[1] = 0;
  for (int i = 1; i <= 2 * n - 1; i++)
    if (a[i] >= x) b[i] = 1, tot[1]++;
    else b[i] = 0, tot[0]++;
  int pl = n - 1, pr = n + 1;
  while (pl >= 1 && pr <= 2 * n - 1) {
    if (b[pl] == b[pl + 1]) {
      if (b[pl] == 0) return false;
      return true;
    }
    if (b[pr] == b[pr - 1]) {
      if (b[pr] == 0) return false;
      return true;
    }
    pl--, pr++;
  }
  if (tot[0] > tot[1]) return false;
  return true;
}

int main() {
  n = rd();
  for (int i = 1; i <= 2 * n - 1; i++) {
    a[i] = rd();
    mn = min(mn, a[i]);
    mx = max(mx, a[i]);
  }
  int l = mn, r = mx, ans = 0;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (chk(mid))
      ans = mid, l = mid + 1;
    else
      r = mid - 1;
  }
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 1280
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <limits>
using namespace std;

int main() {
    // 入力
    int a,b;
    vector<vector<int>> c(3);
    cin >> a >> b;
    vector<int> result;
    bool flg = 0;
    int price = 0;

    for (int i = 0; i <= a; i++) {
        for (int j=i; j <= a; j++) {
            price = b - (1000*i + (j-i)*10000);
            
        
            if (price % 5000 == 0 &&price / 5000 + i + j -i == a) {
                result.push_back(j - i);
                result.push_back(price / 5000);
                result.push_back(i);
                flg =1;
                break;
            }
        }
        
    }
    if (flg) {
        cout << result[0] << " " <<result[1]<< " "<< result[2] <<endl;
    } else {
        cout << "-1 -1 -1" <<endl;
        
    }

}


Measured memory_bytes: 256
// doot diddly donger cuckerino Hahahahahah


#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace __gnu_cxx;
using namespace std;

using ll = long long;
using ld = long double;
using pll = pair<ll, ll>;
using vi = vector<int>;

template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const ld PI = acos(-1);

template <typename T> inline T mini(T& x, T y) { return x = min(x, y); }
template <typename T> inline T maxi(T& x, T y) { return x = max(x, y); }
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());

class CEnergyDrinkCollector {
public:
  
  void solve(std::istream& cin, std::ostream& cout) {
    int n, m;
    cin >> n >> m;
    vector<pair<long long, long long>> a(n);
    for (int i = 0; i < n; ++i) {
      cin >> a[i].first >> a[i].second;
    }
    sort(a.begin(), a.end());
    ll ans = 0;
    for (int i = 0; i < n; ++i) {
      int curr = min((ll) m, a[i].second);
      m -= curr;
      ans += curr * a[i].first;
    }
    cout << ans << '\n';
  }
};

int32_t main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
	CEnergyDrinkCollector solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 4816
#pragma GCC optimize("Ofast")
  
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <string>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <unordered_set>
#include <list>
#include <tuple>
#include <iomanip>
#include <climits>
#include <cstdlib>
#include <cassert>
#include <numeric>
#include <cmath>
#include <bitset>
#include <random>
#include <regex>

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 Fixed fixed << setprecision(14)
#define int int64_t
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9+7; 
constexpr int mod2 = 998244353;
constexpr int dy[] = {0,1,0,-1,1,-1,-1,1};
constexpr int dx[] = {1,0,-1,0,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 A, class B> inline A updiv(const A a,const B b){ return (a + b - 1) / b; }
template <class A, class B> inline A gcd(const A a,const B b){ return b ? gcd(b,a % b) : a; }
template <class A, class B> inline A lcm(const A a,const B b){ return a / gcd(a,b) * b; }

template <class T> using min_heap = priority_queue<T,vector<T>,greater<T> >;
template <class T> using max_heap = priority_queue<T>;
template <class A,class B> using umap = unordered_map<A,B>;
    
signed main(void){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    
    int n, k;
    cin >> n >> k;

    vector<pii> v(n);

    for(auto &e : v){
        cin >> e.first >> e.second;
    }

    sort(all(v));

    int sum = 0;
    for(auto e : v){
        sum += e.second;
        if(k <= sum){
            return cout << e.first << '\n', 0;
        }
    }

    return 0;
}

Measured memory_bytes: 1792
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.IO.Pipes;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;

namespace AtCorders
{
	public class Program
	{
		static void Main(string[] args)
		{
			int n = int.Parse(Console.ReadLine());

			int tn = 0;
			int xn = 0;
			int yn = 0;
			for (int i = 0; i < n; i++) {
				var txy = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
				int t = txy[0];
				int x = txy[1];
				int y = txy[2];

				int dt = t - tn;
				int dx = Math.Abs(x - xn);
				int dy = Math.Abs(y - yn);
				if (dt < dx + dy) {
					Console.WriteLine("No");
					return;
				}

				int remain = dt - (dx + dy);
				if (remain % 2 != 0) {
					Console.WriteLine("No");
					return;
				}

				tn = t;
				xn = x;
				yn = y;
			}

			Console.WriteLine("Yes");
		}
	}
}

Measured memory_bytes: 17452
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
void next(int& y, int & m, int & d){
  int lastday = (m % 2) ? 20 : 19;
  if(y % 3 == 0) lastday = 20;
  if(d == lastday){
    d = 1;
    if(m == 10){
      m = 1;
      y += 1;
    }else{
      m += 1;
    }
  }else{
    d += 1;
  }
}

int main(){
  int n;
  cin>>n;
  while(n--){
    int y, m, d;
    cin>>y>>m>>d;
    int cnt = 0;
    while(!(y == 1000 && m == 1 && d == 1)){
      cnt ++;
      next(y, m, d);
    }
    cout<<cnt<<endl;
  }
  return 0;
}

Measured memory_bytes: 864
#include<iostream>
#include<cstring>
#include<vector>
#include<cmath>
using namespace std;
typedef long long int LL;
LL t[200005];
int main(){
	int n;
	int i,j,k;
	LL s=0;
	cin>>n;
	for(i=0;i<n;i++){
		cin>>t[i];
	}
	for(i=0,j=0;i<n;i++,j++){
		if(t[i]>j){s=-1;break;}
		if(t[i]==j){
			if(j!=0)s++;
		}else s+=t[i],j=t[i];
	}
	cout<<s<<endl;
	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
int main(void){
    // Your code here!
    
    int N, K;
    std::cin >> N >> K;
    std::vector<int> A(N);
    for(int i=0; i<N; ++i) std::cin >> A.at(i);
    
    for(int i = 0; i < K; ++i) {
        // sousa
        std::vector<int> next(N + 1);
        for(int j = 0; j < N; ++j) {
            int left = std::clamp(j - A[j], 0, N - 1);
            int right = std::clamp(j + A[j], 0, N - 1);
            ++next[left];
            --next[right + 1];
        }
        for(int j = 1; j <= N; ++j) next[j] += next[j - 1];
        
        int cntN = 0;
        for(int j = 0; j < N; ++j) { cntN += next[j] == N; A[j] = next[j]; }
        if (cntN == N) break;
    }
    for(int i = 0; i < N; ++i) {
        std::cout << A[i];
        std::cout << (i == N - 1 ? "\n" : " ");
    }
}


Measured memory_bytes: 4812
import           Control.Monad

inf :: Int
inf = 100000

main :: IO ()
main = do
    [n, t] <- fmap (map read . words) getLine :: IO [Int]
    cts    <- replicateM n $ fmap (map read . words) getLine :: IO [[Int]]
    solve t cts

solve :: Int -> [[Int]] -> IO ()
solve t cts =
    let cs = map (\v -> if last v <= t then head v else inf) cts
        c  = minimum cs
    in  if c == inf then putStrLn "TLE" else print c


Measured memory_bytes: 1020
n=int(input())
a=list(map(int,input().split()))
s=0
for j in range(len(bin(max(a)))-2):
    cnt1=0
    cnt0=0
    for i in range(n):
      if (a[i]>>j)&1:
        cnt1+=1
      else:
        cnt0+=1
    s+=(cnt1*cnt0*2**j)%(10**9+7)
print(s%(10**9+7))


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

int n, mx;
string s;
vector <string> v;
map <string, int> mp;
set <string> ans;

int main() {
    cin >> n;
    for (int i = 0; i < n; i++){
        cin >> s;
        mp[s]++;
        v.push_back(s);
    }
    for (int i = 0; i < v.size(); i++){
        if (ans.count(v[i])) continue;
        if (mp[v[i]] > mx){
            mx = mp[v[i]];
            ans.clear();
            ans.insert(v[i]);
        }
        else if (mp[v[i]] == mx){
            ans.insert(v[i]);
        }
    }
    for (set<string>::iterator it = ans.begin(); it != ans.end(); it++){
        cout << *it << "\n";
    }
}


Measured memory_bytes: 36080
use whiteread::parse_line;

fn main() {
    let n: usize = parse_line().unwrap();
    let mut a: Vec<u32> = Vec::new();

    for _ in 0..n {
        a.push(parse_line().unwrap());
    }

    let mut cp: Vec<u32> = a.iter().copied().collect();
    cp.sort();
    let (max1, max2) = (cp.pop().unwrap(), cp.pop().unwrap());

    for num in a {
        if num == max1 {
            println!("{}", max2);
        } else {
            println!("{}", max1);
        }
    }
}


Measured memory_bytes: 3984
N=int(raw_input())
T=map(int,raw_input().split())
A=map(int,raw_input().split())

I,J=N-1,0
ans=1
for i in range(N):
    H=min(T[i],A[i])
    if i>0 and T[i-1]<T[i]:
        H=1
        if i+1 <N  and A[i+1]<A[i]:
            if T[i]!=A[i]:
                ans=0
                break
        if i==N-1 and T[i]!=A[i]:
            ans=0
            break
        if T[i] > A[i]:
            ans=0
            break
    if i+1 <N and A[i+1] <A[i]:
        H=1
        if i==0 and T[i]!=A[i]:
            ans=0
            break
        if A[i] > T[i]:
            ans=0
            break
    if i==0:
        H=1
        if T[i] > A[i]:
            ans =0
            break
    if i==N-1:
        H=1
        if A[i] > T[i]:
            ans = 0
            break
    ans *= H
    ans %= 1000000007
print ans

        



Measured memory_bytes: 14544
n,m = gets.split.map(&:to_i)
ary = [-1]*(n+1)
ary[0],ary[1] = 1,1
m.times do |i|
  ary[gets.to_i] = 0
end

(2..n).each do |i|
  if ary[i] == -1
    ary[i] = ary[i-1]+ ary[i-2]
  end
end

puts ary[n] % 1000000007

Measured memory_bytes: 433020
#include <bits/stdc++.h>
using namespace std;
const long long INF = 100000000000000;
const int MOD = 1000000007;
#define rep(i, a) REP(i, 0, a)
#define REP(i, a, b) for(int i = a; i < b;i++)
#define all(x) x.begin(), x.end()
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<P> vp;

int dp[41][401][401];

int main() {
    int n, ma, mb;
    cin >> n >> ma >> mb;
    vi a(n), b(n), c(n);
    rep(i, n) cin >> a[i] >> b[i] >> c[i];
    rep(i, n + 1) rep(j, 401) rep(k, 401){
        dp[i][j][k] = 1000000000;
    }
    rep(i, n + 1){
        dp[i][0][0] = 0;
    }
    rep(i, n) {
        rep(j, 401) {
            rep(k, 401){
                if(j >= a[i] && k >= b[i]){
                    dp[i + 1][j][k] = min(dp[i][j - a[i]][k - b[i]] + c[i], dp[i][j][k]);
                }else{
                    dp[i + 1][j][k] = dp[i][j][k];
                }
            }
        }
    }
    int p = 1, ans = 1000000000;
    while(true){
        if(dp[n][ma*p][mb*p]){
            ans = min(ans, dp[n][ma*p][mb*p]);
        }
        p += 1;
        if(p * max(ma, mb) > 400){
            break;
        }
    }
    if(ans == 1000000000){
        cout << -1 << endl;
    }else{
        cout << ans << endl;
    }
}

Measured memory_bytes: 25984
#include "bits/stdc++.h"
using namespace std;
#define forn(i, x, n) for (int i = x; i < n; i++)
#define all(a) (a).begin(), (a).end()
#define pii pair<int, int>
#define pll pair<ll, ll>
typedef long double ld;
typedef long long ll;

const int N = 2e5 + 7;
int a[N];
int arr[N];

int main() {
    int n;
    scanf("%d", &n);
    forn (i, 0, n) {
        scanf(" %d", &a[i]);
    }
    
    ll ans = 0;
    
    int l = 0;
    int r = 1;
    ll cur = a[l];
    
    while (l < n) {
        if (r < n && (cur & a[r]) == 0) {
            cur += a[r];
            r++;
        } else {
            cur -= a[l];
            
            int d = r - l;
            ans += d;
            
            l++;
            if (l == r) {
                r = l + 1;
                cur = a[l];
            }
        }
    }
   
    printf("%lld\n", ans);
    return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> length(N);
  for (int i = 0; i < N; i++){
    cin >> length.at(i);
  }
  int sum = 0;
  for (int i = 0; i < N; i++){
    sum += length.at(i);
  }
  int limit = (sum + 1) / 2;
  int flag = 0;
  for (int i = 0; i < N; i++){
    if (length.at(i) >= limit){
      flag = 1;
      break;
    }
  }
  if (flag == 0){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int x;
    map<int, int>::iterator it ;
    map<int,int> y;
    int flag=0;
    for(int i=0;i<n;i++)
    {
        cin>>x;
        if(y.empty())
        {
            y[x]=1;
            continue;
        }
        else
        {
            it=y.find(x);
            if(it==y.end())
            {
                y[x]=1;
            }
            else
            {
                cout<<"NO";
                flag=1;
                break;
            }
        }


    }
    if(flag==0)
        cout<<"YES";
}


Measured memory_bytes: 9600
let fs = require('fs');

const yourAnswerFunctionComesHere = data => {
  var Arr=(data.trim()).split(" ").map(Number);
  Arr.sort(function(a,b){return b-a;});
  console.log(Arr.join(" "));
}

const readFile = path => {
  fs.readFile(path, 'utf8', (err, data) => {
    yourAnswerFunctionComesHere(data);
  });
}

const readFileWithoutArg = () => {
  const data = require('fs').readFileSync('/dev/stdin', 'utf8');
  yourAnswerFunctionComesHere(data);
}

let sampleInputPath = "";

if(process.argv.length > 2) {
  sampleInputPath = process.argv[2];
  readFile(sampleInputPath);
} else {
  readFileWithoutArg();
}



Measured memory_bytes: 15140
#include <stdio.h>
#define MAX 25
#define N 100000
#define NIL -1
struct Node {
  int parent;
  int left;
  int right;
};
struct Node T[MAX];
int D[MAX];
int H[MAX];

void getDepth(int x,int y){
  if(x==NIL)return;
  D[x]=y;

  getDepth(T[x].right,y+1);

  getDepth(T[x].left,y+1);
}

int getHeight(int x){
  int a=0,b=0;
  if(T[x].right!=NIL)
    a=getHeight(T[x].right)+1;
  if(T[x].left!=NIL)
    b=getHeight(T[x].left)+1;
  if(a>b)
    H[x]=a;
  else
    H[x]=b;
  return H[x];
}

int getSibling(int x){
  int y;
  y=T[x].parent;
  if(T[x].parent==NIL)
    return NIL;
  if(T[y].right != x && T[y].right != NIL)
    return T[y].right;
  if(T[y].left != x && T[y].left != NIL)
    return T[y].left;
  return NIL;
}
  


int main(){
  int a,n,i,j,x;
  int id,left,right,y,root;
  int deg=0;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    T[i].parent=NIL;  
  }
    
  for(i=0;i<n;i++){
    scanf("%d%d%d",&id,&left,&right);
    T[id].left=left;
    T[id].right=right;
    if(left != NIL)
      T[left].parent=id;
    if(right != NIL)
      T[right].parent=id;
  }
  
  for(i=0;i<n;i++){
    if(T[i].parent==NIL)
      root=i;
  }
  
  getDepth(root,0);
  getHeight(root);

  
  
  for(i=0;i<n;i++){
    printf("node %d: parent = %d, sibling = %d, ",i,T[i].parent,getSibling(i));
    if(T[i].left!=NIL)
      deg++;
    if(T[i].right!=NIL)    
      deg++;
    printf("degree = %d, depth = %d, height = %d, ",deg,D[i],H[i]);
    deg=0;
    if(T[i].parent==NIL)
      printf("root\n");
    else if(T[i].left==NIL && T[i].right==NIL)
      printf("leaf\n");
    else
      printf("internal node\n");

  }

  return 0;
}

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

int main(){
    int N, h[100], now[100];
    cin >> N;
    rep(i, N) cin >> h[i];

    memset(now, 0, sizeof(now));

    int ans = 0, run = true, add = false;

    while (run) {
        add = false;
        rep(i, N) {
            if(now[i] < h[i]) {
                now[i]++;
                add = true;
            } else {
                if (add) break;
            }
        }

        if (add) ans++;
        else break;

    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.text.DecimalFormat;

public class Main {
	public static void main(String[] args){
		int a, b, d, r;
		double f;
		DecimalFormat t = new DecimalFormat("0.00000");
		Scanner sc = new Scanner(System.in);
		a = sc.nextInt();
		b = sc.nextInt();
		d = a / b;
		r = a % b;
		f =1.0 * a / b;
		System.out.println(d + " " + r + " " + t.format(f));
	}
}

Measured memory_bytes: 26308
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define repi(i,a,b) for(int i = (a); i < (b); i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
map<string,int> data;
map<string,vector<string> >ren;

int res(string s){
	if(!ren.count(s))return data[s];
	int sum = 0;
	for(int i =0;i <ren[s].size();i++){
		sum +=res(ren[s][i]);
	}
	if(data[s]>sum){
		data[s]=sum;
	}
	return data[s];
}

int main(){
	int n,m;
	while(cin>>n,n){
		data.clear();
		ren.clear();
		for(int i =0;i < n;i++){
			string item;
			int cst;
			cin>>item>>cst;
			data[item] =cst;
		}
		cin>>m;
		int k;
		for(int i =0;i <m;i++){
			string renkin;
			cin>>renkin>>k;
			//int sum=0;
			for(int j =0;j <k;j++){
				string tmp;
				cin>>tmp;
				ren[renkin].push_back(tmp);
			}
			//data[renkin]=min(sum,data[renkin]);
		}
		string ans;
		cin>>ans;
		cout <<res(ans)<<endl;
	}
	return 0;
}

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


int main(){
    bool segment[10][7] = {
        {true, true, true, true, true, true, false},
        {false, true, true, false, false, false, false},
        {true, true, false, true, true, false, true},
        {true, true, true, true, false, false, true},
        {false, true, true, false, false, true, true},
        {true, false, true, true, false, true, true},
        {true, false, true, true, true, true ,true},
        {true, true, true, false, false, true, false},
        {true, true, true, true, true, true, true},
        {true, true, true, true, false, true, true} };

    bool result[7];
    int n;
    while(cin >> n, n != -1){
        bool prev[7] = {false, false, false, false, false, false, false};
        for(int i=1; i<=n; i++){
            int digit;
            cin >> digit;
            for(int j=0; j<7; j++){
                if(prev[j] xor segment[digit][j]){
                    result[j] = true;
                }else{
                    result[j] = false;
                }
            }
            for(int j=6; j>=0; j--){
                if(result[j]){
                    cout << "1";
                }else{
                    cout << "0";
                }
            }
            cout << endl;

            for(int j=0; j<7; j++){
                prev[j] = segment[digit][j];
            }
        }
    }
    return 0;
}

Measured memory_bytes: 0
N = int(input())
D = []

ans =0
key =0
for _ in range(N):
    N,M=(map(int, input().split()))
    if N==M:
        ans +=1
    else:
        ans =0
    if ans >=3:
        key =1

if key > 0:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 9172
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;
	while(1){
		int b[10000],i;
		cin>>n;
		if(n==0){
			cout<<0<<endl;continue;
		}
		if(n==-1)break;
		for(i=0;n>0;i++){
			b[i]=n%4;
			n/=4;
		}
		while(i>0)cout<<b[--i];
		cout<<endl;
	}
}

Measured memory_bytes: 1164
n = int(input())
a = [0]*n
b = [0]*n
c = [0]*n
for i in range(n):
    a[i],b[i],c[i] = map(int,input().split())

dp = [[0,0,0] for i in range(n+1)]
for i in range(1,n+1):
    dp[i][0] = max(dp[i-1][1],dp[i-1][2])+a[i-1]
    dp[i][1] = max(dp[i-1][0],dp[i-1][2])+b[i-1]
    dp[i][2] = max(dp[i-1][0],dp[i-1][1])+c[i-1]

print(max(dp[n]))

Measured memory_bytes: 34676
from bisect import bisect
A,B,Q=map(int, input().split())
s=[int(input()) for _ in range(A)] + [99**99]
t=[int(input()) for _ in range(B)] + [99**99]
snt=[0]*A + [99**99]
tns=[0]*B + [99**99]
for i in range(A):
	p = bisect(t, s[i])
	snt[i] = min(abs(s[i] - t[p-1]), abs(s[i] - t[p]))
for i in range(B):
	p = bisect(s, t[i])
	tns[i] = min(abs(t[i] - s[p-1]), abs(t[i] - s[p]))
for _ in range(Q):
	x = int(input())
	ans = []
	p = bisect(s, x)
	ans.append(abs(s[p] - x) + snt[p])
	ans.append(abs(s[p-1] - x) + snt[p-1])
	p = bisect(t, x)
	ans.append(abs(t[p] - x) + tns[p])
	ans.append(abs(t[p-1] - x) + tns[p-1])
	print(min(ans))

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

using namespace std;

int main() {
    int n, u, v;
    cin >> n >> u >> v;
    vector<vector<int>> tree(n + 1);
    for (int i = 0; i < n; i++) {
        int a, b;
        cin >> a >> b;
        tree[a].emplace_back(b);
        tree[b].emplace_back(a);
    }
    queue<pair<int, int>> qa;
    qa.emplace(make_pair(v, 0));
    vector<int> dis_a(n + 1, -1);
    dis_a[v] = 0;
    while (!qa.empty()) {
        auto front = qa.front();
        qa.pop();
        for (auto e: tree[front.first]) {
            if (dis_a[e] < 0) {
                dis_a[e] = front.second + 1;
                qa.emplace(make_pair(e, front.second + 1));
            }
        }
    }

    queue<pair<int, int>> qb;
    qb.emplace(make_pair(u, 0));
    vector<int> dis_t(n + 1, -1);
    dis_t[u] = 0;
    while (!qb.empty()) {
        auto front = qb.front();
        qb.pop();
        for (auto e: tree[front.first]) {
            if (dis_t[e] < 0) {
                dis_t[e] = front.second + 1;
                qb.emplace(make_pair(e, front.second + 1));
            }
        }
    }

    int ans = 0;
    for (int i = 1; i <= n; i++) {
        if (dis_a[i] > dis_t[i]) {
            ans = max(ans, dis_a[i]);
        }
    }

    if (ans == 0) {
        cout << 1 << endl;
    } else {
        cout << ans - 1 << endl;
    }
    return 0;
}


Measured memory_bytes: 7680
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#define int long long
using namespace std;

int dp[100005][2];

vector<vector<int> >adj;
int mod=1e9+7;
pair<int,int> dfs(int ver,int p)
{
    dp[ver][0]=1;
    dp[ver][1]=1;    
    for(auto i:adj[ver])
    {
        if(i!=p)
        {
            pair<int,int>p=dfs(i,ver);
            dp[ver][0]=(dp[ver][0]*p.second)%mod;
            dp[ver][1]=(dp[ver][1]*(p.first+p.second))%mod;
        }
    }
    // cout<<ver<<" "<<dp[ver][0]<<" "<<dp[ver][1]<<"\n";
    return {dp[ver][0],dp[ver][1]};
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);  
// #ifndef ONLINE_JUDGE
//    freopen ("INPUT.txt" , "r" , stdin);
//    freopen ("OUTPUT.txt" , "w" , stdout);
// #endif

    clock_t clk;
	clk = clock();

// --------------Code starts here---------------------------------------------------------------------

    int n;
    cin>>n;
    adj.resize(n+1);
    int x,y;
    for(int i=0;i<n-1;i++)
    {
        cin>>x>>y;
        adj[x].push_back(y);
        adj[y].push_back(x);
    }
    if(n==1)
    {
        cout<<2;
        return 0;
    }
    dfs(1,0);
    cout<<(dp[1][0]+dp[1][1])%mod;
// -------------------------------------Code ends here------------------------------------------------------

    clk = clock() - clk;
	cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << "\n";
	return 0;
}


Measured memory_bytes: 10368
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
//#include <math.h>
//#include <queue>
//#include <stack>
//#include <iomanip>

// sometimes used
//#include <set>
//#include <map>
//#include <numeric>
//#include <list>
//#include <deque>
//#include <unordered_map>

typedef long long LL;
//typedef long double LD;
using namespace std;
 
//#define MOD 1000000007
//#define MAX 100100
//#define NIL -1
//#define INFTY 1000000000000000000

int main(){
    string s;
    string t;
    cin >> s >> t;
    vector<vector<LL>> dp(s.size()+1, vector<LL>(t.size()+1, 0));

    for(LL i=0; i<s.size(); i++){
        for(LL j=0; j<t.size(); j++){
            if(s[i]==t[j]){
                dp[i+1][j+1]=max(dp[i+1][j+1], dp[i][j]+1);
            }
            dp[i+1][j+1]=max(dp[i+1][j+1], dp[i+1][j]);
            dp[i+1][j+1]=max(dp[i+1][j+1], dp[i][j+1]);            
        }
    }

    string ans="";
    LL i=s.size();
    LL j=t.size();
    while(i>0 && j>0){
        if(dp[i][j]==dp[i-1][j]){
            i--;
        }else if(dp[i][j]==dp[i][j-1]){
            j--;
        }else{
            ans=s[i-1]+ans;
            i--;
            j--;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 74008
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,k;
  cin >> n >> k;
  vector<int> l(n);
  for(int i = 0; i < n; i++) {
    cin >> l[i];
  }
  
  sort(l.begin(),l.end());
  int ans=0;
  for(int i = 0; i < k; i++) {
    ans+=l[n-1-i];
  }
  
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<utility>
#include<array>
#include<cassert>
#include<list>
#include<experimental/any>
#include<cstring>
#include<cctype>
#include<ctime>
#include<cstdbool>
#include<cstdint>
#include<cstddef>
#include<set>
#include<unordered_set>
#include<bitset>
 
using namespace std;
using experimental::any;
 
#define SPEEDY cin.tie(0);ios::sync_with_stdio(false);
 
#define REP(i,n) for(int i=0;i<(n);i++)
#define ARREP(i,n,X) for(int i=0;i<(n);i++)cin>>X[i]
#define FOR(i,X,n) for(int i=(X);i<(n);i++)
#define EREP(i,n) for(int i=1;i<=n;i++)
#define BitFOR(N) REP(Bit,1<<(N))
 
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define DEB2(X) cout<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define TFDEB(f) (f)? cout<<"true ":cout<<"false ";
#define FORDEB(n,X) for(int i=0;i<(n);i++)ARDEB(i,X)
#define END cout<<endl;
#else
#define DEB(X) {}
#define DEB2(X) {}
#define ARDEB(i,X) {}
#define TFDEB(f) {}
#define FORDEB(n,X) {}
#define END {}
#endif
 
typedef long long int ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
#define ALL(X) X.begin(),X.end()
struct edge{int to,cost;};
//struct edge{int from,cost,to;};
struct P2{int x,y;};
#define BIT(Bit,n) bitset<n>(Bit)
#define Endl endl
#define YN(f) cout<<((f)?"Yes":"No")<<endl
 
const int MOD7=1000000007;
const int INF=100000000;
const int SET=1000; 
 
int main(){
	int a,b,c;
	cin>>a>>b>>c;
	if((a*100+b*10+c)%4==0){
		cout<<"YES"<<endl;
	}
	else{
		cout<<"NO"<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ull unsigned long long
#define ll long long
#define endl '\n'
#define pb push_back
#define mod 1000000007
#define mp make_pair
#define pi acos(-1)
#define line cout<<"----------------------------"<<endl
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL)
#define filein freopen("input.txt","r",stdin)
#define fileout freopen("output.txt","w",stdout)
using namespace std;
const ll  mx=3000009;
ll iv[mx];
ll facto[mx],facto1[mx];
void pre()
{
    facto[0]=1,facto1[0]=1;
    iv[1]=1;
    for(int i=2;i<mx;i++) iv[i]=mod-(mod/i)*iv[mod%i]%mod;;
    for(ll  i=1;i<mx;i++)
    {
        facto[i]=(facto[i-1]*i)%mod;
        facto1[i]=(facto1[i-1]*iv[i])%mod;

    }
}
int  main()
{
    pre();
    ll  r1,c1,r2,c2;
    cin>>r1>>c1>>r2>>c2;
    ll  ans=0;
    for(ll  i=c1;i<=c2;i++)
    {
        ans+=(facto[r2+i+1]*facto1[i+1])%mod*facto1[r2]%mod;
        ans-=(facto[r1+i]*facto1[i+1])%mod*facto1[r1-1]%mod;
        ans=(ans+mod)%mod;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 70528
#include <stdio.h>

int check(int *a, int x)
{
	int i = 0;
	while (a[i])
	{
		if (x == a[i])
			return 1;
		i++;
	}
	return (0);
}

int		main(void)
{
	int n,m,x;
	scanf("%d%d%d", &n, &m, &x);
	int a[m];
	int i = 0;
	int count1 = 0;
	int count2 = 0;
	while (i < m)
		scanf("%d", &a[i++]);
	i = x;
	int zero = a[0] - 1;
	if (x < n)
	{
		while (i < n)
		{
			if (check(a, i))
				count1++;
			i++;
		}
	}
	else
	{
		while (i > n)
		{
			if (check(a, i))
				count1++;
			i--;
		}
	}
	i = x;
	while (i > zero)
	{
		if (check(a, i))
			count2++;
		i--;
	}
	if (count1 < count2)
		printf("%d\n", count1);
	else
		printf("%d\n", count2);
	return (0);
}


Measured memory_bytes: 128
#include<stdio.h>

#define MAXLEN 10000
 
  
int main( void ) 
{
 	int n,q;
 	int S[MAXLEN+1],T[MAXLEN+1];
 	int i,j;
	int cnt;	
	
    scanf( "%d", &n ); 
    for( i=0; i<n; i++ ) {
    	scanf( "%d", &S[i] ); 
    }

	for( i=0; i<n; i++ ) {
		for( j=i+1; j<n; j++ ) {
			if( S[i] == S[j] ) {
				S[j]=-1;
			}
		}
	}
    scanf( "%d", &q); 
    for( i=0; i<q; i++ ) {
    	scanf( "%d", &T[i] ); 
    }
	
	for( i=0; i<q; i++ ) {
		for( j=i+1; j<q; j++ ) {
			if( T[i] == T[j] ) {
				T[j]=-1;
			}
		}
	}
    
	cnt=0;
	for( i=0; i<n; i++ ) {
		if( -1==S[i] ) { continue; }
		for( j=0; j<q; j++ ) {
			if( S[i] == T[j] ) {
				cnt++;
				break;
			}
		}
	}
	
	if( cnt ) {
		printf( "%d\n", cnt );
	} else {
		printf( "0\n" );
	}

    return 0;
}

Measured memory_bytes: 648
#include <bits/stdc++.h>
#define int long long
#define N 200010
using namespace std;
typedef long long ll;
const int mod = (1e9)+7;

int dp[2][N];

ll mod_pow(ll x,ll n){
  ll res=1;
  while(n){
    if(n%2) res=res*x%mod;
    x=x*x%mod;
    n/=2;
  }
  return res;
}
 
ll nCr(ll n,ll r){
  static vector<ll> k(1e6);
  if(!k[0]){k[0]=1;for(int i=1;i<k.size();i++)k[i]=i*k[i-1]%mod;}
  ll a=mod_pow(k[r],mod-2);
  ll b=mod_pow(k[n-r],mod-2);
  return ((k[n]*a)%mod)*b%mod;
}

signed main(){

  int n,m;
  cin>>n>>m;
  if(n>m) swap(n,m);
  if(m - n > 1) cout<<0<<endl,exit(0);
  int ans = 1;

    for(int i=1;i<=n;i++)ans = (ans*i)%mod;
    for(int i=1;i<=m;i++)ans = (ans*i)%mod;
    if(m == n) ans=(ans*2)%mod;
  
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <stdio.h>
#include <stdlib.h>
#include <cmath>

int main() {

    int S, N, L, tmp1;
    unsigned long long A, B, C, D;

    unsigned long long ans = 0;

    std::cin >> A >> B >> C >> D;

    unsigned long long max_cnt = B - A + 1;
    unsigned long long c_cnt = (B / C) - ((A-1) / C);
    unsigned long long d_cnt = (B / D) - ((A-1) / D);

    unsigned  long x = C*D;

    if(C < D){
        unsigned  long long tmp = C;
        C = D;
        D = tmp;
    }

    unsigned  long long r = C % D;
    while(r != 0){
        C = D;
        D = r;
        r = C % D;
    }

    unsigned long long cd = x/D;
    unsigned long long cd_cnt = (B / cd) - ((A-1) / cd);

    ans = max_cnt - c_cnt - d_cnt + cd_cnt;

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

Measured memory_bytes: 256
#include "iostream"
#include "vector"
#include "array"
#include "string"
#include "algorithm"

using namespace std;
#define rep(p,q) for(int i = p;i < q;i++)

//a
int main(void) {
	int a, b, c, d = 0;
	cin >> a >> b >> c >> d;
	cout << min(a, b) + min(c, d) << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace ConsoleApp6
{
	class Program
	{
		static void Main(string[] args)
		{
			while (true)
			{
				string hw = Console.ReadLine();
				string[] sq = hw.Split(' ');

				int H = int.Parse(sq[0]);
				int W = int.Parse(sq[1]);

				int i, j;
				if (H == 0 && W == 0)
					break;

				for (i = 0; i < H; i++)
				{
					
					for (j = 0; j < W; j++)
					{
						if(j == 0 || j == W - 1 || i == 0 || i == H - 1)
						{
							Console.Write("#");
						}
						else
						{
							Console.Write(".");
						}
					}
					Console.WriteLine();
				}

				Console.WriteLine();

				//Console.ReadKey();
			}
		}
	}
}



Measured memory_bytes: 15884
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdint>
using namespace std;

using int64 = int64_t;
using Store = pair<int64, int64>;  // Cost, Max                                                                                                                                                                    

int main() {
  int64 n, m;
  cin >> n >> m;
  vector<Store> stores;
  for(int64 i = 0; i < n; ++i) {
    int64 a, b;
    cin >> a >> b;
    stores.emplace_back(a, b);
  }
  sort(stores.begin(), stores.end());

  int64 cost = 0;
  int64 num = 0;
  for (Store& s : stores) {
    int64 buy = min(m - num, s.second);
    cost += s.first * buy;
    num += buy;
    if (num >= m)
      break;
  }
  cout << cost << "\n";

  return 0;
}


Measured memory_bytes: 2420
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define INF 0x7fffffff
#define LL_INF 0x7fffffffffffffff
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
int a[200005];

int main(void)
{
	int maxi = -1;
	int k, n; cin >> k >> n;
	for(int i=1;i<=n;i++) scanf("%d", &a[i]);
	for(int i=2;i<=n;i++) maxi = max(maxi, a[i] - a[i-1]);
	maxi = max(maxi, a[1]-a[n]+k);
	cout << k - maxi << endl;

	return 0;
}

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

int main(){
    string card;
    int m;
    while(cin >> card){
        if(card == "-") break;
        cin >> m;
        int h;
        string s;
        for(int i = 0; i < m; i++){
            cin >> h;
            s = card.substr(0, h);
            card.erase(0, h);
            card += s;
        }
        cout << card << endl;
    }
    return 0;
}



Measured memory_bytes: 3056
import java.util.Scanner;

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

        while (!(input = sc.next()).equals("-")) {
            m = sc.nextInt();
            int[] h = new int[m];
            char[] output = new char[input.length()];
            for (int i = 0; i < m; i++) {
                h[i] = sc.nextInt();
            }
            for (int i = 0; i < input.length(); i++) {
                output[i] = input.charAt(i);
            }

            for (int i = 0; i < m; i++) {
                output = change(output, input.length(), h[i]);
            }
            for (char c : output) System.out.print(c);
            System.out.println();
        }
    }

    public static char[] change(char[] input, int length, int n) {
        char[] output = new char[length];

        for (int i = 0; i < length - n; i++) {
            output[i] = input[i+n];
        }
        for (int i = length - n; i < length; i++) {
            output[i] = input[i + n - length];
        }

        return output;
    }
}


Measured memory_bytes: 26436
from math import sqrt
a, b, c = map(int, input().split())

# sqrt(a) + sqrt(b) < sqrt(c)
# 2 * sqrt(ab) < c - a - b
# 4 * a * b < (c - a - b) ** 2

if 0 >= c - a - b:
    print("No")
    exit()

if 4 * a * b < (c - a - b) ** 2:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 2940
#include <iostream>
#include <queue>
#include <map>
#include <list>
#include <vector>
#include <string>
#include <stack>
#include <limits>
#include <climits>
#include <cassert>
#include <fstream>
#include <cstring>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <cstdio>
#include <ciso646>
#include <set>
#include <array>

using namespace std;

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

#define inf 0x3f3f3f3f
#define PB push_back
#define MP make_pair
#define ALL(a) (a).begin(),(a).end()
#define SET(a,c) memset(a,c,sizeof a)
#define CLR(a) memset(a,0,sizeof a)
#define pii pair<int,int>
#define pcc pair<char,char>
#define pic pair<int,char>
#define pci pair<char,int>
#define VS vector<string>
#define VI vector<int>
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define MIN(a,b) (a>b?b:a)
#define MAX(a,b) (a>b?a:b)
#define pi 2*acos(0.0)
#define INFILE() freopen("in0.txt","r",stdin)
#define OUTFILE()freopen("out0.txt","w",stdout)
#define ll long long
#define ull unsigned long long
#define eps 1e-14
#define FST first
#define SEC second
#define SETUP cin.tie(0), ios::sync_with_stdio(false), cout << setprecision(15)

namespace {
	struct input_returnner {
		int N; input_returnner(int N_ = 0) :N(N_) {}
		template<typename T> operator vector<T>() const { vector<T> res(N); for (auto &a : res) cin >> a; return std::move(res); }
		template<typename T> operator T() const { T res; cin >> res; return res; }
		template<typename T> T operator - (T right) { return T(input_returnner()) - right; }
		template<typename T> T operator + (T right) { return T(input_returnner()) + right; }
		template<typename T> T operator * (T right) { return T(input_returnner()) * right; }
		template<typename T> T operator / (T right) { return T(input_returnner()) / right; }
		template<typename T> T operator << (T right) { return T(input_returnner()) << right; }
		template<typename T> T operator >> (T right) { return T(input_returnner()) >> right; }
	};
	template<typename T> input_returnner in() { return in<T>(); }
	input_returnner in() { return input_returnner(); }
	input_returnner in(int N) { return std::move(input_returnner(N)); }
}

void solve();
/// ---template---
signed main(void) {
	SETUP;
	solve();
	return 0;
}

void solve() {
	int N, A, B; cin >> N >> A >> B;
	string S = in();
	int a, b; a = b = 0;
	for (char c : S) {
		if (c == 'a') {
			if (a + b < A + B) {
				++a;
				cout << "Yes" << endl;
			}
			else cout << "No" << endl;
		}
		else if (c == 'b') {
			if (a + b < A + B and b < B) {
				++b;
				cout << "Yes" << endl;
			}
			else cout << "No" << endl;
		}
		else {
			cout << "No" << endl;
		}
	}
}

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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

template<typename T>
vector<T> compress(vector<T> &C1, vector<T> &C2)
{
    vector<T> vals;
    ll i,j;
    ll n = C1.size();
    for(i = 0;i < n;++i){
        for(T d = 0; d < 1;++d){
            T tc1 = C1.at(i) + d;
            T tc2 = C2.at(i) + d;
            vals.push_back(tc1);
            vals.push_back(tc2);
        }
    }

    sort(all(vals));
    vals.erase(unique(vals.begin(), vals.end()), vals.end());
    for(i = 0;i < n;++i){
        C1.at(i) = lower_bound(vals.begin(), vals.end(), C1.at(i)) - vals.begin();
        C2.at(i) = lower_bound(vals.begin(), vals.end(), C2.at(i)) - vals.begin();
    }
    return vals;
}

int main()
{
    ll i,j;
    ll n;
    cin >> n;
    vector<ll> x1(n);
    vector<ll> x2(n);
    vector<ll> y1(n);
    vector<ll> y2(n);
    for(i = 0;i < n;++i){
        cin >> x1.at(i) >> y1.at(i) >> x2.at(i) >> y2.at(i);
    }
    vector<ll> x = compress(x1, x2);
    vector<ll> y = compress(y1, y2);
    ll w = x.size();
    ll h = y.size();
    vector<vector<ll>> g(w,vector<ll>(h,0));
    for(i = 0;i < n;++i){
        ++g.at(x1.at(i)).at(y1.at(i));
        ++g.at(x2.at(i)).at(y2.at(i));
        --g.at(x1.at(i)).at(y2.at(i));
        --g.at(x2.at(i)).at(y1.at(i));
    }
    for(i = 1;i < w;++i){
        for(j = 0;j < h;++j){
            g.at(i).at(j) += g.at(i-1).at(j);
        }
    }
    for(i = 0;i < w;++i){
        for(j = 1;j < h;++j){
            g.at(i).at(j) += g.at(i).at(j-1);
        }
    }

    ll ans = 0;
    for(i = 0;i < w-1;++i){
        rep(j,h-1){
            if(g.at(i).at(j)) ans += (x.at(i+1) - x.at(i))*(y.at(j+1) - y.at(j)); 
        }
    }
    cout << ans << endl;

    return 0;
}


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

      int main(){
         int a,b,c;
         string s;
         cin >> a >> b >> c;
         if (abs(a-b) < abs(a-c)) cout << 'A' << endl;
         else cout << 'B' << endl;
         
         return 0;
         
      }



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

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

  int S = 0;
  for (int i = 0; i < N; i++) {
    int l, r;
    cin >> l >> r;
  
    S += (r - l + 1);
  }

  cout << S << endl;
}

Measured memory_bytes: 256
N, K    = map(int, input().split())
height  = list(map(int, input().split()))
road    = {}

#道がつながっている辞書を作成
for i in range(K):
    a, b = list(map(int, input().split()))
    try:
        road[a-1].append(b-1)
    except:
        road[a-1] = [b-1]
    try:
        road[b-1].append(a-1)
    except:
        road[b-1] = [a-1]

cnt = 0
for k, v in road.items():
  flag = True
  for i in set(v):
    if height[k] > height[i]:
      pass
    else:
      flag = False
  if flag is True:
    cnt += 1
print(cnt+(N-len(road.keys())))

Measured memory_bytes: 34776
#include<stdio.h>

int main() {
    int a,b,c;
    int max,min,mid;

    scanf("%d %d %d",&a,&b,&c);

    if (a > b && a > c) {
        max = a;
        if (b > c) {
            mid = b;
            min = c;
        } else {
            mid = c;
            min = b;
        }
    } else if (b > c) {
        max = b;
        mid = c;
        min = a;
    } else {
        max = c;
        mid = b;
        min = a;
    }
    
    printf("%d %d %d\n",min,mid,max);

    return 0;
}


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

const int MAXN = 200;

typedef long long ll;
const int mod = 1e9 + 7;

#define X first
#define Y second

int sa[MAXN], sb[MAXN];

int main()
{
	//freopen("input", "r", stdin);

	int n;
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i)
		scanf("%d", &sa[i]);
	for (int i = 1; i <= n; ++i)
		scanf("%d", &sb[i]);
	for (int i = 1; i <= n; ++i)
		sa[i] += sa[i - 1];
	for (int i = n; i >= 1; --i)
		sb[i] += sb[i + 1];
	int ans = 0;
	for (int i = 1; i <= n; ++i)
		ans = max(ans, sa[i] + sb[i]);
	cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define endl '\n'
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const ll mod = 1000000007;
const double PI = 3.141592653589793238463;
const int N=1e5+9;
int main()
{
    FASTINOUT;
    int x;
    cin>>x;
    int y;
    bool b=true;
    for (int i=0;i<x;i++){
        cin>>y;
        if (y%2==0&&(y%3!=0 &&y%5!=0))
        {
            b=false;
            break;
        }
    }
    cout<<(b?"APPROVED":"DENIED");
    return 0;
}


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

int main() {
    ll a, b;
    cin >> a >> b;
    if ((a+b)%2 == 0) cout << (a+b)/2 << endl;
    else cout << "IMPOSSIBLE";
    return 0;
}


Measured memory_bytes: 3588