akhauriyash/Code-Regression huggingface dataset:
#include"bits/stdc++.h"
using namespace std;

void Main() {
  int N;
  cin >> N;

  vector<int> e[N];
  for (int i = 0; i < N - 1; i++) {
    int a, b;
    cin >> a >> b;
    e[a - 1].push_back(b - 1);
    e[b - 1].push_back(a - 1);
  }

  int fennec[N], snuke[N];
  memset(fennec, -1, sizeof(fennec));
  memset(snuke, -1, sizeof(snuke));
  fennec[0] = 0; snuke[N - 1] = 0;

  queue<int> q;
  q.push(0);
  while(!q.empty()) {
    int p = q.front(); q.pop();
    for (auto to: e[p]) {
      if (fennec[to] < 0) {
        q.push(to);
        fennec[to] = fennec[p] + 1;
      }
    }
  }

  q.push(N - 1);
  while(!q.empty()) {
    int p = q.front(); q.pop();
    for (auto to: e[p]) {
      if (snuke[to] < 0) {
        q.push(to);
        snuke[to] = snuke[p] + 1;
      }
    }
  }

  /*
  for (int i = 0; i < N; i++) {
    cout << fennec[i] << " ";
  }
  cout << endl;
  for (int i = 0; i < N; i++) {
    cout << snuke[i] << " ";
  }
  cout << endl;
  */

  int f = 0, s = 0;
  for (int i = 0; i < N; i++) {
    if (fennec[i] <= snuke[i]) f++;
    else s++;
  }

  if (f > s) cout << "Fennec" << endl;
  else cout << "Snuke" << endl;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}



Measured memory_bytes: 6528
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#define dlog(str) cout << "====" << str << endl;
#else
#define dlog(str)
#endif
#define INF 999999999
#define MOD 1000000007
#define REP(i, n) for(int i = 0, i##_l = (n); i < i##_l; i++)
#define FOR(i, s, e) for(int i = s, i##_l = (e); i < i##_l; i++)
#define LLI long long int
#define _min(a,b) ((a<b)?a:b)
#define _max(a,b) ((a<b)?b:a)
#define chmax(a, b) a = _max(a, b)
#define chmin(a, b) a = _min(a, b)
#define bit(a, shift) ((a>>shift)&1))
#define pm(a) ((a)?1:-1)
#define SORT(v) sort(v.begin(),v.end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
// int 2.14E±9    lli 9.2E±18    double 1.7E±380


int main()
{
	cout << fixed << setprecision(10);

	int n, k;
	cin >> n >> k;
	vector<int> p(n);
	REP(i, n)cin >> p[i];
	SORT(p);

	int ans = 0;
	REP(i, k)
	{
		ans += p[i];
	}

	cout << ans;

	return 0;
}

Measured memory_bytes: 3596
#include <iostream>
#include <vector>
#include <utility>
#include <set>
#include <algorithm>
#include <map>
using namespace std;
typedef pair<int, int> P;
int main(){
    int H, W, M;
    cin >> H >> W >> M;
    vector<int> h(M), w(M);
    set<P> s;
    map<int, int> mh, mw;
    int cnth = 0, cntw = 0;
    for(int i = 0; i < M; i++) {
        cin >> h[i] >> w[i];
        s.insert(P(h[i], w[i]));
        int b = ++mh[h[i]];
        int c = ++mw[w[i]];
        cnth = max(cnth, b);
        cntw = max(cntw, c);
    }
    sort(h.begin(), h.end());
    sort(w.begin(), w.end());
    vector<int> vh, vw;
    for(auto v: mh){
        if(v.second == cnth) vh.push_back(v.first);
    }
    for(auto v: mw){
        if(v.second == cntw) vw.push_back(v.first);
    }
    for(int i = 0; i < vh.size(); i++){
        for(int j = 0; j < vw.size(); j++){
            if(!s.count(P(vh[i], vw[j]))){
                cout << cnth + cntw << endl;
                return 0;
            }
        }
    }
    cout << cnth + cntw - 1 << endl;
}

Measured memory_bytes: 51872
// import chie template :) {{{
import std.stdio,
       std.algorithm,
       std.array,
       std.string,
       std.math,
       std.conv,
       std.range,
       std.container,
       std.bigint,
       std.ascii,
       std.typecons;
// }}}
// tbh.scanner {{{
class Scanner {
  import std.stdio;
  import std.conv : to;
  import std.array : split;
  import std.string : chomp;

  private File file;
  private dchar[][] str;
  private uint idx;

  this(File file = stdin) {
    this.file = file;
    this.idx = 0;
  }

  private dchar[] next() {
    if (idx < str.length) {
      return str[idx++];
    }

    dchar[] s;
    while (s.length == 0) {
      s = file.readln.chomp.to!(dchar[]);
    }

    str = s.split;
    idx = 0;

    return str[idx++];
  }

  T next(T)() {
    return next.to!(T);
  }

  T[] nextArray(T)(uint len) {
    T[] ret = new T[len];

    foreach (ref c; ret) {
      c = next!(T);
    }

    return ret;
  }
}
// }}}

void main() {
  auto cin = new Scanner;
  int h = cin.next!int, w = cin.next!int, d = cin.next!int;
  auto imos = new long[][](d + 2);
  int[] y = new int[h * w + 1], x = new int[h * w + 1];
  foreach (i; 1 .. h + 1) {
    foreach (j; 1 .. w + 1) {
      int c = cin.next!int;
      y[c] = i;
      x[c] = j;
    }
  }
  foreach (i; 1 .. d + 1) {
    imos[i] ~= 0;
    int dy = y[i], dx = x[i];
    int idx = 0;
    for (int j = i + d; j < h * w + 1; j += d) {
      imos[i] ~= imos[i][idx++] + abs(dy - y[j]) + abs(dx - x[j]);
      dy = y[j];
      dx = x[j];
    }
  }
  int q = cin.next!int;
  foreach (i; 0 .. q) {
    int l = cin.next!int, r = cin.next!int;
    int idx = l % d == 0 ? d : l % d;
    if (idx == d) {
      writeln(imos[idx][r / d - 1] - imos[idx][l / d - 1]);
    } else {
      writeln(imos[idx][r / d] - imos[idx][l / d]);
    }
  }
}


Measured memory_bytes: 12668
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class AtCoderA
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        int[] a = new int[n];
        {
            var line = Console.ReadLine();
            var words = line.Split(' ');
            for (int i = 0; i < n; i++)
            {
                a[i] = int.Parse(words[i]);
            }
        }

        a = a.OrderByDescending(num => num).ToArray();

        int answer = 0;
        for (int i = 0; i < n; i++)
        {
            answer += (i % 2 == 0) ? a[i] : (-1 * a[i]);
        }

        Console.WriteLine(answer);
    }
}

Measured memory_bytes: 13396
import java.util.*;

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

        ArrayList<Integer> d = new ArrayList<Integer>();

        for(int i = 0; i<n; i++)
        {
            d.add(sc.nextInt());
        }
        Collections.sort(d);
        System.out.println(d.get(n/2)-d.get(n/2-1));
    }
}

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

int ct[2000][2000];
int r[2000][2000];

int main() {
  int n, k;
  int x, y;
  char c;
  cin >> n >> k;
  int kk = k + k;
  for (int i = 0; i < n; i++) {
    cin >> x >> y >> c;
    if (c == 'W') {
      x += k;
    }
    ++ct[y % (kk)][x % (kk)];
    ++ct[(y + k) % (kk)][(x + k) % (kk)];
  }

  for (int i = 0; i < kk; i++) {
    r[i][0] = 0;
    for (int j = 0; j < k; j++) r[i][0] += ct[i][j];
    for (int j = 1; j < kk; j++) {
      r[i][j] = r[i][(j + kk - 1) % kk] - ct[i][(j + kk - 1) % kk] +
                ct[i][(j + k - 1) % kk];
    }
  }

  for (int i = 0; i < kk; i++) {
    ct[0][i] = 0;
    for (int j = 0; j < k; j++) ct[0][i] += r[j][i];
    for (int j = 1; j < kk; j++) {
      ct[j][i] = ct[(j + kk - 1) % kk][i] - r[(j + kk - 1) % kk][i] +
                 r[(j + k - 1) % kk][i];
    }
  }

  int maxcount = 0;
  for (int i = 0; i < kk; i++) {
    for (int j = 0; j < kk; j++) {
      maxcount = max(ct[i][j], maxcount);
    }
  }
  cout << maxcount << endl;
  return 0;
}


Measured memory_bytes: 34816
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main(){
    int n, ans = 0;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
        a[i] *= -1;
    }
    vector<int> b;
    b.emplace_back(a[0]);
    for(int i = 1; i < n; i++){
        auto p = upper_bound(begin(b), end(b), a[i]);
        if(p == b.end()){
            b.emplace_back(a[i]);
        }else{
            *p = a[i];
        }
    }
    ans = b.size();
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1276
#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int inf = 1000000007;
constexpr long long mod = 1000000007LL;
//constexpr long long mod = 998244353LL;
const long double PI = acos((long double)(-1));

using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;

vector<ll> dijkstra(int start, vector<vector<pair<int, ll>>>& graph) {
    vector<ll> dist(graph.size(), INF); dist[start] = 0;
    priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>> pq; pq.emplace(0, start);
    while (!pq.empty()) {
        ll cost; int idx; tie(cost, idx) = pq.top(); pq.pop();
        if (dist[idx] < cost) continue;
        for (auto next : graph[idx]) if (chmin(dist[next.first], cost + next.second)) pq.emplace(dist[next.first], next.first);
    }
    return dist;
}


void solve() {
    ll n, M, L, K, A, H; scanf("%lld %lld %lld %lld %lld %lld", &n, &M, &L, &K, &A, &H); if (n == 0) exit(0);
    vector<vector<pair<int, ll>>> g(n * (M + 1));
    vector<bool> f(n); for (int i = 0; i < L; i++) { int x; scanf("%d", &x); f[x] = true; }
    for (int i = 0; i < K; i++) {
        int u, v, t; scanf("%d %d %d", &u, &v, &t);
        for (int j = 0; j <= M; j++) {
            int nxt = j - t; if (nxt < 0) continue;
            g[u + n * j].emplace_back(v + n * nxt, t);
            g[v + n * j].emplace_back(u + n * nxt, t);
        }
    }
    for (int i = 0; i < n; i++) if (f[i]) {
        for (int j = 0; j < M; j++) {
            g[i + j * n].emplace_back(i + (j + 1) * n, 1);
        }
    }
    auto d = dijkstra(A + n * M, g);
    ll res = INF; for (int i = 0; i <= M; i++) chmin(res, d[H + i * n]);
    if (res == INF) puts("Help!");
    else printf("%lld\n", res);
}

int main()
{
    /*
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    */
    int kkt = 89;
    while (kkt) {
        solve();
    }
    return 0;
}


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

int main(){
    //char c[10005];
    string s;
    int n;
    cin >> n;
    cin >> s;
    for (int i = 0; i < s.length(); i++)
    {
        s[i] -= 65;
        s[i] += n;
        s[i] %= 26;
        s[i] += 65;
    }
    cout << s <<endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
	int K, N;
	cin >> N >> K;
	int p[1000];
	for (int i = 0; i < N; i++)
	{
		cin >> p[i];
	}
	int mim = p[0], index = 0, sum = 0;
	for (int i = 0; i < K; i++)
	{
		for (int j = 0; j < N; j++)
		{
			if (mim > p[j] && p[j]!='\0')
			{
				mim = p[j];
				index = j;
			}
		}
		sum += mim;
		p[index] = '\0';
		for (int j = 0; j < N; j++)
		{
			if (p[j] != '\0')
			{
				mim = p[j];
				index = j;
				break;
			}
		}
	}
	cout << sum << endl;
}

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

using namespace std;

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = k; i < n; i++) {
    if (a[i - k] < a[i]) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 4052
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
using namespace std;
const int maxn=100100;
const int INF=0x3f3f3f3f;

int a[maxn],b[maxn],c[maxn],d[maxn];
int s[maxn],n;
int sa[maxn],h[maxn],rk[maxn];
int sum[maxn];
char str[maxn];
bool cmp(int r[],int a,int b,int k){
	return r[a]==r[b]&&r[a+k]==r[b+k];
}
void build_sa(int r[],int sa[],int n,int m){
	int i,j,p,*x=a,*y=b;
	for(i=0;i<m;c[i++]=0);
	for(i=0;i<n;c[x[i++]=r[i-1]]++);
	for(i=0;i<m;c[++i]+=c[i-1]);
	for(i=n-1;i>=0;sa[--c[x[i]]]=i--);
	for(j=1,p=1;p<n;j<<=1,m=p){
		for(p=0,i=n-j;i<n;y[p++]=i++);
		for(i=0;i<n;i++)if(sa[i]>=j)y[p++]=sa[i]-j;
		for(i=0;i<n;d[i++]=x[y[i-1]]);
		for(i=0;i<m;c[i++]=0);
		for(i=0;i<n;c[d[i++]]++);
		for(i=0;i<m;c[++i]+=c[i-1]);
		for(i=n-1;i>=0;sa[--c[d[i--]]]=y[i+1]);
		for(swap(x,y),p=1,x[sa[0]]=0,i=1;i<n;i++)
			x[sa[i]]=cmp(y,sa[i-1],sa[i],j)?p-1:p++;
	}
}
void calh(int r[],int sa[],int n){
	int i,j,k=0;
	for(i=1;i<=n;rk[sa[i++]]=i-1);
	for(i=0;i<n;h[rk[i++]]=k)
		for(k?k--:0,j=sa[rk[i]-1];r[i+k]==r[j+k];k++);
}
int main(){
	int Q;
	scanf("%s",str);
	n=strlen(str);
	for(int i=0;i<n;i++)s[i]=(int)str[i];
	s[n]=0;
	build_sa(s,sa,n+1,256);
	calh(s,sa,n);
	
	int tot=0;
	for(int i=1;i<=n;i++){
		sum[i] = n-sa[i]-h[i];
		tot+=sum[i];
	}
	for(int i=2;i<=n;i++)
		sum[i]+=sum[i-1];
	int kth,ans;
	cin>>kth;
	if(kth>tot)kth%=tot;
	int L=0,R=n,mid;	
	while(L<=R){
		mid=(L+R)>>1;
		if(sum[mid]>=kth){
			ans=mid;R=mid-1;
		}else L=mid+1;
	}
	int s=sa[ans];
	int t=s+kth-sum[ans-1]+h[ans]-1;
	for(int i=s;i<=t;i++)cout<<str[i];
	cout<<endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define rep(i, s, N) for(ll i{s}; i < N; i++)
#define rem(i, N, s) for(ll i{N}; i > s; i--)
using namespace std;using ll = long long int;using ld = long double;using P = pair<ll,ll>;const int MOD = (int)1e9+7;const string rt = "\n";const string sp = " ";/* 最大公約数 */template<typename T> T gcd(T a, T b){return b != 0 ? gcd(b, a % b) : a;}/* UnionFind */template<typename T> struct UnionFind{vector<T> par;UnionFind(T n) : par(n, -1){}void init(T n){par.assign(n, -1);}T root(T x){if (par[x] < 0) return x;else return par[x] = root(par[x]);}bool issame(T x, T y){return root(x) == root(y);}bool merge(T x, T y){x = root(x); y = root(y);if(x == y) return false;if(par[x] > par[y]) swap(x, y);par[x] += par[y];par[y] = x;return true;}int size(int x) {return -par[root(x)];}};/* コンビネーション */template<typename T> ll combpm(T N_, T C_) {const int NUM_=400001;static ll fact[NUM_+1],factr[NUM_+1],inv[NUM_+1];if (fact[0]==0) {inv[1]=fact[0]=factr[0]=1;for (int i=2;i<=NUM_;++i) inv[i] = inv[MOD % i] * (MOD - MOD / i) % MOD;for (int i=1;i<=NUM_;++i) fact[i]=fact[i-1]*i%MOD, factr[i]=factr[i-1]*inv[i]%MOD;}if(C_<0 || C_>N_) return 0;return factr[C_]*fact[N_]%MOD*factr[N_-C_]%MOD;}/* 多次元ベクター */template<class T>vector<T> mvec(size_t a){return vector<T>(a);}template<class T, class... Ts>auto mvec(size_t a, Ts... ts){return vector<decltype(mvec<T>(ts...))>(a, mvec<T>(ts...));}/* 多次元デック */template<class T>deque<T> mdeq(size_t a){return deque<T>(a);}template<class T, class... Ts>auto mdeq(size_t a, Ts... ts){return deque<decltype(mdeq<T>(ts...))>(a, mdeq<T>(ts...));}/* テスト関数 */void test(ll n){cout << "test" << n << endl;}/* 小数点以下 */void fixsp(ll n){cout << fixed << setprecision(n);}void defsp(ll n){cout << defaultfloat << setprecision(n);}/* 重み付きUnionFind */struct WUnionFind {vector<int> par;vector<int> rank;WUnionFind(int n = 1) {init(n);}void init(int n = 1) {par.resize(n); rank.resize(n);for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0;}int root(int x) {if (par[x] == x) {return x;}else {int r = root(par[x]);return par[x] = r;}}bool issame(int x, int y) {return root(x) == root(y);}bool merge(int x, int y) {x = root(x); y = root(y);if (x == y) return false;if (rank[x] < rank[y]) swap(x, y);if (rank[x] == rank[y]) ++rank[x];par[y] = x;return true;}};/* IO高速化 */void fastio(){ios::sync_with_stdio(false);cin.tie(NULL);}
/* ここからコード開始 */

int main(){
  fastio;
  ll N;
  cin >> N;
  ll ans{};
  rep(i, 1, min(N+1,10LL)){
    ans++;
  }
  rep(i, 100, min(N+1,1000LL)){
    ans++;
  }
  rep(i, 10000, min(N+1,100000LL)){
    ans++;
  }
  cout << ans << rt;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <list>
#include <set>
#include <stack>
#include <deque>
#include <queue>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
#include <fstream>
#define debug(x) cout << #x << " = " << x << endl
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define repr(i,n) for(int i = (n); i > -1; i--)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const ll LINF = 1e18;
const double EPS = 1e-9;


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

  ll n;
  cin>>n;
  ll a[n],b[n];
  rep(i,n) cin>>a[i];
  rep(i,n) cin>>b[i];
  vector<ll> sm,bi;
  ll ss = 0, bs = 0;
  rep(i,n) {
    if(a[i] < b[i]) {
      sm.push_back(b[i] - a[i]);
      ss += b[i] - a[i];
    } else {
      bi.push_back(a[i] - b[i]);
      bs += a[i] - b[i];
    }
  }
  if(ss > bs) {
    cout << -1 << endl;
    return 0;
  }
  sort(bi.begin(),bi.end(),greater<ll>());
  ll tmp = 0;
  rep(i, bi.size() + 1) {
    if(tmp >= ss) {
      cout << i + sm.size() << endl;
      break;
    }
    if(i != bi.size()) tmp += bi[i];
  }

  return 0;
}


Measured memory_bytes: 2936
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <set>
#include <string>
#include <bitset>
#include <tuple>
#include <queue>
#include <stack>
#define inf 100100100
using namespace std;
#define ll long long
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, k, n) for (int i = (int)(k); i <(int)(n); i++)
#define rrep(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define rREP(i,k,n) for (int i = (int)(n)-1; i >= k; i--)
#define pb push_back
#define INF (1<<31)
#include<iostream>
#include<string>
using namespace std;
int dp[1010][1010] = {};
int main(){
    int h,w;
    cin >> h >> w;
    string s[1010];
    rep(i,h) cin >> s[i];
    rep(y,h)rep(x,w){
        if(s[y][x]=='#'){
            dp[y][x] = 0;
        }else{
            dp[y][x] = 100100;
        }
    }
    rep(y,h)rep(x,w){
        int mi = dp[y][x];
        if(y-1>=0) mi = min(dp[y-1][x]+1,mi);
        if(x-1>=0) mi = min(dp[y][x-1]+1,mi);
        if(y+1<h)  mi = min(dp[y+1][x]+1,mi);
        if(x+1<w)  mi = min(dp[y][x+1]+1,mi);
        dp[y][x] = mi;
    }
    rep(y,h)rrep(x,w){
        int mi = dp[y][x];
        if(y-1>=0) mi = min(dp[y-1][x]+1,mi);
        if(x-1>=0) mi = min(dp[y][x-1]+1,mi);
        if(y+1<h)  mi = min(dp[y+1][x]+1,mi);
        if(x+1<w)  mi = min(dp[y][x+1]+1,mi);
        dp[y][x] = mi;
    }
    rrep(y,h)rep(x,w){
        int mi = dp[y][x];
        if(y-1>=0) mi = min(dp[y-1][x]+1,mi);
        if(x-1>=0) mi = min(dp[y][x-1]+1,mi);
        if(y+1<h)  mi = min(dp[y+1][x]+1,mi);
        if(x+1<w)  mi = min(dp[y][x+1]+1,mi);
        dp[y][x] = mi;
    }
    rrep(y,h)rrep(x,w){
        int mi = dp[y][x];
        if(y-1>=0) mi = min(dp[y-1][x]+1,mi);
        if(x-1>=0) mi = min(dp[y][x-1]+1,mi);
        if(y+1<h)  mi = min(dp[y+1][x]+1,mi);
        if(x+1<w)  mi = min(dp[y][x+1]+1,mi);
        dp[y][x] = mi;
    }
    int ma = 0;
    rep(y,h){
        rep(x,w){
        ma = max(dp[y][x],ma);
        }
    }
    cout << ma << endl;

    return 0;
}


Measured memory_bytes: 5248
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int m;
    int f;
    int r;
    String result;
    while(true){
      m = sc.nextInt();
      f = sc.nextInt();
      r = sc.nextInt();
      int total = m + f;
      if(m == -1 && f == -1 && r == -1){
        break;
      }
      else if(m == -1 || f == -1){
        result = "F";
      }
      else if(total >= 80){
        result = "A";
      }
      else if(total < 80 && total >= 65){
        result = "B";
      }
      else if(total < 65 && total >= 50){
        result = "C";
      }
      else if(total < 50 && total >= 30){
        if(r >= 50){
          result = "C";
        }
        else{
          result = "D";
        }
      }
      else{
        result ="F";
      }
      System.out.println(result);
    }
  }
}



Measured memory_bytes: 26380
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
As = list(mapint())
As.sort()

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

pairwise = True
s = set()
maxi = As[-1]
for i in range(N):
    a = As[i]
    if a in s:
        pairwise = False
        break
    if a==1:
        continue
    primes = list(set(prime_factorize(a)))
    for p in primes:
        cnt = 1
        while cnt*p<=maxi:
            s.add(cnt*p)
            cnt += 1
else:
    print('pairwise coprime')
    exit()

from math import gcd
g = 0
for a in As:
    g = gcd(g, a)
if g==1:
    print('setwise coprime')
    exit()
else:
    print('not coprime')

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

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

    vector<int> s(n);
    rep(i,n) cin >> s[i];
    int MAX = 105;
    int diff = MAX;
    int ans = 0;
    
    rep(i,MAX){
        bool flag = 0;
        rep(j,n){
            if(s[j] == i) flag = 1;
        }
        if(flag) continue;

        int temp = max(i-x,x-i);
        if(temp < diff){
            diff = temp;
            ans = i;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3628
import java.util.Scanner;
import java.util.Comparator;
import java.util.Arrays;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        Pair[] pairs = new Pair[m];
        for(int i = 0;i < m;i++){
            Pair ps = new Pair();
            ps.from = sc.nextInt();
            ps.end = sc.nextInt();
            pairs[i] = ps;
        }
        Arrays.sort(pairs);
        int cnt = 0;
        int nowclear = 0;
        for(int i = 0;i < m;i++){
            int nowfrom = pairs[i].from;
            int nowend = pairs[i].end;
            if(nowclear < nowfrom){
                cnt++;
                nowclear = nowend - 1;
            }
        }
        System.out.println(cnt);
    }
}
class Pair implements Comparable{
    int from;
    int end;
    public int compareTo(Object other){
        Pair otherpair = (Pair) other;
        return end - otherpair.end;
    }
}


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

int main(){
	int n;
	double w, h, bmi;
	while(scanf("%d,%lf,%lf", &n, &w, &h) != EOF){
		bmi = w / (h * h);
		if(bmi >= 25){
			cout << n << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1232
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }

size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }

//long mod = 10^^9 + 7;
long mod = 998_244_353;
//long mod = 1_000_003;
void moda(T)(ref T x, T y) { x = (x + y) % mod; }
void mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(T)(ref T x, T y) { x = (x * y) % mod; }
void modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); }

void main()
{
	auto K = RD;
	long ans;
	foreach (i; 1..K+1)
	{
		foreach (j; 1..K+1)
		{
			auto tmp = gcd(i, j);
			foreach (k; 1..K+1)
			{
				ans += gcd(tmp, k);
			}
		}
	}

	writeln(ans);
	stdout.flush;
	debug readln;
}

Measured memory_bytes: 2760
#include<iostream>
#include<map>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<cmath>
#define ll long long
using namespace std;

struct train{
	int c;
	int s;
	int f;
}a[1000];

int main(){
	int n;
	cin>>n;
	for (int i=1;i<n;i++){
		cin>>a[i].c>>a[i].s>>a[i].f;
	}
	
	int ans[1000];
	
	for (int i=1;i<n;i++){
		int t=a[i].s+a[i].c;
		
		for (int j=i+1;j<n;j++){
			int k=a[j].s;
			while (k<t){
				k+=a[j].f;
			}
			t=k;
			t+=a[j].c;
		}
		ans[i]=t;
		
	}
	ans[n]=0;
	for (int i=1;i<=n;i++) cout<<ans[i]<<endl;
	
	
}

Measured memory_bytes: 384
using System;
using System.Collections.Generic;

namespace AtCoder_ABC_B
{
    class Program
    {
        static void Main(string[] args)
        {
            int count = 0;
            var numsInt = new List<int>();
            int n = int.Parse(Console.ReadLine());
            string inputLineStr = Console.ReadLine();
            string[] numsStr = inputLineStr.Split(' ');

            for (int i = 0; i < n; i++)
            {
                numsInt.Add(int.Parse(numsStr[i]));
                if(numsInt[i] != (i + 1))
                {
                    count++;
                }
            }
            if (count > 2)
            {
                Console.WriteLine("NO");
            }else
            {
                Console.WriteLine("YES");
            }
        }
    }
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

ll mod_pow(ll a,ll n){
  ll res=1;
  while(n>0){
    if(n&1)res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll fac[10010],finv[10010];
ll comb[510][510];
void make_table(){
  for(ll i=0;i<=500;i++){
    comb[i][0]=1;
    comb[i][i]=1;
  }
  for(ll i=1;i<=500;i++)for(ll j=1;j<i;j++){
    comb[i][j]=(comb[i-1][j-1]+comb[i-1][j])%mod;
  }
}
ll N,K;
vector<vector<ll>> fs;
vector<ll> f;

void dfs(ll i,ll crt,ll sum){
  if(sum-1>N)return ;
  if(i==N){
    fs.push_back(f);
    return ;
  }
  fs.push_back(f);
  for(ll j=crt;j>=1;j--){
    f.push_back(j);
    dfs(i+1,j,sum+(j==1?1+1:(j-1)*2-1+1));
    f.pop_back();
  }
}

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

  fac[0]=1;
  rep(i,10000)fac[i+1]=fac[i]*(i+1)%mod;
  rep(i,10001)finv[i]=mod_pow(fac[i],mod-2);
  make_table();

  string S;

  cin>>N>>K>>S;

  dfs(0,36,0);

  ll res=0;

  rep(i,fs.size()){
    vector<ll> f=fs[i];
    ll M=f.size();
    if(M==0)continue;
    vector<bool> used(K,false);
    vector<ll> rs(M,-1);
    ll rcnt=0;
    rep(j,K){
      if(S[j]=='r'){
        used[j]=true;
        rs[rcnt]=j;
        rcnt++;
        if(rcnt==M)break;
      }
    }
    if(rcnt<M)continue;
    vector<ll> bs(M,-1);
    rep(j,M){
      if(f[j]==1)continue;
      repl(k,rs[j],K){
        if(S[k]=='b'&&!used[k]){
          used[k]=true;
          bs[j]=k;
          break;
        }
      }
    }
    bool ok=true;
    rep(j,M){
      if(f[j]>1&&bs[j]==-1){
        ok=false;
      }
    }
    if(!ok)continue;

    rep(j,M){
      if(f[j]<=2)continue;
      ll rest=f[j]-2;
      repl(k,bs[j]+1,K){
        if(!used[k]){
          used[k]=true; rest--;
          if(rest==0)break;
        }
      }
      if(rest!=0){
        ok=false;
        break;
      }
    }
    if(!ok)continue;

    ll rest=(N+1)-(M-1);
    ll sel=0;
    ll cf=fac[M],scnt=0;
    rep(j,M){
      if(j>0&&f[j-1]==f[j])scnt++;
      else{
        cf*=finv[scnt]; cf%=mod;
        scnt=1;
      }
      if(f[j]==1){
        rest--;
        sel+=2;
      }else{
        rest-=(f[j]-1)*2-1;
        sel+=(f[j]-1)*2+2;
      }
    }
    cf*=finv[scnt]; cf%=mod;

    if(rest+sel-1>=0&&sel>=0)res+=comb[rest+sel-1][sel]*cf%mod;
    res%=mod;
  }
  res++;
  res%=mod;

  cout<<res<<endl;

  return 0;
}


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

int main(){
	ll n;
	cin >> n;
	vector<ll> h(n);
	rep(i,n){
		cin >> h[i];
	}
	ll m = h[0];
	bool ok = true;
	rep(i,n){
		if(m > h[i]+1) ok = false;
		m = max(m, h[i]);
	}
	if(ok){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
    return 0;
}



Measured memory_bytes: 1024
#include <iostream>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >
#define endl '\n'

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

template<class U, class V>
istream& operator >>(istream& in, pair<U, V>& pr) {
    return in >> pr.first >> pr.second;
}

template<class U, class V>
ostream& operator <<(ostream& out, pair<U, V>& p) {
    return out << p.first << " " << p.second;
}

template<class T>
ostream& operator <<(ostream& out, vector<T> vec) {
    for (T& e : vec)
        out << e << " ";
    return out << endl;
}

// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    int N;
    string S;
    cin >> N >> S;

    lint ret = 0;
    map<char, VEC(int)> iset;
    FOR(i, 0, N)
        iset[S[i]].push_back(i);

    FOR(i, 0, N)
        FOR(j, i + 1, N)
            if (S[j] != S[i]) {
                char other = (char)(('R' + 'G' + 'B') - S[i] - S[j]);
                VEC(int)& iv = iset[other];
                // k >= j + 1
                ret += END(iv) - lower_bound(ALL(iv), j + 1);
                if (j + j - i < N && S[j + j - i] == other)
                    ret--;
            }

    cout << ret << endl;
    return 0;
};

Measured memory_bytes: 3688
#include<bits/stdc++.h>                                                                                               
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(x) (x).begin(),(x).end()
#define int long long
using pii = pair<int,int>;

int l,r;
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m;
    int high=1000000,low= -1000;
    cin >> n >> m;
    rep(i,m){
        cin >> l >> r;
        if(l > low){
            low = l;
        }
        if(r < high){
            high = r;
        }
    }   
    if(high < low) cout << 0 << '\n';
    else cout << high - low + 1<< '\n';
    return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

struct UnionFind {
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) { }
 
    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};



int main() {
  long long N, M; cin >> N >> M;
  UnionFind uf(N);
  vector<long long> A(M), B(M);
  REP(i, M) {
    int a, b; cin >> a >> b; a--; b--;
    A[i] = a;
    B[i] = b;
  }
  vector<long long> ans(100100, N * (N - 1) / 2);
  for (long long i = M - 1; i >= 0; i--) {
    int a = A[i], b = B[i];
    if (!uf.issame(a, b)) ans[i] = ans[i + 1] - uf.size(a) * uf.size(b);
    else ans[i] = ans[i + 1];
    uf.merge(a, b);
  }
  for(int i = 1; i <= M; i++) cout << ans[i] << endl;
  return 0;
}

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

int main() {
  int n, k;
  cin >> n >> k;
  string s;
  cin >> s;

  vector<int> nums;
  int now = 1;
  int cnt = 0;

  for (int i = 0; i < n; i++) {
    if (s[i] == (char)('0' + now)) cnt++;
    else {
      nums.push_back(cnt);
      now = 1 - now;
      cnt = 1;
    }
  }
  if (cnt != 0) nums.push_back(cnt);

  if (nums.size() % 2 == 0) nums.push_back(0);

  int add = 2 * k + 1;
  vector<int> sum(nums.size() + 1);
  for (int i = 0; i < nums.size(); i++) {
    sum[i + 1] = sum[i] + nums[i];
  }

  int ans = 0;
  for (int i = 0; i < nums.size(); i += 2) {
    int left = i;
    int right = min(i + add, (int)nums.size());
    int tmp = sum[right] - sum[left];

    ans = max(tmp, ans);
  }

  cout << ans << endl;
}


Measured memory_bytes: 1272
#pragma GCC optimize(3)
#include<bits/stdc++.h>
#define MAXN 100005
#define INF 1000000000
#define MOD 1000000007
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int n,A,B,a[MAXN];
int main()
{
    scanf("%d%d%d",&n,&A,&B);
    int cnt0,cnt1,cnt2;
    cnt0=cnt1=cnt2=0;
    for(int i=1;i<=n;i++)
    {
        int x;
        scanf("%d",&x);
        if(x<=A) cnt0++; else if(x>B) cnt2++; else cnt1++;
    }
    printf("%d\n",min(min(cnt0,cnt1),cnt2));
    return 0;
}



Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String args[]){
        Scanner scanner = new Scanner(System.in);
        int N  = scanner.nextInt();
        HashMap<Long,Long> count = new HashMap<>();
        for(int i=0;i<N;i++){
            Long a = scanner.nextLong();
            if(count.containsKey(a)){
                count.put(a, count.get(a) + 1);
            }else{
                count.put(a,Long.valueOf(1));
            }
        }
        Long first = Long.valueOf(0);
        Long second = Long.valueOf(0);
        for(Long key :count.keySet()){
            if(count.get(key) >= 2){
                if(first < key){
                    first = key;
                }
            }
        }
        if(first!=0 && count.get(first)>=4){
            second = first;
        }else{
            for(Long key :count.keySet()){
                if(count.get(key) >= 2){
                    if(second < key && key!=first){
                        second = key;

                    }
                }
            }
        }
        System.out.println(first * second);
    }
}

Measured memory_bytes: 65428
#include<bits/stdc++.h>
typedef long long ll;
#define endl "\n";
using namespace std;
int main() {
#ifndef ONLINE_JUDGE
	freopen("input.in", "r", stdin);
	freopen("out.o", "w", stdout);
#endif
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	float n, x;
	int t;
	cin >> n >> x >> t;
	int k = ceil(n / x);
	n += k;
	cout << k * t;
}

Measured memory_bytes: 3728
#include <stdio.h>
#define EPSILON 0.001
int main(void){
    int a,b,c,d,e,f;
    double x,y;
    while(scanf("%d %d %d %d %d %d",&a,&b,&c,&d,&e,&f) != EOF){
        x = (double)(c*e-b*f)/(a*e-b*d);
        y = (double)(c*d-f*a)/(b*d-a*e);
        if(x < EPSILON && x > -EPSILON) x = 0;
        if(y < EPSILON && y > -EPSILON) y = 0;
        printf("%.3f %.3f\n",x,y);
    }
    return 0;
}

Measured memory_bytes: 636
#include <cstdio>
using namespace std;
int n,A[20];
int solve(int i,int m){
  if(m==0)return 1;
  if(i>=n)return 0;
  int res=solve(i+1,m)||solve(i+1,m-A[i]);
  return res;
}
int main(){
  int q,M;
  scanf("%d",&n);
  for(int i=0;i<n;i++)scanf("%d",&A[i]);
  scanf("%d",&q);
  for(int i=0;i<q;i++){
    scanf("%d",&M);
    if(solve(0,M))printf("yes\n");
    else printf("no\n");
  }
  return 0;
}

Measured memory_bytes: 2600
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int N,M,X; cin >> N >> M >> X;
    vector<int> A(M);
    for(int i = 0; i < M; i++)
    {
        cin >> A.at(i);
    }
    int left = 0; //左側のコスト
    int right = 0; //右側のコスト
    for(int i = 0; i < M; i++)
    {
        if(A.at(i) < X)
        {
            left++;
        }
        else
        {
            right++;
        }
    }
    cout << min(left,right) << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>

#ifdef WIN32
	#define LL "%I64d"
#else
	#define LL "%lld"
#endif

#ifdef CT
	#define debug(...) printf(__VA_ARGS__)
	#define setfile() 
#else
	#define debug(...)
	#define filename ""
	#define setfile() freopen(filename".in", "r", stdin); freopen(filename".out", "w", stdout)
#endif

#define R register
#define getc() (_S == _T && (_T = (_S = _B) + fread(_B, 1, 1 << 15, stdin), _S == _T) ? EOF : *_S++)
#define dmax(_a, _b) ((_a) > (_b) ? (_a) : (_b))
#define dmin(_a, _b) ((_a) < (_b) ? (_a) : (_b))
#define cmax(_a, _b) (_a < (_b) ? _a = (_b) : 0)
#define cmin(_a, _b) (_a > (_b) ? _a = (_b) : 0)
#define cabs(_x) ((_x) < 0 ? (- (_x)) : (_x))
char _B[1 << 15], *_S = _B, *_T = _B;
inline int F()
{
	R char ch; R int cnt = 0; R bool minus = 0;
	while (ch = getc(), (ch < '0' || ch > '9') && ch != '-') ;
	ch == '-' ? minus = 1 : cnt = ch - '0';
	while (ch = getc(), ch >= '0' && ch <= '9') cnt = cnt * 10 + ch - '0';
	return minus ? -cnt : cnt;
}
#define maxn 110
int a[maxn];
#define P std::pair<int, int>
#define mkp std::make_pair
#define fir first
#define sec second
std::priority_queue<P> q;
int main()
{
//	setfile();
	int k, n, last = 0;
	scanf("%d%d", &k, &n);
	for (int i = 1; i <= n; ++i) scanf("%d", &a[i]), q.push(mkp(a[i], i));
	for (; q.size() > 1; )
	{
		R P top = q.top(); q.pop();
		if (top.sec == last)
		{
			R P top2 = q.top(); q.pop();
			top2.fir--; last = top2.sec;
			q.push(top);
			if (top2.fir > 0) q.push(top2);
		}
		else
		{
			top.fir--; last = top.sec;
			if (top.fir > 0) q.push(top);
		}
	}
	printf("%d\n", q.top().fir - 1 );
	return 0;
}


Measured memory_bytes: 256
n=int(input())
t,a=map(int,input().split())
h=list(map(int,input().split()))
tmp=float('inf')
ans=0
for i in range(n):
    if tmp>abs(a-(t-h[i]*0.006)):
        ans=i
        tmp=abs(a-(t-h[i]*0.006))
print(ans+1)

Measured memory_bytes: 3064
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype

template <class T>
int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define popcount __builtin_popcount

template <class T> void max_swap(T& a, const T b) { a = max(a, b); }
template <class T> void min_swap(T& a, const T b) { a = min(a, b); }

const double EPS = 1e-10;
typedef long long ll;
typedef pair<int, int> pint;


int main()
{
	static char a[4096], b[4096];
	while (~scanf("%s%s", a, b))
	{
		int n = strlen(a);
		int m = strlen(b);
		int res = 0;
		for (int i = 1 - m; i < n; ++i)
		{
			int len = 0;
			for (int j = 0 + max(0, -i), k = max(0, i); j < m && k < n; ++j, ++k)
			{
				if (a[k] == b[j])
					max_swap(res, ++len);
				else
					len = 0;
			}
		}
		printf("%d\n", res);
	}
}

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

const int MOD = 1000000007;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define copy(from, to) copy(from.begin(), from.end(), back_inserter(to))
#define _sort(a) sort(a.begin(), a.end())
#define _sortd(a) sort(a.rbegin(), a.rend())
#define reverse(s) reverse(s.begin(), s.end())
#define p(s) cout << (s) << endl

typedef long long ll;
using namespace std;

template<class T>
void load(vector<T> &v, int n) {
  for (int i = 0; i < n; ++i) {
    T t;
    cin >> t;
    v.push_back(t);
  }
}

template<class T>
T max(vector<T> &v) {
  return *max_element(v.begin(), v.end());
}

template<class T>
T min(vector<T> &v) {
  return *min_element(v.begin(), v.end());
}

void py(bool isUpper = false) {
  if (isUpper) {
    p("YES");
  } else {
    p("Yes");
  }
}

void pn(bool isUpper = false) {
  if (isUpper) {
    p("NO");
  } else {
    p("No");
  }
}

int main() {
  int n, k, q;
  cin >> n >> k >> q;

  int win[1000000] = {0};
  rep(i, q) {
    int a;
    cin >> a;
    win[a-1]++;
  }

  rep(i, n) {
    if (k - (q - win[i]) <= 0) {
      p("No");
    } else {
      p("Yes");
    }
  }
}

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

int main() {
  int N;
  cin >> N;
    
  int x = 0;
  
  if (N % 2 == 0) {
    x = N / 2;
  }
  else {
    x = (N / 2) + 1;
  }
  
  cout << x << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    vector<int> A(N); 
    vector<int> B(N);
    vector<int> C(N);
    rep(i, N) cin >> A[i];
    rep(i, N) cin >> B[i];
    rep(i, N) cin >> C[i];
    sort(A.begin(), A.end());
    sort(C.begin(), C.end());
    ll ans = 0;
    rep(i, N) {
        decltype(A)::iterator a;
        decltype(C)::iterator c;
        a = lower_bound(A.begin(), A.end(), B[i]);
        c = upper_bound(C.begin(), C.end(), B[i]);
        ans += (a - A.begin()) * (C.end() - c);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1408
#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 O, E;
  cin >> O >> E;
  int end = O.size();
  for (int i = 0; i < end; i++) {
    cout << O.at(i);
    if (E.size() < (size_t)end && i == end - 1)
      break;
    cout << E.at(i);
  }
  cout << endl;
}

Measured memory_bytes: 256
import sys

N = int(input())
A = list(map(int, sys.stdin.readline().rsplit()))

for i in range(N):
    A[i] = A[i] - (i + 1)

A.sort()
b = A[(N - int(N % 2 == 0)) // 2]

res = 0
for a in A:
    res += abs(a - b)

print(res)


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

#define int long long
int32_t main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
double t,x;
cin>>t>>x;
cout<<fixed<<setprecision(9)<<t/x<<endl;
return 0;
}

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

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

int student[100][100];
bool target[100][100];

int main(){
	while(true){
		int n;
		cin>>n;
		if(!n)break;
		for(int y=0;y<n;y++){
			for(int x=0;x<n;x++){
				cin>>student[y][x];
				target[y][x] = false;
			}
		}
		for(int y=0;y<n;y++){
			int min_st = 1e5;
			int min_x = -1;
			for(int x=0;x<n;x++){
				if(min_st>student[y][x]){
					min_st = student[y][x];
				}
			}
			for(int x=0;x<n;x++)
				if(min_st == student[y][x])
					target[y][x] = true;
		}

		int ans = 0;
		for(int x = 0;x<n;x++){
			int max_st = 0;
			int max_y = -1;
			for(int y=0;y<n;y++){
				if(max_st<student[y][x]){
					max_y = y;
					max_st = student[y][x];
				}
			}
			for(int y=0;y<n;y++){
				if(max_st == student[y][x]){
					if(target[y][x]){
						ans = student[y][x];
					}
				}
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}

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

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

int main()
{
    int r, d, x;
    cin >> r >> d >> x;

    rep(i, 10)
    {
        x = r * x - d;
        cout << x << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#include <cstdio>
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stdio.h>
#include <stack>
#include <queue>
#include <deque>
#include <numeric>
#include<bits/stdc++.h>
#include <utility>

#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,a,b) for(int i = (a); (b) <= i; i--)
#define REP(i,n) for(int i = 0; i < (n); i++)
#define RREP(i,n) for(int i = n; n <= i; i--)
#define ABS(a) ((a < 0) ? ((-1)*(a)) : (a))
#define elif else if
#define MOD 1000000007
#define INF (1<<29)

using namespace std;
using ll = long long;
map <int ,int> mpa,mpb;
typedef pair<ll, ll> P;
priority_queue<P, vector<P>, greater<P>> pque;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  string S,T;
  cin >> S >> T;
  int a[26]={0},b[26]={0};
  int N=S.size();
  for(int i=0;i<N;i++){
    a[S[i]-'a']++;
    b[T[i]-'a']++;
  }
  sort(a,a+26);
  sort(b,b+26);
  bool flag=true;
  for(int i=0;i<26;i++){
    if(a[i]!=b[i]){
      flag =false;
    }
  }

  if(flag){
    cout << "Yes"<< endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 916