akhauriyash/Code-Regression huggingface dataset:
# -*- coding: utf-8 -*-
import math

s = input()
t = input()


s_list = list(s)
s_list.sort()

t_list = list(t)
t_list.sort(reverse=True)

count = min(len(s_list), len(t_list))
for i in range(count):
    if s_list[i] < t_list[i]:
        print("Yes")
        exit()
    elif s_list[i] == t_list[i]:
        continue
    else:
        print("No")
        exit()

if len(s_list) < len(t_list):
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3064
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD1 1000000007

int ketasum(int x) {
  int sum  = 0;
  while (x > 0) {
    sum += x % 10;
    x = x / 10;
  }
  return sum;
}

int main() {
  int N;
  cin >> N;
  int ans = 100000;
  for(int i= 1; i <N; i++){
    int a = ketasum(i) + ketasum(N-i);
    ans = min(ans,a);
  }

  cout << ans << endl;


}


Measured memory_bytes: 256
from collections import deque

N, M = [int(i) for i in input().split()]

graph = { _:[] for _ in range(N)}

for _ in range(M):
    a, b = [int(i) for i in input().split()]
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)
    
visited = [0] * N

que = deque([0])

while que:
    v = que.popleft()
    for i in graph[v]:
        if visited[i] < 1:
            visited[i]+=v+1
            que.append(i)
            
if 0 in visited:
    print('No')
else :
    print('Yes')
    for v in visited[1:]:
        print(v)

Measured memory_bytes: 45304
#include<cstdio>
#include<iostream>
#include<string>
#include<map>
#include<queue>
#include<set>

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++)

int item[111];
vector<int> cg[111];

int saiki(int a){
	if(cg[a].size()==0)return item[a];
	
	int sum=0;
	rep(i, cg[a].size()){
		sum+=saiki(cg[a][i]);
	}
	
	if(sum<item[a])return sum;
	return item[a];
}

int main(){
	while(1){
		int n;
		cin>>n;
		if(n==0)break;
		
		rep(i,111){
			item[i]=0;
			cg[i].clear();
		}
		map<string,int> N;
		
		rep(i,n){
			string a;int b;
			cin>>a>>b;
			
			N[a]=i;
			item[N[a]]=b;
		}
		
		int T;
		cin>>T;
		
		rep(i,T){
			string a;int b;
			cin>>a>>b;
			
			rep(j,b){
				string c;
				cin>>c;
				cg[N[a]].push_back(N[c]);
			}
		}
		
		string d;
		cin>>d;
		
		printf("%d\n",saiki(N[d]));
	}
}

Measured memory_bytes: 0
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner stdIn = new Scanner(System.in);
		
		int N = stdIn.nextInt();
		int[] max = new int[N];
		int[] min = new int[N];
		int[] num = new int[N];
		for(int i = 0; i < N; i++){
			num[i] = stdIn.nextInt();
			int[] box = new int[num[i]];
			box[0] = stdIn.nextInt();
			for(int j = 1; j < num[i]; j++){
				box[j] = stdIn.nextInt();
				int temp = box[j]-box[j-1];
				if( temp > max[i] ){
					max[i] = temp;
				} else if( temp < min[i] ){
					min[i] = temp;
				}
			}
		}
		for(int i = 0; i < N; i++){
			if( min[i] < 0 ){
				min[i] = -min[i];
			}
			System.out.println(max[i] + " " + min[i]);
		}
	}
}

Measured memory_bytes: 12000
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n,m = na()
s = list(ns())
s = s[::-1] #n+1

ans = []
i = 0
while True:
    j = i+m if i+m < n else n
    for k in reversed(range(i+1,j+1)):
        if s[k] == '0':
            ans.append(k-i)
            i = k
            break
    else:
        print(-1)
        exit()
    if i == n:
        break

print(*ans[::-1],sep=' ')

Measured memory_bytes: 7060
#include <vector>
#include <cstdio>
#include <cstring>
#include <queue>
#include <cctype>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <bitset>
#include <map>
#include <complex>
#include <ctime>
#include <numeric>
#include <set>

using namespace std;

typedef long long ll;

typedef struct node{
    int s, e, val, pos;
    bool operator<(const node& n) const{
        if(e != n.e) return e < n.e;
        return val > n.val;
    }
    node(){};
    node(int ss, int ee, int v, int p){
        s = ss, e = ee, val = v, pos = p;
    }
}node;

int occs[(int)1e6 + 5], tree[500005], n, ans[500005];

void update(int x, int val){
    while(x <= n){
        tree[x] += val;
        x += x & -x;
    }
}

int query(int x){
    int ret = 0;
    while(x > 0){
        ret += tree[x];
        x -= x & -x;
    }
    return ret;
}

int main()
{
#ifndef ONLINE_JUDGE
    freopen("in.in", "r", stdin);
#endif
    
    int q, s, e;
    vector<node> v;
    scanf("%d", &n);
 scanf("%d", &q);
    for(int i = 1; i <= n; i++){
        scanf("%d", &s);
        v.push_back(node(i, i, s, -1));
    }
   
    for(int i = 0; i < q; i++){
        scanf("%d %d", &s, &e);
        v.push_back(node(s, e, 0, i));
    }
    
    sort(v.begin(), v.end());
    
    for(int i = 0;i < v.size(); i++){
        if(v[i].val == 0){
            ans[v[i].pos] = query(v[i].e) - query(v[i].s - 1);
        }else{
            if(occs[v[i].val] != 0) update(occs[v[i].val], -1);
            update(v[i].s, 1);
            occs[v[i].val] = v[i].s;
        }
    }
    
    for(int i = 0; i < q; i++){
        printf("%d\n", ans[i]);
    }
    
    return 0;
}



Measured memory_bytes: 25396
n = int(input())
D = map(int, input().split())
m = int(input())
T = map(int, input().split())
def count(A):
    B = {}
    for a in A:
        B[a] = B.get(a, 0) + 1
    return B

E = count(D)
U = count(T)

ok = 1
for u in U:
    if not U[u] <= E.get(u, 0):
        ok = 0
print("YES"*ok or "NO")


Measured memory_bytes: 67412
"""
C
"""
import sys
N,M=map(int,input().split())
sc=[list(map(int,input().split())) for i in range(M)]

for i in range(10**N):
    if len(str(i))<N:
        continue
    lst=list(str(i))
    for s,c in sc:
        if int(lst[s-1])==c:
            continue
        else:
            break
    else:
        print(i)
        sys.exit()
print(-1)

Measured memory_bytes: 38256
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define ld long double
#define F first
#define S second
#define pii pair<ll,ll>

using namespace :: std;

const ll maxn=5009;
const ll inf=1e9+500;
const ll mod=1e9+7;

ll poww(ll a,ll b){
    ll ans=1;
    while(b){
        if(b&1){
            ans=(ans*a)%mod;
        }
        a=(a*a)%mod;
        b>>=1;
    }
    return ans;
}
ll dp[maxn][maxn];
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

    ll n;
    cin>>n;
    string s;
    cin>>s;
    ll m=s.size();

    dp[0][0]=1;
    for(ll i=1;i<=n;i++){
        dp[i][0]=(dp[i-1][1]+dp[i-1][0])%mod;;
        for(ll j=1;j<=n;j++){
            dp[i][j]=(dp[i-1][j-1]*2+dp[i-1][j+1])%mod;
        }
    }
    cout<<(dp[n][m]*poww(poww(2,m),mod-2))%mod;
}


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

class D
{
	static void Main()
	{
		var p2 = Enumerable.Range(0, 30).Select(i => (int)Math.Pow(2, i)).ToArray();
		var n = int.Parse(Console.ReadLine());
		Func<int[]> read = () => Console.ReadLine().Split().Select(int.Parse).ToArray();
		var a = read();
		var b = read();

		var r = 0;
		for (int k = 0; k <= 28; k++)
		{
			var mask = p2[k + 1] - 1;
			var a2 = Array.ConvertAll(a, x => x & mask);
			var b2 = Array.ConvertAll(b, x => x & mask);
			Array.Sort(a2);
			Array.Sort(b2);

			int c = 0, j1 = 0, j2 = 0, j3 = 0;
			for (int i = n - 1; i >= 0; i--)
			{
				var v = p2[k] - a2[i];
				while (j1 < n && b2[j1] < v) j1++;
				v += p2[k];
				while (j2 < n && b2[j2] < v) j2++;
				v += p2[k];
				while (j3 < n && b2[j3] < v) j3++;

				c ^= j2 - j1 + n - j3;
			}
			if (c % 2 == 1) r |= p2[k];
		}
		Console.WriteLine(r);
	}
}


Measured memory_bytes: 51372
#include<cstdio>
typedef long long ll;
ll pw[20];
ll dfs(int l,int r,ll d){
	if(l>r)return!d;
	if(l==r)return d?0:10;
	ll k=pw[r]-pw[l],t=d/k,s=0;
	if(t<10)s+=dfs(l+1,r-1,d-k*t)*(10-t-!l);
	if(t+1<10)s+=dfs(l+1,r-1,k*t+k-d)*(9-t-!l);
	return s;
}
int main(){
	int D;scanf("%d",&D);
	ll ans=0;
	for(int i=*pw=1;i<=18;i++){
		pw[i]=pw[i-1]*10;
		ans+=dfs(0,i,D);
	}
	printf("%lld\n",ans);
} 

Measured memory_bytes: 128
#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstdio>
#include <stack>
#include <queue>

using namespace std;
int main(){
	int ab[10]={0};
	int ta=0,tb=0;
	

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

	for(int i=0;i<8;i++){
		if(3<i){
			tb+=ab[i];
		}
		
		else ta+=ab[i];
	}

	if(ta>tb){
		cout << ta << endl;
	}
	else cout << tb << endl;
	return 0;
}

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

int main(){
    string s;
    cin >> s;
    int n = s.size() + 1;
    vector<int> greater(n, 0);
    vector<int> smaller(n, 0);
    for (int i = 1; i <= n-1; i++) {
        if (s[i-1] == '<') greater[i] = greater[i-1]+1;
    }
    for (int i = n-2; i >= 0; i--) {
        if (s[i] == '>') smaller[i] = smaller[i+1]+1;
    }
    
    ll ans = 0;
    for (int i = 0; i < n; i++) ans += max(greater[i], smaller[i]);
    cout << ans << endl;
}

Measured memory_bytes: 4740
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
void *wmem;
char memarr[96000000];
template<class T> inline void walloc1d(T **arr, int x, void **mem = &wmem){
  static int skip[16] = {0, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1};
  (*mem) = (void*)( ((char*)(*mem)) + skip[((unsigned long long)(*mem)) & 15] );
  (*arr)=(T*)(*mem);
  (*mem)=((*arr)+x);
}
inline void rd(long long &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(long long x){
  int s=0;
  int m=0;
  char f[20];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
template<class T> int Factor_L(T N, T fac[], int fs[]){
  T i;
  int sz = 0;
  if(N%2==0){
    fac[sz] = 2;
    fs[sz] = 1;
    N /= 2;
    while(N%2==0){
      N /= 2;
      fs[sz]++;
    }
    sz++;
  }
  for(i=3;i*i<=N;i+=2){
    if(N%i==0){
      fac[sz] = i;
      fs[sz] = 1;
      N /= i;
      while(N%i==0){
        N /= i;
        fs[sz]++;
      }
      sz++;
    }
  }
  if(N > 1){
    fac[sz] = N;
    fs[sz] = 1;
    sz++;
  }
  return sz;
}
template<class T> int Divisor_L(T N, T res[], void *mem = wmem){
  int i;
  int j;
  int k;
  int s;
  int sz = 0;
  T *fc;
  int *fs;
  int fsz;
  walloc1d(&fc, 100, &mem);
  walloc1d(&fs, 100, &mem);
  fsz =Factor_L(N, fc, fs);
  res[sz++] = 1;
  for(i=(0);i<(fsz);i++){
    s = sz;
    k = s * fs[i];
    for(j=(0);j<(k);j++){
      res[sz++] = res[j] * fc[i];
    }
  }
  sort(res, res+sz);
  return sz;
}
template<class S, class T> inline S chmin(S &a, T b){
  if(a>b){
    a=b;
  }
  return a;
}
long long N;
int ys;
long long y[100000];
int main(){
  int i;
  wmem = memarr;
  long long res = 4611686016279904256LL;
  rd(N);
  ys =Divisor_L(N, y);
  for(i=(0);i<(ys);i++){
    chmin(res, N/y[i] + y[i] - 2);
  }
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20191027-1

// --- original code ---
// ll N;
// int ys; ll y[1d5];
// {
//   ll res = ll_inf;
//   rd(N);
//   ys = Divisor(N, y);
//   rep(i,ys) res <?= N/y[i] + y[i] - 2;
//   wt(res);
// }

Measured memory_bytes: 256
N = int(input())
S = list(input())
ans = []
for i in range(len(S)):
    if (ord(S[i])+N) > 90:
        ans.append(chr(ord(S[i])+N-90+64))
    else:
        ans.append(chr(ord(S[i])+N))
print(*ans,sep='')

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,M,K,ok=0; cin >> N >> M >> K;
    for (int i=0;i<=N;++i)
        for (int j=0;j<=M;++j)
            if (i*j+(N-i)*(M-j)==K) ok=1;
    cout << (ok?"Yes":"No") << '\n';
}

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

int n,m;
bool graph[55][55];
bool visited[55];
int a[55],b[55];
void dfs(int pos){
  if(visited[pos])
    return;
  
  visited[pos]=true;
  for(int i=0;i<n;++i)
    if(graph[pos][i])
      dfs(i);
}

int main(){
  std::fill((bool*)graph,(bool*)(graph+55),false);
  std::cin>>n>>m;
  for(int i=0;i<m;++i){
    std::cin>>a[i]>>b[i];
    --a[i],--b[i];
    graph[a[i]][b[i]]=graph[b[i]][a[i]]=true;
  }
  
  int ans=0;
  for(int i=0;i<m;++i){
    std::fill((bool*)visited,(bool*)(visited+n),false);
    graph[a[i]][b[i]]=graph[b[i]][a[i]]=false;
    dfs(0);
    for(int i=0;i<n;++i)
      if(!visited[i]){
        ++ans;
        break;
      }
     graph[a[i]][b[i]]=graph[b[i]][a[i]]=true;
  }
  std::cout<<ans<<std::endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll linf = (1ll << 61);
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, m;
	cin >> n >> m;
	vector<vector<int>> g(n);
	rep(i, m) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	queue<int> que;
	vector<int> ans(n, -1);
	que.push(0);
	vector<bool> vi(n);
	ans[0] = 0;
	while (que.size()) {
		int v = que.front(); que.pop();
		vi[v] = true;
		for (int c : g[v]) {
			if (vi[c]) continue;
			ans[c] = v;
			vi[c] = true;
			que.push(c);
		}
	}
	if (find(all(ans), -1) != ans.end()) printf("%s\n", "No");
	else {
		printf("%s\n", "Yes");
		rrep(i, n) printf("%d\n", ans[i] + 1);
	}
	return 0;
}


Measured memory_bytes: 10268
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <string>
#include <tuple>
#include <functional>
#include <numeric>
#include <cmath>
#include <iomanip>
#include <map>
#include <random>
//#include "toollib.h"
//#include "puzzle.h"
#define INT_MAX 2147483647
#define Loop(i, n) for(int i = 0; i < (int)n; i++)
#pragma warning (disable:4018)
#pragma warning (disable:4244)

using namespace std;
typedef long long int lint;


//***** Main Program *****

bool compare(pair<char, int> a, pair<char, int>b) {
	if (a.second < b.second) return true;
	else return false;
}

int main() {
	int N;
	cin >> N;
	vector<pair<char, int>> A(N), B(N);
	Loop(i, N) cin >> A[i].first >> A[i].second;
	B = A;
	//bubble
	Loop(i, N) {
		for (int j = N - 1; j >= i + 1; j--) {
			if (compare(A[j], A[j - 1])) {
				pair<char, int> pass = A[j];
				A[j] = A[j - 1];
				A[j - 1] = pass;
			}
		}
	}
	cout << A[0].first << A[0].second;
	for (int i = 1; i < N; i++) cout << " " << A[i].first << A[i].second;
	cout << endl << "Stable" << endl;
	//Selection
	Loop(i, N) {
		int a = i;
		for (int j = i; j < N; j++) {
			if (compare(B[j], B[a])) a = j;
		}
		if (a != i) {
			pair<char, int> pass = B[i];
			B[i] = B[a];
			B[a] = pass;
		}
	}
	cout << B[0].first << B[0].second;
	for (int i = 1; i < N; i++) cout << " " << B[i].first << B[i].second;
	cout << endl;
	bool judge = true;
	Loop(i, N) {
		if (A[i] != B[i]) {
			judge = false;
			break;
		}
	}
	if (judge) cout << "Stable" << endl;
	else cout << "Not stable" << endl;
	return 0;
}

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

string s, t, u;
map<string, int> cnt;
int ans;

void in();
void solve();
void out();

int main(){
    in();
    solve();
    out();
}

void in(){
    ios::sync_with_stdio(false);
    cout.tie(0);
    cin.tie(0);
    cin >> s;
}

void solve(){
    for(int i = 0; i < s.size(); i++)
        s[i] = 'x';
}

void out(){
    cout << s;
}


Measured memory_bytes: 256
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;
import std.container;

alias sread = () => readln.chomp();
ulong MOD = 1_000_000_007;
ulong INF = 1_000_000_000_000;
alias Goods = Tuple!(long, "w", long, "v");

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}

void main()
{
    auto s = sread();
    long cnt, left, right = s.length - 1;
    bool batch = true;
    while (left <= right)
    {
        if (s[left] == s[right])
            left++, right--;
        else if (s[left] == 'x')
            cnt++, left++;
        else if (s[right] == 'x')
            cnt++, right--;
        else
        {
            batch = false;
            break;
        }
    }
    if (batch)
        writeln(cnt);
    else
        writeln(-1);
}


Measured memory_bytes: 2556
(let* ((c (make-array 27 :element-type 'uint8))
    (s (make-array '(366 27) :element-type 'uint32))
    (td 0)
    (ans 0)
    (last (make-array '(27) :initial-element 0 :element-type 'uint32)))

    (loop for i from 1 to 26 do
        (setf (aref c i) (read))
    )
    (loop for i from 1 to 365 do
        (loop for j from 1 to 26 do
            (setf (aref s i j) (read))
        )
    )
    (loop for d from 1 to 365 do
        (let ((x 1))
            (loop for i from 2 to 26 do
                (if (<= (aref s d x) (aref s d i))
                (setq x i)
                )
            )
            (setq td x)
            (setf (aref last td) d)
            (incf ans (aref s d td))
            (loop for j from 1 to 26 do
                (decf ans (* (aref c j) (- d (aref last j))))
            )
            (format t "~D~%" x)
        )
    )
)

Measured memory_bytes: 29660
import fractions
import functools
import sys

n=int(input())
a = [int(i) for i in input().split()]
a.sort()

if len(a) == 2:
  print(max(a))
  sys.exit()
  
gcd_a = functools.reduce(fractions.gcd, a)
a=[i//gcd_a for i in a]

so = 0
cnt = 0
gcd_0 = functools.reduce(fractions.gcd, a[1:])
for i in range(1,len(a)):
  if fractions.gcd(a[0],a[i]) == 1:
    so = i
    cnt+=1
    if cnt == 2:
      print(max(gcd_a,gcd_0*gcd_a))
      sys.exit()

a_i = [i for i in a if i != a[so]]
gcd_i = functools.reduce(fractions.gcd, a_i)

print(max(gcd_0,gcd_i)*gcd_a)
   


Measured memory_bytes: 16144
n = int(input())
L = list(map(int,input().split()))

from math import gcd
from functools import reduce

def lcm(x,y):
    return x*y//gcd(x,y)
    
a = reduce(lcm,L)

ans = 0
for i in range(n):
    ans += (a-1)%L[i]

print(ans)

Measured memory_bytes: 9804
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

void solve()
{
	int N;
	cin >> N;
	vector< vector<int> > C(N, vector<int>(N));
	for (int i = 0; i < N; ++i)
	{
		for (int j = 0; j < N; ++j)
		{
			cin >> C[i][j];
		}
	}
	long int sum = 0;
	for (int i = 0; i < N; ++i)
	{
		for (int j = i + 1; j < N; ++j)
		{
			sum += min(C[i][j], C[j][i]);
		}
	}
	cout << sum << endl;
}

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

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

using namespace std;

int main() {
  const int INF = 10000;
  string S, T;
  cin >> S >> T;

  int len_S = S.size();
  int len_T = T.size();

  int ans = INF;
  for (int i = 0; i < len_S - len_T + 1; i++) {
    int x = 0;
    for (int j = 0; j < len_T; j++) {
      if (T.at(j) != S.at(i + j)) x++;
    }
    ans = min(ans, x);
  }

  cout << ans << endl;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n) for (int i=1; i < (int)(n); i++)
#define rrep(i, n) for (int i=((int)(n)-1); i>=0; i--)
#define rreps(i, n) for (int i=((int)(n)-1); i>0; i--)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
using namespace std;
using lint = long long;
using p = pair<int, int>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main() {
  int x;
  scanf("%d", &x);
  cout << ((x == 1) ? 0 : 1) << endl;
  return 0;
}


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

using namespace std;

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

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

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

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

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

//constant
//--------------------------------------------
const double PI  = acos(-1.0);

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

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
int main(){
   while(true){
       int r0, w0, c ,r, ans=0;
       cin >> r0 >> w0 >> c >> r;
       if(r0==0&&w0==0&&c==0&&r==0) break;
       while(c>(r0+ans*r)/w0){
           ans++;
       }
       cout << ans << endl;
   }
}


Measured memory_bytes: 3088
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
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; }
typedef long long ll;
typedef pair<int,int> P;

int main(){
    int a,b;
    cin >> a >> b;
    int ans = a+b;
    if(ans>=10)cout << "error" << endl;
    else cout << ans << endl;
}

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

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

int main() {
    int x, n;
    int res=0;
    set<int> s;
    cin >> x >> n;
    rep(i,n){
        int tmp;
        cin >> tmp;
        s.insert(tmp);
    }

    rep1(i,101){
        if(s.count(i)){
            continue;
        }
        if(abs(x-i)<abs(x-res)){
            res=i;
        }
    }

    cout << res << "\n";
}

Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
    int n,max=0,max2=1,k;
    vector<int> a;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>k;
        a.push_back(k);
        if(i==0) continue;
        if(a[max]<=a[i]){
            max2=max;
            max=i;
        }else if(a[max2]<=a[i]){
            max2=i;
        }
    }for(int i=0;i<n;i++){
        if(i==max){
            cout<<a[max2]<<endl;
        }else{
            cout<<a[max]<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 2548
n, a, b = map(int, input().split())
s = input()
jap_c = 0
ab_c = 0
for i in list(s):
    if i == 'a':
        if jap_c + ab_c < a+b:
            jap_c += 1
            print('Yes')
            continue
    if i == 'b':
        if jap_c + ab_c < a+b:
            if ab_c < b:
                ab_c += 1
                print('Yes')
                continue
    print('No')

Measured memory_bytes: 9680
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <queue>
#include <map>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int dy[] = {1, 0, -1, 0};
const int dx[] = {0, 1, 0, -1};
struct edge { int cost, to; };
vector<edge> G[11];
int solve(int s)
{
    int res = 0;
    priority_queue<P, vector<P>, greater<P>> que;
    vector<int> dist(11, INF);
    dist[s] = 0;
    que.push(P(0, s));
    while(not que.empty())
    {
        P now = que.top(); que.pop();
        //if(dist[now.second] < now.first) continue;
        for(int u = 0; u < G[now.second].size(); u++)
        {
            edge e = G[now.second][u];
            if(now.first + e.cost < dist[e.to])
            {
                dist[e.to] = now.first + e.cost;
                que.push(P(dist[e.to], e.to));
            }
        }
    }
    for(int i = 0; i <= 10; i++)
    {
        if(dist[i] == INF) continue;
        res += dist[i];
    }
    if(res == 0) return INF;
    return res;
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    while(cin >> n, n)
    {
        for(int i = 0; i <= 10; i++) G[i].clear();
        for(int i = 0; i < n; i++)
        {
            int from, to, cost;
            cin >> from >> to >> cost;
            G[from].push_back({cost, to});
            G[to].push_back({cost, from});
        }
        int ans = INF, u = -1;
        for(int s = 0; s <= 10; s++)
        {
            int cost = solve(s);
            if(cost < ans)
            {
                ans = cost;
                u = s;
            }
        }
        cout << u << " " << ans << endl;
    }
    return 0;
}


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

int main() {
  int n, l;
  cin >> n >> l;
  vector<int> a(n);
  rep(i,n) a[i] = l+i;
  int s = 0;
  rep(i,n) s += a[i];
  int ans = 1e9;
  rep(i,n) {
    int t = s-a[i];
    if (abs(t-s) < abs(ans-s)) ans = t;
  }
  cout << ans << endl;
  
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define st first
#define nd second
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define umax(x,y) x=max(x,y)
#define umin(x,y) x=min(x,y)
#define ll long long 
#define ii pair<int,int>
#define iii pair<int,ii>
#define iiii pair<ii,ii>
#define sz(x) ((int) x.size())
#define orta ((bas+son)/2)
#define all(x) x.begin(),x.end()
#define pw(x) (1<<(x))
#define inf 1000000005
#define MOD 924844033 
#define N 100005
#define M 1000003
#define LOG 20
#define KOK 250
#define EPS 0.0000001
using namespace std;

int n,m;
char s[505][505];

void solve(int col,int md) {

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

		for(int j=0;j<m;j++) {

			char put=((s[i][j]=='#' || j==col || i%2==md) && ((j>0 && j<m-1) || j==col))?'#':'.';

			printf("%c",put);

		}

		printf("\n");

	}

	printf("\n");

}

int main() {

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

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

		scanf("%s",s[i]);

	}

	solve(0,1);
	solve(m-1,0);

}

Measured memory_bytes: 1024
N = int(input())
A = list(map(int, input().split()))
A.sort()
A.reverse()
flag = 0
result = [0, 0]

while len(A) >= 2 and flag < 2:
    N = A.pop(0)
    if N == A[0]:
        result[flag] = N
        del A[0]
        flag += 1

print(result[0]*result[1])


Measured memory_bytes: 14252
#include<iostream>
#include<bitset>
#include<cstring>
using namespace std;

int len[2010],n,k,cnt,ncnt;
char s[2010][10010],ans[1000010];
bitset<10010> can[2010];
pair<int,int> vis[2][10010];

int main()
{
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++)
		scanf("%s",s[i]),len[i]=strlen(s[i]);
	can[n+1][0]=1;
	for(int i=n;i>=1;i--)
		can[i]=can[i+1]|(can[i+1]<<len[i]);
	for(int i=1;i<=n;i++)
		if(can[i+1][k-len[i]])
			vis[0][++cnt]=make_pair(i,0);
	int ii=0;
	for(int i=0;i<k;i++)
	{
		char minc='z';
		for(int j=1;j<=cnt;j++) minc=min(minc,s[vis[ii][j].first][vis[ii][j].second]);
		ans[i]=minc;
		int minid=n+1;
		ncnt=0;
		for(int j=1;j<=cnt;j++)
		{
			int nid=vis[ii][j].first,nlen=vis[ii][j].second;
			if(s[nid][nlen]!=minc)
				continue;
			if(nlen+1==len[nid])
				minid=min(minid,nid);
			else
				vis[ii^1][++ncnt]=make_pair(nid,nlen+1);
		}
		for(int j=minid+1;j<=n;j++)
			if(k-len[j]-i-1>=0&&can[j+1][k-len[j]-i-1])
				vis[ii^1][++ncnt]=make_pair(j,0);
		ii^=1;
		cnt=ncnt;
	}
	printf("%s",ans);
}


Measured memory_bytes: 23040
#include <stdio.h>
#include <stdlib.h>
#define int long long
#define p (int)(1e9 + 7)

int MOD(int a){
	a %= p;
	return a >= 0 ? a : a + p;
}

signed main(){
	int N, i, j;
	scanf("%lld", &N);
	char *s = (char *)malloc(sizeof(char) * N);
	scanf("%s", s);
	int **dp = (int **)malloc(sizeof(int *) * N);
	int **sum = (int **)malloc(sizeof(int *) * N);
	for(i = 0; i < N; i++){
		dp[i] = (int *)malloc(sizeof(int) * (i + 1));
		sum[i] = (int *)malloc(sizeof(int) * (i + 1));
	}
	for(j = 0; j < N; j++){
		dp[N - 1][j] = 1;
		sum[N - 1][j] = j + 1;
	}
	for(i = N - 2; i >= 0; i--){
		for(j = 0; j <= i; j++){
			if(s[i] == '<'){
				dp[i][j] = MOD(sum[i + 1][i + 1] - sum[i + 1][j]);
			}
			else{
				dp[i][j] = sum[i + 1][j];
			}
		}
		sum[i][0] = dp[i][0];
		for(j = 1; j <= i; j++){
			sum[i][j] = MOD(sum[i][j - 1] + dp[i][j]);
		}
	}
	printf("%lld\n", dp[0][0]);
	return 0;
}

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

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

	if ((s[0] == s[1] && s[1] == s[2]) || (s[1] == s[2] && s[2] == s[3]))
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
const int MOD = 1E9 + 9;
const int INF = 1<<29; 

long long f(long long x){
    if(x == 1) return 1;
    return f(x/2) * 2 + 1;
}

int main(){
    long long H;
    cin >> H;
    cout << f(H) << endl;
    return 0;
}

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


using namespace std;
using ll = long long;

#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define trav(a, x) for(auto& a: x)

template<class T>
void print (vector<T>& v, bool spaced = true) {
    int n = v.size();
    string space = (spaced ? " ": "");
    for (int i = 0; i < n; ++i) {
        cout << v[i] << space;
    }cout << '\n';
}

template<class T>
T gcd (T a, T b) {
    while (b) {
        a %= b;
        swap(a, b);
    }
    return a;

}

int main () {

    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    
    int n, k; cin>> n>> k;
    vector<int> v(n);
    for (int i = 0; i < n; ++i) cin>> v[i];
    sort(all(v));
    int ans = 0;
    for (int i = 0; i < k; ++i) ans += v[i];
    cout << ans << '\n';

    

    return 0;
}



Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s, t;
    cin >> s >> t;
    int n = s.size(), m = t.size();
    int dp[n + 1][m + 1];
    for (int i = 0; i <= n; i++) dp[i][0] = 0;
    for (int i = 0; i <= m; i++) dp[0][i] = 0;
    for (int i = 1; i <= n; i++){
        for (int j = 1; j <= m; j++){
            if (s[i - 1] == t[j - 1]) dp[i][j] = dp[i - 1][j - 1] + 1;
            else dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
        }
    }
    string lcs = "";
    int i = n, j = m;
    while(i && j){
        if (s[i - 1] == t[j - 1]) lcs += s[i - 1], i--, j--;
        else if (dp[i - 1][j] > dp[i][j - 1]) i--;
        else j--;
    }
    reverse(lcs.begin(), lcs.end());
    cout << lcs << endl;
}

Measured memory_bytes: 38612
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

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

    ll n;
    cin >> n;
    vll d(n);
    REP(i, n) cin >> d[i];
    VSORT(d);
    ll m = n / 2;
    ll res = d[m] - d[m - 1];
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <stdio.h>
using namespace std;

int main()
{
	double a, b, c, d, e, f;
	while (cin >> a >> b >> c >> d >> e >> f)
	{
		/*if (a == 0)
		{
			double x = (c * f - b * e) / d;
			double y = b / c;
			printf("%.3f %.3f\n", x, y);
		}
		else*/
		{
			double x = (c / a) - (a * b * f - b * c * d) / (a * a * e - a * b * d);
			double y = (a * f - c * d) / (a * e - b * d);
			printf("%.3f %.3f\n", x, y);
		}
	}

	return 0;
}

Measured memory_bytes: 1236
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;

/*
<url:https://abc057.contest.atcoder.jp/tasks/abc057_d>
問題文============================================================
 N 個の品物が与えられます。
 i 番目の品物の価値は vi(1≦i≦N) です。
 これらの品物から、A 個以上、B 個以下を選ばなければなりません。
 この制約下において、選んだ品物の価値の平均の最大値を求めてください。
 また、選んだ品物の平均が最大となるような品物の選び方が何通りあるかを求めてください。
=================================================================

解説=============================================================

 平均が最大になるには、価値の高いものから順に選んでいけばよい
 よって、平均の最大は価値の高いものから順にA個選んだ時の平均値である。
 
 選び方に関しては、重複に気をつけて計算を行う
 
================================================================
*/

ll C(int n,int m){
    m = m<(n-m) ? m : (n-m);
    if(m == 0) return 1;
    ll ans = 1;
    for(int i=1;i<=m;i++){
        ans = ans *(n-i+1)/i;
    }
    return ans;
}

int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
    int N,A,B; cin >> N >> A >> B;
    vector<ll> v(N);
    for(auto &in:v) cin >> in;
    map<ll,int> mp;
    for(int i = 0; i < N;i++) mp[v[i]]++;
    
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
    reverse(v.begin(),v.end());
    
    double S = 0;
    ll ans = 1;
    if(mp[v[0]] >= A){
        S = v[0];
        ans = 0;
        for(int i = A; i <= min(mp[v[0]],B);i++){
            ans += C(mp[v[0]],i);
        }
    }else{
        int tA = A;
        for(int i = 0; i < v.size();i++){
            int cnt = mp[v[i]];
            if(cnt < tA){
                ans *= cnt;
                tA -= cnt;
                S += v[i]*cnt;
            }else{
                ans *= C(cnt,tA);
                S += v[i] * tA;
                break;
            }
        }
        S /= A;
    }
    cout << fixed << setprecision(10) << S << endl;
    cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int search(int A[],int n, int key){
  int i=0;
  A[n]=key;
  while(A[i] != key) i++;
  return i!=n;
}
int main(){
  int i,n,A[10000+1],q,key,sum=0;
  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d",&A[i]);

  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&key);
    if(search(A,n,key)) sum++;
  }
  printf("%d\n",sum);
  return 0;
}



Measured memory_bytes: 2048
#include <iostream>
#include <cstdio>
#include <vector>
#include <set>
#define N 300005
using namespace std;

int n;
multiset<int, greater<int> > s;
vector<int> a;
int main()
{
	int i, j, t;
	multiset<int>::iterator it;
	cin >> n;
	for (i = 0; i < 1 << n; i++) {
		scanf("%d", &t);
		s.insert(t);
	}
	a.push_back(*s.begin());
	s.erase(s.begin());
	for (i = 0; i < n; i++) {
		for (j = 0; j < 1 << i; j++) {
			it = s.upper_bound(a[j]);
			if (it == s.end()) {puts("No"); return 0;}
			a.push_back(*it);
			s.erase(it);
		}
	}
	puts("Yes");
    return 0;
}

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

using namespace std;

int main()
{
    long long int n,k;
    cin>>n>>k;
    long long int ans=n;
    long long int d=n%k;
    if(d<=k/2.0)
        cout<<d;
    else
    cout<<k-d;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cassert>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
struct Edge
{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w) {}
};
using Graph = vector<vector<Edge>>;
// using Graph = vector<vector<int>>;

const long long INF = 1LL << 60;
const int INT_INF = 1000000000;

int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
// int dx[8] = {-1, -1, -1, 0, 0, 1, 1, 1}, dy[8] = {-1, 0, 1, 1, -1, 1, 0, -1};

int calc(int x)
{
  if (x == 0)
    return 0;
  x %= __builtin_popcount(x);
  return 1 + calc(x);
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N;
  cin >> N;
  string X;
  cin >> X;

  reverse(X.begin(), X.end());

  int cnt = 0;
  for (int i = 0; i < N; i++)
  {
    if (X[i] == '1')
    {
      cnt++;
    }
  }

  ll sum1 = 0, sum2 = 0;
  ll now1 = 1, now2 = 1;

  for (int i = 0; i < N; i++)
  {
    if (X[i] == '1')
    {
      sum1 = (sum1 + now1) % (cnt + 1);
      if (cnt > 1)
        sum2 = (sum2 + now2) % (cnt - 1);
    }
    now1 = (2 * now1) % (cnt + 1);
    if (cnt > 1)
    {
      now2 = (2 * now2) % (cnt - 1);
    }
  }

  now1 = 1, now2 = 1;

  vector<int> ans;

  for (int i = 0; i < N; i++)
  {
    int x = 0;
    if (X[i] == '1')
    {
      if (cnt > 1)
      {
        int d = (sum2 - now2 + cnt - 1) % (cnt - 1);
        x = 1 + calc(d);
      }
    }
    else
    {
      int d = (sum1 + now1) % (cnt + 1);
      x = 1 + calc(d);
    }
    now1 = (2 * now1) % (cnt + 1);
    if (cnt > 1)
      now2 = (2 * now2) % (cnt - 1);
    ans.push_back(x);
  }

  reverse(ans.begin(), ans.end());

  for (auto it : ans)
    cout << it << endl;
  return 0;
}

Measured memory_bytes: 4384
# 
# 1, 2, 3, 4, 5
# sum(a) = a1
# sum(偶数) = a2
# 後ろから
# 
n = int(input())
a = list(map(int, input().split()))

ans = [0]*n
for i in range(n)[::-1]:
    for j in range(0,n+1,i+1)[::-1]:
        if j == 0:
            continue
        if j-1 == i:
            if a[i] == ans[i]:
                ans[i] = 0
            else:
                ans[i] = 1
        else:
            ans[i] = (ans[i] + ans[j-1]) % 2
cnt = sum(ans)
b = []
for i in range(n):
    if ans[i] == 1:
        b.append(i+1)
print(cnt)
if cnt:
    print(*b)







Measured memory_bytes: 70492
// Ver19.03
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define INF (1 << 29) * 2
#define LLINF 4545454545454545454
#define MOD 1000000007
#define ll long long
#define ull unsigned long long
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
int upll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? -1 : *(ll *)a > *(ll *)b ? 1 : 0; }
int downll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? 1 : *(ll *)a > *(ll *)b ? -1 : 0; }
void sortup(ll *a, int n) { qsort(a, n, sizeof(ll), upll); }
void sortdown(ll *a, int n) { qsort(a, n, sizeof(ll), downll); }

int main()
{
  int n, k;
  scanf("%d%d", &n, &k);
  if (n <= 5)
  {
    printf("%d\n", 0);
    return 0;
  }
  else if (6 <= n && n <= 12)
  {
    printf("%d\n", k / 2);
    return 0;
  }
  else
  {
    printf("%d\n", k);
    return 0;
  }
}


Measured memory_bytes: 128
#include <vector>
#include <math.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <deque>
#include <map>

typedef long long ll;
#define rep(i, a, n) for(ll i = a; i<n; i++)
#define ALL(a) begin(a), end(a)
using namespace std;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        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;
}
vector<int> vec;
int vector_finder(std::vector<ll> vec, ll number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}
int main() {
    string s;
    ll N;
    //vector<vector<int>> data(3, vector<int>(4));

    map<ll, ll> mp;
    //初期値0
    //vector<int> data(i, 0);
    cin >> N;
    vector<ll> b;
    rep(i, 0, N) {
        ll a;
        cin >> a;
        mp[a] += 1;
        b.push_back(a);
    }
    ll res = 0;
  sort(b.begin(), b.end());
  b.erase(unique(b.begin(), b.end()), b.end());
    rep(i, 0, b.size()) {
        if (mp[b[i]] == b[i]) continue;

        if (mp[b[i]] > b[i]) {
            res += mp[b[i]] - b[i];
        } else {
            res += mp[b[i]];
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 7028
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int INF = 1 << 29;
const int MOD = 1000000007;

// Union-Find
class UnionFind {
   public:
    vector<int> parent;  // 根の番号
    vector<int> height;  // 木の高さ
    vector<int> count;   // 根に含まれるノードの数(根を参照したときに限る)

    // 要素数nで初期化
    UnionFind(int n) : parent(n), height(n, 1), count(n, 1) {
        for (int i = 0; i < n; i++) {
            parent[i] = i;
        }
    }

    // 木の根を求める
    int root(int x) {
        // 根の場合
        if (parent.at(x) == x) return x;
        // 根ではない場合:経路圧縮しながら根を求める
        return parent.at(x) = root(parent.at(x));
    }

    // xとyが同じ集合に属するか否か
    bool same(int x, int y) {
        return root(x) == root(y);
    }

    // xとyの属する集合を併合
    void unite(int x, int y) {
        int rx = root(x), ry = root(y);
        // 既に同じ集合にある場合
        if (rx == ry) return;

        // 木の高さが低い方を高い方につなげる
        if (height[rx] < height[ry]) {
            parent.at(rx) = ry;
            // 小さい方の大きさを大きい方に足す
            count.at(ry) += count.at(rx);
        } else {
            parent.at(ry) = rx;
            count.at(rx) += count.at(ry);
            // 同じときはyの親をxにしてxの高さを1増やす
            if (height.at(rx) == height.at(ry)) height.at(rx)++;
        }
    }

    // xの属する集合の要素数
    int element_count(int x) {
        return count.at(root(x));
    }
};

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

    vector<vector<int>> fr(n, vector<int>(0));
    vector<vector<int>> bl(n, vector<int>(0));

    UnionFind tree(n);

    rep(i, m) {
        int a, b;
        cin >> a >> b;
        // a, bを[1, n-1]の範囲にする
        a--;
        b--;
        // 友達関係は同じ連結成分
        tree.unite(a, b);
        // i番目の人の友達関係を記録
        fr.at(a).push_back(b);
        fr.at(b).push_back(a);
    }

    rep(i, k) {
        int c, d;
        cin >> c >> d;
        c--;
        d--;
        // i番目の人のブロック関係を記録
        bl.at(c).push_back(d);
        bl.at(d).push_back(c);
    }

    vector<int> ans(n, 0);

    rep(i, n) {
        // i番目の人が持つ関係の数
        int count = 0;

        // 友達関係であれば連結
        count += fr.at(i).size();

        // i番目の人のブロック関係を調べる
        for (int bb : bl.at(i)) {
            // ブロック関係と連結していたならプラス1
            if (tree.same(i, bb)) count++;
        }

        // 頂点iの連結サイズ - 同じ連結成分の中の関係の数 - 1
        ans.at(i) = tree.element_count(i) - count - 1;
        cout << ans.at(i) << " ";
    }
    cout << endl;
}


Measured memory_bytes: 13432
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;

//dfsでないやり方
vector<ll> calc_next(const vector<ll> &arr){
    vector<ll> res;
    for(auto val : arr){
        for(int j = -1; j <= 1; ++j){
            int add = (val % 10) + j;
            if(add >= 0 && add <= 9) res.push_back(val*10 + add);
        }
    }
    return res;
}

int main(){
    int k; cin >> k;
    vector<ll> all;
    vector<ll> cur;
    for(int i = 1; i <= 9;++i) cur.push_back(i), all.push_back(i);
    rep(d, 10){
        cur = calc_next(cur);
        for(auto val : cur) all.push_back(val);
    }
    cout << all[k-1] << endl;
    return 0;
}

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

class UnionFind {
    public:
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    //初期化 initialization
    UnionFind(int n){ //最初は全てが根であるとして初期化
        par = vector<int>(n,-1);
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] < 0) return x; // xの親が-ならroot
        return par[x] = root(par[x]); // xの親にxの親の根を代入
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //rxにxの根を代入
        int ry = root(y); //ryにyの根をを代入
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま，すでにくっついている
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main(){
    int n,m,k;
    cin >> n >> m >> k;
    UnionFind tree(n); // nサイズのUnionFind型の構造体treeを宣言
    vector<int> ans(n,0); // for answer
    vector< vector<int> > graph_g(n,vector<int>(0));
    // graph_gをタテn行，ヨコ0列に設定

    for(int i=0; i<m; i++){
        int u, v;
        cin >> u >> v;
        u--,v--; // input dataとc++のindex調整
        graph_g[u].push_back(v); // graph_g[u]の末尾にvを追加，u行目に1列追加してv代入
        graph_g[v].push_back(u);
        tree.unite(u,v); // uの木とvの木を併合する
    }
    
    
    vector< vector<int> > graph_b;
    graph_b.assign(n, vector<int>(0)); // タテn行，ヨコ0列
    for(int i=0; i<k; i++){
        int u,v;
        cin >> u >> v;
        u--, v--;
        graph_b[u].push_back(v);
        graph_b[v].push_back(u);
    }

    /*
    // check part
    cout << "graph_g" << endl;
    for(int i=0; i<n; i++){
        for( int j=0; j<graph_g[i].size(); j++){
            cout << "i=" << i << ",j=" << j << ", graph_g = " << graph_g[i][j] << endl;
        }
    }

    // check part
    cout << "graph_b" << endl;
    for(int i=0; i<k; i++){
        for(auto j : graph_b[i]){
            cout << "i=" << i << ",j=" << j << ", graph_b = " << graph_b[i][j] << endl;
        }
    }

    // check part
    cout << "tree" << endl;
    for(int i=0; i<n; i++){
        cout << "i=" << i << ", tree.root = " << tree.root(i) << endl;
    }
    */

    vector<int> root_num(n,0);

    for(int i=0;i<n;i++){
        root_num[tree.root(i)]++;
    }//木のノード(節)数の配列を作成
 
    /*
    //check part
    for(int i=0; i<n; i++){
        cout << "i=" << i << ", root_num = " << root_num[i] << endl;
    }
    */

    for(int i=0; i<n; i++){
        ans[i] += root_num[tree.root(i)];//所属する木のノード数, 最大の友達候補
        ans[i]-=1;//自分自身は友達候補ではないので除外
        ans[i]-=graph_g[i].size();//直の友達，すでに友達になっている人は除外
        for (auto nv : graph_b[i]){
            if (tree.same(i,nv)) ans[i] -= 1;//同じ木にいるブロックリスト
        }
     }

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

}





Measured memory_bytes: 13304