akhauriyash/Code-Regression huggingface dataset:
# 貪欲法で得た解に対して、局所探索法(改良ver)

import sys

def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり

D = I()
c = [0] + LI()
s = [0] + [[0] + LI() for _ in range(D)]

last = [[0]*27 for _ in range(D+1)]
t = [0]

for i in range(1,D+1):
    r = 0
    manzoku = 0
    for j in range(1,27):
        m = s[i][j]
        for k in range(1,27):
            if k != j:
                m -= c[k]*(i-last[i-1][k])
            else:
                continue
        if j == 1:
            r = 1
            manzoku = m
        else:
            if manzoku < m:
                manzoku = m
                r = j
    t.append(r)
    for j in range(1,27):
        if j == r:
            last[i][j] = i
        else:
            last[i][j] = last[i-1][j]


dq = []
for i in range(1,D+1):
    for j in range(1,27):
        dq.append([i,j])

from copy import deepcopy

for i in range(60):
    for d, q in dq:
        t0 = t[d]
        manzoku = s[d][q] - s[d][t0]
        for j in range(d, D + 1):
            if j == d:
                last[d][t0] = last[d - 1][t0]
                manzoku -= c[t0] * (d - last[d][t0])
                last[d][q] = d
                manzoku += c[q] * (d - last[d - 1][q])
            else:
                if last[j][t0] == d:
                    last[j][t0] = last[d - 1][t0]
                    manzoku -= c[t0] * (d - last[d][t0])
                if last[j][q] == last[d - 1][q]:
                    last[j][q] = d
                    manzoku += c[q] * (d - last[d - 1][q])
        if manzoku > 0:
            t[d] = q
        else:
            for j in range(d, D + 1):
                if j == d:
                    last[d][t0] = d
                    last[d][q] = last[d - 1][q]
                else:
                    if last[j][t0] == last[d - 1][t0]:
                        last[j][t0] = d
                    if last[j][q] == d:
                        last[j][q] = last[d - 1][q]

del t[0]

print(*t,sep='\n')

Measured memory_bytes: 77296
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define mod 1000000007
#define f(i,a,b) for(ll i=a;i<b;i++)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ii pair<ll,ll>
#define vii vector<ii>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define MAX 1e9
 
ll modpow(ll base, ll exp, ll modulus) {base %= modulus;ll result = 1;while (exp > 0) {if (exp & 1) result = (result * base) % modulus;base = (base * base) % modulus;exp >>= 1;}return result;}
const ld pi=acos(-1);


int main(){
    IOS;
    ll a[5];
    f(i,0,5)cin>>a[i];
    f(i,0,5){if(a[i]==0){cout<<i+1;break;}}
    return 0;  
} 





Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
 
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
    return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}

int main() {
    constexpr ll mod = 1e9 + 7;
    ll n; cin >> n;
    vector<ll> a(n), b(63, 0);

    REP(i, n) {
        cin >> a[i];
        REP(j, 63) {
            b[j] += (a[i] >> j) & 1;
        }
    }

    ll ans = 0;
    REP(i, 63) {
        ans += (1LL << i) % mod * (b[i] * (n - b[i]) % mod) % mod;
        ans %= mod;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 2560
N,M,K=gets.split.map(&:to_i)
MOD=1000000007

def xsum
  sum=0
  (N-1).times do |i|
    i+=1
    sum+=(i*(N-i)*M*M) % MOD
  end
  return sum
end

def ysum
  sum=0
  (M-1).times do |i|
    i+=1
    sum+=(i*(M-i)*N*N) % MOD
  end
  return sum
end

def comb(n, k)
  def mpow(x, n)
    ret = 1
    while n > 0
      if n.even?
        x = x * x % MOD
        n >>= 1
      else
        ret = ret * x % MOD
        n -= 1
      end
    end
    return ret
  end
  k = k < n-k ? k : n-k
  return (n-k+1..n).inject(1){|p, q| p*q % MOD} * mpow((1 .. k).inject(1){|p, q| p*q % MOD}, MOD - 2)
end
puts ((xsum+ysum)*comb(N*M-2,K-2)) % MOD


Measured memory_bytes: 1916
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>

#define MP make_pair
#define PB push_back
#define in int
#define ll long long
#define ull unsigned long long
#define vc vector
#define SQ(j) (j)*(j)
#define x first
#define y second
//
//#define ld long double
#define dbl  long double
#define pll pair<long long,long long>
#define pii pair<int,int>
#define pdd pair<dbl,dbl>
#define sz(xxx) ((int)(xxx.size()))
#define all(j) j.begin(), j.end()
#define loop(xxx, yyy) for(int xxx = 0; xxx < yyy; xxx++)
//#define printf(fmt, ...) (0)
//#define HOME
//#define y0 ngacaleiebinvoaeu
//#define y1 gnarpipipaigare
#define j1 adsfndnasfafoasp

//#define printf(...) (0)
#define db(x) if(DEBUG) {cout << #x << " = " << x << endl;}
#define dbCont(x) if(DEBUG) {cout << #x << ": "; for(auto shun: x) cout << shun << ' '; cout<<endl;}

using namespace std;

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

// 4:13

int DEBUG = 0;

using namespace std;

const int N = 100 * 1000 + 5;
const ll MOD = 1000 * 1000 * 1000 + 7;

int main() {

    ll h, a;
    cin >> h >> a;

    if(h%a == 0) cout << h/a;
    else cout << h/a + 1;
    return 0;
}


Measured memory_bytes: 256
c = [list(map(int,input().split())) for k in range(3)]
if c[0][0] + c[1][1] != c[0][1] + c[1][0] or c[0][2] + c[2][0] != c[0][0] + c[2][2] or c[1][2] + c[2][1] != c[1][1] + c[2][2]:
    print("No")
else:
    print("Yes")


Measured memory_bytes: 38484
#include <iostream>
#include <map>
#include <vector>
#define int long long
typedef long long ll;
using namespace std;

signed main(){
    ll a, b, n;

    cin >> a >> b >> n;
    
    ll w;
    if(b-1>n) w = n;
    else w = b-1;
    ll ansa = a*w/b;
    ll ansb = w/b;
    ansb = a*ansb;
    cout << ansa - ansb << endl;
    return 0;
}

Measured memory_bytes: 3572
def main():
	n, m = map(int, input().split())
	l = list(map(int, input().split()))
	if m <= n:
		print(0)
		return
	l.sort()
	dif = [l[i+1]-l[i] for i in range(m-1)]
	dif.sort()
	result = 0
	for i in range(m-n):
		result += dif[i]
	print(result)

if __name__ == '__main__':
    main()

Measured memory_bytes: 13960
import math
N=int(input())
ans=0
a,b=0,0
tmp=0
for i in range(N):
    s=input()
    if s[0]=="B": b+=1
    if s[-1]=="A": a+=1
    if a!=b: tmp=1
    ans+=s.count("AB")


if tmp==0: ans+=max(0,min(a,b)-1)
else:ans+=min(a,b)
print(ans)

Measured memory_bytes: 3064
#include <cstdio>
#include <iostream>
#include <vector>
#include <queue>

using namespace std;


const int N = 202;

vector<int> g[N];
int col[N];

bool dfs(int v, int c, vector<int> & comp)
{
    comp.push_back(v);
    col[v] = c;
    for (int u : g[v])
    {
        if (col[u] == -1)
        {
            if (!dfs(u, c ^ 1, comp))
                return false;
        }
        else
        {
            if (col[u] == col[v])
                return false;
        }
    }
    return true;
}

bool used[N];
int d[N];

int bfs(int s, vector<int> & vert)
{
    for (int v : vert)
    {
        used[v] = false;
        d[v] = N;
    }
    d[s] = 0;
    used[s] = true;
    queue<int> Q;
    Q.push(s);
    while(!Q.empty())
    {
        int v = Q.front();
        Q.pop();
        for (int u : g[v])
        {
            if (!used[u])
            {
                d[u] = d[v] + 1;
                used[u] = true;
                Q.push(u);
            }
        }
    }

    int ans = 0;
    for (int v : vert)
        ans = max(ans, d[v] + 1);
    return ans;
}

char s[N];

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


    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; ++i)
    {
        scanf("%s", s);
        for (int j = 0; j < n; ++j)
        {
            if (s[j] == '1')
                g[i].push_back(j);
        }
    }

    for (int v = 0; v < n; ++v)
        col[v] = -1;

    int ans = 0;
    vector<int> comp;
    for (int v = 0; v < n; ++v)
    {
        if (col[v] == -1)
        {
            comp.clear();
            if (!dfs(v, 0, comp))
            {
                printf("-1");
                return 0;
            }

            int cur = 0;
            for (int u : comp)
                cur = max(cur, bfs(u, comp));

            ans += cur;
        }
    }

    printf("%d", ans);

}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> ve_vel;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<bool>> ve_veb;
typedef vector<vector<string>> ve_ves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pub push_back
#define puf push_front
#define pob pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

int main() {
    string s; cin >> s;
    int w; cin >> w;
    rep(i,s.size()) {
      if(i % w == 0) cout << s[i];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n,i;
	char c[1001];
	scanf("%s",c);
	scanf("%d",&n);
	for(i=0;i<strlen(c);i+=n)
	{
		printf("%c",c[i]);
	}
	return 0;
}

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

int main() {
  int M = 3;
  vector<vector<int>> V(M, vector<int>(M));
  for (int i = 0; i < M; i++) {
    for (int j = 0; j < M; j++) {
      cin >> V.at(i).at(j);
    }
  }
  int N;
  cin >> N;
  for (int i = 0; i < N; i++) {
    int B;
    cin >> B;
    for (int i = 0; i < M; i++) {
      for (int j = 0; j < M; j++) {
        if (V.at(i).at(j) == B) V.at(i).at(j) = -1;
      }
    }
  }
  for (int i = 0; i < M; i++) {
    int tmp1 = 1, tmp2 = 1;
    for (int j = 0; j < M; j++) {
      if (V.at(i).at(j) != -1) tmp1 = 0;
      if (V.at(j).at(i) != -1) tmp2 = 0;
    }
    if (tmp1) return cout << "Yes" << "\n", 0;
    if (tmp2) return cout << "Yes" << "\n", 0;
  }
  if (V.at(0).at(0) == -1 && V.at(1).at(1) == -1 && V.at(2).at(2) == -1) return cout << "Yes" << "\n", 0;
  if (V.at(0).at(2) == -1 && V.at(1).at(1) == -1 && V.at(2).at(0) == -1) return cout << "Yes" << "\n", 0;
  cout << "No" << "\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <string>
#include <string.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <stdlib.h>
#include <deque>  
#include <iomanip>

using namespace std;

int main(){
    int r,D,x[11],m;
    cin>>r>>D>>x[0];
    for(int i=1;i<11;i++){
        x[i]=r*x[i-1]-D;
        cout<<x[i]<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#define REP(i, n) for(i=0; i<n; i++)
#define REPR(i, n) for(i=n; i>=0; i--)
#define FOR(i, m, n) for(i=m; i<n; i++)
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define INF 10000000000
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
typedef pair<double, double> doup;

ll singleChar(string s) {
    ll i;
    for(i=0; i<s.size(); i++) {
        if(s[i]!=s[0]) {
            return 0;
        }
    }
    
    return 1;
}

int main(void) {
    string s, cpyt;
    cin >> s;
    ll i, tmp, ans=100;
    char p;
    
    if(s.size()==1 || singleChar(s)) {
        cout << 0 << endl;
        return 0;
    }
    
    for(p='a'; p<='z'; p++) {
        cpyt=s;
        tmp=0;
        while(1) {
            string t;
            for(i=0; i<cpyt.size()-1; i++) {
                if(cpyt[i]==p || cpyt[i+1]==p) {
                    t+=p;
                }else {
                    t+=cpyt[i];
                }
            }
            
            tmp++;
            
            if(singleChar(t)) {
                break;
            }
            cpyt=t;
        }
        ans=min(ans, tmp);
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 256
def X_amida_number(W, W_i):
    x_amida = "0" * (W - 1)

    if (W_i-2 >= 0):
        left_x_amida = x_amida[:(W_i-2)]
    else:
        left_x_amida = ""

    right_x_amida = x_amida[(W_i+1):]

    if(len(left_x_amida) > 0):
        left_counter = 0

        for left_bin in range(2**len(left_x_amida)):
            if (("11" in format(left_bin, "b")) == False):
                left_counter += 1
    else:
        left_counter = 1

    if(len(right_x_amida) > 0):
        right_counter = 0

        for right_bin in range(2**len(right_x_amida)):
            if (("11" in format(right_bin, "b")) == False):
                right_counter += 1

    else:
        right_counter = 1

    return (left_counter * right_counter)

def Y_amida_number(W, W_i):
    y_amida = "0" * (W - 1)

    if (W_i-1 >= 0):
        left_y_amida = y_amida[:W_i-1]
    else:
        left_y_amida = ""

    right_y_amida = y_amida[W_i+1:]

    if(len(left_y_amida) > 0):
        left_counter = 0

        for left_bin in range(2**len(left_y_amida)):
            if (("11" in format(left_bin, "b")) == False):
                left_counter += 1
    else:
        left_counter = 1

    if(len(right_y_amida) > 0):
        right_counter = 0

        for right_bin in range(2**len(right_y_amida)):
            if (("11" in format(right_bin, "b")) == False):
                right_counter += 1
    else:
        right_counter = 1

    return (left_counter * right_counter)

def Z_amida_number(W, W_i):
    z_amida = "0" * (W - 1)

    if (W_i-1 >= 0):
        left_z_amida = z_amida[:W_i-1]
    else:
        left_z_amida = ""

    right_z_amida = z_amida[W_i+2:]

    if(len(left_z_amida) > 0):
        left_counter = 0

        for left_bin in range(2**len(left_z_amida)):
            if (("11" in format(left_bin, "b")) == False):
                left_counter += 1
    else:
        left_counter = 1

    if(len(right_z_amida) > 0):
        right_counter = 0

        for right_bin in range(2**len(right_z_amida)):
            if (("11" in format(right_bin, "b")) == False):
                right_counter += 1
    else:
        right_counter = 1

    return (left_counter * right_counter)


H, W, K = map(int, input().split())

seed_dp_array = [0 for i in range(W)]
dp_array = [list(seed_dp_array) for i in range(H + 1)]
dp_array[0][0] = 1

for H_i in range(1, H + 1):
    for W_i in range(W):
        if (W_i == 0):
            if(W == 1):
                dp_array[H_i][0] = dp_array[H_i - 1][W_i] * Y_amida_number(W, W_i)
            else:
                dp_array[H_i][0] = dp_array[H_i - 1][W_i] * Y_amida_number(W, W_i) + dp_array[H_i - 1][W_i + 1] * Z_amida_number(W, W_i)
        elif (W_i == (W - 1)):
            dp_array[H_i][W - 1] = dp_array[H_i - 1][W_i - 1] * X_amida_number(W, W_i) + dp_array[H_i - 1][W_i] * Y_amida_number(W, W_i)
        else:
            dp_array[H_i][W_i] = dp_array[H_i - 1][W_i - 1] * X_amida_number(W, W_i) + dp_array[H_i - 1][W_i] * Y_amida_number(W, W_i) + dp_array[H_i - 1][W_i + 1] * Z_amida_number(W, W_i)

print(dp_array[H][K - 1] % 1000000007)

Measured memory_bytes: 3192
n = int(input())
a = list(map(int,input().split()))

def wh(cst,ttl,flg):
    for i in range(n):
        ttl += a[i]

        if ttl*flg < 0:
            flg *= -1
        else:
            if flg > 0:
                memo = abs(ttl)+1
                ttl -= memo
                cst += memo
            elif flg < 0:
                memo = abs(ttl)+1
                ttl += memo
                cst += memo
            flg *= -1

        
    return cst




ttl = 0
cst = 0



cst = wh(cst,ttl,1)
ttl = 0
cst2 = 0
cst2 = wh(cst2,ttl,-1)
   

print(min(cst,cst2))



Measured memory_bytes: 14468
#include <iostream>
#include <vector>
using namespace std;
using vi=vector<int>;

int main(){   
    int N;
    int ans=0;
    cin>>N;
    vi h(N);
    for(int i=0;i<N;i++){
        cin>>h[i];
    }
    
    vi w(N);
    
    for(int i=0;i<N;i++){
        while(w[i]!=h[i]){
            ans++;
            w[i]++;
            for(int j=i+1;j<N;j++){
                if(w[j]!=h[j]){
                    w[j]++;
                }
                else{
                    break;
                }
            }
        }
    }
    
    cout<<ans<<endl;                     

    return 0;}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i<(n);i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const ll INF = 1LL << 60;

int main() {

    ll N;
    cin >> N;
    ll A[16];
    ll X[16][16];
    ll Y[16][16];

    for(int i=1;i<=N;i++){
        cin >> A[i];
        for(int j=1;j<=A[i];j++){
            cin >> X[i][j] >> Y[i][j];
        }
    }

    int ans = 0;
    for(int honest=0;honest<(1<<N);honest++){
        int ok = 1;
        for(int i=1;i<=N;i++){
            //cout << "honest=" << honest << endl;
            if(honest&(1<<(i-1))){
                //cout << "test=" << i << endl;
                for(int j=1;j<=A[i];j++){
                    int tmp = (honest>>(X[i][j]-1))&1 ;
                    //cout << "i=" << i << " j= " << j << endl;
                    //cout << "tmp=" << tmp << " y= " << Y[i][j] << endl;
                    if(tmp == Y[i][j]){
                    }
                    else{
                        ok = 0;
                    }
                }
            }
        }
        if(ok == 1){
            ans = max(ans,__builtin_popcount(honest));
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 3604
from sys import stdin
N, A, B = [int(_) for _ in stdin.readline().rstrip().split()]
S = stdin.readline().rstrip()
limit = A + B
ab_count, b_count = 0, 0
for c in S:
    if c == 'a':
        if ab_count < limit:
            print('Yes')
            ab_count += 1
        else:
            print('No')
    elif c == 'b':
        if ab_count < limit and b_count < B:
            print('Yes')
            ab_count += 1
            b_count += 1
        else:
            print('No')
    else:
        print('No')

Measured memory_bytes: 4024
n = int(input())
a = list(map(int, input().split()))

mod = 10**9+7
nums = [0]*n
nums[0] = a[0]
for i in range(1,n): nums[i] = a[i] + nums[i-1]

ans = 0
for i in range(n-1):
  ans += a[i] * (nums[n-1]-nums[i])
  ans %= mod
print(ans)

Measured memory_bytes: 31592
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      int W = sc.nextInt();
      int H = sc.nextInt();
      int x = sc.nextInt();
      int y = sc.nextInt();
      int r = sc.nextInt();
      
      //真偽を代入して見やすく
      boolean A = r <= x;
      boolean B = x <= W - r;
      boolean C = r <= y;
      boolean D = y <= H - r;
      if(A && B && C && D){
          System.out.println("Yes");
      }else{
          System.out.println("No");
      }
    }
}


Measured memory_bytes: 26204
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

type Card struct {
	mark  string
	value int
}

func (self Card) Equal(other Card) bool {
	return self.mark == other.mark && self.value == other.value
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	n, err := nextInt(sc)
	if err != nil {
		panic(err)
	}
	cards, err := nextCards(n, sc)
	if err != nil {
		panic(err)
	}
	copied := make([]Card, len(cards))
	copy(copied, cards)
	quickSort(cards)
	sortedByMerge, _ := mergeSort(copied)
	if isEqualCards(cards, sortedByMerge) {
		fmt.Println("Stable")
	} else {
		fmt.Println("Not stable")
	}
	for _, card := range cards {
		fmt.Printf("%s %d\n", card.mark, card.value)
	}
}

func quickSort(cards []Card) {
	if len(cards) > 1 {
		q := partition(cards, 0, len(cards)-1)
		quickSort(cards[:q])
		quickSort(cards[q+1:])
	}
}

func partition(cards []Card, p int, r int) int {
	// fmt.Printf("before: %v\n", cards)
	k := p - 1
	v := cards[r].value
	for i := p; i < r; i++ {
		if cards[i].value <= v {
			k++
			cards[i], cards[k] = cards[k], cards[i]
		}
	}
	k++
	cards[r], cards[k] = cards[k], cards[r]
	// fmt.Printf("after: %v\n", cards)
	return k
}

func mergeSort(elems []Card) ([]Card, int) {
	length := len(elems)
	if length == 1 {
		return elems, 0
	}
	mid := length / 2
	left, countL := mergeSort(elems[:mid])
	right, countR := mergeSort(elems[mid:])
	sorted, countS := merge(left, right)
	return sorted, (countL + countR + countS)
}

func merge(xs, ys []Card) ([]Card, int) {
	sorted := make([]Card, 0)
	count := 0
	for len(xs) > 0 && len(ys) > 0 {
		if xs[0].value <= ys[0].value {
			sorted = append(sorted, xs[0])
			xs = xs[1:]
		} else {
			sorted = append(sorted, ys[0])
			ys = ys[1:]
		}
		count++
	}
	if len(xs) > 0 {
		sorted = append(sorted, xs...)
		count += len(xs)
	} else if len(ys) > 0 {
		sorted = append(sorted, ys...)
		count += len(ys)
	}
	return sorted, count
}

func nextInt(sc *bufio.Scanner) (int, error) {
	sc.Scan()
	return strconv.Atoi(sc.Text())
}

func nextText(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

func nextCard(sc *bufio.Scanner) (Card, error) {
	mark := nextText(sc)
	value, err := nextInt(sc)
	if err != nil {
		panic(err)
	}
	return Card{mark, value}, nil
}

func nextCards(n int, sc *bufio.Scanner) ([]Card, error) {
	ns := make([]Card, n)
	for i, _ := range ns {
		x, err := nextCard(sc)
		if err != nil {
			return nil, err
		}
		ns[i] = x
	}
	return ns, nil
}

func isEqualCards(x []Card, y []Card) bool {
	if len(x) != len(y) {
		return false
	}
	for i := 0; i < len(x); i++ {
		if !x[i].Equal(y[i]) {
			return false
		}
	}
	return true
}


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


class Solver {
public:
    void solve();
};


bool pairCompair(const std::pair<long long, long long>& l, const std::pair<long long, long long>& r) {
    return l.first < r.first;
}


void Solver::solve() {
    using namespace std;
    long long n, m;
    cin >> n >> m;
    vector<pair<long long, long long>> store = vector<pair<long long, long long>>();
    for (size_t i = 0; i < n; ++i) {
        long long a, b;
        cin >> a >> b;
        pair<long long, long long> p = pair<long long, long long>(a, b);
        store.push_back(p);
    }
    sort(store.begin(), store.end(), pairCompair);

    long long count = 0;
    long long accum = 0;
    for (size_t i = 0; i < n; ++i) {
        if (count + store[i].second > m) {
            for (size_t j = 0; j < store[i].second; ++j) {
                if (count == m) {
                    break;
                }
                count++;
                accum += store[i].first;
            }
        }
        else {
            count += store[i].second;
            accum += store[i].first * store[i].second;
        }
    }

    cout << accum << endl;
}



int main() {
    Solver solver = Solver();
    solver.solve();
    return 0;
}

Measured memory_bytes: 2420
#include<stdio.h>
int main(void){
  char *s="python3 -c\""
"n=10**5;p=[0,0]+[1]*~-n\n"
"for i in range(2,int(n**0.5)+1):\n"
" if p[i]:\n"
"  for j in range(i*2,n+1,i):p[j]=0\n"
"c=[0]\n"
"for i in range(1,n+1):c.append(c[-1]+(i%2and p[i]and p[-~i//2]))\n"
"for _ in[0]*int(input()):l,r=map(int,input().split());print(c[r]-c[l-1])\n"
"\"";
  system(s);
  return 0;
}            

Measured memory_bytes: 8256
using System;

namespace arc070_a
{
    class Program
    {
        static void Main(string[] args)
        {
            int i;
            int N = int.Parse(Console.ReadLine());
            int num = 0;
            for(i = 0; N > num; i++)
            {
                num += i;
            }
            Console.WriteLine(i - 1);
        }
    }
}


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

using namespace std;

using ll = long long;

const long long MOD_NUMBER = 1000000007;
const double PI = 3.14159265358979323846;

int main() {
  ll min = 0, max = 1000, x, n, p_x;
  vector<ll> p(101);
  cin >> x >> n;
  for (int i = 0; i < 101; i++) {
    p[i] = 1;
  }
  for (int i = 0; i < n; i++) {
    cin >> p_x;
    p[p_x] = 0;
  }
  for (int i = 0; i < 202; i++) {
    if (i % 2) {
      if (x - (i / 2 + 1) > 100) continue;
      if (p[x - (i / 2 + 1)] != 0) {
        cout << (x - (i / 2 + 1)) << endl;
        return 0;
      }
    } else {
      if (x + i / 2 < 0) continue;
      if (p[x + i / 2] != 0) {
        cout << (x + i / 2) << endl;
        return 0;
      }
    }
  }
  if (x > 50) {
    cout << 101 << endl;
  } else {
    cout << -1 << endl;
  }
  return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5+1;
int n, m, a[N], b[N], f[N], c[N], x, y;
long long p, A[N];
int F(int k)
{
	if (f[k] == k)
      return k;
  	return f[k] = F(f[k]);
}
int main()
{
	cin >> n >> m;
  	for (int i = 1; i <= m; i++)
      cin >> a[i] >> b[i];
  	p = (long long) n * (n - 1) / 2;
  	for (int i = 1; i <= n; i++)
      f[i] = i, c[i] = 1;
  	for (int i = m; i >= 1; i--){
    	A[i] = p, x = F(a[i]), y = F(b[i]);
      	if (x != y)
          p -= c[x] * c[y], f[y] = x, c[x] += c[y];
    }
    for (int i = 1; i <= m; i++){
    	cout << A[i] << endl;
    }
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl "\n"
#define ll long long
#define int long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define vi vector<int>
#define vvi vector<vector<int>>
#define pi pair<int, int>
#define ALL(a) (a).begin(), (a).end()
#define BIT(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてからつかうこと
constexpr ll MOD = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec)
        is >> x;
    return is;
}

signed main() {
    cin >> R >> C >> K;
    vector<vector<int>> g(R, vector<int>(C, 0));
    REP(i, K) {
        int r, c, v;
        cin >> r >> c >> v;
        r--, c--;
        g[r][c] = v;
    }
    vector<vector<vector<int>>> dp(R + 1, vector<vector<int>>(C + 1, vector<int>(4, -1)));
    dp[0][0][0] = 0;
    REP(r, R) {
        REP(c, C) {
            if (g[r][c] > 0) {
                REP(i, 3) {
                    if (dp[r][c][i] == -1)
                        continue;
                    dp[r][c + 1][i + 1] = max(dp[r][c + 1][i + 1], dp[r][c][i] + g[r][c]);
                    dp[r + 1][c][0] = max(dp[r + 1][c][0], dp[r][c][i] + g[r][c]);
                }
            }
            REP(i, 4) {
                dp[r][c + 1][i] = max(dp[r][c + 1][i], dp[r][c][i]);
                dp[r + 1][c][0] = max(dp[r + 1][c][0], dp[r][c][i]);
            }
        }
    }
    REP(i, 3)
    ans = max(dp[R - 1][C][i], ans);
    ans = max(dp[R][C - 1][0], ans);
    dump(dp);
    cout << ans << endl;
}

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

int main(){
  ll n;
  cin >>n;
  int a;
  int color[9]={};//8colors,bucket
  int ans=0;
  int amin=0,amax;
  rep(i,n){
    cin >> a;
    if(a<3200){
      rep(j,8){
        if(400*j<=a&&400*(j+1)-1>=a){
          color[j]++;
        }
      }
    }else color[8]++;
  }
  rep(i,8){
    if(color[i]!=0)ans++;
  }
  if(ans==0)amin++;//only3199over in
  amin +=ans;
  amax=ans+color[8];
  cout << amin << " " << amax << endl;
}


Measured memory_bytes: 256
#include<algorithm>
#include <bits/stdc++.h>
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>
#include<ctype.h>
using namespace std;
#define pb push_back
#define S second
#define F first
#define f(i,n) for(ll i=0;i<n;i++)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define vi vector<int>
#define pii pair<int,int>
#define CASES  ll t;cin>>t;while(t--)
typedef long long ll;
typedef unsigned long long ull;
int main()
{
    fast;
    ll n, flag=0;
    cin>>n;
    while(n!=0)
    {
        ll a=n%10;
        n=n/10;
        if(a==7)
            flag=1;
    }
    if(flag==1)
        cout<<"Yes";
    else
        cout<<"No";
    return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <iomanip>
#include <fstream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>

#define _GLIBCXX_DEBUG
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
using namespace std;
using vi = vector<int64_t>;
using vvi = vector<vi>;

int main(int argc, const char * argv[]) {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    int64_t n,c,t,T;
    cin >> n >> T;
    vi cost;
    rep(i,n){
        cin >> c >> t;
        if(t<=T) cost.push_back(c);
    }
    sort(cost.begin(), cost.end());
    string res;
    res = cost.empty() ? "TLE" : to_string(cost.at(0));
    cout << res << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<set>

using namespace std;

int main(){
  int n;
  cin >> n;
  set<string> s;
  string w[109];
  for(int i=0;i<n;i++){
    cin >> w[i];
    s.insert(w[i]);
  }
  bool ans=true;
  char cur=w[0][w[0].length()-1];
  for(int i=1;i<n;i++){
    if(cur!=w[i][0]){
      ans=false;
      break;
    }
    cur = w[i][w[i].length()-1];
  }
  if(s.size()!=n){
    ans=false;
  }
  if(ans){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
from itertools import combinations

n = int(input())
m, a, r, c, h = 0, 0, 0, 0, 0
for _ in range(n):
    char = input()[0]
    if char == "M":
        m += 1
    if char == "A":
        a += 1
    if char == "R":
        r += 1
    if char == "C":
        c += 1
    if char == "H":
        h += 1

l = [m, a, r, c, h]
ans = 0
for i in combinations(l, 3):
    tmp = 1
    for j in i:
        tmp *= j
    ans += tmp
print(ans)

Measured memory_bytes: 3064
import java.util.*;
import java.io.*;

class Main {
  public static void main(String[] args) throws Exception{
    try (Scanner sc = new Scanner(System.in)){
      int N = sc.nextInt();
      int[] a = new int[N];
      double ave = 0.0;
      for (int i = 0; i < N; i++) {
        a[i] = sc.nextInt();
        ave += a[i];
      }
      ave /= N;
      int min_frame = 0;
      double r = Integer.MAX_VALUE;
      for (int i = 0; i < N; i++) {
        if (Math.abs((double)a[i] - ave) < r) {
          min_frame = i;
          r = Math.abs((double)a[i] - ave);
        }
      }



      System.out.println(min_frame);
    }
  }
}


Measured memory_bytes: 22868
#include<stdio.h>
#include<stdlib.h>
 
int main(int argc,char** argv)
{
	int L, R , A, B, C, D;
	scanf("%d%d%d%d",&A, &B, &C, &D);
	L = A + B;
	R = C + D;
	if(L > R){
		printf("Left\n");
	}
	else if(L < R){
		printf("Right\n");
	}
	else{
		printf("Balanced\n");
	}
	return(0);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long int ll;
int main()
{
    ll n;
    cin>>n;
    ll sq=sqrt(n);
    map<int,int> mp;
    while (n % 2 == 0)
    {
        mp[2]++;
        n = n/2;
    }
    for (int i = 3; i <= sqrt(n); i = i + 2)
    {
        while (n % i == 0)
        {
            mp[i]++;
            n = n/i;
        }
    }
    if (n > 2)
        mp[n]++;
    map<int,int>::iterator it;
    vector<int> freq;
    for(it=mp.begin();it!=mp.end();it++)
        freq.push_back(it->second);
    int k=freq.size();
    int ans=0;
    for(int i=0;i<k;i++)
    {
        int val= -1 + sqrt(1+8*freq[i]);
        val=val/2;
        ans+=val;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3724
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <cassert>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int INF = INT_MAX/10;

struct state {
	int p, t;
	state(int p, int t) : p(p), t(t) {};
	bool operator<(const state &o)const {
		return o.t < t;
	}
};

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

	vi field(N);
	REP(i, N) {
		cin >> field[i];
	}

	vi turn(N, INF);
	turn[0] = 0;

	priority_queue<state> Q;
	Q.push(state(0, 0));

	while(!Q.empty()) {
		state st = Q.top();
		Q.pop();

		if(st.p == N-1) {
			cout << st.t << endl;
			return 0;
		}

		if(field[st.p] != 0) {
			int np = st.p + field[st.p];
			if(turn[np] > st.t) {
				turn[np] = st.t;
				Q.push(state(np, st.t));
			}
		} else {
			FOR(d, 1, 6) {
				int np = min(st.p+d, N-1);
				if(turn[np] > st.t+1) {
					turn[np] = st.t+1;
					Q.push(state(np, st.t+1));
				}
			}
		}
	}

	return 0;

}

Measured memory_bytes: 1796
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int sum=700;
	char ch1,ch2,ch3;
	cin>>ch1>>ch2>>ch3;
	if(ch1=='o') sum=sum+100; 
	if(ch2=='o') sum=sum+100; 
	if(ch3=='o') sum=sum+100; 
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 256
from itertools import accumulate
from bisect import bisect_right

N, K = map(int, input().split())
A = [-19] + [int(input()) for i in range(N)]

diff = [a - K for a in A]
diff = list(accumulate(diff))


class BinaryIndexedTree:
    def __init__(self, n):
        self.size = n
        self.bit = [0] * (n + 1)

    def sum(self, i):
        s = 0
        while i > 0:
            s += self.bit[i]
            i -= (i & -i)
        return s

    def add(self, i, x):
        while i <= self.size:
            self.bit[i] += x
            i += (i & -i)

    def reset(self):
        self.bit = [0] * (self.size + 1)


BIT = BinaryIndexedTree(N + 1)

temp = sorted(diff)
order = [bisect_right(temp, d) for d in diff]
ans = 0

for x in order:
    ans += BIT.sum(x)
    BIT.add(x, 1)

print(ans)


Measured memory_bytes: 82084
import java.util.*;

public class Main {

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

        for(int tmp = 0; tmp < n; tmp++){
            as[tmp] = sc.nextInt();
        }
        

        long result = 0;

        for(int tmp = 0; tmp < n; tmp++){
            result += as[tmp] -1;
        }


        System.out.println(result);
    }

    //最小公約数
    private static long lcm(long m, long n) {
        return m * n / gcd(m, n);
    }

    //最大公約数
    private static long gcd(long m, long n) {
        if(m < n) return gcd(n, m);
        if(n == 0) return m;
        return gcd(n, m % n);
    }
}

Measured memory_bytes: 25444
function nk(n, k)
	x = n%k
	z = convert(Int, (n-x)/k)
	return(z)
end


function main()
	n = parse.(split(readline()))
	a = n[1]
	b = n[2]
	for i in 1:n[3]
		if i% 2 == 1
			if a%2 == 1
				a -=1
			end
			a = convert(Int, a/2)
			b += a
		else
			if b%2 == 1
				b -=1
			end
			b = convert(Int, b/2)
			a += b
		end
	end
	println(a, " ", b)
end

main()

Measured memory_bytes: 130508
# -*-coding:utf-8

def main():

    while True:
        n, x = map(int, input().split())
        if ((n == 0) and (x == 0)):
            break

        count = 0
        for i in range(1, n+1):
            for j in range(1, n+1):
                for k in range(1, n+1):
                    if((i<j) and (j<k) and i+j+k == x):
                        count += 1

        print(count)

if __name__ == '__main__':
    main()

Measured memory_bytes: 7696
#include<bits/stdc++.h>
#define N 200010
#define EPS 1e-9
#define PI acos(-1)
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define fs first
#define sc second
#define db double
#define pb push_back
#define ll long long
#define VI vector<int>
#define PII pair<int,int>
#define PQ priority_queue
#define NP next_permutation
#define ull unsigned long long
#define sz(a) (int)a.size()
#define len(a) (int)strlen(a)
#define all(a) a.begin(),a.end()
#define mem(a,b) memset(a,b,sizeof(a))
#define F(i,j,k) for(register int i=j;i<=k;i++)
#define CK1(x) cout<<"["<<(x)<<"]\n";
#define CK2(x,y) cout<<"["<<(x)<<","<<(y)<<"]\n";
#define CK3(x,y,z) cout<<"["<<(x)<<","<<(y)<<","<<(z)<<"]\n";
#define IOS ios::sync_with_stdio(false)
using namespace std;
istream &operator >> (istream &in,VI &v){for(auto &i:v)in>>i;return in;}
ostream &operator << (ostream &out,VI &v){for(auto i:v)out<<i<<" ";return out;}
int n,k;
ll a[N],ans;
int main()
{
    IOS;
#if 0
    int T;cin>>T;
    while(T--)
#endif
    {
        int cnt=1;
        cin>>n;
        for(int i=1;i<=n;i++)cin>>a[i];
        sort(a+1,a+1+n);
        reverse(a+1,a+1+n);
        cnt=1;
        ans=a[1];
        for(int i=2;i<=n;i++)
        {
            if(cnt==n-1)break;
            else cnt++,ans+=a[i];
            if(cnt==n-1)break;
            else cnt++,ans+=a[i];
        }
        cout<<ans;
    }
}


Measured memory_bytes: 5224
Public Class Program
  Shared Sub Main()
    Dim n As Long = Long.Parse(Console.ReadLine())
    ' 0 = a, 1 = b, 2 = c '
    Dim dp(0 To n, 0 To 2) As Long
    dp(0, 0) = 0
    dp(0, 1) = 0
    dp(0, 2) = 0
    For i As Long = 1 To n
      Dim abc As Long() = Array.ConvertAll(Of String, Long)(Console.ReadLine().Split(" "), AddressOf Long.Parse)
      Dim a As Long = abc(0)
      Dim b As Long = abc(1)
      Dim c As Long = abc(2)
      dp(i, 0) = Math.Max(dp(i - 1, 1), dp(i - 1, 2)) + a
      dp(i, 1) = Math.Max(dp(i - 1, 2), dp(i - 1, 0)) + b
      dp(i, 2) = Math.Max(dp(i - 1, 0), dp(i - 1, 1)) + c
    Next
    Dim output As Long = Math.Max(dp(n, 0), Math.Max(dp(n, 1), dp(n, 2)))
    Console.WriteLine(output.ToString())
  End Sub
End Class

Measured memory_bytes: 17312
//簡易競プロテンプレ
#include<bits/stdc++.h>
using namespace std;
int n, m;
string s[100], t[100];
int main(void){
 cin >> n >> m;
 for(int i=0;i<n;i++) cin >> s[i];
 for(int i=0;i<m;i++) cin >> t[i];

 for(int i=0;i<=n-m;i++)for(int j=0;j<=n-m;j++){
  bool ok = true;
  for(int k=0;k<m;k++)for(int l=0;l<m;l++){
   if (s[i+k][j+l] != t[k][l]) ok = false;
  }
  if (ok) {cout << "Yes" << endl; return 0;}
 } 
 cout << "No" << endl;
 return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#define INF 100000000
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cstdio>

using namespace std;

typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P> PP;

static const double EPS = 1e-8;

const int tx[] = {0,1,0,-1};
const int ty[] = {-1,0,1,0};

struct Rect {
  int lx,ly;
  int rx,ry;
  int id;
  Rect(int rx,int ry,int lx,int ly,int id) :
    rx(rx),ry(ry),lx(lx),ly(ly),id(id) {}
  Rect() {}

  Rect(const Rect& r) {
    lx = r.lx;
    ly = r.ly;
    rx = r.rx;
    ry = r.ry;
    id = r.id;
  }

  bool operator>(const Rect& r) const {
    if(rx == r.rx){
      return ry > r.ry;
    }
    return rx > r.rx;
  }
};

bool used[10];
int order[10];
int idx;
int total_pages;
void dfs(int border_x,int lower_bound,const vector<Rect>& pages){
  for(int round = 0; round < total_pages; round++){
    priority_queue<Rect,vector<Rect>,greater<Rect> > candidates;
    
    for(int i = 0; i < total_pages; i++){
      if(used[i]) continue;
      if(lower_bound < pages[i].ly) continue;
      if(pages[i].lx > border_x) continue;
      candidates.push(pages[i]);
    }
    
    if(candidates.empty()) return;
    
    Rect last = candidates.top();
    candidates.pop();
    
    order[last.id] = idx++;
    used[last.id] = true;
    
    int next_lower_bound = last.ly;
    int next_border_x = 1000;
    for(int i = 0; i < total_pages; i++){
      if(pages[i].ly > last.ly && pages[i].ry < last.ly
         && pages[i].rx >= last.lx){
        next_border_x = min(pages[i].rx,next_border_x);
      }
    }
    dfs(next_border_x,next_lower_bound,pages);
  }
}

int main(){
  bool is_first = true;
  while(~scanf("%d",&total_pages)){
    if(total_pages == 0) break;
    vector<Rect> pages;
    for(int i = 0; i < total_pages; i++){
      int lx,ly;
      int rx,ry;
      scanf("%d %d %d %d",&rx,&ry,&lx,&ly);
      pages.push_back(Rect(rx,ry,lx,ly,i));
    }


    memset(used,false,sizeof(used));
    memset(order,0,sizeof(order));
    idx = 1;
    dfs(1000,1000,pages);

    if(!is_first) {
      printf("\n");
    }
    for(int i = 0;i<total_pages;i++){
      printf("%d\n",order[i]);
    }
    is_first = false;
  }
}

Measured memory_bytes: 1196
N,M = map(int,input().rstrip().split(" "))
ans = [False for _ in range(N + 1)]
wa = [0 for _ in range(N + 1)]
ansi = 0
penai = 0
for i in range(M):
  k = input().rstrip().split(" ")
  if ans[int(k[0])] == False:
    if k[1] == "AC":
      ans[int(k[0])] = True
      penai += wa[int(k[0])]
      ansi += 1
    else:
      wa[int(k[0])] += 1
print(str(ansi) + " " + str(penai))

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

int main(){
    long long a, b, c;
    cin >> a >> b >> c;
    if (a%2 == 0 || b%2 == 0 || c%2 == 0){
        cout << 0 << endl;
    } else {
        cout << min(min(a*b, b*c), a*c) << endl;
    }
}


Measured memory_bytes: 256
S = input()
D = 0

if len(S)%2 != 0:
    print("No")
    D = 1
    
else:
    for i in range(len(S)//2):
        if ((S[i * 2] == "h") & (S[(i * 2) + 1] == "i")) != True:
            print("No")
            D = 1
            break
        
if D == 0:
    print("Yes")


Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <climits>
#include <iomanip>

using namespace std;

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

	int  n;
	cin >> n;
	cout << pow(n, 3) << endl;

	return 0;
}

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

int main() {
    int d;
    cin >> d;
    
    cout << "Christmas";
    
    for (int i = 25; i > d; i--) {
        cout << " Eve";
    }
    
    cout << endl;
    
    return 0;
}

Measured memory_bytes: 256
X,Y,A,B,C =map(int,input().split())
P = list(map(int,input().split()))
Q = list(map(int,input().split()))
R = list(map(int,input().split()))

P.sort()
Q.sort()
R.sort()

P_new = P[-X::]
Q_new = Q[-Y::]


agg = P_new + Q_new +R
agg.sort()
print(sum(agg[-X-Y::]))

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

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

int main()
{
    ll N, K;
    cin >> N >> K;
    if (K == 1)

    {
        cout << 0 << endl;
        return 0;
    }
    ll s = N - K;
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<typename T> inline bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T &a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U &u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U &u,const V... v){for(auto &e:u)fill_v<T>(e,v...);}

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

    int h, w, k;
    cin >> h >> w >> k;
    vector<string> c(h);
    rep(i, h) cin >> c[i];
    int ans = 0;
    rep(bit1, 1<<h) rep(bit2, 1<<w) {
        int cnt = 0;
        rep(i, h) rep(j, w) {
            if ((bit1>>i&1) && (bit2>>j&1)) {
                if (c[i][j] == '#') cnt++;
            }
        }
        if (cnt == k) ans++;
    }
    cout << ans << endl;
}


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

const int MAX = 1000000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

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;
}
const long long INF = 1LL << 60;

int main() {
    ll N;
    string S, C;
    cin >> N >> S;

    ll pointer = 0;
    ll need_left = 0, need_right = 0;
    rep(i, S.size()) {
        if (S[i] == '(') {
            pointer++;
        } else {
            if (pointer == 0) {
                need_left++;
            } else {
                pointer--;
            }
        }
    }
    need_right = pointer;

    string ans = "";
    rep(i, need_left) { ans += "("; }
    ans += S;
    rep(i, need_right) { ans += ")"; }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>

#include <set>
#include <map>
#include <iomanip>

using namespace std;

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

using ll = long long;

int main()
{
	int r;
	cin >> r;
	
	cout << r * r << endl;

	return 0;
}

Measured memory_bytes: 256