akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
     
#define all(A) begin(A), end(A)
#define rall(A) rbegin(A), rend(A)
#define sz(A) int(A.size())
#define pb push_back
#define mp make_pair
     
using namespace std;
     
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;

int main () {
  ios::sync_with_stdio(false); cin.tie(0);
  ll k;
  cin >> k;
  ll mod = 9 * k;
  int p = 10;
  for (int i = 1; i <= 2 * k; i++) {
    int pp = p - 1;
    if (pp < 0) pp += mod;
    int r = (7 * pp) % mod;
    if (r == 0) {
      cout << i << '\n';
      return (0);
    }
    p = (p * 10) % mod;
  }
  cout << -1 << '\n';
  return (0);
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
const int maxn = 60;

int T, n, ind[maxn], deg[maxn];
bool ban[maxn], vis[maxn];

vector<int> G[maxn], e1[maxn], e2[maxn];

void init()
{
	for(int i = 1; i <= n; ++i)
	{
		G[i].clear();
		ind[i] = 0;
		vis[i] = 0;
	}
}

void Clear()
{
	for(int i = 1; i <= n; ++i)
	{
		e1[i].clear();
		e2[i].clear();	
		deg[i] = 0;
	}
}

void dfs1(int x, int fa)
{
	int id;
	for(int i = 0; i < (int)e1[x].size(); ++i)
	{
		id = e1[x][i];
		if(id == fa || ban[id])	continue;
		if(!vis[id] && !vis[x])
		{
			G[id].push_back(x);
			++ ind[x];
		}
		dfs1(id, x);
	}
}

void dfs2(int x, int fa)
{
	int id;
	for(int i = 0; i < (int)e2[x].size(); ++i)
	{
		id = e2[x][i];
		if(id == fa)	continue;
		if(!vis[x] && !vis[id])
		{
			G[x].push_back(id);
			++ ind[id];
		}
		dfs2(id, x);
	}
}

int dfs3(int x, int fa)
{
	vis[x] = 1;
	int ret = 1;
	vector<int> :: iterator pt1 = e1[x].begin(), pt2 = e2[x].begin();
	while(pt1 != e1[x].end() && pt2 != e2[x].end())
	{
		if((*pt1) == fa)
		{
			++ pt1;
			continue;
		}
		if((*pt2) == fa)
		{
			++ pt2;
			continue;
		}
		if((*pt1) == (*pt2))
		{
			ret += dfs3((*pt1), x);
			++ pt1;
			++ pt2;
			continue;
		}
		if((*pt1) < (*pt2))
			++ pt1;
		else
			++ pt2;
	}
	return ret;
}

int que[maxn];

bool bfs()
{
	int h = 1, t = 0, s, id;
	for(int i = 1; i <= n; ++i)
		if(!ind[i])
		{
			que[++t] = i;
		}
	while(h <= t)
	{
		s = que[h++];
		for(int i = 0; i < (int)G[s].size(); ++i)
		{
			id = G[s][i];
			-- ind[id];
			if(!ind[id])
			{
				que[++t] = id;
			}
		}
	}
	return t == n;
}

int main()
{
	scanf("%d", &T);
	while(T --)
	{
		scanf("%d", &n);
		int u, v;
		for(int i = 1; i < n; ++i)
		{
			scanf("%d%d", &u, &v);
			e1[u].push_back(v);
			e1[v].push_back(u);
			++ deg[u];
			++ deg[v];
		}
		for(int i = 1; i < n; ++i)
		{
			scanf("%d%d", &u, &v);
			e2[u].push_back(v);
			e2[v].push_back(u);
		}
		for(int i = 1; i <= n; ++i)
		{
			sort(e1[i].begin(), e1[i].end());
			sort(e2[i].begin(), e2[i].end());
		}
		int ans = 100;
		for(int i = 1; i <= n; ++i)
		{
			init();
			int res = dfs3(i, 0);
			dfs1(i, 0);
			dfs2(i, 0);
			if(bfs())
			{
				ans = min(ans, n - res);
			}
		}
		for(int i = 1; i <= n; ++i)
			if(deg[i] == 1)
			{
				ban[i] = 1;
				for(int j = 1; j <= n; ++j)
					if(i != j)
					{
						init();
						int res = 0;
						for(int k = 0; k < (int)e2[i].size(); ++k)
							if(e2[i][k] == j)
							{
								res = dfs3(j, i);
								break;	
							}
						vis[i] = 1;
						dfs1(j, 0);
						dfs2(i, 0);
						if(bfs())
						{
							ans = min(ans, n - res);
						}
					}
				ban[i] = 0;
			}
		printf("%d\n", ans == 100? -1: ans);
		Clear();
	}
	return 0;
}


Measured memory_bytes: 256
def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b, a%b)

K = int(input())

ans = 0
for i in range(1,K+1):
    for j in range(i, K+1):
        temp = gcd(i, j)
        for k in range(j, K+1):
            if i == j and j == k:
                ans += gcd(temp, k)
            elif i == j or j == k:
                ans += gcd(temp, k) * 3
            else:
                ans += gcd(temp, k) * 6

print(ans)



Measured memory_bytes: 9128
/*
  Contest 093
  A - abc of ABC
  Rakesh Kumar --> 21/09/2020
 */

#include <bits/stdc++.h>

int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(0); std::cout.tie(0);

    std::string s;
    std::getline(std::cin, s);
    int total = 0;
    for (char c: s)
        total += c - 'a';
    std::cout << (total == 3 ? "Yes" : "No") << std::endl;

    return 0;
}


Measured memory_bytes: 3580
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
using namespace std;

int parse(string s) {
	int ret = 0;
	int multiplier = 1;

	for (int i = 0; i < (int)s.size(); i++) {
		if('2' <= s[i] && s[i] <= '9') {
			multiplier = s[i] - '0';
		}
		else {
			ret += multiplier
					* (s[i] == 'm' ? 1000
					: s[i] == 'c' ? 100
					: s[i] == 'x' ? 10
					: s[i] == 'i' ? 1
					: 0);
			multiplier = 1;
		}
	}
	return ret;
}

void print_mcxi_string(int i) {
	int multiplier = 0;
	char bases[] = {'m', 'c', 'x', 'i'};
	for (int j = 3; j >= 0; j--) {
		int pos = (int)pow(10.0, (double)j);
		if(i >= pos) {
			multiplier = i / pos;
			if(multiplier > 1) {
				cout << multiplier;
			}
			cout << bases[3-j];
			i %= pos;
		}
	}
	cout << endl;
}

int main() {
	int n;
	cin >> n;
	while(n--) {
		string s1, s2;
		cin >> s1 >> s2;
		print_mcxi_string(parse(s1) + parse(s2));
	}
	return 0;
}

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

#define NDEBUG
#include <cassert>


typedef long long ll;
typedef long double Double;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<long double> vD;

#define sz(a)  int((a).size())
#define pb  push_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))
#define cons make_pair

template <class T> inline void amin(T & a, T const & b) { a = min(a, b); }
template <class T> inline void amax(T & a, T const & b) { a = max(a, b); }
template <typename X, typename T> auto vectors(X x, T a) { return vector<T>(x, a); }
template <typename X, typename Y, typename Z, typename... Zs> auto vectors(X x, Y y, Z z, Zs... zs) { auto cont = vectors(y, z, zs...); return vector<decltype(cont)>(x, cont); }


ll gcd(ll a, ll b) { while(a) swap(a, b%=a); return b; }

const ll MOD=1000000007LL;


ll solve(int N, ll K, vll& a) {
    vvi cnt(40, vi(2, 0));
    rep(i,N){
        ll ai = a[i];
        for (ll i=0,b=1; i<40; ++i,b<<=1){
            if (ai&b) cnt[39-i][1]++;
            else cnt[39-i][0]++;
        }
    }
    vi ku(40,0);
    for (ll i=0,b=1; i<40; ++i,b<<=1){
        if(K&b) ku[39-i]=1;
    }

    vector<vll> dp(41, vll(2, -1));
    dp[0][0] = 0;

    rep(i,40){
        if (dp[i][0] >= 0) {
            if (ku[i] == 1) {
                amax(dp[i+1][0], dp[i][0]*2 + cnt[i][0]);
                amax(dp[i+1][1], dp[i][0]*2 + cnt[i][1]);
            } else {
                amax(dp[i+1][0], dp[i][0]*2 + cnt[i][1]);
            }
        }
        if (dp[i][1] >= 0) {
            amax(dp[i+1][1], dp[i][1]*2 + cnt[i][0]);
            amax(dp[i+1][1], dp[i][1]*2 + cnt[i][1]);
        }

    }
    return max(dp[40][0], dp[40][1]);
}

int main() {
    int N; ll K; scanf("%d%lld",&N,&K);
    vll a(N); rep(i,N) scanf("%lld", &a[i]);
    cout << solve(N,K,a) << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
#define max(x, y) ((x)<(y) ? (y) : (x))
#define swap(type, x, y) do{ type t = x; x = y; y = t; }while(0)

void quick(int a[], int left, int right, int b[]){
  int pl = left, pr = right, x = a[(left+right)/2];
  do{
    while(a[pl] < x)  pl++;
    while(a[pr] > x)  pr--;
    if(pl <= pr){
      swap(int, a[pl], a[pr]);
      swap(int, b[pl], b[pr]);
      pl++, pr--;
    }
  }while(pl <= pr);
  if(pl < right)  quick(a, pl, right, b);
  if(pr > left)   quick(a, left, pr, b);
}

int main(){
  int n;  scanf("%d", &n);
  int s[100005] = {0}, g[100005] = {0};
  int longest = -(1<<30);
  for(int i=1; i<=n; i++){
    int x, l;  scanf("%d %d", &x, &l);
    s[i] = x - l;
    g[i] = x + l;
  }

  quick(g, 1, n, s);
  s[n+2] = 1<<30;
  int now = g[1], count = 1, idx = 1;
  while(idx < n){
    while(s[idx] < now)  idx++;
    if(idx <= n)  count++;
    now = g[idx];
  }

  printf("%d\n", count);

  return 0;
}


Measured memory_bytes: 2488
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String atcoder = sc.next();
        String mid = sc.next();
        String contest = sc.next();
        System.out.print(atcoder.charAt(0));
        System.out.print(mid.charAt(0));
        System.out.print(contest.charAt(0));
        System.out.println();
    }
}

Measured memory_bytes: 24020
const val MOD: Long = (1e9+7).toLong()

fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val a = readLine()!!.split(" ").map{it.toInt()}

    var min = Int.MAX_VALUE
    for (i in -100..100) {
        val x = a.map{Math.pow((it-i).toDouble(), 2.0)}.sum().toInt()
        min = Math.min(min, x)
    }
    println(min)
}


Measured memory_bytes: 37864
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <cstdint>
#include <cmath>
#include <functional>
#include <limits>
#include <cassert>

using namespace std;

using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;

void debug_out() { std::cout << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cout << "debug: "; debug_out(__VA_ARGS__)
#else
#define debug(...) 
#endif

#define rep(i, a, n) for (int i = (int)(a); i < (int)(n); i++)
#define rrep(i, a, n) for (int i = ((int)(n)-1); i >= (int)(a); i--)
#define Rep(i, a, n) for (long long i = (long long)(a); i< (long long)(n); i++)
#define RRep(i, a, n) for (long long i = ((long long)(n)-1); i>=(long long)(a); i--)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

struct Edge{
    int to;
    int weight;
    Edge(int t, int w) : to(t), weight(w){ }
};

struct edge{
    int from;
    int to;
    int weight;
    edge(int f,int t,int w) : from(f), to(t), weight(w){ }
};


using Graph = vector<vector<Edge>>;
using graph = vector<vector<int>>;
using edges = vector<edge>;

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

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

template <class T>
T lcm(T a, T b){
    return (a*b)/gcd(a,b);
}

bool isPalindrome(string s){
    string t = s;
    reverse(all(t));
    return s==t;
}

constexpr ll INF = 1e9+7;

vector<int> dx = {-1,0,1,0};
vector<int> dy = {0,-1,0,1};

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string s,t; cin >> s >> t;
    map<char,vector<ll>> m;
    Rep(i,0ll,s.size()){
        m[s[i]].emplace_back(i);
    }
    ll n = t.size();
    Rep(i,0,n){
        if(m[t[i]].empty()){
            cout << "-1\n";
            return 0;
        }
    }
    ll ans = m[t[0]][0]+1ll, now = ans-1ll;
    Rep(i,1,n){
        char next = t[i];
        auto len = upper_bound(all(m[next]),now);
        if(len!=m[next].end()){
            ans += (*len-now);
            now = *len;
        }
        else{
            ans += (s.size()-now+m[next][0]);
            now = m[next][0];
        }
        debug(now,*len);
    }
    cout << ans << '\n';
}

Measured memory_bytes: 1736
#include<iostream>
#include<string>
const long long mod = 1000000007;
using namespace std;
int main(){
    int N,i;
    bool isSame[52];
    long long ans = 3;
    string S1,S2;
    cin >> N >> S1 >> S2;
    for(i=0;i<N;i++){
        isSame[i] = S1[i] == S2[i]?true:false;
    }
    i = 1;
    if(!isSame[0]){
        ans *= 2;
        i++;
    }
    for(;i<N;i++){
        if(! isSame[i]){
            if(! isSame[i-1]) ans = (ans*3)%mod;
            else ans = (ans*2)%mod;
            i++;
        }
        else{
            if(isSame[i-1]) ans = (ans*2)%mod;
        }
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

int main()
{
  int t;
  cin >> t;
  if (t == 1)
    cout << "Hello World" << endl;
  else
  {
    int a, b;
    cin >> a >> b;
    cout << a + b << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main () {
  int K, A, B;
  cin >> K >> A >> B;
  string C = "NG";
  for(int i = A; i <= B; i++){
    if(i % K == 0){
      C = "OK";
    }
  }
  cout << C << endl;
}

Measured memory_bytes: 3596
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)



int main() {
    string s;
    cin >> s;
    REP(i, s.size() - 1){
        if(s[i] == 'C'){
            for(ll j = i + 1; j < s.size(); j++){
                if(s[j] == 'F'){
                    cout << "Yes" << endl;
                    return 0;
                }
            }
        }
    }
    cout << "No" << endl;
}

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

int main() {
  int x;
  cin >> x;
  
  if (x>=400 && x<600)	cout << "8" << endl;
  else if (x<800)		cout << "7" << endl;
  else if (x<1000)		cout << "6" << endl;
  else if (x<1200)		cout << "5" << endl;
  else if (x<1400)		cout << "4" << endl;
  else if (x<1600)		cout << "3" << endl;
  else if (x<1800)		cout << "2" << endl;
  else if (x<2000)		cout << "1" << endl; 
  
  return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int a[1000001];
string s;
signed main()
{
	int n,flag=0;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		if(a[i]%2==0)
		{
			if(a[i]%3!=0&&a[i]%5!=0)
				flag=1;
		}
	}
	if(flag)
		printf("DENIED");
	else
		printf("APPROVED");
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#ifdef JLOCAL
#include "stress.h"
#endif
using namespace std;

#define rep(i, z, n) for (int i = (z); i < int(n); ++i)
#define repr(i, n, z) for (int i = int(n) - 1; i >= (z); --i)
#define shl(n) (1 << (n))
#define hbit(n, i) (((n) >> (i)) & 1)

#define STRESS 0
using lint = long long;

void solve(istream& cin, ostream& cout) {
    lint n, a, b, c, d;
    cin >> n >> a >> b >> c >> d;
    n -= 1;
    b -= a;
    for (int i = 0; i <= n; i++) {
        lint mn = -d * i + c * (n - i);
        lint mx = d * (n - i) - c * i;
        if (mn <= b && b <= mx) {
            cout << "YES";
            return;
        }
    }
    cout << "NO";
}

int main() {
#if !defined(JLOCAL) || !STRESS
#ifdef JLOCAL
    freopen("input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    solve(cin, cout);
#else
    srand();
    for (int ti = 0; ti < 100; ti++) {
        stress::gen();
        stress::stupid();
        ifstream in("input.txt");
        ofstream out("output.txt");
        solve(in, out);
        out.flush();
        stress::check();
    }
    cout << "ok" << endl;
#endif
    return 0;
}


Measured memory_bytes: 256
A, B, C, D = list(map(int, list(input())))
ops = ['+', '-']
for i in range(2):
  for j in range(2):
    for k in range(2):
      if A + ((-1)**i)*B + ((-1)**j)*C + ((-1)**k)*D == 7:
        ans = str(A) + ops[i] + str(B) + ops[j] + str(C) + ops[k] + str(D) + '=7'
        print(ans)
        quit()

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

int main() {
    int n;
    cin >> n;
    int t = n, c = 0;
    while (t > 0) {
        c += t % 10;
        t /= 10;
    }
    cout << (n % c == 0 ? "Yes" : "No") << endl;
}

Measured memory_bytes: 384
//Rafiqul Islam, MBSTU,ICT

#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <queue>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

#define pb push_back
#define mk make_pair
#define f0(i,b) for(int i=0;i<(b);i++)
#define f1(i,b) for(int i=1;i<=(b);i++)
#define f2(i,a,b) for(int i=(a);i<=(b);i++)
#define sf(a) scanf("%d",&a);
#define sfl(a) scanf("%lld",&a);
#define pf(a) printf("%d\n",a);
#define pfl(a) printf("%lld\n",a);
#define TEST int test; cin >> test ;while(test--)
#define ii pair<int,int>
#define iil pair<ll,ll>
#define loop(i,a,b) for(int i = a ; i < b ; i++)
#define INF 2147483647
#define endl "\n"
#define all(v) v.begin(),v.end()

int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, -1};
int dy4[] = {1, -1, 0, 0};

const double pi = acos(-1.0);
const ll mod = 1e9 + 7;;
const ll maxn = 1e5+5;

ll power(ll x, unsigned long long y)
{
    ll res = 1;     // Initialize result

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res*x);

        // y must be even now
        y = y>>1; // y = y/2
        x = (x*x);  // Change x to x^2
    }
    return res;
}
ll modOp(ll a, ll b)
{
    ll c = a % b;
    if (c < 0)
        c += b;
    return c;
}
ll iv[maxn + 1];
void mod_inv()
{
    iv[1] = 1;
    for(ll i = 2 ; i <= maxn ; i++ )
    {

        iv[i] = (mod - mod/i * iv[mod%i]%mod)%mod;
        //cout << iv[i] << endl;
    }
}

ll Logn(ll n, ll base)
{
    return (n > base - 1) ? 1 + Logn(n / base, base) : 0;
}

void run_case()
{
    ll a[10];
    cin >> a[0] >> a[1] >> a[2] >> a[3];
    if(a[0] > a[1]) swap(a[0],a[1]);
    if(a[2] > a[3]) swap(a[2],a[3]);

    ll ans[10];
    ans[0] = a[0]*a[2];
    ans[1] = a[0]*a[3];
    ans[2] = a[1]*a[2];
    ans[3] = a[1]*a[3];

    sort(ans,ans+4);
    cout << ans[3] << endl;
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    //TEST
    run_case();
    //main();
    return 0;
}


Measured memory_bytes: 3652
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt"

struct po {
	int index;
	int coors[2];
	po(int _d){
		index = 0;
		coors[0] = 0;
		coors[1] = 0;
	}
	po() {}
};
template<class T>
class axisSorter {
	int k;
public:
	axisSorter(int _k) : k(_k) {}
	bool operator()(const T &a, const T &b) {
		return a.coors[k] < b.coors[k];
	}
};
template<class T,int Dim = 2>
struct kdtree {
public:
	T val;
	kdtree<T> *ltree, *rtree;
	int depth;
	int axis;
	kdtree(const T &p_) :val(p_), ltree(nullptr), rtree(nullptr){

	}
	
	kdtree(vector<T>&ps_,const int& l,const int& r,const int depth_=0): ltree(nullptr), rtree(nullptr),depth(depth_),axis(depth%Dim) {
		init(ps_,l,r);
	}
	vector<T>query(const T & amin, const T&amax) {
		vector<T>ans;
		bool aok = true;
		for (int i = 0; i < Dim; ++i) {
			if (amin.coors[i] <= val.coors[i] && val.coors[i] <= amax.coors[i]) {

			}
			else {
				aok = false;
				break;
			}
		}
		if (aok) {
			ans.emplace_back(val);
		}
		axisSorter<T> as(axis);
		if (as(val, amax)||val.coors[axis]==amax.coors[axis]) {
			if (rtree != nullptr) {
				vector<T>tans(rtree->query(amin, amax));
				ans.insert(ans.end(), tans.begin(), tans.end());
			}
		}
		if (as(amin, val) || val.coors[axis] == amin.coors[axis]) {
			if (ltree != nullptr) {
				vector<T>tans(ltree->query(amin, amax));
				ans.insert(ans.end(), tans.begin(), tans.end());
			}
		}
		return ans;
	}
private :
	void init(vector<T>&ps,const int& l,const int& r) {
		if (l >= r) {
			return;
		}
		sort(ps.begin()+l, ps.begin()+r, axisSorter<T>(axis));
		const int mid = (l + r) / 2;
		val = ps[mid];
		ltree = make_kdtree(ps, l, mid, depth + 1);
		rtree = make_kdtree(ps,mid+1,r, depth + 1);
	}
	
};
template<class T>
kdtree<T> *make_kdtree(vector<T>&ps_, const int& l, const int& r, const int& depth = 0) {
	if (l >= r)return nullptr;
	else {
		return new kdtree<T>(ps_, l, r, depth);
	}
}
int main() {
	vector<po> ps(0);
	{
		int N;
		scanf("%d", &N);
		for (int i = 0; i < N; ++i) {
			int x, y; scanf("%d", &x);
			scanf("%d", &y);
			po d(2);
			d.index = i;
			d.coors[0] = x;
			d.coors[1] = y;
			ps.push_back(d);
		}
	}
	
	kdtree<po>kd(ps,0,ps.size());
	int M;
	scanf("%d", &M);
	for (int i = 0; i < M; ++i) {
		int sx, tx, sy, ty; 
		scanf("%d %d %d %d", &sx, &tx, &sy, &ty);
		po s(2);
		s.coors[0] = sx;
		s.coors[1] = sy;
		po t(2);
		t.coors[0] = tx;
		t.coors[1] = ty;
		vector<int>is;
		vector<po>anss(kd.query(s, t));
		for (auto a : anss) {
			is.emplace_back(a.index);
		}
		sort(is.begin(), is.end());
		for (auto i : is) {
			printf("%d", i);
			printf("\n");
		}
		printf("\n");
		
	}
	return 0;
}

Measured memory_bytes: 31472
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

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

    ll n,k,a,b;

    while(cin>>n>>k){
        // cin>>n>>k;
        ll v[100010]={0};
        int l=-1;
        // for(int i=1;i<=100005;i++) v[i]=0;
        
        for(int i=0;i<n;i++){
            cin>>a>>b;
            v[a] += b;
            if(l<=a)l=a;
        }

        ll count = 0;
        int ans;
        for(int i=1;i<=l;i++){
            count += v[i];
            if(count >= k){
                ans = i;
                break;
            }
        }
        cout<<ans<<endl;
    }

    return 0;
 
}

Measured memory_bytes: 1024
import java.util.*;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		Integer[] A = new Integer[N];
		Arrays.setAll(A, i -> sc.nextInt());
		sc.close();

		Integer[] C = A.clone();
		Arrays.sort(C, Collections.reverseOrder());
		for (int i = 0; i < N; i++) {
			if (A[i] == C[0]) {
				System.out.println(C[1]);
			} else {
				System.out.println(C[0]);
			}
		}
	}
}

Measured memory_bytes: 97224
a, b, c = map(int, input().split())
x = y = 0
for i in range(c):
    d, e, f = map(int, input().split())
    if f == 1:
        x = max(x, d)
    elif f == 2:
        a = min(a, d)
    elif f == 3:
        y = max(y, e)
    elif f == 4:
        b = min(b, e)
if x >= a or y >= b:
    print(0)
else:
    print(abs(a - x) * abs(b - y))


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define maxn 100086

using namespace std;

int n, m;
char s[maxn], t[maxn];
int ans = 1e5;

int main(){
	scanf("%s%s",s + 1, t + 1);
	n = strlen(s + 1), m = strlen(t + 1);
	for(int i = 1;i + m - 1 <= n;i++){
		int sum = 0;
		for(int j = 0;j < m;j++){
			sum += s[i + j] != t[j + 1];
		}
		ans = min(ans, sum);
	}
	printf("%d", ans);
}

Measured memory_bytes: 3828
#include<vector>
#include<iostream>
#include<algorithm>
#include<functional>
#include<string>
#include<limits.h>
#include<cmath>
using namespace std;



int main(){

  int n; cin >> n;
  vector<int> b(n);

  for (int i=1; i<=n-1; i++){ cin >> b[i]; }

  int ans = 0;

  ans = ans + b[1] + b[n-1];

  for (int i=1; i<n-1; i++){
    ans += min(b[i],b[i+1]);
  }

  cout << ans;

  return 0;
}


Measured memory_bytes: 256
# WIP
A, B, C = map(int, input().split())

combi = [A, B, C]
set_abc = set(combi)

len_set_abc = len(set_abc)
max_set = max(set_abc)
min_set = min(set_abc)
if len_set_abc == 1:
    print(0)
elif len_set_abc == 2:
    max_freq = combi.count(max_set)
    diff = max_set - min_set
    if max_freq == 2 and diff % 2:
        print((diff + 1) // 2 + 1)
    elif max_freq == 2:
        print(diff // 2)
    else:
        print(diff)
else:
    other = [c for c in combi if c != max_set]
    max_other = max(other)
    min_other = min(other)
    
    n_operation = max_set - max_other
    max_other += n_operation
    min_other += n_operation

    diff = max_set - min_other
    if diff % 2 and diff == 1:
        n_add = (max_set - min_other) // 2 + 2
    elif diff % 2:
        n_add = (max_set - min_other) // 2 + 2
    else:
        n_add = (max_set - min_other) // 2
    n_operation += n_add

    print(n_operation)


Measured memory_bytes: 3064
import java.io.FileNotFoundException;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws FileNotFoundException {
		new Main().run();
	}

	void run() {
		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt();
		int W = sc.nextInt();
		int h = sc.nextInt();
		int w = sc.nextInt();
		if (H % h == 0 && W % w == 0) {
			System.out.println("No");
			return;
		} else {
			System.out.println("Yes");
		}
		int[][] a = new int[H][W];
		for (int i = 0; i < H; i += h) {
			for (int j = 0; j < W; j += w) {
				a[i][j] = 1_000_000_000 - 1;
				if (i + h - 1 < H && j + w - 1 < W) {
					a[i + h - 1][j + w - 1] = -1_000_000_000;
				}
			}
		}
		for (int i = 0; i < H; ++i) {
			for (int j = 0; j < W; ++j) {
				System.out.print(a[i][j] + (j < W - 1 ? " " : "\n"));
			}
		}

	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}


Measured memory_bytes: 54836
from sys import stdin
input = stdin.readline
def main():
    R, C, K = map(int, input().split())
    items = [[0 for _ in range(C)] for _ in range(R)]
    for _ in range(K):
        r, c, v = map(int, input().split())
        items[r - 1][c - 1] = v
    dp = [[[0 for _ in range(C)] for _ in range(R)] for _ in range(4)]
    dp[1][0][0] = items[0][0]
    for r in range(R):
        for c in range(C):
            for i in range(4):
                tmp = dp[i][r][c]
                # right
                if c != C - 1:
                    # unpick
                    dp[i][r][c + 1] = max(dp[i][r][c+1], tmp)
                    # pick
                    if i < 3:
                        dp[i+1][r][c + 1] = max(dp[i+1][r]
                                                [c + 1], tmp + items[r][c + 1])
                # down
                if r != R - 1:
                    # unpick
                    dp[0][r + 1][c] = max(dp[0][r + 1][c], tmp)
                    # pick
                    dp[1][r + 1][c] = max(dp[1][r + 1][c],
                                          tmp + items[r + 1][c])
    ans = 0
    for i in range(4):
        ans = max(ans, dp[i][-1][-1])
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 467524
#include <bits/stdc++.h>                                           
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define int long long
//#pragma GCC optimize("Ofast")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
 
 
#define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout);
#define fastio ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define all(x) x.begin(), x.end()
#define sz(s) (int)s.size()
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define s second
#define f first
 
 
 
 
typedef pair < long long, long long > pll;    
typedef pair < int, int > pii;  
typedef unsigned long long ull;         
typedef vector < pii > vpii;                                   	
typedef vector < int > vi;
typedef long double ldb;  
typedef long long ll;  
typedef double db;
 
typedef tree < int, null_type, less < int >, rb_tree_tag, tree_order_statistics_node_update > ordered_set;
 
const int inf = 1e9, maxn = 2e5 + 48, mod = 998244353, N = 3012;
const int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1}, block = 300;
const pii base = mp(1171, 3307), Mod = mp(1e9 + 7, 1e9 + 9);
const db eps = 1e-12, pi = acos(-1);
const ll INF = 1e18;
 
int n, m, k, x, y, z, a[N][N], dp[N][N][4];

main () {
	scanf("%lld%lld%lld", &n, &m, &k);
	for (int i = 1; i <= k; ++i) {
		scanf("%lld%lld%lld", &x, &y, &z);	
		a[x][y] = z;
	}
	
	dp[1][1][0] = 0;
	dp[1][1][1] = a[1][1];
	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= m; ++j) {
			if (i > 1) {
				for (int x = 0; x <= 3; ++x) {
					dp[i][j][0] = max(dp[i][j][0], dp[i - 1][j][x]); 
					dp[i][j][1] = max(dp[i][j][1], dp[i - 1][j][x] + a[i][j]); 
				}
			} 

			if (j > 1) {
				for (int x = 0; x <= 3; ++x) {
					dp[i][j][x] = max(dp[i][j][x], dp[i][j - 1][x]);
					if (x)
						dp[i][j][x] = max(dp[i][j][x], dp[i][j - 1][x - 1] + a[i][j]);
				}
			}
		}

	int ans = 0;
	for (int x = 0; x <= 4; ++x)
		ans = max(ans, dp[n][m][x]);
	cout << ans << endl;

}


Measured memory_bytes: 356596
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <cmath>

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

using namespace std;

double dp[1<<12][12][12];
const double eps = 1e-8;

int main() {
    string line;
    while(getline(cin, line)) {
        stringstream ss;
        double width;
        vector<double> cake;
        int tmp;
        ss << line;
        ss >> width;
        while(ss >> tmp) {
            cake.push_back(tmp);
        }
        const int n = cake.size();

        rep(i,1<<n) {
            rep(j,n) {
                rep(k,n) {
                    dp[i][j][k] = 1000;
                }
            }
        }
        for (int i = 0; i < n; i++) {
            dp[1<<i][i][i] = 2 * cake[i];
        }
        for (int i = 1; i < (1 << n) - 1; i++) {
            rep(j, n) {
                if (!(i & (1 << j)))continue;
                rep(k, n) {
                    if (!(i & (1 << k)))continue;
                    rep(l, n) {
                        if (i & (1 << l))continue;
                        //cout << i << "," << j << "," << k << "," << l << endl;
                        double d = abs(cake[l] - cake[j]);
                        double dif = cos(asin(d / (cake[l]+cake[j]))) * (cake[l] + cake[j]) - cake[j] + cake[l];

                        dp[i | (1 << l)][l][k] = min(dp[i | (1 << l)][l][k], dp[i][j][k] + dif);
                        d = abs(cake[l] - cake[k]);
                        dif = cos(asin(d / (cake[l]+cake[k]))) * (cake[l] + cake[k]) - cake[k] + cake[l];
                        dp[i | (1 << l)][j][l] = min(dp[i | (1 << l)][j][l], dp[i][j][k] + dif);
                    }
                }
            }
        }
        double ans = 1000;
        rep(i,n)rep(j,n) {
            ans = min(ans, dp[(1 << n) - 1][i][j]);
        }
        cout << (width - ans + eps > 0 ? "OK" : "NA") << endl;
    }
}

Measured memory_bytes: 5928
#include<bits/stdc++.h>
#define vll vector<ll>
#define vi vector<int>
#define vpll vector<pair<ll,ll>>
#define pii pair<int,int>
#define REP(i,a) for(int (i)=0; (i)<(a); (i)++)
#define RREP(i,a) for(int (i)=a-1; (i)>=(0); (i)--)
#define REP2(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
#define m0(x) memset(x,0,sizeof(x))
typedef long long ll;

using namespace std;

const int MAX = 1100000;

ll fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
ll COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll X,Y;
  cin >> X >> Y;
  if( (Y+X)%3 != 0 ){
    cout << "0";
    return 0;
  }
  ll p = (2*X-Y)/3, q = (2*Y-X)/3;
  
  COMinit();
  cout << COM(p+q, p);
  return 0;
}

Measured memory_bytes: 25984
#include <stdio.h>
#include <iostream>

using namespace std;

#define REP(a, i, n) for (int i = a; i < n; ++i)

// 0 = 000
// 1 = 001 g(1) = 0
// 2 = 010 g(2) = 1 XOR g(1) = 001
// 3 = 011 g(3) = 2 XOR g(2) = 011
// 4 = 100 g(4) = 3 XOR g(3) = 000
// 5 = 101 g(5) = 4 XOR g(4) = 100
long g(long x) {
    if (x % 4 == 2) return 1;
    else if (x % 4 == 3) return x;
    else if (x % 4 == 0) return 0;
    else return x - 1;
}

// 3 XOR 5 = 6
// 011 XOR 101 = 110
int main() {
    long A, B;
    cin >> A >> B;

    cout << (g(B + 1) ^ g(A)) << endl;

    return 0;
}


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

int main() {
	int n; cin >> n;
	vector<pair<int, int> > xy(n);
	REP(i, n) cin >> xy[i].first >> xy[i].second;
	sort(xy.begin(), xy.end());

	int maxi = 0;
	REP(i, n) REP(j, n) {
		if (i == j) continue ;
		pair<int, int> diff = make_pair(xy[i].first - xy[j].first, xy[i].second - xy[j].second);
		int cnt = 0;
		REP(k, n) REP(l, n) {
			if (k == l) continue ;
			pair<int, int> diff2 = make_pair(xy[k].first - xy[l].first, xy[k].second - xy[l].second);
			if (diff == diff2)
				cnt++;
		}
		maxi = max(maxi, cnt);
	}
	cout << n - maxi << '\n';
	return 0;
}

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

int main() {
  int A, B;
  cin >> A >> B;
  int ans=0;
  for(int i=A;i<=B;i++){
    if((i/10000)==(i%10)&&((i/1000)%10)==((i/10)%10)){
      ans++;
    }
  }
  cout << ans << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
    
#define IOS cin.sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define rep(i, n) for (int i = 0; i < n; i++)
#define repn(i, a, b) for (int i = a;i<=b;i++)
#define ll long long int
#define pb push_back
#define mpi map<int,int>
#define mpl map<ll,ll>
#define ff first
#define ss second
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define mem(x,val) memset(x, val, sizeof(x))
#define ritr(it, a) for (auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define pai pair < int, int> 
#define pal pair < ll, ll> 
#define vi vector <int> 
#define vl vector < ll > 
#define vpai vector < pii > 

const int mod = 1e9+7;
const int INF = INT_MAX;
const int sze = 3005;

void solve() {
    int n;
    cin>>n;
    vi arr(2*n,0);
    ll sum=0;
    rep(i,2*n) cin>>arr[i];
    sort(all(arr));
    rep(i,2*n){
        sum+=arr[i];
        i++;
    }
    cout<<sum<<endl;
}

int main() {
    IOS;

    int t = 1;
    //cin >> t;
    while (t--) {
       solve();
    }

  return 0;
}

Measured memory_bytes: 3628
n, k = map(int, input().split())
a = list(map(int, input().split()))
a.sort()

def f(l, s):
    return s if l % s == 0 else f(s, l % s)

z = f(a[-1], a[0])
for i in a:
    z = f(i, z)
if a[-1] >= k and k % z == 0:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')

Measured memory_bytes: 14252
#include <cstdio>
using namespace std;
typedef long long ll;
int main()
{
    int N, A, B, C, D;
    scanf("%d%d%d%d%d", &N, &A, &B, &C, &D);

    ll x = B - A;

    for(int i=0; i<N; i++){
        ll Imin, Imax;
        Imin = ((ll)N - 1 - i) * C - i * (ll)D;
        Imax = ((ll)N - 1 - i) * D - i * (ll)C;
        if(Imin <= x && x <= Imax){
            printf("YES\n");
            return 0;
        }
    }
    printf("NO\n");

    return 0;
}


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

// #define int long long
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

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

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

ll n;
ll ans=0;

void dfs(ll v,bool a, bool b, bool c){
  if(v>n) return;
  if(a&&b&&c) ans++;
  v*=10;
  dfs(v+7,true,b,c);
  dfs(v+5,a,true,c);
  dfs(v+3,a,b,true);
  return;
}

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  cin>>n;
  dfs(0,false,false,false);
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    ios::sync_with_stdio(false);
    int x,a,b;
    cin >> x >> a >> b;
    if(abs(x-a) > abs(x-b))
    cout << "B" << endl;
    else
    cout << "A" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0), cin.tie(0)
#define RI(x) x = rit()
#define RII(a,b) a = rit(), b = rit()
#define RIII(a,b,c) a = rit(), b = rit(), c = rit()
#define REP(I, N) for(int I=0;I<(N);I++)
#define REPP(I, N) for(int I=1;I<=(N);I++)
#define SZ(x) (int)(x).size()
#define P pair<int, int>
#define F first
#define S second
#define PB(x) push_back(x)
#define endl "\n"
#define ll long long
//#define int long long

//===================================================//

#define N 100000
#define modn 1000000007

using namespace std;
inline int rit(){
    int f=0,key=1;
    char ch;
    do{
        ch = getchar();
        if(ch=='-') key=-1;
    }while(ch<'0'||ch>'9');
    do{
        f = f*10+ch-'0';
        ch = getchar();
    }while(ch>='0'&&ch<='9');
    return f*key;
}
map<int,bool> mp;
int n, num;
int32_t main(void){
    RI(n);
    REP(i,n){
        RI(num);
        if(mp.find(num)!=mp.end()){
            mp.erase(num);
        } else {
            mp[num] = true;
        }
    }
    printf("%d\n",mp.size());
	return 0;
}


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

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

#define p_ary(ary,a,b,i) do { cout << "["; for (int (i) = (a);(i) < (b);++(i)) cout << ary[(i)] << ((b)-1 == (i) ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

int main() {
    int n;
    ll k;
    cin >> n >> k;
    vector<int> a(n),b(n);
    unordered_map<int,int> mp;
    for (int i = 0;i < n;++i) {
        scanf("%d",&a[i]);
        if (mp.find(a[i]) != mp.end()) b[mp[a[i]]] = i;
        mp[a[i]] = i;
    }
    for (int i = 0;i < n;++i) {
        b[mp[a[i]]] = i;
        mp[a[i]] = i;
    }
    int cnt = 1,f = 0;
    do {
        if (b[f] <= f) cnt++;
        f = (b[f]+1)%n;
    } while (f);
    k %= cnt;
    while (1) {
        if (k == 0) break;
        if (b[f] <= f) {
            k--;
            if (k == 0) {
                k++;
                break;
            }
        }
        f = (b[f]+1)%n;
    }
    vector<int> ans;
    if (k) {
        do {
            if (b[f] > f) {
                f = (b[f]+1)%n;
            } else {
                ans.push_back(a[f]);
                f++;
                f %= n;
            }
        } while (f);
    }
    int m = ans.size();
    for (int i = 0;i < m;++i) cout << ans[i] << " \n"[i == m-1];
    return 0;
}

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

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

#define sf scanf
#define pf printf
#define pb push_back
#define mp make_pair
#define IN freopen("input.txt","r",stdin)
#define OUT freopen("output.txt","w",stdout)
#define FOR(i,a,b) for(i=a ; i<=b ; i++)
#define DBG pf("Hi\n")
#define INF 1000000000
#define i64 long long int
#define eps (1e-8)
#define xx first
#define yy second
#define ln 17
#define off 2

//using namespace __gnu_pbds;
using namespace std ;

typedef pair<int, int> pi ;
//typedef tree< pi, null_type, less<pi>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const i64 mod = 1000000007LL ;

#define maxn 500005

/*
     *os.find_by_order(k) -> returns the k'th smallest element (indexing starts from 0)
      os.order_of_key(v)  -> returns how many elements are strictly smaller than v
*/

char s[100005] ;

int main()
{
    i64 N ;

    scanf("%lld",&N) ;

    i64 ans = 0LL ;

    for(i64 i=1 ; i<=N ; i++)
    {
        i64 q = (N/i) ;
        i64 j = (N/q) ;


   //     printf("%lld %lld %lld\n",i,j,q) ;

        i64 x = (N-q)/q ;

        if( x >=i && x <= j && N%x == q && x*q == (N-q) ) ans+= x ;

        i = j ;
    }

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

    return 0 ;
}


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

int main()
{
    ll n;
    cin >> n;
    vector<ll> a(n), b(n);
    rep(i, n)
    {
        cin >> a.at(i);
        a.at(i)--;
        b.at(a.at(i))++;
    }
    ll sum = 0;
    rep(i, n) if (b.at(i) > 1) sum += b.at(i) * (b.at(i) - 1) / 2;
    rep(i, n)
    {
        ll c = sum;
        c -= b.at(a.at(i)) - 1;
        cout << c << endl;
    }
    return 0;
}

Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ii pair<ll,ll>
#define iii pair<ll,ii>
#define endl '\n'

long long qexp(long long b,long long p,int m){
    long long res=1;
    while (p){
        if (p&1) res=(res*b)%m;
        b=(b*b)%m;
        p>>=1;
    }
    return res;
}


int main(){
	ios::sync_with_stdio(0);
    cin.tie(0);
	
	int n;
	cin>>n;
	
	if (n%10==7){
		cout<<"Yes";
		return 0;
	}
	
	n/=10;
	
	if (n%10==7){
		cout<<"Yes";
		return 0;
	}
	
	n/=10;
	
	if (n%10==7){
		cout<<"Yes";
		return 0;
	}
	
	n/=10;
	
	cout<<"No";
	
}

Measured memory_bytes: 3660
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
typedef long long ll;
using namespace std;
const int maxn = 100009;
int n,r,g,b;
ll ans;
string s;
int main(){
    scanf("%d",&n);
    cin >> s;
    for(int i = 0; i < n; i++){
        if(s[i] == 'R')r++;
        else if(s[i] == 'G')g++;
        else if(s[i] == 'B')b++;
    }
    ans = (ll)r*g*b;
    for(int i = 0; i < n; i++)
        for(int p = 1; p <= (n-i-1)/2; p++){
            int j = i+p, k = j+p;
            if(s[i] != s[j] && s[j] != s[k] && s[k] != s[i]) ans--;
        }
    printf("%lld",ans);
    return 0;
}

Measured memory_bytes: 3828
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        String t = sc.next();
        if (s.equals(t)) {
            System.out.println("Yes");
        } else {
            for (int i = 0; i < s.length(); i++) {
                t = t.substring(t.length() - 1, t.length()) + t.substring(0, t.length() - 1);
                if (s.equals(t)) {
                    System.out.println("Yes");
                    System.exit(0);
                }
            }
            System.out.println("No");
        }
    }
}

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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod =(1e9)+7;
using P = pair<ll,ll>;

int main() {
    int h,w;cin >>h>>w;
    char a;
    vector<vector<ll>>turn(h,vector<ll>(w,INF));
    queue<P>now;
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
          cin >>a;
          if(a=='#') {
              turn[i][j] = 0;
              now.push({i, j});
          }
        }
    }
    vector<int>dx={1,-1,0,0};
    vector<int>dy={0,0,1,-1};
    while(!now.empty()){
        P pos;
        pos=now.front();
        now.pop();
        ll ns=turn[pos.first][pos.second];
//        cout <<ns<<endl;
        for (int i = 0; i < 4; ++i) {
            int x=pos.first+dx[i];
            int y=pos.second+dy[i];
//            if(pos.first==0&&pos.second==1){
//                cout <<x<<" "<<y<<endl;
//            }
            if(x>=h||x<0)continue;
            if(y>=w||y<0)continue;
//            if(x==0&&y==0){
//                cout <<turn[x][y]<<" "<<ns+1<<endl;
//            }
            if(turn[x][y]>ns+1){
                now.push({x,y});
            }
            turn[x][y]=min(turn[x][y],ns+1);
        }
    }
    ll ans=0;
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
//            cout <<turn[i][j]<<" ";
            ans=max(ans,turn[i][j]);
        }
//        cout <<endl;
    }
    cout <<ans <<endl;
    return 0;
}



Measured memory_bytes: 24500
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  int A[2][N];
  for (int i = 0; i < 2; i++) {
    for (int j = 0; j < N; j++) {
      cin >> A[i][j];
    }
  }
  int dp[2][N];
  dp[0][0] = A[0][0];
  dp[1][0] = A[0][0] + A[1][0];
  for (int i = 1; i < N; i++) {
    dp[0][i] = dp[0][i - 1] + A[0][i];
    dp[1][i] = max(dp[0][i], dp[1][i - 1]) + A[1][i];
  }
  cout << dp[1][N - 1];
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define pp pair<ll,ll>
#define ppp pair<ll,pp >
#define trace(...) cout<<"Line:"<<__LINE__<<" "; __f(#__VA_ARGS__, __VA_ARGS__)
template<typename Arg1>
void __f(const char* name, Arg1&& arg1) {
	cout<<name<<" : "<<arg1<<endl;
}
template<typename Arg1, typename ... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
	const char* comma=strchr(names+1,',');
	cout.write(names,comma-names)<<" : "<<arg1<<" | ";
	__f(comma+1,args...);
}
typedef tree<pp,null_type,less<pp>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
#define ld long double
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define rep(i,a,b) for(ll i=a;i<b;i+=1)
#define sz(v) (ll)(v.size())
#define hell (ll)1000000007
#define slld(x) scanf("%lld",&x)
ll t=1, tt;
void solve(){
	ll n;
	cin>>n;
	vector<ll> v(n+5);
	rep(i,0,n+1)cin>>v[i];
	//~ for(auto u : v)cout<<u<<" ";
	//~ cout<<"\n";
	ll nonleaves=0, f=1, ans=0;
	for(ll lvl=n;lvl>=0;lvl--){
		if(lvl<=50){
			if((1LL<<lvl)<nonleaves+v[lvl])f=0;
		}
		//~ ans+=nonleaves+v[lvl];
		//~ trace(nonleaves,v[lvl]);
		nonleaves=(nonleaves+v[lvl]+1)/2;
	}
	vector<ll> maxpossible(n+5);
	for(ll i=n;i>=0;i--){
		if(i<=58){
			maxpossible[i]=min(1LL<<i,maxpossible[i+1]+v[i]);
		}
		else
			maxpossible[i]=maxpossible[i+1]+v[i];
	}
	rep(i,0,n+1)maxpossible[i+1]=min((maxpossible[i]-v[i])*2,maxpossible[i+1]);
	rep(i,0,n+1)ans+=maxpossible[i];
	if(!f)ans=-1;
	cout<<ans;
}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
   	//cin>>t;
   	tt=t;
    while(t--){
        solve();
        if(t)cout<<"\n";
    }
    return 0 ;
}


Measured memory_bytes: 4784