akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>

using namespace std;
using ll = long long;

template <typename K,typename V>
using umap = unordered_map<K,V>;
template <typename V>
using uset = unordered_set<V>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define REP(i,n) for(int i=0;i<n;i++)
#define REPD(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define ALL(v) v.begin(),v.end()

#define endl "\n"
#define INF 1'000'000'000'000 //10^12
#define MOD 1'000'000'007
//グリッドグラフの範囲チェック
bool range_validation(int y,int x,int h,int w){
    return y>=0 && y<h && x>=0 && x < w;
}
//ビットカウント
int popcount(long bits){
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

int gcd(ll a, ll b){
  if(b == 0){
    return a;
  }else{
    return gcd(b,a%b);
  }
}

vector<ll> sieve(ll n){
  vector<bool> is_prime(n+1,true);
  vector<ll> res;
  for(int i=2;i<=n;i++){
    if(is_prime[i]){
      res.push_back(i);
      for(int j=2*i;j<=n;j+=i){
        is_prime[j] = false;
      }
    }
  }
  return res;
}

vector<ll> divisor(ll n){
  vector<ll> list;
  for(int i=1;i*i<=n;i++){
    if(n%i==0){
      list.push_back(i);
      if(n/i != i){
        list.push_back(n/i);
      }
    }
  }
  return list;
}

umap<int,int> prime_factor(ll n){
  umap<int,int> fac;
  for(int i=2;i*i<=n;i+=2){
    if(n%i == 0){
      int count = 0;
      while(n%i == 0){
        count++;
        n /= i;
      }
      fac[i] = count;
    }
  }
  if(n!=1)fac[n] = 1;
  return fac;
}

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  
  int n;string s;
  cin >> n;
  cin >> s;
  
  string pin;
  int count = 0;
  for(int i=0;i<1000;i++){
    pin = to_string(i);
    int zero = 3-(int)pin.length();
    REP(j,zero){
		pin = "0"+pin;
    }
    int idx = 0;
    for(int j=0;idx<3 && j<n;j++){
      if(pin[idx] == s[j]){
        idx++;
      }
    }
    if(idx == 3){
		count++;
    }
  }
  
  cout << count << endl;
  
  return 0;
}


Measured memory_bytes: 3732
#include<stdio.h>
#define N 2000

int main(){
  int i,j;
  int n,q,a,m;
  int A[N+1] = {0};

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&a);
    for(j = N-a ;0<j ;j--){
      if(A[j]){
	A[j+a] = 1;
      }
    }
    A[a] = 1;
  }
  
  scanf("%d",&q);
  for(i=0 ;i<q ;i++){
    scanf("%d",&a);
    if(A[a]){
      printf("yes\n");
    }
    else printf("no\n");
  }
  return 0;
}


Measured memory_bytes: 2044
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define F first
#define S second
#define int long long
#define ll long long
//#define int  unsigned long long
#define pb push_back
//#define double long double

using namespace std;
using namespace __gnu_pbds;
typedef  tree< int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int mod = 998244353;
const int N = 1300;
int ans[N][N];
void solve(int ur, int dr, int lc, int rc){
    if (dr < ur || rc < lc) return;
    int x = (ur + dr) / 2;
    int y = (lc + rc) / 2;
    ans[x][y] = 1;
    solve(ur, x - 1, lc, y - 1);
    solve(ur, x - 1, y + 1, rc);
    solve(x + 1, dr, lc, y - 1);
    solve(x + 1, dr, y + 1, rc);
}
main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt", "r", stdin);
    int n, m;
    cin >> n >> m;
    int r = (1 << n) - 1;
    int c = (1 << m) - 1;
    solve(0, r - 1, 0, c - 1);
    for (int i = 0; i < r; i++){
        for (int j = 0; j < c; j++){
            cout << ans[i][j];
        }
        cout << endl;
    }
}


Measured memory_bytes: 13568
/*----------------
     Smit Patel
     DA-IICT
----------------*/
#include<iostream>
#include<bits/stdc++.h>
using namespace std;

#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define ins insert
#define fori(i,a,n) for(int i=a; i<n; i++)
#define ford(i,a,n) for(int i=a; i>n; i--)
#define clr(a,b) memset(a,b,sizeof(a))
#define deb(x) cout<<#x<<" : "<<x<<endl;
#define debug(x,y) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<endl;
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define bp __builtin_popcount
#define mod 1000000007
#define eps 1e-6
#define infi 1000000002
#define infll 1e18+5
#define N 200005
#define LN 20

typedef long double ld;
typedef long long ll;
typedef map<ll,ll> mll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef set<ll> sll;

ll choose(ll n,ll k);
bool isprime(ll n);
ll power(ll x,ll y,ll p);
ll power(ll x,ll y);
ll gcd(ll a,ll b);

int main()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ll n;
  cin>>n;
  ll a[n];
  fori(i,0,n)
  {
    cin>>a[i];
  }
  ll dp[n+1]={};
  fori(i,1,n)
  {
    dp[i]=infi;
    fori(j,1,3)
    {
      if(i-j>=0) dp[i]=min(dp[i],dp[i-j]+abs(a[i]-a[i-j]));
    }
  }
  cout<<dp[n-1]<<endl;
  return 0;
}

ll gcd(ll a,ll b)
{
  if(b==0)
    return a;
  return gcd(b,a%b);
}

ll choose(ll n,ll k)
{
  if(k==0)
    return 1;
  return (n* choose(n-1,k-1))/k;
}

bool isprime(ll n)
{
  for(ll i=2;i*i<=n;i++)
  {
    if(n%i==0)
      return false;
  }
  return true;
}

ll power(ll x,ll y,ll p)
{
  ll res=1;
  x=x%p;
  while(y>0)
  {
    if(y&1)
      res=(res*x)%p;
    y=y>>1;
    x=(x*x)%p;
  }
  return res;
}

ll power(ll x,ll y)
{
  ll res=1;
  while(y>0)
  {
    if(y&1)
      res=res*x;
    y=y>>1;
    x=x*x;
  }
  return res;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h> 
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define all(vec) vec.begin(), vec.end()
#define tmax(x,y,z) max((x),max((y),(z)))
#define tmin(x,y,z) min((x),min((y),(z)))
typedef long long ll;ll MM = 1000000000;ll mod = MM + 7; ll MMM=9223372036854775807;//2^63 -1
ll GCD(ll x, ll y) {if (y == 0) return x;else return GCD(y, x % y);}
ll LCM(ll x, ll y) { return x / GCD(x, y) * y;}
//cout << fixed << setprecision(10);

int main(){
ll a,b; cin>>a>>b;
  cout<<(a-1)*(b-1)<<endl;

  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
char a[101000];
int main()
{
    ll i,j,k,m,n,x,b;
    cin>>a;
    n=strlen(a);
    for(i=0; i<n; i++)
    {
        if(a[i]=='e')
        {
            if(a[i+1]=='r'&&a[i+2]=='a'&&a[i+3]=='s'&&a[i+4]=='e')
            {
                if(a[i+5]=='r')
                    i+=5;
                else
                    i+=4;
            }
        }
        else if(a[i]=='d')
        {
            if(a[i+1]=='r'&&a[i+2]=='e'&&a[i+3]=='a'&&a[i+4]=='m')
            {
                if(a[i+5]=='e'&&a[i+6]=='r'&&a[i+7]=='a'&&a[i+8]=='s'&&a[i+9]=='e')
                    i+=4;
                else if(a[i+5]=='e'&&a[i+6]=='r')
                    i+=6;
                else
                    i+=4;
            }
        }
        else
        {
            cout<<"NO"<<endl;
            return 0;
        }
    }
    cout<<"YES"<<endl;
    return 0;
}


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

int main()
{
    string s;
    getline(cin,s);
    cout<<((char)(s[0]-32));
    for(int i=0; i<s.length(); i++)
    {

        if(s[i]==' ')
            cout<<((char)(s[i+1]-32));
    }
}


Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const double PI2 = 8.0 * atan(1.0);

#define REP(i,n)	for(int i=0;i<(int)n;++i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define FOR(i,s,n)	for(int i=s;i<(int)n;++i)

typedef pair<int, int> pii;
typedef pair<int, pii> piii;

int n;
int x[500];
int a[250000];
vector<piii> qs[250001];

#define YES "Yes"
#define NO "No"

int main(int argc, char **argv) {
	memset(a, -1, sizeof(a));
	cin >> n;
	REP(i, n) {
		cin >> x[i];
		--x[i];
		a[x[i]] = i;
		qs[x[i] + 1].push_back(MP(n * n, MP(i, n - i - 1)));
	}

	priority_queue<piii, vector<piii>, greater<piii>> q;
	REP(i, n) q.push(MP(x[i], MP(i, i)));
	int p = 0;
	while (!q.empty() || p < n * n) {
		if (p >= n * n) {
			break;
		}
		if (a[p] >= 0) {
			++p;
			REP(i, qs[p].size()) q.push(qs[p][i]);
			continue;
		}
		if (q.empty()) {
			cout << NO << endl;
			return 0;
		}
		auto t = q.top(); q.pop();
		int r = t.first, v = t.second.first, c = t.second.second;
		//cerr << "[" << p << ", " << r << "] " << (v + 1) << "x" << c << endl;
		if (c == 0) continue;
		if (r <= p) {
			cout << NO << endl;
			return 0;
		}
		a[p] = v;
		--c;
		++p;
		q.push(MP(r, MP(v, c)));
		REP(i, qs[p].size()) q.push(qs[p][i]);
	}

	cout << YES << endl;
	REP(i, n * n) {
		if (i != 0) cout << ' ';
		cout << (a[i] + 1);
	}
	cout << endl;

	return 0;
}


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

using namespace std;

int main(){
	map <int, int> mp;
	int n, x;
	scanf("%d", &n);
	for(int i = 1; i <= n; ++i){
		scanf("%d", &x);
		mp[x] ^= 1;
	}
	int ans = 0;
	for(auto u : mp) ans += u.second;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4864
#include "bits/stdc++.h"
#define Rep(i,n) for(int i=0;i<n;i++)
#define For(i,n1,n2) for(int i=n1;i<n2;i++)
#define REP(i,n) for(ll i=0;i<n;i++)
#define FOR(i,n1,n2) for(ll i=n1;i<n2;i++)
#define put(a) cout<<a<<endl;
#define all(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define TDARRAY(int,a,n,m) vector<vector<int>> a(n,vector<int>(m,0));
using namespace std;
typedef long long 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;}

ll a,b;

int xbit(int k){
    ll o = 0;
    ll p = pow(2,k);
    ll c1 = a/p;
    ll d1 = a%p;
    if(c1%2==0){
    }else{
        o-=d1;
    }
    ll c2 = b/p;
    ll d2 = b%p;
    if(c2%2==0){
        o-=p;
    }else{
        o-=p-d2;
    }
    o+=(c2/2-c1/2+1)*p;
    if(o%2){
        return 1;
    }else{
        return 0;
    }
}

int main(){
    cin >> a >> b;
    b++;
    vector<int> x;
    int n = floor(log2(b))+1;
    REP(i,n){
        x.push_back(xbit(i));
    }
    ll res = 0;
    REP(i,n){
        res+= (ll)pow(2,i)*x[i];
    }
    put(res);
    return 0;
}


Measured memory_bytes: 256
import sys
from heapq import heappop, heappush

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def solve():
    N, M, S = map(int, rl().split())
    init_s = min(2500, S)
    graph = [[] for _ in range(N)]
    for _ in range(M):
        u, v, a, b = map(int, rl().split())
        u, v = u - 1, v - 1
        graph[u].append((v, a, b))
        graph[v].append((u, a, b))
    C, D = [0] * N, [0] * N
    for i in range(N):
        C[i], D[i] = map(int, rl().split())
    
    costs = [[10 ** 18] * 2501 for _ in range(N)]
    costs[0][init_s] = 0
    
    que = [(0, 0, init_s)]
    while que:
        t, cur, s = heappop(que)
        self_roop_s = min(s + C[cur], 2500)
        self_roop_t = t + D[cur]
        if self_roop_t < costs[cur][self_roop_s]:
            costs[cur][self_roop_s] = self_roop_t
            heappush(que, (self_roop_t, cur, self_roop_s))
        for child, s_cost, t_cost in graph[cur]:
            if s < s_cost:
                continue
            nt = t + t_cost
            ns = s - s_cost
            if nt < costs[child][ns]:
                costs[child][ns] = nt
                heappush(que, (nt, child, ns))
    
    for costs_i in costs[1:]:
        print(min(costs_i))


if __name__ == '__main__':
    solve()


Measured memory_bytes: 89200
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int q, current_time;

struct _task {
  struct _task *next;
  struct _task *prev;
  char name[11];
  int time, done_time;
};
typedef struct _task task;

task task_head = { &task_head, &task_head, "", 0 };
task *current_task;

task done_task_head = { &done_task_head, &done_task_head, "", 0 }; // 処理済みのタスクの先頭

void add_task(char *name, int time) {
  task *new;
  new = (task *)malloc(sizeof(task));

  strcpy(new->name, name);
  new->time = time;
  new->prev = task_head.prev;
  new->next = &task_head;
  task_head.prev->next = new;
  task_head.prev = new;
}

void done_task(task *done_task, int time) {
  done_task->prev->next = done_task->next;
  done_task->next->prev = done_task->prev;

  done_task_head.prev->next = done_task;
  done_task->prev = done_task_head.prev;
  done_task_head.prev = done_task;
  done_task->next = &done_task_head;

  done_task->done_time = time;
}

void process_task() {
  if(q < current_task->time) {
    current_task->time -= q;
    current_time += q;

    current_task = current_task->next;
  } else {
    current_time += current_task->time;
    current_task->time = 0;

    current_task = current_task->next;
    done_task(current_task->prev, current_time);
  }
}

void show_list() {
  task *x;
  x = done_task_head.next;

  while(x != &done_task_head) {
    printf("%s %d\n", x->name, x->done_time);
    x = x->next;
  }
}

int main(void) {
  int n, i, time;
  char name[11];

  scanf("%d %d", &n, &q);

  for(i = 0;i < n;i++) {
    scanf("%s %d", name, &time);
    add_task(name, time);
  }

  current_task = task_head.next;
  while(task_head.next != &task_head) {
    if(current_task == &task_head)
      current_task = current_task->next;

    process_task();
  }

  show_list();

  return 0;
}



Measured memory_bytes: 4124
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
  int r,d,x[11];
  cin>>r>>d>>x[0];
  rep(i,10){
    x[i+1]=r*x[i]-d;
    cout<<x[i+1]<<endl;
  }
}

Measured memory_bytes: 256
N, K = map(int, input().split())
dp = [[0 for j in range(10)] for i in range(2 * 10 ** 5 + 10)]
sumdp = [0 for i in range(2 * 10 ** 5 + 10)]
sumdp[1] = 1
que = []
mod = 998244353

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

for i in range(2, N + 1):
    sumdp[i] += sumdp[i - 1]
    sumdp[i] %= mod
    for j in range(K):
        l, r = que[j]
        if i - r >= 1:
            dp[i][j] = sumdp[i - l] - sumdp[i - r - 1]
            sumdp[i] += dp[i][j]
        elif i - l >= 1:
            dp[i][j] = sumdp[i - l]
            sumdp[i] += dp[i][j]

ans = sum(dp[N][i] for i in range(10))

print(ans % mod)









Measured memory_bytes: 210788
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = Integer.parseInt(scanner.nextLine());

        String[] line = scanner.nextLine().split(" ", n);
        int[] ts = new int[n];
        for (int i = 0; i < n; i++) {
            ts[i] = Integer.parseInt(line[i]);
        }

        int m = Integer.parseInt(scanner.nextLine());
        for (int i = 0; i < m; i++) {
            line = scanner.nextLine().split(" ", 2);
            int p = Integer.parseInt(line[0]);
            int x = Integer.parseInt(line[1]);

            int result = 0;
            for (int j = 0; j < n; j++) {
                if (j == p - 1) {
                    result += x;
                } else {
                    result += ts[j];
                }
            }
            System.out.println(result);
        }
    }
}


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

int main(void){
    
    int hana, taro;
    hana = taro = 0;
    
    int N;
    cin >> N;
    for(int i = 0; i < N; i++){
        
        string hana_Str, taro_Str;
        cin >> hana_Str >> taro_Str;
        
        int check = hana_Str.compare(taro_Str);
        if(check == 0) { hana++; taro++; }
        else if(check < 0) { taro += 3;}
        else { hana += 3; }
    }

    cout << hana << " " << taro << endl;
    
}



Measured memory_bytes: 3132
n = int(input())
s = [int(input()) for _ in range(n)]

ans = sum(s)
s.sort()
if ans%10==0:
    for i in range(n):
        if s[i]%10!=0:
            ans-=s[i]
            break
        if i==n-1:
            ans = 0

print(ans)

Measured memory_bytes: 3060
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
	    int n = Integer.parseInt(sc.next());
        int[][] val_cost = new int[2][n];
        
        for (int i = 0; i < 2; i++) {
            for (int j = 0; j < n; j++) {
                val_cost[i][j] = Integer.parseInt(sc.next());
            }
        }
        int val_sum = 0;
        int cost_sum = 0;
        for (int i = 0; i < n; i++) {
            int val = val_cost[0][i];
            int cost = val_cost[1][i];
            if (val > cost) {
                val_sum += val;
                cost_sum += cost;
            }
        }
        System.out.println(val_sum - cost_sum);
    }
}


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

using namespace std;
typedef long long ll;

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

int main()
{
    char x, y;
    cin >> x >> y;

    cout << ((x < y) ? '<' : (x == y) ? '=' : '>') << endl;
    return 0;
}


Measured memory_bytes: 3560
#define _USE_NATH_DEFINES
#include<cstdio>
#include <iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include <string>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
using namespace std;

int main() {
	int x, a, b,n;
	cin >> x >> a >> b;
	n = (x - a) / b;
	cout << x - (a + b * n) << endl;
}

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

int main(){
  int a,b,c,x;
  cin>>a>>b>>c>>x;
  int cnt=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) cnt++;
      }
    }
  }
  cout<<cnt;

}


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

#define each(i, c) for (auto& i : c)
#define mkp(a, b) make_pair(a, b)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> Pll;
const ll MOD = 1e9+7;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << ": " << p.second << ")"; return os; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ", "; os << ")"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; each (i, m) os << i << ", "; os << "}"; return os; }

int main() {
  string s, t;
  cin >> s >> t;

  ll ans = 0;
  for (ll i = 0; i < s.size(); ++i) {
    if (s[i] != t[i]) ++ans;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3920
#include <iostream>

using namespace std;

int main() {
    int n, p, c = 0;
    cin >> n;

    for (int i = 1; i <= n; i++) {
        cin >> p;
        if (p != i)
            c++;
    }
    if (c == 2 || c == 0) 
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
using namespace std;
// using namespace __gnu_pbds;
// typedef tree<int, null_type, less<int>, rb_tree_tag,
//              tree_order_statistics_node_update>
//     new_data_set;
// order_of_key(val): returns the number of values less than val
// find_by_order(k): returns an iterator to the kth largest element (0-based)
#define lli long long int
#define llu unsigned long long int
#define fr(va, beg, end) for (lli va = beg; va < end; va++)
#define pb push_back
#define rt return 0
#define endln "\n"
#define all(x) x.begin(), x.end()
// cout << fixed << setprecision(0) << pi <<" "<<npi<<endl;
// gcd function
// __gcd(a, b)
// for max of n elements
// cout<<max({a,b,c,d})<<endl;

lli input(lli n, vector<lli> &ve);
lli input(lli n, vector<lli> &ve) {
    lli val;
    for (lli i = 0; i < n; i++) {
        cin >> val;
        ve.pb(val);
    }
    return 0;
}

int main(void) {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    lli n, a;
    vector<lli> v;
    cin >> n;
    input(n, v);
    vector<lli> pref(n + 1, 0);
    pref[0] = v[0];
    fr(i, 1, n) {
        pref[i] = pref[i - 1] + v[i];
    }

    vector<vector<lli>> dp(n + 1, vector<lli>(n + 1, 0));
    fr(i, 0, n - 1) {
        dp[i][i + 1] = v[i] + v[i + 1];
    }

    for (lli i = 3; i <= n; i++) {
        for (lli j = 0; j <= n - i; j++) {
            lli l = j, r = j + i - 1;
            for (lli k = l; k < r; k++) {
                if (dp[l][r] == 0) {
                    dp[l][r] =
                        dp[l][k] + dp[k + 1][r] + pref[r] - pref[l] + v[l];
                } else {
                    dp[l][r] = min(dp[l][r], dp[l][k] + dp[k + 1][r] + pref[r] -
                                                 pref[l] + v[l]);
                }
            }
        }
    }

    cout << dp[0][n - 1] << endl;
    rt;
}


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

ll Ymin(ll X, ll P){
    ll Y = 0;
    while(X > P){
        X /= 2;
        Y++;
    }
    return Y;
}

ll Mmin(ll P, vector<ll> &A){
    ll ret = 0;
    for(int i = 0; i < A.size(); i++){
        ret += Ymin(A[i], P);
    }
    return ret;
}

int main(void){
    ll N, M;
    cin >> N >> M;
    vector<ll> A(N);
    for(int i = 0; i < N; i++) cin >> A[i];

    ll Pmin = 0;
    ll Pmax = 100000000000LL;
    while(Pmin < Pmax){
        // cout << Pmin << " " << Pmax << endl;
        ll Pmid = (Pmin + Pmax) / 2;
        if(Mmin(Pmid, A) > M) Pmin = Pmid + 1;
        else Pmax = Pmid;
    }
    // cout << Pmin << " " << Pmax << endl;
    for(int i = 0; i < N; i++){
        while(A[i] > Pmin){
            A[i] /= 2;
            M--;
        }
    }
    sort(A.rbegin(), A.rend());
    for(int i = 0; i < M && i < N; i++) A[i] /= 2;
    ll ans = 0;
    for(int i = 0; i < N; i++) ans += A[i];
    cout << ans << endl;
    return 0;
}


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

using namespace std;

const int N = 123456;

int x, y, z, n;

struct info_t {
  int a, b, c;
} info[N];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> x >> y >> z;
  n = x + y + z;
  for (int i = 1; i <= n; ++i) {
    cin >> info[i].a >> info[i].b >> info[i].c;
  }
  sort(info + 1, info + 1 + n, [&] (const info_t& x, const info_t& y) {
    return x.b - x.a < y.b - y.a;
  });
  multiset<int> heap1, heap2, heap3;
  long long answer = 0;
  for (int i = 1; i <= n; ++i) {
    answer += info[i].c;
  }
  for (int i = 1; i <= x; ++i) {
    heap1.insert(info[i].a - info[i].c);
  }
  for (int i = x + 1; i <= n; ++i) {
    heap2.insert(info[i].b - info[i].c);
  }
  while (heap2.size() > y) {
    heap3.insert(*heap2.begin());
    heap2.erase(heap2.begin());
  }
  for (auto x : heap1) {
    answer += x;
  }
  for (auto x : heap2) {
    answer += x;
  }
  long long t = answer;
  for (int i = x + 1; i <= n - y; ++i) {
    int foo = info[i].b - info[i].c, bar = info[i].a - info[i].c;
    if (heap2.find(foo) != heap2.end()) {
      int add = *(--heap3.end());
      heap3.erase(heap3.find(add));
      heap2.erase(heap2.find(foo));
      heap2.insert(add);
      t -= foo;
      t += add;
    } else {
      heap3.erase(heap3.find(foo));
    }
    if (bar >= *heap1.begin()) {
      t -= *heap1.begin();
      t += bar;
      heap1.erase(heap1.begin());
      heap1.insert(bar);
    }
    answer = max(answer, t);
  }
  cout << answer << '\n';
  return 0;
}

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

bool even(string s) {
  int len = s.size();
  if (len % 2) return false;
  len /= 2;
  for (int i = 0; i < len; i++) if (s[i] != s[len + i]) return false;
  return true;
}

int main() {
  string s; cin >> s;
  s.pop_back();
  while (!even(s)) s.pop_back();
  cout << s.size() << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N; string S;
  cin >> N;
 
  for (int i = 0; i < N; i++) {
    cin >> S;
      if (S == "Y") {
        cout << "Four" << endl; break;
      }
  }
  if (!(S == "Y")) cout << "Three" << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define ArraySizeOf(array)     (sizeof(array) / sizeof(array[0]))
#define res(i,n) for(int i=n;;i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define REV(i,n) for(int i=n-1;i>0;i--)
#define req(i,n,m) for(int i=n;i<m;i++)
#define REQ(i,n,m,l) for(int i=n;i<m;i+=l) 
#define _GLIBCXX_DEBUG
int INF = 1e9 + 7;
unsigned NthDayOfWeekToDay(unsigned n, unsigned dow, unsigned dow1)
{
    unsigned day;
    if (dow < dow1) dow += 7;
    day = dow - dow1;
    day += 7 * n - 6;
    return day;
}
signed gcd(long long x, long long y) {
    if (y == 0)return x;
    return gcd(y, x % y);
}
signed lcm(long long x, long long y) {
    return x / gcd(x, y) * y;
}
unsigned DayToWeekNumber(unsigned day)
{
    return (day - 1) / 7 + 1;
}
unsigned AnotherDayOfWeek(unsigned day, unsigned day0, unsigned dow0)
{
    return (dow0 + 35 + day - day0) % 7;
}
using namespace std;
signed main() {
    int N; cin >> N;
    for (long double i = N; i > 0; i--) {
        if (sqrt(i) == int(sqrt(i))) {
            cout << int(i) << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 3612
import sys
import time
import math
import itertools as it
def inpl():
    return list(map(int, input().split()))
st = time.perf_counter()
# ------------------------------

N = int(input())
P = inpl()
Q = inpl()
ls = P.copy()
ls.sort()
cnt = 0
a = 0
b = 0
for l in it.permutations(ls):
    cnt += 1
    l = list(l)
    if P == l:
        a = cnt
    if Q == l:
        b = cnt
print(abs(a - b))
# ------------------------------
ed = time.perf_counter()
print('time:', ed-st, file=sys.stderr)


Measured memory_bytes: 9040
A,B,C,D=input().split()
a,b,c,d=int(A),int(B),int(C),int(D)
while True:
    if a>0 and c>0:
        c=c-b
    else:
        print("No")
        break
    if a>0 and c>0:
        a=a-d
    else:
        print("Yes")
        break

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

string s;
string res = "NO";

int main(){
  cin >> s;
  int n = s.size();
  while( n > 4 ){
    if(s.substr(n - 5) == "dream" || s.substr(n - 5) == "erase"){
      s = s.substr(0, n-5);
      n = s.size();
      if(!n) break;
      continue;
    }
    if(s.substr(n - 6) == "eraser"){
      s = s.substr(0, n-6);
      n = s.size();
      if(!n) break;
      continue;
    }
    if(s.substr(n - 7) == "dreamer"){
      s = s.substr(0, n-7);
      n = s.size();
      if(!n) break;
      continue;
    }
    //cout << s << endl;
    //cout << n;
    break;
  }
  if(!n){
    res = "YES";
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define MAX_N 100005
 
int n, m, tmp1, tmp2, c[MAX_N] = {0};
int cnt[3] = {0};
vector<vector<int>> graph(MAX_N, vector<int>{});
 
bool dfs(int i, int col = 1) {
  bool ans = true;
  if (c[i] == 0) {
    c[i] = col;
    cnt[col]++;
    for (int j = 0; j < graph[i].size(); ++j) {
      ans &= dfs(graph[i][j], (3 - col));
    }
  }
  else {
    if (c[i] == col) return true;
    else return false;
  }
  return ans;
}
 
int main(void){
  scanf("%d %d", &n, &m);
  for (int i = 0; i < m; ++i) {
    scanf("%d %d", &tmp1, &tmp2);
    graph[tmp1].push_back(tmp2);
    graph[tmp2].push_back(tmp1);
  }
  bool temp = dfs(1);
  if (!temp) printf("%lld\n", 1LL * n * (n - 1) / 2 - m);
	else printf("%lld\n", 1LL * cnt[1] * cnt[2] - m);
}

Measured memory_bytes: 6912
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <cstring>
#include <deque>
#include <cstdio>
#include <cmath>
#include <complex>

using namespace std;

#define reep(i,f,t) for(int i=f ; i<int(t) ; ++i)
#define rep(i,n) reep(i, 0, n) 

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

typedef vector<double> vd;
typedef vector<vd> vvd;

struct Store
{
	int id;
	int dist;
	int money;
};

int main()
{
	int n;
	scanf("%d", &n);
	
	vector<Store> stores(n);
	rep(i, n){
		scanf("%d%d%d", &stores[i].id, &stores[i].dist, &stores[i].money);
	}
	
	vvd t(1<<n, vd(n, 1e20));
	vvi w(1<<n, vi(n));
	vvi p(1<<n, vi(n));
	rep(i, n){
		t[1<<i][i] = 0.0;
		w[1<<i][i] = stores[i].money * 20;
		p[1<<i][i] = -1;
	}
	
	rep(i, 1<<n){
		rep(j, n){
			rep(k, n){
				if(j==k || (i&(1<<j)) == 0 || (i&(1<<k)) == 0)
					continue;
				int pre = i ^ (1<<k);
				double tmp = t[pre][j] + abs(stores[j].dist - stores[k].dist) * (70.0 + w[pre][j]) / 2000.0;
				if(tmp < t[i][k]){
					t[i][k] = tmp;
					w[i][k] = w[pre][j] + stores[k].money * 20;
					p[i][k] = j;
				}
			}
		}
	}
	
	vector<int> path;
	int minid = distance(t[(1<<n)-1].begin(), min_element(t[(1<<n)-1].begin(), t[(1<<n)-1].end()));
	path.push_back(minid);
	for(int i=(1<<n)-1; p[i][minid]!=-1;){
		int tmp = minid;
		minid = p[i][minid];
		i ^= 1 << tmp;
		path.push_back(minid);
	}
	
	for(int i=path.size()-1; i>=0; --i)
		printf("%d%s", stores[path[i]].id, i?" ":"");
	puts("");

	return 0;
}

Measured memory_bytes: 9000
#include <vector>
#include <string>
#include <iostream>
#include <stdlib.h> // @atoi
#include <algorithm>
using namespace std;


#define NUMBEROF(Array)		( sizeof( Array ) / sizeof( Array[ 0 ] ) )


int main(void)
{
	int value[5] = { 0 };
	int distance;
	cin >> value[0] >> value[1] >> value[2] >> value[3] >> value[4] >> distance;

	bool isCan = true;
	for (int i = 0; i < NUMBEROF(value); ++i)
	{
		for (int j = 0; j < NUMBEROF(value); ++j)
		{
			if (abs(value[i] - value[j]) > distance)
			{
				isCan = false;
				break;
			}
		}
	}
	cout << ((isCan) ? "Yay!" : ":(") << endl;
	return 0;
}

Measured memory_bytes: 256
import sys
def rs(): return sys.stdin.readline().rstrip()
def ri(): return int(rs())
def rs_(): return [_ for _ in rs().split()]
def ri_(): return [int(_) for _ in rs().split()]

X, Y = ri_()
print('Yes' if X * 2 <= Y <= X * 4 and Y % 2 == 0 else 'No')

Measured memory_bytes: 9200
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi  vector<int> 
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   all(a) (a.begin(),a.end())
#define   ff   first
#define   ss   second
#define   pii  pair<int,int> 
#define   lcm(a,b) (a*b)/__gcd(a,b) 
using namespace std;

inline void solve(){
    map <int,bool> flag;
    int n,m,ans=0; cin>>n>>m;
    int a[m],dis[m-1];
    for (int i=0;i<m;i++) cin>>a[i];
    sort(a,a+m); 
    for (int i=1;i<m;i++) { 
        dis[i-1] = (a[i]-a[i-1]); 
        ans += dis[i-1];
    } 
    sort(dis,dis+(m-1),greater<int> ());
    for (int i=0;i<min(n-1,m-1);i++) ans-=dis[i];
    cout << ans << endl;
}

signed main()
{
    int n=1; // cin>>n;
    while (n--) solve();
    return 0;
}


Measured memory_bytes: 5100
#include <iostream>
using namespace std;
int H, W, K; 
char c[6][6];
char cc[6][6];

void set() {
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) cc[i][j] = c[i][j];
    }
}

int main() {
    cin >> H >> W >> K;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) cin >> c[i][j];
    }
    
    int ans = 0;
    for (int bit1 = 0; bit1 < (1<<H); bit1++) {
        for (int bit2 = 0; bit2 < (1<<W); bit2++) {
            set();
            int cnt = 0;
            for (int j = 0; j < W; j++) {
                if ((bit2 >> j) & 1) {
                    for (int l = 0; l < H; l++) {
                        cc[l][j] = '.';
                    }
                }
            }
            for (int i = 0; i < H; i++) {
                if ((bit1 >> i) & 1) {
                    for (int k = 0; k < W; k++) {
                        cc[i][k] = '.';
                    }
                }
            }

            for (int i = 0; i < H; i++) {
                for (int j = 0; j < W; j++) {
                    if (cc[i][j] == '#') cnt++;
                }
            }
            if (cnt == K) ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3568
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>



#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 repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()

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

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll res=1e9;
  int n;cin>>n;
  vector<int>a(n);
  rep(i,n)cin>>a[i];
  repi(i,-100,101){
    ll tres=0;
    rep(j,n){
      tres+=(a[j]-i)*(a[j]-i);
    }
    chmin(res,tres);
  }
  cout<<res<<endl;

  return 0;

}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner std = new Scanner(System.in);
		int a = Integer.parseInt(std.next());
		int b = Integer.parseInt(std.next());
		int temp;
		if(a<b){temp=b; b=a; a=temp;}

		int m = a%b;
		while(m!=0){
			temp = a;
			a = b;
			b = temp%b;
			m = a%b;
		}
		System.out.println(b);
	}
}

Measured memory_bytes: 26080
#include <iostream>
using namespace std;
int main(void){
  long long n, k;
  long long a, b;
  long long num[100010]={};
  int ans=0;

  cin >> n >> k;
  for(int i=0; i<n; i++){
    cin >> a >> b;
    num[a]+=b;
  }

  for(int i=0; i<100010; i++){
    if(num[i]==0)continue;
    k-=num[i];
    if(k<=0){
      ans=i;
      break;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
int main(){
  int K,N,i,j,tmp,sum;
  sum=0;
  scanf("%d %d",&N,&K);
  int l[N];
  for(i=0;i<N;i++){
    scanf("%d",&l[i]);
  }
  
  for (i=0; i<N; i++) {
    for (j=i+1; j<N; j++) {
      if (l[i] < l[j]) {
	tmp = l[i];
	l[i] = l[j];
	l[j] = tmp;
	}
    }
  }
  for(i=0; i<K; i++){
    sum+=l[i];
  }
  printf("%d",sum);
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <set>
#include <map>

using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(a) a.begin(), a.end();
typedef long long ll;

int main()
{
    int x;
    cin >> x;
    int ans;
    if (x >= 1800)
    {
        ans = 1;
    }
    else if (x >= 1600)
    {
        ans = 2;
    }
    else if (x >= 1400)
    {
        ans = 3;
    }
    else if (x >= 1200)
    {
        ans = 4;
    }
    else if (x >= 1000)
    {
        ans = 5;
    } else if(x >= 800){
        ans = 6;
    } else if(x >= 600) {
        ans = 7;
    } else {
        ans = 8;
    }

    cout << ans << "\n";
}

Measured memory_bytes: 3616
N,M = map(int,input().split())
src = [tuple(map(lambda x:int(x)-1,input().split())) for i in range(N-1+M)]
indeg_n = [0]*N
indeg = [[] for i in range(N)]
outdeg = [[] for i in range(N)]
for a,b in src:
    indeg_n[b] += 1
    indeg[b].append(a)
    outdeg[a].append(b)

root = indeg_n.index(0)
toposo = []
stack = [root]

while stack:
    v = stack.pop()
    toposo.append(v)
    for to in outdeg[v]:
        indeg_n[to] -= 1
        if indeg_n[to] == 0:
            stack.append(to)

order = [-1]*N
for i,v in enumerate(toposo):
    order[v] = i

ans = [-1]*N
ans[root] = 0
for ti in range(1,N):
    v = toposo[ti]
    maxo = max(order[p] for p in indeg[v])
    ans[v] = toposo[maxo] + 1
print(*ans, sep='\n')

Measured memory_bytes: 52068
N = int(input())
S = input()

def z_algorithm(s):
    n = len(s)
    res = [0] * n
    i = 1
    j = 0
    while i < n:
        while i + j < n and s[j] == s[i + j]:
            j += 1
            
        res[i] = j
        if j == 0:
            i += 1
            continue

        
        k = 1
        while i + k < n and k + res[k] < j:
            res[i + k] = res[k]
            k += 1
        
        i += k
        j -= k
        
    return res


res = 0
for i in range(N):
    lcp = z_algorithm(S[i:])
    for j in range(N - i):
        res = max(res, min(lcp[j], j))
        
print(res)


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

typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vll;

#define fi first
#define se second
#define INF 0x3f3f3f3f
#define len(x) (int)(x.size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

const int maxN = 1e6+10, mod=1e9+7;

void solve() {
}

int main() {
	ios_base::sync_with_stdio(0), cin.tie(NULL);
	
	ll a, b;
	cin>>a>>b;
	cout<<a*b<<'\n';
	
	
	return 0;
}


Measured memory_bytes: 3652
#include<iostream>
#include<set>
using namespace std;
typedef long long ll;
multiset<int>h1,h2;
ll s1,s2;
void push(int x){
	if(!h1.empty()&&x<*h1.rbegin()){   //先插入小堆
		h1.insert(x);
		s1+=x;
	}
	else{
		h2.insert(x);
		s2+=x;
	}
	while(h1.size()>h2.size()){
		const int cur=*h1.rbegin();
		h2.insert(cur);
		auto it=h1.end();
		it--;
		h1.erase(it);
		s1-=cur;
		s2+=cur;
	}
	while(h2.size()>h1.size()){
		const int cur=*h2.begin();
		h1.insert(cur);
		h2.erase(h2.begin());
		s1+=cur;
		s2-=cur;
	 }
 }
 ll num;
 int main(){
	int q;
	cin>>q;
	while(q--){
		int n;
		cin>>n;
		if(n==1){
			int a,b;
			cin>>a>>b;
			num+=b;
			push(a);
		}
		else{
			int x=*h1.rbegin();
	ll ans=1ll*x*(int)(h1.size())-s1+s2-1ll*x*(int)(h2.size())+num;
	    cout<<x<<' '<<ans<<'\n';
		}
	}
}


Measured memory_bytes: 9600
n=int(input())
S=[int(x) for x in input().split()]
q=int(input())
T=[int(x) for x in input().split()]

def binary_serch(t, n, S):
    left=0
    right=n
    while left<right:
        mid=(left+right)//2
        if t == S[mid]:
            return t
        elif t > S[mid]:
            left = mid +1
        else:
            right = mid
    return -1

cnt=0
for t in T:
    if binary_serch(t,n,S)==t:
        cnt+=1
print(cnt)


Measured memory_bytes: 16900
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef vector<pair<ll, ll>> pll;
 
#define mod 1000000007
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define popcount(x) __builtin_popcountll(x)
 
const long double PI = acos(-1);
 
ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a / gcd(a,b) * b;}
ll stringcount(string s, char c){return count(s.cbegin(), s.cend(), c);}
bool isInteger(double x){return floor(x) == x;}


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

  ll x, y, a, b, c;
  cin >> x >> y >> a >> b >> c;
  vector<ll> p(a), q(b), r(c);
  for(ll i = 0; i < a; i++) cin >> p[i];
  for(ll i = 0; i < b; i++) cin >> q[i];
  for(ll i = 0; i < c; i++) cin >> r[i];
  
  priority_queue<ll> que;
  sort(all(p), greater<ll>());
  sort(all(q), greater<ll>());
  for(ll i = 0; i < x; i++) que.push(p[i]);
  for(ll i = 0; i < y; i++) que.push(q[i]);
  for(ll i = 0; i < c; i++) que.push(r[i]);

  ll ans = 0;
  for(ll i = 0; i < x+y; i++){
    ans += que.top();
    que.pop();
  }
  cout << ans << endl;
  return 0;
}

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

int main(){
  int N, M, C;
  cin >> N >> M >> C;

  vector<vector<int>> A(N, vector<int>(M));
  vector<int> B(M);

  for (int i = 0; i < M; i++){
    cin >> B.at(i);
  }
  
  for (int i = 0; i < N; i++)
  {
    for (int j = 0; j < M; j++)
    {
      cin >> A.at(i).at(j);
    }
  }


  

  int cnt = 0;
  for (int i = 0; i < N; i++){
    int score = C;
    for (int j = 0; j < M; j++){
      score += A.at(i).at(j) * B.at(j);
    }
    if (score > 0) cnt += 1;
  }

  cout << cnt << endl;
}

Measured memory_bytes: 3616
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp;

fn main() {
    input!{
        n: usize,
    }
    let mut ans = 1;
    for i in 0..n {
        ans = ans * (i+1);
        ans %= 1000000007;
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
import java.util.Scanner;

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

    int N = scanner.nextInt();
    int[][] pos = new int[N][2];
    for (int i = 0; i < N; i++) {
      pos[i][0] = scanner.nextInt();
      pos[i][1] = scanner.nextInt();
    }

    double sum = 0;
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < N; j++) {
        if (i == j) continue;
        sum += dist(pos[i][0], pos[i][1], pos[j][0], pos[j][1]);
      }
    }
    System.out.println(sum / N);
  }

  private static double dist(int x1, int y1, int x2, int y2) {
    return Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
  }
}


Measured memory_bytes: 21716
N,K = map(int,input().split())
a= [0 for _ in range(N+1)]

for _ in range(K):
    d = int(input())
    dr = map(int,input().split())
    for it in dr:
        a[it]+=1

print(len(list(filter(lambda x:x==0,a)))-1)


Measured memory_bytes: 9188
import numpy as np

N,M=map(int,input().split())
K=[list(map(int,input().split())) for _ in range(N)]
count=0
matrix=np.zeros(M)
for i in range(N):
    for j in range(K[i][0]):
        matrix[K[i][j+1]-1]=matrix[K[i][j+1]-1]+1
#print(matrix)
matrix=matrix.tolist()
matrix.sort(reverse=True)
#print(matrix)
for i in range(M):
    if (int(matrix[i])==N):
        count=count+1
    else:
        break
print(count)

Measured memory_bytes: 12428
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define pi 3.141592653589793238
#define int long long
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

long long power(long long a, long long b,long long m) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a %m;
        a = a * a %m;
        b >>= 1;
    }
    return res;
}

const int mod=998244353;


int dp[3005][3005];

signed main()
{

ios_base::sync_with_stdio(false);
cin.tie(NULL);  
cout.tie(0);   

#ifndef ONLINE_JUDGE
    if(fopen("INPUT.txt","r"))
    {
    freopen ("INPUT.txt" , "r" , stdin);
    freopen ("OUTPUT.txt" , "w" , stdout);
    }
#endif  

    int n;
    cin>>n;
    int a[n+2];
    int tot=0;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        tot+=a[i];
    }
    int z=n*(n+1)/2;
    if(tot%z)
        cout<<"NO";
    else
    {
        z=tot/z;
        int temp=z;
        int diff;
        // cout<<z<<'\n';
        a[n+1]=a[1];
        for(int i=2;i<=n+1;i++)
        {   
            diff=a[i-1]-a[i]+z;
            // cout<<diff<<'\n';
            if(diff<0)
            {
                cout<<"NO";
                return 0;
            }
            if(diff%n)
            {
                cout<<"NO";
                return 0;
            }
            // cout<<diff/n<<'\n';
            temp-=diff/n;
        }

        if(temp)
            cout<<"NO";
        else
        {
            cout<<"YES";
        }
        
    }
    


} 
    
 


Measured memory_bytes: 4412
#include<bits/stdc++.h>
using namespace std;
double w,h,x,y;
int main()
{
	cin>>w>>h>>x>>y;
	printf("%.9lf %d",w*h/2.0,(int)w%2==0&&(int)h%2==0&&(int)x*2==w&&(int)y*2==h); 
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
char X, Y;
int main() {
    cin >> X >> Y;
    if(X > Y) {
        cout << ">" << endl;
    }else if(X < Y) {
        cout << "<" << endl;
    }else {
        cout << "=" << endl;
    }
}

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

int main() {
  int n, m;
  cin >> n >> m;
  
  bool exist = false;
  int a, b, c;
  for(int i=0; i<=n; i++) {
    for(int j=0; j<=n; j++) {
      if(1000*i+5000*j+10000*(n-(i+j))==m && n-(i+j)>=0) {
        exist = true;
        a=n-(i+j), b=j, c=i;
      }
    }
    if(exist) break;
  }
  
  if(exist) cout << a << " " << b << " " << c;
  else cout << "-1 -1 -1" << endl;
  return 0;
}

Measured memory_bytes: 3612