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

#define rep(i,n) for(ll i=0;i<ll(n);i++)
#define YESNO(T) if(T){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define yesno(T) if(T){cout<<"yes"<<endl;}else{cout<<"no"<<endl;}
#define YesNo(T) if(T){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}

const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
const double pi = 3.14159265358979;

struct UnionFind {
    vector<ll> d;
    //親(負)…木のsize*(-1)
    //子(正)…親のindex

    UnionFind(ll n){
        d = vector<ll>(n,-1);        
    }
    //初期化

    ll find(ll x){
        if (d[x] < 0) return x;
        return d[x] = find(d[x]);
    }
    //親のindexを返す



    bool unite(ll x,ll y){
        x = find(x);
        y = find(y);

        if (x == y) return false;

        if (d[x] >d[y]) swap(x,y);

        d[x] += d[y];
        d[y] = x;

        return true;
    }
    //木と木を接続する

    bool same(ll x,ll y){
        return find(x) == find(y) ? true : false;
    }
    //xとyの親が同じか判定する

    ll size(ll x){
        return -d[find(x)];
    }
    //xが属する木のsizeを返す

    ll group(){
        ll res = 0;
        for (auto p : d){
            if (p < 0){
                res++;
            }
        }
        return res;
    }
};

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

    ll n,m;
    cin >> n >> m;
    UnionFind uf(n);

    rep(i,m){
        ll a,b;
        cin >> a >> b;
        a--; b--;

        uf.unite(a,b);
    }

    ll x = uf.group();

    cout << x-1 << endl;

    
}

Measured memory_bytes: 3992
#include <iostream>
#include <string>
#include <functional>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <math.h>
#include <iomanip>
#include <map>

using namespace std;
using ll = long long;

int main()
{
	int h, w;
	cin >> h >> w;
	vector<string> mat(h);

	for (int i = 0; i < h; ++i)
	{
		cin >> mat[i];
	}
	map<char, int> m;
	
	for (int i = 0; i < h; ++i)
	{
		string s = mat[i];
		for (int j = 0; j < w; ++j)
		{
			m[s[j]] ++;
		}
	}

	map<int, int> amari;

	for (auto itr = m.begin(); itr != m.end(); itr++)
	{
		int cnt = itr->second;
		amari[cnt % 4]++;
	}

	amari[1] += amari[3];
	amari[2] += amari[3];

	if (amari[1] <= ((h % 2) * (w % 2)) && amari[2] <= ((h / 2) * (w % 2) + (w / 2) * (h % 2)))
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long sumHeight = 0;
long currentHeight = 0;
int main() {
  int N;
  cin >> N;
  vector<long> A(N);
  for (int i = 0; i < N; i++) cin >> A[i];
  for (int i = 0; i < N; i++) {
    if(currentHeight > A[i]) sumHeight += currentHeight - A[i];
    else currentHeight = max(currentHeight, A[i]);
  }
  cout << sumHeight << endl;
  return 0;
}


Measured memory_bytes: 4748
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> P;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
/*
vector<char>al(26);
al = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
vector<char>AL(26);
AL = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
vector<char>NUM(10);
	NUM = { '0','1','2' ,'3' ,'4' ,'5' ,'6' ,'7' ,'8' ,'9' };
*/



int main() {
	string s;
	cin >> s;
	lint Z = s.size();
	vector<lint>S(Z);
	rep(i, Z) {
		S[i] = char(s[Z-i-1] - '0');
	}
	lint cnt = 1;
	lint ans = 0;
	for (int T = 0; T < (1 << (Z - 1)); T++) {
		ans += S[0];
		for (int i = 1; i < Z; i++) {
			if ((((T >> (i - 1)) & 1) == 0)) {
				cnt=1;
			}
			else {
				cnt*=10;
			}
			ans+=(S[i]*cnt);
		}
		cnt = 1;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<queue>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstring>
using namespace std;
const int N=550;

typedef long long ll;
int mp[N][N], dp[N][N];

int main()
{
    memset(dp,0,sizeof(dp));
    int n,m,q;
    cin>>n>>m>>q;

    while(m--)
    {
        int a,b;
        cin>>a>>b;
        mp[a][b] ++;
    }

    for(int i=n; i>=1; i--)
        for(int j=i; j<=n; j++)
        {
            dp[i][j] = mp[i][j] + dp[i+1][j] + dp[i][j-1] - dp[i+1][j-1];
        }

    while(q--)
    {
        int a,b;
        cin>>a>>b;
        cout<<dp[a][b]<<endl;
    }
    return 0;
}

Measured memory_bytes: 3200
tf = [True] * 100001
tf[0] = tf[1] = True
for i in range(2, 320):
  if tf[i]:
    for j in range(i ** 2, 100001, i):
      tf[j] = False

tf2 = [False] * 100001
for i in range(3, 100001):
  if tf[i] and tf[(i + 1) // 2]:
    tf2[i] = True

count = []
acc = 0
for i in range(100001):
  acc += tf2[i]
  count.append(acc)

q = int(input())
for _ in range(q):
  l, r = map(int, input().split())
  print(count[r] - count[l - 1])

Measured memory_bytes: 8088
// created by mtnshh
 
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
 
#define ll long long
#define ld long double
 
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repb(i,a,b) for(ll i=a;i>=b;i--)
 
#define err() cout<<"=================================="<<endl;
#define errA(A) for(auto i:A)   cout<<i<<" ";cout<<endl;
#define err1(a) cout<<#a<<" "<<a<<endl
#define err2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl
#define err3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl
#define err4(a,b,c,d) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<" "<<#d<<" "<<d<<endl
 
#define pb push_back
#define all(A)  A.begin(),A.end()
#define allr(A)    A.rbegin(),A.rend()
#define ft first
#define sd second
 
#define pll pair<ll,ll>
#define V vector<ll>
#define S set<ll>
#define VV vector<V>
#define Vpll vector<pll>
 
#define endl "\n"
 
const ll logN = 20;
const ll M = 1000000007;
const ll INF = 1e12;
#define PI 3.14159265
 
const ll N = 100005;

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	ld l;
	cin>>l;
	ld v = (l/3)*(l/3)*(l/3);
	cout<<fixed<<setprecision(9)<<v<<endl;
    return 0;
}

Measured memory_bytes: 384
import java.util.Scanner
object Main {
  def main(args: Array[String])= {
    new Scanner(System.in).next() match{
      case "Sunny" => println("Cloudy")
      case "Cloudy" => println("Rainy")
      case "Rainy" => println("Sunny")
      case _ => println("unexpected")
    }
  }
}


Measured memory_bytes: 25268
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int N, X, Y, c, w, inv[200009], inf = 1012345678, mod = 1000000007; vector<int> g[200009];
int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	inv[1] = 1;
	for (int i = 2; i <= 200000; i++) inv[i] = 1LL * inv[mod % i] * (mod - mod / i) % mod;
	cin >> N >> X >> Y;
	for (int i = 0; i < N; i++) {
		cin >> c >> w;
		g[--c].push_back(w);
	}
	int cm = inf;
	for (int i = 0; i < N; i++) {
		if (g[i].size() == 0) continue;
		sort(g[i].begin(), g[i].end());
		for (int j = 1; j < g[i].size(); j++) {
			if (g[i][j] + g[i][0] <= X) g[i][j] = g[i][0];
		}
		cm = min(cm, g[i][0]);
	}
	vector<int> p;
	for (int i = 0; i < N; i++) {
		if (g[i].size() && cm + g[i][0] <= Y) p.push_back(i);
	}
	if (p.size() <= 1) cout << "1\n";
	else {
		vector<int> lm(p.size() + 1, inf), rm(p.size() + 1, inf);
		for (int i = 0; i < p.size(); i++) lm[i + 1] = g[p[i]][0], rm[i] = g[p[i]][0];
		for (int i = 0; i < p.size(); i++) lm[i + 1] = min(lm[i + 1], lm[i]);
		for (int i = p.size() - 1; i >= 0; i--) rm[i] = min(rm[i], rm[i + 1]);
		vector<int> cnt(p.size()); int sum = 0;
		for (int i = 0; i < p.size(); i++) {
			int sm = Y - min(lm[i], rm[i + 1]);
			for (int j = 0; j < g[p[i]].size(); j++) {
				if (g[p[i]][j] <= sm) cnt[i]++, sum++;
			}
		}
		int ret = 1;
		for (int i = 1; i <= sum; i++) ret = 1LL * ret * i % mod;
		for (int i = 0; i < p.size(); i++) {
			for (int j = 1; j <= cnt[i]; j++) ret = 1LL * ret * inv[j] % mod;
		}
		cout << ret << '\n';
	}
	return 0;
}

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

using namespace std;

int main() {
    int n, x, t;
    cin >> n >> x >> t;
    if(n%x == 0) {
        cout << (n/x) * t <<endl;
    } else {
        cout << (n/x + 1) * t<<endl;
    }
    return 0;
}

Measured memory_bytes: 3620
n, m = map(int, input().split())
a = [list(input()) for _ in range(n)]
b = [list(input()) for _ in range(m)]

ans = False
for i in range(n - m + 1):
    for j in range(n - m + 1):
        #check
        f = True
        for x in range(m):
            for y in range(m):
                if a[x + i][y + j] != b[x][y]:
                    f = False

        if f:
            ans = True

if ans:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3064
#include <stdio.h>
#include <string.h>

int main(void) {
  int n, i;
  char t[101], h[101];
  int taro = 0;
  int hanako = 0;
  int judge;
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%s %s", &t, &h);
    judge = strcmp(t, h);
    if (judge > 0) {
      taro += 3;
    } else if (judge < 0) {
      hanako += 3;
    } else {
      taro++;
      hanako++;
    }
  }
  printf("%d %d\n", taro, hanako);
  return 0;
}


Measured memory_bytes: 2028
n, k = list(map(int,input().split()))
d = []
aa = []
a = []

answer = n

for i in range(k):
  d0 = int(input())
  d.append(d0)
  a = list(map(int,input().split()))
  aa.extend(a)
  
for i in range(n):
  if aa.count(i + 1) > 0:
    answer -= 1
    
print(answer)

Measured memory_bytes: 9196
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 R = RD;
	auto G = RD;

	writeln((G * 2) - R);
	stdout.flush();
	debug readln();
}

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

int main() {
	int n,a;
	cin >> n;
	if (n / 10 == 9) {
		cout << "Yes\n";
		return 0;
	}
	a = n / 10;
	a = n - a * 10;
	if (a == 9) {
		cout << "Yes\n";
		return 0;
	}
	cout << "No\n";
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define NB 100001
int abs(int a) {
	if(a<0) return -a;
	return a;
}

ll tab[NB];

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	ll cur_max = 0;
	ll n,w;
	cin>>n>>w;
	ll weight, price;
	for(int t = 0; t < n; ++t) {
		cin>>weight>>price;
		for(ll i = NB - 1; i >= price; --i) {
			if(tab[i - price] != 0 || i == price) {
				if(tab[i] != 0){tab[i] = min(tab[i], tab[i - price] + weight);}
				else {tab[i] = weight + tab[i - price];}
				if(tab[i] <= w && tab[i] > 0) cur_max = max(cur_max, i);
			}
		}
	}/**
	for(int i = 0; i <= 140; ++i) {
		if(tab[i]!=0)cout<<"i : "<<i<<" "<<tab[i]<<"\n";
	}**/
	cout<<cur_max<<endl;
	return 0;
}


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

int N, p[200010];

inline bool check (int x) {
	int lt = 0;
	for (int i = 1; i <= 2 * N - 1; i++) {
		int r = i;
		while (r < 2 * N - 1 && (p[r + 1] >= x) == (p[i] >= x)) r++;
		if (r == i) continue;
		if (i <= N && r >= N) return p[i] >= x;
		if (r < N) { lt = i = r; continue; }
		if (i - N < N - lt) return p[i] >= x;
		else return p[lt] >= x;
	}
	if (lt) return p[lt] >= x;
	if (N & 1) return p[N] >= x;
	else return p[N] < x;
}

inline void solveB () {
	scanf ("%d", &N);
	for (int i = 1; i <= 2 * N - 1; i++) scanf ("%d", &p[i]);
	int l = 1, r = 2 * N - 1;
	while (l < r) {
		int mid = (l + r + 1) >> 1;
		if (check (mid)) l = mid;
		else r = mid - 1;
	}
	printf ("%d\n", l);
}

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

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

int divid2(int x){
    int y = 0;
    while(true){
        if(x%2 == 0){
            x = x/2;
            y ++;
        }
        else break;
    }
    return y;
}

int main(){

    int n;
    cin >> n;
    long long int a[n],ans = 0;
    for(int i=0;i<n;i++){
         cin >> a[i];
         ans += divid2(a[i]);
    }

    cout << ans << endl;

    

    return 0;
}

Measured memory_bytes: 384
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <ctype.h>

char O[51], E[51];
int main() {
  scanf("%s%*c", O);
  scanf("%s%*c", E);
  int lenO = strlen(O);
  int lenE = strlen(E);
  int i;
  int odd;
  if (lenE < lenO) odd = 1;
  else odd = 0;
  for (i = 0; i < lenO - 1; i++) {
    printf("%c", O[i]);
    printf("%c", E[i]);
  }
  printf("%c", O[lenO - 1]);
  if (!odd) {
    printf("%c", E[lenE - 1]);
  }
  printf("\n");
  return 0;
}


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

int main(){
  int a,b,ans;
  cin >> a >> b;
  if(a >=13){
    ans = b;
  }else if(a > 5){
    ans = b/2;
  }else{
    ans = 0;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll MOD = 1000000007;

#define vec              vector<int>
#define vecll            vector<ll>
#define vecd             vector<double>
#define vecst            vector<string>
#define vecb             vector<bool>
#define v2(v,n,m,init)   vector<vector<int>>  v(n, vector<int>(m, init))
#define vb2(v,n,m,init)  vector<vector<bool>> v(n, vector<bool>(m, init))
#define vll2(v,n,m,init) vector<vector<ll>>   v(n, vector<ll>(m, init))

#define rep(i,n)         for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n)       for(ll i=(ll)m; i<(ll)n; i++)
#define arr(var, n)      vec var(n); rep(i,n){cin >> var[i];}
#define arrll(var, n)    vecll var(n); rep(i,n){cin >> var[i];}
#define arrst(var, n)    vecst var(n); rep(i,n){cin >> var[i];}
#define all(var)         (var).begin(), (var).end()
#define sortall(var)     sort(all(var))
#define uniqueall(v)     v.erase(unique(v.begin(), v.end()), v.end());
#define pb(var)          push_back(var)
#define prt(var)         cout << (var) << "\n"
#define prtd(n, var)     cout << fixed << setprecision(n) << (var) << "\n"
#define prtfill(n, var)  cout << setw(n) << setfill('0') << (var);
#define prt2(v1, v2)     cout << (v1) << " " << (v2) << "\n"
#define prt3(v1, v2, v3) cout << (v1) << " " << (v2) << " " << (v3) << "\n"
#define prtall(v)        rep(i,v.size()){cout<<v[i]<<(i!=v.size()-1?" ":"\n");}
template <typename T>
bool chmax(T &a, const T& b){if(a<b){a=b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T& b){if(a>b){a=b; return true;} return false;}
//------------------------------------------------------------------

int main(void){
  string s;
  cin >> s;
  if(s[s.size()-1]=='s'){
    cout << s << "es";
  } else {
    cout << s << "s";
  }
}


Measured memory_bytes: 3624
n = int(input())
d = {}
for i in range(n):
    s = str(input())
    if s in d.keys():
        d[s] += 1
    else:
        d[s] = 1
max = max(d.values())
k = [x for x, y in d.items() if y ==max]
k.sort()
for i in k:
    print(i)

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

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var N = input[0];
            var M = input[1];

            var lMax = 1;
            var rMin = N;
            for (int i = 0; i < M; i++)
            {
                var LR = Console.ReadLine().Split().Select(int.Parse).ToArray();
                lMax = Math.Max(lMax, LR[0]);
                rMin = Math.Min(rMin, LR[1]);
            }

            Console.WriteLine(Math.Max(0, rMin - lMax + 1));
        }
    }
}


Measured memory_bytes: 41248
#include <bits/stdc++.h>
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--) // [a, b)
#define reprev(i,n) reprrev(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n==0) return 1;
    ll res=modpow(x, n/2);
    if(n%2==0) return res*res%mod;
    else return res*res%mod*x%mod;
}

ll power(ll x, ll n){
    if(n == 0) return 1;

    ll res = power(x, n/2);
    if(n%2 == 0) return res*res;
    else return res*res*x;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };

// 線分 ab の偏角 返り値は[-π, π]
double argument(const pair<double, double> &a, const pair<double, double> &b){
    double ax=a.first, ay=a.second, bx=b.first, by=b.second;
    return atan2(by-ay, bx-ax);
}

/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */


struct Edge {
    int to, id;
    Edge(int to, int id) :to(to), id(id) {}
};

vector<Edge> adj[55];

// now から goal までに含まれる辺の id を帰るときに edges_id に格納する
bool dfs(int now, int goal, int from, vector<int> & edges_id) {
    if (now == goal) return true;
    for(auto edge: adj[now]) {
        if (edge.to == from) continue;
        if (dfs(edge.to, goal, now, edges_id)) { edges_id.push_back(edge.id); return true; }
    }
    return false;
}


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

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

    int m; cin >> m;
    // u[i]-v[i] 上の辺の id を bit で管理する．
    vector<ll> bit_edges(m, 0);
    rep(i, m) {
        int a, b; cin >> a >> b; --a; --b;
        vector<int> edges_id;
        dfs(a, b, -1, edges_id);
        for(auto id: edges_id) bit_edges[i] |= 1LL<<id;
    }

    ll ans = 0;
    rep(bit, 1<<m) {
        ll mask = 0;
        rep(i, m) if (bit>>i&1) mask |= bit_edges[i];
        int white = __builtin_popcountll(mask);
        ll val = 1LL<<(n-1-white);

        if (__builtin_popcount(bit)%2==0) ans += val;
        else ans -= val;
    }
    cout << ans << endl;
    
    return 0;
}



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

struct UnionFindTree {
    vector<int> par;
    vector<int> rank;
    vector<int> siz;
    int cnt;

    void init(int n) {
        cnt = n;
        par.resize(n);
        rank.resize(n);
        siz.resize(n);
        for (int i = 0; i < n; i++) {
            par[i] = i;
            rank[i] = 0;
            siz[i] = 1;
        }
    }
    int find(int x) {
        if (par[x] == x) {
            return x;
        } else {
            return par[x] = find(par[x]);
        }
    }
    void unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y) return;
        if (rank[x] < rank[y]) swap(x, y);
        if (rank[x] == rank[y]) rank[x]++;
        par[y] = x;
        siz[x] += siz[y];
        cnt--;
    }
    bool is_same(int x, int y) {
        return find(x) == find(y);
    }
    int size(int x) {
        x = find(x);
        return siz[x];
    }
};

int main(){
    ll n, m, q;
    cin >> n >> m >> q;
    UnionFindTree uf;
    uf.init(n);
    set<P> ls;
    for(int i=0;i<q;i++){
        int a, b, c;
        cin >> a >> b >> c;
        if(c) ls.insert(P(a,b));
        else uf.unite(a, b);
    }
    bool ok = true;
    if(ls.size() > 0 && m == n-1) ok = false;
    for(auto p : ls){
        int a = p.first, b = p.second;
        a = uf.find(a);
        b = uf.find(b);
        if(a > b) swap(a,b);
        if(uf.is_same(a,b)) ok = false;
    }
    ok &= m <= n-uf.cnt + ll(uf.cnt-1)*uf.cnt/2;
    cout << (ok ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 7680
N=int(input())
for h in range(1,3501):
  if 4*h-N!=0:
    n=(N*h)//(4*h-N)+1
    if 4*h*n-N*(h+n)>0 and (N*h*n)%(4*h*n-N*(h+n))==0:
      w=(N*h*n)//(4*h*n-N*(h+n))
      break
print(h,n,w)

Measured memory_bytes: 3064
n, k = gets.split.map(&:to_i)
sum = 0
c = []
j = 1
c[1] = 1
while j < k
  j *= 2
  c[1] *= 2
end
sum += 1

for i in 2..n do
  j = i
  c[i] = 1
  while j < k
    j *= 2
    c[i] *= 2
  end
  sum += c[1] / c[i]
end
puts sum.to_f / (c[1] * n).to_f


Measured memory_bytes: 2632
p = int(input().split()[1])
s = input()
if 10 % p == 0:
  r = sum(i for i, x in enumerate(s, 1) if int(x) % p == 0)
else:
  d = [1] + [0] * (p - 1)
  t, y = 0, 1
  for x in reversed(s):
    t = (t + int(x) * y) % p
    d[t] += 1
    y = y * 10 % p;
  r = sum(i * i - i for i in d) // 2
print(r)

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

typedef long long ll;

int main(){
  ll n;
  cin >> n;
  ll a[n],b[n];
  for(int i=0;i<n;i++) cin >> a[i] >> b[i];
  ll ans=0;
  for(int i=n-1;i>=0;i--){
    if((a[i]+ans)%b[i]!=0){
      ans+=b[i]-(a[i]+ans)%b[i];
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define req(i,n) for(int i = 1;i <=n;i++)
#define pai 3.14159265358979323846
const int INF = 1001001001;
typedef long long ll;
int A[3][3], N;
bool punched[3][3];
bool ok[3][3];
using Graph = vector<vector<int>>;
vector<vector<int>> field;
vector<bool> seen;

const int MOD = 1000000007;
typedef pair<int,int> P;

//最大公約数
int gcd(int a,int b){
	if (a%b == 0){
		return b;
	}
	else{
		return gcd(b,a%b);
	}

}

//最小公倍数
int lcm(int a,int b){
	return a /gcd(a,b) * b;
}

//素数判定
bool is_prime(long long N) {
    if (N == 1) return false;
    for (long long i = 2; i * i <= N; ++i) {
        if (N % i == 0) return false;
    }
    return true;
}

// 素因数分解
vector<pair<long long, long long> > prime_factorize(long long n) {
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

// 10進数から2進数
int binary(int bina){
    int ans = 0;
    for (int i = 0; bina>0 ; i++)
    {
        ans = ans+(bina%2)*pow(10,i);
        bina = bina/2;
    }
    return ans;
}




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

int main() {
    int N; cin >> N;
    vector<long long> a(N);
    for (int i = 0; i < N; ++i) cin >> a[i];
    int num_minus = 0;
    long long mi = 1LL<<60;
    long long sum = 0;
    for (int i = 0; i < N; ++i) {
        if (a[i] < 0) ++num_minus;
        chmin(mi, abs(a[i]));
        sum += abs(a[i]);
    }
    if (num_minus % 2 == 0) cout << sum << endl;
    else cout << sum - mi*2 << endl;
}

Measured memory_bytes: 4048
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 998244353;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  vector<vector<ll>> dp(c+1, vector<ll>(d+1));
  dp[a][b] = 1;
  for(int i=a; i<=c; i++) {
    for(int j=b; j<=d; j++) {
      if(i==a&&j==b) continue;
      else if(i==a) (dp[i][j] = dp[i][j-1]*i%mod) %= mod;
      else if(j==b) (dp[i][j] = dp[i-1][j]*j%mod) %= mod;
      else (dp[i][j] = mod + dp[i-1][j]*j%mod + dp[i][j-1]*i%mod - dp[i-1][j-1]*(i-1)*(j-1)%mod) %= mod;
    }
  }
  cout << dp[c][d] << "\n";
  return 0;
}


Measured memory_bytes: 73632
N, K = map(int, input().split())
mod = 10 ** 9 + 7
factl = [1]
for i in range(1, N + 1):
	factl.append(factl[-1] * i % mod)
invl = [pow(factl[-1], mod - 2, mod)]
for i in range(N, 0, -1):
	invl.append(invl[-1] * i % mod)
invl.reverse()

def Comb(a, b):
	return factl[a] * invl[a - b] * invl[b] % mod

M = N - K
for i in range(1, K + 1):
	if M<i-1:
		print(0)
		continue
	print(Comb(K-1,i-1)*Comb(M+1,M-i+1)%mod)

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

// #define int long long
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

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

#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef pair<int, int> pii;
typedef double D;
typedef complex<D> P;
typedef vector<string> vs;

#define SZ(x) ((int)(x).size())

#define fill(x,y) memset(x,y,sizeof(x))

// with compile option -DLOCAL
#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

#define pcnt __builtin_popcount
#define pcntll __builtin_popcountll

#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)
#define F first
#define S second

#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev

inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;}

int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a;a=1ll*a*a;}while(b>>=1);return ans;}
int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};



#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

const int MOD = 1e9 + 7;
const int INF = INT_MAX;

signed main() {
    Fast();


    int n, m;

    vector<pii> pref[100001];
    
    cin >> n >> m;

    rep(m){
        int p, y;
        cin >> p >> y;
        pref[p - 1].eb(y, i);
    }
    
    pii* ans = new pii[100001];
    rep(n){
        sort(all(pref[i]));
        
        for(int j=0; j<SZ(pref[i]); j++) {
            ans[pref[i][j].S] = pii(i, j);
        }
        
    }

    rep(m) {
        printf("%06d%06d\n", ans[i].F + 1, ans[i].S + 1);
    }
    
    return 0;
}



Measured memory_bytes: 7808
N,K=map(int,input().split())
grid = []
for i in range(N):
    array = list(map(int, input().strip().split(' ')))
    grid.append(array)
dic = {}
for lis in grid:
  if lis[0] in dic:
    dic[lis[0]] += lis[1]
  else:
    dic[lis[0]] = lis[1]
dic = sorted(dic.items())
num = 0
for li in dic:
  num += li[1]
  if num >= K:
    print(li[0])
    break

Measured memory_bytes: 35788
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>

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

typedef long long ll;

using namespace std;

vector< pair<ll, ll> > ar;
ll N, K;

int main()
{
    cin >> N >> K;
    REP(i, N) {
        ll a, b;
        cin >> a >> b;
        ar.push_back(make_pair(a, b));
    }
    sort(ar.begin(), ar.end());
    ll ret = 0;
    for(ll i=0; i<=N; ++i) {
        ret += ar[i].second;
        if(ret >= K){
            printf("%lld\n", ar[i].first);
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 2420
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
	
typedef long long ll;
int main(){
	int N,A,B;
	cin>>N;
	if (N==1){
		cout<<"Hello World"<<endl;
	}else{
		cin>>A>>B;
		cout<<A+B<<endl;
	}
	return 0;
}

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

int main(){
  int n, ans = 0;
  cin >> n;
  vector<int> a(n);
  rep(i, n, 0) cin >> a.at(i);
  
  rep(i, n-1, 1){
    if(a.at(i-1) > a.at(i) && a.at(i) > a.at(i+1)) ans++;
    else if(a.at(i-1) < a.at(i) && a.at(i) < a.at(i+1)) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
template<typename T>inline void read(T &x){
	register short f=1;x=0;char c=getchar();
	while(!isdigit(c)){ if(c=='-')f=-1;c=getchar();}
	while(isdigit(c))x=(x<<3)+(x<<1)+(c^48),c=getchar();
	x*=f;
}
template<typename T>inline void write(T x){
	if(x<0)putchar('-'),x=-x;
	if(x>9)write(x/10);
	putchar(x%10+'0');
}
template<typename T>inline void writeln(T x){
	write(x),putchar('\n');
}
int main(){
//	freopen(".txt","w",stdout);
	int h,w;
	read(h),read(w);
	for(int i=1;i<=h;i++){
		string s;cin>>s;
		cout<<s<<endl<<s<<endl;
	}
	return 0;
}


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

using namespace std;

int main(){
    string s, t;
    cin>>s>>t;
    int ans=0;
    for(int i=0;i<3;i++){
        if(s[i]==t[i]){
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<typename T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<typename T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef tuple<ll,ll,ll> tlll;
typedef tuple<int,int,int> tiii;
const ll mod=1e9+7;
const int inf=1<<30;

int main(){
  int n; cin >> n;
  vector<vector<ll> > a(n,vector<ll>(n));
  rep(i,n)rep(j,n) cin >> a[i][j];
  rep(k,n)rep(i,n)rep(j,n){
    if(a[i][j]>a[i][k]+a[k][j]){
      cout << -1 << endl;
      return 0;
    }
  }
  rep(k,n)rep(i,n)rep(j,n){
    if(k!=i&&i!=j&&j!=k&&a[i][j]==a[i][k]+a[k][j]){
      a[i][j]=inf;
    }
  }
  ll ans=0;
  rep(i,n)rep(j,n)if(i<j&&a[i][j]!=inf) ans+=a[i][j];
  cout << ans << endl;
}

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

using namespace std;
using ll = long long;
const ll MOD = 1e9+7;

bool pairCompare(const pair<string, ll>& firstElof, const pair<string, ll>& secondElof)
{
    if(firstElof.first != secondElof.first){
        return firstElof.first < secondElof.first;
    }else{
        return firstElof.second > secondElof.second;
    }
}

int main() {
    ll n;
    cin >> n;

    vector<pair<string, ll>> v;
    vector<pair<string, ll>> d;

    for (int i = 0; i < n; ++i) {
        string ts;
        ll tp;
        cin >> ts >> tp;
        v.push_back(make_pair(ts, tp));
        d.push_back(make_pair(ts, tp));
    }

    sort(v.begin(), v.end(), pairCompare);

//    for (auto itr: v) {
//        cout << itr.first << itr.second << endl;
//    }

    for (int i = 0; i < n; ++i) {
        auto res = find(d.begin(), d.end(), make_pair(v.at(i).first, v.at(i).second));
        cout << distance(d.begin(), res) + 1 << endl;
    }
    return 0;
}


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

int main() {
    int N, T;
    cin >> N >> T;
    vector<pair<int, int>> l (N);
    for (int i = 0; i < N; i++) {
        int A, B;
        cin >> A >> B;
        l.at(i) = make_pair(A, B);
    }
    sort(l.begin(), l.end());
    int i = 0;
    while (i < N) {
        if (l.at(i).second <= T) {
            cout << l.at(i).first << endl;
            break;
        }
        i++;
    }
    if (i == N) {
        cout << "TLE" << endl;
    }
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
int main()
{
	int h, w, mi = 100000000;
	scanf("%d %d", &h, &w);
	int a, b, c;
	a = w / 3;
	b = (w - a) / 2;
	mi = min(mi, (w - a - b - a) * h);
	b = w - a;
	c = h / 2;
	mi = min(mi, max(max(b * c, b * (h - c)), a * h) - min(min(b * c, b * (h - c)), a * h));
	a = w / 3 + 1;
	b = w - a;
	mi = min(mi, max(max(b * c, b * (h - c)), a * h) - min(min(b * c, b * (h - c)), a * h));
	a = w / 3 + 2;
	b = w - a;
	mi = min(mi, max(max(b * c, b * (h - c)), a * h) - min(min(b * c, b * (h - c)), a * h));
	a = h / 3;
	b = (h - a) / 2;
	mi = min(mi, (h - a - b - a) * w);
	b = h - a;
	c = w / 2;
	mi = min(mi, max(max(b * c, b * (w - c)), w * a) -  min(min(b * c, b * (w - c)), w * a));
	a = h / 3 + 1;
	b = h - a;
	c = w / 2;
	mi = min(mi, max(max(b * c, b * (w - c)), w * a) - min(min(b * c, b * (w - c)), w * a));
	a = h / 3 + 2;
	b = h - a;
	c = w / 2;
	mi = min(mi, max(max(b * c, b * (w - c)), w * a) -  min(min(b * c, b * (w - c)), w * a));
	printf("%d\n", mi);
}


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

public class Solution
{
    public static void Main()
    {
        var N = int.Parse(Console.ReadLine());
        var W = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

        var min = int.MaxValue;
        for (int i = 1; i < N; i++)
        {
            var diff = Math.Abs(W.Take(i).Sum() - W.Skip(i).Sum());
            min = Math.Min(diff, min);
        }
        
        Console.WriteLine(min);
    }
}

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

int main() {
    string w; cin >> w;
    unordered_map<char,int> cnt;
    for (const auto& i : w) {
        cnt[i]++;
    }
    bool ans = true;
    for (const auto& i : cnt) {
        if (i.second % 2 == 1) ans = false;
    }
    if (ans) printf("Yes");
    else printf("No");
}

Measured memory_bytes: 3624
{-# LANGUAGE BangPatterns #-}
import Control.Arrow
import Control.Applicative
import Control.Monad.Fix
import Control.Monad.ST
import Data.Int
import Data.Foldable
import Data.List
import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as VU
import qualified Data.ByteString.Char8 as B
import Debug.Trace

solve :: Int -> VU.Vector Int -> Bool
solve !n !an = VU.all even an

main = do
  let readInt :: Integral a => B.ByteString -> Maybe (a, B.ByteString)
      readInt = fmap (first fromIntegral . second B.tail) . B.readInt

  n  <- (\vec -> vec VU.! 0) . VU.unfoldrN 1 readInt <$> B.getLine
  an <-
    VU.replicateM n $ (\vec -> vec VU.! 0) . VU.unfoldrN 1 readInt <$> B.getLine
  putStrLn $ if solve n an then "second" else "first"


Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
  ll A, B, V, W, T;
  cin >> A >> V;
  cin >> B >> W;
  cin >> T;
  if (V > W && abs(A - B) <= T * (V - W)) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  return 0;
}


Measured memory_bytes: 3612
import sys

stdin = sys.stdin
 
ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))
rs = lambda: stdin.readline().rstrip()  # ignore trailing spaces

X = ri()
q, r = divmod(X, 100)
bool = True
if q * 5 < r:
    bool = False
print(1 if bool else 0)



Measured memory_bytes: 3060
#include <iostream>
#include <unordered_map>

using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	int n;
	cin >> n;
	unordered_map<int, int> a, b;
	for (int i = 1; i <= n; i++) {
		int t;
		cin >> t;
		a[i + t]++;
		if (i - t > 0) b[i - t]++;
	}
	long long res = 0;
	for (auto& i : a) {
		int c = i.second;
		int d = b[i.first];
		res += (long long)c * (long long)d;
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 19964
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int n, k,x,y,a,b,c,ans;
	scanf("%d%d", &n, &k);
	
	for (int i = 0; i < k; i++)
	{
		scanf("%d%d", &x, &y);
		a = min(x, n - x + 1);
		b = min(y, n - y + 1);
		c = min(a, b);
		ans = c % 3;
		if (ans == 0)
			ans = 3;
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 3148
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-8;

//int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;


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

	cin >> N;
	vector<int>v(N);
	priority_queue<pair<int, int>>PQ;
	vector<int>used(N);
	for (auto &i : v) {
		cin >> i;
		i--;
		used[i]++;
	}
	for (int i = 0; i < N; i++) {
		PQ.push({ used[i],i });
	}
	if (N == 2) {
		cout << -1 << endl;
		return 0;
	}
	if (N == 3) {
		vector<int>p(N);
		for (int i = 0; i < N; i++) {
			p[i] = i;
		}
		do {
			bool flag = true;
			for (int i = 0; i + 1 < N; i++) {
				if (v[p[i]] == p[i + 1])flag = false;
			}
			if (flag) {
				for (auto i : p)cout << i + 1 << " ";
				cout << endl;
				return 0;
			}
		} while (next_permutation(p.begin(), p.end()));
		cout << -1 << endl;
		return 0;
	}
	vector<int>ans;
	set<int>s;
	for (int i = 0; i < N; i++)s.insert(i);
	int nx = -1;
	vector<int>er(N);
	while (s.size() > 4) {
		while (er[PQ.top().second])PQ.pop();
		while (PQ.top().first != used[PQ.top().second]) {
			PQ.push({ used[PQ.top().second],PQ.top().second });
			PQ.pop();
		}
		if (PQ.top().first + 1 == s.size()) {
			ans.push_back(PQ.top().second);
			nx = v[PQ.top().second];
			used[nx]--;
			s.erase(PQ.top().second);
			PQ.pop();
			continue;
		}
		auto it = s.begin();
		if (nx == *it)it++;
		ans.push_back(*it);
		nx = v[*it];
		used[nx]--;
		er[*it] = 1;
		s.erase(it);
	}
	//for (auto i : ans)cout << i + 1 << endl;
	vector<int>p;
	for (auto i : s) {
		p.push_back(i);
	}
	do {
		bool flag = true;
		int cnx = nx;
		for (int i = 0; i < 4; i++) {
			if (cnx == p[i])flag = false;
			cnx = v[p[i]];
		}
		if (flag) {
			for (auto i : p)ans.push_back(i);
			for (auto i : ans)cout << i + 1 << " ";
			cout << endl;
			return 0;
		}
	} while (next_permutation(p.begin(), p.end()));
	cout << -1 << endl;
	return 0;
}

Measured memory_bytes: 7540
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

int gcd(int a, int b) {
  return b == 0 ? a : gcd(b, a % b);
}

int lcm(int a, int b) {
  return a / gcd(a, b) * b;
}

int main() {
#ifdef DEBUG
  ifstream ifs("in.txt");
  cin.rdbuf(ifs.rdbuf());
#endif
  int X;
  while (cin >> X) {
    int res = lcm(X, 360) / X;
    cout << res << endl;
  }
  return 0;
}


Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
long long n,m,fac[100005];
int main()
{
	fac[0]=1;
	for(int i=1;i<=100000;i++)
	{
		fac[i]=fac[i-1]*i;
		fac[i]%=1000000007;
	}
	scanf("%lld%lld",&n,&m);
	if(abs(m-n)==1)
	{
		printf("%lld\n",(fac[n]*fac[m])%1000000007);
	}else if(abs(m-n)==0)
	{
		printf("%lld\n",(fac[n]*fac[m]*2)%1000000007);
	}else
	{
		printf("0\n");
	}
}

Measured memory_bytes: 4500
import math
def main():
  A,B=map(int, input().split())
  for i in range(math.ceil(A/0.08),math.ceil((A+1)/0.08)):
    if i in list(range(math.ceil(B/0.1),math.ceil((B+1)/0.1))):
      print(i)
      return
  print(-1)
  return
  
  
  
main()

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

int gcd(int a, int b) {
    if(a%b == 0)    return b;
    return gcd(b, a%b);
}

int main(void) {
    int N, ans;
    cin >> N;
    vector<int> A;
    for(int i = 0; i < N; i++) {
        int tmp;
        cin >> tmp;
        A.push_back(tmp);
    }
    ans = A.back();
    A.pop_back();
    for(auto v : A) {
        ans = gcd(max(ans, v), min(ans, v));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 892
#include <iostream>

using namespace std;

int main() {
    int A, B, C, X;
    cin >> A >> B >> C >> X;
    int count = 0;
    for (int a = 0; a <= A; ++a) {
        for (int b = 0; b <= B; ++b) {
            for (int c = 0; c <= C; ++c) {
                int total = 500 * a + 100 * b + 50 * c;
                if (total == X) count++;
            }
        }
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 256
// "for if God is with them who can be against them."
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define endl '\n'
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define all(a) a.begin(),a.end()
#define watch(x) cout << (#x) << " is " << (x) << endl
int ans = 0;
int cnt[400004];
void solve() {
	int a[6], ans;
	for (int i = 1; i <= 5; i++) {
		cin >> a[i];
		if (a[i] != i) {
			ans = i;
		}
	}
	cout << ans;
}
int main() {
#ifndef ONLINE_JUDGE
	freopen("input1.txt", "r", stdin);
	freopen("output1.txt", "w", stdout);
#endif
	IOS;
	int t = 1;
	//cin >> t;
	while (t--) {
		solve();
	}


#ifndef ONLINE_JUDGE
	cout << "\nTime Elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " sec\n";
#endif
	return 0;
}

Measured memory_bytes: 3576
#include <bits/stdc++.h>
using namespace std;
int main() {
    int k,x;
    cin >> k >> x;
    int i = x-k+1;
    while ((x-k<i)&&(i<x+k)){
        cout << i;
        if (i != x+k-1) cout << " ";
        i++;
    }
    cout << "\n";
}

Measured memory_bytes: 256
#include<iostream>
#include<sstream>
#include<vector>
#include<algorithm>
#include<string>
#include<stdexcept>
#include<stdio.h>
#include<queue>
using namespace std;
 int main(){
   int x; cin >> x;
   if(x==3 || x==5 || x==7) cout <<"YES"<<endl;
   else cout<<"NO"<<endl;
 }

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

long euclid_gcd(long a, long b){
    long r;
    while(true){
        r = a%b;
        if (r==0){break;}
        a = b;
        b = r;
    }
    return b;
}

int main(void){
    int n;
    cin >> n;
    long a[n+5];
    for (int i = 0; i < n; ++i){
        cin >> a[i];
    }

    sort(a, a + n, greater<int>());
    long result = a[0];
    for (int i = 0; i < n; ++i){
        result = euclid_gcd(result, a[i]);
    }
    cout << result << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define x first
#define y second
#define pb push_back
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const double PI  = acos(-1.0);
const double eps = 1e-8;
const int inf = 0x3f3f3f3f;
const LL INF  = 0x3f3f3f3f3f3f3f3f;
const int N=3e5+10;
const int M=1e6+10;
const int mod=1e9+7;
inline LL gcd(LL a, LL b) { return b ? gcd(b, a % b) : a; }
inline LL lcm(LL a, LL b) { return a * b / gcd(a, b); }
inline LL read(){LL x=0,f=1;char c=getchar();while(c<'0'||c>'9') {if(c=='-')f=-1;c=getchar();}while(c>='0'&&c<='9') {x=x*10+c-'0';c=getchar();}return x*f;}
inline LL qpow(LL x,LL k=mod-2,LL m=mod){LL res=1;while(k){if(k&1) res=res*x%m;x=x*x%m;k>>=1;}return res;}
/*=================================================================================================================*/
LL n,x,m;
map<LL,int> mp;
vector<LL> vec;

int main(){
    cin>>n>>x>>m;
    LL now=x;mp[now]=1;
    while(1){
        now=now*now%m;mp[now]++;
        if(mp[now]==2) break;
    }
    vec.push_back(now);
    while(1){
        now=now*now%m;mp[now]++;
        if(mp[now]==3) break;
        vec.push_back(now);
    }
    if(n<=mp.size()){
        LL ans=now=x;
        for(int i=2;i<=n;i++){
            now=now*now%m;
            ans+=now;
        }
        cout<<ans<<endl;
    }
    else{
        LL ans=now=x;
        for(int i=2;i<=mp.size();i++){
            now=now*now%m;
            ans+=now;
        }
        n-=mp.size();
        LL sum=0;
        for(int i=0;i<vec.size();i++) sum+=vec[i];
        ans+=sum*(n/vec.size());
        for(int i=0;i<n%vec.size();i++) ans+=vec[i];
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 6940
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <memory.h>
#include <math.h>
#include <string>
#include <stdlib.h>
#include <iomanip>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define mset(a, b) memset(a, b, sizeof(a))
#define LL long long
#define P pair<int, int>
#define PLL pair<LL, LL>
const int MAX = 1e5 +5;
const int inf = 0x3f3f3f3f;
using namespace std;

int main()
{
    int n, k;
    cin >> n >> k;
    int tot = (n-1) *(n-2) / 2;
    if(k > tot){
        cout << "-1" << endl;
        return 0;
    }
    int m = tot - k;
    printf("%d\n", n-1+m);
    for(int i = 2; i <= n; i++){
        printf("%d %d\n", 1, i);
    }
    for(int i = 2; i <= n && m; i++){
        for(int j = i+1; j <= n && m; j++){
            printf("%d %d\n", i, j);
            m--;
        }
    }

    return 0;
}


Measured memory_bytes: 256