akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {
	public static void main(String args[]) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		Solver solver = new Solver();
		solver.init();
		solver.readHead(in.readLine());
		// for (; solver.hasNext();) {
		// solver.readBody(in.readLine());
		// }
	}
}

class Solver {
	int N;
	int cnt;

	public void init() {
		N = 0;
		cnt = 0;
	}

	public void readHead(String str) {
		String[] strArr = str.split(" ");
		int W = Integer.parseInt(strArr[0]);
		int a = Integer.parseInt(strArr[1]);
		int b = Integer.parseInt(strArr[2]);

		int al = a;
		int ar = a + W;
		int bl = b;
		int br = b + W;

		if (al <= bl && bl <= ar) {
			System.out.println(0);
			return;
		}
		if (al <= br && br <= ar) {
			System.out.println(0);
			return;
		}
		if (ar < bl) {
			System.out.println((bl - ar));
			return;
		}
		System.out.println((al - br));

		// N = Integer.parseInt(strArr[0]);
		// System.out.println(N);
	}

	public boolean hasNext() {
		return cnt < N;
	}

	public void readBody(String str) {
		// System.out.println(str);
		cnt++;
	}
}


Measured memory_bytes: 21332
#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long ll;
const int MAXN = 1e5 + 10;

int n, m, pow[MAXN];
ll a[MAXN], b[MAXN], val, spd, sol;

void add( int from, int to ){
	
	if ( from == to ) return;
	
	if ( from < to ){
		b[0] += to - from;
		a[from + 1] -= 1;
		
		a[to] += 1;
		b[to + 1] += to - from - 1;
	}
	else{
		b[0] += to + 1;
		a[0] -= 1;
		
		a[to] += 1;
		b[to + 1] += m + to - from - 1;
		
		a[from + 1] -= 1;
	}
	
}

int main(){
	scanf("%d %d", &n, &m);
	for ( int i = 0; i < n; i++ ){
		scanf("%d", pow + i);
		--pow[i];
	}
	
	for ( int i = 0; i + 1 < n; i++ )
		add(pow[i], pow[i + 1]);
	
	sol = ll(n) * ll(m);
	for ( int i = 0; i < m; i++ ){
		//printf("%d %d %d %d\n", val, spd, a[i], b[i]);
		val += spd + b[i];
		sol = min(sol, val);
		spd += a[i];
	}
	
	printf("%lld\n", sol);
	
	return 0;
}


Measured memory_bytes: 2176
import itertools
import copy
q=int(input())
qr=[list(map(int,input().split())) for i in range(q)]
sosu=[1]*(10**5+1)
sosu[0]=0
sosu[1]=0
k=2
while k<(10**5+1)**0.5+1:
  for i in range(2*k,10**5+1,k):
    sosu[i]=0
  if k==2:
    k+=1
  else:
    k+=2
    
n=[0]*(10**5+1)
for i in range(1,len(sosu)):
  if i%2==1 and sosu[i]==1 and sosu[(i+1)//2]==1:
    n[i]=1
ans=list(itertools.accumulate(n))
for i in range(q):
  print(ans[qr[i][1]]-ans[qr[i][0]-1])

Measured memory_bytes: 32512
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	string day[] = {"mon",
		"tue", "wed", "thu", "fri", "sat", "sun"};
	int x; cin >> x;
	cout << (day[(x + 3) % 7]) << endl;
	return 0;
}


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

int main(){

  int N;
  cin>>N;

  string A,B;
  cin>>A>>B;
  
  rep(i,N){

    cout<<A[i]<<B[i];
    
  }
  cout<<endl;
}




Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <bitset>
#include <cmath>
#include <map>

using namespace std;
#define ll long long
bool IsPrime(ll num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く
    
    double sqrtNum = sqrt(num);
    for (ll i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return false;
        }
    }
    return true;
}

int main(){
    ll a,b; cin >> a >> b;
    int ans = 1;
    for(int i=1;i<=sqrt(a);i++){
        if(a % i == 0){
            if(b%i==0&&IsPrime(i)) ans++;
            if(b%(a/i)==0&&IsPrime(a/i)&&i*i!=a) ans++;
        }
    }
    cout << ans;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
int N,M;
  cin>>N>>M;
  vector<pair<int,int>>A(M);
  if(N%2==0){
  for(int i=0;i<M;i++){
  if(i%2==0){
  int a=(i/2)+1;
    int b=(N+1-a);
    pair<int,int>p(a,b);
    A.at(i)=p;
  }else{
  int a=N/2-(i+1)/2;
    int b=N-a;
    pair<int,int>p(a,b);
    A.at(i)=p;
  }
  
  
  }
  
  }else{
  for(int i=0;i<M;i++){
  int a=i+1;
    int b=N-1-i;
    pair<int,int>p(a,b);
    A.at(i)=p;
  
  }
  }
    for(int i=0;i<M;i++)
    cout<<A.at(i).first<<" "<<A.at(i).second<<endl;
    return 0;
}

Measured memory_bytes: 3936
#include <iostream>
#include <math.h>
#include <limits>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <stdio.h>
#include <map>
#include <utility>
using namespace std;
#define rep(i, n) for (int i =0; i < (int)(n); i++)
typedef pair<int, string> P;



int main() {
    int k, n;
    cin >> k >> n;
    vector<int> a(n),l(n);
    rep(i, n) {
        cin >> a[i];
    }
    a.push_back(a[0] + k);
    int ss=-1;
    rep(i, n) {
        ss = max(ss,a[i + 1]-a[i]);
    }
    cout << k - ss << endl;
}


Measured memory_bytes: 2560
#include <iostream>

int main(){
    int r,d;
    int x[11];
    std::cin >> r >> d >> x[0];
    
    for(int i=0;i<10;i++){
        x[i+1]=r*x[i]-d;
    }
    
    for(int i=1;i<11;i++){
        std::cout << x[i] << std::endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
using namespace std;
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
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;
}

using ll = long long;
using ull = unsigned long long;
const int INF = 2100100100;
const int MOD = 1e9 + 7;

int N, M, K, Q;
string S;

void dfs(int N, int k, string s) {
    if ((int)s.size() == N) {
        cout << s << "\n";
        return;
    }
    for (int i = 0; i < k; i++) {
        string s1 = s;
        s1.push_back((char)(i + 'a'));
        dfs(N, k, s1);
    }
    s.push_back((char)(k + 'a'));
    dfs(N, k + 1, s);
}

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

    cin >> N;

    dfs(N, 0, "");

    return 0;
}


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

vector<long long> v;
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int k;
    cin>>k;
    for(int i=1;i<10;i++)
        v.push_back(i);
    int i=0;
    while(v.size()<k){
        long long a=v[i];
        int d=a%10;
        if(d>0)
            v.push_back(a*10+d-1);
        v.push_back(a*10+d);
        if(d+1<10)
            v.push_back(a*10+d+1);
        i++;
    }
    cout<<v[k-1]<<endl;
    return 0;
}

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

int n, m;
vector<int> a[5000];
bool b[5000];
vector<int> v;

void f(int x){
	for(int i=0; i<a[x].size(); ++i){
		if(!b[a[x][i]]){
			b[a[x][i]] = true;
			f(a[x][i]);
		}
	}
	v.push_back(x);
}

int main(){
	scanf("%d %d", &n, &m);
	for(int i=0; i<m; ++i){
		int s, t;
		scanf("%d %d", &s, &t);
		a[s-1].push_back(t-1);
	}

	for(int i=0; i<n; ++i){
		if(!b[i]){
			b[i] = true;
			f(i);
		}
	}

	for(int i=0; i<v.size(); ++i)
		printf("%d\n", v[v.size()-i-1]+1);

	bool c = false;
	for(int i=0; i<v.size()-1; ++i){
		bool d = false;
		bool e = false;
		for(int j=0; j<a[v[i]].size(); ++j) if(a[v[i]][j] == v[i+1]) d = true;
		for(int j=0; j<a[v[i+1]].size(); ++j) if(a[v[i+1]][j] == v[i]) e = true;
		if(!d && !e) c = true;
	}
	if(c) printf("1\n");
	else printf("0\n");
}

Measured memory_bytes: 3444
#include "stdio.h"

int N = 0;

void sort(int A[],int N){
  int tmp = 0;
  for(int i = 0; i < N - 1; i++){
    for(int j = N - 1; j > i; j--){
      if(A[j - 1] < A[j]){//ソート　逆
        tmp = A[j];
        A[j] = A[j - 1];
        A[j - 1] = tmp;
      }
    }
  }
}

void game(int A[], int alise, int bob){
  for(int k = 0; k < N ; k += 2){
    alise += A[k];
    bob += A[k + 1];
  }

  printf("%d", alise - bob);
}

int main(void){
  //intA[] ←配列はメモリを確保する．
  int alice = 0;
  int bob = 0;
  scanf("%d", &N);
  int A[N + 1];
  for (int i = 0; i < N; i++) {
    scanf("%d", &A[i]);
  }
  A[N] = 0;//番兵

  sort(A, N);

  game(A, alice, bob);
}


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

char s[10000][1025],tmp[20000000],x[1025],*p,q;
int c[10000]={0},n,i,j,f,r;

int main()
{
	for(;scanf("%d\n",&n),n;)
	{
		memset(c,0,sizeof(c));
		memset(tmp,0,sizeof(tmp));
		for(;n--;sprintf(tmp,"%s %s ",tmp,x))
			gets(x);
		q=getchar();

		for(p=strtok(tmp," ");p;p=strtok(NULL," "))
		{
			sscanf(p,"%s",x);
			if(x[0]==q)
			{
				for(i=f=0;s[i][0]&&strcmp(s[i],x)<=0;i++)
					if(strcmp(s[i],x)==0)
						c[i]++,f=1;
				if(!f)
				{
					memmove(s+i+1,s+i,(10000-i-1)*sizeof(x));strcpy(s[i],x);
					memmove(c+i+1,c+i,(10000-i-1)*sizeof(0));c[i]=1;
				}
			}
		}

		for(j=5;j--;)
		{
			for(i=0,r=-1;s[i][0]&&s[i][0]<=q;i++)
				if(s[i][0]==q&&(r==-1||c[i]>c[r]))
					r=i;
			if(r==-1||!c[r])
			{
				printf("%s",j==4?"NA":"");
				break;
			}
			printf("%s%s",j==4?"":" ",s[r]);
			c[r]=0;
		}
		puts("");
	}
	return 0;
}

Measured memory_bytes: 30260
#include<bits/stdc++.h>
using namespace std;
#define all(vec) vec.begin(),vec.end()
typedef long long int ll;
typedef pair<ll,ll> P;
const ll MOD=1234567;
const ll INF=1000000010;
const ll LINF=1000000000000000010LL;
const int MAX=500010;
const double EPS=1e-3;
int dx[4]={0,1,0,1};
int dy[4]={0,0,1,1};
struct UnionFind{
    vector<int> par;
    vector<int> dep;
    
    UnionFind(int siz){
        par.assign(siz,0);
        dep.assign(siz,0);
        for(int i=0;i<siz;i++){
            par[i]=i;
        }
    };

    int find(int x){
        if(par[x]==x){
            return x;
        }else{
            return par[x]=find(par[x]);
        }
    }

    void unite(int x,int y){
        x=find(x);
        y=find(y);
        if(x==y){
            return;
        }
        if(dep[x]<dep[y]){
            par[x]=y;
        }else{
            par[y]=x;
            if(dep[x]==dep[y]){
                dep[x]++;
            }
        }
    }

    bool same(int x,int y){
        return find(x)==find(y);
    }
};
int root1[200010],root2[200010];
int main(){
    int n,k,l;cin>>n>>k>>l;
    UnionFind uf1(n);
    UnionFind uf2(n);
    for(int i=0;i<k;i++){
        int p,q;cin>>p>>q;p--;q--;
        uf1.unite(p,q);
    }
    for(int i=0;i<l;i++){
        int r,s;cin>>r>>s;r--;s--;
        uf2.unite(r,s);
    }
    map<P,int> m;
    for(int i=0;i<n;i++){
        root1[i]=uf1.find(i);
        root2[i]=uf2.find(i);
        m[P(root1[i],root2[i])]++;
    }
    for(int i=0;i<n;i++){
        cout<<m[P(root1[i],root2[i])];
        if(i!=n-1)cout<<" ";
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 16640
use io::*;
use std::*;

fn solve(k: i64) {
    let dat = vec![1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51];
    println!("{}",dat[(k-1) as usize]);
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
fn main() {
    let con = read_string();
    let mut scanner = Scanner::new(&con);
    let  k = scanner.next();
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(move || solve(k)).unwrap().join().unwrap();
}

pub mod io {
    use std;
    use std::str::FromStr;

    pub struct Scanner<'a> {
        iter: std::str::SplitWhitespace<'a>,
    }

    impl<'a> Scanner<'a> {
        pub fn new(s: &'a str) -> Scanner<'a> {
            Scanner {
                iter: s.split_whitespace(),
            }
        }

        pub fn next<T: FromStr>(&mut self) -> T {
            let s = self.iter.next().unwrap();
            if let Ok(v) = s.parse::<T>() {
                v
            } else {
                panic!("Parse error")
            }
        }

        pub fn next_vec_len<T: FromStr>(&mut self) -> Vec<T> {
            let n: usize = self.next();
            self.next_vec(n)
        }

        pub fn next_vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
            (0..n).map(|_| self.next()).collect()
        }
    }

    pub fn read_string() -> String {
        use std::io::Read;

        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }

    pub fn read_line() -> String {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        s.trim_right().to_owned()
    }
}


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

public class Main {
	public static void main(String[] args) {
		final Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int C = sc.nextInt();
		int[] s = new int[N], t = new int[N], c = new int[N];
		int sm[] = new int[200002], tt[] = new int[200002];

		for(int i = 0; i < N; i++) {
			s[i] = sc.nextInt();
			t[i] = sc.nextInt();
			c[i] = sc.nextInt();
		}

		for(int i = 1; i <= C; i++) {//チャンネル数だけ回す
			//	i = チャンネル番号
			Arrays.fill(tt, 0);//初期化
			//以下imos法
			for(int j = 0; j < N; j++) {
				if(c[j]==i) {//チャンネル番号が同じ
					tt[s[j]*2-1]++;
					tt[t[j]*2]--;
				}
			}
			for(int j = 1; j < 200002; j++) {
				tt[j]+=tt[j-1];
			}
			//imos終了
			for(int j = 0; j < 200002; j++) {
				if(tt[j] > 0) {
					sm[j]++;
				}
			}
		}

		int max = 0;
		for(int j = 0; j < sm.length; j++) {
			if(max < sm[j]) {
				max = sm[j];
			}
		}
		System.out.println(max);
	}
}

Measured memory_bytes: 96592
#include <cstdio>
#include <iostream>

using namespace std;

int main(){
	int y, m, d;
	
	while(scanf(" %d %d %d", &y, &m ,&d) != EOF){
		string ans;
		int year;
		bool flag=false;
		
		if(y<1868 || (y==1868 && m<9) || (y==1868 && m==9 && d<=7) ) { 
			ans = "pre-meiji";
			flag=true;
		}
		else if(y<1912 || (y==1912 && m<7) || (y==1912 && m==7 && d<=29) ) {
			ans = "meiji";
			year = y - 1868 + 1;
		}
		else if(y<1926 || (y==1926 && m<12) || (y==1926 && m==12 && d<=24) ) {
			ans = "taisho";
			year = y - 1912 + 1;
		}
		else if(y<1989 || (y==1989 && m<1) || (y==1989 && m==1 && d<=7) ) {
			ans = "showa";
			year = y - 1926 + 1;
		}
		else {
			ans = "heisei";
			year = y - 1989 + 1;
		}
	
		if(flag) cout << ans << endl;
		else cout << ans << " " << year << " " << m << " " << d <<endl;
	}

	return 0;
}

Measured memory_bytes: 1216
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;

constexpr int mod = 1000000007;
struct mint {
  long long x;
  constexpr mint(long long x = 0) : x((x % mod + mod) % mod) {}
  constexpr mint operator-() const { return mint(-x); }
  constexpr mint &operator+=(const mint &a) {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  constexpr mint &operator-=(const mint &a) {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  constexpr mint &operator*=(const mint &a) {
    (x *= a.x) %= mod;
    return *this;
  }
  constexpr mint operator+(const mint &a) const {
    mint res(*this);
    return res += a;
  }
  constexpr mint operator-(const mint &a) const {
    mint res(*this);
    return res -= a;
  }
  constexpr mint operator*(const mint &a) const {
    mint res(*this);
    return res *= a;
  }
  constexpr mint pow(long long t) const {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  constexpr mint inv() const { return pow(mod - 2); }
  constexpr mint &operator/=(const mint &a) { return (*this) *= a.inv(); }
  constexpr mint operator/(const mint &a) const {
    mint res(*this);
    return res /= a;
  }
};
ostream &operator<<(ostream &os, const mint &m) {
  os << m.x;
  return os;
}

struct combination {
  vector<mint> fact, ifact;
  combination(int n) : fact(n + 1), ifact(n + 1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i)
      fact[i] = fact[i - 1] * i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i)
      ifact[i - 1] = ifact[i] * i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n)
      return 0;
    return fact[n] * ifact[k] * ifact[n - k];
  }
};

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

  int n, k;
  cin >> n >> k;
  int a = n - k + 1;
  int b = k - 1;
  combination c1(2001);
  combination c2(2001);

  rep(i, 1, k + 1) {
    mint v = c1(b, i - 1);
    cout << (v * c2(a, i)).x << endl;
  }
}


Measured memory_bytes: 3716
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <map>
#include <queue>
#include <set>

using namespace std;

typedef unsigned long long int ULL;
typedef long long LL;
typedef long double LD;


int main()
{
	
	LL n;
	cin >> n;
	
	LL g[n][3];

	for (LL i = 0; i < n; ++i) {
		for (int j = 0; j < 3; ++j) {
			cin >> g[i][j];
		}
	}

	LL ans[n][3];
	for (int i = 0; i < 3; ++i) {
		ans[0][i] = g[0][i];
	}

	for (LL i = 1; i < n; ++i) {
		ans[i][0] = g[i][0] + max(ans[i-1][1], ans[i-1][2]);
		
		ans[i][1] = g[i][1] + max(ans[i-1][0], ans[i-1][2]);
		
		ans[i][2] = g[i][2] + max(ans[i-1][0], ans[i-1][1]);
	}

	cout << max(ans[n-1][0], max(ans[n-1][1], ans[n-1][2])) << endl;
	 
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
typedef pair<ll,ll> pll;
void read(int& x){ scanf("%d",&x); }
void read(ll& x){ scanf("%lld",&x); }
template<typename T,typename... Args>
void read(T& a,Args&... b){ read(a); read(b...); }
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define eb emplace_back
#define x first
#define y second
 
int a[200010];
int b[200010];
int n;
 
int main()
{
	read(n);
	for(int i=1; i<=n; ++i){
		scanf("%d", a+i); b[i]=a[i];
	}
	sort(b+1, b+n+1);
	for(int i=1; i<=n; ++i) printf("%d\n", b[n/2+(a[i] <= b[n/2])]);
	return 0;
}

Measured memory_bytes: 3712
#include<iostream>
#include<math.h>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<queue>
#include<string>
#include<stdlib.h>
#include <set>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)


	int h, w;



int check(int i, int j, vector<vector<char>> t)
{
	int bom = 0;
	if (i > 0)			if ('#'	== t[i - 1][j] ) bom++;
	if (i<h-1)			if ('#' == t[i + 1][j]) bom++;
	if (j > 0)			if ('#' == t[i][j-1]) bom++;
	if (j < w - 1)		if ('#' == t[i][j+1]) bom++;
	/*if (j>0&&i>0)		if ('#' == t[i - 1][j-1]) bom++;
	if (j>0&&i<h-1)		if ('#' == t[i + 1][j-1]) bom++;
	if (j <w-1 && i>0)	if ('#' == t[i - 1][j + 1]) bom++;
	if (j <w-1&&i<h-1)	if ('#' == t[i + 1][j + 1]) bom++;*/


	return bom;
}
int main(void)
{


	cin >> h >> w;
	bool f = true;

	vector<vector<char>> t(h, vector<char>(w));

	rep(i, h)
	{
		rep(j, w)
		{
			char a;
			cin >> a;

			t[i][j] = a;
		}
	}


	rep(i, h)
	{
		rep(j, w)
		{
			if (t[i][j] == '#') if (check(i, j, t) == 0) f = false;
	
		}
	
	}



	if (f) cout << "Yes" << endl;

	else cout << "No" << endl;
}


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

#define int long long

#define all(v) (v).begin(),(v).end()
#define pb push_back
#define fi first
#define se second
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define low(a,b) lower_bound(all(a),(b))
#define upp(a,b) upper_bound(all(a),(b))
#define fill(i,n) memset(i,n,sizeof(i)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
typedef pair<pint,int> P1;
typedef pair<int,pint> P2;
typedef pair<pint,pint> PP;
static const ll maxLL = (ll)1 << 62;
const ll MOD=1000000007;
const ll INF=1e18;

int N,M,K;
string s;

signed main() {
    IOS();
    /*シフト演算は(1ll<<x)*/
    
    cin>>N>>M>>K;
    int ans=M/K+1;
    N--;
    if(N!=-1)ans-=N/K+1;
    cout<<ans<<endl;
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3

a=[int(input()) for i in range(5)]
k=int(input())
ans=True
for i in range(5):
    for j in range(5):
        if abs(a[i]-a[j]) > k:
            ans=False
if ans:
    print("Yay!")
else:
    print(":(")


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

using namespace std;

#define f first
#define s second
#define pb push_back
#define FILL(a, b) memset(a, b, sizeof(a))

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<pii, pii> piii;
typedef vector<int> vi;
typedef vector<pii> vii;
const int INF = 0x3F3F3F3F;
const int MOD = 1e9 + 7;
const int MAX = 1e5 + 5;

int N, tot = 0;
string S;
ll pref[4][MAX], dp[2][MAX];
ll power[MAX];

inline ll query(int l, int r, ll pref[]) {
    return (pref[r] - pref[l - 1] + MOD) % MOD;
}

inline ll pow3(int n) {
    if (n < 0) {
        return 0;
    } else {
        return power[n];
    }
}

int main() {
    
    cin.sync_with_stdio(0);
    cin.tie(0);
    
    cin >> S;
    N = (int) S.length();
    S = ' ' + S;
    power[0] = 1;
    for (int i = 1; i <= N; i++) {
        power[i] = power[i - 1] * 3 % MOD;
        if (S[i] == 'A') {
            pref[0][i] = 1;
        } else if (S[i] == 'B') {
            pref[1][i] = 1;
        } else if (S[i] == 'C') {
            pref[2][i] = 1;
        } else {
            tot++;
            pref[3][i] = 1;
        }
        for (int j = 0; j <= 3; j++) {
            pref[j][i] += pref[j][i - 1];
        }
    }
    
    for (int i = 1; i <= N; i++) {
        for (int j = 0; j <= 1; j++) {
            if (S[i] == 'B') {
                dp[j][i] = (query(i + 1, N, pref[2]) * pow3(tot - j) % MOD
                            + query(i + 1, N, pref[3]) * pow3(tot - 1 - j) % MOD) % MOD;
            } else if (S[i] == '?') {
                dp[j][i] = (query(i + 1, N, pref[2]) * pow3(tot - 1 - j) % MOD
                            + query(i + 1, N, pref[3]) * pow3(tot - 2 - j) % MOD) % MOD;
            }
            //printf("%lld %lld\n", dp[i], power[max(0, tot - 1)]);
            dp[j][i] += dp[j][i - 1];
            dp[j][i] %= MOD;
        }
    }
    ll ans = 0;
    for (int i = 1; i <= N; i++) {
        if (S[i] == 'A') {
            ans += query(i + 1, N, dp[0]);
            ans %= MOD;
        } else if (S[i] == '?') {
            ans += query(i + 1, N, dp[1]);
            ans %= MOD;
        }
    }
    printf("%lld\n", ans);
    
    return 0;
}


Measured memory_bytes: 5868
#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];

	vector<int> b(N);
	for (int i = 1; i <= N; i++) b[i-1] = i;
	vector<pair<int, int>> ab(N);
	for (int i = 0; i < N; i++) {
		ab[i] = make_pair(A[i], b[i]);
	}

	sort(ab.begin(), ab.end());
	for (int i = 0; i < N; i++) {
		cout << ab[i].second << " ";
	}
	cout << endl;
}

Measured memory_bytes: 2432
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long long int lli;
typedef long double ld;
const int oo = 1e9;
const int mod = 1e9+9;

const int nax = 1e5+3;
int n;
int dp[nax];
int a[nax];
int f(int i){
	if (i==n-1) return 0;
	if(dp[i]!=-1) return dp[i];
	int ans = abs(a[i]-a[i+1])+f(i+1);
	if(i!=n-2) ans = min(ans, abs(a[i]-a[i+2])+f(i+2));
	return dp[i]=ans;
}
int main(){
	cin>>n;
	for(int i=0; i<n; i++) cin>>a[i];
	memset(dp, -1, sizeof dp);
	cout<<f(0)<<endl;
	return 0;
}

Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n, a[5];
    cin>>a[1]>>a[2]>>a[3];
    sort(a+1, a+4);
    if (a[1]!=5 || a[2]!= 5 || a[3] != 7) cout<<"NO"; else cout<<"YES";
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

long long a[101010];
long long num[101010];

long long min(long long a, long long b){
    if(a < b) return a;
    else return b;
}

int main(){
    int n; scanf("%d",&n);
    for(int i=0; i<=n; i++) scanf("%lld",&a[i]);
    num[0] = 1;
    for(int i=0; i<=n; i++){
        if(num[i] < a[i]){
            printf("-1\n");
            return 0;
        }
        if(i == n) break;
        num[i] -= a[i];
        num[i+1] = min(1LL<<60, num[i] * 2);
    }
    long long ans = a[n];
    long long now = a[n];
    for(int i=n-1; i>=0; i--){
        ans += min(num[i], now) + a[i];
        now += a[i];
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 3296
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
  
int main() {
  int N;
  cin >> N;
  vl dp(N+1,0);
  dp[0] = 2;
  dp[1] = 1;
  srep(i,2,N+1) {
    dp[i] = dp[i-1] + dp[i-2];
  }
  cout << dp[N] << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define mod 1000000007
#define fast ios::sync_with_stdio(false); cin.tie(0)
#define setpres(x) fixed<<setprecision(x)
using namespace std;
vector<int> v[100001];
bool vis[100001];
void dfs(int s)
{
    vis[s]=1;
    for(auto x:v[s])
    {
        if(!vis[x])
            dfs(x);
    }
}
int32_t main()
{
    int tt=1;
    //cin>>tt;
    while(tt--)
    {
        int n,m;
        cin>>n>>m;
        for(int i=0;i<m;i++)
        {
            int a,b;
            cin>>a>>b;
            v[a].pb(b);
            v[b].pb(a);
        }
        int cc=0;
        for(int i=1;i<=n;i++)
        {
            if(!vis[i])
                dfs(i), cc++;
        }
        cout<<cc-1;
    }
}



Measured memory_bytes: 10360
K = int(raw_input())
S = raw_input().strip()
L = len(S)

P = 10**9 + 7

facts = [0 for _ in xrange(L + K)]
finvs = [0 for _ in xrange(L + K)]
facts[0] = 1
for i in xrange(1, L+K):
  facts[i] = (i*facts[i-1]) % P

finvs[L+K-1] = pow(facts[L+K-1], P-2, P)
for i in xrange(L+K-2, -1, -1):
  finvs[i] = (finvs[i+1]*(i+1)) % P

ans = 0
for k in xrange(0, K+1):
  ncr = (facts[k+L-1]*finvs[k]*finvs[L-1]) % P
  ans += ncr * pow(25, k, P) * pow(26, K-k, P)
  ans %= P

print ans


Measured memory_bytes: 126344
//Range Flip Find Route

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long
#define rep(i,x,y) for(ll i=x;i<y;i++)
#define nvarep(n,a) ll n;cin>>n;vector<ll>a(n);rep(i,0,n)cin>>a[i]
#define vecrep(n,a,type) vector<type>a(n);rep(i,0,n)cin>>a[i]
#define YN(flag) (flag?"Yes":"No")
#define lcm(a,b) (a/__gcd(a, b)*b)
#define range(a) (a).begin(),(a).end() 
#define pb push_back
#define mp make_pair
#define nnn "\n"
#define spa " "
using P = pair<ll,ll>;
using graph = vector<vector<ll>>;
const int inf = 2147483647;//2*10^9
const ll INF = 9223372036854775807;//9*10^18

signed main (){
    int h,w;cin>>h>>w;
    vecrep(h,s,string);
    vector<vector<int>>ans(h,vector<int>(w,0));
    if(s[0][0]=='#')ans[0][0]=1;
    rep(i,1,h){
        if(s[i-1][0]!=s[i][0]&&s[i][0]=='#')ans[i][0]=ans[i-1][0]+1;
        else ans[i][0]=ans[i-1][0];
    }
    rep(i,1,w){
        if(s[0][i-1]!=s[0][i]&&s[0][i]=='#')ans[0][i]=ans[0][i-1]+1;
        else ans[0][i]=ans[0][i-1];
    }
    rep(i,1,h){
        rep(j,1,w){
            int ue = ans[i-1][j] + (s[i-1][j]!=s[i][j]&&s[i][j]=='#'?1:0);
            int hd = ans[i][j-1] + (s[i][j-1]!=s[i][j]&&s[i][j]=='#'?1:0);
            ans[i][j] = min(ue,hd);
        }
    }
    cout<<ans[h-1][w-1]<<nnn;
    return 0;
}

Measured memory_bytes: 3708
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<stdio.h>



using namespace std;


int main(void)
{
	int n;
	int a;
	cin >> n;
	vector<int> v(n);
	vector<int> c(n);
	int i;
	for (i = 0; i < n; i++)
	{
		cin >> v[i];
	}
	for (i = 0; i < n; i++)
	{
		a = v[i];
		c[i] = a;
	}
	sort(v.begin(), v.end());
	for (i = 0; i < n; i++)
	{
		if (v[n-1] != c[i])
		{
			cout << v[n-1] << endl;
		}
		else
		{
			cout << v[n-2] << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
int main(){

    string N;
    cin >> N;
    long long n = N.size(),i,j,sum=0,c[n];

    for(i = 0; i < n; i++) {
        c[i] = N[i] - '0';
    }
    for(i = 0; i < n-1; i += 1) {

        if (c[i + 1] != 9) {
                c[i] -= 1;
                c[i + 1] = 9;
                break;
            
        }
    }
    if(i != n-2) {
        for (j = i + 2; j < n; j++) {
            c[j] = 9;
        }
    }


    for(i = 0; i < n; i++){
        sum += c[i];
    }

    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 256
import fractions

def main():
    a, b, c, d = map(int, input().split())
    l =  (c * d) // fractions.gcd(c, d)
    cntb = b - (b // c + b // d - b // l)
    cnta = (a-1) - ((a-1) // c + (a-1) // d - (a-1) // l)
    ans = cntb - cnta

    print(ans)

if __name__ == '__main__':
    main()

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

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


Measured memory_bytes: 384
#include <iostream>
#include <map>
#include <vector>

using namespace std;


int main()
{
    int N;
    cin >> N;
    map<int, int> count;

    int comp_num = N < 3 ? N : 3;
    for (int i = 0; i < comp_num; i++) {
        int A;
        cin >> A;
        count[A]++;
        for (int j = 2; j*j <= A; j++) {
            if (A % j == 0) {
                count[j]++;
                if (i * i != A) {
                    count[A / j]++;
                }
            }
        }
    }

    for (auto i = count.begin(); i != count.end(); i++) {
        if (i->second == 1) {
            i = count.erase(i);
        }
    }


    // for (auto i = count.begin(); i != count.end(); i++) {
    //     cout << i->first << " " << i->second << endl;
    // }

    for (int i = 3; i < N; i++) {
        int A;
        cin >> A;

        for (auto itr = count.begin(); itr != count.end(); itr++) {
            if (A % itr->first == 0) {
                count[itr->first]++;
            }

        }
    }

    int max = 1;
    for (auto i = count.begin(); i != count.end(); i++) {
        // cout << i->first << " " << i->second << endl;
        if (i->second >= N-1) {
            max = i->first;
        }
    }

    cout << max << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<ll, ll>;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }
struct FastIO {FastIO() { cin.tie(0); ios::sync_with_stdio(0); }}fastiofastio;
#ifdef DEBUG_ 
#include "../program_contest_library/memo/dump.hpp"
#else
#define dump(...)
#endif
const ll INF = 1LL<<60;

int main(void) {
    string s;
    cin >> s;
    ll n = s.size();

    ll ret = 0;
    REP(i, n/2) if(s[i] != s[n-1-i]) ret++;
    cout << ret << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
     
int main() {    
  long n, a, b, i, result;
      scanf("%ld", &n);
      result = n;
      for(a = 1; a*a <= n; a++) {
        if(n%a == 0) {
          b = n/a;
          i = 0;
        while(b > 0) {
    	  b /= 10;
          i++;
          }
       if(i < n) {
    	result = i;
          }
        }
      }
      printf("%ld\n", result);
      return 0;
    }

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

int main(){
    int n,count=0;
    cin >> n;
    string s;
    cin >> s;
    rep(i,n){
        if(i!=0 && s[i-1]==s[i])++count;
    }
    cout << n-count << endl;
}

Measured memory_bytes: 512
#include <stdio.h>

int main(void)
{
	char a, b, p;
	int s;
	
	for(p=0;~scanf(" %c,%c",&a,&b);p<=s&&(p=(s-p)%3))s=a+b-130;
	printf("%c\n",65+p);
	return (0);
}

Measured memory_bytes: 540
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int main()
{
	string s;
	int flag1=0;
	int flag2=0;
	cin>>s;
	for(int i=0;i<s.length();i++)
	{
		if(s[i]=='C')
			flag1=1;
		if(s[i]=='F'&&flag1==1)
			flag2=1;
	}
	if(flag1==1&&flag2==1)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
import numpy as np
H,W = map(int,input().split())
grid = []
ans = []
for i in range(H):
    h = list(input())
    if "#" in h:
        grid.append(h)
grid = np.array(grid)
grid = grid.T
for i in range(len(grid)):
    w = grid[i]
    if "#" in w:
        ans.append(w)
ans = np.array(ans).T
for i in ans:
    print("".join(i))


Measured memory_bytes: 12488
#include<iostream>
using namespace std;
int main(){
	int n,a,b,ans;
	while(cin>>n,n){
		ans=-1;
		for(int i=1;i<=12;i++){
			cin>>a>>b;
			n -= a-b;
			if(ans==-1 && n<=0)ans=i;
		}
		if(ans!=-1)cout<<ans<<endl;
		else cout<<"NA\n";
	}
}

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

ll gcd(ll m,ll n){
  if(n==0) return m;
  return gcd(n,m%n);
}

int main(){
  ll N;
  cin >> N;
  vector<ll> A;
  ll a;
  for(int i=0;i<N;i++){
    cin >> a;
    A.push_back(a);
  }
  
  //累積GCD
  vector<ll> L(N+2,0);//1-(i-1)
  vector<ll> R(N+2,0);//i-N
  for(int i=1;i<=N;i++){
    L[i+1]=gcd(L[i],A[i-1]);
  }
  for(int i=N;i>0;i--){
    R[i]=gcd(R[i+1],A[i-1]);
  };
  
  vector<ll> M;
  for(int i=1;i<=N;i++){
    M.push_back(gcd(L[i],R[i+1]));
  }
  sort(M.begin(),M.end(),greater<ll>());
  cout<<*M.begin()<<endl;
  return 0;
}

Measured memory_bytes: 4084
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <bitset>
#include <random>
#include <complex>
#include <assert.h>

using namespace std;
typedef long long ll;
#define endl '\n'

template<typename T>
inline bool chmin(T& x, T a) {
	if (x >= a) { x = a; return true; }
	return false;
}

template<typename T>
inline bool chmax(T& x, T a) {
	if (x <= a) { x = a; return true; }
	return false;
}

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

	vector<int> ans(10001, 0);
	for (int x = 1; x <= 100; x++) {
		for (int y = 1; y <= 100; y++) {
			for (int z = 1; z <= 100; z++) {
				int n = x * x + y * y + z * z + x * y + y * z + z * x;
				if (n <= 10000) {
					ans[n]++;
				}
			}
		}
	}

	int N; cin >> N;
	for (int i = 1; i <= N; i++) {
		cout << ans[i] << endl;
	}

	return 0;
}

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

#define endl "\n"
#define f first
#define s second
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define ll long long
#define faster ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

const ll M = 998244353;
const int N = 1e6+5;
const ll INF = 1e18;

ll n,m,l[N],r[N],a[N],cnt;

int main() {
	faster;
	cin>>n>>m;
	for (int i = 1; i<=m; i++) {
		cin>>l[i]>>r[i];
		a[l[i]]++;
		a[r[i]+1]--;
	}
	for (int i = 1; i<=n; i++) {
		a[i]+=a[i-1];
		if (a[i] == m) {
			cnt++;
		}
	}
	cout<<cnt;

    return 0;
}


Measured memory_bytes: 9216
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define fast()    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

int main()
{
	fast()
	ll r,c;
	cin>>r>>c;
	ll k=r*c;
	if(r==1 || c==1)
	cout<<1;
	else {
	if(k%2==0)
	cout<<(k/2);
	else
	cout<<(k+1)/2;
}
}
		
		
		
		
	
	

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n,m) for(int i = (n); i <(m); i++)
#define rrep(i,n,m) for(int i = (n) - 1; i >=(m); i--)
#define pvec(vec) {for (auto v: vec) cout << v << ' '; cout << endl;}
#define pivec(vec) {rep(i, 0, vec.size()) cout << i << ':' << vec[i] << ' '; cout << endl;}

using namespace std;
using ll = long long;

int main()
{
    int n, m;
    cin >> n >> m;
    
    vector<pair<int, int>> battles(m);
    int pos1 = 0;
    int pos2 = 0;
    rrep(wid, m+1, 1)
    {
        int state = (pos1+pos2);
        if (state%2 == 0)
        {
            battles[state] = make_pair(pos1, pos1+wid);
            ++pos1;
        }
        else
        {
            battles[state] = make_pair(pos2+m+1, pos2+m+1+wid);
            ++pos2;
        }
    }

    vector<bool> check(n, false);
    for (auto battle: battles)
    {
        if (check[battle.first] or check[battle.second])
        {
            cout << "wrong battle: " << battle.first+1 << ' ' << battle.second+1 << ' ' << endl;
        }
        check[battle.first] = check[battle.second] = true;

        printf("%d %d\n", battle.first+1, battle.second+1);
    }

    return 0;
}


Measured memory_bytes: 3976
// finish date: 2018/01/23
#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <map>
#include <climits>

using namespace std;

#define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i, n)  FOR(i,0,n)
#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define bigmod 1000000007
#define INF 500000000


int main() {
    int N;
    cin >> N;
    map<int, int> mp;
    int A;
    rep(i, N) {
        cin >> A;
        if (mp.count(A)) mp.erase(A);
        else mp[A] = 1;
    }
    cout << mp.size() << endl;

    return 0;
}



Measured memory_bytes: 4864
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String a = scan.next();
        String b = scan.next();
        String c = scan.next();
        
        Integer ia = 0, ib = 0, ic = 0;

        char d = 'a';
        while(true) {
            if (d == 'a') {
                if (ia >= a.length()) {
                    System.out.println("A");
                    return;
                }
                d = a.charAt(ia++);
            } else if (d == 'b') {
                if (ib >= b.length()) {
                    System.out.println("B");
                    return;
                }
                d = b.charAt(ib++);
            } else {
                if (ic >= c.length()) {
                    System.out.println("C");
                    return;
                }
                d = c.charAt(ic++);
            }
        }
    }
}


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

int main(){
    ll a,b,v,w,t;
    cin>>a>>v>>b>>w>>t;
    ll k=v-w;
    ll l=abs(a-b);
    if(k<=0){
        cout<<"NO"<<endl;
    }
    else{
        if(k*t>=l){
            cout<<"YES"<<endl;
        }
        else{
            cout<<"NO"<<endl;
        }
    }
}

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

int main() {
    int K, A, B;
    cin >> K >> A >> B;
    ll ans = 1;
    if (B-A <= 2 || K <= A-1) {
        cout << K+1 << endl;
        return 0;
    }
    K -= A-1;
    ans += A-1;
    ll count = K/2;
    ans += count*(B-A) + K%2;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>

using namespace std;

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

	int ans = 0;

	for (int i = 2; i < n; i++){
		if ((p[i - 2] < p[i - 1] && p[i - 1] < p[i]) || (p[i - 2] > p[i - 1] && p[i - 1] > p[i])) {
			ans++;
		}
	}
	cout << ans << endl;
}


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

#define PI acos(-1.0)
#define nl '\n'

typedef long long int ll;
typedef unsigned long long int  llu;

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

    double x,ans;
    cin>>x;
    ans=2*PI*x;
    cout<<fixed<<setprecision(20)<<ans<<nl;
    return 0;
}


Measured memory_bytes: 3764
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
ll modpow(ll a, ll n) {
    ll res = 1;
    while(n > 0) {
        if(n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }

    return res;
}

ll comb(ll a, ll b) {
    ll ans = 1;

    for(ll i = a; i > a - b; i--) {
        ans = ans * i % mod;
    }
    for(ll i = 1; i <= b; i++) {
        ans = (ans * modpow(i, mod - 2)) % mod;
    }
    return ans;
}

int main() {
    int N, A, B;
    cin >> N >> A >> B;

    cout << (modpow(2, N) - comb(N, A) - comb(N, B) - 1 + mod + mod) % mod;
    return 0;
}

Measured memory_bytes: 256
/*raghav0307 - Raghav Gupta*/

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

#define ff first
#define ss second
#define pb push_back
#define fast_io() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

typedef long long ll;

int main(){
	fast_io();
	int n;	cin >> n;
	int v[n];
	for(int i = 0; i < n; i++)	cin >> v[i];
	int c[n];
	for(int i = 0; i < n; i++)	cin >> c[i];
	int ans = 0;
	for(int i = 0; i < n; i++)	ans += max(0, v[i]-c[i]);
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
 
int main() {
  int N, M;
  cin >> N >> M;
  
  vector<int> a(M), b(M);
  for (int i = 0; i < M; i++) {
    cin >> a.at(i) >> b.at(i);
  }
  
  vector<int> c(N);
  for (int i = 0; i < M; i++) {
    c.at(a.at(i) -1)++;
    c.at(b.at(i) -1)++;
  }
  
  for (int i = 0; i < N; i++) {
    cout << c.at(i) << endl;
  }
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){


int ai,n,i,min,max;


long sum;


scanf("%d",&n);


for(i=0;i<n;i++){


scanf("%d",&ai);


if(i==0){


min=ai;


max=ai;


sum=ai;


}


else{


sum=sum+ai;


if(min>ai){


min=ai;


}


if(max<ai){


max=ai;



}


}


}


printf("%d %d %ld\n",min,max,sum);


return 0;


}

Measured memory_bytes: 600
package main

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

//=====I/O=====

var (
	sc = bufio.NewScanner(os.Stdin)
	wr = bufio.NewWriter(os.Stdout)
)

func scanInt() int {
	sc.Scan()
	a,_ := strconv.Atoi(sc.Text())
	return a
}

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ { res[i] = scanInt() }
	return res
}

func scanText() string {
	sc.Scan()
	return sc.Text()
}

func printInts(a ...int) {
	for i, e := range a {
		fmt.Fprint(wr, e)
		if i != len(a)-1 { fmt.Fprint(wr, " ") }
	}
	fmt.Fprintln(wr)
	wr.Flush()
}

//=====main=====

func main() {
	sc.Split(bufio.ScanWords)

	n := scanInt()
	d := scanInts(n)

	ans := 0

	for i := 0; i < n; i++ {
		for j := i+1; j < n; j++ {
			ans += d[i]*d[j]
		}
	}

	fmt.Println(ans)
}


Measured memory_bytes: 640
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i8 = int8_t;
using i16 = int16_t;
using i32 = int32_t;
using i64 = int64_t;

constexpr char newl = '\n';
constexpr double eps = 1e-10;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
#define fi first
#define se second
#define debug(x) cout << #x << ": " << x << '\n';
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()

template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
template<class T> void Print(vector<T> v) {
  F0R(i, v.size()) {
    cout << v[i] << ' ';
  }
  cout << newl;
}

#if 1

#ifdef __GNUC__
#define popcount __builtin_popcountll
#else
// 立っているビットを数える
constexpr int popcount(u64 x)
{
  x = (x & 0x5555555555555555) + (x >> 1 & 0x5555555555555555);
  x = (x & 0x3333333333333333) + (x >> 2 & 0x3333333333333333);
  x = (x & 0x0f0f0f0f0f0f0f0f) + (x >> 4 & 0x0f0f0f0f0f0f0f0f);
  x = (x & 0x00ff00ff00ff00ff) + (x >> 8 & 0x00ff00ff00ff00ff);
  x = (x & 0x0000ffff0000ffff) + (x >> 16 & 0x0000ffff0000ffff);
  return (int)((x & 0x00000000ffffffff) + (x >> 32 & 0x00000000ffffffff));
}
#endif

// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int N;
  string X;
  cin >> N >> X;

  int pc = 0;
  F0R(i, N) {
    if (X[i] == '1') pc++;
  }
  int pcl = pc - 1, pcr = pc + 1;

  auto xmod = [&](int v) {
    int n = 0;
    F0R(i, N) {
      n <<= 1;
      if (X[i] == '1') n++;
      n %= v;
    }
    return n;
  };

  // X % (pc, pcl, pcr)
  //int xm = xmod(pc);
  int xml = pcl ? xmod(pcl) : 0;
  int xmr = pcr ? xmod(pcr) : 0;

  // pow(2, n) % pc
  int twol = 1, twor = 1;

  auto calc = [](int n) {
    int r = 0;
    while (n) {
      //debug(n);
      n %= popcount(n);
      r++;
    }
    return r;
  };

  vector<int> rs(N);
  RF0(i, N) {
    if (pcl) twol %= pcl; else twol = 0;
    if (pcr) twor %= pcr; else twor = 0;

    int n;
    if (X[i] == '0') {
      n = xmr + twor;
      if (n >= pcr) n -= pcr;
      rs[i] = 1 + calc(n);
    }
    else {
      if (pcl) {
        n = xml - twol;
        if (n < 0) n += pcl;
        rs[i] = 1 + calc(n);
      }
      else {
        rs[i] = 0;
      }
    }

    twol <<= 1;
    twor <<= 1;
  }

  F0R(i, N) {
    cout << rs[i] << newl;
  }
}
#endif


Measured memory_bytes: 4396
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,q,w,e;
	cin>>n;
	q=n%10;
	n/=10;
	w=n%10;
	n/=10;
	e=n%10;
	if(q!=7&&w!=7&&e!=7)
	{
		printf("No");
	}
	else
	{
		printf("Yes");
	}
} 


Measured memory_bytes: 3764
#include <stdio.h>

int main(void)
{
  int h1,h2,a1,a2;
  int flag=0;
  scanf("%d",&h1);
  scanf("%d",&a1);
  scanf("%d",&h2);
  scanf("%d",&a2);
  
  do
  {
    h2-=a1;
    
    if(h2<=0)
    {  
      flag=1;
      break;
    }
    h1-=a2;
  }while(h1>0);
  
  
  if(flag)
    printf("Yes");
  else 
    printf("No");
  
  return 0;
}
    

Measured memory_bytes: 1736