akhauriyash/Code-Regression huggingface dataset:
input = gets.chomp.to_i
ans = 0
#2の倍数かどうかのフラグ
isBinary = false

while true do
  #素数の確認は半分で良い
  half = input / 2 + 1
  #素数かどうかのフラグ
  flag = true
  half.times do |i|
    next if i <= 1
    if input != i && input % i == 0
      #素数でない場合
      flag = false
      break
    end
  end
  
  if flag
    ans = input
    break
  end
  
  #isBinaryがtrueの場合は１つ飛ばしにする
  if isBinary
    input += 2
    next
  end

  if input % 2 == 0
    input += 1
    isBinary = true
    next
  end
    
  input += 1
end

puts ans

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


int main(){
  int t, n, f, sz;
  string s, c;
  int i;
  cin >> s >> n;
  sz = s.size();
  deque<string> data(sz);
  for(i=0; i<sz; i++) data.at(i) = s.at(i);
  int th = 0;
  for(i=0; i<n; i++){
    cin >> t;
    if(t==1){
      if(th==0) th = 1;
      else th = 0;
    }
    else if(th==0){
      cin >> f >> c;
      if(f==1) data.push_front(c);
      else data.push_back(c);
    }
    else {
      cin >> f >> c;
      if(f==1) data.push_back(c);
      else data.push_front(c);
    }
  }
  if(th == 1) reverse(data.begin(), data.end());
  for(i=0; i<data.size(); i++) cout << data.at(i);
  cout << endl;
  
}

Measured memory_bytes: 17152
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using ld = long double;
const int INF = 1 << 29;
const ll LINF = 1l << 61;
const ld PI = abs(acos(-1));
#define pq priotity_queue
#define pb push_back
#define mp make_pair
#define rep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define cbuf(buf, init) memset(buf, init, sizeof(buf))

template <class T>
constexpr T modp(T x, T y)
{
    return (y + x % y) % y;
}
template <class T>
constexpr T sq(T x)
{
    return x * x;
}
template <class T>
constexpr double divd(T x, T y)
{
    static_cast<double>(x) / static_cast<double>(y);
}

template <class T>
T nextInput()
{
    T t;
    cin >> t;
    return t;
}

#define netint nextInput<ll>()
#define netstr nextInput<string>()

template <class T>
void print(T&& t)
{
    cout << forward<T&&>(t) << endl;
}

void print(double t) { cout << fixed << setprecision(14) << t << endl; }

//

ll a[200005];
ll b[200005];
ll sb[200005];
ll sa[200005];

int main()
{
    //
    ll N = netint;
    rep(i, 0, N) { a[i] = netint; }
    rep(i, 0, N) { b[i] = netint; }

    ll ans = 0;
    rep(k, 0, 30)
    {
        ll T = (1 << k);
        rep(i, 0, N) { sb[i] = b[i] % (2 * T); }
        rep(i, 0, N) { sa[i] = a[i] % (2 * T); }
        sort(sb, sb + N);
        ll c = 0;
        rep(i, 0, N)
        {
            c += upper_bound(sb, sb + N, 2 * T - sa[i] - 1) -
                 lower_bound(sb, sb + N, 1 * T - sa[i]);
            c += upper_bound(sb, sb + N, 4 * T - sa[i] - 1) -
                 lower_bound(sb, sb + N, 3 * T - sa[i]);
        }
        ans |= ((c & 1) << k);
    }

    print(ans);
}


Measured memory_bytes: 6528
#include <stdio.h>

int main(void)
{
    int k, x;
    int ans[300];
    int i, j;

    scanf("%d %d", &k, &x);

    for(i = x-k+1, j = 0; i <= x+k-1; i++, j++){
        ans[j] = i;
    }

    printf("%d", ans[0]);

    for(int i = 1; i < 2*k-1; i++){
        printf(" %d", ans[i]);
    }

    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<cstring>

using namespace std;
typedef struct{
  int teamnum;
  int solve;
  int stime;
}TEAM;

const int MAXTEAM = 51;
const int MAXPROBLEM = 11;
TEAM team[MAXTEAM];
int T,P,R;
int wrong[MAXTEAM][MAXPROBLEM];


void init(){
  for(int i = 1; i < MAXTEAM; i++){
    team[i].teamnum = i;
    team[i].solve = team[i].stime = 0;
  }
  memset(wrong,0,sizeof(wrong));
}


void solve(int tID,int pID,int solvetime){
  team[tID].solve++;
  team[tID].stime += wrong[tID][pID]*1200+solvetime;
}


void teamsort(){
  for(int i = 1; i <= T; i++)
    for(int j = i+1; j <= T; j++)
      if(team[i].solve < team[j].solve) swap(team[i],team[j]);
      else if(team[i].solve == team[j].solve)
	if(team[i].stime > team[j].stime) swap(team[i],team[j]);
	else if(team[i].stime == team[j].stime)
	  if(team[i].teamnum > team[j].teamnum) swap(team[i],team[j]);

}

void print(){
  for(int i = 1; i <= T; i++)
    cout << team[i].teamnum << " " << team[i].solve << " "<< team[i].stime << endl;

}
int main(){
  int tID,pID,solvetime;
  string judge;

  while(cin >> T >> P >> R && T+P+R){
    init();
    for(int i = 0; i < R; i++){
      cin >> tID >> pID >> solvetime >> judge;
      if(judge == "WRONG") wrong[tID][pID]++;
      else solve(tID,pID,solvetime);
    }
    teamsort();
    print();
  }
}

Measured memory_bytes: 924
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using piii = pair<int, pair<int, int>>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
template <typename T>
using Graph = vector<vector<T>>;
const int MOD = 1e9 + 7;

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

    int N;
    cin >> N;
    vector<int> dp;
    for (int i = 0; i < N; ++i) {
        int A;
        cin >> A;
        auto itr = lower_bound(dp.rbegin(), dp.rend(), A);
        if (itr == dp.rbegin())
            dp.push_back(A);
        else
            *(itr - 1) = A;
    }

    cout << dp.size() << endl;
    return 0;
}


Measured memory_bytes: 892
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define all(a) (a).begin(),(a).end()
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef double D;
typedef complex<D> P;

D cross(P a, P b){
  return a.real()*b.imag() - a.imag()*b.real();
}

D area(P a, P b, P c){
  return cross(c-a,b-a)/2;
}

const D PI = acos(-1);

int main(){
  D r,x,y,p[11];
  int n;

  cin >> r >> x >> y >> n;
  rep(i,n)cin >> p[i];

  D def[11];
  rep(i,n)def[i] = r*r*PI*p[i]/100;
 
  P prv = P(0,r);
  int sumper = 0;
  rep(i,n){
    sumper += p[i];
    D seta = 2*PI*sumper/100;
    P cur = P(r*sin(seta),r*cos(seta));
    D tri1 = area(P(x,y), prv, cur);
    D tri2 = area(P(0,0), prv, cur);
    D nxt = def[i] - tri2 + tri1;

    cout << (int)(100*nxt/def[i]) << (i+1==n?"\n":" ");

    prv = cur;
  }
}

Measured memory_bytes: 1236
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#define rep(i,n) for(int i = 0; i < n;i++)
#define ll long long
#include <bits/stdc++.h>
using namespace std;
#define mo 1000000007
#define ull unsigned long long 

int main(){
  ll n;cin>>n;
  ll ans=0;
  vector<ll>p(n+1);
  
  for(ll i=0;i<n;i++){
    cin>>p.at(i);
  }
    for(ll i=0;i<n;i++){
      if(i+1==p.at(i)){
        if(i!=n-1){
          p.at(i+1)=p.at(i);
        }
        ans++;
      }
    }
  cout<<ans;
}
        
   

  
    
  


Measured memory_bytes: 1024
sa = list(input())
sb = list(input())
sc = list(input())
sa.append('z')
sb.append('z')
sc.append('z')
ans = None
nextp = sa.pop(0)
while True:
    if len(sa) == 0:
        ans = 'A'
        break
    elif len(sb) == 0:
        ans = 'B'
        break
    elif len(sc) == 0:
        ans = 'C'
        break
    if nextp == 'a':
        nextp = sa.pop(0)
    elif nextp == 'b':
        nextp = sb.pop(0)
    elif nextp == 'c':
        nextp = sc.pop(0)
   
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
    int n,d[100009];
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>d[i];
    }
    sort(d,d+n);
    cout<<d[n/2]-d[n/2-1]<<endl;
    return 0;
}

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

using namespace std;

int main(){
  string S;
  cin >> S;
  int ans = S.length();
  auto check = [&](string L, char R){
    return all_of(L.begin(), L.end(),
                  [R](char x){ return x == R; });
  };
  for(char A = 'a';A <= 'z';A++){
    string T = S;
    int t = 0;
    while(T.length() > 1 && !check(T, A)){
      for(int i=0;i<T.length()-1;i++){
        if(T[i] != A && T[i+1] != A){
          continue; 
        }else{
          T[i] = A; 
        }
      }
      T.pop_back();
      t++;
    }
    ans = min(ans, t);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#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 repr(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define ALL(a) (a).begin(), (a).end()
using ll = long long;
// using Graph = vector<vector<int>>;
const ll MOD = 1e9 + 7;
const ll INF = 1e9;
const ll LINF = 1LL << 60;

int main() {
  ll a, b, c, k;
  cin >> a >> b >> c >> k;
  if (a >= k)
    cout << k << endl;
  else if (a + b >= k)
    cout << a << endl;
  else
    cout << a - (k - a - b) << endl;
  return 0;
}


Measured memory_bytes: 3640
import java.util.*;

public class Main {

  public static void main(String args[]) {
    int rep = 1;
    if( args.length > 0 ) { rep = Integer.parseInt(args[0]); }
    (new Main()).__solve(rep);
  }

  void __solve(int rep) {

    try (
      Scanner cin = new Scanner(System.in);
    ) {

      for( int i = 0; i < rep; ++i ) {
        __solve(cin);
      }

    }

  }
  
  String m[] = new String[] { "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12" };

  void __solve(Scanner cin) {
	  String s = cin.next();
	  boolean f = false;
	  boolean t = false;
	  for( String M : m ) {
		  f |= s.substring(0, 2).equals(M);
		  t |= s.substring(2, 4).equals(M);
	  }
	  if( f && t ) {
		  System.out.println("AMBIGUOUS");
	  }
	  else if( f ) {
		  System.out.println("MMYY");
	  }
	  else if( t ) {
		  System.out.println("YYMM");
	  }
	  else {
		  System.out.println("NA");
	  }
  }

}


Measured memory_bytes: 21844
#include <tuple>
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
    int N;
    cin >> N;
    vector<tuple<string, int, int> > v(N);

    for (int i = 0; i < N; i++) {
        string a;
        int b;
        cin >> a >> b;
        v[i] = make_tuple(a, -1*b, i+1);
    }

    sort(v.begin(), v.end());

    for (int i = 0; i < N; i++) {
        int a;

        tie(ignore, ignore, a) = v[i];
        cout << a << endl;
    }
}

Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( stdin . lock ( ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , mut $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let mut $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

fn main() {
    input! {
        a: i64, b: i64
    }

    if a > 0 {
        println!("Positive");
    } else if b >= 0 {
        println!("Zero");
    } else if (b - a + 1) % 2 == 0 {
        println!("Positive");
    } else {
        println!("Negative");
    }
}

Measured memory_bytes: 4352
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>

using namespace std;

#define REP(i,n) for(int i=0;i<int(n);i++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
typedef long long ll;
typedef pair<int,int> P;

int dp[5][5][110],p[110],N,K;

int main(void){
	int i,j,k;

	cin >> N >> K;
	for(i=1;i<=K;i++){
		int a,b;
		cin >> a >> b;
		p[a]=b;
	}

	for(i=2;i<=N;i++){
		if(i==2){
			if(p[1]==0 && p[2]==0){
				for(j=1;j<=3;j++) for(k=1;k<=3;k++) dp[j][k][i]=1;
			}
			if(p[1]==0 && p[2]!=0){
				dp[1][p[2]][i]=dp[2][p[2]][i]=dp[3][p[2]][i]=1;
			}
			if(p[1]!=0 && p[2]==0){
				dp[p[1]][1][i]=dp[p[1]][2][i]=dp[p[1]][3][i]=1;
			}
			if(p[1]!=0 && p[2]!=0){
				dp[p[1]][p[2]][i]=1;
			}
		}

		if(i>=3){
			if(p[i]==1){
				dp[1][1][i]=(dp[2][1][i-1]+dp[3][1][i-1])%10000;
				dp[2][1][i]=(dp[1][2][i-1]+dp[2][2][i-1]+dp[3][2][i-1])%10000;
				dp[3][1][i]=(dp[1][3][i-1]+dp[2][3][i-1]+dp[3][3][i-1])%10000;
			}
			if(p[i]==2){
				dp[2][2][i]=(dp[1][2][i-1]+dp[3][2][i-1])%10000;
				dp[1][2][i]=(dp[1][1][i-1]+dp[2][1][i-1]+dp[3][1][i-1])%10000;
				dp[3][2][i]=(dp[1][3][i-1]+dp[2][3][i-1]+dp[3][3][i-1])%10000;
			}
			if(p[i]==3){
				dp[3][3][i]=(dp[1][3][i-1]+dp[2][3][i-1])%10000;
				dp[1][3][i]=(dp[1][1][i-1]+dp[2][1][i-1]+dp[3][1][i-1])%10000;
				dp[2][3][i]=(dp[1][2][i-1]+dp[2][2][i-1]+dp[3][2][i-1])%10000;
			}
			if(p[i]==0){
				dp[1][1][i]=(dp[2][1][i-1]+dp[3][1][i-1])%10000;
				dp[2][1][i]=(dp[1][2][i-1]+dp[2][2][i-1]+dp[3][2][i-1])%10000;
				dp[3][1][i]=(dp[1][3][i-1]+dp[2][3][i-1]+dp[3][3][i-1])%10000;
				dp[2][2][i]=(dp[1][2][i-1]+dp[3][2][i-1])%10000;
				dp[1][2][i]=(dp[1][1][i-1]+dp[2][1][i-1]+dp[3][1][i-1])%10000;
				dp[3][2][i]=(dp[1][3][i-1]+dp[2][3][i-1]+dp[3][3][i-1])%10000;
				dp[3][3][i]=(dp[1][3][i-1]+dp[2][3][i-1])%10000;
				dp[1][3][i]=(dp[1][1][i-1]+dp[2][1][i-1]+dp[3][1][i-1])%10000;
				dp[2][3][i]=(dp[1][2][i-1]+dp[2][2][i-1]+dp[3][2][i-1])%10000;
			}
		}
	}

	      int ans=0;
	      for(i=1;i<=3;i++) for(j=1;j<=3;j++){
		     ans+=dp[i][j][N];
		     ans%=10000;
	      }

		cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1168
#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
int main(){
  
  int N;
  cin >> N;
  int ans = 0;

  for(int i=0;i<N;i++){
    int a;
    cin >> a;
    ans += a-1;
  }
  cout << ans <<endl;
  
  return 0;
}

Measured memory_bytes: 256
import heapq
INFTY = 10**15
n,m,s,t = map(int,input().split())
G = {}
for _ in range(m):
    u,v,a,b = map(int,input().split())
    if u not in G:
        G[u] = []
    G[u].append((v,a,b))
    if v not in G:
        G[v] = []
    G[v].append((u,a,b))
ce = [INFTY for _ in range(n+1)]
ce[s] = 0
hist = [0 for _ in range(n+1)]
heap = [(0,s)]
hist[s] = 1
while heap:
    c,x = heapq.heappop(heap)
    if c>ce[x]:continue
    hist[x] = 1
    for y,a,_ in G[x]:
        if hist[y]==0:
            if ce[y]>ce[x]+a:
                ce[y] = ce[x]+a
                heapq.heappush(heap,(ce[y],y))
cs = [INFTY for _ in range(n+1)]
cs[t] = 0
hist = [0 for _ in range(n+1)]
heap = [(0,t)]
hist[t] = 1
while heap:
    c,x = heapq.heappop(heap)
    if c>cs[x]:continue
    hist[x] = 1
    for y,_,b in G[x]:
        if hist[y]==0:
            if cs[y]>cs[x]+b:
                cs[y] = cs[x]+b
                heapq.heappush(heap,(cs[y],y))
F = [0 for _ in range(n+1)]
F[0] = INFTY
for i in range(1,n+1):
    F[i] = ce[i]+cs[i]
H = [0 for _ in range(n)]
H[n-1] = F[n]
for i in range(n-2,-1,-1):
    H[i] = min(H[i+1],F[i+1])
for i in range(n):
    print(10**15-H[i])

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

double calc(ll k, ll d) {
    ll res = 0;
    while (true) {
        if (d * pow(2, res) >= k) break;
        res += 1;
    }
    return pow(2.0, res);
}

int main() {
    ll n, k;
    cin >> n >> k;

    double res = 0;
    for(ll d = 1; d <= n; ++d) {
        res += 1.0 / calc(k, d);
    }
    res /= n;

    cout << setprecision(10) << res << endl;

    return 0;
}

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

#define endl '\n'
#define pb push_back
#define fi(a,b) for(i=a;i<=b;i++)
#define fj(a,b) for(j=a;j<=b;j++)
#define elif else if
#define ll  long long
#define vi vector<int>
#define vl vector<long long>
#define ii pair<int,int>
#define vii vector<ii>
#define ff first
#define ss second
#define speed() ios_base::sync_with_stdio(false); cin.tie(NULL);
#define mod 1000000007
#define PI 3.14159265358979323846
#define N 1000001



int main()
{
    int t=1;
    //cin>>t;
    while(t--)
    {
        int D,T,S;
        cin>>D>>T>>S;
        
        if(S*T>=D)  cout<<"Yes";
        else cout<<"No";
    }
}


Measured memory_bytes: 3592
#include <iostream>
using namespace std;
inline long long ask(long long x)
{
	return (x%4==1||x%4==2)+(x%2==0)*(x);
}
int main(int argc, char** argv) {
	long long l,r;
	cin >> l >> r;
	cout << (ask(r)^ask(l-1)); 
	return 0;
}

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

using namespace std;

int main(void){

    int n, m;
    cin >> n;
    vector<string> s(n);
    for(int i = 0;i < n;i++) cin >> s[i];
    cin >> m;
    vector<string> t(m);
    for(int i = 0;i < m;i++) cin >> t[i];

    int ans = 0;

    for(int i = 0;i < n;i++){
        int score = 0;
        for(int j = 0;j < n;j++) if(s[i] == s[j]) score++;
        for(int j = 0;j < m;j++) if(s[i] == t[j]) score--;
        ans = max(ans, score);
    }

    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stack>

int main ()
{
    std::stack<u_int> cars;
    u_int number;

    while(std::cin >> number){
        if(number != 0){
            cars.push(number);
        }else{
            std::cout << cars.top() << std::endl;
            cars.pop();
        }
    }
    
    return 0;
}

Measured memory_bytes: 1188
#include<bits/stdc++.h>
using namespace std;
#define INF 1e9
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
const int MOD = 1000000007;
const double PI = acos(-1);


void solve() {
  double a, b, h, m;
  cin >> a >> b >> h >> m;
  double ang = abs((m*6) - (h * 30 + m * 0.5));
  double ans = sqrt(pow(a,2) + pow(b,2) - 2.0 * a * b * cos(ang * PI / 180));
  cout << setprecision(12) << ans << endl;
}

int main() {
  solve();
  return 0;
}

Measured memory_bytes: 4108
/*                                  /   \                                 */      
/*                                 /*****\                               */
/*     Jai Shree Mataji           /       \ |\| |_| $ |-| K             */
#include<vector>
#include<iostream>
#include<algorithm>                
#include<string.h>                 
#include<bits/stdc++.h>            
#include<cstring>                  
#include<map>                     
#include<cmath>                  
#include<set>
using namespace std;            
#define ll long long int        
#define ld long double
#define MOD 1000000007 
#define PI 3.1415926535897932384626433832795                                               
#define YY cout<<"YES"
#define NN cout<<"NO"
#define ee cout<<"\n"
#define ne cout<<"-1"
#define pb push_back 
#define fi first
#define se second
#define mkp make_pair    
#define sall(v ) sort(v.begin(), v.end())      
#define all(v )  v.begin(), v.end()      
#define fo(i , n) for(ll i = 0 ; i < n ; i++)
#define vl vector<ll>
#define vll vector< pair<ll,ll> > 
#define mpl map<ll, ll>
#define pr pair<ll,ll>
ll pow1(ll n,ll p){if(p==0)return 1;ll x=pow1(n, p/2);x=(x*x);if(p%2==0) return x;else return (x*n);}
ll pd(ll x,ll y){if(x%y==0) return x/y;else return x/y+1;}  
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);	
	  ll t=1;


//	   cin>>t;
	      while(t--)
{
ll n;
cin>>n;
cout<<1-n;
ee;


		
}
return 0;
}









Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int ans1=0,ans2=0,n;
	string s;
	cin>>n>>s;
	for(int i=0;i<n;i++)
	 if(s[i]=='R')ans1++;
	 else ans2++;
	if(ans1>ans2)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

string divide[4] = {"dream", "dreamer", "erase", "eraser"};


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

    reverse(S.begin(), S.end());
    for (int i=0; i<4; ++i) reverse(divide[i].begin(), divide[i].end());

    bool can = true;

    for (int i=0; i<S.size();){
        bool can2 = false;
        for (int j=0; j<4; ++j){
            string d = divide[j];
            if (S.substr(i, d.size()) == d){
                can2 = true;
                i += d.size();
            }
        }

        if ( !can2 ){
            can = false;
            break;
        }
    }

    if (can) cout << "YES" << endl;
    else cout << "NO" << endl;
}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

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

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

    int l=1;
    rep(i,N){
        int a;cin>>a;l=lcm(a,l);
    }
    cout<<l<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
int n,a[3005];
ll f[3005][3005];
bool vis[3005][3005];
ll dfs(int l,int r)
{
	if(l>r)return 0;
	if(vis[l][r])return f[l][r];
	vis[l][r]=1;
	if((n-(r-l))&1)f[l][r]=max(dfs(l+1,r)+a[l],dfs(l,r-1)+a[r]);
	else f[l][r]=min(dfs(l+1,r)-a[l],dfs(l,r-1)-a[r]);
	return f[l][r];
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;++i)
		scanf("%d",a+i);
	printf("%lld\n",dfs(1,n));
	return 0;
}

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

using namespace std;

#define COUNTOF(array) (sizeof(array) / sizeof(array[0]))
#define OUT(P) cout << (P) << endl
#define OUT2(P1, P2) cout << (P1) << " " << (P2) << endl
#define PRINT_ARRAY(P) for(int i=0; i<P.size(); i++) cout << P[i] << endl;
#define PRINT_ARRAY_INLINE(P) do { for(int i=0; i<P.size(); i++) cout << P[i] << " "; cout << endl; } while(0)
#define PRINT_ARRAY_WITH_LABEL(L, P) do { cout << L << ": "; PRINT_ARRAY_INLINE(P); cout << endl; } while(0)
typedef long long ll;

int sum_digits(int num);
template <class T>
vector<T> copy_vector(vector<T> vec);
int gcd(int a, int b);

int main() {
    int r, g, b, n;
    cin >> r >> g >> b >> n;

    int count = 0;
    for(int i=0; i<=3000; i++) {
        int num_r = i * r; 
        for(int j=0; j<=3000; j++) {
            int num_g = j * g; 
            int k = (n - (num_r + num_g)) / b;
            int num_b = k * b;
            if(num_r + num_g + num_b == n && k >= 0) {
                count++;
            }
        }
    }
    cout << count << endl;
    return 0;
}

/******************************/
/***** DECRARED FUNCTIONS *****/
/******************************/

int sum_digits(int num) {
    int rtn = 0;
    while(num != 0) {
        int tmp = num % 10; 
        rtn += tmp;
        num /= 10; 
    }   
    return rtn;
}

// vectorのコピー
template <class T>
vector<T> copy_vector(vector<T> vec) {
    vector<T> rtn;
    rtn.reserve(vec.size());
    copy(vec.begin(), vec.end(), back_inserter(rtn));
    return rtn;
}

// ユークリウッドの互除法
int gcd(int a, int b) {
    if(b==0) return a;
    else return gcd(b, a % b);
}



Measured memory_bytes: 256
#include<algorithm>
#include <iostream>
#include<cstdio>
#include<cmath>
#include<iomanip>
#include<string>
using namespace std;
int main(){
   
    int a,b,c;
    cin>>a>>b>>c;
    
    int ans=3;
    
    if(a==b && b==c){
        ans=1;
    }else if(a==b && b!=c){
        ans=2;
    }else if(a==c && a!=b){
        ans=2;
    }else if(b==c && a!=b){
        ans=2;
    }
    
    cout<<ans<<endl;
    
    return 0;
   
}






Measured memory_bytes: 256
import sys
input = sys.stdin.readline


def main():
    H, N = map(int, input().split())
    A = []
    for _ in range(N):
        a, b = map(int, input().split())
        A.append((a, b))

    dp = [[float("inf") for j in range(H+1)] for i in range(N+1)]
    for i in range(N):
        for j in range(H+1):
            if j <= A[i][0]:
                dp[i+1][j] = min(dp[i][j], A[i][1])
            else:
                dp[i+1][j] = min(dp[i][j], dp[i+1][j-A[i][0]] + A[i][1])
#    [print(d) for d in dp]
    print(dp[N][H])


if __name__ == '__main__':
    main()


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

typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
 
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

int n,k;
string s;

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

    // initial
    int cnt = 0;
    int it = 0;
    int ans = 0;
    while(cnt<k) {
        if(it==n-1) {
            cout << n << endl;
            return 0;
        }
        else if(s[it]=='0' && s[it+1]=='1') {
            cnt++;
        }
        it++;
    }
    while(s[it]=='1') {
        it++;
        if (it==n) break;
    }
    ans = it;
    // syakutori
    int l = 0, r = it;
    int temp = ans;
    while(r<n) {
        bool flg = true;
        while(flg) {
            if(s[l]=='0' && s[l+1]=='1') flg = false;
            temp--;
            l++;
        }

        bool flg2 = true;
        while(flg2) {
            if(r==n) break;
            if(s[r]=='0' && s[r+1]=='1') {
                flg2 = false;
                temp++;
                r++;
                while(s[r]=='1') {
                    temp++;
                    r++;
                    if(r==n) break;
                }
            }
            else {
                temp++;
                r++;
            }
        }
        ans = max(ans,temp);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 512
judge=True
while judge:
    N=list(map(int,input().split()))
    if N[0] + N[1] == 0:
        judge = False
    else :
        for i in range(0,N[0]):
            for j in range(0,N[1]):
                print("#",end="")
            print("\n",end="")

        print("\n",end="")



Measured memory_bytes: 7012
def chk(innum):
  if 1<=innum and innum<=12:
    return "MM"
  elif 0<=innum and innum<=99:
    return "YY"

s=input()
front=int(s[0:2])
back=int(s[2:4])
ans=chk(front)+chk(back)
if ans=="YYYY":
  ans="NA"
elif ans=="MMMM":
  ans="AMBIGUOUS"
print(ans)

Measured memory_bytes: 3064
N = int(input())
A = list(map(int, input().split()))
mod = 1000000007
ans = 0
cs = [0]*N
cs[0] = A[0]

for i in range(1, N):
    cs[i] = cs[i-1] + A[i]

for i in range(N-1):
    n = A[i] * (cs[-1] - cs[i]) % mod
    ans += n
    ans %= mod

print(ans)

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

#define trace(...) __f( #__VA_ARGS__ , __VA_ARGS__ )
template <typename Arg1>
void __f( const char* name , Arg1&& arg1 ) {
        cerr << name << " : " << arg1 << "\n";
}
template <typename Arg1, typename... Args>
void __f( const char* na , Arg1&& arg1 , Args&&... args ) {
        const char* c = strchr( na + 1 , ',' );
        cerr.write( na , c - na ) << " : " << arg1 << " , ";
        __f( c + 1 , args... );
}
#define endl "\n"
#define all(V) V.begin(),V.end()
#define Unique(V) sort(all(V)),V.erase(unique(all(V)),V.end())
#define IO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long long int LL;
typedef pair <int,int> pii;
const int MOD = 1e9 + 7;
const int inf = 1e9;
const double EPS = 1e-9;
const double PI = acos(-1.0);
const long long INF = 1e18;
const int N = 1e5 + 5;

int main( ) {
        IO;
        #ifdef LOCAL
            freopen( "input.txt" , "r" , stdin );
        #endif // LOCAL
        int a , b;
        cin >> a >> b;
        cout << max( a + b , max( a - b , a * b ) ) << endl;
        return 0;
}










Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FALSE 0
#define TRUE 1

int main(){
    // int A, B, C;
    int N;
    vector<int>     vH(100010);
    // map<int64_t, int>   mP;
    string res;

    cin >> N;
    for (int i=0; i<N; i++){
        cin >> vH.at(i);
    }

    res = "Yes";

    // int nMinus = 0;
    int nowMax = 0;
    for (int i=0; i<N-1; i++){
        nowMax = max(nowMax, vH.at(i));
        if (vH.at(i) - vH.at(i+1) > 1){
            res = "No";
            break;
        }
        if (vH.at(i) - vH.at(i+1) == 1){
            if (nowMax != vH.at(i)){
                res = "No";
                break;
            }
        }

    }

    // if (nMinus > 1) res = "No";
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 640
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#define N 100005
using namespace std;
struct node {
    int s, t, order;
}a[N];
int n, c;
bool vst[N];
bool cmp(node x, node y) {
    return x.s < y.s;
}
int main() {
    int now, t, cnt = 0;
    scanf("%d%d", &n, &c);
    for(int i = 1; i <= n; i++) 
        scanf("%d %d %d", &a[i].s, &a[i].t, &a[i].order);
    
    // for(int i = 1; i <= n; i++)
    //     printf("%d %d %d\n", a[i].s, a[i].t, a[i].order);

    sort(a+1, a+1+n, cmp);
    for(int i = 1; i <= n; i++) {
        if(!vst[i]) {
            vst[i] = 1;
            cnt ++;
            now = a[i].t, t = a[i].order;
            // printf("start : %d: %d,%d,%d\n", cnt, a[i].s, a[i].t, a[i].order);
            for(int j = i+1; j <= n; j++) {
                if(!vst[j]) {
                    if((a[j].s > now) || (a[j].s == now && t == a[j].order)) {
                        now = a[j].t;
                        // printf("%d: %d,%d,%d\n", cnt, a[j].s, now, a[j].order);
                        t = a[j].order;
                        vst[j] = 1;
                    }
                }
            }

        }
    }
    printf("%d", cnt);
}

Measured memory_bytes: 1408
N, K = map(int, input().split()) # 横に2個

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
X = 10**4
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, X + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )


for i in range(1, K+1):
    ans = (cmb(N-K+1, i, mod) * cmb(K-1, i-1, mod)) % mod
    print(int(ans))

Measured memory_bytes: 4584
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
// #include <boost/multiprecision/cpp_int.hpp> 

#define gc getchar//_unlocked
#define pc putchar//_unlocked
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define pp pair<int,int>
#define ppl pair<ll,ll>
#define bigint boost::multiprecision::cpp_int
#define finp ios_base::sync_with_stdio(0);cin.tie(0);
#define bc __builtin_popcountll
#define afor(i,a,b) for(int i=a;i<=b;++i)
#define bfor(i,a,b) for(int i=a;i>=b;--i)
#define vi vector<int>
#define vpp vector<pp>
#define vll vector<ll>

using namespace std;
using namespace __gnu_pbds;

char putnb[20];
void putn(ll n) {if(!n)pc('0');if(n<0)pc('-'),n=0-n;int pi=0;while(n)putnb[pi++]=(n%10)+'0',n/=10;while(pi)pc(putnb[--pi]);}
void sci(int *x) {register char c = gc();*x = 0;for(; (c<48)||(c>57);c = gc());for(; (c>47)&&(c<58);c = gc())*x = (int)((((*x)<<1) + ((*x)<<3)) + c - 48);}
void scll(ll *x)  {register char c = gc();*x = 0;for(; (c<48)||(c>57);c = gc());for(; (c>47)&&(c<58);c = gc())*x =  (ll)((((*x)<<1) + ((*x)<<3)) + c - 48);}
ll fp(ll a,ll b,ll c) {if(b==0)return 1%c; if(b==1)return a%c; ll ret=fp(a,b/2,c); ret=(ret*ret)%c; if(b&1)ret=(ret*a)%c; return ret;}

const ll mod=1e9 +7;
const ll mod2=1999999973;
const ll inf=1e18;
const int infs=1e9 + 1000;
const int N=100000;
const long double PI = acos(-1);

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;


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

  if(x==1 || x==(2*n - 1))
  {
  	cout<<"No";
  	return 0;
  }

  cout<<"Yes\n";

  deque<int> ans;
  ans.pb(x);
  int bef = x-1;
  int af = x+1;

  afor(i,1,2*n - 2)
  {
  	if(i & 1)
  	{
  		if(bef>=1)ans.push_front(bef--);
  		if(af<=(2*n - 1))ans.pb(af++);
  	}
  	else
  	{
  		if(bef>=1)ans.pb(bef--);
  		if(af<=(2*n - 1))ans.push_front(af++);
  	}
  }

  afor(i,0,2*n - 2)
  {
  	cout<<ans[i]<<"\n";
  }
  
return 0;
}

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

int main(){

  
  int n,t,l,r,mx;
  n=0, t=0, l=0, r=0, mx=0;
  cin>>n>>t;
  int a[100001]={};


  for(int i=0;i<n;i++){
    cin >> l >> r;

    a[l]++;
    a[r]--;

  }

  for(int i=0;i<t;i++){
    a[i+1] += a[i];
  }

  for(int i=0;i<t;i++){
    mx =  max(mx,a[i]);


  }
  cout << mx << endl;
}
  







/*
  
  for(int i=0;i<n;i++){
    int l,r;
    cin>>l>>r;

    for(int x=l;x<r;x++){
      a[x]++;
    }
    
  }

  int ans=0;

  for(int i=0;i<t;i++){

    ans = max(ans, a[i] );
    
  }

  cout<<ans<<endl;
  
  return 0;

  
  int n ,t , l , r, mx ;
  int a[10001][10001] = { };
  int b[10001] ={}
  n = 0, t =0, l = 0, r =0;
  cin >> n >> t;
  
  for(int i=0;i<t;i++){

    for(int j=0;j<n;j++){
      cin >> l >> r;

      for(int k=l;k<=r;k++){
	a[j][k] = 1;
      }

    }



  }

  mx = 0;
  for(int i =0;i<n;i++)
    for(int j =0;j<k;j++){
      if(a[i][j] == 1) b[j]++;
  }

  for(int i=0;i<t;i++){
    max(mx)


  }



    
  }
  
}

*/



Measured memory_bytes: 3500
#include<stdio.h>

int n;
int A[2000];


int solve(int i, int m){
  int res;
  if(m == 0) return 1; //TRUE
  if(i >= n) return 0; //FALSE
  res = solve(i + 1, m) || solve(i + 1, m - A[i]);
  return res;
}

int main(){
  int i,q,res;
  int m[2000];
  scanf("%d",&n);
  for(i=0; i<n; i++){
    scanf("%d",&A[i]);
  }
  scanf("%d",&q);
  for(i=0; i<q; i++){
    scanf("%d",&m[i]);
    res = solve(0, m[i]);
    if(res == 1){
      printf("yes\n");
    }else{
      printf("no\n");
    }
  }

  return 0;
  
}



Measured memory_bytes: 2104
using System;
using System.IO;
using System.Collections.Generic;
using System.Numerics;

namespace abc142
{
    class Program
    {
        static void Main(string[] args)
        {
            //Console.SetIn(new StreamReader("input.txt"));
            solve_abc142B();
        }


        public static void solve_abc142B()
        {
            int[] nk = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            int n = nk[0];
            int k = nk[1];
            int[] h = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);

            int cnt = 0;

            for (int i = 0; i < n; i++)
            {
                if (h[i] >= k)
                {
                    cnt++;
                }
            }

            Console.WriteLine(cnt);
        }
        public static void solve_abc142A()
        {
            int n = Convert.ToInt32(Console.ReadLine());

            double res = n % 2 == 0 ? (double)(n / 2) / n : ((double)(n / 2) + 1) / n;

            Console.WriteLine("{0:F16}", res);
        }
    }
}


Measured memory_bytes: 17376
//Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>
using namespace std;
#define ios ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define endl '\n'
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
bool sortbysec(const pair<ll,ll>&a,const pair<ll,ll>&b)
{
    return (a.second<b.second);
}
int main()
{
    ios;
    int n,m,k;
    priority_queue<int>pq;
    cin>>n>>m;
    while(n--)
    {
        cin>>k;
        pq.push(k);
    }
    while(m--)
    {
        int l=pq.top();
        pq.pop();
        int t=l/2;
        pq.push(t);
    }
    ll sum=0;
    while(!pq.empty())
    {
        sum+=pq.top();
        pq.pop();
    }
    cout<<sum<<endl;




}
//Alhamdulillah

























Measured memory_bytes: 3832
use std::collections::BTreeMap;
use proconio::input;

fn main() {
    input! {
        n: usize,
        v: [usize; n]
    }
    
    let map = {
        let mut map = BTreeMap::new();
        for &x in &v {
            if let Some(&n) = map.get(&x) {
                map.insert(x,n+1);
            } else {
                map.insert(x,1);
            }
        }
        map
    };
    
    let ans = {
        let mut ans = 0;
        for (&x,&n) in map.iter() {
            if n >= x {
                ans += n-x;
            } else {
                ans += n
            }
        }
        ans
    };

    println!("{}",ans)

}

Measured memory_bytes: 6500
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef map<int, int> mi;
typedef set<int> si;
#define VV(T) vector<vector< T > >
#define dump(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl

#define rep(i, n) REP(i, 0, n)                              // 0, 1, ..., n-1
#define REP(i, x, n) for(int i = x; i < n; i++)             // x, x + 1, ..., n-1
#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(v) (v).begin() , (v).end()
#define RALL(v) (v).rbegin(), (v).rend()

#define pb push_back
#define pu push
#define mp make_pair
#define fi first
#define sc second

#define COUT(x) cout << (x) << endl
#define VECCIN(x) for(auto&youso_: (x) )cin>>youso_
#define VECCOUT(x) for(auto&youso_: (x) )cout<<youso_<<" ";cout<<endl

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


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

    string s; cin >> s;
    int K; cin >> K;
    set<string> ss;

    REP (i, 1, s.size()) {
        if (i > K) break;
        rep (j, s.size() - i + 1) {
            ss.insert(s.substr(j, i));
        }
    }
    ss.insert(s);
    int cnt = 1;
    string ans = "";
    for (auto iter = ss.begin(); iter != ss.end(); iter++) {
        if (cnt == K) {
            ans = *iter;
            break;
        }
        cnt++;
    }
    COUT(ans);
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cout<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cout<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 1120000000

template<typename T>
class SegTree {
public:
  int n;
  vector<T> data;
  vector<int> pos;
  SegTree(int n_){
    n=1;
    while(n<n_) n*=2;
    data.resize(2*n, INF);
    pos.resize(2*n, 0);
  }
  inline int query(int l, int r){ // position of min value
    int ret = 0;
    for(l+=n, r+=n; l<r; l/=2, r/=2){
      if(l&1){
        if(data[ret] > data[pos[l]]) ret = pos[l];
        l++;
      }
      if(r&1){
        r--;
        if(data[ret] > data[pos[r]]) ret = pos[r];
      }
    }
    return ret - n;
  }
  inline void update(int k, T a){
    k+=n;
    data[k]=a;
    pos[k]=k;
    while(k>0){
      k = k/2;
      if(data[pos[k*2]] < data[pos[k*2+1]]){
        pos[k] = pos[k*2];
      }
      else {
        pos[k] = pos[k*2+1];
      }
    }
  }
  inline T operator[](int idx){ return data[idx+n]; }
};


int main(){
  int n;
  cin>>n;
  vector<int> vec(n);
  rep(i,n) cin>>vec[i], vec[i]--;
  SegTree<int> st[2] = SegTree<int>(n);
  rep(i,n){
    st[i%2].update(i, vec[i]);
  }

  vector<int> ans;

  using P = pair<int,int>;
  priority_queue<pair<int,P>, vector<pair<int,P>>, greater<pair<int,P>>> pq;
  pq.push(mp(vec[st[0].query(0,n)], mp(0,n)));

  while(!pq.empty()){
    auto p = pq.top(); pq.pop();
    int l = p.se.fi, r = p.se.se;
    int p1 = st[l%2].query(l,r);
    int p2;
    bool sw = false;
    if((p1-l)%2==0) p2 = st[!(p1%2)].query(p1, r);
    else sw=true,p2 = st[!(p1%2)].query(l, p1);
    st[!(p1%2)].update(p2, INF);
    st[(p1%2)].update(p1, INF);

    if(sw) swap(p1,p2);
    ans.pb(vec[p1]);ans.pb(vec[p2]);

    auto ins = [&](int a, int b){
      if(a==b) return;
      pq.push(mp(vec[st[a%2].query(a,b)], mp(a,b)));
    };

    ins(l,p1);
    ins(p1+1,p2);
    ins(p2+1,r);
  }

  rep(i,n) cout << ans[i]+1 << " \n"[i==n-1];

  return 0;
}


Measured memory_bytes: 11944
#include <stdio.h>
#define N 1000000
int a[N+1];
int dp[N+1];

int min(int a, int b){
  if(b>a)return a;
  else return b;
}
int abs(int a){
  if(a<0)return -1*a;
  else return a;
}
int main(){
   int i,j, n, k;
   scanf("%d %d", &n, &k);
   for(i=0;i<n;i++)scanf("%d", &a[i]);
   for(i=0;i<n;i++)dp[i]=1e10;

   dp[0]=0;

   for(i=0;i<n;i++){
     for(j=1;j<k+1;j++){
       dp[i+j]=min(dp[i+j], dp[i]+abs(a[i]-a[i+j]));
     }
   }

   printf("%d\n", dp[n-1]);


   return 0;
 }



Measured memory_bytes: 4608
#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define mk make_pair
#define fi first
#define se second
#define vll vector<ll>
#define pii pair<ll,ll>
#define vvll vector< vector<ll> >
#define pb push_back
#define sz(v) (v).size()
#define inf 1e18
#define md 1000000007
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define tel(a){cout<<a<<"\n";}
#define tell(a,b){cout<<a<<" | "<<b<<"\n";}
#define telll(a,b,c){cout<<a<<" | "<<b<<" | "<<c<<"\n";}
#define teln(v,n){cout<<"v- ";rep(i,0,n)cout<<v[i]<<" ";cout<<"\n";}
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define tihs if(fopen("inp.txt","r"))freopen("inp.txt", "r", stdin),freopen("out.txt", "w", stdout);
using namespace std;
#define TRACE
 
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
 

#define M 2010

ll n,a[M];
ll dp[M][M];
vector<pii>v;
ll f(ll i,ll cnt){
	if(i>=n)return 0;
	if(dp[i][cnt]!=-1)return dp[i][cnt];
	ll ans=v[i].fi*abs(v[i].se-cnt)+f(i+1,cnt+1);
	ans=max(ans,v[i].fi*abs(v[i].se-(n-i+cnt-1))+f(i+1,cnt));
	return dp[i][cnt]=ans;
}
int main(){
	IOS;
	tihs;

	
	memset(dp,-1,sizeof(dp));
	cin>>n;
	rep(i,0,n)cin>>a[i],v.pb({a[i],i});
	sort(v.rbegin(),v.rend());
	cout<<f(0,0);



	return 0;
}





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

#define sws ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define INFINITO 1000000000
#define ll long long
#define vi vector<int>
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
#define ff first
#define ss second
#define vvi vector<vi>
#define all(x) x.begin(), x.end()
#define fo(i, n) for( int i = 0; i < n; i++ )


int main() {

    int a, b;
    cin >> a >> b;

    int at = a / 0.08;
    while ( (int) (at * 0.08) != a or b != (int) (at * 0.1) ) {
        // cout << at * 0.08 << " | " << (int) (at * 0.1) << endl;
        at++;
        if ( (int) (at * 0.1) > b ) {
            cout << -1 << endl;
            return 0;
        }
    }

    cout << at << endl;


    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll n,i,j,k,l,a,b,c,d,x;
    vector<ll>vc;
    cin>>n>>x;
    for(i=0;i<n;i++)
    {
        cin>>k;
        l=abs(x-k);
        vc.push_back(l);
    }
    a=vc[0];
    b=__gcd(a,a);
    for(i=1;i<vc.size();i++)
    {
        d=vc[i];
        c=__gcd(b,d);
        b=c;
    }
    cout<<b<<endl;
    return 0;
}


Measured memory_bytes: 1400
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <utility>
#include <cmath>
#include <bitset>
#include <map>

#define INF_LL 9000000000000000000
#define INF 2000000000

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

using namespace std;

typedef long long ll;
typedef pair<int, int> PII;

class Union_find{
private:
	vector<int> par;
	vector<int> rank;
	int n;

public:
	Union_find(int a){
		n = a;
		for(int i = 0;i < n;i++){
			par.push_back(i);
			rank.push_back(0);
		}
	}

	int find(int x){
		if(par[x] == x){
			return x;
		}else{
			return par[x] = find(par[x]);
		}
	}

	void unite(int x, int y){
		x = find(x);
		y = find(y);
		if(x == y) return;

		if(rank[x] < rank[y]){
			par[x] = y;
		}else{
			par[y] = x;
			if(rank[x] == rank[y]) rank[x]++;
		}
	}

	bool same(int x, int y){
		return find(x) == find(y);
	}
};

int main(){
	int k, s;
	ll res = 0;
	cin >> k >> s;
	REP(i, k+1){
		REP(j, k+1){
			if(0 <= s-i-j && s-i-j <= k) res++;
		}
	}
	cout << res << endl;
}


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

typedef long long ll;

int k, x;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> k >> x;
    if (k * 500 >= x)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

    return 0;
}



Measured memory_bytes: 256
using System;
using System.Linq;

class P
{
  static void Main()
  {
    var a = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
    var ans = 0;
    for(var i=a[0]; i<=a[1]; i++)
      ans += Convert.ToInt32(a[2] % i == 0);
    Console.WriteLine(ans);
  }
}

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

#define int long long
#define pb push_back
#define ff first
#define ss second

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    int n;
    cin>>n;
    
    if(n%1000==0)
        cout<<0;
    else
    {
        int temp=n/1000;
        temp++;
        cout<<temp*1000-n;
    }
}

Measured memory_bytes: 3660
#include <iostream>
#include <string>
#include <vector>
#define rep(i, k, n) for (int i=k; i<n; i++)

int main() {
    std::vector<std::string> data;
    std::string tmp;
    while(std::cin >> tmp) {
        data.push_back(tmp);
    }

    std::vector<int> ReversePolishNotation(std::vector<std::string> data);
    std::vector<int> answer = ReversePolishNotation(data);
    std::cout << answer.at(0) << std::endl;
}

std::vector<int> ReversePolishNotation(std::vector<std::string> data) {
    std::vector<int> tmp;
    for(std::string elem: data ) { // for range
        if (elem=="+" || elem=="-" || elem=="*") {
            int y = tmp.back(); // get a last element.
            tmp.pop_back(); // delete the last element.
            int x = tmp.back();
            tmp.pop_back();
            if (elem =="+") tmp.push_back(x+y);
            else if (elem== "-") tmp.push_back(x-y);
            else if (elem== "*") tmp.push_back(x*y);
            continue;
        }
        tmp.push_back(std::stoi(elem));
    }
    return tmp;
}


Measured memory_bytes: 3192