akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;

namespace ABC
{
    class Program
    {
        static void Main(string[] args)
        {
            ABC111_B();
        }

        static void ABC111_B()
        {
            var N = Console.ReadLine();
            while (true)
            {
                if (N.All(x => x == N[0]))
                    break;

                N = (int.Parse(N) + 1).ToString();
            }
            Console.WriteLine(N);
        }
    }
}

Measured memory_bytes: 13268
#include<stdio.h>
int main()
{
	int x;
	scanf("%d",&x);
	int lose=0;
	while(x!=0)
	{
		if(x%10==9)
		{
			lose=1;	
			break;
		}
		x=x/10;
	}
	if(lose)
		printf("Yes\n");
	else
		printf("No\n");
		return 0;
	
}

Measured memory_bytes: 128
import heapq

V, E, start = map(int, input().split())
G = [[] for _ in range(V)]
for i in range(E):
    si, ti, di = map(int, input().split())
    G[si].append((ti, di))

d = [float('INF')] * V
used = [False] * V
prev = [-1] * V

def Dijkstra(s):
    d[s] = 0
    q =[]
    heapq.heappush(q, (0, s))
    while len(q) > 0:
        dist, v  = heapq.heappop(q)
        if d[v] < dist:
            continue
        for j, cost in G[v]:
            if d[j] > d[v] + cost:
                d[j] = d[v] + cost
                heapq.heappush(q, (d[j], j))
                prev[j] = v

Dijkstra(start)
for i in range(V):
    if d[i] == float('inf'):
        print('INF')
    else:
        print(d[i])



Measured memory_bytes: 90816
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;

string bit(int n,int m){
  string ans="";
  for(int i=0;i<m;i++){
    char c=n%2+'0';
    ans=c+ans;
    n/=2;
  }
  return ans;
}

int main(){
  int n,g;
  cin >> n >> g;
  int a[n],b[n];
  for(int i=0;i<n;i++){
    cin >> a[i] >> b[i];
  }
  int ans=1000;
  int c[n];
  for(int i=0;i<n;i++){
    c[i]=(i+1)*100*a[i]+b[i];
  }
  for(int i=0;i<(int)pow(2,n);i++){
    string s=bit(i,n);
    int x=g;
    int count=0;
    for(int j=0;j<n;j++){
      if(s.at(j)=='1'){
        x-=c[j];
        count+=a[j];
      }
    }
    if(x>0){
      int y=100;
      for(int j=0;j<n;j++){
        if(s.at(j)=='0'){
          y=j+1;
        }
      }
      int z=(x-1)/(y*100)+1;
      if(y==100){
        count=1000;
      }
      else if(z<=a[y-1]){
        count+=z;
      }
      else{
        count=1000;
      }
    }
    ans=min(ans,count);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
from sys import stdin
from itertools import repeat
def f(a):
    n = len(a)
    l = [0] * (n + 1)
    st = [(0, 0, 0, 1)]
    pu = st.append
    po = st.pop
    for i in xrange(1, n):
        ad = 0
        r = i
        u = 0
        k = 1
        while st:
            y = a[r] << u
            x = a[st[-1][0]]
            if x >= y:
                break
            _, r, u, q = po()
            c = 0
            while x < y:
                x *= 4
                c += 2
            ad += c * q
            k += q
            u += c
        pu((i, r, u, k))
        l[i+1] = l[i] + ad
    return l
 
def main():
    n = int(stdin.readline())
    a = map(int, stdin.readline().split(), repeat(10, n))
    l = f(a)
    r = f(a[::-1])[::-1]
    ans = 10 ** 12
    for i in xrange(n + 1):
        if ans > l[i] + i + r[i]:
            ans = l[i] + i + r[i]
    print ans
main()


Measured memory_bytes: 42696
n = int(input())

a = []
for i in range(n):
    a.append(int(input()))

l = [False] * n
p = 0
f = False
cnt = 0
while not l[p]:
    cnt += 1
    l[p] = True
    p = a[p] - 1
    if (p == 1):
        f = True
        break

print(cnt if f else -1)


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

bool IsPrime(int num){
    if(num < 2) return false;
    if(num == 2) return true;
    if(num % 2 == 0) return false;
    double sqnum = sqrt(num);
    for(int i = 3;i<=sqnum;i+=2){
        if(num % i == 0) return false;
    }
    return true;
}

int NextPrime(int x){
    while(!IsPrime(x)) x++;
    return x;
}

int main(){
    int x; cin >> x;
    int res = NextPrime(x);
    cout << res << endl;
}

Measured memory_bytes: 256
# coding: utf-8
from collections import deque
K = int(input())
queue = [str(i) for i in range(1, 10)]
# print(queue)
queue = deque(queue)
L = []
cnt = 0
while cnt < K:
    v = queue.popleft()
    # L.push(int(v))
    L.append(int(v))
    if v[-1] == "0":
        # print("v =", v)
        queue.append(v + v[-1])
        queue.append(v+"1")
        
    elif v[-1] == "9":
        # print("9", v)
        queue.append(v + "8")
        queue.append(v + v[-1])
    else:
        # print("else", v)
        t = int(v[-1])
        queue.append(v+str(t-1))
        queue.append(v + v[-1])
        queue.append(v+str(t+1))
    cnt += 1
print(v)

Measured memory_bytes: 20872
#include <bits/stdc++.h>
typedef long long ll;

const int N=3005,P=998244353;
int A,B,C,D;
int f[N][N];

inline void Inc(int &x){x>=P?x-=P:0;}
ll Pow(ll a,ll b,ll s=1){for(;b;b>>=1,a=a*a%P)if(b&1)s=s*a%P;return s;}

int main()
{
	scanf("%d%d%d%d",&A,&B,&C,&D);
	for(int i=1;i<=3000;++i)
		for(int j=1;j<=3000;++j)
			if(i<A||j<B)continue;
			else if(i==A&&j==B)f[i][j]=1;
			else
				f[i][j]=((ll)f[i-1][j]*j+(ll)f[i][j-1]*i-(ll)f[i-1][j-1]*((i-1)*(j-1))%P+P)%P;
	/*for(int i=1;i<=C;++i)
		for(int j=1;j<=D;++j)
			printf("%d%c",f[i][j],j==D?'\n':' ');*/

	return printf("%d\n",f[C][D]),0;
}

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


def main():
    N, A, B = map(int, input().split())
    ans = 0

    # 線形探索（O(n))
    # for n in range(N + 1):
    #     if A <= sum(list(map(int, str(n)))) <= B:
    #         ans += n

    # bit探索(O(log n))
    for i in range(N + 1):
        each_digits_total = 0
        j = i
        while j > 0:
            each_digits_total += j % 10
            j //= 10
        if A <= each_digits_total <= B:
            ans += i
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,x,a,ans=1;
	cin>>n>>x;
	for(int i=1;i<n;i++){
		cin>>a;
		if(a<x){
			ans++;
			x=a;
		}
	}
	cout<<ans;
	return 0;
} 

Measured memory_bytes: 384
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

int parent[110];
int root(int x) { return parent[x] < 0 ? x : parent[x] = root(parent[x]); }
bool unionSet(int x, int y) {
  x = root(x); y = root(y);
  if (x == y) { return false; }
  if (parent[x] > parent[y]) { swap(x, y); }
  parent[x] += parent[y];
  parent[y] = x;
  return true;
}

struct Edge {
  int from;
  int to;
  int cost;
  Edge() {;}
  Edge(int f, int t, int c) : from(f), to(t), cost(c) {;}
  bool operator<(const Edge &rhs) const { return cost < rhs.cost; }
};

Edge edges[100000];

int main() {
  int n, m;
  while (scanf("%d %d", &n, &m), n|m) {
    REP(i, m) {
      int f, t, c;
      scanf("%d %d %d", &f, &t, &c);
      edges[i] = Edge(f, t, c);
    }
    sort(edges, edges + m);
    int ans = 1 << 30;
    REP(i, m) {
      MEMSET(parent, -1);
      if (i != 0 && edges[i].cost == edges[i - 1].cost) { continue; }
      int sum = 0;
      FOR(j, i, m) {
        //if (edges[j].cost - edges[i].cost >= ans) { break; }
        if (unionSet(edges[j].from, edges[j].to)) {
          sum++;
          if (sum == n - 1) {
            ans = min(ans, edges[j].cost - edges[i].cost);
            break;
          }
        }
      }
      if (sum != n - 1) { break; }
    }
    if (ans == (1 << 30)) { ans = -1; }
    printf("%d\n", ans);
  }
}

Measured memory_bytes: 940
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(void){
    // Your code here!
    int N,M,cnt=0;
    scanf("%d%d",&N,&M);
    int a[M+1],b[M+1];
    for(int i=0;i<M;i++){
        cin>>a[i];
        cin>>b[i];
    }
    for(int i=1;i<=N;i++){
        cnt=0;
        for(int j=0;j<M;j++){
            if(a[j]==i){cnt+=1;}
            if(b[j]==i){cnt+=1;}
        }
        cout<<cnt<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iostream>

using namespace std;

const int maxn = 1e5 + 5;

int h[maxn] = {0};
int dp[maxn] = {0};

int Fact(int i, int k)
{
	if(i <= k + 1)
	{
		int min = dp[1] + abs(h[i] - h[1]);
		for(int j = 1; j < i; j++)
		{
			if(dp[j] + abs(h[i] - h[j]) < min)
			{
				min = dp[j] + abs(h[i] - h[j]);
			}
		}
		return min;
	}
	else
	{
		int min = dp[i - k] + abs(h[i] - h[i - k]);
		for(int j = i - k; j < i; j++)
		{
			if(dp[j] + abs(h[i] - h[j]) < min)
			{
				min = dp[j] + abs(h[i] - h[j]);
			}
		}
		return min;
	}
}

int main()
{
	int n,k;
	scanf("%d %d",&n,&k);
	for(int i = 1; i <= n; i++)
	{
		scanf("%d",&h[i]);
	}
	for(int i = 1; i <= n; i++)
	{
		if(i == 1)
		{
			dp[i] = 0;
		}
		else if(i == 2)
		{
			dp[i] = abs(h[2] - h[1]);
		}
		else
		{
			dp[i] = Fact(i,k);
		}
	}
	printf("%d\n",dp[n]);
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int n,k;
int r,l;
long MIN =999999999999;
vector<long> x(100000);

int minf(int N,int K,vector<long> X)
{
 for(int i = 0;i <= N-K;i++)
 {
  r = i;l = i+K-1;
        long temp = min(abs(X[r])+abs(X[r]-X[l]),abs(X[l])+abs(X[l]-X[r])); 
        if(MIN > temp)
         MIN = temp;
 }
 return MIN; 
}
int main(){
 cin >> n >> k;
 for(int i = 0;i < n;i++) scanf("%ld",&x[i]);
 
 cout << minf(n,k,x) << endl;
 return 0;
}


Measured memory_bytes: 1792
#解答例
N,M=map(int,input().split())
A=list(map(int,input().split()))#使える数字の種類
weight=[0,2,5,5,4,5,6,3,7,6]#作るのに何本必要か、また0は作れないので0になっている
dp=[-1]*(N+1)#とりあえずこれくらい確保しておけばok
dp[0]=0#0本では0しか作れない
#dp[i]はちょうどi本で作れる最高の数を入れることにする
for i in range(N+1):#N本あるから、一本ずつ増やしていって最大N本
    for a in A:
        if i+weight[a]<N+1:#今あるi本にa本を加えてもN本を超えないか
            dp[i+weight[a]]=max(dp[i+weight[a]],dp[i]*10+a)#今まで作ったi+weight[a]のときのdpの値と、今作ったdp[i]*10+aの値を比べ、大きい方を格納する
                                                           #なぜdp[i]*10+aになるのかに関しては、右から数字を追加していく場合のみを考えることで、重複せずに全通り試せるから
print(dp[N])

Measured memory_bytes: 14692
N=int(input())
h=list(map(int,input().split()))

hmin=min(h)
count=0
while hmin<10**6:
    flag=False
    for i in range(N):
        if h[i]<10**6:
            if flag==False:
                count+=hmin
                flag=True
    
            if h[i]==hmin:
                h[i]+=10**6
            else:
                h[i]-=hmin
        else:
            flag=False

    hmin=min(h)
print(count)
            

Measured memory_bytes: 3064
//do not think about past and stay in this moment
//organize and work - Abhinav IIITA
#include <bits/stdc++.h>
#include <ctime>
using namespace std;
#define int long long
#define ld long double
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end() 
const ld pi = acos(-1.0);
const int day[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());


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

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

void solve(){
	int n,s;
	cin>>n>>s;
	s/=1000;
	for(int i=0;i<=s/10;++i){
		for(int j=0;j<=s/5;++j){
			int r=s-i*10-j*5;
			if(r<0)
			break;
			if((i+j+r)==n && r>=0){
				cout<<i<<" "<<j<<" "<<r;
				return ;
			}
		}
	}
	cout<<"-1 -1 -1";
}


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


int32_t main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); 	
	int t=1;
	//cin>>t;
	while(t--)
	solve();
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
int main(){
	int n,i,a;
	std::cin >> n;
	for (i = 1; i <= n; i++){
		if (i % 3 == 0){
			std::cout << " " << i;
		}
		else{
			a = i;
			while (true){
				
				if (a ==0){
					break;
				}
				else if(a % 10 == 3){
					std::cout << " " << i;
					break;
				}
				else{
					a /= 10;
				}
			}
		}
	}std::cout << "\n";
	return 0;
}

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

int main(){
    string s; cin >> s;
    string t = "CODEFESTIVAL2016";
    int c = 0;
    for(int i = 0; i < 16; i++){
        if(s[i] != t[i])c++;
    }
    cout << c  << endl;

    return 0;
}

Measured memory_bytes: 256
n=int(input())
mod=10**9+7

def d(s):
    if "AGC" in s:
        return False
    for i in range(3):
        l=list(s)
        l[i],l[i+1]=l[i+1],l[i]
        if "AGC" in "".join(l):
            return False
    return True

m=[{} for i in range(n+1)]
def f(num,s):
    if s in m[num]:
        return m[num][s]
    if num==n:
        return 1
    ans=0
    for c in "ACGT":
        if d(s+c):
            ans=(ans+f(num+1,s[1:3]+c))%mod
    m[num][s]=ans
    return ans

print(f(0,"PPP"))
        
        





Measured memory_bytes: 3888
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <vector>
#include <functional>
#include <queue>
#include <unordered_set>
#include <climits>
#include <set>
#include <list>
#include <cmath>
#include <map>

using namespace std;
typedef long long ll;

int main()
{
	ll N;
	cin >> N;
	vector<ll> Count;
	ll N_first = N;
	if(N == 1){
		cout << 0 << endl;
		return 0;
	}
	
	ll max = 1000001;
	ll ans = 0;
	int count = 0;
	for(ll i = 2; i <= max;i++){
		// cout << N << " " << i << endl;
		if(N % i == 0){
			//cout << i << endl;
			count++;
			N /= i;
			i -= 1;
		}else if(count > 0){
			int num = 1;
			while(count >= num){
				ans++;
				count -= num;
				num++;
			}
			count = 0;
		}
	}
	
	if(N > 1) ans++;
	if(N == N_first) ans = 1;
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define BIG 1000000010
#define EPS 1e-9
#define fst first
#define scd second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"


signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  int n,k;
  string s;
  cin>>n>>k>>s;
  vector<int> v;
  int a=1;
  int ans=0;
  repi(i,1,s.size() ){
    if(s[i]==s[i-1]){
      a++;
      ans++;
    }else{
      v.push_back(a);
      a=1;
    }
  }
  v.push_back(a);
  int num=v.size();
  //cout<<num<<endl;
  rep(i,k){
    if(num>2){
      ans+=2;
      num-=2;
    }else if(num==2){
      ans+=1;
      break;
    }else break;
  }
  cout<<ans<<endl;
    
  return 0;
}


Measured memory_bytes: 1480
#include <bits/stdc++.h>
#include <string>
#include <vector>
/* 変数i を n回繰り返すマクロ */
#define rep(i,n) for (int i = 0;i < (n);i++)
typedef long long ll;
using namespace std;

ll REC(ll hp){
    if(hp == 1){
        return 1;
    }
    return 2*REC(hp/2)+1;
}
int main()
{
    cout << fixed << setprecision(10);//小数点以下10桁出力
    ll h;
    cin >> h;
    cout << REC(h) << endl;
    return 0;
}

Measured memory_bytes: 256
n,m = map(int, input().split())
H = [int(a) for a in input().split()]
ans= [1] * n
for i in range(m):
    a, b = map(int, input().split())
    if H[a-1] > H[b-1]:
        ans[b-1] = 0
    elif H[a-1] == H[b-1]:
        ans[a-1] = 0
        ans[b-1] = 0
    elif H[a-1] < H[b-1]:
        ans[a-1] = 0
print(sum(ans))

Measured memory_bytes: 84948
"use strict"
 
function Main(input) {
  input = input.trim().split(' ').map(Number);
 
  if(input[0] <= 10) {
    console.log(input[1] + (100 * (10 - input[0])));
  } else {
    console.log(input[1]);
  }
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

struct data{
  int key;
  struct data *right,*left,*parent;
};

struct data *root,*NIL;

void insert(int k){
  struct data *y = NIL;
  struct data *x = root;
  struct data *z;

  z = (struct data *)malloc(sizeof(struct data));
z -> key = k;
z -> left = NIL;
z -> right = NIL;

while(x != NIL){
  y = x;
  if(z -> key < x -> key){
    x = x -> left;
  }
  else{
    x = x -> right;
  }
}

z -> parent = y;
if(y == NIL){
  root = z;
}
else{
  if(z -> key < y -> key){
    y -> left = z;
  }
  else{
    y -> right = z;
  }
}
}

void inorder(struct data *cin){
  if(cin == NIL){
    return;
  }
  inorder(cin -> left);
  printf(" %d",cin -> key);
  inorder(cin -> right);
}
void preorder(struct data *cin){
  if(cin == NIL){
    return;
  }
  printf(" %d",cin -> key);
  preorder(cin -> left);
  preorder(cin -> right);
}

int main(){
  int n,i,x;
  char mozi[1000];

  scanf("%d",&n);

  for(i = 0;i < n;i++){
    scanf("%s",mozi);
    if(strcmp(mozi,"insert") == 0){
      scanf("%d",&x);
      insert(x);
    }
    else if(strcmp(mozi,"print") == 0){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }
  return 0;
}



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

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define per(i,n) for(int i = (n)-1; i >= 0; --i)
#define rng(i,a,b) for(int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()

int main() {
    int n; cin >> n;
    vl cnt(n,0);
    rep(i,n-1) {
        int a; cin >> a;
        cnt[a-1]++;
    }
    rep(i,n) {
        cout << cnt[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 4844
using System;

public class Program
{
    public void Solve()
    {
        var sc = new Scanner();
        bool[] f = new bool[100001];
        f[0] = true;
        for (int i = 0; i <= 100000; i++)
        {
            if (f[i])
            {
                for (int j = 100; j <= 105; j++)
                {
                    if (i + j <= 100000)
                    {
                        f[i + j] = true;
                    }
                }
            }
        }

        int x = sc.NextInt();
        Console.WriteLine(f[x] ? "1" : "0");
    }

    public static void Main(string[] args)
    {
        new Program().Solve();
    }
}

class Scanner
{
    public Scanner()
    {
        _pos = 0;
        _line = new string[0];
    }

    const char Separator = ' ';
    private int _pos;
    private string[] _line;

    #region スペース区切りで取得

    public string Next()
    {
        if (_pos >= _line.Length)
        {
            _line = Console.ReadLine().Split(Separator);
            _pos = 0;
        }

        return _line[_pos++];
    }

    public int NextInt()
    {
        return int.Parse(Next());
    }

    public long NextLong()
    {
        return long.Parse(Next());
    }

    public double NextDouble()
    {
        return double.Parse(Next());
    }

    #endregion

    #region 型変換

    private int[] ToIntArray(string[] array)
    {
        var result = new int[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = int.Parse(array[i]);
        }

        return result;
    }

    private long[] ToLongArray(string[] array)
    {
        var result = new long[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = long.Parse(array[i]);
        }

        return result;
    }

    private double[] ToDoubleArray(string[] array)
    {
        var result = new double[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = double.Parse(array[i]);
        }

        return result;
    }

    #endregion

    #region 配列取得

    public string[] Array()
    {
        if (_pos >= _line.Length)
            _line = Console.ReadLine().Split(Separator);

        _pos = _line.Length;
        return _line;
    }

    public int[] IntArray()
    {
        return ToIntArray(Array());
    }

    public long[] LongArray()
    {
        return ToLongArray(Array());
    }

    public double[] DoubleArray()
    {
        return ToDoubleArray(Array());
    }

    #endregion
}

Measured memory_bytes: 13160
#include "bits/stdc++.h"
using namespace std;

int main(){

    int N;
    cin >> N;
    int sum = 0, mx = 0;
    for(int i = 0; i < N; i++){
        int l;
        cin >> l;
        sum += l;
        mx = max(mx, l);
    }
    if(mx < sum-mx)cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

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

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;


int main(){
    int N,K;
    cin >> N >> K ;

    if(N % K == 0) cout << 0 << endl;
    else           cout << 1 << endl; 
    
}





Measured memory_bytes: 256
export class Main {
  static main(input: string): string {
    const [nStr, aStr] = input.split("\n");
    const n = Number(nStr);
    const aList = aStr.split(" ").slice(0, n).map(Number);
    let result = Main.gcd(aList[0], aList[1]);
    for (let i = 2; i < n; i++) {
      if (result == 1) {
        break;
      }
      result = Main.gcd(result, aList[i]);
    }
    return `${result}`;
  }
  
  private static gcd(a: number, b: number): number {
    if (a == 0 || b == 0) {
      return 0;
    }
    let r = a;
    let tmp = b;
    while (tmp > 0) {
      let t = r % tmp;
      r = tmp;
      tmp = t;
    }
    return r;
  }
}
console.log(Main.main(require("fs").readFileSync("/dev/stdin", "utf8")));

Measured memory_bytes: 28120
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<queue>
using namespace std;
typedef long long ll;
//Global
int x, y;
const int MAX_N = 20;
char maze[MAX_N][MAX_N];
const int INF = 1000000;
int X, Y;//"@"???????????????
int memo[MAX_N][MAX_N];
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };
int counter;

void bsd(int a, int b) {
	maze[b][a] = '#';
	memo[b][a] = INF;
	counter++;
	for (int i = 0; i < 4; i++) {
		int nx = a + dx[i];
		int ny = b + dy[i];
		if (memo[ny][nx] == 0 && maze[ny][nx] == '.' && 0 <= nx && nx < x && 0 <= ny && ny < y) {
			bsd(nx, ny);
		}
	}

}



//solve
//??±???????????¢?´¢??§"@"??¨???????????£?????????"."????????°????±???????
void solve()
{
	//memo????????????
	for (int i = 0; i < y; i++) {
		for (int j = 0; j < x; j++) {
			memo[i][j] = 0;
		}
	}

	//"@"??¨??£??\????????????  ??????  INF??§??????  ??????  ????????????????????£?????????????????????"."??§??????
	counter = 0;//"@"??????
	bsd(X, Y);


	cout << counter << endl;

}







//main
int main()
{
	while (true) {
		cin >> x >> y;
		if (x == 0 && y == 0)break;
		//"W"??¨"."??¨"@"?????\???
		for (int i = 0; i < y; i++) {
			for (int j = 0; j < x; j++) {
				cin >> maze[i][j];
				if (maze[i][j] == '@') {
					X = j; Y = i;//@???????????????????¨????
				}
			}
		}
		solve();
	}
    return 0;
}

Measured memory_bytes: 1168
#include<stdio.h>

int judge(int middle, int k, int n, int w[], int maxw)
{
    if (middle < maxw){
        return 0;
    }

    int sum = 0;
    int cnt = 1;

    for (int i = 0; i < n; i++){
        sum += w[i];

        if (sum > middle){
            sum = w[i];
            cnt ++;
        }            
    }

    if (cnt <= k) return 1;
    else return 0;
}

int main()
{
    int n, k;
    int sum = 0;

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

    int w[n];
    int maxw = 0;

    for (int i = 0; i < n; i++){
        scanf("%d", &w[i]);

        maxw = (maxw < w[i]) ? w[i] : maxw;

        sum += w[i];      
    }

    int min = sum / k;   
    int max = 2 * min + 1;
    min = (min > maxw) ? min : maxw;
    int middle;
    
    while(min <= max){
        middle = (min + max) / 2;
        
    
        if (judge(middle, k, n, w, maxw)) {
            if (judge(middle - 1, k, n, w, maxw) != 1) {
                printf("%d\n", middle);
                break;
            }else 
                max = middle - 1;
        }
        else
            min = middle + 1;
    }


    


}


Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;

int main() {
    string A, s, C;
    cin >> A >> s >> C;
    cout << 'A' << s[0] << 'C' <<endl;
}


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

#define pout(n)  printf ("%d\n", n)

#define rep(i,a,n) for (int i = a;i < n;i++)
#define per(i,n,a) for (int i = n-1;i >= a;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());

const int d4x[4] = {1, 0, -1, 0};
const int d4y[4] = {0, 1, 0, -1};
const int d8x[8] = { 1,1,0,-1,-1,-1,0,1 };
const int d8y[8] = { 0,1,1,1,0,-1,-1,-1 };

#define MAX_N (int)2e5+20
#define INF 1e12+20

typedef long long ll;
using namespace std;

int n;
int ans = 0;
int main() {
    scanf("%d",&n);
    vector<int>a(n);
    rep(i,0,n) cin >> a[i];

    sort(a.begin(),a.end());
    reverse(a.begin(),a.end());
    int al = 0;
    int bo = 0;
    rep(i,0,n){
        if(i%2 == 0) al += a[i];
        else bo += a[i];
    }
    ans = al-bo;
    pout(ans);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define rep3(i, n) for (long long i = 0; i < (long long)(n); i++)
using Graph = vector<vector<int>>;
using ll = long long;

//----------素因数分解----------
vector<ll> prime_factorization(ll n){
  vector<ll> factors(n+1,0);
  rep3(i,n+1){
    if(i<=1) continue;
    while(n%i==0){
      n/=i;
      factors[i]++;
    }
  }
  return factors;
}

int main() {
  int n,x,t;
  cin>>n>>x>>t;
  if(n%x==0){
    int a=n/x;
    cout<<a*t<<endl;  
  }
  else{
    int a=n/x;
    cout<<(a+1)*t<<endl;  
  }
}


Measured memory_bytes: 3588
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cassert>
#include <queue>
#include <map>
#include <set>
using namespace std;
using ll = long long;
const int INF = 1<<30;
const int MOD = (int)1e9 + 7;
const int MAX_N = (int)1e5 + 5;
#define debug(x) cout << #x << ": " << x << endl
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2>& p) { os << p.first << " " << p.second; return os; }
template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v) { for(int i = 0; i < (int) v.size(); i++) os << v[i] << (i + 1 != v.size() ? " " : ""); return os; }

void solve()
{
    int n, m; cin >> n >> m;
    cout << (n - 1) * (m - 1) << endl;
}

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}

Measured memory_bytes: 256
// -----------------------------------
// author   : MatsuTaku
// country  : Japan
// created  : 08/09/20 20:58:21
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

  int n; cin>>n;
  array<array<int, 19>, 19> tab = {};
  ll ans = 0;
  for (int i = 0; i < n; i++) {
    string s; cin>>s;
    ll a = 0, b = 0;
    int k = 0;
    for (; k < s.size(); k++) {
      if (s[k] == '.') break;
      a = a*10 + (s[k]-'0');
    }
    k++;
    int pt = 1e8;
    for (int j = 0; j+k < s.size(); j++) {
      b += pt*(s[j+k]-'0');
      pt/=10;
    }
    ll num = a*1e9+b;

    int ps[2] = {};
    while (num%2==0) {
      num/=2;
      ps[0]++;
    }
    while (num%5==0) {
      num/=5;
      ps[1]++;
    }

    for (int j = max(18-ps[0], 0); j <= 18; j++) {
      for (int k = max(18-ps[1], 0); k <= 18; k++) {
        ans += tab[j][k];
      }
    }
    tab[min(ps[0], 18)][min(ps[1], 18)]++;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3620
A,B = map(int, input().split())


def f(n):
    if n % 4 == 0:
        return n
    elif n % 4 == 1:
        return 1
    elif n % 4 == 2:
        return n ^ (n-1) ^ (n-2)
    elif n % 4 == 3:
        return 0

print(f(A-1) ^ f(B))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main(){
	char a[200005];
	int q,w;
	cin >> a;
	for (int i=0;i<strlen(a);i++){
	     if (a[i]=='A') {
	     q=i;break;
	 }
	}
	for (int j=strlen(a)-1;j>=0;j--) if (a[j]=='Z') {
	w=j;break;
}
	cout << w-q+1;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
using ll=long long;
using namespace std;
const ll mod=1e9+7;
int main(){
  ll n,m,ans=1;
  cin>>n>>m;
  rep(i,1,n+1){ans*=i;ans%=mod;}
  rep(i,1,m+1){ans*=i;ans%=mod;}
  if(abs(n-m)>1)cout<<"0";
  else if(abs(n-m)==0) cout<<ans*2%mod;
  else cout<<ans%mod;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define COUT(x) cout<<(x)<<endl
#define dump(x)  cout << #x << " = " << (x) << endl;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
using M = map<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int, vector<int>, greater<int>>;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

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

  REP(i,n+1) {
    REP(j,n+1) {
      int k = (y - (10000*i + 5000*j)) / 1000;
      if (k >= 0 && i+j+k == n) {
        printf("%d %d %d", i,j,k);
        return 0;
      }
    }
  }
  printf("-1 -1 -1");
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>

#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

using namespace std;

//inline int read(){int t = 0;int neg=1;char c;while((c=getchar_unlocked())!='\n'&&c!=' '&&c!=EOF){if(c=='-'){neg=-1;continue;}t=t*10+c-48;}return neg*t;}
//inline int readl(){long long t = 0;long long neg=1ll;char c;while((c=getchar_unlocked())!='\n'&&c!=' '&&c!=EOF){if(c=='-'){neg=-1ll;continue;}t=t*10+c-48;}return neg*t;}

#define debug(x) cout<<(#x)<<"="<<(x)<<", ";
#define debug1(x) debug(x) cout<<'\n';
#define debug2(x1, x2) debug(x1) debug(x2) cout<<'\n';
#define debug3(x1, x2, x3) debug(x1) debug(x2) debug(x3) cout<<'\n';
#define debug4(x1, x2, x3, x4) debug(x1) debug(x2) debug(x3) debug(x4) cout<<'\n';
#define debug5(x1, x2, x3, x4, x5) debug(x1) debug(x2) debug(x3) debug(x4) debug(x5) cout<<'\n';

typedef long long int lli;
typedef unsigned long long int ulli;
typedef pair<int,int> pi;
typedef pair<lli,lli> plli;
typedef vector<int> vi;
typedef vector<lli> vlli;
typedef vector<pi> vpi;
typedef vector<plli> vplli;
const lli M=1000000007ll;

int main(){
	fast_io 
	int a7=0,a5=0,b;
	for(int i=0; i<3; ++i){
		cin>>b;
		if(b==5) a5++;
		if(b==7) a7++;
	}
	if(a5==2 and a7==1)cout<<"YES\n";
	else cout<<"NO\n";	
	
	return 0;
}

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

#define int long long
#define double long double
#define ff first
#define ss second
#define endl '\n'
#define ii pair<int, int>
#define mp make_pair
#define mt make_tuple
#define DESYNC                      \
  ios_base::sync_with_stdio(false); \
  cin.tie(0);                       \
  cout.tie(0)
#define pb push_back
#define vi vector<int>
#define vii vector<ii>
#define all(x) x.begin(), x.end()
#define EPS 1e-9
#define INF 1e18
#define ROOT 1
#define M 1000000007
#define curtime chrono::steady_clock::now().time_since_epoch().count
#define rep(i, beg, n, s) for (int i = beg; i < n; i += s)
const double PI = acos(-1);

using namespace std;

inline int mod(int n, int m = M)
{
  int ret = n % m;
  if (ret < 0)
    ret += m;
  return ret;
}

int exp(int n, int k)
{
  if (k == 0)
    return 1;
  if (k == 1)
    return n;
  int ax = exp(n, k / 2);
  ax = mod(ax * ax);
  if (k % 2)
    ax = mod(ax * n);
  return ax;
}

int gcd(int a, int b)
{
  if (a == 0)
    return b;
  else
    return gcd(b % a, a);
}

int v[3000][3000];
int dp[3000][3000][4];
int n, m, k;
int solve(int x, int y, int cnt)
{
  if (x == n - 1 && y == m - 1)
    return 0;
  if (dp[x][y][cnt] != -1)
    return dp[x][y][cnt];

  int &ans = dp[x][y][cnt];

  if (y + 1 < m)
  {
    if (cnt < 3 && v[x][y + 1] != -1)
    {
      ans = max(ans, solve(x, y + 1, cnt + 1) + v[x][y + 1]);
    }
    ans = max(ans, solve(x, y + 1, cnt));
  }
  if (x + 1 < n)
  {
    if (v[x + 1][y] != -1)
    {
      ans = max(ans, solve(x + 1, y, 1) + v[x + 1][y]);
    }
    ans = max(ans, solve(x + 1, y, 0));
  }

  //cout << "dp[" << x << "][" << y << "][" << cnt << "] = " << ans << endl;
  return ans;
}
//#define MULTIPLE_TEST_CASE
void solution()
{
  cin >> n >> m >> k;
  memset(v, -1, sizeof v);
  memset(dp, -1, sizeof dp);
  for (int i = 0; i < k; i++)
  {
    int x, y, c;
    cin >> x >> y >> c;
    x--, y--;
    v[x][y] = c;
  }
  int ans = solve(0, 0, 0);
  if (v[0][0] != -1)
    ans = max(ans, solve(0, 0, 1) + v[0][0]);
  cout << ans << endl;
}

int32_t main()
{
  DESYNC;
  mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
  int t = 1;
#ifdef MULTIPLE_TEST_CASE
  cin >> t;
#endif
  while (t--)
    solution();
}


Measured memory_bytes: 355668
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
using P = pair<int, int>;
int h, w, x, y, dx[] = {0,0,1,-1}, dy[] = {1,-1,0,0}, ans;
char s[25][25];
int main(){
	scanf("%d%d", &h, &w);
	rep(i,h) scanf("\n%s", s[i+1]+1);
	rep(i,h) rep(j,w) if(s[i+1][j+1] == '.'){
		int dist[25][25] = {}, m = 0;
		queue<P> qu;
		qu.push(P{i+1,j+1});
		dist[i+1][j+1] = 1;
		while(!qu.empty()){
			tie(x,y) = qu.front(); qu.pop();
			rep(i,4){
				int nx = x + dx[i], ny = y + dy[i];
				if(dist[nx][ny] || s[nx][ny] != '.') continue;
				dist[nx][ny] = dist[x][y] + 1;
				m = max(m, dist[nx][ny]);
				qu.push(P{nx,ny});
			}
		}
		ans = max(ans,m-1);
	}
	printf("%d\n", ans);
}

Measured memory_bytes: 256
#![allow(unused_imports)]
// use itertools::Itertools;
use proconio::{input, marker::*};

fn main() {
    input! {
        a: u8,
        b: u8
    };
    let sum = a + b;
    if sum >= 10 {
        println!("error");
    } else {
        println!("{}", sum);
    }
}


Measured memory_bytes: 2044
#include <cstdio>
#include <cstdint>
#include <cassert>
#include <cctype>
#include <set>
#include <string>
#include <algorithm>
#include <vector>

std::set<int> apply(
    const std::set<int> &lhs, char op, const std::set<int> &rhs) {

  std::set<int> res;
  for (int lx: lhs)
    for (int rx: rhs) {
      if (op == '+') {
        res.insert(lx+rx);
      } else if (op == '-') {
        res.insert(lx-rx);
      } else if (op == '*') {
        res.insert(lx*rx);
      } else if (op == '/' && rx != 0) {
        res.insert(lx/rx);
      }
    }

  return res;
}

std::set<int> parse(std::string &s, size_t &i, size_t preced=0) {
  static const std::string ops="+-*/";

  if (preced == 1) {
    if (s[i] == '(') {
      auto res=parse(s, ++i);
      assert(s[i] == ')');
      ++i;
      return res;
    } else if (isdigit(s[i])) {
      int res=s[i]-'0';
      while (++i < s.length() && isdigit(s[i]))
        res = res*10+s[i]-'0';

      return {res};
    }
    assert(false);
  }

  std::set<int> res;
  size_t starti=i;
  // skip an expression
  auto tmp=parse(s, i, 1);
  if (i == s.length () || !std::count(ops.begin(), ops.end(), s[i]))
    return tmp;

  while (i < s.length()) {
    char op=s[i];
    if (!std::count(ops.begin(), ops.end(), op)) break;

    s[i] = '$';
    size_t li=starti;
    auto lhs=parse(s, li);
    s[i] = op;

    size_t ri=++i;
    auto rhs=parse(s, ri);

    auto tmp=apply(lhs, op, rhs);
    res.insert(tmp.begin(), tmp.end());

    // skip an expression
    parse(s, i, 1);
  }
  return res;
}

int testcase_ends() {
  char buf[256];
  scanf("%s", buf);
  std::string s=buf;
  if (s == "#") return 1;

  size_t i=0;
  printf("%zu\n", parse(s, i).size());
  return 0;
}

int main() {
  while (!testcase_ends()) {}
}



Measured memory_bytes: 2972
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        exec();
    }

    static void exec() {
        PrintWriter out = new PrintWriter(System.out);
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());

        int[] a = new int[N];
        for (int i = 0; i < N; i++) {
            a[i] = Integer.parseInt(sc.next());

        }
        int k = 0;
        for (int i = 0; i < N; i++) {
            if (a[i] != i+1) {
                k++;
            }
        }
        if(k == 0 || k == 2) {
            out.println("YES");
        } else {
            out.println("NO");
        }

        out.flush();

    }

}


Measured memory_bytes: 21844
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::f64::consts::*;

#[allow(unused)]
const INF: usize = std::usize::MAX / 4;
#[allow(unused)]
const M: usize = 1000000007;

macro_rules! debug {
    ($($a:expr),* $(,)*) => {
    #[cfg(debug_assertions)]
        eprintln!(concat!($("| ", stringify!($a), "={:?} "),*, "|"), $(&$a),*);
    };
}

fn check(x: &Vec<usize>) -> usize {
    if x.len() == 1 {
        return x[0];
    }
    let mut y = vec![];
    for i in 2..x.len() {
        let z = [x[i - 2], x[i - 1], x[i]];
        y.push(z.iter().sum::<usize>() - z.iter().min().unwrap() - z.iter().max().unwrap());
    }
    check(&y)
}

fn main() {
    input! {
        n: usize,
        x: usize,
    }

    if n == 2 {
        if x == 2 {
            println!("Yes");
            println!("1");
            println!("2");
            println!("3");
        } else {
            println!("No");
        }
    } else if x == 1 || x == 2 * n - 1 {
        println!("No");
    } else {
        let mut sol = vec![0; 2 * n - 1];
        let mut nums = if x == 2 * n - 2 {
            sol[n - 3] = x - 1;
            sol[n - 2] = x + 1;
            sol[n - 1] = x;
            sol[n] = x - 2;
            sol[n + 1] = x - 3;
            (1..2 * n)
                .filter(|&y| y < x - 3 || x + 1 < y)
                .collect::<Vec<usize>>()
        } else if x == 2 {
            sol[n - 3] = x + 1;
            sol[n - 2] = x - 1;
            sol[n - 1] = x;
            sol[n] = x + 2;
            sol[n + 1] = x + 3;
            (1..2 * n)
                .filter(|&y| y < x - 1 || x + 3 < y)
                .collect::<Vec<usize>>()
        } else {
            sol[n - 3] = x + 1;
            sol[n - 2] = x - 1;
            sol[n - 1] = x;
            sol[n] = x + 2;
            sol[n + 1] = x - 2;
            (1..2 * n)
                .filter(|&y| y < x - 2 || x + 2 < y)
                .collect::<Vec<usize>>()
        };
        for i in 0..n - 3 {
            sol[i] = nums.pop().unwrap();
        }
        for i in n + 2..2 * n - 1 {
            sol[i] = nums.pop().unwrap();
        }
        debug!(check(&sol) == x);
        println!("Yes");
        for &s in &sol {
            println!("{}", s);
        }
    }
}


Measured memory_bytes: 5032
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <sys/time.h>
#include <cmath>
#include <tuple>
#include <queue>
#include <bitset>

using namespace std;

void solve(long long n, vector<long long> a){
    sort(a.begin(), a.end());
    long long ai = a.back();
    a.pop_back();
    std::cout << ai << " ";
    long long aj1, aj2;
    for (int i = 0; i < a.size(); i++) {
        if (ai/2 <= a[i]) {
            aj1 = a[i];
            if (i == 0) {
                std::cout << a[i] << std::endl;
                return;
            } else {
                aj2 = a[i-1];
                break;
            }
        } else if (i == a.size()-1) {
            std::cout << a[i] << std::endl;
            return;
        }
    }
    if (abs(aj1 - (ai/2.0)) > abs(aj2 - (ai/2.0))) {
        std::cout << aj2 << std::endl;
    } else {
        std::cout << aj1 << std::endl;
    }
}

int main(){	
    struct timeval start,end;
    long long span;
    gettimeofday(&start,NULL);

    long long n;
    scanf("%lld",&n);
    vector<long long> a(n-1+1);
    for(int i = 0 ; i <= n-1 ; i++){
    	scanf("%lld",&a[i]);
    }
    solve(n, a);

    gettimeofday(&end,NULL);
    span = (end.tv_sec -start.tv_sec)*1000000LL + (end.tv_usec - start.tv_usec);
    std::cerr << "--Total Time: " << span/1000 << "ms" << endl;
    return 0;
}


Measured memory_bytes: 2424
#include<stdio.h>

int main()
{
	long long N,A,B;
	scanf("%lld %lld %lld",&N,&A,&B);
	
	long long amari = N%(A+B);
	long long kaisuu =N / (A+B) * A;
	
	
	if(amari<=A){
		printf("%lld",kaisuu + amari);
		return 0;
	}
	printf("%lld",kaisuu + A);
		
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
int W,a,b;
cin>>W>>a>>b;
int R=b-(W+a);
if(R>=0)cout<<R;
else if(b>=a&&b<=W+a)cout<<0;
else cout<<a-(b+W);

return 0;
}


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

#define ipair pair<int,int>
#define rep(i,n) for(i=0;i<n;i++)
#define repj(i,j,n) for(i=j;i<n;i++)

#define PB(a,i) (a).push_back(i)
#define ALL(a) (a).begin(),(a).end()
#define SIZE(a,n) (a).resize(n)
#define SORT(a) sort(ALL(a))
#define VSORT(a, type) sort(ALL(a),greater<type>())
#define MAPIN(a,i,j) (a).insert(make_pair(i,j))

#define OK(i) cout<<"OK "<<i<<endl
#define Yes cout<<"Yes"<<endl
#define YES cout<<"YES"<<endl
#define No cout<<"No"<<endl
#define NO cout<<"NO"<<endl

using namespace std;

typedef long long int lli;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector< vi > Matrix;

int main() {
	int n, i, j;
	bool t;
	
	cin >> n;

	j = 1;
	i = 0;
	if (n < 10) {
		cout << n;
	}
	else {
		while (n / j > 0) {
			if (j * 10 <= n) {
				i += j * 9;
			}
			else {
				i += n % (j * 10) - j + 1;
			}
			j *= 100;
		}
		cout << i;
	}

	return 0;
}


Measured memory_bytes: 256
from math import sqrt
N,D=map(int,input().split())
ans=0
Points=[]
for i in range(N):
  Points.append(list(map(int,input().split())))
bia=1
for point in Points:
  for i in range(N-bia):
    dist=0.0
    for j in range(D):
      #print(k,i+bia,j)
      dist+= (point[j]-Points[i+bia][j]) * (point[j]-Points[i+bia][j])
    dist=sqrt(dist)
    if dist==int(dist):
      ans+=1
  bia+=1
print(ans)

Measured memory_bytes: 3064
D, G = [int(_) for _ in input().split()]
PC = [tuple(int(_) for _ in input().split()) for i in range(D)]
P = [_[0] for _ in PC]
C = [_[1] for _ in PC]

from itertools import product
from math import ceil

INF = 10**20

def calc(pat):
    solved_promlems = 0
    total_score = 0
    left = None
    for e, score, problem_nums, complete_score in zip(pat, range(100, (D+1)*100, 100), P, C):
        if e:
            total_score += score * problem_nums + complete_score
            solved_promlems += problem_nums
        else:
            left = score, problem_nums
    if total_score >= G:
        return solved_promlems
    if left:
        score, problem_nums = left
        n = ceil((G - total_score) / score)
        if 1 <= n < problem_nums:
            return solved_promlems + n
    return INF

result = min(calc(pat) for pat in product((0, 1), repeat=D))

print(result)


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

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

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

int main() {
  int a, b, c;
  cin >> a >> b >> c;

  if (b - a == c - b) cout << "YES" << endl;
  else cout << "NO" << endl;

  return 0;
}


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

constexpr long long mod{1000000007};

long long solve();

int main()
{
	printf("%lld\n", solve());

	return 0;
}

long long solve()
{
	int n, m;
	scanf("%d%d", &n, &m);
	std::vector<int> a(n), b(m);
	for (auto& e: a)
		scanf("%d", &e);
	for (auto& e: b)
		scanf("%d", &e);
	std::sort(a.rbegin(), a.rend());
	std::sort(b.rbegin(), b.rend());
	for (int i{1}; i < n; i++)
		if (a[i] == a[i - 1])
			return 0;
	for (int i{1}; i < m; i++)
		if (b[i] == b[i - 1])
			return 0;
	a.push_back(-1);
	b.push_back(-1);

	long long count{1};
	int a_i{}, b_i{};
	for (int i{n * m}; i > 0; i--)
	{
		if (i == a[a_i] && i == b[b_i])
		{
			a_i++;
			b_i++;
		}
		else if (i == a[a_i])
		{
			count *= b_i;
			count %= mod;
			a_i++;
		}
		else if (i == b[b_i])
		{
			count *= a_i;
			count %= mod;
			b_i++;
		}
		else
		{
			count *= a_i * b_i + i - n * m;
			count %= mod;
		}
	}
	return count;
}

Measured memory_bytes: 256
fun main(args: Array<String>) = println(run {
    tailrec fun gcd(a: Int, b: Int): Int = if (b == 0) a else gcd(b, a % b)
    fun divisors(x: Int): List<Long> = (1..Math.sqrt(x.toDouble()).toLong()).asSequence().filter { x % it == 0L }.map { listOf(it, x / it) }.flatten().distinct().sorted().toList()

    val (a,b,k) = readLine()!!.split(" ").map { it.toInt() }
    divisors(gcd(a, b)).sortedDescending()[k-1]
})


Measured memory_bytes: 36068
#include<bits/stdc++.h>
#define ll long long
#define dbg1(x) cerr<<#x<<"="<<(x)<<" "
#define dbg2(x) cerr<<#x<<"="<<(x)<<"\n"
#define dbg3(x) cerr<<#x<<"\n"
using namespace std;
#define reg register
#define pb push_back
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}
	return x*f;
}
const int MN=1e5+5;
int N,M,id[MN],rk[MN],par[MN];
ll f[MN],sz[MN],A[MN],B[MN],C[MN];
vector<int> G[MN],T[MN];
bool cmp(const int&x,const int&y){return C[x]<C[y];}
int getf(int x){return x==par[x]?x:par[x]=getf(par[x]);}
void rw(ll &x,ll y){if(y<x)x=y;}
void dfs(int x)
{
	#define y T[x][i]
	reg int i;sz[x]=B[x];f[x]=1e15;
	if(!T[x].size())return (void)(f[x]=B[x]+C[x]);
	for(i=T[x].size()-1;~i;--i)dfs(y),sz[x]+=sz[y];
	for(i=T[x].size()-1;~i;--i)rw(f[x],sz[x]-sz[y]+max(C[x],f[y]));
	#undef y
}
int main()
{
	N=read();M=read();
	reg int i,j,x,y;
	for(i=1;i<=N;++i) 
        par[i]=id[i]=i;
	for(i=1;i<=N;++i){ 
        A[i]=read();
        B[i]=read();
        C[i]=max(A[i]-B[i],0LL);
    }
	for(i=1;i<=M;++i) {
        x=read();
        y=read();
        G[x].pb(y);
        G[y].pb(x);
    }
	sort(id+1,id+N+1,cmp);
	for(i=1;i<=N;++i)rk[id[i]]=i;
	for(i=1;i<=N;++i)for(j=G[x=id[i]].size()-1;~j;--j){
		y=getf(G[x][j]);
		if(y!=x&&rk[y]<i) 
            par[y]=x,T[x].pb(y);
	}
	dfs(id[N]);
	return 0*printf("%lld\n",f[id[N]]);
}

Measured memory_bytes: 23376