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

int main() {
  double W, H, X, Y;
  cin >> W >> H >> X >>Y;
  double ans = W/2.00*H;
  int hoka = 0;
  if(X==W/2 && Y ==H/2)hoka =1;
  
  cout << ans << " " << hoka << endl;
}

Measured memory_bytes: 3620
#ifdef __clang__
#include "bits/stdc++.h"
#else
#include <bits/stdc++.h>
#endif

using namespace std;
using ll = long long;

void atcoder()
{
  ll N, A, B;
  cin >> N >> A >> B;
  auto n = N / (A + B);
  auto r = N % (A + B);
  auto a = min(r, A);
  // nのうち最初のA個は青いボール
  cout << n * A + a;
}

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

Measured memory_bytes: 256
#include "stdio.h"


int main()
{
	int a, b;

	scanf("%d %d", &a, &b);

	if (a == 1)
		a += 13;
	if (b == 1)
		b += 13;
	
	if (a > b)
		puts("Alice");
	else if (a == b)
		puts("Draw");
	else if (a < b)
		puts("Bob");

    return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <numeric>

using namespace std;

inline int ctoi(const char c)
{
	return c >= '0'&&c <= '9' ? c - '0' : -1;
}

int main()
{
	int n;
	string s, x, y;

	cin >> n;
	cin >> s;

	int i, j;
	int cnt = 0, max = 0;
	for (i = 1; i < n; i++) {
		cnt = 0;
		for (char c = 'a'; c <= 'z'; c++) {
			bool left = false;
			bool right = false;
			for (j = 0; j < i; j++) {
				if (s[j] == c) {
					left = true;
				}
			}
			for (j = i; j < n; j++) {
				if (s[j] == c) {
					right = true;
				}
			}
			if (left && right) {
				cnt++;
			}
		}
		if (max < cnt) {
			max = cnt;
		}
	}

	cout << max << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define double long double
#define rep(i, a, n) for(int i = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int i = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int i = (int)(a);(x);++(i))
#define repr(i, a, n) for(int i = ((int)(a)-1);(i) >= (int)(n);--(i))
#define reper(i, a, n) for(int i = (int)(a);(i) >= (int)(n);--(i))
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x), end(x)
#define CEIL(x) ((int)ceil(((double)x)))
#define POW(x, y) ((int)pow(x, y))
#define UNIQUE(x) (x).erase(unique(ALL((x))), end(x))
#define gcd(x, y) __gcd(x, y)
#define lcm(x, y) ((x)/gcd(x,y)*(y))
#define isin(x, l, r) ((l) <= (x) and (x) < (r))
#define fcout cout << fixed << setprecision(10)
#define rcout(n) cout << right << setw(n)
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define PI (acos(-1))
#define EPS (1e-10)
#define INF LLONG_MAX
#define INF32 INT32_MAX
#define MOD 1000000007LL
using namespace std;
using VI = vector<int>;
using PII = pair<int, int>;
using TIII = tuple<int, int, int>;
using VPII = vector<PII>;
using VTIII = vector<TIII>;
using Complex = complex<double>;
template<typename T, template<typename> typename C = less> using PQ = priority_queue<T, vector<T>, C<T>>;
template<typename T> bool chmax(T& a, const T& b, bool t = false){ if(a<b or (t and a == b)){ a=b; return true; } return false; }
template<typename T> bool chmin(T& a, const T& b, bool t = false){ if(a>b or (t and a == b)){ a=b; return true; } return false; }


int N;
string S;
int dp[5010][5010];


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

    int ans = 0;
    repr(i, N, 0) repr(j, N, 0){
        if(S[i] == S[j]) dp[i][j] = dp[i+1][j+1]+1;
        if(i-j > 0) chmax(ans, min(dp[i][j], i-j));
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 195968
#include <bits/stdc++.h>
using namespace std;
#define finish(x) return cout << x << endl, 0
#define ll long long

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    string s;
    cin >> s;
    cout << s[0] << s[1] << s[2] << endl;
}


Measured memory_bytes: 3668
#include <stdio.h>

int width,height;
int map[17][17];
int ng_map[17][17];

int main(void) {
	int d_num,d_cur;
	int p,i,j;
	int x1,y1,x2,y2,t;
	scanf("%d",&d_num);
	for(d_cur=0;d_cur<d_num;d_cur++) {
		scanf("%d%d",&width,&height);
		for(i=0;i<17;i++) {
			for(j=0;j<17;j++)map[i][j]=ng_map[i][j]=0;
		}
		scanf("%d",&p);
		for(i=0;i<p;i++) {
			scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
			if(x1>x2){t=x1;x1=x2;x2=t;}
			if(y1>y2){t=y1;y1=y2;y2=t;}
			if(x1!=x2) {
				ng_map[y2+1][x2+1]|=1;
			} else {
				ng_map[y2+1][x2+1]|=2;
			}
		}
		map[1][1]=1;
		for(i=1;i<=height+1;i++) {
			for(j=1;j<=width+1;j++) {
				if(!(ng_map[i][j] & 1))map[i][j]+=map[i][j-1];
				if(!(ng_map[i][j] & 2))map[i][j]+=map[i-1][j];
			}
		}
		if(map[height+1][width+1]==0)puts("Miserable Hokusai!");
		else printf("%d\n",map[height+1][width+1]);
	}
	return 0;
}

Measured memory_bytes: 0
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int main(){
    int N,p;
    int ansb = true;
    cin >> N ;
    int a[10000] = {0};
    rep(i,N){
        cin >> p;
        if(p%2==0){
            if(p%3!=0&&p%5!=0){
                ansb = false;
            }
        }
    }
    if(ansb){
        cout <<"APPROVED"<< endl;
    }else{
        cout <<"DENIED"<< endl;
    }
}

Measured memory_bytes: 256
X = int(input())

if 400 <= X <=599 :
  print("8")
elif 600 <= X <=799 :
  print("7")
elif 800 <= X <=999 :
  print("6")
elif 1000 <= X <=1199 :
  print("5")
elif 1200 <= X <=1399 :
  print("4")
elif 1400 <= X <=1599 :
  print("3")
elif 1600 <= X <=1799 :
  print("2")
elif 1800 <= X <=1999 :
  print("1")


Measured memory_bytes: 9172
x, y, a, b, c = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))
p = sorted(p, reverse=True)
q = sorted(q, reverse=True)
r = sorted(r, reverse=True)
s = p[:x] + q[:y]
s = sorted(s, reverse=True)
i = 1
I = 0
while i <= len(s) and i <= len(r) and s[-i] <= r[i-1]:
    I = i
    i += 1
S = s[:x+y-I] + r[:I]
# print(S)
print(sum(S))

Measured memory_bytes: 111724
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    
		String x = "";
		try {
			while ((x = in.readLine()) != null) {
				if (x.equals("0 0")) break;
				
				String[] values = x.split(" ");
	
				int a = Integer.parseInt(values[0]);
				int b = Integer.parseInt(values[1]);
				
				for (int i = 0; i < a; i++) {
					for (int j = 0; j < b; j++) {
						if (((i + j) % 2) == 0) {
							System.out.print('#');
						} else {
							System.out.print('.');
						}
					}
					System.out.println();
				}
				System.out.println();
			}
		} catch (NumberFormatException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}

Measured memory_bytes: 35412
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=100010;
int n,m,b[N<<1];
ll c[N<<1],f[N<<1];
int main(){
	int t1,t2,temp1,temp2;
	ll ans1=0;
	scanf("%d%d",&n,&m);
	scanf("%d",&temp1);
	for(int i=1;i<n;i++){
		scanf("%d",&temp2);
		ans1+=(temp2-temp1+m)%m;
		if(temp1==temp2-1){
			temp1=temp2;continue;
		}
		t1=temp1,t2=temp2;
		t1+=2;
		if(t1>t2) t2+=m;
		if(t1>m&&t2>m) t1-=m,t2-=m;
		b[t1]+=1,b[t2+1]-=1,c[t2+1]-=t2-t1+1;
		temp1=temp2;
	}
	ll now=0,cnt=0,ans=0;
	for(int i=1;i<=(m<<1);i++){
		cnt+=b[i];
		now+=cnt+c[i];
		f[i]=now;
		if(i>m) ans=max(ans,f[i]+f[i-m]);
	}
//	cout<<ans1<<" "<<ans<<endl;
	printf("%lld\n",ans1-ans);
}

Measured memory_bytes: 3328
const main = stdin => {
  const input = stdin.trim().split('\n')
  const N = parseInt(input[0])
  const lines = input[1].trim().split(' ').map(x => parseInt(x))

  let count = 0
  for (let i = 0; i < N; i++) {
    for (let j = i + 1; j < N; j++) {
      for (let k = j + 1; k < N; k++) {
        if (lines[i] !== lines[j] && lines[i] !== lines[k] && lines[j] !== lines[k]) {
          if (lines[i] + lines[j] > lines[k] && lines[j] + lines[k] > lines[i] && lines[k] + lines[i] > lines[j]) {
            count++
          }
        }
      }
    }
  }

  console.log(count)
}


// 標準入力
main(require("fs").readFileSync("/dev/stdin", "utf8"))


Measured memory_bytes: 32480
#include<iostream>
#include<sstream>
#include<vector>
#include<iterator>
#include<utility>
using namespace std;
 
int N;
vector<vector<pair<int, int>>> edge;
 
const int INIT = -1;
vector<int> color;
 
void dfs(int pos, int dist, int diff)
{
    if (color[pos] != INIT)
        return;
 
    color[pos] = dist % 2;
    for (int i = 0; i < (int)edge[pos].size(); i++) {
        int dst = edge[pos][i].first;
        int weight = edge[pos][i].second;
 
        int sum = dist + weight;
        dfs(dst, sum, sum - dist);
    }
}
 
int main(void)
{
    cin >> N;
 
    edge = vector<vector<pair<int, int>>>(N, vector<pair<int, int>>());
    for (int i = 0; i < N - 1; i++) {
        int u, v, w;
        cin >> u >> v >> w;
 
        u--;
        v--;
        w %= 2;
 
        edge[u].push_back(make_pair(v, w));
        edge[v].push_back(make_pair(u, w));
    }
 
    
    color = vector<int>(N, INIT);
    dfs(0, 0, 0);
 
    for (int i = 0; i < N; i++)
        cout << color[i] << endl;
 
    return 0;
}

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

using namespace std;

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

    int n, nKeys;
    cin >> n >> nKeys;
    vector<int> cost(nKeys);
    vector<int> unlock(nKeys);
    for (int i = 0; i < nKeys; ++i) {
        int cnt;
        cin >> cost[i] >> cnt;
        int mask = 0;
        for (int j = 0; j < cnt; ++j) {
            int bit;
            cin >> bit;
            mask |= (1 << (bit - 1));
        }
        unlock[i] = mask;
    }
    vector<int> dp(1 << n, INT_MAX);
    dp[0] = 0;
    for (int mask = 0; mask < (1 << n); ++mask) {
        for (int key = 0; key < nKeys; ++key) {
            if (dp[mask] == INT_MAX) {
                continue;
            }
            dp[mask | unlock[key]] = min(dp[mask | unlock[key]], dp[mask] + cost[key]);
        }
    }
    int ret = dp.back();
    cout << (ret != INT_MAX ? ret : -1) << '\n';

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int B[8][8]={{1,2,1,2,1,4,1,4},{1,2,1,4,1,4,1,2},{1,4,1,2,1,2,1,4},{1,4,1,4,1,2,1,2},{2,1,2,1,4,1,4,1},{2,1,4,1,4,1,2,1},{4,1,2,1,2,1,4,1},{4,1,4,1,2,1,2,1}};
int d[8];
int cal(int num){
	int TMP=0;
	for(int i=0;i<8;i++){
		if(d[i]>B[num][i]){
			TMP+=(d[i]-B[num][i]);
		}
	}
	return TMP;
}
int main(){
	int tmp,f;
	while(cin>>d[0]){
		for(int i=1;i<8;i++)cin>>d[i];
		f=1;
		tmp=cal(0);
		for(int i=1;i<8;i++)if(tmp>cal(i))tmp=cal(i);
		for(int i=0;f;i++){
			if(tmp==cal(i)){
				for(int j=0;j<8;j++){
					if(j<7)cout<<B[i][j]<<" ";
					else cout<<B[i][j]<<endl;
				}
				f=0;
			}
		}
		
		
	}
	return 0;
}


Measured memory_bytes: 1160
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
#define rep(X,N) for(ll X = 0; X < (N); X++)
#define PI (acos(-1.0))
#define pback push_back
#define mpair make_pair
#define MODN 1000000007
#define ALL(V) (V).begin(),(V).end()

typedef long long ll;

using namespace std;
//using namespace boost::multiprecision;


int main(){

    int n;
    cin >> n;

    vector<int> d;

    rep(i,n){
        int tmp;
        cin >> tmp;
        d.pback(tmp);
    }

    sort(ALL(d));

    int left = d[n / 2 - 1];
    int right = d[n / 2];

    cout << right - left << endl;


    return 0;
}

Measured memory_bytes: 892
from fractions import gcd
from math import factorial, ceil, sqrt, atan2, log
from itertools import *
import string
import copy
import random
import bisect
from decimal import *
def id_generator(size=20, chars=string.digits):
    return ''.join(random.choice(chars) for _ in range(size))
 
def mp():
    return map(int,str(raw_input()).split())

a,b=mp()
s=str(a)+str(b)
s=int(s)
if int(sqrt(s))**2==s:
	print 'Yes'
else:
	print 'No'

Measured memory_bytes: 6028
import java.util.*;
import java.io.*;
public class Main{
	public static void main(String[] args) throws IOException{
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
	int a = Integer.parseInt(reader.readLine());
	int res = a+a*a+a*a*a;
	System.out.println(res);
	}
}


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

using namespace std;
using ll = long long;
using pii = std::pair<int, int>;

#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define pb push_back

const int mn = 1e5 + 5;

struct edge {
    int u, v, color;

    int to(int x) {
        return x == u ? v : u;
    }
} e[mn];

int n;
vector<int> g[mn];

void dfs(int x, int fid) {
    int fa = e[fid].to(x);
    int fcolor = e[fid].color;
    int k = 0;
    for (auto &i:g[x]) {
        edge &E = e[i];
        if (E.to(x) == fa) continue;
        k++;
        while (k == fcolor) k++;
        E.color = k;
        dfs(E.to(x),i);
    }
}

int main() {
#ifdef trote
    freopen("../1.txt", "r", stdin);
#endif
    scanf("%d", &n);
    int ans = 0;
    for (int i = 1; i < n; i++) {
        scanf("%d%d", &e[i].u, &e[i].v);
        g[e[i].u].pb(i);
        g[e[i].v].pb(i);
        ans = max(ans, max(sz(g[e[i].u]), sz(g[e[i].v])));
    }
    printf("%d\n", ans);
    dfs(1, 0);
    for (int i = 1; i < n; i++) printf("%d\n", e[i].color);
    return 0;
}

Measured memory_bytes: 8832
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll;
typedef double db;
const int N = 10;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int dp[N][10];
	for (int i = 0; i < 10; ++i)
		dp[0][i] = 1;
	for (int i = 1; i < N; ++i)
	{
		for (int j = 0; j < 10; ++j)
		{
			dp[i][j] = 0;
			for (int k = max(j - 1, 0); k <= min(9, j + 1); ++k)
				dp[i][j] += dp[i - 1][k];
		}
	}
	int k;
	cin >> k;
	if (k < 13)
	{
		cout << k;
		return 0;
	}
	int sum = 0, x = 0, y = 1;
	while (sum + dp[x][y] < k)
	{
		sum += dp[x][y];
		y += 1;
		if (y == 10)
		{
			x += 1;
			y = 1;
		}
	}
	cout << y;
	while (x > 0)
	{
		k -= sum;
		sum = 0;
		x -= 1;
		y = max(y - 1, 0);
		while (sum + dp[x][y] < k)
		{
			sum += dp[x][y];
			y += 1;
		}
		cout << y;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <math.h>
#include <map>
#include <functional>
#include <iomanip>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <typeinfo>
#define PI 3.14159265359
#define INF 99999999
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(n) rep(i, n)
#define pb push_back
#define mp make_pair
typedef long long ll;
using namespace std;
typedef pair<int, int> P;

string name;
int gozen, gogo;

int main()
{
	while (cin >> name >> gozen >> gogo)
	{
		cout << name << " " << gozen + gogo << " " << 200 * gozen + 300 * gogo << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1200
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,n) for(int i=1; i<=(n); i++)

int main() {
    int n,x,ans=1,d=0;
    cin>>n>>x;
    vector<int>l(n);
    rep(i,n)cin>>l[i];
    rep(i,n){
        d+=l[i];
        if(d<=x)ans++;
    }
    cout<<ans;
	return 0;
}

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

int main() {
	string sa,sb,sc;
	cin >> sa >> sb >> sc;
	
	int a=0,b=0,c=0;
	int turn=0;
			char x;
	while(true){

		if(turn==0){
				if(a==sa.length()){cout << "A"<<endl; return 0;}
			x=sa[a];
			a++;
			
		}
		else if(turn==1){
				if(b==sb.length()){
				cout<<"B"<<endl; return 0;
			}
			x=sb[b];
			b++;
		
		}
		else if(turn ==2){
				if(c==sc.length()){
				cout << "C"<<endl; return 0;
			}
			x=sc[c];
			c++;
		
		}
		
		switch(x){
			case 'a': turn =0; break;
			case 'b' : turn =1; break;
			case 'c' : turn =2; break;
			
		}
	
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <string>    
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
ll q, h, s, d, n;

int main(){
	cin >> q >> h >> s >> d >> n;
	ll mins = min(min(4*q, 2*h), s);
	ll mind = min(2*mins, d);
	ll ans = (n%2)? (n/2)*mind+mins : (n/2)*mind;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);
		String[] temp = scanner.nextLine().split(" ");
		int n = Integer.parseInt(temp[0]);
		int m = Integer.parseInt(temp[1]);

		if(n > 8 || m > 8) {
			System.out.println(":(");
		}else {
			System.out.println("Yay!");
		}

	}

}


Measured memory_bytes: 23764
import math
import itertools

def main():
    r = [tuple(map(int, input().split())) for _ in range(int(input()))]
    d = 0
    for x in itertools.permutations(r):
        #print("x", x)
        for i in range(len(x)-1):
            d += math.sqrt((x[i][0]-x[i+1][0])**2 + (x[i][1]-x[i+1][1])**2)
    print(d/math.factorial(len(r)))
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 3188
# include <stdio.h>
# include <bits/stdc++.h>
using namespace std;
# define fi cin
# define fo cout
# define x first
# define y second
# define ll long long
# define IOS ios_base :: sync_with_stdio(0);cin.tie(0)
# define p(v) cerr << #v << " = " << v << '\n'
# define p2(v) cerr << #v << " = " << (complex < int > (v.x,v.y)) << '\n'
# define vi vector < int >
# define vll vector < ll >
# define pii pair < int , int >
# define mp make_pair
# define db long double
# define pdd pair < db , db >
int main(void)
{
    #ifdef CF
    freopen("input","r",stdin);
    #endif // CF
    srand(time(0));
    fo << fixed << setprecision(7);
    cerr << fixed << setprecision(7);
    int n,m;
    fi>>n>>m;
    static int cnt[1 << 20];
    static map < int , int > s[1 << 20];
    int v;
    for (int i = 1;i <= n;++i)
        fi>>v,s[v % m][v]++,cnt[v % m]++;;
    ll ans = 0;
    for (int i = 0;i + i <= m;++i)
    {
        int a = i;
        int b = (m - i) % m;
        if (a == b)
            ans += cnt[i] / 2;
        else
        {
            if (cnt[a] < cnt[b]) swap(a,b);
            for (auto &it : s[a])
                if ((it.y & 1) && cnt[b])
                    --cnt[a],--cnt[b],++ans,--it.y;
            for (auto &it : s[a])
            {
                int can = min(cnt[b],it.y);
                cnt[b] -= can;
                it.y -= can;
                ans += can;
                ans += it.y / 2;
            }
        }
    }
    fo << ans << '\n';
    cerr << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
    return 0;
}




Measured memory_bytes: 54528
N = int(input())
a = list(map(int, input().split()))
M = N//2
ans = -1

def fun(x):
    u = 0
    n = N//x-1
    for i in range(n):
        u+=a[x*(i+2)-1]
    return u%2

for i in range(M):
    y = fun(M-i)
    if a[M-i-1] == 1 and y == 1:
        a[M-i-1] = 0
    elif a[M-i-1] == 0 and y == 1:
        a[M-i-1] = 1

print(sum(a))
for j in range(N):
    if a[j] == 1:
        print(str(j+1)+" ", end="")

    

Measured memory_bytes: 7276
import math

temp = input().split(' ')
monter_count = int(temp[0])
kill_count = int(temp[1])
 
temp = input().split(' ')
# 数値の配列に変換
temp = [int(s) for s in temp]
# 体力の多い順にソート
temp.sort(reverse=True)
del(temp[0:kill_count])

print(sum(temp))

Measured memory_bytes: 25764
#include <bits/stdc++.h>
using namespace std;
long a[200005],n,k;
bool check(int m)
{
    int sl=0;
    for(int i=1;i<=n;i++)
    {
        sl=sl+(a[i]/m);
        if(a[i]%m==0) sl--;
    }
    return (sl<=k);
}
int main()
{
    long dau=1,cuoi,giua,M;
    cin>>n>>k;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        cuoi=max(cuoi,a[i]);
    }
    while(dau<=cuoi)
    {
        giua=(dau+cuoi)/2;
        if(check(giua)==true)
        {
            M=giua;
            cuoi=giua-1;
        }
        else dau=giua+1;
    }
    cout<<M;
}


Measured memory_bytes: 5156
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10**9)
mod = 10**9+7

H,W = I()
maze = [list(s()) for _ in range(H)]
ans = 0
for i in range(H):
    for j in range(W):
        if maze[i][j] == '#':
            continue
        dist = [[-1]*W for _ in range(H)]
        dist[i][j] = 0
        que = deque([[i,j]])
        while que:
            h,w = que.pop()
            for dh,dw in [[1,0],[0,1],[-1,0],[0,-1]]:
                nh = h+dh
                nw = w+dw
                if nh < 0 or nw < 0 or nh >= H or nw >= W:
                    continue
                if maze[nh][nw] == '#':
                    continue
                if dist[nh][nw] == -1:
                    dist[nh][nw] = dist[h][w]+1
                    que.appendleft([nh,nw])
        ans = max(ans,max([max(d) for d in dist]))
print(ans)


Measured memory_bytes: 79408
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <cstring>
#include <cassert>
#define N (ll)(2e6+5)
#define INF (ll)(1e18+3)

#define ll long long
#define rep(i,a,n) for(ll i = a; i < n; i++)
#define per(i,a,n) for(ll i = n-1; i >= a; i--)

using namespace std;

bool dp[10005];
ll a[105];

void solve() {
    ll n;
    cin >> n;
    rep(i,0,n) {
        cin >> a[i];
    }

    dp[0] = true;
    rep(i,0,n) {
        per(j,0,10005) {
            if (j-a[i] >= 0) {
                dp[j] |= dp[j-a[i]];
            }
        }
    }
    ll ans = 0;
    rep(i,0,10005) {
        if (dp[i] && i%10 != 0)
            ans = i;
    }
    cout << ans << endl;
}

int main() {
    solve();
}

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

using namespace std;

typedef long long ll;

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(void) {
    int A, B;
    cin >> A >> B;

    for (int i = 0; i <= 1000; i++) {
        int a = (int) double(i) * 0.08;
        int b = (int) double(i) * 0.10;

        if (a == A && b == B) {
            cout << i << endl;
            return 0;
        }
    }

    cout << -1 << endl;
    return 0;
}


Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();

    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let k: i32 = read();
    let x: i32 = read();

    for i in x - (k - 1)..x + k {
        print!("{} ", i);
    }
}


Measured memory_bytes: 4352
IDENTIFICATION DIVISION.
       PROGRAM-ID. ABC042-A.
       DATA DIVISION.
       FILE SECTION.
       WORKING-STORAGE SECTION.
       77 STR PIC X(100).
       77 COUNT5 PIC 9(1) VALUE ZERO.
       77 COUNT7 PIC 9(1) VALUE ZERO.

       PROCEDURE DIVISION.
       MAIN-PROCEDURE.
               ACCEPT STR FROM SYSIN.
               INSPECT STR TALLYING
                   COUNT5 FOR ALL "5"
                   COUNT7 FOR ALL "7".
               IF COUNT5 = 2 AND COUNT7 = 1 THEN
                   DISPLAY "YES"
               ELSE
                   DISPLAY "NO"
               END-IF
               STOP RUN.
       END PROGRAM ABC042-A.


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

# AtCoder Beginner Contest
# Problem A

if __name__ == '__main__':
    current_hour, add_hour = list(map(int, input().split()))
    contest_hour = current_hour + add_hour

    if contest_hour < 24:
        print(contest_hour)
    else:
        print(contest_hour - 24)


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

using namespace std;

void solve() {
    long long n, k; cin >> n >> k;
    if (n >= k) {
        n %= k;
    }
    cout << min(n, k - n);
}

int main() {
    ios::sync_with_stdio(NULL), cin.tie(0), cout.tie(0);
    cout.setf(ios::fixed), cout.precision(20);
    solve();
}


Measured memory_bytes: 256
<?php
fscanf(STDIN,"%d",$n);
$A = explode(" ",trim(fgets(STDIN)));
$cnt = 0;
$f = $n - 1;
for($i = 0; $i < $f; ++$i){
    for($j = $f; $j > $i; --$j){
        if($A[$j - 1] > $A[$j]){
            $v = $A[$j - 1];
            $A[$j - 1] = $A[$j];
            $A[$j] = $v;
            $cnt++;
        }
    }
}
echo implode(" ",$A)."\n";
echo $cnt."\n";

Measured memory_bytes: 15320
def slove():
    import sys
    import fractions
    input = sys.stdin.readline
    a, b = list(map(int, input().rstrip('\n').split()))
    gcd = fractions.gcd(a, b)
    cnt = 1
    s = 2
    e = int(gcd ** 0.5) + 1
    d = True
    while True:
        if d:
            d = False
            for i in range(s, e):
                if gcd % i == 0:
                    d = True
                    cnt += 1
                    while True:
                        if gcd % i == 0:
                            gcd //= i
                        else:
                            break
                    s = i + 1
                    e = int(gcd ** 0.5) + 1
                    break
        else:
            break
    if gcd != 1:
        cnt += 1
    print(cnt)


if __name__ == '__main__':
    slove()


Measured memory_bytes: 64620
#include <functional>
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;

int main() {
    int n;
    int m;
 
   cin >> n >> m;
  
   cout << (n-1)*(m-1) << endl;
//   cout << m << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
#include <cmath>
#include <memory>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin)-1; (LoopVariable) >= (numberOFend); (LoopVariable)--)
#define REP(LoopVariable,numberOFend) for(int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

constexpr long long int linf = numeric_limits<long long int>::max()-5;
constexpr int inf= numeric_limits<int>::max()-5;
constexpr long long int mod = 1000000007;

int main(){

    long long int n;
    cin >> n;
    if(n==0){
        cout << 0 << endl;
    }else{
        string s;
        long long int loop = 1;
        while(n!=0){
            if(n%(long long int)pow(2,loop)){
                s.push_back('1');
                n -= pow(-2, loop-1);
            }else{
                s.push_back('0');
            }


            loop++;
        }
        reverse(s.begin(),s.end());
        cout << s << endl;
    }
    

    return 0;
}


Measured memory_bytes: 888
@a = nil
@n = nil

def prim
  d = Array.new(@n, Float::INFINITY)
  color = Array.new(@n, "WHITE")
  p = []
  d[0] = 0
  p[0] = -1
  u = nil

  while true
    mincost = Float::INFINITY
    (0..@n-1).each do |i|
      if color[i] != "BLACK" && d[i] < mincost
        mincost = d[i]
        u = i
      end
    end

    break if mincost == Float::INFINITY

    color[u] = "BLACK"

    (0..@n-1).each do |v|
      if color[v] != "BLACK" && @a[u][v] != -1
        if @a[u][v] < d[v]
          d[v] = @a[u][v]
          p[v] = u
          color[v] = "GLAY"
        end
      end
    end
  end

  return d.reduce { |sum, i| i == Float::INFINITY ? 0 : sum + i }
end

def main
  @n = gets.to_i
  @a = Array.new(@n).map { Array.new(@n, nil) }
  (0..@n-1).each do |i|
    @a[i] = gets.split.map { |j| j.to_i }
  end
  puts prim
end

main

Measured memory_bytes: 8804
#include<stdio.h>
#include<math.h>

int judge(int x, int y, int z, int n){
    int cnt, rx, ry, rz;
    cnt = n;
    if (x%2==1 || y%2==1 || z%2==1){
        return cnt;
    }
    rx = y/2+z/2; ry = z/2+x/2; rz = x/2+y/2;
    cnt += 1;
    return judge(rx, ry, rz, cnt);
}

int main(){
    int a, b, c, ans;
    scanf("%d %d %d", &a, &b, &c);
    if (a%2==1 || b%2==1 || c%2==1){
        printf("0");
        return 0;
    }
    if (a==b && b==c){
        printf("-1");
        return 0;
    }
    ans = judge(a, b, c, 0);
    
    printf("%d", ans);
    
    return 0;
}


Measured memory_bytes: 128
package main

import (
	"bytes"
	"fmt"
	"sort"
)

func main() {
	var s, t string
	fmt.Scan(&s, &t)
	x, y := []byte(s), []byte(t)
	sort.Slice(x, func(i, j int) bool { return x[i] < x[j] })
	sort.Slice(y, func(i, j int) bool { return y[i] > y[j] })
	if bytes.Compare(x, y) == -1 {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


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

int main(void){

    int K;
    cin >> K;
    string s;
    int ans = 0, flag = 1;
    for (int i = 1; i <= K; i++){
        s = to_string(i);
        if(s.size()%2 == 1){
            ans++;
        }
        
    }

    cout << ans << endl;

    return 0;
}

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

int main(void)
{
	ios_base::sync_with_stdio(0);
	string s;
	cin >> s;
	int a = (s[0] - '0') * 10 + (s[1] - '0');
	int b = (s[2] - '0') * 10 + (s[3] - '0');
	int y = -1, m = -1;
	if(a > 0 && a <= 12 && b > 0 && b <= 12)
                cout << "AMBIGUOUS";
        else if(a > 0 && a <= 12 && (b == 0 || b > 12))
                cout << "MMYY";
        else if((a == 0 || a > 12) && b > 0 && b <= 12)
                cout << "YYMM";
        else
                cout << "NA";
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#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>
#include <climits>
#define ll long long
#define ld long double
#define mp make_pair
#define pb push_back
#define in insert
#define vll vector<ll>
#define endl "\n"
#define pll pair<ll,ll>
#define f first
#define s second
#define FOR(i,a,b) for(int i=(a),_b=(b); i<=_b; i++)
#define int ll
#define sz(x) (ll)x.size()
#define all(x) (x.begin(),x.end())
using namespace std;

 
const ll INF = 1e12;
const ll N =(1e5+5); // TODO : change value as per problem
const ll MOD = 1e9+7;

int col[N];
vector<int> adj[N];
bool vis[N];
void dfs(int u,int c){
	vis[u]=true;
	col[u]  =c;
	for(auto v:adj[u]){
		if(vis[v]==false){
			dfs(v,c^1);
		}
	}
}
void solve(){
	int n,m;
	cin>> n >> m;	
	vector<pll> ed;
	for(int i =1;i<=m;i++){
		int u,v;
		cin >> u >> v;
		adj[u].pb(v);
		adj[v].pb(u);
		ed.pb(mp(u,v));
	}
	dfs(1,0);
	bool bip= true;
	int a = 0,b=0;
	for(auto p:ed){
		bip &= (col[p.f] != col[p.s]);
	}
	for(int i =1;i<=n;i++){
		if(col[i]) a++;
		else b++;
	}
	if(bip){
		cout<<(a*b)-m<<endl;
		return;
	}
	cout << ((n*(n-1))>>1ll) - m << endl;

}
signed main(){
 
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
     // freopen(".in","r",stdin);freopen(".out","w",stdout);
    
     ll tt=1;   
     // cin >> tt;
    while(tt--){    
        solve();
    }    
}

Measured memory_bytes: 12632
#!usr/bim/python
#! -*- coding: utf-8 -*-

n = raw_input()
n = int(n)

maxa = 0

for i in range(n):
    ab = raw_input()
    ab = ab.split()
    a,b = map(int,ab)
    if a > maxa:
        maxa = a
        minb = b

ans = maxa + minb

print ans


Measured memory_bytes: 5764
a,b,c,x,y=map(int,input().split())
s = []
for i in range(max(x,y)+1):
    xs=x-i
    ys=y-i
    if xs <= 0:
        xs=0
    if ys <= 0:
        ys=0
    s.append(a*xs+b*ys+c*2*i)
print(min(s))


Measured memory_bytes: 44784
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#define rep(i, n) for(i = 0; i < n; i++)
using namespace std;

int h, w, n;
int sr, sc;
string s;
string t;

bool checkU(int y) {
	int i;
	rep(i, n) {
		if (s[i] == 'U') y--;
		if (y < 0) return false;
		if (y < h - 1 && t[i] == 'D') y++;
	}
	return true;
}

bool checkD(int y) {
	int i;
	rep(i, n) {
		if (s[i] == 'D') y++;
		if (y >= h) return false;
		if (y > 0 && t[i] == 'U') y--;
	}
	return true;
}

bool checkL(int x) {
	int i;
	rep(i, n) {
		if (s[i] == 'L') x--;
		if (x < 0) return false;
		if (x < w - 1 && t[i] == 'R') x++;
	}
	return true;
}

bool checkR(int x) {
	int i;
	rep(i, n) {
		if (s[i] == 'R') x++;
		if (x >= w) return false;
		if (x > 0 && t[i] == 'L') x--;
	}
	return true;
}

int getU() {
	int st = -1, ed = 1e+6, mid;	//xxxooo, (st, ed]
	while (ed - st >= 2) {
		mid = (st + ed) / 2;
		if (checkU(mid)) ed = mid;
		else st = mid;
	}
	return ed;
}

int getD() {
	int st = -1, ed = 1e+6, mid;	//oooxxx, [st, ed)
	while (ed - st >= 2) {
		mid = (st + ed) / 2;
		if (checkD(mid)) st = mid;
		else ed = mid;
	}
	return st;
}

int getL() {
	int st = -1, ed = 1e+6, mid;	//xxxooo, (st, ed]
	while (ed - st >= 2) {
		mid = (st + ed) / 2;
		if (checkL(mid)) ed = mid;
		else st = mid;
	}
	return ed;
}

int getR() {
	int st = -1, ed = 1e+6, mid;	//oooxxx, [st, ed)
	while (ed - st >= 2) {
		mid = (st + ed) / 2;
		if (checkR(mid)) st = mid;
		else ed = mid;
	}
	return st;
}

signed main() {
	int i, j;
	
	cin >> h >> w >> n;
	cin >> sr >> sc; sr--; sc--;
	cin >> s >> t;
	
	int ly = getU();
	int ry = getD();
	int lx = getL();
	int rx = getR();
	
	if (ly <= sr && sr <= ry && lx <= sc && sc <= rx) cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}


Measured memory_bytes: 776
n,m=map(int,input().split())
a=[list(input()) for i in range(n)]
b=[list(input()) for i in range(m)]
f=True
for i in range(n-m+1):
  for j in range(n-m+1):
    f=True
    for k in range(i,i+m):
      for l in range(j,j+m):
        if b[k-i][l-j]!=a[k][l]:
          f=False
    if f:
      print('Yes')
      break
  if f:
    break
if not f:
  print('No')


Measured memory_bytes: 3064
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {

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

		for (int i = 0; i < m; i++) {
			Arrays.fill(s[i], 0);
		}

		for (int i = 0; i < m; i++) {
			int k = sc.nextInt();
			for (int j = 0; j < k; j++) {
				s[i][sc.nextInt() - 1] = 1;
			}
		}

		for (int i = 0; i < m; i++) p[i] = sc.nextInt();

		int ans = 0;
		for (int i = 0; i < (1 << n); i++) {
			List<Integer> list = new ArrayList<>();
			for (int j = 0; j < n; j++) {
				if (((i >> j) & 1) == 1) {
					list.add(j);
				}
			}
			boolean can = true;
			for (int j = 0; j < m; j++) {
				int cnt = 0;
				for (int x : list) {
					if (s[j][x] == 1) cnt++;
				}
				if (cnt % 2 != p[j]) can = false;
			}
			if (can) ans++;
		}

		System.out.println(ans);

		sc.close();

	}

}


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

int main() {
    string s;
    int count;
    cin >> s;
    count = 0;
    for (int i = 0; i < s.size();i++){
        if(s[i]=='1'){
            count++;
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MAX 10000
static const int INFTY = (1 << 20);
#define WHITE 0
#define BLACK 1

// グラフの頂点数
int n;
// 隣接リスト表現(第1成分は頂点番号、第2成分は辺の重み)
vector<vector<pair<int, int> > > G(MAX);
// 頂点のコストを記録する配列
vector<int> d(MAX, INFTY);
// 頂点の状態を記録する配列
vector<int> color(MAX, WHITE);

void dijkstra()
{
  // コストが小さいものを優先する優先度付きキュー
  // 第1成分は辺の重み*(-1)、第2成分は頂点番号
  priority_queue<pair<int, int> > PQ;
  // 初期化
  d.at(0) = 0;
  PQ.push(make_pair(0, 0));
  while (!PQ.empty())
  {
    pair<int, int> f = PQ.top();
    int v = f.second;
    PQ.pop();
    color.at(v) = BLACK;

    // 「余り物」の要素は無視する
    if (d.at(v) < f.first * (-1))
    {
      continue;
    }

    // vに隣接するV-Sの頂点uのdを更新する
    for (int i = 0; i < G.at(v).size(); i++)
    {
      int u = G.at(v).at(i).first;
      // 辺(v,u)の重み
      int cost = G.at(v).at(i).second;
      if (color.at(u) == WHITE)
      {
        // uがV-Sの頂点のとき
        if (d.at(v) + cost < d.at(u))
        {
          // uのdを更新する必要があるとき
          d.at(u) = d.at(v) + cost;
          PQ.push(make_pair(d.at(u) * (-1), u));
        }
      }
    }
  }
}

int main()
{
  cin >> n;
  for (int i = 0; i < n; i++)
  {
    int u, m;
    cin >> u >> m;
    for (int j = 0; j < m; j++)
    {
      int v, cost;
      cin >> v >> cost;
      G.at(u).push_back(make_pair(v, cost));
    }
  }

  dijkstra();

  for (int i = 0; i < n; i++)
  {
    cout << i << " " << d.at(i) << endl;
  }
}


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

using namespace std;
const int maxn = 1e5 + 5;
int n , m , p[maxn] , lab[maxn] , pos[maxn];
pair<int,int> edge[maxn];
int finds(int u)
{
    return lab[u] < 0 ? u : lab[u] = finds(lab[u]);
}
int main()
{
    cin >> n >> m;
    for(int i = 1 ; i <= n ; ++i)
    {
        cin >> p[i];
        pos[p[i]] = i;
    }
    for(int i = 1 ; i <= m ; ++i)
        cin >> edge[i].first >> edge[i].second;
    fill_n(lab , maxn , -1);
    for(int i = 1 ; i <= m ; ++i)
    {
        int s = finds(edge[i].first);
        int d = finds(edge[i].second);
        if(s != d)
        {
            if(lab[s] > lab[d])swap(s , d);
            lab[s] += lab[d];
            lab[d] = s;
        }
    }
    int res = 0;
    for(int i = 1 ; i <= n ; ++i)
        res += finds(i) == finds(pos[i]);
    cout << res;
}


Measured memory_bytes: 2176
# -*- coding: utf-8 -*-
# 
import math
import sys
import itertools
import numpy as np

# いっこ入力
n =int(input())

# n行の複数列ある数値を二次元配列へ。x[n][?]
s = [list(input()) for i in range(n)] 
t = [0]*n
#print(s)
for i in range(n):
    a = sorted([s[i][ii] for ii in range(10)])
    for j in range(10):
        t[i] = t[i] * 26 + ord(a[j]) - ord('a')
t = sorted(t)
same = 1
mae = -1
answer = 0
#print(t)
for i in range(n):
    if t[i]==mae:
        same += 1
    else:
        answer += same * (same-1) // 2
        same = 1
        mae = t[i]
answer += same * (same-1) // 2
print(answer)


Measured memory_bytes: 38436
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	as := make([]int, n+1)
	for i := 0; i <= n; i++ {
		fmt.Scan(&as[i])
	}

	s := make([][2]int, n+1)
	s[n][0] = as[n]
	s[n][1] = as[n]
	for i := n - 1; i >= 0; i-- {
		s[i][0] = (s[i+1][0]+1)/2 + as[i]
		s[i][1] = s[i+1][1] + as[i]
	}
	if !(s[0][0] <= 1 && 1 <= s[0][1]) {
		fmt.Println(-1)
		return
	}

	ans := 1
	c := 1
	for i := 1; i <= n; i++ {
		c = min(c*2, s[i][1])
		ans += c
		c -= as[i]
	}
	fmt.Println(ans)
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}


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

const int maxa = 200005;
const long long inf = 1000000000000000000;
const int too_many_bottles_of_this_wine_we_cant_pronounce = 65;

signed main () {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	long long n, k;
	cin >> n >> k;
	k *= n;
	vector < long long > a(n), w(n);
	vector < vector < long long > > idx(maxa);
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
		idx[a[i]].push_back(i);
	}
	for (int i = 0; i < maxa; ++i) {
		if (!idx[i].empty()) {
			long long sz = idx[i].size();
			idx[i].push_back(idx[i][0] + n);
			for (int j = 0; j < sz; ++j)
				w[idx[i][j]] = idx[i][j + 1] - idx[i][j] + 1;
		}
	}
	vector < vector < long long > > nx{w};
	for (int p = 0; p < too_many_bottles_of_this_wine_we_cant_pronounce; ++p) {
		vector < long long > &x = nx.back();
		vector < long long > y(n);
		for (int i = 0; i < n; ++i)
			y[i] = min(inf, x[i] + x[(i + x[i]) % n]);
		nx.push_back(y);
	}
	long long pos = 0;
	for (int i = too_many_bottles_of_this_wine_we_cant_pronounce; i >= 0; --i) {
		if (pos + nx[i][pos % n] <= k)
			pos += nx[i][pos % n];
	}
	vector < long long > ans;
	set < long long > saw;
	for (int i = pos % n; i < n; ++i) {
		if (saw.find(a[i]) == saw.end()) {
			ans.push_back(a[i]);
			saw.insert(a[i]);
		}
		else {
			while (ans.back() != a[i]) {
				saw.erase(ans.back());
				ans.pop_back();
			}
			saw.erase(ans.back());
			ans.pop_back();
		}
	}
	for (long long x: ans)
		cout << x << ' ';
	cout << '\n';
}


Measured memory_bytes: 131404
N, L = map(int, input().split())
sumi = (N * L + ((N-1) * N)//2)
mini = 10**10
ans = sumi
for idx in range(N):
	if(mini > abs(L+idx)):
		mini = abs(L+idx)
		ans = sumi - (L+idx)
print(ans)

Measured memory_bytes: 3060
h, w, a, b = map(int,input().split())

list_s = [0 for i in range(a)]
list_t = [1 for i in range(a)]

while len(list_s) != w:
    list_s.append(1)
    list_t.append(0)

s = ''.join(map(str, list_s))
t = ''.join(map(str, list_t))

for i in range(h):
    if i < b:
        print(s)
    else:
        print(t)


Measured memory_bytes: 9000
#include<bits/stdc++.h>
using namespace std;
int main(){
  stack<int> st;
  stack<int> sti;
  vector<int> ans;
  int co=0;
  char ch;
  int zn=0;
  for(int i=0;;i++){
    cin >> ch;
    if(cin.eof())break;
    if(ch=='\\'){
      st.push(i);
      sti.push(0);
      zn++;
    }
    else if(ch=='/'){
      if(!st.empty()){
	int to;
	while(1){
	  to=st.top();
	  st.pop();
	  if(to>=0)break;
	}
	if(zn!=0){
	  int c=0;
	  while(1){
	    
	    int toi=sti.top();
	    sti.pop();
	    c+=toi;
	    if(toi==0){
	      c+=i-to;
	      sti.push(c);
	      zn--;
	      break;
	    }
	  }
	}
	co+=i-to;
      }
    }
  }
  while(!sti.empty()){
    if(sti.top())
      ans.push_back(sti.top());
    sti.pop();
  }
  cout << co << endl;
  cout << ans.size();
  for(int i=ans.size()-1;i>=0;i--){
    cout << " "<<ans[i];
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 3268
/* -------------------------------- Template -------------------------------- */

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <locale>
#include <iostream>
#include <map>
#include <new>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()

using namespace std;

using ll = long long;
using ld = long double;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }

template<typename T> constexpr T inf = [](){ assert(false); };
// template<> constexpr int inf<int> = 1e9;
// template<> constexpr ll inf<ll> = 1e18;
// template<> constexpr ld inf<ld> = 1e30;

struct yes_no : numpunct<char> {
  string_type do_truename()  const { return "Yes"; }
  string_type do_falsename() const { return "No"; }
};

/* -------------------------------- Library -------------------------------- */

/* ---------------------------------- Main ---------------------------------- */

string solve() {
  int N;
  string a, b;
  cin >> N >> a >> b;
  for (int i = 0; i < N; ++i) {
    if (a.substr(i) == b.substr(0, N-i)) {
      return a + b.substr(N-i);
    }
  }
  return a + b;
}

int main() {
  locale loc(locale(), new yes_no);
  cout << boolalpha;
  cout.imbue(loc);
  cout << solve().size() << endl;
  return 0;
}


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

int main(){
  int A,B;
  cin >> A >> B;
  
  int minAB = min(A,B);
  
  int gcdAB = 1;
  for(int i=2; i<=minAB; i++){
    if(A % i ==0  &&  B % i ==0){
      gcdAB = i;
    }
  }
  
  long int a = A/gcdAB;
  long int b = B/gcdAB;
  long int ans = a * b *gcdAB;
  cout << ans << endl;
}

Measured memory_bytes: 256
using System;
using System.Linq;

namespace myapp2
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToList();
            int a = input[0];
            int b = input[1];
            string result  = (a * b) % 2 == 0 ? "Even" : "Odd";
            Console.WriteLine(result);
            var end = Console.ReadLine();
        }
    }
}


Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define COUT(x) cout<<(x)<<endl
#define dump(x)  cout << #x << " = " << (x) << endl;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
using M = map<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int, vector<int>, greater<int>>;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main() {
  int r,g; cin >> r >> g;
  cout << 2.0*g-r << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();
		
		int sum = 0;
		
		if(a > b){
			sum += b;
		}else{
			sum += a;
		}
		
		if(c > d){
			sum += d;
		}else{
			sum += c;
		}
		
		System.out.println(sum);
	}
}

Measured memory_bytes: 20820
from math import sqrt
X = int(input())
def is_prime_next(X):
    X_sqrt = int((sqrt(X)+1)/6) 
    if X==2 or X==3:
        return X
    if X%2 == 0:
        return None
    if X%3 == 0:
        return None
    for i in range(1, X_sqrt+1):
        if X % (6*i+1) == 0 or X % (6*i-1) == 0:
            return None
    return X
while(1):
    X_keep = is_prime_next(X)
    if X_keep != None:
        break
    X += 1
print(X)

Measured memory_bytes: 3064
N = int(input())
s1 = []
s2 = []

for i in range(N):
    a = int(input())
    if a % 10 != 0:
        s1.append(a)
    else:
        s2.append(a)

if len(s1) == 0:
    print(0)
else:
    if sum(s1) % 10 == 0:
        print(sum(s1)-min(s1)+sum(s2))
    else:
        print(sum(s1)+sum(s2))


Measured memory_bytes: 9192
#include<iostream>
#include<set>
#include<vector>
#include<algorithm>

int main() {

	int n;
	std::cin >> n;

	std::vector<int> v;
	v.resize(n);

	for (auto&e : v)
		std::cin >> e;
			

	std::sort(std::begin(v), std::end(v));

	auto it = std::unique(std::begin(v), std::end(v));

	while (std::distance(std::begin(v), it) > 2) {
		auto beg = std::begin(v);
		auto me = *beg == 0 ? *(++beg) : *beg;

		for (auto itk = ++std::begin(v); itk != it; ++itk) {
			if (me != *itk)
				*itk %= me;
		}
		std::sort(std::begin(v), it);
		it = std::unique(std::begin(v), it);
	}
	

	while (v[0] > 1) {
		auto rem = v[1] % v[0];
		v[1] = v[0];
		v[0] = rem;
	}

	std::cout << ( v[0]==0 ? v[1] : v[0] ) << "\n";

	return 0;
}

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

int main(){
	long long N,M;
	cin >> N>>M;
	long long L[M],R[M];
	long long L_min=0;
	long long R_max=1<<30;
	
	for(int i=0;i<M;i++){
		cin>>L[i]>>R[i];
		L_min=max(L_min,L[i]);
		R_max=min(R_max,R[i]);
	}
	if(R_max-L_min+1>0)cout<<R_max-L_min+1<<endl;
	else cout<<0;
}


Measured memory_bytes: 1792
#include <stdio.h>
#include <queue>
#include <vector>
#include <map>
#include <set>
using namespace std;

char t[100010];
int n,k,r,s,p;

int check(char tmp){
    if (tmp=='s') return r;
    if (tmp=='r') return p;
    return s;
}

int main()
{
    int ans=0;
    scanf("%d%d%d%d%d",&n,&k,&r,&s,&p);
    scanf("%s",t+1);
    for (int i=1;i<=k;++i){
        char last=t[i];
        ans+=check(last);
        for(int j=i+k;j<=n;j+=k){
            if (t[j]==last)
                last=-1;
            else{
                last=t[j];
                ans+=check(last);
            }
        }
    }
    printf("%d\n",ans);
}





Measured memory_bytes: 256