akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>
#define UNKNOWN_ID -1
#define SENTINEL (1 << 30)

typedef struct { int s, t, w; } edge_t;

static void merge(edge_t *a, int left, int mid, int right) {
  int n1, n2, i, j, k;
  edge_t *l, *r;

  n1 = mid - left;
  l = (edge_t *) malloc(sizeof(edge_t) * (n1 + 1));
  for (i = 0; i < n1; ++i) l[i] = a[left + i];
  l[i].s = l[i].t = UNKNOWN_ID;
  l[i].w = SENTINEL;

  n2 = right - mid;
  r = (edge_t *) malloc(sizeof(edge_t) * (n2 + 1));
  for (i = 0; i < n2; ++i) r[i] = a[mid + i];
  r[i].s = r[i].t = UNKNOWN_ID;
  r[i].w = SENTINEL;

  for (i = j = 0, k = left; k < right; ++k) {
    if (l[i].w <= r[j].w) {
      a[k] = l[i++];
    } else {
      a[k] = r[j++];
    }
  }
  free(l); free(r);
}

static void merge_sort(edge_t *a, int left, int right) {
  int mid;

  if (left >= right - 1) return;
  mid = (left + right) / 2;
  merge_sort(a, left, mid);
  merge_sort(a, mid, right);
  merge(a, left, mid, right);
}

static int find_representative(int *ds, int i) {
  if (i != ds[i]) ds[i] = find_representative(ds, ds[i]);
  return ds[i];
}

static int kruskal(edge_t *es, int e, int *ds, int v) {
  int mst_cost, i, r1, r2;

  for (i = mst_cost = 0; i < e; ++i) {
    r1 = find_representative(ds, es[i].s);
    r2 = find_representative(ds, es[i].t);
    if (r1 != r2) {
      mst_cost += es[i].w;
      ds[r1] = r2;
    }
  }
  return mst_cost;
}

int main(int argc, char **argv) {
  int v, e, i, *ds; // disjoint-set
  edge_t x, *es;    // edges

  scanf("%d %d", &v, &e);
  ds = (int *) malloc(sizeof(int) * v);
  es = (edge_t *) malloc(sizeof(edge_t) * e);
  for (i = 0; i < v; ++i) ds[i] = i;
  for (i = 0; i < e; ++i) {
    scanf("%d %d %d", &x.s, &x.t, &x.w);
    es[i] = x;
  }
  merge_sort(es, 0, e);
  printf("%d\n", kruskal(es, e, ds, v));
  free(es); free(ds);
}


Measured memory_bytes: 3948
#include <stdlib.h>
#include <stdio.h>
#include <stdio.h>

int main()
{

    int A, L;
    scanf("%d %d", &A, &L);

    int Big = A;
    for (int i = 0; i < A+1; i++)
    {
        if (i * 2 + Big * 4 == L)
        {
            printf("Yes");
            return 0;
        }
        Big--;
    }

    printf("No");

    return 0;
}


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

using ll = long long;
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) < (b)) ? (b) : (a))

using ll = long long;
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) < (b)) ? (b) : (a))

int const nmax = 100000;
std::vector<int> g[1 + nmax];
int sz[1 + nmax];
bool verdict = 1;
void dfs(int node, int parent) {
  sz[node] = 1;
  int ned = 0;
  for(int h = 0; h < g[node].size(); h++) {
    int to = g[node][h];
    if(to != parent) {
      dfs(to, node);
      sz[node] += sz[to];
      ned += sz[to] % 2;
    }
  }
  if(1 < ned)
    verdict = 0;
}

int main() {
  int n;
  std::cin >> n;
  for(int i = 1;i < n; i++) {
    int x, y;
    std::cin >> x >> y;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  dfs(1, 0);
  if(sz[1] % 2 == 1 || verdict == 0)
    std::cout << "First";
  else
    std::cout << "Second";
  return 0;
}


Measured memory_bytes: 9576
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define P pair<int,int>
#define PI 3.141592653589793
const int INF = 1001001001;
const ll MX = 1e18;

int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i, n) cin >> a[i];
	sort(a.begin(), a.end());

	double ans = a[0];
	rep(i, n - 1) {
		ans = (ans + a[i + 1]) / 2;
	}
	cout << ans << endl;
}


Measured memory_bytes: 3788
#include<iostream>
#include<cstdlib>
#include<utility>
#include<tuple>
#include<string>
#include<vector>
#include<numeric>
#include<algorithm>
#include<queue>
#include<deque>
#include<bitset>
#include<cmath>
#include<map>
#include<iomanip>
using namespace std;
using ll = long long int;
const ll mod = 1e9 + 7;
#define rep(i, a, b) for(int i = a; i < b; i++)

int main() {
	
	int k;
	cin >> k;

	int x = 0, y = 0;
	rep(i, 1, k + 1) {
		if (i % 2 == 0) x++;
		else y++;
	}

	cout << x * y << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;
    
#define rep(i,n) for(ll (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(ll i=(a);i<(b);i++)
#define rrrep(i,a,b) for(ll i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define doublecout(a) cout<<fixed<<setprecision(15)<<a<<endl;
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 
#define U_MAP unordered_map<ll,ll>
#define pq priority_queue<ll>
#define rpq priority_queue<ll,vector<ll>,greater<ll>>
#define p_b push_back
    
ll n,cnt,ans,a[ohara],b[ohara],c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k,q;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};
    
//------ Believe yourself as a genius!!!!!! ------
    
int main(void){
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    
    cin>>n>>h;
    rep(i,n)cin>>a[i]>>b[i];
    ll nage=0;
    rep(i,n){
        nage=max(nage,a[i]);
    }
    sort(b,b+n);
    reverse(b,b+n);
    rep(i,n){
        if(h<=0||b[i]<nage)break;
        h-=b[i];
        ans++;
    }
    if(h>0)ans+=(h%nage==0 ? h/nage : h/nage+1);
    Cout(ans);
    return 0;
}

Measured memory_bytes: 5120
#include <bits/stdc++.h>
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define IFOR(i, m, n) for(int i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
const int MOD = 1000000007;
/* テンプレートここまで */

ll modpow(ll a , ll b){
  if (b == 0) return 1;

  if (b%2 == 0){
    ll  t = modpow(a, b/2)%MOD;
    return t*t % MOD;
  }else{
    ll t = modpow(a, (b-1)/2)%MOD;
    return a*t %MOD * t % MOD;
  }
}


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

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

  sort(ALL(a));
  bool valid = true;

  if(N%2 !=0){
    if(a[0] != 0) valid = false;
    FOR(i, 1, N/2 + 1){
      if(a[2*i-1] != 2*i || a[2*i] != 2*i ) valid = false;
    }
  }else{
    FOR(i, 0, N/2){
      if(a[2*i] != 2*i + 1|| a[2*i + 1] != 2*i + 1 ) valid = false;
    }
  }

  if(valid){
    cout << modpow(2, N/2) << endl;
  }else{
    cout << 0 << endl;
  }
}


Measured memory_bytes: 640
#include <algorithm>
#include <climits>
#include <complex>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <vector>

// using
using namespace std;

// typedef
typedef long long ll;

// define
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REVERSE(c) reverse(ALL(c))
#define UNIQ(c) unique(ALL(c))
#define FOR(i, a, b, c) for (int i = (int)(a); i < (int)(b); i += (int)(c))
#define REP(i, n) FOR(i, 0, n, 1)
#define RFOR(i, a, b, c) for (int i = (int)(a); i >= (int)(b); i -= (int)(c))
#define RREP(i, n) RFOR(i, n, 0, 1)

// functions
int ceil(int a, int b) {
    return (a + b - 1) / b;
}
int round(int a, int b) {
    return (a + b / 2) / b;
}
int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
template <class T> bool amax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> bool amin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

// main
int main() {
    string S;
    cin >> S;
    SORT(S);
    if (S[0] == 'a' && S[1] == 'b' && S[2] == 'c') {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
n, k, q = map(int, input().split())
x = [0]*n
for i in range(q):
  a = int(input())
  a -= 1
  x[a] += 1

y = [k]*n
for i in range(n):
  y[i] -= (q-x[i])
  if y[i] <= 0:
    print('No')
  else:
    print('Yes')
  

Measured memory_bytes: 8520
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5 + 5;
ll t[N * 4], lazy[N * 4];

void push(int v) {
    t[v*2] += lazy[v];
    lazy[v*2] += lazy[v];
    t[v*2+1] += lazy[v];
    lazy[v*2+1] += lazy[v];
    lazy[v] = 0;
}

void update(int v, int tl, int tr, int l, int r, ll addend) {
    if (l > r)
        return;
    if (l == tl && tr == r) {
        t[v] += addend;
        lazy[v] += addend;
    } else {
        push(v);
        int tm = (tl + tr) / 2;
        update(v*2, tl, tm, l, min(r, tm), addend);
        update(v*2+1, tm+1, tr, max(l, tm+1), r, addend);
        t[v] = max(t[v*2], t[v*2+1]);
    }
}

ll query(int v, int tl, int tr, int l, int r) {
    if (l > r)
        return -1e18;
    if (l <= tl && tr <= r)
        return t[v];
    push(v);
    int tm = (tl + tr) / 2;
    return max(query(v*2, tl, tm, l, min(r, tm)),
               query(v*2+1, tm+1, tr, max(l, tm+1), r));
}

vector<pair<int, int>> intervals[N];

int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        int l, r, a;
        cin >> l >> r >> a;
        intervals[r].push_back({l, a});
    }
    for (int i = 1; i <= n; i++) {
        ll mx = query(1, 1, n, 1, i);
        update(1, 1, n, i, i, mx);
        for (auto q : intervals[i])
            update(1, 1, n, q.first, i, q.second);
    }
    cout << max(0LL, query(1, 1, n, 1, n));
    return 0;
}


Measured memory_bytes: 22912
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<ll,ll> ii;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define RST(i,n) memset(i,n,sizeof i)
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(),a.end()
#define X first
#define Y second
#define mkp make_pair
#define pb push_back
#define eb emplace_back
#define pob pop_back
#ifdef cold66
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<", ";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // cold66
//}
template<class T> inline bool chkmax(T &a, const T &b) { return b > a ? a = b, true : false; }
template<class T> inline bool chkmin(T &a, const T &b) { return b < a ? a = b, true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;

const ll MAXn=1e3+5,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=0x3f3f3f3f;
const ll MAXw=1e4+5;

struct block{
  ll w,s,v;
  bool operator < (const block &a) const {
    return w + s < a.w + a.s;
  }
} d[MAXn];
ll dp[MAXw];
int main(){
  IOS();
  ll n;
  cin >> n;
  REP (i,n) cin >> d[i].w >> d[i].s >> d[i].v;
  sort(d,d+n);

  ll ans = 0;
  REP (i,n) {
    for (ll j=d[i].s;j>=0;j--) {
      ll tmp = dp[j] + d[i].v;
      ans = max(ans,tmp);
      if (j + d[i].w < MAXw) dp[j+d[i].w] = max(dp[j+d[i].w],tmp);
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main() {
  string S;
  cin >> S;
  if (S.at(2) == S.at(3) && S.at(4) == S.at(5)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h> 

using namespace std;
int main(){
	int A, B;
	string op;
	cin>>A>>op>>B;
	if(op=="+"){
		cout<<A+B;
	}else if(op=="-"){
		cout<<A-B;
	}
	return 0;
	
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

int main() {
		int N;
		cin >> N;
		int A[N];
		for (int i = 0; i < N; i++) cin >> A[i];

		int L[N], R[N];
		L[0] = A[0], R[0] = A[N-1];
		for (int i = 1; i < N; i++) {
				L[i] = gcd(L[i-1], A[i]);	
				R[i] = gcd(R[i-1], A[N-1-i]);
		}

		int ans = 0;
		for (int i = 0; i < N; i++) {
				if (i==0) ans = max(ans, R[N-2]);
				else if (i==N-1) ans = max(ans, L[N-2]);
				else ans = max(ans, gcd(L[i-1], R[N-i-2]));
		}

		cout << ans << endl;

		return 0;
}


Measured memory_bytes: 1408
#pragma GCC optimize("O2")
#include <iostream>
#include <vector>
#include <algorithm>
#include <bitset>
#include <unordered_set>
#include <map>
#include <string>
#include <cmath>
#include <queue>
#include <ctime>
#include <set>

using namespace std;

typedef long long ll;
typedef long double ld;
#define fastInp cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);

const ll SIZE = 1e5 * 2 + 10;

vector<vector<ll>> add;
vector<ll> costs;
ll q;

int main() {
    fastInp;

    ll n, m, x;
    cin >> n >> m >> x;

    add.resize(n);
    costs.resize(n);
    for (int i = 0; i < n; i++) {
        ll c;
        cin >> c;
        costs[i] = c;
        add[i].resize(m);
        for (int j = 0; j < m; j++) {
            cin >> add[i][j];
        }
    }
    
    ll pw = (1ll << n);

    ll ans = INT64_MAX;
    for (int i = 1; i < pw; i++) {
        vector<ll> cur(m);
        ll curC = 0;
        for (int j = 0; j < n; j++) {
            if (i & (1ll << j)) {
                curC += costs[j];
                for (int k = 0; k < add[j].size(); k++) cur[k] += add[j][k];
            }
        }

        bool flag = true;
        for (int k = 0; k < m; k++) {
            if (cur[k] < x) flag = false;
        }

        if (flag) ans = min(ans, curC);
    }

    if (ans == INT64_MAX) {
        cout << "-1";
    }
    else {
        cout << ans;
    }
    return 0;
}

Measured memory_bytes: 3624
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int k = sc.nextInt();
    if(k%2==0){
      System.out.println((k/2)*(k/2));
    }else{
      System.out.println((k/2)*((k/2)+1));
    }
  }
  

  
}

Measured memory_bytes: 23124
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
    ll t,i,j,k,l,n,m;
    cin>>n>>k;
    vector<ll> val(n),wt(n);
    l=0;
    for(i=0;i<n;i++)
    {
        cin>>wt[i]>>val[i];
        l+=val[i];
    }
    vector<ll> dp(l+1,INT_MAX);
    dp[0]=0;
    for(i=0;i<n;i++)
    {
        for(j=l;j>=val[i];j--)
        dp[j]=min(dp[j],dp[j-val[i]]+wt[i]);
    }
    j=0;
   // cout<<k<<" "<<l<<endl;
    for(i=0;i<=l;i++)
    {
        //cout<<dp[i]<<endl;
        if(dp[i]<=k)
    j=i;
    }
    cout<<j;
    
    return 0;
}

Measured memory_bytes: 4032
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  int N;
  cin >> N ;

  int A=(N-N%1000)/1000;
  int B=((N-1000*A)-(N-1000*A)%100)/100;
  int C=((N-1000*A-100*B)-(N-1000*A-100*B)%10)/10;
  int D=N%10;
    //N=ABCD

  if(A==B && B==C){
    cout << "Yes" << endl;
  }
  else if (B==C && C==D){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

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

int main() {
  int N, M; cin >> N >> M;
  vector<long long> A(N);
  vector<long long> S(N+1);
  S[0] = 0;
  map<int, int> m;
  for(int i = 0; i < N; ++i) {
    cin >> A[i];
    S[i+1]  = (S[i] + A[i]) % M;
  }
  long long ans = 0;
  for(int i = 0; i < S.size(); ++i) {
    ans += m[S[i]];
    m[S[i]]++;
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 4736
#include <algorithm>
#include <array>
#include <bitset>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
#define int long long
constexpr long long INF = 1000000000000000000LL + 8;
constexpr int MAXN = 100000;
using P = pair<int, int>;

class Graph {
   private:
    struct edge {
        int to;
        int cost;
        edge(int i, int c) : to(i), cost(c) {}
    };
    vector<vector<edge>> edges;
    vector<int> dists;

   public:
    Graph(int n) { edges.resize(n); };
    int size() const { return edges.size(); };
    int countEdge() const {
        int count = 0;
        for (auto &&i : edges)
            for (auto &&j : i) count++;
        return count;
    }
    void addDirectedEdge(int from, int to, int cost) {
        edges[from].push_back(edge(to, cost));
    }
    void addEdge(int from, int to, int cost) {
        addDirectedEdge(from, to, cost);
        addDirectedEdge(to, from, cost);
    }

    void dijkstrta(int s) {
        dists.assign(size(), INF);
        priority_queue<P, vector<P>, greater<P>> pq;
        pq.push({0, s});
        dists[s] = 0;

        while (!pq.empty()) {
            // 仮の最短距離と頂点の集合のうち、最短距離が最小の頂点を「最短距離が確定した頂点」とする
            int p = pq.top().second, p_dists = pq.top().first;
            pq.pop();
            // ある経路で仮の最短距離と頂点の集合に追加されたが、別の経路で「最短距離が確定した頂点」は更新しない
            if (dists[p] < p_dists) continue;

            // 「最短距離が確定した頂点」と隣接した頂点の最短距離を更新する
            for (auto &&next_edge : edges[p]) {
                const int np = next_edge.to;
                const int cost = next_edge.cost;
                if (dists[np] > dists[p] + cost) {
                    dists[np] = dists[p] + cost;
                    // 仮の最短距離と頂点の集合に追加する
                    pq.push({dists[np], np});
                }
            }
        }
    }
    int distance(int i) const { return dists[i]; }
};

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

    int n, m, s, t;
    cin >> n >> m >> s >> t;
    s--;
    t--;

    Graph g_yen(n), g_snuuk(n);
    for (int i = 0; i < m; i++) {
        int u, v, a, b;
        cin >> u >> v >> a >> b;
        u--;
        v--;  // convert to 0-based
        g_yen.addEdge(u, v, a);
        g_snuuk.addEdge(u, v, b);
    }

    g_yen.dijkstrta(s);
    g_snuuk.dijkstrta(t);

    const int initial_yen = 1e15;
    vector<int> answers(n);

    // 旅費リスト
    priority_queue<int> travel_costs;
    // i年に旅行したときの旅費を計算する
    for (int i = n - 1; i >= 0; i--) {
        // 都市sから都市i+1に円を使用して移動した旅費
        const int yen = g_yen.distance(i);
        // 都市i+1から都市tにをスヌーク使用して移動した旅費
        const int snuuk = g_snuuk.distance(i);

        // i年は都市i+1の両替所で両替できる
        // 都市i+1で両替したときの旅費を旅費リストに追加する
        const int travel_cost = initial_yen - (yen + snuuk);
        travel_costs.push(travel_cost);

        // 最安の旅費を得る
        answers[i] = travel_costs.top();
    }

    for (auto &&i : answers) {
        cout << i << endl;
    }
}


Measured memory_bytes: 20732
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <string>
#include <iostream>
#include <complex>
#include <ctime>
#include <cmath>
#include <cstdio>
#include <stack>
#include <map>
#include <list>
#include <queue>
#include <deque>
#include <random>
#include <set>
#include <vector>
#include <unordered_map>
#include <bitset>
#include <unordered_set>
#include <array>
#include <forward_list>
//#include <chrono>
#include <iomanip>
#include <utility>
#include <assert.h>

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define mp make_pair
#define pb push_back

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

mt19937 gen(34);

int a, b;

int main()
{
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#else
	//freopen("bst.in", "r", stdin);
	//freopen("bst.out", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin >> a >> b;
	cout << max(0, a - 2 * b);



	return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
def gcd(m,n):
    m,n = max(m,n), min(m,n)
    while n > 0:
        m, n = n, m%n
    return(m)
A.sort()
g = A[0]
for i in range(N):
    if g == 1:
        break
    else:
        g = gcd(g,A[i])

print(g)


Measured memory_bytes: 15020
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b) - 1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)

#define PB push_back
#define INF INT_MAX/3
#define ALL(a) (a).begin(),(a).end()
#define CLR(a) memset(a,0,sizeof(a))

typedef long long int ll;

using namespace std;

int main(){
    while(true){
	int a,b;
	cin >> a >> b;
	if(a == 0 && b == 0) break;
	int ans = 1;
	if(a < b) swap(a,b);
	while(a % b != 0){
	    int temp = b;
	    b = a % b;
	    a = temp;
	    ans++;
	}
	cout << b << " " << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 1160
n = int(input())
h_list = list(map(int,input().split()))
count = 0
count_temp = 0
for i in range(n-1):
    if h_list[i] >= h_list[i+1]:
        count_temp += 1
    else:
        count_temp = 0
    if count_temp > count:
        count = count_temp
print(count)

Measured memory_bytes: 14252
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop;

const long INF = 1L << 59;

void main() {
    auto N = readln.chomp.to!int;
    auto HP = N.iota.map!(_ => readln.split.map!(to!long).array).array;
    HP.sort!"a[0]+a[1] == b[0]+b[1] ? a[1] < b[1] : a[0]+a[1] < b[0]+b[1]"();
    //HP.sort();

    auto dp = new Tuple!(long, long)[][](2, N+1);
    foreach (i; 0..2) dp[i].fill(tuple(INF, INF));
    dp[0][0] = tuple(0L, INF);
    int cur = 0;
    int tar = 1;

    foreach (i; 0..N) {
        foreach (j; 0..N+1)
            dp[tar][j] = dp[cur][j];
        foreach (j; 0..N) {
            if (dp[cur][j][0] <= HP[i][0]) {
                long takasa = dp[cur][j][0]+HP[i][1];
                long seigen = min(dp[cur][j][1], HP[i][0]-dp[cur][j][0]);
                if (takasa < dp[tar][j+1][0] || (takasa == dp[tar][j+1][0] && seigen > dp[tar][j+1][1]))
                    dp[tar][j+1] = tuple(takasa, seigen);
            } else if (dp[cur][j][1] >= HP[i][1]) {
                long takasa = dp[cur][j][0]+HP[i][1];
                long seigen = dp[cur][j][1]-HP[i][1];
                if (takasa < dp[tar][j+1][0] || (takasa == dp[tar][j+1][0] && seigen > dp[tar][j+1][1]))
                    dp[tar][j+1] = tuple(takasa, seigen);
            }
        }

        cur ^= 1;
        tar ^= 1;
    }

    //dp.each!(d => d.each!(p => [p[0], p[1]].writeln));

    int ans = 0;
    foreach (i; 0..2)
        foreach (j; 0..N+1)
            if (dp[i][j][0] < INF)
                ans = max(ans, j);
    ans.writeln;
}


Measured memory_bytes: 3068
import sys

input = sys.stdin.readline
N = int(input())
A = list(map(int, input().split()))

C = [0 for _ in range(10**5+10)]

for a in A:
    C[a] += 1
Q = int(input())

res = sum(A)
for _ in range(Q):
    b,c = map(int, input().split())
    res += (c-b) * C[b]
    C[c] += C[b]
    C[b] = 0
    print(res)


Measured memory_bytes: 83516
/*
貪欲
後ろから見る
DP
順位表をチェック
二分探索


*/
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include <cmath>
#include <limits>
#include <iostream>
#include <map>
#include<tuple>
#include<set>
using namespace std;
#define INF 1100000000000000000
#define MAX 100000
#define MOD 1000000007
typedef long long ll;
//typedef pair<int,int> P;
//typedef pair< pair<int,int>,pair<int,int> > p;
#define bit(n,k) ((n>>k)&1) /*nのk bit目*/
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)
struct edge{ll to,cost,val;};
template<class T,class U>bool chmin(T&a,const U&b){if(a<=b)return false;a=b;return true;}
template<class T,class U>bool chmax(T&a,const U&b){if(a>=b)return false;a=b;return true;}
//__builtin_popcount(S);
//C.erase(unique(C.begin(),C.end()),C.end());

int main(){
    int N;
    cin>>N;
    ll A[210000];
    for(int i=1;i<=N;i++){
        cin>>A[i];
    }
    if(A[1]>0){
        cout<<-1<<endl;
        return 0;
    }
    ll ans=A[N],now=A[N]-1;
    for(int i=N-1;i>=1;i--,now--){
        if(A[i]==now) continue;
        if(now>A[i]){
            cout<<-1<<endl;
            return 0;
        }
        ans+=A[i];
        now=A[i];
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 1792
n, m, x = gets.chomp.split.map(&:to_i)
cas = n.times.map { gets.chomp.split.map(&:to_i) }

min = -1
(0...2 ** n).each do |ptn|
    ts = (0...n).map { |e| ptn / 2 ** e % 2 }

    csum = 0
    asum = [0] * m
    cas.each_with_index do |ca, i|
        next if ts[i] == 0
        c = ca[0]
        csum = csum + c
        as = ca[1,m]
        as.each_with_index do |a, j|
            asum[j] = asum[j] + a
        end
    end

    ngs = asum.select { |e| e < x }
    next if ngs.count > 0

    min = csum if min == -1
    min = csum if csum < min
end

puts min


Measured memory_bytes: 14440
#include <stdio.h>
#include <string.h>
#include <stdbool.h>

int main()
{
    char str[200001]="";
    int cot=0,p_a=0,len=0;
    bool ex_a=false;
    scanf("%s",str);
    len=strlen(str);
    for(int i=0;i<len;i++){
	if(str[i]=='A' && ex_a==false){
	    ex_a=true;
	    p_a=i;
	    cot=0;
	}
	
	if(str[i]=='Z' && ex_a==true){
	    cot=i-p_a+1;
	}
    }

    printf("%d",cot);
    return 0;
}





Measured memory_bytes: 384
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		 Scanner scan = new Scanner(System.in);
		 int A = scan.nextInt();
		 int B = scan.nextInt();

		 int max = -9999;
		 max = A+B > max ? A+B : max;
		 max = A-B > max ? A-B : max;
		 max = A*B > max ? A*B : max;
		 System.out.println(max);
	}
}


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

long long int rightt=1000000009; long long int lefft=0;
long long int n, a, b;
long long int vec[111111];

void bin(){
    long long int mid=(rightt+lefft)/2;
    long long int ans=b*mid, sum=0;
    for(int i=0;n>i;i++){
        sum+=max(0LL, (vec[i]-ans+(a-b-1))/(a-b));
    }
    if(sum>mid){
        lefft=mid;
    }
    else{
        rightt=mid;
    }
}

int main(){
    ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    cin >> n >> a >> b;
    for(int i=0;n>i;i++){
        cin >> vec[i];
    }
    while(rightt-lefft>1){
        bin();
    }
    cout << rightt;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
#define ALL(a) (a).begin(),(a).end()
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define ll long long
#define ull unsigned long long
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

using namespace std;
int nextInt(){
  int a;
  cin >> a;
  return a;
}

int n,q,m;
vector<int> sch;
bool key;
int main(){
  while(true){
    cin >> n >> q;
    if(!n&&!q)break;
    sch.resize(101,0);
    REP(i,n){
      cin >> m;
      REP(j,m){
	sch[nextInt()]++;
      }
    }

    key = false;
    for(int i=n;i>q-1;i--){
      for(int j=0;j<101;j++){
	if(sch[j]==i){
	  key = true;
	  cout << j << endl;
	  break;
	}
      }
      if(key)break; 
    }
    if(!key)cout << 0 << endl;
    sch.clear();
  }
    

  return 0;
}

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

#define _p(...) (void)printf(__VA_ARGS__)
#define forr(x,arr) for(auto&& x:arr)
#define _overload3(_1,_2,_3,name,...) name
#define _rep2(i,n) _rep3(i,0,n)
#define _rep3(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,_rep3,_rep2,)(__VA_ARGS__)
#define _rrep2(i,n) _rrep3(i,0,n)
#define _rrep3(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2,)(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
#define bit(n) (1LL<<(n))
#define sz(x) ((int)(x).size())
#define fst first
#define snd second
using ll=long long;
using pii=pair<int,int>;using pll=pair<ll,ll>;using pil=pair<int,ll>;using pli=pair<ll,int>;
using vs=vector<string>;using vvs=vector<vs>;using vvvs=vector<vvs>;
using vb=vector<bool>;using vvb=vector<vb>;using vvvb=vector<vvb>;
using vi=vector<int>;using vvi=vector<vi>;using vvvi=vector<vvi>;
using vl=vector<ll>;using vvl=vector<vl>;using vvvl=vector<vvl>;
using vd=vector<double>;using vvd=vector<vd>;using vvvd=vector<vvd>;
using vpii=vector<pii>;using vvpii=vector<vpii>;using vvvpii=vector<vvpii>;
template<class T,class U>istream&operator>>(istream&is,pair<T,U>&P){is>>P.fst;is>>P.snd;return is;}
template<class T>T read(){T t;cin>>t;return t;}
template<class T,class U>ostream&operator<<(ostream&o,const pair<T,U>&p){return o<<'('<<p.fst<<", "<<p.snd<<')';}
template<class T>ostream&operator<<(ostream&o,const vector<T>&t){o<<"{";rep(i,sz(t))o<<t[i]<<",";o<<"}"<<endl;return o;}
#ifdef LOCAL
vs s_p_l_i_t(const string&s,char c){vs v;stringstream ss(s);string x;while(getline(ss,x,c))v.emplace_back(x);return move(v);}
void e_r_r(vs::iterator it){cerr<<endl;}
template<class T,class... Args>void e_r_r(vs::iterator it,T a,Args... args){cerr<<it->substr((*it)[0]==' ',it->length())<<" = "<<a<<", ";e_r_r(++it,args...);}
#define out(args...){vs a_r_g_s=s_p_l_i_t(#args,',');e_r_r(a_r_g_s.begin(),args);}
#else
#define out(args...)
#endif

const ll mod = 1e9+7;

void Main() {
  int n = read<int>();

  ll ans = 1;
  ll t = 0;

  rep(i, n) {
    int a = read<int>();
    if (a < t * 2 + 1) {
      (ans *= (t + 1)) %= mod;
      t--;
    }
    t++;
  }
  rep(i, t) (ans *= (i+1)) %= mod;
  cout << ans << endl;
}
int main() { cin.tie(nullptr); ios::sync_with_stdio(false); Main(); return 0; }


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>
#include<complex>

using namespace std;

#define ll long long
#define ld long double
#define EPS 1e-9
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef pair<int,pii> pip;
typedef vector<pii> vp;
typedef vector<vi> vvi;

int gcd(int a, int b){if(b==0) return a;return gcd(b,a%b);}
int lcm(int a, int b){return a/gcd(a,b)*b;}


signed main(void) {
    int n;
    cin >> n;
    int ans = 0;
    loop(i,1,n+1){
        string s = to_string(i);
        if(s.size()%2)ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        //String str = sc.next();
        double A = sc.nextDouble();
        double B = sc.nextDouble();
        double H = sc.nextDouble();
        double M = sc.nextDouble();
        
        double hx = A*Math.sin(Math.toRadians(H*30+M*0.5));
        double hy = A*Math.cos(Math.toRadians(H*30+M*0.5));
        double mx = B*Math.sin(Math.toRadians(M*6));
        double my = B*Math.cos(Math.toRadians(M*6));
        
        //System.out.println(hx);
        //System.out.println(hy);
        //System.out.println(mx);
        //System.out.println(my);
        
        double dist = Math.sqrt((hx-mx)*(hx-mx)+(hy-my)*(hy-my));
        System.out.println(dist);
    }
}


Measured memory_bytes: 37444
#include<stdio.h>
#include<math.h>
int main(){
  int n,i;
  double x1,y1,x2,y2,x3,y3,a1,b1,c1,a2,b2,c2,x,y,r,dst;
  scanf("%d",&n);
  for(i=0;i<n;i++){
  scanf("%lf %lf %lf %lf %lf %lf",&x1,&y1,&x2,&y2,&x3,&y3);

  a1=2*(x2-x1),b1=2*(y2-y1),c1=(x1*x1)-(x2*x2)+(y1*y1)-(y2*y2);
  a2=2*(x3-x1),b2=2*(y3-y1),c2=(x1*x1)-(x3*x3)+(y1*y1)-(y3*y3);

  x=((b1*c2)-(b2*c1))/((a1*b2)-(a2*b1));
  y=((c1*a2)-(c2*a1))/((a1*b2)-(a2*b1));

  r=sqrt((x1-x)*(x1-x)+(y1-y)*(y1-y));
  
  printf("%.3f %.3f %.3f\n",x,y,r);
  }
  return 0;
  }

Measured memory_bytes: 664
#include <iostream>

using namespace std;
typedef long long ll;

ll gcd(ll a, ll b) {
  if (a < b) return gcd(b, a);
  if (a % b == 0) return b;
  return gcd(b, a % b);
}

int main() {
  ll a, b;
  cin >> a >> b;
  cout << a * b / gcd(a, b);	
}

Measured memory_bytes: 256
# from (x,y) to SW (0,0) by (-1,-1) 
def raySW(x,y):
    return x - y
    
n,w,d=map(int,input().split())
def toRange(xyf):
    sx,sy,f = xyf
    x=int(sx)
    y=int(sy)
    if f == 'S':
        s = raySW(x,y)
        t = w - raySW(w-x,y)  # flip in X
        return (s,t)
    if f == 'E':
        s = w - raySW(w-x,y)  # flip in X
        t = w + d + raySW(w-x,d-y) # flip in both X and Y
        return (s,t)
    if f == 'N':
        s = w + d + raySW(w-x,d-y) # flip in both X and Y
        t = w + d + w - raySW(x,d-y)  # flip in Y
        return (s,t)
    if f == 'W':
        s = w + d + w - raySW(x,d-y)  # flip in Y
        t = w + d + w + d + raySW(x,y)
        return (s,t) if t <= w+d+w+d else (s-w-w-d-d,t-w-w-d-d)
    exit(-1)
    
xyfs=[input().split() for _ in range(n)]

def swap(xy):
    x,y=xy
    return (y,x)

stso=list(map(swap,list(map(toRange,xyfs))))
sts=sorted(stso)

def contains(s,t,r):
    if t <= r <= s: return True
    if t <= r+d+d+w+w <= s: return True
    if t <= r-d-d-w-w <= s: return True
    return False

def findMin(sts):
    c = 0
    r = w+w+d+d+w+w+d+d+w+w+d+d
    for s,t in sts:
        if not contains(s,t,r):    # put a new clock at t
            c += 1
            r = s
    return c
# stupid concat?
mins=[findMin(sts[i:] + sts[:i]) for i in range(n)]
print(min(mins))



Measured memory_bytes: 6000
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        n: usize,
        t: i64,
        p: [i64; n]
    }
    let mut answer = t;
    for i in (0..n-1).rev() {
        let diff = p[i + 1] - p[i];
        answer += if diff < t {diff} else {t};
    }
    println!("{}", answer);
}


Measured memory_bytes: 6396
#define ll long long
#define MOD 1000000007 
// #define mp make_pair
#define pb push_back
#include <bits/stdc++.h>
using namespace std;
ll flag=0,ans=0;
vector<ll>v[100009];
int vis[100009]={0};
map<ll,ll>mp;

ll dfs(ll s)
{
  if(v[s].size()==0)
  {
    vis[s]=1;
    mp[s]=1;
    return 1;
  }
  if(!vis[s])
  {
  for(int i:v[s])
  {
    mp[s]=max(dfs(i),mp[s]);
  }
  mp[s]++;
  }
  vis[s]=1;
  return mp[s];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll n,e,x,y;
  cin>>n>>e;
  for(int i=0;i<e;i++)
  {
    cin>>x>>y;
    v[x].pb(y);
  }
  for(int i=1;i<=n;i++)
  if(!vis[i])
  dfs(i);

  for(auto i=mp.begin();i!=mp.end();i++)
    ans=max(ans,i->second);
  
  cout<<ans-1;
  return 0;
}

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

using namespace std;

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

  long long N, K;
  cin >> N >> K;
  long long sum = 0;
  for (long long k = K; k <= N + 1; k++) {
    long long min_sum = (k - 1) * k / 2;
    long long max_sum = (N - (k - 1) + N) * k / 2;
    sum += max_sum - min_sum + 1;
    // cout << max_sum << ":" << min_sum << endl;
  }
  cout << sum % 1000000007 << endl;
}


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

using namespace std;

using ll = long long;
using P = pair<int, int>;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mkp(a, b) make_pair(a, b)
const int inf = 1e+9;



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

	vector<ll> cs(26,0);

	int n = s.size();
	for(char c : s) {
		cs[c - 'a']++;
	}

	ll ans = 0;

	bool plus1 = false;

	for (int i = 0; i < 26; i++) {
		if (cs[i] >= 2) {
			plus1 = true;
		}
		ans += (n - cs[i]) * cs[i];
	}
	ans /= 2;

	ans++;
	cout << ans << endl;
	

	return 0;
}


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

int main(){
    int in[2];
    cin >> in[0] >> in[1];
    for(int i=0;i<2;i++){
        if(in[i] == 2){
            in[i] = 3;
        }
        else if(in[i] == 4 || in[i] == 6 || in[i] == 9||in[i] == 11){
            in[i] = 2;
        }
        else{
            in[i] = 1;
        }
    }
    if(in[0] == in[1]){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    return 0;
}

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

int main() {
  int x, n;
  cin >> x >> n;
  vector<int> d(102);
  rep(i,n) {
    int p;
    cin >> p;
    d[p] = 1;
  }
  P ans(99999,-1);
  for (int i = 0; i <= 101; ++i) {
    if (d[i] == 1) continue;
    int dif = abs(x-i);
    ans = min(ans, P(dif,i));
  }
  cout << ans.second << endl;
  return 0;
}

Measured memory_bytes: 3576
K = int(input())

queue = [i for i in range(1, 10)]

for i in range(K - 1):
    N = queue.pop(0)
    if i < K // 2:
        if N % 10 == 0:
            queue.append(N * 10)
            queue.append(N * 10 + 1)
        elif N % 10 == 9:
            queue.append(N * 10 + 8)
            queue.append(N * 10 + 9)
        else:
            queue.append(N * 10 + (N % 10 - 1))
            queue.append(N * 10 + N % 10)
            queue.append(N * 10 + (N % 10 + 1))

print(queue.pop(0))

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


#include "boost/multiprecision/cpp_int.hpp"
#include "boost/multiprecision/cpp_dec_float.hpp"
namespace mp = boost::multiprecision;
typedef mp::cpp_int LL;
typedef mp::number<mp::cpp_dec_float<1024>> DD;// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)

 
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
typedef pair<dd,dd> d_d;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define rrep(i,r,l) for(ll i=r;i>=l;i--)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-12;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi first
#define se second
#define endl "\n"  //インタラクティブで消す！！！！！！！！！！！！！！！！！！！！！
#define SORT(v) sort(v.begin(),v.end())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
#define POSL(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define POSU(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
template<class T,class S>
inline bool chmax(T &a, S b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
template<class T,class S>
inline bool chmin(T &a, S b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

void mod_print(ll k){
    ll P=50000;
    rep(y,1,P){
        ll x=mod(y*k);
        
        if(abs(x)<=P||x+P>=i_7){
            if(x+P>=i_7){
                x-=i_7;
            }
            cout<<x<<"/"<<y<<endl;
            //cout<<setprecision(5)<<(dd)x/(dd)y;
            return;
        }
    }
    cout<<"nun"<<endl;
}
#define all(c) c.begin(),c.end()
typedef vector<ll> vl;
//////////////////////////



int main(){fastio
    ll n;cin>>n;
    ll l[n];rep(i,0,n-1)cin>>l[i];
    sort(l,l+n);
    ll ans=0;
    rep(i,0,n-1){
        rep(j,i+1,n-1){
            rep(k,j+1,n-1){
                if(l[i]==l[j]||l[j]==l[k])continue;
                if(l[i]+l[j]>l[k])ans++;
            }
        }
    }
    cout<<ans<<endl;
    
    
    return 0;
}



Measured memory_bytes: 3656
#include <bits/stdc++.h>
 
using namespace std;
 
#define REP(i, a, b) for (int i = (a), i##_end_ = (b); i < i##_end_; ++i)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define mp make_pair
#define x first
#define y second
#define pb push_back
#define SZ(x) (int((x).size()))
#define ALL(x) (x).begin(), (x).end()
 
template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }
 
typedef long long LL;
 
const int oo = 0x3f3f3f3f;
 
const int maxn = 100100;
 
int n, m;
vector<int> adj[maxn + 5];
 
int col[maxn + 5];
 
int cnt = 0;
int cntx = 0, cnty = 0;
 
bool dfs(int x, int c)
{
	if (~col[x])
	{
		return col[x] == c;
	}
	col[x] = c;
	++cnt;
	if (col[x] == 0) ++cntx;
	else ++cnty;
	bool ret = 1;
	for (auto y : adj[x])
		ret &= dfs(y, !c);
	return ret;
}
 
int main()
{
	scanf("%d%d", &n, &m);
	REP(i, 0, m)
	{
		int u, v;
		scanf("%d%d", &u, &v), --u, --v;
		adj[u].pb(v), adj[v].pb(u);
	}
	memset(col, -1, sizeof col);
	LL ans = -m;

		cnt = cntx = cnty = 0;
		if (!dfs(1, 0))
		{
			ans += (LL)cnt * (cnt - 1) >> 1;
		}
		else ans += (LL)cntx * cnty;
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 6912
N = int(input())
S = tuple([s for s in input()])
B = {'R','G','B'}
ans = 0
d = {}
d['R'] = 0
d['G'] = 1
d['B'] = 2
num = [[0,0,0]for _ in range(N+1)]
for i in range(N):
    for j in range(3):
        num[i+1][j] = num[i][j]
        if d[S[i]] == j:
            num[i+1][j] += 1
num = tuple(num[1:])
for i in range(N-2):
    s = S[i]
    for j in range(i+1,N-1):
        if S[j] != s:
            l = j-i
            t = (B-{s,S[j]}).pop()
            L = 0
            R = 0
            if l > N-j-1:
                ans += num[N-1][d[t]]-num[j][d[t]]
            else:
                L = num[j+l-1][d[t]]-num[j][d[t]]
                R = num[N-1][d[t]]-num[j+l][d[t]]
                ans += L+R
print(ans)

Measured memory_bytes: 70160
#include <bits/stdc++.h>
using namespace std;
#define ll long long
map<int, list<int>> mp;

void dfs(vector<int> &vis, int nd, vector<int> &dp)
{
  vis[nd] = 1;
  
   for(auto a: mp[nd])
    {
      if(!vis[a])
        dfs(vis, a, dp);
      dp[nd] = max(dp[nd], 1+dp[a]);
    }

}

int main()
{

 int n, m;
 cin >> n >> m;
 
 for(int i=0,x,y; i<m; i++)
 {
  cin >> x>> y;
  --x; --y;
  mp[x].push_back(y);
 } 

 vector<int> dp(n, 0);
 vector<int> vis(n, 0);

 for(int i=0; i<n; i++)
 {
  if(!vis[i])
    dfs(vis, i, dp);
 }

 int ans = 0;
 for(int i=0; i<n; i++)
  ans = max(ans, dp[i]);

  cout<<ans;
  return 0;
}


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

int main(){
  int n;
  cin>>n;
  long long int a=1,b=1,c=1;
  for(int i=0;i<n;i++){
    a*=10;
    b*=9;
    c*=8;
    a=a%1000000007;
    b=b%1000000007;
    c=c%1000000007;
  }
  if((a-2*b+c)>=0){
    cout<<(a-2*b+c)%1000000007<<endl;
  }
  else{
    cout<<(a-2*b+c+2000000014)%1000000007<<endl;
  }
}

Measured memory_bytes: 3620
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#define TRUE 1
#define FALSE 0
int isPrime(int);

int main(){
  int i, n,*a,q,f=0;
  scanf(" %d",&n);

  a=(int *)malloc(n *sizeof(int));
  for(i=0;i<n;i++){

    scanf(" %d",&a[i]);
   
  }
  for(i=0;i<n;i++){
     
     if(isPrime(a[i])==1)f++;;

  }
  printf("%d\n",f);
  free(a);
  return 0;
}
int isPrime(int x){

  int   i=3;
  if(x==2) return 1;
  if(x<2 ||x%2==0){
    return 0;

  }
  while((double)i <= sqrt(x)){
    if(x%i==0)
      return 0;
      i=i+2;
    }
  return 1;
}
    


Measured memory_bytes: 2084
#[allow(dead_code)]
fn main() {
    let (n, m) = i::u2();

    let mut a = HashSet::new();
    for _ in 0..m {
        a.insert(i::u());
    }

    let mut dp = vec![1usize];
    if !a.contains(&1) {
        dp.push(1);
    } else {
        dp.push(0);
    }
    for i in 2..(n + 1) {
        if a.contains(&i) {
            dp.push(0);
            continue;
        }
        let t = (dp[i - 1] + dp[i - 2]) % 1_000_000_007;
        dp.push(t);
    }
    println!("{}", dp[n]);
    // dbg!(dp);
}

#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::io::*;
#[allow(unused_imports)]
use std::num::*;
#[allow(unused_imports)]
use std::str::*;

#[allow(dead_code)]
mod i {
    use super::*;

    pub fn read<T: FromStr>() -> T {
        stdin()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>()
            .parse::<T>()
            .ok()
            .unwrap()
    }

    pub fn str() -> String {
        read()
    }

    pub fn s() -> Vec<char> {
        str().chars().collect()
    }

    pub fn i() -> i64 {
        read()
    }

    pub fn u() -> usize {
        read()
    }

    pub fn u2() -> (usize, usize) {
        (read(), read())
    }

    pub fn u3() -> (usize, usize, usize) {
        (read(), read(), read())
    }

    pub fn f() -> f64 {
        read()
    }

    pub fn c() -> char {
        read::<String>().pop().unwrap()
    }

    pub fn iv(n: usize) -> Vec<i64> {
        (0..n).map(|_| i()).collect()
    }

    pub fn iv2(n: usize) -> Vec<(i64, i64)> {
        (0..n).map(|_| iv(2)).map(|a| (a[0], a[1])).collect()
    }

    pub fn uv(n: usize) -> Vec<usize> {
        (0..n).map(|_| u()).collect()
    }

    pub fn uv2(n: usize) -> Vec<(usize, usize)> {
        (0..n).map(|_| uv(2)).map(|a| (a[0], a[1])).collect()
    }

    pub fn uv3(n: usize) -> Vec<(usize, usize, usize)> {
        (0..n).map(|_| uv(3)).map(|a| (a[0], a[1], a[2])).collect()
    }

    pub fn fv(n: usize) -> Vec<f64> {
        (0..n).map(|_| f()).collect()
    }

    pub fn cmap(h: usize) -> Vec<Vec<char>> {
        (0..h).map(|_| s()).collect()
    }
}


Measured memory_bytes: 8444
#include <iostream>
#include <string>

std::string StringRotation(std::string s);

int main() {
  std::string S, T;
  std::cin >> S >> T;

  bool flag{false};
  // A string S returns to its original state after N rotations, N = S.length()
  for (int i = 0; i < S.length(); i++) {
    S = StringRotation(S);
    if (S == T) flag = true;
  }

  if (flag)
    std::cout << "Yes" << std::endl;
  else
    std::cout << "No" << std::endl;

  return 0;
}

std::string StringRotation(std::string s) {
  // "abc" -> 'c' + "ab" -> "cab"
  return s.back() + s.substr(0, s.length() - 1);
}


Measured memory_bytes: 256