akhauriyash/Code-Regression huggingface dataset:
#define debug_interval ','
#define dump_interval ' '
#define debug_toggle 1
//{
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define INT_MAX LLONG_MAX
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define fi first
#define se second
#define mp make_pair
#define rev reverse
#define dans dump(ans)
#define MOD 1000000007
#define amp(v,n) (v).count(n)?v[n]++:v[n]=1;
#define cni cin

//{
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();}
template<class...A> inline void dump(){cout<<endl;}
template<class...A> inline void dump_rest() {cout<<endl;}
template<class T, class...A> inline void dump_rest(const T& first, const A&... rest){cout<<dump_interval<<first;dump_rest(rest...);}
template<class T,class...A> inline void dump(const T&first,const A&...rest){cout<<first;dump_rest(rest...);}
template<class...A> inline void debug(){cerr<<endl;}
template<class...A> inline void debug_rest() {cerr<<endl;}
template<class T, class...A> inline void debug_rest(const T& first, const A&... rest){cerr<<debug_interval<<first;debug_rest(rest...);}
template<class T,class...A> inline void debug(const T&first,const A&...rest){if(debug_toggle)cerr<<first,debug_rest(rest...);}
//}

typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}
template<int m>class mint{private:int i;public:mint() : i(0){}mint(int i): i((i%m+m)%m){}mint operator+(const mint& o){return o.i+i;}mint operator*(const mint& o){return o.i*i;}mint operator-(){return -i;}operator int() {return i;}};

//}

string s;
int rq[111111],lq[111111],a[111111]/*cb[111111]*/,c[111111],ans,tb[111111];



main(){
    tb[0]=1;
    for(int i=1;i<111111;i++){
        tb[i]=tb[i-1]*3;
        tb[i]%=MOD;
    }
    cin>>s;
    int n=s.size();
    for(int i=1;i<n;i++){
        if(s[i-1]=='A')a[i]++;
        //if(s[i]=='B')cb[i]++;
        if(s[n-i]=='C')c[n-i-1]++;
        if(s[i-1]=='?')lq[i]++;
        if(s[n-i]=='?')rq[n-i-1]++;
        a[i]+=a[i-1];
        c[n-i-1]+=c[n-i];
        lq[i]+=lq[i-1];
        rq[n-i-1]+=rq[n-i];
    }
    /*rep(i,n)cout<<a[i]<<' ';
    cout<<endl;
    rep(i,n)cout<<c[i]<<' ';
    cout<<endl;
    rep(i,n)cout<<lq[i]<<' ';
    cout<<endl;
    rep(i,n)cout<<rq[i]<<' ';
    cout<<endl;
    rep(i,n)cout<<tb[i]<<' ';
    cout<<endl;*/
    if(rq[0]<10){
        rep(i,n){
            if(s[i]=='B'||s[i]=='?'){
                ans+=(((tb[lq[i]+rq[i]]%MOD*(3*a[i]+lq[i])%MOD*(3*c[i]+rq[i])%MOD))/9);
                ans%=MOD;
            }
        }
    }else{
        rep(i,n){
            if(s[i]=='B'||s[i]=='?'){
                ans+=((tb[lq[i]+rq[i]-2]%MOD*(3*a[i]+lq[i])%MOD*(3*c[i]+rq[i])%MOD));
                ans%=MOD;
            }
        }
    }
    dans;
}




Measured memory_bytes: 4608
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int a, b, n;
    cin >> a >> b >> n;
    for (int i = 0; i < n; ++i) {
        int c, d;
        cin >> c >> d;
        if(max(a, c) < min(b, d)) {
            puts("1");
            return 0;
        }
    }
    puts("0");
    return 0;
}


Measured memory_bytes: 3096
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	double R; cin>>R; cout<<setprecision(10)<<fixed<<2*2*acos(0)*R<<endl;
	return 0;
}


Measured memory_bytes: 3804
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <tuple>
#include <algorithm>
#include <array>
using namespace std;
using ll = long long;
#define rep(i,n) for(decltype(n) i=0; i<n; ++i)
inline constexpr ll Inf = (1ULL << 62) -1;

template <class T>
void updatemax(T& a, T b) { if (b > a) a = b; }

int main() {
    ll N, K;
    cin >> N >> K;
    vector<ll> pv,nv;
    bool negative = true;
    rep(i,N) {
        ll a;
        cin >> a;
        if (a >= 0) {
            negative =false;
            pv.push_back(a);
        } else {
            nv.push_back(a);
        }
    }
    const ll modulo = (ll)1e9+7;
    ll ans=1;
    if (N == K) {
        rep(i,pv.size()) {
            ans *= pv[i];
            ans %= modulo;
        }
        rep(i,nv.size()) {
            ans *= nv[i];
            ans %= modulo;
        }
        if (ans < 0)
            ans += modulo;
        cout << ans << endl;
        return 0;
    }
    if (negative && K % 2 == 1) {
        sort(nv.rbegin(), nv.rend());
        rep(i,K) {
            ans *= nv[i];
            ans %= modulo;
        }
        if (ans < 0)
            ans += modulo;
        cout << ans << endl;
        return 0;
    }
    sort(pv.begin(), pv.end());
    sort(nv.begin(), nv.end());
    vector<ll> tmp;
    for (size_t i=0; i+1<nv.size(); i+=2) {
        auto t = nv[i] * nv[i+1];
        tmp.push_back(t);
    }
    nv.swap(tmp);
    reverse(nv.begin(), nv.end());
    
    while (K > 0) {
        if (nv.empty()) {
            ans *= pv.back();
            pv.pop_back();
            --K;
        } else if (pv.empty()) {
            ans *= nv.back() % modulo;
            nv.pop_back();
            K -= 2;
        } else {
            ll pm = pv.back();
            if (pv.size() >= 2) {
                pm *= pv[pv.size()-2];
            }
            if (pm > nv.back() || K == 1) {
                ans *= pv.back();
                pv.pop_back();
                --K;
            } else {
                ans *= nv.back() % modulo;
                nv.pop_back();
                K -= 2;
            }
        }
        ans %= modulo;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 6116
# -*- coding: utf-8 -*-

def comb(n,k,p):
  """power_funcを用いて(nCk) mod p を求める"""
  from math import factorial
  if n<0 or k<0 or n<k: return 0
  if n==0 or k==0: return 1
  a=factorial(n) %p
  b=factorial(k) %p
  c=factorial(n-k) %p
  return (a*power_func(b,p-2,p)*power_func(c,p-2,p))%p
def power_func(a,b,p):
  """a^b mod p を求める"""
  if b==0: return 1
  if b%2==0:
    d=power_func(a,b//2,p)
    return d*d %p
  if b%2==1:
    return (a*power_func(a,b-1,p ))%p

s = int(input())
ans = 0
n = s//3
p = 10**9+7
for i in range(1,n+1):
  ans = (ans+comb(s-i*2-1,s-i*3,p))%p
print(ans)

Measured memory_bytes: 9268
#include<bits/stdc++.h>
using namespace std;
#define maxn 200020
#define rep(i,l,r) for(register int i = l ; i <= r ; i++)
#define repd(i,r,l) for(register int i = r ; i >= l ; i--)
#define rvc(i,S) for(register int i = 0 ; i < (int)S.size() ; i++)
#define rvcd(i,S) for(register int i = ((int)S.size()) - 1 ; i >= 0 ; i--)
#define fore(i,x)for (register int i = head[x] ; i ; i = e[i].next)
#define pb push_back
#define prev prev_
#define stack stack_
#define mp make_pair
#define fi first
#define se second
#define inf 0x3f3f3f3f
typedef long long ll;
typedef pair<int,int> pr;

int a[maxn],n;
ll ans;

int main(){
	scanf("%d",&n);
	rep(i,1,n) scanf("%d",&a[i]) , a[i] -= i;
	sort(a + 1,a + n + 1);
	int b = a[(n + 1) / 2];
	rep(i,1,n) ans += abs(b - a[i]);
	cout<<ans<<endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std ; 
long long int dp[20005];  

//this is lis ka hee modifcation and this is an o(n^2) solution. 
// this will give tle as n-> 10^5. //therefire we need to have  o(nlogn)solutioon
long long int solve(int n,long long int h[],long long int b[]){
   dp[1] = b[1] ; //max sum of beauties of a subseq ending at 1.  
   for(int i = 2 ; i<=n  ;i++){
       dp[i] =b[i] ;
   }
   for(int i= 2 ; i<=n; i++)
{   
    for(int j = 1; j<=i-1; j++){
     if(h[i]>h[j]){
         dp[i] = max(dp[i],b[i]+dp[j]) ; 
     }   
    }
} 
 return *max_element(dp+1,dp+n+1) ; 
}

//o(nlogn) 
struct flower{
    long long int h ; long long int b ; 
};
long long solve_better(vector<flower>& v,int n){
       vector<long long > dp(n+1); 
       map<long long int,long long int>meaningful ; 
       dp[1] = v[1].b ;  
       meaningful[v[1].h] = dp[1] ; //inserted into the map . 
      long long int ans  = dp[1];
      for(long long int i = 2 ; i<=n; i++){
            dp[i] = v[i].b ; 
            auto it = meaningful.lower_bound(v[i].h + 1) ; 
            if(it!=meaningful.begin()){
               it-- ; 
               dp[i] += it->second ; 
            }
            meaningful[v[i].h] = dp[i] ; 
           
           auto it2 = meaningful.upper_bound(v[i].h) ; 
           while(it2!=meaningful.end() && it2->second<=dp[i]){
               auto temp = it2 ; 
               temp++ ; 
               meaningful.erase(it2) ; 
               it2 = temp ; 
           }
          ans = max(ans,dp[i]) ; 
       }

return ans ; 

}
int main(){
    long long int n ; cin>>n ; 
    vector<flower> v(n+1);
    for(int i = 1 ; i<=n ; i++){
        cin>>v[i].h ;
    }
    for(int i = 1 ; i<=n ; i++){
        cin>>v[i].b  ; 
    }
    cout<<solve_better(v,n); 
}

Measured memory_bytes: 17408
#include<cstdio>
using namespace std;
static const int MAX_V = 10;
static const int MAX_E = 45;
static const int INFTY = (1 << 21);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n, M[MAX_V][MAX_V];

int dijkstra(int s){
	int mincost;
	int d[MAX_V], color[MAX_V];

	for(int i = 0; i < MAX_V; i++){
		d[i] = INFTY;
		color[i] = WHITE;
	}

	d[s] = 0;
	color[s] = GRAY;
	while(true){
		int u;
		mincost = INFTY;
		for(int i = 0; i < MAX_V; i++){
			if(mincost > d[i] && color[i] != BLACK){
				u = i;
				mincost = d[i];
			}
		}

		if(mincost == INFTY) break;

		color[u] = BLACK;

		for(int v = 0; v < MAX_V; v++){
			if(color[v] != BLACK && M[u][v] != INFTY){
				if(d[v] > d[u] + M[u][v]){
					d[v] = d[u] + M[u][v];
					color[v] = GRAY;
				}
			}
		}
	}
	int sum_d = 0;
	for(int i = 0; i < MAX_V; i++){
		if(d[i] != INFTY){
			sum_d += d[i];
		}
	}
	return sum_d;
}

int main(void){
	while(true){
		scanf("%d", &n);
		if(n == 0) break;

		for(int i = 0; i < MAX_V; i++){
			for(int j = 0; j < MAX_V; j++){
				M[i][j] = INFTY;
			}
		}

		for(int i = 1; i <= n; i++){
			int a, b, c;
			scanf("%d %d %d", &a, &b, &c);
			M[a][b] = M[b][a] = c;
		}

		int min_v, min_d = INFTY;
		for(int i = 0; i < MAX_V; i++){
			int dist = dijkstra(i);
			//printf("%d %d\n", i, dist);
			if(dist < min_d && dist != 0){
				min_d = dist;
				min_v = i;
			}
		}

		printf("%d %d\n", min_v, min_d);
	}

	return 0;
}

Measured memory_bytes: 2708
N, M = map(int, input().split())

store_list = []
min_cost = 0

for n in range(N):
    a, b = map(int, input().split())
    store_list.append([a,b])

store_list = sorted(store_list,key=lambda x:(x[0],x[1]))

for sl in store_list:
    if M - sl[1] >= 0:
        min_cost += sl[0]*sl[1]
        M = M - sl[1]
    else:
        min_cost += sl[0]*M
        break

print(min_cost)

Measured memory_bytes: 28372
/*
  AOJ 1118
  Title:Net of a dice
  @kankichi573
*/
#include <stdio.h>
#include <string.h>
#define mysign(x) (((x)>0)?1:(-1))
#define myabs(x)  (((x)>0)?(x):(-(x)))
int n;
int net[11][11];


void search_pos(int me,int *y,int *x)
{
  int i,j;

  for(i=3;i<8;i++)
    for(j=3;j<8;j++)
      if(net[i][j]==me)
	{
	  *y=i;*x=j;
	  return;
	}
  *x=*y=-1;
}
/*
  check relative position of dice whose added value is 7. 

   1  1   1   1    1*6 1*  1*  1*
   *  **  *** ****      *6  *   *
   6   6    6    6          *6  * 
                                *6

   where * is 2,3,4,5
 */
int ck_rel_pos(int y,int x,int y_,int x_)
{
  int i,j,ret;
#ifdef DEBUG
  printf("yxyx=%d %d %d %d\n",y,x,y_,x_);
#endif
  if(y+2==y_)
    {
      for(i=-3;i<=3;i++)
	{
	  if(x_==x+i)
	    {
	      ret=-1;
	      for(j=0;myabs(j)<=myabs(i);j+=mysign(i))
		{
#ifdef DEBUG
		  printf("ck* %d %d:%d\n",y+1,x+j,net[y+1][x+j]);
#endif
		  ret &= (net[y+1][x+j]!=0);
		}
	      if(ret)
		return(-1);
	    }
	}
    }
  if(x+2==x_)
    {
      for(i=-3;i<=3;i++)
	{
	  if(y_==y+i)
	    {
	      ret=-1;
	      for(j=0;myabs(j)<=myabs(i);j+=mysign(i))
		{
#ifdef DEBUG
		  printf("ck: %d %d:%d\n",y+j,x+1,net[y+j][x+1]);
#endif
		  ret &= (net[y+j][x+1]!=0);
		}
	      if(ret)
		return(-1);
	    }
	}
     }
  return(0);
}

int count_dice()
{
  int i,j,ret;

  ret=0;
  for(i=3;i<8;i++)
    for(j=3;j<8;j++)
      if(net[i][j])
	ret++;
  return(ret);
}


int solve()
{
  int i,ret[7];
  int posx[7],posy[7];

  if(count_dice()!=6)
    return(0);

  for(i=1;i<=6;i++)
    {
      search_pos(i,&posy[i],&posx[i]);
      if(posy[i]==-1)
	return(0);
    }
  for(i=1;i<=6;i++)
    ret[i]=ck_rel_pos(posy[i],posx[i],posy[7-i],posx[7-i]);
 #ifdef DEBUG2
 for(i=1;i<=6;i++)
   printf("[%d]%d|",i,ret[i]);
 printf("\n");
 #endif
  return((ret[1]||ret[6]) && (ret[2]||ret[5]) && (ret[3]||ret[4]));
}
main()
{
  int i,j,k,ret;

  scanf("%d",&n);
  for(i=0;i<n;i++)
    {
      memset(&net[0][0],0,11*11);
      
      for(j=0;j<5;j++)
	for(k=0;k<5;k++)
	  scanf("%d",&net[j+3][k+3]);

      ret=solve();
      printf("%s\n",ret?"true":"false");
    }
  
  return(0);
}

Measured memory_bytes: 584
#include <bits/stdc++.h>
#define ___                      \
	ios::sync_with_stdio(false); \
	cin.tie(NULL);               \
	cout.tie(0);
#define endl '\n'
#define pii pair<int, int>
#define MAX INT_MAX
#pragma GCC optimize("Ofast")
#define int long long
const int MOD = (1e9 + 7);
using namespace std;
#define vvi vector<vector<int>>
const int mod = 998244353;

signed main()
{
	___ 
	int r; cin>>r;
cout<<3*r*r<<endl;	
}



Measured memory_bytes: 256
from collections import defaultdict
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

N = int(readline())
C = tuple(map(lambda x: int(x)-1, readline().split()))

temp = map(int,read().split())
temp = zip(temp,temp)

adj = [list() for _ in range(N)]
for a,b in temp:
    adj[a-1].append(b-1)
    adj[b-1].append(a-1)


parent = [None]*N
parent[0] = -1

stack = [0]
order = []
while stack:
    p = stack.pop()
    order.append(p)
    for c in adj[p]:
        if parent[c] is None:
            parent[c] = p
            stack.append(c)

def merge(a,b):
    if len(a) > len(b):
        a,b = b,a
    for k,v in a.items():
        b[k] += v
    return b

dp = [defaultdict(int) for _ in range(N)] # color-wise counter
subtreesize = [0]*N
cnt = [N*(N+1)//2]*N

for c in reversed(order):
    p = parent[c]
    if p >= 0:
        dp[c][C[c]] = subtreesize[c]+1
        x = subtreesize[c]-dp[c][C[p]]+1
        cnt[C[p]] -= x*(x+1)//2
        subtreesize[p] += subtreesize[c]+1

        dp[p] = merge(dp[c],dp[p])
        dp[c] = None

dp[0][C[0]] = subtreesize[0]+1
for c in range(N):
    x = subtreesize[0]-dp[0][c]+1
    cnt[c] -= x*(x+1)//2

print(*cnt, sep='\n')


Measured memory_bytes: 249684
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	for i := 1; i <= 9; i++ {
		for j := 1; j <= 9; j++ {
			if i*j == n {
				fmt.Println("Yes")
				return
			}
		}
	}
	fmt.Println("No")
}


Measured memory_bytes: 1768
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC126A
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int N = int.Parse(input[0]);
            int K = int.Parse(input[1]);
            string S = Console.ReadLine();

            char[] answer = new char[N];

            for (int i = 0; i < N; i++)
            {
                answer[i] = S[i];
            }

            if (answer[K-1]=='A')
            {
                answer[K-1] = 'a';
            }
            if (answer[K-1]=='B')
            {
                answer[K-1] = 'b';
            }
            if (answer[K-1]=='C')
            {
                answer[K-1] = 'c';
            }
            for (int i = 0; i < N; i++)
            {
                Console.Write(answer[i]);
            }


        }
    }
}


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

int main() {
	long long int A, B, N, C, D, sumA = 0;
	cin >> N >> A >> B;

	C = N / (A + B);
	D = N % (A + B);
	sumA = (C * A);

	if (A < N - ((A+B)*C))
		sumA += A;
	else
		sumA += N- ((A + B) * C);
	cout << sumA << endl;

}

Measured memory_bytes: 256
[m,n] = map(int,input().split())

def find(v,cs):
    for c in cities:
        if v in c:
            return (True,c)
    return (False,set([v]))

cities = []
for _ in range(n):
    [a,b] = map(int,input().split())

    (ra,fa) = find(a,cities)
    (rb,fb) = find(b,cities)

    mg = fa | fb

    if ra:
        cities.remove(fa)
    else:
        m = m - 1
    if rb:
        if fa != fb:
            cities.remove(fb)
    else:
        m = m - 1
    cities.append(mg)

print(abs(m-len(cities)))



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

#define fi first
#define se second

const int N = 1000011;
const long long mod = 1e9 + 7;

using namespace std;

int n;
int mx[N];
string s;

int solve(int B)
{
        int cur = 0, A = 0;
        for(int i = 0; i < n; i++){
                if(s[i] == '0'){
                        cur -= 1;
                } else if(s[i] == '1'){
                        cur += 1;
                } else{
                        if(cur + 1 + max(0, mx[i + 1]) > B){
                                cur -= 1;
                        } else{
                                cur += 1;
                        }
                }
                A = min(A, cur);
        }
        return B - A;
}

int main()
{
        ios_base::sync_with_stdio(0);

        //freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);

        cin >> s;
        n = s.size();

        for(int i = n - 1; i >= 0; i--){
                mx[i] = max(0, mx[i + 1]) + (s[i] == '1' ? 1 : -1);
        }

        int l = 0, r = n;
        for(int i = 0, cur = 0; i < n; i++){
                cur += (s[i] == '1' ? 1 : -1);
                l = max(l, cur);
        }

        int res = solve(l);
        for(int i = 1; i <= 40; i++){
                if(i + l <= n){
                        res = min(res, solve(i + l));
                }
        }

        while(l + 40 < r){
                int m = (r - l) / 3;
                int h1 = l + m, h2 = r - m;
                if(solve(h1) < solve(h2)){
                        r = h2;
                } else{
                        l = h1;
                }
        }
        while(l <= r){
                res = min(res, solve(l));
                l += 1;
        }

        cout << res << "\n";
}


Measured memory_bytes: 8272
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define debug(x) cout << #x << " = " << (x) << endl;
#define SUM(x) accumulate(rng(x),0)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = 1<<30;
const ll INFLL = 1LL<<60;
//cout << fixed << setprecision(10);

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

int main () {
  ll n, k;
  cin >> n >> k;
  if (k%2 == 0) {
    ll a = n/k;
    ll b = (n+(k/2))/k;
    cout << a*a*a + b*b*b << endl;
  }
  else {
    ll a = n/k;
    cout << a*a*a << endl;
  }
  return 0;
}

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


int main(){
    int x,y,a,b,c;
    cin >> x >> y >> a >> b >> c;
    vector<int> A(a),B(b),C(c);
    rep(i,a) cin >> A[i];
    rep(i,b) cin >> B[i];
    rep(i,c) cin >> C[i];

    sort(A.rbegin(),A.rend());
    sort(B.rbegin(),B.rend());
    sort(C.rbegin(),C.rend());

    multiset<int> m;
    rep(i,x) m.insert(A[i]);
    rep(i,y) m.insert(B[i]);

    rep(i,c){
        if(*m.begin()<C[i]){
            m.erase(m.begin());
            m.insert(C[i]);
        }else break;
    }
    ll ans = 0;
    for(auto it=m.begin();it!=m.end();it++){
        ans += *it;
    }

    cout << ans << endl;





 }

Measured memory_bytes: 12736
X, Y, Z, K = map(int, input().split())
A = sorted(list(map(int, input().split())), reverse=True)
B = sorted(list(map(int, input().split())), reverse=True)
C = sorted(list(map(int, input().split())), reverse=True)
#A~Cは降順でソート済み
lenA = X
lenB = Y
lenC = Z #分かりにくいので名前を変えただけ

AB = []

for i in range(0, min(K,lenA)):
  for j in range(0, min(K,lenB)):
      AB.append(A[i]+B[j])
AB.sort(reverse=True)

ABC = []

for j in range(0, min(K,len(AB))):
  for k in range(0, min(K,lenC)):
      ABC.append(AB[j]+C[k])
ABC.sort(reverse=True)

for i in range(K):
  print(ABC[i])


Measured memory_bytes: 147776
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main()
{
  string S;
  cin >> S;
  int r = 0;
  int b = 0;
  REP(i, S.length())
  {
    if (S[i] == '0')
      r++;
    else
      b++;
  }
  cout << 2 * min(r, b) << endl;
  return 0;
}

Measured memory_bytes: 512
using System;

class Program
{
    static void Main(string[] args)
    {
        var hw = Console.ReadLine().Split(' ');
        var h = int.Parse(hw[0]);
        var w = int.Parse(hw[1]);

        var s = new string[h];
        for (int i = 0; i < h; i++)
        {
            s[i] = Console.ReadLine();
        }

        var ans = new int[h, w];
        var dx = new[] { -1, 0, 1, -1, 1, -1, 0, 1, };
        var dy = new[] { -1, -1, -1, 0, 0, 1, 1, 1, };

        for (int i = 0; i < h; i++)
        {
            for (int j = 0; j < w; j++)
            {
                if (s[i][j] == '.')
                {
                    for (int k = 0; k < 8; k++)
                    {
                        var sy = i + dy[k];
                        var sx = j + dx[k];

                        if (0 <= sy && sy < h &&
                            0 <= sx && sx < w &&
                            s[sy][sx] == '#')
                        {
                            ans[i, j]++;
                        }
                    }
                }
            }
        }

        for (int i = 0; i < h; i++)
        {
            for (int j = 0; j < w; j++)
            {
                if (s[i][j] == '#')
                {
                    Console.Write('#');
                }
                else
                {
                    Console.Write(ans[i, j]);
                }
            }
            Console.WriteLine();
        }
    }
}


Measured memory_bytes: 13140
#include <algorithm>
#include <iostream>
using namespace std;
typedef long long ll;
typedef pair<ll, int> P;

int main()
{
    ll x, y, a[4]{0};
    cin >> x >> y >> a[1] >> a[2] >> a[3];
    for(int i = 1; i <= 3; i++) a[i] += a[i - 1];
    P p[300005];
    for(int i = 0; i < 3; i++){
        for(int j = a[i]; j < a[i + 1]; j++){
            ll q;
            cin >> q;
            p[j] = P(q, i);
        }
    }
    sort(p, p + a[3], greater<P>());
    int u[3]{0};
    ll ans = 0;
    for(int i = 0; i < a[3]; i++){
        if(u[0] + u[1] + u[2] == x + y) break;
        if(p[i].second == 0){
            if(u[0] < x){
                ans += p[i].first;
                u[0]++;
            }
        }
        else if(p[i].second == 1){
            if(u[1] < y){
                ans += p[i].first;
                u[1]++;
            }
        }
        else{
            ans += p[i].first;
            u[2]++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 4992
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

using namespace std;

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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v; return v;}

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector< vector<int> > Mat;
typedef tuple<int, int, int, int> T;

const int MOD = (int)1e9+7;
const int INF = (int)1e9;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

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

    int N;
    string s;
    cin >> N >> s;

    int r = 0, b = 0;
    rep(i, N){
        if(s[i] == 'R') r++;
        else b++;
    }

    if(b < r) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    vector<int> v={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int a;
    cin>>a;
    cout<<v[a-1]<<endl;
    return 0;



}


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

using namespace std;
using ll = long long;
using Pll = pair<ll, ll>;
constexpr int MOD = 1000000007;

int main() {
  int N;
  cin >> N;
  vector<vector<int>> G(N);
  for (int i = 0; i < N - 1; ++i) {
    int a, b;
    cin >> a >> b;
    G[a - 1].push_back(b - 1);
    G[b - 1].push_back(a - 1);
  }
  vector<ll> fact(N), factinv(N), inv(N);
  fact[0] = fact[1] = 1;
  factinv[0] = factinv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < N; ++i) {
    fact[i] = fact[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    factinv[i] = factinv[i - 1] * inv[i] % MOD;
  }
  function<ll(ll)> modinv = [&](ll x) {
    ll b = MOD, u = 1, v = 0;
    while (b) {
      ll t = x / b;
      x -= t * b;
      u -= t * v;
      swap(x, b);
      swap(u, v);
    }
    return (u + MOD) % MOD;
  };
  vector<map<int, Pll>> dp(N);
  function<Pll(int, int)> dfs = [&](int u, int par) {
    if (par != -1 && G[u].size() * 2 > N) dfs(u, -1);
    if (!dp[u].count(par)) {
      Pll ret = {1, 1};
      if (!dp[u].count(-1)) {
        for (int v : G[u]) {
          if (v != par) {
            Pll t = dfs(v, u);
            ret.first += t.first;
            ret.second = ret.second * t.second % MOD;
            ret.second = ret.second * factinv[t.first] % MOD;
          }
        }
        ret.second = ret.second * fact[ret.first - 1] % MOD;
      } else {
        ret = dp[u][-1];
        Pll t = dfs(par, u);
        ret.second = ret.second * factinv[ret.first - 1] % MOD;
        ret.second = ret.second * fact[t.first] % MOD;
        ret.first -= t.first;
        ret.second = ret.second * fact[ret.first - 1] % MOD;
        ret.second = ret.second * modinv(t.second) % MOD;
      }
      dp[u][par] = ret;
    }
    return dp[u][par];
  };
  for (int i = 0; i < N; ++i) cout << dfs(i, -1).second << endl;
  return 0;
}

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

int mx;

int main(void)
{
    string s;
    cin >> s;
    for(int i=1;i<=s.size();i++)
    {
        for(int j=0;j<=s.size()-i;j++)
        {
            int cnt=0;
            for(int k=j;k<=j+i-1;k++)
                if(s[k]=='A' || s[k]=='C' || s[k]=='G' || s[k]=='T')
                cnt++;
            if(cnt==i)
            {
                mx=max(cnt,mx);
            }
        }
    }
    cout << mx;
    return 0;
}

Measured memory_bytes: 256
N,M,C = map(int,input().split())
B = list(map(int,input().split()))
A = [0]*N
for i in range(N):
    A[i] = list(map(int,input().split()))
cnt = 0
for j in range(N):
    sum = 0
    for k in range(M):
        sum += A[j][k]*B[k]
    if sum+C > 0:
        cnt += 1
        
print(cnt)

Measured memory_bytes: 38384
#include <stdio.h>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>

using ll = long long int;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = 998244353ll;

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

int a,b;
bool done[3030][3030];
ll memo[3030][3030];
ll solve(int x, int y){
	if(done[x][y]){
		return memo[x][y];
	}
	done[x][y] = true;
	if(x==a && y==b){
		memo[x][y] = 1ll;
	}else if(x==a){
		memo[x][y] = solve(x,y-1)*x%MOD;
	}else if(y==b){
		memo[x][y] = solve(x-1,y)*y%MOD;
	}else{
		memo[x][y] = solve(x-1,y)*y%MOD;
		add_mod(memo[x][y],solve(x,y-1)*x%MOD);
		add_mod(memo[x][y],MOD-solve(x-1,y-1)*(x-1)%MOD*(y-1)%MOD);
	}
	// std::cout << x << " " << y << " " << memo[x][y] << std::endl;
	return memo[x][y];
}

int main(void){
	int c,d;
	std::cin >> a >> b >> c >> d;
	std::cout << solve(c,d) << std::endl;
	return 0;
}


Measured memory_bytes: 83920
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int n;
  cin >> n;
  if(n == 0){
    cout << 0 << endl;
    return 0;
  }
  stack<int> ans;
  while(n != 0){
    if(abs(n) % 2 == 0) ans.push(0);
    else{
      n--;
      ans.push(1);
    }
    n /= -2;
  }
  while(!ans.empty()){
    cout << ans.top();
    ans.pop();
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 3600
package main

import (
	"fmt"
)

func main() {
	var a, b, ans int
	fmt.Scanln(&a, &b)
	if a > b {
		a, b = b, a
	}
	if a == b {
		ans = 2 * a
	} else {
		ans = 2*b - 1
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
// #define int long long
typedef long long ll;
typedef pair<int,int> pii;
#define ITR(v,c) for(auto v=begin(c);v!=end(c);v++)
#define FOR(v,a,n) for(int v=a;v<(int)(n);v++)
#define FORE(x,arr) for(auto &x:arr)
#define REP(v,n) FOR(v,0,n)
#define RREP(v,n) for(int v=(int)(n);v>=0;v--)
#define ALL(c) begin(c),end(c)
const int DX[4]={0,1,0,-1}, DY[4]={-1,0,1,0};
const int INF = 1e9;
const ll INFLL = 1e18;
template<class T,class U>ostream&operator<<(ostream &os,const pair<T,U> &p){
    os<<"("<<p.first<<","<<p.second<<")";return os;}
template<class T>ostream&operator<<(ostream &os,const vector<T> &v){
    ITR(i,v)os<<*i<<(i==end(v)-1?"":" ");return os;}
//------------------------------------------------------------------------------

signed main() {
    string alpha="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    string s;
    cin>>s;
    FORE(c,s) putchar(alpha[(26+c-'A'-3)%26]);
    putchar('\n');
    return 0;
}

Measured memory_bytes: 3232
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<functional>
#include<math.h>
 
#define rep(i,n) for(ll i=0;i<(n;i++)
typedef long long ll;
using namespace std;

int main(void){
    int N;
    cin >> N;
    cout << 10 - N/200 << endl;
    }
    

Measured memory_bytes: 3576
n = int(input())
p = list(map(int,input().split()))
q = list(map(int,input().split()))
import itertools 
data = list(itertools.permutations([i+1 for i in range(n)]))
for i in range(len(data)):
    d = list(data[i])
    if p==d:a=i
    if q==d:b=i
print(abs(a-b))

Measured memory_bytes: 45552
import fractions
N = int(input())
x = []
for i in range(N):
    a1,b1,c1,d1=[int(i) for i in input().split()]
    x.append([a1,b1,c1,d1])
for i in range(N):
  y = x[i]
  if y[0] < y[1]:
    print("No")
  elif y[1] > y[3]:
    print("No")
  elif y[1] > y[2]:
    ama = y[0] % y[1]
    mo = y[3] %  y[1]
    if mo == 0:
      if ama<= y[2]:
        print("Yes")
      else:
          print("No")
    elif mo <= y[1]-y[2]-1:
      print("No")
    else:
        to = y[1] % mo
        if to == 0:
          if ama<= y[2]:
            print("Yes")
          else:
              print("No")
        else:
          are = fractions.gcd(to, y[1])
          if are-ama%are <= y[1]-y[2]-1:
            print("No")
          else:
            print("Yes")
          
  else:
    print("Yes")

Measured memory_bytes: 5596
using System;
using System.Collections.Generic;

namespace _0001 {

	public static class Program {

		public static void Main() {
			var list = new List<int>();
			for (int i = 0; i < 10; i++) {
				list.Add(int.Parse(Console.ReadLine()));
			}
			list.Sort((a, b) => b - a);

			for (int i = 0; i < 3; i++) {
				Console.WriteLine(list[i]);
			}
		}

	}

}

Measured memory_bytes: 9180
//
//  CPlibrary
//
//  Created by Tanmay Singh on 3/03/2020.
// INDIAN INSTITUTE OF TECHNOLOGY (BHU) , VARANASI
//  Copyright © 2020 Tanmay Singh. All rights reserved.
//#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")
 
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <climits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <ratio>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
 
#define FAST(); ios_base::sync_with_stdio(false);cin.tie(NULL);
#define endl "\n"
#define mod 1000000007
typedef long long int  bigint ;
typedef std::vector< int > vi;
typedef std::vector< long long int > vll;
typedef std::vector< vi > vvi;
 
using namespace std;

int main(){
    FAST() ;
    int A , B , C ; cin >> A >> B >> C ;
    int arr[] = { A , B , C } ;
    sort( arr , arr + 3 ) ;
    int cnt1 = 0 , cnt2 = 0 ;
    cnt1 += (arr[2] - arr[0]) / 2 ;
    cnt2 += ( arr[2] - arr[1] ) / 2 ;
    arr[0] = arr[0] + 2 * cnt1 ;
    arr[1] = arr[1] + 2 * cnt2 ;
    sort( arr , arr + 3 ) ;
    if( arr[0] == arr[1] && arr[1] == arr[2] ){
        cout << cnt1 + cnt2 << endl ;
        return 0 ;
    }
    if( arr[0] == arr[1] ){
        cout << cnt1 + cnt2 + arr[2] - arr[1] << endl ;
        return 0 ;
    }
    if( arr[0] != arr[1] ){
        cout << cnt1 + cnt2 + 2 << endl ;
    }
    return 0 ;
}


Measured memory_bytes: 256
from functools import reduce
import math

def main():
    # 文字列の2進数を数値にする
    # '101' → '5'
    # 文字列の頭に'0b'をつけてint()にわたす
    # binary = int('0b'+'101',0)

    # 2進数で立っているbitを数える
    # 101(0x5) → 2
    # cnt_bit = bin(5).count('1')
    
    # N! を求める
    # f = math.factorial(N)
    
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    INF = float("inf")
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]    
    S = list(_ for _ in input())
    e= ''
    for i in range(2**3):
        e=S[0]
        for j in range(0,3):
            if 1<<j & i:
                e+='+'
            else:
                e+='-'
            e+=S[j+1]
        if eval(e) == 7:
            e+='=7'
            break
    print(e)
if __name__ == '__main__':
    main()


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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SZ(x) ((int)(x).size())
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 55;
const int mod = 1000000007;
//const int mod = 998244353;

template <class T>inline bool chmin(T &a, const T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline bool chmax(T &a, const T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline void line_out(const vector<T> vec) {
  int n = SZ(vec);
  rep(i, n) {
    cout << vec[i];
    if(i < n-1) cout << " ";
  }
  cout << endl;
  return;
}

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

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


int main()
{
  int n, k; cin >> n >> k;
  vector<int> a(n);
  rep(i, n) cin >> a[i];

  for(int i = 0; i < k; ++i) {
    vector<int> r(n, 1), l(n, 1), del(n, 0);

    rep(j, n) {
      r[j] -= del[j];
      if(j+a[j]+1 < n) ++del[j+a[j]+1];
      if(j < n-1) r[j+1] += r[j];
    }

    reverse(ALL(a));
    del.assign(n, 0);
    rep(j, n) {
      l[j] -= del[j];
      if(j+a[j]+1 < n) ++del[j+a[j]+1];
      if(j < n-1) l[j+1] += l[j];
    }
    reverse(ALL(l));

    rep(j, n) a[j] = r[j]+l[j]-1;

    if(*max_element(ALL(a)) == n && *min_element(ALL(a)) == n) break;
  }

  line_out(a);
}

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

typedef long long LL;

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(x) (x).begin(),(x).end()
const int IINF = 1e9;
const LL LINF = 1e18;
const LL MOD = 1e9+7;

int main() {
    int N, X, T;
    cin >> N >> X >> T;
    int n = (N + X - 1)/X;
    cout << n*T << endl;
    return 0;
}


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

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,int> plli;
typedef pair<int,pii> pipii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n);i>=0;i--)
#define rrep2(i,a,b) for (int i=(a);i>b;i--)
#define pb push_back
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()

const ll mod = 1e9 + 7;
const ll INF = 1<<30;
const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {1, 1, 1, 0, 0, -1, -1, -1};
const int dy8[8] = {0, 1, -1, 1, -1, 0, 1, -1};
const double pi = 3.141592653589793;

int n, m, h, k;
int s[1005];
int c[1010][1010];

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> m >> h >> k;
    while (n != 0) {
        map<pair<int, int>, int> e1;
        vector<vector<int>> e2(100000 + 5);
        map<int,int> score;
        rep(i, n) cin >> s[i];
        rep(i, 1005) rep(j, 1005) c[i][j] = i;
        rep(i, m) {
            int a, b;
            cin >> a >> b;
            a--;
            c[a][b] = a + 1;
            c[a + 1][b] = a;
            e1[make_pair(a, b)] = i;
            e1[make_pair(a + 1, b)] = i;
        }
        int ans = 0;
        rep(i, n) {
            int now = i;
            int now_h = 0;
            while (now_h < h) {
                int nx = c[now][now_h];
                if (now != nx) {
                    int idx = e1[make_pair(now, now_h)];
                    e2[idx].pb(i);
                }
                now = nx;
                now_h++;
            }
            score[i] = s[now];
            if (i < k) ans += s[now];
        }
        int tmp1 = ans;
        int tmp2 = ans;
        rep(i, m) {
            int u = e2[i][0];
            int v = e2[i][1];
            if (k <= u || v < k) continue;
            tmp1 = min(tmp1, tmp2 - score[u] + score[v]);
        }
        ans = tmp1;
        cout << ans << endl;
        cin >> n >> m >> h >> k;
    }

}

Measured memory_bytes: 28980
//グリッド探索

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

int main(){
    int h,w;
    cin>>h>>w;
    string str[h];
    for(int i=0;i<h;i++){
        cin>>str[i];
    }
    int dx[8]={1,0,-1,0,1,-1,-1,1};
    int dy[8]={0,1,0,-1,1,1,-1,-1};
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            
            if(str[i][j]=='.'){
                int num=0;
                for(int d=0;d<8;d++){
                    int ni=i+dy[d];
                    int nj=j+dx[d];
                    if(ni>=0&&ni<h){
                        if(nj>=0&&nj<w){
                            if(str[ni][nj]=='#')
                            num++;
                        }
                    }
                }

                str[i][j]=char(num+'0');
            }
        }
    }
    for(int i=0;i<h;i++){
        cout<<str[i]<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
//go:generate echo "https://atcoder.jp/contests/abc176/tasks/abc176_a"
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

type scanner struct{ *bufio.Scanner }

func newScanner(r io.Reader) *scanner {
	s := bufio.NewScanner(r)
	s.Split(bufio.ScanWords)
	s.Buffer(nil, 100000000)
	return &scanner{s}
}

func (s *scanner) Int() int {
	s.Scan()
	n, _ := strconv.Atoi(s.Text())
	return n
}

func (s *scanner) IntSlice(l int) []int {
	if l == 0 {
		return []int{}
	}
	sl := make([]int, l, l)
	for i := range sl {
		sl[i] = s.Int()
	}
	return sl
}

func (s *scanner) IntSlice2(l, n int) []int {
	if l == 0 {
		return []int{}
	}
	sl := make([]int, l, l)
	for i := 0; i < n; i++ {
		sl[i] = s.Int()
	}
	return sl
}

func solve(n, x, t int) int {
	return ((n + x - 1) / x) * t
}

func main() {
	scan := newScanner(os.Stdin)
	n, x, t := scan.Int(), scan.Int(), scan.Int()
	fmt.Println(solve(n, x, t))
}


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

#define int long long
struct Fast {Fast(){cin.tie(0);ios::sync_with_stdio(0);}} fast;
using intpair = pair<int, int>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define ceiv(a, b) ((int)((a) + (b) - 1)/(int)(b))

signed main() {
    int n, y;
    cin >> n >> y;
    rep(gosen,4020)rep(man,2020){
        int sen = (y - gosen * 5000 - man * 10000) / 1000;
        if(sen < 0) continue;
        if(n == sen + gosen + man){
            cout << man << " " << gosen << " " << sen << endl;
            return 0;
        }
    }
    cout << "-1 -1 -1" << endl;
}

Measured memory_bytes: 256
import collections
n = int(input())
a_list = [str(input()) for i in range(n)]
c = collections.Counter(a_list)

cc = c.most_common()
values, counts = zip(*c.most_common())
max_counts = max(counts)


counts_num = counts.count(max_counts)

ans = []
for i in range(counts_num):
    ans.append(values[i])
    
ans = sorted(ans)

for i in range(len(ans)):
    print(ans[i])

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

int main()
{
  int n;
  cin >> n;
  int p = n%1000;
  if(p==0)
  {
    cout << "0\n";
  }
  else
  {
    p=1000-p;
    cout << p << "\n";
  }
}

Measured memory_bytes: 3636
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();
        int x = sc.nextInt();
        if (k * 500 >= x) {
            System.out.println("Yes");
            return;
        }
        System.out.println("No");
    }

}


Measured memory_bytes: 21844
#include <iostream>
#include <set>
#include <math.h>
#include <list>
#include <vector>
#include <map>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define MAX_N 100005
#define MAX_M 100

int N;
int A[MAX_N];

int main()
{
    rep(i, MAX_N) A[i] = 0;
    int a, x = 0, ans = 0;
    cin >> N;

    rep(i, N)
    {
        cin >> a;
        if (A[a] == 0)
        {
            ans++;
            A[a]++;
        }
        else
            x++;
    }
    if (x % 2)
        ans--;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <stdio.h>
#include <vector>
#include <map>
#include <string.h>
#include <set>
#include <algorithm>
using namespace std;
vector<int> a[1000];
int n;
void solve(){
    int p = -1;
    for (int i = 1 ; i * (i + 1) <= 2 * n ; ++i){
        if (i * (i + 1) == 2 * n){
            p = i;
            break;
        }
    }
    if (p == -1){
        puts("No");
        return;
    }
    for (int i = 0 ; i <= p ; ++i) a[i].clear();
    int q = 0;
    for (int i = 0 ; i < p ; ++i){
        for (int j = i + 1 ; j <= p ; ++j){
            ++q;
            a[i].push_back(q);
            a[j].push_back(q);
        }
    }
    puts("Yes");
    printf("%d\n" , p + 1);
    for (int i = 0 ; i <= p ; ++i){
        printf("%d" , (int)a[i].size());
        for (int j = 0 ; j < a[i].size(); ++j)
            printf(" %d" , a[i][j]);
        puts("");
    }
}
int main(){
    while(cin >> n) solve();
}

Measured memory_bytes: 2304
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7;
const ll LINF=1e18;
using namespace std;
#define int long long

signed main(){
  int a,b,x;cin>>a>>b>>x;
  if(x<a){cout<<x%MOD<<endl;return 0;}
  int ans=0;
  x-=a;
  int z=x/(a-b);z%=MOD;int aa=a%MOD;
  ans+=z*aa;ans%=MOD;
  x%=(a-b);
  ans+=a;ans+=x;ans+=b;
  ans%=MOD;
  cout<<ans<<endl;
}



Measured memory_bytes: 3072
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
#include <set>
#include <math.h>
#include <queue>
#define rep(i,n) for (int i = 0; i < (n); ++i)
typedef long long ll;
using namespace std;

int main() {
    string s, t;
    cin >> s >> t;
    int ans = 10e3;
    rep(i,s.size()-t.size()+1) {
        int cnt=0;
        rep(j,t.size()) {
            if(s[i+j]!=t[j]) cnt++;
        }
    ans = min(ans, cnt);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3176
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, *A = map(int, read().split())

    s = 0
    xors = 0
    ans = 0
    right = 0
    for left in range(N):
        while right < N and xors ^ A[right] == s + A[right]:
            xors ^= A[right]
            s += A[right]
            right += 1

        ans += right - left

        if left == right:
            right += 1
        else:
            xors ^= A[left]
            s -= A[left]

    print(ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 32400