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

#define for_(i,a,b) for(int i=(a);i<(b);++i)
typedef long long lint;
template< typename T > void modMul(T& a, T b, T m) { a = (a*b)%m; }
template< typename T > void modAdd(T& a, T b, T m) { a = (a+b+m)%m; }

lint n, a[100005], fact[100005], inv[100005];
const lint MOD = (lint)1e9 + 7;

lint power(lint x, lint k) {
	lint res = 1;
	while (k) {
		if (k&1) modMul(res, x, MOD);
		modMul(x, x, MOD);
		k >>= 1;
	}
	return res;
}

void pre() {
	fact[0] = fact[1] = 1;
	for_(i,2,n+2) fact[i] = (fact[i-1] * i) % MOD;
	for_(i,0,n+2) inv[i] = power(fact[i], MOD-2);
}

lint nCk(int n, int k) {
	if (n < k) return 0;
	lint res = fact[n];
	modMul(res, inv[n-k], MOD);
	modMul(res, inv[k], MOD);
	return res;
}

int main() {
	cin >> n;
	for_(i,0,n+1) cin >> a[i];
	
	pre();
	
	lint x = accumulate(a, a+n+1, lint()) - (lint)n*(n+1)/2;
	
	int L = -1, R = -1;
	for_(i,0,n+1) {
		if (a[i] == x) {
			if (L == -1) L = i;
			else R = n-i;
		}
	}
	
	cout << n << endl;
	for_(k,2,n+2) {
		lint ans = nCk(n+1,k);
		modAdd(ans, -nCk(L+R, k-1), MOD);
		cout << ans << endl;
	}
}

Measured memory_bytes: 3584
const int LG = 21;
const int FN = 400005;
const long long MOD = 1e9 + 7;
const long long INF = 1e9;
const long long INFLL = 1e18;

#include <bits/stdc++.h>

using namespace std;
#define int long long
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;

#define forn(i, n) for (int (i) = 0; (i) != (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define fi first
#define se second
#define re return
#define pb push_back
#define uniq(x) sort(all(x)); (x).resize(unique(all(x)) - (x).begin())

#ifdef LOCAL
#define dbg(x) cerr << __LINE__ << " " << #x << " " << x << endl
#define ln cerr << __LINE__ << endl
#else
#define dbg(x) void(0)
#define ln void(0)
#endif // LOCAL

int cx[4] = {-1, 0, 1, 0};
int cy[4] = {0, -1, 0, 1};
string Yes[2] = {"No", "Yes"};
string YES[2] = {"NO", "YES"};

ll inq(ll x, ll y)
{
    if (!y) re 1 % MOD;
    ll l = inq(x, y / 2);
    if (y % 2) re l * l % MOD * x % MOD;
    re l * l % MOD;
}

ll rev(ll x)
{
    return inq(x, MOD - 2);
}

bool __precomputed_combinatorics = 0;
vector<ll> __fact, __ufact, __rev;

void __precompute_combinatorics()
{
    __precomputed_combinatorics = 1;
    __fact.resize(FN);
    __ufact.resize(FN);
    __rev.resize(FN);
    __rev[1] = 1;
    for (int i = 2; i < FN; i++) __rev[i] = MOD - __rev[MOD % i] * (MOD / i) % MOD;
    __fact[0] = 1, __ufact[0] = 1;
    for (int i = 1; i < FN; i++) __fact[i] = __fact[i - 1] * i % MOD, __ufact[i] = __ufact[i - 1] * __rev[i] % MOD;
}

ll fact(int x)
{
    if (!__precomputed_combinatorics) __precompute_combinatorics();
    return __fact[x];
}

ll cnk(int n, int k)
{
    if (k < 0 || k > n) return 0;
    if (!__precomputed_combinatorics) __precompute_combinatorics();
    return __fact[n] * __ufact[n - k] % MOD * __ufact[k] % MOD;
}

int Root(int x, vector<int> &root)
{
    if (x == root[x]) return x;
    return root[x] = Root(root[x], root);
}

void Merge(int v, int u, vector<int> &root, vector<int> &sz)
{
    v = Root(v, root), u = Root(u, root);
    if (v == u) return;
    if (sz[v] < sz[u])
    {
        sz[u] += sz[v];
        root[v] = u;
    }
    else
    {
        sz[v] += sz[u];
        root[u] = v;
    }
}

int ok(int x, int n)
{
    return 0 <= x && x < n;
}

void bfs(int v, vi &dist, vector<vi> &graph)
{
    fill(all(dist), -1);
    dist[v] = 0;
    vi q = {v};
    for (int i = 0; i < q.size(); i++)
    {
        for (auto u : graph[q[i]])
        {
            if (dist[u] == -1)
            {
                dist[u] = dist[q[i]] + 1;
                q.push_back(u);
            }
        }
    }
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    string s;
    cin >> s;
    cout << accumulate(all(s), -3 * '0');
}

/* Note:
Check constants at the beginning of the code.
    N is set to 4e5 but be careful in problems with large constant factor.
    Setting N in every problem is more effective.
Check corner cases.
    N = 1
No def int long long for now.
Add something here.
*/


Measured memory_bytes: 256
n = int(input())
a, b = map(int, input().split())
p = list(map(int, input().split()))
x1 = 0
x2 = 0
x3 = 0
for i in p:
  if i <= a:
    x1 += 1
  elif i <= b:
    x2 += 1
  else:
    x3 += 1
print(min(x1, x2, x3))


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<long long> a(n);
  for(int i = 0; i < n; i++) cin >> a.at(i);
  sort(a.begin(), a.end());
  long long p = 1;
  long long x = pow(10,18);
  long long y = pow(10,9);
  for(int i = 0; i < n; i++) {
    if(p > y && a.at(i) > y) {
      p = -1;
      break;
    }
    p *= a.at(i);
    if(p == 0) break;
    if(p > x) {
      p = -1;
      break;
    }
  }
  cout << p << endl;
}

Measured memory_bytes: 4040
use proconio::{input, fastout};
use std::cmp::max;
use num::abs;


#[fastout]
fn main() {
    input! {
        n: usize,
        aaa: [usize; n],
    }

    let mut aaa_with_idx: Vec<(usize, &usize)> = aaa.iter().enumerate().collect();
    aaa_with_idx.sort_by(|a, b| { a.1.cmp(b.1) });
    aaa_with_idx.reverse();

    let ni = n as isize;

    let mut dp = vec![0];

    for k in 1..=n {
        let mut ndp = vec![0; k + 1];
        let ai = aaa_with_idx[k - 1];
        let ki = k as isize;
        let i = ai.0 as isize;
        let a = *ai.1 as isize;
        for l in 0..k {
            let li = l as isize;
            ndp[l + 1] = max(ndp[l + 1], dp[l] + a * abs(i - li));
            ndp[l] = max(ndp[l], dp[l] + a * abs(ni - ki + li - i));
        }
        dp = ndp;
    }

    let ans = dp.iter().max().unwrap();

    println!("{:?}", ans);
}

Measured memory_bytes: 2352
#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <iomanip>
 
using namespace std;
#define LOCAL  1
#define UPLOAD 2
#define ll long long
ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
template <class T = long long> T input(){T x;cin >> x;return x;}
template <class T> void output(T x){cout << x << endl;}
#define debug(x) cerr << #x<< ": " << x<< '\n';
#define debugBit(x,n) cerr << #x<< ": " << std::bitset<n>(x) << '\n';
 
int main()
{
#if LOCAL_ENVIRONMENT == 1
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
#endif
  ll N = input();
  ll W = input();

  vector<ll> weight;
  vector<ll> value;
  
  for(ll i=0;i<N;i++){
    ll w = input();
    ll v = input();
    weight.push_back(w);
    value.push_back(v);
  }

  ll dp[N+1][W+1];

  for(int w=0;w<=W;w++){
    dp[0][w] = 0;
  }

  for(int i=0;i<N;i++){
    for(int w=0;w<=W;w++){
      if(weight[i] <= w){
        dp[i+1][w] = max(dp[i][w], dp[i][w-weight[i]] + value[i]);
      }
      else{
        dp[i+1][w] = dp[i][w];
      }
    }
  }

  output(dp[N][W]);

  return 0;
}

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

using namespace std;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define blank(ans) cout << (ans) << " ";
#define mp(p, q) make_pair(p, q)
#define mt(p, q, r) make_tuple(p, q, r)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef string str;

typedef vector<ll> vll;
typedef vector<ld> vd;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<str> vs;
typedef vector<vector<ll>> vvll;
typedef vector<vector<ld>> vvd;
typedef vector<vector<bool>> vvb;
typedef vector<vector<char>> vvc;
typedef vector<vector<str>> vvs;
typedef vector<pair<ll, ll>> vpll;
typedef vector<tuple<ll, ll, ll>> vtlll;

const ld PI = acos(-1.0);
const ll MAX = 9000000000000000000;
const ll MIN = -9000000000000000000;
const ld DMAX = 4500;
const ld DMIN = -4500;
const ll MOD = 1000000007;

template <typename T>
void fin(T a)
{
  cout << a << endl;
  exit(0);
}

//桁数
ll GetDigit(ll num)
{
  return log10(num) + 1;
}

//約数全列挙
vector<ll> enum_div(ll n)
{
  vector<ll> ret;
  for (ll i = 1; i * i <= n; ++i)
  {
    if (n % i == 0)
    {
      ret.push_back(i);
      if (i * i != n)
      {
        ret.push_back(n / i);
      }
    }
  }
  sort(begin(ret), end(ret));
  return ret;
}

//累乗(xのn乗%mod)
ll modpow(ll x, ll n, ll mod = MAX)
{
  ll res = 1;
  while (n > 0)
  {
    if (n & 1)
      res = res * x % mod;
    x = x * x % mod;
    n >>= 1;
  }
  return res;
}

//階乗
ll factorial(ll n)
{
  if (n > 0)
    return n * factorial(n - 1);
  else
    return 1;
}

ll modinv(ll a, ll mod)
{
  ll b = mod, u = 1, v = 0;
  while (b)
  {
    ll t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= mod;
  if (u < 0)
    u += mod;
  return u;
}

void Main()
{
  ll n, x;
  cin >> n >> x;
  vll a(n);
  rep(i, n) cin >> a[i];
  ll ans = 0;
  if(a[0] > x)
  {
    ans += (a[0] - x);
    a[0] -= (a[0] - x);
  }
  for(ll i = 1;i < n;i++)
  {
    ll flag = a[i - 1] + a[i];
    if(flag > x)
    {
      if(flag > x)
      {
        ans += flag - x;
        a[i] -= flag - x;
      }
      else
      {
        ans += a[i];
        a[i] = 0;
      }
    }
  }
  fin(ans);
}

//前処理
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(20); //高精度少数表示
  //cout << setfill('0') << internal << setw(4); 0埋め４桁
  Main();
  return 0;
}


Measured memory_bytes: 1024
from collections import Counter
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**9)

def solve():
    INF = 10**10

    # Union-Findデータ構造
    class UnionFind:
        def __init__(self, numV):
            self.pars = list(range(numV))
            self.ranks = [0] * numV
        def getRoot(self, x):
            par = self.pars[x]
            if par != x:
                self.pars[x] = par = self.getRoot(par)
            return par
        def merge(self, x, y):
            x, y = self.getRoot(x), self.getRoot(y)
            if x == y: return
            if self.ranks[x] < self.ranks[y]:
                self.pars[x] = y
            else:
                self.pars[y] = x
                if self.ranks[x] == self.ranks[y]:
                    self.ranks[x] += 1
        def isSame(self, x, y):
            return self.getRoot(x) == self.getRoot(y)
        def updatePars(self):
            for v in range(len(self.pars)):
                self.getRoot(v)

    N = int(input())
    #pts = [tuple(map(lambda x: int(x)-1, input().split())) for _ in range(N)]
    pts = []
    for i in range(N):
        x, y = map(int, input().split())
        x, y = x-1, y-1
        pts.append((x, y, i))

    UF = UnionFind(N)

    # x昇順
    pts.sort(key=lambda x: x[0])
    stack = [(INF, INF, -1)]
    for x, y, i in pts:
        while stack[-1][1] < y:
            x0, y0, i0 = stack.pop()
            UF.merge(i0, i)
        stack.append((x, y, i))

    # x降順
    #pts.sort(key=lambda x: x[0])
    stack = [(-INF, -INF, -1)]
    for x, y, i in reversed(pts):
        while stack[-1][1] > y:
            x0, y0, i0 = stack.pop()
            UF.merge(i0, i)
        stack.append((x, y, i))

    # y昇順
    pts.sort(key=lambda x: x[1])
    stack = [(INF, INF, -1)]
    for x, y, i in pts:
        while stack[-1][0] < x:
            x0, y0, i0 = stack.pop()
            UF.merge(i0, i)
        stack.append((x, y, i))

    # y降順
    #pts.sort(key=lambda x: x[1])
    stack = [(-INF, -INF, -1)]
    for x, y, i in reversed(pts):
        while stack[-1][0] > x:
            x0, y0, i0 = stack.pop()
            UF.merge(i0, i)
        stack.append((x, y, i))


    UF.updatePars()
    #print('# UF.pars:', UF.pars, file=sys.stderr)

    cnt = Counter(UF.pars)
    #print('# cnt:', cnt, file=sys.stderr)

    anss = [0] * N
    for i in range(N):
        anss[i] = cnt[UF.pars[i]]

    print('\n'.join(map(str, anss)))


solve()


Measured memory_bytes: 69552
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
static const int MAX = 10000;

int solve_coin_changing1(vector<int> coins, int target) {
  vector<vector<int>> com = {{0}};
  com.push_back(coins);
  bool data[50000] = {false};

  for (int n = 2; n <= 10000; n++) {
    vector<int> b;
    cout << n << endl;
    for (int i = 1; i <= n / 2; i++) {
      for (int j = 0; j < com[i].size(); j++) {
        for (int k = j; k < com[n - i].size(); k++) {
          int val = com[i][j] + com[n - i][k];
          if (val == target) {
            return n;
          }
          if (!data[val]) {
            b.push_back(val);
            data[val] = true;
          }
        }
      }
    }
    cout << b.size() << endl;
    com.push_back(b);
  }
  return -1;
}
int solve_coin_changing(vector<int> coins, int target) {
  int need_ncoin[50001];
  sort(coins.begin(), coins.end());
  auto cp = coins.begin();

  for (int i = 1; i <= target; i++) {
    if (*cp == i) {
      need_ncoin[i] = 1;
      cp++;
      continue;
    }
    int minimum = 50000;
    for(int j=1; j <=i/2; j++) {
      int ncoin = need_ncoin[i-j] + need_ncoin[j];
      minimum = min(minimum, ncoin);
      if (ncoin == 2)
        break;
    }
    need_ncoin[i] = minimum;
  }
  return need_ncoin[target];
}

int main() {
  int ncoin, target;
  cin >> target >> ncoin;
  vector<int> coins;
  for (int i = 0; i < ncoin; i++) {
    int val;
    cin >> val;
    coins.push_back(val);
  }
  cout << solve_coin_changing(coins, target) << endl;
}

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

int		main(void)
{
	string	a;
	int		cnt = 0;
	cin >> a;
	for (auto &i : a)
	{
		if (i == '1')
			cnt++;
	}
	cout << cnt << endl;
}

Measured memory_bytes: 256
n,a,b=map(int, input().split())
s=input()
pass_all=0
pass_foreigner=0

for i in range(n):
    if s[i]=='a':
        if pass_all<a+b:
            pass_all+=1
            print("Yes")
        else:
            print("No")
    
    elif s[i]=='b':
        if pass_all<a+b and pass_foreigner<b:
            pass_all+=1
            pass_foreigner+=1
            print("Yes")
        else:
            print("No")
    
    else:
        print("No")

Measured memory_bytes: 4016
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
const double EPS = 1e-10;
struct Point{
  double x,y;
  Point(){}
  Point(double x,double y):x(x),y(y){}
  Point operator+(Point a){return Point(x+a.x,y+a.y);}
  Point operator-(Point a){return Point(x-a.x,y-a.y);}
};
typedef Point Vector;

struct Segment{
  Point p1,p2;
  Segment(){}
  Segment(Point p1,Point p2):p1(p1),p2(p2){}
};
typedef Segment Line;

double dot(Vector a,Vector b){
  return a.x*b.x+a.y*b.y;
}

double cross(Vector a,Vector b){
  return a.x*b.y-a.y*b.x;
}

double norm(Vector a){
  return dot(a,a);
}

double abs(Vector a){
  return sqrt(norm(a));
}

/*
1
-1
2
-2
0
 */
Int ccw(Point p0,Point p1,Point p2){
  Vector a=p1-p0;
  Vector b=p2-p0;
  if(cross(a,b) > EPS) return 1;
  if(cross(a,b) < -EPS) return -1;
  if(dot(a,b) < -EPS) return 2;
  if(norm(a)<norm(b)) return -2;
  return 0;
}

bool intersectSS(Point p1,Point p2,Point p3,Point p4){
  return (ccw(p1,p2,p3)*ccw(p1,p2,p4) <= 0 && ccw(p3,p4,p1)*ccw(p3,p4,p2) <= 0);
}

bool intersectSS(Segment s1,Segment s2){
  return intersectSS(s1.p1,s1.p2,s2.p1,s2.p2);
}

double getDistanceLP(Line l,Point p){
  return abs(cross(l.p2-l.p1,p-l.p1)/abs(l.p2-l.p1));
}

double getDistanceSP(Segment s,Point p){
  if(dot(s.p2-s.p1,p-s.p1) < 0.0) return abs(p-s.p1);
  if(dot(s.p1-s.p2,p-s.p2) < 0.0) return abs(p-s.p2);
  return getDistanceLP(s,p);
}
double getDistanceSS(Segment s1,Segment s2){
  if(intersectSS(s1,s2)) return 0.0;
  return min({getDistanceSP(s1,s2.p1),getDistanceSP(s1,s2.p2),
	getDistanceSP(s2,s1.p1),getDistanceSP(s2,s1.p2)});
}

Int cnt[111][111];
signed main(){  
  cin.tie(0);
  ios::sync_with_stdio(0);
  Int n;
  cin>>n;
  vector<Segment> vs(n);
  memset(cnt,0,sizeof(cnt));
  for(Int i=0;i<n;i++){
    Int x1,y1,x2,y2;
    cin>>x1>>y1>>x2>>y2;
    cnt[x1][y1]++;
    cnt[x2][y2]++;
    vs[i]=Segment(Point(x1,y1),Point(x2,y2));
  }
  cout<<fixed<<setprecision(12);
  for(Int i=0;i<111;i++){
    for(Int j=0;j<111;j++){
      if(cnt[i][j]>1){
	cout<<0.0<<endl;
	return 0;
      }
    }
  }
  assert(n<5555);
  double ans=getDistanceSS(vs[0],vs[1]);
  for(Int i=0;i<n;i++)
    for(Int j=i+1;j<n;j++)
      ans=min(ans,getDistanceSS(vs[i],vs[j]));
  cout<<ans<<endl;
  return 0;
}



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

int main() {
  int H,W;
  cin>>H>>W;
  vector<vector<char>> Rectangle(H,vector<char>(W));
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cin>>Rectangle.at(i).at(j);
    }
  }
  for(int i=0;i<2*H;i++){
    for(int j=0;j<W;j++){
      cout<<Rectangle.at(i/2).at(j);
    }
    cout<<endl;
  }
}

Measured memory_bytes: 256
splitline()=split(readline())
parseInt(x)=parse(Int,x)
parseMap(x::Array{SubString{String},1})=map(parseInt,x)

function main()
    n = parseInt(readline())
    a = parseMap(splitline())

    ans = 0
    for i in 1:n
        while a[i]%2 == 0
            a[i] /= 2
            ans += 1
        end
    end

    println(ans)
end

main()


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

static const double PI = 6*asin( 0.5 );
int main()
{
	double east=0.0,north=0.0,theta=90;
	double dm,dt;
	char dot;
	while(cin >> dm && cin >> dot && cin >> dt){
		if(dm==0 && dt==0)
			break;
		east += dm*cos(theta*PI/180);
		north += dm*sin(theta*PI/180);
		theta-=dt;
	}
	cout << static_cast<int>(east) << endl;
	cout << static_cast<int>(north) << endl;
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define rep(i,c) for(int i=0;i<c;++i)
int  main(){
  int  a;
  cin >> a;
  long long  count = 0;
  for(long long i= 1;i<=a;i++){
    if(i%3!=0&&i%5!=0) count +=i;
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 3640
import sys
import heapq

input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


def main():
    N, M = map(int, input().split())

    H = []
    for i in list(map(int, input().split())):
        heapq.heappush(H, (-i, 1))

    for i in range(M):
        b, c = map(int, input().split())
        heapq.heappush(H, (-c, b))

    cnt = 1
    ans = 0
    while cnt <= N:
        c, b = heapq.heappop(H)
        c = -c
        ans += c
        if b > 1:
            b -= 1
            heapq.heappush(H, (-c, b))
        cnt += 1

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 27208
#include <iostream>

using namespace std;

main(){
  int h, m, s;
  while(1){
    cin >> h >> m >> s;
    if(h==-1 && m==-1 && s==-1) break;

    int rec=h*3600+m*60+s;
    int ans=120*60-rec;
    int ans3=ans*3;
    int a1, a2, a3;
    a1=ans/3600;
    ans-=a1*3600;
    a2=ans/60;
    ans-=a2*60;
    a3=ans;
    if(a1<10) cout << 0;
    printf("%d:", a1);
    if(a2<10) cout << 0;
    printf("%d:", a2);
    if(a3<10) cout << 0;
    printf("%d\n", a3);

    a1=ans3/3600;
    ans3-=a1*3600;
    a2=ans3/60;
    ans3-=a2*60;
    a3=ans3;
    if(a1<10) cout << 0;
    printf("%d:", a1);
    if(a2<10) cout << 0;
    printf("%d:", a2);
    if(a3<10) cout << 0;
    printf("%d\n", a3);
  }
  return 0;
}

Measured memory_bytes: 0
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<limits.h>

int main(){
	int k,s,x,y,z;
	int pattern=0;
	scanf("%d %d",&k,&s);
	
	for(x=0;x<=k;x++){
		for(y=0;y<=k;y++){
			if(x+y>s){
				break;
			}
			z=s-x-y;
			if(z<=k){
				pattern++;
			}
		}
	}
	
	printf("%d\n",pattern);
	
	return 0;
}

Measured memory_bytes: 128
N = int(input())

maxA1 = 0
maxi = 0
maxA2 = 0
for i in range(N):
    a = int(input())
    if maxA1<a:
        maxA2 = maxA1
        maxA1 = a
        maxi = i
    elif maxA2<a:
        maxA2 = a

for i in range(N):
    if i == maxi:
        print(maxA2)
    else:
        print(maxA1)

Measured memory_bytes: 4540
#include <cassert>
#include <iostream>
#include <functional>
#include <iomanip>
#include <set>
#include <unordered_map>
#include <map>
#include <queue>
#include <vector>
#include <deque>
#include <algorithm>
#include  <cstring>
#include <string>
#include <cmath> 
#include <random>

#pragma warning(disable: 4996)

using namespace std;
 
namespace Bigcat {
	template <typename T> inline void max_s(T&a, const T&b) { a = max(a, b); }
	template <typename T> inline void min_s(T&a, const T&b) { a = min(a, b); }

	template <typename T>  void sort_v(T & x) { sort(x.begin(), x.end()); }
	template <typename T>  void erase_dup(T & x) { x.erase(unique(x.begin(), x.end()), x.end()); }    // erase duplicate
	template <typename T, typename V>  int pos_l(const T & x, const V & v) { return lower_bound(x.begin(), x.end(), v) - x.begin(); }
	template <typename T, typename V>  int pos_u(const T & x, const V & v) { return upper_bound(x.begin(), x.end(), v) - x.begin(); }

	inline unsigned rand_g() {
		static mt19937 mt_rand((int)time(0));
		return mt_rand();
	}

	using LL = long long;


	using VI = vector<int>;
	using VVI = vector< VI >;
	using VL = vector<LL>;
	using PII = pair<int, int>;
	using VPII = vector< PII >;

}
using namespace Bigcat;
const int MAX = int ( 2e5 + 100 ) ;
const LL base = LL(1e9 + 7);
const LL INFL = 4223372036854775807LL;
const int INF = 1047483647;


struct Node {
	LL a, b;
	LL t;
};
bool operator < (const Node & n0, const Node & n1) {
	return n0.t< n1.t;
}
void solve1() {
	 
	LL result = 0;
	int n;

	cin >> n;
	vector<Node > zd(n);
	for (int i = 0; i < n; ++i) {
		cin >> zd[i].a >> zd[i].b;
		zd[i].t = zd[i].a + zd[i].b;
	}
	sort(zd.begin(), zd.end());
	int c = 0;
	for (int i = n - 1; i >= 0; --i) {
		++c;
		if (c % 2 == 1) {
			result += zd[i].a ;
		}
		else {
			result -=   zd[i].b;
		}
	}

	cout << result << endl;

}
void solve() {
	int t = 1;
	//cin >> t;
	for (int i = 0; i < t; ++i) {
		solve1();
	}
    int x = 1;
}

int main() {
	const int inId = 0;
	const int outId = 0;
	if (inId>0) {
		cerr << "redirect stdin to input " << inId << endl;
		string s = "input";
		s += to_string(inId);
		s += ".txt";
		auto r = freopen(s.c_str(), "r", stdin);
		if (r == nullptr) {
			cerr << "invalid input file " << s << endl;;
			r = freopen("CON", "r", stdin);
		}
	}
	if (outId>0) {
		cerr << "redirect stdout to stdout " << outId << endl;
		string s = "stdout";
		s += to_string(outId);
		s += ".txt";
		auto r = freopen(s.c_str(), "w", stdout);
		if (r == nullptr) {
			cerr << "invalid output file " << s << endl;;
			r = freopen("CON", "w", stdout);
		}
	}
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); // close sync between cout and printf
	cout.precision(10);
	solve();
}


Measured memory_bytes: 2560
import math
N=int(input())
ans=0
X=[0]*N
Y=[0]*N
leng=[]
for i in range(N):
    x,y=map(int,input().split())
    X[i]=x
    Y[i]=y
for i in range(N):
    for j in range(N):
        leng.append(((X[i]-X[j])**2+(Y[i]-Y[j])**2)**0.5)
ans=sum(leng)/N
print(ans)

Measured memory_bytes: 3064
#include <stdio.h>

int main(){
   int h, w, m, n;
   scanf("%d %d", &h, &w);

  while( h != 0 | w != 0){
      for(m=1;m<=h;m++){
         for(n=1;n<=w;n++){
            printf("#");
         }
         printf("\n");
      }
      printf("\n");
      scanf("%d %d", &h, &w);
   }
   return 0;
}

Measured memory_bytes: 1740
#include <stdio.h>

int A[1000000],n;

//BinarySearch
int binarySearch(int key)
{
    int left=0;
    int right=n;
    int mid;
    while(left<right)
    {
        mid=(left+right)/2;
        if(key==A[mid])return 1;//find key!
        if(key>A[mid])left=mid+1;//next search right side
        else if(key<A[mid])right=mid;//next search left side

    }
    return 0;
}

int main()
{
    int i,q,k,sum=0;

    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%d",&A[i]);
    }

    scanf("%d",&q);
    for(i=0;i<q;i++)
    {
        scanf("%d",&k);
        if(binarySearch(k))sum++;
    }

    printf("%d\n",sum);

    return 0;
}


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

int main()
{
  string s;
  cin >> s;
  int size = s.size();
  string ans = "";
  for (int i = 0; i < size; i++)
  {
    if(s.at(i) == '0') ans += "0";
    if(s.at(i) == '1') ans += "1";
    if(s.at(i) == 'B')
      if(ans.size() == 0) continue;
      else ans.pop_back();
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
//In The Name of Allah
#include <bits/stdc++.h>

using namespace std;

const int N = 5000 + 10;

int a[N], n, k;

bool check(int x){
    bitset < N > dp;
    dp[0] = 1;
    for (int i = 1; i < x; i ++)
        dp |= dp << a[i];
    for (int i = x + 1; i <= n; i ++)
        dp |= dp << a[i];
    bool f = 0;
    for (int i = max(0, k - a[x]); i < k; i ++)
        f |= dp[i];
    return f;
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin >> n >> k;
    for (int i = 1; i <= n; i ++)
        cin >> a[i];
    sort(a + 1, a + n + 1);
    int l = 0, r = n + 1;
    while (1 < r - l){
        int mid = (l + r) / 2;
        if (check(mid))
            r = mid;
        else
            l = mid;
    }
    cout << l;
    return 0;
}


Measured memory_bytes: 3676
K, S = map(int, input().split())

count = 0
for x in range(K+1):
    if S-x<=2*K and S-x>=0:
        for y in range(K+1):
            if S-x-y<=K and S-x-y>=0:
                count += 1
#                 for z in range(K+1):
#                     if x+y+z==S:
#                         count += 1
print(count)

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

long long n, t, p, c, m[100001], a[100001];
int main(){
	cin >> n >> t;
	m[0] = INT_MAX;
	for(int i = 1; i <= n; i++){
		cin >> a[i];
		m[i] = min(a[i], m[i-1]);
	}
	for(int i = 1; i <= n; i++){
		if(a[i]-m[i] > p){
			p = a[i]-m[i];
			c = 1;
		} else if(a[i]-m[i] == p) c++;
	}
	cout << c;
}

Measured memory_bytes: 1792
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        if (n % k == 0) {
            System.out.println(0);
        } else {
            System.out.println(1);
        }
    }
}

Measured memory_bytes: 21844
#include <iostream>
#include <stdio.h>
#include <vector>
using namespace std;
const int N=123456;
vector<int> vec[N];
int pre[N];
int flag,n;
int dis[N];
int ans;
void dfs_1(int c,int f,int u){
	pre[c]=f;
	dis[c]=u;
	if(flag){
		return;
	}
	if(c==n){
		flag=1;
		return;
	}
	for(int x:vec[c]){
		if(x!=f){
			dfs_1(x,c,u+1);
		}
	}
}
void dfs_2(int c,int f){
	ans++;
	for(int x:vec[c]){
		if(x!=f){
			dfs_2(x,c);
		}
	}
}
int main(){
	scanf("%d",&n);
	for(int i=0;i<n-1;i++){
		int u,v;
		scanf("%d %d",&u,&v);
		vec[u].push_back(v);
		vec[v].push_back(u);
	}
	flag=0;
	dfs_1(1,0,0);
	int s=n,f;
	int d=dis[n]/2;
	while(s!=1){
		f=s;
		s=pre[s];
		if(dis[s]==d){
			break;
		}
	}
	ans=0;
	dfs_2(s,f);
	if((n-ans)<ans){
		puts("Fennec");
	} else {
		puts("Snuke");
	}
	return 0;
}


Measured memory_bytes: 11776
<?php
  list($n) = explode(" ", trim(fgets(STDIN)));
  $a = [];
  list($a[]) = explode(" ", trim(fgets(STDIN)));
  list($a[]) = explode(" ", trim(fgets(STDIN)));
  list($a[]) = explode(" ", trim(fgets(STDIN)));
  list($a[]) = explode(" ", trim(fgets(STDIN)));
  list($a[]) = explode(" ", trim(fgets(STDIN)));

  $min = min($a);

  if($n <= $min){
    echo 5;
  }else{
    echo intdiv($n+$min-1, $min) + 4;
  }

Measured memory_bytes: 16320
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int z = 0;
        int o = 0;
        for (int i = 0; i < s.length(); i++) {
            if ((i + 1) % 2 == 0) {
                if (s.charAt(i) != '0') {
                    z++;
                } else {
                    o++;
                }
            } else {
                if (s.charAt(i) != '1') {
                    z++;
                } else {
                    o++;
                }
            }
        }
        System.out.println(Math.min(z, o));
    }
}


Measured memory_bytes: 24548
//abc149_b.cpp
//Sun Jan 12 11:18:25 2020

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;

int main(){
	ll a,b,k;
	cin >> a >> b >> k;

	if (a>=k){
		cout << a-k << " " << b << endl;
	}else if (a+b>=k){
		cout << 0 << " " << b-(k-a) << endl;
	}else {
		cout << 0 << " " << 0 << endl;
	}

//	printf("%.4f\n",ans);
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<queue>
#include<vector>
#include<string.h>
#include<algorithm>
#include<map>

using namespace std;

int N;
int X;
int i,n;

int main()
{
  
  cin >> N;
  
  X=N*100/108;
  for(i=-1;i<3;i++)
  {
    n=(X+i)*108/100;
    
    if(n==N)
    {
      cout << X+i;
      return 0;
    }
  }
  
  cout << ":(";
  
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
int main()
{
    char s[5];
    int flag=0;
    scanf("%s",s);
    for(int i = 0;s[i]!='\0';i++)
    {
        if(s[i]=='9') flag=1;
    }
    if(flag) printf("Yes\n");
    else printf("No\n");
}


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

// Shrotening
#define fst first
#define snd second
#define pb push_back

// Loop
#define FOR(i,a,b) for(long i=(a);i<(b);++i)
#define RFOR(i,a,b) for(long i=(a);i>=(b);--i)

#define REP(i,a) for(long i=0;i<(a);++i)
#define RREP(i,a) for(long i=(a);i>=0;--i)

#define EACH(i,a) for(auto (i)=(a).begin(),_END=(a).end();i!=_END;++i)
#define REACH(i,a) for(auto (i)=(a).rbegin(),_END=(a).rend();i!=_END;++i)

//Algorithm
#define ALL(a) (a).begin(), a.end()
#define RALL(a) (a).rbegin(), a.rend()
#define EXIST(a,x) ((a).find(x)!=(a).end())
#define SORT(a) std::sort((a).begin(), (a).end())
#define UNIQUE(a) std::sort((a).begin(), a.end()), a.erase(std::unique((a).begin(), a.end()), a.end());
#define SUM(a) std::accumulate((a).begin(), (a).end(), 0);

//Setting
#define OPT std::cin.tie(0);std::ios::sync_with_stdio(false);

//debug message
bool debug = true;
#define MSG(s)   if(debug){std::cout << s << std::endl;}
#define DEBUG(x) if(debug){std::cout << "debug(" << #x << "): " << x << std::endl;}

//alias
typedef long long LL;
typedef std::vector<char> VC;
typedef std::vector<int>  VI;
typedef std::vector<long> VL;
typedef std::vector<long long> VLL;

typedef std::vector< VC > VC2;
typedef std::vector< VI > VI2;
typedef std::vector< VL > VL2;
typedef std::vector< VLL > VLL2;

typedef std::pair<int,int> PII;

int N, M;
const int MOD = 1000000007;

int frac(int N) {
    int res = 1;
    for(int i=2; i<=N; ++i) {
        res = ((LL)(res % MOD) * (i % MOD)) % MOD;
    }
    return res;
}

int main() {
    std::cin >> N >> M;
    if(std::abs(N-M) >= 2) {
        std::cout << 0 << std::endl;
        return 0;
    }

    int np = frac(N);
    int mp = frac(M);
    if(N == M) {
        std::cout << ((((LL)(np % MOD) * (mp % MOD)) % MOD) * 2) % MOD << std::endl;
    } else {
        std::cout << (((LL)np % MOD) * (mp % MOD)) % MOD << std::endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<set>
#include<math.h>
#include<vector>
#include<sstream>
#include<queue>
#include<functional>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include <string.h>
using ll = long long;
 
#define rep(i, n) for(ll i = 0; i < (int)(n); i++)
#define reps(i,x) for(ll i=1;i<=(int)(x);i++)
#define rrep(i,x) for(ll i=((int)(x)-1);i>=0;i--)
#define rreps(i,x) for(ll i=(int)(x);i>0;i--)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define vll vector<ll>
#define vi vector<int>
#define mp make_pair
#define vpll vector<pair<ll,ll>>
#define vpi vector<pair<int,int>>
#define mod 1000000007 
using namespace std;
int x[501][501];
int main() {
  int n, m, Q, l, r, p, q;
  scanf("%d%d%d", &n, &m, &Q);
  rep(i, m){
    scanf("%d%d", &l, &r);
    x[l][r]++;
  }
  reps(i, n){
    reps(j, n){
      x[i][j] += x[i][j-1];
    }
  }
  rep(i, Q){
    int ans = 0;
    scanf("%d%d", &p, &q);
    for(int j = p; j <= q; j++) ans += x[j][q] - x[j][p - 1];
    printf("%d\n", ans);
  }
  return 0; 
}


Measured memory_bytes: 1920
n=int(input())
l=list(map(int,input().split()))
l.sort()
s=0
for i in range(n-2):
    for j in range(i+1,n-1):
        s+=sum([1 for k in l[j+1:] if l[j]<k and k<l[i]+l[j]]) if l[i]<l[j] else 0
print(s)

Measured memory_bytes: 68324
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <string.h>
#include <string>
#include <queue>
#include <stack>
using namespace std;
typedef long long int ll;
int n;
string s;
string t;

int main(void)
{
	cin>>n>>s>>t;	
	int i, j;
	for(i=n ; i>=1 ; i--)
	{
		string ss="";
		string tt="";
		for(j=n-i ; j<=n-1 ; j++)
		{
			ss+=s[j];
		}
		for(j=0 ; j<=i-1 ; j++)
		{
			tt+=t[j];
		}
		if(ss==tt)
		{
			cout<<2*n-i;
			return 0;
		}
	}
	cout<<2*n;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<stack>
#include<algorithm>
#include<cmath>
#include<map>
#include <iomanip>
#include<utility>//swapでaとbの値を入れ替える
#define rep(i,a,n) for(ll i=(a);i<(n);i++)
#define ll long long
#define sort(s) sort(s.begin(),s.end())
#define Yes(a) if(a)cout<<"Yes"<<endl; else cout<<"No"<<endl;
using namespace std;

int main() {
	int n;
	cin >> n;
	vector<int> a(n),s(n+1);
	for (int i = 0; i < n; i++)cin >> a[i];
	for (int j = 0; j < n; j++) {
		s[a[j]] = j+1;
	}
	sort(a);
	for (int i = 0; i < n; i++) {
		cout << s[a[i]];
		if (i == n - 1)cout << endl;
		else cout << " ";
	}

	return 0;
}

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

ll n;

int main() {
	cin>>n;
	ll u[n], v[n];
	vector <ll> point[n+1];
	for (int i=1; i<n; i++) {
		cin>>u[i]>>v[i];
		if (u[i]>v[i]) point[u[i]].push_back(v[i]);
		else point[v[i]].push_back(u[i]);
	}
	for (int i=1; i<=n; i++) {
		sort(point[i].begin(), point[i].end());
	}
	ll ans=0;
	for (int i=1; i<=n; i++) {
		ll tambah=i*(n-i+1);
		ans+=tambah;
	}
	for (int i=1; i<=n; i++) {
		ll byk=point[i].size(), kiri, kanan=n-i+1;
		for (int j=0; j<byk; j++) {
			if (j>0) kiri=point[i][j]-point[i][j-1];
			else kiri=point[i][j];
			ans-=(kiri*kanan*(byk-j));
		}
	}
	cout<<ans<<endl;
}



Measured memory_bytes: 17648
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[4];
int main()
{
    ios::sync_with_stdio(false);
    ll n;cin>>n;
    for(ll i=0;i<n;i++)
    {
        string s;cin>>s;
        if(s=="AC") a[0]++;
        else if(s=="WA") a[1]++;
        else if(s=="TLE") a[2]++;
        else a[3]++;
    }
    cout<<"AC x "<<a[0]<<endl;
    cout<<"WA x "<<a[1]<<endl;
    cout<<"TLE x "<<a[2]<<endl;
    cout<<"RE x "<<a[3];
    return 0;
}


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

int main(){
    ll N;
    vector<ll> A(100004), B(100004), C(100004); // Aは深さdの葉、Bは葉じゃない頂点、Cは下にある葉の数の合計
    cin >> N;
    rep(i, N+1) cin >> A[i];
    for(int i = N; i > 0; i--) C[i] = C[i+1] + A[i+1];
    if(N == 0){
        if(A[0] == 1) {
          cout << 1 << endl;
          return 0;
        }
    }
    if(A[0] != 0){
        cout << -1 <<endl;
        return 0;
    }
    B[0] = 1;
    for(int i = 1; i < N+1; i++){
        B[i] = 2 * B[i-1] - A[i];
        if(B[i] > C[i]) B[i] = C[i];
        if(B[i] < 0) {
           cout << -1 << endl;
           return 0;
        }
    }
    ll answer = 0;
    rep(i,N+1) answer += (A[i]+B[i]);
    cout << answer << endl;
}


Measured memory_bytes: 5464
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <vector>

static const int IINF = 1 << 30;
static const long long LINF = 1LL << 60;
static const long long MOD = 1.0e+9 + 7;

template <typename T> std::vector<T> vectors(std::size_t n, T val) {
  return std::vector<T>(n, val);
}

template <typename T, typename... Args>
auto vectors(std::size_t n, Args... args) {
  return std::vector<decltype(vectors<T>(args...))>(n, vectors<T>(args...));
}

template <class T> inline bool chmin(T &a, const T &b) {
  return (a > b) ? a = b, true : false;
}

template <class T> inline bool chmax(T &a, const T &b) {
  return (a < b) ? a = b, true : false;
}

template <class T> inline void chadd(T &a, const T &b) {
  a += b, a %= MOD;
  // TODO minus case
}

template <class T>
std::ostream &operator<<(std::ostream &s, const std::vector<T> &v) {
  if (v.empty())
    return s;
  s << *v.begin();
  for (auto iter = v.begin() + 1; iter != v.end(); ++iter)
    if (std::is_fundamental<T>::value)
      s << " " << *iter;
    else
      s << std::endl << *iter;
  return s;
}

int main() {
  // Input
  int N, M;
  std::cin >> N >> M;
  std::vector<int> a(M);
  for (int i = 0; i < M; ++i)
    std::cin >> a[i];

  // Main
  std::vector<long long> f(1000000, 0);
  f[0] = 0;
  f[1] = 1;
  f[2] = 1;
  for (int i = 3; i <= N + 1; ++i) {
    f[i] = f[i - 1] + f[i - 2];
    f[i] %= MOD;
  }

  long long res = 1;
  for (int i = 0; i < M; ++i) {
    if (i == 0) {
      int d = a[0];
      assert(d >= 0);
      res *= f[d];
      res %= MOD;
      continue;
    }
    if (a[i] == a[i - 1])
      continue;
    int d = a[i] - a[i - 1] - 1;
    assert(d >= 0);
    res *= f[d];
    res %= MOD;
  }
  int d;
  if (M >= 1)
    d = N - a[M - 1];
  else
    d = N + 1;
  assert(d >= 0);
  res *= f[d];
  res %= MOD;

  // Output
  std::cout << res << std::endl;

  return 0;
}


Measured memory_bytes: 8448
#include<iostream>
#include<vector>
#include<string>
#include<array>
#include<algorithm>
#include<list>
#include<cmath>
#include<iomanip>
#include<queue>
#include<functional>
#include<climits>
#include<iterator>
using namespace std;

const double pi=4*atan(1.0);

int main() {
	int N,L;
	cin>>N>>L;
	vector<int> Lengths(N);
	for(auto& val:Lengths){
		cin>>val;
	}

	vector<int> AnsArr(N-1);

	int index=-1;
	for(int i=0;i<Lengths.size()-1;++i){
		if(Lengths[i]+Lengths[i+1]>=L){
			index=i;
			break;
		}
	}

	if(index<0){
		cout<<"Impossible"<<endl;
	}
	else{
		int fill_index=0;

		for(;fill_index<AnsArr.size();++fill_index){

			AnsArr[fill_index]=index;
			++index;
			if(index>=N)break;

		}

		index=AnsArr[0];
		--index;
		for(;fill_index<AnsArr.size();++fill_index){

			AnsArr[fill_index]=index;
			--index;

		}

		cout<<"Possible"<<endl;

		for(int i=AnsArr.size()-1;i>=0;--i){
			cout<<AnsArr[i]+1<<"\n";
		}
		
	}

	//system("pause");
	return 0;
}

Measured memory_bytes: 1536
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main (){
  int n;
  cin >> n;
  vector<string> v;
  for (int i = 0; i < n; i++){
    string s;
    cin >> s;
    v.push_back(s);
  }
  sort(v.begin(), v.end());
  vector<string>::iterator vUnique;
  vUnique = unique(v.begin(), v.begin() + n); 
  v.resize(distance(v.begin(), vUnique));
  cout << v.size() << "\n";

}

Measured memory_bytes: 11664
#n = 人数,a = 日本,b = 海外
n,a,b = map(int,input().split())
#s = 順位
s = list(input())
#k = 結果格納
k = []
j = a + b
c = 0
d = 0

for i in range(n):
    if s[i] == 'a':
        if c < j:
            c += 1
            k.append('Yes')
        else:
            k.append('No')
    elif s[i] == 'b':
        if c < j:
            if d < b:
                c += 1
                d += 1
                k.append('Yes')
            else:
                k.append('No')
        else:
            k.append('No')
    else:
        k.append('No')

for i in range(n):
    print(k[i])

Measured memory_bytes: 10472
import java.util.*;
	import java.util.Map.Entry;
	 
	 
	 class Main {
		 static int mod =  (int) (Math.pow(10,9)+7);
//		 static int mod =  (int) 998244353;
		 public static void main(String[] args) {
	    	
	        Scanner sc = new Scanner(System.in);

	        
	        int N = sc.nextInt()+1;	
	        int[] a = new int[N];
	        long sum=0;
	        for (int i=0 ; i<N; i++) {
	            a[i] = Integer.parseInt(sc.next());
	            sum=sum+a[i];
	        }
	        long ans=0;
	        long ro=1;
	        for(int i=0;i<N;i++) {
	        	ans=ans+Math.min(ro, sum);
	        	sum=sum-a[i];
	        	ro=ro-a[i];
	        	if(ro<0) {
	        		ans=-1;
	        		break;
	        	}
	        	ro=Math.min(ro*2, Long.MAX_VALUE/2-100);
	        }
	        
	        
	        
	        System.out.println(ans);
	    }
	}

Measured memory_bytes: 58736
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <ctime>
#include <cassert>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define fs first
#define sc second
#define INF 1000000000
#define MOD 1000000007
#define EPS 0.00000001




int main() {
    string S, T; cin >> S >> T;
    int ret = 0;
    for(int i=0; i<3; i++){
        if(S[i]==T[i]) ret++;
    }
    cout << ret << endl;
    return 0;
}



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

int main() {
  string S, T;
  cin >> S >> T;
  vector<int> c1(26, 0), c2(26, 0);
  for (int i = 0; i < S.length(); ++i) c1[S[i] - 'a']++;
  for (int i = 0; i < T.length(); ++i) c2[T[i] - 'a']++;
  sort(c1.begin(), c1.end());
  sort(c2.begin(), c2.end());
  if (c1 == c2)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 776
n = int(input())
s = list(map(int,input().split()))

ans = 0

for c in range(1,n-1):
  if (n-1)%c == 0:
    p = ((n-1)//c-1)//2 
  else:
    p = (n-1)//c-1
    if p <= 0:
      break
  if p <= 0:
    continue
  m = 0
  k = 0
  for i in range(1,p+1):
    k += s[c*i] + s[n-1-c*i]
    m = max(m,k)
  ans = max(ans,m)
    
    
print(ans)

Measured memory_bytes: 14468
#include <iostream>
#include <vector>
#include <bitset>
#include <utility>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
 
using namespace std;
typedef long long ll;
 
int main(){
  int H1,H2,M1,M2,K;
  cin >> H1 >> M1 >> H2 >> M2 >> K;

  cout << 60*H2+M2-60*H1-M1-K << endl;

  return 0;
}


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

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

int main(){
	string S, T;
	cin >> S >> T;
	T.pop_back();
	if(S==T) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

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

#ifdef DEBUG
    #define IFD if(true)
#else
    #define IFD if(false)
#endif

int main()
{
    long long dp[100001];
    priority_queue<int, vector<int>, greater<int> > a;
    int N, M;

    memset(dp, 0, sizeof(dp));

    cin >> N >> M;
    for(int i = 0; i < M; i++) {
        int n;
        cin >> n;
        a.push(n);
    }

    dp[0] = 1;

    for(int i = 1; i <= N; i++) {
        if(!a.empty() && i == a.top()) {
            a.pop();
            continue;
        }
        if(i == 1) {
            dp[1] = dp[0];
        } else {
            dp[i] = (dp[i - 1] + dp[i - 2]) % 1000000007;
        }
    }

    cout << dp[N] << endl;

    return 0;
}


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

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

    int Hasu = N % 500;
    if (A >= Hasu) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    return 0;
    // ここにプログラムを追記
}

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

using namespace std;

int k, k1, n;

int main()
{
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> k;
        if (k % 2 == 1)
            k1++;
    }
    if (k1 % 2 == 1)
        cout << "NO";
    else
        cout << "YES";
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int H,W;
  cin >> H >> W;
  string A;
  
  for (int i = 0; i < (H + 2); i++){
    
    A = "";
    
    //1行目は#で埋める
    if (i == 0){
      for(int j = 0; j < (W + 2); j++){
        A = A + '#';
      }
    }
    //最終行は#で埋める
    else if (i == (H + 1)){
      for(int j = 0; j < (W + 2); j++){
        A = A + '#';
      }
    }
    //間の行は先頭と最後尾を#で埋める
    else{
      cin >> A;
      A = '#' + A + '#';
    }

    //出力
    cout << A << endl;
    
  }
}

Measured memory_bytes: 3604
using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
    static void Main(string[] args)
    {
            // 入力
            string sS = Console.ReadLine().Trim();

            // 解析
            string sOut = "AC";
            string sTmp = sS.Substring(2, sS.Length - 3);
            string sTm2 = sTmp.Replace("C", "");
            if (sS.Substring(0, 1) == "A")
            {
                if (sTmp.Length - 1 == sTm2.Length)
                {
                    sTm2 = sS.Substring(1, 1) + sTm2 + sS.Substring(sS.Length - 1, 1);
                    for (int i = 0; i < sTm2.Length; i++)
                    { if (char.IsUpper(sTm2, i)) { sOut = "WA"; break; } }
                }
                else
                { sOut = "WA"; }
            }
            else
            { sOut = "WA"; }

            //出力
            Console.WriteLine("{0}", sOut.ToString());

#if DEBUG
        Console.WriteLine("続行するには何かキーを押してください．．．");
        Console.ReadKey();
#endif

    }

}


Measured memory_bytes: 13140
#include <stdio.h>
int main()
{
    int n, arr[50], i, count=0, a[2], j=0;
    scanf("%d", &n);
    for(i=1; i<=n; i++)
    {
        scanf("%d", &arr[i]);
        if(i!=arr[i])
        {
            count++;
            a[j]=i;
            j++;

        }
    }
    if(count==2)
        printf("YES\n", a[0], a[1]);
    else if(count==0)
        printf("YES\n");
    else
        printf("NO\n");
}


Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		while (true) {
			int n = scan.nextInt();
			if (n == 0) {
				break;
			}
			int[] a = new int[n];
			for (int i = 0; i < n; i++) {
				a[i] = scan.nextInt();
			}
			int dis = Math.abs(a[0] - a[1]);
			for (int i = 0; i < n; i++) {
				for (int j = i + 1; j < n; j++) {
					if (dis > Math.abs(a[i] - a[j])) {
						dis=Math.abs(a[i] - a[j]);
					}
				}
			}
			System.out.println(dis);
		}
	}
}



Measured memory_bytes: 49484
#include <bits/stdc++.h>
using namespace std;
 
int N, M;
int WA[105000];
bool AC[105000];
 
void solve() {
    cin >> N >> M;
    int WAnum = 0;
    int ACnum = 0;
    for(int i = 1; i <= N; i++) {
        WA[i] = 0;
        AC[i] = false;
    }
    while(M--) {
        int p;
        string S;
        cin >> p >> S;
        if(AC[p]) continue;
        if(S == "AC") {
            AC[p] = true;
            ACnum++;
            WAnum += WA[p];
        } else if(S == "WA") {
            WA[p]++;
        }
    }
    cout << ACnum << " " << WAnum << endl;
    return;
}

 
int main() {
    solve();
    return 0;
}

Measured memory_bytes: 768
import math
N, K = [int(s) for s in input().split(' ')]
ret = [1] * N
for n in range(1, N + 1):
    p = n
    rate = 1
    if p > K - 1:
        ret[n - 1] = rate
        continue
    for i in range(100000):
        p *= 2
        rate /= 2
        if p > K - 1:
            ret[n - 1] = rate
            break

print(sum(ret) / len(ret))


Measured memory_bytes: 3828
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

int main() {
    int n, w;
    cin >> n >> w;
    vector<int> ws(n), vs(n);
    for (int i = 0; i < n; ++i) {
        cin >> ws[i] >> vs[i];
    }
    vector<long long> dp(w + 1, -1);
    dp[0] = 0;
    for (int i = 0; i < n; ++i) {
        for (int wi = w - 1; wi >= 0; --wi) {
            if (dp[wi] == -1) continue;
            if (wi + ws[i] > w) continue;
            dp[wi + ws[i]] = max(dp[wi + ws[i]], dp[wi] + vs[i]);
        }
    }
    long long ans = 0;
    for (int i = 0; i <= w; ++i) {
        ans = max(ans, dp[i]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024