akhauriyash/Code-Regression huggingface dataset:
from collections import Counter
from itertools import accumulate

n, k = map(int, input().split())
aaa = list(map(int, input().split()))
bbb = list(accumulate(aaa))
ccc = list(-i % k for i in range(n))
ddd = [(b + c) % k for b, c in zip(bbb, ccc)]

# print(aaa)
# print(bbb)
# print(ccc)
# print(ddd)

count = dict(Counter(ddd[:k - 1]))
ans = 0
for i in range(n):
    key = (1 - aaa[i] + bbb[i] + ccc[i]) % k
    if key in count:
        ans += count[key]

    j = i + k - 1
    if j < n:
        dj = ddd[j]
        if dj not in count:
            count[dj] = 1
        else:
            count[dj] += 1

    di = ddd[i]
    count[di] -= 1
    if count[di] == 0:
        count.pop(di)

print(ans)


Measured memory_bytes: 66148
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String n = sc.next();
		n = n.replace("1", "X");
		n = n.replace("9", "1");
		n = n.replace("X", "9");
		System.out.println(n);
	}
}

Measured memory_bytes: 21844
n=int(input())
s=[0]*n
a=list(map(int,input().split()))
for i,h in enumerate(a):
    if i!=0:
        g=0 if i-2<0 else i-2
        s[i]=min([abs(h-d)+p for d,p in zip(a[g:i],s[g:i])])
print(s[-1])   

Measured memory_bytes: 14696
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>

using namespace std;

void solve()
{
	int n;
	while(cin >> n)
	{
		vector<int> Vec(n);
		for(int i = 0; i < n; ++i)
		{
			cin >> Vec[i];
		}
		sort(Vec.begin(), Vec.end(), greater<int>());
		int sum = 0;
		for(int i = n; i >= 1; --i)
		{
			sum += i * Vec[i - 1];
		}
		cout << sum << endl;
	}
}

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

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

int32_t main(){

	int n;
	cin>>n;

	int arr[n];
	for (int i=0;i<n;i++) cin>>arr[i];

	set<int>s;
	for (int i=0;i<n;i++){
		int y = arr[i];
		if (s.find(y)!=s.end()){
				cout<<"NO\n";
				return 0;
		}
		else
			s.insert(y);
	}

	cout<<"YES\n";

}

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

int main(){
    string S;

    //入力
    cin >> S;
    int l = S.size();
    //if文
    if(S[l-1]!='s'){
        cout << S + 's' << endl;
    }else{
        cout << S + "es" << endl;
    }

}

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

#define ll long long 
#define pii pair<int, int>
#define ull unsigned ll
#define f first
#define s second
#define FOR(i,a,b) for (int i=(a); i<(b); i++)
#define REP(i,n) for (int i=0; i<(n); i++)
#define RREP(i,n) for (int i=(n-1); i>=0; i--)
#define ALL(x) x.begin(),x.end()
#define SZ(x) (int)x.size()
#define SQ(x) (x)*(x)
#define MN(a,b) a = min(a,(__typeof__(a))(b))
#define MX(a,b) a = max(a,(__typeof__(a))(b))
#define pb push_back
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define bug(x) cerr<<#x<<" is "<<x<<endl

using namespace std;

#define int ll

const int iinf = 1<<29;
const ll inf = 1ll<<60;
const ll mod = 1e9+7;


void GG(){cout<<"No\n"; exit(0);}

ll mpow(ll a, ll n, ll mo = mod){ // a^n % mod
    ll re=1;
    while (n>0){
        if (n&1) re = re*a %mo;
        a = a*a %mo;
        n>>=1;
    }
    return re;
}

ll inv (ll b, ll mo = mod){
    if (b==1) return b;
    return (mo-mo/b) * inv(mo%b) % mo;
}

const int maxn = 1e5+5;



main(){
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    int n,k; cin>>n>>k;
    vector<int> a(n);
    ll poss = 0;
    REP(i,n) cin>>a[i], poss+=max(a[i],0ll);
    ll ns = 0, ps = 0;
    ll lose = inf;
    REP(i,n){
        if (a[i]>=0) ps += a[i]; else ns += a[i];
        if (i>=k-1){
            MN(lose, min(-ns, ps));
            if (a[i-k+1]>=0) ps -= a[i-k+1]; else ns -= a[i-k+1];
        }
    }
    cout<<poss-lose<<'\n';
} 

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n) for(ll i=0;i<(n);i++)
#define For1(i,n) for(ll i=1;i<(n);i++)
#define MOD 1000000007
ll gcd(ll a,ll b){
    return b?gcd(b,a%b):a;
}
int main(){
    ll k,x;cin>>k>>x;
    for(ll i=-1000000;i<2000001;i++){
        if(abs(x-i)<k){
            cout<<i<<" ";
        }
    }
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define ll long long
#define mod 1000000007
ll powe(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}

ll n;
ll p[212345];

int main(){
  scanf("%lld",&n);

  ll ans=(powe(10,n,mod)-2*powe(9,n,mod)+powe(8,n,mod)+mod*2)%mod;
  printf("%lld\n",ans);
  
  return 0;
}


Measured memory_bytes: 1708
import java.util.Arrays;

public class Main {

	private static void solve() {
		int n = ni();
		int[] d = na(n);
		Arrays.sort(d);
		
		int count = 1;
		int now = d[0];
		for (int i = 1; i < n; i ++) {
			if (now < d[i]) {
				now = d[i];
				count ++;
			}
		}
		System.out.println(count);
	}

	public static void main(String[] args) {
		new Thread(null, new Runnable() {
			@Override
			public void run() {
				long start = System.currentTimeMillis();
				String debug = args.length > 0 ? args[0] : null;
				if (debug != null) {
					try {
						is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
					} catch (Exception e) {
						throw new RuntimeException(e);
					}
				}
				reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
				solve();
				out.flush();
				tr((System.currentTimeMillis() - start) + "ms");
			}
		}, "", 64000000).start();
	}

	private static java.io.InputStream is = System.in;
	private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
	private static java.util.StringTokenizer tokenizer = null;
	private static java.io.BufferedReader reader;

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

	private static double nd() {
		return Double.parseDouble(next());
	}

	private static long nl() {
		return Long.parseLong(next());
	}

	private static int[] na(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}

	private static char[] ns() {
		return next().toCharArray();
	}

	private static long[] nal(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nl();
		return a;
	}

	private static int[][] ntable(int n, int m) {
		int[][] table = new int[n][m];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				table[i][j] = ni();
			}
		}
		return table;
	}

	private static int[][] nlist(int n, int m) {
		int[][] table = new int[m][n];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				table[j][i] = ni();
			}
		}
		return table;
	}

	private static int ni() {
		return Integer.parseInt(next());
	}

	private static void tr(Object... o) {
		if (is != System.in)
			System.out.println(java.util.Arrays.deepToString(o));
	}
}


Measured memory_bytes: 23252
#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <bitset>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

string S;
long beki(int l){
	if(l==0) return 1;
	else return 2*beki(l-1);
}
int main(){
	cin >> S;
	int l = S.size();
	long M = beki(l-1);

	long ans = 0;

	for(long x=0;x<M;x++){
		//cout << "aaaaa" <<endl;
		int i=0;

		while(i < l){
			//cout << 3 <<endl;
			ans += S[l-i-1] - '0';
			//cout << ans <<endl;
			long b = 10;
			//cout << 5 <<endl;
			while(i<l-1 && (!(x&(1<<i)))){
				//cout << 4 <<endl;
				ans += b*(S[l-i-2] - '0');
				//cout << ans <<endl;
				b *= 10;
				i++;
			}
			i++;
		}

  	}
  	cout << ans <<endl;

  	return 0;
}



Measured memory_bytes: 256
const main = function(input){
  var str = input.split("\n")[1];
  var len = str.length;
  var min = 3*Math.pow(10,5);
  
  var rightCount = 0;
  var leftCount = 0;
  for(var i=0;i<len;i++){
    if(str[i] === "E") rightCount++;
  }
  var left = "";
  for(var i=0;i<len;i++){
  	var leader = str[i];
    if(leader==="E")rightCount--;
    
    var count = rightCount+leftCount;
    if(min>count) min = count;
    
    if(leader==="W")leftCount++;
    left+=leader;
  }
  
  console.log(min);
}


main(require('fs').readFileSync('/dev/stdin', 'UTF-8'));

Measured memory_bytes: 27852
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define INF INT_MAX;
typedef long long ll;
using namespace std;

int main(){
  int n; cin >> n;
  int num=0,ans=0,found=0;
  rep(i,n){
    int x; cin >> x;
    if(x==num+1){
      num++;
    }else{
      ans++;
    }
  }
  if(num!=0) cout << ans << endl;
  else puts("-1");
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define SP << " " 

using namespace std;

vector<int> bi;
long long int n, m, x, mi=99999999;
vector< vector<int> > v;

void bitgen(int len){

	//生成完了時の処理
	if(len==0){
		long long int tmp;
		vector<int> stu(m);
		tmp=0;
		rep(i, m) stu[i]=0;

		for(int i=0;i<n;i++){
			//cout<< bi[i];
			if(bi[i]){
				tmp+=v[i][0];
				rep(j, m) stu[j]+=v[i][j+1];
			}
		}
		//cout<< endl;
		
		int flag;
		flag=1;

		rep(i, m){
			//cout<< stu[i] << " ";
			if(stu[i]<x) flag=0;
		}
		//cout<< endl;

		if(flag){
			mi=min(mi, tmp);
		}

		return;
	}

	//再帰部分
	for(int i=0;i<2;i++){
		bi[len-1]=i;
		bitgen(len-1);
	}
}

void PV(vector<int> pvv) {
	rep(i, pvv.size()) cout << pvv[i] SP;
	cout << endl;
}

int main(){

	cin>> n >> m >> x;
	v.resize(n);
	rep(i, n) v[i].resize(m+1);

	rep(i, n){
		rep(j, m+1){
			cin>> v[i][j];
		}
	}
	
	bi.resize(n);
	bitgen(n);

	if(mi==99999999) cout<< "-1" << endl;
	else cout<< mi << endl;
 
	return 0;
}

Measured memory_bytes: 3640
# from collections import defaultdict,deque
# import sys,heapq,bisect,math,itertools,string,queue,copy,time
# sys.setrecursionlimit(10**8)
#
#
import sys
import itertools
INF = float("INF")

N = int(input())
AA = list(map(int, sys.stdin.readline().split()))
BB = list(map(int, sys.stdin.readline().split()))

cards = set()
for i,(a,b) in enumerate(zip(AA,BB)):
    if i%2 == 0:
        cards.add((a, b, i))
    else:
        cards.add((b, a, i))




# In[]:
def solve(ii):
    tmp = 0
    for _ in range(N):
        next = []
        for k, i in enumerate(ii):
            if i == 0:
                tmp += k
            else:
                next.append(i-1)
        ii = next[:]
    return tmp



# In[]:
ans = INF
for Acards in itertools.combinations(cards, (N+1)//2):
    Bcards = cards - set(Acards)

    Ais = sorted([(card[0], card[2]) for card in Acards])
    Bis = sorted([(card[1], card[2]) for card in Bcards])

    nums = []
    ii = []
    for i in range(N):
        if i%2 == 0:
            n,i = Ais[i//2]
        else:
            n,i = Bis[i//2]
        nums.append(n)
        ii.append(i)

    if nums != sorted(nums):
        continue
    else:
        ans = min(ans,solve(ii))
        if ans == 0:
          print(0)
          sys.exit()


if ans == INF:
    print(-1)
else:
    print(ans)


Measured memory_bytes: 3188
def bubble_sort(A, n):
    A = A[:]
    flag = True
    while flag:
        flag = False
        for i in range(n - 1, 0, -1):
            if int(A[i][1:]) < int(A[i - 1][1:]):
                A[i], A[i - 1] = A[i - 1], A[i]
                flag = True
    return A


def selection_sort(A, n):
    A = A[:]
    for start in range(n):
        smallest_i = start
        smallest = A[smallest_i]
        for i in range(start, n):
            if int(A[i][1:]) < int(smallest[1:]):
                smallest_i = i
                smallest = A[smallest_i]
        A[start], A[smallest_i] = A[smallest_i], A[start]
    return A


def is_stable(ordered, original):
    for n in range(1, 10):
        f_original = filter(lambda c: int(c[1:]) == n, original)
        f_ordered = filter(lambda c: int(c[1:]) == n, ordered)
        for a, b in zip(f_ordered, f_original):
            if a != b:
                return False
    return True


n = int(input())
A = input().split()
bA = bubble_sort(A, n)
sA = selection_sort(A, n)
print(*bA, sep=" ")
print("Stable" if is_stable(bA, A) else "Not stable")
print(*sA, sep=" ")
print("Stable" if is_stable(sA, A) else "Not stable")



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

int n, m;
int  p[100010];
long long int a[100010], b[100010], c[100010];
int times[100010];
long long int ans = 0;
int main()
{
  scanf("%d%d", &n, &m);
  for(int i = 1; i <= m; i++)
    scanf("%d", &p[i]);
  
  for(int i = 1; i < n; i++)
    scanf("%lld%lld%lld", &a[i], &b[i], &c[i]);

  for(int i = 1; i < m; i++){
    times[min(p[i], p[i + 1])]++;
    times[max(p[i], p[i + 1])]--;
  }
  
  for(int i = 1; i < n; i++)
    times[i] += times[i - 1];

  for(int i = 1; i < n; i++)
    ans += min(a[i] * times[i], c[i] + b[i] * times[i]);
  
  printf("%lld\n", ans);
  return 0;
}

Measured memory_bytes: 4316
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(), (x).end())
#define ALL(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define reps(i, m, n) for (ll i = m; i < n; i++)
#define repr(i, m, n) for (ll i = m; i >= n; i--)
#define de(x) cout << #x << "=" << x << endl;
template <class T> bool maxi(T &a, const T &b) {
    if (a < b) { a = b; return 1;} return 0;}
template <class T> bool mini(T &a, const T &b) {
    if (b < a) { a = b; return 1;} return 0;}
#define dame {cout<< "-1" <<"\n"; return;}
#define INF2 1000000000000000037
#define INF  1000000007
#define MOD  1000000007
using namespace std;
using ll = long long;
using ld = long double;
using P  = pair<ll,ll>;
//--GLOBAL---------------------------------

//--MAIN-----------------------------------
void Main() {
    ll N; cin>>N;
    vector<ll> A(N);
    rep(i,N) cin>>A[i];
    ll mimi=INF;
    ll ans=0;
    rep(i,N) if(mini(mimi,A[i])) ++ans;
    cout<< ans <<"\n";
}

//--START----------------------------------
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}
//-----------------------------------------


Measured memory_bytes: 1792
//author-abhijit dey
 //Welcome to my code. btw I hate coding 😉
#include <bits/stdc++.h>
using namespace std;
#define     ff first
#define     ss second
#define     pb push_back
#define     mp make_pair
#define     INF 1000000005
#define     MOD 1000000000
#define     ninf -1000000000
#define     all(c) c.begin(), c.end()
#define     tinput long long int t;cin>>t;
#define     mem(a,x) memset(a,x,sizeof a)
#define     for0(i,n) for(long long int i=0;i<n;i++)
#define     pi 3.141592653589793238462643383279502884
#define     fori(i,a,n) for(long long int i=a;i<n;i++)
#define     forxy(i,x,y) for(int i=x;i<=y;i++)
#define     rfor(i,n) for(long long int i=n-1;i>=0;i--)
#define     ainput for(int i=0; i<n; i++) cin>>a[i];
#define     fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

typedef     long long int ll;
typedef     vector<long long int>vll;
typedef     vector<vector<int> >vvll;
typedef     pair<long long int,long long int>pr;
typedef     vector<pair<long long int,long long int> >vp;

inline long long  min2(long long  a, long long  b)  {return (a)<(b)?(a):(b);}
inline long long  max2(long long  a, long long  b)  {return (a)>(b)?(a):(b);}
inline long long  max3(long long  a, long long  b, long long  c)    {return (a)>(b)?((a)>(c)?(a):(c)):((b)>(c)?(b):(c));}
inline long long  min3(long long  a, long long  b, long long  c)    {return (a)<(b)?((a)<(c)?(a):(c)):((b)<(c)?(b):(c));}
using namespace std::chrono;
ll N,k;
ll dp[100001][4];
vll a(100001);
vll b(100001);
vll c(100001);
ll maxcost(ll ind,ll prev)
{
    ll ans=0;
    if(ind-1==N)return 0;
    if(dp[ind][prev]!=-1)return dp[ind][prev];
    if(prev==0)
    {
        ans+=max3(a[ind]+maxcost(ind+1,1),b[ind]+maxcost(ind+1,2),c[ind]+maxcost(ind+1,3));
    }
    if(prev==1)
    {
        ans+=max(b[ind]+maxcost(ind+1,2),c[ind]+maxcost(ind+1,3));
    }
    else if(prev==2)
    {
        ans+=max(a[ind]+maxcost(ind+1,1),c[ind]+maxcost(ind+1,3));
    }
    else if(prev==3)
    {
        ans+=max(a[ind]+maxcost(ind+1,1),b[ind]+maxcost(ind+1,2));
    }
    dp[ind][prev]=ans;
    return dp[ind][prev];
}
void process()
{
    cin>>N;
    for(ll i=1;i<=N;i++)cin>>a[i]>>b[i]>>c[i];
    memset(dp,-1,sizeof(dp));
    cout<<maxcost(1,0);
}
int main()
{
    fastio;
    //tinput;
    //while(t--)
        process();
}

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

int main()
{
	string S;
	cin >> S;
	int i = 0;

	while(S[i] != '\0')
	{
		if(S[i] == '?')
		{
			S[i] = 'D';
		}
		i++;
	}
	cout << S;
	return 0;
}

Measured memory_bytes: 3688
from collections import deque
def tsort(In,G,N):
    que=deque([i for i,c in enumerate(In) if c==0])
    l=[]
    while que:
        v=que.popleft()
        l.append(v)
        for nv in G[v]:
            In[nv]-=1
            if In[nv]==0:
                que.append(nv)
    return l

N,M=map(int,input().split())
In=[0]*N
In_Edge=[[] for _ in range(N)]

G=[[] for _ in range(N)]

for _ in range(N-1+M):
    a,b=map(lambda x:int(x)-1,input().split())
    G[a].append(b)
    In[b]+=1
    In_Edge[b].append(a)

T_sorted=tsort(In,G,N)
P=[-1]*N
for i,v in enumerate(T_sorted):
    P[v]=i
ans=[-1]*N
for i in reversed(range(N)):
    v=T_sorted[i]
    if not In_Edge[v]:
        ans[v]=0
        continue
    In_Edge[v].sort(key=lambda x:P[x])
    ans[v]=In_Edge[v][-1]+1
print(*ans,sep='\n')

Measured memory_bytes: 110948
N = int(input())
W = [input() for _ in range(N)]
sorted_W = sorted(W)
for i in range(len(sorted_W) - 1):
    if sorted_W[i] == sorted_W[i + 1]:
        print('No')
        exit()
for i in range(len(W) - 1):
    if W[i][-1] != W[i + 1][0]:
        print('No')
        exit()
print('Yes')


Measured memory_bytes: 2940
/*
            _           __                _      _____ _____ _____ 
  ___ _   _| |__   ___ / _|_ __ ___  __ _| | __ |___  |___  |___  |
 / __| | | | '_ \ / _ \ |_| '__/ _ \/ _` | |/ /    / /   / /   / / 
| (__| |_| | |_) |  __/  _| | |  __/ (_| |   <    / /   / /   / /  
 \___|\__,_|_.__/ \___|_| |_|  \___|\__,_|_|\_\  /_/   /_/   /_/   

*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll ;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<ll> vi;
typedef vector<pll> vpll;
typedef unordered_map <ll,ll> umap ; 
//#pragma GCC optimize "trapv"
#define loop(i,a,b) for(ll i=a ;i<b;i++)
#define For(i,n) for(int i=0;i<(ll)n;i++)
#define Rev(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,n) for(int i=1;i<=n;++i)
#define F first
#define S second
#define pb push_back
#define em emplace_back
#define all(v) (v).begin(),(v).end()
#define mems(x, y) memset(x, y, sizeof(x))
#define sz(v) (v).size()
#define mp(a,b) make_pair(a,b)
#define pf(n) cout<<n<<"\n"
#define pff(n) cout << n << " " ; 
#define ar array
#define endl "\n"
#define int ll 
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
long const M=1e9+7;
const long mxN =2e5+2 ;
ll a[mxN] ;
void solve(){
  ll n,k ; cin >> n >> k ;
  Rep(i,n)
    cin >> a[i] ;
  int x =1,steps=1,cyc=0;
  map<int,int> check;
  check[x]=steps ;
  vector<int>pos={x} ;
  while(1){
    if(check[a[x]]!=0){
      ++steps ;cyc = steps-check[a[x]] ;
      break ;
    }
    ++steps ;x=a[x] ;
    check[x]=steps ;pos.pb(x) ;
  }
  vi cycle ;
  while(sz(cycle)!=cyc){
    cycle.pb(pos.back()) ;
    pos.pop_back() ;
  }
  reverse(all(cycle)) ;
  if(k<sz(pos)){
    cout << pos[k] << endl ;
    return ;
  }
  k-=sz(pos) ;
  ll rem= k%cyc ;
  cout << cycle[rem] << endl ;
}
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //cout << setprecision(20) << fixed ;
    solve() ;
    //ll t ; cin >> t ; while(t--)solve();
	return 0;
}

Measured memory_bytes: 20636
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();

		for(int i = 1; i <= 9; i++){
			if(n%i == 0 && n/i <= 9){
				System.out.println("Yes");
				return;
			}
		}

		System.out.println("No");
	}

}


Measured memory_bytes: 21972
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

int main() {
  vector<int> n(4);
  REP(i, 4) cin >> n[i];
  sort(n.begin(), n.end());
  int t[4] = {1, 4, 7, 9};
  bool check = true;
  REP(i, 4) {
    if (n[i] != t[i])
      check = false;
  }
  if (check)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=1000000007,MAX=55,INF=1<<30;
int ans=-1;
int H=20,W=17;

vector<int> dh={-1,0,1,1,1,0,-1,-1},dw={1,1,1,0,-1,-1,-1,0};

set<vector<pair<int,int>>> SE;

void BFS(vector<pair<int,int>> &s){
    queue<pair<vector<pair<int,int>>,int>> Q;
    Q.push(mp(s,0));
    
    while(!Q.empty()){
        auto a=Q.front();Q.pop();
        
        if(SE.count(a.fi)) continue;
        SE.insert(a.fi);
        
        vector<string> S(H,string(W,'.'));
        
        int sh,sw;
        
        for(auto x:a.fi){
            if(x.fi>=100){
                S[x.fi-100][x.se-100]='O';
                sh=x.fi-100;
                sw=x.se-100;
            }
            else S[x.fi][x.se]='X';
        }
        
        for(int j=0;j<W;j++){
            if(S[H-1][j]=='O'){
                ans=a.se;
                while(!Q.empty()) Q.pop();
            }
            if(j>=1&&j<=15&&S[H-2][j]=='O'){
                ans=a.se;
                while(!Q.empty()) Q.pop();
            }
        }
        if(ans!=-1) break;
        
        for(int i=0;i<H;i++){
            for(int j=0;j<W;j++){
                if(S[i][j]=='O'){
                    sh=i;
                    sw=j;
                }
            }
        }
        
        if(sw==0||sw==W-1) continue;
        
        for(int k=0;k<8;k++){
            int toh=sh+dh[k],tow=sw+dw[k];
            while(toh>=0&&toh<H&&tow>=0&&tow<W&&S[toh][tow]=='X'){
                toh+=dh[k];
                tow+=dw[k];
            }
            if(toh==sh+dh[k]&&tow==sw+dw[k]) continue;
            
            vector<string> T=S;
            T[sh][sw]='.';
            toh=sh+dh[k];tow=sw+dw[k];
            while(toh>=0&&toh<H&&tow>=0&&tow<W&&S[toh][tow]=='X'){
                T[toh][tow]='.';
                toh+=dh[k];
                tow+=dw[k];
            }
            T[toh][tow]='O';
            
            vector<pair<int,int>> to;
            
            for(int i=0;i<H;i++){
                for(int j=0;j<W;j++){
                    char c=T[i][j];
                    if(c=='O') to.push_back(mp(100+i,100+j));
                    if(c=='X') to.push_back(mp(i,j));
                }
            }
            
            Q.push(mp(to,a.se+1));
        }
    }
}

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    vector<pair<int,int>> s;
    for(int i=0;i<19;i++){
        for(int j=1;j<=15;j++){
            char c;cin>>c;
            if(c=='O') s.push_back(mp(100+i,100+j));
            if(c=='X') s.push_back(mp(i,j));
        }
    }
    
    BFS(s);
    
    cout<<ans<<endl;
}



Measured memory_bytes: 17388
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;

int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        if(n<1200) cout<<"ABC"<<endl;
        else cout<<"ARC"<<endl;
    }
}


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

int students[50][2], checkpoints[50][2];
int main()
{
	
	int n, m; cin>>n>>m;
	for(int i = 0; i<n; i++)
	{
		cin>>students[i][0]>>students[i][1];
	}

	for(int i = 0; i<m; i++)
	{
		cin>>checkpoints[i][0]>>checkpoints[i][1];
	}

	for(int i = 0; i<n; i++)
	{
		int ans = 1, distance = abs(students[i][0]-checkpoints[0][0])
								+abs(students[i][1]-checkpoints[0][1]);
		int preX = checkpoints[0][0], preY = checkpoints[0][1];

		for(int j = 1; j<m; j++)
		{
			int temp = abs(students[i][0]-checkpoints[j][0])
								+abs(students[i][1]-checkpoints[j][1]);

			if(temp<distance)
			{
				ans = j+1; distance = temp;
			}
			else if(temp == distance)
			{
				if(preX>checkpoints[j][0])
				{
					preX = checkpoints[j][0]; 
				}
			}

		}

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

Measured memory_bytes: 256
from  collections import Counter

n = int(input())
v = list(map(int, input().split()))

c = Counter(v[::2])
d = Counter(v[1::2])

x = c.most_common()
y = d.most_common()

s = 0

if x[0][0] == y[0][0]:
    if len(x) > 1 and len(y) > 1:
        s = min(n - x[0][1] - y[1][1], n - x[1][1] - y[0][1])
    elif len(x) > 1:
        s = n - x[1][1] - y[0][1]
    elif len(y) > 1:
        s = n - x[0][1] - y[1][1]
    else:
        s = n // 2
else:
    s = n - x[0][1] - y[0][1]

print(s)

Measured memory_bytes: 27584
#include<iostream>
#include<iomanip>
#include<queue>
#include<string>
#include<stack>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<cassert>
#include<ctime>
#include<algorithm>
#include<utility>
#include<map>
#include<set>
#include<vector>
#include<functional>

using namespace std;

#ifdef DEBUG
#define dprintf      printf
#define dout(x)      cout<<#x" = "<<(x)<<endl
#define darray(x,n)    {int i;rep(i,n)cout<<#x"["<<i<<"] = "<<*((x)+i)<<endl;}
#define dloop(i,s,g) for((i)=(s);(i)<(g);(i)++)
#define drep(i,n)    for((i)=0;(i)<(n);(i)++)
#define dstop()      scanf("%*c")
#else
#define dprintf      (1)?0:printf
#define dout(x)
#define darray(x,n)
#define dloop(i,s,g) if(1){}else
#define drep(i,n)    if(1){}else
#define dstop()      if(1){}else
#endif

#define F    first
#define S    second
#define pb   push_back
#define mp   make_pair

#define loop(i,s,g) for((i)=(s);(i)<(g);(i)++)
#define rep(i,n)    for((i)=0;(i)<(n);(i)++)
#define all(x)      (x.begin(),x.end())
#define in(T,...) T __VA_ARGS__; impl(__VA_ARGS__);
#define array(T,id,n) T id[n]; rep(i,n)cin>>id[i];

//#define int long long;
#ifndef int
#define INF  (0x7fffffff)
#else
#define LINF (0x7fffffffffffffff)
#endif

typedef  long long           ll;
typedef  unsigned            ui;
typedef  unsigned long long  ull;
typedef  pair<int,int>       i_i;
typedef  pair<ll,int>        ll_i;
typedef  pair<ll,ll>         ll_ll;
typedef  pair<double,int>    d_i;
typedef  pair<double,double> d_d;

void impl(){};
template <typename T,typename... TS >
void impl(T &head,TS &... tail)
{
  cin>>head;
  impl(tail ...);
}

int dp[20][20];

signed main(void)
{
  while(1)
    {
      int i,j,k;
      int a,b;
      int n;
      int x[40]={},y[40]={};
      cin>>a>>b;
      if(!a)break;
      cin>>n;
      rep(i,n)
	cin>>x[i]>>y[i];
      dprintf("-------------------------\n");
      rep(i,a)
        rep(j,b)
	  {
	    dp[i+1][j+1]=dp[i+1][j]+dp[i][j+1];
	    if(i==0&&j==0)dp[i+1][j+1]=1;
	    rep(k,n)
	      if(x[k]==i+1&&y[k]==j+1)
		{
		  dp[i+1][j+1]=0;
		  break;
		}
	    dout(dp[i+1][j+1]);
	  }
      dprintf("-------------------------\n");
      cout<<dp[a][b]<<endl;
    }
  return 0;
}

Measured memory_bytes: 3084
#include<cstdio>
#include<algorithm>
using namespace std;

char s[10];

int main() {
	scanf("%s",s);
	for(int i=1;i<=3;i++)
		if(s[i]==s[i-1]) {
			printf("Bad\n");
			return 0;
		}
	printf("Good\n");
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define md 1000000007
#define ld long double
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n, i = 0, j= 0, k = 0, l = 0, m = LLONG_MAX, a = 0, b = 0, sum = 0, x = 0, y = 0, z = 0, c, p = 0;
    cin >> k >> n;
    ll arr[n];
    for(i = 0; i < n; i++){
        cin >> arr[i];
    }
    //m = 0;
    for(i = 0; i < n; i++){
        x  = arr[i];
        if(i == 0){
            z = arr[0]+k - arr[n-1];
        }
        else{
            z = arr[i]-arr[i-1];
        }
        y = k - z;
        m = min(y,m);
        //cout << y << " ";
    }
    cout << m;

    return 0;
}


Measured memory_bytes: 1792
// Problem D : Rotation Estimation

#include <iostream>
#include <vector>
#include <complex>
#include <algorithm>
#include <cmath>
#include <stdio.h>

using namespace std;

const double EPS = 1e-8;
typedef complex<double> P;
double rot(P a, P b) { return arg(conj(a)*b); }

namespace std{
	bool operator < (const P &a, const P &b){
		return make_pair(real(a),imag(a)) < make_pair(real(b),imag(b));
	}
}

int main(){
	int n;
	while(cin >> n, n){
		vector<P> vp1(n), vp2(n);
		P g1 = P(0,0), g2 = P(0,0);
		double x, y;
		for(int i=0;i<n;i++){
			cin >> x >> y; vp1[i] = P(x,y);
			g1 += vp1[i];
		}
		for(int i=0;i<n;i++){
			cin >> x >> y; vp2[i] = P(x,y);
			g2 += vp2[i];
		}
		g1 /= n;
		g2 /= n;
		// dSðdËí¹é
		for(int i=0;i<n;i++){
			vp1[i] -= g1;
			vp2[i] -= g2;
		}
		sort(vp1.begin(), vp1.end());
		double ans = 1e12;
		for(int i=0;i<n;i++){
			// ´_©çÌ£ªµ¢_ÉÂ¢ÄCÀÛÉñµÄm©ßÄÝé
			if(abs(abs(vp1[0])-abs(vp2[i])) < EPS){
				double r = rot(vp2[i], vp1[0]);
				vector<P> tmp(n);
				for(int j=0;j<n;j++){					
					tmp[j] = P(real(vp2[j])*cos(r)-imag(vp2[j])*sin(r),real(vp2[j])*sin(r)+imag(vp2[j])*cos(r));
				}
				sort(tmp.begin(), tmp.end());
				bool flag = true;
				for(int j=0;j<n;j++){
					flag &= (abs(vp1[j]-tmp[j]) < EPS);
				}
				if(flag) ans = min(ans, abs(r));
			}
		}
		printf("%.10lf\n", ans);
	}
}

Measured memory_bytes: 0
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(long long i=0;i<(long long)(n);i++)
#define N 200000

int main() {
	long long x, y, z;
	long long s, ans;
	scanf("%lld %lld", &x, &y);
	if ((y - x) >= 10000) {
		printf("0\n");
		return 0;
	}
  ans=10000;
	for (int i = x; i <= y; i++) {
		for (int j = x; j < i; j++) {
          z=i%2019;
          z=z*(j%2019);
          z%=2019;
			ans = min(ans, z);
		}
	}


	printf("%lld\n", ans);


	return 0;
}

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

using ll = long long;
using ull = unsigned long long;
using st = string;
using db = double;
using vll = vector<long long>;
using vvll = vector<vll>;
using vst = vector<st>;
using vchar = vector<char>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
using vvpll = vector<vpll>;
#define rep(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define vrep(i, vec) for(auto& i : vec)
#define vin(vec) for(auto& i : vec) cin >> i
#define all(v) v.begin(), v.end()
ll mod = 1000000007;

int main(){
  ll n;
  cin >> n;
  vst s(n);
  vin(s);
  map<st, ll> cnt;
  vrep(i, s){
    cnt[i]++;
  }
  priority_queue<st, vst, greater<st>> ans;
  ll max = 0;
  vrep(i, cnt){
    if(max < i.second){
      max = i.second;
      while(ans.size()) ans.pop();
      ans.push(i.first);
    }
    else if(max == i.second){
      ans.push(i.first);
    }
  }
  while(ans.size()){
    st a = ans.top();
    ans.pop();
    cout << a << endl;
  }
}

Measured memory_bytes: 28404
#include <bits/stdc++.h>
using namespace std;
int main() {
	ios::sync_with_stdio(false);
	int tmp;
	int tmp2;
	int cnt = 0;
	cin >> tmp;
	int ar1[tmp];
	for (int i = 0; i < tmp; i++)
		cin >> ar1[i];

	cin >> tmp2;
	int ar2[tmp2];
	for (int i = 0; i < tmp2; i++)
		cin >> ar2[i];

	for (int i = 0; i < tmp2; i++) {
		for (int j = 0; j < tmp; j++) {
			if (ar2[i] == ar1[j]) {
				cnt++;
				break;
			}
		}
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 3188
import bisect

n,q = map(int, input().split())
aList = list(map(int, input().split()))

sumList=[]
sep2SumList=[]
for i in range(n):
    if i==0:
        sumList.append(aList[i])
    else:
        sumList.append(sumList[-1]+aList[i])
    if n%2==0:
        if i%2==1:
            if i==1:
                sep2SumList.append(aList[i])
            else:
                sep2SumList.append(sep2SumList[-1]+aList[i])
    else:
        if i%2==0:
            if i==0:
                sep2SumList.append(aList[i])
            else:
                sep2SumList.append(sep2SumList[-1]+aList[i])

                
sakaime=[]
anskazu=(n+1)//2
for i in range(anskazu):
    sakaime.append((aList[n-(i+1+1)]+aList[n-((i+1+1)*2-1)])//2)
sakaime.reverse()
sakaime=sakaime[1:]

def kotae(x):
    bisect.bisect_left(sakaime,x)
    num=len(sakaime)+1-bisect.bisect_left(sakaime,x)
    if num==len(sakaime)+1:
        ans=sumList[-1]-sumList[-1-num]
    else:
        ans=sumList[-1]-sumList[-1-num]+sep2SumList[(n-num*2+1)//2-1]
    return ans

for i in range(q):
  x=int(input())
  print(kotae(x))

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

int main() {
    bool label=true;
    char array[55][55]={};
    int a, b;
    scanf("%d %d", &a, &b);
    
    for (int i=0;i<a;i++){
            scanf("%s",array[i]);
    }
     for (int i=0;i<a;i++){
        for(int j=0;j<b;j++){
           // cout<<array[i][j];
            if(array[i][j]=='#'){
                if(array[i][j]!=array[i-1][j]&&array[i][j]!=array[i][j-1]&&array[i][j]!=array[i+1][j]&&array[i][j]!=array[i][j+1]){
                    return printf("No"), 0;
                }
                }
            }
        }
    
    //cout<<array[2][2];
    printf("Yes");
	return 0;
}


Measured memory_bytes: 256
// --------------------<optimizations>--------------------
#pragma GCC optimize("O3")

//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)
#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)
#pragma GCC optimize("unroll-loops")
// -------------------</optimizations>--------------------
#include <iostream>
#include <bitset>
#include <algorithm>        // sort()
#include <vector>           // for vectors
#include <map>              // for ordered map
#include <unordered_map>
#include <list>             // for list
#include <iomanip>          // for setprecision()
#include <cmath>            // for pow(), sqrt(), log(), log10(), ....
#include <cstring>          // for memset()
#include <unordered_set>    // for unordered_set
#include <climits>          // for INT_MAX & INT_MIN
#include <set>              // for ordered set

#define C ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
typedef long long ll;
#define INF INT_MAX
#define NINF INT_MIN
#define MOD 1000000007
const double pi=acos(-1); // value of pi


bool isVowel(char ch) {
    if(ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u') {
        return 1;
    }
    return 0;
}

bool compare(pair<ll, ll> a, pair<ll, ll> b) {
    return a.second<b.second;
}


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

map<ll, list<ll>> m;
// map<ll, ll> m;

int main() {
    C
//     freopen("input.txt","r",stdin);
// 	freopen("output.txt","w",stdout);
    int t=1;
    //cin >> t;
    while(t--) {
        ll d, x, res=0;
        cin >> d;
        ll c[26];
        ll arr[d][26];
        ll la[26];
        for(ll i=0; i<26; i++) {
            cin >> c[i];
            la[i]=-1;
        }
        for(ll i=0; i<d; i++) {
            for(ll j=0; j<26; j++) {
                cin >> arr[i][j];
            }
        }
        for(ll i=0; i<d; i++) {
            cin >> x;
            x--;
            la[x]=i;
            res+=arr[i][x];
            for(ll j=0; j<26; j++) {
                res-=((c[j])*(i-la[j]));
            }
            cout << res << endl;
        }
    }
}


Measured memory_bytes: 3268
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef pair<int, int> P;
typedef long long ll;
    long long MOD = 1e9 + 7;
    long long modpow(long long a, long long n)
    {
        if (n == 0)
            return 1;
        if (n % 2 == 0)
        {
            long long t = modpow(a, n / 2);
            return t * t % MOD;
        }
        return a * modpow(a, n - 1) % MOD;
    }
    long long modinv(long long a)
    {
        // mod is prime
        return modpow(a, MOD - 2);
    }
ll combination(ll n,ll a){
    ll res = 1;
    rep(i,a){
        res*=n-i;
        res%=MOD;
    }
    ll inv = 1;
    rep(i,a){
        inv*=(i+1);
        inv%=MOD;
    }
    inv = modinv(inv);
    return res*inv%MOD;
}
int main(){
    ll n,a,b;
    cin >> n >> a >> b;
    ll ans = modpow(2,n)-1+MOD;
    ll res1 = combination(n,a);
    ll res2 = combination(n,b);
    ans+=(MOD-res1);
    ans+=(MOD-res2);
    ans%=MOD;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define ALLR(v) v.rbegin(), v.rend()
using namespace std;
typedef long long ll;
typedef long double ld;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  ll k;
  cin >> n >> k;
  vector<int> a(n),f(n);
  REP(i,n) cin >> a[i];
  REP(i,n) cin >> f[i];
  sort(ALL(a));
  sort(ALLR(f));
  ll l = -1, r = 1e18;
  while(l+1 < r){
    ll c = (l+r)/2;
    ll sum = 0;
    REP(i,n) sum += max(0ll, a[i]-c/f[i]);
    if(sum<=k) r = c;
    else l = c;
  }
  cout << r << '\n';
  return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>
int main(void)
{
	int n,p[100],i,j,x;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&p[i]);
	}
	for(i=0;;i++){
		x=0;
		for(j=0;j<n;j++){
			if(p[j]>=i){
				x++;
			}
		}
		if(x<i){
			break;
		}
	}
	printf("%d\n",i-1);
	return 0;
}

Measured memory_bytes: 596
import sys

n, y = map(int, input().split())

a = 10000
b = 5000
c = 1000
l = 0
m = 0
r = 0
sta = 0
stb = 0

for x in range(n+1):
    for z in range(n+1-x):
        sum = x * a + z * b + (n - x - z) * c

        if sum==y:
            print("{} {} {}".format(x,z,n-x-z))
            sys.exit()

print("{} {} {}".format(-1,-1,-1))


Measured memory_bytes: 3064
namespace ABC127.C
{
    using System;
    using static System.Console;
    using System.Linq;
    using System.Collections.Generic;
    public class Program
    {

        public static void Main(string[] args)
        {
            var l = ReadInputsAsInt().ToList();
            var n = l[0];
            var m = l[1];


            WriteLine(Solve(n, m, ReadLinesAsInts(m).ToList()));
        }

        public static int Solve(int n, int m, List<List<int>> restriction)
        {
            var LMax = restriction.Select(x => x[0]).Max();
            var RMin = restriction.Select(x => x[1]).Min();

            if (RMin - LMax < 0) return 0;
            return RMin - LMax + 1;
        }

        static IEnumerable<int> ReadInputsAsInt() => ReadLine().Split(' ').Select(x => int.Parse(x));

        static IEnumerable<List<int>> ReadLinesAsInts
            (int lines)
        {
            for (int i = 0; i < lines; i++)
            {
                var l = ReadLine();

                yield return l.Split(' ').Select(x => int.Parse(x)).ToList();
            }
        }

    }
}

Measured memory_bytes: 29728
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define mkp make_pair
#define in insert
#define er erase
#define fd find
#define fr first
#define sc second
#define all(x) x.begin(),x.end()
typedef long long ll;
typedef long double ld;
const ll INF=0x3f3f3f3f3f3f3f3f;
const ll llinf=(1LL<<62);
const int inf=(1<<30);
const int nmax=2e5+50;
const int mod=1e9+7;
using namespace std;
int x,y,na,nc,nb,i,j;
ll a[nmax],b[nmax],c[nmax],rs;
vector<ll>vc;
int main()
{
	//freopen("sol.in","r",stdin);
	//freopen("sol.out","w",stdout);
	//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
	cin>>x>>y>>na>>nb>>nc;
	for(i=1;i<=na;i++)cin>>a[i];
	for(i=1;i<=nb;i++)cin>>b[i];
	for(i=1;i<=nc;i++)cin>>c[i];
	sort(a+1,a+na+1);
	sort(b+1,b+nb+1);
	sort(c+1,c+nc+1);
	for(i=na;i>=na-x+1;i--)vc.pb(a[i]),rs+=a[i];
	for(i=nb;i>=nb-y+1;i--)vc.pb(b[i]),rs+=b[i];
	sort(all(vc));
	//reverse(all(vc));
	j=nc;
	for(i=0;i<x+y;i++)
	{
		if(vc[i]<c[j])rs+=c[j]-vc[i],j--;
		if(!j)break;
	}
	cout<<rs<<endl;
	return 0;
}


Measured memory_bytes: 5748
# stack
exp = input().split()
s = []

for lt in exp:
    if lt == '+':
        rhs = s.pop()
        lhs = s.pop()
        s.append(lhs + rhs)
    elif lt == '*':
        rhs = s.pop()
        lhs = s.pop()
        s.append(lhs * rhs)
    elif lt == '-':
        rhs = s.pop()
        lhs = s.pop()
        s.append(lhs - rhs)
    else:
        s.append(int(lt))
        
print(str(s[0]))

Measured memory_bytes: 7664
N = int(input())
A = list(map(int, input().split()))

wallet = 1000
stock = 0

for i in range(N - 1):
    if A[i] < A[i + 1] and wallet > 0:  # 次値上がり and 金がある→買う
        action = wallet // A[i]
        if wallet >= action * A[i]:
            stock += wallet // A[i]
            wallet -= action * A[i]
    elif A[i] > A[i + 1] and stock > 0:  # 次値下がり and 株持っている→売り
        wallet += stock * A[i]
        stock = 0
    # print(i, wallet, stock)

# 最後残っていたら全部売る
wallet += stock * A[-1]

print(wallet)


Measured memory_bytes: 9116
import java.util.Scanner;

public class Main
{

	public static void main(String[] args)
	{
		Scanner in = new Scanner(System.in);
		int a[] = new int[3];
		for (int i = 0; i < a.length; i++)
			a[i] = in.nextInt();

		for (int i = a.length - 1; i > 0; i--)
		{
			for (int j = i - 1; j >= 0; j--)
			{
				if (a[j] > a[i])
				{
					int temp = a[i];
					a[i] = a[j];
					a[j] = temp;
				}
			}
		}
System.out.println(a[0] + " " + a[1] + " " + a[2]);

	}

}

Measured memory_bytes: 26268
lst=[1 for i in range(0,100001)]

lst[0]=0
lst[1]=0
n=2

while n*n<=100000:
    if lst[n]:
        for i in range(n*n,100001,n):
            lst[i]=0
    n+=1

prinmelist=[]
for i in range(2,len(lst)):
    if lst[i]:
        prinmelist.append(i)
prinmelist.append(100003)
X=int(input())

for i in range(0,len(prinmelist)):
    if X<=prinmelist[i]:
        print(prinmelist[i])
        break


Measured memory_bytes: 4120
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rep1(i, n) for(int i=1; i<=n; i++)
#define repr(i, n) for(int i=n-1; i>=0; i--)
#define repr1(i, n) for(int i=n; i>=1; i--)
#define all(v) v.begin(),v.end()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
const double EPS = 1e-10;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

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

    ll ans = 0;
    ll cur = 0;
    rep(i, n) {
        if (a[i] > 0) cur += a[i];
        else {
            ans += cur / 2;
            cur = 0;
        }
    }
    ans += cur / 2;
    cout << ans << endl;
}


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

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ').Select(s => long.Parse(s)).ToArray();
            var N = input[0];
            var M = input[1];
            var ans = N * M;

            if (N == 1 && M == 1) {
                Console.WriteLine(ans);
            }
            else if (N == 1 || M == 1)
            {
                ans -= 2;
                Console.WriteLine(ans);
            }
            else
            {
                ans -= 2 * N + 2 * M - 4;
                Console.WriteLine(ans);
            }
        }
    }
}

Measured memory_bytes: 13268
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>

#define int long long
#define MOD 1000000007

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

using namespace std;

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


signed main() {
	int N;
	cin >> N;

	if (N == 1) cout << "Hello World" << endl;
	else {
		int A, B;
		cin >> A >> B;
		cout << A + B << endl;
	}
}


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

string str1 ,str2;
int a[30] ,b[30];

int main(){
    cin >> str1 >> str2;
    for(int i = 0;i < str1.size(); i++)
        a[str1[i] - 'a']++ ,b[str2[i] - 'a']++;
    sort(a ,a + 26),   sort(b ,b + 26);
    for(int i = 0; i < 26; i++)
        if(a[i] != b[i])
            return cout << "No", 0;
    cout << "Yes";
    return 0;
}




Measured memory_bytes: 776
n,k = gets.chomp.split.map(&:to_i)
as = gets.chomp.split.map(&:to_i)
ans = 10 ** 18

(2**n).times do |i|
	cnt = 0
	cost = 0
	height = 0
	n.times do |j|
		add = 0
		if i[j] == 1
			cnt += 1
			add = [height - as[j] + 1,0].max
		end
		cost += add
		height = as[j] + add if height < as[j] + add
	end
	ans = cost if cnt >= k && ans > cost
end

puts ans


Measured memory_bytes: 14264
N = int(input())
sum_a = 0
num = 10e10
for i in range(N):
  a,b = list(map(int,input().split()))
  sum_a += a
  if a > b:
    num = min(num,b)

if num == 10e10:
  print(0)
else:
  print(sum_a-num)


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

#define rep(i, a, b) for (int i = (a), i##end = (b); i <= i##end; ++i)
#define per(i, a, b) for (int i = (a), i##end = (b); i >= i##end; --i)

mt19937 Rnd(chrono::high_resolution_clock::now().time_since_epoch().count());

template <typename T>
inline void chkmax(T &x, T y) { if (x < y) x = y; }

template <typename T>
inline void chkmin(T &x, T y) { if (x > y) x = y; }

inline int read() {
  #define nc getchar()
  int x = 0;
  char c = nc;
  while (c < 48) c = nc;
  while (c > 47) x = x * 10 + (c ^ 48), c = nc;
  return x;
  #undef nc
}

typedef long long ll;

int main() {
  double x;
  cin >> x;
  double tmp = acos(-1);
  cout << 2.0 * tmp * x << endl;
  return 0;
}

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

#define forn(i,n) for(ll i = 0;i<n;i++)
#define forne(i,j,n) for(ll i = j;i<n;i++)
const ll mod = 1e9+7;
const ll mod2 = 998244353;
const ll INF = 1000000001;
const ll N = 100001;
const lld PI = 3.141593;
#define F first
#define pb(a) push_back(a)
#define S second
#define pii pair<int,int>
typedef pair<ll,ll> pll;

lld powm(ll base,ll exp) {
	ll ans=1;
	while(exp){
		if(exp&1) ans=(ans*base)%mod;
		exp>>=1,base=(base*base)%mod;
	}
	return ans;
}

// ll dir[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
// bool valid(ll i, ll j) {
// 	return i >= 1 && i <= n && j >= 1 && j <= m; 
// }
// int maxdepth = INT_MAX;
// vector<int> edgeVector[100000];
// ll minans = 1;
// printf("1 %d D\n",abs(r));
// priority_queue<ll,vector<ll>,greater<ll>> pq;
// ll a[N],b[N];
// vector<vector<ll>> adj(N);
// vector<set<ll>> adjs(N);
// ll adj[1001][1001];
// vector<vector<ll>> ans(1001);
// bool visited[N];
// ll cnt[1001];
// ll h,c,t;
// vector<pair<int, pair<int, int> > > g[300043];


int main(){
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output1.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

ll n;
cin>>n;
ll A[n];
forn(i,n){
	cin>>A[i];
}
ll B[n],C[n];
forn(i,n){
	if(i!=n-1){
		B[i] = (A[i]^A[i+1]);
	}
	else B[i] = (A[i]^A[0]);
}
ll a = A[0];
ll k = 1;
forn(i,(n/2)-1){
	a = a^(B[k]);
	k+=2;
}
a = a^(B[n-1]);
ll v = (a^A[0]);
forn(i,n){
	C[i] = (v^A[i]);
}
forn(i,n) cout<<C[i]<<" ";
cout<<endl;
// ll x = C[0];

// forne(i,1,n){
// 	x^=C[i];
// }
// forn(i,n) {
// 	cout<<(x^C[i])<<" ";
// }
// cout<<endl;


}

Measured memory_bytes: 8344