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

#define trace(...) __f( #__VA_ARGS__ , __VA_ARGS__ )
template <typename Arg1>
void __f( const char* name , Arg1&& arg1 ) {
        cerr << name << " : " << arg1 << "\n";
}
template <typename Arg1, typename... Args>
void __f( const char* na , Arg1&& arg1 , Args&&... args ) {
        const char* c = strchr( na + 1 , ',' );
        cerr.write( na , c - na ) << " : " << arg1 << " , ";
        __f( c + 1 , args... );
}
#define endl "\n"
#define all(V) V.begin(),V.end()
#define Unique(V) sort(all(V)),V.erase(unique(all(V)),V.end())
#define IO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long long int LL;
typedef pair <int,int> pii;
const int MOD = 1e9 + 7;
const int inf = 1e9;
const double EPS = 1e-9;
const double PI = acos(-1.0);
const long long INF = 1e18;
const int N = 1e5 + 5;

int n;
vector <pii> graph[ N ];
int col[ N ];

void dfs( int s , int p , int d , int c ) {
        if( col[s] != -1 ) return;
        if( d%2 == 0 ) col[s] = c;
        else col[s] = (c^1);
        for( auto x : graph[s] ) {
                if( x.first == p ) continue;
                dfs( x.first , s , x.second , col[s] );
        }
}
int main( ) {
        IO;
        #ifdef LOCAL
            freopen( "input.txt" , "r" , stdin );
        #endif // LOCAL
        cin >> n;
        for( int i = 1; i <= n - 1; i++ ) {
                int u , v , w;
                cin >> u >> v >> w;
                graph[u].push_back( {v,w} );
                graph[v].push_back( {u,w} );
        }
        memset( col , -1 , sizeof( col ) );
        dfs( 1 , 0 , 0 , 0 );
        for( int i = 1; i <= n; i++ ) cout << col[i] << endl;
        return 0;
}










Measured memory_bytes: 8448
fun main() {
    val n = readLine()!!.toInt()
    val an = readLine()!!.split(" ").map(String::toInt).toIntArray()
    var count = 0L

    // i < j
    // j - i = a_j + a_i
    // j - a_j = a_i + i
    // ansJ = j - a_j
    // ansI = i + a_i
    val map = mutableMapOf<Int, Long>()
    for (i in an.indices) {
        // ansJ = j - a_j
        val ansJ = i - an[i]
        count += map[ansJ] ?: 0L

        val ansI = i + an[i]
        map[ansI] = (map[ansI] ?: 0) + 1
    }

    println(count)
}





Measured memory_bytes: 73024
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    s = input()
    ss = []
    for i in s:
        if i != "x":
            ss.append(i)

    if ss != ss[::-1]:
        print(-1)
    else:
        n = len(ss) + 1
        cnt = 0
        cnt_x = [0] * (n)
        pos = 0
        for i in range(len(s)):
            if s[i] == "x":
                cnt += 1

            if s[i] != "x" or i == len(s) - 1:
                cnt_x[pos] = cnt
                cnt = 0
                pos += 1

        res = 0
        for i in range(n // 2):
            res += abs(cnt_x[i] - cnt_x[-(i + 1)])

        print(res)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 50032
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
#define pb push_back
#define fr(i,n) for(int i=0;i<n;i++)
#define Fr(i,n) for(int i=0;i++<n;)
#define ifr(i,n) for(int i=n-1;i>=0;i--)
#define iFr(i,n) for(int i=n;i>0;i--)

int main(){
  ll n,m,a,b;
  bool f[200010]={},g[200010]={},h=0;
  cin>>n>>m;
  fr(i,m){
    cin>>a>>b;
    if(a==1) f[b]=1;
    if(b==1) f[a]=1;
    if(a==n) g[b]=1;
    if(b==n) g[a]=1;
  }
  Fr(i,n-2) if(f[i+1]&g[i+1]) h=1;
  cout<<(h?"POSSIBLE":"IMPOSSIBLE")<<endl;
}

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

int main()
{
	int n, r, p, c;
	while (true) {
		cin >> n >> r;

		if (n == 0 && r == 0) {
			break;
		}

		vector<int> cards;
		for (int i = 1; i <= n; i++) {
			cards.push_back(i);
		}

		for (int i = 0; i < r; i++) {
			cin >> p >> c;

			p = n - p - c + 1;
			for (int j = 0; j < c; j++) {
				cards.push_back(cards[p]);
				cards.erase(cards.begin() + p);
			}
		}

		cout << cards.back() << '\n';
	}

	return 0;
}

Measured memory_bytes: 1220
#include <bits/stdc++.h>
typedef long long LL;
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

using namespace std;

LL dig(LL x, LL n) {
  if(n<x) return n;
  else return dig(x,n/x)+n%x;
}
int main(void)
{
  LL n,s;
  cin >> n >> s;
  if(n==s) {
    cout << n+1 << endl;
    return 0;
  }
  if(n<s) {
    cout << -1 << endl;
    return 0;
  }
  vector<LL> f;
  for(LL i=1; i*i <= n;++i) {
    if((n-s)%i) continue;
    f.push_back(i+1);
    f.push_back((n-s)/i+1);
  }
  vector<LL> as;
  for(LL x: f) {
    if(dig(x,n)==s) as.push_back(x);
  }
  sort(as.begin(),as.end());
  as.push_back(-1ll);
  cout << as[0] << endl;
  return 0;
}


Measured memory_bytes: 256
N=int(input())
ls=[int(s) for s in input().split()]
dic1={}
dic2={}
i=0
while i<N:
  if ls[i] in dic1:
    dic1[ls[i]]+=1
  else:
    dic1[ls[i]]=1
  if ls[i+1] in dic2:
    dic2[ls[i+1]]+=1
  else:
    dic2[ls[i+1]]=1  
  i+=2
ls1=sorted(list(dic1.items()),key=lambda x : -x[1])
ls2=sorted(list(dic2.items()),key=lambda x : -x[1])
#print(ls1)
#print(ls2)
#ls1とls2の一位の値が異なる場合
if ls1[0][0]!=ls2[0][0]:
  print(N-ls1[0][1]-ls2[0][1])
elif len(ls1)==1:
  #ls1,ls2がともに1種類の場合
  if len(ls2)==1:
    print(N//2)
  #ls1が1種類、ls2が複数種類の場合
  else:
    print(N//2-ls2[1][1])
#ls2が1種類、ls1が複数種類の場合
elif len(ls2)==1:
  print(N//2-ls1[1][1])
else:
  #ls1の2位の数がls2の2位の数より多いとき
  if ls1[1][1]>ls2[1][1]:
    #ls1を2位にそろえ、ls2を1位にそろえる
    print(N-ls1[1][1]-ls2[0][1])
  else:
    #逆なら逆
    print(N-ls2[1][1]-ls2[0][1])
    

Measured memory_bytes: 21140
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using static System.Math;
 
public class Hello{
    public static void Main(){
//        long readhp = long.Parse(ReadLine());
//        string[] reader = ReadLine().Split(' ');
//        int monsterhp = int.Parse(reader[0]);
//        int magicnum = int.Parse(reader[1]);
/*        string[] reader = ReadLine().Split(' ');
        string[] reader1 = ReadLine().Split(' ');
        int a = int.Parse(reader1[0]);
        int b = int.Parse(reader1[1]);*/
        string c = ReadLine();
        int a = c.Length;
        for(int i=0;i<a;i++){
            Write("x");
        }
        WriteLine();
//        string[] readerhp = ReadLine().Split(' ');
//        long total = 0;
//        int leng = readerhp.Length;
/*        int[,] map = new int[magicnum+10,monsterhp+10];
        for(int i=0;i<=monsterhp;i++){
            map[0,i] = 1000000000;
        }
        for(int i=1;i<=magicnum;i++){
            string[] reader2 = ReadLine().Split(' ');
            int magicdam = int.Parse(reader2[0]);
            int magicuse = int.Parse(reader2[1]);
            
            for(int j=1;j<=monsterhp;j++){
                if(j <= magicdam){
                    map[i,j] = Min(map[i-1,j],magicuse);
                }else{
                    map[i,j] = Min(map[i-1,j],map[i,j-magicdam]+magicuse);
                }
            }
        }
        /*for(int i=0;i<=magicnum;i++){
            for(int j=0;j<=monsterhp;j++){
                Write(map[i,j]);
                Write(" ");
            }
            WriteLine();
        }*/
        //WriteLine(map[magicnum,monsterhp]);*/
    }
}

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

using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
int b[1000000];
int c[1000000];
int main(){
int n;
int i,j;
cin>>n;
pair<int,int> a[n+1];
for(i=1;i<=n;i++)
    {
        int e;
        cin>>e;
        a[i].first=e;
        a[i].second=i;

    c[e]=i;
    }
    sort(a+1,a+n+1);
int x=n*n;
int fl=0;
for(i=1;i<=n;i++){

    int z=a[i].first;
    int u=a[i].second;
b[z]=a[i].second;
u--;
    for(j=1;j<z;j++){
            if(u==0)
            break;
        if(b[j])
            continue;
        else
        {
            b[j]=a[i].second;
            u--;
        }


    }
    if(u!=0){
        fl=1;
        break;
    }

}

if(fl)
    cout<<"No"<<endl;
else{
    deque<pair<int,int> > ww;
    for(i=1;i<=x;i++){
        if(b[i])
            {
                if(c[i]&&(c[i]!=n))
                {
                    ww.push_back(mp(c[i],n-c[i]));
                }

                continue;}
        else{

            if(ww.empty())
            {
                fl=1;
                break;
            }
            deque<pair<int,int> >::iterator q=ww.begin();
            pair<int,int> s=(*q);
            b[i]=s.first;
            int d=s.second-1;
            s.second=s.second-1;
            ww.pop_front();
            if(d==0){


            }
            else{


                ww.push_front(s);

            }



        }


    }
    if(fl)
        cout<<"No"<<endl;
    else{

        cout<<"Yes"<<endl;
        for(i=1;i<=x;i++)
            cout<<b[i]<<" ";
        cout<<endl;

    }




}




return 0;
}


Measured memory_bytes: 6016
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, n) for(int i = 0;i < n;i++)
#define ll long long
 
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n;
	cin >> n;
	set<ll> st;
	ll d;
	REP(i, n){
		cin >> d;
		st.insert(d);
	}
	cout << st.size() << endl;
}

Measured memory_bytes: 256
w,h=map(int,raw_input().split())
p=[[int(raw_input()),0] for _ in xrange(w)]
q=[[int(raw_input()),1] for _ in xrange(h)]
pq=p+q
pq.sort()
a=w+1
b=h+1
ans=0
for i in xrange(w+h):
    if pq[i][1]==0:
        ans+=b*pq[i][0]
        a-=1
    else:
        ans+=a*pq[i][0]
        b-=1

print(ans)

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

int n;

bool cek(int x){
	for(int i=2;i*i<=x;i++){
		if(x%i == 0) return 0;
	}
	return 1;
}

int main(){
	scanf("%d",&n);
	while(!cek(n)) n++;
	printf("%d\n",n);
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main()
{
    int s[33];
    s[1]=1;
    s[2]=1;
    s[3]=1;
    s[4]=2;
    s[5]=1;
    s[6]=2;
    s[7]=1;
    s[8]=5;
    s[9]=2;
    s[10]=2;
    s[11]=1;
    s[12]=5;
    s[13]=1;
    s[14]=2;
    s[15]=1;
    s[16]=14;
    s[17]=1;
    s[18]=5;
    s[19]=1;
    s[20]=5;
    s[21]=2;
    s[22]=2;
    s[23]=1;
    s[24]=15;
    s[25]=2;
    s[26]=2;    
    s[27]=5;
    s[28]=4;
    s[29]=1;
    s[30]=4;
    s[31]=1;
    s[32]=51;

    int k;
    scanf("%d",&k);
    printf("%d\n",s[k]);
    return 0;
}

Measured memory_bytes: 128
def calc(N, D):
    c = 0
    for (d1, d2) in D:
        if d1 == d2:
            c += 1
            if c == 3:
                return 'Yes'
        else:
            c = 0
    return 'No'


N = int(input())
D = [tuple([int(s) for s in input().split()]) for _ in range(N)]
print(calc(N, D))

Measured memory_bytes: 62392
#include <stdio.h>

int main(void)
{
	int n[10];
	int i;
	for (i = 0; i < 10; i++){
		scanf("%d", &n[i]);
	}
	int j, k;
	for (j = 9; j > 0; j--){
		for (k = 0; k < j; k++){
			if (n[k] > n[k + 1]){
				int t;
				t = n[k];
				n[k] = n[k + 1];
				n[k + 1] = t;
			}
		}
	}
	printf("%d\n%d\n%d\n", n[9], n[8], n[7]);

	return 0;
}

Measured memory_bytes: 600
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

struct Roadwork {
  int from, to;
  int x;
  Roadwork(int f, int t, int x): from(f), to(t), x(x) {}
  friend bool operator< (const Roadwork& lhs, const Roadwork& rhs) { 
    return lhs.from < rhs.from;
  }
};

struct Data {
  int to;
  int x;
  Data(int t, int x): to(t), x(x) {}
  friend bool operator< (const Data& lhs, const Data& rhs) { 
    return lhs.x > rhs.x;
  }
};

int main() {
  int n, q;
  cin >> n >> q;
  vector<Roadwork> lr;
  for (int i = 0; i < n; ++i) {
    int s, t, x;
    cin >> s >> t >> x;
    lr.emplace_back(s-x, t-x-1, x);
  }
  sort(lr.begin(), lr.end());
  // for (Roadwork& r: lr) {
  //   cerr << r.from << " " << r.to << " " << r.x << endl;
  // }
  int rid = 0;
  priority_queue<Data> pq;
  for (int i = 0; i < q; ++i) {
    int d;
    cin >> d;
    Roadwork& r = lr[rid];
    // cerr << "[R]" << r.from << " " << r.to << " " << r.x << endl;
    while (r.from <= d && rid < n) {
      pq.push(Data(r.to, r.x));
      r = lr[++rid];
      // cerr << "[R]" << r.from << " " << r.to << " " << r.x << endl;
    }
    Data data = pq.top();
    // cerr << d << " " << data.to << " " << data.x << endl;
    while (data.to < d && !pq.empty()) {
      pq.pop();
      data = pq.top();
    }
    if (pq.empty()) cout << "-1" << endl;
    else { cout << data.x << endl; }
  }
}


Measured memory_bytes: 7152
#include <stdio.h>
#include <cstdlib>
#include <iostream>
#include <string>
#include <set>
#include <tuple>
#include <algorithm>

using namespace std;

int main()
{
	int N;
	int A;
	int B;

	cin >> N >> A >> B;

	int dist = std::abs(A - B);
	if (dist % 2 == 0) {
		cout << "Alice";
	}
	else {
		cout << "Borys";
	}

	return 0;
}




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

int main() {
   int N,K,i;
   cin >> N >> K;
   int result=1;
   for(i=0;i<N;i++){
      if(result>K){
        result = result+K; 
      } 
      else{
       result = result*2;
      }  
   }
     cout << result <<endl;
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define RALL(a)     (a).rbegin(),(a).rend()
#define PRINT(a)   cout << (a) << endl

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second

#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';

using ll = long long int;
using P = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;

template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

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; }

const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;

int main(){
  int H,W,M;
  cin >> H >> W >> M;

  map<int,int> hmp, wmp;
  vector<P> bomb;
  vi hv(M), wv(M);
  REP(i,M){
    int h,w;

    cin >> h >> w;
    hv[i] = h;
    wv[i] = w;
    hmp[h]++;
    wmp[w]++;
  }

  int max_h = 0;
  int max_w = 0;

  set<int> max_h_set, max_w_set;
  for(auto v: hmp){
    chmax(max_h, v.second);
  }
  for(auto v: hmp){
    if(v.second == max_h){
      max_h_set.insert(v.first);
    }
  }
  for(auto v: wmp){
    chmax(max_w, v.second);
  }
  for(auto v: wmp){
    if(v.second == max_w){
      max_w_set.insert(v.first);
    }
  }

  // for(auto v: max_h_set){
  //   cout << v << endl;
  // }
  // cout << "--" << endl;
  // for(auto v: max_w_set){
  //   cout << v << endl;
  // }

  int cnt=0;
  REP(i,M){
    if(max_h_set.count(hv[i]) == 1 &&  max_w_set.count(wv[i]) == 1)cnt++;
  }
  if(max_h_set.size() * max_w_set.size() == cnt){
    cout << max_h + max_w - 1 << endl;
  }else{
    cout << max_h + max_w << endl;
  }

}



Measured memory_bytes: 61864
// to be build tomorrow
#include <bits/stdc++.h>
#define ll long long
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<pair<int, int>, null_type,less<pair<int, int>>, rb_tree_tag,tree_order_statistics_node_update> 
#include <bits/stdc++.h> 
using namespace std; 
ordered_set s[200005];
struct pt {
    long long x, y;
    pt() {}
    pt(long long _x, long long _y) : x(_x), y(_y) {}
    pt operator-(const pt& p) const { return pt(x - p.x, y - p.y); }
    long long cross(const pt& p) const { return x * p.y - y * p.x; }
    long long cross(const pt& a, const pt& b) const { return (a - *this).cross(b - *this); }
};

int sgn(const long long& x) { return x >= 0 ? x ? 1 : 0 : -1; }

bool inter1(long long a, long long b, long long c, long long d) {
    if (a > b)
        swap(a, b);
    if (c > d)
        swap(c, d);
    return max(a, c) <= min(b, d);
}

bool check_inter(const pt& a, const pt& b, const pt& c, const pt& d) {
    if (c.cross(a, d) == 0 && c.cross(b, d) == 0)
        return inter1(a.x, b.x, c.x, d.x) && inter1(a.y, b.y, c.y, d.y);
    return sgn(a.cross(b, c)) != sgn(a.cross(b, d)) &&
           sgn(c.cross(d, a)) != sgn(c.cross(d, b));
}
using pp = pair <ll, ll>;
ll dp[30][30][2];
ll valid(ll f1, ll pos, string s, string cur, ll count)
{
    if (pos == s.length())
    {
        // cout << cur << "\n";
        if (stoull(cur))
        return 1;
        return 0;
    }
    if (dp[pos][count][f1] != -1)
    return dp[pos][count][f1];
    if (f1 == 1)
    {
        dp[pos][count][f1] = valid(f1, pos+1,s, cur+'0', count) + valid(f1, pos+1,s, cur + '1', count+1);   
    }
    else 
    {
        if (s[pos] == '0')
        {
            dp[pos][count][f1] = valid (f1, pos+1, s, cur+'0', count);
        }
        else if (s[pos] == '1')
        dp[pos][count][f1] = valid(0, pos+1, s, cur+'1', count+1) + valid(1, pos+1, s, cur + '0', count);
        else 
        dp[pos][count][f1] = valid(1, pos+1, s, cur+'1',count+1) + valid(1, pos+1, s, cur+'0', count);
    }
    return dp[pos][count][f1];
}
int main ()
{
ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t = 1;
    // cin >> t;
    while (t--)
    {
        ll n;
        cin >> n;
        ll a[n];
        map <ll, ll> m;
        ll sxor = 0;
        for (auto &i : a)
        {
            cin >> i;
            sxor ^= i;
        }
        for (auto i : a)
        {
            cout << (sxor^i) << " ";
        }
    }
    return 0;
}

Measured memory_bytes: 23972
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.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; }
using namespace std;
using ll = long long;


int main(){
    int a, b;
    cin >> a >> b;
    if((a+b)%2 == 1) cout << "IMPOSSIBLE" << endl;
    else cout << (a+b)/2 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#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 FOR(i,n,m) for(int i=n;i<=(int)(m);i++)
#define RFOR(i,n,m) for(int i=(int)(n);i>=m;i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(std::unique(all(x)), x.end());
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
const double PI=acos(-1);
using namespace std;
vector<int> dx={1,0,-1,0};
vector<int> dy={0,1,0,-1};
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

struct UnionFind {
    vector<int> data;
    UnionFind(int size): data(size,-1) {
    }
    
    int root(int x){
        return (data[x] < 0)? x : data[x]=root( data[x] );
    }
    
    bool unite(int x, int y){
        x=root(x);
        y=root(y);
        if( x != y ){
            if( data[y] < data[x] ) swap(x, y);
            data[x] += data[y];
            data[y] = x;
        }
        return x!=y;
    }
    
    bool find(int x, int y){
        return root(x) == root(y);
    }
    
    int size(int x){
        return -data[ root(x) ];
    }
};


int main() {
    int n;
    cin>>n;
    UnionFind uf(200100);
    rep(i,n) {
        int x,y;
        cin>>x>>y;
        uf.unite(x,y+100010);
    }
    
    map<int,int> yoko,tate;
    rep(i,100010) {
        yoko[uf.root(i)]++;
        tate[uf.root(i+100010)]++;
    }
    
    ll ans=-n;
    rep(i,200100) ans+=(ll)tate[i]*yoko[i];
    cout<<ans<<endl;
    
}


Measured memory_bytes: 19840
#![allow(unused)]

use std::cmp;
use std::io::{self, BufRead};
use std::iter;

macro_rules! destruct_ {
  ($e: expr, ()) => (
    assert!($e.next().is_none())
  );
  ($e: expr, ($arg: ident, $( $args: ident, )*)) => (
    $arg = $e.next().unwrap();
    destruct_!($e, ($($args,)*))
  );
  ($e: expr, ($arg: ident $(, $args: ident )*)) => (
    $arg = $e.next().unwrap();
    destruct_!($e, ($($args,)*))
  );
}

macro_rules! into {
  ($e: expr, $($name: ident)*) => {
    let mut iter = $e.into_iter();
    destruct_!(iter, ($($name)*));
  }
}

macro_rules! get {
  ($i: ident) => (
    let stdin = io::stdin();
    let mut $i = Vec::new();
    for line in stdin.lock().lines() {
      $i.push(
        line
          .unwrap()
          .split_whitespace()
          .map(|a| a.parse().unwrap())
          .collect()
      );
    }
  )
}

macro_rules! p {
  ($a: expr) => (
    println!("{}", $a);
  )
}

fn main() {
  let stdin = io::stdin();
  let mut lines = stdin.lock().lines();
  let args: Vec<i32> = lines
    .next()
    .unwrap()
    .unwrap()
    .split_whitespace()
    .map(|a| a.parse().unwrap())
    .collect();

  let x = args[0];
  let a = args[1];
  let b = args[2];

  if b - a <= x {
    if b > a {
      p!("safe");
    } else {
      p!("delicious");
    }
  } else {
    p!("dangerous");
  }
}


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

int N, K, h, ans;

int main() {
  scanf("%d%d", &N, &K);
  for (int i = 0; i < N; i++) {
    scanf("%d", &h);
    if (h >= K) {
      ans++;
    }
  }

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

Measured memory_bytes: 256
N=int(input())
l1=list(map(int,input().split()))
l2=list(map(int,input().split()))
l3=list(map(int,input().split()))
ans=sum(l2)
for i in range(N-1):
  if l1[i+1]==l1[i]+1:
    ans+=l3[l1[i]-1]
print(ans)

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

char s[1001];
bool a, b, c, d;

int main() {
	scanf("%s", s);
	for (int i = 0; s[i]; ++i) {
		if (s[i] == 'N')a = true;
		else if (s[i] == 'S')b = true;
		else if (s[i] == 'W')c = true;
		else d = true;
	}
	if (!(a^b) && !(c^d))printf("Yes\n");
	else printf("No\n");
}

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

using namespace std;

int main(int argc, char* argv[]) {
  int K;
  cin >> K;
  string s;
  cin >> s;

  if (s.size() <= K)
    cout << s << endl;
  else
    cout << s.substr(0, K) + "..." << endl;

  return 0;
}

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

int main() {
    while (true) {
        int n, m;
        cin >> n >> m;
        if (!n) return 0;

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

        int ans = 0;
        if (n < m) {
            for (int i = 1; i < (1 << n); ++i) {
                bitset<500> bs;
                int c = 0;
                for (int j = 0; j < n; ++j) {
                    if ((i >> j) & 1) {
                        ++c;
                        bs ^= b[j];
                    }
                }
                if (c > ans && !bs.any())
                    ans = max(ans, c);
            }
        }
        else {
            vector<int> bs(n);
            for (int i = 0; i < n; ++i)
                bs[i] = b[i].to_ulong();

            vector<int> dp(1 << m, -1e5);
            dp[0] = 0;
            for (int i = 0; i < n; ++i) {
                vector<int> nex(1 << m);
                for (int j = 0; j < (1 << m); ++j)
                    nex[j] = max(dp[j], dp[j ^ bs[i]] + 1);

                dp = nex;
            }
            ans = max(ans, dp[0]);
        }
        cout << ans << "\n";
    }
}



Measured memory_bytes: 35836
#include <bits/stdc++.h>
#define ll long long
#define INF 999999999
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

typedef pair<int,int>P;

const int MAX_N = 15;
const int MAX_M = 225;

int n,m;
ll dp[1 << MAX_N][MAX_N];
ll d[MAX_N][MAX_N];
int s[MAX_M];
int t[MAX_M];
int D[MAX_M];

ll solve()
{
	rep(S,1<<n){
		fill(dp[S],dp[S]+n,INF);
	}
	dp[(1<<n)-1][0] = 0;
	for(int S=(1<<n)-2;S>=0;S--){
		rep(v,n){
			if(S==0 || (S>>v&1)){
				rep(u,n){
					if(!(S>>u&1)){
						dp[S][v] = min(dp[S][v],dp[S|1<<u][u] + d[v][u]);
					}
				}
			}
		}
	}
	return dp[0][0];
}

int main()
{
	ll ans=INF-1;
	cin >> n >> m;
	rep(i,m){
		cin >> s[i] >> t[i] >> D[i];
	}
	rep(i,n){
		fill(d[0],d[n],INF);
		rep(j,m){
			d[(s[j]+n-i)%n][(t[j]+n-i)%n] = D[j];
		} 
		ans = min(ans,solve());
	}
	if(ans > 16000){
		cout << "-1\n";
	}else{
		cout << ans << "\n";
	}
}

Measured memory_bytes: 6928
#include <stdio.h>
#include <math.h>
 
int main(){
    double x,h,temp,result;
     
    while(1){
        result=0;
        scanf("%lf %lf",&x,&h);
         
        if(x==0 && h==0)
            break;
         
        temp=(x/2)*(x/2)+h*h;
        temp=sqrt(temp);
        result=x*x+temp*x*2;
         
        printf("%f\n",result);
    }
    return 0;
}

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

using namespace std;

int main() {
	string s; cin >> s;
	int a, b, c, d;
	a = s[0] - '0';
	b = s[1] - '0';
	c = s[2] - '0';
	d = s[3] - '0';


	if ((a + b + c + d) == 7) cout << s[0] << '+' << s[1] << '+' << s[2] << '+' << s[3] << "=7" << endl;
	else if ((a + b + c - d) == 7) cout << s[0] << '+' << s[1] << '+' << s[2] << '-' << s[3] << "=7" << endl;
	else if ((a + b - c + d) == 7) cout << s[0] << '+' << s[1] << '-' << s[2] << '+' << s[3] << "=7" << endl;
	else if ((a - b + c + d) == 7) cout << s[0] << '-' << s[1] << '+' << s[2] << '+' << s[3] << "=7" << endl;
	else if ((a + b - c - d) == 7) cout << s[0] << '+' << s[1] << '-' << s[2] << '-' << s[3] << "=7" << endl;
	else if ((a - b - c + d) == 7) cout << s[0] << '-' << s[1] << '-' << s[2] << '+' << s[3] << "=7" << endl;
	else if ((a - b + c - d) == 7) cout << s[0] << '-' << s[1] << '+' << s[2] << '-' << s[3] << "=7" << endl;
	else if ((a - b - c - d) == 7) cout << s[0] << '-' << s[1] << '-' << s[2] << '-' << s[3] << "=7" << endl;

	return 0;
}

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

int main() {
	long long n,m,i,j,i1,i2,i3,k,ans,cur,zero=0,jud;
	string s;
	cin >> s >> k;
	n=s.size();
	vector<long long> p(n);
	
	for(i=0; i<n; i++){
		j=s[i]-'0';
		p[i]= j;
	}
	
	ans=0;
	
	if(k>n){
		cout << 0; return 0;
	}
	if(k==1){
		ans=p[0];
		ans+=9*(n-1);
		
	}else if(k==2){
		/*
		ans+=p[1];
		ans+=9*(n-2);
		ans+=(p[0]-1)*9*(n-1);
		ans+=81*(n-1)*(n-2)/2;
		*/
		jud=0;
		ans=81*n*(n-1)/2;
		ans-=9*(9-p[0])*(n-1);
		for(i=1; i<n && jud==0; i++){
			ans-=(9-p[i]);
			if(p[i]>0){
				jud++;
			}
		}
	}else{
		i1=-1; i2=-1;
		ans+=(p[0]-1)*81*(n-1)*(n-2)/2;
		for(i=1; i<n && i1==-1; i++){
			if(p[i]>0){
				i1=i;
			}
		}
		for(i=i1+1; i<n && i2==-1; i++){
			if(p[i]>0){
				i2=i;
			}
		}
		if(i2!=-1){
			ans+=p[i2];
			ans+=9*(n-i2-1);
		}
		if(i1!=-1){
			ans+=81*(n-i1-1)*(n-i1-2)/2;
		}
		ans+=729*(n-1)*(n-2)*(n-3)/6;
		ans+=(p[i1]-1)*9*(n-i1-1);
		/*
		ans+=p[2];
		ans+=9*(n-3);
		ans+=9*(p[1]-1)*(n-2);
		
		ans+=81*(p[0]-1)*(n-1)*(n-2)/2;
		
		ans+=729*(n-1)*(n-2)*(n-3)/6;
		
		jud=0;
		ans=729*n*(n-1)*(n-2)/6;
		ans-=81*(9-p[0])*(n-1)*(n-2)/2;
		for(i=1; i<n && jud==0; i++){
			ans-=9*(9-p[i])*(n-i-1);
			if(p[i]>0){
				jud++;
			}
		}
		*/
		
	}
	cout << ans;
	
	
}

Measured memory_bytes: 256
#include <valarray>
#include <cstdio>
using namespace std;
typedef valarray<int>V;
int n,m,t;
V e,x,z,w;
void M(const V &_x,const V &_y){
	int i=0,j;
	if(t&1){
		for(;i<n;i++)for(j=0;j<n;j++)z[i*n+j]=(_x[slice(i*n,n,1)]*_y[slice(j,n,n)]).sum()%m,w[i*n+j]=(_y[slice(i*n,n,1)]*_y[slice(j,n,n)]).sum()%m;
		swap(e,z);
	}else{
		for(;i<n;i++)for(j=0;j<n;j++)w[i*n+j]=(_y[slice(i*n,n,1)]*_y[slice(j,n,n)]).sum()%m;
	}
	swap(x,w);
}
void O(const V &r,const V &s){
	int i=0;
    for(;i<n-1;i++)printf("%d ",(r[slice(i*n,n,1)]*s).sum()%m);
    printf("%d\n",(r[slice(i*n,n,1)]*s).sum()%m);
}
main(){
	int i,a,b,c;
	for(;scanf("%d%d%d%d%d%d",&n,&m,&a,&b,&c,&t),n;){
		x.resize(0);
		x.resize(n*n);
		e.resize(0);
		e.resize(n*n);
		z.resize(n*n);
		w.resize(n*n);

		x[0]=b;
		x[1]=c;
		e[0]=1;
		for(i=1;i<n-1;i++){
			x[i*n+i-1]=a;
			x[i*n+i]=b;
			x[i*n+i+1]=c;
			e[i*n+i]=1;
		}
		x[i*n+i-1]=a;
		x[i*n+i]=b;
		e[i*n+i]=1;
		for(;t;t>>=1)M(e,x);
		V s(n);
		for(i=0;i<n;i++)scanf("%d",&s[i]);
		O(e,s);
	}
}

Measured memory_bytes: 1108
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
using namespace std;

#define FOR(i,f,t) for(int i=(int)f; i<(int)t; i++)
#define FORR(i,f,t) for(int i=(int)f; i>(int)t; i--)
#define ms(obj, val) memset(obj, val, sizeof(obj))
#define pb push_back
#define SYNC ios_base::sync_with_stdio(false)
#define inf 2248012
#define mp make_pair
#define F first
#define S second
#define ri(x) scanf("%d",&x)
#define rii(x,y) scanf("%d %d",&x,&y)
#define riii(x,y,z) scanf("%d %d %d",&x,&y,&z)
#define lri(x) scanf("%lld",&x)
#define lrii(x,y) scanf("%lld %lld",&x,&y)
#define lriii(x,y,z) scanf("%lld %lld %lld",&x,&y,&z)

typedef vector<int> vi;
typedef long long ll;
typedef pair<int, int> ii;

const int MAXN = 5e3+3; //AREGLAAAAAAAAR!!!!
int a[101];
int main(){
	int n;
	ri(n);
	FOR(i,0,n) ri(a[i]);
	sort(a,a+n,greater<int>());
	int y=1,ans=0,ans2=0;
	FOR(i,0,n){
		if(i%2) ans2+=a[i];
		else ans+=a[i];
	} 
	printf("%d\n",ans-ans2);


}

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

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

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

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

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


	int ans = -1;
	for (int i = 1; i*i <= m; i++) {
		if (m%i != 0)continue;

		int j = m / i;

		if (i >= n) {
			ans = max(ans, j);
		}

		if (j >= n) {
			ans = max(ans, i);
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;

namespace CSharp
{
    static class Program
    {
        static void Main(string[] args)
        {
            ReadString();
            string s = ReadString();

            int ans = 0;
            for (int i = 0; i < s.Length - 2; i++)
            {
                if (s.Substring(i, 3) == "ABC")
                {
                    ans++;
                }
            }

            Console.WriteLine(ans);
        }

        #region Helpers

        static int[] ReadIntArray() => Console.ReadLine().Split().Select(s => int.Parse(s)).ToArray();
        static long[] ReadLongArray() => Console.ReadLine().Split().Select(s => long.Parse(s)).ToArray();

        static int[] ReadLineIntArray(int count) => Enumerable.Repeat(0, count).Select(_ => int.Parse(Console.ReadLine())).ToArray();
        static long[] ReadLineLongArray(int count) => Enumerable.Repeat(0, count).Select(_ => long.Parse(Console.ReadLine())).ToArray();

        static string ReadString() => Console.ReadLine();
        static int ReadInt() => int.Parse(Console.ReadLine());
        static long ReadLong() => long.Parse(Console.ReadLine());

        static void ReadInt(out int first)
        {
            var array = ReadIntArray();
            first = array[0];
        }

        static void ReadInt(out int first, out int second)
        {
            var array = ReadIntArray();
            first = array[0];
            second = array[1];
        }

        static void ReadInt(out int first, out int second, out int third)
        {
            var array = ReadIntArray();
            first = array[0];
            second = array[1];
            third = array[2];
        }

        static void ReadInt(out int first, out int second, out int third, out int fourth)
        {
            var array = ReadIntArray();
            first = array[0];
            second = array[1];
            third = array[2];
            fourth = array[3];
        }

        static void ReadLong(out long first)
        {
            var array = ReadLongArray();
            first = array[0];
        }

        static void ReadLong(out long first, out long second)
        {
            var array = ReadLongArray();
            first = array[0];
            second = array[1];
        }

        static void ReadLong(out long first, out long second, out long third)
        {
            var array = ReadLongArray();
            first = array[0];
            second = array[1];
            third = array[2];
        }

        static void ReadLong(out long first, out long second, out long third, out long fourth)
        {
            var array = ReadLongArray();
            first = array[0];
            second = array[1];
            third = array[2];
            fourth = array[3];
        }

        #endregion
    }
}

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

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define co(x) cout << (x) << "\n"
#define pb push_back
#define Never
#define To

using namespace std;

int main(){

	cin.tie(0);
	ios::sync_with_stdio(false);


	string S;
	int win = 0;

	cin >> S;

	for(int i =0; i < S.size(); i++){
		if( S[i] == 'o') win++;
	}

	win += 15 - S.size();

	if(win >= 8){
		cout << "YES" << endl;
	} else {
		cout << "NO" << endl;
	}

	Never To return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
const int maxn = 4e5 + 7;
const double pi = acos(-1);

int main(){
	int a,b;
	cin >> a >> b;
	int fl = 1;
	for(int i = 1;i <= 1250;i++){
		if((int)(i*0.08) == a && (int)(i*0.1)==b){
			cout << i << endl;
			fl = 0;
			break;
		}
	}
	if(fl) cout << -1 << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
#define inRange(x,a,b) (a <= x && x <= b)

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

    while(t-- > 0){
        int x, y, w, h;
        cin >> x >> y >> w >> h;
        int n;
        cin >> n;
        int a, b, cnt = 0;
        while(n-- > 0){
            cin >> a >> b;
            if(inRange(a, x, x+w) && inRange(b, y, y+h))    cnt++;
        }
        cout << cnt << endl;
    }

    return 0;
}


Measured memory_bytes: 3004
N,M=map(int, input().split())
X=list(map(int, input().split()))
if N>=M:
    print(0)
    exit()

X=sorted(X)

L=[]
for i in range(len(X)):
    L.append(abs(X[i]-X[i-1]))

print(sum(sorted(L)[:(M-N)]))


Measured memory_bytes: 13968
# -*- coding: utf-8 -*-
import itertools

N = int(input())
P_tuple = tuple(list(map(int, input().split())))
Q_tuple = tuple(list(map(int, input().split())))

N_list = [i for i in range(1, N + 1)]
ans = 0
counter = 0
if P_tuple == Q_tuple:
    print(0)
else:
    for v_tuple in itertools.permutations(N_list):
        counter += 1
        if P_tuple == v_tuple:
            ans -= counter
        elif Q_tuple == v_tuple:
            ans += counter
    print(abs(ans))

Measured memory_bytes: 3064
#include<stdio.h>
#include<algorithm>
#include<string.h>

#define rep(i,j) for(int i=0;i<(j);i++)
#define reps(i,j,k) for(int i=j;i<=k;i++)

using namespace std;


int main(){
	char k[11];
	int n,cnt=0;;
	char s[21];
	size_t l=sizeof(char)*10;
	scanf("%s%d",k,&n);
	rep(i,n){
		scanf("%s",s);
		memcpy(s+10,s,l);
		if(strstr(s,k)!=NULL)cnt++;
	}
	printf("%d\n",cnt);
	return 0;
}

Measured memory_bytes: 1032
def main():
    from sys import setrecursionlimit, stdin, stderr
    from os import environ
    from collections import defaultdict, deque, Counter
    from math import ceil, floor
    from itertools import accumulate, combinations, combinations_with_replacement
    setrecursionlimit(10**6)
    dbg = (lambda *something: stderr.write("\033[92m{}\033[0m".format(str(something)+'\n'))) if 'TERM_PROGRAM' in environ else lambda *x: 0
    input = lambda: stdin.readline().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    P = 10**9+7
    INF = 10**18+10

    N = II()
    C = list(input())
    l = 0
    r = N-1
    ans = 0
    while l < r:
        while C[l] != 'W' and l < N-1:
            l += 1
        while C[r] != 'R' and 0 < r:
            r -= 1
        if l < r:
            ans += 1
            l += 1
            r -= 1
        else:
            break
    print(ans)

    
main()

Measured memory_bytes: 77688
//long long -> ll
//http://web.mit.edu/~ecprice/acm/acm08/notebook.html#file12
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#include<bits/stdc++.h>
typedef long long ll;
#define x first
#define y second
#define all(aaa) (aaa).begin(),(aaa).end()
#define REP(i,sss,eee) for(long long i=sss;i<=eee;++i)
#define pb push_back
#define pii pair<long long,long long>
#define vi vector<long long>
#define speed ios_base::sync_with_stdio(0);cin.tie(0);
#define N 1000000007
using namespace __gnu_pbds;
using namespace std;
template <class T>
T MAX(T a, T b){return ((a>b)?a:b);}
template <class T>
T MIN(T a, T b){return ((a<b)?a:b);}
template <class T>
T MOD(T a){return ((a>=0)?a:(-1*a));}
template <class T>
void SWAP(T &a,T &b){T temp=a;a=b;b=temp;}

typedef tree<
long long,
null_type,
less<long long>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;

long long ex(long long a, long long b){
	if(b==0||a==1){return 1;}
	if(a==0||b==1){return a;}
	long long tmp=ex(a,(b/2));
	if(b%2){return ((((tmp*tmp)%N)*a)%N);}
	else{return ((tmp*tmp)%N);}
}
long long inv(long long k){
	if(k==1){return 1;}
	else{return ex(k,N-2);}
}
/*****************default********************/
std::vector<std::vector<long long>> inp;
std::vector<long long> dp,cost;
long long solve()
{
	long long n;cin>>n;
	inp.resize(n,std::vector<long long>(n,0));
	REP(i,0,n-1)
	{
		REP(j,0,n-1)
		{
			cin>>inp[i][j];
		}
	}
	long long lim=((1<<n)-1);
	dp.resize((1<<n)+1,0);
	cost.resize(((1<<n)+1),0);
	REP(i,0,lim)
	{
		REP(j,0,n-1)
		{
			REP(k,j+1,n-1)
			{
				if(((i>>j)&1) && ((i>>k)&1))
				{
					cost[i]+=inp[j][k];
				}
			}
		}
	}
	REP(pres,0,lim)
	{
		for(long long j=pres;j>=0;j=pres&(j-1))
		{
			long long com=(j^pres);
			dp[pres]=MAX(dp[pres],(cost[com]+dp[j]));
			if(j==0){break;}
		}
	}
	cout<<dp[lim]<<"\n";
}
signed main(){
	speed
	long long tt=1;
	//cin>>tt;
	while(tt--)
	{
		solve();
	}
	return 0;
}

Measured memory_bytes: 1280
X,Y,A,B,C=map(int,input().split())
p=list(map(int,input().split()))
q=list(map(int,input().split()))
r=list(map(int,input().split()))
from collections import deque

p.sort()
p=p[len(p)-X:]
q.sort()
q=q[len(q)-Y:]
r.sort(reverse=True)
p=deque(p)
q=deque(q)

for i in r:
  if min(p[0],q[0])>i:break
  if p[0]<q[0]:
    p.popleft()
    p.append(i)
  else:
    q.popleft()
    q.append(i)
print(sum(p)+sum(q))


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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
#define LINF 1e18
typedef long long ll;

int main() {
    int Q; cin >> Q;
    vector<ll> A;
    priority_queue<ll> left;
    priority_queue<ll, vector<ll>, greater<ll> > right;
    left.push(-LINF);
    right.push(LINF);
    ll l_sum = 0;
    ll r_sum = 0;
    ll sum = 0;
    REP(i,Q){
        int q; cin >> q;
        if(q==1){
            ll a,b; cin >> a >> b;
            if(left.size() > right.size()){
                ll t = left.top();
                if(a >= t){
                    right.push(a); r_sum += a;
                }else{
                    left.pop(); l_sum -= t;
                    left.push(a); l_sum += a;
                    right.push(t); r_sum += t;
                }
            }else{
                ll t = right.top();
                if(a <= t){
                    left.push(a); l_sum += a;
                }else{
                    right.pop(); r_sum -= t;
                    right.push(a); r_sum += a;
                    left.push(t); l_sum += t;
                }
            }
            
            sum += b;

        }else{
            ll x = left.top();
            ll l = x*(left.size()-1) - l_sum;
            ll r = r_sum - x*(right.size()-1);
            cout << x << " " <<  l + r + sum << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 5004
/*
    飲んだ魔剤で家が建つ。
    created at: 2020-04-18 10:51:04
*/

#include <bits/stdc++.h>
using namespace std;

#define all(x) (x).begin(),(x).end()
#define rev(x) greater<x>()
#define MOD 1000000007
#define INF 1000000000

typedef long long LL;
typedef long double LD;

bool compare_by_b(pair<int, int> a, pair<int, int> b)
{
    if (a.second != b.second) {
        return a.second < b.second;
    } else {
        return a.first < b.first;
    }
}

LL modpower(LL n, LL m, LL mod)
{
    if (m == 0) {
        return 1;
    } else if (m % 2 == 0) {
        LL p = modpower(n, m/2, mod);
        return p*p % mod;
    } else {
        return n*modpower(n, m-1, mod) % mod;
    }
}

LL modinv(LL n, LL mod)
{
    return modpower(n, mod-2, mod);
}

LL modcombination(LL n, LL r, LL mod)
{
    LL ret = 1;

    for (int i = 0; i < r; i++) {
        ret *= (n-i);
        ret %= mod;
        ret *= modinv(i+1, mod);
        ret % mod;
    }

    return ret % mod;
}

int gcd(int k, int l)
{
    if (l > 0) return gcd(l, k%l);
    else return k;
}

struct UnionFind
{
    vector<int> par;

    UnionFind(int n) : par(n) {
        for (int i = 0; i < n; i++) par[i] = i;
    }

    int root(int x) {
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return;
        par[rx] = ry;
    }

    bool same(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main()
{
    string s;
    cin >> s;
    int n = s.length();

    cout << s[0] << n-2 << s[n-1] << endl;

    return 0;
}


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

int  main()
{
	int n; cin >> n;
	int k; cin >> k;
	vector <int> a(n);
	rep(i, n) cin >> a[i];
	rep(j, k)
	{
		vector <int> b(n+1);
		rep(i, n)
		{
			int l = max(i-a[i], 0);
			int r = min(i+a[i], n-1);
			b[l]++;
			if (r < n+1)
				b[r+1]--;
		}
		for(int i = 1; i < n; i++)
			b[i] += b[i-1];
		if (a == b)
			break;
		a = b;
	}
	rep(i, n)
		cout << a[i] << " ";
	cout << endl;
	return (0);
}

Measured memory_bytes: 5616
#include "bits/stdc++.h"
#include "math.h"
#include "string.h"
#include "algorithm"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SIZE(a) int((a).size())

int main(){
  ll n,ans=0;
  cin>>n;
  vll x(n);
  REP(i,n){
    cin>>x[i];
    x[i]--;ans+=x[i];
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
S = input()

f = False

i = 0

words = []


while(i < len(S)-1):
    if(S[i] == S[i+1]):
        if(f == False):
            if(i < len(S)-2):
                words.append(S[i])
                words.append(S[i+1]+S[i+2])
            else:
                words.append(S[i] + S[i+1])
            f = True
        else:
            words.append(S[i] + S[i+1])
    else:
        words.append(S[i])

    if(f):
        i += 3
        f = False
    else:
        i += 1

if(i == len(S)-1):
    print(len(words)+1)
else:
    print(len(words))




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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep_r(i, n) for(int i = n-1; i >= 0; i--)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((ll)(x).size())
#define bit(n) (1LL<<(n))
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define INF bit(60)
#define pb push_back
#define mod 1000000007

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; }

using namespace std;
using uif=uint_fast64_t;
using ll=long long int;
using tTree=__gnu_pbds::tree< ll , __gnu_pbds::null_type, less< ll >, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;

int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mod;a=1ll*a*a%mod;}while(b>>=1);return ans;}
int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};


#define FACSIZE 2002

ll invfac[FACSIZE];
ll fac[FACSIZE];

ll mod_pow(ll ,ll );
ll mod_add(ll ,ll );
ll mod_mul(ll ,ll );
ll mod_div(ll ,ll );
void make_fact(ll );
void make_invfact(ll );

//unordered_map<string,ll> um;

int main(void){

  string s;
  cin>>s;
  ll n=s.size();
  bool cont=false;
  char prev=-1;
  ll num_A=0;
  ll ans=0;
  for(ll i=0;i<n;i++){
    auto c=s[i];
    
    if(c=='A'&&prev=='B'){
      num_A=1;
    }
    else if(c=='A'){
      num_A++;
    }
    else if(c=='C'&&prev=='B'){
      ans+=num_A;
    }
    else if(c=='C'&&prev!='B'){
      cont=false;
      num_A=0;
    }
    else if(c=='B'&&prev=='B'){
      cont=false;
      num_A=0;
    }
    prev=c;
  }

  cout << ans << endl;

  return 0;

}

ll mod_pow(ll x,ll r){
  if(r==0) return 1;
  else if(r==1) return x%mod;
  else if(r%2==0){
    ll t=mod_pow(x,r/2)%mod;
    return t*t %mod;
  } 
  else{
    ll t=mod_pow(x,r/2)%mod;
    ll k= t*t %mod;
    return k*x%mod;
  } 
}
ll mod_add(ll a,ll b){
  return (a+b)%mod;
}

ll mod_mul(ll a,ll b){
  return (a*b)%mod;
}

ll mod_div(ll a,ll b){
  return mod_mul(a,mod_pow(b,mod-2));
}

void make_fact(ll n){
  fac[0]=1;
  rep(i,n){
    fac[i+1]=mod_mul(fac[i],i+1);
  }  
}

void make_invfact(ll n){
  invfac[n]= mod_pow( fac[n] ,mod-2);
  for(int i=n-1;i>=0;i--){
    invfac[i]=mod_mul(invfac[i+1],i+1);
  }

}

Measured memory_bytes: 640