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

#define loop(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < n; ++i)
#define dump(a) cerr << #a << " = " << (a) << "(L:" << __LINE__ << ")" << endl

const string YES = "Possible";
const string NO = "Impossible";

void solve(long long N, long long L, std::vector<long long> a) {
    long long sum = accumulate(a.begin(), a.end(), 0LL);
    int i = 0, j = N - 2;
    vector<int> ans;
    while (i != j) {
        int x = a[i] + a[i + 1];
        int y = a[j] + a[j + 1];
        if (sum < L) {
            cout << NO << endl;
            return;
        }
        if (x < y) {
            ans.push_back(i);
            sum -= a[i];
            i++;
        } else {
            ans.push_back(j);
            sum -= a[j + 1];
            j--;
        }
    }
    if (a[i] + a[i + 1] < L) {
        cout << NO << endl;
        return;
    }
    ans.push_back(i);

    cout << YES << endl;
    rep(i, ans.size()) { cout << ans[i] + 1 << endl; }
}

int main() {
    long long N;
    scanf("%lld", &N);
    long long L;
    scanf("%lld", &L);
    std::vector<long long> a(N);
    for (int i = 0; i < N; i++) {
        scanf("%lld", &a[i]);
    }
    solve(N, L, std::move(a));
    return 0;
}


Measured memory_bytes: 4716
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <inttypes.h>
#include <time.h>

using namespace std;

typedef long long tnum;

#define loop(i, num) for(int i = 0; i < num; i++)

tnum* tnumAlloc(int num);
tnum scanNum();
int scanInt();
tnum* scanNums(int);
char* scanChars(int maxlength);
string scanString();
void printlnNums(int count, tnum* nums);
void printlnNum(tnum num);
void printString(string str);

#define min(a,b) (a <= b ? a : b)
#define max(a,b) (a >= n ? a : b)

#define concatVectors(dest, src) dest.insert(dest.end(), src.begin(), src.end());

int main() {
    tnum a = scanNum();
    tnum b = scanNum();
    tnum c = scanNum();
    tnum d = scanNum();
 
    tnum p1 = a * c;
    tnum p2 = b * d;
    tnum p3 = a * d;
    tnum p4 = b * c;
 
    tnum max = -9223372036854775807;
 
    if(p1 > max){
        max = p1;
    }
    if(p2 > max){
        max = p2;
    }
    if(p3 > max){
        max = p3;
    }
    if(p4 > max){
        max = p4;
    }
 
    printlnNum(max);
 
    return 0;
}

//have to be free()
tnum* tnumAlloc(int num) {
	return (tnum*)calloc(num,sizeof(tnum));
}

tnum scanNum() {
	tnum ret;
    cin >> ret;

    return ret;
}

int scanInt() {
	tnum ret;
    cin >> ret;

    return ret;
}

//have to be free()
tnum* scanNums(int num) {
	tnum* buf;
	tnum* tmp;
	buf = tnumAlloc(num);
	for (int i = 0; i < num; i++) {
		cin >> buf[i];
	}

	return buf;
}

//have to be free()
char* scanChars(int maxlength) {
	char* ret = (char*)malloc(maxlength+1);
	scanf("%s", ret);

	return ret;
}

//have to be free()
string scanString() {
	string ret;
	cin >> ret;
	return ret;
}

void printlnNum(tnum num) {
    cout << num << endl;
}

// can be used for debugging
void printlnNums(int count, tnum *nums) {
	loop(i, count) {
		cout << nums[i];
		if (i != count - 1) printf(" ");
	}
	printf("\n");
}

void printString(string str) {
	cout << str;
}


Measured memory_bytes: 3628
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <cstring>
#include <cmath>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const int MAX = 200100;
int BIT[MAX];
void add(int i, int n) {
  while (i < MAX) {
    BIT[i] += n;
    i += i & -i;
  }
}
int sum(int i) {
  int res = 0;
  while (i > 0) {
    res += BIT[i];
    i -= i & -i;
  }
  return res;
}
void clear() {
  for (int i = 1; i < MAX; i++)
    BIT[i] = 0;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  int l = 0, r = 1e9;
  const ll all = (n+1)*n/2;
  while (r-l > 1) {
    int mid = (l+r)/2;
    vector<int> b(n), s(n+1);
    rep(i, n) b[i] = (a[i]<=mid ? 1 : -1);
    rep(i, n) s[i+1] = s[i]+b[i];
    rep(i, n+1) s[i] += n+1;
    add(s[0], 1);
    ll num = 0;
    for (int i = 1; i <= n; i++) {
      num += sum(s[i]-1);
      add(s[i], 1);
    }
    clear();
    if (num >= all/2+1)
      r = mid;
    else
      l = mid;
  }
  cout << r << endl;
  return 0;
}

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

int main(){

    int x,n,p;
    int flags[105]={0};
    int dist = 0;
    scanf("%d %d",&x,&n);
    for(int i=0;i<n;i++){
        scanf("%d",&p);
        flags[p] = 1;
    }
    int left, right;
    while(true){
        left = x-dist;
        right = x+dist;
        if(left <= 0 || !flags[left]){
            printf("%d\n",left);
            break;
        }else if(!flags[right]){
            printf("%d\n",right);
            break;
        }
        dist++;
    }
    return 0;
}

Measured memory_bytes: 3824
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
lli mod=1000000007;

int main() {
	ios_base::sync_with_stdio(false); 
	cin.tie(NULL);
	cout.tie(NULL);
	lli x,y,a,b,c;
	cin>>x>>y>>a>>b>>c;
	lli red[a],green[b],colorless[c];
	for(lli i=0;i<a;++i)
		cin>>red[i];
	for(lli i=0;i<b;++i)
		cin>>green[i];
	for(lli i=0;i<c;++i)
		cin>>colorless[i];
	priority_queue<lli, vector<lli>, greater<lli> > pq;
	sort(red,red+a);
	sort(green,green+b);
	sort(colorless,colorless+c);
	lli ans=0;
	for(lli i=0;i<x;++i){
		pq.push(red[a-1-i]);
		ans+=red[a-1-i];
	}
	for(lli i=0;i<y;++i){
		pq.push(green[b-1-i]);
		ans+=green[b-1-i];
	}
	for(lli i=0;i<min(x+y,c);++i){
		if(colorless[c-i-1]<=pq.top())
			break;
		ans-=pq.top();
		ans+=colorless[c-i-1];
		pq.pop();
		pq.push(colorless[c-i-1]);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 4852
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)n;i++)
int main() {
  int W,H,N,x,y,a; cin>>W>>H>>N;
  int ans[W][H]={0};
  
  for(int i=0; i<N; i++){
    cin>>x>>y>>a;
    if(a==1){
      for(int j=0; j<x; j++){
        for(int k=0; k<H; k++) ans[j][k]=1;
      }       
    }
    else if(a==2){
      for(int j=x; j<W; j++){
        for(int k=0; k<H; k++) ans[j][k]=1;
      }
    }
    else if(a==3){
      for(int j=0; j<W; j++){
        for(int k=0; k<y; k++) ans[j][k]=1;
      }
    }
    else{
      for(int j=0; j<W; j++){
        for(int k=y; k<H; k++) ans[j][k]=1;
      }
    }
  }
  int cnt=0;
  rep(i,W){
    rep(j,H) if(!ans[i][j]==1) cnt++;
  }
  cout<<cnt;
}

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

int main(void){
    const int inf = 1000000000;

    int n, m;
    cin >> n >> m;
    int a[1000], b[1000], c[1000], dist[100][100];

    for(int i = 0; i < m; i++){
        cin >> a[i] >> b[i] >> c[i];
        a[i]--; b[i]--;
    }

    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            if(i == j)
                dist[i][j] = 0;
            else
                dist[i][j] = inf;
        }
    }

    for(int i = 0; i < m; i++){
        dist[a[i]][b[i]] = min(dist[a[i]][b[i]], c[i]);
        dist[b[i]][a[i]] = min(dist[b[i]][a[i]], c[i]);
    }

    for(int k = 0; k < n; k++){
        for(int i = 0; i < n; i++){
            for(int j = 0; j < n; j++){
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
            }
        }
    }

    int ans = m;
    for(int i = 0; i < m; i++){
        bool shortest = false;
        for(int j = 0; j < n; j++){
            if(dist[j][a[i]] + c[i] == dist[j][b[i]]) shortest = true;
        }

        if(shortest == true) ans--;
    }

    cout << ans << endl;

    return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <deque>
using namespace std;
using P = pair<int,int>;
typedef long long int ll;
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)

int main(){ 
  int n; cin >>n;
  vector<int>a(n);
  rep(i,n)cin>>a[i],a[i]--;
  int ans=0;
  rep(i,n){
    if(a[a[i]]==i)ans++;
  }
  cout << ans/2 << endl;
  return 0;
}




Measured memory_bytes: 640
#include<bits/stdc++.h>
#define fastio 	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long int
using namespace std;
int mod = 1e9 + 7;

int32_t main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	fastio;

	int n, k;
	cin >> n >> k;
	int p[n + 1], c[n + 1];
	for (int i = 1; i <= n; i++)
		cin >> p[i];
	for (int i = 1; i <= n; i++)
		cin >> c[i];
	bool vis[n + 1];
	int ans = INT_MIN;
	for (int i = 1; i <= n; i++) {
		memset(vis, false, sizeof vis);
		vector<int> pre;
		int curr = i;
		int sum = 0;
		while (!vis[curr]) {
			vis[curr] = true;
			pre.emplace_back(sum += c[curr]);
			curr = p[curr];
		}
		int len = pre.size();
		int t = k / len, m = k % len;
		for (int j = 2; j < len; j++)
			pre[j] = max(pre[j - 1], pre[j]);
		if (t >= 1) {
			ans = max(ans, pre[len - 1] - pre[0]);
			ans = max(ans, pre[m] - pre[0] + t * sum);
			ans = max(ans, pre[len - 1] - pre[0] + (t - 1) * sum);
		} else {
			ans = max(ans, pre[m] - pre[0]);
		}
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 3796
#include <stdio.h>
int main(void){
	int n,m,x,y;
	scanf("%d%d",&n,&m);
	int i;
	int box[100009];
	box[1]=(n+1)+1;
	for(i=2;i<n+1;i++){
		box[i]=1;
	}
	for(i=0;i<m;i++){
		scanf("%d%d",&x,&y);
		box[x]-=1;
		box[y]+=1;
		if(box[x]>=n+1&&box[y]<n+1){
			box[y]+=n+1;
		}
		if(box[x]%(n+1)==0){
			box[x]=0;
		}
	}
	int count=0;
	for(i=1;i<n+1;i++){
		if(box[i]>=n+1){
			count+=1;
		}
	}
	printf("%d\n",count);
	return 0;
}

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

int main() {
	int a, b;
	cin >> a>> b;
	b = b-1;
	a = a-1;
	int n;
	if (b%a != 0) {
		n = b/a + 1;
	} else {
		n = b/a;
	}
	cout << n << endl;
	return 0;
}

Measured memory_bytes: 384
#include <iostream>

using namespace std;
const long long MAXN = 200010;
long long pref[MAXN];
long long sum;
long long arr[MAXN];
long long ans = 1e18;
int main(){
    long long n;
    cin>>n;
    for(long long i=1;i<=n;i++){
        cin>>arr[i];
        pref[i] = pref[i-1]+arr[i];
    }
    for(long long i=n;i>=2;i--){
        sum+=arr[i];
        ans = min(ans,abs(sum-pref[i-1]));
    }
    cout<<ans<<endl;
}


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

int main(){
    int n; ll k; cin >> n >> k;
    int a[n]; rep(i,n) cin >> a[i];
    ll cur[n]; //Aにおけるa[i]以下の数の個数
    ll tur = 0; //Aにおける転倒数
    rep(i,n-1){
        for(int j = i + 1; j < n; j++){
            if(a[i] > a[j]) tur++;
        }
    }
    rep(i,n) cur[i] = 0;
    rep(i,n){
        rep(j,n){
            if(i != j && a[i] > a[j]){
                cur[i]++;
            }
        }
    }
    ll ans = 0;
    rep(i,n){
        ans += cur[i]%MOD;
        ans %= MOD;
    }
    ans *= (k*(k-1)/2)%MOD;
    ans %= MOD;
    ans += tur%MOD*k%MOD;
    ans %= MOD;
    cout << ans << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using static MyIO;


public class C
{
	public static void Main()
	{
		char[] s = GetString().ToCharArray();
		int N = s.Length;
		int[] a = new int[N];
		for(int i = 0; i < N; i++)
			a[i] = (int)(s[i] - 'a');

		int K = GetInt();
		int rest = K;
		for(int i = 0; i < N; i++)
		{
			int diff = (26 - a[i]) % 26;
			if(diff <= rest)
			{
				a[i] = 0;
				rest -= diff;
			}
		}
		a[N - 1] = (a[N - 1] + rest) % 26;

		char[] c = new char[N];
		for(int i = 0; i < N; i++)
			c[i] = (char)(a[i] + 'a');
		Console.WriteLine(new String(c));
	}
}


public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt(){ return int.Parse(getArg()); }
	public static long GetLong(){ return long.Parse(getArg()); }
	public static double GetDouble(){ return double.Parse(getArg()); }
	public static string GetString(){ return getArg(); }
}


Measured memory_bytes: 13340
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 1000000000
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;




int main(){

    string s;
    getline(cin,s);
    
    for(int i = 0;i < s.length();i++){

        if(s[i] == 'a' && s.substr(i+1,4) == "pple"){
            s.replace(i,5,"peach");
        }else if(s[i] == 'p' && s.substr(i+1,4) == "each"){
            s.replace(i,5,"apple");
        }
    }
    cout << s << endl;



    return 0;

}


Measured memory_bytes: 3144
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Console = System.Console;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var nmxy = ReadIntArray();
            var condX = ReadIntArray().Max();
            var condY = ReadIntArray().Min();
            for (int i = nmxy[2] + 1; i <= nmxy[3]; i++)
            {
                if (condX < i &&
                    condY >= i)
                {
                    Console.WriteLine("No War");
                    return;
                }
            }

            Console.WriteLine("War");
        }
        private static readonly Func<string> Read = () => Console.ReadLine();
        private static readonly Func<string[]> ReadStringArray = () => Console.ReadLine().Split();
        private static readonly Func<int> ReadInt = () => int.Parse(Console.ReadLine());
        private static readonly Func<long> ReadLong = () => long.Parse(Console.ReadLine());
        private static readonly Func<int[]> ReadIntArray = () => Console.ReadLine().Split().Select(int.Parse).ToArray();
        private static readonly Func<long[]> ReadLongArray = () => Console.ReadLine().Split().Select(long.Parse).ToArray();
        private static readonly Action<string> Cw = str => Console.WriteLine(str);
    }
}

Measured memory_bytes: 13396
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#define MAX(X, Y) (((X) > (Y))? (X) : (Y))
#define MIN(X, Y) (((X) < (Y))? (X) : (Y))
int compare_int(const void *a, const void *b){
  return *(long int*)b - *(long int*)a; // 大きい順
}
int compare_int_small(const void *a, const void *b){
  return *(long int*)a - *(long int*)b; // 小さい順
}
// 公約数
long int gcd(long int a, long int b){
  if(b == 0){
    return a;
  }else{
    return gcd(b, a % b);
  }
}
// 最小公倍数 = a * b / 最大公約数
// 公倍数
long int lcm(long int a, long int b){
  return a * b / gcd(a, b);
}

// 30min
int main(void){
  int n, l;
  long int sum = 0;
  int a = 0;
  scanf("%d%d", &n, &l);

  // N個の総和を求める
  for(int i = 0; i < n; i++){
    sum += (l + i);
  }

  // 絶対値が小さい数を求める
  // Lが正ならりんご1つ目の時
  if(l >= 0){
    a = l + 1 - 1;
  }else{
    // L が負ならNの最大の時
    if(l + n <= 0){
      a = l + n - 1;
    }else{ // もしくは、0の時
      a = 0;
    }
  }

  printf("%ld\n", sum - a);

  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n, s) for (int i = (s); i < (n); i++)
#define MOD 1000000007
typedef long long ll;
using namespace std;
using Graph = vector<vector<int>>;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string Sd, T;
    cin >> Sd >> T;
    int N_Sd = Sd.size();
    int N_T = T.size();
    bool isFit;
    vector<string> candidate;
    rep(i, N_Sd - N_T + 1)
    {
        isFit = true;
        rep(j, N_T)
        {
            if (Sd[i + j] != T[j] && Sd[i + j] != '?')
            {
                isFit = false;
                break;
            }
        }
        if (isFit)
        {
            string S_c = Sd;
            S_c.replace(S_c.begin() + i, S_c.begin() + i + N_T, T);
            replace(S_c.begin(), S_c.end(), '?', 'a');
            candidate.pb(S_c);
        }
    }

    if (candidate.size() > 0)
    {
        sort(candidate.begin(), candidate.end());
        cout << candidate[0] << endl;
    }
    else
    {
        cout << "UNRESTORABLE" << endl;
    }
    //system("pause");
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    map<string,int>mp;
    vector<string>v1,v2;
    string s;
    for(int i=0;i<n;i++)
    {
        cin>>s;
        if(mp[s]==0) v1.push_back(s);
        mp[s]++;
    }
    int mx=0;
    for(int i=0;i<v1.size();i++)
    {
        mx=max(mx,mp[v1[i]]);
    }
    for(int i=0;i<v1.size();i++)
    {
        if(mp[v1[i]]==mx)
            v2.push_back(v1[i]);
    }
    sort(v2.begin(),v2.end());
    for(int i=0;i<v2.size();i++)
    {
        cout<<v2[i]<<endl;
    }

}


Measured memory_bytes: 37428
from time import time

def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    a = [0 for i in range(N)]
    for i in A:
        a[i-1] += 1

    a.sort(reverse=True)
    a = a[K:]
    print(sum(a))

if __name__ == '__main__':
    start = time()
    main()
    # print(time() - start)


Measured memory_bytes: 25856
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#define pb push_back
#define mod 1000000007
using namespace std;
typedef long long int ll;

int main(void){
  int a,b,c;
  cin>>a>>b>>c;
  if(b-a==c-b) cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
  return 0;
}


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

int main(){
    char s[101];
    long long k;
    scanf("%s",s);
    scanf("%lld",&k);
    int i=0,l=strlen(s);
    while(i<l&&s[i]=='1'){
        i++;
    }
    if(l==1){
        printf("%c",s[0]);
        return 0;
    }
    if(i>=k){
        printf("1");
        return 0;
    }
    printf("%c",s[i]);
    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

int main(void){
  int r, g, b, a;

  scanf("%d %d %d", &r, &g, &b);

  a = 100*r + 10*g + b;

  if (a % 4 == 0) {
    printf("YES\n");
  }
  else {
    printf("NO\n");
  }

  return 0;
}

Measured memory_bytes: 128
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
from math import gcd
g = 0
ans = 1
for _ in range(N):
    t = int(input())
    g = gcd(t, ans)
    ans = t*ans//g
print(ans)

Measured memory_bytes: 62108
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define MOD1 1000000007
#define MOD2 998244353
#define LIMIT1 200002
#define LIMIT2 500002
typedef long long ll;
typedef long double ld;
typedef const void cv;
#define rep(i,n) for((i)=0;(i)<(n);(i)++)
#define per(i,n) for((i)=(n)-1;(i)>=0;(i)--)
#define max(a,b) ((a)>(b) ? (a) : (b))
#define min(a,b) ((a)<(b) ? (a) : (b))
#define zt(a,b) (max((a),(b))-min((a),(b)))
#define absl(v) labs((v))
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll nPr(int n,int r){ll i,result=1;rep(i,r){result*=(ll)(n-i);}return result;}
ll nCr(int n,int r){ll i,result=1;if(n<r) return 0;rep(i,min(r,n-r)){result*=(ll)(n-i);result/=(ll)(i+1);}return result;}
#define nHr(n,r) nCr((int)((n)+(r)+1),(int)(r))
#define sankaku(x) (((x)*((x)+1))/2)
int dx[8]={1,0,-1,0,1,-1,-1,1},dy[8]={0,1,0,-1,1,1,-1,-1};
int upint(cv *a, cv *b) { return *(int *)a < *(int *)b ? -1 : *(int *)a > *(int *)b ? 1 : 0; }
int downint(cv *a, cv *b) { return *(int *)a < *(int *)b ? 1 : *(int *)a > *(int *)b ? -1 : 0; }
int upchar(cv *left, cv *right) {return strcmp((char *)left,(char *)right);}
int downchar(cv *left, cv *right) {return strcmp((char *)right,(char *)left);}
void tmpInit(int *c,ll m) {ll i;rep(i,m) c[i]=i;}
ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1){
      res *= a; if(mod>=1) res %= mod;
    }
    a *= a; if(mod>=1) a %= mod;
    n >>= 1;
  }
  return res;
}
void initialize(){
  
}
int main(void){
  initialize();
  ll n,m,i,j,k,result=0;
  int a[LIMIT2]={0},b[LIMIT1]={0};
  char s[LIMIT1];
  
  scanf("%lld",&n);
  rep(i,n) scanf("%d %d",&a[i],&b[i]);
  
  qsort(a,n,sizeof(int),upint);
  qsort(b,n,sizeof(int),upint);
  
  if(n%2==1){
    result = (ll)b[n/2]-(ll)a[n/2]+1;
  }else{
    result = ((ll)b[n/2]+(ll)b[n/2-1]-(ll)a[n/2]-(ll)a[n/2-1])+1;
    //printf("%d %d %d %d\n",a[n/2-1],a[n/2],b[n/2-1],b[n/2]);
  }
  
  printf("%lld",result);
  return 0;
}

Measured memory_bytes: 5164
#include<bits/stdc++.h>
using namespace std;
string to_string(const string& s) {
	return '"' + s + '"';
}
string to_string(const bool b) {
	return (b ? "true" : "false");
}
string to_string(const char* s) {
	return to_string((string)s);
}
string to_string(const char c) {
	string s = "'";
	s += c;
	s += "'";
	return s;
}
template<class T, class U>
string to_string(const pair<T, U>& p) {
	string s = "(";
	s += to_string(p.first);
	s += ", ";
	s += to_string(p.second);
	s += ")";
	return s;
}
template<class T>
string to_string(const T& a) {
	bool first = true;
	string s = "{";
	for (const auto& x : a) {
		if(!first){
			s += ", ";
		}
		first = false;
		s += to_string(x);
	}
	s += "}";
	return s;
}
void debug_out() {cerr << '\n';}
template<class Head, class... Tail>
void debug_out(Head head, Tail... tail) {
	cerr << ' ' << to_string(head);
	debug_out(tail...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "] = ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif
using ll = long long;
using ld = long double;
const int mod = 1e9 + 7;
const int inf = 1e9 + 100;
const ll inf64 = 7e18l;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(20);
	ll a, b, k;
	cin >> a >> b >> k;
	ll  mn = min(a, k);
	a -= mn;
	k -= mn;
	mn = min(b, k);
	b -= mn;
	k -= mn;
	cout << a << ' ' << b << '\n';
	return 0;
}


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

int a, b, c, d, e, f;

int main (){
	cin >> a >> b >> c >> d;
	e= a*b;
	f= c*d;
	if(e>f) cout << e << endl;
	else if(f>e) cout << f << endl;
	else cout << e << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int N, M;
vector<vector<int>> chi;
vector<int> nPar;
vector<int> dist;
vector<int> ans;

void dfs(int n){
    if(chi[n].size()==0) return;

    int nChi = chi[n].size();
    for(int i=0; i<nChi; i++){
        int nxt = chi[n][i];
        nPar[nxt]--;
        if(dist[nxt] < dist[n] + 1){
            ans[nxt] = n;
            dist[nxt] = dist[n] + 1;
        }
        if(nPar[nxt]==0) dfs(nxt);
    }
}

int main(){
    cin >> N >> M;
    chi = vector<vector<int>>(N+1, vector<int>());
    nPar = vector<int>(N+1,0);
    for(int i=0; i<N+M-1; i++){
        int A, B;  cin >> A >> B;
        chi[A].push_back(B);
        nPar[B]++;
    }
    
    vector<bool> rootCand(N+1, true);
    for(int i=1; i<=N; i++){
        int nChi = chi[i].size();
        for(int j=0; j<nChi; j++) rootCand[chi[i][j]]=false;
    }
    int root;
    for(int i=1; i<=N; i++) if(rootCand[i]) root = i;
    
    dist = vector<int>(N+1, 0);
    ans = vector<int>(N+1, 0);
    ans[root] = 0;
    dfs(root);
    for(int i=1; i<=N; i++){
        cout << ans[i] << endl;
    }
}


Measured memory_bytes: 12160
import sys

if __name__ == "__main__":
    (X, Y, Z, K) = list(map(int, sys.stdin.readline().split()))
    A = list(map(int, sys.stdin.readline().split()))
    B = list(map(int, sys.stdin.readline().split()))
    C = list(map(int, sys.stdin.readline().split()))

    A.sort(reverse=True)
    B.sort(reverse=True)
    C.sort(reverse=True)
    v = []
    for a in range(len(A)):
        for b in range(len(B)):
            if (a + 1) * (b + 1) > K:
                break
            for c in range(len(C)):
                if (a + 1) * (b + 1) * (c + 1) > K:
                    break
                v.append(A[a] + B[b] + C[c])

    v.sort(reverse=True)

    for i in range(K):
        sys.stdout.write("%d\n" % v[i])

Measured memory_bytes: 8708
import itertools
from collections import deque
from sys import stdin
input = stdin.readline


def main():
  H, W = list(map(int, input().split()))

  M = [input()[:-1] for _ in range(H)]

  def bfs(start):
    dist = [[float('inf')]*W for _ in range(H)]
    dist[start[0]][start[1]] = 0

    is_visited = [[0]*W for _ in range(H)]
    is_visited[start[0]][start[1]] = 1

    q = deque([start])
    max_ = 0

    while len(q):
      now_h, now_w = q.popleft()
      if M[now_h][now_w] == '#':
        return
      for next_h, next_w in ((now_h+1, now_w),
                             (now_h-1, now_w),
                             (now_h, now_w-1),
                             (now_h, now_w+1)):

        if not(0 <= next_h < H) or not(0 <= next_w < W) or \
           (is_visited[next_h][next_w] == 1) or \
           M[next_h][next_w] == '#':
           # (dist[next_h][next_w] != float('inf')) or \
          continue

        dist[next_h][next_w] = dist[now_h][now_w] + 1
        is_visited[next_h][next_w] = 1

        max_ = max(max_, dist[next_h][next_w])
        q.append((next_h, next_w))
    return max_

  max_ = 0
  for h in range(H):
    for w in range(W):
      if M[h][w] == '.':
        max_ = max(bfs((h, w)), max_)

  print(max_)


if(__name__ == '__main__'):
  main()


Measured memory_bytes: 9388
// Ryo Kamoi

#include<iostream>
#include<math.h>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<queue>

using namespace std;

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

typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;

int INF = 1000000000;

int n;
vector<int> b;
vector<int> ans;

int main(){
    cin >> n;
    REP(i, n) {
        int bi;
        cin >> bi;
        b.push_back(bi);
    }

    REP(i, n) {
        bool flag = false;
        REP(j, b.size()) {
            int idx= b.size()-j-1;
            if (b[idx] == idx+1) {
                ans.push_back(b[idx]);
                b.erase(b.begin()+idx);
                flag = true;
                break;
            }
        }

        if (!flag) {
            cout << -1 << endl;
            return 0;
        }
    }

    REP(i, n) {
        cout << ans[n-i-1] << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int A = 0;
  int B, N, answer = 0;
  cin >> N >> B;
  for(int i = 0; i < N; i++)
  {
    int ballX, shorterDist;
    cin >> ballX;
    shorterDist = ballX;
    if(ballX > (B/2))
    {
      shorterDist = B - ballX;
    }
    answer += shorterDist * 2;
  }
  cout << answer<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,K;
  cin >> N >> K;
  
  vector<int>vec(N);
  
  for(int i=0;i<N;i++){
    cin >> vec.at(i);
  }
  
  sort(vec.begin(),vec.end());
  
  int sum=0;
  for(int i=0;i<K;i++){
    sum+=vec.at(i);
  }
  
  cout << sum << endl;
}


Measured memory_bytes: 3648
use v5.18; # strict say state
use warnings;
use List::Util qw(reduce first max min sum0);

chomp (my $n = <STDIN>);
chomp (my @a = split / /, <STDIN>);
my %h;
$h{$_}++ for @a;
my (%k, %g);
my $sum = 0;
for my $key (keys %h) {
  if ($h{$key} > 1) {
    $k{$key} = $h{$key} * ($h{$key} - 1) / 2;
    $sum += $k{$key};
    $g{$key} = ($h{$key} - 1) * ($h{$key} - 2) / 2;
  }
}
for my $i (0..($n-1)) {
  my $ans = $sum - $k{$a[$i]} + $g{$a[$i]};
  say $ans;
}

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

int main() {

  int n;
  cin >> n;

  vector<int> a(n);

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

  deque<int> b;

  for (int i = 0; i < n; i++) {
    if (i % 2 == 0) {
      b.push_back(a[i]);
    } else {
      b.push_front(a[i]);
    }
  }

  if (a.size() % 2 == 1) {
    while (!b.empty()) {
      cout << b.back() << " ";
      b.pop_back();
    }
  } else {
    while (!b.empty()) {
      cout << b.front() << " ";
      b.pop_front();
    } 
  }
  cout << endl;

  return 0;

}

Measured memory_bytes: 3840
#include <stdio.h>
#include <string>
#include <iostream>
std::string n;
int main(){
	std::cin>>n;
	if(n.size()==1) std::cout<<n<<std::endl;
	else{
		long long s=9*(n.size()-1)+n[0]-'0';
		for(register int i=1;i<n.size();i++) if(n[i]!='9') return printf("%lld\n",s-1),0;
		return printf("%lld\n",s),0;
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N=sc.nextInt();
		sc.close();
		int num=N%10;
		if(num==3)
			System.out.println("bon");
		else if(num==0||num==1||num==6||num==8)
			System.out.println("pon");
		else
			System.out.println("hon");
		
	}
}


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

using namespace std;
#define mp make_pair
#define all(x) (x).begin(), (x).end()
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<vector<int>> vvi;
typedef vector<vector<long long>> vvl;
typedef pair<int,int> pii;
typedef long long ll;

ll expMod(ll a, ll exp, ll mod){
    if(exp == 0) return 1;
    __int128_t pa = expMod(a, exp/2, mod);
    pa = (pa*pa)%mod;
    if(exp%2 == 1) pa = (pa*a)%mod;
    return pa;
}

const ll mod = 1e9 + 7;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    ll ans = 0;
    vl dp(k+1,0);
    for(int i=k;i>=1;i--){
        dp[i] = expMod(k/i, n, mod);
        for(int j = 2*i; j <= k; j += i){
            dp[i] -= dp[j];
            dp[i] %= mod;
        }
        ans += (dp[i]*i)%mod;
        ans %= mod;
    }
    ans = (ans + mod)%mod;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3988
#include<stdio.h>

int main(void)
{
    int n, b, f, r, v;
    int count[4][3][10]={}; 
    int h, i, j, k;
    
    scanf("%d", &n);
    for(h=0; h<n; h++)
    {
        scanf("%d %d %d %d", &b, &f, &r, &v);

        count[b-1][f-1][r-1] += v;
    }

    for(i=0; i<4; i++)
    {
        if(i>0) 
        printf("####################\n");
            
        for(j=0; j<3; j++)
        {
            for(k=0; k<10; k++)
            {
                printf(" %d", count[i][j][k]);
            }
            printf("\n");
        }

    }
    
    
    return 0;
}


Measured memory_bytes: 2676
namespace Test
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    public class Test
    {
        public static void Main(string[] args)
        {
            var t = new Test();
            var s = t.ConvertIntList(t.ReadInput());
            var w = s[0];
            var h = s[1];
            var x = s[2];
            var y = s[3];
            var r = s[4];


            if (w >= x + r && x - r >= 0 && h >= y + r && y - r >= 0)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }

        }

        public string[] ReadInput()
        {
            return Console.ReadLine().Split(' ');
        }


        public List<int> ConvertIntList(string[] x)
        {
            var convertedList = new List<int>(x.Length);
            for (var i = 0; i < x.Length; i++)
            {
                convertedList.Add(int.Parse(x[i]));
            }

            return convertedList;
        }
}
}


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

using namespace std;

#define ll long long

main() {
  ll k;
  string s;
  cin >> s;
  cin >> k;
  int n = s.size();
  int res = -1;
  for (int i = 0; i < n; i++) {
    if (s[i] != '1') {
      break;
    }
    res = i;
  }
  k--;
  if (k <= res) {
    cout << 1;
  } else {
    cout << s[res + 1];
  }
}


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

int n, s, a[200005], b[200005];
vector<int> ans;
int main()
{
	int i, j;
	cin >> n;
	for (i = 1; i <= n; i++) scanf ("%d", &a[i]);
	for (i = n; i >= 1; i--) {
		s = 0;
		for (j = i; j <= n; j += i) {
			s += b[j];
		}
		if (s % 2 != a[i] % 2) {
			b[i] = 1;
			ans.push_back(i);
		}
	}
	cout << ans.size() << endl;
	for (i = ans.size() - 1; i >= 0; i--) printf("%d ", ans[i]);
    return 0;
}


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

int main() {
    int H, W;
    cin >> H >> W;
    int N;
    cin >> N;
    vector<int> As(N);
    for (auto & a : As) cin >> a;
    vector<int> ans;
    for (int i = 0; i != N; ++i){
        for (int j = 0; j != As[i]; ++j){
            ans.push_back(i + 1);
        }
    }
    for (int h = 0; h != H; ++h){
        for (int i = 0; i != W; ++i){
            int w = i;
            if (h & 1) w = W - i - 1;
            cout << ans[h * W + w] << (i == W - 1 ? '\n' : ' ');
        }
    }
    return 0;
}

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

long gcd(long a,long b);

int main(void){
  int n,i;
  long t,s=1,k;
  cin >> n;
  for (i=0;i<n;i++){
    cin >> t;
    k=gcd(s,t);
    s=s/k*t;
  }
  cout << s << endl;
  return 0;
}

long gcd(long a,long b){
  if (a<b) swap(a,b);
  if (a%b==0) return b;
  return gcd(b,a%b);
}

Measured memory_bytes: 256
PROGRAM-ID.                      ABC_026_A.
DATA                             DIVISION.
WORKING-STORAGE                  SECTION.
    01 MAX_A   PIC 9(3) VALUE 999.

    01 N       PIC 9(3).
    01 INP     PIC X(600).
    01 maxlen  PIC 9(3).
    01 cur     PIC 9(3) VALUE 1.
    01 i       PIC 9(18) VALUE 1.
    01 j       PIC 9(18).
    01 len     PIC 9(3).
    01 ans     PIC X(3).

    01 sm      PIC 9(3).
    01 cnt     PIC 9(3).
    01 bk      PIC 9(3).

    01 a       PIC 9(3).

    01 ZS      PIC Z(3)9.
    01 DUMMY   PIC X(1).

PROCEDURE                        DIVISION.
    ACCEPT N.

    ACCEPT INP.

    MOVE N TO maxlen.

    MOVE MAX_A TO bk.

    MOVE 1 TO cnt.

    PERFORM maxlen TIMES

        PERFORM VARYING j FROM cur BY 1
            UNTIL INP(j:1) = SPACE
        END-PERFORM

        COMPUTE len = j - cur

        MOVE INP(cur:len) TO a

        IF bk NOT = a
            DIVIDE 2 INTO cnt
            ADD cnt TO sm
            MOVE 1 TO cnt
            MOVE a TO bk
        ELSE
            ADD 1 TO cnt
        END-IF

        COMPUTE cur = j + 1

        ADD 1 TO i

    END-PERFORM.

    DIVIDE 2 INTO cnt.
    ADD cnt TO sm.

    MOVE sm TO ZS.

    PERFORM UNANS.

    DISPLAY ans(1:FUNCTION STORED-CHAR-LENGTH(ans)).
    STOP RUN.

UNANS                            SECTION.
    UNSTRING
        ZS DELIMITED BY ALL SPACE
        INTO DUMMY ans
    END-UNSTRING.


Measured memory_bytes: 384
word = input()
flag = False
C_count = 0

if word[0] == 'A':
    for i in range(2,len(word)-1):
        if word[i] == 'C' and C_count == 0:
            C_count += 1
            C_place = i
        elif word[i] == 'C' and C_count == 1:
            C_count += 1

    if C_count == 1:
        for i in range(1,len(word)):
            if word[i].isupper() and i != C_place:
                break
            if i == len(word)-1:
                flag = True
if flag:
    print('AC')
else:
    print('WA')

Measured memory_bytes: 9132
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int top, S[1000];
void push(int x){
	S[++top]=x;
}
	
int pop(){
	top--;
	return S[top+1];
}
int main(){
	int a,b;
	top = 0;
	char s[100];
	while(scanf("%s",s) != EOF){
		if(s[0] == '+'){
			a = pop();
			b = pop();
			push(a+b);
		}
		else if(s[0] == '-'){
			b = pop();
			a = pop();
			push(a-b);
		}
		else if (s[0] == '*'){
			a = pop();
			b = pop();
			push(a*b);
		}
		else{
			push(atoi(s));
		}
	}
	
	printf("%d\n", pop());
	
	
	
	
	return 0;
}

Measured memory_bytes: 548
use std::io;
fn main() {
    let mut odd = String::new();
    let mut even = String::new();
    io::stdin().read_line(&mut odd);
    io::stdin().read_line(&mut even);
    let odd = odd.chars();
    let even = even.chars();

    println!("{}",
             odd.zip(even)
                 .fold(String::from(""), |mut c, (o, e)| {
                     c.push(o);
                     c.push(e);
                     c
                 })
                 .trim());
}


Measured memory_bytes: 4352
#include<iostream>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)

const int N = 100010;
int in[N];
int de[N];

int main(){
  int n;
  while(cin>>n){
    rep(i,N)in[i] = 0,de[i] = 0;
    rep(i,n){
      int a,b;
      cin>>a>>b;
      in[a]++;
      de[b+1]++;
    }
    //xテつ人テつづつセテつづδkテつづδ暗つ人テつづつェテつ嘉つステつ人テつづつ「テつづδゥテつづつゥテつづδーテつ静つ氾つづつヲテつづδゥ
    int ans = 0;
    int now = 0;
    rep(i,N){
      now += in[i];
      now -= de[i];
      if (now+1 >= i)ans = i;
      /*
      //if (now >= i)ans = i;
	2
	3 3
	3 3
	テつづδつ療つ偲つづつソテつづδゥ
       */
    }
    if (ans != 0)ans--;
    cout << ans << endl;
  }
}

Measured memory_bytes: 1608
#include <bits/stdc++.h>
#define mid ((l+r)>>1)
using namespace std;
const int maxn=2e5+1;
char s[maxn];
int x[maxn];
int o[maxn],d[maxn];
bool del[maxn];
int n,q,ans;
int cnt[26];

bool clean(){
	for (int k=0;k<26;++k)
	if (cnt[k]!=0) return 0;
	return 1;
}

bool check_l(int pos){
	for (int i=1;i<=q;++i){
		if (o[i]==x[pos])
		pos+=d[i];
		if (pos==0) return 1;
	}
	return 0;
}

bool check_r(int pos){
	for (int i=1;i<=q;++i){
		if (o[i]==x[pos])
		pos+=d[i];
		if (pos==n+1) return 1;
	}
	return 0;
}

void findl(){
	int l=1,r=n,res=0;
	while(l<=r){
		if (check_l(mid)) res=mid,l=mid+1;
		else r=mid-1;
	}
	for (int i=1;i<=res;++i)
	del[i]=1;
}

void findr(){
	int l=1,r=n,res=n+1;
	while(l<=r){
		if (check_r(mid)) res=mid,r=mid-1;
		else l=mid+1;
	}
	for (int i=res;i<=n;++i)
	del[i]=1;
}

int main(){
	scanf("%d%d",&n,&q);
	scanf("%s",s+1);
	for (int i=1;i<=n;++i)
	x[i]=s[i]-'A';
	for (int i=1;i<=q;++i){
		char ch[1],op[1];
		scanf("%s%s",ch,op);
		o[i]=ch[0]-'A',
		d[i]=op[0]=='R'?1:-1;
	}
	findl();findr();
	for (int i=1;i<=n;++i)
	if (!del[i]) ans++;
	printf("%d\n",ans);
}

Measured memory_bytes: 2944
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define pi (acos(-1))
#define ull  unsigned long long
#define ld long double
///freopen("input.txt","r",stdin);
///freopen("output.txt","w",stdout);
#define M 100000
ll LCM(ll a, ll b)
{
    ll g = __gcd(a,b);
    return (a*b)/g ;
}
string numtostr(ll n)
{
    ostringstream str1 ;
    str1 << n ;
    return str1.str();
}
ll strtonum(string s)
{
    ll x ;
    stringstream str1(s);
    str1 >> x ;
    return x ;
}
int n,i;
ld l=0;
ull s=1;
bool b=true;
int main(void)
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin>>n;
    ll a[n];
    for(i=0;i<n;++i)
         cin>>a[i];
    for(i=0;i<n;++i)
        if(a[i]==0)
    {
        cout<<0<<'\n';
        return 0;
    }
    for(i=0;i<n;++i)
        l+=log10(a[i]);
    if(l>18.1)
        cout<<-1<<"\n";
    else
    {
        for(i=0;i<n;++i)
            s*=a[i];
        if(s>1000000000000000000)
            cout<<-1<<'\n';
        else
            cout<<s<<'\n';
    }
    return 0;
}


Measured memory_bytes: 4664
from itertools import combinations
N, K = list(map(int, input().split()))

def combination_2(n):
    return n * (n-1) // 2


if N == 2 and K > 0:
    print("-1")
    exit()

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

max_K = combination_2(N-1)

if K > max_K:
    print("-1")
    exit()

M = max_K - K + N - 1
print(M)
cnt = 0
for x, y in combinations(range(1, N+1), 2):
    print(x, y)
    cnt += 1
    if cnt >= M:
        exit()


Measured memory_bytes: 3608
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int input[] = new int[n];
		for(int i = 0; i < n; i++){
			input[i] = sc.nextInt();
		}

		int dp[] = new int[n];
		dp[1] = Math.abs(input[1] - input[0]);
		for(int i = 2; i < n; i++){
			dp[i] = Math.min(dp[i - 1] + Math.abs(input[i] - input[i - 1]), dp[i - 2] + Math.abs(input[i] - input[i - 2]));
		}

		System.out.println(dp[n - 1]);
	}

}


Measured memory_bytes: 49516
#include<iostream>
#include <algorithm>
#include<string>
#include<math.h>
#include <functional>
using namespace std;

int main(void) {
	int N;
	int n[9] = {1,2,3,5,6,9,10,13,17};
	cin >> N ;
	for (int i = 0;i < 9;i++) {
		if (n[i] == N) {
			cout << "No" << endl;
			return 0;
			break;
		}
	}
	cout << "Yes" << endl;
	return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.util.*
import kotlin.math.abs
import kotlin.math.max
import kotlin.math.min

val MOD = 1_000_000_007L

class Solver(stream: InputStream, private val out: java.io.PrintWriter) {
  fun solve() {
    val X = ni()
    val Y = ni()
    for (i in 0 .. X) {
      if (Y == 2 * i + (X - i) * 4) {
        out.println("Yes")
        return
      }
    }
    out.println("No")
  }













































  private val isDebug = try {
    // なんか本番でエラーでる
    System.getenv("MY_DEBUG") != null
  } catch (t: Throwable) {
    false
  }

  private var tokenizer: StringTokenizer? = null
  private val reader = BufferedReader(InputStreamReader(stream), 32768)
  private fun next(): String {
    while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {
      tokenizer = StringTokenizer(reader.readLine())
    }
    return tokenizer!!.nextToken()
  }

  private fun ni() = next().toInt()
  private fun nl() = next().toLong()
  private fun ns() = next()
  private fun na(n: Int, offset: Int = 0): IntArray {
    return map(n) { ni() + offset }
  }
  private fun nal(n: Int, offset: Int = 0): LongArray {
    val res = LongArray(n)
    for (i in 0 until n) {
      res[i] = nl() + offset
    }
    return res
  }

  private fun na2(n: Int, offset: Int = 0): Array<IntArray> {
    val a  = Array(2){IntArray(n)}
    for (i in 0 until n) {
      for (e in a) {
        e[i] = ni() + offset
      }
    }
    return a
  }

  private inline fun map(n: Int, f: (Int) -> Int): IntArray {
    val res = IntArray(n)
    for (i in 0 until n) {
      res[i] = f(i)
    }
    return res
  }

  private inline fun debug(msg: () -> String) {
    if (isDebug) System.err.println(msg())
  }

  private fun debug(a: LongArray) {
    debug { a.joinToString(" ") }
  }

  private fun debug(a: IntArray) {
    debug { a.joinToString(" ") }
  }

  private fun debug(a: BooleanArray) {
    debug { a.map { if (it) 1 else 0 }.joinToString("") }
  }

  private fun debugDim(A: Array<LongArray>) {
    if (isDebug) {
      for (a in A) {
        debug(a)
      }
    }
  }
  private fun debugDim(A: Array<IntArray>) {
    if (isDebug) {
      for (a in A) {
        debug(a)
      }
    }
  }

  /**
   * 勝手にimport消されるのを防ぎたい
   */
  private fun hoge() {
    min(1, 2)
    max(1, 2)
    abs(-10)
  }
}

fun main() {
  val out = java.io.PrintWriter(System.out)
  Solver(System.`in`, out).solve()
  out.flush()
}

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

#define MAX_LEN_TEXT 1001
#define MAX_LEN_WORD 33
#define MAX_ID_WORD  500


int main(void) {
    char text[MAX_LEN_TEXT];
    char words[MAX_ID_WORD][MAX_LEN_WORD];
    int  arise_counts[MAX_ID_WORD];
    int  letter_counts[MAX_ID_WORD];

    int cnt_most_freq = 0;
    int id_most_freq  = 0;
    int len_longest   = 0;
    int id_longest    = 0;

    fgets(text, MAX_LEN_TEXT, stdin);

    int i = 0, j = -1, k = 0;
    char curr_word[MAX_LEN_WORD];
    while(i < MAX_LEN_TEXT) {
        // The end of the current word.
        if(text[i] == ' ' || text[i] == '\0') {
            curr_word[k] = '\0';

            int x;
            int found = 0;
            for(x = 0; x <= j; x++) {
                // The case where the current word has appeared already.
                if(strcmp(words[x], curr_word) == 0) {
                    found = 1;
                    arise_counts[x]++;
                    j++;

                    // Checks whether the current word appears most frequently.
                    if(arise_counts[x] > cnt_most_freq) {
                        cnt_most_freq = arise_counts[x];
                        id_most_freq  = x;
                    }

                    break;
                }
            }

            // The case where the current word appears for the first time.
            // Uses j as the index of words.
            if(!found) {
                strcpy(words[++j], curr_word);
                arise_counts[j]  = 1;
                letter_counts[j] = k - 1;

                // Checks whether the current word is longest.
                if(letter_counts[j] > len_longest) {
                    len_longest = letter_counts[j];
                    id_longest  = j;
                }
            }

            // The end of the input text.
            if(text[i] == '\0') break;

            found = 0;
            k = 0;
        }

        // The middle of the current word.
        else {
            curr_word[k] = text[i];
            k++;
        }

        i++;
    }

    printf("%s %s\n", words[id_most_freq], words[id_longest]);

    return 0;
}

Measured memory_bytes: 548
/*input
35897 932
*/
#ifdef UncleGrandpa
#include <prettyprint.hpp>
#define LOCAL 1
#else
#define LOCAL 0
#endif
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define sp ' '
#define endl '\n'
#define fi first
#define se second
#define bit(x,y) ((x>>y)&1)
#define loop(i,l,r) for(int i=(l); i<=(r); i++)
#define rloop(i,l,r) for(int i=(l); i>=(r); i--)
#define debug(x...) {if (!LOCAL) return; cout << "[" << #x << "] ="; print(x);}
void print() {cout << endl;}
template<typename T, typename... Ts> void print(const T& value, const Ts&... values) {if (!LOCAL) return; cout << value << ' '; print(values...);}
// const int N =;

int n, m;
signed main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    cin >> n >> m;
    int ans = 0;
    int x = ((n - n % m) - m) / m + 1;
    ans += x * x * x;
    if (m % 2 == 0) {
        x = ((n - (m + n % m - m / 2) % m) - m / 2) / m + 1;
        ans += x * x * x;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    long long i,j,l,N,a,b,c,ans;
    cin>>N;
    string s;
    a=0;b=0;c=0;
    ans=0;
    for(i=0;i<N;i++){
        cin>>s;
        l=s.length();
        for(j=0;j<l-1;j++){
            if(s[j]=='A'&&s[j+1]=='B'){
                ans++;
            }
        }
        if(s[0]=='B'&&s[l-1]=='A'){
            c++;
        }else if(s[0]=='B'){
            b++;
        }else if(s[l-1]=='A'){
            a++;
        }
    }
    if(a>0){
        ans+=c;
        ans+=min(a,b);
    }else if(c>0){
        ans+=c-1;
        if(b>0){
            ans++;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
def main():
    N,A,B = map(int,input().split())
    ans0 = N//(A+B)
    ans1 = A*ans0
    ans2 = (N-(A+B)*ans0)
    if ans2 <= 0:
        ans2 = 0
    ans1 += min(ans2,A)
    print(ans1)
if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>

using namespace std;

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

int main() {
  int n, k;
  cin >> n >> k;
  int v[n];
  rep(i,n) cin >> v[i];
  
  int c = min(n, k);
  int g[c], m = 0, s;
  rep(l,c+1) rep(r,c+1-l) {
    rep(i,c) g[i] = 0;
    rep(i,l) g[i] = v[i];
    rep(i,r) g[l+i] = v[n-1-i];
    sort(g, g + c);
    rep(i,min(c,k-l-r)) g[i] = max(g[i], 0);
    
    s = 0;
    rep(i,c) s += g[i];
    m = max(m, s);
  }
  
  cout << m << endl;
  return 0;
}

Measured memory_bytes: 256