akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const ll INF = 1e18;
const long double EPS = 1e-10;
const int MAX = 1e5;

vector<int> G[MAX];
vector<vector<int>> d(2, vector<int>(MAX, -1));

void dfs(int u, int i) {
  for (int v: G[u]) {
    if (d[i][v] != -1) continue;
    d[i][v] = d[i][u] + 1;
    dfs(v, i);
  }
}

int main() {
  int n;
  cin >> n;
  rep(i, n - 1) {
    int a, b;
    cin >> a >> b;
    G[a - 1].push_back(b - 1);
    G[b - 1].push_back(a - 1);
  }

  d[0][0] = 0, d[1][n - 1] = 0;
  dfs(0, 0);
  dfs(n - 1, 1);

  vector<int> c(2, 0);
  rep(i, n) {
    if (d[0][i] <= d[1][i]) c[0]++;
    else c[1]++;
  }
  cout << (c[0] > c[1] ? "Fennec" : "Snuke") << endl;








  
  return 0;
}

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

int main(){
    double pai=3.141592653589;
    int n,x,ans;
    for(;;){
        scanf("%d %d",&n,&x);
        ans=0;
        if(n==0) break;
        for(int i=1;i<n-1;i++){
            for(int j=i+1;j<n;j++){
                for(int k=j+1;k<=n;k++){
                    if(i+j+k==x){
                        ans++;
                    }
                }
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}

Measured memory_bytes: 1188
#include <iostream>
#include <algorithm>
#include <cmath>
#include<string>
#include <array>
#include <vector>
using namespace std;

int main() {
	string s;
	int p = 0, g = 0, i, size, ans = 0;
	cin >> s;
	size = s.size();
	for (i = 0; i < size; i++) {
		if (s[i] == 'p')p++;
		if (s[i] == 'g')g++;
	}
	if (g == p || g - p == 1) {
		ans = 0;
	}
	else {
		ans = (size / 2) - p;
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 512
#import<stdio.h>
#import<queue>
int main(){std::queue<int>q;int w,h,f[484],i,j,a,b,t,x,z;char p[15];for(;scanf("%d%d ",&h,&w),h;){for(j=0;j<w+2;j++)f[j]=f[j-~h*22]=-9;for(i=1;i<=h;i++){for(j=1;j<=w;j++)f[x=i*22+j]=-1,z=getchar(),z-35?z>65?b=x:z>64?a=x:1:--f[x];f[i*22]=f[i*22-~w]=-9;getchar();}f[a]=t=0;q.push(0);for(q.push(a);a=q.front(),q.size()>1;q.pop())if(!a)++t,q.push(0);else for(i=4;i--;)if(f[x=a+" 57L"[i]-54]==-1)f[x]=t,q.push(x);q.pop();scanf("%s",p);for(a=t=0;!a;){x=b;z=0;for(i=0;!a&&p[i];f[b]>=0&&++z)++t,f[j=b-54+"L65676 "[p[i++]-50]]>-3?b=j:0,f[b]>=0&t>=f[b]?a=b:0;!z&!a&!p[i]&b==x&f[b]<0&&--a;}printf(~a?"%d %d %d\n":"impossible\n",t,a/22-1,a%22-1);}}

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

ll gcd(ll a,ll b){
    if(b == 0) return a;
    return gcd(b,a%b);
}
map<ll,ll> prime_factor(ll N){
    map<ll,ll> res; //res[2] = 4は、素因数2が4個あることを表す
    for(ll i = 2;i*i <= N;i++){//小さい素因数から順に割っていく
        while(N % i == 0){//i = 2が素因数だとすると、割り切れる限り2で割る
            res[i]++;//割り切れる回数をres[i]に格納
            N /= i;
        }
    }
    if(N != 1) res[N] = 1;//ループ処理の結果、nが素数の場合、res[n] = 1とする。
    return res;
}
/*
*/
int main(){
  ll A,B;
  cin >> A >> B;
  ll g = gcd(A,B);

  map<ll,ll> ma = prime_factor(g);//gの素因数とその個数を収納
  ll count = 0;
  // Keyの値が小さい順にループ
/*for (auto p : ma) {
  auto key = p.first;
  auto value = p.second;
  // key, valueを使う
  if(value >= 1) count++;//素因数の個数が１以上のものをカウント
}*/
cout << ma.size() + 1 << endl;
 }

Measured memory_bytes: 256
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * y / gcd(x, y); }

long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

void main()
{
	auto s = RD!string;
	long ans;
	auto cnt = new long[](26);
	foreach (i; 0..26)
	{
		auto tokens = s.split(['a'+i]);
		long len;
		foreach (token; tokens)
		{
			len = max(len, token.length);
		}
		cnt[i] = len;
	}
	char c = cast(char)('a' + MIN_POS(cnt));
	while (true)
	{
		bool ok = true;
		foreach (cc; s)
		{
			if (cc != c)
			{
				ok = false;
				break;
			}
		}
		if (ok) break;
		++ans;
		string ns;
		auto streaks = new long[](s.length);
		long streak;
		foreach (i; 0..s.length-1)
		{
			if (s[i] == c || s[i+1] == c)
			{
				ns ~= c;
				streaks[i] = streak;
				streak = 0;
			}
			else
			{
				ns ~= s[i];
				++streak;
			}
		}
		/*if (s[$-1] == c)
		{
			ns ~= c;
			long pos = MIN_POS!"a > b"(streaks);
			long mid = max(pos-1,0);
			s = ns[0..mid] ~ ns[mid+1..$];
		}
		else*/
		{
			s = ns;
		}
		debug writeln(s);
	}

	writeln(ans);
	stdout.flush();
	debug readln();
}


Measured memory_bytes: 380
#include<iostream>
#include<sstream>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<map>
#include<vector>
#include<queue>
#include<set>
#include<numeric>

using namespace std ;

#define pb(n) push_back(n)
#define fi first
#define se second
#define np string::npos
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define repc(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto n :(array))

typedef long long ll ;
typedef vector<int> vi ;
typedef vector<ll> vl ;
typedef map<string,int> dict;

constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
double eps = 1e-10 ;

template <typename T>
void out(vector < T > v)
{
  for(size_t i = 0; i < v.size(); i++)
  {
    debug(v[i]);
  }
}

template<typename T>
string ntos( T i ) {
  ostringstream s ;
  s << i ;
  return s.str() ;
}

template<typename T>
T ston(string str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int num,cor,ans,tmp = -1;
  char c;
  multimap<int,int> mi;
  while(1){
    cin >> num>>c >> cor;
    if(num + cor ==0){
      break;
    }
    mi.insert(make_pair(cor,num)) ;
  }
  while(cin >> num){
    ans = 0;
    tmp = -1;
    for(auto it = mi.rbegin(); it != mi.rend() ; ++it){
      if(tmp != it->fi){
        ++ans;
        tmp = it->fi;
      }
      if(it->se == num){
        break;
      }
      //cout << it->fi << " " << it->se << endl;
    }
    cout << ans << endl ;
  }
  return 0;
}

Measured memory_bytes: 1192
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	input := bufio.NewReader(os.Stdin)

	var N int
	fmt.Fscanf(input, "%d\n", &N)
	p := make([]int, N)
	for n := 0; n < N; n++ {
		fmt.Fscanf(input, "%d", &p[n])
	}
	// fmt.Println(p)
	l := 0
	for l+1 < N && p[l] < p[l+1] {
		l++
	}
	if l+1 == N {
		fmt.Println("YES")
		return
	}
	r := N - 1
	for r > 0 && p[r-1] < p[r] {
		r--
	}
	// fmt.Println(l, r)
	tmp := p[l]
	p[l] = p[r]
	p[r] = tmp
	// fmt.Println(p)
	for i := 0; i+1 < N; i++ {
		if p[i] > p[i+1] {
			fmt.Println("NO")
			return
		}
	}
	fmt.Println("YES")
}


Measured memory_bytes: 640
x,N = list(map(int,input().split()))
p = list(map(int,input().split()))

d_min = 300
i_ans = 300
for i in range(100+1,-100-1,-1):
    if i not in p:
        if abs(x-i) <= d_min:
            d_min = min(d_min,abs(x-i))
            i_ans = i

print(i_ans)


Measured memory_bytes: 9180
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef int64_t int64;
typedef uint32_t uint;
typedef uint64_t uint64;

//---

template <typename T>
inline void print(const T& rhs){ std::cout<<" = "<<rhs<<std::endl; }
template <typename T>
inline void print(const std::vector<T>& rhs){
    std::cout<<" = [ ";
    for(uint i=0; i<rhs.size(); ++i){ std::cout<<rhs[i]<<' '; }
    std::cout<<"]"<<std::endl;
}
template <typename T>
inline void print(const std::vector<std::vector<T>>& rhs){
    std::cout<<" = "<<std::endl;
    std::cout<<"[[ ";
    for(uint p=0; p<rhs.size(); ++p){
        if(p!=0){ std::cout<<" [ "; }
        for(uint q=0; q<rhs[p].size(); ++q){
            std::cout<<rhs[p][q]<<' ';
        }
        if(p!=rhs.size()-1){ std::cout<<"]"<<std::endl; }
    }
    std::cout<<"]]"<<std::endl;
}
template <typename TL, typename TR>
inline void print(const std::vector<std::pair<TR,TL>>& rhs){
    std::cout<<" = [";
    uint i=0;
    for(; i<rhs.size()-1; ++i){ std::cout<<"[f: "<<rhs[i].first<<", s: "<<rhs[i].second<<"], "; }
    std::cout<<"[f: "<<rhs[i].first<<", s: "<<rhs[i].second<<"]]" << endl;
}
#define printn(var) {printf("%s", #var);print(var);}
#define printn_all(var) {printf("%s(%d): ", __func__, __LINE__);printf("%s", #var);print(var);}

//---

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    uint N, M; cin >> N >> M;
    vector<int> vX(M);
    for(uint i=0; i<M; ++i){ cin >> vX[i]; }
    sort(vX.begin(), vX.end());
    
    vector<pair<int, int>> vDiff(M-1); // val, idx
    for(uint i=0; i<M-1; ++i){ vDiff[i] = make_pair(vX[i+1]-vX[i], i); }
    sort(vDiff.begin(), vDiff.end(), greater<pair<int, int>>());
    
    int sum=0;
    int prev=0;
    for(uint i=0; i<min(N-1, M-1); ++i){
        sum += vX[ vDiff[i].second ] - vX[prev];
        prev = vDiff[i].second+1;
    }
    sum += vX[ vX.size()-1 ] - vX[prev];
    cout << sum << endl;
    
    return 0;
}


Measured memory_bytes: 1408
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int s = sc.nextInt();
		Map<Integer, Integer> sequence = new HashMap<>();
		int i = 1;
		int tmp = s;
		while(true) {
			sequence.put(i, tmp);
			if(tmp%2 == 0) {
				tmp = tmp/2;
			} else {
				tmp = 3*tmp+1;;
			}
			if(sequence.containsValue(tmp)) {
				System.out.println(i+1);
				break;
			}
			i++;
		}
	}
}

Measured memory_bytes: 21844
import sys
import math
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, input().split()))
ns = lambda: input()

N,Y=na()

for i in range(N+1):
    for j in range(N+1):
        if(i+j>N):
            break
        if(10000*i+5000*j>Y):
            break
        if(10000*i+5000*j+(N-(i+j))*1000==Y):
            print(i,j,N-i-j)
            exit()


print(-1,-1,-1)

Measured memory_bytes: 3064
/*author @dhanush*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL)
#define pb push_back
#define se second
#define fi first

int main()
{


  ll n, k;
  cin >> n >> k;
  int ans = 0;
  for (int i = 0; i < n; i++)
  {
    ll x, y;
    cin >> x >> y;

    ll xx = x * x + y * y;
    ll yy = sqrt(xx);
    if (yy * yy == xx)
    {
      if (yy <= k)
      {
        ans++;
      }
    }
    else
    {
      if (yy < k)
      {
        ans++;
      }
    }
    // if (yy <= k)
    // {
    //   ans++;
    // }
  }
  cout << ans << endl;

}





Measured memory_bytes: 3608
#pragma region
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <iomanip>
#include <cstdint>
#include <cstdlib>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i))
#define all(x) x.begin(),x.end()
#pragma endregion


int main()
{
	int q; cin >> q;
	multiset<ll> l, r;
	ll res = 0;
	while (q--)
	{
		int t; cin >> t;
		if (t == 1)
		{
			ll a, b; cin >> a >> b;
			if (l.empty())
			{
				l.insert(a);
				res = b;
			}
			else
			{
				ll px = *(--l.end());
				if ((l.size() + r.size()) % 2 == 0)
				{
					if (px < a)
					{
						r.insert(a);
						ll nx = *r.begin();
						l.insert(nx);
						r.erase(r.begin());
						res += a - nx + b;
					}
					else
					{
						l.insert(a);
						res += px - a + b;
					}
				}
				else
				{
					if (a < px)
					{
						l.insert(a);
						r.insert(px);
						l.erase((--l.end()));
						ll nx = *(--l.end());
						res += (px - nx) + (nx - a) + b;
					}
					else
					{
						r.insert(a);
						res += a - px + b;
					}
				}
			}
		}
		else
		{
			cout << *(--l.end()) << " " << res << endl;
		}
	}
}


Measured memory_bytes: 9600
import bisect
A, B, Q = map(int, input().split())
INF = 10 ** 18
s = [-INF] + [int(input()) for i in range(A)] + [INF]
t = [-INF] + [int(input()) for i in range(B)] + [INF]

for q in range(Q):
    x = int(input())
    b, d = bisect.bisect_right(s, x), bisect.bisect_right(t, x)
    res = INF
    for S in [s[b - 1], s[b]]:
        for T in [t[d - 1], t[d]]:
            d1, d2 = abs(S - x) + abs(T - S), abs(T - x) + abs(S - T)
            res = min(res, d1, d2)
    print(res)

Measured memory_bytes: 12812
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)
	for {
		n := nextInt()
		x := nextInt()

		if n == 0 && x == 0 {
			break
		}

		ans := calcCombination(n, x)
		fmt.Println(ans)
	}
}

func nextInt() int {
	sc.Scan()
	n, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return n
}

func calcCombination(n, x int) int {
	counter := 0
	for i := 1; i <= n; i++ {
		for j := i + 1; j <= n; j++ {
			for k := j + 1; k <= n; k++ {
				if i+j+k == x {
					counter++
				}
			}
		}
	}
	return counter
}



Measured memory_bytes: 1088
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        while(true) {
        	String cards = sc.nextLine();
        	if(cards.equals("-")) {
        		break;
        	}

            int count = Integer.parseInt(sc.nextLine());;
            for(int i = 0; i < count; i++) {
            	int shuffleNum = Integer.parseInt(sc.nextLine());
            	cards = cards.substring(shuffleNum) + cards.substring(0, shuffleNum);
            }
            System.out.println(cards);
        }
    }
}


Measured memory_bytes: 26408
<?php

$n =trim(fgets(STDIN));
$dx = explode(' ', trim(fgets(STDIN)));

$sum = 0;
for($i=0; $i<$n; $i++){
  $s = trim(fgets(STDIN));
  $sum += ceil($dx[0]/$s);
}
echo $sum+$dx[1];

?>

Measured memory_bytes: 4604
// Problem : A - Three-letter acronym
// Contest : AtCoder - AtCoder Beginner Contest 059
// URL : https://atcoder.jp/contests/abc059/tasks/abc059_a
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#define eb emplace_back
#define pb push_back
#define size(s) (int)s.size()
#define int long long
#define vi vector<int>
#define vs vector<string>
#define vv vector<vector<int>>
#define pii pair<int,int>
#define m_p(x,y) make_pair(x,y)
#define vp vector<pair<int,int>>
#define setbits(x) __builtin_popcountll(x)
#define f first
#define se second
#define inc(v,n,x) v.assign(n,x)
#define incd(v,n) v.resize(n)
#define iniz(n) memset(n,0,sizeof(n))
#define inin(n) memset(n,-1,sizeof(n))
#define inimi(n) memset(n,0xc0,sizeof(n))
#define inima(n) memset(n,0x3f,sizeof(n))
#define all(v) (v).begin(),(v).end()

using namespace std;

template<typename T1,typename T2>istream &operator>>(istream &is, vector<pair<T1,T2>> &v) { for (pair<T1,T2> &t : v) is >> t.f>>t.se; return is; }
template<typename T>istream &operator>>(istream &is, vector<T> &v) { for (T &t : v) is >> t; return is; }
template<typename T>ostream &operator<<(ostream &os, const vector<T> &v) { for (const T &t : v) {os << t <<" ";} os << '\n'; return os; }

double pi=acos(-1.0);
const int md=1e9+7;
const int INF=1e15;
int dx1[]={0,0,-1,1};
int dy1[]={1,-1,0,0};

template<class T>
T abst(T a)
{return a<0?-a:a;}

template<class T>
T max2(T a,T b){return a>b?a:b;}
template<class T>
T min2(T a,T b){return a<b?a:b;}

void solve()
{
string s1,s2,s3;cin>>s1>>s2>>s3;
cout<<char(s1[0]-('a'-'A'))<<char(s2[0]-('a'-'A'))<<char(s3[0]-('a'-'A'));
}

int32_t main(){
ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
int t=1;
//cin>>t;
for(int i=1;i<=t;i++)
{
    solve();
}
return 0;
}


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

#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define FORR(i,m,n) for(int i=m;i>=n;i--)
#define pb(x) push_back(x) 
#define SORT(x) sort((x).begin(),(x).end())
#define INF 20000000000

using namespace std;

#define int long long

int32_t main(){
	int a, b, x, y;
	cin >> a >> b;	
	
	int ans=INF;
	x=a; y=b;
	a=-a;
	if(a<=b){
		int cnt=0;
		cnt++;
		cnt+=(b-a);
		ans=min(ans, cnt);
	}
	b=-b;
	if(a<=b){
		int cnt=0;
		cnt++;
		cnt++;
		cnt+=(b-a);
		ans=min(ans, cnt);
	}
	a=x;
	if(a<=b){
		int cnt=0;
		cnt++;
		cnt+=(b-a);
		ans=min(ans, cnt);
	}
	b=y;
	if(a<=b){
		int cnt=0;
		cnt+=(b-a);
		ans=min(ans, cnt);
	}
	
	cout << ans << endl;		
}

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
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 = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

int main(){
    ll n;
    cin >> n;
    cout << (n-1) * n / 2 << endl;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define ll          long long int
#define pb          push_back
#define pll         pair<ll,ll>
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mod         1000000007
#define inf         1000000000000000000LL
#define vl          vector<ll>
#define F           first
#define S           second
#define db          long double
#define sz(x)       (ll)x.size()
#define fix(n)      cout<<fixed<<setprecision(n)
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define all(x)      x.begin(),x.end()
#define pi          3.14159265358979323




void solve()
{
       ll n,k;
       cin>>n>>k;
       ll t = (1 << n) - 1;
       if(k==0)
       {
              rep(i,0,t+1) cout<<i<<" "<<i<<" ";
              return;
       }
       ll x=0;
       rep(i,1,t+1)
       {
              if(i!=k) x ^= i;
       }
       if(x!=k)
       {
              cout<<-1;
              return;
       }
       rep(i,0,t+1)
       {
              if(i!=k) cout<<i<<" ";
       }
       cout<<k<<" ";
       for(ll i=t; i>=0; i--) if(i!=k) cout<<i<<" ";
       cout<<k<<" ";
}

int main()
{
       speed_up;
       ll T=1;
       //cin>>T;
       while(T--) solve();
	return 0;
}


Measured memory_bytes: 1792
import sys
sys.setrecursionlimit(10 ** 6)

n, m = map(int, input().split())
e = [[] for _ in range(n)]

for _ in range(m):
    a, b = map(int, input().split())
    e[a-1].append(b-1)

c = [0] * n
ans = []
def search_path(p, temp):
    c[p] = 1
    for x in e[p]:
        if x in temp:
            print(-99999)
            exit()
        else:
            search_path(x, temp + [x])


t = 1
for i in range(n):
    if c[i] == 0:
        ans = search_path(i, [i])

print(-1)


Measured memory_bytes: 13728
loop do
  n = gets.to_i
  break if n.zero?
  ss = n.times.map { gets.split.map(&:to_i) }
  m = gets.to_i
  ss += m.times.map { gets.split.map(&:to_i) }
  cs = Array.new n + m, 0
  es = Array.new(n + m) { [] }
  rs = Array.new n + m, 0
  (n+m).times do |i|
    (n+m).times do |j|
      next if i == j
      if ss[i][0] < ss[j][0] && ss[i][1] < ss[j][1]
        cs[i] += 1
        es[j] << i
      end
    end
  end
  stack = []
  (n+m).times do |i|
    if cs[i].zero?
      stack << i
      rs[i] = 1
    end
  end
  until stack.empty?
    i = stack.pop
    es[i].each do |j|
      rs[j] = [rs[j], rs[i] + 1].max
      cs[j] -= 1
      stack << j if cs[j].zero?
    end
  end
  p rs.max
end

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

#define F first
#define S second
#define PB push_back

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
typedef priority_queue<int> HEAP;
typedef priority_queue<int, vector<int>, greater<int> > RHEAP;

const int N = 5010, M = 1010, INF = 0x3f3f3f3f;

int n, m;
int a[N], b[N];
int f[N][N];

int main()
{
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= m; i ++ )
	{
		int cnt;
		scanf("%d%d", &a[i], &cnt);
		for (int j = 0; j < cnt; j ++ )
		{
			int c;
			scanf("%d", &c);
			b[i] += 1 << (c - 1);
		}
	}
	
	memset(f, 0x3f, sizeof f);
	f[0][0] = 0;
	
	for (int i = 1; i <= m; i ++ )
	{
		memcpy(f[i], f[i - 1], sizeof f[i - 1]);
		for (int j = 0; j < 1 << n; j ++ )
		{
			int t = min(f[i - 1][j | b[i]], f[i - 1][j] + a[i]);
			f[i][j | b[i]] = min(f[i][j | b[i]], t);
		}
	}
	
	int res = f[m][(1 << n) - 1];
	if (res == INF) puts("-1");
	else printf("%d\n", res);
	return 0;
}

Measured memory_bytes: 98432
#include <bits/stdc++.h>
#define L long long

using namespace std;

L n,m,k,ans,cnt;

L c[100010];

vector<L>colors[100010];

L bu[100010],lev[100010];

L fin(L x){
	return x==bu[x]?x:bu[x]=fin(bu[x]);
}

struct S{
	L s,e,len;
}a[100010];

bool operator<(S a,S b){
	return a.len<b.len;
}

void uni(L x,L y){
	x=fin(x);
	y=fin(y);
	if(x==y) return;
	if(lev[x]<lev[y]) swap(x,y);
	bu[y]=x;
	if(lev[x]==lev[y]) lev[x]++;
}

int main()
{
	scanf("%lld %lld %lld",&n,&m,&k);
	L i,j;
	for(i=1;i<=n;i++)
	{
		scanf("%lld",&c[i]);
		colors[c[i]].push_back(i);
		
		bu[i]=i;
	}
	for(i=1;i<=k;i++)
	{
		for(j=1;j<colors[i].size();j++)
		{
			uni(colors[i][j],colors[i][j-1]);
			//printf("%lld %lld\n",colors[i][j],colors[i][j-1]);
		}
	}
	for(i=1;i<=m;i++)
	{
		scanf("%lld %lld %lld",&a[i].s,&a[i].e,&a[i].len);
	}
	sort(a+1,a+m+1);
	for(i=1;i<=m;i++)
	{
		//if(c[a[i].s]&&c[a[i].e])
		if(cnt<k-1)
		{
			if(fin(a[i].s)!=fin(a[i].e))
			{
				cnt++;
				ans+=a[i].len;
				uni(a[i].s,a[i].e);	
			}
		}
	}
	if(cnt<k-1) puts("-1");
	//printf("%lld ",cnt);
	else printf("%lld",ans);
}

Measured memory_bytes: 10368
def main():
    N = int(input())
    a = list(map(int, input().split()))
    dic = {}
    for i in a:
        dic[i] = 1 + dic.get(i, 0)

    res = 0
    for k, v in dic.items():
        if k > 10**5:
            res += v
        elif k == v:
            continue
        elif k > v:
            res += v
        else:
            res += v- k

    print(res)

if __name__ == '__main__':
    main()


Measured memory_bytes: 18172
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define per1(i,n) for(int i=n;i>0;i--)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,m,d;
    cin>>n>>m>>d;
    cout<<setprecision(10)<<(double)(n-d)*(m-1)/n/n*(2-(!d));
}

Measured memory_bytes: 3784
#include<bits/stdc++.h>
    using namespace std;
    
    //                                 (POLICY BASED DS)
    // #include <ext/pb_ds/assoc_container.hpp>
    // #include <ext/pb_ds/tree_policy.hpp>
    // using namespace __gnu_pbds;
    // template<typename T>
    // using ordered_set=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
    // template<typename T>
    // using ordered_multiset=tree<T,null_type,less_equal<T>,rb_tree_tag,tree_order_statistics_node_update>;
    //                      ( find_by_order( )  ,  order_of_key( ) )
    
    typedef long long ll;
    typedef long double ld;
    typedef unsigned long long ull;
    typedef vector<int> vi;
    typedef vector<long long> vll;
    typedef pair<ll,ll> pll;
     
    const ll mod = 1e9 + 7;
    const ld PI = 3.1415926535897932384626;
    const ld eps = 1e-9;                            
     
    #define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
    #define sidha(i,a,b) for(ll i=(ll)(a);i<(ll)(b);++i)
    #define ulta(i,a,b) for(ll i=(ll)(a);i>=(ll)(b);--i)
    #define stl(container,itr) \
        for(auto itr = container.begin(); itr != container.end(); itr++)
    #define sab(v) v.begin(), v.end()
    #define rall(v) v.rbegin(), v.rend()            
    #define test ll t;cin>>t;while(t--)
    #define sz size()
    #define pb push_back
    #define mp make_pair
    #define fi first
    #define se second
    #define LOG2(X) (63ll - __builtin_clzll(X))
    #define endl '\n'
    #define modinv(x) power(x, mod-2)
    #define ncr(n,r) ( n >= r ? ((((fact[n]*modinv(fact[r]))%mod)*modinv(fact[n-r]))%mod) : (ll)0)
    #define MAX 100005
     
    ll power(ll x, ll y) { 
        ll ans=1;
        x=x%mod;
        while(y>0) { 
            if (y&1) 
                ans=(ans*x)%mod; 
            y=y>>1;
            x=(x*x)%mod; 
        } 
        return ans; 
    }
    
    // vector<ll> adj[MAX];
    // ll visit[MAX];
    // void dfs(ll node){
    //     visit[node]=1;
    //     for(auto i : adj[node]){
    //         if(!visit[i]) dfs(i);
    //     }
    // }
    
    // ll spf[MAX];
    // void sieve(){
    //     sidha(i,1,MAX)  spf[i]=i;
    //     for(ll i=4;i<MAX;i+=2)  spf[i]=2;
    //     for(ll i=3;i*i<=MAX;i++){
    //         if(spf[i]==i){
    //             for(ll j=i*i;j<MAX;j+=i){
    //                 if(spf[j]==j)   spf[j]=i;
    //             }
    //         }
    //     }
    // }

    int main()
    {
        boost;
        string s,t;
        ll count,ans=LLONG_MAX;
        cin>>s>>t;
        sidha(i,0,s.size()-t.size()+1){
            count=0;
            sidha(j,i,i+t.size()){
                if(s[j]!=t[j-i])    count++;
            }
            ans=min(count,ans);
        }
        cout<<ans;
        return 0;
    }
    

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
int dp[401][401],n;
int a[401];
int cost(int ac,int bc)
{
    int x=0;
    if(ac) x=a[ac-1];
    return a[bc]-x;
}
int fun(int s,int e)
{
    if(s==e)
        return 0;
    int &ret=dp[s][e];
    if(~ret) return ret;
    ret=1e18;
    for(int i=s;i<e;i++)
        ret=min(ret,cost(s,i)+fun(s,i)+fun(i+1,e)+cost(i+1,e));
    return ret;
}
signed main()
{
    memset(dp,-1,sizeof dp);
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        if(i) a[i]+=a[i-1];
    }
    cout<<fun(0,n-1)<<endl;
	return 0;
}



Measured memory_bytes: 4920
#include<iostream>
using namespace std;
int main(void)
{
    int A,B,C,X,a,b,c,sum=0,cnt=0;
    cin>>A>>B>>C>>X;
    for(a=0;a<=A;a++){
        for(b=0;b<=B;b++){
            for(c=0;c<=C;c++){
                sum=500*a+100*b+50*c;
                if(sum==X)
                cnt++;
            }
        }
    }
    cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
        char type;
        int card[4][13]={0},num,amount,i,j;
        scanf("%d",&amount);
        for(i=0;i<amount;i++){
                scanf(" %c %d",&type,&num);
                if(type == 'S')
                        card[0][num-1]=1;
                else if(type =='H')
                        card[1][num-1]=1;
                else if(type=='C')
                        card[2][num-1]=1;
                else if(type=='D')
                        card[3][num-1]=1;
        }
        for(i=0;i<4;i++){
                for(j=0;j<13;j++){
                        if(card[i][j]==0){
                                switch(i){
                                        case 0:
                                                putchar('S');
                                                break;
                                        case 1:
                                                putchar('H');
                                                break;
                                        case 2:
                                                putchar('C');
                                                break;
                                        case 3:
                                                putchar('D');
                                                break;
                                }
                                printf(" %d\n",j+1);
                        }
                }
        }
        return 0;
}

Measured memory_bytes: 600
/*   _/                _/                 _/_/_/   _/
  _/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
   _/     _/    _/   _/     _/    _/  _/_/_/     _/
  _/     _/    _/   _/     _/    _/  _/    _/   _/
   _/_/   _/_/       _/_/   _/_/      _/_/     _/ */
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
using ll=long long;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=2e9;
const ll INF=1e18;
using P=pair<int,int>;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  int n,a,ans=0;
  cin >> n;
  for(int i=0; i<n; i++) {
    cin >> a;
    while(a%2==0) {
      ans++;
      a/=2;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(false), cout << fixed << setprecision(20);
#define int long long
#define gcd __gcd
#define all(x) (x).begin(), (x).end()
template<class T>
bool chmax(T& a, T b){return (a = max(a, b)) == b;}
template<class T>
bool chmin(T& a, T b){return (a = min(a, b)) == b;}
#define _overload(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(...) _overload(__VA_ARGS__, repi, _rep)(__VA_ARGS__)
#define _rev(i, n) revi(i, n, 0)
#define revi(i, a, b) for(int i = (int)(a - 1); i >= (int)(b); i--)
#define rev(...) _overload(__VA_ARGS__, revi, _rev)(__VA_ARGS__)
#define each(i, n) for(auto&& i: n)
const int INF = 1e18, MOD = 1e9 + 7;
struct UnionFind {
    vector<int> t;
    UnionFind(int size): t(size, -1) {}
    int root(int x) {return t[x] < 0 ? x : t[x] = root(t[x]);}
    int size(int x) {return -t[root(x)];}
    bool isSame(int x, int y) {return root(x) == root(y);}
    bool unite(int x, int y) {
        x = root(x), y = root(y);
        if(x != y) {
            if(t[y] < t[x]) swap(x, y);
            t[x] += t[y], t[y] = x;
        }
        return x != y;
    }
};
map<int, int> factorization(int n) {
    map<int, int> res;
    rep(i, 2, sqrt(n) + 1) {
        if(i > 3) i++;
        while(!(n%i)) res[i]++, n /= i;
    }
    if(n > 1) res[n]++;
    return res;
}
signed main() {
    INCANT;
    int n, res = 0;
    int a[111111];
    pair<int, int> b[111111];
    struct UnionFind uf(222222);
    map<int, int> m;
    cin>>n;
    rep(i, n) {
        cin>>a[i];
        b[i] = {a[i], i};
    }
    rep(i, n){
        m = factorization(a[i]);
        each(p, m){
            uf.unite(i, 111111 + p.first);
        }
    }
    sort(b, b + n);
    rep(i, n){
        if(a[i] != b[i].first){
            if(!uf.isSame(i, b[i].second)){
                cout<<0<<endl;
                return 0;
            }
        }
    }
    cout<<1<<endl;
}



Measured memory_bytes: 7048
#include<bits/stdc++.h>
#define int long long
using namespace std;
constexpr int mod=1e9+7;
signed main(){
    int n,k,d,a,arr[101]={};
    cin>>n>>k;
    while(cin>>d)
        for(int i=0;i<d;i++)
            cin>>a,arr[a]++;
    int ans=0;
    for(int i=1;i<=n;i++)
        if(arr[i]==0)
            ans++;
    cout<<ans<<endl;
}

Measured memory_bytes: 3624
n,a,b=map(int,input().split())
s=input()
japan=0
abroad=0
for i in range(n):
    p=s[i]
    if p == 'c':
        print('No')
        continue
    if p == 'a' and japan+abroad < a+b:
        japan+=1
        print('Yes')
        continue
    elif p=='a':
        print('No')
        continue
    if p=='b' and japan+abroad < a+b and abroad < b:
        print('Yes')
        abroad+=1
        continue
    else:
        print('No')
        continue



Measured memory_bytes: 4244
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <cstring>
#include <vector>
#include <map>
#include <cmath>
#include <climits>

//find out the use of the below
#include <list>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <memory.h>
#include <cassert>

using namespace std;
//using namespace __gnu_pbds;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> set_t;
#define mp(a,b) make_pair((a),(b))
#define pii pair<int,int>
#define pll pair<LL,LL>
#define pdd pair<double,double>
#define pb push_back
#define x first
#define y second
#define sqr(x) ((x)*(x))
#define EPS 1e-6
#define MEM(x) memset(x,0,sizeof(x))
#define MEMS(x) memset(x,-1,sizeof(x))
#define pi acos(-1)

int main(){
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt","w", stdout);
    int n;
    scanf("%d", &n);
    vector<int> a(n+2);
    for (int i = 1; i <= n+1; ++i)
        scanf("%d", &a[i]);
    long long ans = 0;
    int pb = 0;
    for (int i = 1; i <= n; ++i){
        int b;
        scanf("%d", &b);
        int kld = min(a[i], pb+b);
        ans += kld;
        kld -= pb;
        if (kld <= 0)
            pb = b;
        else
            pb = b-kld;
    }
    ans += min(a[n+1], pb);
    cout << ans;

        
    return 0;
}
/* BEFORE submitting, check for:
 *  1. Integer overflow
 *  2. Float/Double precision errors
 *  3. Array index out of bounds
 *  4. Edge cases.(n=1, n=max, etc.)
 *  5. Time complexity. No TLEs
 */



Measured memory_bytes: 640
import java.util.*;
import static java.lang.Math.*;
import java.math.BigInteger;

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 x = sc.nextInt();
		int y = sc.nextInt();

		// 計算
		int result = 0;
		if(a + b <= 2*c){
		    result = a*x + b*y;
		}else{
		    int c_cnt = min(x, y);
		    result += c*c_cnt*2;
		    int r_cnt = max(x, y) - c_cnt;
		    int r_price = a;
		    if(x < y) r_price = b;
		    if(r_price < 2*c){
		        result += r_cnt * r_price;
		    }else{
		        result += r_cnt * 2 * c;
		    }
		}
		
		// 出力
		System.out.println(result);
	}
}



Measured memory_bytes: 23636
X = int(input())
a = 0
b = 0

if X < 500:
    if X % 5 == 0 :
        print(X)
    else:
        a = X // 5 * 5
        print(a)
elif X >= 500 :
    if X % 500 == 0 :
        print(X*2)
    else:
        a = X // 500 * 1000
        b = X % 500
        if b % 5 == 0 :
            print(a + b)
        else:
            b = b // 5 * 5
            print(a + b)

Measured memory_bytes: 3064
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv,
    std.functional, std.math, std.numeric, std.range, std.stdio, std.string,
    std.random, std.typecons, std.container;

ulong MAX = 100_100, MOD = 1_000_000_007, INF = 1_000_000_000_000;
alias sread = () => readln.chomp();
alias lread(T = long) = () => readln.chomp.to!(T);
alias aryread(T = long) = () => readln.split.to!(T[]);
alias Pair = Tuple!(long, "x", long, "y");
alias PQueue(T, alias less = "a>b") = BinaryHeap!(Array!T, less);

void main()
{
    auto n = lread();
    auto status = new long[][](n, n);
    foreach (ref e; status)
        e[] = -1;

    foreach (i; iota(n))
    {
        auto a = lread();
        foreach (_; iota(a))
        {
            long x, y;
            scan(x, y);
            status[i][x - 1] = y;
        }
    }
    // status.each!(x => x.writeln());
    long ans;
    outer: foreach (s; iota(0, 1 << n))
    {
        auto p = new long[](n);
        p[] = -1;
        foreach (loc; iota(n))
        {
            if (s & (1 << loc))
            {
                bool t = true;
                t &= (p[loc] != 0);
                p[loc] = 1;
                foreach (u; iota(n))
                {
                    if (p[u] == -1)
                        p[u] = status[loc][u];
                    else if (status[loc][u] != -1 && p[u] != status[loc][u])
                        t = false;
                }
                // writef("%b, %s ", s, loc);
                // p.writeln(" ", t);
                if (!t)
                    continue outer;
            }
            else
            {
                // writef("%b, %s ", s, loc);
                // p[loc].writeln("= p[loc]");
                if (p[loc] == 1)
                    continue outer;
                p[loc] = 0;
            }
        }
        ans = max(ans, popcnt(s));
        // ans.writeln(" = ans");
    }
    ans.writeln();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}


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

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

    int ans = n - i + 1;

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(long long int i = 0; i < n; i++)
#define _rep(i,m,n) for(long long int i = m; i < n; i++)
#define print(n) std::cout << n << std::endl
#define _print(n) std::cout << n
using namespace std;
typedef long long ll;
const int N = 1000000;
const ll mod = 1000000007;
using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll n, w;
ll weight[110], value[110];
ll dp[110][100100];

int main(){
    cin >> n >> w;
    rep(i,n) cin >> weight[i] >> value[i];
    
    rep(i,n){
        rep(j,w + 1){
            if(j < weight[i]){
                dp[i + 1][j] = dp[i][j];
            }else{
                dp[i + 1][j] = max(dp[i][j], dp[i][j - weight[i]] + value[i]);
            }
        }
    }
    cout << dp[n][w] << endl;
}

Measured memory_bytes: 79360
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;

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

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

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

// container util
//------------------------------------------
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i, c)                                                             \
  for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())

// repetition
//------------------------------------------
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

// constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);

// clear memory
#define CLR(a) memset((a), 0, sizeof(a))

// debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x)                                                               \
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")"                       \
       << " " << __FILE__ << endl;

void solve(long long A, long long B, long long C, long long D) {
  int a = B/C - A/C;
  int b = B/D - A/D;
  int c = B/(C*D) - A/(C*D);
  cout<<a+b-c<<endl;
}
bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}

LL gcd(LL m, LL n){
  LL temp;
  while(n!=0){
    temp=n;  // t=2 1
    n = m%n; // n=1 0
    m=temp;  // m=2 1
  }
  return m;
}

LL lcm(LL m,LL n){
  return m*n/gcd(m,n);
}
int main() {
  LL A,B;
  LL C,D;
  cin>>A>>B>>C>>D;
  A--;
  A -= (A/C)+(A/D)-A/lcm(C,D);
  B -= (B/C)+(B/D)-B/lcm(C,D);
  cout<<B-A<<endl;
  return 0;
}

/*


1 10 2 3

1 2' 3' 4' 5 6'' 7 8' 9' 10
10 - (10/2);
10 - (10/3);

10+10/lcm(2,3);

4' 5 6' 7 8' 9' : 2

1 2 3 4: 1

1 2' 3' 4' 5 6' 7 8' 9'
*/

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string>
#include <cstring>
#include <stack>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
using namespace std;
#define INF 0x3f3f3f3f
#define mod 998244353
bool cmp(const int& a, const int& b) {
	return a > b;
}
int main() {
	int a[3];
	for (int i = 0; i < 3; ++i) {
		cin >> a[i];
	}
	sort(a, a + 3,cmp);
	if (a[0] & 1) {
		if (a[1] & 1) {
			if (a[2] & 1) {
				printf("%d\n", (a[0] - a[1]) / 2 + (a[0] - a[2]) / 2);
			}
			else {
				printf("%d\n", 1 + (a[0] - a[1]) / 2+ (a[0] - a[2] + 1) / 2);
			}
		}
		else {
			if (a[2] & 1) {
				printf("%d\n", 1 + (a[0] - a[1] + 1) / 2 + (a[0] - a[2]) / 2);
			}
			else {
				printf("%d\n", 1 + (a[0] - a[1]) / 2 + (a[0] - a[2]) / 2);
			}
		}
	}
	else {
		if (a[1] & 1) {
			if (a[2] & 1) {
				printf("%d\n", 1 + (a[0] - a[1]) / 2 + (a[0] - a[2]) / 2);
			}
			else {
				printf("%d\n", 1 + (a[0] - a[1] + 1) / 2 + (a[0] - a[2]) / 2);
			}
		}
		else {
			if (a[2] & 1) {
				printf("%d\n", 1 + (a[0] - a[1]) / 2 + (a[0] - a[2] + 1) / 2);
			}
			else {
				printf("%d\n",(a[0] - a[1]) / 2 + (a[0] - a[2]) / 2);
			}
		}
	}
	return 0;
}


Measured memory_bytes: 256
from itertools import product
n, m, x = map(int, input().split())
costs = []
gets = []
for i in range(n):
    cost, *argo = map(int, input().split())
    costs.append(cost)
    gets.append(argo)

    
bits_list = list(product([0,1], repeat=n))
min_cost = float('inf')
cnt = 0
for bits in bits_list:
    tmp_cost = 0
    tmp_argo = [0] * m
    for i, v in enumerate(bits):
        if v:
            tmp_cost += costs[i]
            for j, p in enumerate(gets[i]):
                tmp_argo[j] += p
                
    if all(map(lambda X:X>=x, tmp_argo)):
        min_cost = min(min_cost, tmp_cost)
        cnt = 1
if cnt:
    print(min_cost)
else:
    print(-1)

Measured memory_bytes: 9616
use proconio::{fastout, input};
#[allow(unused_mut)]
#[fastout]
fn main() {
    input! {
        x: usize
    }
    for i in x..=100003usize {
        if i.is_prime() {
            println!("{}", i);
            return;
        }
    }
}

trait Prime {
    fn is_prime(&self) -> bool;
}

impl Prime for usize {
    fn is_prime(&self) -> bool {
        let n = *self;
        if n <= 1 {
            return false;
        }

        if n == 2 {
            return true;
        }
        let lim = (n as f64).sqrt().ceil() as usize;
        for i in 2..=lim {
            if n % i == 0 {
                return false;
            }
        }
        true
    }
}


Measured memory_bytes: 2688
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <queue>
#include <cstdlib>

using namespace std;

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

const ll mod = 1000000007;

struct lazy_segtree {
  int n;
  vector<int> data;
  vector<int> lazy;
  vector<bool> lazyFlag;

  lazy_segtree(const int s) {
    init(s);
  }

  lazy_segtree(const vector<int> &v) {
    int s = v.size();
    init(s);
    for (int i = 0; i < s; i++) {
      data[i+n-1] = v[i];
    }
    for (int i = n-2; i >= 0; i--) {
      data[i] = min(data[i*2+1], data[i*2+2]);
    }
  }

  void init(const int s) {
    n = 1;
    while (n < s) n <<= 1;
    data = vector<int>(2*n-1);
    lazy = vector<int>(2*n-1);
    lazyFlag = vector<bool>(2*n-1);
  }

  void evaluate(int p, int a, int b) {
    if (lazyFlag[p]) {
      data[p] += lazy[p];
      if (b - a > 1) {
        lazy[p*2+1] += lazy[p];
        lazy[p*2+2] += lazy[p];
        lazyFlag[p*2+1] = true;
        lazyFlag[p*2+2] = true;
      }
      lazy[p] = 0;
      lazyFlag[p] = false;
    }
  }

  void update(int l, int r, int v, int p = 0, int a = 0, int b = -1) {
    if (b < 0) b = n; // init

    // evaluate lazy value
    evaluate(p, a, b);

    if (r <= a || b <= l) return; // out of range
    if (l <= a && b <= r) { // fully covered
      lazy[p] += v;
      lazyFlag[p] = true;
      evaluate(p, a, b);
    }
    else {
      update(l, r, v, p*2+1, a, (a + b) / 2); // left
      update(l, r, v, p*2+2, (a + b) / 2, b); // right
      data[p] = min(data[p*2+1], data[p*2+2]); // update
    }
    return;
  }

  int query(int l, int r, int p = 0, int a = 0, int b = -1) {
    if (b < 0) b = n; // init
    if (r <= a || b <= l) return 0x7fffffff; // out of range

    // evaluate lazy value
    evaluate(p, a, b);

    if (l <= a && b <= r) return data[p];// fully covered

    int vl = query(l, r, p*2+1, a, (a + b) / 2); // left
    int vr = query(l, r, p*2+2, (a + b) / 2, b); // right
    return min(vl, vr);
  }
};

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

  int n, q;
  cin >> n >> q;
  vector<vector<int> > query(q, vector<int>(4));
  for (int i = 0; i < q; i++) {
    cin >> query[i][0] >> query[i][1] >> query[i][2];
    if (query[i][0] == 0) cin >> query[i][3];
  }

  lazy_segtree lst(n);
  vector<ll> ans;
  for (int i = 0; i < q; i++) {
    if (query[i][0] == 0) { // add
      lst.update(query[i][1], query[i][2]+1, query[i][3]);
    }
    else { // findMin
      ans.push_back(lst.query(query[i][1], query[i][2]+1));
    }
  }

  for (auto &x: ans) cout << x << endl;

  return 0;
}



Measured memory_bytes: 11524
#include<iostream>
using namespace std;
int main(){
  int temp;
  int x;
  cin >> temp;
  x += temp * 100;
  cin >> temp;
  x += temp*10;
  cin >> temp;
  x += temp;

  switch(x){
  case 0:cout << "Close"<<endl;break;
  case 1:cout << "Open" << endl;break;
  case 10:
  case 100:cout << "Close"<<endl;break;
  case 110:cout<<"Open"<<endl;break;
  
  cefault:cout << "Close"<<endl;break;
  }
  
  return 0;
}

Measured memory_bytes: 1156
#include<stdio.h>

int main(void) {
    double a, b, c, d, e, f;
    double x, y;
    while(scanf("%lf%lf%lf%lf%lf%lf", &a, &b, &c, &d, &e, &f) != -1) {
        x = (b*f - c*e) / (b*d - a*e);
        y = (a*f - c*d) / (a*e - b*d);
        
        x += 0.0004;
        y += 0.0004;
        
        printf("%.3lf %.3lf\n", x, y);
    }
    return 0;
}

Measured memory_bytes: 656