akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

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

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

int main(int argc, char const *argv[]) {
    string s; cin>>s;
    int n = s.length();

    rep(i,n/2) {
        if (s[i]!=s[n-i-1]) {
            cout << "No" << '\n';
            return 0;
        }
    }

    int m = n/2;
    rep(i,m/2) {
        if (s[i]!=s[m-i-1]) {
            cout << "No" << '\n';
            return 0;
        }
    }

    cout << "Yes" << '\n';
    return 0;
}

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

int main()
{
	bool a=true,b=true,c=true;
	int x,y;
	cin>>x>>y;
	if(x==1||y==1) a=false;
	if(x==2||y==2) b=false;
	if(x==3||y==3) c=false;
	if(a==true) cout<<1;
	if(b==true) cout<<2;
	if(c==true) cout<<3;
	return 0; 
}

Measured memory_bytes: 256
#include<map>
#include<iostream>
#include<deque>
#include<algorithm>
#include<string>
#include<cctype>
#include<iomanip>
#include<vector>
#include<queue>
#include<math.h>
#include<bitset>
#include<random>
 
using namespace std;
#define REP(i,b,e) for(ll i=(ll)b;i<(ll)e;i++)
#define rep0(i,n) REP(i,0ll,n)
#define rep1(i,n) REP(i,1ll,n+1)
 
#define shosu setprecision(17)
 
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<char,P> Q;
//ll longinf=1ll<<60;
int inf=1<<29;
ll longinf=(1ll<<60);

int dx[]={1,-1,0,0};
int dy[]={0,0,-1,1};



int main(){
    int a;
    cin>>a;
    if(a%2==1&&a>=3&&a<=7) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;

    return 0;
}


Measured memory_bytes: 256
h,w = map(int, input().split())
map = ["#"*(w+2)]

for i in range(h):
    lst = input()
    lst = "#"+lst+"#"
    map.append(lst)
map.append("#"*(w+2))
# print(map)

for i in range(1,h+1):
    for j in range(1, w+1):
        if map[i][j]=="#":
            if map[i-1][j]=="." and map[i][j-1]=="." and map[i+1][j]=="." and map[i][j+1]==".":
                print("No")
                exit()

print("Yes")


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
#define forn(i,a,b)for(int i=(a),_b=(b);i<=_b;i++)
#define fore(i,b,a)for(int i=(b),_a=(a);i>=_a;i--)
#define rep(i,n)for(int i=0,_n=n;i<n;i++)
#define ll long long
#define pii pair<int,int>
#define vi vector<int>
#define vpii vector<pii>
#define m_p make_pair
#define re return
#define pb push_back
#define si set<int>
#define ld long double
#define X first
#define Y second
#define st string
#define ull unsigned long long
#define mod 1000000007
#define INF 1000000007
#define x1 XZVJDFADSPFOE
#define y1 GASDIJSLDAEJF
#define x2 DFDAJKVOHKWIW
#define y2 PSFSAODSXVNMQ
#define LLINF 0x3f3f3f3f3f3f3f3fLL
using namespace std;
inline void read(int &x)
{
	short negative=1;
    x=0;
    char c=getchar();
    while(c<'0' || c>'9')
    {
		if(c=='-')
			negative=-1;
		c=getchar();
	}
    while(c>='0' && c<='9')
        x=(x<<3)+(x<<1)+(c^48),c=getchar();
    x*=negative;
}
ll quickpower(ll n,ll k){
	ll ans=1;
	while(k){
		if(k%2){
			ans*=n;
			ans%=mod;
		}
		n*=n;
		n%=mod;
		k/=2;
	}
	return ans;
}
string int_to_string(int n)
{
	string s="";
	while(n)
	{
		int now=n%10;
		s+=now+'0';
		n/=10;
	}
	reverse(s.begin(),s.end());
	return s;
}
int string_to_int(string s)
{
	int n=0;
	rep(i,s.size())
	{
		n*=10;
		n+=s[i]-'0';
	}
	return n;
}
int b[4444],r[4444],g[4444];
int main()
{
	ios::sync_with_stdio(0);
	//think twice,code once
	int n;
	cin>>n;
	string s;
	cin>>s;
	forn(i,1,n)
	{
		b[i]=b[i-1];
		r[i]=r[i-1];
		g[i]=g[i-1];
		if(s[i-1]=='B')b[i]++;
		if(s[i-1]=='R')r[i]++;
		if(s[i-1]=='G')g[i]++; 
	}
	ll cnt=0;
	forn(i,1,n){
		forn(j,i+2,n){
			if((s[i-1]=='R'&&s[j-1]=='G')||(s[i-1]=='G'&&s[j-1]=='R')){
				cnt+=b[j]-b[i-1];
				if((i+j)%2==0){
					if(s[(i+j)/2-1]=='B'){
						cnt--;
					}
				}
			}
			else if((s[i-1]=='R'&&s[j-1]=='B')||(s[i-1]=='B'&&s[j-1]=='R')){
				cnt+=g[j]-g[i-1];
				if((i+j)%2==0){
					if(s[(i+j)/2-1]=='G'){
						cnt--;
					}
				}
			}
			else if((s[i-1]=='G'&&s[j-1]=='B')||(s[i-1]=='B'&&s[j-1]=='G')){
				cnt+=r[j]-r[i-1];
				if((i+j)%2==0){
					if(s[(i+j)/2-1]=='R'){
						cnt--;
					}
				}
			}
		}
	}
	cout<<cnt<<endl;
	return 0;
}



Measured memory_bytes: 3696
import sys
import math
from fractions import gcd
# import queue
# from collections import Counter
# from itertools import accumulate
# from functools import reduce

def lcm(a, b):
    return a * b // gcd(a, b)

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

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

big_prime = 1000000007

"""
# 標準入力取得
## 文字列
 =  sys.stdin.readline().rstrip()
 =  list(sys.stdin.readline().rstrip())

## 数値
 =  int(sys.stdin.readline())
 =  map(int, sys.stdin.readline().split())
 =  list(map(int, sys.stdin.readline().split()))
 =  [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]
"""
a,b=  map(int, sys.stdin.readline().split())

# c=1
# t=a
# while True:
#     if t>=b:
#         break
#     else:
#         t+=a-1 
#         c+=1
# print(c)

c = 1
t = a
if b ==1:
    print(0)
else:
    while t<b:
        c+=1
        t+=a-1
    print(c)

Measured memory_bytes: 5432
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define bit(k) (1LL<<(k))
typedef long long ll;

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

const int INF = 1e9;
const ll INFLL = 1e18;
const ll MOD = 1e9+7;
const double PI = acos(-1.0);

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

/*------------------------------------/
for library*/

/*------------------------------------*/

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    int H,A;
    cin>>H>>A;
    cout<<(H+A-1)/A<<endl;
}

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

using namespace std;

#define pb push_back

vector <int> p;
int m, n, j;
bool a = true, ok;

int main () {

int a, b;

cin >> a >> b;

if (a <= 0 && b >= 0) cout << "Zero";
else if (a < 0 && b < 0 && (a * -1 - (b * -1) + 1) % 2 == 0) cout << "Positive";
else if (a < 0 && b < 0) cout << "Negative";
else if (a > 0 && b > 0) cout << "Positive";
else cout << "Zero";

return 0;

}


Measured memory_bytes: 256
f2 :: Int->Int
f2 x
   |x<=0 = 0
   |otherwise=x


f :: Int->Int->Int->Int->Int->Int->[Int]
f a b c s x y
    |x<0 && y<0 = []
    |otherwise = (s + a * (f2 x) + b * (f2 y)) : f a b c (s+c) (x-1) (y-1)


main =do
      e<-getLine
      let (a:b:c:x:y:[])=map read (words e)::[Int]
      putStrLn $ show $ minimum $ f a b (c*2) 0 x y

Measured memory_bytes: 1020
#include <iostream>
using namespace std;
void exchange();
int main(){

exchange();
return 0;
}
void exchange(){
int i,j;

while(1){
cin >> i >> j;
if(i== 0 && j == 0){
break;
}
if(i > j){
cout << j<< " " <<  i << endl;
}else cout <<  i << " " <<  j << endl;
}
}


Measured memory_bytes: 3072
n = int(input())
list = list(map(int,input().split()))

list2 = [0]*(n+1)
list3 =[0]*(n+1)
list4 = []
for x in list:
  list2[x]+=1
 
for i in range(1,n+1):
    list3[i] = list2[i]*(list2[i]-1)/2

SUM=sum(list3)
for k in range(n):
    print(int(SUM-list2[list[k]]+1))



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

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

  int answer = 0;
  if(n <= 599) {
    answer = 8;
  } else if(n <= 799) {
    answer = 7;
  } else if(n <= 999) {
    answer = 6;
  } else if(n <= 1199) {
    answer = 5;
  } else if(n <= 1399) {
    answer = 4;
  } else if(n <= 1599) {
    answer = 3;
  } else if(n <= 1799) {
    answer = 2;
  } else if(n <= 1999) {
    answer = 1;
  }
  cout << answer << '\n';

  return 0;
}

Measured memory_bytes: 3648
def resolve():
    # import sys
    # input = sys.stdin.readline
    Q, H, S, D = [int(i) for i in input().split()]
    N = int(input())
    a = []
    a.append(N * S)
    a.append(N * H * 2)
    a.append(N * Q * 4)
    if N > 1:
        if N % 2 == 0:
            a.append((N // 2) * D)
        else:
            a.append((N // 2) * D + S)
            a.append((N // 2) * D + H * 2)
            a.append((N // 2) * D + Q * 4)
    print(min(a))


resolve()


Measured memory_bytes: 9068
// #define _CRT_SECURE_NO_WARNINGS
// #define _USE_MATH_DEFINES	// M_PI=3.1415...
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <locale>
#include <cctype>
#include <sstream>
#include <iomanip>	// 20桁出力 cout << setprecision(20) << double;
#include <queue>
#include <bitset>	// bitset<8> bs1(131uL); // 10000011 bs1[0]は1 01stringからビット集合生成可
#include <numeric>
#include <random>
#include <climits>  // A/Bを計算するときA==LLONG_MIN && B==-1のみ(1ull<<63)で代用
using namespace std;

typedef long long LL;
typedef pair<LL, LL> P;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<LL> VL;
typedef vector<VL> VVL;				// VVL v(100,VL(100,0));
typedef vector<pair<LL, LL> > VP;
typedef vector<string> VS;
typedef map<int, int> MAPII;
typedef multimap<int, char, greater<int> > MuMAPIC;
typedef multimap<int, string, greater<int> > MuMIS;
typedef pair<LL, pair<P, P> > PP;

#define INF 999999999999999997		// 少し加算したらオーバーフローする
#define MP make_pair
#define FAST_IO  cin.tie(0); ios::sync_with_stdio(false);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORL(i,a,b) for(LL i=(a);i<(b);i++)
#define FOR_REV(i,a,b) for(int i=(a);i>=(b);i--)
#define foreach_it(type,it,c) for(type::iterator it=c.begin(),c_end=c.end();it!=c_end;++it)
#define FOR_ITR(d) for(auto itr=d.begin(),d_end=d.end();itr!=d_end;++itr)	// C++11
#define O(s) cout<<s<<endl;

#define DUMP_VVI(b) if(dbgF){FOR(i,0,b.size()){FOR(j,0,b[i].size())printf("%d ",b[i][j]);puts("");}}
#define D_OUT(str,value) if(dbgF){cout<<str<<" : "<<value<<endl;}

template<class T>T IN() { T d; cin >> d; return d; }

LL gcd(LL a, LL b) { return (b > 0) ? gcd(b, a % b) : a; } // 最大公約数（Greatest Common Divisor）
LL lcm(LL a, LL b) { return a / gcd(a, b) * b; } // 最小公倍数（Least Common Multiple）
bool uruu(LL Y) { return (((Y % 4 == 0 && Y % 100 != 0) || Y % 400 == 0) ? true : false); } // うるう年判定
string Replace(string S, string from, string to) { auto p = S.find(from); while (p != string::npos) { S.replace(p, from.size(), to); p = S.find(from, p + to.size()); }return S; }
// 桁和
LL Ketawa_s(string s) { LL a = 0; FOR(i, 0, s.length())a += s[i] - '0'; return a; }

//二項係数 nCk mod pを求める
const LL MAX = 510000, p = 998244353; LL fac[MAX], finv[MAX], inv[MAX];
/* 前処理 */void COM_init() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; FOR(i, 2, MAX) { fac[i] = fac[i - 1] * i % p; inv[i] = p - inv[p % i] * (p / i) % p; finv[i] = finv[i - 1] * inv[i] % p; } }
/* 主処理 */LL COM(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % p) % p; }

int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
int dxx[8] = { 0,1,1,1,0,-1,-1,-1 };
int dyy[8] = { 1,1,0,-1,-1,-1,0,1 };

// -------------------------------------------------------------------------------

int main() {
	FAST_IO;
	bool dbgF = true; // for D_OUT(str, value)  ... cout<< str <<" : "<< value <<endl;

	LL a, b, c, d, e, k;
	cin >> a >> b >> c >> d >> e >> k;

	string ans = "Yay!";
	if (e - a > k) {
		ans = ":(";
	}
	O(ans);

	return 0;
}

Measured memory_bytes: 256
import itertools
import math

n = int(input())
coordinates = []

for i in range(n):
  x, y = map(int, input().split())
  coordinates.append([x, y])
# print(coordinates)
c = [num for num in range(n)]
pc = 0
dists = []
for p in itertools.permutations(c):
  pc += 1
  # print(p)
  dist = 0
  for i in range(n-1):
    a = coordinates[p[i]]
    b = coordinates[p[i+1]]
    dist += math.sqrt( ((b[0] - a[0]) ** 2) + ((b[1] - a[1]) ** 2))
  dists.append(dist)
print(sum(dists) / pc)
# print(dists)

Measured memory_bytes: 43628
import sys
sys.setrecursionlimit(10**6)

N = int(input())
V = [3, 5, 7]

li = []


def rec(curr, use):
    if curr > N:
        return
    if use == 0b111:
        li.append(curr)
    for i, b in enumerate(V):
        rec(curr * 10 + b, use | max(1, i * 2))


rec(0, 0)

print(len(li))

Measured memory_bytes: 4008
#define _CRT_SECURE_NO_WARNINGS
#include"bits/stdc++.h"
#ifdef _DEBUG
#define DBG(n) n
#else
#define DBG(n)
#endif
#define INF          1e9
#define INFLL        1e18
#define EPS          1e-9
#define MOD          1000000007
#define REP(i,n)     for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)    for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)    for(ll i=(n)-1;i>=0;--i)
#define REPR1(i,n)   for(ll i=(n);i>0;--i)
#define REPC(i,obj)  for(auto i:obj)
#define ALL(obj)     (obj).begin(),(obj).end()
#define SETP(n)      cout<<fixed<<setprecision(n)
#define VV(T,h,w)    move(vector<vector<T>>(h,vector<T>(w)))
#define VVI(T,h,w,i) move(vector<vector<T>>(h,vector<T>(w,i)))
using namespace std;
using ll = long long;
template<typename T = ll>inline T in() { T ret; cin >> ret; return ret; }

signed main()
{
	double a, b;
	cin >> a >> b;
	SETP(20);
	cout << a / b << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <deque>
#include <numeric>
#include <sstream>
#include <iomanip>
using lint = long long;

int main()
{
    lint n;
    scanf("%lld", &n);

    lint l = 0;
    std::cout << l << "\n";
    std::string sl;
    std::string sr;
    std::cin >> sl;
    sr = sl;

    if (sl == "Vacant")
        return 0;

    lint r = n;
    lint c = (l + r) / 2;
    std::cout << c << "\n";
    std::string sc;
    std::cin >> sc;

    if (sc == "Vacant")
        return 0;

    for (int i = 0; i < 18; ++i)
    {
        if ((c - l) % 2 != 0)
        {
            if (sl == sc)
            {
                r = c;
                sr = sc;
                c = (r + l) / 2;
            }
            else
            {
                l = c;
                sl = sc;
                c = (r + l) / 2;
            }
        }
        else if ((c - l) % 2 == 0)
        {
            if (sl != sc)
            {
                r = c;
                sr = sc;
                c = (r + l) / 2;
            }
            else
            {
                l = c;
                sl = sc;
                c = (r + l) / 2;
            }
        }

        std::cout << c << "\n";

        std::cin >> sc;
        if (sc == "Vacant")
            return 0;
    }
    return 0;
}


Measured memory_bytes: 852
import sys
def func():
    n,y=map(int,input().split())
    for yukichi in range(n+1):
        for ichiyou in range(n + 1 - yukichi):
          hideyo = n - yukichi - ichiyou

          if 10000*yukichi + 5000*ichiyou + 1000*hideyo == y:
            print(yukichi, ichiyou, hideyo)
            sys.exit()
    print(-1,-1,-1)

func()


Measured memory_bytes: 3060
using System;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var KX = Console.ReadLine().Split(' ');

            var K = int.Parse(KX[0]);
            var X = int.Parse(KX[1]);

 
            Console.WriteLine(K * 500 >= X ? "Yes": "No");
        }
    }
}

Measured memory_bytes: 11092
'use strict'

const ncr = (n, r, mod) => {
  mod = mod || 1e9+7
  const a = Math.max(n, r)
  const b = Math.min(n, r)
  const p = Math.min(b, a-b)
  const nu = new Array(p + 1)
  const de = new Array(p + 1)
  let dest = 1
  if (p > 0) {
    for (let i = 1; i <= p; i++) {
      nu[i] = a - p + i 
      de[i] = i
    }
    for (let k = 2; k <= p; k++) {
      const piv = de[k]
      const j = (piv > 1) ? -((a - p) % k) : 0
      for (let i = k; i <= p; i += k) {
        nu[i + j] /= piv; de[i] /= piv
      }
    }
    for (let i = 1; i <= p; i++) {
      if (nu[i] > 1) dest = dest * nu[i] % mod
    }
  }
  return dest
}

function main(inp) {
  inp = inp.trim().split(' ');
  const x = Number(inp[0])
  const y = Number(inp[1])

  let sum = 0
  for (let i = Math.floor(x / 2); i >= 0; i--) {
    const a = x - i * 2
    if (a * 2 + i === y) {
      sum = ncr(i+a, i)
    }
  }
  
  console.log(sum)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 15180
#include <iostream>
#include <algorithm>
#include <vector>
#include <unordered_map>
#include <functional>
#include <map>
#include <string>
using namespace std;
#define INF 1000000000;
#define MOD 1000000007;
typedef long long int ll;
int main(void){
    string s;
    cin>>s;
    int len=s.size();
    int cnt=0;
    for(auto c:s){
        if(c=='o')cnt++;
    }   
    if(cnt+15-len>=8){
        cout<<"YES"<<endl;
    }else{
        cout<<"NO"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int(i)=0;i<(n);i++)
#define SIZE 200001
int n,k,A[SIZE];

bool check(int c){
  int tmp=0;
  REP(i,n){
    tmp+=(A[i]-0.1)/c;
    if(tmp>k) return false;
  }
  return true;
}

int binary_search(){
  int lb=1,ub=1e9,mid;
  REP(i,100){
    mid=(lb+ub)/2;
    (check(mid)?ub:lb)=mid;
  }
  return ub;
}

int main(){
  cin>>n>>k;
  REP(i,n) cin>>A[i];
  cout<<binary_search();
}


Measured memory_bytes: 4392
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef map<int, int> mii;
typedef map<char,int> mci;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<pair<int,int>> vii;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define F first
#define S second
#define in insert
const int INF = 1e9 + 7;
int gcd (int a, int b) {
	return b ? gcd (b, a % b) : a;
}
int main(){
    int n, m, t;  cin>>n>>m;
    cin>>t;
    int ans = abs(t-m);
    for(int i = 2; i <= n; i++){
        cin>>t;
        ans = gcd(ans, abs(t-m));
    }
    cout<<ans;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
typedef long long bignum;
struct xy
{
	long long x;
	long long y;
};

int getGCD(int a, int b) {
	if (b != 0)
		return getGCD(b, a%b);
	else
		return a;
}
int main()
{
	int a, b;
	vector<xy> dst;
	while (cin >> a >> b ) {
		int GCD = a > b ? getGCD(a, b) : getGCD(b, a);
		bignum LCD = bignum(a) * bignum(b) / bignum(GCD);
		dst.push_back({ GCD ,LCD });
	}
	for (vector<xy>::iterator it = dst.begin(); it < dst.end(); it++)
		cout << (*it).x << " " << (*it).y << endl;
	return 0;
}


Measured memory_bytes: 3108
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

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

const ll mod=1e9+7;

int main(){
    ll d;
    cin >> d;
    vector<pll> c;
    rep(i,26){
        ll t;
        cin >> t;
        c.push_back(make_pair(t,i+1));
    }
    vector<vector<pll>> s(d);
    rep(i,d){
        rep(j,26){
            ll v;
            cin >> v;
            s[i].push_back(make_pair(v,j+1));
        }
        sort(s[i].rbegin(),s[i].rend());
    }
    vector<ll> ans,used(26);
    ll tot=d;
    ll cnt=0;
    sort(c.rbegin(),c.rend());
    rep(i,d){
        //cout << ans[i] << endl;
    }
    vector<ll> per(26);
    rep(i,26){
        per[i]=i+1;
    }
    do{
        rep(i,26){
            ans.push_back(per[i]);
            cnt++;
            if(cnt==d) break;
        }
        if(cnt==d) break;
    }while(next_permutation(per.begin(),per.end()));
    vector<ll> num(5);
    rep(i,5){
        num[i]=c[i].se;
    }
    rep(i,d){
        cout << num[i%5] << endl;
    }
    return 0;
} 


Measured memory_bytes: 3792
#!/usr/bin/env python3
import sys
import math
MOD = 1000000007  # type: int
from collections import Counter

# 素因数分解
def prime_decomposition(n):
  i = 2
  table = []
  while i * i <= n:
    while n % i == 0:
      n //= i
      table.append(i)
    i += 1
  if n > 1:
    table.append(n)
  return table

def solve(N: int):
    soinsuu = prime_decomposition(math.factorial(N))
    counter = Counter(soinsuu)
    answer =1
    for value in counter.values():
        answer = answer*(value+1)
    print(answer%MOD)
    return

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
#include <iostream>
#include <vector>
#include <array>
#include <queue>
#include <algorithm>

constexpr int N = 60;

using namespace std;

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

    const array<int, 4> wsad_y{-1, 1, 0, 0};
    const array<int, 4> wsad_x{0, 0, -1, 1};

    int h, w;
    array<string, N> map;
    array<array<int, N>, N> dis;

    cin >> h >> w;
    for (int i = 0; i < h; i++)
        cin >> map[i];

    for (int i = 0; i < h; i++)
        dis[i].fill(-1);

    queue<int> srch_y, srch_x;
    dis[0][0] = 0;
    srch_y.push(0);
    srch_x.push(0);

    while (!srch_y.empty() && dis[h - 1][w - 1] < 0)
    {
        const int y = srch_y.front();
        const int x = srch_x.front();
        srch_y.pop();
        srch_x.pop();
        for (int i = 0; i < 4; i++)
        {
            const int y_next = y + wsad_y[i];
            const int x_next = x + wsad_x[i];
            if (y_next >= 0 && y_next < h && x_next >= 0 && x_next < w)
                if (map[y_next][x_next] == '.')
                    if (dis[y_next][x_next] < 0)
                    {
                        dis[y_next][x_next] = dis[y][x] + 1;
                        srch_y.push(y_next);
                        srch_x.push(x_next);
                    }
        }
    }

    int n_b = 0;
    for (int i = 0; i < h; i++)
        for (int j = 0; j < w; j++)
            if (map[i][j] == '#')
                n_b++;
    const int n_w = w * h - n_b;
    const int n_route = dis[h - 1][w - 1] + 1;

    int ans;
    if (dis[h - 1][w - 1] < 0)
        ans = -1;
    else
        ans = n_w - n_route;

    cout << ans << endl;

    return 0;
}


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

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

signed main(){
    string s;cin>>s;
    replace(all(s),',',' ');
    cout<<s<<endl;
    return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-

current_time = 0
current_state = (0, 0)

n = int(input())
for i in range(n):
    t, x, y = map(int, input().split())

    # distance check
    distance = abs(current_state[0] - x) + abs(current_state[1] - y)
    time_gap = t - current_time
    if time_gap < distance:
        print("No")  # 遠すぎて時間内で移動できない
        exit()

    # possibility check (時間差に)
    # 偶数時間で行ける位置は、偶数距離に存在する必要がある
    # (同様に) 奇数時間で行ける位置は、奇数距離に存在する必要がある
    if time_gap % 2 == 0:
        if not (distance % 2 == 0):
            print("No")
            exit()
    else:
        if distance % 2 == 0:
            print("No")
            exit()

    current_time = t
    current_state = (x, y)

print("Yes")


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

using namespace std;

struct mazepoint {
	int y;
	int x;
};

int main() {

	int h, w;
	cin >> h >> w;
	int sy, sx;
	int gy, gx;

	vector<int> mukix{ 1,0,-1,0 };
	vector<int> mukiy{ 0,1,0,-1 };

	//迷路読み込み
	vector<string> maze(h + 1);
	for (int i = 0; i < h; i++) {
		cin >> maze[i];
	}
	bool brkflg = false;
	int fukasamax=0;
	for (int hh = 0; hh < h; hh++) {
		for (int ww = 0; ww < w; ww++) {

			if (maze[hh][ww] != '.') { continue; }

			sy = hh;
			sx = ww;

			for (int hhh = 0; hhh < h; hhh++) {
				for (int www = 0; www < w; www++) {
					if (hh == hhh && ww == www) { continue; }
					if (maze[hhh][www] != '.') { continue; }

					gy = hhh;
					gx = www;

					brkflg = false;

					//幅優先探索処理
					vector<vector<bool>> seen(h + 1, vector<bool>(w + 1));	//発見したらtrue
					deque<mazepoint> todo;					//行く所のスタック

					todo.push_back({ sy, sx });
					mazepoint s = todo.front();							//今いる場所

					seen[s.y][s.x] = true;
					vector<vector<int>> fukasa(h + 1, vector<int>(w + 1, 0));

					while (todo.empty() != true) {				//スタックが空になるまで処理	
						s = todo.front();						//処理番号を指定
						int tugiflg = false;					//次があったらtrueにするフラグ
						for (int i = 0; i < 4; i++) {
							if (s.y + mukiy[i] == gy && s.x + mukix[i] == gx) {
								fukasamax = max(fukasamax, fukasa[s.y][s.x] + 1);
								brkflg = true;
								break;
							}
							if (s.y + mukiy[i] < 0 || s.y + mukiy[i] >= h || s.x + mukix[i] < 0 || s.x + mukix[i] >= w) { continue; }
							if (maze[s.y + mukiy[i]][s.x + mukix[i]] == '#') { continue; }
							if (seen[s.y + mukiy[i]][s.x + mukix[i]] != true) {
								seen[s.y + mukiy[i]][s.x + mukix[i]] = true;
								todo.push_back({ s.y + mukiy[i],s.x + mukix[i] });
								fukasa[s.y + mukiy[i]][s.x + mukix[i]] = fukasa[s.y][s.x] + 1;
								tugiflg = true;
								//				cout << s.y + mukiy[i] << " " << s.x + mukix[i] << endl;
							}
						}
						if (brkflg) { break; }
						todo.pop_front(); //次を全部探したので削除する
					}
				}
			}
		}
	}

	cout << fukasamax << endl;
	return 0;

}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
using namespace std;
 
int main() {
    int n; cin >> n;
    vector<int> num(n);
    
    for(int i = 0; i < n; ++i) {
        int a;
        cin >> a; --a;
        num[a] = i+1;
    }
    
    for(int i = 0; i < n; ++i) cout << num[i] << ' ';
    cout << endl;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> x(n);
  for (int i = 0; i< n; i++) {
    cin >> x.at(i);
  }
  int p;
  int sum;
  int min = 100000000;
  for (p = 1; p <= 100; p++) {
    sum = 0;
    for (int i = 0; i < n; i++) {
      sum += (x.at(i) - p) * (x.at(i) - p);
    }
    //cout << sum << endl;
    if (sum < min)
      min = sum;
  }
  cout << min << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
#define rep(i,n)for(int i=0;i<n;i++)
#define int long long
#define ggr getchar();getchar();return 0;
#define prique priority_queue
constexpr auto mod = 1000000007;
#define inf 1e15
#define key 1e9
using namespace std;
typedef pair<int, int>P;
void yes() { cout << "Yay!" << endl; }
void no() { cout << ":(" << endl; }
template<class T> inline void chmax(T& a, T b) {
	a = std::max(a, b);
}
template<class T> inline void chmin(T& a, T b) {
	a = std::min(a, b);
}

//combination(Nが小さい時はこれを使う)
const int MAX = 300000;
int fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % mod;
		inv[i] = mod - inv[mod % i] * (mod / i) % mod;
		finv[i] = finv[i - 1] * inv[i] % mod;
	}
}
int COMB(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}

bool prime(int n) {
	int cnt = 0;
	for (int i = 1; i <= sqrt(n); i++) {
		if (n % i == 0)cnt++;
	}
	if (cnt != 1)return false;
	else return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}

//繰り返し二乗法（Nが大きい時の場合のcombination)
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= (i % mod); res %= mod;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}
//UnionFind
class UnionFind {
protected:
	int* par, * rank, * size;
public:
	UnionFind(unsigned int size) {
		par = new int[size];
		rank = new int[size];
		this->size = new int[size];
		rep(i, size) {
			par[i] = i;
			rank[i] = 0;
			this->size[i] = 1;
		}
	}
	int find(int n) {
		if (par[n] == n)return n;
		return par[n] = find(par[n]);
	}
	void unite(int n, int m) {
		n = find(n);
		m = find(m);
		if (n == m)return;
		if (rank[n] < rank[m]) {
			par[n] = m;
			size[m] += size[n];
		}
		else {
			par[m] = n;
			size[n] += size[m];
			if (rank[n] == rank[m])rank[n]++;
		}
	}
	bool same(int n, int m) {
		return find(n) == find(m);
	}
	int getsize(int n) {
		return size[find(n)];
	}
};
map<int, int>mp;
signed main() {
	int n, m;
	cin >> n >> m;
	int memo = m;
	COMinit();
	if (prime(m))cout << n << endl;
	else {
		for (int i = 2; i <= sqrt(m); i++) {
				while (memo % i == 0) {
					memo /= i;
					mp[i]++;
				}
		}
		if (memo != 1)mp[memo]++;
		int ans = 1;
		for (auto x : mp) {
			ans *= COMB(n + x.second - 1, n - 1);
			ans %= mod;
		}
		cout << ans << endl;
	}
	ggr
}


Measured memory_bytes: 7296
#include <iostream>

int main(){
  char Station[3];

  std::cin >> Station;

  for(int i=1;i<3;i++){
    if(Station[i] != Station[i-1]){
      std::cout << "Yes" << std::endl;
      return 0;
    }
  }

  std::cout << "No" << std::endl;
  return 0;
}


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

enum inf = 1_001_001_001;
enum infl = 1_001_001_001_001_001_001L;


void main() {
    int N;
    string s;

    scan(N);
    scan(s);

    long r, g, b;
    foreach (ch ; s) {
        if (ch == 'R') r++;
        if (ch == 'G') g++;
        if (ch == 'B') b++;
    }

    long ans = r * g * b;

    foreach (i ; 0 .. N) {
        foreach (j ; i + 1 .. N) {
            if ((i + j) % 2) continue;
            auto k = (i + j) / 2;
            if (s[i] != s[k] && s[k] != s[j] && s[i] != s[j]) ans--;
        }
    }

    writeln(ans);
}



void scan(T...)(ref T args) {
    auto line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront;
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;
    foreach (arg; args) if (x > arg) {
        x = arg;
        isChanged = true;
    }
    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;
    foreach (arg; args) if (x < arg) {
        x = arg;
        isChanged = true;
    }
    return isChanged;
}

void yes(bool ok, string y = "Yes", string n = "No") {
    return writeln(ok ? y : n);
}


Measured memory_bytes: 2708
using System;
using System.Collections.Generic;
using System.Linq;

namespace ITP1_6_B
{
	class Card
	{
		public char Mark { get; set; } = ' ';
		public int No { get; set; } = 0;

		public Card(string[] args)
		{
			Mark = args[0][0];
			No = int.Parse(args[1]);
		}
		public Card(char mark, int no)
		{
			Mark = mark;
			No = no;
		}
	}


	class Program
	{
		static void Main(string[] args)
		{
			int n = int.Parse(Console.ReadLine());

			List<Card> cards = new List<Card>();
			for(int i = 0; i < n; i++) {
				cards.Add(new Card(Console.ReadLine().Split(' ')));
			}

			List<Card> nothings = new List<Card>();
			char[] marks = { 'S', 'H', 'C', 'D' };

			foreach(char mark in marks) {
				for(int i = 1; i <= 13; i++) {
					if(!cards.Any(x => x.Mark == mark && x.No == i)) {
						nothings.Add(new Card(mark, i));
					}
				}
			}

			foreach(Card card in nothings) {
				Console.WriteLine($"{card.Mark} {card.No}");
			}
		}
	}
}



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

using namespace std;

int main(void)
{
    int N;
    int L[105];
    
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> L[i];
    }
    sort(L, L + N);
    int ans = 0;
    for (int i = 0; i < N - 2; i++) {
        for (int j = i + 1; j < N - 1; j++) {
            for (int k = j + 1; k < N; k++) {
                if(L[i] != L[j] && L[j] != L[k] && L[k] != L[i]) {
                    if (L[i] + L[j] > L[k] && L[j] + L[k] > L[i] && L[k] + L[i] > L[j]) {
                        ans++;
                    }
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3580
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N, K;
  int h[100000];
  cin >> N >> K;
  for(int i = 0; i < N; i++){
    cin >> h[i];
  }
  sort(begin(h), begin(h) + N);
  for(int i = 0; i <= N - K; i++){
    h[i] = h[i + K - 1] - h[i];
  }
  sort(begin(h), begin(h) + N - K + 1);
  cout << h[0] << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define ll long long
using namespace std;
//typedef vector<unsigned int>vec;
//typedef vector<ll>vec;
//typedef vector<vec> mat;
typedef pair<int, int> P;
typedef pair<ll,ll> LP;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;

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; }
//template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    REP(i,S.size()) cout << "x";
    cout << endl;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;

int main(){
  int n, m, q;
  cin >> n >> m >> q;
  vector<string> ss(n);
  for(int i = 0; i < n; ++i) cin >> ss[i];
  vvi nblue, nb_tate, nb_yoko;
  nblue.emplace_back(m+1,0);
  nb_tate.emplace_back(m+1,0);
  nb_yoko.emplace_back(m+1,0);
  for(int i = 1; i < (n+1); ++i){
    nblue.emplace_back(nblue[i-1]);
    nb_tate.emplace_back(nb_tate[i-1]);
    nb_yoko.emplace_back(nb_yoko[i-1]);
    for(int j = 1; j < (m+1); ++j){
      nblue[i][j] += nblue[i][j-1];
      nb_tate[i][j] += nb_tate[i][j-1];
      nb_yoko[i][j] += nb_yoko[i][j-1];
      nblue[i][j] -= nblue[i-1][j-1];
      nb_tate[i][j] -= nb_tate[i-1][j-1];
      nb_yoko[i][j] -= nb_yoko[i-1][j-1];
      if(ss[i-1][j-1] == '1'){
        nblue[i][j] += 1;
        if(i != 1 and ss[i-2][j-1] == '1') nb_tate[i][j] += 1;
        if(j != 1 and ss[i-1][j-2] == '1') nb_yoko[i][j] += 1;
      }
    }
  }
  for(int i=0; i < q; ++i){
    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    int node = nblue[x2][y2] - nblue[x1-1][y2] - nblue[x2][y1-1] + nblue[x1-1][y1-1];
    int edge = (nb_yoko[x2][y2] - nb_yoko[x1-1][y2] - nb_yoko[x2][y1] + nb_yoko[x1-1][y1]);
    edge += (nb_tate[x2][y2] - nb_tate[x1][y2] - nb_tate[x2][y1-1] + nb_tate[x1][y1-1]);
    cout << (node - edge) << endl;
  }
  return 0;
}


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

void pops(std::vector<int>& stack, int& lhs, int&rhs) {
    rhs = stack.back();
    stack.pop_back();
    lhs = stack.back();
    stack.pop_back();
}

int main(int argc, const char *argv[]) {
    std::vector<int> stack;
    for (std::string x; std::cin >> x; ) {
        if (x == "+") {
            if (stack.size() >= 2) {
                int lhs, rhs;
                pops(stack, lhs, rhs);
                stack.push_back(lhs + rhs);
            }
        } else if (x == "-") {
            if (stack.size() >= 2) {
                int lhs, rhs;
                pops(stack, lhs, rhs);
                stack.push_back(lhs - rhs);
            }
        } else if (x == "*") {
            if (stack.size() >= 2) {
                int lhs, rhs;
                pops(stack, lhs, rhs);
                stack.push_back(lhs * rhs);
            }
        } else {
            int val = x[0] - '0';
            for (int i = 1; i < x.size(); i++) {
                val = val * 10 + x[i] - '0';
            }
            stack.push_back(val);
        }
    }
    std::cout << stack.front() << std::endl;
    return 0;
}

Measured memory_bytes: 3188
#include <cstdio>

constexpr int maxn = 500005;

struct Node {
    int l, r, sum;
} tree[maxn << 7];

int root[maxn], pos[maxn], A[maxn], cnt;
void build(int& o, int l, int r) {
    o = ++cnt;
    if (l == r)
        return;
    int m = (l + r) >> 1;
    build(tree[o].l, l, m);
    build(tree[o].r, m + 1, r);
}
int modify(int old, int l, int r, int p, int v) {
    int o = ++cnt;
    tree[o] = tree[old];
    if (l == r) {
        tree[o].sum += v;
        return o;
    }
    int m = (l + r) >> 1;
    if (p <= m)
        tree[o].l = modify(tree[old].l, l, m, p, v);
    else
        tree[o].r = modify(tree[old].r, m + 1, r, p, v);
    tree[o].sum = tree[tree[o].l].sum + tree[tree[o].r].sum;
    return o;
}
int query(int l, int r, int o, int p) {
    if (l == r)
        return tree[o].sum;
    int m = (l + r) >> 1;
    if (p <= m)
        return tree[tree[o].r].sum + query(l, m, tree[o].l, p);
    return query(m + 1, r, tree[o].r, p);
}
int main() {
    int n, m;
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i++)
        scanf("%d", A + i);
    build(root[0], 1, n);
    for (int i = 1; i <= n; i++) {
        if (!pos[A[i]])
            root[i] = modify(root[i - 1], 1, n, i, 1);
        else {
            int t = modify(root[i - 1], 1, n, pos[A[i]], -1);
            root[i] = modify(t, 1, n, i, 1);
        }
        pos[A[i]] = i;
    }
    while (m--) {
        int l, r;
        scanf("%d%d", &l, &r);
        printf("%d\n", query(1, n, root[r], l));
    }

    return 0;
}

Measured memory_bytes: 252496
#include<bits/stdc++.h>
typedef long double db;
db sum,a;
int n;
int main()
{
	std::cin >> n;
	for(int i = 1;i <= n;i++) {
		std::cin >> a;
		sum += (1 / a);
	}
	std::cout << 1/ sum;

	return 0;
}



Measured memory_bytes: 256
/*************************************************************************
	> File Name: B.cpp
	> Author: Knowledge_llz
	> Mail: 925538513@qq.com 
	> Created Time: 2020/4/19 20:41:09
 ************************************************************************/

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
#define For(i,a,b) for(register int i=(a);i<=(b);++i)
#define LL long long
using namespace std;
int read(){
	char x=getchar(); int u=0,fg=0;
	while(!isdigit(x)){ if(x=='-') fg=1; x=getchar(); }
	while(isdigit(x)){ u=(u<<3)+(u<<1)+(x^48); x=getchar(); }
	return fg?-u:u;
}
struct node{
	LL val,id;
}a[2020];
bool cmp(node x,node y){
	return x.val>y.val;
}
LL dp[2020][2020];
int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.in", "r", stdin);
	freopen("output.out", "w", stdout);
#endif
	int n;
	n=read();
	For(i,1,n){
		a[i].val=read();
		a[i].id=i;
	}
	sort(a+1,a+n+1,cmp);
	For(i,0,n-1)
		For(j,0,n-1){
			int k=i+j+1;
			if(k>n) break;
			dp[i+1][j]=max(dp[i+1][j],dp[i][j]+1ll*a[k].val*abs(a[k].id-i-1));
			dp[i][j+1]=max(dp[i][j+1],dp[i][j]+1ll*a[k].val*abs(n-j-a[k].id));
		}
	LL ans=0;
	For(i,0,n)
		ans=max(ans,dp[i][n-i]);
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 26448
#include <iostream>
using namespace std;
typedef long long ll;
ll ans,n;
main(){
	register int i;
	cin>>n;
	for(i=1;i<=n;i++){
		ll x;
		cin>>x;
		ans+=x;ans%=2;
	}
	if(ans%2==0)cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	return 0; 
}

Measured memory_bytes: 256
/* Atcoder abc168c
 * See tasks at: https://atcoder.jp/contests/abc168/tasks/abc168_c
 */
#include <bits/stdc++.h>

#define until(symbol, max) for (int symbol = 0; (symbol) < (max); (symbol)++)

using namespace std;
using ll = long long;
int main()
{
    int a, b, h, m;
    cin >> a >> b >> h >> m;

    double hd = h * 2 * M_PI / 12 + m * 2 * M_PI / 12 / 60;
    double md = m * 2 * M_PI / 60;
    double dd = hd - md;

    double lsq = a * a + b * b - 2 * a * b * cos(dd);
    double l = sqrt(lsq);

    cout << fixed << setprecision(20) << l;

    return 0;
}


Measured memory_bytes: 4224
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef long long ll;
 
int main(){
  
  int sum=0;
  rep(i,3){
    sum*=10;
    int a;
    cin >> a;
    sum+=a;
  }
  if(sum%4==0) cout <<"YES"<<endl;
  else cout << "NO" << endl;
  
  return 0;
}

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

double h(double a){
  if(a>0)a=floor(a);
  else a=ceil(a);
  return a;
}

int main(){
  int a,ir;
  double x=0,y=0,r=0;
  while(1){
    scanf("%d,%d",&a,&ir);
    if(a==0&&ir==0)break;
    y+=a*cos(M_PI*r/180);
    x+=a*sin(M_PI*r/180);
    r+=ir;
  }
  x=h(x);
  y=h(y);
  printf("%.0f\n%.0f\n",x,y);
  return 0;
}

Measured memory_bytes: 640
<?php

fscanf(STDIN, "%d %d %d", $n, $m, $c);
$b_arr = explode(' ', trim(fgets(STDIN)));

$a_arr = [];
for ($i = 0; $i < $n; ++$i) {
    $a_arr[$i] = explode(' ', trim(fgets(STDIN)));
}

$count = 0;
for ($i = 0; $i < $n; ++$i) {
    $tmp = $c;
    for ($j = 0; $j < $m; ++$j) {
        $tmp += $a_arr[$i][$j] * $b_arr[$j];
    }

    if ($tmp > 0) {
        ++$count;
    }
}

echo $count;


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

using namespace std;

int main(){
  int N, A[100000], B[100000], ans = 1;

  cin >> N;

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

  sort(A, A+N, greater<int>());

  for(int i = 1, j = 0;N - i >= 0;i += 2, j+=2){
    B[j] = N - i;
    B[j+1] = N - i;
  }

  for(int i = 0;i < N;i++){
    if(A[i] != B[i]){
      cout << 0 << endl;
      return 0;
    }
  }

  for(int i = 0;i < N/2;i++){
    ans *= 2;
    ans %= 1000000000 + 7;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1024
// Lets go to the next level
// AIM EXP at CF *__* asap
// Hit A,B,C faster and reach Expert
// Remember you were also a novice when you started,
// hence never be rude to anyone who wants to learn something!Be calm and help everyone.
// Never open the rank list until and unless you are done with solving problems!
/*HACK ME IF YOU CAN!
░░███▒▒░░░░░░░░░░░░░░░░████
░░████▒░░░░░░░░░░░░░░░███▒█
░░██████░░░░░░░░░░░░░███▒▒▒█
░░██▒▒▒▒█▒▒▒▒▒▒▒▒▒▒▒█████▒██
░▒▒▒▒▓▓▓▓▓▓▒▒▒▒▒▓▓▓▓▓▓▒▒▒░██
▒▒▒▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▒▒▒▒█
▒▒▓▓███████▓░▓▓███████▓▒▒▒▒▒▒
▒▒▓▓▓█▓▄▓█▓░░░▓▓█▓▄▓█▓▓▒▒▒▒▒▒
▒▒▓▓▓▓███▓░░░░░▓▓███▓▓▓▒▒▒▒▒▒
▒▒▒▓▓▓▓▓▓████▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒
▒▒▒▒▓▓▓▓▓▒██▒▒▒▓▓▓▓▒▒▒▒▒▒▒▒▒▒
▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
░▒▒▒▒▒▒▒▒█████▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
░░▒▒▒▒▒▒█▒▒▒▒▒█▒▒▒▒▒▒▒▒▒▒▒▒▒
░░░░░▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
*/

//Author: kaiyu
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define sz(x) ((long long)(x).size())
#define all(x)  x.begin(),x.end()
#define endl "\n"
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define leastsigbit(x)     __builtin_ffs(x)
#define mod             1000000007
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define pii pair<int,int>
#define vpii vector<pii>
#define tt ll tt;cin >> tt;while(tt--)
#define  fio ios::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define D1(x) { cerr << " [" << #x << ": " << x << "]\n"; }
#define D2(x) { cerr << " [" << #x << ": "; for(auto it:x) cerr << it << " "; cerr << "]\n";}
const double PI = acos(-1);
ll power(ll a,ll b,ll m=mod){ ll ans=1; a=a%m;  while(b>0) {  if(b&1)  ans=(1ll*a*ans)%m; b>>=1;a=(1ll*a*a)%m;}return ans;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll lcm( ll x, ll y) { return (x*y)/gcd(x,y);}
bool isprime(ll n){if(n < 2) return 0; ll i = 2; while(i*i <= n){if(n%i == 0) return 0; i++;} return 1;}
struct cmp {
    bool operator() (const pair<int,int>& lhs, const pair<int,int>& rhs) const {
        return lhs.ff * rhs.ss < lhs.ss * rhs.ff;
    }
//for map<pii,int>
};

bool cmps(pair<int,int>p1,pair<int,int>p2) {
    return p1.ss > p2.ss;
}

const int MAXN = 2e5+ 10;

#define int long long
int32_t main() {
//#ifndef ONLINE_JUDGE
    //freopen("inp1.txt","r",stdin);
    //freopen("out1.txt","w",stdout);
//#endif
    fio
    char x ;
    cin >> x;
    if(x <= 'Z' && x >= 'A')cout << 'A' << endl;
    else cout << 'a' << endl;


    cerr << "[ Time : " << (float)clock() / CLOCKS_PER_SEC << " secs ]" << endl;


}






Measured memory_bytes: 3800
# coding:utf-8

import sys
import math
import time
#import numpy as np
import collections
from collections import deque
from collections import Counter
import queue
import copy
import bisect
import heapq

#sys.setrecursionlimit(10**7)
#N, Q = map(int, input().split())
#G = [list(input()) for i in range(H)]
#INF = V * 10001
#A = [int(i) for i in input().split()]
#AB = [list(map(int, input().split())) for _ in range(K)]

N, K = map(int, input().split())
temp = N%K

while True:
  if(abs(temp-K)<temp):
    temp = abs(temp-K)
  else:
    break

print(temp)


Measured memory_bytes: 38764
def bubble_sort(r, n):
    flag = True  # ??£??\????´?????????¨????????°
    while flag:
        flag = False
        for i in range(n - 1, 0, -1):
            if r[i - 1][1] > r[i][1]:
                r[i - 1], r[i] = r[i], r[i - 1]
                flag = True
    return r


def select_sort(r, n):
    for i in range(0, n):
        minj = i
        for j in range(i, n):
            if r[j][1] < r[minj][1]:
                minj = j
        if i != minj:
            r[i], r[minj] = r[minj], r[i]
    return r


def stable_sort(r, sort_r):
    for i in range(len(r)):
        for j in range(i + 1, len(r)):
            for a in range(len(sort_r)):
                for b in range(a + 1, len(sort_r)):
                    if r[i][1] == r[j][1] and r[i] == sort_r[b] and r[j] == sort_r[a]:
                         return "Not stable"

    return "Stable"


N = int(input())
R = list(input().split())
C = R[:]
BS_R = bubble_sort(R, N)
SS_R = select_sort(C, N)
print(*BS_R)
print(stable_sort(R, BS_R))
print(*SS_R)
print(stable_sort(R, SS_R))

Measured memory_bytes: 7824