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

using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair

#define int long long

typedef pair<int, int> ii;

const int mod = 1e9 + 7;

const int N = 1005;

const int M = 2e4 + 5;

const int inf = 1e15;

int n, dp[N][M], s[N], w[N], v[N];

vector<pair<ii, ii>> vec;

signed main() {
    cin.tie(0), ios::sync_with_stdio(0);
    cin >> n;
    for(int i = 1; i <= n; i++) {
        int x, y, z;
        cin >> x >> y >> z;
        vec.pb({{y + x, x}, {y, z}});
    }
    sort(vec.begin(), vec.end());
    for(int i = 0; i < vec.size(); i++) {
        s[i + 1] = vec[i].se.fi;
        w[i + 1] = vec[i].fi.se;
        v[i + 1] = vec[i].se.se;
    }
    for(int i = 1; i <= n; i++) {
        for(int j = 0; j <= M - 5; j++)
            dp[i][j] = -inf;
    }
    dp[0][0] = 0;
    for(int i = 0; i < n; i++) {
        for(int j = 0; j <= M - 5; j++) {
            if(j <= s[i + 1])
                dp[i + 1][j + w[i + 1]] = max(dp[i + 1][j + w[i + 1]], dp[i][j] + v[i + 1]);
            dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
        }
    }
    int mx = 0;
    for(int j = 0; j <= M - 5; j++)
        mx = max(mx, dp[n][j]);
    cout << mx;
}


Measured memory_bytes: 156672
#include <bits/stdc++.h>
 
using namespace std;
 
#define rep(i, n) for(int i=0; i<(n); i++)
#define FOR(i, m, n) for(int i=(m);i<(n);i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define RSORT(x) sort((x).rbegin(),(x).rend())
#define REVE(x) reverse((x).begin(),(x).end())
#define mp make_pair
#define pb push_back
#define chmax(x,y) x = max(x,y)

 
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<vector<int> > VVI;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<bool> VB;
typedef vector<LL> VL;
typedef vector<vector<long long>> VVLL;
const int MOD = 1e9+7;
const int INF = 1e9;
const LL LINF = 1e18;
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 * b / gcd(a, b);
}

struct UnionFind {
    VI d;
    UnionFind(int n = 0): d(n,-1) {}
    int find(int x) {
        if(d[x] < 0) return x;
        return d[x] = find(d[x]);
    }
    bool unite(int x,int 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(int x,int y) { return find(x) == find(y); }
    int size(int x) { return -d[find(x)]; }
};
int deg[100005];
VI to[100005];

int main() {
    int n,m,k;
    cin >> n >> m >> k;
    UnionFind uf(n);
    rep(i,m) {
        int a,b;
        cin >> a >> b;
        a--; b--;
        deg[a]++;
        deg[b]++;
        uf.unite(a,b);
    }
    rep(i,k) {
        int a,b;
        cin >> a >> b;
        --a; --b;
        to[a].push_back(b);
        to[b].push_back(a);
    }
    rep(i,n) {
        int ans = uf.size(i) - 1 -deg[i];
        for(auto u: to[i]) {
           if(uf.same(u,i)) --ans; 
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 6784
#include <iostream>
#include <algorithm>
using namespace std;
 
static const long MAX = 1000;
static const long VMAX = 10000;
 
long n, A[MAX], s;
long B[MAX], T[VMAX + 1];
 
long solve(){
    long ans = 0;
    bool V[MAX];
    for (long i = 0; i < n; i++){
        B[i] = A[i];
        V[i] = false;
    }
    sort(B, B + n);
    for (long i = 0; i < n; i++) T[B[i]] = i;
    for (long i = 0; i < n; i++){
        if (V[i]) continue;
        long cur = i, S = 0, m = VMAX, an = 0;
        while (1){
            V[cur] = true;
            an++;
            long v = A[cur];
            m = min(m, v);
            S += v;
            cur = T[v];
            if (V[cur]) break;
        }
        ans += min(S + (an - 2) * m, m + S + (an + 1) * s);
    }
    return ans;
}
 
int main(){
    cin >> n;
    s = VMAX;
    for (long i = 0; i < n; i++){
        cin >> A[i];
        s = min(s, A[i]);
    }
    long ans = solve();
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3172
//in the name of god
#include <bits/stdc++.h>
using namespace std;
#define MAX_N (int)1e5+20
#define INF 1e9+20
#define pb push_back
#define F first
#define S second
typedef long long LL;
typedef pair<int,int> pii;
const int delta=(int)1e9+7;
int n,a,b,x,ans; string s,t,r;
bool ac(){
	for(int i=0;i<s.size();++i){
		if(s[i]!='x'){
			t+=s[i]; r=s[i]+r;
		}
	}
	if(r!=t) return 1;
	a=0,b=s.size()-1;
	while(a<b){
		if(s[a]=='x'){
			if(s[b]!='x') ++ans;
			else --b;
			++a;
		}
		else{
			while(s[a]!=s[b]){
				++ans;
				--b;
			}
			--b; ++a;
		}
	}
	return 0;
}
int main(){
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin>>s;
	if(ac()) ans=-1;
	cout<<ans;
	return cout<<endl,0;
}

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

const int N = 1e5 + 100;

typedef long long LL;

int n, X;
LL pre_X[N];
LL pre_0[N];

struct Exam {
    int b, l, r;
    bool operator < (const Exam &e) {
        LL c0 = 1ll*X*r - 1ll*b*(r-l);
        LL c1 = 1ll*X*e.r - 1ll*e.b*(e.r-e.l);
        return c0 > c1;
    }
}E[N];

bool ok(LL days) {
    LL full = days/X, extra = days%X;
    if(full == n) return 1;
    for(int i = 1; i <= n; i++) {
        LL cur_X = 1ll*(X-E[i].b)*E[i].r;
        LL cur_0 = -1ll*E[i].b*E[i].l;
        LL D = 0;
        if(i <= full) D += pre_X[full+1] - cur_X + pre_0[full+2];
        else D += pre_X[full] + pre_0[full+1] - cur_0;
        if(extra <= E[i].b) D += 1ll*(extra-E[i].b)*E[i].l;
        else D += 1ll*(extra-E[i].b)*E[i].r;
        if(D >= 0) return 1;
    }
    return 0;
}

int main() {
    // freopen("in.txt", "r", stdin);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> X;
    for(int i = 1; i <= n; i++) cin >> E[i].b >> E[i].l >> E[i].r;
    sort(E+1, E+n+1);
    for(int i = 1; i <= n; i++) {
        pre_X[i] = pre_X[i-1] + 1ll*(X-E[i].b)*E[i].r;
    }
    for(int i = n; i >= 1; i--) {
        pre_0[i] = pre_0[i+1] - 1ll*E[i].b*E[i].l;
    }
    LL lo = 0, hi = 1ll*n*X;
    while(hi > lo) {
        LL mid = (lo+hi)/2;
        if(ok(mid)) hi = mid;
        else lo = mid+1;
    }
    cout << lo << endl;
    return 0;
}



Measured memory_bytes: 2944
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0

n = int(readline())
lst1 = list(map(int,readline().split()))
ct = 1000
stock = 0
#次の日に上がるか下がるか
lst2 = [0]*n
for i in range(n-1):
    if lst1[i] < lst1[i+1]:
        lst2[i] = 1
    elif lst1[i] > lst1[i+1]:
        lst2[i] = -1
for i in range(n):
    if lst2[i] == 1:
        stock += ct//lst1[i]
        ct %= lst1[i]
    elif lst2[i] == -1:
        ct += stock*lst1[i]
        stock = 0


print(ct + stock*lst1[-1])


Measured memory_bytes: 62004
N = int(input())
a = list(map(int,input().split()))

ma = max(a)
ma2 = ma/2
mi = 999999999999.0
mii = -1
for i in a:
    if abs(ma2 - i) < mi and i != ma:
        mi = abs(ma2 - i )
        mii = i

print(ma,mii,sep=" ")


Measured memory_bytes: 14060
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>
#include <tuple>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e12;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

ll sq(ll num) { return num*num; }
ll mod_pow(ll x, ll n) {
	if (n == 0)return 1;
	if (n == 1)return x%MOD;
	ll res = sq(mod_pow(x, n / 2));
	res %= MOD;
	if (n % 2 == 1) {
		res *= x;
		res %= MOD;
	}
	return res;
}
ll mod_add(ll a, ll b) { return (a + b) % MOD; }
ll mod_sub(ll a, ll b) { return (a - b + MOD) % MOD; }
ll mod_mul(ll a, ll b) { return a*b % MOD; }

int n;
ll k[101];
string table = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main() {
	while (cin >> n&&n) {
		rep(i, n)cin >> k[i];
		string s;
		cin >> s;
		rep(i, s.size()) {
			int pos = table.find(s[i]);
			cout << table[(pos - k[i%n] + 52) % 52];
		}
		cout << endl;
	}
}


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

int main() {
  ll m1,m2,d1,d2;
  cin >> m1 >> d1;
  cin >> m2 >> d2;
  if (m1 != m2 && d2 == 1) cout << 1 << endl;
  else  cout << 0 << endl;

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
	int N;
	scanf("%d",&N);
	int a,b;
	int c=0;
	int d=0;
	for(a=1;a<=N;a++){
		if((a%2)==1){
			for(b=1;b<=a;b++){
				if((a%b)==0){
					c++;
				}
			}
		}
		if(c==8){
			d++;
		}
		c=0;
	}
	printf("%d",d);
return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

int main(){
	int h, w, i, j, ct=0;
	char c;
	scanf("%d%d\n",&h,&w);
	for( i=0; i<h; i++ ){
		for( j=0; j<w; j++ ){
			scanf("%c",&c);
			if( c=='#' ) ct++;
		}
		getchar();
	}
	if( ct == w+h-1 ) printf("Possible\n");
	else printf("Impossible\n");
	return 0;
}

Measured memory_bytes: 128
/*
    Author - Param Kothari
    Ah shit, here we go again
*/

#include <bits/stdc++.h>
 
using namespace std;

#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
#define mk make_pair

typedef long long ll;
typedef long double ld;

ll dp[3003][3003][4] = {}, a[3003][3003] = {};

void solve(){
    int r, c, q;
    cin >> r >> c >> q;
    for(int i = 0; i <= r; i++){
        for(int j = 0; j <= c; j++){
            a[i][j] = 0;
        }
    }
    for(int i = 0; i < q; i++){
        ll ri, ci, vi;
        cin >> ri >> ci >> vi;
        a[ri][ci] = vi;
    }
    for(int i = 0; i <= r; i++){
        for(int j = 0; j <= c; j++){
            for(int k = 0; k <= 3; k++){
                dp[i][j][k] = 0;
            }
        }
    }
    dp[1][1][0] = 0;
    dp[1][1][1] = a[1][1];
    for(int i = 2; i <= c; i++){
        for(int j = 1; j <= min(i, 3); j++){
            dp[1][i][j] = max(dp[1][i][j], dp[1][i - 1][j - 1] + a[1][i]);
            dp[1][i][j] = max(dp[1][i][j], dp[1][i - 1][j]);
        }
    }
    for(int i = 2; i <= r; i++){
        for(int j = 1; j <= 3; j++){
            dp[i][1][0] = max(dp[i][1][0], dp[i - 1][1][j]);
            dp[i][1][1] = max(dp[i][1][1], dp[i - 1][1][j] + a[i][1]);
        }
    }
    for(int i = 2; i <= r; i++){
        for(int j = 2; j <= c; j++){
            for(int k = 1; k <= min(j, 3); k++){
                dp[i][j][k] = max(dp[i][j][k], dp[i][j - 1][k - 1] + a[i][j]);
                dp[i][j][k] = max(dp[i][j][k], dp[i][j - 1][k]);
                dp[i][j][0] = max(dp[i][j][0], dp[i - 1][j][k]);
                dp[i][j][1] = max(dp[i][j][1], dp[i - 1][j][k] + a[i][j]);
            }
        }
    }
    ll res = 0;
    for(int i = 0; i <= 3; i++){
        res = max(res, dp[r][c][i]);
    }
    cout << res << "\n";
    return;
}

int main(){
    IOS;
    int t = 1;
    // cin >> t;
    for(int i = 1; i <= t; i++){
        solve();
    }
    return 0;
}

Measured memory_bytes: 355508
function main(input) {
    const args = input.split('\n')
    const limit = parseInt(args[0])
    const num = args[1].split(' ').map( x => parseInt(x, 10))
    const arr = []
    num.forEach((element, i) => {
      arr[element - 1] = i + 1 
    });
    arr.forEach(e => process.stdout.write(e + " "));
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 35152
x = int(input())

l = []
for i in range(10 ** 9):
    if i ** 5 <= 10 ** 13:
        l.append(i)
        l.append(-i)
    else:
        break

for i in range(len(l) - 1):
    for j in range(i, len(l)):
        if l[i] ** 5 - l[j] ** 5 == x:
            print(l[i], l[j])
            exit()

Measured memory_bytes: 9072
#include <bits/stdc++.h>
using namespace std;
long long MOD = 1000000007;
long long modsub(long long a, long long b){
	a %= MOD;
	b %= MOD;
	if (a >= b){
		return (a - b) % MOD;
	} else {
		return MOD - (b - a) % MOD;
	}
}
long long modpow(long long a, long long b){
	a %= MOD;
	long long res = 1;
	while (b > 0){
		if (b % 2 == 1) res = res * a % MOD;
		a = a * a % MOD;
		b = b / 2;
	}
	return res;
}
long long modinv(long long a){
	return modpow(a, MOD - 2);
}
vector<long long> mf;
long long modfact(long long n){
	if (n < mf.size()){
		return mf[n];
	} else {
		if (mf.empty()) mf.push_back(1);
		long long res = mf.back();
		for (int i = mf.size(); i <= n; i++){
			res = res * i % MOD;
			mf.push_back(res);
		}
		return res;
	}
}
long long modbinom(long long n, long long r){
	long long res;
	res = modfact(n);
	res = res * modinv(modfact(r)) % MOD;
	res = res * modinv(modfact(n - r)) % MOD ;
	return res;
}
int main(){
  int N;
  cin >> N;
  long long ans = modfact(N - 1) * (N - 1) % MOD;
  for (int i = 1; i <= N / 2 - 1; i++){
    long long tmp1 = modfact(N - 1 - i) * modfact(i) % MOD;
    long long tmp2 = modbinom(N - 2 - i, i);
    long long tmp = tmp1 * tmp2 % MOD;
    ans = modsub(ans, tmp);
  }
  cout << ans << endl;
}

Measured memory_bytes: 10476
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<queue>
#include<deque>
#include<map>
using namespace std;
typedef long long ll;

int main() {
    int n; cin >> n;
    struct edge {
        int next;
        int id;
    };
    vector<vector<edge>> ab(n);
    for (int i = 0; i < n-1; i++)
    {
        int a, b; cin >> a >> b;
        a--; b--;
        ab[a].push_back((edge){b, i});
        ab[b].push_back((edge){a, i});
    }
    
    vector<int> ans(n-1);
    auto rec = [&](auto &&rec, int now, int before, int bcolor) -> void {
        int color = 1;
        for (int i = 0; i < ab[now].size(); i++)
        {
            if (before == ab[now][i].next) continue;
            if (color == bcolor) color++;
            ans[ab[now][i].id] = color;
            rec(rec, ab[now][i].next, now, color);
            color++;
        }
    };
    rec(rec, 0, -1, 0);
    int mx = 1;
    for (int i = 0; i < n-1; i++)
    {
        mx = max(mx, ans[i]);
    }
    cout << mx << endl;
    for (int i = 0; i < n-1; i++)
    {
        cout << ans[i] << endl;
    }
    
    return 0;
}

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

/**
 * Created by Ayushi on 26 Apr 2020.
 * Problem:
 * Round:
 */

public class Main {
    public static void main(String[] args) throws IOException {
        StringTokenizer st;
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        st = new StringTokenizer(br.readLine(), " ");
        int s = Integer.parseInt(st.nextToken());
        int w = Integer.parseInt(st.nextToken());
        br.close();
        System.out.println(w >= s ? "unsafe":"safe");
    }
}


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

int main(){
  int w;
  while(cin >> w){
    int a = 1; 

    while(w > 0){
      if(w == 1){
        cout << a;
      } else if(w & 1){
        cout << a << " ";
      }
      w /= 2; a *= 2;
    }
    cout << endl;
  }
}
  
  


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

typedef struct{
	char c;
	int cnt;	
}charcnt;

int main(){
	string w;
	charcnt c[100];
	for(int i = 0; i < 100; ++i){
		c[i].cnt = 0;
		c[i].c = '\0';	
	}
	
	int wlen;	
	cin >> w;
	wlen = w.size();
	
	c[0].c = w[0];
	++c[0].cnt;
	int flaga = false;
	for(int i = 1; i < wlen; ++i){
		int j;
		flaga = false;
		for(j = 0; c[j].c != '\0'; ++j){
			if(w[i] == c[j].c){
				++c[j].cnt;
				flaga = true;
			}
		}
		if(!flaga){	
			c[j].c = w[i];
			++c[j].cnt;
		}
		
	}
	
	bool flag = false;
	for(int i = 0; c[i].c != '\0'; ++i){
		if(c[i].cnt % 2 == 1) flag = true;
	}
	
	if(flag) cout << "No" << endl;
	else cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include <ctime>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
typedef long long ll;
#define rep(i, a, b) for (int i = a; i <= b; ++ i)
const int maxn = 210;
using namespace std;

int a[maxn], n;

int main() {
	scanf("%d", &n);
	rep(i, 1, n << 1) scanf("%d", &a[i]);
	sort(a + 1, a + (n << 1) + 1);
	int ans = 0;
	for (int i = 1; i <= (n << 1); i += 2) ans += a[i];
	printf("%d\n", ans);	 
	return 0;
}

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

int main()
{
    long long n, a, b;
    cin >> n >> a >> b;

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

    long long m = a + b;
    long long times = n / m;
    long long count = a * times;
    long long left = n - m * times;

    count+=min(left,a);
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(0), cout << fixed << setprecision(20);
#define rep(i,n) for (int i=0; i<n;++i)
#define ALL(a)  (a).begin(),(a).end()
typedef long long ll;
using namespace std;
const int INF = 2e9;
int n, plus_cnt, minus_cnt; 
ll K;
auto nC2 = [](ll a) { return a*(a-1)/2; };
vector<ll> Po,Ne;

ll calc_count(ll X, vector<ll> &V, vector<ll> &W, bool posi) {
  ll ret = 0ll;
  // t以上のものはWに何個あるかを求める
  rep(i, V.size()) {
    ll t = (X+V[i]-1)/V[i];
    int idx = lower_bound(ALL(W), t)-W.begin();
    if (posi && i>=idx) ret += W.size()-i-1;
    else ret+=W.size()-idx;
  }
  return ret;
} 


int main() {
  INCANT;
  cin >> n >> K;
  ll a;
  rep(i, n) {
    cin >> a;
    if (a<0) Ne.push_back(-a); // 便宜上正にする
    else if (a>0) Po.push_back(a);
  }
  plus_cnt = Po.size();minus_cnt = Ne.size();
  sort(ALL(Ne)); sort(ALL(Po));
  ll negative_count = Ne.size()*Po.size();
  ll positive_count = nC2(Po.size())+nC2(Ne.size());

  if (negative_count<K && K < nC2(n)-positive_count) {
    cout << 0 << "\n";
    return 0;
  }

  ll ok = 0ll;
  ll ng = 1e18;
  ll base;
  while(ng-ok>1ll) {
    ll mid = (ok+ng)/2;
    ll r;
    if (K<=negative_count) {
      r = calc_count(mid, Ne,Po, false);
      base =K-1;
    } else {
      r = calc_count(mid, Ne, Ne, true)+calc_count(mid,Po, Po, true);
      base = nC2(n)-K;
    }
    if (r<=base) ng = mid;
    else ok = mid;
  } 
  if (negative_count>=K) ok *= -1;

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


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

int main(){
  int n, taro=0, hanako=0;
  string t, h;

  cin>>n;
  for(int i=0;i<n;i++){
    cin>>t>>h;
    if(t>h) taro+=3;
    else if(t<h) hanako+=3;
    else{
      taro++;
      hanako++;
    }
  }

  cout<<taro<<" "<<hanako<<endl;

  return 0;
}

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

using namespace std;

int used[110] = {0};
int n, x, cnt = 0;

void dfs(int depth, int ending)
{
    int sum = 0;
    if (depth == 3) {
        for (int i = 1; i <= n; i++) {
            if (used[i]) {
                sum += i;
            }
        }
        if (sum == x) {
            cnt++;
        }
        return;
    }
    
    for (int i = ending; i <= n; i++) {
        if (used[i]) continue;
        used[i] = 1;
        dfs(depth+1,i);
        used[i] = 0;
    }
}


int main(int argc, char *argv[])
{
   
    
    
    cin.tie(0), cout.tie(0), ios::sync_with_stdio(false);
    
    while (cin >> n >> x, n>0 || x>0) {
        dfs(0,1);
        cout << cnt << endl;
        used[110] = {0};
        cnt = 0;
    }
    
    return 0;
}



Measured memory_bytes: 3136
#include <stdio.h>
int main(void) {
	int H, W, i, ii;
	while (scanf("%d %d", &H, &W) == 2) {
		if (H == 0 && W == 0) break;
		for (i = 1; i <= W; i ++) printf("#");
		printf("\n");
		for (i = 2; i <= H - 1; i ++) {
			printf("#");
			for (ii = 2; ii <= W - 1; ii ++) printf(".");
			printf("#\n");
		}
		for (i = 1; i <= W; i ++) printf("#");
		printf("\n\n");
	}
	return 0;
}

Measured memory_bytes: 588
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define SHIFT_LEFT(n) (1LL<<((ll)n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;
ll combination(ll n,ll r){
  if(n < r)return 0;
  ll ret = 1;
  ll divide = 1;
  for(ll i=0;i<r;i++){
    divide *= i+1;
    ret *= n-i;
  }
  return ret/divide;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;cin>>s;
  ll k;
  cin>>k;
  ll ans = 0;
  ll kake = 1;
  for(int i=0;i<k;i++){
    kake*=9;
  }
  ll hoge = 0;
  for(int i=0;i<s.size();i++){
    if(s[i] == '0'){
    }else{
      //    cout<<s.size()-1-i<<" "<<k-i<<endl;
      ans += combination(s.size()-1-i,k-hoge)*kake;
      //cout<<i<<" "<<ans<<endl;
      //cout<<s.size()-1-i<<" "<<k-i<<endl;
      ans += (s[i]-'0'-1)*combination(s.size()-1-i,k-hoge-1)*(kake/9);
      // cout<<i<<" "<<ans<<endl;
      hoge++;
      kake/=9;
    }
  }
  ll cnt=0;
  for(int i=0;i<s.size();i++)
    if(s[i] != '0')cnt++;
  if(cnt == k)ans++;
  cout<<ans<<endl;
  return 0;
}


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

int main() {
    int n, t, a, h;
    cin >> n >> t >> a;

    int ans = 0;
    int mini = 1<<30;
    for (int i = 0; i < n; i++) {
        cin >> h;
        int tmpe = abs(t * 1000 - h * 6 - a * 1000);
        if (tmpe < mini) {
            ans = i+1;
            mini = tmpe;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
#define SZ(x) ((int)(x).size())
int gcd(int a,int b){return b?gcd(b,a%b):a;}
const double pi=acos(-1);




int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<char>> masu(H, vector<char>(W));
  rep (i, H) {
    rep (j, W) {
    cin >> masu.at(i).at(j);
    }
  }

  vector<bool> black1(H, false);
  rep (i, H) {
    rep (j, W) {
      if (masu.at(i).at(j)=='#') black1.at(i) = true;
    } 
  }
  
  vector<bool> black2(W, false);
  rep (i, W) {
    rep (j, H) {
      if (masu.at(j).at(i)=='#') black2.at(i) = true;
    }
  }
  
  int count = 0;
  rep (i, W) {
  if (black2.at(i)) count++;
  }  
  
  int memo = 0;
  
  rep (i, H) {
    rep (j, W) {
      if (black1.at(i) && black2.at(j)) {
      cout << masu.at(i).at(j);
      memo++;
        if (memo==count) {
        cout << endl;
        memo=0;
        }
      }
    } 
  }
  
  
  
}


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

const int MAX=101;
int A[MAX];

int N;
int selection(int A[]){
	int minv,count=0;
	for(int i=0;i<N-1;i++){
		minv=i;
		for(int j=i+1;j<N;j++)
		{
			if(A[minv]>A[j])
                  minv=j;
		}
		if(i!=minv){
		swap(A[i],A[minv]);
		count++;
		}
	}
	cout<<A[0];
	for(int i=1;i<N;i++)
		  cout<<" "<<A[i]; 
    cout<<endl;			
	return count;
}

int main()
{
	cin>>N;
	for(int i=0;i<N;i++)
		cin>>A[i];
	cout<<selection(A)<<endl;
	return 0;
}

Measured memory_bytes: 3068
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N,X; cin >> N >> X;
  vector<int> m(N);
  int ans=0;
 
  for(int i=0; i<N; i++) cin >> m.at(i);
  sort(m.begin(),m.end());
  
  for(int i=0; i<N; i++) {
    if(X >= m.at(i)) {
      X -= m.at(i);
      ans +=1;
    }
  }
  while(X >= m.at(0)) {
    X -= m.at(0);
    ans +=1;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3640
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = input()


RSP = ['r', 's', 'p']
ANS = ['p', 'r', 's']
ANS_SCORE = [P, R, S]
hands = []
ans = 0
for i in range(N):
    # K回前をきにする
    if i >= K:
        idx = RSP.index(T[i])
        if hands[-K] == ANS[idx]:
            hands.append('x')
        else:
            hands.append(ANS[idx])
            ans += ANS_SCORE[idx]
    else:
        idx = RSP.index(T[i])
        hands.append(ANS[idx])
        ans += ANS_SCORE[idx]
print(ans)


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

int main(){
    int n,x,sum = 0;
    cin >> n >> x;
    int cnt = 0;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    sort(a.begin(),a.end());
  	int s = x;
    rep(i,n) {
        s -= a[i];
      	sum += a[i];
        if(s < 0){
            cout << i << endl;
            return 0;
        }
    }
  	if(sum == x){
      cout << n << endl;
      return 0;
    }
  	cout << n-1 << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define int long long
#define pii pair<int, int>
#define F first
#define S second
#define pb push_back
const int N=1e5+5, INF=1e9;
using namespace std;
using namespace __gnu_pbds;
template <typename T> 
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
int n, a[N], f[N], s[N], prv[N], pos[N], tot;
set< pii > st;
pii ss[N];
signed main()
{
    cin >> n;
    for(int i = 1; i <= n; i++)
    {
        cin >> a[i];
        tot+=a[i];
        ss[i] = {a[i], i};
    }
    sort(ss+1, ss+n+1);
    s[n+1]=0;
    for(int i = n; i >= 1; i--)
    {
        s[i] = s[i+1] + ss[i].F;
        pos[ss[i].S]=i;
    }
    st.insert({-INF, 0});
    st.insert({a[1], 1});
    int mx=a[1], mxi=1;
    for(int i = 2; i <= n; i++)
    {
        prv[i] = (*(--st.upper_bound({a[i], 0}))).S;
        prv[i] = (*(st.upper_bound({a[prv[i]], -1}))).S;
        st.insert({a[i], i});
        if(a[i]>mx)
        {
            mxi = i;
            mx = a[i];
        }
    }
    int idx = mxi, curr=0, nxt;
    while(idx!=1)
    {
        int nidx = prv[idx];
        int cnt = n - pos[nidx];
        int suffsum = s[pos[nidx]+1];
        nxt = suffsum - cnt*a[nidx];
        f[idx] = nxt - curr;
        curr = nxt;
        idx = nidx;
    }
    f[1]=tot-curr;
    for(int i = 1; i <= n; i++)
    {
        cout << f[i] << endl;
    }
}

Measured memory_bytes: 12800
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define loop(i,n) rep(i,0,n)
using namespace std;
using ll = long long;
int main(){
    string s,t;
    int q;
    cin >> s >> t >> q;
    //cnt_s[i]=s[0,...,i)にあるAの数-s[0,...,i)にあるBの数
    vector<int> cnt_s(s.size()+1), cnt_t(t.size()+1);
    cnt_s[0]=0;
    cnt_t[0]=0;
    loop(i,s.size())cnt_s[i+1]=cnt_s[i]+(s[i]=='A'?1:-1);
    loop(i,t.size())cnt_t[i+1]=cnt_t[i]+(t[i]=='A'?1:-1);
    loop(i,q){
        int a,b,c,d;
        cin >> a >> b >> c >> d;
        if(((cnt_s[b]-cnt_s[a-1])-(cnt_t[d]-cnt_t[c-1]))%3==0)cout << "YES" << endl;
        else cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 1664
#include <iostream>

using namespace std;

int main(){
  int M;
  int D;
  cin >> M >> D;
  int count=0;
  for(int i=1;i<M+1;i++){
    for(int j=1;j<D+1;j++){
      if((j/10)*(j%10)==i&&(j/10)>1&&(j%10)>1){
       count++; 
      }
    }
  }
 cout << count << endl;
  return 0;
}


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

class Main {

    public static void main(String[] args) throws Exception {

        try {

            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

            int inputInt = Integer.parseInt(br.readLine());

            int multipleOfTwoAndN = inputInt;
            while (true) {
                if (multipleOfTwoAndN % 2 == 0 && multipleOfTwoAndN % inputInt == 0) {
                    break;
                }
                multipleOfTwoAndN += inputInt;
            }

            System.out.println(multipleOfTwoAndN);
        } catch (IOException | NumberFormatException e) {
            e.printStackTrace();
            System.exit(0);
        } catch (final Exception e) {
            e.printStackTrace();
            System.exit(0);
        }
    }
}

Measured memory_bytes: 23124
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        String b = sc.next();
        int[] count = new int[n+1];
        for (int i = 1;i < n;i ++) {
            int p = i+1;
            if (b.charAt(i-1) == 'A' && b.charAt(i) == 'C') {
                count[p] = count[p-1] + 1;
            } else {
                count[p] = count[p-1];
            }
            //System.out.println("ip="+p+", count="+count[p]);
        }

        for (int i = 0; i < q;i++) {
            int l = sc.nextInt();
            int r = sc.nextInt();
            System.out.println(count[r]-count[l]);
        }
    }
}


Measured memory_bytes: 68520
n = input()
l = list(map(int, input().split()))
w, h, temp = 0, 0, 0
cnt = 1
for i in sorted(l, reverse=True):
    if temp == i:
        cnt += 1
        if w == 0:
            w = i
        elif w != i:
            print(w*i)
            exit()
        if cnt == 4:
            print(w*w)
            exit()    
    else:
        cnt = 1
    temp = i
print(0)

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

int K;

int main(){
    cin >> K;
    int ans = -1;
    long long a[K];
    a[0]=0;
    for(int i = 1; i <= K; ++i){
        a[i] = (a[i-1]*10+7) % K;
        if(a[i] == 0){
            ans = i;
            break;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 11408
#include<iostream>
using namespace std;
typedef long long li;
#define rep(i,n) for(int i=0;i<(n);i++)
#define df 0
template<class T> void print(const T& t){ cout << t << "\n"; }
template<class T, class... Ts> void print(const T& t, const Ts&... ts) { cout << t; if (sizeof...(ts)) cout << " "; print(ts...); }

int main(){
  string s,t; cin >>s >>t;
  int n=s.size(),cnt=0;
  rep(i,n){
    if(s[i]!=t[i])cnt++;
  }
  print(cnt);
}


Measured memory_bytes: 3828
# 最大値、最小値、合計

# input process
n = int(input())
a_list = list(map(int, input().split()))

# operation
min_num = min(a_list)
max_num = max(a_list)
sum_num = sum(a_list)

print("%d %d %d"%(min_num, max_num, sum_num))



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

ll gcd(ll x, ll y) {return y ? gcd(y,x%y) : x;}

vector<pair<ll,int>> factorize(ll n){
  vector<pair<ll,int>> res;
  for (ll i=2; i*i<=n;++i){
    if(n%i) continue;
    res.emplace_back(i,0);
    while (n%i==0){
      n/=i;
      res.back().second++;
    }
  }
  if (n!=1)res.emplace_back(n,1);
  return res;
}

int main(){
  ll a,b;
  cin>>a>>b;
  ll g=gcd(a,b);
  auto f= factorize(g);
  int ans =f.size()+1;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <cassert>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF  9223300000000000000
#define LINF2 1223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;

using namespace std;


void solve()
{
    int x, y, z;
    scanf("%d%d%d", &x, &y, &z);
    printf("%d %d %d\n", z, x, y);

    return;
}

int main(int argc, char* argv[])
{
#if 1
    solve();
#else
    int T;
    scanf("%d", &T);
    int t;
    for(t=0; t<T; t++) {
        printf("Case #%d: ", t+1);
        solve();
    }
#endif
    return 0;
}


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

int main()
{
  ll int l,r;
  cin>>l>>r;
  if(abs(r-l)>2020)
  {
    cout<<"0";
    return 0;
  }
  l=l%2019;
  r=r%2019;
  if(l>r) 
    swap(l,r);
  int ans=1e6;
  for(int i=l;i<=r;i++)
  {
    for(int j=i+1;j<=r;j++)
    {
      ans=min(ans,(i*j)%2019);
    }
  }
  cout<<ans;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FastIO ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)
void solve();int main() {FastIO;solve();return 0;}
// ====================================================================================
void solve()
{
	int a;
cin>>a;
cout<<(a*(a+1))/2;

}


Measured memory_bytes: 3620
#include<stdio.h>
int main(){
  int a,b;
  int x=0;
  int z=0;
  int tate[5]={0};
  for(x=0;x<5;x++){
    scanf("%d",&tate[x]);
  }
  for(a=0;a<5;a++){
    for(b=5-1;b>0;b--){
      if(tate[b]>tate[b-1]){
	z=tate[b];
	tate[b]=tate[b-1];
	tate[b-1]=z;
      }
    }
  }
  for(x=0;x<5;x++){
    if(x==4){
      printf("%d\n",tate[x]);
    }
    else{
      printf("%d ",tate[x]);
    }
  }
  return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
vector<vector<char>> MAP(22,vector<char> (22,'#'));
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};

int bfs(int a,int b){
    vector<vector<int>> dist(22,vector<int> (22,-1));
    queue<int> X;
    queue<int> Y;
    X.push(a);
    Y.push(b);
    int maximum=0;
    if(MAP[a][b]=='.') dist[a][b]=0;
    else
        return maximum;
    while(!X.empty()) {
        int x = X.front();    X.pop();
        int y = Y.front();    Y.pop();
        for (int i = 0; i < 4; i++) {
            if (dist[x + dx[i]][y + dy[i]] == -1 && MAP[x + dx[i]][y + dy[i]] != '#') {
                dist[x+dx[i]][y+dy[i]]=dist[x][y]+1;
                X.push(x+dx[i]);
                Y.push(y+dy[i]);
                maximum=max(maximum,dist[x+dx[i]][y+dy[i]]);
            }
        }
    }
    return maximum;
}

int main(){
    int H,W;    cin>>H>>W;
    for(int i=1;i<=H;i++){
        for(int j=1;j<=W;j++){
            cin>>MAP[i][j];
        }
    }
    int maximum=0;
    for(int i=1;i<=H;i++){
        for(int j=1;j<=W;j++){
            maximum=max(maximum,bfs(i,j));
        }
    }
    cout<<maximum;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
const int MAX = 510000;

int main() {
  int X, Y, Z;
  cin >> X >> Y >> Z;
  cout << Z << " " << X << " " << Y << endl;
}

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

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define DSORT(c, type) sort(ALL(c), greater<type>())

using namespace std;


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

  int A, B;
  cin >> A >> B;

  if(abs(A-B) <= 1)
    cout << A + B << endl;
  else{
    int m = max(A, B);
    cout << m * 2 - 1 << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define MAX(a,b) a=a>b?a:b
#define MIN(a,b) a=a>b?a:b
#define REP(i,x,n) for(int i=x;i<n;i++)
#define REPR(i,x,n) for(int i=n-1;i>=x;i--)
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll MOD =1000000007;//1e9 + 7;

int main(){
    ll a,b,k;cin>>a>>b>>k;
    if(a<k){
        cout<<0<<" ";
        k-=a;
        if(b<k){
            cout<<0;
        }else{
            cout<<b-k;
        }
    }else{
        cout<<a-k<<" "<<b;
    }
    cout<<endl;
}

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

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int H, W;
char ans[105][105];

int main(){
  cin >> H >> W;
  for (int i = 0; i <= H + 1; i++){
    for (int j = 0; j <= W + 1; j++){
      ans[i][j] = '#';
    }
  }
  for (int i = 1; i <= H; i++){
    for (int j = 1; j <= W; j++){
      cin >> ans[i][j];
    }
  }
  for (int i = 0; i <= H + 1; i++){
    for (int j = 0; j <= W + 1; j++){
      cout << ans[i][j];
    }
    cout << endl;
  }


  return 0;
}


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

int main() {
    int A, B, C;
    cin >> A >> B >> C;
    string ans = "No";
    if (A == B && A != C) ans = "Yes";
    if (A == C && A != B) ans = "Yes";
    if (B == C && A != C) ans = "Yes";
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int a,b,c,d,e,f;
    scanf("%d%d%d%d",&a,&b,&c,&d);
    e=a+b;
    f=c+d;
    if(e>f)printf("Left\n");
    if(f>e)printf("Right\n");
    if(e==f)printf("Balanced\n");
    return 0;

}


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

int main()
{
  int N, M, Q;
  scanf("%d%d%d", &N, &M, &Q);

  int sum[N+1][N+1];
  fill(sum[0],sum[N+1],0);

  int l, r;
  for(int i = 0; i < M; ++i){
    scanf("%d%d", &l, &r);
    ++sum[l][r];
  }

  for(int i = 1; i <= N; ++i){
    for(int j = 1; j <= N; ++j){
      sum[i][j] += sum[i-1][j] + sum[i][j-1] - sum[i-1][j-1];
    }
  }
  
  int p, q;
  for(int i = 0; i < Q; ++i){
    scanf("%d%d", &p, &q);
    printf("%d\n", sum[q][q] - sum[p-1][q] - sum[q][p-1] + sum[p-1][p-1]);
  }
}

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

int main(){
    int v[110];
    int a;scanf("%d",&a);
    for(int i=0;i<a;i++)
        scanf("%d",v+i);
    std::sort(v,v+a);
    double res=(v[0]+v[1])/2.0;
    for(int i=2;i<a;i++){
        res=(res+v[i])/2.0;
    }
    printf("%.12f\n",res);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  int n, a[55], mxa = 0, mna = 0, i, k;
  scanf("%d", &n);
  for(i = 0; i < n; i++){
    scanf("%d", &a[i]);
    if(a[mxa] < a[i]) mxa = i;
    if(a[mna] > a[i]) mna = i;
  }
  k = a[mxa] + a[mna] > 0 ? mxa : mna;
  
  if(a[mxa] > 0 && a[mna] < 0){
    printf("%d\n", 2*(n-1));
    for(i = 0; i < n; i++){
      if(i == k) continue;
      printf("%d %d\n", k+1, i+1);
    }
  }else printf("%d\n", n-1);
  
  if(a[k] > 0) for(i = 1; i < n; i++) printf("%d %d\n", i, i+1);
  else for(i = n-1; i > 0; i--) printf("%d %d\n", i+1, i);
}

Measured memory_bytes: 256
#!usr/bin/env python3
from collections import defaultdict, deque, Counter, OrderedDict
from bisect import bisect_left, bisect_right
from functools import reduce, lru_cache
from heapq import heappush, heappop, heapify

import itertools, bisect
import math, fractions
import sys, copy

def L(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline().rstrip())
def SL(): return list(sys.stdin.readline().rstrip())
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return [list(x) for x in sys.stdin.readline().split()]
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def LIR1(n): return [LI1() for _ in range(n)]
def SR(n): return [SL() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
def LR(n): return [L() for _ in range(n)]

def perm(n, r): return math.factorial(n) // math.factorial(r)
def comb(n, r): return math.factorial(n) // (math.factorial(r) * math.factorial(n-r))

alphabets = "abcdefghijklmnopqrstuvwxyz"
ALPHABETS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

sys.setrecursionlimit(1000000)
dire = [[1, 0], [0, 1], [-1, 0], [0, -1]]
dire8 = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]]
MOD = 1000000007
INF = float("inf")

def main():
    N, K = LI()

    if (N == 2 and K == 0):
        print(1)
        print(1, 2)
        return

    if ((N-1 < 2) or comb(N-1, 2) < K):
        print(-1)
        return
    maxpairs = comb(N-1, 2)

    edges = [[] for _ in range(N)]
    edges[0] = list(range(1, N))

    pairs = list(itertools.combinations(range(1, N), 2))

    for _ in range(maxpairs - K):
        a, b = pairs.pop()
        edges[a].append(b)

    ans = []
    for a in range(N):
        for b in edges[a]:
            ans.append((a+1, b+1))

    print(len(ans))
    for a, b in ans:
        print(a, b)

if __name__ == '__main__':
    main()

Measured memory_bytes: 79748
#include<bits/stdc++.h>
#define pb push_back
using namespace std;
const int B=716070898,mod=998244353,N=5e5+50;
int n,m,pw[N],sum[3][N],mx,f[N],ans;bool vis[N];
vector<int>v[N];
void init(int id){
    scanf("%d",&m);
    for(int i=1;i<=n;i++)v[i].clear();
    for(int i=1,x,y;i<=m;i++){
        scanf("%d%d",&x,&y);
        if(x>y)swap(x,y);v[x].pb(y);
    }
    for(int i=n;i;i--){
        for(int j=0;j<v[i].size();j++)vis[f[v[i][j]]]=1;
        for(int j=0;;j++)if(!vis[j]){f[i]=j;break;}
        for(int j=0;j<v[i].size();j++)vis[f[v[i][j]]]=0;
        (sum[id][f[i]]+=pw[i])%=mod;mx=max(mx,f[i]);
    }
}
int main(){
    scanf("%d",&n);pw[0]=1;
    for(int i=1;i<=n;i++)pw[i]=1ll*pw[i-1]*B%mod;
    init(0);init(1);init(2);
    for(int i=0;i<=mx;i++)for(int j=0;j<=mx;j++)
        ans=(ans+1ll*sum[0][i]*sum[1][j]%mod*sum[2][i^j])%mod;
    cout<<ans;
    return 0;
}

Measured memory_bytes: 23424
#include <iostream>
#include <iomanip>
#include <bits/stdc++.h>
#include <vector>
#include <iterator>
#include <string>
#define pan(i,n) for(int i=0;i<n;i++)
#define ll long long int
#define vi vector<int>
#define pb push_back
#define INF 1e9+7
#define PI 3.141592653
using namespace std;
 


int main() 
{ 
    double n,k;
    cin>>n>>k;
    double ans=0;
    for(int i=1;i<=n;i++){
        double score=i;
        int count=0;
        while(score<k){
            score*=2;
            count++;
        }
        // cout<<count<<endl;
        ans+=pow(0.5,count);
    }
    ans=ans/n;
    cout<<fixed<<setprecision(12)<<ans;
} 


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<tuple>
#define int long 
using namespace std;

signed main() {
	string S;
	cin >> S;
	bool A = false;
	bool B = false;
	bool C = false;
	bool D = false;
	for(int i = 0;i < S.size();i++) {
		if(S.at(i) == 'N') {
			A = true;
		}
		if(S.at(i) == 'W') {
			B = true;
		}
		if(S.at(i) == 'S') {
			C = true;
		}
		if(S.at(i) == 'E') {
			D = true;
		}
	}
	if(A == true && B == true && C == true && D == true) {
		cout << "Yes" << endl;
	}
	else if(A == true && B == false && C == true && D == false) {
		cout << "Yes" << endl;
	}
	else if(A == false && B == true && C == false && D == true) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
    int A[1024], N;
    int i, j, tmp;

    //input data
    scanf("%d", &N);

    for(i=0; i<N; i++) scanf("%d", &A[i]);
    for(j=0; j<N-1; j++){
        printf("%d ", A[j]);
    }
    printf("%d\n", A[j]);


    //insertion sort
    for(i=1; i<N; i++){
        tmp = A[i];
        j = i-1;

        while(j>=0 && A[j]>tmp){
            A[j+1] = A[j];
            j--;
        }

        A[j+1] = tmp;

        for(j=0; j<N-1; j++){
            printf("%d ", A[j]);
        }
        printf("%d\n", A[j]);
    }
        
}



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

//// < "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\b.txt"
struct tv {
	string name;
	int time;
};
int main() {
	while (1) {
		int N; cin >> N; 
		if (!N)break;
		vector<tv>tvs;
		vector<int>needs;
		for (int i = 0; i < N; ++i) {
			string name; int w, s; cin >> name >> w >> s;
			int time = w * 1440 + (s / 100) * 60 + s % 100;
			tvs.push_back(tv{ name,time });
		}
		sort(tvs.begin(), tvs.end(), [](const tv&l, const tv&r) {
			return l.time < r.time;
		});
		for (int i = 0; i < N; ++i) {
			tv atv{ tvs[i].name,tvs[i].time + 1440 * 7 };
			tvs.emplace_back(atv);
		}
		int P; cin >> P;
		for (int i = 0; i < P; ++i) {
			string target; cin >> target;
			auto it = find_if(tvs.begin(), tvs.end(), [=](const tv&t) {
				return t.name == target;
			});
			needs.push_back(it - tvs.begin());
		}
		sort(needs.begin(), needs.end());
		needs.push_back((*needs.begin())+N);
		bool ok = true;
		int ans = P;
		for (int i = 0; i < needs.size()-1; ++i) {
			int from = tvs[needs[i]].time + 30;
			int to = tvs[needs[i + 1]].time;
			if (to < from)ok = false;
			else {
				int sum = 0;
				for (int p = needs[i] + 1; p < needs[i + 1]; ++p) {
					if (from <= tvs[p].time&&tvs[p].time + 30 <= to) {
						sum++;
						from = tvs[p].time + 30;
					}
				}
				ans += sum;
			}
			
		}
		if (!ok)cout << -1 << endl;
		else {

			cout << ans << endl;
		}

	}
	return 0;
}

Measured memory_bytes: 3128
#include <stdio.h>
int main(){
  int n,x,t,a,b,c;

  while(1){
    scanf("%d %d",&n,&x);    
    if ( n == 0 && x == 0 ) break;
    t=0; 
    for(a=1;a<=n;a++){
      for(b=1;b<=n;b++){
	for(c=1;c<=n;c++){
	  if(a<b&&b<c){
	    if(a+b+c==x){
	      ++t;
	    }
	  }
	}
      }
    }
    printf("%d\n",t);
  }

  return 0;
}

Measured memory_bytes: 1028
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
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;}
#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> l_l;
typedef pair<int,int> i_i;
const ll MOD=1e9+7;
const int INF=1<<30;

int main(){
  string S;
  cin >> S;
  if(S=="keyence"){
    cout << "YES" << endl;
    return 0;
  }
  int l=S.size();
  rep(i,l){
    for(int j=i;j<l;j++){
      string T;
      for(int k=0;k<l;k++){
        if(k>=i&&k<=j) continue;
        else{
          T.push_back(S[k]);
        }
      }
      if(T=="keyence"){
        cout << "YES" << endl;
        return 0;
      }
    }
  }
  cout << "NO" << endl;
}

Measured memory_bytes: 256
import heapq
def main():
    n,m=map(int, input().split()) 
    a = list(map(lambda x: int(x)*(-1), input().split())) 
    heapq.heapify(a)

    for i in range(m):
        tmp_min = heapq.heappop(a)
        heapq.heappush(a, -1*(-tmp_min//2))
    print(-sum(a))

if __name__ == '__main__':
    main()

Measured memory_bytes: 14180
from collections import defaultdict
from itertools import combinations
N = int(input())
counter = defaultdict(int)
for i in range(N):
    head = input()[0]
    if head not in ('M', 'A', 'R', 'C', 'H'):
        continue
    counter[head] += 1
if len(counter) < 3:
    print(0)
else:
    count = 0
    for v in combinations(counter.values(), 3):
        count += v[0] * v[1] * v[2]
    print(count)


Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
using namespace std;
typedef long long ll;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	vector<ll> A(n);
	rep(i, n) cin >> A[i];

	sort(all(A));

	int k = 0;
	int ans = 0;
	for (int i = 1; i < n; ++i) {
		if (A[i] == A[i - 1]) k++;
		else {
			k++;
			if (k % 2 != 0) ans++;
			k = 0;
		}
		if (i == n - 1) {
			if (A[i] == A[i - 1]) {
				k++;
				if (k % 2 != 0) ans++;
			}
			else {
				ans++;
			}
		}
	}

	dunk(ans);

	return 0;
}


Measured memory_bytes: 1024