akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

#define ll long long 
#define Fastest ios_base :: sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"

int main()
{
	Fastest
	int a;
	cin >> a;
	if(a >= 1 && a <= 9) cout << a << endl;
	else if(a >= 10 && a <= 99) cout << 9 << endl;
	else if(a >= 100 && a <= 999) cout << 9 + (a-100+1) << endl;
	else if(a >= 1000 && a <= 9999) cout << 9 + 900 << endl;
	else if(a >= 10000 && a <= 99999) cout << 9+900+(a-10000+1) << endl;
	else cout << 9+900+90000 << endl;
	
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
#define repo(i, n) for(int i=1; i<=n; i++)
#define MAX 200005

using namespace std;
typedef unsigned long long ull;
typedef long long ll;

int n, k;
ll ans=0;
vector<int> h(MAX);

int main(){
  cin >> n >> k;
  rep(i, n){
    cin >> h[i];
  }
  sort(h.begin(), h.begin()+n);
  rep(i, n-k){
    ans+=h[i];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define MOD (1000000007)
#define vi vector<int>
#define vl vector<ll>
#define vvi vector<vi>
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()

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

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

const ll INF = 1LL << 60;

const int dw[2] = {1,-1};

int main(){
  int H,W,K; cin >> H >> W >> K;

  vector<vector<char>> s(H,vector<char>(W));
  vector<pii> itigo;
  rep(h,H) rep(w,W) {
    cin >> s[h][w];
    if(s[h][w] == '#') itigo.pb(mp(h,w));
  }

  vvi ans(H,vi(W,-1));
  rep(i,K) {
    ans[itigo[i].first][itigo[i].second] = i+1;
  }
  rep(i,K) {
    int h = itigo[i].first;
    int w = itigo[i].second;
    ans[h][w] = i+1;
    rep(dir,2) {
      int nw = w + dw[dir];
      while(0 <= nw && nw < W && ans[h][nw] == -1) {
        ans[h][nw] = i+1;
        nw += dw[dir];
      }
    }
  }

  for(int h = 1; h < H; h++) {
    rep(w,W) if(ans[h][w] == -1) ans[h][w] = ans[h-1][w];
  }

  for(int h = H-2; h >= 0; h--) {
    rep(w,W) if(ans[h][w] == -1) ans[h][w] = ans[h+1][w];
  }

  rep(h,H) rep(w,W) {
    if(w != W-1) cout << ans[h][w] << " ";
    else cout << ans[h][w] << endl;
  }
  
}


Measured memory_bytes: 1908
#include<stdio.h>

#define N 101

void DFS(int);

int n,G[N][N],dfs[N],d[N],f[N],count=1;

int main() {
  int i,j,u,k,v;

  scanf("%d",&n);

  dfs[0] = 0;
  for(i = 0 ; i < n ; i++){
    for(j = 0 ; j < n ; j++) {
      G[i][j] = 0;
    }
  }

  for(i = 0 ; i < n ; i++) {
    scanf("%d%d",&u,&k);
    u--;
    for(j = 0 ; j < k ; j++) {
      scanf("%d",&v);
      v--;
      G[u][v] = 1;
    }
  }

  for(i = 0 ; i < n ; i++) {
    if(dfs[i] == 0) {
      DFS(i);
    }
  }

  for(i = 0 ; i < n ; i++) {
    printf("%d %d %d\n",i+1,d[i],f[i]);
  }
  return 0;
}

void DFS(int x) {
  int y;

  d[x] = count++;
  dfs[x] = 1;
  for(y = 0 ; y < n ; y++) {
    if(G[x][y] == 1 && dfs[y] == 0) {
      DFS(y);
    }
  }
  f[x] = count++;
}



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

int main(){
    int A,B,C;
    cin >> A>>B>>C;
    if((A==B)&&(A!=C)){
        cout << "Yes";
        return 0;
    }else if((A==C)&&(A!=B)){
        cout << "Yes";
        return 0;
    }else if((B==C)&&(A!=B)){
        cout << "Yes";
        return 0;
    }
    cout << "No";
    return 0;
}

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

#define F first 
#define S second

using namespace std;

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

const int N = 200010, M = 2 * N, INF = 0x3f3f3f3f;

int n, m;
int h[N], e[M], w[M], ne[M], idx;
int dist[N], q[N];

bool bfs(int u)
{
	int hh = 0, tt = -1;
	q[ ++ tt] = u;
	dist[u] = 0;
	
	while (hh <= tt)
	{
		int t = q[hh ++ ];
		
		for (int i = h[t]; ~i; i = ne[i])
		{
			int j = e[i];
			if (dist[j] == INF)
			{
				dist[j] = dist[t] + w[i];
				q[ ++ tt] = j;
			}
			else if (dist[j] != dist[t] + w[i])
			{
			// cout << t << ' ' << j << endl;
			// cout << dist[t] << ' ' << w[i] << ' ' << dist[j] << endl;
				return false;
			}
		}
	}
	return true;
}

void add(int a, int b, int c)
{
	e[idx] = b, w[idx] = c, ne[idx] = h[a], h[a] = idx ++ ;
}

int main()
{
	memset(h, -1, sizeof h);
	scanf("%d%d", &n, &m);
	for (int i = 0; i < m; i ++ )
	{
		int a, b, c;
		scanf("%d%d%d", &a, &b, &c);
		add(a, b, c), add(b, a, -c);
	}
	
	memset(dist, 0x3f, sizeof dist);
	for (int i = 1; i <= n; i ++ )
		if (dist[i] == INF && !bfs(i))
		{
			puts("No");
			return 0;
		}
	puts("Yes");
    return 0;
}

Measured memory_bytes: 6912
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
using namespace std;
int main(){
int a;
cin >>a;
  string s;
  cin >> s;
for(int i =0;i <s.size();i++){
if(s[i]+a <= 'Z'){
printf("%c", s[i]+a);
}else{

printf("%c", s[i]-26+a);
}
}
puts("");
return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <limits>
#include <numeric>
#include <set>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;

int gcd(int a, int b) {
	while (a != b) {
		if (a > b)a = a - b;
		else b = b - a;
	}
	cout << "最大公約数：" << a << endl;
	return a;
}

int main()
{
	
	int x, y;
	cin >> x >> y;
	cout << x + (y / 2) << endl;


	return 0;
}

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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, r; cin >> n >> r;
	if(n >= 10) cout << r << "\n";
	else cout << r + 100 * (10 - n) << "\n";
}

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

int main(){
  int n;
  cin>>n;
  set<int> s;
  for(int i=0,t;i<n;i++)
    cin>>t,s.insert(t);
  if(s.size()==n)
    cout<<"YES\n";
  else cout<<"NO\n";
}

Measured memory_bytes: 9600
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
// Welcome to my source code!

int main() {
    int n;
    cin >> n;
    int a[n];
    for (int i = 0; i < n; i++) cin >> a[i];
    sort(a, a+n, greater<int>());
    int Alice = 0, Bob = 0;
    for (int i = 0; i < n; i++) {
        if (i % 2) Bob += a[i];
        else Alice += a[i];
    }
    cout << Alice - Bob << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int k;
    string s;
    cin>>k>>s;
    int d=s.length();
        if(d>k)
        {
            for(int i=0;i<k;i++)
                {
                cout<<s[i];
                    if(i==k-1)
                    cout<<"...";
                }
        }
        else
            cout<<s;



}



Measured memory_bytes: 3628
n,m=map(int, input().split())
if n==m:
    ans=2
elif abs(n-m)==1:
    ans=1
else:
    ans=0
for i in range(1,n+1):
    ans*=i
    ans%=(10**9+7)
for i in range(1, m+1):
    ans*=i
    ans%=(10**9+7)
print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    int n,k;
    cin>>n>>k;
    int p[100000];
    for(int i=0;i<n;i++) cin>>p[i];
    sort(p,p+n);
    int ans=1000000001;
    for(int i=0;i<=n-k;i++){
        if(ans>p[i+k-1]-p[i]) ans=p[i+k-1]-p[i];
    }
    cout<<ans;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll MOD = 1000000007;
constexpr ll INF = 1ll<<60;

int main(int argc, char **argv)
{
	ll a, b, ab, an, bn;
	cin >> a >> b >> ab >> an >> bn;

	ll res{0};
	if (an == bn)
	{
		if (a + b < ab*2)
			res = an*a + bn*b;
		else
			res = ab*2*an;
	}
	else
	{
		if (a + b < ab*2)
			res = an*a + bn*b;
		else
		{
			ll abn = min(an, bn);
			//std::cout << "abn : " << abn*2 << std::endl;
			res += abn*ab*2;

			an -= abn, bn -= abn;
			if (an != 0)
			{
			//	std::cout << "an : " << an << std::endl;
				res += min(a*an, ab*2*an);
			}
			else
			{
				res += min(b*bn, ab*2*bn);
			}
		}
	}
	std::cout << res << std::endl;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <math.h>
int main(void) {
	int a, b, i, ans = 0, n, c;
	scanf("%d", &a);
	n = a;
	c = a;
	for (i = 9; i >= 0; i--) {
		b = pow(10, i);
		if (c >= b) {
			ans += c / b;
			c -= c / b * b;
		}
	}
	if (n%ans == 0) {
		printf("Yes");
	}
	else {
		printf("No");
	}
		
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>
#include <cctype>

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

const long long MAX = 5100000;
const long long INF = 1LL << 60;
const long long mod = 1000000007LL;
//const long long mod = 998244353LL;

using namespace std;
typedef unsigned long long ull;
typedef long long ll;

typedef string::const_iterator State;

pair<int, int> expression(State& begin);

string s;

pair<int, int> factor(State& begin) {
    if (*begin == '(') {
        begin++; // '('を飛ばす。
        auto ret = expression(begin);
        begin++; // ')'を飛ばす。
        return ret;
    }
    else {
        begin++;
        return { 1,1 };
    }
}

pair<int, int> term(State& begin) {
    auto ret = factor(begin);
    for (;begin != s.end();) {
        //cout << *begin << endl;
        if (*begin == '&') {
            begin++;
            auto p = factor(begin);
            auto tmp = ret;
            ret.second += p.second;
            chmin(ret.first, tmp.second + p.first);
        }
        else {
            break;
        }
    }

    return ret;
}

pair<int, int> expression(State& begin) {
    //cout << *begin << endl;
    auto ret = term(begin);

    for (;begin != s.end();) {
        if (*begin == '|') {
            begin++;
            auto p = term(begin);
            auto tmp = ret;
            ret.first += p.first;
            chmin(ret.second, tmp.first + p.second);
        }
        else {
            break;
        }
    }

    return ret;
}



int main()
{
	/*
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	*/
    cin >> s;
    State begin = s.begin();
    auto p = expression(begin);
    cout << p.first << " " << p.second << endl;
	return 0;
}


Measured memory_bytes: 3336
use std::io;


fn main() {
    let mut i = 1;
    loop {
        let x = read_one::<usize>();
        if x == 0 { break; }
        println!("Case {}: {}", i, x);
        i += 1;
    }
}


#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
std::str::FromStr,
T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
std::str::FromStr,
T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}


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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  for(int i=0; i<200; i++) {
    C-=B;
    if(C<=0) {
      cout << "Yes" << endl;
      return 0;
    }
    A-=D;
    if(A<=0) {
      cout << "No" << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
const int MAX = 2000010;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

ll mod_pow(ll a, ll n){
    a %= MOD;
    ll ret = 1;
    while(n > 0){
        if(n & 1LL) ret = (ret * a) % MOD;
        a = (a * a) % MOD;
        n = n >> 1;
    }
    return ret;
}

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
    COMinit();
    ll k;
    string s;
    cin >> k >> s;
    ll n = s.size();
    ll sum = n + k;
    ll ans = 0;
    rep(b, 0, k+1) {
        ll f = sum - b;
        ll tmp = ( COM(f - 1, n - 1) * mod_pow(25, k - b) ) % MOD; 
        tmp = (tmp * mod_pow(26, b)) % MOD;
        ans = (ans + tmp) % MOD;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 52128
import java.util.*;

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

        Scanner sc = new Scanner(System.in);
        
        int N = sc.nextInt();
        int K = sc.nextInt();
        
        double probability = 0;
        
        for(int i = 1; i <= N; i++){
            if ( i >= K ) {
                probability += 1.0;
            } else {
                double x =  Math.log( (double)K/i ) / Math.log(2) ;
                x = Math.max(Math.ceil(x) , 1);
                probability += 1 / Math.pow(2, x);   
            }
        }
        
        System.out.println(probability/N);
    }
}


Measured memory_bytes: 21972
#include<bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
//g++ -std=c++11 

using namespace std;

#define INF LONG_MAX/3

long long N, M;
vector<long long> tree[2005];

vector<long long> bfs(long long start) {
	queue<long long> q;
	vector<long long> pre(N);
	vector<long long> dist(N, INF);

	q.push(start);
	dist[start] = 0;

	while(!q.empty()) {
		long long cur = q.front();
		q.pop();

		for(auto next: tree[cur]) {
			if(dist[next] != INF) continue;
			pre[next] = cur;
			dist[next] = dist[cur] + 1;
			q.push(next);
		}
	}

	pair<long long, long long> best(INF, -1);
	rep(i, N) {
		if(i == start) continue;
		for(auto next: tree[i]) {
			if(next == start) {
				best = min(best, make_pair(dist[i], i));
			}
		}
	}
	if(best.first == INF) return vector<long long>(N+1);

	vector<long long> ans;
	long long cur = best.second;
	while(cur != start) {
		ans.push_back(cur);
		cur = pre[cur];
	}
	ans.push_back(cur);
	reverse(ans.begin(), ans.end());
	return ans;
}

int main(){
	cin >> N >> M;
	rep(i, M) {
		long long a, b;
		cin >> a >> b;
		a--;b--;
		tree[a].push_back(b);
	}


	vector<long long> ans(N+1);
	rep(i, N) {
		vector<long long> tmp = bfs(i);
		if(tmp.size() < ans.size()) {
			ans = tmp;
		}
	}

	if(ans.size() == N + 1) {
		cout << -1 << endl;
	} else {
		cout << ans.size() << endl;
		for(auto item: ans) cout << item + 1<< endl;
		exit(0);
	}
}


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

using namespace std;

constexpr static int MAXN = 1e6;

int n, m;
vector <int> adj[MAXN];
bool vis[MAXN];
int c[MAXN];
vector <int> q[2];

void dfs(int i) {
    if (vis[i])
        return;
    vis[i] = true;
    for (int j : adj[i])
        dfs(j);
}

int is_bipartite(int i) {
    q[0].clear();
    q[1].clear();

    q[0].push_back(i);
    int cur = 0;
    int cnt = 0;
    while (q[cur].size() > 0) {
        for (int u : q[cur]) {
            c[u] = cur;
            cnt++;
            for (int v : adj[u]) {
                if (c[v] == c[u])
                    return 0;
                if (c[v] == -1)
                    q[cur ^ 1].push_back(v);
            }
        }
        q[cur].clear();
        cur ^= 1;
    }
    return cnt;
}

int main() {
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        int u, v;
        cin >> u >> v;
        u--, v--;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }

    for (int i = 0; i < n; i++)
        c[i] = -1;

    int64_t acnt = 0, bcnt = 0, scnt = 0;
    for (int i = 0; i < n; i++) {
        if (!vis[i]) {
            dfs(i);
            int cnt = is_bipartite(i);
            if (cnt == 0)
                acnt++;
            else if (cnt == 1)
                scnt++;
            else
                bcnt++;
        }
    }

    //cout << acnt << " " << bcnt << " " << scnt << endl;

    int64_t total = 2 * bcnt * bcnt; // bb (1)
    total += acnt * acnt + 2 * acnt * bcnt;
    total += 2 * scnt * n - scnt * scnt;
    cout << total << endl;
}


Measured memory_bytes: 33024
#include <iostream>
#include <set>
#include <map>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <climits>
#include <math.h>
#include <cassert>
#include <unordered_map>
using namespace std;
#pragma warning(disable : 4996)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const ld PI = 3.14159265358979323846;
const ll MOD = 998244353;


int main() {
#ifdef _DEBUG
	freopen("input1.txt", "r", stdin);
	freopen("output2.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int a, b;
	cin >> a >> b;
	cout << a * b;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h> 
using namespace std; 
int main () 
{
    string s,t,s1;cin>>s>>t;
    int m,n;cin>>m>>n;
    cin>>s1;
    if (s==s1) cout<<m-1<<" "<<n<<endl;
    else cout<<m<<" "<<n-1<<endl;
    
    
    
    
    
    
    
    
    
    
    
    
}

Measured memory_bytes: 256
#include<iostream> 
#include<iomanip> 
#include<vector> 
#include<map> 
#include<set> 
#include<algorithm> 
#include<numeric> 
#include<limits> 
#include<bitset> 
#include<functional> 
#include<type_traits> 
#include<queue> 
#include<stack> 
#include<array> 
#include<random> 
#include<utility> 
#include<cstdlib> 
#include<ctime>
//#define _LIBCPP_DEBUG 0
//#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define all(a) (a).begin(),(a),end()
#define rep(i,n) for (ll i = 0; i < (ll)(n); ++i)	

int max(int a, int b) {
	int max;
	if (a > b) max = a;
	else max = b;
	return max;
}
int min(int a, int b) {
	int min;
	if (a < b) min = a;
	else min = b;
	return min;
}


int main(void) {
	int n, m;
	int a[110];

	cin >> n >> m;
	rep(i, n) {
		cin >> a[i];
	}

	bool can = false;
	int cnt = 0;
	int sum = 0;
	rep(i, n) {
		sum += a[i];
	}
	rep(i, n) {
		if (a[i]*4 * m >= sum ){
			cnt++;
		}
		if (cnt == m) {
			can = true;
			break;
		}
	}
	if (can) cout << "Yes" << endl;
	else cout << "No" << endl;
}


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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  string S;
  cin >> S;
  const int N = S.size();
  vector<vector<int>> nxt(400, vector<int>(N, 0));
  for (int i = 0; i < N; i++) {
    nxt[0][i] = S[i] == 'R' ? i + 1 : i - 1;
  }
  for (int k = 0; k + 1 < 400; k++) {
    for (int i = 0; i < N; i++) {
      nxt[k + 1][i] = nxt[k][nxt[k][i]];
    }
  }
  vector<int> res(N, 0);
  for (int i = 0; i < N; i++) {
    res[nxt[350][i]]++;
  }
  for (const auto& e : res) {
    cout << e << (&e == &res.back() ? '\n' : ' ');
  }
  return 0;
}


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

#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 namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;
const ll mod = 1e9+7;


int main(){
	
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    
    ll n,q;cin>>n>>q;
    vector<tuple<int,int,int>> vec;
    REP(i,n){
        ll s,t,x; cin>>s>>t>>x;
        s-=x; t-=x;
        vec.push_back(make_tuple(s,1,x));
        vec.push_back(make_tuple(t,0,x));
    }
    REP(i,q){
        ll d;cin>>d;
        vec.push_back(make_tuple(d,2,0));
    }
    sort(ALL(vec));
    set<ll> st;
    for(auto p:vec){
        ll a,b,c; tie(a,b,c)=p;
        if (b==1) st.insert(c);
        else if (b==0) st.erase(c);
        else cout<< (st.empty() ? -1 : *st.begin()) <<endl;
    }

    return 0;
}

Measured memory_bytes: 19560
N,X = map(int,input().split())
list = [int(x) for x in input().split()]
list_dist = sorted([abs(x - X) for x in list])

def gcd(a, b):
    if a < b:
        a , b = b , a
    while b:
        a, b = b, a % b
    return a

ans = list_dist[0]

for x in list_dist[1:]:
    ans = gcd(ans,x)

print(ans)

Measured memory_bytes: 14224
#include<bits/stdc++.h>
#define eps 1e-6
#define ll long long
#define IOS cin.sync_with_stdio(false);cin.tie(0);cout.tie(0);
//#define int long long
#define MEM(x,y) memset(x,y,sizeof(x))
#define rep(i,a,n) for (int i=a;i<n;i++)
#define fi first
#define se second
#define endl "\n"
#define pii pair<int,int>
#define fi first
#define se second
const ll mod=1000000007;
const int inf=0x3f3f3f3f;
const ll INF=0x3f3f3f3f3f3f3f3f;
ll Max(ll a,ll b){return a>=b?a:b;}
ll Min(ll a,ll b){return a<=b?a:b;}
ll qpow(ll a,ll b){ll s=1;while(b>0){if(b%2==1){s=s*a;}a=a*a;b=b>>1;}return s;}
ll qpowmod(ll a, ll b, ll c){ll res,t;res=1;t=a%c;while(b){if(b&1){res=res*t%c;}t=t*t%c;b>>=1;}return res;}
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;}
inline long long read(){long long k=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){k=k*10+ch-'0';ch=getchar();}return k*f;}
inline void write(long long x){if(x<0)x=-x,putchar('-');if(x>9)write(x/10);putchar(x%10+'0');}
using namespace std;
//head file
int main()
{
    ll n;
    cin>>n;
    char a[100];
    int k=0;
    while(n)
    {
        if(n%26==0)
            a[k++]='z';
        else
            a[k++]=n%26+'a'-1;
        if(n%26==0)
            n=n/26-1;
        else
            n/=26;
    }
    for(int i=k-1;i>=0;i--)
        cout<<a[i];
}


Measured memory_bytes: 3632
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func fib(n int) int {
	x, y := 1, 1
	for n > 0 {
		x, y = y, x+y
		n--
	}
	return x
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	n, err := nextInt(sc)
	if err != nil {
		panic(err)
	}
	fmt.Println(fib(n))
}

func nextText(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

func nextInt(sc *bufio.Scanner) (int, error) {
	return strconv.Atoi(nextText(sc))
}


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

using namespace std;

#define forn(a, e) for (int a = 0; a < (int)(e); a++)
#define forr(a, s, e) for (int a = s; a < (int)(e); a++)
#define fore(e, a) for (auto& e : a)

#ifdef LOCAL
#define logv(a) {cerr << #a << " = "; fore(e, a) {cerr << e << " ";} cerr << "\n";}
#define logvp(a) {cerr << #a << " = "; fore(e, a) {cerr << "(" << e.first << ", " << e.second << ") ";} cerr << "\n";}
#define logvv(a) {cerr << #a << " = \n"; fore(r, a) { fore(e, r) {cerr << e << " ";} cerr << "\n";} }
#define logvf(a, field) {cerr << #a"."#field << " = \n"; fore(e, a) { cerr << e.field << " ";} cerr << "\n"; }
#define logs(a) cerr << #a << " = " << (a) << "\n";
#define logss(a, b) cerr << #a << " = " << (a) << ", " << #b << " = " << (b) << "\n";
#define logp(a) cerr << #a << " = " << "(" << a.first << ", " << a.second << ")" << "\n";
#define cond(pred, stmt) if (pred) { stmt }
#else
#define logv(a)
#define logvp(a)
#define logvv(a)
#define logvf(a, field)
#define logs(a)
#define logss(a, b)
#define logp(a)
#define cond(pred, stmt)
#endif

using i64 = long long;
using iip = pair<i64, i64>;
using ivec = vector<int>;
using llvec = vector<i64>;
using svec = vector<string>;

template<typename T, typename Dim>
auto make_vec(T value, Dim dim) { return vector<T>(dim, value); }
template<typename T, typename Dim1, typename... Dim>
auto make_vec(T value, Dim1 dim1, Dim... dims) { return make_vec(make_vec(value, dims...), dim1); }

template<typename T>
bool uax(T& v, const T& newv) { if (v < newv) { v = newv; return true; } else return false; }
template<typename T>
bool uin(T& v, const T& newv) { if (v > newv) { v = newv; return true; } else return false; }

template<typename T>
istream& operator>>(istream& is, vector<T>& c) { for (auto& e : c) is >> e; return is; }

// template<typename ...T>
// istream& read(T&... args) { return (cin >> ... >> args); }

static mt19937 rande(123123);
template<typename T>
T rand_int(T from, T to) { uniform_int_distribution<T> distr(from, to); return distr(rande); }

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


    int a, b;
    while (cin >> a >> b) {
        cout << max(0, a - 2 * b) << endl;
    }
}


Measured memory_bytes: 256
#include <stdio.h>
int main(){
	int i;
	int n,k,q;
	scanf("%d %d %d",&n,&k,&q);
	int a [q];
	int data[n];
	for(i=0;i<n;i++){
		data[i]=0;
	}
	for(i=0;i<q;i++){
		scanf("%d",&a[i]);
		data[a[i]-1]++;
	}
	for(i=0;i<n;i++){
		if(q - k  <data[i]){
			printf("Yes\n");
		}else{
			printf("No\n");
		}
	}




	return 0;
	}


Measured memory_bytes: 1280
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace C
{
    public class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var N = int.Parse(Console.ReadLine());
            var prevT = 0;
            var prevX = 0;
            var prevY = 0;
            var isValid = true;
            var infos = new int[N][];
            for (var i = 0; i < N; i++)
            {
                infos[i] = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
            }
            foreach (var info in infos)
            {
                var t = info[0];
                var x = info[1];
                var y = info[2];
                var dt = t - prevT;
                var dx = Math.Abs(x - prevX);
                var dy = Math.Abs(y - prevY);

                if (dx + dy > dt || (dx + dy) % 2 != dt % 2)
                {
                    isValid = false;
                    break;
                }
                prevT = t;
                prevX = x;
                prevY = y;
            }

            Console.WriteLine(isValid ? "Yes" : "No");
        }
    }
}


Measured memory_bytes: 24632
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int h,a,cnt=0,b,c,d;
    cin>>h>>a;

        b=h/a;
        c=h%a;
        if(c>0)
        {
            cnt=1;
        }
        cout<<(b+cnt)<<endl;


}


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

const int maxn=1e5+7;
vector<int> to[maxn];
int n,cnt,c[maxn];
int vis[maxn];
map<pair<int,int>,int> m;

void dfs(int x,int f)
{
	cnt=max(cnt,int(to[x].size()));
	for(int i=0;i<to[x].size();++i) {
		int t=to[x][i];
		if(t==f) continue;
		dfs(t,x);
	}
}

queue<int> q;
void bfs(int x)
{
	while(!q.empty()) q.pop();
	q.push(x);
	while(!q.empty()) {
		int now=q.front();q.pop();vis[now]=1;
		int e=0;
		for(int i=0;i<to[now].size();++i) {
			int t=to[now][i];
			if(vis[t]) e=c[m[make_pair(now,t)]];
		}
		int j=1;
		for(int i=0;i<to[now].size();++i) {
			int t=to[now][i];
			if(vis[t]) continue;
			if(j==e) j++;
			c[m[make_pair(t,now)]]=j;
			j++;
			q.push(t);
		}
	}
}

int main()
{
	scanf("%d",&n);
	for(int i=1;i<n;++i) {
		int a,b;
		scanf("%d %d",&a,&b);
		m[make_pair(a,b)]=m[make_pair(b,a)]=i;
		to[a].push_back(b);
		to[b].push_back(a);
	}
	dfs(1,0);
	bfs(1);
	printf("%d\n",cnt);
	for(int i=1;i<n;++i) printf("%d\n",c[i]);
}

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

int main(){

  int a, b, c, max, mdl, min;

  cin >> a >> b >> c;

  mdl = a;
  if(mdl < b){
    max = b;
    if(max < c){
      min = a;
      mdl = b;
      max = c;
    }else if(c < mdl){
      min = c;
    }else{
      min = a;
      mdl = c;
    }
  }else{
    min = b;
    if(c < min){
      max = a;
      mdl = b;
      min = c;
    }else if(mdl < c){
      max = c;
    }else{
      max = a;
      mdl = c;
    }
  }

  cout << min << " " << mdl << " " << max << endl;

  return 0;
}



Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long K;
  long long N;
  std::cin >> K >> N;
  long long A[N] = {};
  long long B[N] = {};
  long long M = 0;
  for (size_t i = 0; i < N; i++) {
    std::cin >> A[i];
  }
  for (size_t i = 0; i < N; i++) {
    if (i == N-1) {
      B[N-1] = K - A[N-1] + A[0];
    }
    else{
      B[i] = A[i+1]-A[i];
    }
  }
  for (size_t i = 0; i < N; i++) {
    M = max(M,B[i]);
  }
  std::cout << K-M << '\n';
}


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

int main(){
  int a,b;
  string z;
  while(1){
    cin>>a>>z>>b;
    if(z == "+"){cout<<a + b<<endl;}
    else{if(z == "-"){cout<<a - b<<endl;}
      else{if(z == "*"){cout<<a * b<<endl;}
	else{if(z == "/"){cout<<a / b<<endl;}
	  else{break;}
	}
      }
    }
  }
}



Measured memory_bytes: 3168
#include <iostream>
#include <string>
#include <stack>
#include <math.h>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <vector>

using namespace std;
int n;
int a[100];
int k=0;




int main()
{
	cin >> n;
	for (int i = 0; i <= n - 1; i++) {
		cin >> a[i];
	}
	for (int i = 0; i < n; i++) {
		for (int j = n - 1; j >= i + 1; j--) {
			if (a[j - 1] > a[j]) {
				swap(a[j], a[j - 1]);
				k++;
			}
		}
	}
	for (int i = 0; i < n-1; i++) {
		cout << a[i] << " ";

	}
	cout << a[n - 1] << endl;
	cout << k << endl;
}

Measured memory_bytes: 1164
using DataStructures
const double = Float64
const int = Int64

parseint(x) = parse(int, x)
readint() = map(parseint, split(readline()))

function main()
  N = readint()[1]

  NN = Vector{int}(undef,N)
  NN .= 1

  for i in 2:N
    for j in i:i:N
      NN[j] += 1
    end
  end
  
  s = 0
  for i in 1:N
    s += i*NN[i]
  end
  
  println(s)
end

main()

Measured memory_bytes: 267680
n = int(input())
s = input()
stack_len = 0
ans = ""
streak = 0
for i in s:
    if i == ")":
        if stack_len:
            stack_len -= 1
            ans += ")"
        else:
            ans = "(" + ans + ")"
    else:
        ans += "("
        stack_len += 1
ans += ")" * stack_len
print(ans)


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

const int MOD = (int) 1e9 + 7;

map<int, int> M;
long long dp[101][63250], fp[101][63250];
vector< pair<int, int> > X;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(NULL), cout.tie(NULL);

    int N, K;
    cin >> N >> K;

    X.push_back({0, 0});

    for(int i=1; i<=N; )
    {
        int left = i, right = N, ptr = i;

        while(left <= right)
        {
            int mid = (left + right) / 2;

            if(N / i == N / mid)
                ptr = mid, left = mid + 1;
            else
                right = mid - 1;
        }

        X.push_back({i, ptr});
        i = ptr + 1;
    }

    int sz = X.size() - 1;

    for(int i=1; i<=sz; i++)
    {
        M[ X[i].second ] = i;
        dp[1][i] = X[i].second - X[i].first + 1;
        fp[1][i] = fp[1][i-1] + dp[1][i];
    }

    for(int i=2; i<=K; i++)
        for(int j=1; j<=sz; j++)
        {
            dp[i][j] = 1LL * (X[j].second - X[j].first + 1) * fp[i-1][ M[ N / X[j].first ] ] % MOD;
            fp[i][j] = (fp[i][j-1] + dp[i][j]) % MOD;
        }

    cout << fp[K][sz] << "\n";
    return 0;
}


Measured memory_bytes: 103032
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
	int r;
	cin >> r;
	if (r < 1200) {
		cout << "ABC" << endl;
	} 
	else if (r < 2800) {
		cout << "ARC" << endl;
	}
	else {
		cout << "AGC" << endl;
	}
}	

Measured memory_bytes: 3584
#include <cstdio>
#include <iostream>
#include <string.h> //for strlen
using namespace std;


int main(){
	int a, b, c;
	cin >> a >> b >> c;
	int i = 0;
	
	while((i*a)%b != c){
		i++;
		if( i*a > 10000) {
			cout << "NO" << endl;
			return 0;
		}
	}

	cout << "YES" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int x,y;
    cin>>x>>y;
    if(x==2 && y==2)cout<<"Yes"<<endl;
    else if((x==4||x==6||x==9||x==11)&&(y==4||y==6||y==9||y==11))cout<<"Yes"<<endl;
    else if((x==1||x==3||x==5||x==7||x==8||x==10||x==12)&&(y==1||y==3||y==5||y==7||y==8||y==10||y==12))cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <complex>
#include <tuple>

#define FAST ios_base::sync_with_stdio(false); cin.tie(0)
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define repr(i, a, b) for(int i=int(a); i>=int(b); i--)
#define reps(i,n) for(int i=1;i<=int(n);++i)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define iceil(x,y) (x+y-1)/y
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define all(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define LF "\n"

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

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

using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef pair<int, PII> PP;

long N,M;
vector<PLL> drink;
long ans;
bool flag=false;

/*
 * @
 * @brief	pair用の比較演算子 
 * 	std::sort(v.begin(), v.end(), sort_pair_first<T1, T2>());
 *  std::sort(v.begin(), v.end(), sort_pair_first<T1, T2, std::greater<int> >());
 */
template <class T1, class T2, class Pred = std::less<T2> >
struct sort_pair_first {
    bool operator()(const std::pair<T1,T2>&left, const std::pair<T1,T2>&right) {
        Pred p;
        return p(left.first, right.first);
    }
};


int main()
{
	FAST;
	cin >> N >> M;
	drink.resize(N);
	rep(i,N) cin >> drink[i].first >> drink[i].second;

	sort(drink.begin(), drink.end(), sort_pair_first<ll, ll>());

	// rep(i,N) {
	// 	cout << drink[i].first << ", " << drink[i].second << LF;
	// }

	rep(i,N) {
		long num;
		if (M>=drink[i].second) {
			num = drink[i].second;
		}
		else{
			num = M;
		}
		
		ans += num * drink[i].first;
		M -= num;
	}
	cout << ans << LF;

	return 0;
}

Measured memory_bytes: 1792
#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; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)

#define ALL(v) v.begin(), v.end()

int main() {
  int64_t N;
  cin >> N;
  vector<int64_t>a(N);
  REP(i,N) cin >> a[i];

  int64_t t = 1;
  int64_t c = 0;
  REP(i,N){
    if(a[i] == t){
      t++;
    }else{
      c++;
    }

  }
  if(t == 1){
    cout << -1 << endl;
    return 0;
  }
  cout << c << endl;

}

Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;

int main(){
  ios_base::sync_with_stdio(false);

  int n;
  int l[222];
  int ans = 0;
   
  cin >> n;
  n += n;
  for(int i=0;i<n;i++){
    cin >> l[i];
  }
  
  sort(l, l+n);
  
  for(int i=n-2;i>=0;i-=2){
    ans += l[i];
  }
  
  cout << ans << endl;  

  return 0;
}

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

int q(int a){
  if(a==2){
    return 3;
  }
  if(a<8 && a%2==1){
    return 1;
  }
  if(a>7 && a%2==0){
    return 1;
  }
  return 2;
}

int main() {
  int x,y;
  cin>>x>>y;
  
  if(q(x)==q(y)){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
  
}

Measured memory_bytes: 256
n=int(input())
a=list(map(lambda x: int(x), input().split()))
a.sort()
cnt=[]
val=[]
last=-1
for i in a:
    if i == last:
        cnt[-1]+=1
    else:
        cnt.append(1)
        val.append(i)
        last = i

low_val=-10
low_cnt=0
mid_val=0
mid_cnt=0
ans=0
for i, v in enumerate(val):
    if v>=low_val+3:
        ans=max(ans, low_cnt+mid_cnt)
        low_val=v
        low_cnt=cnt[i]
        mid_val=0
        mid_cnt=0
    elif v==low_val+2:
        ans=max(ans, low_cnt+mid_cnt+cnt[i])
        if mid_val>0:
            low_val=mid_val
            low_cnt=mid_cnt
            mid_val=v
            mid_cnt=cnt[i]
        else:
            low_val=v
            low_cnt=cnt[i]
            mid_val=0
            mid_cnt=0
    if v==low_val+1:
        mid_val=v
        mid_cnt=cnt[i]
ans=max(ans, low_cnt+mid_cnt)
print(ans)

Measured memory_bytes: 13964
import sys
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    Hs, Ms, He, Me, K = map(int, readline().split())
    ans = (He-Hs)*60 + (Me-Ms) -K
    print(max(ans,0))
if __name__ == '__main__':
    main()

Measured memory_bytes: 9244
#include<bits/stdc++.h>
using namespace std;
int main ()
{
    int i,j,a,b;
    int t,n,s;
    cin >> a>>b;
    t=a+b;
    n=((a)-(b));
    s=b*a;
    if(t>=n && t>=s)
    {
        cout <<t << endl;
    }
    else if(n>=t && n>=s)
    {
        cout << n <<endl;
    }
    else if(s>=t && s>=n)
    {
        cout << s << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define mst(a,b) memset((a),(b),sizeof(a))
#define mp(a,b) make_pair(a,b)
#define pi acos(-1)
#define pii pair<int,int>
#define pb push_back
#define lowbit(x) ((x)&(-x))
const int INF = 0x3f3f3f3f;
const double eps = 1e-6;
const int maxn = 1e5 + 10;
const int maxm = 1e6 + 10;
const ll mod =  998244353;

int n,m;
int du[maxn];
pii a[maxn];
vector<int>vec[maxn];
int fa[maxn];


int main() {
#ifdef local
    freopen("data.txt", "r", stdin);
//    freopen("data.txt", "w", stdout);
#endif
    mst(du, 0);
    scanf("%d%d",&n,&m);
    for(int i = 0; i < n - 1 + m; i++) {
        scanf("%d%d",&a[i].first,&a[i].second);
        vec[a[i].first].push_back(a[i].second);
        du[a[i].second]++;
    }
    queue<int>q;
    int tot = 0;
    for(int i = 1; i <= n; i++)
        if(du[i] == 0) q.push(i), fa[i] = 0;
    while(!q.empty()) {
        int u = q.front();
        q.pop();
        for(int i = 0; i < vec[u].size(); i++) {
            int v = vec[u][i];
            du[v]--;
            fa[v] = u;
            if(du[v] == 0) q.push(v);
        }
    }
    for(int i = 1; i <= n; i++) printf("%d\n",fa[i]);
    return 0;
}


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

#define rep(i,n) for (int i = 0; i< (n); ++i)
#define vvec(m,n) vector<vector<int>> (int(m), vector<int>(n))
#define ALL(a) (a).begin(), (a).end()

using ll = long long;

int main(){
    string s;
    cin >> s;
    for(char c:s){
        if(c == '1'){
            cout << '9';
        }else { 
            cout << '1';
        }
    }
}

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

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

typedef long long ll;
using namespace std;
int mod = 1000000007;

int ans = 0;
int T;

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

int grid[150][150];
bool visited[150][150];

void init(){
    ans = 0;
    rep(i, 150) rep(j, 150){grid[i][j] = 0; visited[i][j] = false;}
}

int main(void){
    int N;
    vector<int> oput;
    while(true){
        init();
        cin >> T >> N;
        if(N == 0 && T == 0) break;
        rep(i, N){
            int x, y; cin >> x >> y;
            x += 70; y += 70;
            grid[x][y] = -1;
        }
        int st_x, st_y; cin >> st_x >> st_y;
        st_x += 70; st_y += 70;
        queue<pair<int, pair<int, int>>> que;
        que.push(make_pair(0, make_pair(st_x, st_y)));
        while(!que.empty()){
            pair<int, pair<int, int>> op = que.front();
            que.pop();
            int t = op.first;
            int sx = op.second.first;
            int sy = op.second.second;
            if(visited[sx][sy]) continue;
            visited[sx][sy] = true;
            ans++;
            if(t == T) continue;
            rep(i, 6){
                int nx = sx + dx[i];
                int ny = sy + dy[i];
                if(grid[nx][ny] == 0 && !visited[nx][ny]) que.push(make_pair(t+1, make_pair(nx, ny)));
            }
        }
        /*for(int i = 25; i < 40; i++){
            for(int j = 25; j < 40; j++){
                cout << visited[i][j] << " ";
            }
            cout << endl;
        }*/
        oput.push_back(ans);
    }
    rep(i, oput.size()) cout << oput[i] << endl;
    return 0;
}


Measured memory_bytes: 3180
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;

struct Edge {int to; long long cost;};
struct Bedge { int from, to; long long cost; };

template<class T>
vector<T> Bell(const vector<vector<Edge>> &G, int s, T def) {
    int N = (int)G.size();
    vector<T> dist(N, def);
    vector<bool> negative(N);
    vector<Bedge> edges;
    for(int from = 0; from < N; ++from) {
        for(auto &e : G[from]) edges.push_back({from, e.to, e.cost});
    }
    dist[s] = 0;
    for(int loop = 0; loop < N - 1; ++loop) {
        for(auto &e : edges) {
            if(dist[e.from] == INF) continue;
            if(dist[e.to] > dist[e.from] + e.cost) {
                dist[e.to] = dist[e.from] + e.cost;
            }
        }
    }
    for(int loop = 0; loop < N; ++loop) {
        for(auto &e : edges) {
            if(dist[e.from] == INF) continue;
            if(dist[e.to] > dist[e.from] + e.cost) {
                dist[e.to] = dist[e.from] + e.cost;
                negative[e.to] = true;
            }
            if(negative[e.from]) negative[e.to] = true;
        }
    }
    for(int i = 0; i < N; ++i) {
        if(negative[i]) dist[i] = -INF;
    }
    return dist;
}

void solve() {
    int N, M;
    cin >> N >> M;
    vector<vector<Edge>> G(N);
    for(int i = 0; i < M; ++i) {
        int a, b, c;
        cin >> a >> b >> c;
        a--, b--;
        G[a].push_back({b, -c});
    }
    auto dist = Bell(G, 0, INF);
    if(dist[N - 1] == -INF) cout << "inf" << '\n';
    else cout << -dist[N - 1] << '\n';
}

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


Measured memory_bytes: 384
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  ll N, K;
  cin>>N>>K;
  ll A[N];
  for(int i=0;i<N;++i) cin>>A[i], A[i]--;
  //for(int i=0;i<N;++i) cout<<A[i]<<" "; cout<<endl;
  int now = 0;
  int start = -1;
  int dist = -1;
  int cycle = -1;
  vector<int> reached(N, -1);
  for(ll i=0;i<K;++i) {
    if(reached[now]>-1) {
      dist = reached[now];
      cycle = i-dist;
      start = now;
      break;
    }
    reached[now] = i;
    now = A[now];
  }
  if(start==-1) {
    cout<<now+1<<endl;
    return 0;
  }
  K -= dist;
  K %= cycle;
  now = start;
  for(int i=0;i<K;++i) {
    now = A[now];
  }
  cout<<now+1<<endl;
}



Measured memory_bytes: 5604
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define f(i,a,n) for(int i=a ; i<n ; i++)
#define F first
#define S second
#define vll vector<ll>
#define fast ios:: sync_with_stdio(false),cin.tie(0);
#define COUT cout<<fixed<<setprecision(12)
#define SET set<ll,greater<ll>>gquiz
#define ITERATOR set<ll,greater<ll>> :: iterator itr
#define V vector<ll>vector
#define sz size()
//#define A vector<pair<ll,ll>>vect
ll N=100000,M=100000;
#define B vect.push_back(make_pair(N,M));
ll MOD=1000000007;
 
bool isprime(ll n){if(n==1 || (n!=2 && n%2==0))return false; if(n==2)return true; 
		for(ll i=3;i<=sqrt(n);i+=2)if(n%i==0)return false; return true; }
ll gcd(ll a,ll b) 
{ 
    if (a == 0) 
        return b; 
    return gcd(b % a, a); 
} 
/*
ll ncr(ll n,ll r)
{
	if(n==1 || r==0)
	return 1;
	if(r>n/2)
	r=n-r;
	ll ans=1;
	for(ll i=1;i<=r;i++)
	{
		ans=((ans * n )/i);
		n--;
	}
	return ans;
}
*/
ll pow1(ll n,ll k,ll mm){
    if(k==0)return 1;
    if(k%2==0)return (pow1((n%mm)*(n%mm),k/2,mm))%mm;
    return ((n%mm)*(pow1((n%mm)*(n%mm),k/2,mm)%mm))%mm;
}
ll pow(ll a,ll b,ll m)
{
	ll ans=1;
	while(b>0)
	{
		if(b&1)
			ans=(ans*a)%m;
		b=b/2;
		a=(a*a)%m;
	}
	return ans;
}
 
ll modinv(ll k)
{
	return pow(k,MOD-2,MOD);
}

ll ncr(ll n,ll c)
{
    ll t=1;
    c=min(c,n-c);
    for(ll i=1;i<=c;i++)
    {
     	t=(t*(n-i+1))%MOD;
        t=(t*modinv(i))%MOD;
	}
    return t;
}

void solve()
{
	ll n,k;
	cin>>n>>k;
	ll h=n%k;
	ll ans=min(h,abs(h-k));
	cout<<ans;
}
int main()
{
	fast;
	ll t=1;
	//cin>>t;
	while(t--)
	{
		solve();
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <algorithm>
#include <bitset>
#include <tuple>
#include <set>
#include <map>
#define range(i, r) for(int i=0;i<r;i++)
#define ranges(i, l, r) for(int i=l;i<r;i++)
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi std::vector<std::vector<int> >
#define vvl std::vector<std::vector<ll> >
#define MODs 1000000007;
#define MODn 1000000009;
typedef long long int ll;
using namespace std;

int main(int argc, char const *argv[]) {
  ll N, majo=0, mino = 1000000, majo_count=0, mino_count=0;
  std::cin >> N;
  std::vector<ll> a(N);
  for(int i=0;i<N;i++){
    std::cin >> a[i];
    majo = max(majo, a[i]);
    mino = min(mino, a[i]);
  }
  //majo - mino >= 2
  if(majo-mino>=2){
    std::cout << "No" << '\n';
    return 0;
  }
  for(int i=0;i<N;i++){
    if(a[i]==majo) majo_count++;
    if(a[i]==mino) mino_count++;
  }
  //majo == mino
  if(majo==mino) std::cout << (majo*2<=N||majo==N-1?"Yes":"No") << '\n';
  // majo - mino = 1
  else if(((majo-(mino_count))*2<=N-mino_count||majo==N-1-mino_count)&&mino>=mino_count){
    std::cout << "Yes" << '\n';
  }else{
    std::cout << "No" << '\n';
  }
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    sort(a.begin(), a.end());
    reverse(a.begin(), a.end());
    int id = 0, lef = 1;
    long long ans = 0;
    for(int i = 1; i < n; i++) {
        ans += a[id];
        lef -= 1;
        if (lef == 0) {
            lef = 2;
            id += 1;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4000
#include<algorithm>
#include <iostream>
#include<cstdio>
#include<cmath>
#include<iomanip>
#include<string>
using namespace std;
int main(){
   
    int x,y;
    cin>>x>>y;
    
    if(x+y<10){
        cout<<x+y<<endl;
    }else{
        cout<<"error"<<endl;
    }
    
    
    
    return 0;
}






Measured memory_bytes: 256