akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cassert>
#include <fstream>
#include <sstream>
#include <math.h>
#include <memory>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <time.h>
#include <stdio.h>
#include <deque>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define POW(n) ((n)*(n))
#define ALL(a) (a).begin(),(a).end()
#define cerr if(false) cerr

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<unsigned long long> vull;

string W;
const int alp = ('z' - 'a') + 1;
int L[alp];

void solve() {
	REP(i,W.size()) {
		L[W[i] - 'a']++;
	}

	REP(i,alp) {
		if (L[i] % 2 != 0) {
			cout << "No" << endl;
			return;
		}
	}
	cout << "Yes" << endl;
}

int main() {
	cin >> W;

	solve();

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
  int i,j,a[100],n,flag,tmp,cnt=0;

  scanf("%d",&n);
  for(i=0;i<n;i++)
    {
      scanf("%d",&a[i]);
    }
  flag = 1;
  i=0;
  while(flag==1)
    {
      flag = 0;
      for(j=n-1;j>i;j--)
	{
	  if(a[j]<a[j-1])
	    {
	      tmp = a[j];
	      a[j] = a[j-1];
	      a[j-1] = tmp;
	      cnt++;
	      flag = 1;
	    }
	}
      i++;
    }
  for(j=0;j<n;j++)
    {
      if(j!=0)printf(" ");
      printf("%d",a[j]);
    }
  printf("\n%d\n",cnt);

  return 0;
}



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

using namespace std;

#define REP(i, n) for(int i=0;i<(int)n;i++)
#define ALL(v) v.begin(), v.end()
#define pb push_back
typedef vector<int> vi;

enum DIR { LEFT, RIGHT, FRONT, BACK, BOTTOM, TOP };
int rotm[4][6]={
	{5,4,2,3,0,1},
	{0,1,5,4,2,3},
	{0,1,4,5,3,2},
	{4,5,2,3,1,0}
};

struct Dice{
	vi d, x;
	Dice(vi d):d(d), x(6){
		
	}
	
	inline int &operator[](int i){
		return d[i];
	}
	
	inline void rot(int k){
		REP(i, 6) x[rotm[k][i]] = d[i];
		swap(d, x);
	}
	
	inline int check(){
		if(d[BOTTOM] == -1) return 0;
		const int A = d[BOTTOM] + d[TOP];
		const int B = d[LEFT] + d[RIGHT];
		const int C = d[FRONT] + d[BACK];
		return (A <= B+C && B <= A+C+1 && C <= A+B+1);
	}
	
};
int n;
string db = "ENSW";
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	while(1){
		vi t(6);
		REP(i, 6) cin >> t[i];
		sort(ALL(t));
		if(t[5] == 0) break;
		int n = accumulate(ALL(t), 0);
		string ans(n, 'Z');
		do{
			Dice dice(t);
			string tmp;
			int f = 0;
			REP(itr, n){
				REP(i, 4){
					dice.rot(i);
					dice[BOTTOM] --;
					if(dice.check()){
						tmp.pb(db[i]);
						break;
					}
					dice[BOTTOM] ++;
					dice.rot(3-i);
				}
				if(tmp.size() != itr+1 || !f && ans[itr] < tmp[itr]) break;
				f |= ans[itr] > tmp[itr];
			}
			if(tmp.size() == n) ans = min(ans, tmp);
		}while(next_permutation(ALL(t)));
		int p, q;
		cin >> p >> q; p--;
		if(ans[0] == 'Z') cout << "impossible" << endl;
		else cout << ans.substr(p, q-p) << endl;
	}
}

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

using namespace std;

int a[4],b[2];

int main(){
    cin>>a[0]>>a[1]>>a[2]>>a[3]>>b[0]>>b[1];
    sort(a,a+4);sort(b,b+2);
    cout<<a[1]+a[2]+a[3]+b[1]<<endl;
}


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

int main () {
  int N;
  cin >> N;

  vector<int> data1 = {2, 4, 5, 7, 9};
  vector<int> data2 = {0, 1, 6, 8};
  vector<int> data3 = {3};

  for (int i = 0; i < 5; i++){
    if (N % 10 == data1.at(i)){
      cout << "hon" << endl;
      break;
    }
  }

  for (int i = 0; i < 4; i++) {
    if (N % 10 == data2.at(i)) {
      cout << "pon" << endl;
    }
  }

  if (N % 10 == data3.at(0)) {
    cout << "bon" << endl;
  }
}


Measured memory_bytes: 3636
import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Arrays;
import java.util.Collections;
import java.util.*;
class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    int N = scan.nextInt();
    Integer X[] = new Integer[N];
    int sum = 0;
    int summ = 0;
    for (int i = 0; i < N; i++) {
      X[i] = scan.nextInt();
      sum += X[i];
    }
    //真ん中を求める
    int HP = (sum / N);
    int HPP = (sum / N) + 1;
    sum = 0;
    //体力消耗量
    for (int i = 0; i < N ; i++) {
      sum += (X[i] - HP) * (X[i] - HP);
    }
    for (int i = 0; i < N ; i++) {
      summ += (X[i] - HPP) * (X[i] - HPP);
    }
    if (sum < summ) {
      System.out.println(sum);
    }
    else{
      System.out.println(summ);
    }
  }
}


Measured memory_bytes: 22612
MAX=1000000
B=[]
def P(MAX,B):

    A=[i for i in range(2,MAX+1)]
    lim=MAX**(1/2)
    while True:
        p=A[0]
        if p>lim:
            B+=A
            return B
        else:
            B.append(p)
            A=[i for i in A if i%p!=0]
            
P(MAX,B)
while True:
    try:
        n=int(input())
        if n==1:
            print(0)
        elif n>=max(B):
            print(len(B))
        else:
            for i in range(n+1):
                if B[i]==n:
                    print(i+1)
                    break
                if B[i]>n:
                    print(i)
                    break

    except:
        break


Measured memory_bytes: 48908
#!/usr/bin/env python
# coding: utf-8

# In[6]:


import bisect


# In[1]:


N = int(input())


# In[30]:


A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
C = [int(x) for x in input().split()]
lenC = len(C)


# In[3]:


A.sort()
B.sort()
C.sort()


# In[49]:


ans = 0
for b in B:
    ans += bisect.bisect_left(A, b) * (lenC - bisect.bisect_right(C, b))
print(ans)


# In[ ]:





# In[ ]:





# In[ ]:






Measured memory_bytes: 104804
#include<iostream>
#include<math.h>
#include<stdio.h>
using namespace std;
int main(){
  int d,i,j,k;
  cin >> d;
  double a[1000]={},b[1000]={};
  for(i=0;i<d;i++) cin >> a[i];
  for(i=0;i<d;i++) cin >> b[i];
  double o1=0,o2=0,o3=0,oe=0;
  for(i=0;i<d;i++){
    o1+=fabs(a[i]-b[i]);
    o2+=fabs(a[i]-b[i])*fabs(a[i]-b[i]);
    o3+=fabs(a[i]-b[i])*fabs(a[i]-b[i])*fabs(a[i]-b[i]);
    oe=max(oe,fabs(a[i]-b[i]));
  }
  printf("%.6f\n",o1);
  printf("%.6f\n",sqrt(o2));
  printf("%.6f\n",pow(o3,1.0/3.0));
  printf("%.6f\n",oe);
  return 0;
}



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

using namespace std;
typedef long long ll;

struct mint{
    static const long long MOD = 1000000007;

    long long v;

    mint() : v(0) {}
    mint(long long x){
        x = x % MOD;
        if(x < 0){ x += MOD; }
        v = x;
    }
    mint& operator+=(mint a){
        v += a.v;
        if(v >= MOD){ v -= MOD; }
        return *this;
    }
    mint& operator*=(mint a){
        v *= a.v;
        v %= MOD;
        return *this;
    }
    mint& operator-=(mint a){
        v -= a.v;
        if(v < 0){ v += MOD; }
        return *this;
    }
    mint& operator/=(mint a){
        return (*this) *= a.inv();
    }

    mint operator*(mint a) const{
        return mint(v) *= a;
    }

    mint operator+(mint a) const {
        return mint(v) += a;
    }

    mint operator-(mint a) const {
        return mint(v) -= a;
    }

    mint operator/(mint a) const {
        return mint(v) /= a;
    }

    mint pow(long long k) const {
        mint res(1),tmp(v);
        while(k){
            if(k&1) res *= tmp;
            tmp *= tmp;
            k >>= 1;
        }
        return res;
    }
    mint inv(){return pow(MOD - 2); }

    static mint comb(long long n, int k){
        mint res(1);
        for(int i = 0; i < k; ++i){
            res *= mint(n - i);
            res /= mint(i + 1);
        }
        return res;
    }

    static mint factorial(long long n){
        mint res(1);
        for(int i = n; i > 1; --i){
            res *= mint(i);
        }
        return res;
    }

    bool operator<(const mint &a) const {
        return v < a.v;
    };
};

mint operator*(long long l, mint r){ return r * l; }

int main(){
    ll n, k;
    cin >> n >> k;
    vector<mint> dp(k + 1);
    dp.at(k) = 1;
    for(int i = 0; i < n; ++i){
        ll a;
        cin >> a;

        vector<mint> cs(k + 2, 0);
        cs.at(0) = dp.at(0);
        for(int j = 1; j <= k + 1; ++j){
            cs.at(j) = cs.at(j - 1) + dp.at(j - 1);
        }

        vector<mint> nxt(k + 1, 0);
        for(int j = 0; j <= k; ++j){
            nxt.at(j) = cs.at(min(j + a, k) + 1) - cs.at(j);
        }
        dp.swap(nxt);
    }
    cout << dp.at(0).v << endl;
    return 0;
}


Measured memory_bytes: 2780
#include <bits/stdc++.h>
using namespace std;
int main() {
	long int d, n; cin >> d >> n;
	if(d==0 && n==100){
		cout << n+1 << endl;
		return 0;
	}
	if(d==1 && n==100){
		cout << (n+1)*100 << endl;
		return 0;
	}
	if(d==2 && n==100){
		cout << (n+1)*10000 << endl;
		return 0;
	}
	if(d==0){
		cout << n << endl;
		return 0;
	}
	if(d==1){
		cout << n*100 << endl;
		return 0;
	}
	if(d==2){
		cout << n*10000 << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep1(i,n) for(int i=1; i<=(n); ++i)
#define repi(i,a,b) for(int i=a; i<=(b); ++i)
#define rrep(i,n) for(int i=(n-1); i>=0; --i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define vvi vector<vi>
// #define int long long
using namespace std;
using ll = long long;

int main() {
  ll n,d,cnt=0;
  cin >> n >> d;
  vi x(n),y(n);
  rep(i,n){
    cin >> x[i] >> y[i];
  }

  rep(i,n){
    if(sqrt(pow(x[i],2)+pow(y[i],2)) <= d){
      cnt++;
    }
  }
  cout << cnt << endl;
}


Measured memory_bytes: 4844
#include <iostream>

using namespace std;

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

    if(a > b)
    {
        swap(a, b);
    }

    if(b > c)
    {
        swap(b, c);
    }

    if(a > b)
    {
        swap(a, b);
    }

    int cnt = (b - a) / 2;
    cnt += (c - b);
    if(1 == (b - a) % 2)
    {
        cnt += 2;
    }

    cout << cnt << endl;

    return 0;
}


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

int main(){
    int N,max=0,C=0;
    cin >> N;
    vector<string> s(N);
    for(int i=0;i<N;i++){
        cin >> s.at(i);
    }
    int M;
    cin >> M;
    vector<string> t(M);
    for(int i=0;i<M;i++){
        cin >> t.at(i);
    }
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            if(s.at(i)==s.at(j)) C++;
        }
        for(int j=0;j<M;j++){
            if(s.at(i)==t.at(j)) C--;
        }
        if(max<C) max=C;
        C=0;
    }
    cout << max << endl;
}



Measured memory_bytes: 256
# 辺を消していく操作は難しい
# 操作を逆から考え、辺を足していくと考える
#####################


class UnionFind:

    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, v):  # vが属する集合の根を返す
        if self.parents[v] < 0:
            return v
        else:
            self.parents[v] = self.find(self.parents[v])
            return self.parents[v]

    def unite(self, u, v):  # 「uが属する集合」と「vが属する集合」を併合（根同士を結ぶ）
        u = self.find(u)
        v = self.find(v)

        if u == v:
            return

        if self.parents[u] > self.parents[v]:  # u < v に統一する
            u, v = v, u

        self.parents[u] += self.parents[v]
        self.parents[v] = u

    def size(self, v):  # vが属する集合の要素数
        return -self.parents[self.find(v)]

    def same(self, u, v):  # uとvが同じ集合に属するか否か
        return self.find(u) == self.find(v)
############################################
N, M = map(int, input().split())
uf = UnionFind(N)
edges = []

for i in range(M):
    A, B = map(int, input().split())
    # 0-indexに直す
    edges.append((A - 1, B - 1))

# n_C_2 = N*(N-1)//2
# [辺が(M-1)本(=1本崩落), ..., 辺が1本(=M-1本崩落), 辺が0本(=M本崩落)]
# [-1]はn_C_2のまま、[-2]から[-M]に向かって逆順に更新していく（辺を増やしていく）

total = [N * (N - 1) // 2 for _ in range(M)]

# -i-1 = -1,-2,...,-(M-1)
# -i-2 = -2,-3,...,-M
for i in range(M - 1):
    u, v = edges[-i - 1]
    # 既に同じ集合に属しているなら、辺を足しても、行き来出来ない組み合わせ数は変わらない（減らない）
    if uf.same(u, v):
        total[-i - 2] = total[-i - 1]
    # uとvが異なる集合に属している場合
    # 辺を張ることで、ダメな組み合わせが(uの要素数)*(vの要素数)だけ減る　（行き来できるようになる）
    else:
        total[-i - 2] = total[-i - 1] - uf.size(u) * uf.size(v)
        uf.unite(u, v)

for t in total:
    print(t)


Measured memory_bytes: 90232
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
template <class T> vector<T> make_vec(size_t a, T val) {
    return vector<T>(a, val);
}
template <class... Ts> auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec(ts...))>(a, make_vec(ts...));
}
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using Graph = vector<vector<int>>;
template <typename T> struct edge {
    int to;
    T cost;
    edge(int t, T c) : to(t), cost(c) {}
};
template <typename T> using WGraph = vector<vector<edge<T>>>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

// 素数篩＋素因数分解
// 初期化O(N),素因数分解O(logN)
// たくさん素因数分解するときはこっち
#include <cassert>
struct prime_sieve {
    int N;
    vector<ll> sieve;
    prime_sieve(int n) : N(n + 1) {
        sieve.resize(N);
        iota(All(sieve), 0);
        init();
    }

    void init() {
        for(int i = 2; i * i <= N; i++) {
            if(sieve[i] < i)
                continue;
            for(int j = i * i; j < N; j += i) {
                if(sieve[j] == j)
                    sieve[j] = i;
            }
        }
    }

    map<ll, int> prime_factorize(ll n) {
        assert(n <= N);
        map<ll, int> ret;
        while(n > 1) {
            ret[sieve[n]]++;
            n = n / sieve[n];
        }
        return ret;
    }
};

int main() {
    ll N;
    cin >> N;
    prime_sieve sieve(N + 1);
    ll res = 0;
    for(int c = 1; c <= N - 1; c++) {
        ll n = N - c;
        auto mp = sieve.prime_factorize(n);
        ll num = 1;
        for(auto x : mp) {
            num *= (ll)x.second + 1;
        }
        res += num;
    }
    cout << res << endl;
}

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




int main(){
  int n;
  int *A;
  int i,j;

  scanf("%d",&n);
  A=malloc(n*sizeof(int));
  for(i=0;i<n;i++) scanf("%d",&A[i]);//読み込み完了

  int x=A[n-1];
  int swap;
  j=-1;
  for(i=0;i<n;i++){
    if(A[i]<=x){
      j+=1;
      swap=A[i];
      A[i]=A[j];
      A[j]=swap;
    }//ピボット以下のものと、ピボットより大きいものに分ける。
  }
  
  for(i=0;i<j;i++) printf("%d ",A[i]);
  printf("[%d]",A[j]);
  for(i=j+1;i<n;i++) printf(" %d",A[i]);
  printf("\n");
  return 0;
}
    


Measured memory_bytes: 2236
N, M = map(int, input().split())
Counted = [0 for _ in range(N)]
num1 = 0
num2 = 0
subnum2 = [0 for l in range(N)]
for j in range(M):
  p, S = input().split()
  p_ = int(p)
  if S == "AC" and Counted[p_ -1] == 0:
    num1 += 1
    num2 += subnum2[p_ - 1]
    Counted[p_ -1] = 1
  elif S == "WA" and Counted[p_-1] == 0:
    subnum2[p_ - 1] += 1
print("{} {}".format(num1, num2))


Measured memory_bytes: 4656
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S; cin >> S;
    int cnt[2] = {};
    rep(i, 3) cnt[S[i] - 'A']++;
    if(min(cnt[0], cnt[1]) > 0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


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

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

    bool yes = (a == b && a != c) || (a == c && a != b) || (b == c && a != b);
    cout << (yes ? "Yes" : "No") << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll pow(ll a) {
    return a * a * a;
}

int main(){
    ll n, k;
    cin >> n >> k;
    ll ans = 0;
    if(k & 1) {
        ll mul_k = n / k;
        ans = pow(mul_k);
    }
    else {
        ll num_k = n / k;
        ll num_k2 = num_k;
        if(n % k >= k / 2)
            num_k2 += 1;
        ans = pow(num_k) + pow(num_k2);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
from collections import deque

H, W = map(int, input().split())
Si, Sj = map(int, input().split())
Gi, Gj = map(int, input().split())

S = ["#" * (W + 2)] + ["#" + input() + "#" for _ in range(H)] + ["#" * (W + 2)]

INF = float("inf")
D = [[INF] * (W + 2) for _ in range(H + 2)]
D[Si][Sj] = 0
Q = deque([(0, Si, Sj)])
while Q:
    c, i, j = Q.popleft()
    if (i, j) == (Gi, Gj):
        print(D[i][j])
        quit()

    for ni, nj in [(i + 1, j), (i - 1, j), (i, j + 1), (i, j - 1)]:
        if 1 <= ni <= H and 1 <= nj <= W and D[ni][nj] > c and S[ni][nj] == ".":
            D[ni][nj] = c
            Q.appendleft((c, ni, nj))

    for di in range(-2, 3):
        for dj in range(-2, 3):
            ni, nj = i + di, j + dj
            if 1 <= ni <= H and 1 <= nj <= W and (di, dj) not in [(1, 0), (0, 1), (-1, 0), (0, -1), (0, 0)] and D[ni][nj] > c + 1 and S[ni][nj] == ".":
                D[ni][nj] = c + 1
                Q.append((c + 1, ni, nj))

print(-1)

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


#define file "file"
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef complex<double> point;
typedef pair<int, int> pii;
typedef vector<int> vi;

#define DEBUG 0
#define dout if(DEBUG) cout

const int MAXN = 1e5 + 5;

int a[MAXN];

int gcd(int a, int b){
    if(!b) return a;
    return gcd(b, a % b);
}

void solve(){
    int n, k;
    cin >> n >> k;
    for(int i = 0; i < n; i++) scanf("%d", &a[i]);
    int g = a[0];
    int mx = a[0];
    for(int i = 1; i < n; i++){
        g = gcd(g, a[i]);
        mx = max(mx, a[i]);
    }
    if(k % g == 0 && mx >= k) cout << "POSSIBLE";
    else cout << "IMPOSSIBLE";
}

int main() {
    #ifdef NASTYA
        assert(freopen("input.txt", "r", stdin)); assert(freopen("output.txt", "w", stdout));
    #else
    // assert(freopen(file".in", "r", stdin)); assert(freopen(file".out", "w", stdout));
    #endif
    int t = 1;
    while(t--) {
        solve();
    }
    return 0;
}


Measured memory_bytes: 640
import java.util.Scanner;

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

	int X = sc.nextInt();
	int i, j;

	for (i = X; ; i++) {
	    for (j = 2; j * j <= X; j++) {
		if (i % j == 0) {
		    break;
		}
	    }

	    if (j * j > i) {
		break;
	    }
	}

	System.out.println(i);
    }
}

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

int main(){
  int n;
  cin>>n;
  uint64_t sum=0;
  int m=0;
  int a;
  for(int i=0;i<n;i++){
    cin>>a;
    if(a<m){
      sum+=m-a;
    }else{
      m=a;
    }
  }
  cout<<sum<<endl;
}
      

Measured memory_bytes: 3628
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
using namespace std;
vector<int> he(long long a){
    vector<int> het;
    while(a >= 1){
        het.push_back(a%2);
        a = a/2;
    } 
    return het;
};
int beki(long long a){
    long long b,t;
    bool flag = true;
    t = 1;
    while(flag){
        if(a < 2*t){
            b = 2*t - 1;
            flag = false;
        }
        t = t*2;
    }
    return b;
}
int main(){
    long long a,b;
    cin >> a >> b;
    a--;
    vector<int> temp1 = he(a);
    vector<int> temp2 = he(b);
    if(a % 2 == 1){
        for(int i = 0;i<temp1.size();i++){
            temp1[i] = 0;
        }
        if(a % 4 == 1){
        temp1[0] = 1;
        }
    }
    else{
        if(a % 4 == 2){
            if(temp1[0] == 0){
                temp1[0]  =1;
            }
            else{
            temp1[0] = 0;
            }
        }
    }
    if(b % 2 == 1){
        for(int i = 0;i<temp2.size();i++){
            temp2[i] = 0;
        }
        if(b % 4 == 1){
        temp2[0] = 1;
        }
    }
    else{
        if(b % 4 == 2){
            if(temp2[0] == 0){
                temp2[0]  =1;
            }
            else{
            temp2[0] = 0;
            }
        }
    }
    for(int i = 0;i<temp1.size();i++){
        if(temp1[i] != temp2[i]){
            temp2[i] = 1;
        }
        else{
            temp2[i] = 0;
        }
    }
    long long ans = 0;
    long long t = 1;
    for(int j = 0;j<temp2.size();j++){
        ans = ans + t*temp2[j];
        t = t*2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
n,m=map(int,input().split())
seito=[]
for i in range(n):
    a,b=map(int,input().split())
    seito.append([a,b])
point=[]
for i in range(m):
    c,d=map(int,input().split())
    point.append([c,d])

ans=[float("inf")]*n
for i in range(n):
    a,b=seito[i]
    min_kyori=float("inf")
    for j in range(m):
        c,d=point[j]
        kyori=abs(a-c)+abs(b-d)
        if kyori<min_kyori:
            min_kyori=kyori
            ans[i]=j+1

for i in ans:
    print(i)

Measured memory_bytes: 67092
var
  a:array[0..6] of longint;
  n,i:longint;
begin
  readln(n);
  a[0]:=1;
  for i:=1 to 6 do a[i]:=a[i-1]*2;
  for i:=6 downto 0 do
    if a[i]<=n then
      begin
        writeln(a[i]);exit;
      end;
end.

Measured memory_bytes: 128
#!/usr/bin/env ruby

def straight?(s)
  return true if s.length == 5 && (s.max - s.min) == 4
  return true if [1,10,11,12,13] == s.sort
  false
end

while line = gets
  nums = Hash.new(0)
  hands = line.chomp!.split(?,).map(&:to_i)

  # ?¨?????????¨????????°?????°??????
  hands.each{ |h| nums[h] += 1 }

  one,two,three,four = 0,0,0,0
  nums.each do |k, v|
    one += 1 if v == 1
    two += 1 if v == 2
    three += 1 if v == 3
    four += 1 if v == 4
  end

  if four > 0
    puts "four card"
  elsif three == 1 && two == 1
    puts "full house"
  elsif straight?(nums.keys)
    puts "straight"
  elsif three == 1
    puts "three card"
  elsif two == 2
    puts "two pair"
  elsif two == 1
    puts "one pair"
  else
    puts "null"
  end

end

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

int main(void){
  long long N;
  vector<long long> vec(5);
  cin >> N;
  for(int i = 0; i < 5; i++){
    cin >> vec[i];
  }
 long long min = *min_element(vec.begin(), vec.end());
  if(N % min == 0) cout << 4 + N / min;
  else cout << 5 + N / min;
 return 0;
}

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

#define INF 2000000000
#define MAXN 100100

int dp[MAXN], h[MAXN];

int main(){
    int n, k;
    cin >> n >> k;
    for(int i = 1; i <= n; i++){
        cin >> h[i];
    }
    fill(dp, dp+n+1, INF);
    dp[1] = 0;
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= k; j++){
            if(i-j < 1) continue;
            dp[i] = min(dp[i], dp[i-j] + abs(h[i] - h[i-j]));
        }
    }
    cout << dp[n] << endl;
}

Measured memory_bytes: 1024
import numpy as np
import scipy
def gcd(a, b):
    if a % b:
        return gcd(b, (a % b))
    else:
        return b
N, M = map(int,input().split())
S = input()
T = input()
t = gcd(N,M)
n = N // t
m = M // t
ans = n * m * t
for i in range(t):
    if(S[n*i]!=T[m*i]):
        ans = -1
        break
print(ans)



Measured memory_bytes: 21372
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        new Main().run();
    }

    private void run() {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        String S = scanner.next();
        char[] chars = S.toCharArray();
        long r = 0, g = 0, b = 0;

        for (int i = 0; i < S.length(); i++) {
            if (chars[i] == 'R') {
                r++;
            } else if (chars[i] == 'B') {
                b++;
            } else {
                g++;
            }
        }
        long sum = r * g * b;
        long sub = 0;
        for (int i = 0; i < chars.length; i++) {
            int length = 1;
            while (i + (length * 2) < chars.length) {
                int j = length + i;
                int k = (length * 2) + i;
                if (chars[i] != chars[j] &&
                        chars[i] != chars[k] &&
                        chars[j] != chars[k]) sub++;
                length++;
            }
        }

        System.out.println(sum - sub);
    }
}

Measured memory_bytes: 36180
N, K= gets.chomp.split.map(&:to_i)

yen10000 = -1

yen5000 = -1

yen1000 = -1

(0..N).each do |n|
  (0..N-n).each do |m|
  	if K == n*1000 + m*5000 + (N-n-m)*10000
  		yen1000 = n
  		yen5000 = m
  		yen10000 = N-n-m
  	end
  end
end

puts "#{yen10000} #{yen5000} #{yen1000}"

Measured memory_bytes: 1788
#include <iostream>
#include <map>

using namespace std;

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

    map<int, int> M;
    for(int i = 0; i < N; i++){
        M[a[i]]++;
    }

    int ans = 0;
    for(auto p : M){
        if(p.first > p.second){
            ans += p.second;
        }else if(p.first < p.second){
            ans += (p.second - p.first);
        }
        
    }

    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 5120
#include <stdio.h>

typedef struct {
	char kind;
	int value;
} card;

void print( card , int );

int main( void ){
	int i, j, n, minj, cnt;
	card tmp;
	
	scanf("%d", &n );
	
	card c1[n], c2[n];
	
	for( i = 0; i < n; i++ ){
		c1[i].kind = 't';
		c2[i].kind = 't';
		c1[i].value = 0;
		c2[i].value = 0;
	}
	
	for( i = 0; i < n; i++ ){
		scanf(" %c%d", &c1[i].kind, &c1[i].value );
		c2[i].kind = c1[i].kind;
		c2[i].value = c1[i].value;
	}

	for( i = 0; i < n; i++ ){
		for( j = n-1; j >= i+1; j-- ){
			if( c1[j].value < c1[j-1].value ){
				tmp = c1[j];
				c1[j] = c1[j-1];
				c1[j-1] = tmp;
			}
		}
	}
	
	for( i = 0; i < n; i++ ){
		if( i != n-1 ){
			printf("%c%d ", c1[i].kind, c1[i].value );
		}
		else{
			printf("%c%d\n", c1[i].kind, c1[i].value );
		}
	}
	printf("Stable\n");
	
	for( i = 0; i < n; i++ ){
		minj = i;
		for( j = i; j < n; j++ ){
			if( c2[j].value < c2[minj].value ){
				minj = j;
			}
		}
		
		tmp = c2[i];
		c2[i] = c2[minj];
		c2[minj] = tmp;
	}
	
	for( i = 0; i < n; i++ ){
		if( i != n-1 ){
			printf("%c%d ", c2[i].kind, c2[i].value );
		}
		else{
			printf("%c%d\n", c2[i].kind, c2[i].value );
		}
	}
	
	cnt = 0;
	for( i = 0; i < n; i++ ){
		if( c1[i].kind == c2[i].kind && c1[i].value == c2[i].value ){
			cnt++;
		}
	}
	if( cnt == n ){
		printf("Stable\n");
	}
	else{
		printf("Not stable\n");
	}
	
	return 0;
}



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

int main()
{
	   int n;
	   cin >> n;
	   
	   int total = 0, freq[105] = {0};
	   
	   for(int i = 1; i <= n; i++){
				    int val;
				    cin >> val;
				    freq[val]++;
				}
				
				for(int i = 1; i <= 100; i++){
				    total += (i * freq[i]);
				}
				
				int ans1 = total / n, res1 = 0, res2 = 0, ans2 = ans1;
				if(total%n) ans2++;
				
				for(int i = 1; i <= 100; i++){
				    res1 += (freq[i] * (i-ans1) * (i-ans1));
				}
				for(int i = 1; i <= 100; i++){
				    res2 += (freq[i] * (i-ans2) * (i-ans2));
				}
				
				cout << min(res1, res2) << "\n";
	   
    return 0;
}


Measured memory_bytes: 3612
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long k = sc.nextLong();
		Input[] in = new Input[n];
		for (int i = 0; i < n; i++) {
			in[i] = new Input(sc.nextInt(), sc.nextLong());
		}
		Arrays.sort(in, new Comparator<Input>() {
		public int compare(Input t1, Input t2) {
			return t1.val - t2.val;
		}
		});
		long total = 0;
		int ans = 0;
		for (int i = 0; i < n; i++) {
			total += in[i].count;
			if (total >= k) {
				ans = in[i].val;
				break;
			}
		}
		System.out.println(ans);
	}
	
	static class Input {
		int val;
		long count;
		public Input(int val, long count) {
			this.val = val;
			this.count = count;
		}
	}
}


Measured memory_bytes: 86596
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
int gcd(int n,int m){return m==0?n:gcd(m,n%m);}
int read()
{
	int x=0,f=1;char c=getchar();
	while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
	while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
	return x*f;
}
#define N 400010
#define ll long long
int n,m,a[N],fa[N],id[N],cnt,ans;
bool isdel[N],flag[N];
ll value[N<<2];
struct data
{
	int x,y,z;
	bool operator <(const data&a) const
	{
		return z<a.z;
	}
}e[N];
int find(int x){return fa[x]==x?x:fa[x]=find(fa[x]);}
namespace kruskal_tree
{
	int p[N<<2],t,degree[N<<2],fa[N<<2];
	ll size[N<<2];
	struct data{int to,nxt;}edge[N<<2];
	void addedge(int x,int y){t++;degree[y]++;fa[y]=x;edge[t].to=y,edge[t].nxt=p[x],p[x]=t;}
	void link(int x,int y,int i)
	{
		id[i]=++cnt;addedge(cnt,x),addedge(cnt,y);
	}
	void dfs(int k)
	{
		size[k]=a[k];
		for (int i=p[k];i;i=edge[i].nxt)
		{
			dfs(edge[i].to);
			size[k]+=size[edge[i].to];
		}
	}
	void build()
	{
		for (int i=1;i<=cnt;i++)
		if (!degree[i]) dfs(i);
	}
	void del()
	{	
		isdel[0]=1;
		for (int i=m;i>=1;i--)
		if (flag[i]&&isdel[fa[id[i]]]&&e[i].z>size[id[i]]) isdel[id[i]]=1;
	}
}
void dfs(int k)
{
	for (int i=kruskal_tree::p[k];i;i=kruskal_tree::edge[i].nxt)
	{
		dfs(kruskal_tree::edge[i].to);
		if (!isdel[k]) fa[find(kruskal_tree::edge[i].to)]=k;
	}
}
int main()
{
	n=read(),m=read();
	for (int i=1;i<=n;i++) a[i]=read();
	for (int i=1;i<=m;i++) e[i].x=read(),e[i].y=read(),e[i].z=read();
	sort(e+1,e+m+1);
	for (int i=1;i<=4*n;i++) fa[i]=i;cnt=n;
	for (int i=1;i<=m;i++)
	{
		int p=find(e[i].x),q=find(e[i].y);
		if (p!=q) kruskal_tree::link(p,q,i),fa[p]=fa[q]=id[i],flag[i]=1;
	}
	kruskal_tree::build();
	kruskal_tree::del();
	for (int i=1;i<=cnt;i++) fa[i]=i;
	for (int i=1;i<=cnt;i++)
	if (!kruskal_tree::degree[i]) dfs(i);
	for (int i=1;i<=m;i++)
	if (find(e[i].x)==find(e[i].y)&&kruskal_tree::size[find(e[i].x)]>=e[i].z) ans++;
	cout<<m-ans;
	return 0;
}

Measured memory_bytes: 21376
//
// Created by yamunaku on 2019/09/07.
//

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repl(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perl(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD9 998244353
#define MOD1 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)
#define CST(x) cout<<fixed<<setprecision(x)

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> mti;
typedef vector<ll> vl;
typedef vector<vector<ll>> mtl;

int main(){
    int n;
    cin >> n;
    vi a(n);
    rep(i,n ) cin >> a[i];
    int ans=0;
    int now=0;
    rep(i,n-1){
        if(a[i]<a[i+1]){
            ans=max(ans,i-now);
            now=i+1;
        }
    }
    ans=max(ans,n-1-now);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
#include<stdio.h>
 
int main(){
	int n;
	scanf("%d", &n);
	int height[n];
	for(int i=0; i<n; i++){
		scanf("%d", &height[i]);
	}
	
	int max = 0, count = 0;
	for(int i=0; i<n; i++){
		if(max <= height[i]){
			max = height[i];
			count++;
		}
	}
	printf("%d", count);
	
	return 0;
}

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

ll gcd(ll a, ll b){return b ? gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}

ll f(ll x, int c, int d){
  ll res = x; 
  res -= x/c;
  res -= x/d;
  res += x/lcm(c,d);
  return res;
}

int main() {
  ll a,b;
  int c,d;
  cin >> a >> b >> c >> d;
  
  ll ans = f(b,c,d) - f(a-1,c,d);
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0; i<(int)n; i++)
#define REPR(i, n) for(int i=(int)n-1; i>=0; i--)
#define FOR(i, m, n) for(int i=(int)m; i<(int)n; i++)
#define FORR(i, m, n) for(int i=(int)m-1; i>=(int)n; i--)
#define ALL(x) (x).begin(), (x).end()
#define ASC(v) sort(ALL(v));
#define DESC(v) sort(ALL(v), greater<int>());
#define UNIQ(a) sort(ALL(a));(a).resize(unique(ALL(a)) - a.begin());
#define DEBUG(x) cout<<#x<<": "<<x<<"\n"
typedef long long ll;
const double PI = acos(-1);
ll lcm(ll a, ll b) { return a / __gcd(a, b) * b; }
bool isprime(int x){ int i; if(x<2)return 0; else if(x==2) return 1; if(x%2==0) return 0; for(i=3; i*i<=x; i+=2) if(x%i==0) return 0; return 1; }
int digsum(int n) { int r=0; while(n>0) { r+=n%10; n/=10; } return r; }
//struct nya{ nya(){ cin.tie(0); ios::sync_with_stdio(false); } }nyan;

const string YES = "Yes";
const string NO = "No";

void solve(long long N, std::string S){
	ll s = S.size();
	string f = S.substr(0, s/2);
	string b = S.substr(s/2, s);
	if (f==b) cout << YES << "\n";
	else cout << NO << "\n";
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::string S;
    std::cin >> S;
    solve(N, S);
    return 0;
}


Measured memory_bytes: 256
import java.util.*

fun main(args:Array<String>){
    var K:Long
    var A:Long
    var B:Long
    var ans:Long=0
    val sc:Scanner= Scanner(System.`in`)
    K=sc.nextLong()
    A=sc.nextLong()
    B=sc.nextLong()

    if(K>A && (B-A)>2){
        K-=(A-1)
        var cnt=K/2
        ans=A+(cnt*(B-A))
        ans+=(K%2)
    }
    else{
        ans=K+1
    }
    println(ans)

}

Measured memory_bytes: 31260
#include <stdio.h>

int main(void) {
  int A, B, flag = 0;
  scanf("%d %d", &A, &B);

  for(int i=1; i<=3; ++i) {
    if((A*B*i)%2 == 1) {
      flag = 1;
      break;
    }
  }

  if(flag) printf("Yes\n");
  else printf("No\n");

  return 0;
}


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

int main()
{
    ll n;
    cin>>n;
    
    vector<ll> v(n),s(n),t(n),u(n);
    
    for(ll i=0;i<n;i++)
    {
        ll x,y;
        cin>>x>>y;
        s[i] = x-y;
        v[i] = x+y;
        t[i] = y-x;
        u[i] = -x-y;
    }
    sort(v.begin(),v.end());
    sort(s.begin(),s.end());
    sort(t.begin(),t.end());
    sort(u.begin(),u.end());
    
    cout<<max(u[n-1]-u[0],max(t[n-1]-t[0],max(v[n-1]-v[0],s[n-1]-s[0])))<<endl;
    
}

Measured memory_bytes: 9536
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
using namespace std;

typedef long long ll;

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

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];
  }
} comb(1e7);

int c1, r1, c2, r2;

mint g(int r, int c) {
    return comb(c + r + 2, r + 1);
}

int main() {
    cin >> r1 >> c1 >> r2 >> c2;
    c1--;
    r1--;

    mint ans = 0;
    ans += g(r2, c2);
    ans -= g(r1, c2);
    ans -= g(r2, c1);
    ans += g(r1, c1);

    cout << ans.x << endl;
}

Measured memory_bytes: 156544
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc =new Scanner(System.in);
    int L =sc.nextInt();
    int A[] =new int[L];
    int ans =0;
    for(int i=0;i<L;i++){
      A[i]=sc.nextInt();
      if(i%2==0){
        if(A[i]%2==1){
          ans =ans+1;}}}
    System.out.println(ans);
  }
}

Measured memory_bytes: 35692
import java.util.*;
    public class Main {
     
    	public static void main(String[] args) {
    		Scanner scan=new Scanner(System.in);
    		
    		int n=Integer.parseInt(scan.next());
    		System.out.print(n*800-200*(n/15));
    		
  
    				
    	}
     
    }

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

vector<int> to[200005];
vector<int> ans;

void dfs(int v,int p=-1) {
  for(int u : to[v]) {
    if(u==p)continue;
    ans[u] += ans[v];
    dfs(u,v);
  }
}

int main() {
  int n,q;
  cin >> n >> q;
  rep(i,n-1) {
    int a,b;
    cin >> a >> b;
    a--; b--;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  ans.resize(n);
  rep(i,q) {
    int p,x;
    cin >> p >> x;
    p--;
   ans[p] += x;
  }
  dfs(0);
  rep(i,n) {
    cout << ans[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 24216
#include<algorithm>
#include<algorithm>     //sort,二分探索,など
#include<bitset>        //固定長bit集合
#include<cmath>         //pow,logなど
#include<complex>       //複素数
#include<deque>         //両端アクセスのキュー
#include<functional>    //sortのgreater
#include<iomanip>       //setprecision(浮動小数点の出力の誤差)
#include<iostream>      //入出力
#include<iterator>      //集合演算(積集合,和集合,差集合など)
#include<map>           //map(辞書)
#include<numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include<queue>         //キュー
#include<set>           //集合
#include<stack>         //スタック
#include<string>        //文字列
#include<unordered_map> //イテレータあるけど順序保持しないmap
#include<unordered_set> //イテレータあるけど順序保持しないset
#include<utility>       //pair
#include<vector>        //可変長配列

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef vector<vector<ld>> vvld;
typedef vector<vector<string>> vvs;
typedef vector<vector<bool>> vvb;
const ll MOD = 1000000007;
const ll INF = 1000000000000000000;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,s,e) for(int i=s;i<e;i++)
#define reple(i,s,e) for(int i=s;i<=e;i++)
#define revrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()

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

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

    int N, M;
    cin >> N >> M;

    vi L(M), R(M);
    rep(i, M) cin >> L[i] >> R[i];

    sort(all(L), greater<int>());
    sort(all(R));


    cout << max(R[0] - L[0] + 1, 0) << endl;

    return 0;
}

Measured memory_bytes: 3928
import           Control.Monad
import qualified Data.ByteString.Char8 as BS
import           Data.Maybe

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
  [a, b] <- getIntList
  let solve x | x > 1000 = -1
              | otherwise =
                if floor (0.08 * fromIntegral x) == a &&
                   floor (0.10 * fromIntegral x) == b
                then x
                else solve (x+1)
  print $ solve 10

Measured memory_bytes: 380
#include <iostream>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <list>
#include <set>
#include <unordered_set>
#include <vector>
#include <utility>
#include <algorithm>
#include <queue>
#include <stack>
#include <cstdint>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>

#define rep(i, n) for(ll (i) = 0;(i) < (n);(i)++)
#define mp(a, b) make_pair((a),(b))
#define bs(n) ((ull)1<<(ull)n)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

constexpr ll inf = INT64_MAX / 4;
constexpr double pi = asin(1) * 2;
constexpr ll mod = 1000000007;
constexpr double eps = 0.000000001;

bool solve() {
    int n, x, c = 0;
    cin >> n >> x;
    if (n == 0 && x == 0)return false;
    for (int i = 1; i <= n; i++)
        for (int j = i + 1; j <= n; j++)
            for (int k = j + 1; k <= n; k++)
                if (i + j + k == x)
                    c++;
    cout << c << endl;
    return true;
}

int main() {
    while (solve());
}



Measured memory_bytes: 3084
n, d = map(int, input().split())
x = [list(map(int, input().split())) for i in range(n)]
square = [i**2 for i in range(1, 10 * 40**2)]

def distsq(i, j):
    total = 0
    for k in range(d):
        total += (x[i][k]-x[j][k])**2
    return total

count = 0
for i in range(n-1):
    for j in range(i+1, n):
        if distsq(i, j) in square:
            count+=1
print(count)

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

int main (){
	string s;
    int ans =0;
	cin >> s;
    for(int i = 0; i< s.size(); i++ ){
        if(i%2==0){
            if(s[i]=='L' ){
                cout<<"No"<<endl; 
                return 0;
            }
        }else{
            if(s[i]=='R'){
                cout<<"No"<<endl;
                return 0;
            }
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
bool bo[100];
#define ll long long int
int main()
{
	ll n,k;
	cin>>n>>k;
	char a[1000][1000];
	vector<string>v;
	for(int j=0;j<n;j++)
	{
		string s="";
		for(int i=0;i<k;i++)
		{
			cin>>a[j][i];
			s+=a[j][i];
		}
		//cout<<s<<endl;
		v.pb(s);
	}
	for(int i=0;i<(int)v.size();i++)
	{
		ll k=1;
		for(int j=i;k<=2;)
		{
			cout<<v[j]<<endl;
			k++;
		}
	}

}


Measured memory_bytes: 384
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();
        if((a < c && c < b) || (b < c && c < a))System.out.println("Yes");
        else System.out.println("No");
        sc.close();
    }

}


Measured memory_bytes: 22228
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
const int MOD = 1001;
const int MAXV = 1000;

struct UnionFind {
    vector<int> data;
    int __size;
    UnionFind(int size) : data(size, -1), __size(size) { }
    void unionSet(int x, int y) {
        if ((x = root(x)) != (y = root(y))) {
            if (data[y] < data[x]) swap(x, y);
            data[x] += data[y]; data[y] = x; __size--;
        }
    }
    bool findSet(int x, int y) { return root(x) == root(y); }
    int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); }
    int size(int x) { return -data[root(x)]; }
    int size() { return __size; }
    vector<int> subset_roots() {
        vector<int> roots;
        for (int i = 0; i < data.size(); i++) if (data[i] < 0) roots.push_back(i);
        return roots;
    }
};

int main() {
    vector<int> F(MAXV + 1);
    F[0] = 1, F[1] = 2;
    for (int i = 2; i <= MAXV; i++) (F[i] = F[i - 1] + F[i - 2]) %= MOD;

    int V, d;
    while (cin >> V >> d) {
        UnionFind uf = UnionFind(V + 1);    // 1-origin
        for (int i = 1; i <= V; i++) {
            for (int j = i + 1; j <= V; j++) {
                if (abs(F[i] - F[j]) < d) {
                    uf.unionSet(i, j);
                }
            }
        }
        cout << uf.size() - 1 << endl;   // 1-origin
    }
    return 0;
}


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

int dp[maxn][maxn];

int main(){
    string s, t;
    cin >> s >> t;
    int n = s.size();
    int m = t.size();

    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            if(s[i-1] == t[j-1]){
                dp[i][j] = dp[i-1][j-1] + 1;
            }
            else{
                dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
            }
        }
    }
    string res = "";
    //cout << dp[n][m] << endl;
    while(n>0 && m>0){

        if(dp[n][m] == dp[n-1][m])  n--;
        else if(dp[n][m] == dp[n][m-1]) m--;
        else{
            res += s[n-1];
            n --;
            m --;
        }
    }
    reverse(res.begin(), res.end());
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 35456
#include<cstdio>//AT3855
#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#include<cstdlib>

using namespace std;

int vjudge;

int n,a,b;

int main(){
    scanf("%d%d%d",&n,&a,&b);
    if((b-a-1)%2){
        printf("Alice\n");
    }
    else{
        printf("Borys\n");
    }
    return 0;
}


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

/** Problem0034 : Railway Lines **/
int main()
{
	double l[10], v1, v2, total, totalL; char camma;
	double t;
	
	while (1) {
		total = 0; totalL=0;
		for (int i=0; i<10; i++) {
			cin >> l[i];
			cin >> camma;
			totalL+=l[i];
		}
		
		
		cin >> v1 >> camma >> v2;
		if (cin.eof()) break;
		for (int i=0; i<10; i++) {
			total+=l[i];
			t = (double)l[i]/v1;
			total+=t*v2;
			if (total >= totalL) {
				cout << i+1 << endl;
				break;
			}
		}
	}
		return 0;
}

Measured memory_bytes: 1224
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<ll,ll> P;
#define M 1000000007
#define F first
#define S second
#define PB push_back
#define INF 100000000000000000
int x,y;
int main(void){
    cin>>x>>y;
    cout<<x+y/2<<endl;
    
}


Measured memory_bytes: 256
import java.io.*;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
  private static PrintWriter out;

  public static void main(String[] args) {
    Main main = new Main();
    Runtime.getRuntime().addShutdownHook(new Thread(() -> out.close()));
    try {
      main.run(args);
    } catch (Exception e) {
      e.printStackTrace();
    }
  }

  private void run(String[] arguments) throws Exception {
    MyScanner sc = new MyScanner();
    out = new PrintWriter(new BufferedOutputStream(System.out));

    int x = sc.nextInt();
    int MAX = 100003;

    boolean[] sift = new boolean[MAX+1];
    Arrays.fill(sift,true);
    sift[0] = false;
    sift[1] = false;

    for (int i = 2; i < sift.length; i++) {
      if (!sift[i]) continue;
      for (int j = i*2; j < sift.length; j=j+i) {
        sift[j] = false;
      }
    }

    int ans = 0;
    for (int i = x; i < sift.length; i++) {
      if (sift[i]){
        ans = i;
        break;
      }
    }
    out.println(ans);
    out.close();
  }

  /*          
   * Form: http://codeforces.com/blog/entry/7018
   */
  private class MyScanner {
    BufferedReader br;
    StringTokenizer st;

    MyScanner() {
      br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
      while (st == null || !st.hasMoreElements()) {
        try {
          st = new StringTokenizer(br.readLine());
        } catch (IOException e) {
          e.printStackTrace();
        }
      }
      return st.nextToken();
    }

    int nextInt() {
      return Integer.parseInt(next());
    }

    long nextLong() {
      return Long.parseLong(next());
    }

    double nextDouble() {
      return Double.parseDouble(next());
    }

    String nextLine() {
      String str = "";
      try {
        str = br.readLine();
      } catch (IOException e) {
        e.printStackTrace();
      }
      return str;
    }
  }
}


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

int a, b;
int ta = 0;
int main(){
	cin >> a >> b;
	for (int i = a; i <= b; i++) {
		if (i / 10000 == i % 10 && i / 1000 % 10 == i / 10 % 10) {
			ta++;
		}
	}
	cout << ta << endl;
	return 0;
}

Measured memory_bytes: 256