akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<iostream>
#include<queue>
#include<deque> 
#include<cmath>
#include<cstring>
#include<algorithm>
#include<queue>
#define ll long long
#define inf 9999999999
#define mod 1000000007
using namespace std;
int num[100005];
int flag[100005];
int n;
int main()
{
	while(cin >> n)
	{
		memset(flag,0,sizeof(flag));
		flag[1] = 1;
		for(int i = 1;i <= n;i ++)
		{
			cin >> num[i];
		}
		int ans = 0;
		int nxt = num[1];
		int now = 1;
		int judge = 1;
		while(flag[2] != 1)
		{
			if(nxt == now || flag[nxt] == 1)
			{
				judge = 0;
				break;
			}
			now = nxt;
			ans ++;
			nxt = num[nxt];
			flag[now] = 1;
		}
		if(judge == 0)
			cout << -1 << endl;
		else
			cout << ans << endl;
	}
	return 0;
} 

Measured memory_bytes: 1024
#include <stdio.h>

int main(void)
{
 int a,b,c,d,s,t,e,f,g,h;
 	scanf("%d %d %d %d",&a,&b,&c,&d);
 	scanf("%d %d %d %d",&e,&f,&g,&h);
 	
 	s = a+b+c+d;
 	t = e+f+g+h;
 	
 if(s>t){
 	printf("%d\n",s);
 }
 else if(s<t){
 	printf("%d\n",t);
 }
 else{
 	printf("%d\n",s);
 }
 return 0;
 }
 	

Measured memory_bytes: 592
n , m = gets.split.map(&:to_i)
pre1 = []
pre2 = []
m.times do
  s , t = gets.split.map(&:to_i)
  if s == 1
    pre1.push(t)
  elsif t == n
    pre2.push(s)
  end
end
# 共通の要素を持っているか否か？
puts (pre1 & pre2).empty? ? "IMPOSSIBLE" : "POSSIBLE"

Measured memory_bytes: 9852
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <tuple>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

int n, m;
int a[100100], b[100100];

vector<int> G[100100];
vector<int> rG[100100];
int dp[100100];
int res[100100];

int calc(int v) {
    if (dp[v] < 0) {
        int res = 0;
        for (int i = 0; i < rG[v].size(); i++) {
            int u = rG[v][i];
            res = max(res, calc(u)+1);
        }
        dp[v] = res;
    }
    return dp[v];
}

void solve() {
    for (int i = 0; i < n+m-1; i++) {
        G[a[i]].push_back(b[i]);
        rG[b[i]].push_back(a[i]);
    }
    memset(dp, -1, sizeof(dp));

    for (int i = 0; i < n; i++) {
        if (dp[i] < 0) {
            calc(i);
        }
    }

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < G[i].size(); j++) {
            int v = G[i][j];
            if (dp[i] + 1 == dp[v]) res[v] = i+1;
        }
    }

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

void input() {
    cin >> n >> m;
    for (int i = 0; i < n+m-1; i++) {
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);

    input();
    solve();
}


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

int main() {
int N;
  cin >> N;
int Nc = N;
int sum = 0;
  for(int i = 0; i < 9; i++){
    sum += N % 10;
    N = N / 10;
  }
  if(Nc % sum == 0){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3552
n, x = map(int, input().split())

hambs = [(1, 1)]
for l in range(1, n+1):
    n_p, n_l = hambs[l-1]
    hambs.append((2*n_p+1, 2*n_l+3))
# for h in hambs:
#     print(h)

def eat(m, y):
    if y == 0:
        return 0
    if m == 0:
        return 1

    if y < 2+hambs[m-1][1]:
        return eat(m-1, y-1)
    elif y == 2+hambs[m-1][1]:
        return hambs[m-1][0] + 1
    elif 2+hambs[m-1][1] < y and y < hambs[m][1]:
        return hambs[m-1][0] + 1 + eat(m-1, y-(2+hambs[m-1][1]))
    else:
        return hambs[m][0]
print(eat(n, x))

Measured memory_bytes: 3064
N,M = map(int,input().split())

lis = [ [] for i in range(N) ]

for i in range(M):

    A,B = map(int,input().split())
    A -= 1
    B -= 1

    lis[A].append(B)
    lis[B].append(A)

from collections import deque

p = [i for i in range(N)]
d = [float("inf")] * N
d[0] = 0
q = deque([0])

while len(q) > 0:

    now = q.popleft()

    for nex in lis[now]:

        if d[nex] > d[now] + 1:
            d[nex] = d[now]
            p[nex] = now
            q.append(nex)

print ("Yes")
for i in range(1,N):
    print (p[i]+1)



Measured memory_bytes: 97076
#include<stdio.h>
int main(){
  int n,i,kai=1;
  
  scanf("%d",&n);
  
  for(i=0;i<100;i++){
    if(n==1)
      break;
    if(kai*2>n)
      break;
    kai=kai*2;
  }
  
  printf("%d",kai);
  return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		String s = sc.next();
		char[] a = new char[10];

		for (int i = 0; i < s.length(); i++) {
			a[i] = s.charAt(i);
		}
		a[3] = '8';

		for (int i = 0; i < a.length; i++) {
			System.out.print(a[i]);
		}
	}
}

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


int main(){
    int n, m;
    cin >> n >> m;
    vector<int> a(26, 0);
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            char x;
            cin >> x;
            a[x - 'a']++;
        }
    }
    int tot = n*m;
    int a4 = (n/2)*(m/2); //cout << a4;
    tot -= a4*4;
    for(int i = 0; i < 26; i++){
        while(a[i]  >= 4 && a4 > 0){
            a[i] -= 4;
            a4--;
        }
    }
    
    if(a4) {
        cout << "No\n"; return 0;
    }

    if(tot == 0) {
        cout << "Yes\n"; return 0;
    }
    int a2 = (m/2)*(n%2) + (n/2)*(m%2);
    tot -= a2*2;
    for(int i = 0; i < 26; i++){
        while(a[i]  >= 2 && a2 > 0){
            a[i] -= 2;
            a2--;
        }
    }
    if(a2) {
        cout << "No\n"; return 0;
    }

    if(tot == 0) {
        cout << "Yes\n"; return 0;
    }
    for(int i = 0; i < 26; i++){
        if(a[i]) {
            cout << "Yes\n"; return 0;
        }
    }
    cout << "No";

}


Measured memory_bytes: 3596
#include <iostream>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int t;
    cin>>t;
    int mini=1e9;
    for(int i=0;i<n;i++)
    {
        int a,b;
        cin>>a>>b;
        if(b<=t)
        {
            mini=min(mini,a);
        }
    }
    if(mini==1e9)
        cout<<"TLE"<<endl;
    else
        cout<<mini<<endl;
    return 0;
}

Measured memory_bytes: 256
#!usr/bin/env python3
from collections import defaultdict
import math
def LI(): return list(map(int, input().split()))
def II(): return int(input())
def LS(): return input().split()
def S(): return input()
def IIR(n): return [II() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
mod = 1000000007

#A
"""
n,a,b = LI()
ans = [min(a,b),max(0,a+b-n)]
print(ans[0],ans[1])
"""

#B
"""
n = II()
a = S()
b = S()
c = S()
ans = 0
for i in range(n):
    if a[i] == b[i]:
        if b[i] == c[i]:
            continue
        else:
            ans += 1
    else:
        if b[i] == c[i] or c[i] == a[i]:
            ans += 1
        else:
            ans += 2
print(ans)
"""

#C
"""
n = II()
c = LIR(n)
c.sort(key = lambda x:-x[0]-x[1])
ans = 0
i = 0
for i in range(n):
    x,y = c.pop(0)
    if i%2 == 0:
        ans += x
    else:
        ans -= y
print(ans)
"""

#D
import queue
n,m = LI()
c = LIR(n-1+m)
for i in range(n-1+m):
    c[i][0] -= 1
    c[i][1] -= 1
v = [[] for i in range(n)]
ins = [0 for i in range(n)]
for a,b in c:
    v[a].append(b)
    ins[b] += 1
ans = [-1 for i in range(n)]
q = queue.Queue()
for i in range(n):
    if ins[i] == 0:
        q.put(i)
while not q.empty():
    i = q.get()
    for j in v[i]:
        ans[j] = i
        ins[j] -= 1
        if ins[j] == 0:
            q.put(j)
for i in ans:
    print(i+1)
#E

#F

#G

#H

#I

#J

#K

#L

#M

#N

#O

#P

#Q

#R

#S

#T


Measured memory_bytes: 39248
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <climits>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++ )
#define repf(i,m,n) for(int (i)=m;(i)<n;(i)++)
#define all(v) (v).begin(), (v).end()
#define ll long long
#define vec(name,num) vector<ll> name((num),0);
#define op(i) cout<<(i)<<endl;
#define ip(i) cin>>(i);
#define opN cout<<"No"<<endl;
#define opY cout<<"Yes"<<endl;
#define opP cout<<"Possible"<<endl;
#define opI cout<<"Impossible"<<endl;
#define mat(name,fnum,snum); vector<vector<ll>> name((fnum),vector<ll>((snum),0));
#define matC(name,fnum,snum); vector<vector<char>> name((fnum),vector<char>((snum),0));
#define debugP int debug_point; cin>>debug_point;
#define FI first
#define SE second
const ll MOD= 1e9 + 7;
template <typename T>
void putv(vector<T>& V){
	// cout << "The elements in the vector are: " << endl;
	for(auto x: V)
		cout << x << " ";
	cout << endl;
}
ll pow_mod(ll fi,ll se,ll mod){
  if(se==0){
    return 1;
  }
  if(se%2){
    return pow_mod(fi,se-1,mod)*fi%mod;
  }
  ll t=pow_mod(fi,se/2,mod);
  return t*t%mod;
}
template <class T>
vector<T> getv(ll n){
	vector<T> Vector_temp;
	rep(i,n){
		T input;
		cin >> input;
		Vector_temp.emplace_back(input);
	}
	return Vector_temp;
}
ll gcd(ll c,ll b){
    while(1){
        if(c%b!=0){
        ll tmp=b;
        b=c%b;
        c=tmp;
        }else{
            return b;
        }
    }
}

vector<pair<int,int>> Dir={{-1,0},{1,0},{0,1},{0,-1}};
/* <3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3*/


int main(){
  ll n,m;
  cin>>n>>m;
  mat(a,m,0);
  vec(p,m);
  rep(i,m){
    ll k;
    cin>>k;
    rep(j,k){
      ll s;
      cin>>s;
      s--;
      a[i].push_back(s);
    }
  }
  ll ans=0;
  rep(i,m)cin>>p[i];

  vec(tmp_s,11);
  int bit=0;
  while(1){
    for(int i=0;i<10;i++){
      if((bit>>i)&1)tmp_s[i]=1;
    }
    ans++;
    rep(i,m){
      
      ll tmp=0;
      rep(j,(ll)a[i].size()){
        tmp+=tmp_s[a[i][j]];
      }
      if((tmp%2)!=p[i]){
        ans--;
        break;
      }
    }
    rep(i,11){
      tmp_s[i]=0;
    }
    bit++;
    if((bit>>n)&1)break;
  }
  op(ans);
}


Measured memory_bytes: 256
/*
 * 	The way if it's all predetermined
 * 		And the way i should go all my life
 * 			I swear to go wherever will be
 * 				'Cause there'll be something to see and to find
 */
//#pragma GCC optimize("Ofast,unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,avx2,tune=native")
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#ifdef rd
#define trace(...) cout<<"Line:"<<__LINE__<<" "; __f(#__VA_ARGS__, __VA_ARGS__)
template<typename Arg1>
void __f(const char* name, Arg1&& arg1) {
	cout<<name<<" : "<<arg1<<endl;
}
template<typename Arg1, typename ... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
	const char* comma=strchr(names+1,',');
	cout.write(names,comma-names)<<" : "<<arg1<<" | ";
	__f(comma+1,args...);
}
#else
#define trace(...)
#define endl '\n'
#endif
#define pb push_back
#define fi first
#define se second
//#define int long long
typedef long long ll;
typedef long double f80;
#define double long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define sz(x) ((long long)x.size())
#define fr(a,b,c) for(int a=b; a<=c; a++)
#define rep(a,b,c) for(int a=b; a<c; a++)
#define trav(a,x) for(auto &a:x)
#define all(con) con.begin(),con.end()
const ll infl=2e18;
const int infi=1e9;
//const int mod=998244353;
const int mod=1000000007;
typedef vector<int> vi;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> oset;
auto clk=clock();
mt19937 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim) {
	uniform_int_distribution<int> uid(0,lim-1);
	return uid(rang);
}


void solve() {
	int n;
	cin>>n;
	cout<<(n-2)*180<<endl;
}

signed main() {
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	srand(chrono::high_resolution_clock::now().time_since_epoch().count());
	cout<<fixed<<setprecision(10);
	int t=1;
//	cin>>t;
	while(t--)
		solve();
#ifdef rd
	cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
#endif
	return 0;
}


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

#define REP(i ,n) for(int i=0 ;i < n; i++)
#define REPB(i ,n) for(int i=n; i >= 0; i--)
#define FOR(i ,m ,n) for(int i=m; i < n; i++)
#define FORB(i, m, n) for(int i=m; i>= n; i--)
#define ll long long
#define pb push_back
#define popb pop_back
#define debug(i) cout << i << endl
using namespace std;
int main(){
  ll n;
  cin >> n;
  cout << ((n - 1) * n) /2 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
 
int main() {
 
  int N; cin >> N;
  vector<int> s(N);
  for(int i=0; i<N; i++){
    cin >> s.at(i);
  }
  
  int sum = 0;
  for(int i=0; i<N; i++){
    sum += s.at(i);
  }

  vector<int> undiv(N);
  for(int i=0; i<N; i++){
    undiv.at(i) += 10000;
  }
  
  if(sum % 10 == 0){
    bool find = 0;
    for(int i=0; i<N; i++){
      if(s.at(i) % 10 != 0){
        find = true;
        undiv.at(i) = s.at(i);
      }
    }
    if(find){
      sort(undiv.begin(), undiv.end());
      cout << sum - undiv.at(0) << endl;
    }else cout << '0' << endl;
  }else cout << sum << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
    int r, c;
    cin >> r >> c;
    int E[r][c];
    int i, j;
    for (i=0;i<r;i++) {
        for (j=0;j<c;j++) {
            cin >> E[i][j];
        }
    }
    for (i=0;i<r;i++) {
        int sum = 0;
        for (j=0;j<c;j++) {
            cout << E[i][j] << " ";
            sum += E[i][j];
        }
        cout << sum << endl;
    }
    int Sum = 0;
    for (j=0;j<c;j++) {
        int sum = 0;
        for (i=0;i<r;i++) {
            sum += E[i][j];
        }
        cout << sum << " ";
        Sum += sum;
    }
    cout << Sum << endl;
    return 0;
}


Measured memory_bytes: 3120
#include <bits/stdc++.h>
using namespace std;
// define
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define SUB(a, b) a = (a+mod-b)%mod
#define MUL(a, b) a = (((a)%mod) * ((b)%mod)) % mod
#define rollcall cout << "I'm Sucu." << endl;
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define fi first
#define se second
// typedef
typedef complex<double> Point;
typedef pair<int, int> P;
typedef pair<int, P> PP;
typedef pair<P, int> Pi;
typedef vector<int> vi;
typedef deque<int> dq;
const int inf = 1e9+7;
const int INF = 1e18+7;
const int mod = 1e9+7;
// int sum = accumulate(a, a+n, 0LL);
// int mx = max_element(a, a+n);
// int mn = min_element(a, a+n);
// int cnt = count(a, a+n, k);

int a[200000], b[200000], dp[200000];
int fib(int k){
  if(k == 0)return 1;
  if(k == 1 and b[1] == 1)return 0;
  if(k == 1 and b[1] == 0)return 1;
  if(b[k] == 1)return 0;
  if(dp[k] >= 0)return dp[k];
  int ret = fib(k-1) + fib(k-2);
  return dp[k] = ret%mod;
}
signed main(){
  int n, m;cin >> n >> m;
  rep(i,m)cin >> a[i];
  rep(i,m)b[a[i]] = 1;
  rep(i,n+1)dp[i] = -1;
  cout << fib(n) << endl;
  return 0;
}


Measured memory_bytes: 6656
import copy
import time
 
t1 = time.time()
 
def calc(T):
    res = 0
    L = [0]*26
    for i in range(D):
        res += S[i][T[i]-1]
        L[T[i]-1] = i+1
        for j in range(26):
            res -= C[j]*(i+1-L[j])
    return res
    
D = int(input())
C = [int(c) for c in input().split()]
S = [[int(s) for s in input().split()] for _ in range(D)]
 
T = [0]*D
for i in range(D):
    temp = -1
    for j in range(26):
        if temp < S[i][j]:
            temp = S[i][j]
            idx = j+1
    T[i] = idx

T2 = [0]*D
L = [0]*26
for i in range(D):
    p = -10**15
    for j in range(26):
        d = S[i][j]
        for k in range(26):
            if k == j:
                continue
            d -= C[k]*(i+1-L[k])
        if p < d:
            p = d
            idx = j+1
    T2[i] = idx
    
p1 = calc(T)
p2 = calc(T2)
if p2 > p1:
    T = copy.deepcopy(T2)
    p = p2
else:
    p = p1
i = 0
next = 1
while time.time()-t1 < 1.9:
    for j in range(26):
        temp = copy.deepcopy(T)
        temp[i] = j+1
        newp = calc(temp)
        if p < newp:
            T[i] = j+1
            p = newp
    i += next
    if i == -1:
        i = 1
        next = 1
    elif i == D:
        i = D-2
        next = -1

for t in T:
    print(t)

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

using namespace std;
using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vvs = vector<vector<string>>;
template<typename T> using vv = vector<vector<T>>;
template<typename T> using vvv = vector<vector<vector<T>>>;
template<typename T> using pq = priority_queue<T>;
template<typename T> using pqg = priority_queue<T, vector<T>, greater<T>>;

const int INF = 1e9;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
const int DX[4] = {1, 0, -1, 0};
const int DY[4] = {0, 1, 0, -1};

#define _sel(_1, _2, x, ...) x
#define repn(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, ...) _sel(__VA_ARGS__, reps, repn)(i, __VA_ARGS__)
#define reppn(i, n) for (ll i = 1; i <= (n); i++)
#define repps(i, a, b) for (ll i = (a); i <= (b); i++)
#define repp(i, ...) _sel(__VA_ARGS__, repps, reppn)(i, __VA_ARGS__)
#define rrepn(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define rreps(i, a, b) for (ll i = (b) - 1; i >= (a); i--)
#define rrep(i, ...) _sel(__VA_ARGS__, rreps, rrepn)(i, __VA_ARGS__)
#define rreppn(i, n) for (ll i = (n); i >= 1; i--)
#define rrepps(i, a, b) for (ll i = (b); i >= (a); i--)
#define rrepp(i, ...) _sel(__VA_ARGS__, rrepps, rreppn)(i, __VA_ARGS__)

#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define rng(v) (v).begin(), (v).end()
#define rrng(v) (v).rbegin(), (v).rend()
#define siz(x) int((x).size())
#define pow2(x) (1ll << (x))
#define bit(x, n) ((x) >> (n) & 1)
#define prt(x) cout << (x) << endl
#define dbg(x) dbgn(#x, x)

template<typename T, typename U> inline bool umax(T& m, U x) { if (m < x) { m = x; return true; } return false; }
template<typename T, typename U> inline bool umin(T& m, U x) { if (m > x) { m = x; return true; } return false; }
template<typename T> inline void errv(T& v) { for (auto x: v) cerr << x << " "; cerr << endl; }
inline void errv(vb& v) { for (auto x: v) cerr << (x ? 1 : 0) << " "; cerr << endl; }
template<typename T> inline void dbgn(string n, T x) { cerr << n << ": " << x << endl; }
template<typename T> inline void dbgn(string n, vector<T>& v) { cerr << n << ": "; errv(v); }
template<typename T> inline void dbgn(string n, vv<T>& m) { cerr << n << ":" << endl; for (auto& v: m) errv(v); }


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

    ll ans = 0;
    sort(rrng(a));

    ans += a[0];
    ll cnt = 1;
    bool f = true;
    rep(i, 1, n - 1) {
        ans += a[cnt];
        f = !f;
        if (f) cnt++;
    }

    prt(ans);

    return 0;
}


Measured memory_bytes: 4840
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int main() {
    int n, m;
    cin >> n >> m;
    int a[n];
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    int tot = 0;
    for (int i = 0; i < n; i++) {
        tot += a[i];
    }
    int cnt = 0;
    for (int i = 0; i < n; i++) {
        if (a[i] * 4 * m >= tot) cnt++;
    }

    string ans = "Yes";
    if (cnt < m) ans = "No";
    cout << ans << endl;
    return 0;
}


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

int main(){

  int X;

  cin>>X;

  if ( X % 7 == 1 ){

    cout<<"fri"<<endl;

  }

  if ( X % 7 == 2 ){

    cout<<"sat"<<endl;

  }

  if ( X % 7 == 3 ){

    cout<<"sun"<<endl;

  }

  if ( X % 7 == 4 ) {

    cout << "mon" << endl;
  }

  if ( X % 7 == 5 ){

    cout <<"tue"<<endl;
  }

  if ( X % 7 == 6 ){

    cout <<"wed"<<endl;
  }

  if ( X % 7 == 0 ){

    cout << "thu" <<endl;

  }

  return 0;

}



Measured memory_bytes: 3108
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    int n,k; cin>>n>>k;
    cout<<n-k+1<<endl;
}


Measured memory_bytes: 3600
#include<iostream>
#include<vector>
#include<utility>
#include<algorithm>#define PB push_back
#define FOR(n)   for(int i = 0; i < n; ++i)
#define COUT(n)   cout << n << " " << flush
#define IN(n)	 cin >> n;
#define ALL(obj)  obj.begin(), obj.end()
using namespace std;

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	cout << ((c - (a - b) < 0)? 0 : c-a+b) << endl;
}

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

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

   const double EPS = (1e-7);
   const ll INF =(1e13);
   const double PI = (acos(-1));
   const ll MOD = ll(1e9) + 7;

   #define REP(i, n) for(ll i = 0; i < (ll)(n); i++)
   #define REPR(i, n) for(ll i = n; i > -1; i--)
   #define FOR(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
   #define ALL(x) (x).begin(),(x).end()
   #define SORT(x) sort((x).begin(), (x).end())
   #define REVERSE(x) reverse((x).begin(), (x).end())
   #define SZ(x) ((ll)(x).size())
   #define pb push_back
   #define mp make_pair

   //chmax(a, b): a>bならaをbで更新　更新したときにtrueを返す
   //chmin(a, b): a<bならaをbで更新　更新したときにtrueを返す
   template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
   template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

   #define dump(x) cerr<< #x << "= " << (x) << endl;

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

   ll dx[4]={1,0,-1,0};
   ll dy[4]={0,1,0,-1};
ll X;
int main(){
   cin >> X;
   if (X == 3 || X == 5 || X == 7) cout << "YES" << endl;
   else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <math.h>
#include <unordered_map>
#include <numeric>
#include <sstream>
#include <functional>
using namespace std;

int main()
{
    int a,b,t;
    int i=1;
    int ans=0;
    cin >> a >> b >> t;

    while(1){
        if(t<a*i) break;
        ans += b;
        i++;
    }
    cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;

#define ll long long
const long long llINF = 1LL << 60;
const int iINF = 0x20000000;
template<class T> inline bool chmin(T& a, T b) { if (b < a) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

void execute();
int main() 
{
    cin.tie(nullptr);
    ios::sync_with_stdio(false);// cin と scanfの併用禁止
    cout << fixed << setprecision(15);
    execute();
    return 0;
}


void execute()
{
    ll N;
    cin >> N;

    cout << 1-N << endl; 
}


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

const int N=1e6+5;

int f[10];

int32_t main()
{
	IOS;
	for(int i=1;i<=4;i++)
	{
		int x;
		cin>>x;
		f[x]++;
	}	
	if(f[1] && f[4] && f[7] && f[9])
		cout<<"YES";
	else
		cout<<"NO";
	return 0;
}

Measured memory_bytes: 764
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>

int main()
{
    int a, b, x;

    scanf("%d%d%d", &a, &b, &x);

    if(a==x){
        printf("YES\n");
    }
    else if(a>x){
        printf("NO\n");
    }
    else if(a<x){
        if(a+b>=x){
            printf("YES\n");
        }
        else{
            printf("NO\n");
        }
    }
    
    return 0;
}

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

using namespace std;
int a[105][15], p[105][15];
int main(){
    int n;
    cin >> n;

    for(int i = 0; i < n; i++)
    for(int j = 0; j < 10; j++){
        cin >> a[i][j];
    }
    for(int i = 0; i < n; i++)
    for(int j = 0; j < 11; j++){
        cin >> p[i][j];
    }
    long long ans = -(1ll<<32);
    for(int mask = 1; mask < (1ll<<10); mask++){
        long long c1 = 0;
        for(int i = 0; i < n; i++){
            int c2 = 0;
            for(int j = 0; j < 10; j++){
                if(mask & (1<<j) && a[i][j]) c2++;
            }
            c1 += p[i][c2];
        }
        if(ans < c1) ans = c1;
    }
    cout << ans;
}


Measured memory_bytes: 3576
n,m = map(int,input().split())
x = input().split()

if n >= m:
  	print(0)
else:
  for i in range(m):
    x[i] = int(x[i])
  x.sort()
  ans = x[-1] - x[0]
  #print(ans)
  b = []
  for i in range(m-1):
  	b.append(x[i+1]-x[i])
  b.sort()
  #print(b)
  for i in range(1,n):
    #print(i,b[-i])
    ans -= b[-i]
  print(ans)

Measured memory_bytes: 10256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ; //何もしない文
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size()) //unsignedのサイズをint型に変換
#define pb push_back

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

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

const int MAX_N = 1e5 + 10;
int memo[26][MAX_N];
VI change[26];

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);	
    string S; cin >> S;
    REP(i,26)
    {
        REP(j,MAX_N) memo[i][j] = 0;
    }

    REP(i,S.length())
    {

        REP(j,26)
        {
            if(S[i]-'a' == j) 
            {
                memo[j][i+1] = memo[j][i] + 1;
                change[j].pb(i+1);
            }
            else memo[j][i+1] = memo[j][i];
        }

    }
    REP(i,26)
    {
        for(int j = 0; j < SZ(change[i])-1; j++)
        {
            int prev = change[i][j];
            int next = change[i][j+1];
            if(memo[i][next] - memo[i][prev-1] > (next-prev+1)/2)
            {
                cout << prev << " " << next << endl;
                return 0;
            }
        }

    }
    cout << -1 << " " << -1 << endl;


}


Measured memory_bytes: 11216
using System;

public class Problem_D
{
  public static void Main(string[] args)
  {
    var inputs = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
    var deck = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
    int n = inputs[0], z = inputs[1], w = inputs[2];
    var score = n >= 2 ? Math.Max(Math.Abs(deck[n - 1] - w), Math.Abs(deck[n - 2] - deck[n - 1])) : Math.Abs(deck[0] - w);
    Console.WriteLine($"{score}");
  }
}


Measured memory_bytes: 13268
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <iomanip>
#include <cmath>
using namespace std;

int main(){
	int a,b,k;
	cin>>a>>b>>k;
	for(int i=a;i<a+k&&i<b+1;i++){
		cout<<i<<endl;
	}
	for(int i=max(a+k,b-k+1);i<b+1;i++){
		cout<<i<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> ve_vel;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<bool>> ve_veb;
typedef vector<vector<string>> ve_ves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pub push_back
#define puf push_front
#define pob pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

int main(){
    
    int N;cin>>N;
    vector<int> A(N);
    int cnt=0;
    for(int i=0;i<N;i++){
        cin>>A[i];
        if(A[i]%2) cnt++;
    }
    if(cnt%2) cout<<"NO"<<endl;
    else cout<<"YES"<<endl;
}

Measured memory_bytes: 640
#include <algorithm>
#include <functional>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <climits>

#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

const int INF=100000000;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
using namespace std;
typedef pair<int ,int > P;
typedef long long ll;

int n, m;
void solve() {
    map<char, char> conv;
    rep(i,n) {
        char c1, c2;
        cin>>c1>>c2;
        conv[c1] = c2;
    }
    cin>>m;
    rep(i,m) {
        char c1;
        cin>>c1;
        if(conv.find(c1) == conv.end()) {
            cout<<c1;
        }
        else {
            cout<<conv[c1];
        }
    }
    cout<<endl;

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

        solve();
    }
    return 0;
}

Measured memory_bytes: 1188
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;
typedef string::const_iterator State;
#define Ma_PI 3.141592653589793
#define eps 1e-5
#define LONG_INF 1000000000000000000LL
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL
#define MOD 998244353LL
#define seg_size 262144*4
#define REP(a,b) for(long long a = 0;a < b;++a)
int main() {
	int n;
	cin >> n;
	vector<pair<int, int>> inputs;
	REP(i, n) {
		int a;
		cin >> a;
		inputs.push_back(make_pair(a, i + 1));
	}
	sort(inputs.begin(), inputs.end());
	REP(i, n) {
		if (i != 0)cout << " ";
		cout << inputs[i].second;
	}
	cout << endl;
}

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

int main() {
    int n; scanf("%d", &n);
    vector<int> x = {0}, y = {0};
    for (int i = 0; i < n; ++i) {
        int l, r;
        scanf("%d%d", &l, &r);
        x.push_back(r);
        y.push_back(l);
    }
    sort(x.begin(), x.end());
    sort(y.begin(), y.end(), greater<int>());
    int64_t ans = 0, res = 0;
    for (int i = 0; i < min(x.size(), y.size()); ++i) {
        res += y[i];
        res -= x[i];
        ans = max(ans, res);
    }
    printf("%lld\n", ans * 2);
}


Measured memory_bytes: 1276
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define forn(i, a, n) for (int i = (int)(a); i < (int)(n); ++i)
#define ford(i, a, n) for (int i = (int)(n) - 1; i >= (int)(a); --i)
#define fore(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define all(a) (a).begin(), (a).end()
#define fs first
#define sn second
#define trace(a)\
    for (auto i : a) cerr << i << ' ';\
    cerr << '\n'
#define eb emplace_back

#ifndef M_PI
const ld M_PI = acos(-1.0);
#endif

template<typename T>
inline void setmax(T& a, T b) {
    if (a < b) a = b;
}

template<typename T>
inline void setmin(T& a, T b) {
    if (a > b) a = b;
}

template<typename T, typename S>
istream& operator>> (istream& in, pair<S, T>& p) {
    in >> p.fs >> p.sn;
    return in;
}
template<typename T, typename S>
ostream& operator<< (ostream& out, pair<S, T>& p) {
    out << p.fs << ' ' << p.sn << ' ';
    return out;
}

template<typename T>
istream& operator>> (istream& in, vector<T>& v) {
    for (T& x : v) in >> x;
    return in;
}
template<typename T>
ostream& operator<< (ostream& out, vector<T>& v) {
    for (T& x : v) out << x << ' ';
    return out;
}

const ld eps = 1e-9;
const int INF = 2000000000;
const ll LINF = 1ll * INF * INF;
const ll MOD = 1000000007;

const int N = 1e5 + 10;
vector<int> e[N];
char used[N];
set<int> comp;

void dfs(int u) {
    if (used[u]) return;
    used[u] = 1;
    comp.insert(u);
    for (int v : e[u])
        dfs(v);
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); 
    srand((unsigned)chrono::high_resolution_clock::now().time_since_epoch().count());
    int n, m;
    int ans = 0;
    cin >> n >> m;
    vector<int> p(n);
    cin >> p;
    for (int& x : p) --x;
    while (m--) {
        int x, y;
        cin >> x >> y;
        --x, --y;
        e[x].eb(y);
        e[y].eb(x);
    }
    forn(i, 0, n)
        if (!used[i]) {
            comp.clear();
            dfs(i);
            for (int x : comp)
                if (comp.find(p[x]) != comp.end())
                    ++ans;
        }
    cout << ans << '\n';
}


Measured memory_bytes: 13312
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
signed main()
{
    SPEED;
  	int a,b;
  	cin>>a>>b;
  	double c=a/0.08,d=b/0.1;
  for(int i=min(floor(c),floor(d));i<=max(ceil(c),ceil(d));++i)
  {
    if(floor((int)i*0.1)==b && floor((int)i*0.08)==a)
    {
        cout<<i;
        return 0;
    }
  }
  cout<<-1;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
template <typename T>
using vec = std::vector<T>;

int main() {
    int N;
    cin >> N;
    vec<vec<int>> F(N,vec<int>(10));
    rep(i,N)rep(j,10) cin >> F[i][j];
    vec<vec<int>> P(N,vec<int>(11));
    rep(i,N)rep(j,11) cin >> P[i][j];

    ll ans = -1e9;
    rep(i,1<<10){
        if(i==0) continue;
        ll tmpans = 0;
        rep(f,N){
            int d = 0;
            rep(j,10){
                if(!(i&1<<j)) continue;
                if(F[f][j]) ++d;
            }
            tmpans += P[f][d];
        }
        ans = max(ans,tmpans);
    }
    cout << ans << endl;
}

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

#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define MOD 1000000007
#define cey ce("Yes")
#define cen ce("No")
#define ceY ce("YES")
#define ceN ce("NO")
ll dp[100][5][5][5];
int main()
{
	int N;
	cin >> N;

	fx(5) {
		fy(5) {
			dp[1][0][x][y] = 1;
		}
	}

	for (int i = 2; i < N; i++) {
		fw(5) {
			fx(5) {
				fy(5) {
					fz(5) {
						if (x == 0 || y == 0 || z == 0) { continue; }
						if ((w == 1 && y == 3 && z == 2) ||
							(x == 1 && y == 2 && z == 3) ||
							(x == 3 && y == 1 && z == 2) ||
							(w == 1 && x == 3 && z == 2) ||
							(x == 1 && y == 3 && z == 2)) {
							continue;
						}
						dp[i][x][y][z] += dp[i - 1][w][x][y];
						dp[i][x][y][z] %= MOD;
					}
				}
			}

		}
	}
	ll ans = 0;
	fx(4) {
		fy(4) {
			fz(4) {
				ans += dp[N - 1][x+1][y+1][z+1];
				ans %= MOD;
			}
		}
	}
	ce(ans)
    return 0;
}



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

int main() {
	long long N, M;
	while (cin >> N >> M) {
		if (N == 0 && M == 0) return 0;
		vector<long long> S(N), T(M);
		long long SC = 0, TC = 0;
		for (int i = 0; i < N; i++) cin >> S[i], SC += S[i];
		for (int i = 0; i < M; i++) cin >> T[i], TC += T[i];
		sort(S.begin(), S.end()), sort(T.begin(), T.end());
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < M; j++) {
				if (SC - S[i] + T[j] == TC - T[j] + S[i]) {
					cout << S[i] << " " << T[j] << endl;
					goto next;
				}
			}
		}
		cout << -1 << endl;
	next:;
	}
}


Measured memory_bytes: 3156
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define int long long
#define double long double
#define mod 1000000007
#define F first
#define S second
#define P pair<long long,long long>
#define all(a) a.begin(),a.end()
#define INF 1000000000000000
#define endl '\n'
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; }
using namespace std;

signed main(){
    int k; cin>>k;
    vector<int> a(k);
    rep(i,k)cin>>a.at(i);
    reverse(all(a));
    int Min=2,Max=2;
    rep(i,k){
        int t=a.at(i);
        if((Min-1)/t==Max/t){
            cout<<-1<<endl;
            return 0;
        }
        Min=(Min+t-1)/t*t;
        Max=Max/t*t+t-1;
    }
    cout<<Min<<' '<<Max<<endl;
}

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

const int N = 1e9 + 7;

int main(){
	
	int n, k;
	scanf("%d %d", &n, &k);
	vector <int> arr(n), ans(n, N);
	for(int& i : arr){
		scanf("%d", &i);
	}
	ans[0] = 0;
	for(int i = 0; i < n; i++){
		for(int j = i + 1; j != i+k+1; j++){
			if(j < n){
				ans[j] = min(ans[j], ans[i]+abs(arr[i]-arr[j]));
			}
		}
	}
	printf("%d", ans[n-1]);
}

Measured memory_bytes: 4020
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ProConA_AntiAdjacency
{
    class Program
    {
        static void Main(string[] args)
        {
            // 整数の入力
            //int a = int.Parse(Console.ReadLine());
            // スペース区切りの整数の入力
            string[] input = Console.ReadLine().Split(' ');
            int N = int.Parse(input[0]);
            int K = int.Parse(input[1]);
            // 文字列の入力
            //string s = Console.ReadLine();
            if (N >= 2*K - 1)
            {
                Console.WriteLine("YES");
            }
            else
            {
                Console.WriteLine("NO"); ;
            }
        }
    }
}


Measured memory_bytes: 13140
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;

int main(){
  int N; cin >> N;
  vector<int> v; int V; for(int i=0; i<N; i++){cin >> V; v.push_back(V);}
  
  sort(v.begin(),v.end());
  
  float ans=(float)v[0];
  for(int i=0; i<N-1; i++){
    ans = (ans+(float)v[i+1])/2;
  }
  
  cout << ans;
  
  return 0;
}

Measured memory_bytes: 256
s=list(input())
k=int(input())
S=sorted(set(s))
t=0
l=[]
can=[]
while len(can)==0:
    for i in range(len(s)):
        if s[i]==S[t]:
            l.append(i)
    for i in l:
        for j in range(1,k+1):
            if i+j<=len(s) and s[i:i+j] not in can:
                can.append(s[i:i+j])
    if len(can)<k:
        k -= len(can)
        t += 1
        can=[]
        l=[]
can.sort()
ans=can[k-1]
print(''.join(ans))

Measured memory_bytes: 9252
#include <iostream>
#include <queue>
#include <cstring>
using namespace std;

int main() {
  string s;
  cin >> s;
  queue<char> zero,one;

  for(int i = 0; i < s.size(); i++) {
    if(s[i] == '0') {
      if(!one.empty()) {
	one.pop();
      }
      else zero.push('0');
    }
    else {
      if(!zero.empty()) {
	zero.pop();
      }
      else one.push('1');
    }
  }

  cout << s.size() - (zero.size() + one.size()) << endl;
}

  


Measured memory_bytes: 512
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
#include <cmath>
#include <stack>

using namespace std;
using ll = long long int;

template <class T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto i = v.begin(); i != v.end(); i++) {
    os << *i << " ";
  }
  return os;
}


void solve(std::string S, std::string T, long long A, long long B, std::string U){
  if(S==U) A--;
  if(T==U) B--;
  std::cout << A << " " << B << std::endl;
}

int main(){
  std::string S;
  std::cin >> S;
  std::string T;
  std::cin >> T;
  long long A;
  scanf("%lld",&A);
  long long B;
  scanf("%lld",&B);
  std::string U;
  std::cin >> U;
  solve(S, T, A, B, U);
  return 0;
}



Measured memory_bytes: 256
n,m=map(int,input().split())
r=[[*input()] for _ in range(n)]
ans=[[[0] for _ in range(m)] for _ in range(n)]
dir1=[0,0,1,1,1,-1,-1,-1]
dir2=[-1,1,-1,0,1,-1,0,1]
for i in range(n):
  for j in range(m):
    count=0
    if r[i][j]=='#':
      ans[i][j]='#'
      continue
    for k in range(8):
      dx = i + dir1[k]
      dy = j + dir2[k]
      if 0<=dx<n and 0<=dy<m and r[dx][dy]=='#':
        count+=1
    ans[i][j]=count
[print(*i,sep='') for i in ans]

Measured memory_bytes: 9232
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 998244353;

int main(){
	
	ll n,k; cin>>n>>k;
	int m = log2(k);
	vector d(m+1,vector(n,-1));
	for(int i=0; i<n; i++){
		cin >> d.at(0).at(i);
		d.at(0).at(i)--;
	}
	for(int i=1; i<=m; i++){
		for(int j=0; j<n; j++){
			d.at(i).at(j) = d.at(i-1).at(d.at(i-1).at(j));
		}
	}
	int now{0},cnt{0};
	while(k){
		if(k&1){
			now = d.at(cnt).at(now);
		}
		k>>=1;
		cnt++;
	}
	cout << now+1 << endl;
}


Measured memory_bytes: 51140
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
int A,B,C;
int main()
{
	scanf("%d%d%d",&A,&B,&C);
	if(B>A) swap(A,B);
	if(C>A) swap(A,C);
	if(C>B) swap(B,C);
	int ans=(A-B);
	C+=(A-B);
	B=A;
	ans+=(A-C)/2;
	if((A-C)%2==1) ans+=2;
//	dfs(A,B,C,0);
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 256
def eratos(n):
    isPrime = [True]*(n+1)
    isPrime[0] = isPrime[1] = False
    for i in range(3,n+1,2):
        if isPrime[i]:
            j = i+i
            while j <= n:
                isPrime[j] = False
                j += i
    for i in range(4,n+1,2): isPrime[i] = False
    return isPrime

def isLikeNum(x):
    if x%2 == 0: return False
    if isPrime[x] and isPrime[(x+1)//2]: return True
    else: return False

q = int(input())
l = [0]*q
r = [0]*q
for i in range(q):
    x,y = map(int,input().split())
    l[i] = x
    r[i] = y
m = max(r)
isPrime = eratos(m)
cnt = [0]*(m+1)
for i in range(3,m+1):
    if isLikeNum(i):
        cnt[i] += cnt[i-1]+1
    else:
        cnt[i] = cnt[i-1]
for i in range(q): print(cnt[r[i]]-cnt[l[i]-1])

Measured memory_bytes: 13388
#include<stdio.h>

int main(){
  int i, j;
  int h, w;

  while(1){
    scanf("%d %d", &h, &w);

    if(h == 0 && w == 0) break;
  
    for(i = 0; i < h; i++){
      for(j = 0; j < w; j++){
	if(i == 0 || i == h - 1 || j == 0 || j == w - 1){
	  printf("#");
	}
	else{
	  printf(".");
	}
      }
      printf("\n");
    }
    printf("\n");
  }
  
  return 0;
}



Measured memory_bytes: 2040
#include <bits/stdc++.h>
#include <string>
#include <sstream>
using namespace std;
#define ll long long
#define ff first
#define ss second
#define clr(a) memset(a, 0, sizeof(a))
#define set(a) memset(a, -1, sizeof(a))
#define pb push_back
#define sz(a) ((ll)a.size())
#define all(a) a.begin(), a.end()
#define mp make_pair
#define rep(i, a, y) for (ll i = a; i <= y; i++)
#define rep2(i, b) for (int i = 0; i < b; i++)
#define repl(i, a, b) for (ll i = a; i <= b; i++)
#define ppi pair<int, int>
#define scl(x) scanf("%d", &x)
#define pcl(x) printf("%d", x)
#define FastRead                  \
    ios_base::sync_with_stdio(0); \
    cin.tie(0)
/*

     ██╗██╗   ██╗██╗  ██╗ █████╗ ███╗   ██╗
     ██║██║   ██║██║  ██║██╔══██╗████╗  ██║
     ██║██║   ██║███████║███████║██╔██╗ ██║
██   ██║██║   ██║██╔══██║██╔══██║██║╚██╗██║
╚█████╔╝╚██████╔╝██║  ██║██║  ██║██║ ╚████║
 ╚════╝  ╚═════╝ ╚═╝  ╚═╝╚═╝  ╚═╝╚═╝  ╚═══╝

*/
int main()
{
    ll a,i=1,k=0;
    cin>>a;
    if(a%1000==0)
    {
        cout<<"0"<<endl;
        return 0;
    }
    while (k<=a)
    {
        k=i*1000;
        i++;
    }
    cout<<abs(k-a)<<endl;
    return 0;
}

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

int main() {
    int house[4][3][10], n, building, floor, address, number;

    for (int h = 0; h < 4; h++) {
        for (int i = 0; i < 3; i++) {
            for (int s = 0; s < 10; s++) {
                house[h][i][s] = 0;
            }
        }
    }

    cin >> n;

    for (int i = 0; i < n; i++) {
        cin >> building >> floor >> address >> number;
        house[building - 1][floor - 1][address - 1] += number;
        if (house[building - 1][floor - 1][address - 1] >= 10) {
            house[building - 1][floor - 1][address - 1] = 9;
        } else if (house[building - 1][floor - 1][address - 1] < 0) {
            house[building - 1][floor - 1][address - 1] = 0;
        }
    }

    for (int h = 0; h < 4; h++) {
        for (int i = 0; i < 3; i++) {
            for (int s = 0; s < 10; s++) {
                cout << " " << house[h][i][s];
            }
            cout << endl;
        }
        if ((h + 1) != 4) {
            cout << "####################" << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 3040