akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
using namespace std;

int N;
int x;

int V[200015];

int main(void) {

	cin >> N >> x;

	bool ans;

	if (N == 2) {
		if (x == 2) { ans = true; V[1] = 1; V[2] = 2; V[3] = 3; }
		else { ans = false; }
	}
	else {

		if (x == 1 || x == 2 * N - 1) { ans = false; }
		else {
			ans = true;

			if (x == 2) {
				V[N] = x; V[N - 1] = 1; V[N + 1] = 2 * N - 1;
				V[N - 2] = 3;
				vector<int> tmp;
				for (int i = 4; i <= 2 * N - 2; i++) { tmp.push_back(i); }
				int I = 0;
				for (int i = 1; i <= 2 * N - 1; i++) {
					if (V[i] == 0) { V[i]=tmp[I]; I++; }
				}

			}
			else {
				V[N] = x; V[N - 1] = 1; V[N + 1] = 2 * N - 1;
				V[N + 2] = 2;
				vector<int>tmp;
				for (int i = 3; i <= 2 * N - 2; i++) {
					if (i == x) { continue; }
					tmp.push_back(i);
				}
				int I=0;
				for (int i = 1; i <= 2 * N - 1; i++) {
					if (V[i] == 0) { V[i] = tmp[I]; I++; }
				}

			}
		}

	}


	if (ans) { cout << "Yes" << endl;
	for (int i = 1; i <= 2 * N - 1; i++) {
		cout << V[i] << endl;
		}
	}
	else {
		cout << "No" << endl;
	}
	//system("pause");
	return 0;
}

Measured memory_bytes: 2404
#include<iostream>
#include<numeric>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<map>
#include<utility>
#include<cmath>
#include<tuple>
#include<string>
#include<bitset>
#include<set>
#include<queue>
#include<stack>
#include<cstdio>
using namespace std;
typedef long long ll;

int main(){
    int k,a,b;
    cin>>k>>a>>b;
    for(int i=a;i<=b;i++){
        if(i%k==0){
            cout<<"OK"<<endl;
            return 0;
        } 
    }
    cout<<"NG"<<endl;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define mod 1000000007
using ll=long long;
const int INF=1000000000;
const ll LINF=1001002003004005006ll;
int dx[]={1,0,-1,0},dy[]={0,1,0,-1};
// ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}
 
struct IOSetup{
    IOSetup(){
        cin.tie(0);
        ios::sync_with_stdio(0);
        cout<<fixed<<setprecision(12);
    }
} iosetup;

template<typename T1,typename T2>
ostream &operator<<(ostream &os,const pair<T1,T2>&p){
    os<<p.first<<" "<<p.second;
    return os;
}
 
template<typename T>
ostream &operator<<(ostream &os,const vector<T>&v){
    for(int i=0;i<(int)v.size();i++) os<<v[i]<<(i+1==(int)v.size()?"":" ");
    return os;
}

template<typename T1,typename T2>
istream &operator>>(istream &is,pair<T1,T2>&p){
    is>>p.first>>p.second;
    return is;
}

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

struct UnionFind{
    vector<int> par,siz;
    int con;
    UnionFind(int n){
        par.resize(n);
        iota(begin(par),end(par),0);
        siz.assign(n,1);
    }
    int root(int x){
        return (par[x]==x?x:(par[x]=root(par[x])));
    }
    bool sameroot(int x,int y){
        return root(x)==root(y);
    }
    bool unite(int x,int y){
        x=root(x);y=root(y);
        if(x==y) return false;
        if(siz[x]<siz[y])swap(x,y);
        siz[x]+=siz[y];
        par[y]=x;
        con--;
        return true;
    }
    int size(int x){
        return siz[root(x)];
    }
};

signed main(){
    int n,q;cin>>n>>q;
    UnionFind uf(n);
    while(q--){
        int t,u,v;cin>>t>>u>>v;
        if(t){
            cout<<uf.sameroot(u,v)<<endl;
        }else{
            uf.unite(u,v);
        }
    }
    return 0;
}

Measured memory_bytes: 4772
N, K = map(int, input().split())
A = [0] + list(map(int, input().split()))
visited = [-1 for _ in range(N+1)]
path = [1]
visited[1] = 0
pos = 1
endi = -1
for i in range(1, N+1):
    pos = A[pos]
    if i == K:
        endi = -i
        break
    if visited[pos] > -1:
        endi = i
        break
    visited[pos] = i

if endi < 0:
    print(pos)
else:
    loop = endi - visited[pos]
    ansi = (K-visited[pos])%loop
    for i in range(ansi):
        pos = A[pos]
    print(pos)

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

long long func_zero(long long &N){
    if(N % 2 != 0){
        return 0;
    }
    else{
        long long r = N / 10;
        N = N / 10;
        while(N > 0){
            r += N / 5;
            N = N / 5;
        }
        return r;
    }
}

int main() {
    long long N;

    cin >> N;

    cout << func_zero(N) << endl;


    return 0;
}

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

using namespace std;

string rez;

bool interact(int poz) {
  cout << poz << endl;
  cin >> rez;
  if(rez == "Vacant")
    exit(0);
  else if(rez == "Male")
    return 0;
  else 
    return 1;
}

int main() {
  int n;
  int st, dr;
  bool first;
  scanf("%d", &n);
  first = interact(0);
  st = 0, dr = n;
  while(dr - st > 1) {
    int mid = (st + dr) / 2;
    if((interact(mid) ^ (mid & 1)) == first)
      st = mid;
    else
      dr = mid;
  }
  printf("something went wrong");
  return 0;
}


Measured memory_bytes: 852
#include <iostream>
#include <vector>
#include<algorithm>
#include<iomanip>
#include<queue>
#include<deque>
#include<map>
#include<bitset>
#include<math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define REP(i,m,n) for(ll i=m;i<(ll)(n);i++)
typedef pair<int,long long> pint;
typedef long long ll;
const ll mod= 1e9+7;
const ll  longinf = 1LL<<60;
int dx[4]={1,0,-1,0}, dy[4]={0,1,0,-1};




int main(){
  int h,w;
  cin>>h>>w;
  string s[h];
  rep(i,h)cin>>s[i];
  rep(i,h)rep(j,w){
    if(s[i][j]=='#'){
      bool ok=false;
      rep(k,4){
        int nx=i+dx[k],ny=j+dy[k];
        if(0<=nx&&nx<h&&0<=ny&&ny<w){
          if(s[nx][ny]=='#')ok=true;
          }
        }
      if(!ok){
        cout<<"No"<<endl;
        return 0;
        }
      }
    }
  cout<<"Yes"<<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;

int p[300000][26];
vector<int>E[300000];
int dp[300000];

int main(){
	string s;cin>>s;
	rep(i,26)p[s.size()][i]=s.size()+1;
	for(int i=s.size()-1;i>=0;i--){
		rep(j,26){
			if(s[i]-'a'==j)p[i][j]=i+1;
			else p[i][j]=p[i+1][j];
			E[p[i][j]].push_back(i);
		}
	}
	memset(dp,0x3f,sizeof(dp));
	dp[s.size()+1]=0;
	for(int i=s.size()+1;i>0;i--){
		for(auto v:E[i]){
			dp[v]=min(dp[v],dp[i]+1);
		}
	}
	int pos=0;
	string ans;
	while(pos!=s.size()+1){
		rep(i,26){
			if(dp[p[pos][i]]==dp[pos]-1){
				ans+='a'+i;
				pos=p[pos][i];
				break;
			}
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 61828
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>

int main()
{
	int n,k;
	scanf("%d%d",&n,&k);
	if ((n+1)/2>=k) puts("YES");
	else puts("NO");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define LLINF 9223372036854775807
#define MOD ll(1e9+7)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr<<#x<<": "<<x<<endl

int main(){
    int a, b;
    cin >> a >> b;
    if(a<=9 && b<=9){
        cout << a*b << endl;
    }else{
        cout << -1 << endl;
    }


    return 0;

}


Measured memory_bytes: 256
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define rSort(v) sort(v.rbegin(), v.rend())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

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

/* Macros reg. ends here */

const ll INF = 1LL << 50;

static const long long mod = 1000000007;

struct LzyST {
  ll n;
  vll dat, laz;
  LzyST() {}
  LzyST(ll n_) { init(n_); }
  void init(ll n_) {
    n = 1;
    while (n < n_) n *= 2;
    dat.clear();
    dat.resize(2 * n - 1, (1LL << 31) - 1);
    laz.clear();
    laz.resize(2 * n - 1, -1);
  }

  inline void eval(ll k) {
    if (laz[k] == -1) return;
    if (k * 2 + 1 < n * 2 - 1) {
      laz[k * 2 + 1] = laz[k];
      laz[k * 2 + 2] = laz[k];
    }
    dat[k] = laz[k];
    laz[k] = -1;
  }
  void update(ll a, ll b, ll x, ll k, ll l, ll r) {
    eval(k);
    if (r <= a || b <= l) return;
    if (a <= l && r <= b) {
      laz[k] = x;
      eval(k);
      return;
    }
    update(a, b, x, k * 2 + 1, l, (l + r) / 2);
    update(a, b, x, k * 2 + 2, (l + r) / 2, r);
    dat[k] = min(dat[2*k+1], dat[2*k+2]);
    return;
  }
  ll find(ll a, ll b, ll k, ll l, ll r) {
    if (r <= a || b <= l) return INF;
    eval(k);    
    if (a <= l && r <= b) return dat[k];
    ll vl = find(a, b, k * 2 + 1, l, (l + r) / 2);
    ll vr = find(a, b, k * 2 + 2, (l + r) / 2, r);
    return min(vl, vr);
  }
  void update(ll a, ll b, ll x) { update(a, b + 1, x, 0, 0, n); }
  ll find(ll a, ll b) { return find(a, b + 1, 0, 0, n); }
};

int main() {
  // ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  ll n, q;
  cin >> n >> q;
  LzyST lst(n);
  for (ll i = 0; i < q; i++) {
    ll c;
    cin >> c;
    if (c == 0) {
      ll s, t, x;
      cin >> s >> t >> x;
      lst.update(s, t, x);
    } else {
      ll s, t;
      cin >> s >> t;
      cout << lst.find(s, t) << endl;
    }
  }

  return 0;
}



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

int main(){
    string s;
    cin >> s;
    if(s[0] == s[1] && s[0] == s[2]) cout << "Yes" << endl;
    else if(s[1] == s[2] && s[1] == s[3]) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
N,_=gets.split(" ").map{|i| i.to_i}
h=gets.split(" ").map{|i| i.to_i}
DP=Array.new(N){0}
DP[2-1] = (h[2-1]-h[1-1]).abs
for i in 2..(N-1)
	DP[i] = [(h[i]-h[i-2]).abs+DP[i-2], (h[i]-h[i-1]).abs+DP[i-1]].min
end
puts DP[N-1]


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

int main(){
        int64_t n, a, a2;
        int64_t ans = 0;
        cin >> n ;

        for(int i=0; i < n; i++){
                cin >> a;
                if(i == 0){
                        a2 = a;
                        continue;
                }
                if(a < a2){
                        ans = ans + (a2 - a);
                }
                else{
                        a2 = a;
                }
        }

        cout << ans << endl;
}

Measured memory_bytes: 3556
#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 = 1e18;
/* テンプレートここまで */
void yes(){
  cout << "YES" << endl;
  exit(0);
}

void no(){
  cout << "NO" << endl;
  exit(0);
}

int main() {
  string s,t,u; cin >> s >> t >> u;
  ll n = s.size();
  ll m = t.size();
  if(s[n-1] == t[0] && t[m-1] == u[0]) yes();
  else no();
}

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

int main(){
    string s,t;
    cin>>s>>t;
    int i;
    for(i=0;i<s.size();i++){
        s=s[s.size()-1]+s;
        s.pop_back();
        if(s==t) break;
    }
    cout<<(i<s.size()?"Yes":"No")<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,r;
    cin>>n>>r;
    int inn_rating;
    if(n>=10)
    {
        inn_rating=r;
    }
    else
    {
        int rem=100*(10-n);
        inn_rating=r+rem;
    }
    cout<<inn_rating<<endl;

}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;
using namespace std;
int n;
vector<int> child[100010];
int DFS(int x){
  if(child[x].size()==0)return 0;
  vector<int> v;
  lol(i,child[x].size()){
    v.push_back(DFS(child[x][i]));
  }
  sort(v.begin(),v.end());
  int maxi=0;
  lol(i,v.size()){
    int cost=v[i]+v.size()-i;
    maxi=max(maxi,cost);
  }
  return maxi;
}
int main(){
  cin>>n;
  lol(i,n-1){
    int a;cin>>a;a--;
    child[a].push_back(i+1);
  }
  cout<<DFS(0)<<endl;
  return 0;
}


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

using namespace std;


int limit;
int cost;

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


struct state {
    int puzzle[9];
    int space;
    int cost;
    int evaluation;

    bool operator < (const state &s) const {
        return evaluation > s.evaluation;
    }
};


int goal[9] = {1, 2, 3,
               4, 5, 6,
               7, 8, 0};


bool IsGoal(state s) {
    for (int i = 0; i < 9; i++) {
        if (s.puzzle[i] != goal[i]) return false;
    }
    return true;
}


vector<state> closed;

bool IsSamePuzzle(state s1, state s2){
    for (int i = 0; i < 9; i++) {
        if (s1.puzzle[i] != s2.puzzle[i]) {
            return false;
        }
    }
    return true;
}

bool InClosed(state s){
    for (int i = 0; i < closed.size(); i++) {
        if (IsSamePuzzle(s, closed[i])) return true;
    }
    return false;
}


int h2(state s) {
    int res = 0;
    for (int i = 0; i < 9; i++) {
        if (s.puzzle[i] == 0) continue;

        int px = (s.puzzle[i] - 1) / 3;
        int py = (s.puzzle[i] - 1) % 3;

        int x = i / 3;
        int y = i % 3;

        res += abs(x - px) + abs(y - py);
    }
    return res;
}


int astar(state s) {
    priority_queue<state> pq;
    pq.push(s);

    while (!pq.empty()) {
        state st = pq.top(); pq.pop();

        if (IsGoal(st)) {
            return st.cost;
        }

        closed.push_back(st);

        int px = st.space / 3;
        int py = st.space % 3;

        for (int i = 0; i < 4; i++) {
            int x = px + dx[i];
            int y = py + dy[i];

            if (x < 0 || y < 0 || x >= 3 || y >= 3) continue;

            state next = st;
            swap(next.puzzle[st.space], next.puzzle[x * 3 + y]);
            next.space = x * 3 + y;

            if (!InClosed(next)) {
                next.cost++;
                next.evaluation = next.cost + h2(next);
                pq.push(next);
            }
        }
    }

    return -1;
}


int main() {
    state init;

    for (int i = 0; i < 9; i++) {
        cin >> init.puzzle[i]; 
        if (init.puzzle[i] == 0) init.space = i;
    }
    init.cost = 0;
    init.evaluation = init.cost + h2(init);

    cout << astar(init) << endl;
}


Measured memory_bytes: 3952
#include<stdio.h>
int main(){

	int W,H,x,y,r;
	scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
	
	if (( W>=x+r ) && ( H>=y+r ) && ( 0<=x-r) && ( 0<=y-r ))
		printf("Yes\n");
	else 
	    printf("No\n");
return 0;
}

Measured memory_bytes: 584
#include <bits/stdc++.h>
#define f first
#define s second
#define MOD 1000000007
#define PMOD 998244353
#define pb(x) push_back(x)
using namespace std;

typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> plii;
typedef pair<int, pii> piii;
const int INF = 1e9+10;
const ll LINF = 1LL*INF*INF;
const int MAXN = 2e5+10;
const int MAXM = 5e3+10;

priority_queue<int> pq;
vector<vector<int> > graph;
queue<int> que;

int A[MAXN];
char S[MAXN];

int main()
{
    int n,m,k,a,b,x,y;
    int sum = 0;
    int cnt = 0;
    int mx = 0;
    int mn = INF;
    int cur = 0, idx = -1;

    scanf("%s",&S);

    for(int i=0;i<4;i++){
        A[S[i]-'A']++;
    }

    for(int i=0;i<26;i++){
        if(A[i]==2)cnt++;
    }

    if(cnt==2)cout<<"Yes";
    else cout<<"No";
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[][] field = new int[n + 1][n];
        HashSet<Integer> current = new HashSet<>();
        HashSet<Integer> next = new HashSet<>();
        for (int i = 1; i <= n; i++) {
            for (int j = 0; j < n - 1; j++) {
                field[i][j] = sc.nextInt();
            }
            current.add(i);
        }
        int[] idxes = new int[n + 1];
        int day = 0;
        while (current.size() > 0) {
            for (int x : current) {
                if (!next.contains(x) && idxes[x] < n - 1) {
                    int play = field[x][idxes[x]];
                    if (next.contains(play)) {
                        continue;
                    }
                    if (field[play][idxes[play]] == x) {
                        idxes[x]++;
                        idxes[play]++;
                        if (idxes[x] != n - 1) {
                            next.add(x);
                        }
                        if (idxes[play] != n - 1) {
                            next.add(play);
                        }
                    }
                }
            }
            HashSet<Integer> tmp = next;
            next = current;
            current = tmp;
            next.clear();
            day++;
        }
        for (int i = 1; i <= n; i++) {
            if (idxes[i] != n - 1) {
                System.out.println(-1);
                return;
            }
        }
        System.out.println(day);
    }
}

Measured memory_bytes: 282996
#include<iostream>
#include<string>
using namespace std;
int main() {
	int N, ans = 0;
	cin >> N;
	for (int i = 0; i <= N / 7; i++) {
		for (int j = 0; 4 * j + 7 * i <= N; j++) {
			if (4 * j + 7 * i == N) ans++;
		}
	}
	if (ans == 0) cout << "No" << endl;
	else cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(k,i,n) for(long long i=k;i<n;++i)
using namespace std;
typedef long long ll;
int main(void){
    // Your code here!
    ll N,D;
    cin>>N>>D;
    cout<<(N-1)/(2*D+1)+1<<endl;
}


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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
  while(x->left != NIL){
    x = x->left;
  }
  return x;
}

Node treeSearch(Node u, int k){
  if (u == NIL || k == u->key){
    return u;
  }
  if (k < u->key){
    return treeSearch(u->left, k);
  } else {
    return treeSearch(u->right, k);
  }
}

Node treeSuccessor(Node x){
  Node y;
  if (x->right != NIL){
     return treeMinimum(x->right);
  }
  y = x->parent;
  while (y != NIL && x == y->right){
    x = y;
    y = y->parent;
  }
  return y;

}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y

  if (z->left == NIL || z->right ==NIL){
    y = z;
  } else {
    y = treeSuccessor(z);
  }

  if (y->left!=NIL){
    x = y->left;
  } else {
    x = y->right;
  }
  if (x!=NIL){
    x->parent = y->parent;
  }
  if (y->parent==NIL){
    root = x;
  } else if (y == y->parent->left){
    y->parent->left = x;
  } else {
    y->parent->right = x;
  }

  if (y!=z){
    z->key = y->key;
  }

}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while (x!=NIL){
    y = x;
    if (z->key < x->key){
      x = x->left;
    } else {
      x = x->right;
    }
  }
  z->parent = y;
  if (y == NIL){
    root = z;
  } else if (z->key < y->key){
    y->left = z;
  } else {
    y->right = z;
  }

}

void inorder(Node u){
  if (u!=NIL){
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
  }
}
void preorder(Node u){
  if (u!=NIL){
    printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right);
  }
}

int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}

Measured memory_bytes: 19364
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main(void) {
  ios::sync_with_stdio(false);
  string S;
  cin >> S;
  int N = S.size();

  const int64_t mod = 1e9 + 7;
  vector<vector<int64_t>> DP(N + 1, vector<int64_t>(4, 0));
  DP[0][0] = 1;
  rep(i, N) {
    for (int j = 0; j < 4; ++j) {
      if (S[i] == '?') {
        DP[i + 1][j] = (DP[i + 1][j] + (DP[i][j] * 3) % mod) % mod;
      } else {
        DP[i + 1][j] = (DP[i + 1][j] + DP[i][j]) % mod;
      }
      if (j < 3) {
        if (S[i] == (j + 'A') || S[i] == '?') {
          DP[i + 1][j + 1] = (DP[i + 1][j + 1] + DP[i][j]) % mod;
        }
      }
    }
  }
  cout << DP[N][3] << endl;
  return 0;
}

Measured memory_bytes: 10316
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using Vec  = vector<int>;
using Graph = vector<Vec>;

int n, m, q;
Vec a, b, c, d;
Vec A;
ll max_score;

int		score()
{
	ll score = 0;
	for (int i = 0; i < q; i++)
	{
		if (A.at(b.at(i) - 1) - A.at(a.at(i) - 1) == c.at(i))
			score += d.at(i);
	}
	return (score);
}

void	rec(int it)
{
	if (it != 0)
		A.at(it) = A.at(it - 1);
	while (A.at(it) <= m)
	{
		if (it == n - 1)
		{
			ll tmp = score();
			if (tmp > max_score)
				max_score = tmp;
		}
		else
			rec(it + 1);
		A.at(it) += 1;
	}
}

int		main(void)
{
	cin >> n >> m >> q;
	a = Vec(q);
	b = Vec(q);
	c = Vec(q);
	d = Vec(q);
	for (int i = 0; i < q; i++)
		cin >> a.at(i) >> b.at(i) >> c.at(i) >> d.at(i);
	A = Vec(n, 1);
	max_score = 0;
	rec(0);
	cout << max_score << endl;
}


Measured memory_bytes: 3632
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;

const long long maxn=1e9+7;
int n;

int main()
{
	while(scanf("%d",&n)!=EOF)
	{
		long long cnt=1;
		for(int i=1;i<=n;i++)
		{
			cnt=(i*cnt)%maxn;
		}
		cout << cnt << endl; 
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> //JuniorMonster a.k.a Sho10
#define ll long long int
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define all(a) (a).begin(), (a).end()
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define sz size
#define f first
#define s second
#define pb push_back
#define er erase
#define in insert
#define mp make_pair
#define pi pair
#define rc(s) return cout<<s,0
#define mod 1000000007
#define PI 3.14159265359
#define CODE_START  ios_base::sync_with_stdio();cin.tie();cout.tie();
using namespace std;
ll n;
double a[1000],ans=0;
int32_t main(){
    cout<<fixed;
    cin>>n;
    for(ll i=0;i<n;i++)
    {
        cin>>a[i];
    }
    sort(a,a+n);
    if(n==2){
        cout<<setprecision(6)<<(a[0]+a[1])/2<<endl;
    }else {
    ans=(a[0]+a[1])/2;
    for(ll i=2;i<n;i++)
    {
        ans=(ans+a[i])/2;
    }
    cout<<setprecision(6)<<ans<<endl;
    }
}


Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var h, w int
	fmt.Scan(&h, &w)

	ss := make([]string, h)
	for i := 0; i < h; i++ {
		fmt.Scan(&ss[i])
	}

	const inf int = 1e9
	m := make([][]int, h)
	for i := 0; i < h; i++ {
		m[i] = make([]int, w)
		for j := 0; j < w; j++ {
			m[i][j] = inf
		}
	}

	dx := []int{0, 1}
	dy := []int{1, 0}

	ans := h * w
	var dfs func(i, j, c, p int)
	dfs = func(i, j, c, p int) {
		if ss[i][j] == '#' {
			if p == 0 {
				c++
			}
			p = 1
		} else {
			p = 0
		}

		if m[i][j] <= c {
			return
		}
		m[i][j] = c

		if i == h-1 && j == w-1 {
			ans = min(ans, c)
			return
		}

		for d := 0; d < 2; d++ {
			nx, ny := j+dx[d], i+dy[d]
			if 0 <= nx && nx < w && 0 <= ny && ny < h {
				dfs(ny, nx, c, p)
			}
		}
	}
	dfs(0, 0, 0, 0)

	fmt.Println(ans)
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define len(x) ((ll)(x).size())
#define debug(var) cout << "[" << #var << "]\n" << var << "\n"
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;
const double EPS = 1e-9;

template <typename T>
ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i];
    if (i < len - 1)
      s << ' ';
  }
  return s;
}

template <typename T>
ostream& operator<<(ostream& s, const vector<vector<T>>& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i];
    if (i != len - 1)
      cout << '\n';
  }
  return s;
}

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

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

__attribute__((constructor)) void initial() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

signed main() {
  ll H, N;
  cin >> H >> N;
  vector<ll> A(N);
  rep(i, N) {
    cin >> A[i];
  }

  ll sum = 0;
  rep(i, N) {
    sum += A[i];
  }

  if (sum >= H)
    cout << "Yes\n";
  else
    cout << "No\n";
}

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

int main() {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    vector<ll>x, y;
    x.push_back(a); x.push_back(b);
    y.push_back(c); y.push_back(d);
    if (a <= 0 && 0 <= b) x.push_back(0);
    if (c <= 0 && 0 <= d) y.push_back(0);
    ll ans = -1e18;
    rep(i, x.size()) {
        rep(j, y.size()) {
            ans = max(ans, x[i] * y[j]);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
using ll = long long;

int main(int argc, const char * argv[]) {
    int n;
    cin >> n;
    if (n >= 1000) {
        cout << "ABD" << endl;
    }else{
        cout << "ABC" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
n = int(input())
str_dic = {}
for _ in range(n):
    inp = input()
    if inp in str_dic:
        str_dic[inp] += 1
    else:
        str_dic[inp] = 1

max_num = max(str_dic.values())

max_str = [s[0] for s in str_dic.items() if s[1] == max_num]

for s in sorted(max_str):
    print(s)


Measured memory_bytes: 96100
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
using namespace std;
int main(){
  int n, k;
  cin >> n >> k;
  vector<int>h(n);
  for(int i; i<n; i++)  cin >> h[i];
  sort(h.begin(), h.end());
  vector<int>hh(n-k+1);
  for(int i=0; i<n-k+1; i++){
    hh[i] = h[i+k-1] - h[i];
  }
  sort(hh.begin(), hh.end());
  cout << hh[0] << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

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

typedef long long lint;

using namespace std;

int main(){
  int A,B,C,K;
  cin>>A>>B>>C>>K;
  cout<<min(A,K)-max(K-B-A,0)<<endl;
  return 0;
}


Measured memory_bytes: 3600
import java.util.*;
import java.io.*;
 
public class Main {
    static HashMap<Integer,ArrayList<Integer>> to = new HashMap<Integer,ArrayList<Integer>>();
    static int[] ans;
    public static void main(String[] args) throws Exception {
        FastScanner sc = new FastScanner(System.in);
        int n = sc.nextInt();
        int[] dums = new int[n];
        double[] ans = new double[n];
        int sum = 0;
        for(int i = 0; i < n; i++){
            dums[i] = sc.nextInt();
            sum += dums[i];
        }
        for(int i = 0; i < n/2; i++){
            sum -= 2*dums[i*2+1];
        }
        ans[0] = sum;
        for(int i = 1; i < n; i++){
            ans[i] = 2*dums[i-1]-ans[i-1];
        }
        
        for(int i = 0; i < n; i++){
            System.out.print((int)ans[i]+" ");
        }
    }
    
    static class FastScanner {
        private BufferedReader reader = null;
        private StringTokenizer tokenizer = null;

        public FastScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
            tokenizer = null;
        }

        public String next() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public String nextLine() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    return reader.readLine();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }

            return tokenizer.nextToken("\n");
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public double nextDouble() {
             return Double.parseDouble(next());
         }

        public int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        public long[] nextLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = nextLong();
            return a;
        } 
    }
}


Measured memory_bytes: 48228
#include <cstdio>
#include <iostream>

typedef long long i64;

#define MID ((l+r)>>1)

i64 N, M;

void exec() {
  i64 l(-1), r(1e12+1);
  scanf("%lld%lld", &N, &M);
  while (l+1 < r) {
    (std::min(N + std::max((M-MID*2) / 2, 0ll), M/2) >= MID? l : r) = MID;
  }
  printf("%lld\n", l);
}

int main() {
  if (fopen("C.in", "r") != NULL) {
    freopen("C.in", "r", stdin);
    freopen("C.out", "w", stdout);
  }
  exec();
  return 0;
}


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

int n;
int a[200001];

long long calc(long long x)
{
	long long res = 0;
	for (int i = 1; i <= n; i++)
		res += abs(a[i] - i - x);
	
	return res;
}

int main()
{
	scanf("%d", &n);
	for (int i = 1; i <= n; i++)
		scanf("%d", &a[i]);
		
	long long s = -1e9, e = 1e9;
	while (e - s >= 3)
	{
		long long p = (s * 2 + e) / 3, q = (s + 2 * e) / 3;
		if (calc(p) <= calc(q))
			e = q;
		else
			s = p;	
	}
	
	long long ans = LLONG_MAX;
	for (int i = s; i <= e; i++)
		ans = min(ans, calc(i));
		
	printf("%lld\n", ans);
}

Measured memory_bytes: 1024
import java.io.*;
public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str = "";
		int i = 1;
		while(true){
			str = br.readLine();
			if(str.equals("0")){
				break;
			}//if
			System.out.println("Case " + i + ": " + str);
			i++;
		}//while
		br.close();
	}
}

Measured memory_bytes: 27924
#include <string>
#include <vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<functional>
#include<list>
#include<deque>
#include<bitset>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<cstring>
#include<sstream>
#include<complex>
#include<iomanip>
#include<numeric>
#include<cassert>
#include<random>
#define X first
#define Y second
#define pb push_back
#define rep(X,Y) for (int (X) = 0;(X) < (int)(Y);++(X))
#define reps(X,S,Y) for (int (X) = (int)(S);(X) < (int)(Y);++(X))
#define rrep(X,Y) for (int (X) = (int)(Y)-1;(X) >=0;--(X))
#define rreps(X,S,Y) for (int (X) = (int)(Y)-1;(X) >= (int)(S);--(X))
#define repe(X,Y) for ((X) = 0;(X) < (Y);++(X))
#define peat(X,Y) for (;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())
#define Endl endl
#define NL <<"\n"

using namespace std;
using ll=long long;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
template<class T> using vv=vector<vector<T>>;
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
//#undef NUIP
#ifdef NUIP
#include "benri.h"
#else
#define out(args...)
#endif
#ifdef __cpp_init_captures
template<typename T>vector<T> table(int n, T v){ return vector<T>(n, v);}
template <class... Args> auto table(int n, Args... args){auto val = table(args...); return vector<decltype(val)>(n, move(val));}
#endif
const ll MOD=1e9+7; //998244353

const int L=128;
string ans="Atcod3rIsGreat";
int cnt=0;

array<int,200> numOf;
int len;

int edst(string s,string t){
	int n=s.size();
	int m=t.size();
	vv<int> dp(n+1,vector(m+1,(int)MOD)); dp[0][0]=0;
	rep(i,n+1)rep(j,m+1){
		if(i!=n) MN(dp[i+1][j],dp[i][j]+1);
		if(j!=m) MN(dp[i][j+1],dp[i][j]+1);
		if(i!=n && j!=m) MN(dp[i+1][j+1],dp[i][j]+(s[i]!=t[j]));
	}
	return dp[n][m];
}

int ask(string s){
	if(s.empty()) return 0;
	// if(s.size()>=L) return 0;
	if(s.size()>=L) s=s.substr(0,L);
	++cnt;
#ifdef NUIP
	return edst(s,ans);
#else
	cout<<"? "<<s<<endl; cout.flush();
	int re;
	cin>>re;
	return re;
#endif
}
bool isSub(string s){
	int t=ask(s);
	return (s.size()+t==len);
}


string solve(string cs){
	if(cs.empty()) return "";
	if(cs.size()==1){
		int t=numOf[cs[0]];
		return string(t,cs[0]);
	}
	int n=cs.size();
	string A=solve(cs.substr(0,n/2));
	string B=solve(cs.substr(n/2));
	string re=A;
	rrep(i,A.size()){
		while(B.size()){
			string s=re.substr(0,i+1)+B.back()+re.substr(i+1);
			if(!isSub(s)) break;
			B.pop_back();
			re=s;
		}
	}
	re=B+re;
	out(cs,re,1);
	return re;
}

string solve(){
	string cs;
	reps(c,'a','z'+1) cs+=c;
	reps(c,'A','Z'+1) cs+=c;
	reps(c,'0','9'+1) cs+=c;
	//random_shuffle(all(cs));
	for(char c:cs) numOf[c]=L-ask(string(L,c));
	for(char c:cs) out(c,numOf[c],1);
	len=0;
	for(char c:cs) len+=numOf[c];
	return solve(cs);
}

int main(){
	string re=solve();
	out(cnt,1);
	cout<<"! "<<re<<endl; cout.flush();
  return 0;
}


Measured memory_bytes: 3792
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // uint64_t

#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) > (b) ? (b) : (a))

int get_int(void) {
  int num;
  scanf("%d", &num);
  return num;
}

int get_int2(int *a1, int *a2) {
  scanf("%d %d", a1, a2);
  return 0;
}

int get_int3(int *a1, int *a2, int *a3) {
  scanf("%d %d %d", a1, a2, a3);
  return 0;
}

// <arr[0]> <arr[1]> .. <arr[size-1]>
int fget_array(int *arr, int size) {
    int i;
    for(i = 0; i < size; i++) {
        scanf("%d", &arr[i]);
    }
    return 0;
}

#define ROW_MAX 300
#define COL_MAX 300

struct point2d {
    int x;
    int y;
};

int dist(struct point2d p1, struct point2d p2) {
    return abs(p1.x - p2.x) + abs(p1.y - p2.y);
}
#define QUERY_MAX 100000

int main(void) {
    int row, col, d;
    get_int3(&row, &col, &d);
    static struct point2d map[ROW_MAX*COL_MAX];
    int i, j;
    for(i = 1; i <= row; i++) {
        for(j = 1; j <= col; j++) {
            int label = get_int();
            map[label] = (struct point2d){i, j};
        }
    }

    int rem;
    static int64_t cum[ROW_MAX*COL_MAX+1];
    for(rem = 0; rem < d; rem++) {
        int ulimit = ((row*col)-rem)/d;
        int prev = rem;
        for(i = 1; i <= ulimit; i++) {
            int cur = i*d+rem;
            cum[cur] = cum[prev] + dist(map[prev], map[cur]);
            prev = cur;
        }
    }

    int queries = get_int();
    static int64_t ans[QUERY_MAX];
    int aidx = 0;
    for(i = 0; i < queries; i++) {
        int start, goal;
        get_int2(&start, &goal);
        ans[aidx++] = cum[goal] - cum[start];
    }
    
    for(i = 0; i < aidx; i++) {
        printf("%lld\n", ans[i]);
    }
    return 0;
}

Measured memory_bytes: 3200
// C - Train Ticket
#include <bits/stdc++.h>
using namespace std;

int main(){
	string S; cin>>S;
	int a=S[0]-'0', b=S[1]-'0', c=S[2]-'0', d=S[3]-'0';
	if(a+b+c+d==7) printf("%d+%d+%d+%d=7\n",a,b,c,d);
	else if(a+b+c-d==7) printf("%d+%d+%d-%d=7\n",a,b,c,d);
	else if(a+b-c+d==7) printf("%d+%d-%d+%d=7\n",a,b,c,d);
	else if(a+b-c-d==7) printf("%d+%d-%d-%d=7\n",a,b,c,d);
	else if(a-b+c+d==7) printf("%d-%d+%d+%d=7\n",a,b,c,d);
	else if(a-b+c-d==7) printf("%d-%d+%d-%d=7\n",a,b,c,d);
	else if(a-b-c+d==7) printf("%d-%d-%d+%d=7\n",a,b,c,d);
	else if(a-b-c-d==7) printf("%d-%d-%d-%d=7\n",a,b,c,d);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
char txt;
void solve(){
    if(isupper(txt)) {
        cout<<"A"<<endl;
    }else{
        cout<<"a"<<endl;
    }
}

int main(){
    cin>>txt;

    solve();
    return 0;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
constexpr ll INF = LLONG_MAX;
constexpr double DINF = DBL_MAX;
constexpr ll mod = 1e9+7;
constexpr double PI = M_PI;

int main(){
  cin.tie(0);
  cout.tie(0);
  ios::sync_with_stdio(false);
 
  long long d;
  string s;
  cin >> s >> d;
  long long n = (ll)s.size();
  vector<vector<vector<ll> > > dp(n+1, vector<vector<ll> >(d, vector<ll>(2, 0ll)));
  // dp[i+1][j][k] := 先頭からi文字目まで見たときに
  //                桁和をdで割った余りがjになるs以下の数の個数
  //                k = ( 先頭i文字目までsと一致しているか ? 1 : 0)
  dp[0][0][1] = 1;
  for(int i = 0; i < n; i++){
    for(int j = 0; j < d; j++){
      for(int k = 0; k < 10; k++){
        for(int l = 0; l < 2; l++){
          if(l == 1 and s[i]-'0' < k) continue;
          dp[i+1][(j+k) % d][s[i]-'0' == k and l] += dp[i][j][l];
          dp[i+1][(j+k) % d][s[i]-'0' == k and l] %= mod;
        }
      }
    }
  }
  cout << (dp[n][0][0] + dp[n][0][1] - 1 + mod)%mod << endl;
  return 0;
}

Measured memory_bytes: 55424
#include<stdio.h>
int main(void)
{
    int n,d[50],i,j,s=0;
    scanf("%d",&n);
    for(i=0;i<n;i++)
        scanf("%d",&d[i]);
    for(i=0;i<n-1;i++)
        for(j=i+1;j<n;j++)
                s+=d[i]*d[j];
    printf("%d\n",s);
    return 0;
}

Measured memory_bytes: 128
use std::io;
use std::str::FromStr;

fn main() {
    let stdin = io::stdin();
    let mut buf = String::new();
    stdin.read_line(&mut buf).ok();

    let mut it = buf.split_whitespace().map(|n| i64::from_str(n).unwrap());
    let n = it.next().unwrap();

    let mut buf = String::new();
    stdin.read_line(&mut buf).ok();

    let mut it = buf.split_whitespace().map(|n| i64::from_str(n).unwrap());
    let a = it.next().unwrap();

    let nn = n * n;
    println!("{}", nn - a);
}


Measured memory_bytes: 4352
#include<stdio.h>
int main()
{
    int ara[10000],i,n;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%d",&ara[i]);
    }
    for(i=n-1;i>=0;i--)
    {
        printf("%d",ara[i]);
        if(i>0)
        {
            printf(" ");
        }
    }
    printf("\n");
    return 0;
}



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

#define SZ(x) (((int)x.size()))
#define all(x) (x).begin(), (x).end()

typedef long long ll;
typedef long double ld;

using namespace std;

const int mod = 998244353, maxn = 3*1000+10;
ll dp[maxn], ans;
int n, s, a;

int main()
{
	cin >> n >> s;
	for (int i = 0; i < n; i++)
	{
		cin >> a;
		for (int j = s; j >= a; j--)
		{
			if (j == s)
			{
				if (j - a == 0)
					ans += (ll)(n - i) * (i + 1);
				else
					ans += (ll)(n - i) * dp[j - a];
				ans %= mod;
			}
			if (j - a == 0)
				dp[j] += i + 1;
			else
				dp[j] += dp[j - a];
			dp[j] %= mod;
		}
	}
	cout << ans;
	return 0;
}


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

typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<vi> vvi;

vb states;

int checkOns(vb &v, vvi &ons) {
	for (int i = 0; i < ons.size(); i++) {
		int st = 0;
		for (int j = 0; j < ons[i].size(); j++) {
			if (v[ons[i][j]])
				st++;
		}
		if ((st % 2) != states[i])
			return 0;
	}
	return 1;
}

int generatCombs(int n, vvi &ons) {
	int c = 0;
	string bull;
	for (int i = 0; i <= n; i++) {
		vb v(n);
		fill(v.end() - i, v.end(), true);
		do {
			c += checkOns(v, ons);
		} while (next_permutation(v.begin(), v.end()));
	}
	return c;
}

int main()
{
	int n, m, k, p, s, i, j;
	scanf("%d %d", &n, &m);
	vvi ons(m);
	for (i = 0; i < m; i++) {
		scanf("%d ", &k);
		for (j = 0; j < k; j++) {
			scanf("%d ", &s);
			ons[i].push_back(s - 1);
		}
	}
	for (i = 0; i < m; i++) {
		scanf("%d ", &p);
		states.push_back(p);
	}
	printf("%d\n", generatCombs(n, ons));
	return 0;
}

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

int main() {
	string o, e;
	cin >> o >> e;
	rep(i, o.size()) {
		cout << o[i];
		if(i < e.size()) cout << e[i];
	}
	cout << endl;
	return 0;
}

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

using namespace std;

int main()
{
	int N, K;
	cin >> N >> K;
	vector<int> p;
	for (int i = 0; i < N; i++) {
		int tmp;
		cin >> tmp;
		p.push_back(tmp);
	}
	sort(p.begin(), p.end());

	int ans = 0;
	for (int i = 0; i < K; i++) {
		ans += p[i];
	}

	cout << ans << endl;

	return 0;
}

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

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

int main(){
    int n,x,t; cin>>n>>x>>t;
    cout<<(n+x-1)/x*t<<endl;
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
namespace IO
{
	template <typename T> inline void read(T &x)
	{
		int f = 1; x = 0; char c = getchar();
		for (; !isdigit(c); c = getchar()) if (c == '-') f = -1;
		for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + (c ^ 48);
		x *= f;
	}

	template <typename T> inline void chkmax(T &x, T y) { x = x > y ? x : y; }
	template <typename T> inline void chkmin(T &x, T y) { x = x < y ? x : y; }

	template <typename T> inline void write(T x)
	{
		if (x < 0) putchar('-'), x = -x;
		if (x > 9) write(x / 10);
		putchar(x % 10 + '0');
	}
	template <typename T> inline void writesp(T x) { write(x); putchar(' '); }
	template <typename T> inline void writeln(T x) { write(x); putchar('\n'); }
}
using namespace IO;
const int N = 1e3 + 5;
int n, k, a[N];
int main(){
	read(n); read(k);
	for (int i = 1; i <= n; i++) read(a[i]);
	sort(a + 1, a + n + 1);
	int ans = 0;
	for (int i = 1; i <= k; i++) ans += a[i];
	writeln(ans);
  return 0;
}

Measured memory_bytes: 3620
#include <stdio.h>
#define MAX 110

int main(void) {
    int
        N,
        cont = 0,
        max_cont = 0;

    scanf("%d", &N);

    for (int i = 0; i < N; i++) {
        int t = 0;
        scanf("%d", &t);

        if (t == 1) {
            cont++;
        } else {
            max_cont = cont > max_cont ? cont : max_cont;
            cont = 0;
        }
    }

    max_cont = cont > max_cont ? cont : max_cont;
    printf("%d\n", max_cont+1);
    return 0;
}


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

ab = []
room = [set() for _ in range(n)]
root_help = [-1 for _ in range(n)]
for i in range(m):
    tmp=list(map(int,input().split()))
    tmp.sort()
    room[tmp[0]-1].add(tmp[1]-1)
    room[tmp[1]-1].add(tmp[0]-1)
    ab.append(tmp)

ab.sort(key=lambda x:x[0])

posi=[0]
next = [1]
already = {0}
while posi:
    tmp_posi=[]
    for p in posi:
        connect = room[p]
        for i in connect:
            if i not in already:
                root_help[i]=p
                already.add(i)
                tmp_posi.append(i)
    posi=tmp_posi

answer = [i + 1 for i in root_help[1::]]
if 0 in answer:
    print('No')
else:
    print('Yes')
    for i in answer:
        print(i)

Measured memory_bytes: 169084
// https://atcoder.jp/contests/dp/tasks/dp_r

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define REP(i,n)   for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for(int i=(b); i<=(int)(e); i++)
#define DUMP(a, n) REP(i, n) printf("%d%c", a[i], i + 1 == n ? '\n' : ' ')
#define DUMP2D(a, n, m) REP(i, n) REP(j, m) printf("%d%c", a[i][j], j + 1 == m ? '\n' : ' '); puts("")

const int N_MAX = 50;
const ll K_MAX = 1e18;
const int MOD = 1e9+7;

//------------------------------------------------------------------------------
typedef vector<int> vec;
typedef vector<vec> mat;

mat mul(mat &A, mat &B) {
  mat C = mat(A.size(), vec(B[0].size()));
  REP(i, A.size()) REP(k, B.size()) REP(j, B[0].size())
    C[i][j] = (C[i][j] + (ll) A[i][k] * B[k][j]) % MOD;
  return C;
}

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

//------------------------------------------------------------------------------
int N;
ll K;
mat a;

void solve() {
  mat ak = pow(a, K);
  int ans = 0;
  REP(i, N) REP(j, N) {
    ans = (ans + ak[i][j]) % MOD;
  }
  printf("%d\n", ans);
}

void input() {
  scanf("%d%lld", &N, &K);
  a = mat(N, vec(N));
  REP(i, N) REP(j, N) scanf("%d", &a[i][j]);
}

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


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

typedef long long ll;
const int MAX_NODES = 1e5;
int N, M, ans = 0;
vector<vector<int>> g;
vector<int> vis;

int dfs(int u) {
    if(vis[u]) return vis[u];
    int mx = 0;
    for(int i = 0; i < g[u].size(); i++)
        mx = max(mx, dfs(g[u][i]) + 1);
    
    vis[u] = mx;
    return mx;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> N >> M;
    g.resize(N);
    vis.resize(N);

    for(int i = 0; i < M; i++) {
        int u, v;
        cin >> u >> v;
        --u, --v;
        g[u].push_back(v);
    }

    for(int i = 0; i < N; i++) {
        if(!vis[i])
            ans = max(ans, dfs(i));
    }
    cout << ans << "\n";

    return 0;
}


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

int main(){
    long long n, c, k;
    cin >> n >> c >> k;

    vector<long long> T(n);

    for(long long i = 0; i < n; i++) cin >> T[i];

    sort(T.begin(), T.end());

    long long ans = 0;
    long long cnt = 0;
    long long left = T[0];
    long long right = T[0] + k;

    for(long long i = 0; i < n; i++){
        if(cnt < c and left <= T[i] and T[i] <= right){
            cnt++;
            right = min(right, T[i] + k);
        }
        else if(cnt >= c){
            ans++;
            cnt = 1;
            left = T[i];
            right = T[i] + k;
        }
        else if(T[i] > right){
            ans++;
            cnt = 1;
            left = T[i];
            right = T[i] + k;
        }
    }
    ans++;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3984