akhauriyash/Code-Regression huggingface dataset:
import math
N, M = map(int, input().split())
judge = [0]*N
ac = 0
wa = 0
for i in range(M):
  p, S = input().split()
  if judge[int(p)-1] == 'AC':
    pass
  elif S == 'AC':
    wa += judge[int(p)-1]
    judge[int(p)-1] = 'AC'
    ac += 1
  else:
    judge[int(p)-1] += 1
print(ac,wa)

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

#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)

int main() {
	int N;
	cin>>N;
	int ans;
	if(N%2==0)ans=N;
	else ans=N*2;
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
 
using namespace std;
 
#define int long long
#define deb(x) cout << #x << " " << x << endl;
#define pb push_back
#define pp pop_back
#define F first
#define S second
#define all(x) x.begin(),x.end()
 
#define MOD 1000000007
#define MAX 50000
 
typedef long double ld;
const int N = 1e5 + 10;
const long double Pie = acos(-1);
 
signed main() 
{	
	int n, k;
	cin >> n >> k;
	
	vector<int> h(n);
	for (auto &it : h) 
	{
		cin >> it;
	}
	
	vector<int> dp(n, INT_MAX);
	dp[0] = 0;
	dp[1] = abs(h[1] - h[0]);
	
	for (int i = 2; i <= n; i++)
	{
		for (int j = k; j >= 1; j--)
		{
			if (i - j >= 0)
			{ 
				dp[i] = min(dp[i - j] + abs(h[i] - h[i - j]) , dp[i]);
			}
		}
	}
	
	cout << dp[n - 1];
	
	return 0;
}


Measured memory_bytes: 1792
/* Bismillahirrahmanirrahim */
/* Author : Jehian Norman Saviero (@Reiva5) */
#include <bits/stdc++.h>
 
// MACROS SAMPAH
#define Jehian using
#define Norman namespace
#define Saviero std
 
Jehian Norman Saviero;
 
// MACROS TYPE
typedef long l;
typedef long long ll;
typedef unsigned long ul;
typedef unsigned long long ull;
typedef double ld;
typedef pair<int,int> pi;
typedef pair<l,l> pl;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<l> vl;
typedef vector<ll> vll;
 
// MACROS FOR PRINT
#define nl printf("\n")
#define sp printf(" ")
 
// MACROS FOR ATTRIBUTE
#define fi first
#define se second
 
// MACROS FOR FUNCTION AND METHOD
#define eb emplace_back
#define mp make_pair
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define ALL(x) (x).begin(), (x).end()
#define ALLN(x,n) (x), (x)+(n)
#define CUBE(x) (SQR(x)*(x))
#define SET(x,y) for (int _qwe = sizeof(x)/sizeof(x[0]); _qwe; ) x[--_qwe] = (y)
#define SQR(x) ((x)*(x))
#define SSORT(x,sz) sort(ALLN(x,sz))
#define RESET(x) memset((x), 0, sizeof(x))
#define VSORT(x) sort(ALL(x))
 
// MACROS READ INPUT
#define sci(x) scanf("%d", &x)
#define scl(x) scanf("%ld", &x)
#define scll(x) scanf("%lld", &x)
#define scul(x) scl(x)
#define scull(x) scll(x)

int main() {
	string s;
	cin >> s;
	int cnt[256];
	RESET(cnt);
	for (int i = 0; i < 3; ++i) {
		++cnt[s[i]];
	}
	puts(cnt['A'] && cnt['B'] ? "Yes" : "No");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define forn(i, n) for (ll i = 0; i < (n); i++)
#define fori(i, b, e) for (ll i = (b); i < (e); i++)
#define forr(i, b, e) for (ll i = (b); i >= (e); i--)
#define allele(v) v.begin(), v.end()
#define fi first
#define se second
#define Mat vector<vector<ll>>
#define Arr vector<ll>
#define Matd vector<vector<ld>>
#define Arrd vector<ld>

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n;
    cin >> n;
    Arr a(n);
    forn(i, n) cin >> a[i];
    vector<pair<ll, ll>> d(n);
    d[0] = {0, 0};
    fori(i, 1, n)
    {
        ll ind = (2 * i) % n;
        d[i] = {ind, a[(ind + n - 1) % n] - a[(ind + n - 2) % n]};
        // cout << d[i].fi << ' ' << d[i].se << endl;
    }
    ll sum = d[0].se;
    vector<pair<ll, ll>> D = d;
    fori(i, 1, n) D[i].se += D[i - 1].se, sum += D[i].se;
    ll tot = 0;
    forn(i, n) tot += a[i];
    ll base = (tot / 2 - sum) / n;
    forn(i, n) d[i].se = base + D[i].se;
    sort(allele(d));
    forn(i, n) cout << d[i].se * 2 << ' ';
    cout << endl;
    return 0;
}

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

long long dp[110][100010];
int w[110];
int v[110];

int main() {
    int N, W; cin >> N >> W;
    for(int i = 0; i < N; ++i) cin >> w[i] >> v[i];
    
    for(int i = 0; i <= N; ++i) {
        for(int sum_w = 0; sum_w <= W; ++sum_w) {
            dp[i+1][sum_w] = max(dp[i+1][sum_w], dp[i][sum_w]);
            if(sum_w >= w[i]) dp[i+1][sum_w] = max(dp[i+1][sum_w], dp[i][sum_w - w[i]] + v[i]);
        }
    }
    
    cout << dp[N][W] << endl;
}


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

namespace Atc_0004
{
    class Program
    {
        static void Main(string[] args)
        {
            var read = Console.ReadLine();

            int maxCount = 0;
            int cnt = 0;

            for (int i = 0; i < read.Length; i++)
            {
                cnt = 0;
                int index = i;
                while (index < read.Length)
                {
                    if (read.Substring(index, 1) == "R")
                    {
                        cnt++;
                    }
                    else
                    {
                        break;
                    }
                    index++;
                }

                if (maxCount < cnt)
                {
                    maxCount = cnt;
                }
            }

            Console.WriteLine(maxCount);
        }
    }
}


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

public class Main {
    FastScanner in;
    PrintWriter out;

    void solve() {
        int n = in.nextInt();
        int[] a= new int[n];
        for (int i= 0; i< n; i++) {
            a[i] = in.nextInt();
        }
        if (a[0] != 0) {
            out.println(-1);
            return;
        }
        for (int i = 1; i < n; i++) {
            if (a[i] > a[i - 1] + 1) {
                out.println(-1);
                return;
            }
        }
        long cost = 0;
        for (int i = n - 1; i > 0; i--) {
            if (a[i] == a[i - 1] + 1) {
                cost++;
            } else {
                cost += a[i];
            }
        }
        out.println(cost);
    }

    void run() {
        try {
            in = new FastScanner(new File("Main.in"));
            out = new PrintWriter(new File("Main.out"));

            solve();

            out.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }

    void runIO() {

        in = new FastScanner(System.in);
        out = new PrintWriter(System.out);

        solve();

        out.close();
    }

    class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner(File f) {
            try {
                br = new BufferedReader(new FileReader(f));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }

        public FastScanner(InputStream f) {
            br = new BufferedReader(new InputStreamReader(f));
        }

        String next() {
            while (st == null || !st.hasMoreTokens()) {
                String s = null;
                try {
                    s = br.readLine();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (s == null)
                    return null;
                st = new StringTokenizer(s);
            }
            return st.nextToken();
        }

        boolean hasMoreTokens() {
            while (st == null || !st.hasMoreTokens()) {
                String s = null;
                try {
                    s = br.readLine();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (s == null)
                    return false;
                st = new StringTokenizer(s);
            }
            return true;
        }

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

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

        double nextDouble() {
            return Double.parseDouble(next());
        }
    }

    public static void main(String[] args) {
        new Main().runIO();
    }
}

Measured memory_bytes: 46024
from collections import defaultdict,deque, Counter
import sys,heapq,bisect,math,itertools,string,queue,copy,time
import numpy as np
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
ans = 1

[n,m] = inpl()
fibsec = [0]*(n+2)
fibsec[0] = 1
fibsec[1] = 1
fibsec[-1] = 0
for i in range(2,n+1):
    fibsec[i] = fibsec[i-1]+fibsec[i-2]

firsta = -1
for k in range(m):
    seconda = inp()
    ans = ans*(fibsec[seconda-firsta -2 ])%mod
    firsta = seconda

ans = ans*(fibsec[n-firsta-1])%mod
    

print(ans)

Measured memory_bytes: 469040
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <string>
#include <sstream>
#include <ostream>
#include <bitset>
#include <list>
#include <deque>
#include <complex>
#include <cassert>
#include <cstring>
#include <cstdio>
#include <cfloat>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <climits>

using namespace std;

#define MAX 60010
#define MAX_C 20
#define INF 1e9
#define rep(i,n) for(int i = 0 ; i < n ; i++)
#define FOR(i,a,b) for(int i = a ; i < b ; i++)
#define all(p) (p).begin(),(p).end() 

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;

int N,M;
int c[MAX_C];

int solve(){
  int dp[MAX];
  fill(dp,dp+MAX,INF);
  dp[0] = 0;
  for(int i = 0 ; i < M ; i++){
    for(int j = c[i] ; j <= N ; j++){
      dp[j] = min(dp[j],dp[j-c[i]] + 1);
    }
  }
  return dp[N];
}

int main(){
  scanf("%d%d",&N,&M);
  rep(i,M){
    scanf("%d",&c[i]);
  }
  printf("%d\n",solve());
  return 0;
}

Measured memory_bytes: 1420
/*input
*/
#define debug 0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll; typedef double db;
const int N = 2e5 + 5, M = 998244353; const db eps = 1e-8;
typedef vector<ll> vi; typedef vector<vi> vii;
void solve();
void print(){cout<<'\n';}template<class T,class ...U>void print(T x, U ...y){cout<<x<<' ';print(y...);}
int main() {
  ios::sync_with_stdio(0); cin.tie(0);
  cout << setprecision(3) << fixed;
  if(debug){freopen("main.cpp","r",stdin);string x;cin>>x;}
  solve();
}
//
ll a[N];
void solve() {
  int n;
  ll m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> a[i];
  ll d = a[0], x = 1;
  for (int i = 0; i < n; i++) {
    d = __gcd(x, a[i]);
    x = x * a[i] / d;
    if (x > 2 * m) {
      cout << 0 << endl;
      return;
    }
  }
  for (int i = 0; i < n; i++) {
    if (x / a[i] % 2 == 0) {
      cout << 0 << endl;
      return;
    }
  }
  cout << (2 * m / x + 1) / 2 << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main() {
    int A ,B, C;
    cin >> A >> B >> C;
    if (C > A && C < B) {
        cout << "Yes" << endl;
    }
    else if(A > C && B < C) {
        cout << "Yes" << endl;
    }
    else cout << "No" << 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>;

ll f(ll a, ll b) {
    ll ak = 0, bk = 0;
    while (a) {
        a /= 10;
        ak++;
    }
    while (b) {
        b /= 10;
        bk++;
    }
    ll ret = max(ak, bk);
    return ret;
}

int main()
{
    ll n;
    cin >> n;
    ll ans = 1e9;
    for (ll i = 1; i*i <= n; i++) {
        if (n % i == 0) {
            ll j = n / i;
            ll keta = f(i, j);
            ans = min(ans, keta);
        }
    }
    cout << ans << endl;
    return 0;
}

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

const int SENTINEL = 1000000005;

long long merge(vector<int> & a, int left, int mid, int right){
    auto n1 = mid - left;
    auto n2 = right - mid;
    vector<int> L(n1);
    vector<int> R(n2);
    copy(a.begin()+left, a.begin()+mid, L.begin());
    copy(a.begin()+mid, a.begin()+right, R.begin());
    L.push_back(SENTINEL);
    R.push_back(SENTINEL);
    long long counts = 0;
    int iL = 0;
    int iR = 0;
    for (int i = left; i != right; ++i){
        if (L[iL] > R[iR]){
            a[i] = R[iR];
            ++iR;
            counts += n1 - iL;
        }else{
            a[i] = L[iL];
            ++iL;
        }
    }
    return counts;
}


long long count_inversion(vector<int> & a, int left, int right){
    long long counts = 0;
    if (left + 1 < right){
        int mid = (left + right) / 2;
        counts += count_inversion(a, left, mid);
        counts += count_inversion(a, mid, right);
        counts += merge(a, left, mid, right);
    }
    return counts;
}


int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    for (auto & elem : a) cin >> elem;
    cout << count_inversion(a, 0, n) << endl;
    return 0;
}

Measured memory_bytes: 5240
# ()の問題は折れ線で捉えると良い

N = int(input())
ls = [] # 増減が正のもの(0を含む)
rs = [] # 増減が負のもの

tot = 0
for i in range(N):
    s = input()
    h = 0
    b = 0
    for c in s:
        if c == "(":
            h += 1
        else:
            h -= 1
        b = min(b, h)
    if h >= 0:
        # 折れ線に対して上っていく奴ら
        ls.append([b, h])
    else:
        # 折れ線に対して下っていく奴ら
        # 右から(hから見るので、最下点は-hする)
        rs.append([b-h, -h])
    tot += h

ls.sort(key = lambda x:x[0], reverse=True)
rs.sort(key = lambda x:x[0], reverse=True)

def check(s):
    h = 0
    for p in s:
        if h+p[0] < 0:
            return False
        h += p[1]
    return True

if check(ls) and check(rs) and tot == 0:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 200768
#include <stdio.h>
#include <string.h>
char x[2000], y[2000];
int z[2000][2000];
int m, n;
 
 
int lcs(void) {
    int i, j;
 
    m = strlen(x);
    n = strlen(y);
 
    for (i = 1; i <= m; i++) {
        z[i][0] = 0;
    }
    for (j = 0; j < n; j++) {
        z[0][j] = 0;
    }
    for (i = 1; i <= m; i++) {
        for (j = 1; j <= n; j++) {
            if (x[i - 1] == y[j - 1]) {
                z[i][j] = z[i-1][j - 1] + 1;
            }
            else if (z[i-1][j] >= z[i][j-1]) {
                z[i][j] = z[i-1][j];
            }
            else {
                z[i][j] = z[i][j-1];
            }
        }
    }
    return z[i-1][j-1];
 
}
 
int main()
{
    int a[150];
    int i, q;
 
    scanf("%d", &q);
 
    for (i = 0; i < q; i++) {
        scanf("%s", x);
        scanf("%s", y);
        lcs();
        a[i] = lcs();
    }
 
    for (i = 0; i < q; i++) {
        printf("%d\n", a[i]);
    }
 
    return 0;   
}



Measured memory_bytes: 9536
s = list(input())
t = list(input())

r1 = [-1] * 26
r2 = [-1] * 26

for i in range(len(s)):
    ss = ord(s[i]) - 97
    tt = ord(t[i]) - 97
    if r1[ss] >= 0:
        if r1[ss] != tt:
            print("No")
            exit()
    if r2[tt] >= 0:
        if r2[tt] != ss:
            print("No")
            exit()
    if r1[ss] < 0:
        r1[ss] = tt
    if r2[tt] < 0:
        r2[tt] = ss

print("Yes")

Measured memory_bytes: 6704
#include <bits/stdc++.h>
#define int long long
#define override_rep(i, l, r, mes, ...) mes
#define rep1(i, n) for (int i = 0; i < n; i++)
#define rep2(i, l, r) for (int i = l; i < r; i++)
#define rep(...) override_rep(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)

using namespace std;
using P = pair<int, int>;

template<typename T, typename U>
istream& operator>>(istream& in, pair<T, U>& p) {
    in >> p.first >> p.second;
    return in;
}

//(ノ)>◡<(ヾ)ﾓﾁﾓﾁ
signed main(signed argc, char* argv[]) {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    const int MOD = 1e9+7;
    int n,m;
    cin>>n>>m;
    vector<int> a(n,0);
    rep(i,m){
        int s,t;
        cin>>s>>t;
        a[s-1]++;
        a[t-1]++;
    }
    rep(i,n){
        if(a[i]%2){
            cout<<"NO"<<endl;
            return 0;
        }
    }
    cout<<"YES"<<endl;
}


Measured memory_bytes: 1024
from fractions import gcd
from functools import reduce

def lcm_base(x, y):
    return (x * y) // gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

N = int(input())
T = [int(input()) for _ in range(N)]

print(lcm_list(T))

Measured memory_bytes: 64364
#バブルソート
def print_output(_list):
    for index in range(len(_list)):
        if index == len(_list) - 1:
            print(_list[index])
        else:
            print(_list[index],end=' ')

target_length = int(input())
target_list = list(map(int,input().split()))

bubble_count = 0
for index in range(1, target_length):
    for compare_index in reversed(range(index)):
        if target_list[compare_index + 1] < target_list[compare_index]:
            target_list[compare_index + 1] ,target_list[compare_index] = target_list[compare_index] ,target_list[compare_index + 1]
            bubble_count += 1
        else:            
            break
print_output(target_list)
print(bubble_count)


Measured memory_bytes: 5608
//
#include <vector>
#include <set>
#include <map>
#include <array>
#include <iostream>
#include <cstdio>
#include <cstdint>
#include <algorithm>
#include <numeric>
#include <bitset>
//
using ll = long long;
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);++i)
inline void yes(bool cond) { cond ? puts("Yes") : puts("No"); }
template<typename Type> inline void chmin(Type& a, Type b) { if (a > b) a = b; }
template<typename Type> inline void chmax(Type& a, Type b) { if (a < b) a = b; }
template<typename Arr, typename Type> inline void fill(Arr& arr, Type v) { std::fill(arr.begin(), arr.end(), v); }
template<typename Type> inline void sort(Type& arr) { std::sort(arr.begin(), arr.end()); }
template<typename Type> inline Type nth(vector<Type>& arr, size_t pos) { std::nth_element(arr.begin(), arr.begin() + pos, arr.end()); return arr[pos]; }
constexpr double BIGP = 1000000007L;
constexpr double INF_I = std::numeric_limits<double>::max();
constexpr double INF_F = std::numeric_limits<float>::infinity();
constexpr double PI = 3.14159265358979323846L;
//
int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    ll N;
    cin >> N;

    // 約数を得る
    ll mind = 10000000000000;
    ll a = -1, b = -1;
    ll loop = ll(sqrt(double(N)) + 1);
    rep(i, loop)
    {
        ll j = i + 1;
        if (N % j == 0)
        {
            ll k = N / j;
            if (abs(k - j) < mind)
            {
                a = j;
                b = k;
                mind = abs(k - j);
            }
        }
    }
    //
    ll ans = (a - 1) + (b - 1);
    cout << ans;

    return 0;
}

Measured memory_bytes: 3216
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,x,y) for(int i=(int)(x);i<(int)(y);++i)
#define FORE(i,x,y) for(int i=(int)(x);i<=(int)(y);++i)
#define FORD(i,x,y) for(int i=(int)(x);i>=(int)(y);--i)
#define PB push_back
#define ST first
#define ND second
#define db(v...) cerr<<#v<<"="<<v<<"\n";
#define dbr(v,x,y) FORE(_I,x,y){cerr<<#v<<"["<<_I<<"]="<<v[_I]<<"\n";}
#define dba(v) int _I=0;for(auto _it:v)cerr<<#v<<"["<<_I++<<"]="<<_it<<"\n";
typedef long long ll;
typedef pair<int,int> pii;
const int INF=2e9;
const int MOD=1e9+7;
const int MAXN=507;

ll ans=0;
int n,m,k,q;

int tab[MAXN][MAXN];
int dir[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
int vis[MAXN][MAXN];
void Upd(int r,int c){
    if(r==0||r==n+1||c==0||c==n+1)return;
    FOR(i,0,4){
        int nr=r+dir[i][0];
        int nc=c+dir[i][1];
        if(tab[r][c]+vis[nr][nc]<tab[nr][nc]){
            tab[nr][nc]=tab[r][c]+vis[nr][nc];
            Upd(nr,nc);
        }
    }
}
int main()
{
	ios_base::sync_with_stdio(false);cin.tie(0);
    cin>>n;
    FORE(i,1,n){
        FORE(j,1,n){
            tab[i][j]=min(min(i,n-i+1),min(j,n-j+1));
            vis[i][j]=1;
        }
    }

    FOR(i,0,n*n){
        int v;
        cin>>v;
        int r=(v-1)/n+1;
        int c=(v-n*(r-1));
        --tab[r][c];
        ans+=tab[r][c];
        vis[r][c]=0;
        Upd(r,c);
    }
    cout<<ans<<"\n";
}


Measured memory_bytes: 21144
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main() {
    int N;
    cin >> N;
    int h[100005];
    int dp[100005];
    for (int i = 0; i < N; i++){
        cin >> h[i];
    }
    dp[1] = abs(h[1]-h[0]);
    for (int i = 2; i < N; i++) {
        dp[i] = min(dp[i-1] + abs(h[i]-h[i-1]), dp[i-2] + abs(h[i]-h[i-2]));
    }
    cout << dp[N-1] << endl;
}

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

int a, b, c, d, e, k;

int main(void){

    cin >> a;
    cin >> b;
    cin >> c;
    cin >> d;
    cin >> e;
    cin >> k;

    if (e - a <= k) {
        cout << "Yay!" << endl;
    } else {
        cout << ":(" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
using namespace std; using ll = long long; using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
int ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{ return firstElof.second < secondElof.second; }
//**Snippetリスト**//
//rep, vin, all//
//gcdlcm, isPrime, eratos, modinv, bitSearch, dfs, bfs, dijkstra, UnionFind, COM, digitDP//
ll i, j, k, l, m, n; ll N, M, K, H, W, L; 
ll MOD = 1000000007; ll INF = 9999999999999; ll ans = 0;
vl flag, color; vll path; vl D;
//***********//
int main() {
	
	cin >> N >> M;
	cout << N * (N - 1) / 2 + M * (M - 1) / 2;
}


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

int arr[200010],odd,ev;

int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>arr[i];
		if(arr[i]%2)
			odd++;
		else
			ev++;
	}
	if(odd%2){
		cout<<"NO"<<endl;
	}
	else{
		cout<<"YES"<<endl;
	}
	return 0;
}


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

int main() {
    int N;  cin >> N;
    map<int, int> mp;
    for (int i = 0; i < N; ++i) {
        int a;  cin >> a;
        ++mp[a];
    }
    int ans = 0;
    for (auto e : mp) {
        if (e.second > e.first) ans += e.second - e.first;
        else if (e.second < e.first) ans += e.second;
    }
    cout << ans << endl;
}


Measured memory_bytes: 8152
package main
import "fmt"
func main() {
  var n,m,s int
  var h []int
  fmt.Scan(&n)
  h = make([]int,n)
  for i:=0;i<n;i++ {
    fmt.Scan(&h[i])
  }
  m = h[0]
  s = 0
  for i:=0;i<n;i++ {
    if h[i] >= m {
      s++
      m = h[i]
    }
  }
  fmt.Println(s)
}

Measured memory_bytes: 512
<?php
  fscanf(STDIN,'%d%d%d%d',$a,$b,$c,$d);
  if(abs($a-$c)<=$d){
    echo 'Yes';
  }elseif(abs($a-$b)<=$d&&abs($c-$b)<=$d){
      echo 'Yes';
  } else{
        echo 'No';
      }
?>

Measured memory_bytes: 3576
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n;
    while(cin>>n,n) {
        bool lu=0,ru=0,up=0;
        int ans=0;
        for(int i=0;i<n;i++) {
           string f;
           cin>>f;
           if(f=="lu") {
                lu=1;
                if(ru) {
                    if(!up) {ans++;up=1;}
                }
           }else if(f=="ru") {
                ru=1;
                if(lu) {
                    if(!up) {ans++;up=1;}
                }
           }else if(f=="ld") {
                lu=0;
                if(!ru) {
                    if(up) {ans++;up=0;}
                }
           }else {
                ru=0;
                if(!lu) {
                    if(up) {ans++;up=0;}
                }
           }
        }
        printf("%d\n",ans);
    }
}

Measured memory_bytes: 3156
#include "bits/stdc++.h"
#define rep(i,n) for(ll i = 0; i < n; i++)
typedef long long ll;
using namespace std;
#define llMAX numeric_limits<long long>::max()
#define intMAX numeric_limits<int>::max()
#define d_5 100000
#define d9_7 1000000007
#define vll vector<vector<long long>>
#define vl vector<long long>
#define vi vector<int>
#define vii vector<vector<int>>
#define pb push_back
#define pf push_front
#define ld long double
#define ll long long
int main(void){
  int a,b;
  cin>>a>>b;
  swap(a,b);
  int k=50;
  vector<string> s(2*k);
  string tmp=".";
  rep(i,k){
    rep(j,2*k){
    s[i]+=tmp;

    }
  }
  tmp="#";
  rep(i,k){
    rep(j,2*k){
    s[i+k]+=tmp;

    }
  }
  rep(i,a-1){
    s[(i/(k))*2][(i%(k))*2]='#';
  }
  rep(i,b-1){
    s[2*k-(i/(k))*2-1][(i%(k))*2]='.';
  }
  // a<b とした
  cout<<2*k<<" "<<2*k<<endl;
  rep(i,2*k){
    cout<<s[i]<<endl;
  }
  return 0;
}


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

#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define deb(x)	cout << #x << " " << x << endl;

typedef long long int ll;

ll countDiv(ll n) {
	if (n == 1)
		return 0;

	ll cnt = 1;	// n is a divisor. We have to count all divisors not 1
	for (ll i = 2; i*i <= n; i++) {

		if (i*i == n)
			cnt ++;
		else if (n%i == 0)
			cnt += 2;
	}

	return cnt;
}

bool reduced(ll n, ll i) {
	while (n%i == 0)
		n /= i;

	return n % i == 1;
}

int main() {

	IOS

	ll n;
	cin >> n;

	ll m = n-1;

	ll cnt = 1;
	cnt += countDiv(m);

	for (ll i = 2; i*i <= n; i++) {
		if (n%i == 0)
			if (reduced(n, i))
				cnt++;
	}

	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 256
//
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
using namespace std;
#define MAXN 10005
#define LL long long
#define INF 0x3f3f3f3f 
int n,a,ans;
int main()
{
	scanf("%d",&n);
	bool f=0;
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a);
		if(a!=0) f=1;
		ans^=a;
	}
	if(f==0)
	{
		printf("Yes\n");
		return 0;
	}
	if(ans==0&&n%3==0) printf("Yes\n");
	else printf("No\n");
	return 0;
} 


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
using ll=long long;
#define rep(i,a,b) for(int i=(a); i<(b); ++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+b,(a).begin()+c // コンテナ a の 要素 b から c へのイテレータ
// typedef
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

int main() {
	string S;
	cin >> S;
	vector<bool> app(26);
	rep(i, 0, 26) app[i] = false;
	
	for (char c : S) {
		app[c - 'a'] = true;
	}
	rep(i, 0, 26) {
		if (!app[i]) {
			cout << (char)(i + 'a' )<< "\n";
			return 0;
		}
	}
	cout << "None" << "\n";


	return 0;
}


Measured memory_bytes: 512
def insertionSortG(a, n, g):
    for i in range(g, n):
        v = a[i]
        j = i - g
        while j >= 0 and a[j] > v:
            a[j+g] = a[j]
            j -= g
            global cnt
            cnt += 1
        a[j+g] = v

def shellSort(a, n):
    G = []
    i = 0
    while 3 * i + 1 <= n:
        i = 3 * i + 1
        G.append(i)
    G.sort(reverse=True)
    for g in G:
        insertionSortG(a, n, g)
    G = [str(s) for s in G]
    print(len(G))
    print(' '.join(G))

n = int(input())
a = [int(input()) for _ in range(n)]
cnt = 0

shellSort(a, n)
print(cnt)
for s in a:
    print(s)


Measured memory_bytes: 45516
while(True):
    n, x = map(int, input().split())
    if(n == x == 0):
        break
    ans = 0
    for i in range(1, n + 1):
        for j in range(i + 1, n + 1):
            if(j < x - i - j < n + 1):
                ans += 1
    print(ans)

Measured memory_bytes: 7652
#include <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 1000000002486618624LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);

  int n;

  std::cin >> n;

  std::vector<int> a(n), x, y;

  for (int i = 0; i < n; i ++)
    std::cin >> a[i];

  for (int i = 0; i < n; i ++)
    if (i % 2 == 0) {
      x.push_back(a.back());

      a.pop_back();
    }
    else {
      y.push_back(a.back());

      a.pop_back();
    }

  std::reverse(ALL(y));

  std::copy(ALL(y), std::back_inserter(x));

  for (const auto& i : x)
    std::cout << i << ' ';
  std::cout << std::endl;
  
  return 0;
}


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

int main() {
  int k, a, b;
  cin >> k >> a >> b;
  while(a <= b){
    if(a % k == 0){
      cout << "OK";
      return 0;
    }
    a++;
  }
  cout << "NG";
}
    

Measured memory_bytes: 3588
#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cctype>
#include<map>
#include<cstring>

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,a,b) for (int (i)=a;(i)<(b);(i)++)
#define all(x) (x).begin(),(x).end()

using namespace std;
using ll = long long int;

const int inf = 1001001000;
const long long int Inf = 1001001001001001000;


void print(vector<vector<int>> a){
	for (int i = 0; i < a.size(); i++)
	{
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<vector<long long int>> a){
	for (int i=0;i<a.size();i++){
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(set<int> a){
	for (auto x:a)
		cout << x << " ";
	cout << endl;
}

//幅優先探索のテンプレ.デフォルトではstartからの距離を返す.
//graphは隣接リスト.startは探索開始地点
vector<int> bfs(vector<vector<int>> &graph, int start){
	queue<int> todo;
	vector<int> dist(graph.size(),-1);
	dist[start] = 0;
	todo.push(start);
	while(!todo.empty()){
		int now = todo.front();
		todo.pop();
		for (int i=0;i<graph[now].size();i++){
			int nxt = graph[now][i];
			if (dist[nxt] != -1) continue;
			dist[nxt] = dist[now] + 1;
			todo.push(nxt);
		}
	}
	return dist;
}

const int D = 80*160+10;
const int D2 = D*2;
typedef bitset<D2> bs;
 
int a[100][100];
bs dp[90][90];
 
int main() {
  int h, w;
  cin >> h >> w;
  rep(i,h)rep(j,w) {
    int x;
    cin >> x;
    a[i][j] = x;
  }
  rep(i,h)rep(j,w) {
    int x;
    cin >> x;
    a[i][j] = abs(x-a[i][j]);
  }
 
  dp[0][0][D-a[0][0]] = 1;
  dp[0][0][D+a[0][0]] = 1;
  rep(i,h)rep(j,w) {
    if (i) {
      dp[i][j] |= dp[i-1][j]<<a[i][j];
      dp[i][j] |= dp[i-1][j]>>a[i][j];
    }
    if (j) {
      dp[i][j] |= dp[i][j-1]<<a[i][j];
      dp[i][j] |= dp[i][j-1]>>a[i][j];
    }
  }
  int ans = D2;
  rep(i,D2) if (dp[h-1][w-1][i]) {
    ans = min(ans, abs(i-D));
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 24704
#include <functional>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <iomanip>
#include <vector>
#include <string>
#include <cstdio>
#include <chrono>
#include <random>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <set>
#if __cplusplus >= 201103L
#include <unordered_map>
#include <unordered_set>
#endif
#define ls x<<1
#define rs x<<1|1
#define fi first
#define se second
#define ll long long
#define pb push_back
#define mp make_pair
#define fun function
#define sz(x) x.size()
#define lowbit(x) x&(-x)
#define all(x) x.begin(),x.end()
#define mem(a,b) memset(a,b,sizeof(a))
#define IOS ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0);

using namespace std;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int INF = 0x3f3f3f3f;

char s[111111];

int main() {
	IOS;
#ifdef xiaofan
	freopen("1.in","r",stdin);
	freopen("1.out","w",stdout);
#endif

	ll n;
	cin>>n;
	cout<<(n/500)*1000+(n%500)/5*5<<endl;


	return 0;
}



Measured memory_bytes: 256
s = input()
t = input()

stri = []
mincount = 1e9
for i in range(len(s)-len(t)+1):
    count = 0
    for j in range(len(t)):
        if(s[i+j] != t[j]):
            count+= 1
    mincount = min(mincount,count) 
print(mincount)


Measured memory_bytes: 73284
// i_am_arin

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<long long> vll;
typedef vector<string> vs;


#define f(i, a, n) for(ll i=a; i<(ll)n; i++)
#define f2(i, a, b) for(ll i=a; i<=(ll)b; i++)
#define PB push_back
#define FF first
#define SS second
const ll MOD = 1e9+7;
const ll INF = LLONG_MAX;

void solve(){
ll n;
cin>>n;
ll dp[100005][3];
f(i,0,n){
	ll a,b,c;
	cin>>a>>b>>c;
	if(i==0){
		dp[i][0]=a;
		dp[i][1]=b;
		dp[i][2]=c;
	}
	else{
		dp[i][0]=max(dp[i-1][1],dp[i-1][2])+a;
		dp[i][1]=max(dp[i-1][0],dp[i-1][2])+b;
		dp[i][2]=max(dp[i-1][0],dp[i-1][1])+c;
	}
	//cout<<dp[i][0]<<" "<<dp[i][1]<<" "<<dp[i][2]<<endl;
}
cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]))<<endl;;

}

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int t=1;
	//cin>>t;
	while(t--){
		solve();
	}
	return 0;
}

Measured memory_bytes: 2560
#include <stdio.h>
#include <string.h>
#define N 100000
#define Name 10

struct process{
	char n[Name];
	int p;
};

int tail,head,n,t,total=0;
struct process S[N],f[N];

void init(){
	tail = head = 0;
}

void enque(struct process x){
	S[tail++] = x;
	tail = tail % N;
}

struct process deque(){
	struct process x;
	x = S[head++];
	head = head % N;
	return x;
}

int isEmpty(){
	if(tail == head) return 1;
	return 0;
}

int calc(){
	struct process l;
	int count=0;
	l = deque();
	while(count != n){
		if(l.p - t > 0) {
			l.p -= t;
			enque(l);
			total += t;
		}
		else {
			strcpy(f[count].n,l.n);
			total += l.p;
			f[count++].p = total;
		}
		l = deque();
	}
	return 1;

}

int main(){
	scanf("%d%d",&n,&t);
	int i;
	struct process s[N];
	for(i=0;i<n;i++){
		scanf("%s",s[i].n);
		scanf("%d",&s[i].p);
		enque(s[i]);
	}
	calc();
	for(i=0;i<n;i++){
		printf("%s %d\n",f[i].n,f[i].p);
	}
	return 0;
}

Measured memory_bytes: 5716
#include<cstdio>
#define ll long long int
ll maxn(ll a,ll b){return a>b?a:b;}
ll minn(ll a,ll b){return a<b?a:b;}
int main()
{
    ll H,M;
    while (scanf("%lld %lld",&H,&M)==2)
    {
        ll cur;
        if (H%3==0||M%3==0)printf("0\n");
        else
        {
            cur=minn(H,M);
            for (ll i=1;i<H;i++)
            {
                cur=minn(maxn(maxn(i*M,(H-i)*(M/2)),(H-i)*((M+1)/2))-minn(minn(i*M,(H-i)*(M/2)),(H-i)*((M+1)/2)),cur);
            }
            ll t=H;H=M;M=t;
            for (ll i=1;i<H;i++)
            {
                cur=minn(maxn(maxn(i*M,(H-i)*(M/2)),(H-i)*((M+1)/2))-minn(minn(i*M,(H-i)*(M/2)),(H-i)*((M+1)/2)),cur);
            }
            printf("%lld\n",cur);
        }
    }
    return 0;
}

Measured memory_bytes: 128
#D - Prediction and Restriction
# N,K = 30,5
# R,S,P=325,234,123
# T='rspsspspsrpspsppprpsprpssprpsr'

N,K = list(map(int, input().split()))
R,S,P = list(map(int, input().split()))
T = input().strip()

T=T.replace('r','P')
T=T.replace('s','R')
T=T.replace('p','S')

T_list = list(T)

for i in range(K,N):
    if T_list[i] == T_list[i-K]:
        T_list[i] = int(0)

for i in range(0,N):
    if T_list[i] == 'R':
        T_list[i] = R
    if T_list[i] == 'S':
        T_list[i] = S
    if T_list[i] == 'P':
        T_list[i] = P

print(sum(T_list))

Measured memory_bytes: 4084
from __future__ import print_function

import sys

import re
import array
import copy
import functools
import operator

import math
import string
import fractions
from fractions import Fraction
from fractions import gcd
# fractions.gcd() を用いること
# math.log2()はatcoderでは対応していない．留意せよ．

import collections
import itertools
import bisect

import random
import time

import heapq
from heapq import heappush
from heapq import heappop
from heapq import heappushpop
from heapq import heapify
from heapq import heapreplace
from queue import PriorityQueue as pq
from queue import Queue

from itertools import accumulate

from collections import deque
from collections import Counter

from operator import mul
from functools import reduce

input = sys.stdin.readline


def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)
    return


def lcm(n, m):
    return int(n * m / gcd(n, m))


def coprimize(p, q):
    common = fractions.gcd(p, q)
    return (p // common, q // common)


def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom


def find_gcd(list_l):
    x = reduce(gcd, list_l)
    return x


def main():
    n = int(input().strip())
    a = list(map(int, input().strip().split()))

    sur=0
    b=[0 for _ in range(8)]
    for i in range(n):
        if a[i] // 400 >=8:
            sur += 1
        else:
            b[a[i]//400]=1

    eprint('b ',end=':\n')
    eprint(b)

    cnt=0
    for i in range(8):
        if b[i]==1:
            cnt+=1

    ans1=cnt + sur
    ans2=cnt
    print(max(ans2,1),ans1)

if __name__ == '__main__':
    main()

Measured memory_bytes: 5440
a_l = list(range(0,int(input())+1))
b_l = list(range(0,int(input())+1))
c_l = list(range(0,int(input())+1))
X = int(input())

count = 0
for a in a_l :
    for b in b_l :
        for c in c_l :
            N = 500 * a + 100 * b + 50 * c
            if N == X :
                count = count + 1

print(count)

Measured memory_bytes: 3064
w, a, b = [int(n) for n in input().split()]

if a + w <= b:
    ans = b - (a + w)
elif a <= b < a + w:
    ans = 0
elif a < b + w <= a + w:
    ans = 0
elif b + w <= a:
    ans = a - (b + w)

print(ans)


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
  ll n;
  cin>>n;
  vector<ll> a(n+1),b(n);
  for(int i=0;i<n+1;i++){
    cin>>a[i];
  }
  for(int i=0;i<n;i++){
    cin>>b[i];
  }
  ll ans=0;
  for(int i=0;i<n;i++){
    if(b[i]>a[i]){
      ans+=a[i];
      if(b[i]-a[i]<=a[i+1]){
        a[i+1]-=b[i]-a[i];
        ans+=b[i]-a[i];
      }
      else{
        ans+=a[i+1];
        a[i+1]=0;
      }
    }
    else{
      ans+=b[i];
    }
  }
  cout<<ans;
}

Measured memory_bytes: 1792
(* O(n m) *)
let n, m = Scanf.scanf " %d %d" @@ fun a b -> a, b
let ab_s = Array.init n @@ fun _ -> Scanf.scanf " %d %d" @@ fun a b -> a, b
let cds = Array.init m @@ fun _ -> Scanf.scanf " %d %d" @@ fun a b -> a, b
let md (x1, y1) (x2, y2) = abs (x1 - x2) + abs (y1 - y2)
let _ =
  for i = 0 to n - 1 do
    let d = ref max_int in
    let c = ref 0 in
    for j = 0 to m - 1 do
      let nd = md ab_s.(i) cds.(j) in
      if nd < !d then (d := nd; c := j + 1)
    done;
    Printf.printf "%d\n" !c
  done

Measured memory_bytes: 512
#include <stdio.h>

int memo[17][301];

int tansaku(int pos,int rest) {
	int result=0;
	int i;
	int nownumber=(17-pos)*(17-pos);
	if(pos>=17)return (rest==0)?1:0;
	if(rest<0)return 0;
	if(memo[pos][rest]>0)return memo[pos][rest]-1;
	for(i=0;rest-nownumber*i>=0;i++) {
		result+=tansaku(pos+1,rest-nownumber*i);
	}
	memo[pos][rest]=result+1;
	return result;
}

int main(void) {
	int query;
	while(1) {
		scanf("%d",&query);
		if(query==0)break;
		printf("%d\n",tansaku(0,query));
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
#include <cmath>
#include <numeric>
using namespace std;
long long p[100000];
long long q[100000];
long long r[100000];
int main(){
  int X;
  int Y;
  int A;
  int B;
  int C;
  cin >> X >> Y >> A >> B >> C;
  for(int i = 0; i < A; i++){
    cin >> p[i];
  }
  for(int i = 0; i < B; i++){
    cin >> q[i];
  }
  for(int i = 0; i < C; i++){
    cin >> r[i];
  }
  
  vector <pair <long long, int> > tmp;
  for(int i = 0; i < A; i++){
    tmp.push_back(make_pair(p[i], 0));
  }
  for(int i = 0; i < B; i++){
    tmp.push_back(make_pair(q[i], 1));
  }
  for(int i = 0; i < C; i++){
    tmp.push_back(make_pair(r[i], 2));
  }

  sort(tmp.begin(), tmp.end());
  reverse(tmp.begin(), tmp.end());

  long long ans = 0;
  int red_num = 0;
  int green_num = 0;
  int inv_num = 0;
  for(int i = 0; i < tmp.size(); i++){
    if(tmp[i].second == 0 && red_num < X){
      ans += tmp[i].first;
      red_num ++;
    } else if(tmp[i].second == 1 && green_num < Y){
      ans += tmp[i].first;
      green_num ++;
    } else if(tmp[i].second == 2){
      ans += tmp[i].first;
      inv_num ++;
    }

    if(red_num + inv_num >= X){
      int inv_for_green = inv_num - (X - red_num);
      if(green_num + inv_for_green >= Y){
        cout << ans << endl;
        break;
      }
    }
  }

  return 0;
}


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

using namespace std;
int main(void) {
long long int x;cin>>x;
  int c500=0,c5=0;
  
  c500=x/500;x -= c500 * 500;//cout<<"c500  "<<c500<<endl;
  c5 = x/5;//cout<<"c5  "<<c5<<endl;
  cout<<c500*1000 + c5 *5;
 
}

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

using namespace std;

using ll = long long int;
using vi = vector<int>;
#define f(n) for(int i = 0; i < n; i++)
#define fj(n) for(int j = 0; j < n; j++)
#define fk(n) for(int k = 0; k < n; k++)
#define ci(n) cin >> n;
#define ic(n) int n; cin >> n;
#define lc(n) int n; cin >> n;
#define all(a) a.begin(), a.end()
#define pri(a, n) for(int i = 0; i < n; i++) cout << a[i] << " "; cout << "\n";
#define sc(a, n) int a[n] = {0}; for(int i = 0; i < n; i++) cin >> a[i];
#define scl(a, n) ll a[n] = {0}; for(int i = 0; i < n; i++) cin >> a[i];
#define pb push_back
#define eb emplace_back
#define int long long
const int inf = 2e18, maxn = 200000;

int g2(int n, int a, int b, int c, int d)
{
    if(n == 0) return 0;
    if(n == 1) return d;
    if(((n + 1) / 2) < (a + d - 1) / d && ((n + 2) / 3) * 2 >= (b + d - 1) / d && ((n + 4) / 5) * 4 < (c + d - 1) / d) return n * d;
    int res = 0;
    while(n % 2 == 0 && (n / 2) >= (a + d - 1) / d) n /= 2, res += a;
    while(n % 3 == 0 && (n / 3) * 2 >= (b + d - 1) / d) n /= 3, res += b;
    while(n % 5 == 0 && (n / 5) * 4 >= (c + d - 1) / d) n /= 5, res += c;
    return min(g2(n - 1, a, b, c, d), g2(n + 1, a, b, c, d));
}
int get(int n, int p, int c1, int c2)
{
    if(n == 0) return 0;
    int res = inf;
    if (n <= inf / c1) res = n * c1;
    if(n % p == 0) res = min(res, get(n / p, p, c1, c2) + c2);
    else res = min(res, get(n - 1, p, c1, c2) + c1);
    return res;
}

void solve(int ci)
{
    string s;
    cin >> s;
    cout << s.substr(0, 3);
}


main()
{
    //cout << atan2(0, -1);
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int t = 1;
    //cin >> t;
    f(t) solve(i + 1);
}


Measured memory_bytes: 3660
#include <bits/stdc++.h>
#define l_ength size
const int inf = (1<<30);
const int mod = 1000000007; // 998244353
using ll = long long;
using namespace std;

int main(){
	ll n, k; cin >> n >> k;
	cout << min(n%k, k-n%k) << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
#include<iomanip>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;


/*
木dp
*/

ll n,dp[100010][2],d[100010]={},mod=1e9+7;
vector<ll> v[100010];

ll f(ll p,ll black){
	if(dp[p][black]!=-1)return dp[p][black];
	ll ans=1;
	if(black==1){
		rep(i,v[p].size()){
			ll q = v[p][i];
			if(d[q]>d[p]){
				d[q]=d[p]+1;
				ans=(ans*f(q,0))%mod;
			}
		}
	}else{
		rep(i,v[p].size()){
			ll q = v[p][i];
			if(d[q]>d[p]){
				d[q]=d[p]+1;
				ans=(ans*((f(q,0)+f(q,1))%mod))%mod;
			}
		}
	}
	return dp[p][black]=ans;
}

int main(void){
	cin>>n;
	rep(i,n-1){
		ll x,y;
		cin>>x>>y;
		v[x].push_back(y);
		v[y].push_back(x);
	}
	//
	reg(i,1,n)rep(j,2)dp[i][j]=-1;
	reg(i,1,n)d[i]=1e9;
	d[1]=0;
	//
	cout<<(f(1,1)+f(1,0))%mod<<endl;
	// reg(i,1,n)cout<<d[i]<<" ";
	// cout<<endl;
	return 0;
}

Measured memory_bytes: 16384
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;

int find_el(vector<int> & v){
	int ans = -1;
	for(int i=0;i<(int)v.size();i++){
		if(i+1 == v[i]){
			ans = i;
		}
	}
	return ans;
}

int main() {  
	ios_base::sync_with_stdio(false);cin.tie(nullptr);
	int n;
	cin>>n;
	vector<int> v(n,0);
	for(int i=0;i<n;i++){
		cin>>v[i];
	}
	vector<int> answer;
	while(v.size()){
		int nxt = find_el(v);
		if(nxt == -1){
			cout<<nxt;
			return 0;
		}
		answer.push_back(nxt + 1);
		for(int i = nxt + 1; i<(int)v.size();i++){
			swap(v[i], v[i-1]);
		}
		v.pop_back();
	}
	for(int i =n-1;i>=0;i--){
		cout<<answer[i]<<"\n";
	}
	return 0;  
}


Measured memory_bytes: 256
import copy
N = int(input())
A = []
for _ in range(N):
  A.append(int(input()))
a = max(A)
AA = copy.deepcopy(A)
AA.remove(a)
b = max(AA)

for hoge in A:
  if hoge == a:
    print(b)
  else:
    print(a)

Measured memory_bytes: 14568
#include <iostream>
#include <vector>
using namespace std;
int main()
{
    long long H, W;
    cin >> H >> W;
    if (H == 1 || W == 1)
    {
        cout << 1 << endl;
        return 0;
    }
    long long ans = ((W + 1) / 2 )  * ((H + 1) / 2 ) + (W / 2) * (H / 2);
    cout << ans << endl;
    return 0;
}


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

int main(){
    ios::sync_with_stdio(false);    cin.tie(NULL);  cout.tie(NULL);
    string t;   cin >> t;
    int n=t.length()-1;
    for(int i=0;n>=i;i++){
        if(t[i]==t[n-i]){
            continue;
        }
        cout << "No";   return 0;
    }
    for(int i=0;(n-1)/2>=i;i++){
        if(t[i]==t[(n-1)/2-i]){
            continue;
        }
        cout << "No";   return 0;
    }
    for(int i=(n+2)/2;n>=i;i++){
        if(t[i]==t[n-i]){
            continue;
        }
        cout << "No";   return 0;
    }
    cout << "Yes";
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
    int n, i, x;
    
    scanf("%d", &n);

    for(i = 1; i <= n; i++)
    {
        if(i % 3 ==0)
        {
            printf(" %d", i);
        }
        else
        {
            x = i;
            do
            {
                if(x % 10 ==3)
                {
                    printf(" %d", i);
                    break;
                }

                x = x / 10;
            } while (x);
            
        }
        
    }
    
    printf("\n");
    
    return 0;
}


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

int main() {
  int n;
  cin >> n;
  
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  
  int cnt = 0;
  int target = 1;
  for(int i = 0; i < n; i++) {
    if(a[i] == target){
      target++;
    } else {
      cnt++;
    }
  }
  if (target == 1) {
    cnt = -1;
  }
  cout << cnt << endl;
}

Measured memory_bytes: 1024
def resolve():
    N, M = list(map(int, input().split()))
    A = list(map(lambda x: -int(x), input().split()))
    import heapq
    heapq.heapify(A)
    for i in range(M):
        v = heapq.heappop(A)
        heapq.heappush(A, v/2)
    import math
    A = list(map(lambda x: math.floor(-x), A))
    print(sum(A))
    


if '__main__' == __name__:
    resolve()

Measured memory_bytes: 89504