akhauriyash/Code-Regression huggingface dataset:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
x = list(product([0, 1], repeat=N))
ans = []

def dfs(s, mx):
	if len(s) == N:
		ans.append(s)
		return
	for i in range(mx+1):
		if i == mx:
			dfs(s+ascii_lowercase[i], mx+1)
		else:
			dfs(s+ascii_lowercase[i], mx)

dfs("", 0)
print(*ans, sep="\n")


Measured memory_bytes: 16704
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1000000007;
const int INF = MOD + 1;
const ld EPS = 1e-12;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }

/*--------------------template--------------------*/

int main()
{
	cin.sync_with_stdio(false); cout << fixed << setprecision(10);
	string s;
	cin >> s;
	int n = s.size();
	vi cnt(n);
	REP(i, n)
	{
		if (s[i] == 'a') cnt[i] = 0;
		else cnt[i] = 26 - (s[i] - 'a');
	}
	int k; cin >> k;
	REP(i, n)
	{
		if (k >= cnt[i])
		{
			k -= cnt[i];
			s[i] = 'a';
		}
	}
	s.back() += k % 26;
	cout << s << endl;
	return 0;
}

Measured memory_bytes: 1024
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n, k = list(map(int, readline().split()))
    cnt = 0
    for i in range(1, n + 1):
        if i > k:
            cnt += int((n - n % i) / i * (i - k) + max(0, n % i - max(1, k) + 1))
    print(cnt)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 39280
#include <bits/stdc++.h>
using namespace std;
#define pi acos(-1)
#define IOS ios_base::sync_with_stdio(0); cin.tie(); cout.tie();
#define ff first
#define ss second
#define pb push_back
#define debug(val) cerr << "The value of " << #val << " is = " << val << '\n';
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll inf = 0x3f3f3f3f;
const ll mininf = -922337203685477;
const ll nax = 0;
int r, c;
char arr[105][105];
bool row[105], col[105];

int main(){
	IOS
	cin >> r >> c;
	for(int i=1;i<=r;i++){
		for(int j=1;j<=c;j++){
			cin >> arr[i][j];
			if(arr[i][j]=='#'){
				row[i]=1;
				col[j]=1;
			}
		}
	}
	for(int i=1;i<=r;i++){
		if(row[i]){
			for(int j=1;j<=c;j++){
				if(col[j]){
					cout << arr[i][j];
				}
			}
			cout << endl;
		}
	}
}


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

void textIO()
{
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
}

void fastIO()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
}

vector<long long> arr[100005];
vector<bool> visited(1e5+5);
vector<long long> signpost(1e5+5);

bool bfs(long long n){
    long long cnt = 0;

    queue<long long> q({1});

    while(!q.empty()){
        long long u = q.front();
        q.pop();
        for(int i=0;i<arr[u].size();i++){
            long long v = arr[u][i];
            if(!visited[v]){
                cnt++;
                q.push(v);
                signpost[v] = u;
                visited[v] = true;
            }
        }
    }

    return cnt==n ? true:false;
}

int main()
{
    //textIO();
    fastIO();

    long long n, m;
    cin >> n >> m;

    for(int i=0;i<m;i++){
        long long u, v;
        cin >> u >> v;

        arr[u].push_back(v);
        arr[v].push_back(u);
    }

    if(bfs(n)){
        cout << "Yes" << '\n';
        for(int i=2;i<=n;i++){
            cout << signpost[i] << '\n';
        }
    }
    else{
        cout << "No" << '\n';
    }

    return 0;
}


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

typedef pair<int, int> YM;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, M, y;
  cin >> N >> M;
  int P[M], X[M];
  vector<YM> ym[N];
  for(int m=0; m<M; m++){
    cin >> P[m] >> y;
    ym[P[m]-1].push_back({y, m});
  }
  for(int n=0; n<N; n++){
    sort(
      ym[n].begin(), ym[n].end(),
      [](const YM& ym0, const YM& ym1) {return ym0.first < ym1.first;}
    );    
    for(int i=0; i<ym[n].size(); i++){
      X[ym[n][i].second] = i+1;
    }
  }
  for(int m=0; m<M; m++)printf("%06d%06d\n", P[m], X[m]);
  return 0;
}

Measured memory_bytes: 7808
/*
 #pragma GCC target ("avx2")
 #pragma GCC optimize ("Ofast")
 #pragma GCC optimize ("unroll-loops")
*/
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
#include <set>
#include <map>
#include <unordered_map>
#include <iomanip>
#include <stack>
#include <queue>
#include <deque>
using namespace std;
bool possible[10011];
int a[105];
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    possible[0]=true;
    int n;
    cin>>n;
    long long ans=0;
    for(int i=1;i<=n;i++)cin>>a[i];
    for(int k=1;k<=n;k++){
        for(int x = 10000-a[k]; x >=0;x--){
            possible[x+a[k]]|=possible[x];
        }
    }
    for(long long i=1;i<=10000;i++){
        if(possible[i]){
            if(i%10!=0){
                ans=max(ans,i);
            }
        }
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 256
/*                         _
                        _ooOoo_
                       o8888888o
                       88" . "88
                       (| -_- |)
                       O\  =  /O
                    ____/`---'\____
                  .'  \\|     |//  `.
                 /  \\|||  :  |||//  \
                /  _||||| -:- |||||_  \
                |   | \\\  -  /'| |   |
                | \_|  `\`---'//  |_/ |
                \  .-\__ `-. -'__/-.  /
              ___`. .'  /--.--\  `. .'___
           ."" '<  `.___\_<|>_/___.' _> \"".
          | | :  `- \`. ;`. _/; .'/ /  .' ; |
          \  \ `-.   \_\_`. _.'_/_/  -' _.' /
===========`-.`___`-.__\ \___  /__.-'_.'_.-'================

                  Please give me AC.
*/

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>

using namespace std;

using int64 = long long;
using uint64 = unsigned long long;
using vi = vector<int>;
using vl = vector<int64>;
using pii = pair<int, int>;
using pll = pair<int64, int64>;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define print(x) cout << (x) << '\n'
#define print2(x, y) cout << (x) << ' ' << (y) << '\n'
#define print3(x, y, z) cout << (x) << ' ' << (y) << ' ' << (z) << '\n'
#define printn(v) rep(i, (v).size() - 1) cout << (v)[i] << ' '; cout << (v)[n - 1] << '\n';
#define debug(x) cerr << #x << ": " << (x) << '\n'
#define debug2(x, y) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v) for (size_t _ = 0; _ < v.size(); ++_){cerr << #v << "[" << _ << "] : " << v[_] << '\n';}
// constant
const int INF = (1<<30) - 1;
const int64 INF64 = (1LL<<62) - 1;

// End of template.


int main(){
    cout << fixed << setprecision(15);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n;
    int a[100100];
    int b[100100];
    int c[100100];
    cin >> n;
    rep(i, n) cin >> a[i] >> b[i] >> c[i];

    int dp[100100][3];
    // fill(begin(dp), end(dp), INF);
    dp[0][0] = dp[0][1] = dp[0][2] = 0;
    rep(i, n) {
        dp[i + 1][0] = max(dp[i][1] + a[i], dp[i][2] + a[i]);
        dp[i + 1][1] = max(dp[i][0] + b[i], dp[i][2] + b[i]);
        dp[i + 1][2] = max(dp[i][0] + c[i], dp[i][1] + c[i]);
    }

    print(max({dp[n][0], dp[n][1], dp[n][2]}));

    return 0;
}



Measured memory_bytes: 2560
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstring>
#include <cmath>
const double EPS = 1e-9;
const int INF = 10000000;
const int MOD = 1e9 + 7;
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, 1, -1};
typedef long long ll;
using namespace std;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    while(cin >> n, n)
    {
        vector<int> vec(n + 1), R(n + 1), O(n + 1);
        for(int i = 0; i < n; i++)
        {
            cin >> vec[i];
        }
        double H = 1e9;
        int ans1, ans2, ans3;
        for(int s = 0; s < 16; s++)
        {
            for(int a = 0; a < 16; a++)
            {
                for(int c = 0; c < 16; c++)
                {
                    vector<int> cnt(256, 0);
                    R[0] = s;
                    for(int i = 1; i <= n; i++)
                    {
                        R[i] = (a * R[i - 1] + c) % 256;
                        O[i] = (vec[i - 1] + R[i]) % 256;
                        cnt[O[i]]++;
                    }
                    double sum = 0;
                    for(int i = 0; i < 256; i++)
                    {
                        if(cnt[i] <= 0)
                            continue;
                        sum -= (((double)cnt[i] / n) * log((double)cnt[i] / n));
                    }
                    if(sum + EPS < H)
                    {
                        H = sum;
                        ans1 = s;
                        ans2 = a;
                        ans3 = c;
                    }
                }
            }
        }
        cout << ans1 << " " << ans2 << " " << ans3 << endl;
    }
    return 0;
}



Measured memory_bytes: 3436
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {
	static PrintWriter out = new PrintWriter(System.out);
	public static void main(String[] args) {
		// 入力
		final int n;	// 1≦N≦100
		final int[] a;	// −100≦ai≦100
		try(Scanner scan = new Scanner(System.in)) {
			n = scan.nextInt();
			a = new int[n];
			for (int i = 0; i < n; i++) {
				a[i] = scan.nextInt();
			}
		}
		
		// 数値が小さいのでそのまま全列挙計算したほうが速い。
		
		int result = IntStream.rangeClosed(-100, 100)
				.map(y -> Arrays.stream(a).map(e -> (e-y)*(e-y)).sum())
				.min().getAsInt();
		
		// 出力
		out.println(result);
		out.close();
	}

}

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

struct Process
{
	string name;
	int time;
};

int main()
{
	int N, Q;
	list<Process> v;
	cin >> N >> Q;
	for(int i = 0; i < N; ++i)
	{
		Process temp;
		cin >> temp.name >> temp.time;
		v.push_back(temp);
	}
	
	int total = 0;
	list<Process>::iterator now = v.begin();
	while(!v.empty())
	{
		if(now == v.end())
		{
			now = v.begin();
		}
		
		if((*now).time <= Q)
		{
			total += (*now).time;
			cout << (*now).name << " " << total << endl;
			now = v.erase(now);
		}
		else
		{
			(*now).time -= Q;
			total += Q;
			++now;
		}
	}

    return 0;
}



Measured memory_bytes: 7860
a=int(input())
if 400<=a<=599:
    print(8)
elif 600<=a<=799:
    print(7)
elif 800<=a<=999:
    print(6)
elif 1000<=a<=1199:
    print(5)
elif 1200<=a<=1399:
    print(4)
elif 1400<=a<=1599:
    print(3)
elif 1600<=a<=1799:
    print(2)
else:
    print(1)

Measured memory_bytes: 9184
#include "bits/stdc++.h"

using namespace std;

#define ll             long long int
#define eb             emplace_back

static const int maxn = 4e5 + 5;
static const ll mod = 1e9 + 7;

int main()
{
      ios_base::sync_with_stdio(false);
      cin.tie(nullptr);
      cout.tie(nullptr);
      cout << fixed << setprecision(12);


      ll a, b;
      cin >> a >> b;
      ll maxi = a + b;
      maxi = max(maxi, a - b);
      maxi = max(maxi, a * b);
      cout << maxi << endl;

}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")

#include <algorithm>      //sort,二分探索,など
#include <bitset>         //固定長bit集合
#include <cmath>          //pow,logなど
#include <complex>        //複素数
#include <deque>          //両端アクセスのキュー
#include <functional>     //sortのgreater
#include <iomanip>        //setprecision(浮動小数点の出力の誤差)
#include <iostream>       //入出力
#include <iterator>       //集合演算(積集合,和集合,差集合など)
#include <map>            //map(辞書)
#include <numeric>        //iota(整数列の生成),gcdとlcm(c++17)
#include <queue>          //キュー
#include <set>            //集合
#include <stack>          //スタック
#include <string>         //文字列
#include <unordered_map>  //イテレータあるけど順序保持しないmap
#include <unordered_set>  //イテレータあるけど順序保持しないset
#include <utility>        //pair
#include <vector>         //可変長配列
#include <list>           //双方向連結リスト

using namespace std;


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

    int n, q;
    cin >> n;
    vector<int> s(n);
    for(int i = 0; i < n; ++i){
        cin >> s[i];
    }
	cin >> q;
    vector<int> t(q);
    for(int i = 0; i < q; ++i){
        cin >> t[i];
    }
    int count = 0;
    int front, rear, middle;
    for(int i = 0; i < q; ++i){
        front = 0;
        rear = n - 1;
        while(front <= rear){
            middle = (front + rear) / 2;
            if(t[i] == s[middle]){
                ++count;
                break;
            }else if(t[i] < s[middle]){
                rear = middle - 1;
            }else{
                front = middle + 1;
            }
        }
    }
    cout << count << "\n";
	return 0;
}


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

int main(){

    int n; cin >> n;
    vector<int> a(n);
    vector<int> b(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    for(int i = 0; i < n; i++) b[i] = i + 1;

    map<vector<int>, int> mb;
    queue<pair<vector<int>, int> > qb;
    
    mb[b] = -1;
    qb.push({b, 0});
    

    while(1){

        vector<int> now(n);
        now = qb.front().first;
        int cost = qb.front().second;
        qb.pop();
        
        if(cost == 4) break;

        bool ok = true;
        for(int i = 0; i < n; i++){
            if(a[i] != now[i]){
                ok = false;
                break;
            }
        }

        if(ok){
            cout << cost << endl;
            return 0;
        }

        for(int i = 0; i < n - 1; i++){
            for(int j = i + 1; j < n; j++){
                vector<int> next(n);
                next = now;

                for(int k = i; k <= j; k++){
                    next[k] = now[j - k + i];
                }


                if(mb.find(next) == mb.end()){
                    mb[next] = cost + 1;
                    qb.push({next, cost + 1});
                }
            }
        }
    }


    //cout << "junnbihadeketa" << endl;
    map<vector<int>, int> ma;
    queue<pair<vector<int>, int> > qa;
    ma[a] = -1;
    qa.push({a, 0});

    while(1){

        vector<int> now(n);
        now = qa.front().first;
        int cost = qa.front().second;
        qa.pop();

        if(cost == 4) break;

        if(mb.find(now) != mb.end()){
            cout << cost + mb[now] << endl;
            return 0;
        }

        for(int i = 0; i < n - 1; i++){
            for(int j = i + 1; j < n; j++){
                vector<int> next(n);
                next = now;
                for(int k = i; k <= j; k++){
                    next[k] = now[j + i - k];
                }

                if(ma.find(next) == ma.end()){
                    ma[next] == cost + 1;
                    qa.push({next, cost + 1});
                }
            }
        }
    }

    cout << 9 << endl;
    return 0;
}


Measured memory_bytes: 102956
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
#include<vector>
using namespace std;
int N,X;
int r[31];
bool sosu[1000001];
bool dp[1000001];
int solve(){
  int res=0;
  memset(dp,false,sizeof(dp));
  for(int i=0;i<N;i++) dp[r[i]]=true;
  for(int i=1;i<=X;i++){
    if(!dp[i]) continue;
    if(!sosu[i]) res=i;
    for(int j=0;j<N;j++){
      if(i+r[j]>X) continue;
      dp[i+r[j]]=true;
    }
  }
  return res;
}

main(){
  sosu[0]=true;
  sosu[1]=true;
  for(int i=2;i<1000001;i++){
    if(!sosu[i])
      for(int j=i*2;j<1000001;j+=i){
	if(j>1000000) break;
	sosu[j]=true;
      }
  }
  while(1){
    scanf("%d %d",&N,&X);
    if(N==0 && X==0) break;
    for(int i=0;i<N;i++){
      scanf("%d",&r[i]);
    }
    int res = solve();
    if(res==0) puts("NA");
    else printf("%d\n",res);
  }
}

Measured memory_bytes: 3156
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0175

"""
import sys
from sys import stdin
input = stdin.readline


def main(args):
    while True:
        n = int(input())
        if n == -1:
            break

        q = []
        q.append(n % 4)
        while n > 3:
            n //= 4
            q.append(n % 4)

        q.reverse()
        print(''.join(map(str, q)))


if __name__ == '__main__':
    main(sys.argv[1:])
    

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

int64_t pow2(int ex){
    int64_t ans=1;
    for(int i;i<ex;i++) ans*=2;
    return ans;
}

int main() {
    int64_t H;
    cin >> H;

    int64_t l2H = int(log2(H));

    cout << pow2(l2H+1)-1 << endl;


    return 0;
}


Measured memory_bytes: 256
N = int(input())
SN = [input() for i in range(N)]

AC = 0
WA = 0
TLE = 0
RE = 0
for n in SN:
    if n == "AC":
        AC += 1
    elif n == "WA":
        WA += 1
    elif n == "TLE":
        TLE += 1
    else:
        RE += 1

print("AC x " + str(AC))
print("WA x " + str(WA))
print("TLE x " + str(TLE))
print("RE x " + str(RE))


Measured memory_bytes: 16228
# coding: utf-8
X, N = map(int, input().split())
if N == 0:
    print(X)
    exit()
P = list(map(int, input().split()))
P.sort()
ans = 10 ** 9
# d = [True for _ in range(0, 101)]
li = []
for i in range(-200, 201, 1):
    if i not in P:
        li.append(i)
for i in range(len(li)):
    if abs(ans - X) > abs(li[i] - X):
        ans = li[i]
print(ans)

Measured memory_bytes: 9204
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <random>
#include <cstdio>
#include <cstring>
#include <cmath>

// for i in f..<t {... : as Swift
#define forin(i, f, t) for(auto i = f; i < t; i++)

using namespace std;
using ll = long long;

int main() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    
    vector<int> numE(n), numW(n);
    numE[0] = 0;
    for (auto i = 1; i < n; i++) {
        numE[i] = (s[i - 1] == 'E') ? numE[i - 1] + 1 : numE[i - 1];
    }
    numW.back() = 0;
    for (auto i = n - 2; i >= 0; i--) {
        numW[i] = (s[i + 1] == 'W') ? numW[i + 1] + 1 : numW[i + 1];
    }
    auto maxC = 0;
    for (auto i = 0; i < n; i++) {
        maxC = max(maxC, numE[i] + numW[i]);
    }
    cout << n - maxC - 1 << endl;
    
}



Measured memory_bytes: 3076
import numpy as np
import math
import scipy as sp
import queue
import collections

MOD = 10 ** 9 + 7
INF = 10 ** 9

def main(kwargs):
    n = kwargs["n"]
    if n == 1:
        res = 0
    elif n == 2:
        res = 2
    else:
        res = (10 ** n % MOD - 9 ** n % MOD * 2 + 8 ** n) % MOD
    return res

if __name__ == "__main__":
    kwargs = {}

    cin = input().split()
    kwargs["n"] = [int(i) for i in cin][0]

    cout = main(kwargs)
    print(cout)

Measured memory_bytes: 32436
import std.stdio;
import std.range;
import std.array;
import std.algorithm;
import std.string;
import std.conv;

void main(){
    immutable n = readln.chomp.to!int;
    auto d_x = readln.chomp.split.map!(to!int);
    auto days = d_x[0];
    auto rest = d_x[1];
    int[] as;
    as.length = n;
    as.each!((ref a){
        a = readln.chomp.to!int;
    });
    auto answer = rest;
    iota(0,n).each!((p){
        auto day = 1;
        while(day <= days){
            answer++;
            day += as[p];
        }
    });
    answer.writeln;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
typedef long long ll;

const ll MOD =1000000007LL;
ll fact[220010];


ll rev(int a){
	ll ans=1;
	ll b=a;
	ll n=MOD-2;
	while(n){
		if(n&1)
			ans=(ans*b)%MOD;
		b=(b*b)%MOD;
		n >>=1;
	}
	return (ans+MOD)%MOD;
}

ll com(ll n,ll m){
	ll ans=1;
	ans=(fact[n]*rev(fact[m]))%MOD*rev(fact[n-m])%MOD;
	return (ans+MOD)%MOD;
}

int main(void){
	fact[0]=1;
	for(int i=1;i<=220000;i++)
		fact[i]=(fact[i-1]*i)%MOD;
	int N,M,K;
	cin >> N >> M >> K;
	ll ans=0;
	for(int p=0;p<=K;p++){
		int q=K-p;
		ll a=((com(N+2*p,p)*(N+1))%MOD*rev(N+p+1))%MOD;
		ll b=((com(M+2*q,q)*(M+1))%MOD*rev(M+q+1))%MOD;
		ll c=(com(M+N+2*K,N+2*p))%MOD;
		ans=(ans+((a*b)%MOD*c)%MOD)%MOD;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 2880
def f(x, y)
  if x * y < 0
    return 0
  else
    $memo[x][y] = f(x - 1, y) + f(x, y - 1) unless $memo[x][y]
    return $memo[x][y]
  end
end
def main(input = STDIN)
  while (a, b = input.gets.split(" ").map(&:to_i)) != [0, 0]
    $memo = Array.new(a){Array.new(b)}
    $memo[0][0] = 1
    input.gets.to_i.times do
      x, y = input.gets.split(" ").map(&:to_i)
      $memo[x - 1][y - 1] = 0
    end
    #puts $memo.map{|a|a.map(&:to_i).join(" ")}
    puts f(a - 1, b - 1)
  end
end
main

Measured memory_bytes: 6096
#include<stdio.h>
int main()
{
	int m,f,r,p;
	while(1){
		scanf("%d%d%d",&m,&f,&r);
		if(m==-1&&f==-1&&r==-1)break;
		p=m+f;
		if (m<0||f<0) printf("F\n");
		else if (80<=p) printf("A\n");
		else if (65<=p&&p<80) printf("B\n");
		else if (50<=p&&p<65) printf("C\n");
		else if (50<=p&&p<65) printf("C\n");
		else if (30<=p&&p<50) {
			if (50<=r) printf("C\n");
			else printf("D\n");
		} else if (p<30) printf("F\n");
	}
	return 0;
}

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

int main(){
    int ans = 0;
    int N, K;

    cin >> N >> K;

    int h[N];
    for(int i=0; i<N; i++){
        cin >> h[i];
    }

    for(int i=0; i<N; i++){
        if(h[i] >= K){
            ans += 1;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 640
N,M = map(int,input().split())

a = [0]*M
b = [0]*M
ans = [0]*M
for i in range(M):
	A,B = map(int,input().split())
	a[i] = A
	b[i] = B


class UnionFind():
    #負の値はルートで集合の個数
    #正の値は次の要素を返す
    def __init__(self,size):
        self.table = [-1 for _  in range(size)]

    #集合の代表を求める
    def find(self,x):
        while self.table[x] >= 0:
            #根に来た時,self.table[根のindex]は負の値なのでx = 根のindexで値が返される。
            x = self.table[x]
        return x
    def is_same_set(self,x,y):
    	return self.find(x)==self.find(y)
    #併合
    def size(self,x):
    	y = self.find(x)
    	return -self.table[y]
    def union(self,x,y):
        s1 = self.find(x)#根のindex,table[s1]がグラフの高さ
        s2 = self.find(y)
        if s1 != s2:#根が異なる場合
            if self.table[s1] != self.table[s2]:#グラフの高さが異なる場合
                if self.table[s1] < self.table[s2]:
                    self.table[s1] -= self.size(s2)	
                    self.table[s2] = s1
                else:
                    self.table[s2] -= self.size(s1)
                    self.table[s1] = s2
            else:
                #グラフの長さが同じ場合,どちらを根にしても変わらない
                #その際,グラフが1長くなることを考慮する
                self.table[s1] -= self.size(s2)
                self.table[s2] = s1
        return
uf = UnionFind(N+1)
now = N*(N-1)//2

for i in range(M):
	j = M-i-1
	ans[j] = now
	sa = uf.size(a[j])
	sb = uf.size(b[j])
	if not uf.is_same_set(a[j],b[j]):
		now -= sa*sb
	uf.union(a[j],b[j])

for i in range(M):
	print(ans[i])

Measured memory_bytes: 16936
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <map>
#include <functional>
#include <tuple>
using namespace std;

long long K, S, cnt;

int main() {
	cin >> K >> S;
	for (int i = 0; i <= K; i++) {
		for (int j = 0; j <= K; j++) {
			long long B = S - i - j;
			if (B >= 0 && B <= K) cnt++;
		}
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include <map>
#include <algorithm>
#include <vector>
#define ll long long int
using namespace std;

int main(){
	int a, b,ans;
	char op;
	cin >> a >> op >> b;
	if (op == '+') {
		ans = a + b;
	}
	if (op == '-') {
		ans = a - b;
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
const int N = 3e5 + 5;
const int M = 1 << 26;
char str[N];
int n;
int bst[M];
int dp[N];
int pre[N];
int main(){
	scanf("%s" , str + 1);
	n = strlen(str + 1);
	for(int i = 0 ; i < M ; ++i){
		bst[i] = N;
	}
	pre[0] = 0;
	for(int i = 1 ; i <= n ; ++i){
		pre[i] = pre[i - 1] ^ (1 << (str[i] - 'a'));
	}
	dp[n + 1] = 0;
	for(int i = n ; i >= 1 ; --i){
		bst[pre[i]] = min(bst[pre[i]] , dp[i + 1]);
		int res = bst[pre[i - 1]];
		for(int j = 0 ; j < 26 ; ++j){
			res = min(res , bst[pre[i - 1] ^ (1 << j)]);
		}
		dp[i] = res + 1;
	}
	printf("%d\n" , dp[1]);
}

Measured memory_bytes: 264576
#include<iostream>
#include<sstream>
#include<vector>
#include<iterator>
#include<climits>
#include<algorithm>
#include<utility>
using namespace std;

int main(void)
{
	int N, K;
	cin >> N >> K;

	string S;
	cin >> S;

	vector<pair<int, int>> s;
	int now = 1;
	int cnt = 0;
	for (int i = 0; i < N; i++) {
		if (S[i] == (char)(now + '0')) {
			cnt++;
		}
		else {
			s.push_back(make_pair(now, cnt));
			now = 1 - now;
			cnt = 1;
		}
	}
	if (cnt != 0)
		s.push_back(make_pair(now, cnt));

	vector<int> imos(s.size() + 1, 0);
	for (int i = 0; i < (int)s.size(); i++)
		imos[i + 1] += imos[i] + s[i].second;

	int ans = 0;
	for (int i = 0; i < (int)s.size(); i++) {
		int j;
		if (s[i].first == 0) {
			j = min((int)imos.size() - 1, i + 2 * K);
		}
		else {
			j = min((int)imos.size() - 1, i + 2 * K + 1);
		}

		ans = max(ans, imos[j] - imos[i]);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1652
#pragma region include
#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <tuple>
#include <bitset>

#include <queue>
#include <complex>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <fstream>
#include <random>
//#include <time.h>
#include <ctime>
#pragma endregion //#include
/////////
#define REP(i, x, n) for(int i = x; i < n; ++i)
#define rep(i,n) REP(i,0,n)
#define ALL(X) X.begin(), X.end()
/////////
#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
typedef std::pair<LL,LL> PLL;//
typedef std::pair<int,int> PII;//
#pragma endregion //typedef
////定数
const int INF = (int)1e9;
const LL MOD = (LL)1e9+7;
const LL LINF = (LL)1e18+20;
const double PI = acos(-1.0);
const double EPS = 1e-9;
/////////
using namespace::std;

struct Rectangle{LL height;int pos;};
void solve(){
	int H,W;
	cin >> H >> W;
	vector< string > RC(H);
	vector< vector<int> > fld(H-1,vector<int>(W-1,0));
	for(int h=0;h<H;++h){
		cin >> RC[h];
	}
	--H;
	--W;
	for(int h=0;h<H;++h){
		for(int w=0;w<W;++w){
			int cnt = 0;
			cnt += (RC[h][w]=='#');
			cnt += (RC[h+1][w]=='#');
			cnt += (RC[h][w+1]=='#');
			cnt += (RC[h+1][w+1]=='#');
			if( cnt % 2 == 0 ){
				//パリティを調べる。偶数なら1
				fld[h][w] = 1;
			}
		}
	}
	vector< vector<int> > fld2(H,vector<int>(W,0));//H方向の累積和
	fld2 = fld;
	for(int w=0;w<W;++w){
		for(int h=1;h<H;++h){
			if( fld2[h][w] == 0 ) continue;
			fld2[h][w] += fld2[h-1][w];
		}
	}
	//最小値コーナー：一辺が2以上の長方形が作れない場合
	int maxV = max(W+1,H+1);//
	for(int h=0; h<H; ++h){
		stack< Rectangle> S;
		for(int w=0;w<=W;++w){//ヒストグラムの最大長方形と同じ
			Rectangle rect;//高さと位置
			if( w != W ){//
				rect.height = fld2[h][w];
			}else{//
				rect.height = 0;//端の処理
			}
			rect.pos = w;
			if( S.empty() ){//空なら追加
				S.push( rect );
			}else{//空でない
				//高さが同じ時は何もしない。前の情報に任せる
				if( S.top().height < rect.height){//前より高い
					S.push( rect );
				}else if( S.top().height > rect.height ){//前より低い
					int target = w;
					while( !S.empty() && S.top().height >= rect.height){
						Rectangle pre = S.top();S.pop();
						//この問題特有。縦横それぞれに+1する。
						int area = (pre.height+1) * (1+w-pre.pos);
						maxV = max(maxV,area);
						target = pre.pos;
					}
					rect.pos = target;
					S.push( rect );
				}
			}
		}
	}
	cout << maxV << endl;
}

#pragma region main
signed main(void){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}
#pragma endregion //main()

Measured memory_bytes: 35968
<?php
$n = intval(fgets(STDIN));
$A = array_map("intval", explode(" ", trim(fgets(STDIN))));
$j = 0;
$bits = 0;
$sum = $n * ($n+1) / 2;
foreach($A as $i => $a){
  while($bits & $A[$i])$bits^=$A[$j++];
  $bits |= $a;
  $sum -= $j;
}
echo $sum;


Measured memory_bytes: 27120
import java.util.Scanner;


	public class Main {
		

		public static void main(String[] args) {

			Scanner sc = new Scanner(System.in);
	        
			long a = sc.nextLong();
			long b = sc.nextLong();
			long c = sc.nextLong();
			long k = sc.nextLong();
			
			long ab = a+b;
			long ret = 2*a-k+b;
			
			if(a>=k) {
				System.out.println(k);
				return;
			}else if(ab>=k) {
				System.out.println(a);
				return;
			}else {
				System.out.println(ret);
				return;
			}
		}
		
	}


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

int main() {
	int n, k;
	cin >> n >> k;
	vector<int> l(n);
	for (int i = 0; i < n; i++) cin >> l.at(i);

	sort(l.begin(), l.end(), greater<int>());
	
	int ans = 0;
	for(int i = 0; i < k; i++) ans += l.at(i);

	cout << ans << endl;

 	return 0;
}

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

int main(){
  int n, num; cin >> n;
  num = n /7 + 1;
  int nn = n;
  bool b = false;
  for(int i = 0; i < num; i++)
  {
    n -= 7*i;
    if(n < 0) n = nn;
    if(n % 4 == 0){
      b = true;
      cout << "Yes" << endl;
      break;
    }
  }
  if (! b) {
    cout << "No" << endl;
  }
  
  
  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define M (1000000007)
#define N (1010)
int n,ans,ti[N];
queue<int>a[N];

int main(){
	scanf("%d",&n); int x;
	for (int i=1;i<=n;++i)
		for (int j=1;j<n;++j){
			scanf("%d",&x);
			a[i].push(x);
		}
	bool f1,f2; int fir;
	while (1){
		f1=0,f2=0;
		for (int i=1;i<=n;++i){
			if (!a[i].empty()) f1=1;
			while (!a[i].empty()&&a[a[i].front()].front()==i){
				ti[i]=ti[a[i].front()]=max(ti[i],ti[a[i].front()])+1;
				a[a[i].front()].pop(),a[i].pop(),f2=1;
			}
		}
		if (!f1){
			for (int i=1;i<=n;++i) ans=max(ans,ti[i]);
			printf("%d",ans);
			return 0;
		}
		if (!f2){
			printf("-1\n");
			return 0;
		}
	}
}


Measured memory_bytes: 4736
//                        Bismillahir Rahmanir Rahim
//ALGO:
#include<bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define all(v) v.begin(), v.end()
#define FILL(a, x) memset(a, x, sizeof(a))
#define ll long long
#define _i ({int a; scanf("%d", &a); a;})
#define _l ({ll a; scanf("%lld", &a); a;})
#define _d ({double a; scanf("%lf", &a); a;})
#define _c ({char a; cin>>a; a;})
#define _s ({string a; cin>>a; a;})
#define Fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define INF INT_MAX
#define mx 1000010
#define mod 1000000007
#define dout if(debug) cout
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ordered_multiset tree<pair<int, int>, null_type,less<pair<int, int> >, rb_tree_tag,tree_order_statistics_node_update>
*/
const double Pi=acos(-1);
using namespace std;
int debug=01;
ll n, fact[10];
ll f(){
    int a[n+1];
    set<int>s;
    for(int i=1; i<=n; i++){
        cin>>a[i];
        s.insert(i);
    }
    ll pos=1;
    for(int i=1; i<n; i++){
        pos+=distance(s.begin(), s.lower_bound(a[i]))*fact[n-i];
        s.erase(s.find(a[i]));
    }
    return pos;
}
int main() {
    Fast
    fact[0]=1;
    for(int i=1; i<9; i++) fact[i]=fact[i-1]*i;
    cin>>n;
    cout<<abs(f()-f());
}


Measured memory_bytes: 3604
N,Q = map(int,input().split())
scores = [0 for _ in range(N)]
flags = [1 for _ in range(N)]

tree = [[] for _ in range(N)]
for i in range(N-1):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    tree[a].append(b)
    tree[b].append(a)

for _ in range(Q):
    p,x = map(int,input().split())
    scores[p-1] += x

from collections import deque
nextp = deque([0])
flags[0] = 0
while nextp:
    p = nextp.pop()
    for t in tree[p]:
        if flags[t]:
            scores[t] += scores[p]
            flags[t] = 0
            nextp.append(t)
print(*scores)

Measured memory_bytes: 56168
#include <bits/stdc++.h>
using namespace std;
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
    int h[n], dp[n];
    for (int i = 0; i < n; i++)
    {
    	cin >> h[i];
    }

    dp[0] = 0;
    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] << "\n";

    return 0;
}

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

#define ll long long

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll a, b, c, d;
	cin >> a >> b >> c >> d;
	if (a+b > c+d){cout << "Left" << endl;}
	else if (a+b == c+d){cout << "Balanced" << endl;}
	else {cout << "Right" << endl;}
}


Measured memory_bytes: 256
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007

#A
def A():
    x, t = LI()
    print(max(0, x-t))
    
    return

#B
def B():
    return

#C
def C():
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    A()


Measured memory_bytes: 3700
#include <bits/stdc++.h>
#define REP(i,n,N) for(int i=(n);i<(int)N;i++)
#define p(s) cout<<(s)<<endl
#define ck(n,a,b) ((a)<=(n)&&(n)<(b))
#define F first
#define S second
typedef long long ll;
using namespace std;
const int inf=1e9;

bool ok[8];
int main() {
	int n;
	cin>>n;
	int ans=0;

	int cnt = 0;
	REP(i,0,n){
		int a;
		cin>>a;
		if(a<400) ok[0]=true;
		else if(a<800) ok[1]=true;
		else if(a<1200) ok[2]=true;
		else if(a<1600) ok[3]=true;
		else if(a<2000) ok[4]=true;
		else if(a<2400) ok[5]=true;
		else if(a<2800) ok[6]=true;
		else if(a<3200) ok[7]=true;
		else cnt++;
	}
	REP(i,0,8) ans+=ok[i];
	cout<<max(ans,1)<<" "<<ans+cnt<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;
const int INF = 1000000009;
const ll LINF = 1e18;

int main() {
  int n; cin >> n;
  vector<ll> a(n);
  for (int i = 0; i < n; ++i) cin >> a[i];
  sort(a.begin(), a.end(), greater<ll>());
  
  ll sum = 0;
  int t = n - 1;
  for (int i = 0; i < n; ++i) {
    if (i == 0) {
      sum = a[0];
      --t;
      if (t == 0) {
        cout << sum << endl;
        return 0;
      }
    } else {
      for (int j = 0; j < 2; ++j) {
        --t;
        sum += a[i];
        if (t == 0) {
          cout << sum << endl;
          return 0;
        }
      }
    }
  }
}


Measured memory_bytes: 4384
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    int ans=1e9;
    ans=min(ans,abs(a+b-c-d));
    ans=min(ans,abs(a-b+c-d));
    ans=min(ans,abs(a-b-c+d));
    cout << ans<<endl;
    return 0;
}



Measured memory_bytes: 3216
#include <iostream>
#include <algorithm>

using namespace std;

void trace(int* A, int n)
{
    cout << A[0];
    for(int i=1; i < n; i++)
    {
        cout << " " << A[i];
    }
    cout << endl;

    return;
}

void insertionSort(int* A, int n)
{
    trace(A, n);

    for(int i=1; i<n; i++)
    {
        int v = A[i];
        int j = i - 1;

        while(j >= 0 && A[j] > v)
        {
            A[j+1] = A[j];
            j--;
        }
        A[j+1] = v;

        trace(A, n);
    }

    return;
}


int main(void)
{
    int n;
    int input;
    int A[100];

    cin >> n;
    for(int i=0; i < n; i++) cin >> A[i];

    insertionSort(A, n);

    return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<n; ++i)
#define rep1(i, n) for (int i=1; i<=n; ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
constexpr ll  MOD = (1e9+7);
constexpr int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
constexpr int lcm(int a, int b) { return a / gcd(a, b) * b; }

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;
}
ll factorial(ll n, ll m=2) {
    // calculate n!
    m = max(2LL, m);
    ll rtn = 1;
    for (ll i=m; i<=n; i++) {
        rtn = (rtn * i) % MOD;
    }
    return rtn;
}
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
ll modpow(ll a, ll n) {
    ll res = 1;
    while (n > 0) {
        if (n & 1)
            res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int h, a; cin >> h >> a;
    cout << (h+(a-1)) / a << endl;
    return 0;
}

Measured memory_bytes: 256
// Forked from http://d.hatena.ne.jp/sndr/20150112/1421067951

import std.stdio, std.string, std.conv, std.algorithm, std.range;
import std.container : RedBlackTree;

void main()
{
    foreach (m; 0..readln.chomp.to!int)
    {
        auto ans = new RedBlackTree!dstring();
        auto str = readln.chomp.to!dstring;
        foreach (i, c; str)
            foreach (x; [str[0..i].idup, str[0..i].retro.array.idup])
                foreach (y; [str[i..$].idup, str[i..$].retro.array.idup])
                    ans.insert([x~y, y~x]);
        ans.length.writeln;
    }
}

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

int main() {
  int n, k;
  cin >> n >> k;
  
  int ans = 0;
  
  for(int i = n; i <= k ; i++) {
    int s = i % 10;
    int t = i / 10000 % 10;
    int u = i / 10 % 10;
    int v = i / 1000 % 10;
    if (s == t && u == v)
      ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main(){
    int x,y,a,b,c,x2=0,y2=0;
    unsigned long long int sum=0;
    cin>>x>>y>>a>>b>>c;
    vector<int> p(a),q(b),r(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];
    sort(p.begin(), p.end(), greater<int>());
    sort(q.begin(), q.end(), greater<int>());
    sort(r.begin(), r.end(), greater<int>());
    for(;;){
        if(x-x2+y-y2==0 || min(x-x2?p[x-1-x2]:INT32_MAX, y-y2?q[y-1-y2]:INT32_MAX) >= r[x2+y2] || x2+y2==c){
            break;
        }
        if((y-y2==0)||(x-x2!=0 && p[x-1-x2] < q[y-1-y2])){
            if(r[x2+y2] > p[x-1-x2])
                x2++;
        }else{
            if(r[x2+y2] > q[y-1-y2])
                y2++;
        }
    }
    for(int i=0; i<x-x2; i++)
        sum += p[i];
    for(int i=0; i<y-y2; i++)
        sum += q[i];
    for(int i=0; i<x2+y2; i++)
        sum += r[i];
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 1408
n,m=map(int,input().split())
x=list(map(int,input().split()))
x.sort()
lis=[]
for i in range(1,m):
  lis.append(x[i]-x[i-1])
  
lis.sort()
res=0
for i in range(0,m-n):
  res+=lis[i]
print(res)

Measured memory_bytes: 13968
import bisect
def main():
    n=int(input())
    l=sorted(list(map(int,input().split(' '))))
    ans = 0
    for n,i in enumerate(l):
        for m,j in enumerate(l[n+1:]):
                ans +=bisect.bisect_left(l,i+j) - bisect.bisect_right(l,abs(i-j))
                if abs(i-j)<i<i+j:
                    ans -=1
                if abs(i-j)<j<i+j:
                    ans -=1
    print(ans//3)
if __name__ == '__main__':
    main()


Measured memory_bytes: 49500
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <cstring>
#include <map>

#define rep(i, N) for (int i = 0; i < (int)N; i++)
using namespace std;
typedef long long ll;
const ll LLINF = 9223372036854775807;
const int MOD = 1000000007;

int main() {
  int a, b, h; cin >> a >> b >> h;
  int result = (a+b)*h/2;
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 256
n,q=map(int,input().split(' '))
x=list(input())
d=[0 for i in range(n)]
for i in range(1,n):
    if x[i]=="C" and x[i-1]=="A":
        d[i]=d[i-1]+1
    else:
        d[i]=d[i-1]
for i in range(q):
    l,r=map(int,input().split(' '))
    print(d[r-1]-d[l-1])
            


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

class Program {
  static void Main (string[] args) {
    string str = Console.ReadLine();
    int ans = int.Parse(str);
    if (ans == 3 || ans == 5 || ans == 7) {
      Console.WriteLine("YES");
    }
    else
    {
      Console.WriteLine("NO");
    }
  }
}

Measured memory_bytes: 13140
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,k,i=2,ans=1,divider,flag=0;
    cin>>n>>k;
    divider=k;
    while(n>divider)
    {
        divider=pow(k,i);
        if(divider==n)
        {
            flag=1;
        }
        ans++;
        i++;
    }
    cout<<ans+flag;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
X = list(map(int, input().split()))
maxX =max(X)
ansmin = float('INF')
HP = 0
for i in range(1,maxX+1):
    for j in range(N):
        HP += (X[j]-i)**2
    ansmin = min(ansmin, HP)
    HP = 0
print(ansmin)

Measured memory_bytes: 3060
#include <bits/stdc++.h> 
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define sz(x) (int)(x).size()
typedef vector<int> vi;
// #define ll long long 
#define int long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define all(x) (x).begin(), (x).end()
const int MOD = 1e9+7;
int mpow(int a,int b,int p=MOD){a=a%p;int res=1;while(b>0){if(b&1)res=(res*a)%p;a=(a*a)%p;b=b>>1;}return res%p;}
const int N=2*1e5+2;

int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int n,r;
	cin>>n>>r;
	if(n>=10)
	{
		cout<<r;
	}
	else{
		cout<<r+100*(10-n);
	}
} 
// I never lose. I either win or I learn

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>

using namespace std;


int main() {
	int a; cin >> a;
	if (a >= 3200) {
		string s; cin >> s;
		cout << s << endl;
	}
	else {
		cout << "red" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#
# abc051 a
#
import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """happy,newyear,enjoy"""
        output = """happy newyear enjoy"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """haiku,atcoder,tasks"""
        output = """haiku atcoder tasks"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """abcde,fghihgf,edcba"""
        output = """abcde fghihgf edcba"""
        self.assertIO(input, output)


def resolve():
    s = input()
    print(s.replace(",", " "))


if __name__ == "__main__":
    # unittest.main()
    resolve()


Measured memory_bytes: 16068
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
using ll=long long;
#define int ll
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define SZ(x) x.size()
#define fi first
#define se second
const int INF = 1e13;
using namespace std;

template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;

using pi=pair<int,int>;
using vi=vc<int>;

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

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(20);

    int N,K; cin >> N >> K;
    int A[N]; rep(i,N) cin >> A[i];
    if(K==1) {
        cout << 0 << endl;
        return 0;
    }
    int ans=INF;
    int comb=(1<<(K-1))-1;
    while(comb < (1<<N)){
        if(comb&1);
        else{
            int now=0;
            int pos=0;
            rep(i,N){
                if(chmax(now,A[i]));
                else if((comb>>i)&1){
                    if(now+1>A[i]) {
                        pos+=now+1-A[i];
                        now++;
                    }
                }
            }
            chmin(ans,pos);
        }
        int x=comb&-comb,y=comb+x;
        comb=((comb&~y)/x>>1)|y;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
typedef long long ll;

int main(void)
{
    int ans = 1, min;
    int n, p[200001];

    scanf("%d", &n);
    rep(i, n)
        scanf("%d", &p[i]);

    min = p[0];
    for (int i = 1; i < n; i++)
        if (min > p[i])
        {
            ans++;
            min = p[i];
        }

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

    return 0;
}

Measured memory_bytes: 896