akhauriyash/Code-Regression huggingface dataset:
N = int(input())
A = list(map(int , input().split()))
bb = -(-sum(A)//N)
cc = sum(A)//N
ans = 0
ans_ = 0
for i in range(len(A)):
    ans += (A[i]-bb)**2
for i in range(len(A)):
    ans_ += (A[i]-cc)**2
print(min(ans,ans_))

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

#define NREP() for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define ALL(x) (x).begin(), (x).end()
#define MSG(x) cout << x << endl;
#define IPT(t, x) t ipt; cin >> ipt; x.push_back(ipt);
#define YN(x) x ? cout << "YES" << endl : cout << "NO" << endl;
#define Yn(x) x ? cout << "Yes" << endl : cout << "No" << endl;
#define yn(x) x ? cout << "yes" << endl : cout << "no" << endl;

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;

const static ll MOD = 1e9 + 7;
ll n, cnt, ans, tmp, sum, a, b, c, d, k, m, h, w, q, x, y;
string s, t;

int main() {
    queue<char> qa, qb, qc;

    cin >> s;
    REP(i, s.size()) {
        qa.push(s.at(i));
    }

    cin >> s;
    REP(i, s.size()) {
        qb.push(s.at(i));
    }

    cin >> s;
    REP(i, s.size()) {
        qc.push(s.at(i));
    }

    char now = qa.front();
    while (!(qa.empty() && now == 'a') && !(qb.empty() && now == 'b') && !(qc.empty() && now == 'c')) {
        if (now == 'a') {
            now = qa.front();
            qa.pop();
        } else if (now == 'b') {
            now = qb.front();
            qb.pop();
        } else {
            now = qc.front();
            qc.pop();
        }
    }

    if (now == 'a') {
        MSG('A')
    } else if (now == 'b') {
        MSG('B')
    } else {
        MSG('C')
    }
}


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

int main() {
  int n;
  cin>>n;
  int a[n];
  for(int i = 0;i<n;i++)
    cin>>a[i];
  int ans=0;
  for(int i = 0;i < n;i+=2){
    if(a[i] % 2 == 1)
      ans++;
  }
  
  cout<<ans;
  
  return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <deque>
#include <set>
#include <iomanip>
#include <utility>
typedef long long ll;
typedef long double ld;
using namespace std;

int main(void){
    ll N, K;
    cin >> N >> K;
    N %= K;
    cout << min(N, K-N) << endl;
    return 0;
}


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

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

  map<int, int> m;
  for (int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    m[a]++;
  }

  int ans = 0;
  for (auto i : m) {
    ans += i.second % 2;
  }

  cout << ans << endl;
}


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

ll inline sum(ll n, ll k) {
    ll last = n / k;
    ll sum = 1ll * (last + 1) * last / 2ll;
    sum *= 1ll * k;
    return sum;
}

int main() {


    ll n;
    cin >> n;
    ll ans = sum(n, 1) - sum(n, 3) - sum(n, 5) + sum(n, 15);
    
    cout << ans << "\n";
    

    return 0;
}

Measured memory_bytes: 3196
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const int inf = 1e9;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, b, a) for (int i = a - 1; i >= b; i--)
using Graph = vector<vector<int>>;
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int dxx[8] = {1, 1, 1, 0, 0, -1, -1, -1}, dyy[8] = {-1, 0, 1, -1, 1, -1, 0, 1};

int main() {
    string s;
    int k;
    cin >> s >> k;
    int alpha[26] = {};
    rep (i, 0, s.size()) alpha[s[i] - 'a']++;
    set<string> l;
    rep (i, 0, 26) {
        if (alpha[i] > 0) {
            rep (j, 0, s.size()) {
                if (i + 'a' == s[j]) {
                    rep (m, 1, k + 1) {
                        if (m + j - 1 < s.size()) l.insert (s.substr (j, m));
                    }
                }
            }
        }
    }
    int cnt = 0;
    for (auto p : l) {
        if (++cnt == k) {
            cout << p << "\n";
            break;
        }
    }
}

Measured memory_bytes: 1664
#include<set>
#include<map>
#include<deque>
#include<queue>
#include<stack>
#include<cmath>
#include<ctime>
#include<bitset>
#include<string>
#include<vector>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<complex>
#include<iostream>
#include<algorithm>
#define ll long long
using namespace std;

const int maxn = 310;

int n,m;
int a[maxn][maxn];

bool v[maxn];
int ans;
int d[maxn];
void solve(const int num)
{
	if(num==1) return;
	for(int i=1;i<=m;i++) d[i]=0;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++) if(v[a[i][j]])
		{
			d[a[i][j]]++;
			break;
		}
	}
	int now=0;
	for(int i=1;i<=m;i++) if(d[i]>d[now]) now=i;
	if(ans>d[now]) ans=d[now];
	v[now]=false;
	solve(num-1);
}

int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++) scanf("%d",&a[i][j]);
	}
	for(int i=1;i<=m;i++) v[i]=true;
	ans=n;
	solve(m);
	printf("%d\n",ans);
	
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}
#ifdef __LOCAL
#define debug(x) cerr << __LINE__ << ": " << #x << " = " << x << endl
#define debugArray(x, n)                           \
  cerr << __LINE__ << ": " << #x << " = {";        \
  for (long long hoge = 0; (hoge) < (n); ++(hoge)) \
    cerr << ((hoge) ? "," : "") << x[hoge];        \
  cerr << "}" << endl
#else
#define debug(x) (void(0))
#define debugArray(x, n) (void(0))
#endif

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, K, C;
  cin >> N >> K >> C;
  string S;
  cin >> S;
  int dpl[N + 1], dpr[N + 1];
  dpl[0] = 0;
  for (int i = 1; i <= N; i++) {
    dpl[i] = dpl[i - 1];
    if (S[i - 1] == 'o') {
      int tmp = 0;
      if (i >= C + 1) tmp = dpl[i - C - 1];
      dpl[i] = max(dpl[i], tmp + 1);
    }
  }
  debugArray(dpl, N + 1);
  dpr[N] = 0;
  for (int i = N - 1; i >= 0; i--) {
    dpr[i] = dpr[i + 1];
    if (S[i] == 'o') {
      int tmp = 0;
      if (i + C + 1 <= N) tmp = dpr[i + C + 1];
      dpr[i] = max(dpr[i], tmp + 1);
    }
  }
  debugArray(dpr, N + 1);
  for (int k = 0; k < N; k++) {
    if (S[k] == 'x') continue;
    if (dpl[k] + dpr[k + 1] >= K) continue;
    cout << k + 1 << endl;
  }
  return 0;
}


Measured memory_bytes: 5288
Scanf.scanf "%d %d" (fun n m ->
    let module S = Set.Make (struct type t = int let compare = compare end) in
    let ab = Array.init n (fun _ -> Scanf.scanf " %d %d" (fun a b -> a, b)) in
    let bias = 1000000 in
    Array.sort compare ab;

    let rec loop i q acc set =
        if i > m then acc else
            let rec loop2 q set =
                if q = n then q, set else
                    let a, b = ab.(q) in
                    if a > i then q, set else
                        loop2 (q + 1) (S.add (b * bias + q) set)
            in
            let q, set = loop2 q set in
            try
                let mm = S.max_elt set in
                loop (i + 1) q (acc + mm / bias) (S.remove mm set)
            with _ ->
                loop (i + 1) q acc set
    in
    loop 1 0 0 S.empty |> Printf.printf "%d\n"
)

Measured memory_bytes: 72300
#include <bits/stdc++.h>
using namespace std;
//#define endl '\n'
typedef long long ll;
ll oo = 0x3f3f3f3f3f3f3f3f;
const ll mod = 1e9+7;

int main()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  
  int n, m;
  cin >> n >> m;
  
  
  vector<vector<ll>> dp(m+1, vector<ll>(2));
  dp[1][1] = 1;
  
  for(int i = 0; i < n; ++i)
  {
    string s;
    cin >> s;
    
    for(int j = 0; j < m; ++j)
    {
      dp[j+1][i % 2] = (dp[j+1][(i+1) % 2] + dp[j][i % 2]) % mod;
      
      if(s[j] == '#')
        dp[j+1][i % 2] = 0;
    }
  }
  
  
  cout << dp[m][(n-1) % 2] << endl;
  
}


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

int main()
{
    ll a,b,c,d,e,f;
    ll w,s;
    double den=-1.0;
    cin>>a>>b>>c>>d>>e>>f;

    ll a1=f/a,b1=f/b;

    for(int i=0;i<=a1;i++)
    {
        for(int j=0;j<=b1;j++)
        {
            ll h = a*i+ b*j;
            ll water = h*100;
            //ll g= water + e*h;
            if(water>f) break;

            ll g=h*e;
            ll c1=g/c;
            ll d1=g/d;

            for(int k=0;k<=c1;k++)
            {
                for(int l=0;l<=d1;l++)
                {
                    ll salt = k*c + l*d;
                    if(salt>g)break;
                    if(salt+water>f) break;
                    double tmp = (salt*100.0)/((salt+water)*1.0);
                    if(tmp>den)
                    {
                        den=tmp;
                        w=salt+water;
                        s=salt;
                    }
                }
            }
        }
    }

    cout<<w<<" "<<s<<endl;

}





Measured memory_bytes: 256
from operator import mul
from functools import reduce
from collections import Counter


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


N = int(input())
A = list(map(int, input().split()))
dp = [0] * (N + 1)
ans = 0
l = Counter(A)
#print(l)
for sa in set(A):
    if l[sa] < 2:
        continue
    dp[sa] = combinations_count(l[sa], 2)
sum_dp = sum(dp)
#print(dp)
for a in A:
    ans = dp[a] * (l[a]-2)
    ans //= l[a]
    ans += sum_dp - dp[a]
    print(ans)

Measured memory_bytes: 132532
import java.util.Iterator;
import java.util.PrimitiveIterator;
import java.util.Scanner;
import java.util.function.Supplier;
import java.util.stream.IntStream;
import java.util.stream.Stream;

public class Main{
	static Scanner s=new Scanner(System.in);
	
	void solve(){
		int[]a=INTS(3).sorted().toArray();
		System.out.println(a[2]-a[0]);
	}

	public static void main(String[] A){
		new Main().solve();
	}

	static int gInt(){
		return Integer.parseInt(s.next());
	}
	static long gLong(){
		return Long.parseLong(s.next());
	}
	static double gDouble(){
		return Double.parseDouble(s.next());
	}

	SupplyingIterator<Integer> ints(int n){
		return new SupplyingIterator<>(n,Main::gInt);
	}
	SupplyingIterator<Long> longs(int n){
		return new SupplyingIterator<>(n,Main::gLong);
	}
	SupplyingIterator<Double> doubles(int n){
		return new SupplyingIterator<>(n,Main::gDouble);
	}
	SupplyingIterator<String> strs(int n){
		return new SupplyingIterator<>(n,s::next);
	}

	Range rep(int i){
		return Range.rep(i);
	}
	Range rep(int f,int t,int d){
		return Range.rep(f,t,d);
	}
	Range rep(int f,int t){
		return rep(f,t,1);
	}
	Range rrep(int f,int t){
		return rep(t,f,-1);
	}

	IntStream REP(int v){
		return IntStream.range(0,v);
	}
	IntStream REP(int l,int r){
		return IntStream.rangeClosed(l,r);
	}

	IntStream INTS(int n){
		return IntStream.generate(Main::gInt).limit(n);
	}
	Stream<String> STRS(int n){
		return Stream.generate(s::next).limit(n);
	}

}
class SupplyingIterator<T> implements Iterable<T>,Iterator<T>{
	int			t;
	Supplier<T>	supplier;

	SupplyingIterator(int t,Supplier<T> supplier){
		this.t=t;
		this.supplier=supplier;
	}

	@Override
	public Iterator<T> iterator(){
		return this;
	}

	@Override
	public boolean hasNext(){
		return t>0;
	}

	@Override
	public T next(){
		--t;
		return supplier.get();
	}

}

class Range implements Iterable<Integer>,PrimitiveIterator.OfInt{
	int to,cur,d;

	Range(int from,int to,int d){
		this.cur=from-d;
		this.to=to;
		this.d=d;
	}

	Range(int n){
		this(0,n-1,1);
	}

	@Override
	public Iterator<Integer> iterator(){
		return this;
	}

	@Override
	public boolean hasNext(){
		return cur+d==to||(cur!=to&&(cur<to==cur+d<to));
	}

	@Override
	public int nextInt(){
		return cur+=d;
	}
	static Range rep(int i){
		return new Range(i);
	}
	static Range rep(int f,int t,int d){
		return new Range(f,t,d);
	}
	static Range rep(int f,int t){
		return rep(f,t,1);
	}
	static Range rrep(int f,int t){
		return rep(f,t,-1);
	}
}


Measured memory_bytes: 26964
import Data.List

f :: Integral a => [a] -> a -> a
f [] _ = 0
f [_] _ = 0
f (x:y:xs) cur
  | x == y && cur == 0 = f xs x
  | x == y && cur /= 0 = x * cur
  | otherwise = f (y:xs) cur

main = do
  getLine
  nums <- reverse . sort . map read . words <$> getLine :: IO [Integer]
  print $ f nums 0

Measured memory_bytes: 40060
mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline

    T = input().rstrip('\n')
    ans = []
    for t in T:
        if t == "?":
            ans.append("D")
        else:
            ans.append(t)
    print("".join(ans))


if __name__ == '__main__':
    main()


Measured memory_bytes: 91024
N,M = map(int,input().split())
drink = []
for i in range(N):
	sub = list(map(int,input().split()))
	drink.append(sub)
drink.sort()
i = 0
ans = 0
while True:
	if M > drink[i][1]:
		ans += drink[i][0] * drink[i][1]
		M -= drink[i][1]
	else:
		ans += drink[i][0] * M
		break
	i+=1
print(ans)

Measured memory_bytes: 27760
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define vv(T) vector<vector<T>>
using namespace std;
using ll = long long;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using vll = vector<long long>;
using vvll = vector<vector<long long>>;
using vbool = vector<bool>;
using vvbool = vector<vector<bool>>;
using qint = queue<int>;
using sint = stack<int>;
using pii = pair<int, int>;

map< long long, int > prime_factor(long long n) {
    map< long long, int > ret;
    for(long long i = 2; i * i <= n; i++) {
        while(n % i == 0) {
        ret[i]++;
        n /= i;
        }
    }
    if(n != 1) ret[n] = 1;
    return ret;
}

long long count(long long p){
    long long ret = 0;
    ll tp = p;
    for(long long i = 1; i <= p; i++){
        tp -= i;
        if(tp < 0) break;
        ret += 1;
    }
    return ret;
}

int main(){
    ll n;
    cin >> n;
    map<ll, int> factor = prime_factor(n);


    ll ans = 0;
    for(auto p : factor){
        // cout << p.second << endl;
        ans += count(p.second);
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3628
N = int(input())
num_t, num_a = 0, 0

for i in range(N):
    t, a = map(int, input().split())
    if i == 0 or (num_t <= t and num_a <= a):
        num_t, num_a = t, a
    else:
        mul_t = num_t // t if num_t % t == 0 else num_t // t + 1
        mul_a = num_a // a if num_a % a == 0 else num_a // a + 1
        mul = max(mul_t, mul_a)
        num_t, num_a = t*mul, a*mul

print(num_t + num_a)

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

import sys
# import math
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product                # product(iter, repeat=n)
# from itertools import accumulate             # accumulate(iter[, f])
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from copy import deepcopy                    # to copy multi-dimentional matrix without reference


def main():
    mod = 1000000007                  # 10^9+7
    inf = float('inf')
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():  return int(input())
    def mi():  return map(int, input().split())
    def mi_0(): return map(lambda x: int(x)-1, input().split())
    def lmi(): return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():  return list(input())
    
    
    n = ii()
    print(n ** 3)

if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
# C - Poll
from collections import Counter


def main():
    _, *S = open(0).read().split()
    cnt = Counter(S)
    max_votes = max(cnt.values())
    ans = [k for k, v in cnt.items() if v == max_votes]
    ans.sort()
    print("\n".join(ans))


if __name__ == "__main__":
    main()


Measured memory_bytes: 38392
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <limits>
#include <map>
#define REP(i,n) for(long (i)=0;(i)<(n);(i)++)
#define REPI(i,a,b) for(long (i)=(a);(i)<(b);(i)++)
#define INF numeric_limits<double>::infinity()
constexpr long MOD = 1e9 + 7;
using namespace std;
using P = pair<long, long>;
using VI = vector<long>;

long maxdiv(long n) {
    long ans = 1;
    for (long i = 1; i * i <= n; i++) {
        if (n % i == 0) ans = i;
    }
    return ans;
}

int f(long a, long b) {
    long c = max(a,b);
    return int(to_string(c).size());
}

int main() {
    long n;
    cin >> n;
    long a = maxdiv(n);
    long b = n / a;
    cout << f(a,b) << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

constexpr int P = 1000000007;

vector<int> f;
void init(int n) {
    f.resize(n + 1);
    f[0] = 1;
    for (int i = 1; i <= n; i++) {
        f[i] = (ll)f[i - 1] * i % P;
    }
}
ll fact(int k) {
    return f[k];
}
ll powmod(ll n, ll k) {
    ll r = 1, t = n % P;
    for (; k != 0; k /= 2) {
        if (k & 1) r = r * t % P;
        t = t * t % P;
    }
    return r;
}
ll inv(ll n) {
    return powmod(n, P - 2);
}
ll comb(int n, int k) {
    if (n < k || k < 0) return 0;
    return (ll)f[n] * inv((ll)f[k] * f[n - k]) % P;
}

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

    init(n);

    ll r = 0, b = 0;
    for (int k = (n + 1) / 2; k <= n - 1; k++) {
        ll a = comb(k - 1, n - 1 - k) * fact(k) % P * fact(n - 1 - k) % P;
        r += (a - b) * k % P;
        b = a;
    }
    r %= P; if (r < 0) r += P;

    cout << r << endl;

    return 0;
}

Measured memory_bytes: 4224
#include <bits/stdc++.h>
using namespace std;
#define REP(i,N) for(i=0;i<N;i++)
#define INF 1e9
typedef long long ll;

int main(void){
  int i,N,K;
  string S;
  cin >> N >> S >> K;
  K--;
  REP(i,N){
    if(S[i]!=S[K])cout << '*';
    else cout << S[i];
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
if __name__ == "__main__":
    N = int(input())
    a = [int(input()) for _ in range(N)]

    index = 0
    count = 0
    number = 1
    flags = [0 for _ in range(N)]
    flags[index] = 1
    while(number != 2):
        number = a[index]
        index = number - 1
        count += 1
        if flags[index] == 1:
            break
        else:
            flags[index] = 1

    if number == 2:
        print(count)
    else:
        print(-1)

Measured memory_bytes: 7852
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <random>
#include <chrono>

using namespace std;

typedef long long ll;
typedef long double ld;
#define fastInp cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);

const ll SIZE = 1e5 * 2 + 10, INF = 1e9 * 1e9 + 10, MOD = 1e9 + 7;

bool used[SIZE][12];
ll c[SIZE][12];
bool u[SIZE];

vector<vector<ll>> gr;

void upd(int v, int dist, int col) {
    if (used[v][dist]) return;

    if (!u[v]) c[v][0] = col;
    used[v][dist] = 1;
    u[v] = 1;
    for (auto to : gr[v]) {
        if (dist != 0) upd(to, dist - 1, col);
    }
}

int main()
{
    fastInp;
    
    ll n, m, q;
    cin >> n >> m;
    gr.resize(n);
    for (int i = 0; i < m; i++) {
        ll u, v;
        cin >> u >> v;
        u--; v--;
        gr[u].push_back(v);
        gr[v].push_back(u);
    }

    cin >> q;

    vector<tuple<ll, ll, ll>> qs;
    while (q--) {
        ll u, d, c;
        cin >> u >> d >> c;
        u--;
        qs.push_back({u, d, c});
    }

    reverse(qs.begin(), qs.end());

    for (int i = 0; i < qs.size(); i++) {
        upd(get<0>(qs[i]), get<1>(qs[i]), get<2>(qs[i]));
    }

    for (int i = 0; i < n; i++) {
        cout << c[i][0] << "\n";
    }

    return 0;
}

Measured memory_bytes: 23136
#include <iostream>

using namespace std;

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

    if(b-a <= x && a >= b)
        cout << "delicious" << endl;
    else if(b-a<=x&&a<b)
        cout << "safe" << endl;
    else 
        cout << "dangerous" << endl;

    return 0;
}

Measured memory_bytes: 256
def main():
    import sys
    input = sys.stdin.readline
    N = int(input())
    S = input()

    import re
    num_li = [False]*1000
    for i in range(10):
        first_ = S.find(str(i),0,N-2)
        if first_==-1:
            continue
        for j in range(10):
            second_ = S.find(str(j),first_+1,N-1)
            if second_==-1:
                continue
            for k in range(10):
                third_ = S.find(str(k),second_+1,N)
                if third_==-1:
                    continue
                num_li[i*100+j*10+k]=True
            
    print(sum(num_li))

if __name__=='__main__':
    main()

Measured memory_bytes: 9880
import java.util.*;

@SuppressWarnings("unchecked")
public class Main {
	// public static void printArray(int[] a) {
	// 	for (int i = 0; i < a.length; i++) {
	// 		System.out.print(a[i] + ", ");
	// 	}
	// 	System.out.println();
	// }

	// public static<T> void printArrayT(T[] a) {
	// 	for (int i = 0; i < a.length; i++) {
	// 		System.out.print(a[i] + ", ");
	// 	}
	// 	System.out.println();
	// }

	public static String joinInt(int[] a, String separator) {
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < a.length; i++) {
			if (i > 0) {
				sb.append(separator);
			}
			sb.append(a[i]);
		}
		return sb.toString();		
	}

	static int[] nextIntArray(Scanner sc, int N) {
		int[] arr = new int[N];
		for (int i = 0; i < N; i++) {
			arr[i] = sc.nextInt();
		}
		return arr;
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] A = new int[N];
		int[] B = new int[N];
		int[] C = new int[N];
		for (int i = 0; i < N; i++) {
			A[i] = sc.nextInt();
			B[i] = sc.nextInt();
			C[i] = sc.nextInt();
		}
		int[] dpA = new int [N+1];
		int[] dpB = new int [N+1];
		int[] dpC = new int [N+1];
		for (int i = 0; i < N; i++) {
			dpA[i + 1] = A[i] + Math.max(dpB[i], dpC[i]);
			dpB[i + 1] = B[i] + Math.max(dpC[i], dpA[i]);
			dpC[i + 1] = C[i] + Math.max(dpA[i], dpB[i]);
		}
		int ans = Math.max(Math.max(dpA[N], dpB[N]), dpC[N]);
		System.out.println(ans);
	}
}


Measured memory_bytes: 91904
#include <bits/stdc++.h>
#define re return
#define ull unsigned long long
#define ll long long
#define ld long double
#define oo 1e9
#define pi 3.1415926536
#define OO 1e18
#define EPS 1e-7
#define FX(n) fixed<<setprecision(n)
#define mm(o,k) memset(o,k,sizeof o)
#define Hossam_Yehia ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;
ll n,p,x,ans,dp[5005];
int main(){
    Hossam_Yehia;
    cin >> n >> p;
    dp[0]=1;
    while(n--){
        cin >> x;
        for(int i=ans;i>=0;--i)
            dp[i+x]+=dp[i];
        ans+=x;
    }
    ans=0;
    for(int i=0;i<=5000;++i)
        if(dp[i]&&i%2==p)ans+=dp[i];
    cout<<ans<<endl;
    re 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>

using namespace std;

int main() {
	int n;
	int tokuten[1000];
	double heikin;
	double sum;
	double hensa2;
	double hensa;
	while (cin >> n) {
		if (n == 0) {
			break;
		}
		sum = 0.0;
		hensa2 = 0.0;
		for (int i = 0; i < n; i++) {
			cin >> tokuten[i];
			sum += tokuten[i];
		}
		heikin = sum / (double)n;
		for (int i = 0; i < n; i++) {
			hensa2 += pow(tokuten[i]-heikin, 2);
		}
		hensa = hensa2 / (double)n;
		printf("%.8f\n",sqrt(hensa));
	}
	return 0;
}

Measured memory_bytes: 1196
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
using namespace std;
#define loop(i,N) for(ll (i)=0; (i)<(N);++(i))
struct _OMAZINAI_ { _OMAZINAI_() { std::ios::sync_with_stdio(false); std::cin.tie(0); } } __omazinai_instance__;
#define INF (1LL<<61 + 1<<29)
#define YesNo(x) {std::cout << ((x)?"Yes":"No") << std::endl;}
#define YESNO(x) {std::cout << ((x)?"YES":"NO") << std::endl;}
#define OddEven(x) {std::cout << ((x)%2?"Odd":"Even") << std::endl;}
#define ODDEVEN(x) {std::cout << ((x)%2?"ODD":"EVEN") << std::endl;}
typedef long long int ll;
void _INPUT_IMPL_() {};
template <class T, class... Args> void _INPUT_IMPL_(T& dest, Args&... args) { cin >> dest; _INPUT_IMPL_(args...); }
void _OUTPUT_IMPL_() {};
template <class T, class... Args> void _OUTPUT_IMPL_(T dest, Args... args) { cout<< dest << (sizeof...(Args)?" ":""); _OUTPUT_IMPL_(args...); }
#define in(type, ...) type __VA_ARGS__; _INPUT_IMPL_(__VA_ARGS__)
#define in_v(type, name, cnt) vector<type> name(cnt); loop(i, cnt) cin >> name[i];
#define sort_v(v) std::sort(v.begin(), v.end())
#define out(...) (_OUTPUT_IMPL_(__VA_ARGS__), std::cout<<std::endl)
//小さい方に寄る
#define space_op(x, y, a, b, c) ([](auto x_, auto y_, auto a_, auto b_, auto c_){if(x_<y_)return a_;if(x_>y_)return c_;return b_;}(x,y,a,b,c))
#define space_out(x, y, a, b, c) out(space_op(x, y, a, b, c))

int main() {
	in(ll, N, K);
	if(K&1)	out((N/K)*(N/K)*(N/K));
	else	out((N/K)*(N/K)*(N/K) + ((N+K/2)/K)*((N+K/2)/K)*((N+K/2)/K));
}



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

int n,a,b,c;
int l[8];
int inf=pow(10,9);
int search(int now,int la,int lb,int lc){
    if(now==n){
        if(min({la,lb,lc})>0) return abs(la-a)+abs(lb-b)+abs(lc-c)-30;
        else return inf;
    }
    int m0=search(now+1,la,lb,lc);
    int ma=search(now+1,la+l[now],lb,lc)+10;
    int mb=search(now+1,la,lb+l[now],lc)+10;
    int mc=search(now+1,la,lb,lc+l[now])+10;
    return min({m0,ma,mb,mc});
}

int main(){
    scanf("%d %d %d %d",&n,&a,&b,&c);
    rep(i,n){
        scanf("%d",&l[i]);
    }
    int ans=search(0,0,0,0);
    printf("%d\n",ans);
}


Measured memory_bytes: 256
#include<bits/stdc++.h> 
#include<random>
#define int long long   
#define pp pair<int,int> 
#define ss second 
#define ff first 
#define pb push_back
#define mod 1000000007
#define mk(arr,n,type)  type *arr=new type[n];
#define sl s1.length();
#define yes cout<< "Yes"<<endl
#define no  cout<< "No"<<endl
#define all(v) (v).begin(),(v).end()
#define  mt mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
using namespace std;    
void fastio()
{  
  #ifndef ONLINE_JUDGE
  freopen("INPUT.txt","r",stdin);
  freopen("OUTPUT.txt","w",stdout); 
  #endif
  ios_base :: sync_with_stdio(false); 
  cin.tie(NULL) ; 
  cout.tie(NULL);
}
int dp[101][1001],ans1=1e10;
signed main()
{   
    fastio();
    int t=1;
    //cin>>t;
    while(t--)
    {
       string s;
       cin>>s;
       for(int i=0;i<3;i++)
       {
           if(s[i]=='R' &&s[i+1]=='R' &&s[i+2]=='R')
           {
           cout<<3;
           break;
           }
           else if((s[i]=='R' &&s[i+1]=='R')||(s[i+1]=='R' &&s[i+2]=='R'))
           {
           cout<<2;
           break;
           }
           if(s[i]=='R'||s[i+1]=='R'||s[i+2]=='R')
           {
           cout<<1;
           break;
           }
           else
           {
           cout<<0;
           break;
           }
       }
       
    }
}

Measured memory_bytes: 3668
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for (int i = (n)-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = (s); i < (n); ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vd vector<double>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define vp vector<P>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class S,class T> istream& operator>>(istream &is,pair<S,T> &p) { return is >> p.first >> p.second; }
template<class S,class T> ostream& operator<<(ostream &os,const pair<S,T> &p) { return os<<'{'<<p.first<<","<<p.second<<'}'; }
template<class T> istream& operator>>(istream &is,vector<T> &v) { for(T &t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) { os<<'[';rep(i,v.size())os<<v[i]<<(i==v.size()-1?']':','); return os; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YES(bool b) { cout << (b ? "YES" : "NO") << endl; }
template<class T> bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

template<typename T>
class prime {
    T n;
public:
    prime(T n):n(n) { assert(n > 0); }
    map<int,int> factorlist() {
        if(n == 1) return {};
        T nn = n;
        map<int,int> ret;
        for(int i = 2; (ll)i*i <= n; i++) {
            if(nn%i != 0) continue;
            int cnt = 0;
            while(nn%i == 0) {
                cnt++;
                nn /= i;
            }
            ret[i] = cnt;
        }
        if(nn != 1) ret[nn]++;
        return ret;
    }
    vi unique_factor() {
        map<int,int> m = factorlist();
        vi ret;
        for(P p : m) ret.pb(p.first);
        return ret;
    };
    bool isprime() {
        auto v = factorlist();
        return v.size() == 1 && v[0].second == 1;
    }
    int count_divisor() {
        int ret = 1;
        map<int,int> fl = factorlist(n);
        for(auto p : fl) ret *= p.second+1;
        return ret;
    };
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    ll n;
    cin >> n;
    prime<ll> p(n);
    map<int,int> m = p.factorlist();
    int ans = 0;
    for(auto np : m) {
        int now = 1;
        while(np.second >= now) {
            np.second -= now;
            now++;
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3656
# cook your dish here
s=list(input())
x,y = map(int,input().split())
s.append('T')
n = len(s)
d = 0
c = 0
t = 0
k = 1
xa = {0}
ya = {0}

while d <= n-1:
    if s[d] == 'F':
        c += 1
        d += 1
    else:
        if k == 1:
            if t == 0:
                xa = {c}
                t = 1
            else:    
                xb = set()
                for xx in xa:
                    xb.add(xx + c)
                    xb.add(xx-c)
                    xa = xb
        else:
            yb = set()
            for yy in ya:
                yb.add(yy+c)
                yb.add(yy-c)
                ya = yb
        c = 0
        d += 1
        k = k * (-1)
if x in xa and y in ya:
    print('Yes')
else:
    print('No')

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

using ll = long long;
using ull = unsigned long long;
#define repi(n) for (long long i = 0; i < (n); ++i)
#define repj(n) for (long long j = 0; j < (n); ++j)
#define repk(n) for (long long k = 0; k < (n); ++k)
#define rep(i, a, b) for (auto i = (a); i < (b); ++i)
#define itr(itr) for (auto&& v : (itr))
#define updatemax(t, v) (t = std::max(t, (v)))
#define updatemin(t, v) (t = std::min(t, (v)))

ll p[100010], q[100100], r[100100], psum[100100], qsum[100100], rsum[100100];
int main() {
  ll x, y, a, b, c;
  cin >> x >> y >> a >> b >> c;
  repi(a) cin >> p[i];
  repi(b) cin >> q[i];
  repi(c) cin >> r[i];
  sort(p, p + a, greater<ll>());
  sort(q, q + b, greater<ll>());
  sort(r, r + c, greater<ll>());
  ll result = 0;
  repi(x) result += p[i];
  repi(y) result += q[i];
  ll pc = x - 1, qc = y - 1;
  repi(c) {
    ll pscore = pc >= 0 ? r[i] - p[pc] : -1;
    ll qscore = qc >= 0 ? r[i] - q[qc] : -1;
    if (pscore < 0 && qscore < 0) break;
    if (pscore > qscore) {
      result += pscore;
      --pc;
    } else {
      result += qscore;
      --qc;
    }
  }
  cout << result << endl;
}


Measured memory_bytes: 5984
#include <iostream>
#include <queue>
#include <utility>
#include <vector>

using namespace std;

typedef pair<int, int> P;

int n, m, s, t;
vector<int> edge[110000];
queue<P> q;
bool visited[110000][3];

int main()
{
  cin >> n >> m;
  
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    edge[u].push_back(v);
  }
  
  cin >> s >> t;
  
  q.push(make_pair(s, 0));
  visited[s][0] = true;
  
  while (q.size()) {
    for (int v: edge[q.front().first]) {
      if (visited[v][1]) continue;
      visited[v][1] = true;
      for (int w: edge[v]) {
        if (visited[w][2]) continue;
        visited[w][2] = true;
        for (int x: edge[w]) {
          if (visited[x][0]) continue;
          visited[x][0] = true;
          int ans = q.front().second + 1;
          if (x == t) {
            cout << ans << endl;
            return 0;
          }
          q.push(make_pair(x, ans));
        }
      }
    }
    q.pop();
  }
  
  cout << -1 << endl;
  return 0;
}


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

int main(){
	const int max_num=1001000;
	int prime[max_num];
	int prime2[max_num];
	int min_prime[169]={2 ,3 ,5 ,7 ,11 ,13 ,17 ,19 ,23 ,29 ,31 ,37 ,41 ,43 ,47 ,53 ,59 ,61 ,67 ,71 ,73 ,79 ,83 ,89 ,97 ,101 ,103 ,107 ,109 ,113 ,127 ,131 ,137 ,139 ,149 ,151 ,157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233 ,239 ,241 ,251 ,257 ,263 ,269 ,271 ,277 ,281 ,283 ,293 ,307 ,311 ,313 ,317 ,331 ,337 ,347 ,349 ,353 ,359 ,367 ,373 ,379 ,383 ,389 ,397 ,401 ,409 ,419 ,421 ,431 ,433 ,439 ,443 ,449 ,457 ,461 ,463 ,467 ,479 ,487 ,491 ,499 ,503 ,509 ,521 ,523 ,541 ,547 ,557 ,563 ,569 ,571 ,577 ,587 ,593 ,599 ,601 ,607 ,613 ,617 ,619 ,631 ,641 ,643 ,647 ,653 ,659 ,661 ,673 ,677 ,683 ,691 ,701 ,709 ,719 ,727 ,733 ,739 ,743 ,751 ,757 ,761 ,769 ,773 ,787 ,797 ,809 ,811 ,821 ,823 ,827 ,829 ,839 ,853 ,857 ,859 ,863 ,877 ,881 ,883 ,887 ,907 ,911 ,919 ,929 ,937 ,941 ,947 ,953 ,967 ,971 ,977 ,983 ,991 ,997 ,1009 };
	int sosuu=0;
	int k=169;

	for(int i=0;i<169;i++){
		prime[i]=min_prime[i];
	}
	for(int i=1011;i<max_num;i+=2){
		sosuu=0;
		for(int j=0;j<169;j++){
			if(i%min_prime[j]==0){
				sosuu++;
			}
		}
		if(sosuu==0){
			prime[k]=i;
			k++;
		}
	}
	int l=0;
	for(int i=0;i<max_num;i++){
		if(i>=prime[l]){
			l++;
		}
		prime2[i]=l;
	}

	int n;

	while(cin>>n){
		cout<<prime2[n]<<endl;
	}

	return 0;
}

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


int main(){
    unsigned long long int H,W;
    cin >> H >> W;

    unsigned long long int answer = 0;

    if(H == 1){
        answer = 1;
        cout << answer;
        return 0;
    }

    if(W == 1){
        answer = 1;
        cout << answer;
        return 0;
    }

    if(W%2 == 0){
        answer = (W/2) * H;
    }
    else{
        if(H%2 == 0){
            answer = (W/2+1)*(H/2) + (W/2)*(H/2);
        }
        else{
            answer = (W/2+1)*(H/2) + (W/2)*(H/2) + (W/2)+1; 
        }
        
    }

    cout << answer;

    return 0;
}

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

typedef long double ld;
typedef long long ll;
const ld pi=acos(-1.0);

int n;
struct vec{
	ll x,y;
	vec(){}
	vec(ll a,ll b){x=a;y=b;}
	vec operator+(vec v){return vec(x+v.x,y+v.y);}
	vec operator-(vec v){return vec(x-v.x,y-v.y);}
	vec operator-(){return vec(-x,-y);}
	ll operator*(vec v){return x*v.y-v.x*y;}
	inline ld arg(){return atan2(y,x);}
	inline friend bool operator<(vec a,vec b){
		return a.arg()<b.arg(); 
	}
}p[105],q[105];

inline void init(){
	scanf("%d",&n);
	for(int i=1;i<=n;++i)
		scanf("%lld%lld",&p[i].x,&p[i].y);
}

inline void solve(){
	for(int i=1;i<=n;++i){
		for(int j=1,k=0;j<=n;++j){
			if(i==j)continue;
			q[++k]=p[j]-p[i];
		}
		sort(q+1,q+n);
		ld arg=0;
		for(int i=1;i<n-1;++i)
			arg=max(arg,q[i+1].arg()-q[i].arg());
		arg=max(arg,q[1].arg()+2*pi-q[n-1].arg());
		arg=arg<pi?0:arg-pi;
		printf("%.6lf\n",double(arg/pi/2));
	}
}

int main(){
	init();
	solve();
	return 0;
} 

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

#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define LL long long
#define pii pair <int,int>
#define fi first
#define se second
#define pb push_back
#define mpr make_pair

using namespace std;

const LL MOD=1e9+7;

int x,n,y;
map <int,int> a;

int main()
{
	cin>>x>>n;
	rep(i,n)
	{
		cin>>y;
		a[y]=1;
	}
	rep(i,105)
	{
		if(a[x-i]==0)
		{
			cout<<x-i<<endl;
			return 0;
		}
		if(a[x+i]==0)
		{
			cout<<x+i<<endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
#define mod 1000000007
using namespace std;
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int f[25005][405],g[25005][405],a[25005],n,m,K,ans,aft[405],vis[405],flag,lgg,rgg;
inline int pow(int x,int k)
{
    int res=1;
    for(;k;k>>=1,x=1LL*x*x%mod) if(k&1) res=1LL*res*x%mod;
    return res;
}
int main()
{
    n=read();K=read();m=read();
    for(int i=1;i<=m;++i) a[i]=read();
    for(int i=1;i+K-1<=m;++i)
    {
        int tot=0;
        for(int j=0;j<K;++j) if(vis[a[i+j]]!=i) vis[a[i+j]]=i,++tot;
        if(tot==K) {flag=1;break;}
    }
    ans=1LL*pow(K,n-m)*(n-m+1)%mod;
    if(flag) return 0*printf("%d\n",ans);
    for(int i=1;i<=m;++i) if(vis[a[i]]!=n+1) vis[a[i]]=n+1; else {lgg=i;break;}
    for(int i=m;i>=1;--i) if(vis[a[i]]!=n+2) vis[a[i]]=n+2; else {rgg=i;break;}
    for(int i=1;i<K;++i) f[0][i]=1,g[0][i]=i;
    for(int i=1;i<=n;++i) for(int j=1;j<K;++j)
    {
        f[i][j]=(1LL*(K-j)*f[i-1][j+1]+g[i-1][j])%mod;
        g[i][j]=(g[i][j-1]+f[i][j])%mod;
    }
    for(int i=1;i+m-1<=n;++i)
        if(lgg) ans=(ans-1LL*f[i-1][lgg-1]*f[n-(i+m-1)][m-rgg]%mod+mod)%mod;
        else for(int j=i+m,p=1;j-i<K&&j<=n+1;++j)
        {
            ans=(ans-1LL*f[i-1][j-i]*(j>n?1:g[n-j][j-i])%mod*p%mod+mod)%mod;
            p=1LL*p*(K-m-(j-(i+m)))%mod;
        }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 79488
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <list>

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
typedef long long ll;
int d[105000];
int main() {
    int n;
    cin >> n;
    int ans = 0;
    rep(i, n) {
        int l, r;
        cin >> l >> r;
        ans += r - l + 1;
    }
    
    cout << ans << endl;
}

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

#ifdef LOCAL
#define DEBUG(...) debug(#__VA_ARGS__, __VA_ARGS__);
#else
#define DEBUG(...) 6;
#endif

template<typename T, typename S> ostream& operator << (ostream &os, const pair<T, S> &p) {return os << "(" << p.first << ", " << p.second << ")";}
template<typename C, typename T = decay<decltype(*begin(declval<C>()))>, typename enable_if<!is_same<C, string>::value>::type* = nullptr>
ostream& operator << (ostream &os, const C &c) {bool f = true; os << "["; for (const auto &x : c) {if (!f) os << ", "; f = false; os << x;} return os << "]";}
template<typename T> void debug(string s, T x) {cerr << s << " = " << x << "\n";}
template<typename T, typename... Args> void debug(string s, T x, Args... args) {cerr << s.substr(0, s.find(',')) << " = " << x << " | "; debug(s.substr(s.find(',') + 2), args...);}

int cover[50];
long long dp[50][1<<20];
vector<pair<int, int>> adj[50];

bool dfs(int u, int p, int v, int i) {
    if (u == v)
        return true;
    bool ret = false;
    for (auto &e : adj[u])
        if (e.first != p && dfs(e.first, u, v, i)) {
            ret = true;
            cover[e.second] |= 1 << i;
        }
    return ret;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int n;
    cin >> n;
    for (int i=0; i<n-1; i++) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        adj[a].emplace_back(b, i);
        adj[b].emplace_back(a, i);
    }
    int m;
    cin >> m;
    for (int i=0; i<m; i++) {
        int u, v;
        cin >> u >> v;
        u--, v--;
        dfs(u, -1, v, i);
    }

    dp[0][0] = 1;
    for (int i=0; i<n-1; i++)
        for (int mask=0; mask<1<<m; mask++) {
            dp[i+1][mask] += dp[i][mask];
            dp[i+1][mask | cover[i]] += dp[i][mask];
        }

    cout << dp[n-1][(1<<m)-1] << "\n";

    return 0;
}


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

using namespace std;

typedef long long int ll;

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

  string s;
  cin >> s;
  if(s == "ABC") cout << "ARC" << endl;
  else cout << "ABC" << endl;
}


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

using namespace std;
using LL = long long;
using P = pair<int, int>;
using Tapris = tuple<int, int, int>;

#define REP(i, n) for(LL i = 0; i < n; ++i)
#define FOR(i, a, n) for(LL i = a; i < n; ++i)
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e15;
const int MOD = 1e9 + 7;

int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

//#define int long long

/*************** using variables ***************/
int x, y;
/**********************************************/

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

    cin >> x >> y;
    
    if(x == 0){
        if(y > 0) cout << y << endl;
        else cout << abs(y) + 1 << endl;
    }else if(y == 0){
        if(x < 0) cout << abs(x) << endl;
        else cout << 1 + x << endl;
    }else if(x > 0 && y > 0){
        cout << (abs(x) > abs(y) ? abs(y-x) + 2 : abs(y-x)) << endl;
    }else if(x < 0 && y > 0){
        cout << (abs(x) > abs(y) ? abs(y+x) + 1 : 1 + abs(y+x)) << endl;
    }else if(x > 0 && y < 0){
        cout << (abs(x) > abs(y) ? 1 + abs(y+x) : abs(y+x) + 1) << endl;
    }else{
        cout << (abs(x) >= abs(y) ? abs(x) - abs(y) : abs(y) - abs(x) + 2) << endl;
    }
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <queue>

using namespace std;

int a[303030];
int n;

int list1[303030] , list2[303030];
priority_queue <pair<int , int> > Q;
int main(){
	ios::sync_with_stdio(0);
	cin >> n;for(int i = 1 ; i <= n ; ++ i) cin >> a[i];
	sort(a + 1 , a + n + 1);
	long long ans = 0;
	ans += a[n];
	list1[1] = a[n] , list2[1] = a[n - 1];
	list1[2] = a[n] , list2[2] = a[n - 1];
	Q.push(make_pair(a[n - 1] , 1));
	Q.push(make_pair(a[n - 1] , 2));
	int cnt = 2;
	for(int i = n - 2 ; i >= 1 ; -- i){
		pair<int , int> top = Q.top();
		++ cnt;
		ans += top.first;
		Q.pop();
		list1[cnt] = a[i] , list2[cnt] = list1[top.second];
		Q.push(make_pair(a[i] , cnt));
		++ cnt;
		list1[cnt] = a[i] , list2[cnt] = list2[top.second];
		Q.push(make_pair(a[i] , cnt));
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 8192
N = int(input())
V = list(map(int, input().split()))
C = list(map(int, input().split()))
cnt = 0
""""
xy_l = []
for i in range(1 << N):
    xy = 0
    for j in range(N):
        if (i >> j) & 1:
            xy += V[j] - C[j]
            print(xy)
    xy_l.append(xy)
print(max(xy_l))
"""

for i in range(N):
    if V[i] > C[i]:
        cnt += V[i] - C[i]
print(cnt)

Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {

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

		System.out.println((int)Math.ceil((double)n / x) * t);

		sc.close();

	}

}

Measured memory_bytes: 35668
MOD = 10**9 + 7
n, k = map(int, input().split())
ans = 0
for i in range(k, n+2):
    mn = (0+(i-1))*i*0.5
    mx = (n+(n-(i-1)))*i*0.5
    ans += mx - mn + 1

print(int(ans%MOD))


Measured memory_bytes: 9028
#define _CRT_SECURE_NO_WARNINGS
#define y1 klfjvkldfngldf

#pragma comment(linker, "/STACK:400000000")

#include <iostream>
#include <fstream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <complex>
#include <functional>
#include <numeric>
#include <random>
#include <memory.h>
#include <time.h>

using namespace std;

typedef long long LL;

int n;

int a[300000];

int main()
{
	scanf("%d", &n);
	for (int i = 0; i < 3 * n; ++i)
		scanf("%d", &a[i]);
	sort(a, a + 3 * n);
	LL res = 0;
	for (int i = n; i < 3 * n; i += 2)
		res += a[i];
	printf("%lld\n", res);
	return 0;
}

Measured memory_bytes: 1408
import sys
import collections

def solve(N: int, A: "List[int]"):
    counter = collections.Counter(A)
    counter = sorted(counter.items(), key=lambda x:x[0], reverse=True)

    w =0
    h =0
    for i,item in enumerate(counter):
        if item[1] >=2:
            w = item[0]
            counter[i] = (item[0],item[1]-2)
            break
    
    for i,item in enumerate(counter):
        if item[1] >=2:
            h = item[0]
            break
    
    print(w*h)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()


Measured memory_bytes: 30368
import * as fs from "fs"

// mPr
const permutation = (n: number, r: number) => {
  let res = 1
  for (let i = 0; i < r; i++) {
    res *= n - i
  }
  return res
}

// mCr
const combination = (n: number, r: number) => {
  return permutation(n, r) / permutation(r, r)
}

// ############################################################ //

const process = (n: number, s: string[]): string => {
  const sorted = s
    .map((e) =>
      e
        .split("")
        .sort()
        .join("")
    )
    .sort()

  const div: string[][] = []
  sorted.forEach((e) => {
    if (div.length > 0) {
      if (div[div.length - 1][0] === e) {
        div[div.length - 1].push(e)
      } else {
        div.push([e])
      }
    } else {
      div.push([e])
    }
  })

  const comb = div.map((e) => {
    if (e.length <= 1) {
      return 0
    }
    return combination(e.length, 2)
  })

  return comb.reduce((a, b) => a + b, 0) + ""
}

const Main = (input: string): string => {
  const aa: string[][] = input.split("\n").map((e) => e.split(" "))
  const na0: number[] = aa[0].map((e) => parseInt(e))
  const [n] = na0
  const aaa = aa.map((e) => e[0])
  aaa.shift()

  const res = process(n, aaa) + ""
  console.log(res)
  return res
}
Main(fs.readFileSync("/dev/stdin", "utf8"))


Measured memory_bytes: 60844
#include <bits/stdc++.h>
    
using namespace std;
    
int main() {
    vector<int> a(3);
    for(int i = 0; i < 3; i++) {
        scanf("%d", &(a[i]));
    }
    
    sort(a.begin(), a.end());
    
    printf("%d", a[2] - a[0]);
    
    return 0;
}

Measured memory_bytes: 256