akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
#define int long long
#define INF 1000000000000000
using namespace std;

typedef vector<int> vec;
typedef vector<vec> mat;
typedef pair<int, int> Pii;

template<typename T>
void readvec(vector<T> &a);
void readindex(vector<int> &a);

void process(vec &a, int N){
    int imax, m = -1;
    REP(i, N){
        if(a[i] > m){
            m = a[i];
            imax = i;
        }
    }
    a[imax] -= (N + 1);
    REP(i, N) a[i]++;
}

signed main(){

    int K; cin >> K;
    if(K == 0){
        cout << 2 << endl;
        cout << 0 << " " << 0;
        return 0;
    }
    int N = 50;
    int a = K / N + min((int)1, K % N);
    int b = a * N - K;
    vec ans(N);
    REP(i, N) ans[i] = i + a;
    REP(i, b) process(ans, N);

    cout << N << endl;
    REP(i, N) cout << ans[i] << " ";
    
    return 0;
}


template<typename T>
void readvec(vector<T> &a){
    REP(i, a.size()){
        cin >> a[i];
    }
}
void readindex(vector<int> &a){
    REP(i, a.size()){
        cin >> a[i];
        a[i]--;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <string.h>
#include <math.h>
#include <cmath>
#include <vector>
#include <algorithm>

#define ll long long

using namespace std;

const long long mod = 1e9 + 7;

int main() {
    int a, b;
    cin >> a >> b;
    cout << max(a+b, max(a-b, a*b)) << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <stack>
#include <functional>
#include <set>
#include <map>
#include <deque>
#include <cmath>
#define WMAX 10000
#define HMAX 10000
#define NMAX 102
//コメントアウトするとdebug()を実行しない
// #define DEBUG

using namespace std;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

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

struct edge{
  int to,cost;
};

int C,N,W,H,ans[2],dp[9];
string S;
static const int dx[8] = {0,1,1,1,0,-1,-1,-1},
					dy[8] = {1,1,0,-1,-1,-1,0,1};
int A[NMAX] ;
void solve(){
	for (int i = 0; i < N; ++i)
	{
		if(A[i]/400 < 8){
			dp[A[i]/400]++;
		}else{
			dp[8]++;
		}
	}
	for (int i = 0; i < 8; ++i)
	{
		if(dp[i]){
			ans[0]++;
		}
	}
	ans[1] = ans[0] + dp[8];
	if(!ans[0]){
		ans[0] = 1;
	}
}

void debug(){
	for (int i = 0; i < 9; ++i)
	{
		cout << dp[i] << " ";
	}
	cout << endl;
}

void answer(){
	cout << ans[0] << " " << ans[1] << endl;
}

int main(){
	cin >> N;
	for (int i = 0; i < N; ++i)
	{
		cin >> A[i];
	}
	solve();
	#ifdef DEBUG
	debug();
	#endif
	answer();

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp> 
// using namespace __gnu_pbds;
#define ordered_set tree<pair<int,int>, null_type,less<pair<int,int> >, rb_tree_tag,tree_order_statistics_node_update>
#define standardVar ll n,m,i,j,k,num,num1,num2,flag=0
#define nn <<"\n"
#define __ <<" "<<
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define ittr(x,v) for(auto x=v.begin();x!=v.end();x++)
#define itr(x,n) for(x=0;x<n;x++)
#define itrab(x,a,b) for(x=a;x<b;x++)
#define itpr(v) ittr(x,v)cout<<*x<<" "; cout nn
#define itppr(v) ittr(x,v)cout<<(*x).ff<<" "<<(*x).ss<<"  "; cout nn
#define size(x) (ll)x.size()
#define pi 3.14159265359
#define dTor(x) ((x)*pi)/180.0
#define INF 1000000100;

typedef long long int ll;       //TYPEDEFS
typedef long double ld;
typedef vector<ll> vl;
typedef map<ll,ll> ml;
typedef set<ll> sl;
typedef string str;
typedef pair<ll, ll> pl;
typedef vector< pl > vpl;
typedef map<pl,ll> mpl;
typedef set< pl > spl;
typedef vector<str> vst;
typedef vector<vl> vvl;

const ll M=1000000007;          //COMMON MODULO PRIMES
const ll N=998244353;

ll power(ll x, ll y, ll p){     //MODULAR EXPONENTIATION
    ll res=1;
    x=x%p;
    if(x==0)
        return 0;
    while(y>0){
        if(y&1)
            res=(res*x)%p;
        y=y>>1;
        x=(x*x)%p;
    }
    return res;
}
ll inv(ll x, ll m){             //FERMAT INVERSE
    return power(x,m-2,m);
}
struct comp{                    //COMPARISON ON PAIRS
    template<typename T>        
    bool operator()(const T &a, const T &b){
        if (a.ff==b.ff)
            return (a.ss<b.ss);
        else
            return (a.ff<b.ff);
    }
};
bool mod(const pair<ll,ll> &a, const pair<ll,ll> &b){   //COMPARATOR FOR PAIRS (SORTING)
    if(a.ff!=b.ff)
        return (a.ff>b.ff);
    else
        return (a.ss>b.ss);
}
vector<bool> pr(1000000+1,1);
void sieve(ll mn, ll mx){       //SIEVE OF ERATOSTHENES
    for(ll i=mn;i*i<=mx;i++)
        if(pr[i-mn]==1)
            for(ll j=i*i;j<=mx;j+=i)
                pr[j-mn]=0;
}
bool isValid(ll i, ll j, ll n, ll m){   //CHECKS FOR OVERFLOW
    if(i>=0&&i<n&&j>=0&&j<m){
        return true;
    }
    return false;
}

//MAIN FUNCTION STARTS HERE

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    standardVar;
    ll x;
    cin>>x>>n;
    sl s;
    for(i=0;i<=101;i++){
        s.insert(i);
    }
    itr(i,n){
        cin>>num;
        s.erase(num);
    }
    //itpr(s);
    auto it1=s.lower_bound(x);
    ll p=*it1;
    --it1;
    ll q=*it1;
    if(abs(x-p)<abs(x-q))
        cout<<p nn;
    else
        cout<<q nn;
    return 0;
}

Measured memory_bytes: 3784
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
using namespace std;

int main() {
        int n;
        long long k;
        scanf("%d%lld", &n, &k);
        vector<pair<long long, long long>> fl(n);
        for (int i = 0; i < n; i ++) {
                scanf("%lld%lld", &fl[i].first, &fl[i].second);
        }
        long long lb = 0, ub = 2LL * 1e18 + 1;
        while (ub - lb > 1) {
                long long x = (lb + ub) / 2;
                long long cnt = 0;
                for (int i = 0; i < n; i ++) {
                        if (fl[i].first > x) continue;
                        long long get = (x - fl[i].first + fl[i].second - 1) / fl[i].second;
                        cnt += get;
                }
                if (cnt > k - 1) ub = x;
                else lb = x;
        }
        printf("%lld\n", lb);
        return 0;
}



Measured memory_bytes: 1920
#include<stdio.h>
//#include<math.h>
int main()
{
  long int i,n;
  scanf("%ld",&n);
  long int a[n],b[n],m[n];
  long int asum = 0;
  long int bsum = 0;
  long int difs = 0;
  for(i=0;i<n;i++) {
    scanf("%ld",&a[i]);
    asum += a[i];
  }
  for(i=0;i<n;i++) {
    scanf("%ld",&b[i]);
    bsum += b[i];
    if (b[i]>a[i]) {
      difs += (b[i]-a[i]+1)/2;
    }
  }
  if(bsum>=asum) {
    if (difs <= bsum-asum) {
      printf("Yes\n");
    } else {
      printf("No\n");
    }
  } else {
    printf("No\n");
  }
}


Measured memory_bytes: 256
n = int(input())
A = list(map(int,input().split()))
q = int(input())
M = list(map(int,input().split()))

def solve(i,m):
  if m == 0:
    return True
  if i >= n or m < 0:
    return False
  if sum(A[i:]) < m:
    return False
  res =  solve(i+1, m) or solve(i+1, m-A[i])
  return res

ans = [solve(0,m) for m in M]
for a in ans:
  print('yes') if a else print('no')


Measured memory_bytes: 5628
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

const int N=5005,mo=1e9+7;

typedef long long LL;

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

char S[N];

int main()
{
	scanf("%d%s",&n,S); m=strlen(S);
	f[0][0]=1;
	for (int i=1;i<=n;i++)
	{
		f[i][0]=(f[i-1][0]+f[i-1][1]*2ll)%mo;
		for (int j=1;j<=i;j++) f[i][j]=(f[i-1][j-1]+f[i-1][j+1]*2ll)%mo;
	}
	printf("%d\n",f[n][m]);
	return 0;
}

Measured memory_bytes: 96384
#include<stdio.h>

int main(void){

   int a,b;

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

   if(a<b)
       printf("a < b\n");
   else if(a>b)
       printf("a > b\n");
   else
	   printf("a == b\n");


   return 0;

}

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

using namespace std;
 
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  if(s[2]==s[3] && s[4]==s[5]) {
    cout<<"Yes\n";
  } else {
    cout << "No\n";
  }
  return 0;
}


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

using namespace std;

const int N = 1e6 + 6;

long long a[N];

int main() {
  int n;
  scanf("%d", &n);
  long long sum = 0;
  for (int i = 0;i < n; i++) {
    scanf("%lld", a+i);
    sum += a[i];
  }
  long long cur = 0;
  long long ans = 0;
  for (int i = 0; i < n-1; i++) {
    cur += a[i];
    sum -= a[i];
    if (i == 0)
      ans = abs(cur-sum);
    else
      ans = min(ans, abs(cur-sum));
  }
  cout << ans << endl;

  return 0;
}

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,b) FOR(i,0,b)
#define INF 1e9

using ll = long long;
const ll mod = LLONG_MAX;

int main(){
  int a,b,h,S;
  cin>>a>>b>>h;
  S=(a+b)*h/2;
  cout<<S<<endl;
  return 0;
}

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

typedef long long ll;
typedef pair<ll, ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
#define REP(i,n) for (ll i = 0; i < n; ++i)
#define FORE(x,xs) for (const auto& x : xs)
#define PB push_back
#define MP make_pair
#define ALL(v) v.begin(), v.end()

struct BIT {
  vector<ll> data;
  int N;

  BIT(int n) {
    N = 1;
    while (N < n) N *= 2;
    N *= 2;
    data = vector<ll>(N+1);
  }

  void add(int i, ll x) {
    for (int k = i; k <= N; k += k&-k) data[k] += x;
  }

  void update(int i, ll x) {
    add(i, x-get(i));
  }

  ll sum(int i) {
    ll res = 0;
    for (int k = i; k > 0; k -= k&-k) res += data[k];
    return res;
  }

  ll get(int i) {
    return sum(i) - sum(i-1);
  }
};

const int MAX = 2e5+10;
int N, K;
vii b;

int main() {
  cin >> N >> K;
  ll value = 0, a;
  BIT bit(MAX);
  b.PB(MP(0,0));
  REP (i, N) {
    cin >> a;
    value += a - K;
    b.PB(MP(value, i+1));
  }
  sort(ALL(b));
  ll ans = 0;
  REP (i, N+1) {
    int m = b[i].second+1;
    ans += bit.sum(m);
    bit.add(m,1);
  }
  cout << ans << endl;
}

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

const int N=1e5+10;

int a[N],n;
int q;

int read()
{
    char c=getchar();
    int n=0;
    while(c<'0'||c>'9') c=getchar();
    while(c>='0'&&c<='9')
    {
        n=(n<<1)+(n<<3)+(c&15);
        c=getchar();
    }
    return n;
}

int solve(int i,int m)
{
    if(m==0) return 1;
    if(i>=n) return 0;
    int res=solve(i+1,m)||solve(i+1,m-a[i]);
    return res;
}

int main(void)
{
    n=read();
    for(int i=0;i<n;i++) a[i]=read();
    q=read();
    while(q--)
    {
        int m=read();
        if(solve(0,m)) printf("yes\n");
        else printf("no\n");
    }
    return 0;
}



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

using namespace std;
using ll = long long;

const int mod = 1e9 + 7;

int n;
vector<vector<ll>> a, dp;

int main(){
    cin>>n;
    a.resize(n+1, vector<ll>(n+1));
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            cin>>a[i][j];
        }
    }
    dp.resize(n+1, vector<ll>(1 << n));
    dp[0][0] = 1;
    for(int i = 1; i <= n; i++){
        for(int mask = 0; mask <= (1 << n) - 1; mask++){
            if(__builtin_popcount(mask) != i) continue; // number of boys == number of girls
            for(int j = 0; j < n; j++){
                if((mask & (1 << j)) && a[i][j + 1]){
                    dp[i][mask] = (dp[i][mask] + dp[i-1][mask ^ (1 << j)]) % mod;
                }
            }
        }
    }
    ll res = dp[n][(1 << n) - 1];
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 377216
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <cmath>
#include <cstring>
#include <assert.h>
#include <utility>
#include <tuple>
#include <array>
#include <bitset>
#include <cstdlib>
#include <complex>

using int64 = long long;
using uint64 = unsigned long long;

using namespace std;

constexpr int MAX_N = 100000;

vector<int> graph[MAX_N];
int hist[MAX_N];

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    int n, m;
    cin >> n >> m;

    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }
    memset(hist, -1, sizeof(hist));
    queue<int> que;
    hist[0] = 0;
    que.push(0);
    while (!que.empty()) {
        int u = que.front();
        que.pop();

        for (int to : graph[u]) {
            if (hist[to] < 0) {
                hist[to] = u;
                que.push(to);
            }
        }
    }

    cout << "Yes" << endl;
    for (int i = 1; i < n; i++) {
        cout << hist[i] + 1 << endl;
    }

    return 0;
}



Measured memory_bytes: 9984
s = input()
def is_alpha(s):
  if len(set(s)) == 26:
    return 'None'
  al = {chr(i):0 for i in range(97, 97+26)}
  for i in s:
    al[i] +=1
  result = []
  for k, v in al.items():
    if v == 0:
      result.append(k)
  return min(result)


print(is_alpha(s))

Measured memory_bytes: 3188
#include<iostream>
#include <iomanip>
#include <algorithm> 
#include<vector>
#include<cmath>

using namespace std; 

int factorial(int n){
    if(n==0){
        return 1;
    }
    return n*factorial(n-1);
}

int main(){
    int N;
    cin >> N;
    vector<int> X;
    vector<int> Y;
    for(int i=0;i<N;i++){
        int tmp1,tmp2;
        cin >> tmp1 >> tmp2;
        X.push_back(tmp1);
        Y.push_back(tmp2);
    }
    vector<int> V;
    for(int i=0;i<N;i++){
        V.push_back(i);
    }

    double  total=0;
    do{
        for(int i=1;i<N;i++){
            total += sqrt(pow(X[V[i]]-X[V[i-1]],2)+pow(Y[V[i]]-Y[V[i-1]],2));
        }
    }while(next_permutation(V.begin(),V.end()));

    cout << fixed;
    cout << setprecision(10) << total / factorial(N) << endl;

    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main(){
  int x,a,b;
  cin>>x>>a>>b;
  if(a>=b)cout<<"delicious"<<endl;
  else if(a+x>=b)cout<<"safe"<<endl;
  else cout<<"dangerous"<<endl;
  return(0);
}
  


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

int main() {
    int N; cin >> N;
    int A, B; cin >> A >> B;
    int ans = 0;
    for (int i = 1; i <= N; i++) {
        string s = to_string(i);
        int sum = 0;
        for (int j = 0; j < s.size(); j++) {
            sum += s[j]-'0';
        }
        if (sum >= A && sum <= B) ans += i;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <list>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define p(x) cout << x << endl;
#define all(v) (v).begin(), (v).end()

#define MOD 1000000007
#define PI 3.14159265359

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

    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    int dx = x2 - x1;
    int dy = y2 - y1;

    int x3 = x2 - dy;
    int y3 = y2 + dx;
    int x4 = x1 - dy;
    int y4 = y1 + dx;

    cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    if(C<=A&&B<=D) cout << B-A << endl;
    else if(A<=C&&C<=B&&B<=D) cout << B-C << endl;
    else if(B<=C) cout << 0 << endl;
    else if(C<=A&&A<=D&&D<=B) cout << D-A << endl;
    else if(D<=A) cout << 0 << endl;
    else if(A<=C&&D<=B) cout << D-C << endl;
}


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

using namespace std;

const int maxn = 100010;
const int maxh = 210;

int n, h, e, f;
int l[maxh<<1], in_deg[maxh<<1], out_deg[maxh<<1], vis[maxh<<1];

struct Edge {
	int v, x;
} E[(maxn<<1)+(maxh<<2)];

inline void addEdge(int u, int v) {
	E[e].v = v, E[e].x = l[u], l[u] = e++;
}

void dfs(int u) {
	vis[u] = 1;
	if (in_deg[u] != out_deg[u]) f = 1;
	for (int p = l[u]; p >= 0; p = E[p].x) {
		int v = E[p].v;
		if (!vis[v]) dfs(v);
	}
}

int main() {
	memset(l, -1, sizeof(l));
	scanf("%d%d", &n, &h);
	for (int i = 1; i <= n; i++) {
		int a, b, c, d; scanf("%d%d%d%d", &a, &b, &c, &d);
		int u, v;
		if (c) u = c+h;
		else u = a;
		if (d) v = d;
		else v = b+h;
		addEdge(u, v), addEdge(v, u);
		++ in_deg[v], ++ out_deg[u];
	}
	int ok = 1;
	for (int i = 1; i <= h; i++) {
		if (in_deg[i] > out_deg[i]) ok = 0;
		if (in_deg[i+h] < out_deg[i+h]) ok = 0;
	}
	for (int i = 1; i <= 2*h; i++) {
		if ((in_deg[i] || out_deg[i]) && !vis[i]) {
			f = 0;
			dfs(i);
			if (!f) ok = 0;
		}
	}
	if (ok) puts("YES");
	else puts("NO");
	return 0;
}

Measured memory_bytes: 1792
a = input()
b = input()
c = input()

a += "A"
b += "B"
c += "C"
tmp = "a"
ai = 0
bi = 0
ci = 0
while True:
    if tmp == "a":
        tmp = a[ai]
        ai += 1
    elif tmp == "b":
        tmp = b[bi]
        bi += 1
    else:
        tmp = c[ci]
        ci += 1
    if tmp in ("ABC"):
        print(tmp)
        break
        

Measured memory_bytes: 38384
#include <iostream>
#include <vector>
using namespace std;
struct edge{
    int to;
    int cost;
};
vector<int> color;
vector<int> used;
vector<vector<edge>> G;
void dfs(int i){
    for(edge e: G[i]){
        if(used[e.to] == 1) continue;
        if(e.cost % 2 == 0){
            color[e.to] = color[i];
            used[e.to] = 1;
            dfs(e.to);
        }
        else{
            color[e.to] = 1 - color[i];
            used[e.to] = 1;
            dfs(e.to);
        }
    }
}
int main(){
    int N;
    cin >> N;
    G.resize(N);
    used.resize(N, 0);
    color.resize(N);
    for(int i = 0; i < N - 1; i++){
        int s, g, c;
        cin >> s >> g >> c;
        s--;
        g--;
        edge e, e2;
        e.to = g;
        e2.to = s;
        e.cost = c;
        e2.cost = c;
        G[s].push_back(e);
        G[g].push_back(e2);
    }
    color[0] = 0;
    used[0] = 1;
    dfs(0);
    for(int i = 0; i < N; i++) cout << color[i] << endl;
}

Measured memory_bytes: 8576
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = Integer.parseInt(scan.next());
		int[] p = new int[N];
		for (int i = 0; i < N; i++) {
			p[i] = Integer.parseInt(scan.next());
		}
		int maxIndex = getMaxIndex(p);
		int sum = 0;
		for (int i = 0; i < N; i++) {
			if (i == maxIndex) {
				sum += p[i] / 2;
			} else {
				sum += p[i];
			}
		}
		System.out.println(sum);

	}

	private static int getMaxIndex(int[] p) {
		int max = p[0];
		int maxIndex = 0;
		for (int i = 1; i < p.length; i++) {
			if (p[i] > max) {
				max = p[i];
				maxIndex = i;
			}
		}
		return maxIndex;
	}
}


Measured memory_bytes: 21332
#include<iostream>
#include<sstream>
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<cfloat>
#include<functional>
#include<map>
#include<string>
#include<cstring>
#include<vector>
#include<queue>
#include<stack>
#include<deque>
#include<set>
#include<list>
#include<numeric>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<long long, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<long long, long long> ll_ll;
typedef pair<double, double> d_d;
typedef vector<int> vint;
typedef vector<char> vchar;

#define intmax 2000000014
#define longmax 2000000000000000014LL
#define mod 1000000007LL
#define rep(i, n) for(i = 0;i < n;++i)
#define rep1(i, n) for(i = 1;i < n;++i)
#define rep2d(i, j, n) for(i = 0;i < n;++i)for(j = i + 1;j < n;++j)
#define per(i, n) for(i = n - 1;i > -1;--i)
#define int(x) int x; scanf("%d",&x)
#define int2(x, y) int x, y; scanf("%d%d",&x, &y)
#define int3(x, y, z) int x, y, z; scanf("%d%d%d",&x, &y, &z)
#define intn(n, a) rep(i, n)scanf("%d", &a[i]);
#define int2n(n, a, b) rep(i, n)scanf("%d%d", &a[i], &b[i]);
#define sc(x) cin >> x
#define sc2(x, y) cin >> x >> y
#define scn(n, a) rep(i, n)cin >> a[i]
#define sc2n(n, a, b) rep(i, n)cin >> a[i] >> b[i]
#define pri(x) cout << x << "\n"
#define pri2(x, y) cout << x << " " << y << "\n"
#define pri3(x, y, z) cout << x << " " << y << " " << z << "\n"
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define kabe puts("---------------------------")
#define kara puts("")
#define debug(x) cout << " --- " << x << "\n"
#define debug2(x, y) cout << " --- " << x << " " << y << "\n"
#define debug3(x, y, z) cout << " --- " << x << " " << y << " " << z << "\n"
#define debugn(i, n, a) rep(i, n)cout << " --- " << a[i] << "\n";
#define debugin(i, n, a) rep(i, n)printf(" --- %10d\n", a[i])
#define debugi2n(i, n, a, b) rep(i, n)printf(" --- %10d %10d\n", a[i], b[i])
#define debugiin(i, n, a) rep(i, n)printf(" --- %10d %10d\n", a[i].first, a[i].second)
#define X first
#define Y second
#define eps 0.0001
#define prid(x) printf("%.3lf\n", x)

struct unionfind{
	vint data;
	void use(int n){ data.assign(n, -1); }
	bool unionset(int x, int y){
		x = root(x); y = root(y);
		if(x != y){
			if(data[y] < data[x])swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
		return x != y;
	}
	bool findset(int x, int y){ return root(x) == root(y); }
	int root(int x){ return (data[x] < 0) ? x : data[x] = root(data[x]); }
	int size(int x){ return -data[root(x)]; }
};

int i, j, tmp, tmp2;
signed main(void){
  for(int testcase = 1;;testcase++){
    int2(n, q);
    unionfind u; u.use(n);

    rep(i, q){
      int3(com, x, y);
      if(com)puts((u.findset(x, y)) ? "1" : "0");
      else u.unionset(x, y);
    }

//    pri(testcase);

/*/
//*/ break;
  }
  return 0;
}

Measured memory_bytes: 1204
#include<cstdio>
#include<algorithm>
#define maxn 100005
#define ll long long
using namespace std;
const double INF = 1e18;
int n;
double ans = INF;
ll x[maxn],y[maxn];
int d[maxn];
int dx[4] = {-1,1,0,0};
int dy[4] = {0,0,-1,1};

double solve(double t)
{
    double maxx = -INF,maxy = -INF;
    double minx = INF,miny = INF;
    double xx,yy;
    for (int i=1;i<=n;i++)
    {
        xx = x[i] + t*dx[d[i]];
        yy = y[i] + t*dy[d[i]];
        maxx = max(maxx,xx);
        minx = min(minx,xx);
        maxy = max(maxy,yy);
        miny = min(miny,yy);
    }
    return (maxx-minx)*(maxy-miny);
}

int main()
{
    scanf("%d",&n);
    char temp;
    for(int i=1;i<=n;i++)
    {
        scanf("%lld %lld %c",&x[i],&y[i],&temp);
        if (temp=='L') d[i] = 0;
        else if(temp=='R') d[i] = 1;
        else if(temp=='D') d[i] = 2;
        else if(temp=='U') d[i] = 3;
    }
    double u=1e9;
    double d=0;
    for (int i=1;i<=200;i++)
    {
        double uu = (u*2+d)/3;
        double dd = (u+d*2)/3;
        double uv = solve(uu);
        double dv = solve(dd);
        ans = min(ans,uv);
        ans = min(ans,dv);
        if(uv>dv) u=uu;
        else d=dd;
        //printf("%f\n",ans);
    }
    printf("%f",ans);
    return 0;
}


Measured memory_bytes: 2176
#include<bits/stdc++.h>
#include <algorithm>
using namespace std;
 
#define ll long long int 
#define ull unsigned long long int
#define db double
#define ld long double
#define MOD 1000000007
#define inf (1LL << 62)
#define pi acos(-1.0)
#define si(a) scanf("%lld",&a)
#define sd(n) scanf("%lf", &n)
#define for1(i, stop) for(ll i = 1; i <= stop; i++)
#define for0(i, stop) for(ll i = 0; i < stop; i++)
#define rep1(i, start) for(ll i = start; i >= 1; i--)
#define rep0(i, start) for(ll i = (start-1); i >= 0; i--)
#define loop(i, start, stop, inc) for(ll i = start; i <= stop; i += inc)
#define pb(v,a) v.push_back(a)
#define pll pair <ll, ll>
#define mp make_pair
#define pbp(v,a,i) v.push_back(make_pair(a,i)) 
#define srt(v) sort(v.begin(),v.end())
#define rv(v) reverse(v.begin(),v.end())
#define ms(n, i) memset(n, i, sizeof(n))
#define debug printf("Debug\n");
#define en '\n'
 
 
 
#define _fastio  ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);
 
 
int main()
{
	_fastio
	ll n,k,a,sm=0;
	cin>>n>>k;
	vector<ll>v;
	for1(i,n)
	{
		cin>>a;
		pb(v,a);
	}
	srt(v);
	for0(i,k)
		sm+=v[i];

	cout<<sm<<en;
}

Measured memory_bytes: 3668
n,m,c=map(int,input().split())
B=list(map(int,input().split()))
A=[list(map(int,input().split())) for i in range(n)]
ans=0
for a in A:
  s=c
  for i in range(m):
    s += a[i]*B[i]
  if s>0:
    ans += 1
print(ans)

Measured memory_bytes: 9192
s = int(input())
numset = {s}
ans = 1
while 1:
    if ans != len(numset):
        break
    if s%2 == 0:
        s = s//2
        numset.add(s)
    else:
        s = s*3 + 1
        numset.add(s)
    ans += 1
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;

#define mem(dp,a)       memset(dp,a,sizeof dp)
#define ninja           ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define pb(x)           push_back(x)
#define all(c)          c.begin(), c.end()
#define int             long long
#define ff              first
#define ss              second
#define nl              '\n'

set<int> adj[100005];
vector<int> height(100005);
int32_t main()
{
	ninja
	int n,m; cin>>n>>m;
	int a,b;
	for(int i=0;i<n;i++){
		cin>>a;
		height[i]=a;
	}
	for(int i=0;i<m;i++){
		cin>>a>>b;
		adj[a].insert(height[b-1]);
		adj[b].insert(height[a-1]);
	}
	int res=0;
	for(int i=1;i<=n;i++){
		if(adj[i].size()==0){
			res++; continue;
		}
		auto it=adj[i].end();
		it--;
		if(*it<height[i-1])
			res++;
	}
	cout<<res;
}



Measured memory_bytes: 17984
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
#include<cstdio>
#include<cstdlib>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

const double EPS = 1e-10;

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;

bool dp[85][85][161*81];

int main(){
    int H,W; cin >> H >> W;
    vector<vector<int>> A(H,vector<int>(W)),B(H,vector<int>(W));
    rep(i,H)rep(j,W) cin >> A[i][j];
    rep(i,H)rep(j,W) cin >> B[i][j];

    rep(i,85)rep(j,85)rep(k,161*81) dp[i][j][k] = false;
    dp[1][0][0] = true;
    dp[0][1][0] = true;

    rep(i,H+1)rep(j,W+1)rep(k,(H+W)*81){
        if(j >= 1 && i < H &&dp[i][j][k]){
            dp[i+1][j][k+abs(A[i][j-1]-B[i][j-1])] = true;
            dp[i+1][j][abs(k-abs(A[i][j-1]-B[i][j-1]))] = true;
        }
        if(i >= 1 && j < W && dp[i][j][k]){
            dp[i][j+1][k+abs(A[i-1][j]-B[i-1][j])] = true;
            dp[i][j+1][abs(k-abs(A[i-1][j]-B[i-1][j]))] = true;
        }
    
    }
    //rep(i,H+1)rep(j,W+1)rep(k,10) cout << i << " " << j << " " << k << " " <<dp[i][j][k] << endl;
    rep(i,161*81){
        if(dp[H][W][i]){
            cout << i << endl;
            return 0;
        }
    }

}


Measured memory_bytes: 92288
#include <bits/stdc++.h>
#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++)
using namespace std;
using P = pair<int, int>; 
using ll = long long;

int main()
{
  int n;
  cin >> n;
  map<int, int> mp;
  ll ans = 0;
  int a[n];
  int m = 0;
  rep(i, n) {
    cin >> a[i];
    m = max(m, a[i]);
  }
  sort(a,a + n);

  ans += m;
  int cnt = 1;
  for(int i =  n - 2; i > 0; i--){
    if(cnt == n - 1) break;
    if(cnt + 2 < n){
      ans = ans + a[i] * 2;
      cnt += 2;
    }
    else{
      ans += a[i];
      cnt++;
    }
  }
  cout << ans << endl;
      

  return 0;
}

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

typedef long long int ll;
typedef long double ld;

//****************************************************                
#define lp(var,start,end) for (ll var = start; var <end ; ++var)
#define rlp(var,start,end) for(ll var = start; var>=end ; var--)
#define pb push_back
#define mp make_pair
#define pf push_front
#define ff first
#define ss second
#define vll vector<ll>
#define pll pair<ll,ll> 
#define vpll vector<pll>
#define all(X) X.begin(),X.end()
#define endl "\n" //comment it for interactive questions
#define trace1(a) cerr << #a << ": " << a << endl;
#define trace2(a,b) cerr << #a << ": " << a << " " << #b << ": " << b << endl;
#define trace3(a,b,c) cerr << #a << ": " << a << " " << #b << ": " << b << " " << #c << ": " << c << endl;
#define trace4(a,b,c,d) cerr << #a << ": " << a << " " << #b << ": " << b << " " << #c << ": " << c << #d << ": " << d << endl;
#define OC freopen("input.txt" , "r", stdin); freopen("output.txt" , "w", stdout) 
#define MOD (ll)1e9+7; //change it for other mods
#define FAST_IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
        //*******************************************************
//Some Functions

ll powmod(ll a,ll b)
{
   ll res = 1;
   while(b > 0) {
      if(b & 1) res = (res * a) % MOD;
      a = (a*a)%MOD;
      b = b >> 1; 
  }
  return res % MOD;
}

void solve()
{
    ll m1,d1;
    ll m2,d2;
    // ll mon30[] = {4,6,9,11};
    cin >> m1 >> d1;
    cin >> m2 >> d2;
    if(d1 == 31) {
    	cout << "1\n";
    	return;
    }
    else if(d1 == 28 && m1 == 2) {
    	cout << "1\n";
    	return;
    }
    else if(d1 == 30) {
    	if(m1 == 4 || m1 == 6 || m1 == 9 || m1 == 11) {
    		cout << "1\n";
    		return;
    	}
    }
    cout << "0\n";
}

int main()
{
    FAST_IO;
    #ifndef ONLINE_JUDGE 
      // OC;
    #endif
    ll t = 1;
    // cin >> t;
    while(t--){
        solve();
    }
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var A, B, C int
	fmt.Scan(&A, &B, &C)
	if A != B && B != C && A!= C{
		fmt.Println(3)
	}else if A == B && A == C{
		fmt.Println(1)
	}else{
		fmt.Println(2)
	}



}



Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <stdio.h>
#include <math.h>

using namespace std;

int main()
{
	int a[2];
	int a_keta,b_keta;

	while(1)
	{
		if(scanf("%d %d", &a[0],&a[1])==EOF)break;
		a_keta=(int)log10(a[0]+a[1])+1;

		cout<<a_keta<<"\n";				 
	}
	return 0;
}
		

Measured memory_bytes: 0
a,b,c,k = (int(x) for x in input().split())
total=0
total += min(a,k)
k -= min(a,k)
if k==0:
    print(total)
    exit()

if k>0:
    k -= min(b,k)
    if k==0:
        print(total)
        exit()

    if k>0:
        total -= min(c,k)
        print(total)

Measured memory_bytes: 9136
def Base_10_to_n(X, n):
    X_dumy = X
    out = ''
    while X_dumy>0:
        out = str(X_dumy%n)+out
        X_dumy = int(X_dumy/n)
    return out
N,K=map(int,input().split())
x = Base_10_to_n(N,K)
print(len(x))

Measured memory_bytes: 2940
import java.util.Arrays;
import java.util.Scanner;


public class Main {
	
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		
		final long a = sc.nextLong();
		final long b = sc.nextLong();
		
		System.out.printf("%d %d %.7f\n", (a / b), (a % b), (a / (double) b));
		
	}
	
}

Measured memory_bytes: 17256
#include "bits/stdc++.h"
using namespace std;

int main() {
    long long N, M;
    cin >> N >> M;

    long long ans1 = 1;
    long long ans2 = 1;
    for (int i = 1; i <= sqrt(M); i++) {
        if (M % i == 0) {
            long long M1 = i;
            long long M2 = M / i;

            if (M1 * N <= M) {
                ans1 = max(ans1, M1);
            }
            if (M2 * N <= M) {
                ans2 = max(ans2, M2);
            }
        }
    }

    cout << max(ans1, ans2) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <climits>
#include <set>
#include <map>
#include <iomanip>
#include <cassert>
#include <functional>
#include <cstring>

using namespace std;

typedef pair<int, int> P;
#define mp make_pair
#define FOR(i, a, b) for(int (i)=a;(i)<(b);++(i))
#define rep(i, n)  FOR(i,0,n)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort((v).begin(), (v).end());					//小さい順
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());		//大きい順
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define all(c) (c).begin(),(c).end()
#define ll long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define Print(p) cout<<(p)<<endl
#define F first
#define S second
#define pb1 push_back
#define mod 1000000007LL
#define INF 1234567890

const int maxn = 2e5 + 10;


//initialization here
//

//
//initialization finish


// your function is here
//



//
// your function finished



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

	// your code is here
	//
	
	int n, k; cin >> n >> k;

	int d[10];
	rep(i, k)cin >> d[i];

	ll ans;
	FOR(i, n, 100000)
	{
		bool check = false;
		ans = i;
		while (ans != 0)
		{
			rep(j, k)if (ans % 10 == d[j])
			{
				check = true;
				break;
			}
			if (check == true)break;
			ans /= 10;
		}
		if (check == true) continue;

		Print(i);
		return 0;
	}

	
	//
	// your code finished

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MM = 1000000000;
const int MOD = MM + 7;
const int MAX = 510000;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(ll i=j; i<n; i++)
#define all(vec) vec.begin(), vec.end()
template<class T> inline bool chmin(T& a, T b) {if(a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if(a < b) {a = b; return true;} return false;}
const ll INF = 1LL << 60;

int main() {
    ll n; cin >> n;
    vector<ll> a(n); rep(i, n) cin >> a[i];
    ll mon = 1000;
    ll st = 0;
    rep(i, n-1) {
        if(a[i] < a[i+1]) {
            st += mon / a[i];
            mon %= a[i];
        }
        else {
            mon += st * a[i];
            st = 0;
        }
    }
    mon += st * a[n-1];
    cout << mon << endl;
}


Measured memory_bytes: 3552
import java.util.Scanner;

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

		int a = sc.nextInt();
		int b = sc.nextInt();
		int k = sc.nextInt();

		for (int i = 0; i < k; i++) {
			if (i % 2 == 0)
				b += a /= 2;
			else
				a += b /= 2;
		}

		System.out.println(a + " " + b);

		sc.close();
	}

}


Measured memory_bytes: 22736
import java.util.Scanner;

public class Main {
	 public static void main(String[] args) {
	 // ?¨??????\???????????????????????????????????????
	 Scanner sc = new Scanner(System.in);
	 int w = sc.nextInt();
	 int n = sc.nextInt();
	 int[] values = new int[w];
	 for (int i = 0; i < values.length; i++) {
	 values[i] = i + 1;
	 }
	 for (int i = 0; i < n; i++) {
	 String str = sc.next();
	 String[] ab = str.split(",");
	 int a = Integer.parseInt(ab[0]) - 1;
	 int b = Integer.parseInt(ab[1]) - 1;
	 // a??¨b????????£???values??????????????????
	 int ex;
	 ex = values[a];
	 values[a] = values[b];
	 values[b] = ex;
	 }
	 // values??????????????????
	 for(int i = 0; i < w; i++){
		 System.out.println(values[i]);
		 }
	 }

}

Measured memory_bytes: 26156
a,b,m = map(int,input().split())

ref = list(map(int,input().split()))
mic = list(map(int,input().split()))

ans = min(ref)+min(mic)


for i in range(m):
    x,y,c = map(int,input().split())
    x-=1
    y-=1

    if ref[x]+mic[y]-c < ans:
        ans = ref[x]+mic[y]-c

print(ans)

Measured memory_bytes: 18736
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>

using namespace std;

int main()
{
    long n, k;
    cin >> n >> k;

    long count = 0;
    long tmp = n;
    for(count = 1; ; ++count) {
        if (tmp <= k-1) {
            break;
        }
        tmp /= k;
        
    }

    cout << count << endl;

    return 0;
}


Measured memory_bytes: 888
#include <iostream>

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

using namespace std;

int main( void )
{
	int n;
	int fd[5][5], fd2[5][5];
	cin >> n;
	while(n--) {
		rep(y, 5) rep(x, 5) { cin >> fd[y][x]; fd2[y][x] = fd[y][x]; }
		rep(y, 5) rep2(x, 1, 5) {
			if(fd[y][x]) fd[y][x] += fd[y][x-1];
			if(fd2[x][y]) fd2[x][y] += fd2[x-1][y];
		}
		int Max = 0;
		rep(x, 5) {
			rep(s, 4) {
				int val = 0, count = 0;
				rep2(y, s, 5) {
					if(!fd[y][x]) {
						count = 0;
						val = 0;
					}
					else {
						if(val == 0) val = fd[y][x];
						else val = min(val, fd[y][x]);
						++count;
						Max = max(Max, count * val);
					}
				}
			}
		}
		rep(y, 5) {
			rep(s, 4) {
				int val = 0, count = 0;
				rep2(x, s, 5) {
					if(!fd2[y][x]) {
						count = 0;
						val = 0;
					}
					else {
						if(val == 0) val = fd2[y][x];
						else val = min(val, fd2[y][x]);
						++count;
						Max = max(Max, count * val);
					}
				}
			}
		}
		//rep(y, 5) {
		//	rep(x, 5) cout << fd2[y][x] << ' ';
		//	cout << endl;
		//}
		cout << Max << endl;
	}
	return 0;
}

Measured memory_bytes: 0
//https://atcoder.jp/contests/abc153/tasks/abc153_d
#include <bits/stdc++.h>
#if LOCAL
#include "dump.hpp"
#else
#define dump(...)
#endif
using namespace std;
using ll=long long;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
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;}
int main() {
    ll H; cin>>H;
    ll ans=0;
    ll num=1;
    //sim
    while(H>0){
        ans += num;
        num *= 2;
        H/=2;
    }
    cout<<ans<<endl;    
    return 0;
}

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

using namespace std;

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

void solve() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (auto &e : a) cin >> e;

    vector<vector<vector<ll>>> dp(2, vector<vector<ll>>(n + 1, vector<ll>(n + 1)));

    for (int len = 1; len <= n; len++) {
        for (int i = 0; i + len <= n; i++) {
            for (int k = 0; k < 2; k++) {
                dp[k][i][i + len] = max(-dp[k ^ 1][i + 1][i + len] + a[i], -dp[k ^ 1][i][i + len - 1] + a[i + len - 1]);
            }
        }
    }

    cout << dp[0][0][n];
}

int main() {
    cout << fixed << setprecision(20);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

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

    return 0;
}


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

using Graph = vector<pair<ll,ll> >;

Graph G;
// n個の頂点であり、最短距離が２であるk個の対ができるグラフを構築
void makeGraph(ll n, ll k){
    for(int i = 2;i <= n;++i){
        G.push_back(make_pair(1,i));
    }
    // 今現在の完全うにグラフは N-1 C 2 = (N - 1)(N - 2) / 2であるので、辺を　(N - 1)(N - 2) / 2 - K個追加すればいい
    ll count = 0;
    for(int i=2;i <= n;++i){
        for(int j=i+1;j <= n;++j){
            if(count >= ((n-1) * (n-2) / 2 - k))break;
            G.push_back(make_pair(i, j));
            count ++;
        }
    }
}

void printGraph(){
    cout << G.size() << endl;
    for(auto itr : G){
        cout << itr.first << " " << itr.second << endl;
    }
}

int main(){
    ll N, K ; cin >> N >> K;
    // 以下の場合は解が存在しない
    if(((N-1) * (N-2)) / 2 < K){
        cout << "-1" << endl;
        return 0;
    }

    makeGraph(N, K);
    printGraph();
}

Measured memory_bytes: 512
n = int(input())

l = []
for i in range(n):
    a = int(input())
    ll = []
    for j in range(a):
        x,y = map(int,input().split())
        ll.append([x,y])
    l.append(ll)

ans = 0
for i in range(1 << n):
    people = []
    t= 0
    for j in range(n):
        if (i & (1 << j)) == 0:
            t+=1
            people.append(1)
        else:
            people.append(-1)

    flg = True
    for j in range(n):
        if (i & (1 << j)) == 0:
            for k in range(len(l[j])):
                x,y = l[j][k]
                if y == 0 and people[x-1]== 1:
                    flg = False
                elif y == 1 and people[x-1] == -1:
                    flg = False

    if flg:
        ans = max(ans , t)        
print(ans)

Measured memory_bytes: 3064
import java.util.*;

public class Main {

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

        int n = sc.nextInt();

        if (n % 10 == 2 || n % 10 == 4 || n % 10 == 5 || n % 10 == 7 || n % 10 == 9) {
            System.out.println("hon");
        } else if (n % 10 == 3) {
            System.out.println("bon");
        } else {
            System.out.println("pon");
        }

        sc.close();
    }

}


Measured memory_bytes: 35808
#include<stdio.h>
int main(){
  int h,w,i,j,k,l,ans=0,n,c;
  char s[10][10];
  scanf("%d %d %d",&h,&w,&n);
  for(i=0;i<h;i++)scanf("%s",s[i]);
  for(i=0;i<(1<<h);i++){
    for(j=0;j<(1<<w);j++){
      c=0;
      for(k=0;k<h;k++){
	if(i&(1<<k))continue;
	for(l=0;l<w;l++){
	  if(j&(1<<l))continue;
	  if(s[k][l]=='#')c++;
	}
      }
      if(c==n)ans++;
    }
  }
  printf("%d\n",ans);
  return 0;
}


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

int main(){
  int n,ans=0;
  string str;
  cin >> n >> str;
  
  r(i,n){   
  set<char> s;
    r(j,i){
      for(int k = i; k<n; k++){
        if(str[j]==str[k])s.insert(str[j]);
      }
    }
    ans=max(ans,static_cast<int>(s.size()));
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};

int main(){
	int H,W;
	cin >> H >> W;
	string S[110];
	int dist[110][110];
	int wsum = 0;
	for(int i=0;i<H;i++){
		cin >> S[i];
		for(int j=0;j<W;j++){
			if(S[i][j]=='.') wsum++;
		}
	}
	memset(dist, -1, sizeof(dist));
	dist[0][0] = 1;
	queue<pii> que;
	que.push(make_pair(0, 0));
	while(!que.empty()){
		pii cur = que.front();que.pop();
		int x = cur.first, y = cur.second;
		for(int dir=0;dir<4;dir++){
			int nx = x + dx[dir], ny = y + dy[dir];
			if(nx<0 || nx >= H || ny < 0 || ny >= W) continue;
			if(S[nx][ny]=='#') continue;
			if(dist[nx][ny] == -1){
				dist[nx][ny] = dist[x][y] + 1;
				que.push(pii(nx, ny));
			}
		}
	}

	if(dist[H-1][W-1] == -1) cout << -1 << endl;
	else cout << wsum - dist[H-1][W-1] << endl;
}


Measured memory_bytes: 892
n, m = list(map(int, input().split()))
x_li = list(map(int, input().split()))
x_li.sort()
dist = []
for i in range(m-1):
  dist.append(abs(x_li[i] - x_li[i + 1]))
dist.sort()
ans = 0
for i in range(m - n):
  ans += dist[i]
print(ans)

Measured memory_bytes: 13968
//
//  main.cpp
//

#include <algorithm>
#include <array>
#include <assert.h>
#include <iostream>
#include <limits>
#include <math.h>
#include <memory>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

using ll = int64_t;
using ull = uint64_t;

template<typename T>
vector<T> make_vec_nd(T init, size_t size) {
    return vector<T>(size, init);
}
template<typename T, typename... Args>
auto make_vec_nd(T init, size_t size, Args... rest) {
    auto inner = make_vec_nd(init, rest...);
    return vector<decltype(inner)>(size, inner);
}

int main() {
    ll N, A;
    cin >> N >> A;
    vector<ll> Xis;
    for (ll i = 0; i < N; i++) {
        ll Xi;
        cin >> Xi;
        Xis.push_back(Xi);
    }
    auto dp = make_vec_nd((ll)0, N+1, N+1, N*50+1);
    dp[0][0][0] = 1;
    for (ll i = 0; i < Xis.size(); i++) {
        for (ll cnt = 0; cnt <= N; cnt++) {
            for (ll x = 0; x <= N*50; x++) {
                dp[i+1][cnt][x] = dp[i][cnt][x];
                if (Xis[i] <= x && cnt > 0) {
                    dp[i+1][cnt][x] += dp[i][cnt-1][x-Xis[i]];
                }
            }
        }
    }
    ll ans = 0;
    for (ll cnt = 1; cnt <= N; cnt++) {
        if (cnt * A <= N * 50) {
            ans += dp[N][cnt][cnt * A];
        }
    }
    cout << ans << endl;
}


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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

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

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

int main()
{
    cout << fixed << setprecision(15);
    ll N;
    cin >> N;

    vector<ll> P(N);

    REP(i, N){
        cin >> P[i];
        P[i]--;
    }

    vector<ll> dp(N, 0);

    ll ans = 0;
    REP(i, N){
        if(P[i] == 0){
            dp[0] = 1;
        }
        else{
            dp[P[i]] = dp[P[i]-1] + 1;
        }
        ans = max(ans, dp[P[i]]);
    }
    cout << N - ans << endl;

    return 0;
}

Measured memory_bytes: 3328
#include"bits/stdc++.h"
using namespace std;
int main(){
	char cur='a';
	string a,b,c;
	cin>>a>>b>>c;
	while(1){
		if(cur=='a'){
			if(!a.size()){
				cout<<'A';
				return 0;
			}
			cur=a[0];
			a.erase(0,1);
		}
		else if(cur=='b'){
			if(!b.size()){
				cout<<'B';
				return 0;
			}
			cur=b[0];
			b.erase(0,1);
		}
		else{
			if(!c.size()){
				cout<<'C';
				return 0;
			}
			cur=c[0];
			c.erase(0,1);
		}
	}
}


Measured memory_bytes: 256
while True:
  m, f, r = list(map(int, input().split()))
  if m == -1 and f == -1 and r == -1:
    break
  if m == -1 or f == -1:
    print("F")
  elif m + f >= 80:
    print("A")
  elif m + f >= 65:
    print("B")
  elif m + f >= 50:
    print("C")
  elif m + f >= 30:
    print("C" if r >= 50 else "D")
  else:
    print("F")


Measured memory_bytes: 5592
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MM = 1000000000;
const int MOD = MM + 7;
const int MAX = 510000;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(ll i=j; i<n; i++)
#define all(vec) vec.begin(), vec.end()
template<class T> inline bool chmin(T& a, T b) {if(a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if(a < b) {a = b; return true;} return false;}
const ll INF = 1LL << 60;
const double pi = acos(-1.0);


const int dh[4] = {-1, 0, 0, 1};
const int dw[4] = {0, -1, 1, 0};

int main() {
    int H, W; cin >> H >> W;
    int n; cin >> n;
    vector<int> a(n); rep(i, n) cin >> a[i];
    vector<vector<int>> seen(H, vector<int>(W, -1));
    stack<pair<int, int>> q;
    q.push(make_pair(0, 0));
    int id = 0;
    while(q.size()) {
        auto now = q.top(); q.pop();
        if(!a[id]) id++;
        if(seen[now.first][now.second] == -1) seen[now.first][now.second] = id + 1;
        a[id]--;
        rep(i, 4) {
            int nh = now.first + dh[i];
            int nw = now.second + dw[i];
            if(nh<0||H<=nh||nw<0||W<=nw) continue;
            if(seen[nh][nw] != -1) continue;
            q.push(make_pair(nh, nw));
        }
    }
    rep(i, H) {
        rep(j, W) cout << seen[i][j] << ' ';
        cout << endl;
    }
}

Measured memory_bytes: 3760