akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bits/stdc++.h>
#include <bitset>
#include <cassert>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <cmath>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>
using namespace std;
#define REP(i, n) for (int64_t i = 0; i < (int64_t)n; i++)
#define REP_FOR(i, a, b) for (int64_t i = (int64_t)a; i < (int64_t)b; i++)
#define REP_REV(i, a, b) for (int64_t i = (int64_t)a; i > (int64_t)b; i--)
#define FORALL(v) (v).begin(), (v).end()
#define mp(a, b) make_pair(a, b)
#define eb(x) emplace_back(x)
#define F first
#define S second
typedef long long ll;
typedef long double ld;
typedef pair<int64_t, int64_t> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int64_t> vii;
typedef vector<vii> vvii;
const ll mod = 1e9 + 7;
const int64_t infi = 1147483600;
const ll infl = 4e18 + 5;
const char EOL = '\n';
const ll MOD = 998244353;

int main() {
    ll N;
    cin >> N;
    map<string, ll> m;
    ll cur = 0;
    for (ll i = 0; i < N; ++i) {
        string a;
        cin >> a;
        m[a]++;
        cur = max(cur, m[a]);
    }
    vector<string> v;
    for (auto iter = m.begin(); iter != m.end(); ++iter) {
        if (iter->second == cur) {
            v.emplace_back(iter->first);
        }
    }
    sort(v.begin(), v.end());
    for (auto & i: v) {
        cout << i << endl;
    }
}


Measured memory_bytes: 26868
#! /usr/bin/env python3

import sys
import numpy as np
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)


def list_split(l):
    res = []
    idx = 0
    for i in range(len(l) - 1):
        if l[i] > l[i + 1]:
            res.append(l[idx:i + 1])
            idx = i + 1

    res.append(l[idx:len(l)])

    return res


N, *A = map(int, read().split())
money = 1_000
n_stocks = 0
cost = 0

ll = list_split(A)

for l in ll:
    if len(l) == 1:
        continue
    acc = money // min(l)
    money -= acc * min(l)
    money += acc * max(l)

print(money)


Measured memory_bytes: 27156
#include <stdio.h>

#define Mod 1000000007

int main()
{	
	int N, M;
	scanf("%d %d", &N, &M);
	
	int i, j, k;
	long long dp[302][302] = {}, tmp;
	for (k = 1, dp[1][1] = 1; k <= M; k++) {
		for (i = k; i >= 1; i--) {
			for (j = i; j >= 1; j--) {
				tmp = dp[i][j] % Mod;
				dp[i][j] = 0;
				dp[i+1][j] += tmp * (N - i);
				dp[i][i] += tmp * j;
				dp[i][j] += tmp * (i - j);
			}
		}
	}
	
	printf("%lld\n", dp[N][N] % Mod);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 2416
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Stack;

public class Main {

	public static void main(String[] args) throws IOException {
		// TODO ?????????????????????????????????????????????
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String[] strArray = br.readLine().split(" ");
		Stack<Integer> stack = new Stack<Integer>();
		
		for(int i = 0; i < strArray.length ; i++){
			char input = strArray[i].charAt(0);
			if(Character.isDigit(input)){
				stack.push(Integer.parseInt(strArray[i]));
			}
			else {
				int tmpResult = 0;
				if(input == '+'){
					tmpResult = stack.pop() + stack.pop();
				}
				else if(input == '-'){
					tmpResult = -(stack.pop() - stack.pop());
				}
				else if(input == '*'){
					tmpResult = stack.pop() * stack.pop();
				}	
				//System.out.println(tmpResult);
				stack.push(tmpResult);
			}
		}
		
		System.out.println(stack.pop());
	}

}

Measured memory_bytes: 24452
import sys

n, m = map(int, input().split())

L = [float("inf") for i in range(n)]

for i in range(m):
    s, c = map(int, input().split())
    if L[s - 1] == c:
        continue
    elif L[s - 1] < float("inf"):
        print(-1)
        sys.exit()
    else:
        L[s - 1] = c

if n > 1 and L[0] == 0:
    print(-1)
elif n == 1 and L[0] == 0:
    print(0)
elif n == 1 and L[0] == float("inf"):
    print(0)
elif L[0] == float("inf"):
    L[0] = str(1)
    for i in range(1, n):
        if L[i] == float("inf"):
            L[i] = str(0)
        else:
            L[i] = str(L[i])
    print("".join(L))

else:
    for i in range(n):
        if L[i] == float("inf"):
            L[i] = str(0)
        else:
            L[i] = str(L[i])
    print("".join(L))



Measured memory_bytes: 3064
#    !/usr/bin/env python3
#    encoding: UTF-8
#    Modified: <28/Sep/2019 05:37:25 PM>


#    ✪ H4WK3yE乡
#    Mohd. Farhan Tahir
#    Indian Institute Of Information Technology (IIIT), Gwalior


import sys
import os
from io import IOBase, BytesIO


def main():
    n = int(input())
    tmp = get_array()
    arr = []
    for i in range(n):
        arr.append([tmp[i], i + 1])
    arr.sort()
    for i in range(n):
        print(arr[i][1], end=" ")


BUFSIZE = 8192


class FastIO(BytesIO):
    newlines = 0

    def __init__(self, file):
        self._file = file
        self._fd = file.fileno()
        self.writable = "x" in file.mode or "w" in file.mode
        self.write = super(FastIO, self).write if self.writable else None

    def _fill(self):
        s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
        self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
        return s

    def read(self):
        while self._fill():
            pass
        return super(FastIO, self).read()

    def readline(self):
        while self.newlines == 0:
            s = self._fill()
            self.newlines = s.count(b"\n") + (not s)
        self.newlines -= 1
        return super(FastIO, self).readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.getvalue())
            self.truncate(0), self.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        py2 = round(0.5)
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        if py2 == 1:
            self.write = self.buffer.write
            self.read = self.buffer.read
            self.readline = self.buffer.readline
        else:
            self.write = lambda s: self.buffer.write(s.encode("ascii"))
            self.read = lambda: self.buffer.read().decode("ascii")
            self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)


def get_array():
    return list(map(int, sys.stdin.readline().split()))


def get_ints():
    return map(int, sys.stdin.readline().split())


def input():
    return sys.stdin.readline().strip()


if __name__ == "__main__":
    main()


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


int n;
int arr[105];

ll sq(int i){return (ll)i*i;}

int main(){
	cin>>n;
	for (int x=0;x<n;x++) cin>>arr[x];
	
	ll best=1000000000000000000;
	
	ll curr;
	
	for (int x=0;x<=100;x++){
		curr=0;
		for (int y=0;y<n;y++) curr+=sq(x-arr[y]);
		
		best=min(best,curr);
	}
	
	cout<<best;
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define RREP(i, n) RFOR(i, n, 0)
#define MFOR(i, m) for(auto i=(m).begin();i!=(m).end();i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())

typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1 << 30;

template<typename T>
void printv(vector<T> const& s) {
  REP(i, SZ(s)) {
    cout << s[i] << " ";
  }
  cout << endl;
}

int main () {
  cin.tie(0);
  cout << setprecision(10);
  string s; cin >> s;

  string tmp;
  REP(i, SZ(s)) {
    if(s[i] != 'x') tmp.pb(s[i]);
  }
  bool ok = true;
  REP(i, SZ(tmp)/2) {
    if(tmp[i] != tmp[SZ(tmp)-1-i]) {
      ok = false;
      break;
    }
  }
  if(!ok) {
    cout << -1 << endl;
    return 0;
  }
  int ans = 0;
  int l = -1, r = SZ(s);
  while(l < r) {
    int x1 = 0, x2 = 0;
    l++; r--;
    while(s[l] == 'x') {
      x1++;
      l++;
    }
    while(s[r] == 'x') {
      x2++;
      r--;
    }
    if(l <= r) ans += abs(x1 - x2);
    //cout << l << ":" << r << ":" << ans << endl;
  }
  cout << ans << endl;
}


Measured memory_bytes: 640
#pragma GCC optimize ("O3")
// #pragma GCC target ("avx")
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define NDEBUG
#define eprintf(...) do {} while (0)
#endif
#include<cassert>

using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) {
    for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }
    putchar('\n');
}

int N;
char S[1000011];

int F(int n) {
    int ret = 0;
    while (n) {
	n /= 2;
	ret += n;
    }
    return ret;
}
int nCkOdd(int n, int k) {
    return F(n) == F(k) + F(n-k);
}

void MAIN() {
    scanf("%d", &N);
    scanf("%s", S);
    if (N == 1) {
	printf("%c\n", S[0]);
	return;
    }

    REP (i, N) S[i]--;

    int zero = count(S, S+N, '0');
    int one = count(S, S+N, '1');
    int two = N - zero - one;

    char ans;
    if (one == 0 && two) {
	int x = 0;
	REP (i, N) if (S[i] == '2') x ^= nCkOdd(N-1, i);
	if (x & 1) ans = '2';
	else ans = '0';
    } else {
	int x = 0;
	REP (i, N) if (S[i] == '1') x ^= nCkOdd(N-1, i);
	if (x & 1) ans = '1';
	else ans = '0';
    }
    printf("%c\n", ans);
}

int main() {
    int TC = 1;
//    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}



Measured memory_bytes: 1280
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;


int main(){
  int N; cin >> N; string S[N];
  rep(i, N){
    cin >> S[i];
  }
  int cnt = 0;
  rep(i, N){
    bool can = true;
    rep(j, N){
      rep(k, N){
        if(S[j][(k+i)%N]!=S[k][(j+i)%N]){
          can = false; 
        }
      }
    }
    if(can) cnt++;
  }
  cnt*=N;
  cout << cnt << endl;
}

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

int main(){
    string suf[18] = {"", "Man", "Oku", "Cho", "Kei", "Gai", "Jo", "Jou", "Ko", 
                    "Kan", "Sei", "Sai", "Gok", "Ggs", "Asg", "Nyt", "Fks", "Mts"};

    int m, n;
    while(cin >> m >> n, m+n){
        int d[18] = {};
        d[0] = 1;

        for(int i = 0; i < n; i++){
            int carry = 0;
            for(int j = 0; j < 18; j++){
                d[j] = d[j]*m + carry;
                carry = d[j]/10000;
                d[j] %= 10000;
            }
        }

        for(int i = 17; i >= 0; i--){
            if(d[i])    cout << d[i] << suf[i];
        }
        cout << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3196
#include <iostream>
#include <bits/stdc++.h>
 
 
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define fore(i,a) for(auto &i:a)
 
typedef pair <int, int> P;
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
const int  INF = 1 << 30;
const ll INFL = 1LL << 60;
const ll mod = 1000000007;
 
 
 
int main() {
 
    int n;
    cin>>n;
    
    VLL a(n+1),b(n);
    
    REP(i,n+1)cin>>a[i];
    REP(i,n)cin>>b[i];
    
    ll ans = 0;
    
    REP(i,n){
        ans +=min(a[i],b[i]);
        b[i]=max(0LL,b[i]-a[i]);
        ans+=min(a[i+1],b[i]);
        a[i+1]-=b[i];
        a[i+1]=max(a[i+1],0LL);
    }
    
    cout<<ans<<endl;


}

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

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define erep(i, n) for (ll i = 0; i <= (ll)(n); ++i)
#define FOR(i,a,b) for (ll i = (a); i < (ll)(b); ++i)
#define EFOR(i,a,b) for (ll i = (a); i <= (ll)(b); ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } }

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


int main() {
    int a,b,c; cin >> a >> b >> c;
    if(a!=b && a!=c && b!=c) {
        cout << "No" << endl;
        return 0;
    }
    if(a==b && b==c && a==c) {
        cout << "No" << endl;
        return 0;
    }

    cout << "Yes" << endl;
    return 0;

}


Measured memory_bytes: 256
import math

a, b, h, m = map(int, input().split())

degh = (h * 30) + (30 * m / 60)
degm = 6 * m

deg = math.radians(min(abs(degh - degm), 360 - abs(degh - degm)))

# print(degh, degm, deg)

c2 = a ** 2 + b ** 2 - (2 * a * b * math.cos(deg))
c = math.sqrt(c2)

print(c)

Measured memory_bytes: 9560
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) unique(v.begin(), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

#define MAX_E 100000
#define MAX_V 100000

struct edge {
	ll from, to, cost;
};
ll d[MAX_V];
ll V, E;

edge es[MAX_E];

void shortest_path(int s) {
	rep(i, 0, V) d[i] = INF;
	d[s] = 0;
	while(true) {
		bool update = false;
		rep(i, 0, E) {
			edge e = es[i];
			if(d[e.from] != INF && d[e.to] > d[e.from] + e.cost) {
				d[e.to] = d[e.from] + e.cost;
				update = true;
			}
		}
		if(!update) break;
	}
}

bool find_negative_loop(int s) {
	//memset(d, 0, sizeof(d));
	fill(d, d + V, INF);
	d[s] = 0;
	rep(i, 0, V) {
		rep(j, 0, E) {
			edge e = es[j];
			if(d[e.from] != INF && d[e.to] > d[e.from] + e.cost) {
				d[e.to] = d[e.from] + e.cost;
				if(i == V - 1 and e.to == V - 1) return true;
			}
		}
	}
	return false;
}

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

	cin >> V >> E;
	rep(i, 0, E) {
		ll s, t, d;
		cin >> s >> t >> d;
		s--; t--;
		es[i].from = s;
		es[i].to = t;
		es[i].cost = -d;
	}

	if(find_negative_loop(0)) {
		cout << "inf" << endl;
		return 0;
	}

	cout << -d[V - 1] << endl;
}


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

using namespace std;

int main()
{
    string s, t;

    cin >> s >> t;

    const long long l = s.length();
    int count = 0;
    for( int i = 0; i < l; ++i )
    {
        if( s[i] != t[i] )
        {
            ++count;
        }
    }
    cout << count << endl;

    return 0;
}

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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

const ll INF=1234567890123456LL;

//魔法をj回まで使えるときに、スライムiを入手するまでにかかる時間
ll cost[2000][2000]={0};

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

    vector<ll> a(n);
    rep(i,n) scanf(" %lld", &a[i]);

    rep(i,n) cost[i][0]=a[i];

    rep(i,n)for(int j=1; j<n; ++j)
    {
        //魔法をj回使う、つまりj個前の色
        int col=(i-j+n)%n;
        cost[i][j] = min(cost[i][j-1], a[col]);
    }

    // rep(i,n)rep(j,n) printf("cost[%d][%d]= %lld\n",i,j,cost[i][j]);

    ll ans=INF;
    rep(j,n)
    {
        ll getcost=0;
        rep(i,n) getcost+=cost[i][j];

        ans=min(ans, getcost+x*j);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 31488
#include<iostream>
using namespace std;
int main()
{
    string s;
    // int A,B;
    cin >> s;
    // cin >> A >> s >> B;
    string s2="";
    int c = 0;

    for(int i=0;i<s.size();i++){
        if (s[i] == ','){
            s2+=' ';
        }else{
            s2+= s[i];
        }
    }

    cout << s2 << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*

fun main(args: Array<String>) {
    val mod = 1000000007L
    val S = readString()
    val T = readString()

    fun f(S:String, T:String):Boolean {
        val tr = CharArray(26){'0'}
        for ((s,t) in S.zip(T)) {
            if (tr[s - 'a'] == '0') tr[s - 'a'] = t
            if (tr[s - 'a'] == t) continue

            println("No")
            return false
        }
        return true
    }

    if (!f(S,T)) return
    if (!f(T,S)) return

    println("Yes")
}

fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toInt)


Measured memory_bytes: 53976
N = int(input()) 
S = input()
def is_even(num):
    if num % 2 == 0:
        return True
    else:
        return False
if is_even(N):
  if S[:N//2] == S[N//2:]:
    print("Yes")
  else:
    print("No")
else:
  print("No")
  

Measured memory_bytes: 2940
def common(x, y):
    n = len(x)
    m = len(y)
    c1 = [0 for i in range(m + 1)]
    for i in range(n):
        e1 = x[i]
        c2 = c1[:]
        for j in range(m):
            if (e1 == y[j]):
                c1[j + 1] = c2[j] + 1
            elif (c1[j + 1] < c1[j]):
                c1[j + 1] = c1[j]
    return(c1[-1])


n = int(input())
for i in range(n):
    x = str(input())
    y = str(input())
    print(common(x, y))


Measured memory_bytes: 5632
#include <stdio.h>

long long int dp[51][51][2501] = {{{1}}};	// i個からj個選んで和をsにする選び方の総数

// O(N^3X)の解法
int main(void)
{
	int i, j, A, N, s, x;
	long long int ans = 0;

	scanf("%d%d", &N, &A);
	for (i = 1; i <= N; i++) {
		scanf("%d", &x);
		for (j = 0; j <= N; j++) {
			for (s = 0; s <= 2500; s++) {
				if (s < x) {
					dp[i][j][s] = dp[i - 1][j][s];
				} else if (j >= 1) {
					dp[i][j][s] = dp[i - 1][j - 1][s - x]	// xを選択した場合
								+ dp[i - 1][j][s];			// xを選択しなかった場合
				} 
			}
		}
	}

	for (i = 1; i <= N; i++) {
		ans += dp[N][i][i * A];
	}

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

	return 0;
}

Measured memory_bytes: 49280
//use itertools::Itertools;
use std::cmp;
use std::collections::BTreeMap;
use std::collections::BTreeSet;
use std::collections::BinaryHeap;
use std::collections::HashMap;
use std::collections::HashSet;
use std::collections::VecDeque;
use std::io::Read;
use std::usize::MAX;

macro_rules! input {(source = $s:expr, $($r:tt)*) => {let mut iter = $s.split_whitespace();let mut next = || { iter.next().unwrap() };input_inner!{next, $($r)*}};($($r:tt)*) => {let stdin = std::io::stdin();let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));let mut next = move || -> String{bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect()};input_inner!{next, $($r)*}};}
macro_rules! input_inner {($next:expr) => {};($next:expr, ) => {};($next:expr, $var:ident : $t:tt $($r:tt)*) => {let $var = read_value!($next, $t);input_inner!{$next $($r)*}};}
macro_rules! read_value {($next:expr, ( $($t:tt),* )) => {( $(read_value!($next, $t)),* )};($next:expr, [ $t:tt ; $len:expr ]) => {(0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()};($next:expr, chars) => {read_value!($next, String).chars().collect::<Vec<char>>()};($next:expr, usize1) => {read_value!($next, usize) - 1};($next:expr, [ $t:tt ]) => {{let len = read_value!($next, usize);(0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()}};($next:expr, $t:ty) => {$next().parse::<$t>().expect("Parse error")};}

fn solve() {
    input! {
        x1: usize,
        x2: usize,
        x3: usize,
        x4: usize,
        x5: usize,
    }

    if x1 == 0 {
        println!("1");
        return;
    }

    if x2 == 0 {
        println!("2");
        return;
    }

    if x3 == 0 {
        println!("3");
        return;
    }

    if x4 == 0 {
        println!("4");
        return;
    }

    if x5 == 0 {
        println!("5");
        return;
    }

    let mut ans = 0;
}

fn main() {
    let thd = std::thread::Builder::new().stack_size(104_857_600);
    thd.spawn(|| solve()).unwrap().join().unwrap();

    /*
    // 入力を一括で読み込む場合
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut input = buf.split_whitespace();

    // inputに対しnext()で読み込んでいく
    let q: usize = input.next().unwrap().parse().unwrap();
    */
}

const LARGE_PRIME: u64 = 1_000_000_007;

// @〜でsnippet


Measured memory_bytes: 2240
package main

/*
N A B
*/
import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	flag := false
	stdin := bufio.NewScanner(os.Stdin)
	stdin.Scan()
	line := strings.Split(stdin.Text(), " ")
	n, _ := strconv.Atoi(line[0])
	for four := 0;four<=25;four++ {
		for seven := 0 ;seven <=14; seven++ {
			if four*4+seven*7 <=100 {
				if four*4+seven*7 == n {
				 flag = true
				 break
				}
			}
		}
	}

if flag {
	fmt.Println("Yes")
} else {
	fmt.Println("No")
	}
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <string.h>
#include <stack>
#include <queue>
#include <algorithm>
#include <climits>
#include <cmath>
#include <map>
#include <set>
#include <assert.h>
#define REP(i,n) for(ll i=0;i<(n);i++)
#define MOD 1000000007
//#define int long long
#ifdef int
const long long INF = LLONG_MAX / 10;
#else
const int INF = 1010101010;
#endif
using namespace std;
typedef long long ll;
typedef vector<vector<ll> > mat;
typedef pair<int, int> P;
//typedef pair<double, double> P;
const int dx[9] = {-1, 0, 0, 1, -1, -1, 1, 1, 0};
const int dy[9] = {0, -1, 1, 0, -1, 1, -1, 1, 0};

int H, W;
char maze[60][60];
int sx, sy;
int gx, gy;
int d[60][60];  //各点までの最短距離の配列

//(sx, sy)から(gx, gy)への最短経路を求める
int bfs()
{
  queue<P> que;
  REP(i,H) REP(j,W) d[i][j] = INF;
  que.push(P(sx, sy));
  d[sy][sx] = 0;

  while (que.size()) {
    P p = que.front(); que.pop();
    if (p.first == gx && p.second == gy) break;
    REP(i,4) {
      int nx = p.first + dx[i];
      int ny = p.second + dy[i];
      if (0 <= nx && nx < W && 0 <= ny && ny < H && maze[ny][nx] != '#' && d[ny][nx] == INF) {
        que.push(P(nx, ny));
        d[ny][nx] = d[p.second][p.first] + 1;
      }
    }
  }

  return d[gy][gx];
}

signed main()
{
  cin >> H >> W;
  int x = 0;
  REP(i,H) REP(j,W) {
    cin >> maze[i][j];
    if (maze[i][j] == '#') x++;
  }
  sx = 0, sy = 0, gx = W - 1, gy = H - 1;
  //cout << bfs() << endl;
  if (bfs() == INF) {
    cout << -1 << endl;
    return 0;
  }
  cout << H * W - x - bfs() - 1 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define pii pair<int,int>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(c) (c).begin(),(c).end()
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MINF(a) memset(a,0x3f,sizeof(a))
#define POW(n) (1LL<<(n))
#define IN(i,a,b) (a <= i && i <= b)
using namespace std;
template <typename T> inline bool CHMIN(T& a,T b) { if(a>b) { a=b; return 1; } return 0; }
template <typename T> inline bool CHMAX(T& a,T b) { if(a<b) { a=b; return 1; } return 0; }
template <typename T> inline void SORT(T& a) { sort(ALL(a)); }
template <typename T> inline void REV(T& a) { reverse(ALL(a)); }
template <typename T> inline void UNI(T& a) { sort(ALL(a)); a.erase(unique(ALL(a)),a.end()); }
const int MOD = 1000000007;
const int INF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-10;
/* ---------------------------------------------------------------------------------------------------- */

int H,W,D;
int A[310][310];
pii ps[90010];
int cum[90010];

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  cin >> H >> W >> D;
  REP(i,H) REP(j,W) {
    cin >> A[i][j];
    ps[A[i][j]] = pii(i,j);
  }
  FOR(i,1,D+1) {
    for (int j = i+D; j <= H*W; j += D) {
      cum[j] = cum[j-D] + abs(ps[j].first-ps[j-D].first) + abs(ps[j].second-ps[j-D].second);
    }
  }
  int Q;
  cin >> Q;
  REP(i,Q) {
    int L,R;
    cin >> L >> R;
    cout << cum[R] - cum[L] << endl;
  }

  return 0;
}

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

const int maxn = 2e5 + 10;
char s[maxn];

int main()
{
	scanf("%s",s);
	int n = strlen(s),S = 0,res = n;
	for(int i=0;i<n;++i)
	{
		if(s[i] == 'S') S++;
		else
		{
			if(S) S--,res -= 2;
		}
	}
	printf("%d\n",res);
	return 0;
}

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

typedef long long ll;
// #define int int_fast64_t
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 999999999
#define DEBUG(s) cout << s << endl
// typedef int_fast64_t int;

using namespace std;

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

    vector<pair<pair<ll, ll>, ll>> P(m);
    REP(i, m) {
        cin >> P[i].first.first >> P[i].first.second;
        P[i].second = i;
    }
    sort(P.begin(), P.end());

    vector<pair<ll, ll>> D;
    int c(0), p(0), q(0);
    for (auto i : P) {
        if (q != i.first.first)
            q = i.first.first, p = c;
        c++;
        D.emplace_back(i.second, i.first.first * 1000000 + c - p);
    }
    sort(D.begin(), D.end());

    for (auto i : D)
        cout << setw(12) << setfill('0') << i.second << endl;
}

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

const int N = 1e5+20;

int n, k, Piedras[N], dp[N];

int Recursion(int Piedra = 0){
	if (Piedra == n- 1) return 0;
	if(dp[Piedra] != -1) return dp[Piedra];
	dp[Piedra] = INT_MAX;
//	if(Piedra+1 <= n-1) dp[Piedra] = min(dp[Piedra], Recursion(Piedra+1) + abs(Piedras[Piedra] - Piedras[Piedra+1]));
//	if(Piedra+2 <= n-1) dp[Piedra] = min(dp[Piedra], Recursion(Piedra+2) + abs(Piedras[Piedra] - Piedras[Piedra+2]));	
	for (int i = 1; i <= k; i++)
	{
		if(Piedra+i <= n-1) {
			dp[Piedra] = min(dp[Piedra], Recursion(Piedra+i) + abs(Piedras[Piedra] - Piedras[Piedra+i]));	
		} 
	}
	return dp[Piedra];
}

int main()
{
	cin >> n >> k;
	for (int i = 0; i < n; i++){
		cin >> Piedras[i];	
	}
	memset(dp, -1, sizeof dp);
	cout << Recursion();	
}
 

Measured memory_bytes: 5760
while True:
    try:
        n, m = map(int, input().split())
        start = 1
        end = n
        for i in range(m):
            a, b = map(int, input().split())
            if a > end or b < start:
                print(0)
                for j in range(m-i-1):
                    input()
                break
            start = max(start, a)
            end = min(end, b)   
        else:
            print(end-start+1)
    except:
        break

Measured memory_bytes: 3064
text = input()
n = int(input())
for i in range(n):
    cmd, *arg = input().split()
    arg0, arg1 = int(arg[0]), int(arg[1])
    if cmd == 'print':
        print(text[arg0:arg1+1])
    elif cmd == 'reverse':
        text = text[:arg0] + text[arg0:arg1+1][::-1] + text[arg1+1:]
    else: # replace
        text = text[:arg0] + arg[2] + text[arg1+1:]


Measured memory_bytes: 5616
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>

using namespace std;
int main(){
  int n;
  while(cin >> n, n!=0){
    int posx = 10,posy = 10;
    vector<int> tx,ty;
    for(int i=0;i<n;i++){
      int x,y;
      cin >> x >> y;
      tx.push_back(x);
      ty.push_back(y);
    }
    int m;
    cin >> m;
    int movex[m],movey[m];
    string c;
    int l;
    for(int i=0; i<m;i++){
      cin >> c >> l;
      if(c == "N"){
	movex[i] = 0;
	movey[i] = l;	    
      }else if(c == "E"){
	movex[i] = l;
	movey[i] = 0;
      }else if(c == "S"){
	movex[i] = 0;
	movey[i] = -1*l;
      }else if(c == "W"){
	movex[i] = -1*l;
	movey[i] = 0;
      }
      for(int j=0;j<tx.size();j++){
	if(tx[j] >= posx && tx[j] <= posx + movex[i] && ty[j] >= posy && ty[j] <=posy + movey[i]){
	  n--;
	  vector<int>::iterator del;
	  del = tx.begin()+j;
	  tx.erase(del);
	  del = ty.begin()+j;
	  ty.erase(del);
	  j--;
	}else if(tx[j] <= posx && tx[j] >= posx + movex[i] && ty[j] <= posy && ty[j] >=posy + movey[i]){
	  n--;
	  vector<int>::iterator del;
	  del = tx.begin()+j;
	  tx.erase(del);
	  del = ty.begin()+j;
	  ty.erase(del);
	  j--;
	}
      }
      posx += movex[i];
      posy += movey[i];
    }
    if(tx.size() == 0){
      cout << "Yes" <<endl;
    }else{
      cout << "No" <<endl;
    } 
  }		  
}

Measured memory_bytes: 1224
#include <iostream>

#define modes 1000000007
using namespace std;

long long kuri2j(int n,long long x){//n^x mod modesを求める関数
    if(x==0) return (long long)1;
    if(x%2){
        return (n*kuri2j(n,x-1))%modes;
    } else {
        long long ll= kuri2j(n,x/2);
        return (ll*ll)%modes;
    }
}

int main(){
    int n,a,b;
    cin >> n >> a >> b;
    // 2^n-1を求める
    long long ans= kuri2j(2,n)-1;
    long long nCa=1,Y=1;
    for(int i=0; i<a; i++) nCa = (nCa*(n-i))%modes;
    for(int i=1; i<=a;i++) Y = (Y*i)%modes;
    nCa = (nCa*kuri2j(Y,modes-2))%modes;
    ans -= nCa;
    if(a+b==n){
        ans -= nCa;
    } else {
        long long nCb=1,X=1;
        for(int i=0; i<b; i++) nCb = (nCb*(n-i))%modes;
        for(int i=1; i<=b;i++) X = (X*i)%modes;
        nCb = (nCb*kuri2j(X,modes-2))%modes;
        ans -= nCb;
    }
    if(ans < 0) ans = ans%modes + modes;
    cout << ans << endl;
}


Measured memory_bytes: 3600
#include <stdio.h>

int main(){
	int ch;
	int str[1200];
	int i=0;
	int iSize;
	int j;

	while(1){
		ch =  getchar();
		if(ch == EOF)
			break;
		if(ch >= 65 && ch <= 90)
			str[i] = ch+32;
		else if(ch >= 97 && ch <= 122)
			str[i] = ch-32;
		else 
			str[i] = ch;
		i++;
	}
	for(j=0; j<i; j++){
		printf("%c",(char)str[j]);
	}

	return 0;
}

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

const ll mod = 1000000007;
struct mint {
    ll x;  // typedef long long ll;
    mint(ll x = 0) : x((x % mod + mod) % mod) {}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    mint inv() const {
        return pow(mod - 2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res /= a;
    }
};

struct combination {
    vector<mint> fact, ifact;
    // init struct with \"n\" of \"nCk\" (maximum number in other words)
    combination(int n) : fact(n + 1), ifact(n + 1) {
        assert(n < mod);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
    }
    // c(n,k) returns mint that contains nCk (mod p (= 1e9+7)) in x
    // i.e.) mint num = c(n,k), then num.x == nCk (mod p (= 1e9+7))
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n] * ifact[k] * ifact[n - k];
    }

    // nPk - permutation
    mint p(int n, int k) {
        return fact[n] * ifact[n - k];
    }
};

int main() {
	ll n;
    cin >> n;
    mint ans = mint(10).pow(n);
    ans -= mint(9).pow(n);
    ans -= mint(9).pow(n);
    ans += mint(8).pow(n);
    cout << ans.x << endl;
}


Measured memory_bytes: 3612
#include "iostream"
#include "vector"
#include "string"
#include "algorithm"
#include "math.h"
#include "cstring"
#include "stack"
#include "queue"

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

int n;
ll a[3010];
ll dp[3010][3010];
const ll inf = 1e15;

ll rec(int l, int r)//[l,r)
{
  if (dp[l][r] != inf)
  {
    return dp[l][r];
  }
  else
  {
    if (l >= r)
    {
      return dp[l][r] = 0;
    }
    else
    {
      return dp[l][r] = max(a[l] - rec(l + 1, r), a[r - 1] - rec(l, r - 1));
    }
  }
}

int main()
{
  cin >> n;
  for (int i = 0; i < n; i++)
  {
    cin >> a[i];
  }
  fill(dp[0], dp[3009], inf);
  cout << rec(0, n) << "\n";
}

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

int a[3];

int main ()
{
	cin >> a[0] >> a[1] >> a[2];
	sort (a + 0, a + 2 + 1);
	int ans = 0;
//	cout << a[0] << endl << a[1] << endl << a[2] << endl;
	ans += a[2] - a[1];
	int k = (a[1] - a[0]) / 2;
	if (a[0] + k * 2 < a[1])
		++k;
//	cout << k << endl;
	ans += k;
	ans += a[0] + k * 2 - a[1];
	cout << ans;
}

Measured memory_bytes: 256
fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());
    let a: i64 = sc.read();
    let sa: i64 = sc.read();
    let b: i64 = sc.read();
    let sb: i64 = sc.read();
    let t: i64 = sc.read();

    let dist = (a - b).abs();
    let ds = sa - sb;
    if ds * t >= dist {
        println!("YES");
    } else {
        println!("NO");
    }
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> Self {
        Self(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: ToString>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.to_string().as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 2160
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
typedef long long ll;
namespace mp = boost::multiprecision;
using Mint = mp::cpp_int;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = int(a); i < int(b); i++)
#define all(v) v.begin(), v.end()
#define uni(v) v.erase(unique(all(v)), v.end())
#define sort_g(v) sort(all(v), greater<int>())
#define dump(x) cerr << #x << ' ' << '=' << ' ' << x << endl

int main() {
    string S, T;
    cin >> S >> T;

    rep(i, T.size()) {
        cout << S.at(i) << T.at(i);
    }

    if(S.size() > T.size()) cout << S.at(S.size() - 1);
    cout << endl;
}

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

template<class T>
int LIS(const vector<T> &a) {
    vector<T> L;
    for (T x : a) {
        auto it = lower_bound(L.begin(), L.end(), x);
        if (it == L.end()) L.push_back(x);
        else *it = x;
    }
    return (int)L.size();
}

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i=0; i<n; ++i) cin >> a[i];
    cout << LIS<int>(a) << endl;
    return 0;
}


Measured memory_bytes: 3716
/**
 * A - Airplane
 * https://atcoder.jp/contests/abc129/tasks/abc129_a
 **/
#include<iostream>
#include<algorithm>

using namespace std;

int p, q, r;

int main() {
    cin >> p >> q >> r;
    int res;
    res = min({p+q, q+r, r+p});
    cout << res << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < (int)(n); i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
using ll = long long;

int main() {
    int N, M; cin >> N >> M;
    vector<int> A(M), B(M);
    REP(i, 0, M) {
        int b; cin >> A[i] >> b;
        REP(j, 0, b) {
            int c; cin >> c; B[i] |= (1 << (c - 1));
        }
    }

    // REP(i, 0, M) {
    //     cout << A[i] << " " << bitset<3>(B[i]) << endl;
    // }

    vector<vector<int>> dp(M + 1, vector<int>(1 << N, 1 << 30));
    dp[0][0] = 0;
    REP(i, 0, M) {
        REP(j, 0, 1 << N) {
            dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
            dp[i + 1][j | B[i]] = min(dp[i + 1][j | B[i]], dp[i][j] + A[i]);
        }
    }

    // REP(i, 0, M + 1) {
    //     REP(j, 0, 1 << N) {
    //         cout << dp[i][j] << " ";
    //     }
    //     cout << endl;
    // } 

    if (dp[M][(1 << N) - 1] < (1 << 30)) cout << dp[M][(1 << N) - 1] << endl;
    else cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 19200
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string>
#include<iostream>
#include<iostream>
#include<cctype>
#include<cstdio>
#include<vector>
#include<stack>
#include<queue>
#include <algorithm>
#include<math.h>
#include<set>
#include<map>
#include <sstream>
#include<iomanip>
#include <ctype.h>
using namespace std;

//#include<bits/stdc++.h>


int main() {
	long long int a, b;
	cin >> a >> b;
	

	for (long long int i = 0; i <=max(b,a) ; i+=a) {
		if (i%a == 0 && i%b) {
			cout << i << endl;
			return 0;
		}
	}
	cout << -1 << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <iomanip>
#include <vector>
#include <cmath>
#include <map>
#include <algorithm>
using namespace std;

int main(){
  int n = 0;
  cin >> n;
  if(n >= 30){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 3132
#define _CRT_SECURE_NO_WARNINGS
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#define int ll
//#define endl "\n"
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
#define all(c) (c).begin(), (c).end()
#define loop(i,a,b) for(ll i=a; i<ll(b); i++)
#define rep(i,b) loop(i,0,b)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
template<class T> ostream & operator<<(ostream & os, vector<T> const &);
template<int n, class...T> typename enable_if<(n>=sizeof...(T))>::type _ot(ostream &, tuple<T...> const &){}
template<int n, class...T> typename enable_if<(n< sizeof...(T))>::type _ot(ostream & os, tuple<T...> const & t){ os << (n==0?"":" ") << get<n>(t); _ot<n+1>(os, t); }
template<class...T> ostream & operator<<(ostream & os, tuple<T...> const & t){ _ot<0>(os, t); return os; }
template<class T, class U> ostream & operator<<(ostream & os, pair<T,U> const & p){ return os << "(" << p.first << ", " << p.second << ") "; }
template<class T> ostream & operator<<(ostream & os, vector<T> const & v){ rep(i,v.size()) os << v[i] << (i+1==(int)v.size()?"":" "); return os; }
template<class T> inline bool chmax(T & x, T const & y){ return x<y ? x=y,true : false; }
template<class T> inline bool chmin(T & x, T const & y){ return x>y ? x=y,true : false; }
#ifdef DEBUG
#define dump(...) (cerr<<#__VA_ARGS__<<" = "<<mt(__VA_ARGS__)<<" ["<<__LINE__<<"]"<<endl)
#else
#define dump(...)
#endif
// ll const mod = 1000000007;
// ll const inf = 1LL<<60;

struct Trie {
    int val;
    map<char,Trie*> ch;
    Trie() : val(0) {}
    ~Trie(){
        for(auto & e : ch) delete e.second;
    }
};

void insert(char * s, Trie * t){
    Trie * cur = t;
    while(1){
        if(*s=='\0'){
            cur->val++;
            break;
        } else {
            Trie * &nxt = cur->ch[*s];
            if(nxt == nullptr) nxt = new Trie();
            cur = nxt;
            s++;
        }
    }
}

bool erase(char * s, Trie * t){
    Trie * cur = t;
    while(1){
        if(*s == '\0'){
            cur->val--;
            return true;
        } else {
            Trie * &nxt = cur->ch[*s];
            if(nxt == nullptr) return false;
            cur = nxt;
            s++;
        }
    }
}

bool find(char * s, Trie * t){
    Trie * cur = t;
    while(1){
        if(*s == '\0'){
            return cur->val > 0;
        } else {
            Trie * &nxt = cur->ch[*s];
            if(nxt == nullptr) return false;
            cur = nxt;
            s++;
        }
    }
}

int main(){
    int n;
    cin >> n;
    Trie * root = new Trie();
    rep(i,n){
        char com[15], str[15];
        cin >> com >> str;
        if(com[0] == 'i'){
            insert(str,root);
        } else {
            puts(find(str,root) ? "yes" : "no");
        }
    }
    delete root;
}

Measured memory_bytes: 48716
#define _USE_MATH_DEFINES
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <clocale>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i, s, n) for(int i = (s), i##_len=(n); i < i##_len; ++i)
#define FORS(i, s, n) for(int i = (s), i##_len=(n); i <= i##_len; ++i)
#define VFOR(i, s, n) for(int i = (s); i < (n); ++i)
#define VFORS(i, s, n) for(int i = (s); i <= (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FORS(i, 0, n)
#define VREP(i, n) VFOR(i, 0, n)
#define VREPS(i, n) VFORS(i, 0, n)
#define RFOR(i, s, n) for(int i = (s), i##_len=(n); i >= i##_len; --i)
#define RFORS(i, s, n) for(int i = (s), i##_len=(n); i > i##_len; --i)
#define RREP(i, n) RFOR(i, n, 0)
#define RREPS(i, n) RFORS(i, n, 0)
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v), greater<decltype(v[0])>())
#define SZ(x) ((int)(x).size())
#define REV(x) reverse(ALL(x))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end())

using ld = long double;
using ll = long long;
using ui = unsigned int;
using ull = unsigned long long;
using Pi_i = pair<int, int>;
using Pll_ll = pair<ll, ll>;
using VB = vector<bool>;
using VC = vector<char>;
using VD = vector<double>;
using VI = vector<int>;
using VLL = vector<ll>;
using VS = vector<string>;
using VSH = vector<short>;
using VULL = vector<ull>;

const int MOD = 1000000007;
const int INF = 1000000000;
const int NIL = -1;
const double EPS = 1E-10;

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


int main(){
    int Q, H, S, D; ll N; cin >> Q >> H >> S >> D >> N;
    cout << (N/2) * min({8*Q, 4*H, 2*S, D})
            + (N%2) * min({4*Q, 2*H, S}) << endl;
    return 0;
}


Measured memory_bytes: 256
from sys import stdin
from sys import setrecursionlimit
from collections import Counter, deque, defaultdict
from math import floor, ceil
from bisect import bisect_left
from itertools import combinations
setrecursionlimit(100000)

INF = int(1e10)
MOD = int(1e9 + 7)

def main():
    from builtins import int, map
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    A.sort()
    print(sum(A[:K]))

if __name__ == '__main__':
    main()

Measured memory_bytes: 67236
#include <iostream>
#include<cmath>
#include<vector>
#include<tuple>
#include <ctime>
#include<algorithm>
#include <initializer_list>
#include <cstring> 
 
#define tii tuple<int,int>
#define vi vector<int>
#define vii vector<vi>
#define ll long long int
#define vl vector<ll>
#define vll vector<vl>
 
#define mymod 1000000007
#define mx 99999999
#define mn -99999999
#define sz 101
 
using namespace std;
 
int main() {
    clock_t tstart = clock();
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    // Start
    int n;
    cin>>n;
    vl v(n);
    for(auto &x:v) cin>>x;
    int ans = 0;
    for(int i=0;i<n;i++) {
        for(int j=i+1;j<n;j++){
            for(int k=j+1;k<n;k++){
                ll mxv = max({v[i],v[j],v[k]});
                ll mnv = min({v[i],v[j],v[k]});
                ll sum = v[i]+v[j]+v[k];
                int mid = sum - mxv - mnv;
                if(mxv != mid && mnv!=mid && 2*mxv < sum) {
                    // cout<<i+1<<"  "<<j+1<<" "<<k+1<<"\n";
                    ans++;
                }
            }
        }
    }
    cout<<ans;
    // cout<<"\n\nTotal Time Taken : "<<(double)(-tstart + clock())/CLOCKS_PER_SEC<<"sec\n\n";
    return 0;
}
 

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

using namespace std;

const int N = 2010;
int mat[N][N];
int sum[N][N];
int sum_h[N][N];
int sum_v[N][N];

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

	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= m; ++j) {
			char c;
			cin >> c;
			mat[i][j] = c - '0';
			sum[i][j] = mat[i][j] + sum[i][j-1] + sum[i-1][j] - sum[i-1][j-1];
			if(mat[i][j] == 1 && mat[i][j-1] == 1) {
				sum_h[i][j] = 1 + sum_h[i][j-1] + sum_h[i-1][j] - sum_h[i-1][j-1];
			} else {
				sum_h[i][j] = 0 + sum_h[i][j-1] + sum_h[i-1][j] - sum_h[i-1][j-1];
			}
			if(mat[i][j] == 1 && mat[i-1][j] == 1) {
				sum_v[i][j] = 1 + sum_v[i][j-1] + sum_v[i-1][j] - sum_v[i-1][j-1];
			} else {
				sum_v[i][j] = 0 + sum_v[i][j-1] + sum_v[i-1][j] - sum_v[i-1][j-1];
			}
		}
	}

	for (int i = 0; i < q; ++i) {
		int x1, y1, x2, y2;
		cin >> x1 >> y1 >> x2 >> y2;
		int fi = sum[x2][y2] - sum[x1-1][y2] - sum[x2][y1-1] + sum[x1-1][y1-1];
		int se = sum_h[x2][y2] - sum_h[x1-1][y2] - sum_h[x2][y1] + sum_h[x1-1][y1];
		int th = sum_v[x2][y2] - sum_v[x1][y2] - sum_v[x2][y1-1] + sum_v[x1][y1-1];

		//cout << fi << " " << se << " " << th << endl;
		cout << fi - se - th << endl;
	}
}

Measured memory_bytes: 64896