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

#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);--i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define MOD 1000000007

using namespace std;

using ll = long long;

template <class T, T M>
class modulo {
public:
    T data;

    modulo(T data = 0) : data(data % M) {
    }

    modulo operator+(const modulo &x) const {
        return modulo(data + x.data);
    }

    modulo operator-(const modulo &x) const {
        return modulo(data + (M - x.data));
    }

    modulo operator*(const modulo &x) const {
        return modulo(data * x.data);
    }

    modulo operator/(const modulo &x) const {
        return modulo(data * x.inv().data);
    }

    modulo operator+=(const modulo &x) {
        return data = (data + x.data) % M;
    }

    modulo operator-=(const modulo &x) {
        return data = (data + (M - x.data)) % M;
    }

    modulo operator*=(const modulo &x) {
        return data = (data * x.data) % M;
    }

    modulo operator/=(const modulo &x) {
        return data = (data * x.inv().data) % M;
    }

    modulo inv() const {
        return _pow(M - 2);
    }

    template <class Integer>
    modulo operator^(Integer n) const {
        if (n >= 0) {
            return _pow(n);
        } else {
            return _pow(M - 1 - (-n) % (M - 1));
        }
    }

    friend std::ostream& operator<<(std::ostream &os, const modulo &x) {
        os << x.data;
        return os;
    }

private:
    template <class NonNegativeInteger>
    modulo _pow(NonNegativeInteger n) const {
        modulo result(1);
        modulo x(*this);
        while (n) {
            if (n & 1) {
                result *= x;
            }
            x *= x;
            n >>= 1;
        }
        return result;
    }
};

int main() {

    cin.tie(0);
    ios::sync_with_stdio(false);

    using Mod = modulo<ll, MOD>;

    int N, K;
    cin >> N >> K;

    vector<Mod> f(K + 1); // f[i] = #{ sequence A s.t. len(A) = N, gcd(A) = i }
    
    // f[i] + f[2*i] + f[3*i] + ... + f[m*i] = (K / i) ^ N
    // where m = K / i

    RFOR(i, 1, K + 1) {
        f[i] = Mod(K / i) ^ N;
        for (int j = 2 * i; j <= K; j += i) {
            f[i] -= f[j];
        }
    }

    Mod result = 0;

    FOR(i, 1, K + 1) {
        result += f[i] * i;
    }

    cout << result << endl;

    return 0;
}


Measured memory_bytes: 3972
#include<iostream>
#include<cstdio>
#define _USE_MATH_DEFINES
#include<cmath>
#include<vector>
#include<map>
#include<algorithm>
using namespace std;


#define INF 1e+10
#define EPS 1e-10
#define EQ(a,b) (abs(a-b)<EPS)

//誤差を考慮して足し算
double add(double a,double b){
	if(abs(a+b) < EPS*(abs(a)+abs(b)))return 0;
	return a+b;
}
struct P{//2次元ベクトル
	double x,y;
	P(){}
	P(double x,double y):x(x),y(y){}
	P operator + (P p)const{
		return P(add(x,p.x),add(y,p.y));
	}
	P operator - (P p)const{
		return P(add(x,-p.x),add(y,-p.y));
	}
	P operator * (double d)const{
		return P(x*d,y*d);
	}
	P operator / (double d)const{
		return P(x/d,y/d);
	}
	double dot(P p)const{//内積
		return add(x*p.x,y*p.y);
	}
	double det(P p)const{//外積
		return add(x*p.y,-y*p.x);
	}
	bool equal(P p)const{
		return (x-p.x)*(x-p.x)+(y-p.y)*(y-p.y) < EPS*EPS;
	}
	double norm()const{
		return sqrt(x*x+y*y);
	}
};


int ccw(P a, P b, P c){
	b = b-a;
	c = c-a;
	if (b.det(c) > 0)   return +1;       // counter clockwise
	if (b.det(c) < 0)   return -1;       // clockwise
	if (b.dot(c) < 0)     return +2;       // c--a--b on line
	if (b.norm() < c.norm()) return -2;       // a--b--c on line
	return 0;
}

int main(){
	P a,b,c,d;
	char _;
	while(cin>>a.x>>_>>a.y>>_>>b.x>>_>>b.y>>_>>c.x>>_>>c.y>>_>>d.x>>_>>d.y){
		int f=0,r;
		r=ccw(a,b,c);
		if(r==-1)f|=1;
		else if(r==1)f|=2;
		r=ccw(b,c,d);
		if(r==-1)f|=1;
		else if(r==1)f|=2;
		r=ccw(c,d,a);
		if(r==-1)f|=1;
		else if(r==1)f|=2;
		r=ccw(d,a,b);
		if(r==-1)f|=1;
		else if(r==1)f|=2;
		if(f!=3)cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
	return 0;
}

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

int main() {
	int n;
	cin >> n;
	
	for(int i=1; i<=n; i++){
		if(i%3==0){
			cout << " " << i;
		}
		else{
			
			int x=i;
			while(x!=0){
			
			if(x%10 == 3){
				cout << " " << i;
				break;
			}
			else{
				x /=10;
			}
			
			}
			
		}
		
	}
	
	cout << endl;
	return 0;
}

Measured memory_bytes: 1164
import math
def isPrime(x):
    if x == 2:
        return True
    if x < 2 or x % 2 == 0:
        return False
    i = 3
    while i <= math.sqrt(x):
        if x % i == 0:
            return False
        i = i + 2
    return True

if __name__ == '__main__':
    N = int(input())
    a = []
    for i in range(N):
        a.append(int(input()))
    counter = 0
    for x in a:
        if isPrime(x):
            counter += 1
    print(counter)


Measured memory_bytes: 6000
#include<iostream>
#include <stack>
#include<cstdio>
#include<algorithm>
#include<string.h>
#include<set>
#include<map>
#include<cmath>
#define MAXN 100001
#include<utility>
#define DEBUG 0

using namespace std;
typedef long long ll;
int main()
{
    #if DEBUG
    freopen("in.txt","r",stdin);
    #endif // DEBUG
    map<int,int> v;
    int n;
    scanf("%d",&n); 
    for(int i=0;i<n;i++)
    {
        int d;
        scanf("%d",&d);
        if(v.count(d)) v.erase(d);
        else v[d];
    }

    printf("%d\n",v.size());
    cout<<endl;
    #if DEBUG
    fclose(stdin);
    #endif // DEBUG

    return 0;
}


Measured memory_bytes: 4864
#include <bits/stdc++.h>
 
#define mp make_pair
 
using namespace std;
 
typedef int32_t i32;
typedef uint32_t u32;
typedef int64_t i64;
typedef uint64_t u64;
typedef pair<int,int> pii;
typedef pair<i64,int> pli;
typedef pair<int,i64> pil;
typedef pair<i64,i64> pll;
typedef vector<int> vi;
typedef vector<i64> vl;
 
template <typename T>
T id(T b) {return b;};
template <class It>
bool all(It f,It l){return std::all_of(f,l,id<bool>);}
template <class It>
bool any(It f,It l){return std::any_of(f,l,id<bool>);}
 
const int MAX_N = 100;
int n;
double t[MAX_N+1];
double v[MAX_N+2];
//double b[MAX_N+1];
double b1[MAX_N+1];
double b2[MAX_N+1];
 
int main()
{
  cin >> n;
  t[0] = 0;
  for (int i = 1; i <= n; i++) {
    cin >> t[i];
    t[i] += t[i-1];
  }
  v[0] = v[n+1] = 0;
  for (int i = 1; i <= n; i++) cin >> v[i];
  for (int i = 0; i <= n; i++) {
    b1[i] = min(v[i],v[i+1]) + t[i];
    b2[i] = min(v[i],v[i+1]) - t[i];
  }
  for (int i = 0; i <= n; i++) {
    b1[i] = *min_element(b1+i,b1+n+1);
    b2[i] = *min_element(b2,b2+i+1);
  }
 
  double d = 0;
  for (int i = 1; i <= n; i++) {
    double vs = min(-t[i-1]+b1[i-1], t[i-1]+b2[i-1]);
    double ve = min(-t[i]+b1[i], t[i]+b2[i]);
    //printf("vs=%f v[%d]=%f ve=%f\n",vs,i,v[i],ve);
    double dt = t[i] - t[i-1];
    double p = (ve+dt-vs) / 2.0;
    if (v[i] <= vs + p) {
      double mdt = dt - (v[i] - vs) - (v[i] - ve);
      double v1 = (v[i]+vs)*(v[i]-vs)/2.0;
      double v2 = mdt*v[i];
      double v3 = (v[i]+ve)*(v[i]-ve)/2.0;
      //printf("v1=%f v2=%f v3=%f\n",v1,v2,v3);
      d += v1 + v2 + v3;
    } else {
      d += (2.0*vs+p)*p/2.0 + (2.0*ve+dt-p)*(dt-p)/2.0;
    }
    //printf("i=%d d=%f\n",i,d);
  }
  printf("%.10f\n", d);
 
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/indexed.hpp>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)
#define ALL(x) begin(x),end(x)

using namespace std;
using namespace boost::adaptors;
using namespace std::string_literals;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;
using boost::irange;


int main() {
  int n;
  cin>>n;
  if (n == 2) {
    cout<<-1<<endl;
    return 0;
  }
  vecint rules(n);
  for(auto&& e:rules)cin>>e;
  vecint cnt(n+1);
  for(auto&& e:rules) ++cnt[e];
  map<int,int> m;
  for(auto&& e:cnt) {
    ++m[e];
  }
  set<int> s;
  REP(i,n) s.insert(i+1);
  vecint ans;
  REP(i,n-3) {
    int rem = n-i;
    if (rbegin(m)->first == rem-1) { // 1 vs others
      REP(j,n+1) {
        if (s.count(j) && cnt[j] == rem-1) {
          ans.push_back(j);
          s.erase(j);
          --m[cnt[j]];
          if (m[cnt[j]] == 0) {
            m.erase(cnt[j]);
            break;
          } else {
            cout<<-1<<endl;
            return 0;
          }
        }
      }
    } else if (ans.empty()) {
      ans.push_back(1);
      s.erase(1);
      int v = cnt[1];
      --m[v];
      if (m[v] == 0) {
        m.erase(v);
      }
      if (s.count(rules[0])) {
        int u = cnt[rules[0]];
        --cnt[rules[0]];
        --m[u];
        if (m[u] == 0) {
          m.erase(u);
        }
        if (u > 0) ++m[u-1];
      }
    } else {
      int taboo = rules[ans.back()-1];
      auto itr = begin(s);
      if (*itr == taboo) ++itr;
      ans.push_back(*itr);
      int v = cnt[*itr];
      --m[v];
      if (m[v] == 0) {
        m.erase(v);
      }
      if (s.count(rules[*itr-1])) {
        int u = cnt[rules[*itr-1]];
        --cnt[rules[*itr-1]];
        --m[u];
        if (m[u] == 0) {
          m.erase(u);
        }
        if (u > 0) ++m[u-1];
      }
      s.erase(itr);
    }
  }
  vecint ary(ALL(s));
  do {
    bool ok = true;
    if (!ans.empty() && rules[ans.back()-1] == ary[0]) ok = false;
    REP(i,2) {
      if (rules[ary[i]-1] == ary[i+1]) ok = false;
    }
    if (ok) {
      ans.insert(end(ans), ALL(ary));
      break;
    }
  } while (next_permutation(ALL(ary)));
  if (ans.size() < n) {
    cout<<-1<<endl;
    return 0;
  }
  REP(i,n) {
    if (i)cout<<" ";
    cout<<ans[i];
  }
  cout<<endl;
  return 0;
}


Measured memory_bytes: 6272
#include<bits/stdc++.h> 
//#define <- プログラムの文字列を置換する
//typedef <- 新しい型に名前を付けるためのキーワード

using namespace std;

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

const long long MOD = 1e9 + 7;
const long long INF = 1e15;
const int INF_INT = 1e9;

template<class TYPE>
struct edge{
    TYPE to,cost; 
    edge(TYPE t,TYPE c){
        to = t;
        cost = c;
    }
};

int main(){
    int a,b;
    cin >> a >> b;
    int count = 0;
    for(int i = a; i <= b; i++){
        string st = to_string(i);
        string st2 = st;
        reverse(st2.begin(),st2.end());
        if(st == st2) count++; 
    }
    cout << count << endl;
    return 0;
}


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

#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define MOD 1000000007

#define trace1(x)                    cout <<#x<<": "<<x<< endl;
#define trace2(x, y)                 cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;
#define trace3(x, y, z)              cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define trace4(a, b, c, d)           cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;

typedef long long ll;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    ll i,j,n,m;
    cin>>n>>m;
    cout<<(n*3+m)/2;
    return 0;
}

Measured memory_bytes: 764
/* ALDS1_2_B */
import java.io.*;

class Main
{
  public static void main(String[] args)
  {
    try{
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      int n = Integer.parseInt(br.readLine());
      String[] str = br.readLine().split(" ");
      int[] array = new int[n];
      SelectionSort ss = new SelectionSort();

      for(int i = 0; i < n; i++){
        array[i] = Integer.parseInt(str[i]);
      }

      ss.selectionSort(array);
      ss.showArray(array);
      System.out.println(ss.getSwap());

    }catch(Exception e){
      System.out.println(e);
    }
  }
}

class SelectionSort
{
  private int swap;

  public void selectionSort(int[] A)
  {
    swap = 0;

    for(int i = 0; i < A.length; i++){
      int mini = i;
      for(int j = i; j < A.length; j++){
        if(A[j] < A[mini]) mini = j;
      }
      if(i != mini){
        int tmp = A[i];
        A[i] =  A[mini];
        A[mini] = tmp;
        swap++;
      }
    }
  }

  public void showArray(int[] A)
  {
    StringBuilder sb = new StringBuilder();

    for(int i = 0; i < A.length; i++){
      sb.append(A[i]).append(" ");
    }
    sb.deleteCharAt(sb.length() - 1);
    System.out.println(sb);
  }

  public int getSwap() { return swap; }
}

Measured memory_bytes: 24288
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n) for (int i=1; i < (int)(n); i++)
#define rrep(i, n) for (int i=((int)(n)-1); i>=0; i--)
#define rreps(i, n) for (int i=((int)(n)-1); i>0; i--)
#define ALL(x) (X).begin(), (x).end()
#define SZ(x) ((int)(x).size())
using namespace std;
using lint = long long;
using p = pair<int, int>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main() {
  int N, K, Q; cin >> N >> K >> Q;
  vector<int> point(N, K-Q);

  vector<int> a(Q);
  rep (i, Q) {
    cin >> a[i];
    a[i]--;
  }
  rep (i, Q){
    point.at(a[i]) ++;
  }
  rep (i, N) {
    if (point[i] > 0)
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  }
  return 0;
}


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

int main(){
  long long q = 1000000000 + 7;
  long long n; cin >> n;
  string s; cin >> s;
  vector<long long> alpha(26, 0);
  for(long long i=0; i<n; i++){
    alpha[s[i]-'a']++;
  }
  long long ans=1;
  for(long long i=0; i<26; i++){
    if(alpha[i] != 0){
      ans = (ans*(alpha[i]+1)%q)%q;
    }
  }
  cout << (ans-1+q)%q << endl;
  return 0;
}


Measured memory_bytes: 512
#include <iostream>

using namespace std;

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


Measured memory_bytes: 256
package main

import "fmt"

/*
 <url:http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_5_C&lang=jp>
 */

func init() {
}

func main() {
	for {
		var H, W int
		fmt.Scanf("%d %d", &H, &W)
		if H == 0 && W == 0{
			break
		}
		for i := 0; i < H; i++ {
			for j := 0; j < W; j++ {
				if (i+j)%2 == 0{
					fmt.Print("#")
				}else {
					fmt.Print(".")
				}
			}
			fmt.Print("\n")
		}
		fmt.Print("\n")
	}
}

Measured memory_bytes: 1140
#include <stdio.h>
#include <stdlib.h>

int asc(const void *a, const void *b){
    return *(int *)a - *(int *)b;
}

int main(void){
    int n,k,min=2000000000,sa;
    int i;
    scanf("%d %d",&n,&k);
    int h[n];
    for(i=0;i<n;i++){
        scanf("%d", &h[i]);
    }
    qsort(h, n, sizeof(int), asc);

    for(i=0;i<=n-k;i++){
        sa=h[i+k-1]-h[i];
        if(sa<min){
            min=sa;
        }
    }
    printf("%d\n", min);
    return 0;
}

Measured memory_bytes: 892
N = int(input())
As = list(map(int,input().split(" ")))
As.sort(reverse=True)
Bs = list(map(int,input().split(" ")))
Bs.sort(reverse=True)
Cs = list(map(int,input().split(" ")))
Cs.sort(reverse=True)
bcruiseki = [0]
abruiseki = [0]
j = 0
i = 0
while True:
    temp= bcruiseki[j]
    while i < N and Bs[j] <Cs[i]  :
        temp += 1
        i+= 1
    bcruiseki.append(temp)
    j += 1
    if j == N:
        break
j = 0
i = 0
while True:
    temp= abruiseki[j]
    while i < N and As[j] <Bs[i]  :
        temp += bcruiseki[i+1]
        i+= 1
    abruiseki.append(temp)
    j += 1
    if j == N:
        break

print(sum(abruiseki))




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


void main() {
    auto s = readln.split.map!(to!int);
    auto H = s[0];
    auto W = s[1];
    auto A = H.iota.map!(_ => readln.chomp).array;

    auto cnt = new int[](26);
    foreach (i; 0..H) foreach (j; 0..W) cnt[A[i][j] - 'a'] += 1;

    int r1 = 0, r2 = H - 1;
    int[] need = new int[](10);
    while (true) {
        if (r1 < r2) {
            need[4] += W / 2;
            need[2] += W % 2;
            r1 += 1;
            r2 -= 1;
        } else if (r1 == r2) {
            need[2] += W / 2;
            need[1] += W % 2;
            r1 += 1;
            r2 -= 1;
        }

        if (r1 > r2)
            break;
    }


    int odd = cnt.map!(c => c % 2 == 1).sum;
    if (odd != need[1]) {
        writeln("No");
        return;
    }

    if (need[1] == 1) foreach (i; 0..26) if (cnt[i] % 2 == 1) cnt[i] -= 1;

    foreach (i; 0..26) if (need[2] > 0 && cnt[i] % 4 == 2) need[2] -= 1, cnt[i] -= 2;
    if (cnt.map!(c => c % 4 == 0).all) {
        writeln("Yes");
    } else {
        writeln("No");
    }
}


Measured memory_bytes: 256
import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);
      int K = sc.nextInt();
      int A = sc.nextInt();
      int B = sc.nextInt();
      
      int B1 =(B/K)*K;
      
      if(A<=B1){
        System.out.println("OK");
      }
      else{
        System.out.println("NG");
      }
    }
}

Measured memory_bytes: 35608
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <utility>
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

#define INF (1 << 30)
#define INFL (1LL << 62)
#define MOD7 1000000007
#define MOD9 1000000009
#define EPS 1e-10

#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pul pair<ull, ull>
#define all(a) (a).begin(), (a).end()
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);--i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)

void YES() { cout << "YES" << endl; }
void NO() { cout << "NO" << endl; }
void Yes() { cout << "Yes" << endl; }
void No() { cout << "No" << endl; }
void yes() { cout << "yes" << endl; }
void no() { cout << "no" << endl; }
void Taka() { cout << "Takahashi" << endl; }
void Aoki() { cout << "Aoki" << endl; }
void digit(int d) { cout << fixed << setprecision(d); }
void IOup() { cin.tie(0); ios::sync_with_stdio(false); }

int main() {
	string a = "aiueo", s;
	cin >> s;
	puts(a.find(s) != string::npos ? "vowel" : "consonant");

	return 0;
}

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


int main(){
	
	int a,b,c;

	cin>>a>>b>>c;

	if(a==b) cout<<c<<endl;
	if(a==c) cout<<b<<endl;
	if(b==c) cout<<a<<endl;


	
return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) ;for(int i=0; i<(n); i++)
using veci = vector<int>;
int a[21];
int m[210];
bool solve(int i, int m, int n){
    if (m == 0) return true;
    if (i >= n) return false;//もう選べる数字が残っていない
    bool rec = solve(i+1, m, n) || solve(i+1, m-a[i], n);
    return rec;
}
int main(){
    int n;scanf("%d", &n);
    rep(i, n)scanf("%d", &a[i]);
    int q; cin >> q;
    rep(i, q) cin >> m[i];
    for (int i=0; i<q; i++){
        if (solve(0, m[i], n)) cout << "yes" << endl;
        else cout << "no" << endl;
    }
}


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

using namespace std;

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

    int K, X;
    cin >> K >> X;
    for (int i = X - K + 1; i < X + K; ++i) {
        cout << i << " ";
    }
    cout << "\n";

    return 0;
}

Measured memory_bytes: 256
function Main(input) {
    var inputArr = input.split('\n');
    var S = inputArr[0];
    var T = inputArr[1];
    var flg = false;

    for(var i = 0 ; i <= S.length ; ++i) {
        if (S === T) {
            flg = true;
            break;
        }
        S = S.slice(S.length - 1) + S.slice(0, S.length-1);
    }

    if (flg) console.log('Yes');
    else console.log('No');
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <array>
#include <bitset> 
#include <unordered_map>

using namespace std;
typedef long long LL;
typedef pair<int,int> P;

int main() {
	LL N,A,B;
	scanf("%lld%lld%lld",&N,&A,&B);
	if(A+B-1>N||A*B<N){
		puts("-1");
		return 0;
	}
	const char* sp="";
	if(B==1){
		for(int i=1;i<=N;i++){
			printf("%s%d",sp,i);
			sp=" ";
		}
		puts("");
		return 0;
	}
	if(A==1){
		for(int i=N;i>0;i--){
			printf("%s%d",sp,i);
			sp=" ";
		}
		puts("");
		return 0;
	}

	for(int i=N-A+1;i<=N;i++){
		printf("%s%d",sp,i);
		sp=" ";
	}
	LL k=(N-A)/(B-1);
	LL r=(N-A)%(B-1);
	int m=N-A;
	for(int i=0;i<B-1;i++){
		int hi=m;
		int low;
		if(i<r){
			low=m-k;
		}
		else{
			low=m-k+1;
		}
		for(int i=low;i<=hi;i++){
			printf("%s%d",sp,i);
			sp=" ";
		}
		m=low-1;
	}
	puts("");
	assert(m==0);

	return 0;
}



Measured memory_bytes: 2176
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <cmath>
#include <deque>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define ll long long
#define rep2(i,a,b) for(int i=a;i<=b;++i)
#define rep(i,n) for(int i=0;i<n;i++)
#define rep3(i,a,b) for(int i=a;i>=b;i--)
#define REP(e,v) for(auto e:v)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mp make_pair
#define mt make_tuple
#define pq priority_queue<ll>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define vecpll vector<pll>
#define vecbl vector<bool>
#define endl "\n"
#define ALL(c) (c).begin(),(c).end()
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}
string stin(){string s;cin>>s;return s;}

int main(){
    int n=in();
    vec a(n),b(n);
    rep(i,n)cin>>a[i]>>b[i];
    sort(ALL(a));
    sort(ALL(b));
    int ans=n%2==0?b[n/2-1]+b[n/2]-a[n/2-1]-a[n/2]+1:b[n/2]-a[n/2]+1;
    cout<<ans<<endl;
}

Measured memory_bytes: 4844
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store") // to restrict undesirable precision
#pragma GCC optimize ("-fno-defer-pop")// to pop argument of function as soon as it returns
#define all(a) a.begin(),a.end()
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ps push_back
#define fs first
#define sc second
#define takeline cin.ignore();
#define iactive cout.flush();
#define N 100005
#define endl "\n"
#define mod 1000000007
//((1.0l)*BIG MULTIPLY MAGIC?)
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//-----------------------------------------------
ll n,ar[N][4],dp[N][4],k;
ll maxval(ll i,ll flg){
	if(i>n) return 0;
	
	if(dp[i][flg]!=-1){
		return dp[i][flg];
	}
//	cout<<i<<" "<<flg<<endl;
	ll j,an=0;
	for(j=1;j<=3;j++){
		if(j==flg) continue;
		an=max(an,maxval(i+1,j)+ar[i][j]);
	}
	return dp[i][flg]=an;
}
int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	ll i,j,l;
	cin>>n;
	for(i=1;i<=n;i++){
		cin>>ar[i][1]>>ar[i][2]>>ar[i][3];
	}
	memset(dp,-1,sizeof(dp));
	ll an=maxval(1,0);
	cout<<an;
	return 0;
}

Measured memory_bytes: 16120
def main():
    N = int(input())
    X = list(map(int, input().split()))

    sort_X = sorted(X)
    X1 = sort_X[N//2]
    X2 = sort_X[(N//2) - 1]

    for x in X:
        if x <= X2:
            print(X1)
        else:
            print(X2)
main()

Measured memory_bytes: 93652
#include <iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<queue>
#include<cmath>
#include<set>
#include<deque>
using namespace std;
typedef long long ll;

typedef pair<int, int> pii;

const ll MOD_CONST = 1000000007;


const int BIG_INT = 1000000000;
const ll BIG_NUM = 1000000000000000000;



int main() {
	int h, w;
	cin >> h >> w;
	if (h == 1 || w == 1) {
		cout << 1 << endl;
		return 0;
	}
	ll ans = (1LL * h * w) / 2;
	if (h % 2 != 0 && w % 2 != 0) {
		ans++;
	}
	cout << ans << endl;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define all(a) a.begin(), a.end()
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,int> pli;
typedef pair<int,int> pii;
#define rep(i,a,b) for(ll i=a ; i<b ; i++)
#define qrep(que, ite) for(auto ite=begin(que) ; ite!=end(que) ; ite++)
const int max_n = 1e5;
const ll mod = 1e9+7;
const ll INF = 1e17;
const int inf = 1e5;
typedef long double ld;
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; }
ll gcd(ll a, ll b) { return a ? gcd(b%a, a) : b; }
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
struct UnionFind {
    vector<int> par;

    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    int size(int x) {
        return -par[root(x)];
    }
};
struct SegmentTree{
  int N;
  vector<int> node;
  public :
    void intit(vector<int>v){
      int sz = v.size();
      N=1;
      while(N<sz) N*=2;
      node.resize(N);
      for(int i=0 ; i<sz ; i++) node[i+N-1] = v[i];
      for(int i=N-2 ; i>=0 ; i--) node[i] = min(node[i*2+1], node[i*2+2]);
    }
    void update(int x, int val){
      x += N-1;
      node[x+N-1] = val;
      while(x>0){
        x = (x-1)/2;
        node[x] = min(node[x*2+1], node[x*2+2]);
      }
    }
    int getmin(int a, int b, int k, int l, int r){
      if(b<=l || r<=a) return inf;
      else if(a<=l && r<=b) return node[k];
      else{
        int vl = getmin(a, b, 2*k+1, l, (l+r)/2);
        int vr = getmin(a, b, 2*k+2, (l+r)/2, r);
        return min(vl, vr);
      }
    }
};
vector<ll> divisor(ll n){
  vector<ll> res;
  for(ll i=1; i*i<=n ; i++){
    while(n%i==0){
      ++res[i];
      n /= i;
    }
  }
  if(n!=1) res[n]=1;
  return res;
}
int main(){
  ll N,S,K; cin>>N>>K>>S;
  rep(i,0,N){
      ll st = (S+1)%1000000000 + 1;
      if(i<K){
          cout<<S<<" ";
      }else{
          cout<<st<<" ";
      }
  }
  cout<<endl;
  return 0;
}   

Measured memory_bytes: 3644
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <functional>
 
using namespace std;
 
#define fst first
#define scd second
#define PB push_back
#define MP make_pair
#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)
#define rep(i,x) for(int i=0;i<(x);++i)
#define rep1(i,x) for(int i=1;i<=(x);++i)
#define rrep(i,x) for(int i=(x)-1;i>=0;--i)
#define rrep1(i,x) for(int i=(x);i>=1;--i)
#define FOR(i,a,x) for(int i=(a);i<(x);++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
 
template<typename T>T&get(){T a;cin >> a;return a;}
template<typename T>T&rev(T&a){reverse(all(a));return a;}
template<typename T>istream&operator>>(istream&is,vector<T>&vec){rep(i,vec.size())is>>vec[i];return is;}
template<typename T>vector<T>&sort(vector<T>a){sort(all(a));return a;}
 
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
 
const int inf = 1e9;
const ll linf = 3e18;
 
struct edge {
    int to, cost, time;
    edge(int to0,int cost0,int time0) {
        to = to0; cost = cost0; time = time0;
    };
};
 
int N, M;
 
vector<edge> G[100];
int d[100];
 
void dijkstra(int s, int mode)
{
    priority_queue<pii, vector<pii>, greater<pii> > q;
 
    fill(d, d + M, inf);
    d[s] = 0;
 
    q.push(MP(0, s));
 
    while (q.size()) {
        pii p = q.top(); q.pop();
        int v = p.scd;
        rep(u, G[v].size()) {
            edge e = G[v][u];
            int a = mode == 0 ? e.cost : e.time;
            if (d[e.to] > d[v] + a) {
                d[e.to] = d[v] + a;
                q.push(MP(d[e.to], e.to));
            }
        }
    }
}
 
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
 
    while (cin >> N >> M, N || M) {
        rep(i, M) G[i].clear();
 
        rep(i, N) {
            int a, b, cost, time; cin >> a >> b >> cost >> time; a--; b--;
            G[a].PB(edge(b, cost, time));
            G[b].PB(edge(a, cost, time));
        }
 
        int K; cin >> K;
 
        rep(i, K) {
            int p, q, r; cin >> p >> q >> r; p--; q--;
            dijkstra(p, r);
            cout << d[q] << endl;
        }
    }
}

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

long long a;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	
	for(int i = 1;i <= 5;i++){
		cin>>a;
		if(a == 0){
			cout<<i<<endl;
			break;
		}
	}
}


Measured memory_bytes: 3564
#include<iostream>
#include<algorithm>
using namespace std;
static const int MAX = 200000;
int main() {
	int R[MAX], n;
	cin >> n;
	for (int i = 0; i<n; i++)cin >> R[i];

	int maxv = -2000000000;
	int minv = R[0];

	for (int i = 1; i<n; i++) {
		maxv = max(maxv, R[i] - minv);
		minv = min(minv, R[i]);
	}
	cout << maxv << endl;
	return 0;
}



Measured memory_bytes: 3856
import numpy as np
N = int(input())
abc = [list(map(int, input().split())) for i in range(N)]

# dp[i+1日][最終日の活動 0:A, 1:B, 2:C]
dp = np.zeros((N, 3), np.int64)
dp[0] = abc[0]
for i in range(1, N):
    for j in range(3):
        dp[i, j] = max([dp[i - 1, k] + abc[i][j] for k in range(3) if k != j])
print(dp[-1].max())

Measured memory_bytes: 43188
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
	int a = sc.nextInt();
	int b = sc.nextInt();
	int c = sc.nextInt();
	int[] intArray = {a, b, c};
	for(int i = 0; i < intArray.length-1; i++){
        for(int j = i+1; j < intArray.length; j++){
            if(intArray[j] < intArray[i]){
                int temp = intArray[i];
                intArray[i] = intArray[j];
                intArray[j] = temp;
            }
        }
    }
		System.out.print(intArray[0] + " " + intArray[1] + " " + intArray[2]);
	System.out.println();
	}
}

Measured memory_bytes: 26008
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MOD = 1000000007;

long long modpow(long long a, long long n, long long mod) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % MOD;
    a = a * a % MOD;
    n >>= 1;
  }
  return res;
}

int comb( int N, int K ){
  int X = 1; //分子
  int Y = 1; //分母
  for( int i = N; i > N-K; i-- ){
    X = (X*i)%MOD;
  }
  for( int i = 1; i <= K; i++ ){
    Y = (Y*i)%MOD;
  }
  return X * modpow(Y, MOD-2, MOD) % MOD;
}


signed main() {
  int N, A, B;
  cin >> N >> A >> B;
  
  int ans = modpow(2, N, MOD);
  ans = (ans - 1 + MOD) % MOD;
  ans = (ans - comb(N,A) + MOD) % MOD;
  ans = (ans - comb(N,B) + MOD) % MOD;
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[100000],i;
int main()
{
	int b,c;scanf("%d%d",&b,&c);
    for(i=1;i<=b;i++)scanf("%d",&a[i]);
    sort(a+1,a+b+1);int ans=0;
    for(i=b;i>=b-c+1;i--)
    ans+=a[i];printf("%d",ans);
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define PI 3.141592653589
int main(void){
    int a, b;
    char op;
    
    while(scanf("%d %c %d\n", &a, &op, &b) != EOF) {
        if (op == '?') break;
        if (b == 0 && op == '/') break;
        if (op == '+') printf("%d\n", a + b);
        if (op == '-') printf("%d\n", a - b);
        if (op == '*') printf("%d\n", a * b);
        if (op == '/') printf("%d\n", a / b);
    }
    
    return 0;
}


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

/*
code credits : ਜ਼ੈਲਦਾਰ
dashan jot singh
*/
using namespace std;
#define ll long long int
#define fast ios_base::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL)
#define pb push_back
#define mp make_pair
#define inf LLONG_MAX
#define p pair<ll,ll>
string s,t;
ll a,b;
ll dp[3010][3010];
string ans;
ll solve(ll i,ll j){
	if(i==0||j==0){
		return 0;
	}
	// ll ans=0;
	if(dp[i][j]!=-1){
		return dp[i][j];
	}
	if(s[i-1]==t[j-1]){
		dp[i][j]=1+solve(i-1,j-1);
		return dp[i][j];
	}
	else{
		dp[i][j]=max(solve(i-1,j),solve(i,j-1));
		return dp[i][j];
	}
	// dp[i][j]=ans;
	// return dp[i][j];
}
int main(){
	fast;
	cin>>s>>t;
	a=s.length();
	b=t.length();
	memset(dp,-1,sizeof(dp));
	ll axr=solve(a,b);
	ll i=a;
	ll j=b;
	while(i>0 && j>0){
		if(s[i-1]==t[j-1]){
			ans+=t[j-1];
			i--;
			j--;
		}
		else if(dp[i-1][j]>dp[i][j-1]){
			i--;
		}
		else{
			j--;
		}
	}
	reverse(ans.begin(),ans.end());
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 71296
import std.stdio : readln, writeln, chomp, stdin;
import std.conv : to;
import std.algorithm : min;

int[] solve(int[13] d)
{
	int[] ans;
	int[9] map = 0;			// 値の分布
	foreach(v; d){
		++map[v-1];
	}

	foreach(i; 0..9){
		int[9] arr = map.dup;
		++arr[i];
		// 1.入力のせいにしてみる、
		bool flag = false;
		foreach(ite; arr){
			flag |= 4<ite;
		}
		if(flag)continue;
		if(search(arr.idup, 0)){
			ans ~= (i+1);
		}
	}
	
	return ans;
}

bool search(immutable int[] map, int index)
{
	// 3.本体に参照させないようにする
	auto arr = map.dup;
	bool[(9-3)+1] list = arr.renew;
	if(index>=list.length){
		auto tmp = arr.dup;
		foreach(ref ite; tmp){
			ite %= 3;
		}
		foreach(ref ite; tmp){
			if(ite==2){
				ite=0;
				break;
			}
		}
		bool flag = true;
		foreach(ite; tmp){
			flag &= ite==0;
		}
		return flag;
	}
	if(list[index]){
		bool flag = false;
		flag |= search(arr.idup, index+1);
		auto tmp = arr.dup;
		// 2.一度にひとつずつ消してみる
		while(list[index]){
			for(int i=0; i<3; ++i){
				--tmp[index+i];
			}
			list = tmp.renew;
			// 4.途中のものも投げてみる...
			flag |= search(tmp.idup, index+1);
		}
		return flag;
	}else{
		return search(arr.idup, index+1);
	}
}

bool[(9-3)+1] renew(int[] arr)
{
	bool[(9-3)+1] list = true;
	for(int j=0; j<=9-3; ++j){
		for(int k=0; k<3; ++k){
			list[j] &= arr[j+k]>0;
		}
	}
	return list;
}

/+
int getMin(int[] arr, int index)
{
	int[3] f = 0;
	for(int k=0; k<3; ++k){
		f[k] = arr[index+k];
	}
	return min(f[0], f[1], f[2]);
}
+/

void main()
{
	io();
}

void io()
{
	while(true){
		string str = readln.chomp;
		if(stdin.eof())break;
		int[13] d;
		foreach(i, c; str){
			d[i] = c-'0';
		}
		int[] ans = d.solve;
		if(ans.length>0){
			string _ans = "";
			for(int i=0; i<ans.length; ++i){
				_ans ~= ans[i].to!string;
				if(i+1<ans.length){
					_ans ~= " ";
				}
			}
			_ans.writeln;
		}else{
			writeln = 0;
		}
	}
}

Measured memory_bytes: 1804
N = int(input())
A = list(map(int, input().split()))

node = 1
# 作成しなければならない葉の残りの数
leaf = sum(A)
max_node = 1
judge = True
ans = 0
for i, a in enumerate(A):
    ans += node
    leaf -= a
    if node < a+1 and leaf > 0:
        judge = False
        break
    # 次の深さのノード
    max_node = (node - a) * 2
    node = min(leaf, max_node)
    

if judge and max_node == 0:
    print(ans)
else:
    print(-1)


Measured memory_bytes: 83380
import numpy as np

def prepare(n, m):
    f = 1
    for i in range(1, n + 1):
        f = f * i % m
    fn = f
    inv = [1] * (n + 1)
    f = pow(f, m - 2, m)
    inv[n] = f
    for i in range(n, 0, -1):
        f = f * i % m
        inv[i - 1] = f
    return fn, inv

def a_x(a, x, m):
    ret = 1
    yield ret
    for _ in range(x):
        ret = ret * a % m
        yield ret


N, M = map(int, input().split())

fn, inv = prepare(N, M)


stir2 = np.zeros(N + 2, dtype=np.int64)
stir2[0] = 1
upd = np.arange(2, N + 3, dtype=np.int64)

ex2 = [2]
for i in range(N):
    ex2.append(ex2[-1] ** 2 % M)

ans = 0
si = 1

for i in range(N+1):
    nCi = fn * inv[i] * inv[N-i] % M
    i_with = np.fromiter(a_x(pow(2, N-i, M), i, M), dtype=np.int64)
    i_on = (stir2[ :i+1] * i_with % M).sum() % M
    ans = (ans + nCi * i_on % M * ex2[N-i] % M * si) % M
    stir2[1 : i+2] = (stir2[1 : i+2] * upd[ :i+1] + stir2[ :i+1]) % M
    si *= -1


print(ans)


Measured memory_bytes: 29156
import scala.collection.mutable.Queue
import io.Source.stdin

object Main extends App {
    val queue = Queue[(String, Int)]()
    stdin.getLines.foreach(a => {
        val b = a.split(" ")
        queue.enqueue((b(0), b(1).toInt))
    })

    val (_, q) = queue.dequeue
    var tm = 0
    while (!queue.isEmpty) {
        val (n, t) = queue.dequeue
        if (t-q <= 0) {
            tm += t
            println(n + " " + tm)
        } else {
            tm += q
            queue.enqueue((n, t-q))
        }
    }
}

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

int main() {
  int64_t N, K;
  cin >> N >> K;
  if (N % K == 0) {
    cout << 0 << endl;
    return 0;
  }
  N = N % K;
  int64_t prev = N;
  while (1) {
    N = abs(N - K);
    if (prev <= N) break;
    prev = N;
  }
  cout << prev << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
    int n,taro_point=0,hanako_point=0;
    string taro,hanako;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>taro>>hanako;
        if(taro>hanako) taro_point+=3;
        if(taro==hanako){
            taro_point+=1;
            hanako_point+=1;
        }
        if(taro<hanako) hanako_point+=3;
    }
    cout<<taro_point<<" "<<hanako_point<<endl;
    return 0;
}


Measured memory_bytes: 3132
#include<vector>
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<map>
#include<functional>
#include<queue>
#include<stack>
#include<string.h>
#include<list>
#define MOD 10000
#define INF 1000000000
#define MAX 101
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
int main() {
    int n;
    cin>>n;
    int a[60];
    int ma=0;
    int mi=INF;
    int maa,mii;
    bool p=true;
    bool m=true;
    for(int i=0;i<n;i++){
        cin>>a[i];
        if(ma<a[i]){
            ma=a[i];
            maa=i+1;
        }
        if(mi>a[i]){
            mi=a[i];
            mii=i+1;
        }
        if(a[i]<0){
            p=false;
        }
        if(a[i]>0){
            m=false;
        }
    }
    int mm=n-1;
    if(!p&&!m){
        cout<<2*n-1<<endl;
        int pl;
        if(abs(ma)>=abs(mi)){
            pl=maa;
            p=true;
        }else{
            pl=mii;
            m=true;
        }
        for(int i=0;i<n;i++){
            cout<<pl<<" "<<i+1<<endl;
        }
    }else{
        cout<<mm<<endl;
    }
    if(p){
        for(int i=1;i<n;i++){
            cout<<i<<" "<<i+1<<endl;
        }
    }else if(m){
        for(int i=n;i>1;i--){
            cout<<i<<" "<<i-1<<endl;
        }
    }
}
                           


Measured memory_bytes: 256
#include<stdio.h>

int main(void){
  int i,n,m,s=0;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%d",&m);
    if(m%4==0) s+=2;
    else if(m%2==0) s++;
  }

  if(s>=n-n%2)
    printf("Yes\n");
  else
    printf("No\n");

  return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    int N = scan.nextInt();
    int D = scan.nextInt();
    int[][] array = new int[N][D];
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < D; j++) {
        array[i][j] = scan.nextInt();
      }
    }

    int count = 0;
    for (int i = 0; i < N - 1; i++)
      for (int j = i + 1; j < N; j++)
        if (isInteger(array[i], array[j], D))
          count++;
    System.out.println(count);
  }

  private static boolean isInteger(int[] array1, int[] array2, int d) {
    int sum = 0;
    for (int i = 0; i < d; i++) {
      sum += Math.pow(array1[i] - array2[i], 2);
    }
    int squareRoot = (int) Math.sqrt(sum);
    return squareRoot * squareRoot == sum;
  }
}


Measured memory_bytes: 23124
#include <cstdio>
#include <algorithm>

using namespace std;

long long x, y;

int main()
{
    scanf("%lld%lld", &x, &y);
    if (x > y) swap(x, y);
    if (x == 1)
        if (y == 1) puts("1"); else printf("%lld\n", y - 2);
    else if (x == 2) puts("0");
    else printf("%lld\n", (x - 2) * (y - 2));
    return 0;
}


Measured memory_bytes: 128
package main

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

func main() {
    var fp *os.File
    fp = os.Stdin
    reader := bufio.NewReaderSize(fp, 1024)
    N, _ := strconv.Atoi(readLine(reader))
    var nums []int
    var num int

    for i := 0; i < N; i++ {
        num, _ = strconv.Atoi(readLine(reader))
        nums = append(nums, num)
    }

    sort.Sort(sort.IntSlice(nums))

    var arr []int
    var tmp int = 0
    for _, v := range nums {
        if tmp != v {
            arr = append(arr, v)
            tmp = v
        }
    }
    fmt.Println(len(arr))
}

func readLine(reader *bufio.Reader) string {
    buf := make([]byte, 0, 1024)

    for {
        l, p, _ := reader.ReadLine()

        buf = append(buf, l...)

        if !p {
            break
        }
    }

    return string(buf)
}

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

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

typedef long long ll;

using namespace std;
int main()
{
    string S;
    cin >> S;
    int ans;
    int sizeS = S.size();
    for (int i = 1; i <= sizeS - 2; ++i)
    {
        if ((sizeS - i) % 2 == 0)
        {
            int half = (sizeS - i) / 2;
            if (S.substr(0, half) == S.substr(half, half))
            {
                ans = sizeS - i;
                break;
            } 
        }
        else
        {
            continue;
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
# ?´???°?????°?????¨?????????????????°??????

import sys
import math

prim_no = {2: True}                    # ????????°????´???°??§??????????????????????????????

def is_prime(no):
    if no == 2 or no == 1:
        return True
    
    if no % 2 == 0:
        return False

    if prim_no.get(no) is not None:
        return prim_no.get(no)

    max_check = int(math.sqrt(no))
    for i in range(3, max_check+1, 2):
        if no % i == 0:
            prim_no[no] = False
            return False

    prim_no[no] = True
    return True

def main():
    prim_vals = {}                         # ????????°?????§????´???°????????°
    while True:
        num = sys.stdin.readline()
        if num is None or num.strip() == '':
            break

        num = int(num.strip())
        if prim_vals.get(num) is not None:
            cnt = prim_vals.get(num)
        else:
            #print('num:', num)
            if num == 1:
                cnt = 0
            else:
                cnt = 0
                #for i in range(3, num + 1, 2):
                if num % 2 == 0:
                    start_num = num -1
                else:
                    start_num = num
                    
                for i in range(start_num, 0, -2):
                    #print('i:', i)
                    if prim_vals.get(i) is not None:
                        cnt += prim_vals.get(i)
                        #cnt -= 1
                        break
                    
                    if is_prime(i):
                        cnt += 1
                        
                #cnt += 1             # 2??????????¶????
                prim_vals[num] = cnt # ????????°?????§????´???°????????°????????????(2?????????)

        print(cnt)

if __name__ == '__main__':
    main()
    #print(prim_no)

Measured memory_bytes: 55528
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")

#pragma GCC target("avx,avx2")
using namespace std;
using ll=long long ;
ll get_num(vector<int>v){
  int sum=0;
  ll ans=0;
  for(int i=0;i<v.size();++i){
    if(v[i]==0)sum++;
    else{
      ans+=sum;
    }
  }
  return ans;
}

bool check(int l,int r,string st){
  int num=0;
  for(int x=l;x<=r;++x){
    if(st[x]=='#')num++;
    else num=0;

    if(num==2)return false;
  }
  return true;
}
bool check2(int l,int r,string st){
  int num=0;
  for(int x=l;x<=r;++x){
    if(st[x]=='.')num++;
    else num=0;

    if(num==3)return true;
  }
  return false;
}
    
void solve(){
  int N,A,B,C,D;cin>>N>>A>>B>>C>>D;
  string st;cin>>st;
  st.insert(st.begin(),'#');
  st.insert(st.end(),'#');
  bool ok=true;
  if(!check(A,C,st)){
    ok=false;
  }
  if(!check(B,D,st)){
    ok=false;
  }
  if(D<C){
    if(!check2(B-1,D+1,st)){
      ok=false;
    }
  }
  if(ok)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;

}

int main(void){
  solve();


  return 0;
}

Measured memory_bytes: 772
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;

int main(){
	string s;
	cin>>s;
	s+="PPPPP";
	if(s[0]=='Y'&&s[1]=='A'&&s[2]=='K'&&s[3]=='I'){
		cout<<"Yes";
	}else cout<<"No";

    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
using LL=long long;

struct item
{
	int w,s,v;
}a[3005];

int n;
LL dp[20005];

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d%d%d",&a[i].w,&a[i].s,&a[i].v);
	sort(a+1,a+n+1,[&](item &x, item &y){return x.s+x.w<y.s+y.w;});
	for(int i=1,pos;i<=n;i++)
		for(int j=min(20000,a[i].w+a[i].s);j>=a[i].w;j--)
			dp[j]=max(dp[j],dp[j-a[i].w]+a[i].v);
	printf("%lld",*max_element(dp+1,dp+20001));
	return 0;
}

Measured memory_bytes: 384