akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>
#include<set>

//#define DIV 1000000007

using namespace std;
using ll = long long;
using ldb = long double;

typedef struct {
    int to = 0;
    vector<ll> dis;
    ll loop = 1;
}node_t;
vector<node_t> node;

int main() {
    ll N, K; cin >> N >> K;
    node=vector<node_t>(N+1);
    for (int i = 1; i <= N; i++) {
        cin >> node[i].to;
    }

    int lst = 0;
    queue<int> q;
    //node[1].dis.push_back(0); 
    q.push(1);
    for (int i = 1; i <= N + 1; i++) {
        int x = q.front();
        q.pop();
        int y = node[x].to;
        node[y].dis.push_back(i);
        q.push(y);
        int sz = node[y].dis.size();
        if (sz == 2) {
            node[y].loop = node[y].dis[sz - 1] - node[y].dis[sz - 2];
            if (lst == 0) lst = y;
        }
    }
    //cout << lst << endl;
    if (K <= node[lst].dis[0]) {
        for (int i = 1; i <= N; i++) {
            if (node[i].dis.size() <= 0) continue;
            if (K == node[i].dis[0]) {
                cout << i << endl;
                break;
            }
        }
    }

    else {
        ll more = (K - node[lst].dis[0])%node[lst].loop;
        queue<int> L;
        L.push(lst);
        for (ll i = 1; i <= more; i++) {
            int x = L.front();
            L.pop();
            L.push(node[x].to);
        }
        cout << L.front() << endl;
    }
}


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

int main(){
  string str;
  cin >> str;
  
  int count = 0;
  for (int i=0; i<3; i++){
    if (str.at(i)=='R') count++;
  }
  
  if (str == "RSR")
    count = 1;
  
  cout << count;
}

Measured memory_bytes: 3624
import collections
n=int(input())
arr=list(map(int,input().split()))
cnt=collections.Counter(arr) #各数Akの個数を数える
total=0
for key in cnt.keys():
  total+=cnt[key]*(cnt[key]-1)//2 #各数Akについて、cnt[Ak]個から異なる2個のボールを取り出す場合の数を事前に計算する
for i in range(n): #各iについて上記の方法で答えを求める
  print(total-cnt[arr[i]] + 1)

Measured memory_bytes: 26780
n=int(input())
A=list(map(int,input().split()))
def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a
L=[0]
R=[0]
for i in range(n):
    L.append(gcd(L[i],A[i]))
    R.append(gcd(R[i],A[-(i+1)]))
R=R[::-1]

ans=[]
for i in range(n):
    ans.append(gcd(L[i],R[i+1]))
print(max(ans))


Measured memory_bytes: 14060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int H, W; cin >> H >> W;
  vector<vector<char>> S(H, vector<char> (W)), T(H, vector<char> (W));
  for(int i = 0; i < H; i++) {
    for(int j = 0; j < S.at(i).size(); j++) {
      cin >> S.at(i).at(j);
    }
  }
  for(int i = 0; i < H; i++) {
    for(int j = 0; j < S.at(i).size(); j++) {
      int t = 0;
      if(S.at(i).at(j) == '.') {
        if(i > 0 && S.at(i - 1).at(j) == '#') t++;
        if(i > 0 && j > 0 && S.at(i - 1).at(j - 1) == '#') t++;
        if(i > 0 && j < W - 1 && S.at(i - 1).at(j + 1) == '#') t++;
        if(j > 0 && S.at(i).at(j - 1) == '#') t++;
        if(j < W - 1 && S.at(i).at(j + 1) == '#') t++;
        if(i < H - 1 && j > 0 && S.at(i + 1).at(j - 1) == '#') t++;
        if(i < H - 1 && S.at(i + 1).at(j) == '#') t++;
        if(i < H - 1 && j < W - 1 && S.at(i + 1).at(j + 1) == '#') t++;
        cout << t;
      } else cout << '#';
    }
    cout << endl;
  }
}

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

int main() {
  int h, n, a, s = 0;
  cin >> h >> n;
  for(int i = 0; i < n; i++) {
    cin >> a;
    s += a;
  }
  if(s >= h)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  string S;
  cin >> S;
  
  ll L = S.size();
  if(L == 1) {
    cout << S << "\n";
    return 0;
  }
  stack<ll> s;  
  ll sum = 0;
  
  for(ll bits = 0; bits < (1<<(L-1)); bits++) { //bitが1なら+を挿入する
    while(!(s.empty())) s.pop(); //stackを空にする
    s.push(S[0]-'0');
    
    for(ll i = 0; i < L-1; i++) {
      if((bits>>i) & 1) {
        if(s.size() == 1)
          s.push(S[i+1]-'0');
        else {
          ll x = s.top(); s.pop();
          ll y = s.top(); s.pop();
          s.push(x+y);
          s.push(S[i+1]-'0');
        }
      }
      else {
        ll z = s.top(); s.pop();
        z = z*10 + (S[i+1]-'0');
        s.push(z);
      }
    }
    if(s.size() == 1) {
      sum += s.top(); s.pop();
    }
    else {
      sum += s.top(); s.pop();
      sum += s.top(); s.pop();      
    }  
  }
  cout << sum << "\n";
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#define val first
#define pos second
using namespace std;
typedef pair<int,int> P;

inline int read(){
	char ch = getchar(); int x = 0; while (ch < '0' || '9' < ch) ch = getchar();
	while ('0' <= ch && ch <= '9') { x = x*10 + ch-'0'; ch = getchar(); } return x;
}
const int maxn = 300009;
int a[maxn], f[maxn], n;
priority_queue<int, vector<int>, greater<int> > L;
priority_queue<P, vector<P>, greater<P> > R;
long long Lsum, Rsum, best;
P tmp;

int main(){
	n = read();
	for (int i=1; i<=3*n; i++) a[i] = read();
	for (int i=1; i<=n; i++) { Lsum += a[i]; L.push(a[i]); }
	for (int i=n+1; i<=3*n; i++) R.push(make_pair(a[i], i));
	for (int i=1; i<=n; i++){
		tmp = R.top(); R.pop();
		Rsum += tmp.val; f[tmp.pos] = 1;
	}
	best = Lsum - Rsum;
	for (int i=n+1; i<=2*n; i++){
		if (L.top() < a[i]){ Lsum += a[i]-L.top(); L.pop(); L.push(a[i]); }
		if (f[i]){
			Rsum -= a[i];
			while (1){
				tmp = R.top(); R.pop();
				if (tmp.pos <= i) continue;
				Rsum += tmp.val; f[tmp.pos] = 1;
				break;
			}
		}
		best = max(best, Lsum-Rsum);
	}
	printf("%lld\n", best);
	return 0;
}

Measured memory_bytes: 4336
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();

        int temp = N;
        int count = 0;
        while(temp > 0) {
            if (count == 0) {
                temp -= K;
            }
            else {
                temp -= (K-1);
            }
                count ++;
        }

        System.out.println(count);
    }
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,k;
  cin>>n>>k;
  char ch[n];
  cin>>ch;
  for(int i =0;i<n;i++)
  {
    if(i==(k-1))
    ch[i] = tolower(ch[i]);
  }
  cout<<ch<<endl;
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REP(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  ll H, W, N;
  cin >> H >> W >> N;
  vector<ll> A(N), B(N);
  int dx[] = {-1, 0, 1, -1, 0, 1, -1, 0, 1};
  int dy[] = {-1, -1, -1, 0, 0, 0, 1, 1, 1};
  map<pair<int, int>, ll> mp;
  rep(i, N) {
    cin >> A[i] >> B[i];
    A[i]--; B[i]--;
    rep(j, 9) {
      int x = A[i] + dx[j];
      int y = B[i] + dy[j];
      if(x < 1 || x > H-2 || y < 1 || y > W-2) continue;
      auto p = make_pair(x, y);
      if(mp.count(p))
        mp[p]++;
      else
        mp[p] = 1;
    }
  }
  vector<ll> ans(10);
  for(auto m: mp)
    ans[m.second]++;
  ans[0] = (H-2) * (W-2) - accumulate(all(ans), 0LL);
  for(ll a: ans)
    cout << a << endl;
  return 0;
}



Measured memory_bytes: 58112
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
constexpr int N = 1010;
int id[N][N];
int vis[N * N];
int dist[N * N];
vector<int> g[N * N];
int dfs (int cur) {
  int res = 0;
  for (int nxt : g[cur]) {
    if (vis[nxt] == 1) {
      cout << -1 << endl;
      exit(0);
    } else if (vis[nxt] == 2) {
      res = max(res, dist[nxt]);
    } else {
      vis[nxt] = 1;
      res = max(res, dfs (nxt));
    }
  }
  vis[cur] = 2;
  return dist[cur] = res + 1;
}
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  int n;
  cin >> n;
  int c = 0;
  for (int i = 0; i < n; i++) for (int j = i + 1; j < n; j++) id[i][j] = id[j][i] = c++;
  vector<vector<int>> in(n, vector<int>(n - 1));
  for (int i = 0; i < n; i++) for (int j = 0; j < n - 1; j++) {
    cin >> in[i][j];
    in[i][j]--;
    in[i][j] = id[i][in[i][j]];
  }
  for (int i = 0; i < n; i++) for (int j = 0; j + 1 < n - 1; j++) g[in[i][j]].push_back(in[i][j + 1]);
  int ans = 0;
  for (int i = 0; i < c; i++) {
    ans = max(ans, dfs(i));
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 55680
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.util.InputMismatchException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int m = in.nextInt();

            String s = in.nextString();
            String t = in.nextString();

            int g = (int) Euclid.gcd(n, m);
            for (int i = 0; i < g; i++) {
                if (s.charAt(i * (n / g)) != t.charAt(i * (m / g))) {
                    out.println(-1);
                    return;
                }
            }

            out.println((long) n * m / g);
        }

    }

    static class Euclid {
        public static long gcd(long a, long b) {
            return a == 0 ? b : gcd(b % a, a);
        }

    }

    static class InputReader {
        private BufferedReader br;
        private StringTokenizer st;

        public InputReader(InputStream inputStream) {
            br = new BufferedReader(new InputStreamReader(inputStream));
            st = new StringTokenizer("");
        }

        public String nextString() {
            while (!st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine(), " ");
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(nextString());
        }

    }
}



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

using namespace std;

typedef long long ll;
const int MAXN = 1e5 + 1;
int n, pos;
ll num[MAXN],ans[MAXN];
ll an;

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

	cin >> n;

	for (int i = 0; i < n; i++) {
		cin >> num[i];
		if (i % 2 == 0) an += num[i];
		else an -= num[i];
	}

	ans[0] = an;
	int pos = 1;

	for (int i = 0; i < n; i++) {
		ll cur = num[i] * 2LL;
		ans[pos] = cur - an;
		an = ans[pos];
		pos = (pos + 1) % n;
	}

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

	cout << "\n";

	
	return 0;
}

Measured memory_bytes: 2944
#include "bits/stdc++.h"
using namespace std;
int main() {
	long long N;
	cin >> N;
	vector<long long>A(N), B(N);
	for (long long i = 0; i < N; i++) {
		cin >> A.at(i);
	}
	long long ans = 0, num = 0;
	vector<long long>sum;
	for (long long i = 0; i < N; i++) {
		cin >> B.at(i);
		if (A.at(i) >= B.at(i)) sum.push_back(A.at(i) - B.at(i));
		else {
			num += (B.at(i) - A.at(i));
			ans++;
		}
	}
	if (sum.size() == N) {
		cout << 0 << endl;
		return 0;
	}
	sort(sum.begin(), sum.end(), greater<int>());
	for (long long i = 0; i < sum.size(); i++) {
		if (sum.at(i) >= num) {
			cout << ans + 1 << endl;
			return 0;
		}
		else {
			num -= sum.at(i);
			ans++;
		}
	}
	cout << -1 << endl;
 }

Measured memory_bytes: 2936
#include <iostream>
#include <vector>
#include <string>

typedef long long ll;
using namespace std;


int main()
{
    int h, w;
    cin >> h >> w;
    vector<string> c(h);
     for(int i = 0; i < h; i++){
        cin >> c[i];
    }

    for(int i = 0; i < h; i++){
        for(int j = 0; j < 2; j++){
            cout << c[i] << endl;
        }
    }
    
    return 0;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author SimplyDivine
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader in = new FastReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, FastReader in, PrintWriter out) {
            int n = in.nextInt();
            int s[] = new int[n + 1];
            for (int i = 1; i <= n; i++) {
                s[i] = in.nextInt();
            }
            Arrays.sort(s);
            int sum = 0;
            for (int i = 1; i <= n; i++) {
                sum += s[i];
            }
            if (sum % 10 != 0) {
                out.println(sum);
                return;
            }
            for (int i = 0; i < s.length; i++) {
                while (sum % 10 == 0 && s[i] % 10 != 0) {
                    sum -= s[i];
                }

            }
          if(sum%10==0)
            out.println(0);
          else out.println(sum);
        }

    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader(InputStream i) {
            br = new BufferedReader(new
                    InputStreamReader(i));
        }

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

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

    }
}



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


public class Test
{	
    public static void Main()
	{
	    int[] n = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
        if(n[0] <= 8 && n[1] <= 8) Console.WriteLine("Yay!");
        else Console.WriteLine(":(");
	} 
}

Measured memory_bytes: 13268
import kotlin.math.max

fun main(args: Array<String>) {
    val (n, k) = readIntList()
    val p = readIntList()

    val s = MutableList(n) { 0.0 }
    s[0] = (1 + p[0]) * 0.5
    for (i in 1 until n) {
        s[i] = s[i - 1] + (1 + p[i]) * 0.5
    }
    var ans = s[k - 1]
    for (i in k until n) {
        ans = max(ans, s[i] - s[i - k])
    }
    println(ans)
}

// Tools
fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntList() = readLine()!!.split(" ").map(String::toInt)

Measured memory_bytes: 65612
N = int(input())
S = list(input())
L = [1]
cumsumL = [1]
res = 1
rvisited = 0
mod = 10 ** 9 + 7
class Factorial:
  def __init__(self, n, mod):
    self.f=[1]
    for i in range(1, n + 1):
      self.f.append(self.f[-1] * i % mod)
    self.i=[pow(self.f[-1], mod - 2, mod)]
    for i in range(1, n + 1)[: : -1]:
      self.i.append(self.i[-1] * i % mod)
    self.i.reverse()
  def factorial(self, i):
    return self.f[i]
  def ifactorial(self, i):
    return self.i[i]
  def combi(self, n, k):
    return self.f[n] * self.i[n - k] % mod * self.i[k] % mod
f = Factorial(N, mod)
if S[0] == "W" or S[-1] == "W":
  print(0)
  exit(0)
for i in range(1, 2 * N):
  if S[i - 1] == S[i]:
    L.append((L[i - 1] + 1 )% 2)
  else:
    L.append(L[i - 1])
if sum(L) != N:
  print(0)
  exit(0)
for i in range(1, 2 * N):
  cumsumL.append(cumsumL[i - 1] + L[i])
for i in range(1, 2 * N):
  if L[i] == 0:
    res *= cumsumL[i] - rvisited % mod
    res %= mod
    rvisited += 1
print(f.factorial(N) * res % mod)

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

using namespace std;

using ll = long long;

#define ALL(A) A.begin(),A.end()

void ALLIN1_NUMBER(vector<ll>& V)
{
    for(auto& x : V)
    {
        cin >> x;
    }
}

template<class T>
void OUT0(T N)
{
    cout << N << endl;
}

static const double pi = acos(-1.0);

double Cos(double D)
{
    return cos(pi/180 * D);
}

map<char,ll> Char_Counter(string s)
{
    map<char,ll> ret;
    for(auto x : s)
    {
        ret[x]++;
    }
    return ret;
}

void ALLOUT_MAP(map<char,ll> Map)
{
    for(auto x : Map)
    {
        cout << x.first << ' ' << x.second << endl; 
    }
}

void Ans(string s, map<char,ll> number_of_chars)
{
    ll ans = s.size()*(s.size()-1)/2;
    for(auto x : number_of_chars)
    {
        ans -= x.second*(x.second-1)/2;
    }
    OUT0(ans+1);
}

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

    map<char,ll> number_of_chars = Char_Counter(s);

    Ans(s,number_of_chars);

    return 0;
}

Measured memory_bytes: 772
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define fi first
#define se second
#define si size()
#define bk back()
#define popb pop_back()
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define endl "\n"
#define lb lower_bound
#define ub upper_bound
#define emp empty()
#define beg begin()
#define en end()
#define ump unordered_map
#define forl(i,a,n) for(int i=a;i<n;i++)
#define rfor(i,n,a) for(int i=n;i>=a;i--)
#define fore(i,a,n) for(int i=a;i<=n;i++)
#define len length()
double doINF = 1.0/0.0 ;
ostream_iterator <int> outp(cout," ");
inline ll modadd(ll n,ll m,ll mod){
    ll sum = ((n+m)%mod+mod)%mod;
    return sum;
} 
inline ll modsub(ll n,ll m, ll mod){
    ll diff = ((n-m+mod)%mod+mod)%mod;
    return diff;
}
inline ll modpro(ll n,ll m,ll mod){
    ll pro = ((n*m)%mod+mod)%mod;
    return pro;
}
inline ll pow(int x,int y){
    ll res = 1;
    while (y > 0) {
        if (y & 1)
            res = res * x;
        y = y >> 1;
        x = x * x;
    }
    return res;
}
inline ll powmod(ll x,ll y,ll mod){
    ll res = 1;
    while (y > 0) {
        if (y & 1)
            res = modpro(res , x,mod);
        y = y >> 1;
        x = modpro(x , x,mod);
    }
    return res;
}
//ll min(ll a, ll b){
//    if(a>b){
//        return b;
//    }
//    return a;
//}
// 
//ll max(ll a, ll b){
//    if(a>b){
//        return a;
//    }
//    return b;
//}
bool pairdec(const pair<int,int> &a,  
               const pair<int,int> &b) 
{ 		if(a.fi!=b.fi)
       	return (a.fi> b.fi);
		else return a.se>b.se;  
} 
ll power(ll x, ll y, ll mod) 
{ 
    ll res = 1; 
    x = x%mod; 
    while (y > 0) { 
        if (y & 1) 
            res = (res * x) % mod; 
  
        y = y >> 1;
        x = (x * x) % mod; 
    } 
    return res; 
} 
ll modInverse(ll a, ll mod) 
{ 
    return  powmod(a, mod - 2, mod); 
} 
ll modFact(ll n, ll mod) 
{ 
    if (n >=mod) 
        return 0; 
  
    ll result = 1; 
    for (ll i = 1; i <= n; i++) 
        result = (result * i) %mod; 
  
    return result; 
} 
//cout<<setprecision(9)<<fixed<<sum<<endl; --- precision for double numbers
//copy(v.beg,v.en,outp);
const int pN=1e9 +7;
int main()
{	
	
	int n;
	cin>>n;
	int arr[n];
	forl(i,0,n) cin>>arr[i];
	int dp[n];
	forl(i,0,n) dp[i]=pN;
	dp[0]=0;
	forl(j,1,n)
	{
		dp[j]=min(abs(arr[j]-arr[max(j-1,0)])+dp[max(j-1,0)],abs(arr[j]-arr[max(j-2,0)])+dp[max(j-2,0)]);
	}
	cout<<dp[n-1]<<endl;
	
}

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

using ll = long long;

ll mod = 1e9+7;

int main()
{
    ll n,k;
    cin>>n>>k;
    ll ans=0;
    for(ll i=k;i<n+2;i++)
    {
        long long min = i* (i - 1) / 2;
        long long max = i * n - i * (i - 1) / 2;
        ans += (max - min+1);
       // ans=ans%mod;
    }
    cout<<ans%mod<<endl;
}


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

public class AtCoderC
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());

        int[] ds = new int[n];
        {
            var line = Console.ReadLine();
            var words = line.Split(' ');
            for (int i = 0; i < n; i++)
            {
                ds[i] = int.Parse(words[i]);
            }
        }

        Array.Sort(ds);
        int left = ds[n / 2 - 1];
        int right = ds[n / 2];

        Console.WriteLine(right - left);
    }
}

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

using namespace std;

int solve(const std::vector<int64_t>& ds) {
  if (ds.front() >= 0) {
    return 0;
  }

  int ret = 0;
  int64_t move = 0;
  for (auto const d : ds) {
    if (d >= 0) {
      break;
    }
    move += -d;
    ret++;
  }

  for (auto it = ds.rbegin(); it != ds.rend(); ++it) {
    auto const d = *it;
    move -= d;
    ret++;
    if (move < 0) {
      break;
    }
  }

  return ret;
}

int main() {
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  int n;
  std::cin >> n;
  std::vector<int64_t> as(n);
  std::vector<int64_t> bs(n);

  int64_t aSum = 0;
  for (auto& a : as) {
    std::cin >> a;
    aSum += a;
  }
  int64_t bSum = 0;
  for (auto& b : bs) {
    std::cin >> b;
    bSum += b;
  }

  if (bSum > aSum) {
    std::cout << -1 << std::endl;
    return 0;
  }

  std::vector<int64_t> ds(n);
  for (int i = 0; i < n; ++i) {
    ds[i] = as[i] - bs[i];
  }
  std::sort(ds.begin(), ds.end());
  std::cout << solve(ds) << std::endl;
  return 0;
}


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

struct node{
  unsigned int key;
  struct node *next;
  struct node *prev;
};

typedef struct node * NodePointer;

NodePointer nil;

NodePointer listSearch(int);
void init(void);
void printList(void);
void deleteNode(NodePointer);
void deleteFirst(void);
void deleteLast(void);
void delete(int);
void insert(int);

int main(){
  int key,n,i;
  int size=0;
  char com[20];
  int np=0,nd=0;
  scanf("%d",&n);
  init();
  for(i=0;i<n;i++){
    scanf("%s%d",com,&key);
    if(com[0]=='i'){
      insert(key);
      np++;
      size++;
    }
    else if(com[0]=='d'){
      if(strlen(com)>6){
	if(com[6]=='F')deleteFirst();
	else if(com[6]=='L')deleteLast();
      }
      
      else{
	delete(key);
	nd++; 
      }
      size--;
    }
  }
  
  printList();
  return 0;
}

NodePointer listSearch(int key){
  NodePointer n;

  for(n=nil->next;n!=nil;n=n->next){
    if(n->key==key) return n;
  }

  return nil;
}

void init(){
  nil = malloc(sizeof(struct node));
  nil->next=nil;
  nil->prev=nil;
}

void printList(){
  NodePointer cur=nil->next;
  int isf=1;
  while(1){
    if(cur==nil)break;
    if(isf==0)printf(" ");
    printf("%d",cur->key);
    cur=cur->next;
    isf=0;
  }
  printf("\n");
}

void deleteNode(NodePointer t){
  t->prev->next=t->next;
  t->next->prev=t->prev;
  free(t);
}

void deleteFirst(){
  NodePointer t=nil->next;
  if(t==nil) return;
  deleteNode(t);
}

void deleteLast(){
  NodePointer n=nil->prev;

  if(n==nil) return;
  deleteNode(n);
}

void delete(int key){
  NodePointer n;
  n=listSearch(key);
  if(n==nil) return;
  else deleteNode(n);
}

void insert(int key){
  NodePointer x;
  x=malloc(sizeof(struct node));
  x->key=key;
  x->next=nil->next;
  nil->next->prev=x;
  x->prev=nil;
  nil->next=x;
}



Measured memory_bytes: 32940
import sys

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

X.sort()

Y=[0]*(M-1)
for i in range(M-1):
    Y[i]=X[i+1]-X[i]

Y=sorted(Y)[:max(0,M-N)]
print(sum(Y))

Measured memory_bytes: 86300
#include <bits/stdc++.h> 
using namespace std; 
  
// Function to return the probability when 
// number of heads is greater than the number of tails 
long double Probability(long double p[], int n) 
{ 
  
    // Declaring the DP table 
    long double dp[n + 1][n + 1]; 
    memset(dp, 0.000000000, sizeof(dp)); 
  
    // Base case 
    dp[0][0] = 1.000000000; 
  
    // Iterating for every coin 
    for (int i = 1; i <= n; i += 1) { 
  
        // j represents the numbers of heads 
        for (int j = 0; j <= i; j += 1) { 
  
            // If number of heads is equal to zero 
            // there there is only one possiblity 
            if (j == 0) 
                dp[i][j] = dp[i - 1][j] 
                           * (1.00000000 - p[i]); 
            else
                dp[i][j] = dp[i - 1][j] 
                               * (1.000000000 - p[i]) 
                           + dp[i - 1][j - 1] * p[i]; 
        } 
    } 
  
    long double ans = 0.000000000; 
  
    // When the number of heads is greater than (n+1)/2 
    // it means that heads are greater than tails as 
    // no of tails + no of heads is equal to n for 
    // any permuation of heads and tails 
    for (int i = (n + 1) / 2; i <= n; i += 1) 
        ans += dp[n][i]; 
  
    return ans; 
} 
  
// Driver Code 
int main() 
{ 
  	int N;
    cin >> N;
  	
    // 1 based indexing 
    long double p[N+1] ; 
    p[0]=0.000000000;
    for(int i=1;i<=N;i++){
      cin >> p[i];
      p[i]+=0.000000000;
    }
  
    // Number of coins 
    //int n = sizeof(p) / sizeof(p[0]) - 1; 
  
    // Function call 
    cout << setprecision(50)<<Probability(p, N); 
  
    return 0; 
} 

Measured memory_bytes: 144336
#include<cstdio>
#include<cstring>
#include<string>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<vector>
#define mp make_pair
#define pb push_back
using namespace std;
typedef long long LL;
typedef pair<int,int> pa;
const int N=3E5+10;
int n,A,B,t[N];
//vector<int>e[N];
int Write[20],WRI;
void judge(){freopen(".in","r",stdin);freopen(".out","w",stdout);}
int read(){int d=0,f=1; char c=getchar(); while (c<'0'||c>'9'){if (c=='-') f=-1; c=getchar();} while (c>='0'&&c<='9') d=d*10+c-48,c=getchar(); return d*f;}
void write(int x){if (!x){putchar('0'); return;}if (x<0) putchar('-'),x=-x;for (WRI=1;x;x/=10,WRI++) Write[WRI]=x%10;for (int i=WRI-1;i;i--) putchar((char)(Write[i]+48));}
int main()
{
	//judge();
	n=read(); A=read(); B=read();
	if (1LL*A*B<n||A+B>n+1) {puts("-1"); return 0;}
	int tmp=1;
	for (int i=n-A+1;i<=n;i++)
	{
		printf("%d ",i);
		int len=0;
		for (int j=1;j<=B-1;j++)
		{
			if (tmp==n-A+1) break;
			len++;
			t[len]=tmp;
			tmp++;
		}
		for (int j=len;j>=1;j--) printf("%d ",t[j]);
	}
	return 0;
}

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

// #include <bit>
// #include <bitset>
// #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;

int main()
{
	ll n, m, k;
	cin >> n >> m >> k;
	vector<ll> a(n);
	vector<ll> b(m);

	vector<ll> a_sum(n + 1);
	vector<ll> b_sum(m + 1);

	ll ans = 0;

	rep(i, n)
	{
		int val;
		cin >> val;
		a[i] = val;
	}
	rep(i, m)
	{
		int val;
		cin >> val;
		b[i] = val;
	}

	rep(i, n)
	{
		a_sum[i + 1] = a_sum[i] + a[i];
	}

	rep(i, m)
	{
		b_sum[i + 1] = b_sum[i] + b[i];
	}

	rep(i, n + 1)
	{
		ll target = k - a_sum[i];
		if (target < 0)
			continue;

		ll l = 0;
		ll r = b.size() + 1;

		while (r - l > 1)
		{
			ll middle = l + (r - l) / 2;
			if (b_sum[middle] <= target)
			{
				l = middle;
			}
			else
			{
				r = middle;
			}
		}

		// if (index >= 0 && index < b.size())
		// 	index++;
		ans = max(ans, i + l);
	}
	cout << ans << endl;
}
//g++ -std=c++17 -g main.cpp -o mai	n


Measured memory_bytes: 9532
#include <iostream> // cout, endl, cin
#include <iomanip>
#include <string>        // string, to_string, stoi
#include <vector>        // vector
#include <algorithm>     // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility>       // pair, make_pair
#include <tuple>         // tuple, make_tuple
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <map>           // map
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <deque>         // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset>        // bitset
#include <cctype>        // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <numeric>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
const int INF = 1001001001;
const int BG = 1000000007;

int main()
{
    string S;
    cin >> S;
    int cnt = 0;
    rep(i, S.size() / 2)
    {
        if (S[i] != S[S.size() - 1 - i])
        {
            cnt++;
        }
    }
    cout << cnt << endl;
}


Measured memory_bytes: 256
n, m = map(int, input().split())
matrix_a = [[0 for i in range(m)]for j in range(n)]
matrix_b = [0]*m
matrix_c = [0]*n

for i in range(n):
    matrix_a[i] = list(map(int, input().split()))

for i in range(m):
    matrix_b[i] = int(input())
        
for i in range(n):
    for j in range(m):
        matrix_c[i] += matrix_a[i][j] * matrix_b[j] 
    print(matrix_c[i])


Measured memory_bytes: 6032
import java.util.*;

class UnionFind {
	int[] roots;
	int[] sameSetCnt;
	
	public UnionFind(int N) {
		roots = new int[N];
		sameSetCnt = new int[N];
		for(int i = 0; i < N; ++i) {
			roots[i] = i;
			sameSetCnt[i] = 1;
		}
	}
	
	int getRoot(int x) {
		if(roots[x] == x) return x;
		else return roots[x] = getRoot(roots[x]);
	}
	
	boolean isSameSet(int x, int y) {
		return getRoot(x) == getRoot(y);
	}
	
	void unite(int x, int y) {
		int rx = getRoot(x);
		int ry = getRoot(y);
		if(rx == ry) return;
		
		if(sameSetCnt[rx] < sameSetCnt[ry]) {
			int tmp = rx;
			rx = ry;
			ry = tmp;
		}
		sameSetCnt[rx] += sameSetCnt[ry];
		roots[ry] = rx;
	}
	
	int getSameSetNum(int i) {
		return sameSetCnt[getRoot(i)];
	}
}

public class Main {
	static Scanner sc = new Scanner(System.in);
	static int h = 0;
	static int w = 0;
	static char[][] grids = null;
	static boolean[][] hasVisited = null;
	static int[][] bnum = null;
	static UnionFind uf = null;
	static int[] dy = {-1, 1, 0, 0};
	static int[] dx = {0, 0, -1, 1};
	
	public static void main(String[] args) {
		h = sc.nextInt();
		w = sc.nextInt();
		grids = new char[h][w];
		hasVisited = new boolean[h][w];
		for(int i = 0; i < h; ++i) grids[i] = sc.next().toCharArray();
		
		uf = new UnionFind(h * w);
		bnum = new int[h][w];
		// 黒と白が隣接する各箇所に辺を張る
		for(int y = 0; y < h; ++y) {
			for(int x = 0; x < w; ++x) {
				dfs(y, x);
			}
		}
		
		// 各連結成分について選ぶ組み合わせの数を足していく
		long ans = 0;
		for(int i = 0; i < h * w; ++i) {
			if(uf.getRoot(i) == i) {
				int bn = bnum[i / w][i - i / w * w];
				int wn = uf.getSameSetNum(i) - bn;
				ans += 1L * bn * wn;
			}
		}
		System.out.println(ans);
	}
	
	static boolean isOutside(int y, int x) {
		return y < 0 || h <= y || x < 0 || w <= x;
	}
	
	static void dfs(int sy, int sx) {
		// 訪問済みなら何もせず終了
		if(hasVisited[sy][sx]) return;
		
		// 自身のマスに訪問済みの印をつける
		hasVisited[sy][sx] = true;
		
		// 自身のマスの色
		char self = grids[sy][sx];
		
		// 黒マスならば連結成分の根のカウントを1増やす
		if(self == '#') {
			int ufRootIndex = uf.getRoot(w * sy + sx);
			++bnum[ufRootIndex / w][ufRootIndex - ufRootIndex / w * w];
		}
		
		// 上下左右のマスを見る
		for(int i = 0; i < 4; ++i) {
			int oy = sy + dy[i];
			int ox = sx + dx[i];
			
			// 範囲外ならばスキップ
			if(isOutside(oy, ox)) continue;
			
			// 相手のマスの色
			char other = grids[oy][ox];
			if(self != other) {
				// 自身と相手の色が異なれば辺を張る
				int selfIndex = w * sy + sx;
				int otherIndex = w * oy + ox;
				uf.unite(selfIndex, otherIndex);
				
				// 相手のマスに関してDFS
				dfs(oy, ox);
			}
		}
	}
}

Measured memory_bytes: 64880
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<vector>
#define ll long long
#define maxn 700010
inline ll read()
{
	ll x=0; char c=getchar(),f=1;
	for(;c<'0'||'9'<c;c=getchar())if(c=='-')f=-1;
	for(;'0'<=c&&c<='9';c=getchar())x=x*10+c-'0';
	return x*f;
}
inline void write(ll x)
{
	static int buf[20],len; len=0;
	if(x<0)x=-x,putchar('-');
	for(;x;x/=10)buf[len++]=x%10;
	if(!len)putchar('0');
	else while(len)putchar(buf[--len]+'0');
}
inline void writeln(ll x){write(x); putchar('\n');}
inline void writesp(ll x){write(x); putchar(' ');}
int a[maxn],cnt[maxn];
int n;
int main()
{
	n=read();
	for(int i=1;i<=n;i++)
		a[i]=read(),++cnt[a[i]];
	int mx=0;
	for(int i=1;i<=n;i++)
		mx=std::max(mx,a[i]);
	for(int i=1;2*i<mx;i++)
		if(cnt[i]){
			puts("Impossible"); return 0;
		}
	for(int i=(mx+1)/2;i<=mx;i++)
		cnt[i]-=2;
	if(mx%2==0)++cnt[mx/2];
	if(cnt[(mx+1)/2]){
		puts("Impossible"); return 0;
	}
	for(int i=(mx+1)/2;i<=mx;i++)
		if(cnt[i]<0){
			puts("Impossible"); return 0;
		}
	puts("Possible");
	return 0;
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef pair<int,int> P;
const int    INF=(int)1e9;
const int    MOD=(int)1e9+7;
const double EPS=(double)1e-10;
struct Accelerate_Cin{
    Accelerate_Cin(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);
    };
};



int main(){
  lint N,A[100005];
  cin>>N;
  map<lint,lint>map;
  for(lint t=0;t<N;t++){
    cin>>A[t];
    map[A[t]]++;
  }

  lint cont=0;
  for(auto itr=map.begin();itr!=map.end();itr++){
    if((*itr).second%2==1)cont++;
  }

  cout<<cont<<endl;
  return 0;
}


Measured memory_bytes: 7296
#define _GLIBCXX_DEBUG
#include <iostream>
#include <vector>
using namespace std;

int main(){
  int N, W;
  cin >> N >> W;
  vector<int> ans(2*(N), 0);
  ans[0] = W;
  for(int i = 1; i <= W/2; ++i){
    ++ans[i+1];
  }
  for(int i = W/2+1; i < W; ++i){
    for(int j = 3; j*i <= N; ++j){
      ++ans[j*i-W+1];
      --ans[j*i-W+1+W-i];
    }
  }
  for(int i = 1; i <= N-W+2; ++i){
    ans[i] += ans[i-1];
  }
  cout << ans[1];
  for(int i = 2; i <= N-W+1; ++i) cout << " " << ans[i];
  cout << endl;
  return 0;
}



Measured memory_bytes: 3620
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner stdIn = new Scanner(System.in);
		int N = stdIn.nextInt();
		int M = stdIn.nextInt();
		int[] A = new int[M];
		for(int a = 0; a < M; a++){
			A[a] = stdIn.nextInt();
			N = N - A[a];
		}
		if(N >= 0){
			System.out.println(N);
		}
		else{
			System.out.println(-1);
		}
		stdIn.close();
	}
}

Measured memory_bytes: 46128
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>

#define _CRT_SECURE_NO_WARNINGS
#define TLong long long 

// fact(n)
int fact(int n){
	if(n == 1)	return 1;
	else return (n * fact(n - 1));
}

// combination(n,r)
int combination(int n, int r){

	if(r == 0 || r == n)	return 1;
	else if(r == 1)	return n;
	return (combination(n - 1, r - 1) + combination(n - 1, r));
}

// gcd(a,b)
int gcd(int a,int b){
	int ret;
	ret = (b == 0) ? a : gcd(b, a % b);
	return ret;
}

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

// qsort(array, size, sizeof(int),comp);
int comp(const int *a,const int *b){
	return (*a - *b);
}

// append(array,*size,addNum)
void append(int *array,int *size,int num){
	realloc(array, sizeof(int) * (*size + 1));
	array[(*size)] = num;
	++(*size);
}

// pop(array,*size) & nongetpop(array,*size)
int pop(int *array,int *size){
	int temp = array[(*size - 1)];
	realloc(array,sizeof(int) * (*size - 1));
	--(*size);
	return temp;
}

void nongetpop(int *array,int *size){
	realloc(array,sizeof(int) * (*size - 1));
	--(*size);
}

int main(int argc, char const *argv[]){
	char s1[12],s2[12],s3[12];
	scanf("%s %s %s",s1,s2,s3);
	printf("%c%c%c\n", (s1[0] - 0x20),(s2[0] - 0x20),(s3[0] - 0x20));
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, a, n) for(long long i = (a); i < (n); i++)
using namespace std;
using ll = long long;
constexpr ll NIL = -1;

struct Node { ll parent, left, right, depth, height; };
Node T[100005];

ll set_height(ll u){
    Node& cur = T[u];
    ll h1 = 0, h2 = 0;
    if(cur.right != NIL) h1 = set_height(cur.right) + 1;
    if(cur.left != NIL) h2 = set_height(cur.left) + 1;
    return cur.height = max(h1, h2);
}

void set_depth(ll u, ll d){
    Node& cur = T[u];
    cur.depth = d;
    if(cur.right != NIL) set_depth(cur.right , d + 1);
    if(cur.left != NIL) set_depth(cur.left, d + 1);
}

ll get_bro(ll id){
    Node& cur = T[id];
    ll bro = NIL;
    if(cur.parent != NIL){
        Node& curp = T[cur.parent];
        if(curp.left == id && curp.right != NIL) bro = curp.right;
        else if(curp.right == id && curp.left != NIL) bro = curp.left;
    }
    return bro;
}

int get_deg(ll id){
    int deg = 0;
    if(T[id].left != NIL) deg++;
    if(T[id].right != NIL) deg++;
    return deg;
}

void print(ll id){
    Node cur = T[id];
    ll bro = get_bro(id);
    ll deg = get_deg(id);
    printf("node %ld: parent = %ld, sibling = %ld, degree = %d, depth = %ld, height = %ld, ", id, cur.parent, bro, deg, cur.depth, cur.height);

    if(cur.parent == NIL) cout << "root\n";
    else if(!deg) cout << "leaf\n";
    else cout << "internal node\n";
    return;
}

int main(){
    ll n; cin >> n;
    memset(T, -1, 100005*sizeof(Node));

    rep(i, 0, n){
        ll id, left, right;
        cin >> id >> left >> right;
        T[id].left = left;
        T[id].right = right;
        T[left].parent = id;
        T[right].parent = id;
    }

    ll root;
    rep(i, 0, n) if(T[i].parent == NIL) root = i;

    set_height(root);
    set_depth(root, 0);

    rep(i, 0, n) print(i);

    return 0;
}


Measured memory_bytes: 7140
import math
import copy
import sys
import fractions
import numpy as np
from functools import reduce
import statistics


# ===FUNCTION===

def getInputInt():
    inputNum = int(input())
    return inputNum


def getInputListInt():
    outputData = []
    inputData = input().split()
    outputData = [int(n) for n in inputData]

    return outputData


def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList


def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList


# ===CODE===

def gettwice(n):
    counter = 0
    flg = True
    while (flg):
        if n % 2 == 1:
            flg = False
        else:
            n = n / 2
            counter += 1

    return counter


k = getInputInt()
data = getInputListInt()

ans = 0

for i in range(len(data)):
    ans += gettwice(data[i])

print(ans)


Measured memory_bytes: 23040
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int D;
vector<int> c(26+1);
vector<vector<int>> s;

int compute_score(vector<int> t) {
    vector<vector<int>> last(D+1,vector<int>(26+1,0));
    int ans = 0;
    for(int d = 1; d <= D; d++) {
        last[d][t[d]] = d;
        ans += s[d][t[d]];
        for(int i = 1; i <= 26; i++) {
            if(i == t[d]) continue;
            last[d][i] = last[d-1][i];
            ans -= c[i]*(d-last[d][i]);
        }
        cout << ans << endl;
    }
    return 0;
}

int main(){
    ios::sync_with_stdio(false);
    cin >> D;
    s.assign(D+1,vector<int>(26+1,0));
    for(int i = 1; i <= 26; i++) cin >> c[i];    
    for(int d = 1; d <= D; d++) for(int i = 1; i <= 26; i++) cin >> s[d][i];
    vector<int> t(D+1);
    for(int d = 1; d <= D; d++) cin >> t[d];
    compute_score(t);
}


Measured memory_bytes: 3736
mod = 10**9+7
import sys
from collections import Counter, defaultdict, deque
from itertools import product, permutations, combinations
from itertools import accumulate
from operator import itemgetter
from bisect import bisect_left,bisect
from heapq import heappop,heappush
from math import ceil,floor
from copy import deepcopy
from heapq import heappop,heappush,heapify
import heapq


# l = ['a', 'a', 'a', 'a', 'b', 'c', 'c']
# c = Counter(l)

# d = defaultdict(int)

sys.setrecursionlimit(10 ** 6)

int1 = lambda x: int(x) - 1

# リストの要素を改行を挟んで表示する
p2D = lambda x: print(*x, sep="\n")
# 入力を整数に変換して受け取る
def II(): return int(sys.stdin.readline())

def MI(): return map(int, sys.stdin.readline().split())
def MI1(): return map(int1, sys.stdin.readline().split())

# 入力全てを整数に変換したものの配列を受け取る
# def LI(): return list(map(int, sys.stdin.readline().split()))
# 入力全てを整数に変換して1引いたものの配列を受け取る
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LI(): return list(map(lambda x:int(x), sys.stdin.readline().split()))
def HI(): return list(map(lambda x:int(x)*(-1), sys.stdin.readline().split()))




k = II()
a,b = MI()
t=None
for i in range(a,min(b+1, a+k+1)):
	if i%k==0:
		t = 1
		print('OK')
		break
		sys.exit()
if t is None:
	print('NG')





























Measured memory_bytes: 69048
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define fi first
#define se second
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;

bool dfs(ll a, ll b, ll c, ll k){
    if(a < b && b < c){
        return true;
    }
    bool flag = false;
    if(k > 0){
        flag |= dfs(a, b*2, c, k-1);
        flag |= dfs(a, b, c*2, k-1);
    }
    return flag;
}

int main(){
    ll A,B,C,K;
    //string S;
    cin >> A >> B >> C >> K;
    
    cout << (dfs(A,B,C,K)?"Yes":"No") << endl;
}


Measured memory_bytes: 3628
#define NDEBUG
NDEBUG


#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cstring>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <memory>
#include <queue>
#include <random>


using namespace std;

template<class T>
using vec = std::vector<T>;


#define FOR(i, n) for (int i = 0; i < (n); ++i)


// TC_REMOVE_BEGIN
/// caide keep
bool __hack = std::ios::sync_with_stdio(false);
/// caide keep
auto __hack1 = cin.tie(nullptr);
// TC_REMOVE_END


// Section with adoption of array and vector algorithms.


//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//
//template <class T> using StdTree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;


namespace template_util {
    

    constexpr int bytecount(uint64_t x) {
        return x ? 1 + bytecount(x >> 8) : 0;
    }

    template<int N>
    struct bytetype {
        
    };

    
    /// caide keep
    template<uint64_t N>
    struct minimal_uint : bytetype<bytecount(N)> {
    };
}


template<class T>
T next(istream& in) {
    T ret;
    in >> ret;
    return ret;
}


bool check(int n, const vec<int>& ds) {
  while (n) {
    int d = n % 10;
    n /= 10;
    if (ds[d]) return false;
  }
  return true;
}

void solve(istream& in, ostream& out) {
  auto n = next<int>(in);
  auto k = next<int>(in);
  vec<int> ds(10);
  FOR(i, k) {
    auto d = next<int>(in);
    ds[d] = 1;
  }
  for (;;++n) {
    if (check(n, ds)) {
      out << n << "\n";
      return;
    }
  }
}

//#include <fstream>


int main() {
//  ifstream fin("bridges.in");
//  ofstream fout("bridges.out");
    solve(cin, cout);
//  solve(fin, fout);
    return 0;
}



Measured memory_bytes: 256
def calc(x):
    if x%10 == 3:
        return True
    
    else: return False
    

n = int(input())
res = []
i = 1

while True:
    x = i
    x1 = 0
    x2 = 0
    x3 = 0
    if x%3 == 0:
        res.append(i)
    
    elif x%10 == 3:
        res.append(i)
    
    else:
        if x > 10 and x < 100:
            x1 = x//10
            if calc(x1) == True:
                res.append(i)
        
        if x > 100 and x < 1000:
            x1 = x//10
            x2 = x1//10
            if calc(x1) == True or calc(x2) == True:
                res.append(i)
  
        if x > 1000 and x < 10000:
            x1 = x//10
            x2 = x1//10
            x3 = x2//10
            if calc(x1) == True or calc(x2) == True or calc(x3) == True:
                res.append(i)
     
    i += 1
    if i > n:
        break

print("", " ".join(map(str, res)))


Measured memory_bytes: 6108
package main

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

func main() {
	nextReader = NewScanner()
	line1 := nextInt()
	a := line1[0]
	b := line1[1]
	k := line1[2]

	var arr []int
	n := max([]int{a, b}...)
	for i := n; i >= 1; i-- {
		if a%i == 0 && b%i == 0 {
			arr = append(arr, i)
		}
	}
	fmt.Println(arr[k-1])
}

// ------ Mathライブラリ ---------------------------------//
func max(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r < a[i] {
			r = a[i]
		}
	}
	return r
}

func maxIdx(a ...int) int {
	r := a[0]
	index := 0
	for i := 0; i < len(a); i++ {
		if r < a[i] {
			r = a[i]
			index = i
		}
	}
	return index
}

func min(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r > a[i] {
			r = a[i]
		}
	}
	return r
}

func minIdx(a ...int) int {
	r := a[0]
	index := 0
	for i := 0; i < len(a); i++ {
		if r > a[i] {
			r = a[i]
			index = i
		}
	}
	return index
}

func sum(a []int) (r int) {
	for i := range a {
		r += a[i]
	}
	return r
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

// ------ Mathライブラリ ---------------------------------//

// ----- 標準入力用の関数 ----------------------------------//
var nextReader func() []string

func NewScanner() func() []string {
	r := bufio.NewScanner(os.Stdin)
	r.Buffer(make([]byte, 1024), int(1e+11))
	return func() []string {
		r.Scan()
		return strings.Fields(r.Text())
	}
}

func nextString() []string {
	return nextReader()
}

func nextInt() []int {
	var intArray []int
	strArray := nextReader()
	for _, v := range strArray {
		i, _ := strconv.Atoi(v)
		intArray = append(intArray, i)
	}
	return intArray
}

func nextFloat64() []float64 {
	var floatArray []float64
	strArray := nextReader()
	for _, v := range strArray {
		f, _ := strconv.ParseFloat(v, 64)
		floatArray = append(floatArray, f)
	}
	return floatArray
}

// ------ 標準入力用の関数 ---------------------------------//

// ------ あまり使わない -----------------------------------//
func nextInt64() []int64 {
	var int64Array []int64
	strArray := nextReader()
	for _, v := range strArray {
		i, _ := strconv.ParseInt(v, 10, 64)
		int64Array = append(int64Array, i)
	}
	return int64Array
}

// ------ あまり使わない -----------------------------------//


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

int main(){
    int A,B,K;
    cin >> A >> B >> K;
    int count = 0;
    int i;
    for(i = 100; i > 0; i--){
        if(A % i == 0 && B % i == 0) count+= 1;
        if(count == K)break;
    }
    cout << i << endl;
}


Measured memory_bytes: 256