akhauriyash/Code-Regression huggingface dataset:
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <deque>     // deque
#include <iomanip>   //setprecsion
#include <iostream>  // cout, endl, cin
#include <map>       // map
#include <queue>     // queue, priority_queue
#include <set>       // set
#include <stack>     // stack
#include <string>    // string, to_string, stoi
#include <tuple>     // tuple, make_tuple
#include <utility>   // pair, make_pair
#include <vector>    // vector

#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>  //sin, cos, tan

using namespace std;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define blank(ans) cout << (ans) << " ";
#define mp(p, q) make_pair(p, q)
#define mt(p, q, r) make_tuple(p, q, r)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef string str;

typedef vector<ll> vll;
typedef vector<ld> vd;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<str> vs;
typedef vector<vector<ll>> vvll;
typedef vector<vector<ld>> vvd;
typedef vector<vector<bool>> vvb;
typedef vector<vector<char>> vvc;
typedef vector<vector<str>> vvs;
typedef vector<pair<ll, ll>> vpll;
typedef vector<tuple<ll, ll, ll>> vtlll;

const ld PI = acos(-1.0);
const ll MAX = 9000000000000000000;
const ll MIN = -9000000000000000000;
const ld DMAX = 4500;
const ld DMIN = -4500;
const ll MOD = 1000000007;

template <typename T>
void fin(T a)
{
  cout << a << endl;
  exit(0);
}

//桁数
ll GetDigit(ll num)
{
  return log10(num) + 1;
}

//約数全列挙
vector<ll> enum_div(ll n)
{
  vector<ll> ret;
  for (ll i = 1; i * i <= n; ++i)
  {
    if (n % i == 0)
    {
      ret.push_back(i);
      if (i * i != n)
      {
        ret.push_back(n / i);
      }
    }
  }
  sort(begin(ret), end(ret));
  return ret;
}

//累乗(xのn乗%mod)
ll modpow(ll x, ll n, ll mod = MAX)
{
  ll res = 1;
  while (n > 0)
  {
    if (n & 1)
      res = res * x % mod;
    x = x * x % mod;
    n >>= 1;
  }
  return res;
}

//階乗
ll factorial(ll n)
{
  if (n > 0)
    return n * factorial(n - 1);
  else
    return 1;
}

ll modinv(ll a, ll mod)
{
  ll b = mod, u = 1, v = 0;
  while (b)
  {
    ll t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= mod;
  if (u < 0)
    u += mod;
  return u;
}

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

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

void Main()
{
  ll x, y; cin >> x >> y;
  bool ans = false;
  for(ll i = 0;i <= x;i++)
  {
    ll sum = i * 2;
    sum += (x - i) * 4;
    if(sum == y) ans = true;
  }
  fin((ans?"Yes":"No"));
}

//前処理
int main()
{
  //ios::sync_with_stdio(false);
  //cin.tie(0);
  cout << fixed << setprecision(20); //高精度少数表示
  //cout << setfill('0') << internal << setw(4); 0埋め４桁
  Main();
  return 0;
}

Measured memory_bytes: 3724
n,m = map(int,input().split())
s = [0]*m
for i in range(m):
    s[i] = list(map(int,input().split()))
p = list(map(int,input().split()))
ans = 0
for i in range(2**n):
    sw = [0]*m
    for j in range(m):
        num = 0
        for k in range(n):
            if (i>>k)&1:
                if k+1 in s[j][1:]:
                    num += 1
        if num%2 == p[j]:
            sw[j] = 1
    if 0 in sw:
        pass
    else:
        ans += 1
print(ans)


Measured memory_bytes: 3064
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iterator>
#pragma warning(disable:4996)
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223372036854775807
#define INF 2147483647
#define MOD 1000000007
using namespace std;



int main(int argc, char* argv[])
{
    long n;
    scanf("%ld", &n);

    ll curr=1;
    long i;
    for(i=1; i<=n; i++) {
        curr = curr*i %MOD;
    }
    printf("%lld\n", curr);

    return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
#define MAX 105

int queue[100000],g[MAX][MAX],head=0,tail=0,cost[MAX];
void enqueue(int);
int dequeue(void);
void bfs();

int main(){
  int n,i,j,u,k;
  scanf("%d",&n);
  for(i = 1; i <= n; i++){
    cost[i] = -1;
    scanf("%d%d",&u,&k);
    for(j = 1; j <= k; j++){
      scanf("%d",&g[u][j]);
    }
    g[u][j] = -1;
  }
  bfs();
  for(i = 1; i <= n; i++) printf("%d %d\n",i,cost[i]);
  return 0;
}
void enqueue(int id){
  queue[tail] = id;
  tail++;
}
int dequeue(){
  if(head == tail) return -1;
  return queue[head++]; 
}
void bfs(){
  int id,i;
  enqueue(1);
  cost[1] = 0;
  while((id = dequeue()) != -1){
    for(i = 1; g[id][i] != -1; i++){
	if(cost[ g[id][i] ] == -1){
	  cost[ g[id][i] ] = cost[id] + 1;
	  enqueue(g[id][i]);
	}
    }
  }
}




Measured memory_bytes: 1996
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <ctime>
#include <list>
#include <numeric>
#include <utility>
#include <ctime>
#define INF 100000000
#define LINF 9000000000000000000
#define mod 1000000007
 
#define rep(i,n) for(int i=0;i<int(n);i++)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define mp make_pair
#define MOD(x) (x%(mod))
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;
 
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool debug=false;

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

int maze[105][105];
int w,h,xs,ys,xg,yg;

void init(){
  rep(i,105){
    rep(j,105){
      maze[i][j]=-1;
    }
  }
}

void DEBUG(){
  rep(i,h){
    rep(j,w)cout<<maze[i][j]<<" ";
    cout<<endl;
  }
}

bool bfs(int c){
  //DEBUG();
  queue<int>que;
  que.push(xs);
  que.push(ys);
  while(que.size()){
    //cout<<c<<endl;
    int x=que.front();que.pop();
    int y=que.front();que.pop();
    if(x==xg&&y==yg)return true;
    for(int i=0;i<4;i++){
      if(0<x+dx[i]&&x+dx[i]<=w&&0<y+dy[i]&&y+dy[i]<=h&&maze[y+dy[i]][x+dx[i]]==c&&maze[y+dy[i]][x+dx[i]]!=-1){
	que.push(x+dx[i]);
	que.push(y+dy[i]);
	maze[y+dy[i]][x+dx[i]]=-1;
      }
    }
  }
  return false;
}

int main(){
  int n,c,d,x,y;
  while(cin>>w>>h){
    if(w==0&&h==0)break;
    init();
    cin>>xs>>ys;
    cin>>xg>>yg;
    cin>>n;
    rep(i,n){
      cin>>c>>d>>x>>y;
      if(d==0){
	rep(j,2){
	  rep(k,4){
	    maze[y+j][x+k]=c;
	  }
	}
      }else if(d==1){
	rep(j,4){
	  rep(k,2){
	    maze[y+j][x+k]=c;
	  }
	}
      }
    }
    if(bfs(maze[ys][xs]))cout<<"OK"<<endl;
    else cout<<"NG"<<endl;
  }
  return 0;
}

Measured memory_bytes: 3032
#include<vector>
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
const ll MOD=1000000007LL;
const ll INF=1000000000LL;
const int MAX=100001;
int ch(char c){
    if(c=='m'){
        return 1000;
    }else if(c=='c'){
        return 100;
    }else if(c=='x'){
        return 10;
    }else{
        return 1;
    }
}
int mcxi(string s){
    int ret=0;
    stack<int> st;
    for(int i=0;i<s.length();i++){
        if(isalpha(s[i])){
            if(st.empty()){
                ret+=ch(s[i]);
            }else{
                int a=st.top();st.pop();
                ret+=a*ch(s[i]);
            }
        }else{
            st.push(s[i]-'0');
        }
    }
    return ret;
}
string tomcxi(int s,int w){
    string ret="";
    if(s/w){
        if(s/w>1){
            char p='0'+(s/w);
            ret.push_back(p);
        }
        char c;
        switch(w){
            case 1000:c='m';break;
            case 100:c='c';break;
            case 10:c='x';break;
            case 1:c='i';break;
        }
        ret.push_back(c);
    }
    return ret;
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        string s1,s2;
        cin>>s1>>s2;
        int sum=mcxi(s1)+mcxi(s2);
        cout<<tomcxi(sum,1000);sum%=1000;
        cout<<tomcxi(sum,100);sum%=100;
        cout<<tomcxi(sum,10);sum%=10;
        cout<<tomcxi(sum,1);
        cout<<endl;
    }
}

                           



Measured memory_bytes: 3116
#include <bits/stdc++.h>
using namespace std;
main(){
	int N, Q, a, b, i;
	cin>>N>>Q;
	i=N++;
	vector<vector<int>> d(N);
	int c[N]={},P[N]={},v[N]={1,1};
	while(--i)cin>>a>>b,d[a].push_back(b),d[b].push_back(a);
	while(Q--)cin>>a>>b,c[a]+=b;
	stack<int>s;s.push(1);
	while(!s.empty()){
		c[a=s.top()]+=c[P[a]];s.pop();
		for(b:d[a])if(!v[b])v[b]=P[b]=a,s.push(b);
	}
	for(a=1;a<N;a++)cout<<c[a]<<" ";
}

Measured memory_bytes: 17140
main :: IO ()
main = do
  [a, b, k] <- map read . words <$> getLine
  let (a', b') = f a b k
  putStrLn . unwords . map show $ [a', b']

data Person = Takahashi | Aoki

f :: Int -> Int -> Int -> (Int, Int)
f a b k = f' Takahashi k a b

f' :: Person -> Int -> Int -> Int -> (Int, Int)
f' _ 0 a b = (a, b)
f' Takahashi k a b = let a' = a `div` 2 in f' Aoki (k - 1) a' (b + a')
f' Aoki k a b = let b' = b `div` 2 in f' Takahashi (k - 1) (a + b') b'


Measured memory_bytes: 508
using System;

namespace ConsoleApplication7 {
    class Program {
        static void Main(string[] args) {
            int size_set = int.Parse(Console.ReadLine());
            int dim = 2;
            

            for (int iter = 0; iter < size_set; iter++) {
                string data = Console.ReadLine();
                if (string.IsNullOrEmpty(data)) {
                    continue;
                }
                string[] spritData = data.Split(' ');
                if (spritData.Length < 8) {
                    continue;
                }
                
                vector[] vec = new vector[4];
                for (int i = 0; i < vec.Length; i++) {
                    vec[i] = new vector(decimal.Parse(spritData[dim * i]), decimal.Parse(spritData[dim * i + 1]), dim);
                }
                vector[] segment = new vector[2];
                segment[0] = new vector(vec[0], vec[1], dim);
                segment[1] = new vector(vec[2], vec[3], dim);

                decimal product = calcCrossProduct(segment[0], segment[1]);

                if (product == 0) {
                    Console.WriteLine("YES");
                } else Console.WriteLine("NO");
            }

        }

        static decimal calcCrossProduct(vector vecA,vector vecB) {
            decimal crossProduct = 0;
            crossProduct = vecA.getVector()[0] * vecB.getVector()[1] - vecA.getVector()[1] * vecB.getVector()[0];
            return crossProduct;
        }
        
    }
    public class vector {
        decimal[] vec;
        public vector(decimal pointX,decimal pointY,int dim) {
            vec = new decimal[dim];
            vec[0] = pointX; vec[1] = pointY;
        }
        public vector(vector point1,vector point2,int dim) {
            vec = new decimal[dim];
            for (int i = 0; i < dim; i++) {
                vec[i] = point2.getVector()[i] - point1.getVector()[i];
			}
        }
        public decimal[] getVector() {
            return vec;
        }
    } 
}

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

int main(int argc, const char * argv[]) {

    int A,B,C;
    cin >> A >> B >> C;
    bool flag = false;
    
    for(int i=1; i < 101; i++){
        if(((A * i) % B) == C){
            flag = true;
            break;
        }
    }
    
    if(flag == true){
        cout << "YES";
    }else{
        cout << "NO";
    }
    
    return 0;
}

Measured memory_bytes: 256
"""
セグメント木：蟻本P153
できること：a[i]の更新(O(log n))、a[L],...,a[R-1]の最小値など(O(log n))
入力：n,a(配列)
     'ide_ele' : 単位元(min:∞, 和:0, 積:1, gcd:0)
     'segfunc' : return min(x,y) とかにする
出力:'init(a)': 配列aで初期化。O(N)
     'update(k,x)': a[k]をxに変更 O(logN)
     'query(p,q)': [p,q)について "segfunc" したものを返す O(logN)
"""
n=int(input())
a=[int(input()) for i in range(n)]
#####segfunc######
def segfunc(x,y):
    return max(x,y)


def init(init_val):
    #set_val
    for i in range(n):
        seg[i+num-1]=init_val[i]    
    #built
    for i in range(num-2,-1,-1) :
        seg[i]=segfunc(seg[2*i+1],seg[2*i+2]) 
    
def update(k,x):
    k += num-1
    seg[k] = x
    while k:
        k = (k-1)//2
        seg[k] = segfunc(seg[k*2+1],seg[k*2+2])
    
def query(p,q):
    if q<=p:
        return ide_ele
    p += num-1
    q += num-2
    res=ide_ele
    while q-p>1:
        if p&1 == 0:
            res = segfunc(res,seg[p])
        if q&1 == 1:
            res = segfunc(res,seg[q])
            q -= 1
        p = p//2
        q = (q-1)//2
    if p == q:
        res = segfunc(res,seg[p])
    else:
        res = segfunc(segfunc(res,seg[p]),seg[q])
    return res

#####単位元######
ide_ele = 0
num =2**(n-1).bit_length()
seg=[ide_ele]*2*num
init(a)
print(query(1,n))
for i in range(1,n):
    print(max(query(0,i),query(i+1,n)))

Measured memory_bytes: 87512
#include "bits/stdc++.h"

using namespace std;

const char en = '\n';
using  ll =          long long;
using ull = unsigned long long;
#define REP(i  ,n) for(int i=0;i<n;i++)
#define FOR(i,s,g) for(int i=s;i<g;i++)
const ll INFL = 810810191911451400;
const int INF =       1919114514;

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

	int sum=0,buf;
	REP(i, 5){
		cin>>buf;
		sum+=max(buf,40);
	}
	cout<<sum/5<<en;
	return 0;
}

Measured memory_bytes: 3140
object Main {

  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)

    val X = sc.nextInt()

    def eratosthenes(n: Int): Seq[Int] = {
      val upper = Math.sqrt(n)
      def loop(lst: List[Int], used: List[Int]): List[Int] =
        if (lst.head < upper) {
          loop(lst.tail.filter(_ % lst.head != 0), lst.head :: used)
        } else used.reverse ++ lst
      loop((2 to n).toList, Nil)
    }
    val MAX = Math.pow(10, 6).toInt
    println(eratosthenes(MAX).find(_ >= X).get)
  }

}


Measured memory_bytes: 175688
n=int(input())
a=list(map(int,input().split()))
ans=0
for i in range(n):
  if i%2==0:
    ans+=a[i]
  else:
    ans-=a[i]
for i in range(n):
  print(ans)
  ans-=a[i]
  ans=ans*(-1)
  ans+=a[i]

  

Measured memory_bytes: 85624
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <string>
#include <set>
#define INF 1000000000
#define LLINF 2000000000000000
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define LOOP(i,N) for(int i=0;i<N;i++)
#define LOOP1(i,N) for(int i=1;i<=N;i++)
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;
// #define int long long


std::vector<P> node[1000001];// n to first , distance
int n,m;

//i ざひょー dis スタート地点からの距離
int res[100001];
int func(int i, int dis){
  if(res[i]!=0)return 0;
  res[i]= dis%2 ? 1 : -1;
  LOOP(j,node[i].size()){
    func(node[i][j].first, dis + node[i][j].second);
  }
  return 1;
}

signed main(){
  cin >> n >> m;
  LOOP1(i,m){
    int u,v,w;
    cin >> u >> v >> w;
    node[u].push_back(P(v,w));
    node[v].push_back(P(u,w));
  }
  int ans = 0;
  LOOP1(i,n){
    ans +=func(i,0);
  }
  cout << ans << endl;

}


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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int MD = (int)1e9 + 7; typedef vector<ll> VL;
void dbg(){ cerr << "\n"; }  template <class T, class ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }

vector<VI> a;

int f(int s, set<pii>& q){
	int rtn = -1;
	if(sz(a[s])==0) return -1;
	if(a[a[s].back()].back() != s) return -1;
	else{
		q.insert(pii(min(s, a[s].back()), max(s, a[s].back())));
		return a[s].back();
	}
}

int main()
{

	cin.tie(0); ios_base::sync_with_stdio(false);
	ll n; 
	cin >>n;
	
	a = vector<VI>(n, VI(n-1));
	rep(i, n) rep(j, n-1){
		cin >> a[i][j]; a[i][j]--;
	}

	rep(i, n) reverse(all(a[i]));
	
	set<pii> q;
	rep(i, n) f(i, q);
	
	ll ans =0;
	
	while(sz(q)){
		ans++;
		set<pii> cur;
		swap(q, cur);
		for(auto z: cur){
			a[z.first].pop_back();
			a[z.second].pop_back();
		}
		for(auto z: cur){
			int rc = f(z.first, q);
			rc = f(z.second, q);
		}
	}
	rep(i, n) if(sz(a[i])) {puts("-1"); return 0;}
	
	cout << ans <<"\n";
}


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

using namespace std;

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

  int h,w;
  cin >> h >> w;
  vector<string> a(h);
  for(int i=0;i<h;i++) cin >> a[i];
  
  vector<vector<int>> d(h,vector<int>(w,-1));
  vector<pair<int,int>> que;
  
  for(int i=0;i<h;i++){
   for(int j=0;j<w;j++){
    if(a[i][j]=='#') que.emplace_back(i,j), d[i][j]=0; 
   }
  }
  
  
  for(int i=0;i<que.size();i++){
    for(int dx=-1;dx<=1;dx++){
     for(int dy=-1;dy<=1;dy++){
      if(dx*dx+dy*dy==1){
       int x=que[i].first+dx,y=que[i].second+dy;
        if(0<=x&&x<h&&0<=y&&y<w&&d[x][y]==-1){ 
        que.emplace_back(x,y);
        d[x][y]=d[que[i].first][que[i].second]+1;  
      }
      } 
     }
  }
  }
  cout << d[que.back().first][que.back().second] << endl;
}


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

int G;
set<char> g[128];
char D[128];
int p;
string e;

string f(int l){
	if( G == l ){
		if( e[p] == '(' ){
			p++;
			string r = f(0);
			p++;
			return r;
		}else{
			string r = string(1,e[p]);
			p++;
			return r;
		}
	}
	string le = f(l+1);
	vector<string> seq;
	seq.push_back(le);
	while( g[l].count(e[p]) ){
		char op = e[p];
		seq.push_back(string(1,op));
		p++;
		seq.push_back(f(l+1));
	}
	if( D[l] == 'L' ){
		string res = seq[0];
		for(int i = 1 ; i < seq.size() ; i+=2)
			res = "(" + res + seq[i] + seq[i+1] + ")";
		return res;
	}else{
		string res = seq[seq.size()-1];
		for(int i = seq.size()-2 ; i >= 0 ; i-= 2)
			res = "(" + seq[i-1] + seq[i] + res + ")";
		return res;
	}
}
int main(){
	int T;
	cin >> T;
	int cnt = 0;
	while(T--){
		if( cnt++ ) cout << endl;
		for(int i = 0 ; i < 128 ; i++) g[i].clear();
		cin >> G;
		for(int i = 0 ; i < G ; i++){
			cin >> D[i];
			int M;
			cin >> M;
			for(int j = 0 ; j < M ; j++){
				char c;
				cin >> c;
				g[i].insert(c);
			}
		}
		int Q;
		cin >> Q;
		for(int i = 0 ; i < Q ; i++){
			cin >> e;
			p = 0;
			cout << f(0) << endl;
		}
		
		
	}
}

Measured memory_bytes: 1292
import math
a, b, h, m = map(int, input().split())
ba = (360 / 60) * m
aa = 30*h +(30/60)*m
ca = aa - ba
if ca >= 180:
    ca1 = 360-ca
else:
    ca1 = ca

d = math.cos(math.radians(ca1))
c = (a**2 + b ** 2 -2*a*b*d)** 0.5
print(c) 

Measured memory_bytes: 9508
n=gets.to_i
a=[0]
n.times{|i|a<<gets.to_i}
#p -1 if not n.include?(2)
l=1
c=0
while true do
  c+=1
  x=a[l]
  a[l]=-1
  if x==-1
    p -1;exit
  elsif x==2
    p c;exit
  end
  l=x
end

Measured memory_bytes: 2996
def main():
    import sys
    #input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations
    #from itertools import accumulate, product
    from bisect import bisect_left,bisect_right
    from math import floor, ceil
    #from operator import itemgetter

    #mod = 1000000007

    n = int(input())
    res = 0
    for i in range(1, n+1):
        cnt = 0
        while i%2==0:
            i //= 2
            cnt += 1
        res = max(res, cnt)
    print(2**res)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
typedef long long int64;
typedef complex<double> cmplx;
const double pi = 3.14159265358979323846;
const int inf = (int)2e+9 + 2;
const int mod = (int)1e+9 + 7;
const double eps = 1e-8;
const int N = 500'000;

int n, m, k;
int a[100'000];

int gcd(int x, int y)
{
    while (y) {
        x %= y;
        swap(x, y);
    }
    return x;
}

void solve()
{
    int x;
    cin >> n >> x;
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    sort(a, a + n);
    if (n == 1) {
        cout << abs(x - a[0]);
        return;
    }
    int g = a[1] - a[0];
    for (int i = 2; i < n; ++i) {
        g = gcd(a[i] - a[i - 1], g);
    }
    g = gcd(abs(x - a[0]), g);
    cout << g;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    int test = 1;
    //cin >> test;
    for (; test; --test)
        solve();
    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int h, n, i, j, sum = 0;
    scanf("%lld %lld", &h, &n);
    int a[n];
    for (i=0; i<n; i++) {
        scanf("%d", &a[i]);
        sum += (long long int)a[i];
    }
    if (sum >= h) printf("Yes\n");
    else printf("No\n");
    return 0;
}


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

int main(){

  int n,m,reason;

  cin >> n >> m;

  int tag[m],table[n] = {0};

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

  for(int i=0; i<m; i++){
    for(int j=0; j<n; j++){
      cin >> reason;
      if(reason == tag[i]){
        table[j]++;
      }
      else{
        table[tag[i]-1]++;
      }
    }
  }

 for(int i=0; i<n; i++){
   cout << table[i] << endl;
 }

 return 0;

}

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

using namespace std;
double x[10],y[10];

double fact(int n){
    double Res = 1;
    for(double i = n ;i>=1;i--)  Res*=i;
    return Res;
}

vector < int > v;

int main()
{
    int n; cin >> n;
    for(int i = 0;i<n;i++)  v.push_back(i) , cin >> x[i] >> y[i];
    double Ans = 0;
    do{
        for(int i = 0;i<v.size() - 1;i++){
            Ans+=sqrt(((x[v[i]] - x[v[i + 1]]) * (x[v[i]] - x[v[i + 1]])) + ((y[v[i]] - y[v[i + 1]]) * (y[v[i]] - y[v[i + 1]])));
        }

    }while(next_permutation(v.begin() , v.end()));
    cout << setprecision(10) << fixed << (Ans/fact(n));
    return 0;
}


Measured memory_bytes: 256
#![allow(unused)]

//input
//use std::io::Read;

//collections
//use std::collections::BTreeMap;
//use std::collections::BTreeSet;
//use std::collections::HashMap;
//use std::collections::HashSet;

//入力マクロここから
//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
//入力マクロここまで

fn main() {
    input! {
        a: [usize;2]
    }
    let mut a = a;

    for i in 1..3 + 1 {
        if !a.contains(&i) {
            println!("{}", i);
        }
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define FOR(I,X,Y) for(long long (I)=(X);(I)<(Y);(I)++)
#define REP(I,X,Y) for(long long (I)=(Y)-1;(I)>=(X);(I)--)
#define ALL(X) (X).begin(),(X).end()
#define pb push_back
#define COUNT(V,X) upper_bound((V).begin(),(V).end(),X)-lower_bound((V).begin(),(V).end(),X)
#define debug(x0123456789) cerr<<#x0123456789<<':'<<x0123456789<<endl;
#define DEBUG(v) cerr<<#v<<':';for(auto x0123456789:v)cerr<<x0123456789<<' ';cerr<<endl;
#define INF 1000000007
#define LINF 1000000000000000007
#define EPS 1e-9
typedef long long ll;
typedef long double ld;

long long POW(long long x,long long n){long long ans = 1;while(n){if(n%2)ans *= x;x *= x;n >>= 1;}return ans;}
long long POW(long long x,long long n,long long mod){long long ans = 1;while(n){if(n%2)ans *= x;x *= x;x %= mod;ans %= mod;n >>= 1;}return ans;}

vector<long long> PrimeFactorize(long long n){
  vector<bool> prime(round(sqrt(n))+1,1);
  vector<long long> ans;
  for(long long i=2;i*i<=n;i++){
    if(prime[i]){
      for(long long j=2*i;j*j<=n;j+=i){
        prime[j] = 0;
      }
      while(n%i==0){
        ans.push_back(i);
        n /= i;
      }
    }
  }
  if(n != 1)ans.push_back(n);
  return ans;
}

signed main(){
    ll N;
    cin >> N;
    map<int,int> m;
    FOR(i,1,N+1){
        vector<ll> v = PrimeFactorize(i);
        for(auto x:v)m[x]++;
    }
    vector<ll> v;
    FOR(i,1,N+1)v.pb(m[i]);
    sort(ALL(v));
    DEBUG(v)
    int count2 = COUNT(v,2)+COUNT(v,3);
    int count4 = v.end()-lower_bound(ALL(v),4);
    ll ans = 0;
    ans += count2*(count4)*(count4-1)/2+(count4)*(count4-1)*(count4-2)/2;
    count4 = upper_bound(ALL(v),13)-lower_bound(ALL(v),4);
    int count14 = v.end()-lower_bound(ALL(v),14);
    ans += count4*count14+count14*(count14-1);
    count2 = upper_bound(ALL(v),23)-lower_bound(ALL(v),2);
    int count24 = v.end()-lower_bound(ALL(v),24);
    ans += count2*count24+count24*(count24-1);
    ans += v.end()-lower_bound(ALL(v),74);
    cout << ans << endl;
}

//4 14
//2 24
//74



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

int f(int n) {
    if(n % 2 == 0) {
        return n/2;
    }
    else {
        return 3*n + 1;
    }
}

int main() {
    int s;
    cin >> s;
    const int k = 1000000;
    int a[k];

    a[0] = s;
    for(int i = 1; i < k; i++) {
        a[i] = f(a[i-1]);
    }

    int ans;
    if(s == 1 || s == 2) { ans = 4; }
    else {
        for(int i = 0; i < k; i++) {
            if(a[i] == 4) {
                ans = i + 4;
                break;
            }
        }
    }

    cout << ans;

    cout << endl;
    return 0;
}

Measured memory_bytes: 4096
import java.lang.*;
import java.util.*;

public class Main
{
    static Scanner sc = new Scanner(System.in);

    public static void main(String args[])
    {
        int[][] dp = new int[5][4001];
        dp[0][0] = 1;
        
        for(int i = 1; i < 5; i++){
            for(int j = 0; j <= 1000*i; j++){
                for(int k = Math.max(0, j-1000); k <= j; k++){
                    dp[i][j] += dp[i-1][k];
                }
            }
        }
        
        while( sc.hasNext() ){
            System.out.println( dp[4][sc.nextInt()] );
        }
        
    }
}

	    
	    

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

#include <cmath>


using namespace std;

int digit_count(int n) {
  int ret = 0;

  while (n > 0) {
    ret += 1;
    n /= 10;
  }

  return ret;
}

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

  int ans = 0;

  for (int i = 1; i <= n; i++) {
    if (digit_count(i) % 2 == 1) {
      ans++;
    }
  }

  cout << ans << endl;


  return 0;
}


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

int main(){
  
  int a,b,c;
  
  cin >> a >> b >> c;
  
  if ((a != b && b == c) || (a == b && b != c) || (a == c && b != c))
  {
    cout << "Yes";
  }
  else
  {
    cout << "No";
  }
  
  return 0;
}

Measured memory_bytes: 256
//的場梨沙★担当
//結城晴★副担当
//日野茜★副担当
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string.h>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <cctype>
#include <complex>
#include <regex>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <iostream>
#include <stdio.h>
#include <string.h>

using namespace std;
#include <stdio.h>
#include <math.h>
#include <string>
#include <iostream>

int main(void){
    int N,K;
    cin>>N>>K;
    int i=0;
    while(N!=0){
       N/=K;
        i++;
    }

    cout<<i<<endl;

}


Measured memory_bytes: 256
function Main(input) {
  input = input.trim()
  var [a,b,c] = input.split(" ").map(BigInt);
  console.log(((b/c)-(a==0?0n:a-1n)/c+((a==0n)?1n:0n)).toString())
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


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

int main(void) {
	int S, h, m, s, x;
	cin >> S;

		h = S / 3600;
		x = S / 60;
		m = x % 60;
		s = S % 60;
		cout << h << ":" << m << ":" << s << endl;
	return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<long long,long long>
#define ii pair<int,int>
#define mod 1000000007
#define endl '\n'
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);

ll power(ll a,ll b){
	ll ans=1;
	while(b>0){
		if(b%2!=0){
			ans=(ans*a)%mod;
		}
		a=((a%mod)*(a%mod))%mod;
		b>>=1;
	}
	return ans;
}

void sieve(int n){
	bool prime[n+1];
	memset(prime,true,sizeof(prime));
	for(int p=2;p*p<=n;p++){
		if(prime[p]){
			for(int i=p*p;i<=n;i+=p)
				prime[i]=false;
		}
	}
	for(int p=2;p<=n;p++){
		if(prime[p])
			cout<<p<<" ";
	}
}

ll fact[2000005],modi[2000005];
void pre(){
    fact[0]=1;
    modi[0]=1;
    for(int i=1;i<2000005;i++){
        fact[i]=i*fact[i-1];
        fact[i]%=mod;
        modi[i]=power(fact[i],mod-2);
    }
}
 
ll ncr(ll n,ll r){
    if(n<r)
    return 0;
    ll ha=(((fact[n]*modi[n-r])%mod)*modi[r])%mod;
    return ha;
}

int main() {
	IOS;
	int t=1;
	pre();
	//cin>>t;
	while(t--){
		ll x,y;
		cin>>x>>y;
		ll a=0,b=2*x-y;
		if(b<0||b%3!=0){
			cout<<0;
			return 0;
		}
		b/=3;
		a=x-2*b;
		if(a<0){
			cout<<0;
			return 0;
		}
		cout<<ncr(a+b,a);
	}
	return 0;
}

Measured memory_bytes: 34852
#include <iostream>
#include <queue>
using namespace std;
typedef long long ll;

int main()
{
    int n, m;
    cin >> n >> m;
    ll a[100002];
    priority_queue<int> que;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        que.push(a[i]);
    }
    for(int i = 0; i < m; i++){
        int lar = que.top();
        que.pop();
        que.push(lar / 2);
    }
    ll ans = 0;
    while(que.size()){
        ans += que.top();
        que.pop();
    }
    cout << ans << endl;
}

Measured memory_bytes: 1528
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        long W[] = new long[N];
        long sum = 0L;
        for(int i=0; i<N; i++) {
            W[i]=sc.nextLong();
            sum+=W[i];
        }
        long result = Long.MAX_VALUE;
        long tmpsum = 0L;
        for(int i=0; i<N; i++) {
            tmpsum+=W[i];
            long tmpdiff = Math.abs(tmpsum - (sum-tmpsum));
            if(tmpdiff<=result) result=tmpdiff;
        }
        System.out.println(result);
    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
  int dp[100005],h[100005];
  int n;
  cin >> n;
  for(int i=0; i<n; i++) cin >> h[i];
  
  dp[0] = 0;
  dp[1] = abs(h[1] - h[0]);

  for(int i=2; i<n; i++){
    dp[i] = min(abs(h[i] - h[i-1]) + dp[i-1] , abs(h[i] - h[i-2]) + dp[i-2]);
  }

  cout << dp[n-1] << endl;
  return 0;
}


Measured memory_bytes: 1024
#include<iostream>
using namespace std;
int main(){
  int n;
  cin>>n;
  int a[n];int sum=0;
  for(int i=0;i<n;i++){
    cin>>a[i];
    sum+=a[i];
  }
  int p=sum/n;
  int ans1=0,ans2=0;
  for(int i=0;i<n;i++){
    ans1+=((a[i]-p)*(a[i]-p));
    ans2+=((a[i]-(p+1))*(a[i]-(p+1)));
  }
  cout<<min(ans1,ans2)<<endl;
  return 0;
}


Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var n, k int
	fmt.Scan(&n, &k)

	max := (n - 2) * (n - 1) / 2
	if k > max {
		fmt.Println(-1)
		return
	}

	fmt.Println(n - 1 + max - k)

	for i := 1; i <= n-1; i++ {
		fmt.Println(n, i)
	}

	cnt := max
	for i := 1; i < n; i++ {
		for j := i + 1; j < n; j++ {
			if cnt == k {
				return
			}

			cnt--
			fmt.Println(i, j)
		}
	}
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <deque>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;

int main()
{
	string S;
	cin >> S;

	auto ans = 0;
	for (auto i = 0; i < (int)S.length(); ++i)
	{
		auto temp = 0;
		for (auto j = i; j < (int)S.length(); ++j)
		{
			if (S[j] == 'A' || S[j] == 'C' || S[j] == 'G' || S[j] == 'T')
			{
				++temp;
			}
			else
			{
				break;
			}
		}
		ans = max(ans, temp);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
# import heapq


def solve(N: int, M: int, K: int, A: "List[int]", B: "List[int]"):

    sumA = [0]
    sum = 0
    for a in A:
        sum += a
        sumA.append(sum)
    sumB = [0]
    sum = 0
    for b in B:
        sum += b
        sumB.append(sum)
    
    
    # print(sumA)
    # print(sumB)
    # True - ng - ok - False
    def is_ok(mid: int, i):
        # 判定する条件
        if mid < 0:
            return True
        elif mid >= M + 1:
            return False
        # print(i, mid, sumA[i] + sumB[mid])
        return sumA[i] + sumB[mid] <= K

    def binSearch(ok: int, ng: int, i):
        # print(ok, ng)
        while abs(ok - ng) > 1:
            mid = (ok + ng) // 2
            if is_ok(mid, i):
                ok = mid
            else:
                ng = mid
            # print(ok, ng)
        return ok

    ans = 0
    for i in range(N + 1):
        j = binSearch(-1, M + 1, i)
        # print("a", i, j)
        if j < 0:
            break
        ans = max(ans, i + j)

    print(ans)
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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
    M = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    B = [int(next(tokens)) for _ in range(M)]  # type: "List[int]"
    solve(N, M, K, A, B)

if __name__ == '__main__':
    main()


Measured memory_bytes: 128324
import java.util.Scanner;

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();
		// 文字列の入力
		// String s = sc.next();
		// 出力
		// System.out11.println((a+b+c) + " " + s);

		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();
		int w = sc.nextInt();

		int[][] matrix = new int[h][w];



		for (int i = 0; i < h; i++) {
			String str = sc.next();
			for (int j = 0; j < w; j++) {
				matrix[i][j] = str.charAt(j);
			}
		}



		boolean result = true;

		for (int i = 0; i < h; i++) {
			for (int j =0; j < w; j++) {
				if (matrix[i][j] == '#') {
					if (!check4(matrix, i, j, h, w)) {
						result = false;
						break;
					}
				}
			}
		}


		System.out.println(result ? "Yes" : "No");


	}

	private static boolean check4(int[][] mat, int i, int j, int h, int w) {

		boolean result = true;
		if (i == 0 && j == 0) {
			result = (mat[i+1][j] == '#' || mat[i][j+1] == '#');
		} else if (i ==0 && j == w-1) {
			result = (mat[i][j-1] == '#' || mat[i+1][j] == '#');
		} else if (i == h-1 && j==0) {
			result = (mat[i-1][j] == '#' || mat[i][j+1] == '#');
		} else if (i==h-1 && j==w-1) {
			result = (mat[i][j-1] == '#' || mat[i-1][j] == '#');
		} else if (i==0) {
			result = (mat[i][j-1] == '#' || mat[i][j+1] == '#' || mat[i+1][j] == '#');
		} else if (j==0) {
			result = (mat[i-1][j] == '#' || mat[i+1][j] == '#' || mat[i][j+1] == '#');
		} else if (i==h-1) {
			result = (mat[i][j-1] == '#' || mat[i][j+1] == '#' || mat[i-1][j] == '#');
		} else if (j == w-1) {
			result = (mat[i-1][j] == '#' || mat[i+1][j] == '#' || mat[i][j-1] == '#');
		} else {
			result = (mat[i][j-1] == '#' || mat[i][j+1] == '#' || mat[i+1][j] == '#' || mat[i-1][j] == '#');
		}

		return result;

	}

}

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

constexpr int inf = 0x3f3f3f3f;
constexpr ll linf = 0x3f3f3f3f3f3f3f3fLL;

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

    int x[5];
    for (int i = 0; i < 5; i++) cin >> x[i];
    for (int i = 0; i < 5; i++) {
        if (x[i] == 0) cout << i + 1 << endl;
    }

    return 0;
}


Measured memory_bytes: 3608
S = input()
K = int(input())

S = list(S)
i = 0
while(K>0):
  if i == len(S)-1:
    S[i] = chr(((ord(S[i])-97)+K)%26+97)
    K = 0
  else:
    a = 26-(ord(S[i])-97)
    if a != 26 and K >= a:
      S[i] = 'a'
      K -= a
  i += 1
print(''.join(S))


Measured memory_bytes: 4152
#include <bits/stdc++.h>
 
#define rep(i, n) for (ll i=0;i<(n); i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define ALL(x) (x).begin(),(x).end()
 
using namespace std;
//using ll=long long;
typedef long long ll;
typedef pair<ll, ll> pi;

ll h,w;
ll ans;
//vector<char> masu;




int main(){
  ll n,m,x;
  cin >>n>>m>>x;

  vector<ll> c(n);
  vector<vector<ll> > a(n, vector<ll>(m));
  rep(i, n){
    cin >> c[i];
    rep(j, m) cin >> a[i][j];
  }
  vector<ll> rikaido(m, 0);

  ll cost ;
  ll ans = 1e18;
  rep(i, 1<<n){
    rep(j,m) rikaido[j]=0;
    cost = 0;
    rep(j, n){
      if(i>>j&1){
	//cerr<<"i"<<i<<endl;
	cost += c[j];
	rep(k, m){
	  rikaido[k] += a[j][k];
	}
      } 
    }
    bool flug = true;
    rep(k, m){
      //cerr<<rikaido[k]<<endl;
      if(rikaido[k]<x) flug = false;
    }
    if(flug) chmin(ans, cost);
    
  }

  if(ans >=1e18) ans = -1;
  cout << ans<<endl;

  
  
}


Measured memory_bytes: 3636
#include<iostream>
#include<string>
using namespace std;
int main(){
    int a, b;
    string op;
    a = 0,b = 0; 
    while(true){
        cin >> a >> op >> b;
        if     (op == "+")
            cout << a + b << endl;
        else if(op == "-")
            cout << a - b << endl;
        else if(op == "*")
            cout << a * b << endl;
        else if(op == "/")
            cout << a / b << endl;
        else
            break;
    } 
}


Measured memory_bytes: 3160
import re
n,k=[int(i) for i in input().split()]
r,s,p=[int(i) for i in input().split()]
order=input()

ans=0
ans+=order.count("r")*p
ans+=order.count("s")*r
ans+=order.count("p")*s

for i in range(k):
    part=order[i::k]
    check=re.findall(r'r+r', part)
    if check:
        for hand in check:
            ans-=(len(hand)//2)*p
    check=re.findall(r's+s', part)
    if check:
        for hand in check:
            ans-=(len(hand)//2)*r
    check=re.findall(r'p+p', part)
    if check:
        for hand in check:
            ans-=(len(hand)//2)*s

print(ans)   
    

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

class Program
{
    static void Main(string[] args)
    {
        int retValue = 0;
        int n = int.Parse(Console.ReadLine());
        var listD = new List<int>();

        // スペース区切りの整数の入力
        string[] input = Console.ReadLine().Split(' ');
        for (int i = 0; i < n; i++)
        {
            listD.Add(int.Parse(input[i]));
        }

        var list = listD.OrderBy(r => r).ToArray();

        int half = n / 2;
        int l1 = list[half - 1];
        int l2 = list[half];

        retValue = l2 - l1;

        //出力
        Console.WriteLine(retValue);
    }
}

Measured memory_bytes: 22496
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <map>
#include <algorithm>
#include <queue>
#include <tuple>
#include <functional>

#define PI 3.14159265359
#define INF 100100100100100100
#define rep(i,n) for(int i = 0; i < n; i++)
#define rep2(i,a,n) for(int i = a; i < n; i++)
#define in(a) cin >> a
#define out(a) cout << a << endl

using namespace std;

typedef long long ll;
typedef pair<ll, ll> PLL;

int main() 
{
    int dish[5];
    int ans = 100100100;
    rep(i,5) { cin >> dish[i]; } 

    vector<int> index(5);
    rep(i,5) { index[i] = i; }
    
    do{
        int time = 0;
        rep(i,4) { 
            if(dish[index[i]] % 10 != 0) {
                time += 10 * (dish[index[i]] / 10 + 1);
            } else {
                time += dish[index[i]];
            }
        } 
        time += dish[index[4]];
        ans = min(time, ans);
    }while(next_permutation(index.begin(), index.end()));

    cout << ans << endl;

    return 0;
}




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

#define ll long long

int main(){
    ll n;
    cin>>n;
    ll arr[n+1];
    ll count = 0;
    for (ll i=0;i<=n;++i){
        if (i%15==0 || i%3==0 || i%5==0){
            arr[i]=0;
        }
        else{
            arr[i]=i;
        }
    }
    for (auto x : arr){
        count+=x;
    }
    cout<<count;
}

Measured memory_bytes: 11428
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      int[] a = new int[n];
      double sum = 0;
      for(int i = 0;i < n;i++){
        a[i]=sc.nextInt();
        sum+=(double)a[i];
      }
      sum/=(double)n;
      int f = 0;
      double min = 10000000;
      for(int i = n-1;i >=0;i--){
      	double k = (double)Math.abs(sum-(double)a[i]);
        min = Math.min(min,k);
        if(min==k)f = i;
      }
      System.out.println(f);
    }
}


Measured memory_bytes: 22612
from collections import deque

H, W = map(int, input().split())
C0, C1 = map(int, input().split())
D0, D1 = map(int, input().split())

C0 -= 1
C1 -= 1
D0 -= 1
D1 -= 1

map = []
for _ in range(H):
    map.append(input())

inf = 1000000000

q = deque([[C0, C1]])
dist = [[inf for a in range(1100)]for b in range(1100)]
dist[C0][C1] = 0

walk0 = [1, 0, -1, 0]
walk1 = [0, 1, 0, -1]


while q:
    now = q.popleft()
    d = dist[now[0]][now[1]]

    for v in range(4):
        wnxt0 = now[0] + walk0[v]
        wnxt1 = now[1] + walk1[v]

        if wnxt0 < 0 or wnxt0 > H - 1: continue
        elif wnxt1 < 0 or wnxt1 > W - 1: continue
        elif map[wnxt0][wnxt1] == "#": continue
        elif dist[wnxt0][wnxt1] <= d: continue
        
        dist[wnxt0][wnxt1] = d
        q.appendleft([wnxt0, wnxt1])

    for x in [-2, -1, 0, 1, 2]:
        for y in [-2, -1, 0, 1, 2]:
            mnxt0 = now[0] + y
            mnxt1 = now[1] + x

            if mnxt0 < 0 or mnxt0 > H - 1: continue
            elif mnxt1 < 0 or mnxt1 > W - 1: continue
            elif map[mnxt0][mnxt1] == "#": continue
            elif dist[mnxt0][mnxt1] <= d + 1: continue

            dist[mnxt0][mnxt1] = d + 1
            q.append([mnxt0, mnxt1])

ans = dist[D0][D1]

if ans == inf:
    ans = -1

print(ans)

Measured memory_bytes: 114264
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define REP(i, d, n) for(int i=(d); i<(n); ++i)
#define all(v) v.begin(), v.end()
using ll = long long;
using P = pair<int, int>;

int main() {

    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n){
        cin >> a[i];
    }
    
    ll sum = 0;
    rep(i, n){
        if(i&1){
            sum -= a[i];
        }
        else{
            sum += a[i];
        }
    }
    ll x = sum / 2;
    vector<int> ans(n);
    ans[0] = x;
    REP(i, 1, n){
        ans[i] = a[i-1] - ans[i-1];
    }
    
    rep(i, n){
        cout << ans[i] * 2 << endl;
    }

    return 0;
}

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

using namespace std;

#define MOD 1000000007
typedef long long ll;

ll power(ll a, ll b)
{
    if (b == 0) return 1;
    ll t = power(a, b/2) % MOD;
    t = t*t % MOD;
    if (b % 2 == 0) return t;
    return t*a % MOD;
}

int main()
{
    ll n, m;
    cin>>m>>n;
    cout<<power(m, n)<<"\n";
    return 0;
}

Measured memory_bytes: 3096
using System;
using System.IO;
using System.Linq;

class Solve{
    static void Main(string[] args){
        var N = int.Parse(Console.ReadLine());
        var A = Console.ReadLine().Split().Select(x => Convert.ToString(int.Parse(x), 2)).ToArray();
        var answer = int.MaxValue;
        for (int i = 0; i < N; i++){
            var len = A[i].Length;
            var count = 0;
            for (int j = 1; j <= len; j++){
                if (A[i][^j] != '0') break;
                count++;}
            answer = count < answer ? count : answer;}
        var writer = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false};
        Console.SetOut(writer);
        Console.WriteLine(answer);
        Console.Out.Flush();}}

Measured memory_bytes: 28556
#include <iostream>
#include <vector>
using namespace std;
int main(void){
  int N;
  cin >> N;
  
  vector<vector<int>>candy(2,vector<int>(N,0));
  for(int i=0;i<2;i++){
    for(int j=0;j<N;j++){
      cin >> candy[i][j];
    }
  }
  
  int ans = 0;
  for(int i=0;i<N;i++){
    int candy_sum = 0;
    for(int j=0;j<i + 1;j++){
      candy_sum += candy[0][j];
    }
    for(int j=i;j<N;j++){
      candy_sum += candy[1][j];
    }
    if(ans < candy_sum)
      ans = candy_sum;
  }
  
  cout << ans << endl;
  
  return 0;
}

    

Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
const long long MOD = 1000000007;
const long long inf = 1ll<<61;
const double eps = 0.000000000001;
typedef pair<int, int> P;
typedef pair<P,int> PP;
struct edge { int to; int to2; int cost; };
int x[100006], y[100006];
int xn[100006], YN[100006];
int par[100006], rnk[100006];
vector<int>G[114514];
void init(int n) {
	rep(i, n) {
		par[i] = i; rnk[i] = 0;
	}
}
int find(int x) {
	if (par[x] == x)return x;
	return par[x] = find(par[x]);
}
void unite(int x, int y) {
	x = find(x);
	y = find(y);
	if (x == y)return;
	if (rnk[x] < rnk[y])par[x] = y;
	else {
		par[y] = x;
		if (rnk[x] == rnk[y])rnk[x]++;
	}
}
signed main() {
	int n; cin >> n;
	rep(i, n)cin >> x[i] >> y[i];
	vector<PP>X, Y;
	rep(i, n) {
		X.push_back(PP(P(x[i], y[i]), i));
		Y.push_back(PP(P(y[i], x[i]), i));
	}
	sort(X.begin(), X.end());
	sort(Y.begin(), Y.end());
	init(n);
	rep(i, n - 1) {
		if (X[i].first.first == X[i + 1].first.first) {
			unite(X[i].second, X[i + 1].second);
		}
		if (Y[i].first.first == Y[i + 1].first.first) {
			unite(Y[i].second, Y[i + 1].second);
		}
	}
	rep(i, n) {
		G[find(i)].push_back(i);
	}
	int ans = 0;
	rep(i, n) {
		if (G[i].size()) {
			//int mnx = inf, mxx = -inf, mny = inf, mxy = -inf;
			set<int>sx, sy;
			rep(j, G[i].size()) {
				int t = G[i][j];
				sx.insert(x[t]);
				sy.insert(y[t]);
			}
			int res = sx.size()*sy.size();
			res -= G[i].size();
			ans += res;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 18468
#include<iostream>

using namespace std;

main(){
  int k,a,b,f=0;
  cin>>k>>a>>b;
  for(int i=a; i<=b;i++){
    if(i%k == 0){
      f=1;
      break;
    }
  }
  if(f == 1) cout<<"OK"<<endl;
  else cout<<"NG"<<endl;
  return 0;
}

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

typedef long long ll;

int main()
{
	ios_base::sync_with_stdio(false);
	ll n;
	cin>>n;
	set<ll> st;
	
	for(ll i=2;i*i<=n;i++)
	{
		if(n%i==0)
		{
			st.insert(i);
			st.insert(n/i);
		}
	}
	ll ans = n-1;
	for(auto i:st)
	{
		ans = min(i + (n/i) - 2 ,ans);
	}
	cout<<ans;
}

Measured memory_bytes: 512