akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<int>> data(M,vector<int>(4,1));
  for (int i = 0; i < M; i++) {
    data[i][2] = i;
    cin >> data[i][0] >> data[i][1];
  }
  
  sort(data.begin(), data.end());
  swap(data[0][0],data[0][2]);
  for (int i = 1; i < M; i++) {
    if (data[i][0] == data[i-1][2]) data[i][3] = data[i-1][3]+1;
    swap(data[i][0],data[i][2]);
  }
  
  sort(data.begin(),data.end());
  for (auto v : data) {
    cout << setfill('0') << right << setw(6) << v[2];
    cout << setfill('0') << right << setw(6) << v[3] << endl;
  }
}

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

int main()
{
	double r;
	double s,l;
	scanf("%lf",&r);
	s=M_PI*r*r;
	l=2*M_PI*r;
	printf("%.6lf %.6lf\n",s,l);
	return 0;
}

Measured memory_bytes: 652
#include <cstdio>

int mp[105][105];
int nx,ny;
int H,W;
void go()
{
	if(nx&1)
		ny? ny--: nx++;
	else
		ny<W-1? ny++: nx++;
}

int main()
{
	scanf("%d%d",&H,&W);
	int n;scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		int ai;scanf("%d",&ai);
		for(int j=1;j<=ai;j++,go())
			mp[nx][ny]=i;
	}
	for(int i=0;i<H;i++)
		for(int j=0;j<W;j++)
			printf("%d%c",mp[i][j],j==W-1?'\n':' ');
}


Measured memory_bytes: 256
# coding: utf-8
n = int(input())
data = [int(i) for i in input().split()]

for i in range(n):
    v = data[i]
    j = i - 1
    while j >= 0 and data[j] > v:
        data[j+1] = data[j]
        j -= 1
    data[j+1] = v
    print(*data)

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

vector<vector<int>> G;
int ans;

void dfs(int v, vector<int> V) {
  V.at(v) = 1;
  if (accumulate(V.begin(), V.end(), 0) == V.size()) {
    ans++;
    return;
  }
  for (auto g : G.at(v)) if (!V.at(g)) dfs(g, V);
}

int main() {
  int N, M;
  cin >> N >> M;
  G.resize(N);
  for (int i = 0, a, b; cin >> a >> b; i++) {
    G.at(--a).push_back(--b), G.at(b).push_back(a);
  }
  vector<int> V(N);
  dfs(0, V);
  cout << ans << "\n";
}

Measured memory_bytes: 256
s = input()

forward = s[:2]
backward = s[2:]
def check(s):
    if 0<int(s)<=12:
        return True
    else:
        return False

if check(forward) and check(backward):
    print('AMBIGUOUS')
elif check(forward):
    print('MMYY')
elif check(backward):
    print('YYMM')
else:
    print('NA')
    

Measured memory_bytes: 3060
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
using namespace std;
typedef long long ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define in(x) cin >> x
#define out(str) cout << str << endl

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; }

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

int N,ans=0,temp;

int main(){
    cin>>N;
    rep(i,N){
        cin>>temp;
        ans=gcd(temp,ans);
    }
    out(ans);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;cin>>N;
  vector<int>a(100);
  for(int i=0;i<N;i++)cin>>a[i];
  int sum=0;
  for(int i=0;i<N;i++)sum+=a[i];
  int dis=10000000;
  int ans=-1;
  for(int i=0;i<N;i++){
    if(abs(sum-a[i]*N)<dis){
      ans=i;
      dis=abs(sum-a[i]*N);
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#define F first
#define S second

using namespace std;

typedef long long ll;

const ll M = 998244353;

ll n, base = 1;
pair<ll, ll> a[200005];
ll d[200005];
ll e[200005];
ll s[200005];
ll b[540005];

void f(ll p, ll q)
{
    p += base;
    b[p] = q;
    p /= 2;
    while(p >= 1)
    {
        b[p] = max(b[p * 2], b[p * 2 + 1]);
        p /= 2;
    }
}

ll g(ll p, ll q)
{
    p += base;
    q += base;
    ll re = 0;
    while(p < q)
    {
        if(p % 2 == 1) re = max(re, b[p]), p++;
        if(q % 2 == 0) re = max(re, b[q]), q--;
        p /= 2;
        q /= 2;
    }
    if(p == q) re = max(re, b[p]);
    return re;
}

int main()
{
    scanf("%lld", &n);
    for(ll i = 0; i < n; i++)
    {
        scanf("%lld%lld", &a[i].F, &a[i].S);
    }
    while(base < n) base *= 2;
    sort(a, a + n);
    for(ll i = 0; i < base * 2; i++) b[i] = 0;
    d[n - 1] = 1;
    e[n - 1] = n - 1;
    f(n - 1, n - 1);
    s[n - 1] = 1;
    for(ll i = n - 2; i >= 0; i--)
    {
        ll t = lower_bound(a, a + n, make_pair(a[i].F + a[i].S, (ll)-4e18)) - a;
        t--;
        e[i] = max(i, g(i + 1, t));
        d[i] = s[e[i] + 1] + 1;
        d[i] %= M;
        s[i] = d[i] + s[i + 1];
        s[i] %= M;
        f(i, e[i]);
    }
    s[0]++;
    s[0] %= M;
    cout<<s[0]<<endl;
    return 0;
}


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

int main() {

  // int型の2次元配列(3×4要素の)の宣言
  vector<vector<int>> data(3, vector<int>(3));

  // 入力 (2重ループを用いる)
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> data.at(i).at(j);
    }
  }
  int n ;
  cin >> n ;
  for (int i =0; i<n ; i++){
    int t ;
    cin >> t ;
     for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
     if (t ==data.at(i).at(j)){
     data.at(i).at(j)=0; }
      }
     }
  }
  
 for  (int i =0; i<3 ; i++){
  if ( data.at(i).at(0)+data.at(i).at(1)+data.at(i).at(2)==0){
     cout << "Yes" <<endl;
    return 0;}
  if ( data.at(0).at(i)+data.at(1).at(i)+data.at(2).at(i)==0){
     cout << "Yes" <<endl;
    return 0;}
  }
 if ( data.at(0).at(0)+data.at(1).at(1)+data.at(2).at(2)==0||data.at(0).at(2)+data.at(1).at(1)+data.at(2).at(0)==0){
     cout << "Yes" <<endl;
    return 0;}
  else{
    cout << "No" << endl;
  } 
}

Measured memory_bytes: 256
//-------------------------------------------
//-               Train Fare                -
//-                                         -
//-       autumn_eel niha katemasen!        -
//-------------------------------------------

#include<iostream>
#include<functional>
#include<queue>
#include<deque>
#include<vector>
#include<algorithm>
using namespace std;

void reader(int *x) {
	int k = getchar_unlocked(); *x = k - '0';
	while (true) {
		k = getchar_unlocked();
		if (k < '0') break;
		*x = ((*x) << 1) + ((*x) << 3) + k - '0';
	}
}
inline void writeln(int x) {
	int s = 0; char f[7];
	while (x) {
		f[s++] = x % 10;
		x /= 10;
	}
	if (!s) f[s++] = 0;
	while (s--) putchar_unlocked(f[s] + '0');
	putchar_unlocked('\n');
}
#pragma warning(disable:4996)
int n, m, q, a[200003], b[200003], c[200003], d[200003], e[100003], f[100003], g[100003];
int h1[100003], h2[100003], dist[100003], E[200003];
vector<pair<int, int> > z[100003]; vector<int> x[100003];
vector<int>D[100003];
int main() {
	reader(&n); reader(&m); reader(&q);
	fill(d, d + m + 1, 1 << 30);
	for (int i = 1; i <= m; i++) { reader(&a[i]), reader(&b[i]); f[a[i]]++; f[b[i]]++; }
	for (int i = 1; i <= q; i++) reader(&c[i]), d[c[i]] = i;
	for (int i = 1; i <= n; i++) { x[i].resize(f[i]); }
	for (int i = 1; i <= m; i++) {
		x[a[i]][g[a[i]]] = b[i]; g[a[i]]++;
		x[b[i]][g[b[i]]] = a[i]; g[b[i]]++;
	}
	fill(dist, dist + n + 1, -1); dist[1] = 0;
	queue<int> Q1; Q1.emplace(1);
	while (!Q1.empty()) {
		int a1 = Q1.front(); Q1.pop();
		for (int i : x[a1]) {
			if (dist[i] == -1) {
				dist[i] = dist[a1] + 1;
				Q1.emplace(i);
			}
		}
	}
	for (int i = 1; i <= m; i++) {
		if (dist[a[i]] > dist[b[i]]) h1[a[i]]++;
		if (dist[b[i]] > dist[a[i]]) h1[b[i]]++;
	}
	for (int i = 1; i <= n; i++)z[i].resize(h1[i]);
	for (int i = 1; i <= m; i++) {
		if (dist[a[i]] > dist[b[i]]) { z[a[i]][h2[a[i]]] = make_pair(b[i], d[i]); h2[a[i]]++; }
		if (dist[b[i]] > dist[a[i]]) { z[b[i]][h2[b[i]]] = make_pair(a[i], d[i]); h2[b[i]]++; }
	}
	for (int i = 1; i <= n; i++) D[dist[i]].push_back(i);
	e[1] = (1 << 30);
	for (int i = 1; i < n; i++) {
		for (int j : D[i]) {
			for (pair<int, int>k : z[j]) {
				e[j] = max(e[j], min(e[k.first], k.second));
			}
		}
	}
	for (int i = 2; i <= n; i++) {
		if (e[i] < 300000) E[e[i]]++;
	}
	for (int i = 1; i <= q; i++) {
		E[i] += E[i - 1];
		writeln(E[i]);
	}
	return 0;
}

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


def main(input, print):
    n = int(input())
    a = list(map(int, input().split()))
    a.sort(reverse=True)
    ans = 0
    cnt = 0
    for i in range(n):
        lim = 1 if i == 0 else 2
        for j in range(lim):
            if cnt < n-1:
                ans += a[i]
                cnt += 1
    print(ans)


if __name__ == '__main__':
    main(sys.stdin.readline, print)


Measured memory_bytes: 105548
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_1_A&lang=jp

#include <iostream>
#include <cmath>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

#define ll long long
#define vi vector<int>
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

#define MAX_V 100005
#define INF 1e9

int V, E, r, s, t, cost, d[MAX_V];

struct edge {ll to, cost;};
typedef pair<int, int> P; //(最短距離, 頂点番号)

vector<edge> G[MAX_V];

void dijkstra(int s){
    priority_queue<P, vector<P>, greater<P> > que;
    fill(d, d+V, INF);
    d[s] = 0;
    que.push(P(0,s));

    while(!que.empty()){
        P p = que.top(); que.pop();
        int v = p.second;
        if(d[v] < p.first) continue;
        for(int i = 0; i < G[v].size(); i++){
            edge e = G[v][i];
            if(d[e.to] > d[v] + e.cost){
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to], e.to));
            }
        }
    }
}

void solve(){
    dijkstra(r);

    rep(i,V){
        if(d[i] == INF)
            cout << "INF" << endl;
        else
            cout << d[i] << endl;
    }
}

int main(){
    cin >> V >> E >> r;

    rep(i,E){
        cin >> s >> t >> cost;
        edge buff;
        buff.to = t, buff.cost = cost;
        G[s].push_back(buff);
    }

    solve();
}



Measured memory_bytes: 18084
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<stdio.h>
#include<queue>
#include <climits>
#include <map>
#include <set>
const int mod = 1e9 + 7;
const long long INF = 1LL << 60;
using namespace std;
typedef long long ll;

int main()
{
    ll r,d,x;
    cin >> r >> d >> x;
    for(int i = 0; i < 10; i++){
        x = r * x - d;
        cout << x << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = int64_t;
using P = pair<ll, ll>;
template <class T>
using V = vector<T>;

template <class T>
T gcd(T a, T b) {
  if (a % b == 0) {
    return b;
  } else {
    return gcd(b, a % b);
  }
}

template <typename T>
set<T> factorize(T num) {
  set<T> result;
  T d = 2;
  while (d * d <= num) {
    if (num % d == 0) {
      num /= d;
      result.insert(d);
    } else {
      d++;
    }
  }
  if (num != 1) result.insert(num);
  return result;
}

int main() {
  ll n, k;
  cin >> n >> k;
  V<ll> a(n);
  rep(i, n) cin >> a[i];

  sort(a.begin(), a.end());
  if (k > a.back()) {
    cout << "IMPOSSIBLE" << endl;
    return 0;
  }
  if (find(a.begin(), a.end(), k) != a.end()) {
    cout << "POSSIBLE" << endl;
    return 0;
  }

  ll d = a[0];
  rep(i, n) d = gcd(d, a[i]);

  auto fs = factorize(d);
  if (d == 1) fs.insert(1);
  auto itr = lower_bound(a.begin(), a.end(), k);
  int j = distance(a.begin(), itr);
  for (int i = j; i < n; i++) {
    for (auto f : fs) {
      if ((a[i] - k) % f == 0) {
        cout << "POSSIBLE" << endl;
        return 0;
      }
    }
  }
  cout << "IMPOSSIBLE" << endl;
}


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

int main() {
  int N,A,B;
  cin >> N >> A >> B;
  
  string x;
  
  if((B-A)%2==0) x="Alice";
  else if((B-A)%2==1) x="Borys";
  
  cout << x <<endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
int n;
  scanf("%d",&n);
  int a[n+1];
  for(int i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  int ans[n+1];
  for(int i=0;i<n;i++){
ans[a[i]-1]=i+1;
  }
  
   for(int i=0;i<n;i++){
printf("%d ",ans[i]);
  }
  return 0;
}

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

using namespace std; 
const int MAX_N = 16; 
const long long inf = -1e15; 
long long dp[(1 << MAX_N) + 5]; 
long long cost[(1 << MAX_N) + 5]; 
int a[MAX_N][MAX_N];
int n; 

int main () {
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	cin >> n; 
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			cin >> a[i][j]; 
		}
	}

	for (int mask = 1; mask < (1 << n); mask++) {
		for (int i = 0; i < n; i++) {
			for (int j = i + 1; j < n; j++) {
				if ((mask & (1 << i)) > 0 && (mask & (1 << j)) > 0) {
					cost[mask] += a[i][j]; 
				}
			}
		}
	}

	dp[0] = 0; 
	for (int mask = 1; mask < (1 << n); mask++) {
		dp[mask] = cost[mask]; 
		for (int submask = (mask - 1) & mask; submask > 0; submask = (submask - 1) & mask) {
			dp[mask] = max(dp[mask], dp[mask - submask] + cost[submask]); 
		}
	}
	cout << dp[(1 << n) - 1]; 
	return 0; 
}

Measured memory_bytes: 1280
MAX = 10000

def bucket_sort(A):
    count_array = [0] * MAX
    B = [0] * len(A)
    for a in A:
        count_array[a] += 1

    for i in range(1, MAX):
        count_array[i] = count_array[i] + count_array[i-1]

    for a in A[::-1]:
        B[count_array[a]-1] = a
        count_array[a] -= 1
    return B

if __name__ == "__main__":
    n = int(input())
    *A, = map(int, input().split())
    # A = [0] + A
    print(*bucket_sort(A))
    




Measured memory_bytes: 224504
N = int(input())
S1 = input()
S2 = input()
ans = 1
mod = 1000000007
i = 0
while i < N:
    if i == 0:
        if S1[i] == S2[i]:
            ans *= 3
            i += 1
        else:
            ans *= 6
            i += 2
    else:
        if S1[i] == S2[i]:
            if S1[i-1] == S2[i-1]:
                ans *= 2
                ans %= mod
                i += 1
            else:
                ans *= 1
                ans %= mod
                i += 1
        else:
            if S1[i-1] == S2[i-1]:
                ans *= 2
                ans %= mod
                i += 2
            else:
                ans *= 3
                ans %= mod
                i += 2
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

const int N=1e5+5;

int32_t main()
{
	IOS;
	string s;
	cin>>s;
	stringstream ss(s);
	int yy, mm, dd;
	char ch;
	ss>>yy>>ch>>mm>>ch>>dd;
	if(mm<=4)
		cout<<"Heisei";
	else
		cout<<"TBD";
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
#include<complex>
#include<random>
#include<ctime>
using namespace std;

const long long int mod=998244353;
const long long int INF=99999999999999999;

long long int n,m,sum,res=9999999999999999;

int main() {
	cout << fixed << setprecision(10);
    cin>>n;
    for(long long int i=1;i<=1000000;i++){
        if(n%i==0){res=min(res,i-1+(n/i)-1);}
    }
    cout<<res<<endl;
} 


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

#define repi(i, a, b) for(int i = (int)(a); i < (int)(b); ++i)
#define rep(i, n) repi(i, 0, n)
#define all(x) (x).begin(), (x).end()

inline void Main() {
  // code
  int n;
  string s;
  cin >> n >> s;

  if(n % 2 == 1) {
    cout << "No" << endl;
    return;
  }

  rep(i, n/2) {
    if(s.at(i) != s.at(n/2+i)) {
      cout << "No" << endl;
      return;
    }
  }

  cout << "Yes" << endl;
}

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
using ll=long long ;
int main()
{
    int n,m;
    cin>>n>>m;
    int L=0,R=n;
    rep(i,m){
        int l,r;
        cin>>l>>r;
        L=max(L,l);
        R=min(R,r);
    }
    if(R-L>=0) cout<<R-L+1;
    else cout<<"0";
}

Measured memory_bytes: 3584
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstring>
#include<queue>
#include<tuple>
#include<utility>
#include<map>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include<stdlib.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define range(a) a.begin(), a.end()
#define endl "\n"
#define Yes() cout << "Yes" << endl
#define No() cout << "No" << endl
using Graph = vector<vector<int>>;
const unsigned long long mod = 1e9 + 7;
const long long INF = 1LL<<60;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
void chmin(long long &a, long long b) { if (a > b) a = b; }
void chmax(long long &a, long long b) { if (a < b) a = b; }

vector<bool> seen;
int c=0,ans=0;

void dfs(const Graph &G, int v) {
    seen[v] = true; // v を訪問済にする
	c++;

    // v から行ける各頂点 next_v について
    for (auto next_v : G[v]) { 
        if (seen[next_v]) continue; // next_v が探索済だったらスルー
        dfs(G, next_v); // 再帰的に探索
    }

}

int main(void){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int N,M;	cin>>N>>M;
	Graph G(N);
	FOR(i,0,M){
		int a,b; cin>>a>>b; a--; b--;
		bool m = false;
		FOR(j,0,G.at(a).size()){
			if(G.at(a).at(j)==b){
				m = true;
				break;
			}
		}
		if(m==false){
			G.at(a).push_back(b);
			G.at(b).push_back(a);
		}
	}

	int ans=0;
	seen.assign(N, false); // 全頂点を「未訪問」に初期化
    FOR(i,0,N){
		if(seen.at(i)==true)	continue;
		dfs(G, i);
		if(c>=ans)	ans=c;
		c = 0;
	}

	cout<<ans<<endl;

    return 0;
}



Measured memory_bytes: 23416
def solve_a(s):
    n = len(s) + 1
    # from left
    left = [0] * n
    for i in range(1, n):
        if s[i - 1] == "<":
            left[i] = left[i - 1] + 1
    # from right
    right = [0] * n
    for i in range(n - 2, -1, -1):
        if s[i] == ">":
            right[i] = right[i + 1] + 1
    return sum([max(left[i], right[i]) for i in range(n)])


def main():
    s = list(input())
    res = solve_a(s)
    print(res)


def test():
    assert solve_a(list("<>>")) == 3
    assert solve_a(list("<>>><<><<<<<>>><")) == 28


if __name__ == "__main__":
    test()
    main()


Measured memory_bytes: 111352
#include <stdio.h>
typedef unsigned long long ull;

ull n;
ull sum[2 * 100005];
ull xum[2 * 100005];
ull dat[2 * 100005];
ull ans;

int main()
{
	scanf("%llu", &n);
	for (ull i = 1; i <= n; i++) {
		scanf("%llu", &dat[i]);

		sum[i] = sum[i - 1] + dat[i];
		xum[i] = xum[i - 1] ^ dat[i];
	}

	sum[n + 1] = sum[n] + 1;
	for (ull i = 1; i <= n; i++) {
		ull valid = i;
		ull invalid = n + 1;

		while (invalid - valid > 1) {
			ull mid = (valid + invalid) / 2;

			if ((sum[mid] - sum[i - 1]) <= (xum[mid] ^ xum[i - 1])) {
				valid = mid;
			} else {
				invalid = mid;
			}
		}

		if ((sum[valid] - sum[i - 1]) == (xum[valid] ^ xum[i - 1])) {
			ans += valid - i + 1;
		}
	}

	printf("%llu\n", ans);

	return 0;
}


Measured memory_bytes: 4864
a, b, k = map(int, input().split())
ya = []
yb = []

for i in range(1, a + 1):
    if a % i == 0:
        ya.append(i)

for i in range(1, b + 1):
    if b % i == 0:
        yb.append(i)


lres = []

for i in range(0, len(ya)):
    if ya[i] in yb:
        lres.append(ya[i])

lres.reverse()

print(lres[k - 1])


Measured memory_bytes: 3064
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class Main {

	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);

		int n = sc.nextInt();
		int[] p = sc.nextIntArray(n);

		int count = 0;
		boolean b = false;
		for (int i = 0; i < n; i++) {
			if (!b) {
				if (p[i] == i + 1) {
					count++;
					b = true;
				} else {
					b = false;
				}
			} else {
				b = false;
			}
		}

		out.println(count);
		out.flush();
	}

}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) return true;
		else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) return false;
		}
		return true;
	}

	private byte readByte() {
		if (hasNextByte()) return buffer[ptr++];
		return -1;
	}

	private boolean isPrintableChar(byte c) {
		return '!' <= c && c <= '~';
	}

	private void skipUnprintable() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
			ptr++;
		}
	}

	public boolean hasNext() {
		skipUnprintable();
		return hasNextByte();
	}

	public String next() {
		if (!hasNext()) throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		byte b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public int nextInt() {
		if (!hasNext()) throw new NoSuchElementException();
		int n = 0;
		boolean minus = false;
		byte b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) throw new NumberFormatException();
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int[] nextIntArray(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = nextInt();
		}
		return a;
	}

	public long nextLong() {
		if (!hasNext()) throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		byte b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) throw new NumberFormatException();
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public long[] nextLongArray(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++) {
			a[i] = nextInt();
		}
		return a;
	}
}

Measured memory_bytes: 22100
use std::io::*;
use std::cmp;
use std::collections::HashMap;


fn main() {
    let (N, S, W, E) = (0, 1, 2, 3);
    let mut buf: String = String::new();
    stdin().read_line(&mut buf);
    buf = buf.trim().to_string();

    let mut coll: HashMap<char, i32> = HashMap::new();

    for c in buf.chars() {
        let nxt = match coll.get(&c) {
            Some(n) => *n + 1,
            None => 1
        };
        coll.insert(c, nxt);
    }
   
    let v = vec!['N', 'S', 'W', 'E'];
    let mut res = vec![0; 4];
    
    for (i, c) in v.iter().enumerate() {
        res[i] = match coll.get(c) {
            Some(n) => *n,
            None => 0
        };
    }

    let cond = cmp::min(res[N], res[S]) == 0 && cmp::max(res[N], res[S]) != 0 || cmp::min(res[W], res[E]) == 0 && cmp::max(res[W], res[E]) != 0;

    if cond {
        println!("No");
    } else {
        println!("Yes");
    }
}


Measured memory_bytes: 4352
n=int(input())
a=list(map(int,input().split()))
i,j,k=0,0,0
for m in a:
    if m%4==0:
        i+=1
    elif m%2==0:
        j+=1
    else:
        k+=1
if j==0:
    if i>=k-1:
        print('Yes')
    else:
        print('No')
else:
    if i>=k:
        print('Yes')
    else:
        print('No')

Measured memory_bytes: 14252
#include <bits/stdc++.h>
using namespace std;
int main(){
	int N; cin >> N; 
	int A[8] = {1,2,3,4,5,6,7,8}; 
	int P[8], Q[8]; 
	for(int i = 0; i < N; i++) cin >> P[i]; 
	for(int i = 0; i < N; i++) cin >> Q[i]; 
	int cnt = 0; int ans1 = 114514; int ans2 = 114514; 
	do{
		bool ok1 = true; bool ok2 = true; 
		for(int i = 0; i < N; i++){
			if(A[i] != P[i]) ok1 = false; 
			if(A[i] != Q[i]) ok2 = false; 
		}
		if(ok1) ans1 = cnt; 
		if(ok2) ans2 = cnt; 
		cnt++; 
	}while(next_permutation(A, A+N)); 
	cout << abs(ans1 - ans2) << endl; 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
const int MOD = 1000000007;
#define rep(i,n) for (ll i=0; i < (n); i++)
using namespace std;
int get_gcd(int a, int b) {
  while(1) {
    if (a < b) swap(a, b);
    if (b == 0) return a;
    a %= b;
  }
}
int get_lcm(int a, int b){return a * b / get_gcd(a, b);}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

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

  int l,r;
  l = r = 0;
  rep(i,s.size()) {
    if (s[i] == 'L') l++;
    else r++;

    // R--RL--Lとなる部分列に対して計算する。
    if ((i+1 == s.size()) || (s[i] == 'L' && s[i+1] == 'R')) {
      rep(j, r-1) printf("0 ");
      printf("%d ", (r+1)/2 + l/2);
      printf("%d ", r/2 + (l+1)/2);
      rep(j, l-1) printf("0 ");
      l = r = 0;
    }
  }
  printf("\n");

  return 0;
}


Measured memory_bytes: 640
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define MOD1 1000000007
#define MOD2 998244353
#define LIMIT1 200002
#define LIMIT2 500002
typedef long long ll;
typedef long double ld;
typedef const void cv;
#define rep(i,n) for((i)=0;(i)<(n);(i)++)
#define per(i,n) for((i)=(n)-1;(i)>=0;(i)--)
#define max(a,b) ((a)>(b) ? (a) : (b))
#define min(a,b) ((a)<(b) ? (a) : (b))
#define zt(a,b) (max((a),(b))-min((a),(b)))
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll nPr(int n,int r){ll i,result=1;rep(i,r){result*=(ll)(n-i);}return result;}
ll nCr(int n,int r){ll i,result=1;if(n<r) return 0;rep(i,min(r,n-r)){result*=(ll)(n-i);result/=(ll)(i+1);}return result;}
#define nHr(n,r) nCr((int)((n)+(r)+1),(int)(r))
#define sankaku(x) (((x)*((x)+1))/2)
int dx[8]={1,0,-1,0,1,-1,-1,1};
int dy[8]={0,1,0,-1,1,1,-1,-1};
int upint(const void *a, const void *b) { return *(int *)a < *(int *)b ? -1 : *(int *)a > *(int *)b ? 1 : 0; }
int downint(const void *a, const void *b) { return *(int *)a < *(int *)b ? 1 : *(int *)a > *(int *)b ? -1 : 0; }
int upchar(const void* left, const void* right) {return strcmp((char *)left,(char *)right);}
int downchar(const void* left, const void* right) {return strcmp((char *)right,(char *)left);}
ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1){
            res *= a; if(mod>=1) res %= mod;
        }
        a *= a; if(mod>=1) a %= mod;
        n >>= 1;
    }
    return res;
}
void initialize(){
    
}
int main(void){
  initialize();
  ll n,m,i,j,k,result=0,now=0,count,tmp;
  int a[LIMIT2]={0};
  char s[LIMIT1];
  int visited[LIMIT1]={0};
  
  scanf("%lld %lld",&n,&k);
  rep(i,n){
    scanf("%d",&a[i]);
    a[i]--;
  }
  
  now=0;
  count=1;
  while(visited[now]==0&&count<=k){
    visited[now]=count;
    now = a[now];
    count++;
  }
  if(count<=k){
    i = count - visited[now];//loop zone length
    k -= visited[now]-1;
    tmp = k % i + visited[now];
    rep(j,n){
      if(tmp==visited[j]){
        result = j+1;
        break;
      }
    }
  }else{
    result = now+1;
  }
  printf("%lld",result);
  return 0;
}



Measured memory_bytes: 4468
#include <vector>
#include <iostream>
#include <map>
using namespace std;

vector<int> k;
vector<bool> canZero;
int M;

int dfs(int depth, vector<bool> &used, int sum){
  if(depth == M) return (sum == 0) ? 1 : 0;

  int res = 0;
  for(int i=0;i<=9;i++){
    if(not used[i]){
      if(i==0 and not canZero[depth]) continue;
      used[i] = true;
      res += dfs(depth+1, used, sum + k[depth]*i);
      used[i] = false;
    }
  }
  return res;
}

int main(){
  int n;
  while(cin >> n){
    if(n == 0) break;

    string s;
    map<char, int> id;
    k = vector<int>(10, 0);
    canZero = vector<bool>(10, true);
    for(int i=0;i<n;i++){
      cin >> s;
      int x = 1;
      for(int j=s.size()-1;j>=0;j--){
        if(id.count(s[j]) == 0) id[s[j]] = id.size()-1;
        k[id[s[j]]] += (i==n-1) ? -x : x;
        x *= 10;
      }
      if(s.size()>1) canZero[id[s[0]]] = false;
    }

    M = id.size();
    vector<bool> used(M, false);
    cout << dfs(0, used, 0) << endl;
  }
}

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

int main() {
	long long I,O,T,J,L,S,Z;
	long long ans = 0;
	cin >> I >> O >> T >> J >> L >> S >> Z;
	if (!I || !L || !J) {ans = O + 2 * (I / 2) + 2 * (J / 2) + 2 * (L / 2);}
	else {
		ans = max(3 + 2*((I-1)/2) + 2*((J-1)/2) + 2*((L-1)/2),2*(I/2) + 2*(J/2) + 2*(L/2));
		ans += O;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
/*
 *
 * Author: r3gz3n
 * 3b 13 12 9 56 4e
 * 6 56 a a 5f f
 * 6 56 47 18 56 d
 * 13 46 14 1f 13 27
 * 52 52 a 5a 47 1
 * 1d 13 b 1b 49 17
 *
 */


#include <utility>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <random>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;


#define ll long long


class Solution {
public:
    void solve(std::istream& in, std::ostream& out) {
		ll x;
		in >> x;
		ll y = x / 11;
		x = x % 11;
		if (0 < x and x <= 6) x = 1;
		if (x > 6) x = 2;
		out << 2*y + x << endl;
    }
};

void solve(std::istream& in, std::ostream& out)
{
    out << std::setprecision(12);
    Solution solution;
    solution.solve(in, out);
}


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


    istream& in = cin;


    ostream& out = cout;

    solve(in, out);
    return 0;
}




Measured memory_bytes: 384
# -*- coding: utf-8 -*-
import math

N = int(input())

ans = 10
for A in range(1, int(math.sqrt(N)+1)):
    if N % A == 0:
        B = int(N / A)
        tmp = max(len(str(A)), len(str(B)))
        if ans > tmp:
            ans = tmp

print(ans)


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

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

typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;

#define INF INT_MAX
#define MOD 1000000007
#define all(x) x.begin(), x.end()

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

    string S, T; cin >> S >> T;
    T.pop_back();
    if(S == T) cout << "Yes" << endl;
    else cout << "No" << endl;    

    return 0;
}



Measured memory_bytes: 3616
#include <stdio.h>

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

  for(int i = 1; i <= N; i++) {
    int digitSum = 0;
    int temp = i;
    while(temp != 0) {
      digitSum = digitSum + temp % 10;
      temp /= 10;
    }
    if(digitSum >= A && digitSum <= B) {
      sum += i;
    }
  }
  printf("%d\n", sum);
}

Measured memory_bytes: 1724
using System;
using System.IO;
using System.Linq;
using static System.Console;

namespace A
{
    class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(OpenStandardOutput()){AutoFlush = false};
            SetOut(sw);
            var st = ReadLine().Split(' ');
            var ab = ReadLine().Split(' ').Select(int.Parse).ToArray();

            var u = ReadLine();
            if (u == st.First())
            {
                ab[0]--;
            }
            else
            {
                ab[1]--;
            }
            WriteLine($"{ab[0]} {ab[1]}");
            
            Out.Flush();
        }
    }
}

Measured memory_bytes: 11348
import java.io.*
import java.util.*

fun main(args: Array<String>) {
    val inputStream = System.`in`
    val outputStream = System.out
    val inp = Main.InputReader(inputStream)
    val out = PrintWriter(outputStream)
    val solver = Main.TaskB()
    solver.solve(inp, out)
    out.close()
}

class Main {
    internal class TaskB {
        fun solve(inp: InputReader, out: PrintWriter) {
            val n = inp.nextInt()
            val s = inp.next()
            if (n % 2 == 1)
                out.println("No")
            else {
                if (s.substring(0, n / 2).compareTo(s.substring(n / 2, n)) == 0)
                    out.println("Yes")
                else
                    out.println("No")
            }
        }
    }

    internal class InputReader(stream: InputStream) {
        private var reader: BufferedReader = BufferedReader(InputStreamReader(stream), 32768)
        private var tokenizer: StringTokenizer? = null

        init {
            tokenizer = null
        }

        operator fun next(): String {
            while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {
                try {
                    tokenizer = StringTokenizer(reader.readLine())
                } catch (e: IOException) {
                    throw RuntimeException(e)
                }
            }
            return tokenizer!!.nextToken()
        }

        fun nextInt(): Int {
            return Integer.parseInt(next())
        }

        fun nextLong(): Long {
            return next().toLong()
        }
    }
}


Measured memory_bytes: 29476
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};

int n,A,B;

int main(){
	cin>>n>>A>>B;
	if(n<max(A,B)){
		cout<<-1<<endl;
		return 0;
	}
	int B_=(n+A-1)/A;
	B-=B_;
	vi a(n),b;
	for(int i=0;i<n;i++) a[i]=n-i;
	int T=n;
	for(int i=0;i<B_;i++){
		reverse(a.begin()+i*A,a.begin()+i*A+min(A,T));
		T-=A;
	}
	for(int i=0;i<A;i++) b.push_back(a[i]);
	T=n-A;
	for(int i=1;i<B_;i++){
		int t=min({A,T,B}),L=0;
		for(int j=t;j<A&&i*A+j<n;j++) b.push_back(a[i*A+j]),L++;
		for(int j=t-1;j>=0;j--) b.push_back(a[i*A+j]),L++;
		B-=max(0,(L==t?t-1:t));
		T-=A;
	}
	if(B){
		cout<<-1<<endl;
		return 0;
	}
	for(int i=0;i<n;i++){
		if(i) cout<<' ';
		cout<<b[i];
	}
	cout<<endl;
}

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

int main(){
    int ans=0,sum=0;
    int a,b;
    
    cin >>a>>b;

    //cout <<fixed<<setprecision(16)<< << endl;
    cout << max(a*b,max(a-b,a+b)) << endl;

    //if(flag==1)cout << "Yes" <<endl;
    //else cout << "No" <<endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <iomanip>

#define REP(i,n) for(i=0; i < (n); i++)
#define REPONE(i, n) for(i=1; i <= (n); i++)
#define LOOP(n) for(int loopCount=1; loopCount <= (n); loopCount++)
#define ITER(c) __typeof((c).begin())
#define EACH(c,it) for(ITER(c) it =(c).begin(); it!=(c).end(); it++)
#define SZ(c) ((int) (c).size())
#define ALL(c) c.begin(), c.end()
#define SUM(c) accumulate(ALL(c), 0)
#define EXIST(c,v) (find(ALL(c), (v)) != (c).end())
#define PB push_back
#define MP make_pair
#define fs first
#define sc second

using namespace std;
static const double EPS = 1e-9;
static const double PI = 3.141592653589793238462643383279;
typedef long long ll;

int main(){
    int rept;
    scanf("%d",&rept);
    LOOP(rept){
        int sub, money, year, i, j, n, pat, cnst, ans=0, cur;
        double multi;
        vector< pair<double, int> > fukuri, tanri;
        scanf("%d%d%d",&money,&year,&n);
        REP(i,n){
            scanf("%d%lf%d",&pat,&multi,&cnst);
            if(pat) fukuri.PB(MP(multi,cnst));
            else tanri.PB(MP(multi,cnst));
        }

        REP(i,SZ(fukuri)){
            cur = money;
            REP(j,year){
                cur += (int)(cur*fukuri[i].fs) - fukuri[i].sc;
            }
            ans = max(ans, cur);
        }
        REP(i,SZ(tanri)){
            cur = money;
            sub = 0;
            REP(j,year){
                sub += (int)(cur*tanri[i].fs);
                cur -= tanri[i].sc;
            }
            ans = max(ans, cur+sub);
        }

        printf("%d\n",ans);
    }

}

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

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,k,d;
    cin>>n>>k>>d;
    n = abs(n);
    ll till = n/d;
    ll val = n - (till*d);
    ll diff = k - till;
    if(diff > 0){
        if(diff%2 == 1){
            ll ans = min(abs(val + d),abs(val-d));
            cout<<ans;
        }
        else{
            ll curr = val;
            ll next = val-d;
            ll next2 = next -d;
            if(abs(next2)< curr){
                cout<<next2;
            }
            else{
                cout<<curr;
            }
        }
    }
    else if(diff == 0){
        cout<<val;
    }
    else{
        ll ans = n - (k*d);
        cout<<ans;
    }
}

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

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int N, P; cin >> N >> P;
	string S; cin >> S;
	long long ans = 0;
	if (P == 2 || P == 5) {
		for (int i = 0; i < N; i++) {
			int v = S[i] - '0';
			if (v % P == 0) {
				ans += i+1;
			}
		}
	} else {
		reverse(S.begin(), S.end());
		unordered_map<int, int> mp;
		mp[0] ++;
		int pref = 0;
		int pref10 = 1;
		for (char c  : S) {
			int v = c - '0';

			pref += v * pref10;
			pref %= P;

			ans += mp[pref]++;

			pref10 *= 10;
			pref10 %= P;
		}
	}
	cout << ans << '\n';

	return 0;
}


Measured memory_bytes: 916
#include <iostream>
#include <cmath>
#include <algorithm>

using namespace std;

#define ll long long

int K, S, ans = 0;

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

    for(int i = 0; i <= K;i++)
        for(int j = 0; j <= min(S - i, K); j++){
            int Z = S - i - j;
            if( 0 <= Z && Z <= K) ans++;
        }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int N,a,b,K;
vector<int> h(100090),rec(100090);
 
int dp(int n){
  if(n==1){return 0;}
  else if(n==2){return abs(h[1]-h[2]);}
  else{
    if(rec[n-1]==-1){rec[n-1]=dp(n-1);}
    int m=rec[n-1]+abs(h[n]-h[n-1]);
    for(int i=2;i<=K;i++){
      if(n-i<1)continue;
      if(rec[n-i]==-1){rec[n-i]=dp(n-i);} 
      m=min(m,rec[n-i]+abs(h[n]-h[n-i]));
    }
    return m;
  }
}
 
int main(){
  cin >> N >> K;
  for(int i=1;i<=N;i++){cin >> h[i];}
  for(int i=1;i<=N;i++){rec[i]=-1;}
  cout << dp(N) << endl;
}

Measured memory_bytes: 7296
#include <iostream>
#include <queue>
#include <set>
#include <utility>
#include <vector>
using namespace std;

int main() {
	vector<vector<int>> a(3, vector<int>(3)), b{ { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 0 } };
	for (vector<int>& i : a) {
		for (int& j : i) cin >> j;
	}
	queue<pair<int, vector<vector<int>>>> c;
	c.emplace(0, a);
	set<vector<vector<int>>> d;
	d.insert(a);
	while (true) {
		queue<pair<int, vector<vector<int>>>> e;
		while (!c.empty()) {
			if (b == c.front().second) break;
			pair<int, int> f;
			for (int i = 0; i < 9; ++i) {
				if (!c.front().second[i / 3][i % 3]) {
					f.first = i / 3;
					f.second = i % 3;
					break;
				}
			}
			if (2 != f.first) {
				swap(c.front().second[1 + f.first][f.second], c.front().second[f.first][f.second]);
				if (!d.count(c.front().second)) {
					e.emplace(1 + c.front().first, c.front().second);
					d.insert(c.front().second);
				}
				swap(c.front().second[1 + f.first][f.second], c.front().second[f.first][f.second]);
			}
			if (2 != f.second) {
				swap(c.front().second[f.first][1 + f.second], c.front().second[f.first][f.second]);
				if (!d.count(c.front().second)) {
					e.emplace(1 + c.front().first, c.front().second);
					d.insert(c.front().second);
				}
				swap(c.front().second[f.first][1 + f.second], c.front().second[f.first][f.second]);
			}
			if (f.first) {
				swap(c.front().second[f.first - 1][f.second], c.front().second[f.first][f.second]);
				if (!d.count(c.front().second)) {
					e.emplace(1 + c.front().first, c.front().second);
					d.insert(c.front().second);
				}
				swap(c.front().second[f.first - 1][f.second], c.front().second[f.first][f.second]);
			}
			if (f.second) {
				swap(c.front().second[f.first][f.second - 1], c.front().second[f.first][f.second]);
				if (!d.count(c.front().second)) {
					e.emplace(1 + c.front().first, c.front().second);
					d.insert(c.front().second);
				}
				swap(c.front().second[f.first][f.second - 1], c.front().second[f.first][f.second]);
			}
			c.pop();
		}
		if (!c.empty()) break;
		swap(c, e);
	}
	cout << c.front().first << endl;
}


Measured memory_bytes: 46520
import java.util.*;
import java.io.*;
import java.text.*;
import java.math.*;
import static java.lang.Integer.*;
import static java.lang.Double.*;
import java.lang.Math.*;

public class Main {

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

	public void run() throws Exception {
		FastIO file = new FastIO();
		int n = file.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = file.nextInt();
		}
		Arrays.sort(a);
		System.out.println(a[n / 2] - a[n / 2 - 1]);
	}

	public static class FastIO {
		BufferedReader br;
		StringTokenizer st;

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

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

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

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

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

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

	public static long pow(long n, long p, long mod) {
		if (p == 0)
			return 1;
		if (p == 1)
			return n % mod;
		if (p % 2 == 0) {
			long temp = pow(n, p / 2, mod);
			return (temp * temp) % mod;
		} else {
			long temp = pow(n, p / 2, mod);
			temp = (temp * temp) % mod;
			return (temp * n) % mod;

		}
	}

	public static long pow(long n, long p) {
		if (p == 0)
			return 1;
		if (p == 1)
			return n;
		if (p % 2 == 0) {
			long temp = pow(n, p / 2);
			return (temp * temp);
		} else {
			long temp = pow(n, p / 2);
			temp = (temp * temp);
			return (temp * n);

		}
	}

	public static long gcd(long x, long y) {
		if (x == 0)
			return y;
		else
			return gcd(y % x, x);
	}

	public static boolean isPrime(int n) {
		if (n <= 1)
			return false;
		if (n <= 3)
			return true;

		if (n % 2 == 0 || n % 3 == 0)
			return false;

		for (int i = 5; i * i <= n; i = i + 6)
			if (n % i == 0 || n % (i + 2) == 0)
				return false;

		return true;
	}
}


Measured memory_bytes: 34884
#include <iostream>
#include <iomanip>
#include <cstring>
#include <algorithm> 
#include <math.h>
#include <queue>
#include <functional>
#include <map>
#include <vector>
#include <string>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<pair<int, int>, int> PP;

const ll INF = 1e15;
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };


vector<P>G[100010];
int color[100010];

void dfs(int v, int p, int c) {
	color[v] = c;
	for (int i = 0; i < G[v].size(); i++) {
		int q = G[v][i].first;
		int d = G[v][i].second;
		if (color[q] >= 0)continue;
		if (d % 2 == 0) dfs(q, v, color[v]);
		else dfs(q, v, 1 - color[v]);
	}
	return;
}

int main(void) {
	int N; cin >> N;
	for (int i = 0; i < N - 1; i++) {
		int p, q, d; cin >> p >> q >> d;
		p--; q--;
		G[p].push_back({ q, d });
		G[q].push_back({ p, d });
		color[i] = -1;
	}
	color[N-1]=-1;

	dfs(0, -1, 0);

	for (int i = 0; i < N; i++) cout << color[i] << endl;

}


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

int main() {
	int n,in,min=1000000,max=-1000000;
	long sum=0;
	cin>>n;
	while(n--) {
		cin>>in;
		sum+=in;
		if(in>max) {
			max=in;
		}
		if(in<min) {
			min=in;
		}
	}
	cout<<min<<" "<<max<<" "<<sum<<endl;
	return 0;
}

Measured memory_bytes: 1168
use std::io;

fn main() {
    let mod_law: usize = 1_000_000_007;
    let ns: Vec<usize> = parse_values(2);
    let n = ns[0];
    let k = ns[1];
    let mut rev = (0..=n).rev();
    let mut max: usize = 0;
    for _ in 0..k-1 {
        max += rev.next().unwrap();
    }
    let mut sum: usize = 0;
    for i in k..=n+1 {
        let min: usize = (0..i).sum();
        max += rev.next().unwrap();
        sum += max + 1 - min;
        sum = sum % mod_law
    }
    println!("{}", sum);
}

fn parse_line<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn parse_values<T: std::str::FromStr>(n: usize) -> Vec<T> {
    let line = parse_line::<String>();
    let mut split = line.split_whitespace();
    let mut values = Vec::with_capacity(n);
    for _ in 0..n {
        let v = split.next().unwrap().parse::<T>().ok().unwrap();
        values.push(v);
    }
    values
}


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

using namespace std;

int n, a[200005];

int main(){
	scanf("%d", &n);
	
	for(int i = 1; i <= n; i++){
		int x;
		scanf("%d", &x);
		a[x] = i;
	}
	
	int lt = -1;
	int cur = 0;
	int res = 0;
	
	for(int i = 1; i <= n; i++){
		if(a[i] > lt)
		cur++;
		else
		cur = 1;
		
		res = max(res, cur);
		
		lt = a[i];
	}
	
	printf("%d\n", n - res);
}


Measured memory_bytes: 1024
// m-solutions2020_a
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <type_traits>
#include <typeindex>
#include <unordered_map>
#include <unordered_set>
#endif

template <typename A, typename B> bool cmin(A &a, const B &b) {
  return a > b ? (a = b, true) : false;
}
template <typename A, typename B> bool cmax(A &a, const B &b) {
  return a < b ? (a = b, true) : false;
}
const double PI = acos(-1);
const double EPS = 1e-9;
int inf = sizeof(int) == sizeof(long long) ? 2e18 : 1e9 + 10;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main()
{
  int X;
  cin >> X;
  if (X < 600) cout << 8;
  else if (X >= 600 && X < 800) cout << 7;
  else if (X >= 800 && X < 1000) cout << 6;
  else if (X >= 1000 && X < 1200) cout << 5;
  else if (X >= 1200 && X < 1400) cout << 4;
  else if (X >= 1400 && X < 1600) cout << 3;
  else if (X >= 1600 && X < 1800) cout << 2;
  else if (X >= 1800 && X < 2000) cout << 1;
  cout<<endl;
  return 0;
}


Measured memory_bytes: 3632