akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define rep(i,k) for(int i=0;i<k;i++)
using namespace std;
int main(){
    int s,k;
    int count=0;
    cin>>k>>s;
    rep(i,k+1)rep(j,k+1){
        int z=s-i-j;
        if(i+j+z==s&&z<=k&&0<=z) count++;
    }
    cout<<count<<endl;
    return 0;
}

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

#define mp make_pair
#define pb push_back
#define repm(i, n, m)  for(int i = n; i < m; ++i)
#define Repm(i, n, m)  for(int i = n; i <= m; ++i)
#define rep(i, n) for(int i = 0; i < n; ++i)
#define repn(i, n) repm(i, 1, n)
#define mod 1000000000+7

int main(){
    string s; cin >> s;
    int count = 0, t = 0;

    rep(i, s.size()){
        if(s[i] == 'A'|| s[i] == 'T'|| s[i] == 'G'|| s[i] == 'C')   count++;
        else{
            t = max(count, t);
            count = 0;
        }
            
    }
    cout << max(count, t) << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(x) x.begin(), x.end()
#define pii pair<int, int>
#define pll pair<ll, ll>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define em emplace
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, n) for(int i = 1; i <= n; i++)
template<class T> inline int chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline int chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
constexpr int INF = 1<<30;
constexpr ll LINF = 1LL<<58;
constexpr int mod = 1000000007;

double dp[3030][3030];

int main(){
    int n;
    cin >> n;
    double P[3030];
    for (int i = 0; i < n; i++) cin >> P[i];
    dp[0][0] = 1;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j <= i; j++) {
            dp[i + 1][j + 1] += dp[i][j] * P[i];
            dp[i + 1][j] += dp[i][j] * (1 - P[i]);
        }
    }
    double ans = 0;
    for (int i = n / 2 + 1; i <= n; i++) {
        ans += dp[n][i];
    }
    cout << fixed << setprecision(10) << ans << endl;
    return 0;
}


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

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

const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;

#define rep(i, a, b) for(ll (i) = (a); (i) < (b);++i)

int main()
{
  ll a;
  cin >> a;

  double Max = 0;
  for (double i = 1; i <= 1000; ++i)
  {
    for (double j = 2; j <= 100; ++j)
    {
      if (pow(i, j) <= a)
      {
        Max = max(Max, pow(i, j));
      }
    }
  }
  cout << Max << endl;
  return 0;
}


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

using namespace std;

#define REP(i, n)   for(int i = 0; i < (n); i++)
#define REPS(i, n)  for(int i = 1; i <= (n); i++)
#define RREP(i, n)  for(int i = (n)-1; i >= 0; i--)
#define RREPS(i, n) for(int i = (n); i > 0; i--)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define mp make_pair
#define mt make_tuple
#define pb push_back

using ll  = long long;
using pi  = pair<int, int>;
using pl  = pair<ll, ll>;
using vi  = vector<int>;
using vl  = vector<ll>;
using vs  = vector<string>;
using vb  = vector<bool>;
using vvi = vector<vi>;
using vvl = vector<vl>;

const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const ll  INFL = 1e18;
const double PI = 3.141592653589793;
const double EPS = 1e-9;

template<class T> bool chmax(T &a, const T &b) { if(a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if(a > b) { a = b; return true; } return false; }

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

    ll N, M; cin >> N >> M;
    ll ans = min(N, M/2);
    N -= ans;
    M -= ans*2;
    ans += M / 4;
    cout << ans << endl;
}

Measured memory_bytes: 3572
#include <iostream>

using namespace std;
int k;
int main()
{
    int v[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    cin>>k;
    cout<<v[k-1];
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
#include <vector>
#include <algorithm>
#define rep(i,n) for (int i = 0;i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y)
int INF = 1e9;

int dp[1005][1005];
char maze[1005][1005];

int main(){
    int h,w;cin >> h >> w;
    int ch,cw; cin >> ch >> cw;
    int dh,dw; cin >> dh >> dw;
    --ch;--cw;
    --dh;--dw;
    rep(i,1005)rep(j,1005) dp[i][j] = INF;
    dp[ch][cw] = 0;
    rep(i,h)rep(j,w) cin >> maze[i][j];
    priority_queue<P,vector<P>,greater<P>> q;
    q.emplace(0,ch*w+cw);
    while(!q.empty()){
        P p = q.top();
        if(p.first > dp[dh][dw]) break;
        int y = p.second/w;
        int x = p.second%w;
        //cout << p.first << endl;
        q.pop();
        for(int i = -2;i <= 2;i++)for(int j = -2;j <= 2;j++){
            if(i == 0 && j == 0) continue;
            int ny = y + i;
            int nx = x + j;
            if(ny < 0 || nx < 0 || h <= ny || w <= nx) continue;
            if(maze[ny][nx]=='#') continue;
            if((abs(i)==1&&j==0)||(abs(j)==1&&i==0)){
                if(dp[ny][nx]>dp[y][x]){
                    dp[ny][nx] = dp[y][x];
                    q.emplace(p.first,w*ny+nx);
                }
            }else{
                if(dp[ny][nx]>dp[y][x]+1){
                    dp[ny][nx] = dp[y][x]+1;
                    q.emplace(p.first+1,w*ny+nx);
                }
            }
        }
    }

    if(dp[dh][dw] == INF) cout << -1 << endl;
    else cout << dp[dh][dw] << endl;



    
}

Measured memory_bytes: 8620
def color_judge(n):
    if 1<=n<=399:
        return 'gray'
    elif n<=799:
        return 'brown'
    elif n<=1199:
        return 'green'
    elif n<=1599:
        return 'light blue'
    elif n<=1999:
        return 'blue'
    elif n<=2399:
        return 'yellow'
    elif n<=2799:
        return 'orange'
    elif n<=3199:
        return 'red'
    else:
        return 'choice'

n = int(input())
a = list(map(int, input().split()))
dic = {}
for i in a:
    if dic.get(color_judge(i)):
        dic[color_judge(i)] += 1
    else:
        dic[color_judge(i)] = 1
choice = 0
l = len(dic)
if dic.get('choice'):
    choice = dic['choice']
    l -= 1
print(max(1, l), l+choice)

Measured memory_bytes: 9104
#include<bits/stdc++.h>
#define MAX_N 100001
#define INF_INT 2147483647
#define INF_LL 9223372036854775807
#define REP(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
void init(int n);
int find(int n);
void unite(int x,int y);
bool same(int x, int y);
ll bpow(ll,ll,ll);
typedef vector<int> vec;
typedef vector<vec> mat;
mat mul(mat &A,mat &B);
mat pow(mat A,ll n);
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
const int MOD = 1000000007;

bool cmp_P(const P &a,const P &b){
  return a.second < b.second;
}
int main()
{
  int N;
  char alp[26]={0};
  string w;
  cin >> w;
  REP(i,w.size())alp[w[i]-'a']++;
  REP(i,26)if(alp[i]%2){
    cout << "No" << endl;
    return 0;
  }
  cout << "Yes" << endl;
  return 0;
}

int par[MAX_N];
int ranks[MAX_N];

//n要素で初期化
void init(int n){
  REP(i,n){
    par[i] = i;
    ranks[i] = 0;
  }

}

//木の根を求める
int find(int x){
  if(par[x] == x){
    return x;
  }else{
    return par[x] = find(par[x]);
  }
}

void unite(int x,int y){
  x = find(x);
  y = find(y);
  if(x == y) return ;
  if(ranks[x] < ranks[y]){
    par[x] = y;
  }else{
    par[y] = x;
    if(ranks[x] == ranks[y]) ranks[x]++;
  }
}

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

ll bpow(ll a, ll n,ll mod){
  int i = 0;
  ll res=1;
  while(n){
    if(n & 1)
      res = (res*a) % mod;
    a = (a*a) % mod;
    n >>= 1;
  }
  return res;
}
mat mul(mat &A, mat &B){
  mat C(A.size(),vec(B[0].size()));
    REP(i,A.size())REP(k,B.size())REP(j,B[0].size()){
    C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % MOD;
  }
  return C;
}

mat pow(mat A,ll n)
{
  mat B(A.size(),vec(A.size()));
  REP(i,A.size()){
    B[i][i] = 1;
  }
  while(n > 0){
    if ( n & 1) B = mul(B,A);
    A = mul(A,A);
    n >>= 1;
  }
  return B;
}


Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
n,m = map(int,readline().split())
lst1 = [list(map(int,readline().split())) for i in range(m)]

#Union Find

#xの根を求める
def find(x):
    if par[x] < 0:
        return x
    else:
        par[x] = find(par[x])
        return par[x]
#xとyの属する集合の併合
def unite(x,y):
    x = find(x)
    y = find(y)
    
    if x == y:
        return False
    else:
        #sizeの大きいほうがx
        if par[x] > par[y]:
            x,y = y,x
        par[x] += par[y]
        par[y] = x
        return True

#xとyが同じ集合に属するかの判定
def same(x,y):
    return find(x) == find(y)

#xが属する集合の個数
def size(x):
    return -par[find(x)]

#xが属するグループの要素全てを返す
def members(x):
    root = find(x)
    return [i for i in range(n) if find(i) == root]

#全ての根の要素をlistで返す(一個下の関数で使う)
def roots():
    return [i for i,x in enumerate(par) if x < 0]

#グループ数を返す
def group_count():
    return len(roots())

#根をkey,そのグループに含まれる要素をvalueとして全てを辞書型で返す
def all_group_members():
    return {r: members(r) for r in roots()}

#初期化
#根なら-size,子なら親の頂点



ans = 0 #橋
for i in range(m):
    par = [-1]*n
    for j in range(m):
        if i == j:
            continue
        else:
            unite(lst1[j][0]-1,lst1[j][1]-1)
    if group_count() != 1:
        ans += 1
print(ans)
    




Measured memory_bytes: 40944
A, B, C, D = map(int, raw_input().split())

def gcd(m, n):
    while m % n:
        t = n
        n = m % n
        m = t
    return n

def lcm(m, n):
    return m * n / gcd(m, n)

def foo(N, C, D):
    return N - (N / C) - (N / D) + (N / lcm(C, D))

print foo(B, C, D) - foo(A-1, C, D)


Measured memory_bytes: 2568
import java.math.BigDecimal;
import java.util.*;

public class Main {

    Scanner sc = new Scanner(System.in);

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

    void run() {

        int n = sc.nextInt();
        long sum = 0;
        Map<Integer, Integer> map = new HashMap<>();
        int[] a = new int[n];
        for (int i=0; i<n; i++) {
            a[i] = sc.nextInt();
            sum += a[i];
            if (map.containsKey(a[i])) {
                map.put(a[i], map.get(a[i])+1);
            } else {
                map.put(a[i], 1);
            }
        }
        int q = sc.nextInt();
        int[][] bc = new int[q][2];

        StringBuilder sb = new StringBuilder();

        for (int i=0; i<q; i++) {
            int b = sc.nextInt();
            int c = sc.nextInt();
            int cnt = map.containsKey(b) ? map.get(b) : -1;
            if (cnt==-1) {
                sb.append(sum + "\n");
                continue;
            }
            sum -= (long)b * cnt;
            sum += (long)c * cnt;
            map.remove((Integer)b);
            if (map.containsKey(c)) {
                map.put(c, map.get(c)+cnt);
            } else {
                map.put(c, cnt);
            }
            sb.append(sum + "\n");
//            System.out.print(map);
        }

        System.out.print(sb.toString());






    }
}


Measured memory_bytes: 73468
#include <bits/stdc++.h>    //C++の標準ライブラリのヘッダを全て読み込む
 
int main() {
    using std::cout;
    using std::endl;
    using std::cin;
    using std::string;

    char c;
    cin >> c;
 
    if(c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o'){
        cout << "vowel" << endl;
    } else {
        cout << "consonant" << endl;
    }
}

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

int H, W;
int A[80][80];
int B[80][80];
int D[80][80];

const int MAX = 80*80;
typedef bitset<MAX*2+1> bits;

int main(){
	cin >> H >> W;
	
	
	for ( int i = 0; i < H; i++ ){
		for ( int j = 0; j < W; j++ ){
			cin >> A[i][j];
		}
	}
	for ( int i = 0; i < H; i++ ){
		for ( int j = 0; j < W; j++ ){
			cin >> B[i][j];
		}
	}
	for ( int i = 0; i < H; i++ ){
		for ( int j = 0; j < W; j++ ){
			D[i][j] = abs(A[i][j] - B[i][j]);
		}
	}
	
	bits c[80];
	c[0].set(MAX);
	for ( int i = 0; i < H; i++ ){
		for ( int j = 0; j < W; j++ ){
			bits tmp = (j==0) ? c[j] : (c[j] | c[j-1]);
			c[j] = (tmp<<D[i][j]) | (tmp>>D[i][j]);
		}
	}
	
	
	int i;
	for ( i = 0; i <= MAX; i++ ){
		if ( c[W-1].test(MAX+i) )
			break;
		if ( c[W-1].test(MAX-i) )
			break;
	}
	
	cout << i << endl;
	
	return 0;
}



Measured memory_bytes: 512
#print#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**9)
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))
#%%code
from collections import Counter
def resolve():
    w=input()
    a=Counter(w)
    for j in a.values():
        if j%2:print("No");return
    print("Yes")
#%%submit!    
resolve()


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

int count(int n,int i,char* str);

int main()
{
  int n,ans;
  char str[100];
  cin>>n;
  cin>>str;

  ans = 0;
  
  for(int i = 0 ; i <= n-1 ; i++)
  {
    if(ans < count(n,i,str))
    {
      ans = count(n,i,str);
    }
  }
  
  cout<<ans<<endl;
  
  return 0;
}

int count(int n,int i,char* str)
{
  int num = 0;
  bool doubling = false;
  
  for(int j = 0 ; j <= i-1 ; j++)
  {
    doubling = false;
    
    for(int l = 0 ; l <= j-1 ; l++)
    {
      if(str[j] == str[l])
      {
        doubling = true;
        break;
      }
    }


    if(doubling == false)
    {
      for(int k = i ; k <= n ; k++)
      {
        if(str[j] == str[k])
        {
          num++;
          break;
        }
      }
    }
  }  
  return num;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main(void){
    int cnt=0;
    int min=0;
    
    int N;
    string s;
    cin >> N;
    cin >> s;
    for(int i=0; i<N; i++){
        if(s[i] == '('){
            cnt++;
        }else if(s[i] == ')'){
            cnt--;
        }
        if(cnt < min){
            min = cnt;
        }
    }
    for(int i=min; i<0; i++){
        cout << "(";
    }
    cout << s;
    for(int i=cnt; i>min; i--){
        cout << ")";
    }
    cout << endl;
}


Measured memory_bytes: 256
// ProblemURL : https://atcoder.jp/contests/abc134/tasks/abc134_d
// ---------------------------------------------
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	as := [2e5 + 10]int{}
	for i := 1; i <= n; i++ {
		fmt.Scan(&as[i])
	}

	boxes := [2e5 + 10]int{}
	for i := n; i >= 1; i-- {
		sum := 0
		for j := i; j <= n; j += i {
			sum += boxes[j]
		}
		if sum%2 != as[i] {
			boxes[i] = 1
		}
	}

	ans := make([]int, 0, n)
	for i := 1; i <= n; i++ {
		if boxes[i] == 1 {
			ans = append(ans, i)
		}
	}
	fmt.Printf("%d\n", len(ans))
	for i := 0; i < len(ans); i++ {
		if i != len(as)-1 {
			fmt.Printf("%d ", ans[i])
		} else {
			fmt.Printf("%d\n", ans[i])
		}
	}
}


Measured memory_bytes: 8832
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <set>
#include <sstream>
#include <bitset>
#include <stack>
#include <cstdlib>
#include <utility> //pair

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

typedef long long ll;

using namespace std;

int main() {
    int ans=1;
    int n;
    cin >> n;
    vector<string> w(n);
    FOR(i, 0, n){
        cin >> w[i];
        if(i>0){
            if(w[i-1].back()!=w[i].front()){
                ans=0;
            }
        }
    }
    
    
    
    FOR(i, 0, n-1){
        FOR(j, i+1, n){
            if(w[i]==w[j]){
                ans = 0;
            }
        }
    }
    
    if(ans==1){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int a[10],b[10],c,d,i,j,k,n,m;
    for(i=1;i<=6;i++)
        scanf("%d",&a[i]);
    scanf("%d",&d);
    for(i=0;i<d;i++){
        scanf("%d %d",&n,&m);
        for(k=1;k<=6;k++)
            b[k] = a[k];
        for(j=0;j<4;j++){    /*tate idou*/
            if(b[1]==n)
                break;
            c = b[1];
            b[1] = b[2];
            b[2] = b[6];
            b[6] = b[5];
            b[5] = c;
        }
        while(1){       /*tate(1ga yokoniarutoki) idou*/
            if(b[1]==n)
                break;
            c = b[1];
            b[1] = b[3];
            b[3] = b[6];
            b[6] = b[4];
            b[4] = c;
        }
        while(1){       /*yoko idou*/
            if(b[2]==m)
                break;
            c = b[2];
            b[2] = b[3];
            b[3] = b[5];
            b[5] = b[4];
            b[4] = c;
        }
        printf("%d\n",b[3]);
    }
    return 0;
}

Measured memory_bytes: 596
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define all(a) (a).begin(), (a).end()

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 ll = long long;

ll N;
ll ans;

int main()
{
  std::cin >> N;
  rep( i, N )
  {
    ll l, r;
    std::cin >> l >> r;
    ans += r-l+1;
  }

  std::cout << ans << std::endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) {
  return b ? gcd(b, a % b) : a;
}
ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}
ll f(ll l) {
  int x = 0;
  while (l % 2 == 0) {
    l /= 2;
    x++;
  }
  return x;
}
int main() {
  int n, m, l, x;
  cin >> n >> m;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    a[i] /= 2;
  }
  x = f(a[0]);
  m >>= x;
  l = 1;
  for (int i = 0; i < n; i++) {
    if (f(a[i]) == x) {
      l = lcm(l, (a[i] >> x));
      if (l > m) {
        cout << 0;
        return 0;
      }
    } else {
      cout << 0;
      return 0;
    }
  }
  m/=l;
  ll ans = (m + 1) / 2;
  cout << ans;
  return 0;
}

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

using namespace std;
int main() {
#ifdef LDT
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a, b;
    cin >> a >> b;
    cout << a * b;
    return 0;
}

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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

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

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}

int64 d(int64 x) {
  return to_string(x).size();
}

int64 N;
vector<PLL> G[112345];
vector<int64> e;

int main(void) {
  cin >> N;
  e.resize(N-1, -1);
  REP(i, N-1) {
    int64 a, b;
    cin >> a >> b;
    G[a].emplace_back(i, b);
    G[b].emplace_back(i, a);
  }
  vector<int64> ord(N);
  iota(all(ord), 0);
  sort(all(ord), [&](int64 a, int64 b) {
    return G[a].size() > G[b].size();
  });
  int64 col = G[ord[0]].size();
  queue<int64> vs;
  vs.push(ord[0]);
  while (vs.size()) {
    int64 v = vs.front(); vs.pop();
//    cout << v << endl;
    vector<int64> used(col, 0);
    REP(i, G[v].size()) {
      if (e[G[v][i].fs] != -1) used[e[G[v][i].fs]] = 1;
    }
    int64 ptr = 0;
    REP(i, G[v].size()) {
      if (e[G[v][i].fs] == -1) {
        vs.push(G[v][i].sc);
//        cout << G[v][i].sc << " ";
        while (used[ptr]) ptr++;
        used[ptr] = 1;
        e[G[v][i].fs] = ptr;
      }
    }
//    cout << endl;
  }
  cout << col << endl;
  REP(i, e.size()) {
    cout << e[i]+1 << endl;
  }
}

Measured memory_bytes: 9856
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  ll N;
  cin >> N;
  vector<vector<ll>> g(N);
  ll a, b;
  vector<pair<ll, ll>> edge;
  for (int i = 0; i < N - 1; i++) {
    cin >> a >> b;
    a--, b--;
    g[a].push_back(b);
    g[b].push_back(a);
    edge.push_back({a, b});
  }
  ll K = 0;
  vector<ll> edge_color(N, 0);
  vector<bool> visited(N, 0);
  queue<ll> q;
  map<pair<ll, ll>, ll> color_map;
  visited[0] = true;
  q.push(0);
  while (!q.empty()) {
    ll v = q.front();
    q.pop();
    if (K < g[v].size()) K = g[v].size();
    ll cur = 1;
    for (auto next_v : g[v]) {
      if (visited[next_v]) continue;
      if (cur == edge_color[v]) cur++;
      edge_color[next_v] = cur;
      color_map[{next_v, v}] = cur;
      color_map[{v, next_v}] = cur;
      cur++;
      visited[next_v] = true;
      q.push(next_v);
    }
  }
  cout << K << endl;
  for (auto p : edge) {
    cout << color_map[p] << endl;
  }
  return 0;
}

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

namespace kakomon
{
    class Program
    {
        static void Main(string[] args)
        {
            agc002_a();
        }

        static void agc002_a()
        {
            // A - Range Product
            long[] input = Console.ReadLine().Trim().Split().Select(long.Parse).ToArray();
            long a = input[0];
            long b = input[1];
            string ans;
            // すべて1以上なら積は正
            if (0 < a) ans = "Positive";
            // 0を含む区間なら積は0
            else if (a <= 0 && 0 <= b) ans = "Zero";
            // bが0より小さい、すべて負の値の場合
            else
            {
                // 同じ値なら、積は正の値
                if (a == b) ans = "Positive";
                // 個数が偶数なら、積は正の値
                else if ((b-a+1) % 2 == 0) ans = "Positive";
                // 個数が奇数なら、積は負の値
                else ans = "Negative";
            }
            Console.WriteLine(ans);
        }
    }
}

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

using namespace std;

int main()
{
	cin.sync_with_stdio(false);

	int W, a, b;
	cin >> W >> a >> b;
	if (abs(b-a)>W) {
		cout << abs(b-a)-W << endl;
	}
	else {
		cout << 0 << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 100000000000
#define MOD 1000000007
#define ll long long int
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()



using namespace std;





int main() {
  int N; cin>>N;
  int T[1000000] ={};
  REP(i,N) cin>>T[i];
  int M; cin>>M;
  REP(m,M){
    int p,x; cin>>p>>x;
    p--;
    int ans=0;
    REP(i,N){
      if(i==p) ans +=x;
      else ans += T[i];


    }
    cout<<ans<<endl;
  }

  return 0;
}

Measured memory_bytes: 4096
/* ***************************************************
 *	Author        :mutinner
 *	Created Time  :2018年11月04日 星期日 20时52分26秒
 *	File Name     :20:52:26.cpp
 *************************************************** */

#include <bits/stdc++.h>
using namespace std;

int main() {
	int n;	double t, a;
	cin >> n >> t >> a;
	int ans = 0;	double cur = 1 << 30;
	for ( int i = 0; i < n; ++i ) {
		double x;	cin >> x;
		double val = fabs( t - x * 0.006 - a );
		if ( cur > val ) {
			cur = val;
			ans = i + 1;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

class UnionFind {
	vector<int>par, sz;
public:
	UnionFind() {}
	UnionFind(int n) {
		par = sz = vector<int>(n);
		for (int i = 0; i < n; i++) {
			par[i] = i;
			sz[i] = 1;
		}
	}
	int find(int x) {
		if (par[x] == x)return x;
		return par[x] = find(par[x]);
	}
	void unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y)return;
		if (sz[x] > sz[y]) {
			par[y] = x;
			sz[x] += sz[y];
		}
		else {
			par[x] = y;
			sz[y] += sz[x];
		}
	}
	bool same(int x, int y) {
		return find(x) == find(y);
	}
	int size(int x) {
		return sz[find(x)];
	}
};
int a[200000],b[200000];
int main(){
	int n,m;cin>>n>>m;
	rep(i,m){
		scanf("%d%d",&a[i],&b[i]);a[i]--;b[i]--;
	}
	UnionFind uf(n);
	ll ans=n*(ll)(n-1)/2;
	vector<ll>v;
	for(int i=m-1;i>=0;i--){
		v.push_back(ans);
		if(uf.same(a[i],b[i]))continue;
		ans-=uf.size(a[i])*(ll)uf.size(b[i]);
		uf.unite(a[i],b[i]);
	}
	reverse(v.begin(),v.end());
	for(ll i:v){
		printf("%lld\n",i);
	}
}


Measured memory_bytes: 3828
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <climits>
using namespace std;

#define MOD1097 1000000007

#define ll long long
#define pint pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define mpair make_pair
#define pm(first, second) pb(mpair((first), (second)))
#define SPACE " "
#define fpf first.first
#define fps first.second
#define spf second.first
#define sps second.second

#define all(X) (X).begin(), (X).end()
#define reall(X) (X).rbegin(), (X).rend()
#define divcel(a, b) (((a) + ((b) - 1)) / (b))

int main(){

	int N;
	cin >> N;
	vector<ll> V(N);
	for(int i = 0; i < N; i++){
		cin >> V[i];
	}
	for(int i = N  - 2; i >= 0; i--){
		if(V[i] > V[i + 1])V[i]--;
	}
	bool flag = true;
	for(int i = 0; i < N - 1 && flag; i ++){
		if(V[i] > V[i + 1])flag = false;
	}
	if(flag)cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200010;
int64_t N, K;

bool ok(int64_t m, vector<int64_t> &A, vector<int64_t> &F)
{
  int64_t k = 0;
  for (int i = 0; i < N; i++)
  {
    if (A[i] * F[i] <= m)
      continue;
    k += A[i] - (m / F[i]);
  }
  return k <= K;
}

int main()
{
  cin >> N >> K;
  vector<int64_t> A(N), F(N);
  for (int i = 0; i < N; i++)
  {
    cin >> A[i];
  }
  for (int i = 0; i < N; i++)
  {
    cin >> F[i];
  }
  sort(A.begin(), A.end());
  sort(F.begin(), F.end());
  reverse(F.begin(), F.end());

  int64_t l = -1, r = (1LL << 62);
  while (r - l > 1)
  {
    int64_t m = (l + r) / 2;
    if (ok(m, A, F))
      r = m;
    else
      l = m;
  }
  cout << r << endl;
}

Measured memory_bytes: 6408
#![allow(
    non_snake_case,
    unused_variables,
    unused_assignments,
    unused_mut,
    dead_code
)]
use proconio::input;
//use proconio::marker::Usize1;
//use proconio::marker::Chars;
//use std::collections::HashSet;
//use std::cmp::*;
fn main() {
    input! {
        x:u64
    }
    let mut y = 100;
    let mut ans = 0;
    while y < x {
        // if (ans > 3588) {
        //     println!("y={} ans={}", y, ans);
        // }
        y = y / 100 + y;
        ans = ans + 1;
    }
    println!("{}", ans);
}


Measured memory_bytes: 2124
//thanks God For Every Thing!
//contest link:
#include<bits/stdc++.h>
#define pi                      acose(-1)

typedef long long int           ll;
typedef double                  dl;
using namespace std;
const int mx = 1e2+5;


int main()
{
    int n;
    cin>>n;
    cout<<(1000-n%1000)%1000;

    return 0;
}


Measured memory_bytes: 3540
<?php

$cat_count = trim(fgets(STDIN));

$string = trim(fgets(STDIN));


$array = explode(" ", $string);

$counts = array();

$MAX = 0;

foreach ($array as $item)
{
	$counts[$item] ++;
}

ksort($counts);

if (count($counts) > 2)
{
	echo "No\n";
	die();
}

//check to make sure the numbers are adjacent
$keys = array_keys($counts);
if (count($keys) == 2)
{
	if (($keys[1] - $keys[0]) != 1)
	{
		echo "No\n";
		die();
	}
}





$high		 = max(array_keys($counts));
$high_count	 = $counts[$high];
$low		 = max(array_keys($counts)) - 1;
$low_count	 = $counts[$low];




//all cats say the same thing
if ($low_count === null)
{
	//all unique -> number is one less than number of cats
	if (($high + 1) == $cat_count)
	{
		echo "Yes\n";
		die();
	}

	//all non-unique
	if ($high <= ($cat_count / 2))
	{
		echo "Yes\n";
		die();
	}
}
else
{
	$unique_hat_count = $low_count;


	$total_hat_colors = $high;

	$non_unqiue_colors	 = $total_hat_colors - $unique_hat_count;
	$non_unqiue_cats	 = $cat_count - $unique_hat_count;


	if (($non_unqiue_cats > 0) && ($non_unqiue_colors <= 0))
	{
		echo "No\n";
		die();
	}

	if (($non_unqiue_cats <= 0) && ($non_unqiue_colors > 0))
	{
		echo "No\n";
		die();
	}


	if ($non_unqiue_colors <= ($non_unqiue_cats / 2))
	{
		echo "Yes\n";
		die();
	}
}


echo "No\n";


Measured memory_bytes: 36656
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
					*/

#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>

#pragma GCC optimize("Ofast")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printin(a) printf(a ? "possible\n" : "inposible\n")
#define printdb(a) printf("%.50lf\n", a)//少数出力
#define printdbd(a) printf("%.16lf\n", a)//少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str())//string出力
#define all(x) (x).begin(), (x).end()
#define allsum(a, b, c) ((a + b) * c / 2)//等差数列の和、初項,末項,項数
#define pb push_back
#define priq priority_queue
#define rpriq priq<int, vector<int>, greater<int>>
#define deg_to_rad(deg) (((deg)/360.0)*2.0*PI)
#define rad_to_deg(rad) (((rad)/2.0/PI)*360.0)
#define Please return
#define AC 0
#define ushi int
#define tapu main
#define nichia (
#define kunn void
#define wara )

using ll = long long;

const int INF = 1073741823;
const int MINF = -1073741823;
const ll LINF = ll(4661686018427387903);
const ll MOD = 1000000007;
const double PI = acos(-1);

using namespace std;

void scans(string& str) {
	char c;
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);//最初の改行対策
	while (c != '\n' && c != -1) {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

/*-----------------------------------------ここからコード-----------------------------------------*/

int main(){

	int a[3], k;
	scanf("%d%d%d%d", &a[0], &a[1], &a[2], &k);
	sort(a, a + 3);
	printf("%d\n", a[0] + a[1] + a[2] * (int)pow(2, k));

	Please AC;
}


Measured memory_bytes: 256
/*
 * Author : Andrew J
*/
#include <bits/stdc++.h>
using namespace std;
void in(int &x);
#define fi first
#define se second
#define pb push_back
using ll = long long;
typedef pair <int , int> ii;
// const int N = ;
char s[5];

int main() {
   scanf("%s" , s);
   int n = strlen(s);
   int sol = 0;
   for (int i = 0 ; i < n ; ) {
      if (s[i] == 'R') {
         int j = i + 1;
         while (j < n) {
            if (s[j] != s[i]) break;
            j++;
         }
         sol = max(sol , j - i);
         i = j;
      } else {
         i++;
      }
   }
   printf("%d\n" , sol);
   return 0;
}

void in(int &x){
	bool neg = false;
	register int c;
	x = 0;
	c = getchar();
	if(c == '-'){
		neg = true;
		c = getchar();
	}
	for (; c > 47 && c < 58; c = getchar())
	x = (x << 1) + (x << 3) + c - 48;
	if (neg) x *= -1;
}


Measured memory_bytes: 3820
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;

int main(){
  int n,s[1000] = {0};
  int sum = 0;
  
  while (1) {
    cin >> n;
    if ( n == 0 ) {
      putchar ('\n');
      break;
    }
    sum = 0; //crucial!
    for ( int i = 0; i < n; i++ ) {
      cin >> s[i];
      sum += s[i];
    }
    double m = (double)sum / n;
    double subvar = 0;
    for ( int i = 0; i < n; i++ ) {
      subvar += pow(s[i] - m, 2);
    }
    double var = subvar / n;
    double StDv = sqrt(var); //standard deviation
    printf ("%lf\n",StDv);
  }
  
  return 0;
}


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

int main() {
  string A; string B; string C;
  cin>>A>>B>>C;
  int X=A.size()-1;
  int Y=B.size()-1;
  if(A.at(X)==B.at(0)&&B.at(Y)==C.at(0))
    cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
}

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

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << "\n";
}
template <typename Arg1, typename... Args>
void __f(const char* na, Arg1&& arg1, Args&&... args) {
  const char* c = strchr(na + 1, ',');
  cerr.write(na, c - na) << " : " << arg1 << " , ";
  __f(c + 1, args...);
}
#define endl "\n"
typedef long long LL;
const int mod = 1e9 + 7;
const int inf = 1e9;
const LL INF = 1e18;
const int N = 1e5 + 5;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0); cout.tie(0);
  #ifdef LOCAL
    //freopen("input.txt", "r", stdin);
  #endif // LOCAL
  char c;
  cin >> c;
  int x = c - 'a' + 1;
  cout << (char)(x + 'a') << endl;
  return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int main(){
  int n;
  while(cin>>n,n){
    map<int,long long int>m;
    vector<int>num;
    rep(i,n){
      long long int a,b,c;
      cin>>a>>b>>c;
      if(m.find(a)==m.end()){
	num.pb(a);
	m.insert(mp(a,b*c));
      }else{
	m[a]+=b*c;
      }
    }
    bool h=false;
    rep(i,num.size()){
      if(m[num[i]]>=1000000){
	cout<<num[i]<<endl;
	h=true;
      }
    }
    if(!h)cout<<"NA"<<endl;
  }
}

Measured memory_bytes: 1288
import Data.List
main = interact $ unlines . return . unwords . map (exchange "apple" "peach") . words
exchange s1 s2 s = rewrite "" s
 where
  rewrite s' s
   | null s = s'
   | isPrefixOf s1 s = rewrite (s' ++ s2) (s \\ s1)
   | isPrefixOf s2 s = rewrite (s' ++ s1) (s \\ s2)
   | otherwise = rewrite (s' ++ [head s]) (tail s)

Measured memory_bytes: 3700
#include<stdio.h>
int main(){
  int n,m,i,j,count=0;
  scanf("%d%d",&n,&m);
  int h[n+2],a[m+1][3],good[n+2];
  for(i=1;i<=n;i++){
    scanf("%d",&h[i]);
    good[i]=1;
  }
  for(i=0;i<m;i++)
    for(j=0;j<2;j++)
      scanf("%d",&a[i][j]);
  for(i=0;i<m;i++){
    if(h[a[i][0]]>h[a[i][1]])
      good[a[i][1]]=0;
    else if(h[a[i][0]]<h[a[i][1]])
      good[a[i][0]]=0;
    else{
      good[a[i][1]]=0;
      good[a[i][0]]=0;
    }
  }
  for(i=1;i<=n;i++)
    if(good[i]==1)
      count++;
  printf("%d\n",count);
  return 0;
}


Measured memory_bytes: 3672
import java.util.*;

class Main{

  public static void main(String args[]){

    Scanner s=new Scanner(System.in);
    int N=s.nextInt();
    int K=s.nextInt();
    int[] L=new int[N];
	for(int i=0;i<N;i++) L[i]=s.nextInt();
    Arrays.sort(L);
    int ans=0;
    for(int i=0;i<K;i++) ans+=L[i];
    System.out.println(ans);

  }  
}

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

#define REP(i,x,y) for(int i=(x);i<(y);i++)
#define RREP(i,x,y) for(int i=(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
// #define int long long

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

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#else
#define eprintf(...) 42
#define dump(x) 42
#define debug(x) 42
#endif

typedef long long ll;

const ll MOD = 1e9 + 7;

void fill(ll& answer, int K, int parent, int current, vector<vector<int>>& edges) {
    ll childCount = edges[current].size();
    ll colors = K-1;
    if (parent == -1) {
        answer *= K;
    } else {
        childCount--;
        colors--;
    }

    if (childCount == 0) return;

    // fill child's color with nPr
    REP(i,colors-childCount+1, colors+1) {
        answer *= i;
        answer %= MOD;
    }

    for (const auto nextVertex : edges[current]) {
        if (parent == nextVertex) continue;
        fill(answer, K, current, nextVertex, edges);
    }
}

void solve(int N, int K, vector<int>& A, vector<int>& B) {
    ll answer = 1;
    vector<vector<int>> edges(N+1);
    REP(i,1,N) {
        edges[A[i]].emplace_back(B[i]);
        edges[B[i]].emplace_back(A[i]);
    }
    fill(answer, K, -1, 1, edges);

	stringstream ss;
	ss << answer;
	cout << ss.str() << '\n';

    return;
}

signed main() {
    int N, K;
    cin >> N >> K;
    
    vector<int> A(N), B(N);
    REP(i,1,N) cin >> A[i] >> B[i];
    
    solve(N, K, A, B);
    
    return 0;
}



Measured memory_bytes: 12416
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mod 1000000007
#define ff first
#define ss second
using namespace std;
//ll arr[1000002];
/*ll power(ll x,ll y)
{
    ll res=1;
    while(y>0)
    {
        if(y%2==1)
            res=(res*x)%mod;
        x=(x*x)%mod;
        y=y/2;
    }
    return res;
}*/
int main()
{
string s;
ll i,c=0;
cin>>s;
for(i=0;i<s.size();i++)
{
    if(s[i]=='o')
        c++;
}
c=c+(15-s.size());
if(c>=8)
    cout<<"YES"<<endl;
else
    cout<<"NO"<<endl;
}


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

int main(){
    int N;
    cin >> N;
    vector<int> v(N);
    string A = "APPROVED";
    string D = "DENIED";
    for(int i=0;i<N;i++){
        cin >> v.at(i);
        if(v.at(i)%2 == 0){
            if(v.at(i)%3 != 0) {
                 if(v.at(i)%5 != 0){
                cout << D;
                return 0;
                 }
            }
            


        }
    }
    cout << A;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
	int n, l;
	cin >> n >> l;
	map<string, int> m;
	rep(i, n){
		string in;
		cin >> in;
		m[in]++;
	}
	for(auto p : m){
		rep(i, p.second){
			cout << p.first;
		}
	}
	cout << endl;
	return 0;
}

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

int main(){
    ll x,n;
    cin>>x>>n;
    vector<ll> p(n);
    rep(i,n) cin>>p[i];
    sort(all(p));
    ll cnt=n-1,min=100,ans;
    for(ll i=101;i>=0;i--){
        if(cnt>=0&&i==p[cnt]){
            cnt--;
            continue;
        }
        if(abs(i-x)<=min){
            min=abs(i-x);
            ans=i;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3636
//----------BHAVIK DIWANI(PICT_COMP)---------------
#include<bits/stdc++.h>
#include<stdlib.h>
#include<stdio.h>
#define test ll t; cin>>t; while(t--)
#define FOR(p,n) for(ll i=p;i<(ll)n;i++)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define mod 1000000007
#define ll long long
#define int long long
#define ull unsigned long long
#define MAX 1000005
#define pb push_back
#define mkp make_pair
#define vi vector<int>
#define pii pair<int,int>
#define endl '\n'
#define vs vector<string>
#define mii map<int,int>
#define msi map<string,int>
#define vpii vector< pair<int, int > >
#define vpsi vector< pair< string ,int > >
#define forci(p,q) for(int i=p;i<q;i++)
ll gcd(ll a,ll b){ if(b==0) return a;    return gcd(b,a%b);}
ll lcm(ll a,ll b) { return (a/gcd(a,b)*b);}
ull power(ull a, ull b) {a %= mod;  ull res = 1;  while (b > 0) { if (b & 1) res = res * a % mod;  a = a * a % mod;  b >>= 1; }  return res%mod; }
ll modmul(ll x, ll y){return (x*y)%mod;}
ll modadd(ll x, ll y){return (x+y)%mod;}
ll modsub(ll x, ll y){return (x-y+mod)%mod;}
ll fact[1000007]={0};
void facto() {fact[0]=1;fact[1]=1;for(int i=2;i<100007;i++)fact[i]=(fact[i-1]*i)%mod;}
ll ncr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(power(fact[r],mod-2)))%mod; res=(res*(power(fact[n-r],mod-2)))%mod; return res;}
ll npr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(power(fact[n-r],mod-2)))%mod; return res;}
inline long long toint(const std::string &s) {std::stringstream ss; ss << s; long long x; ss >> x; return x;}
inline std::string tostring(long long number) {std::stringstream ss; ss << number; return ss.str();}
inline std::string tobin(long long x) {return std::bitset<63>(x).to_string();}
/*bool prime[MAX];
ull sieve(){memset(prime,true,sizeof(prime));for(ull p=2;p*p<MAX;p++){if(prime[p]==true){for(ull i=2*p;i<MAX;i+=p){prime[i]=false;}}}prime[0]=0;prime[1]=0;
}
int inv[1000001]={0};
void findinverse(){inv[1] = 1;for(int i = 2; i <=1e6 ; ++i)	inv[i] = (mod - (mod/i) * inv[mod%i] % mod) % mod;}
*/
using namespace std;
int solve()
{
	int n;
	cin>>n;
	int res=INT64_MAX;
	for(int i=1;i<=sqrt(n);i++)
	{
		if(n%i==0)
		{
			int j=n/i;
			res=min(i+j-2,res);
		}
	}
	cout<<res<<endl;
}
signed main()
{
	fastio;
//	test
		solve();
}




Measured memory_bytes: 256
import collections

n=int(input())
s=['' for _ in range(n)]
ans=[]
for i in range(n):
  x=input()
  s[i]=x
c = collections.Counter(s)
l=c.most_common()
r=len(list(set(s)))
cnt=l[0][1]
l.sort(key=lambda x: x[0])
for i in range(r):
  if cnt==l[i][1]:
    print(l[i][0])




Measured memory_bytes: 58468
s=input()
n=len(s)
ch=['0','1']
ans=[0,0]
x,y=0,1
for i in range(n):
    if s[i]==ch[x]:
        ans[0]+=1
    if s[i]==ch[y]:
        ans[1]+=1
    x=1-x
    y=1-y
    
print(min(ans))

Measured memory_bytes: 39664
import java.io.*;
public class Main {
    public static void main(String[] args) throws IOException{
        BufferedReader buf=new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sbu=new StringBuilder();
        int x=Integer.parseInt(buf.readLine());
        String[] num=buf.readLine().split(" ");
            for(int i=x-1;0<=i;i--){
                sbu.append(num[i]+" ");
                }
            int y=sbu.length();
            sbu.deleteCharAt(y-1);
            System.out.println(sbu);
            }
        }

Measured memory_bytes: 24092
#include <stdio.h>
#include <vector>
#include <queue>
#include <algorithm>
#include<string.h>
#include <math.h>
#include <stack>
#define ll long long
using namespace std;
#define DIV 998244353
int main() {
	int n, k;
	scanf("%d %d", &n, &k);
	if (k <= (n + 1) / 2)
		printf("YES\n");
	else
		printf("NO\n");
}

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

int main(){
    int N,M,ans=0;
    cin >> N >> M;

    vector<int> x(M+10),y(M+10);

    vector<int> ball(N+10);

    vector<bool> red(N+10);

    for(int i = 1;i <= M;i++){
        cin >> x.at(i); 
        cin >> y.at(i);
    }

    for(int i = 1;i <= N;i++){
        ball.at(i) = 1;
        if(i == 1)
            red.at(i) = true;
        else
            red.at(i) = false;
    }

    for(int i = 1;i <= M;i++){
            
        if(red.at(x.at(i)) == true && ball.at(x.at(i)) >= 2){
            red.at(y.at(i)) = true;
            ball.at(x.at(i))--;
            ball.at(y.at(i))++;
        }else if(red.at(x.at(i)) == true && ball.at(x.at(i)) == 1){
            red.at(x.at(i)) = false;
            red.at(y.at(i)) = true;
            ball.at(x.at(i))--;
            ball.at(y.at(i))++;
        }else{
            ball.at(x.at(i))--;
            ball.at(y.at(i))++;
            }
        


    }

    for(int i = 1;i <= N;i++){
        if(red.at(i) && ball.at(i) >= 1){
            ans++;
        }
    }


    cout << ans << endl;


}

Measured memory_bytes: 1408
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string>
#include <cmath>
#include<cstdio>
using namespace std;

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

  int A, B;
  
  cin >> A >> B;
  
  int res = max({ A + B, A - B, A*B  });
  cout << res;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define REP(i, n) for(int i = 0; i < (n); ++i)

#define endl "\n"
#define pb push_back
#define elif else if
#define cout_db cout << fixed

#define MOD 1000000007
 
const int dx[]={1,0,-1,0}, dy[]={0,-1,0,1};
const int dx_8[]={1,1,0,-1,-1,-1,0,1}, dy_8[]={0,-1,-1,-1,0,1,1,1};

typedef long long ll;

template <typename T>
inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <typename T>
inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template <typename T>
inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template <typename T>
inline T nHr(T a,T b){return nCr(a+b-1,b);}
template <typename T>
inline T POW(T a,T b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}

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

	int k, t, a[100];
	cin >> k >> t;
	int maax = -1;
	REP(i, t){
		cin >> a[i];
		if(a[i] > maax) maax = a[i];
	}
	maax += maax - 1;

	REP(i, t) maax -= a[i];

	cout << max(maax, 0) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
	int h;
	while(scanf("%d", &h), h){
		vector<vector<int> > v(5, vector<int>(h));
		for(int i = h - 1; i >= 0; --i)
		for(int j = 0; j < 5; ++j){
			scanf("%d", &v[j][i]);
		}
		int s = 0;
		bool upd = true;
		while(upd){
			upd = false;
			for(int i = 0; i < h; ++i){
				bool rm[5] = {};
				for(int j = 0; j < 3; ++j){
					if(v[j][i] && v[j][i] == v[j + 1][i] &&
					   v[j][i] == v[j + 2][i]){
						rm[j] = rm[j + 1] = rm[j + 2] = true;
						upd = true;
					}
				}
				for(int j = 0; j < 5; ++j){
					if(rm[j]){
						s += v[j][i];
						v[j][i] = 0;
					}
				}
			}
			for(int j = 0; j < 5; ++j){
				fill(remove(v[j].begin(), v[j].end(), 0), v[j].end(), 0);
			}
		}
		printf("%d\n", s);
	}
}

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

#define MAX 100010

using namespace std;

typedef long long ll;

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

    int n,k; cin >>n >> k;
    int H[n];

    for(int i = 0; i < n; i++){
        cin >> H[i];
    }

    int dp[n]; for(int i = 0; i < n; i++) dp[i] = 1000000100;
    dp[0] = 0;
    for(int i = 0; i < n-1; i++){
        for(int j = 1; j <= k && i+j < n; j++)
            dp[j+i] = min(dp[j+i],dp[i] + abs(H[i]-H[j+i]));
    }
    cout << dp[n-1] << "\n";
    return 0;
}

Measured memory_bytes: 1024