akhauriyash/Code-Regression huggingface dataset:
N = int(input())
A = list(map(int, input().split()))
A = sorted(A, reverse=True)

def solve(N, A):
  ans = A[0]
  exist_zero = False
  if A[-1] == 0:
    exist_zero = True

  if exist_zero:
    print(0)
    return

  for i in range(1, N):
    ans *= A[i]
    if ans > 10**18 and not exist_zero:
      print(-1)
      return

  print(ans)

solve(N, A)


Measured memory_bytes: 84528
#include <bits/stdc++.h>
#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 FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define ifaxb(a, x, b) if (a < x && x < b)  // 比較は昇順
#define vi vector<int>
#define vii vector<vi>
#define vs vector<string>
#define vss vector<vs>
#define all(x) x.begin(), x.end()
#define ff first
#define ss second
#define pq priority_queue
#define ipair pair<int, int>
#define spair pair<string, string>
#define lpair pair<LL, LL>
#define MP make_pair
#define MM multimap
#define PB push_back
#define INF 2147483647
#define _INF -2147483647
#define pi 3.1415926536
#define MAXN 100004
using namespace std;
typedef long long ll;

int main() {
    string S;
    cin >> S;
    // 最後の文字が条件を満たしてるとmaxにlenが代入されないので、適当な文字を最後に追加しておく。
    S = S + 'E';
    int max = 0;  // 最大値
    int len = 0;  // 計測中の長さ

    rep(i, S.size()) {
        if (S[i] == 'A' || S[i] == 'C' || S[i] == 'G' || S[i] == 'T') {
            len++;
        } else {
            if (max < len) {
                max = len;
            }
            len = 0;
        }
    }

    cout << max << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
const double EPS = 1e-10;
using namespace std;
#define COUT(v) cout<<(v)<<endl
#define COUTDOUBLE(v) cout << std::setprecision(10)<<(v)<<endl;
#define CIN(n)  int(n);cin >> (n)
#define LCIN(n) LL(n);cin >> (n)
#define SCIN(n) string(n);cin >> (n)
#define YES(n) cout<<((n)? "YES" : "NO")<<endl
#define Yes(n) cout<<((n)? "Yes" : "No")<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) <<endl

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)

#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(obj) (obj).begin(),(obj).end()

#define P pair<LL,LL>
#define I vector<int>
#define pb(v) push_back(v)
#define V vector
#define rt return
#define rmsame(a) sort(ALL(a)),a.erase(unique(ALL(a)), a.end())
#define ENDL cout<<endl
#define f first
#define s second

typedef string::const_iterator State;
class PalseError {};
class Edge{
public:
    int from,to,value;
    Edge(LL a,LL b,LL c){
        from = a;
        to = b;
        value = c;
    }
    Edge(LL a,LL b){
        from = a;
        to = b;
    }
};
int main(){
    SCIN(str);
    int countA = count(ALL(str),'a');
    int countB = count(ALL(str),'b');
    int countC = count(ALL(str),'c');
    YES(max({countA,countB,countC}) - min({countA,countB,countC}) <= 1);
    return 0;
}


Measured memory_bytes: 512
n, q = map(int, input().split())
s = input().rstrip()

ac = [0] * n

count = 0
for i in range(n-1):
    if s[i] == 'A' and s[i+1] == 'C':
        count += 1
    ac[i] = count

for i in range(q):
    l, r = map(int, input().split())

    if l == 1:
        print(ac[r-2])
    else:
        print(ac[r-2] - ac[l-2])


Measured memory_bytes: 52056
class UnionFind:
    __slots__ = ["_data_size", "_roots"]

    def __init__(self, N):
        self._data_size = N
        self._roots = [-1] * N

    def __getitem__(self, x: int) -> int:
        while self._roots[x] >= 0:
            x = self._roots[x]
        return x

    def unite(self, x, y):
        x = self[x]
        y = self[y]
        if x == y:
            return
        elif self._roots[y] < self._roots[x]:
            x, y = y, x
        self._roots[x] += self._roots[y]
        self._roots[y] = x

    def is_connected(self, x, y):
        return self[x] == self[y]


import sys

read = sys.stdin.buffer.read

N, Q, *TUV = map(int, read().split())
tree = UnionFind(N)
res = []
for t, u, v in zip(*[iter(TUV)] * 3):
    if t:
        res.append(int(tree.is_connected(u, v)))
    else:
        tree.unite(u, v)
print("\n".join(map(str, res)))


Measured memory_bytes: 144916
N = int(input())
nums1 = list(map(int, input().split()))
nums2 = list(map(int, input().split()))
r1 = 1
r2 = 1
def getOrder(nums):
    r = 1
    base = 1
    for i in range(N):
        base *= (i + 1)
    for idx in range(N):
        base //= (N - idx)
        s = {n: i for i, n in enumerate(sorted(nums[idx:]))}
        orders = [s[i] for i in nums[idx:]]
        r += orders[0] * base
    return r
a = (getOrder(nums1))
b = (getOrder(nums2))
print(abs(a - b))


Measured memory_bytes: 3064
n = int(input())
a, b = map(int, input().split())
p = list(map(int, input().split()))
f, s, t = 0, 0, 0
for i in range(n):
    if p[i] <= a:
        f += 1
    elif a+1 <= p[i] <= b:
        s += 1
    else:
        t += 1
print(min(f, s, t))

Measured memory_bytes: 9128
import sys, os, math, bisect, itertools, collections, heapq, queue, copy, array

# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
# from decimal import Decimal
# from collections import defaultdict, deque

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def counting_sort(A, B, C, K, N):
    # C[i]にiの出現数を記録する
    for j in range(N):
        C[A[j]] += 1

    # C[i]にi以下の数の出現数を記録する
    for i in range(1, K + 1):
        C[i] = C[i] + C[i - 1]

    for j in reversed(range(N)):
        B[C[A[j]] - 1] = A[j]
        C[A[j]] -= 1


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    A = il()
    K = max(A)
    B = [0] * N
    C = [0] * (K + 1)

    counting_sort(A, B, C, K, N)
    print(*B)


if __name__ == '__main__':
    main()



Measured memory_bytes: 192412
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.NoSuchElementException;

public class Main {
	
	static long[] fac = new long[200001];
	static final long mod = 1000000007;
	static final BigInteger MOD = BigInteger.valueOf(1000000007);
	
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		
		int h = sc.nextInt();
		int w = sc.nextInt();
		
		int a = sc.nextInt();
		int b = sc.nextInt();
		
		calc();
		
		long ans = 0;
		for (int i = b; i < w; i++) {
			ans = (ans + modCombi(i + (h - a - 1), i) * modCombi((w - i - 1) + (a - 1), w - i - 1) % mod) % mod;
		}
		
		out.println(ans);
		out.flush();
	}
	
	static void calc() {
		fac[0] = 1;
		for (int i = 1; i < fac.length; i++) {
			fac[i] = (fac[i - 1] * i) % mod;
		}
	}
	
	static long modCombi(int n, int r) {
		
		long a = BigInteger.valueOf(fac[r]).modInverse(MOD).longValue();
		long b = BigInteger.valueOf(fac[n - r]).modInverse(MOD).longValue();
		
		return fac[n] * a % mod * b % mod;
	}
	
}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;
	
	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}
	
	private byte readByte() {
		if (hasNextByte()) {
			return buffer[ptr++];
		} else {
			return -1;
		}
	}
	
	private boolean isPrintableChar(int c) {
		return '!' <= c && c <= '~';
	}
	
	private void skipUnprintable() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
			ptr++;
		}
	}
	
	public boolean hasNext() {
		skipUnprintable();
		return hasNextByte();
	}
	
	public int nextInt() {
		if (!hasNext()) {
			throw new NoSuchElementException();
		}
		int n = 0;
		boolean minus = false;
		byte b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}
	
}


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

using namespace std;

int main(){
  string N;
  cin >> N;
  if(N[0] == N[1] && N[1] != N[2] && N[2] == N[3])cout << "Yes" << endl;
  else if(N[0] == N[2] && N[1] == N[3] && N[0] != N[1])cout << "Yes" << endl;
  else if(N[0] == N[3] && N[1] == N[2] && N[0] != N[1])cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BMultipleOf9 solver = new BMultipleOf9();
        solver.solve(1, in, out);
        out.close();
    }

    static class BMultipleOf9 {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int[] s = in.readDigits();
            int sum = 0;
            for (int x : s) {
                sum += x;
                while (sum >= 9)
                    sum -= 9;
            }

            out.println(sum == 0 ? "Yes" : "No");
        }

    }

    static class InputReader {
        public final BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int[] readDigits() {
            char[] chars = next().toCharArray();
            int[] x = new int[chars.length];
            for (int i = 0; i < x.length; i++) {
                x[i] = chars[i] - '0';
            }
            return x;
        }

    }
}



Measured memory_bytes: 30764
s=input()
count=0
for i in range(0,len(s)-1,2):
  if s[i]=='0':
    count+=1
  if s[i+1]=='1':
    count+=1
if len(s)%2==1:
  if s[len(s)-1]=='0':
    count+=1
print(min(count,len(s)-count))


Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<P,int> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

ll Pow(ll n,ll p){
	ll r=1;
	for(;p>0;p>>=1){
		if(p&1) r=(r*n)%mod;
		n=(n*n)%mod;
	}
	return r;
}

const int M=2000005;
ll F[M];

void Init(){
	F[0]=1;
	for(int i=1;i<M;i++) F[i]=F[i-1]*i%mod;
}

ll Div(ll n,ll m){
	return n*Pow(m,mod-2)%mod;
}

ll nCk(ll n,ll k){
	return Div(F[n],F[n-k]*F[k]%mod);
}

ll nPk(ll n,ll k){
	return nCk(n,k)*F[k]%mod;
}

int n,t=0;

int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		int x;
		cin>>x;
		if(i%2==0&&x%2==1) t++;
	}
	cout<<t<<endl;
}

Measured memory_bytes: 3588
#include <stdio.h>
#include <math.h>

int prime[200000];

void Eratos(void);

int main(void){
	int n;
	int p[10000];
	int num = 0;
	int ans;

	Eratos();

	for(int i=0; num < 10000; i++){
		if(prime[i] == 1){
			p[num] = i;
			num++;
		}
	}

	while(1){
		ans = 0;
		scanf("%d", &n);
		if(n == 0) break;

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

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

	return 0;
}

void Eratos(void){
	for(int i=0; i<200000; i++){
		prime[i] = 1;
	}
	prime[0] = prime[1] = 0;

	for(int i=2; i<sqrt(200000); i++){
		for(int j=2; i*j <= 200000; j++){
			prime[i*j] = 0;
		}
	}
}

Measured memory_bytes: 0
n=int(input())
A=[i**5 for i in range(10000)]
B=[i**5 for i in range(10000)]

for i in A:
    for j in B:
        if i-j==n:
            print(int(i**(1/5)),int(j**(1/5)))
            exit()
        if i+j==n:
            print(int(i**(1/5)),int(-j**(1/5)))
            exit()

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

#define rep(i,n) for(ll i = 0; i < n; i++)
#define per(i,n) for(ll i = n-1; i >= 0; i--)
#define REP(i,n) for(ll i = 1; i < n; i++)
#define PER(i,n) for(ll i = n; i >= 1; i--)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
#define fi first
#define se second
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
using vs = vector<string>;
using vb = vector<bool>;
using vc = vector<char>;
using vcc = vector<vc>;
using vP = vector<P>;
using vPP = vector<vP>;
using vPl = vector<Pl>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/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; }



int main(){
  int n, k;
  cin >> n >> k;
  vi p(n);
  rep(i,n) cin >> p[i];
  sort(all(p));
  ll ans = 0;
  rep(i,k) ans += p[i];
  cout << ans << endl;
}

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

const int mod = 1000000007;
struct mint{
	ll x;
	mint(ll x = 0):x((x%mod+mod)%mod){}
	mint operator-() const{return mint(-x);}
	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;
	}
	bool operator==(const mint a){
		return x == a.x;
	}
};

struct Combination{
	vector<mint> fact, ifact;
	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;
	}
	mint operator()(int n, int k){
		if(k < 0 || k > n) return 0;
		return fact[n]*ifact[k]*ifact[n-k];
	}
};

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, k;
	cin >> n >> k;
	chmin(k, n-1);
	Combination comb(n+1);
	mint ans = 0;
	for(int m = 0; m < k+1; ++m){
		ans += comb(n, m) * comb((n-m-1)+m, m);
	}
	cout << ans.x << endl;
	return 0;
}

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

int main(void){
    int x,a,b,c;
    cin>>a>>b>>c>>x;
    int ans=0;
    for(int i=0;i<=a;i++){
        for(int j=0;j<=b;j++){
            for(int k=0;k<=c;k++){
                if(i*500+j*100+k*50 == x)
                    ans++;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
/*
  Contest 105
  A - AtCoder Crackers
  Rakesh Kumar --> 27/09/2020
 */

#include <bits/stdc++.h>

int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(0); std::cout.tie(0);

    int n = 0, k = 0;
    std::cin >> n >> k;
    std::cout << (n % k ? 1 : 0) << std::endl;

    return 0;
}


Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
int main() {
	char str;
	int n[3]={},ans=0;
	while(cin>>str){
		if(str=='J'&&n[1]==n[2]&&n[2]==0)n[0]++;
		else if(str=='O'&&n[1]<n[0]&&n[2]==0)n[1]++;
		else if(str=='I'&&n[2]<n[1]&&n[0]!=0){if((++n[2])==n[1])ans=max(ans,n[1]);}
		else{
			for(int i=0;i<3;i++)n[i]=0;
			if(str=='J')n[0]=1;
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 1144
#include<iostream>
#include<set>
#include<vector>
#include<string>
#include<iterator>
#include<iomanip>
#include<cmath>
#include<map>
#include<string.h>
#include<algorithm>

using namespace std;
void ll(){
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(0);
}

int main(){

	ll();


	int x, a, b,n=0;
	cin >> x >> a >> b;
	n = x - a;
	while (n >= b)
	{
		n -= b;
	}
	cout << n << endl;

}

Measured memory_bytes: 3600
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <queue>
#include <math.h>
#include <assert.h>
#include <set>
#include <map>
#include <bitset>
#include <ctime>
#include <time.h>
#include <algorithm>
#include <cstdio>
#include <fstream>
#include <stack>
#include <ctype.h>
#include <numeric>
#include <sstream>
#include <unistd.h>
#include <unordered_map>
#include <unordered_set>
#include <limits>
#include <random>
#include <chrono>
#include <iomanip>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
using ll = long long;
#define endl '\n'
#define debug(name) DEBUG(#name, (name))
template<typename T>
void DEBUG(string label, T value) {
    cerr << "[" << label << " = " << value << "]\n";
}

void solve(){
    int h, w, m;
    cin >> h >> w >> m;
    vector<int> row(h + 1);
    vector<int> col(w + 1);
    map<pair<int,int>,bool> grid;
    for(int i = 0; i < m; ++i){
        int x, y;
        cin >> x >> y;
        --x; --y;
        grid[{x,y}] = true;
        row[x]++;
        col[y]++;
    }
    pair<int,int> best_row = {-1, -1};
    pair<int,int> best_col = {-1, -1};
    for(int i = 0; i < h; ++i){
        if(row[i] > best_row.first){
            best_row.first = row[i];
            best_row.second = i;
        }
    }
    for(int i = 0; i < w; ++i){
        if(best_col.first < col[i]){
            best_col.first = col[i];
            best_col.second = i;
        }
    }
    int ans = 0;
    for(int i = 0; i < h; ++i){
        ans = max(ans, row[i] + best_col.first - (grid[{i, best_col.second}] == true ? 1 : 0));
    }
    for(int i = 0; i < w; ++i){
        ans = max(ans, col[i] + best_row.first -  (grid[{best_row.second, i}] == true ? 1 : 0));
    }
    cout << ans << endl;

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

    solve();
}


Measured memory_bytes: 61816
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int maxn=1e5+10;
int n,q;
int a[maxn];
priority_queue<P>que;
int main()
{
    int n,m;
    cin>>n>>m;
    for(int i=0;i<n;i++)
        cin>>a[i];
        int x,y;

        sort(a,a+n);
 for(int i=0;i<m;i++)
 {
     cin>>x>>y;
     que.push({y,x});
 }
  for(int i=0;i<n;i++)
  {
      int x=a[i];
      if(!que.empty()&&que.top().first>x)
      {
          a[i]=que.top().first;
          if(que.top().second-1==0)
            que.pop();
          else
          {
                int v=que.top().second-1;
                int w=que.top().first;
                que.pop();
                que.push({w,v});
          }
      }
      else
        break;
  }
  ll ans=0;
  for(int i=0;i<n;i++)
    ans+=a[i];
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 1784
def main():
	N, X, M = [int(a) for a in input().split(" ")]
	used_r = [0] * M
	r = [-1, X]
	used_r[X] = 1
	loop_start_elm = -1
	loop_start_n_2 = -1
	for i in range(M):
		A = r[-1]
		B = (A * A) % M
		if used_r[B] == 0:
			r.append(B)
			used_r[B] = 1
		else:
			loop_start_elm = B
			loop_start_n_2 = i + 2
			break
	loop_start_n = r.index(B)

	s1 = sum(r[:loop_start_n]) + 1
	s2 = sum(r[loop_start_n:loop_start_n_2])
	loop_len = loop_start_n_2 - loop_start_n
	loop_n = int((N - loop_start_n + 1) / loop_len)
	rest_n = (N - loop_start_n + 1) % loop_len
	s3 = sum(r[loop_start_n:(loop_start_n + rest_n)])
	print(s1 + s2 * loop_n + s3)

main()



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

int main() {
	string s;
	cin >> s;
	int q;
	cin >> q;
	bool rev = false;
	string front = "";
	string back = "";
	for (int i = 0; i < q; i++) {
		int x;
		cin >> x;
		if (x == 1) {
			if (rev == true) rev = false;
			else rev = true;
		}
		else {
			int y;
			cin >> y;
			string s2;
			cin >> s2;
			if (y == 1) {
				if (rev == false) front = front + s2;
				else back = back + s2;
			}
			else {
				if (rev == false) back = back + s2;
				else front = front + s2;
			}
		}
	}
	if (!rev) {
		reverse(front.begin(), front.end());
		cout << front + s + back << endl;
	}
	else {
		reverse(back.begin(), back.end());
		reverse(s.begin(), s.end());
		cout << back + s + front << endl;
	}
}

Measured memory_bytes: 1596
grade = []

while 1:
    grade.append(list(map(int, input().split())))
    if grade[-1][0] == -1 and grade[-1][1] == -1 and grade[-1][2]: break

for i in range(len(grade) - 1):
    if grade[i][0] == -1 or grade[i][1] == -1:
        print('F')
    elif grade[i][0] + grade[i][1] >= 80:
        print('A')
    elif grade[i][0] + grade[i][1] >= 65:
        print('B')
    elif grade[i][0] + grade[i][1] >= 50:
        print('C')
    elif grade[i][0] + grade[i][1] >= 30 and grade[i][2] >= 50:
        print('C')
    elif grade[i][0] + grade[i][1] >= 30:
        print('D')
    else:
        print('F')



Measured memory_bytes: 5612
import java.util.Scanner;


public class Main {

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

		while (sc.hasNext()) {
			String a = sc.nextLine().replace(" ", "");
			String b = sc.nextLine().replace(" ", "");
			int H = 0, B = 0;
			for (int i = 0 ; i < b.length() ; i++) {
				if (a.contains(""+b.charAt(i))) {
					if (a.indexOf(b.charAt(i)) == i) H++;
					else B++;
				}
			}
			System.out.println(H+" "+B);
		}


	}
}

Measured memory_bytes: 17336
n = int(input())

def primes(n):
	p_list = [2]
	for i in range(2, n+1):
		for p in p_list:
			if i%p == 0:
				break
		else:
			p_list.append(i)

	return p_list

p_list = primes(n)
x = [1]*len(p_list)

for j in range(1, 1+n):
	temp = j*1
	index = 0

	while temp > 1:
		if temp%p_list[index] == 0:
			temp = temp/p_list[index]
			x[index] += 1
		else:
			index += 1

count = 1
for n in x:
	count = (count*n)%(10**9+7)

print(int(count))


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;

const int maxN = 150010;
const int MAXM = 310;
const int MAXK = 17;
const int MOD = 1000000007;
const ll INF = 10000000000000000LL;
const ll inf = 5000000000000LL;

int n,m,q;


int main()
{
    scanf("%d%d%d",&n,&m,&q);
    int cnt = m/n;
    cnt = min(cnt,q);
    cout<<cnt<<endl;
    return 0;
}

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

using namespace std;

#define MAXN 100005
#define fi first
#define se second

typedef pair<int,int> ii;
typedef vector<ii> vii;

vii adjList[MAXN];

int dist[MAXN];
priority_queue< ii,vector<ii>,greater<ii> > pq;

int main(){

    ios_base::sync_with_stdio(0);

    /*
     *  N = number of vertices
     *  E = number of edges
     *  S = source
     */

    int N, E, S;
    cin >> N >> E >> S;

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

        adjList[u].push_back(ii(w,v));
      //adjList[v].push_back(ii(w,u));      // undirected graph
    }

    memset(dist,-1,sizeof(dist));

    dist[S] = 0; pq.push(ii(0,S));
    while (!pq.empty()){
        ii front = pq.top(); pq.pop();
        int u = front.se;
        int d = front.fi;

        if (d > dist[u]) continue;

        for (int i=0; i<adjList[u].size(); i++){
            int vv = adjList[u][i].se;
            int vd = adjList[u][i].fi;

            if (dist[vv] == -1 || dist[vv] > dist[u] + vd){
                dist[vv] = dist[u] + vd; pq.push(ii(dist[vv],vv));
            }
        }
    }

    // Print all vertices distance from source
    for (int i=0; i<N; i++){
        if (dist[i] == -1) cout << "INF" << endl;   // no route exist
        else cout << dist[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 11312
#include<stdio.h>

int main(void)
{
   int a,b;
   scanf("%d",&a);
   scanf("%d",&b);
   if(a==b)
      printf("a == b\n");
   else
    if(a<b)
       printf("a < b\n");
    else
       printf("a > b\n");
 
    return 0;
}

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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = ((int)(n)-1); i >= 0; i--)
#define all(x) (x).begin(),(x).end()

using namespace std;
using ll = long long;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> P;
 
const int INF = 1e9;
//const ll INF = 1e18;
const double EPS = 1e-10;
const int MOD = 1e9+7;
const double PI = acos(-1.0);

int main(){
	int N,C;
	cin >> N >> C;
	int d[C][C],c[N][N];
	rep(i,C) rep(j,C) cin >> d[i][j];
	rep(i,N) rep(j,N){
		cin >> c[i][j];
		c[i][j]--;
	}
	vector<P> a[3];
	for(int k = 0; k < C; k++){
		int sum[3]; fill(sum,sum+3,0);
		for(int i = 0; i < N; i++){
			for(int j = 0; j < N; j++){
				if((i+j)%3 == 0) sum[0] += d[c[i][j]][k];
				if((i+j)%3 == 1) sum[1] += d[c[i][j]][k];
				if((i+j)%3 == 2) sum[2] += d[c[i][j]][k];
			}
		}
		a[0].emplace_back(sum[0],k);
		a[1].emplace_back(sum[1],k);
		a[2].emplace_back(sum[2],k);
	}
	for(int i = 0; i < 3; i++) sort(all(a[i]));
	int ans = INF;
	for(int i = 0; i < 3; i++){
		for(int j = 0; j < 3; j++){
			for(int k = 0; k < 3; k++){
				if(a[0][i].second == a[1][j].second) continue;
				if(a[1][j].second == a[2][k].second) continue;
				if(a[2][k].second == a[0][i].second) continue;
				ans = min(ans,a[0][i].first+a[1][j].first+a[2][k].first);
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1280
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <map>
#include <cmath>
#include <climits>

constexpr int SINT_MAX = std::numeric_limits<int>::max();
constexpr int SINT_MIN = std::numeric_limits<int>::min();

using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;

template<class T>
T choose(bool b, T t, T f)
{
    if (b) return t;
    else return f;    
}

const char *YesNo(bool b)
{
    return choose(b, "Yes", "No");
}

const char *YESNO(bool b)
{
    return choose(b, "YES", "NO");
}

template<template<class...> class ContT, class ValueT, size_t Dim>
struct vec_type
{
    using type = ContT<typename vec_type<ContT, ValueT, Dim-1>::type>;
};

template<template<class...> class ContT, class ValueT>
struct vec_type<ContT, ValueT, 0>
{
    using type = ValueT;
};

template<class ValueT, size_t Dim = 1>
using vec_t = typename vec_type<std::vector, ValueT, Dim>::type;


template<class ValueT, size_t Dim, class = typename std::enable_if<Dim == 0>::type>
auto make_vec(ValueT value = ValueT()) -> ValueT
{
    return value;
}

template<class ValueT, size_t Dim, class... Rest>
auto make_vec(size_t size0, Rest... rest)
{
    auto vec = make_vec<ValueT, Dim-1>(rest...);
    return std::vector(size0, vec);
}

int diffabs(int l, int r)
{
    if (l < r) return r-l;
    else return l-r;    
}


///////////////////////////////////////////////////

int main()
{
    int N;
    map<int, int, less<int>> A;
    cin >> N;
    for (int i = 0; i < N; i++)
    {
        int a;
        cin >> a;
        ++A[a];
    }

    constexpr int MAX_A = 1000000;
    vi kusi(MAX_A+1, 0);
    for (auto [a, i] : A)
        kusi[a] = i;

    int ans = 0;
    if (kusi[1] > 1)
    {
        ans = 0;
    }
    else if (kusi[1] == 1)
    {
        ans = 1;
    }
    else
    {
        for (auto [a, i] : A)
        {
            if (i != 1) continue;

            int sqr_a = (int)sqrt(a);
            bool ok = true;
            for (int j = 2; ok && j <= sqr_a; ++j)
            {
                if (kusi[j] && a % j == 0) ok = false;
                if (kusi[a/j] && a % (a/j) == 0) ok = false;
            }

            if (ok) ++ans;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 16532
#include <bits/stdc++.h>
#define rep(i, n) for(int i= 0; i < (n); i++)
using ll= long long int;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll mod= 1e9 + 7;



int main(){
  int n,k;
  cin >>n >>k;
  int a[n];
  rep(i,n)cin >>a[i];
  sort(a,a+n);
  int ans=0;
  rep(i,k){ans+=a[i];}
  cout << ans << endl;
}

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

int main(){
  int N, M;
  cin >> N >> M;
  
  using pii = pair<int,int>;
  vector<pii> path(M);
  
  for(int i=0;i<M;i++){
    int a,b;
    cin >> a >> b;
    path.at(i)=make_pair(a,b);
  }
  
 
  vector<int> Perm(N);
  for(int i=0;i<N;i++) Perm.at(i)=i+1;
  sort(Perm.begin(),Perm.end());
  int count = 0;
  do{
    if(Perm.at(0)!=1) break;
    
    for(int i=0;i<N-1;i++){
      bool flag = false;
      pii tmp1=make_pair(Perm.at(i),Perm.at(i+1));
      pii tmp2=make_pair(Perm.at(i+1),Perm.at(i));
      for(int j=0;j<M;j++){
        if(!flag){
          if(path.at(j)==tmp1||path.at(j)==tmp2) flag = true;
        }else{break;}
      }
      if(!flag)break;
      if(i==N-2) count++; 
    }
  }while(next_permutation(Perm.begin(),Perm.end()));
  
  cout << count << endl;
  
}

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

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    
    cout << c <<" " <<  a << " " <<  b;
    
}

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

template <typename T> T load() { T r; cin >> r; return r; }
template <typename T> vector<T> loadMany(int n) { vector<T> rs(n); generate(rs.begin(), rs.end(), &load<T>); return rs; }

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	auto n = load<int>();
	auto dish = loadMany<int>(n);
	for (auto& d : dish)
		--d;
	auto base = loadMany<int>(n);
	auto bonus = loadMany<int>(n-1);
	auto score = 0;
	for (auto i=0; i<n; ++i) {
		score += base[dish[i]];
		if (i+1 < n and dish[i+1] - dish[i] == 1)
			score += bonus[dish[i]];
	}
	cout << score << '\n';
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<climits>

#include<stdio.h>

int main(){
  int a[3];
  std::cin.clear();
  std::cin >> a[0] >> a[1] >> a[2];
  //最大値を見つける
  int max=INT_MIN;
  int maxindex;
  for(int i=0;i<3;i++){
    if(max<=a[i]){
      max=a[i];
      maxindex=i;
    }
  }
  
  std::vector<int> maxnum;
  std::vector<int> other; 
  for(int i=0;i<3;i++){
    if(a[maxindex]==a[i]){
      maxnum.push_back(i);
    }else{
      other.push_back(i);
    }
  }
  
  if(maxnum.size()==3){    
    std::cout << 0 << std::endl;
  }else if(maxnum.size()==2){
    if((a[maxnum[0]]-a[other[0]])%2 == 0){
      std::cout << (a[maxnum[0]]-a[other[0]])/2 << std::endl;
      return 0;
    }else{
      std::cout << ((a[maxnum[0]]-a[other[0]])/2)+2 << std::endl;
    }
  }else{
    int result=0;
    while((a[maxnum[0]]-a[other[0]])>1){
      result++;
      a[other[0]]+=2;
    }  
    while((a[maxnum[0]]-a[other[1]])>1){
      result++;
      a[other[1]]+=2;
    }

    //最大値を見つける
    maxnum.clear();
    other.clear();
    max=INT_MIN;
    for(int i=0;i<3;i++){
      if(max<=a[i]){
	max=a[i];
	maxindex = i;
      }
    }
    for(int i=0;i<3;i++){
      if(a[maxindex]==a[i]){
	maxnum.push_back(i);
      }else{
	other.push_back(i);
      }
    }

    if(maxnum.size()==3){
      std::cout << result << std::endl;
    }else if(maxnum.size()==2){
      std::cout << result+2 << std::endl;
    }else{
      std::cout << result+1 << std::endl;
    }
  }
  return 0;
  
}
      
    
  


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<vector>
#include<map>
using namespace std;
int n;
void dfs(int x,vector<int> *w,int *ans,int sign)
{
	ans[x]=sign;
	for(int i:w[x])
		if(ans[i]==-1)dfs(i,w,ans,sign);
}
vector<int> u[200011],v[200011];
int ansx[200011],ansy[200011];
int main()
{
	int p,q;
	scanf("%d%d%d",&n,&p,&q);
	while(p--)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		u[x].push_back(y);
		u[y].push_back(x);
	}
	while(q--)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		v[x].push_back(y);
		v[y].push_back(x);
	}
	memset(ansx,-1,sizeof ansx);
	memset(ansy,-1,sizeof ansy);
	for(int i=1;i<=n;i++)
		if(ansx[i]==-1)dfs(i,u,ansx,i);
	for(int i=1;i<=n;i++)
		if(ansy[i]==-1)dfs(i,v,ansy,i);
	map<pair<int,int>,int> m;
	for(int i=1;i<=n;i++)m[make_pair(ansx[i],ansy[i])]++;
	for(int i=1;i<=n;i++)printf("%d ",m[make_pair(ansx[i],ansy[i])]);
	putchar('\n');
	return 0;
}

Measured memory_bytes: 26840
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = (ll)(1e9 + 7);
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(int)(n); (i)++)
#ifdef LOCAL
#define debug(x) cerr << #x << ": " << x << endl
#else
#define debug(x)
#endif
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };

int N, M;
priority_queue<ll> pq;

signed main() {
	cin >> N >> M;
	rep(i, N) {
		ll A;
		cin >> A;
		pq.push(A);
	}

	rep(i, M) {
		ll tmp = pq.top();
		pq.pop();
		pq.push(tmp / 2);
	}

	ll ans = 0;
	rep(i, N) {
		ans += pq.top();
		pq.pop();
	}
	cout << ans << endl;
}

Measured memory_bytes: 1400
#include<iostream>
#include<cstring>
#include<string>
using namespace std; 

char s[20];
long long ans, n;
bool pls[20];
long long calc() {
    
    long long t = 0, sum = 0;
    for (int i = 0; i < n - 1; ++i) {
        t = t * 10 + s[i];
        if (pls[i]) {
            sum += t;
            t = 0;
        }
    }
    t = t * 10 + s[n - 1];
    return t + sum;
}
void dfs(int k) {
    if (k == n - 1) {
        ans += calc();
        return;
    }
    pls[k] = false;
    dfs(k + 1);
    pls[k] = true;
    dfs(k + 1);
}
int main() {
    cin >> s;
    n = strlen(s);
    for (int i = 0; i < n; ++i) {
        s[i] -= '0';
    }
    dfs(0);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<map>
#include<set>
#include<cmath>
#include<stack>
#include<queue>
#include<deque>
#include<ctime>
#include<vector>
#include<bitset>
#include<string>
#include<cstdio>
#include<numeric>
#include<utility>
#include<sstream>
#include<cstdlib>
#include<iomanip>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<functional>
#include<unordered_map>
#define _USE_MATH_DEFINES
#define inf 999999999999999999
#define rep(i,n,m) for(lli i=(lli)(n);i<(lli)(m);++i)
#define reep(i,n,m) for(int i=(int)(n);i<=(int)(m);++i)
#define per(i,m,n) for(lli i=(int)(m)-1;i>=(int)(n);--i)
#define st(n) sort(n.begin(), n.end())
#define rev(n) reverse(n.begin(),n.end())
#define ou(S) cout << S << endl
#define pb(n) push_back(n)
#define ue(N) N.erase(unique(N.begin(),N.end()),N.end());
#define nou(S) cout << S
#define hou(S) cout << setprecision(30) << S << endl
#define vec(K,L,N,S) vector<L> K(N,S)
#define dv(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define tv(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define pint pair<lli,lli>
#define paf(L,R) pair<L,R>
#define maxx 5100000
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define endl "\n"
typedef long long int lli;
typedef unsigned long long int uli;
const uli mod = 1e9 + 7;
using namespace std;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
  
  int n,x,mi=10000000;
  cin>>n>>x;
  for(int i=0;i<n;++i){
    int a;
    cin>>a;
    x-=a;
    if(mi>a)
      mi=a;
  }
  cout<<n+x/mi<<endl;
}

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

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    int n;cin>>n;
    int arr[n];
    int x[n]={0};
    for (int i=0;i<n;i++){
        cin>>arr[i];
        x[arr[i]]++;
    }if (n%2==1){
        if (x[0]!=1){
            cout<<0<<endl;
            return 0;
        }
        for (int i=2;i<n;i+=2){
            if (x[i]!=2){
                cout<<0<<endl;
                return 0;
            }
        }int p=1;
        for (int i=2;i<n;i+=2){
            p=(p*x[i])%1000000007;
        }cout<<p%1000000007;
    }else{
        for (int i=1;i<n;i+=2){
            if (x[i]!=2){
                cout<<0<<endl;
                return 0;
            }
        }int p=1;
        for (int i=1;i<n;i+=2){
            p=(p*x[i])%1000000007;
        }cout<<p%1000000007;
    }

    return 0;
}

Measured memory_bytes: 1024
// -*- mode:c++; coding:utf-8; c-basic-offset:2; -*-
// ALDS1_8_B: Binary Search Tree II

#include <cstdio>

#define NDEBUG
#include <cassert>

class BinaryTree {
  struct Node {
    int key;
    Node* parent;
    Node* left = nullptr;
    Node* right = nullptr;
    Node(const int key, Node* parent) : key(key), parent(parent) { }
  };

  Node* root_ = nullptr;;
  
public:
  void insert_node(const int key)
  {
    Node** node_p = &root_;
    Node* parent = nullptr;
    while (*node_p) {
      parent = *node_p;
      if ((*node_p)->key > key) {
        node_p = &(*node_p)->left;
      } else if ((*node_p)->key < key) {
        node_p = &(*node_p)->right;
      } else {
        assert(!"duplicate key?");
      }
    }
    (*node_p) = new Node(key, parent);
  }

  Node* find_node(const int key) const
  {
    Node* node = root_;
    while (node) {
      if (node->key > key) {
        node = node->left;
      } else if (node->key < key) {
        node = node->right;
      } else { // found
        break;
      }
    }
    return node;
  }

  void print_nodes() const
  {
    print_in_order(root_);
    std::puts("");
    print_pre_order(root_);
    std::puts("");
  }

private:
  void print_in_order(const Node* node) const
  {
    if (node == nullptr)
      return;
    print_in_order(node->left);
    std::printf(" %d", node->key);
    print_in_order(node->right);
  }

  void print_pre_order(const Node* node) const
  {
    if (node == nullptr)
      return;
    std::printf(" %d", node->key);
    print_pre_order(node->left);
    print_pre_order(node->right);
  }
};

int main()
{
  unsigned int n;
  std::scanf("%u", &n);
  BinaryTree tree;

  for (auto i = 0u; i < n; ++i) {
    char buf[6+1]; // "insert".size() + 1('\0')
    int k;
    std::scanf("%6s", buf);
    if (buf[0] == 'p') { // print
      tree.print_nodes();
    } else {
      std::scanf("%d", &k);
      if (buf[0] == 'i') { // insert k
        tree.insert_node(k);
      } else if (buf[0] == 'f') { // find k
        const auto node = tree.find_node(k);
        std::puts(node ? "yes" : "no");
      } else {
        assert(!"unknown command?");
      }
    }
  }
}

// eof

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

int main(){
    int n,m,l;
    int a[101][101] = {0};
    int b[101][101] = {0};

    cin >> n >> m >> l;
    
    for(int y=0;y<n;y++){
        for(int x=0;x<m;x++){
            cin >> a[y][x];
        }
    }
    
    for(int y=0;y<m;y++){
        for(int x=0;x<l;x++){
            cin >> b[y][x];
        }
    }
    
    for(int y=0;y<n;y++){
        for(int x=0;x<l;x++){
            long long c = 0;
            for(int i=0;i<m;i++){
                c += a[y][i]*b[i][x];
            }
            if(x == 0) cout << c;
            else cout << " " << c;
        }
        cout << endl;
    }
    
}


Measured memory_bytes: 3188
from itertools import permutations

N = int(input())
A = tuple(( str(i) for i in range(1, N+1) ))
P = tuple(input().split())
Q = tuple(input().split())

X = list(permutations(A))
count = 0

for x in X:
    if x >= min(P, Q) and x < max(P, Q):
        count = count+1
    elif x >= max(P, Q):
        break

print(count)

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

void solve(long long N, long long A, long long B) {
  cout << min( N * A , B ) << endl; 
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You
// use the default template now. You can remove this line by using your custom
// template)
int main() {
  long long N;
  scanf("%lld", &N);
  long long A;
  scanf("%lld", &A);
  long long B;
  scanf("%lld", &B);
  solve(N, A, B);
  return 0;
}


Measured memory_bytes: 3632
from math import gcd
def main():
    a, b, c, d = map(int, input().split())
    ans = b - a + 1
    e = c*d // gcd(c, d)
    x = b//c - (a-1)//c
    y = b//d - (a-1)//d
    z = b//e - (a-1)//e
    print(ans - x - y + z)

if __name__ == "__main__":
    main()

Measured memory_bytes: 8980
n, m = map(int, input().split())
a = list(map(int, input().split()))
b = [0] * (n + 1)
for i in range(n):
    b[i + 1] = (b[i] + a[i]) % m
b.sort()
ans = 0
c = b[0]
m = 0
for i in range(1, n + 1):
    if b[i] == c:
        m += 1
    else:
        c = b[i]
        m = 1
    if m >= 2:
        ans += m - 1
ans += b.count(0) - 1
print(ans)

Measured memory_bytes: 14224
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>

using namespace std;

int main()
{
    const char *YES = "YES";
    const char *NO = "NO";

    int N, A;
    if (scanf("%d", &N) < 1) return 0;

    int cnt = 0;
    for (int i = 0; i < N; i++)
    {
        if (scanf("%d", &A) < 1) return 0;
        if (A % 2) cnt++;
    }

    printf("%s\n", cnt % 2 ? NO : YES);
    return 0;
}


Measured memory_bytes: 128
#include <iostream>

int main(){
   int A, B, C, X;
   std::cin >> A >> B >> C >> X;

   int ans = 0;
   for(int i=0; i<=A; ++i){
      for(int j=0; j<=B; ++j){
	 for(int k=0; k<=C; ++k){
	    if(500*i+100*j+50*k==X) ++ans;
	 }
      }
   }
   std::cout << ans << std::endl;
   return 0;
}


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

int main() {
  int A,B,C;
  cin >> A >> B >> C;
  bool ans = false;
  if(A == B && A!= C || B == C && B != A || C == A && C != B) ans = true;
  puts(ans ? "Yes":"No");
}


Measured memory_bytes: 256
while True:
	aaa = list(input().split())
	a = int(aaa[0])
	op = aaa[1]
	b = int(aaa[2])
	if op == '?':
		exit(0)
	if op == '+':
		print(a + b)
	elif op == '-':
		print(a - b)
	elif op == '*':
		print(a * b)
	elif op == '/':
		print(a // b)



Measured memory_bytes: 5596
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <stack>
#include <functional>
#include <queue>
#include <cmath>
#include <set>

#define rep(i,j,k) for(int i=j;i<k;i++)
#define Sort(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define vi vector<int>
#define INF 1000000000
#define MOD 1000000009
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef std::pair<int,int> pii;
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

using namespace std;


int main(){
    int n;cin>>n;
    vector<int> t(n);
    vector<pair<int,int>> p(n);
    rep(i,0,n){
        cin>>t[i]>>p[i].fi>>p[i].se;
    }
    
    int x=0,y=0;
    int tt=0;
    rep(i,0,n){
        if(t[i]-tt<abs(p[i].fi-x)+abs(p[i].se-y)){
            cout<<"No"<<endl;
            return 0;
        }
        if((t[i]-tt)%2==1){
            if(abs((p[i].fi-x)+abs(p[i].se-y))%2==1){
                x=p[i].fi;
                y=p[i].se;
                tt=t[i];
            }else {
            cout<<"No"<<endl;
            return 0;
            }
        }else {
            if(abs((p[i].fi-x)+abs(p[i].se-y))%2==1){
                cout<<"No"<<endl;
                return 0;
            }else {
                x=p[i].fi;
                y=p[i].se;
                tt=t[i];
            }
        }
    }
    cout<<"Yes"<<endl;
    
    return 0;
}



Measured memory_bytes: 1408
import sys
s=input()
T=input()
a=[]
for i in range(len(s)-len(T)+1):
  for j in range(len(T)):
    if T[j]!=s[i+j] and "?"!= s[i+j] :
      break
  else:
    a.append(s[:i].replace('?', 'a')+T+s[i+len(T):].replace('?', 'a'))
 
if a==[]:
  print("UNRESTORABLE")
else:
  a.sort()
  print(a[0])

Measured memory_bytes: 3064
k,i,j,b[999];main(n){for(;scanf("%d%d",&n,&k),n;puts(b[i]<0?"No":"Yes")){for(i=0;i<k;)scanf("%d",&b[i++]);for(;n--;)for(j=0;j<k;b[j++]-=i)scanf("%d",&i);for(i=0;i<k-1;i++)if(b[i]<0)break;}}

Measured memory_bytes: 388
#include <bits/stdc++.h>
using namespace std;
int main () {
  int N;
  cin >> N;
  vector<int> data(N);
  for(int i = 0; i < N; i++){
    cin >> data.at(i);
  }
  int a;
  for(int i = 0; i < N; i++){
    cin >> a;
    data.at(i) -= a;
  }
  sort(data.begin(), data.end());
  int ans = 0;
  for(int i = N - 1; i >= 0; i--){
    if(data.at(i) + ans >= ans)ans += data.at(i);
    else break;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
  
struct point{
  ll x,y;
};
  
ll w,h,v,t,x,y,p,q;
ll R,H,W;
point o,O;
  
point calc(ll X,ll Y){
  ll dx=abs(X-O.x),dy=abs(Y-O.y);
  point res;
  
  if(dx%2==0)res.x=p;
  else res.x=w-p;
  
  if(dy%2==0)res.y=q;
  else res.y=h-q;
  
  res.x+=X*w;
  res.y+=Y*h;
  return res;
}
  
ll search(ll Y){
  ll l=0,r=W,m;
  while(l<r){
    m=(l+r)/2;
    point d=calc(m,Y);
    ll dist= (d.x-o.x)*(d.x-o.x) + (d.y-o.y)*(d.y-o.y);
    if( dist <= v*t*v*t  || o.x<= d.x ){
      r=m;
    }else{
      l=m+1;
    }
  }
  return l;
}
  
ll search2(ll Y){
  ll l=0,r=W,m;
  while(l<r){
    m=(l+r)/2;
    point d=calc(m,Y);
    ll dist= (d.x-o.x)*(d.x-o.x) + (d.y-o.y)*(d.y-o.y);
    if( dist <= v*t*v*t || d.x < o.x ){
      l=m+1;
    }else{
      r=m;
    }
  }
  return l;
}
  
int main(){
  cin>>w>>h>>v>>t>>x>>y>>p>>q;
  R=v*t;
  W=(v*t/w+1LL)*4;
  H=(v*t/h+1LL)*4;
  O.x=W/2;
  O.y=H/2;
  o.x=O.x*w+x;
  o.y=O.y*h+y;
  
  
  
  ll ans=0;
  for(ll i=0;i<=H;i++){
    ll a=search(i);
    ll b=search2(i);
    point d=calc(a,i);
    ll dist= (d.x-o.x)*(d.x-o.x) + (d.y-o.y)*(d.y-o.y);
    d=calc(b,i);
    ll dist2= (d.x-o.x)*(d.x-o.x) + (d.y-o.y)*(d.y-o.y);
    d=calc(b-1,i);
    ll dist3= (d.x-o.x)*(d.x-o.x) + (d.y-o.y)*(d.y-o.y);
    d=calc(a-1,i);
    ll dist4= (d.x-o.x)*(d.x-o.x) + (d.y-o.y)*(d.y-o.y);
  
   

    ans+=(b-a);
      
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 1160
#include <stdio.h>
int main()
{
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    if (a == b)
    {
        if (b == c)
        {
            printf("No");
        }
        else
        {
            printf("Yes");
        }
    }
    else if (a == c)
    {
        printf("Yes");
    }
    else if (b == c)
    {
        printf("Yes");
    }
    else
    {
        printf("No");
    }
    return 0;
}

Measured memory_bytes: 128