akhauriyash/Code-Regression huggingface dataset:
n=int(input())
h=list(map(int,input().split()))
c=[0]*n
c[1]=abs(h[1]-h[0])
i=2
while i<n:
	c[i]=min(c[i-2]+abs(h[i-2]-h[i]),c[i-1]+abs(h[i-1]-h[i]))
	i+=1
print(c[n-1])

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

using namespace std;

long long val(vector<long long> a){
  sort(a.begin(),a.end());
  return *(a.end()-1)-*a.begin();
}

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

  vector<int> A(N+1, 0);
  vector<long long> sum(N+1, 0);
  for(int i=1; i<=N; i++){
    cin >> A[i];
    sum[i] = sum[i-1] + A[i];
  }

  vector<int> l(N+1, 0);
  l[2] = 1;
  for (int i = 3; i <= N-1; i++) {
    long long n = abs((sum[i]-sum[l[i-1]])-sum[l[i-1]]);
    int j;
    for (j = l[i-1]+1; j<i; j++) {
      if(n>abs((sum[i]-sum[j])-sum[j])){
	n = abs((sum[i]-sum[j])-sum[j]);
      } else {
	break;
      }
    }
    l[i] = j-1;
  }

  vector<int> r(N+1, 0);
  r[N-1] = N;
  for (int i=N-2; i>=2; i--) {
    long long n = abs((sum[N]-sum[r[i+1]])-(sum[r[i+1]]-sum[i]));
    int j;
    for (j = r[i+1]-1; j>i;j--){
      if(n>abs((sum[N]-sum[j])-(sum[j]-sum[i]))) {
	n = abs((sum[N]-sum[j])-(sum[j]-sum[i]));
      } else {
	break;
      }
    }
    r[i] = j+1;
  }
	
  long long res = numeric_limits<long long>::max();
  for (int i = 2; i <= N-1; i++) {
    res = min(val(vector<long long>{sum[l[i]]-sum[0],
	    sum[i]-sum[l[i]],
	    sum[r[i]]-sum[i],
	    sum[N]-sum[r[i]]}),
      res
      );
  }

  cout << res << endl;
  return 0;
}


Measured memory_bytes: 4224
a[9][9][11],b,f,r,v,n;main(){for(scanf("%d",&n);n--;scanf("%d%d%d%d",&b,&f,&r,&v),a[b][f][r]+=v);for(b=0;b++<4;b>3?exit(0):puts("####################"))for(f=0;f++<3;puts(""))for(r=0;r++<10;printf(" %d",a[b][f][r]));}

Measured memory_bytes: 612
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  vector<int>a(n);
  for (int i=1;i<n+1;i++) {
    for (int j=1;j<n+1;j++) {
      if(j*j>i){
        break;
      }
      for (int k=1;k<n+1;k++) {
        if(j*j+k*k+j*k>i){
          break;
        }  
        for (int l=1;l<n+1;l++) {
           if(j*j+k*k+l*l+j*k+k*l+l*j==i){
             a.at(i-1)++;
           }
           if(j*j+k*k+l*l+j*k+k*l+l*j>i){
             break;
           } 
        }
      }
    }
  }
  for (int i=0;i<n;i++) {
    cout << a[i] << endl;
  }
  
}

Measured memory_bytes: 3632
import java.util.Scanner;
import java.lang.Math;

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

    int Porder = 0;
    int[] P = new int[N];
    for(int i=0; i<N; i++) {
      P[i] = scan.nextInt();
      int underCount = 0;
      for(int j=0; j<i; j++) {
        if(P[j] < P[i]) {
          underCount++;
        }
      }
      Porder += kaijo(N-i-1) * (P[i]-underCount-1);
    }

    int Qorder = 0;
    int[] Q = new int[N];
    for(int i=0; i<N; i++) {
      Q[i] = scan.nextInt();
      int underCount = 0;
      for(int j=0; j<i; j++) {
        if(Q[j] < Q[i]) {
          underCount++;
        }
      }
      Qorder += kaijo(N-i-1) * (Q[i]-underCount-1);
    }

    System.out.println(Math.abs(Porder - Qorder));

    scan.close();
  }

  public static int kaijo(int N) {
    int result = 1;
    for(int i=1; i<=N; i++) {
      result *= i;
    }
    return result;
  }
}

Measured memory_bytes: 21844
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 3001; //check the limits, dummy

ll modExp(ll base, ll power, ll P) {
    if (power == 0) {
        return 1;
    } else {
        ll cur = modExp(base, power / 2, P); cur = cur * cur; cur = cur % P;
        if (power % 2 == 1) cur = cur * base;
        cur = cur % P;
        return cur;
    }
}

ll mul(ll A, ll B, int P) {
	return (A*B)%P;
}

ll add(ll A, ll B) {
	return (A+B)%MOD;
}


ll sub(ll A, ll B, int P) {
    return (A-B+P)%P;
}

ll* facs = new ll[3001];


void initFacs(int P) {
	facs[0] = 1;
	FOR(i, 1, MX) {
		facs[i] = (facs[i-1] * i) % P;
	}
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); 
    
    
    int P; cin >> P;
    initFacs(P);
    int data[P]; F0R(i, P) cin >> data[i];
    vector<vi > partials;
    vi cur2;
    F0R(i, P) {
		 cur2.pb(data[i]);
	}
	partials.pb(cur2);
	F0R(i, P-1) {
		  vi cur;
		  F0R(j, sz(partials[i]) - 1) {
			  cur.pb(sub(partials[i][j+1], partials[i][j], P));
		  }
		  partials.pb(cur);
	  }
	  
	  
	  vi ans;

	  F0Rd(i, P) {
		  //X-1, X-2, ..., X-P-1
		  
		  //multiply by X-i+1
		  vi nxt(sz(ans)+1);
		  F0R(j, sz(nxt)) {
			  nxt[j] = 0;
			  if (j > 0) {
				  nxt[j] += mul(ans[j-1], P-i, P);
				  nxt[j] %= P;
			  }
			  if (j < sz(ans)) {
				  nxt[j] += ans[j];
				  nxt[j] %= P;
			  }
		  }
		  
		  ans = nxt;
		  
		  //add X
		  ans[sz(ans)-1] += mul(partials[i][0], modExp(facs[i], P-2, P), P);
		  ans[sz(ans)-1] %= P;
		  
		 
	  }
	  reverse(all(ans));
	  F0R(i, P) cout << ans[i] << " ";
	  cout << endl;
    
    return 0;
}

// read the question correctly (ll vs int)
// template by bqi343


Measured memory_bytes: 18048
#include<stdio.h>
#include<math.h>
 
int main(){
  int n, x[100], y[100];
  int i, k, max = 0;
  double ans;
 
  scanf("%d", &n);
   
  for(i = 0; i<n; ++i){
    scanf("%d", &x[i]);
  }
  for(i = 0; i<n; ++i){
    scanf("%d", &y[i]);
  }
 
  for(i = 1; i<4; ++i){
    ans = 0;
    for(k = 0; k<n; ++k){
      ans += pow(fabs(x[k] - y[k]), i);
      if(max < fabs(x[k] - y[k])){
    max = fabs(x[k] - y[k]);
      }
    }
    ans = pow(ans, 1.0/i);
 
    printf("%lf\n", ans);
  }
 
  printf("%d\n", max);
   
  return 0;
}



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

using namespace std;

long long f[100001][3];

int main(void) {
    int n, k, r, s, p;
    cin >> n >> k >> r >> s >> p;
    string t;
    cin >> t;
    auto chk = [&] (char &ch) {
        return ch == 'r' ? p :
            ch == 's' ? r : s;
    };
    long long ans = 0;
    for (int base = 0; base < k; base++) {
        char last = 0;
        for (int i = base; i < t.length(); i += k) {
            if (t[i] == last) {
                last = 0;
                continue;
            }
            last = t[i];
            ans += chk(t[i]);
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main(void) {
  ios::sync_with_stdio(false);
  int N, X, Y;
  cin >> N >> X >> Y;

  vector<vector<int>> G(N);
  for (int i = 0; i < N - 1; ++i) {
    G[i].emplace_back(i + 1);
    G[i + 1].emplace_back(i);
  }
  X--;
  Y--;
  G[X].emplace_back(Y);
  G[Y].emplace_back(X);

  vector<int> answer(N, 0);
  for (int i = 0; i < N; ++i) {
    priority_queue<pair<int, int>> que;
    que.emplace(0, i);
    vector<int> visit(N, INT_MAX);
    while (!que.empty()) {
      int cost, v;
      tie(cost, v) = que.top();
      que.pop();
      if (visit[v] < cost) continue;
      for (auto nv : G[v]) {
        if (visit[nv] <= cost + 1) continue;
        visit[nv] = cost + 1;
        que.emplace(cost + 1, nv);
      }
    }
    for (int j = 0; j < i; ++j) {
      int k = visit[j];
      answer[k]++;
    }
  }

  for (int i = 1; i < N; ++i) cout << answer[i] << endl;
  return 0;
}


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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"

using namespace std;
using ll = long long;

const ll MOD = 1000000007LL; // = 10^9 + 7
const double PI = 3.14159265358979;

void solve()
{
	int n, x, l;
	cin >> n >> x;
	int cnt = 1;
	int pos = 0;
	for(int i = 0; i < n; ++i)
	{
		cin >> l;
		pos = pos + l;
		if (x < pos) break;
		cnt++;
	}
	cout << cnt;
}

int main()
{
	fastio;
	solve();

	return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define INF (1LL<<50)
#define MOD 1000000007

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i,N){
        cin >> A[i];
    }
    sort(A.rbegin(),A.rend());
    if(N%2==0){
        // N型と逆N型があるが対称なのでN型だけ考える
        // (b-a)+(b-c)+(d-c) = -a + 2b -2c + d
        // 端の係数は-1か1
        // 端以外は-2か2
        // 大きいほうから(N-2)/2取って2かける
        // 次の数はそのまま
        // 次の数を引く
        // 残った(N-2)/2は-2かける
        ll ans = 0;
        for(int i=0; i<(N-2)/2; i++){
            ans += A[i]*2;
        }
        ans += A[(N-2)/2];
        ans -= A[(N-2)/2+1]; // N/2
        for(int i=(N-2)/2+2; i<N; i++){
            ans -= A[i]*2;
        }
        cout << ans << endl;
    }else{
        // 奇数の場合はW型とM型がある
        // W型の時
        // 両端は+1,それ以外のうち(N-2)/2個が+2,残りの(N-2)/2+1が-2
        ll ans1 = 0;
        for(int i=0; i<(N-2)/2; i++){
            ans1 += A[i]*2;
        }
        ans1 += A[(N-2)/2] + A[(N-2)/2+1];
        for(int i=(N-2)/2+2; i < N; ++i){
            ans1 -= A[i]*2;
        }
        // M型の時
        // 両端が-1,それ以外のうち(N-2)/2個が-2,残りの(N-2)/2+1が+2
        ll ans2 = 0;
        for(int i=0; i<(N-2)/2+1; i++){
            ans2 += A[i]*2;
        }
        ans2 -= A[(N-2)/2+1] + A[(N-2)/2+2];
        for(int i=(N-2)/2+3; i < N; ++i){
            ans2 -= A[i]*2;
        }
        cout << max(ans1,ans2) << endl;
    }
    return 0;
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int sum = sc.nextInt() + sc.nextInt() + sc.nextInt() + sc.nextInt();
		System.out.println(sum / 60);
		System.out.println(sum % 60);
	}
}

Measured memory_bytes: 25968
class UnionFind
	def initialize(n)
		@parent = (0..n).to_a
	end

	def unite(x,y)
		rx, ry = x, y
		while @parent[rx] != @parent[ry]
			rx, ry = ry, rx if @parent[rx] > @parent[ry]
			break @parent[rx] = @parent[ry] if rx == @parent[rx]
			@parent[rx], rx = @parent[@parent[ry]], @parent[rx]
		end
	end

	def root(x)
		while x != @parent[x]
			x = @parent[@parent[x]]
		end
	return x
	end
end

N = gets[/.* /].to_i
uf = UnionFind.new(N)
$<.map do |xyz|
	x, y, z = xyz.split.map(&:to_i)
	uf.unite(x,y)
end
p (1..N).map { |x| uf.root(x) }.uniq.size




Measured memory_bytes: 11388
#include <iostream>
#include <cstring>
using namespace std;
const int N=1000000+10;
typedef long long LL;

char s[N];
int nex[N],a[N];

int main(){
    scanf("%s",s+1);
    int n=strlen(s+1);
    for(int i=n+1;i>=1;i--){
        if(s[i]=='>'){
            nex[i]=nex[i+1]+1;
        } else {
            nex[i]=0;
        }
    }
    a[1]=nex[1];
    for(int i=2;i<=n+1;i++){
        if(s[i-1]=='<') a[i]=max(a[i-1]+1, nex[i]);
        else a[i]=nex[i];
    }
    LL ans=0;
    for(int i=1;i<=n+1;i++) {
        //printf("%d\n", a[i]);
        ans += a[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 8448
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<P,int> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

const int M=100;
int A,B,b[M+1][M+1];
vvi a;

int main(){
	cin>>A>>B;
	a=vvi(A+1,vi(B+1));
	for(int i=1;i<=A;i++) for(int j=1;j<=B;j++) cin>>a[i][j];
	for(int i=0;i<=M;i++) for(int j=0;j<=M;j++){
		int res=0;
		for(int k=1;k<=A;k++) for(int l=1;l<=B;l++) res=max(res,a[k][l]-k*i-l*j);
		b[i][j]=res;
	}
	bool flag=1;
	for(int i=1;i<=A;i++) for(int j=1;j<=B;j++){
		bool BB=0;
		for(int k=0;k<=M;k++) for(int l=0;l<=M;l++) if(b[k][l]+k*i+l*j==a[i][j]) BB=1;
		flag&=BB;
	}
	if(flag){
		cout<<"Possible"<<endl;
		cout<<2*M+2<<' '<<2*M+(M+1)*(M+1)<<endl;
		for(int i=1;i<=M;i++) cout<<i<<' '<<i+1<<" X"<<endl;
		for(int i=M+2;i<2*M+2;i++) cout<<i<<' '<<i+1<<" Y"<<endl;
		for(int i=0;i<=M;i++) for(int j=0;j<=M;j++) cout<<i+1<<' '<<2*M+2-j<<' '<<b[i][j]<<endl;
		cout<<1<<' '<<2*M+2<<endl;
	}
	else cout<<"Impossible"<<endl;
}

Measured memory_bytes: 384
X, N = map(int, input().split())
P = sorted(list(map(int, input().split())))

a = -1
if len(P) > 0:
    for p in range(0, 102):
        if abs(X - p) < abs(X - a) and (p not in P):
            a = p
else:
    a = X

print(a)


Measured memory_bytes: 9176
import java.util.*;

public class Main {

  public static void main (String[] args) {

    Scanner sc = new Scanner(System.in);

    int N = sc.nextInt();

    sc.close();

    for (int i = 1; i <= 9; i++) {
      int j = i * 100 + i * 10 + i;
      if (N <= j) {
        System.out.println(j);
        break;
      }
    }

  }

}

Measured memory_bytes: 25172
#include <cstdio>
using namespace std;

int main()
{
	int n;
	
	while (1){
		scanf("%d", &n);
		if (n == 0){
			break;
		}
		int x[11][11] = {0};
		for (int i = 0; i < n; i++){
			for (int j = 0; j < n; j++){
				scanf("%d", &x[i][j]);
				x[i][10] += x[i][j];
				x[10][j] += x[i][j];
			}
			x[10][10] += x[i][10];
		}
		for (int i = 0; i < n; i++){
			for (int j = 0; j < n; j++){
				printf("%5d", x[i][j]);
			}
			printf("%5d\n", x[i][10]);
		}
		for (int j = 0; j < n; j++){
			printf("%5d", x[10][j]);
		}
		printf("%5d\n", x[10][10]);
	}
	
	return (0);
}

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

typedef pair<int,int> P;
#define ll long long
#define ld long double
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define sz(x) ((int)(x).size())
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
int main()
{
    ll n;
    ll k;
    cin >> n >> k;
    k++;
    vector<ll> a(n);
    rep(i,n)
    {
        cin >> a[i];
        a[i]--;
    }
    vector<ll> data;
    vector<ll> counter(n);rep(i,n) counter[i] = 0;
    ll from,to, start;
    from=0;
    start = 0;
    data.push_back(from);
    counter[from]++;
    rep(i,2*n)
    {
        to = a[from];
        if(counter[to]==1)
        {
            start = to;
            break;
        }else
        {
            data.push_back(to);
            counter[to]++;
            from = to;
        }
    }
    ll ldata = (ll)data.size();
    ll cycle = 0;
    ll extra = 0;
    ll flag = 0;
    rep(i,ldata)
    {
        if(data[i] == start)
        {
            break;
        }
        extra++;
    }
    cycle = ldata-extra;
    //cout << extra << " " << cycle << endl;
    if(k<=extra)
    {

        cout << data[k-1]+(ll)1<< endl;
        return 0;
    }
    ll index = extra-1;
    if ((k - extra) % cycle==0)
    {
        index += cycle;
    }else
    {
        index += (k - extra) % cycle;
    }
    
    cout << data[index] + 1 << endl;
    return 0;
}

Measured memory_bytes: 8496
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.PriorityQueue;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.util.Comparator;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author anand.oza
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        EDecreaseJudgeVer solver = new EDecreaseJudgeVer();
        solver.solve(1, in, out);
        out.close();
    }

    static class EDecreaseJudgeVer {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            long[] a = new long[n];

            long sum = 0;
            for (int i = 0; i < n; i++) {
                a[i] = in.nextLong();
                sum += a[i];
            }

            PriorityQueue<Long> max = new PriorityQueue<>(Comparator.reverseOrder());
            for (long x : a) {
                max.add(x);
            }

            long answer = 0;
            long target = n - 1;
            while (max.peek() > target) {
                long cur = max.poll();
                long diff = cur - target;
                long ops = diff / (n + 1);
                if (ops * (n + 1) < diff) ops++;

                cur -= ops * (n + 1);
                answer += ops;
                target -= ops;
                max.add(cur);
            }

            out.println(answer);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

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

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

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

    }
}



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

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

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




int main()
{
  int a, b ;
  cin >> a >> b ;
  
  cout <<(a-1)*(b-1)<<endl ;
  
    return 0 ;
}

/*　吾輩はやれば出来る子である。 
　　　　∩∩ 
　　　（´･ω･） 
　　 ＿|　⊃／(＿＿_ 
　／　└-(＿＿＿_／ 
　￣￣￣￣￣￣￣ 
　やる気はまだない 

　　 ⊂⌒／ヽ-、＿_ 
　／⊂_/＿＿＿＿ ／ 
　￣￣￣￣￣￣￣　　*/

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1LL << 60;

int main() {
    const int n = 200000;
    char *a = new char[n + 10];
    for (int i = 0; i < n + 10; i++) {
        a[i] = 'e';
    }
    cin >> a;
    int i = 0;
    ll sum = 0;
    while (a[i] != 'e') {
        // cout << a[i] << " " << (int)(a[i] - '0') << endl;
        sum += (int)(a[i] - '0');
        i++;
    }
    sum += 48;
    if (sum % 9) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }
    return 0;
}

Measured memory_bytes: 3780
#include<iostream>
#include<vector>
#include<queue>
#include<algorithm>

using namespace std;

#define div 1000000007

int main(){
    int N, K;
    cin >> N >> K;
    vector<int> G[N];

    for(int i=0; i < N-1; i++){
        int a, b;
        cin >> a >>b;
        G[a-1].emplace_back(b-1);
        G[b-1].emplace_back(a-1);
    }

    bool used[N]; for(int i=0; i<N; i++) used[i] = false;

    queue<int> q; 
    q.push(0);
    used[0] = true;

    long ans = K;
    int cnt = 0;

    while(!q.empty()){
        int v = q.front(); q.pop();
        if(cnt == 0){
            K++;
        }
        if(cnt == 1){
            K--;
        }
        cnt++;
        
        int c = 0;
        for(int id : G[v]){
            if(!used[id]){
                used[id] = true;
                q.push(id);
                ans *=max((long)(K-2-c), (long)0);
                ans %=div;
                c++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main()
{
	int a, b, c, min, mid, max;

	cin >> a >> b >> c;

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

	cout << min << " " << mid << " " << max << '\n';

	return 0;
}


Measured memory_bytes: 1164
#include "bits/stdc++.h"
using namespace std;
 
////////////// Prewritten code follows. Look down for solution. ////////////////

#define fs first
#define sc second
#define pb push_back
#define len(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend
#define forn(i, n) for(int i = 0; i < (int)(n); ++i)
#define for1(i, n) for(int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for(int i = (int)(n); i >= 0; --i)
#define fore(i, a, b) for(int i = (int)(a); i <= (int)(b); ++i)

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector<ll> vl;
typedef vector<pll> vpl;
typedef vector<vl> vvl;

template<typename T> void maxself(T &a, T &b){a = max(a, b);};
template<typename T> void minself(T &a, T &b){a = min(a, b);};

const ll LINF = 1e18;
const int INF = 1e9;
const int MOD = 1e9+7;

/// command for char arrays with spaces -> scanf(" %[^\n]", text);
 
////////////////////////// Solution starts below. //////////////////////////////

const int MAX = 1e5+5;
vi f[MAX], B[MAX];
int p[MAX], rnk[MAX], sz[MAX];

int find(int v){
	if(p[v] == v) return v;
	return p[v] = find(p[v]);
}

void merge(int v, int u){
	int x = find(v);
	int y = find(u);
	if(x == y) return;
	if(rnk[x] > rnk[y]) swap(x, y);
	p[x] = y;
	sz[y] += sz[x];
	if(rnk[x] == rnk[y]) rnk[y]++;
}

int main(){

	int n, m, k;
	scanf("%d %d %d", &n, &m, &k);
	forn(i, n){
		p[i] = i;
		sz[i] = 1;
	}
	int a, b;
	forn(i, m){
		scanf("%d %d", &a, &b);
		a--, b--;
		f[a].pb(b);
		f[b].pb(a);
		merge(a, b);
	}
	int c, d;
	forn(i, k){
		scanf("%d %d", &c, &d);
		c--, d--;
		B[c].pb(d);
		B[d].pb(c);
	}
	forn(i, n){
		int ans = sz[find(i)]-1;
		for(int &j : f[i]){
			if(find(j) == find(i)) ans--;
		}
		for(int &j : B[i]){
			if(find(j) == find(i)) ans--;
		}
		printf("%d ", ans);
	}
	
	putchar('\n');
	return 0;
}

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

int main() {
    double x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;

    const double distance = sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2));
    printf("%f\n", distance);

    return 0;
}


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

const int MOD = 1000000007;

int main() {
  int n,k;
  long long ans=0;
  long long tmp;

  cin >> n >> k;

  long long r=0,l=0;

  for(int j=0;j<k-1;j++) {
    r+=n-j;
  }
  for(int j=0;j<k-1;j++) {
    l+=j;
  }

  for(int i=k;i<=n+1;i++) {

    r+=n-i+1;
    l+=i-1;

    tmp=r-l+1;
    //cout<<r<<"-"<<l<<endl;
    ans+=tmp%MOD;
    ans=ans%MOD;
  }

  cout <<ans<< endl;

  return 0;
}


Measured memory_bytes: 3620
import sys
input = sys.stdin.readline

n,m = map(int,input().split())
heap = [int(i) for i in input().split()]
heap.sort()
ans = sum(heap)
ml = []
cnt = 0

for i in range(m):
  a,b = map(int,input().split())
  ml += [[b,a]]
ml.sort(reverse=True)

for i in range(m):
  for j in range(ml[i][1]):
    if ml[i][0] > heap[cnt]:
      ans += ml[i][0] - heap[cnt]
      cnt += 1
      if cnt == n:
        print(ans)
        exit()
    else:
      print(ans)
      exit()
print(ans)

Measured memory_bytes: 23992
S=input()
T=input()
t=len(T)
for i in range(len(S)-t+1):
    a=c=0
    for j in range(t):
        k=S[-t-i+j]
        if k ==T[j] or k=="?" :c+=1
    if c==t:
        bef=S[:len(S)-t-i].replace("?","a")
        aft=""
        if i!=0:aft=S[-i:].replace("?","a")
        print(bef+T+aft)
        exit()
print("UNRESTORABLE")

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <cmath>
using namespace std;

int main(){
    
    int i, j, k, N, count;
    cin >> N;
    count = 0;
    
    int L[N];
    for (i = 0; i < N; i++){
        cin >> L[i];
    }
    
    for (i = 0; i < N; i++){
        for (j = i; j < N; j++){
            for (k = j; k < N; k++){
                
                if (L[i] > L[j] && L[i] > L[k] && L[j] != L[k] && L[i] < L[j] + L[k]){
                    count++;
                } else if (L[j] > L[i] && L[j] > L[k] && L[i] != L[k] && L[j] < L[i] + L[k]){
                    count++;
                } else if (L[k] > L[i] && L[k] > L[j] && L[i] != L[j] && L[k] < L[i] + L[j]){
                    count++;
                }
            }
        }
    }
    
    cout << count << "\n";
    
    return 0;
}


Measured memory_bytes: 3588
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <vector>
#include <functional>
#include <queue>
#include <unordered_set>
#include <climits>

using namespace std;
typedef long long ll;

int main()
{
	string S;
	cin >> S;
	if(S == "ABC"){
		cout << "ARC" << endl;
	}else{
		cout << "ABC" << endl;
	}
	return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>

using namespace std;

int main(){
    int A,B,C;
    cin >> A >> B >> C;
    cerr << A << " " << B << " " << C << " " << B/A << endl;
    int x = B/A;
    if(x<=C) cout << x;
    else
        cout << C;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define ALL(x) (x).begin(), (x).end()
const long long INF = 1e15;
using namespace std;
typedef long long ll;
int main() {
  ll n;
  cin >> n;
  vector<ll> h(n);
  REP(i, n) { cin >> h[i]; }
  ll prev = h[0];
  ll cnt = 0;
  ll ans = 0;
  FOR(i, 1, n) {
    if (prev < h[i]) {
      ans = max(ans, cnt);
      cnt = 0;
      prev = h[i];
      continue;
    }
    prev = h[i];
    cnt++;
  }
  ans = max(ans, cnt);
  cout << ans << endl;
  return 0;
}

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

typedef long long llong;

const int MAX = 100000;
const llong INF = 1LL << 60;
llong h[MAX];
llong dp[MAX];

int main(int argc, const char * argv[]) {
    int N, K;
    
    cin >> N >> K;
    for (int i = 0; i < N; i++) {
        cin >> h[i];
    }
    
    for (int i = 0; i < MAX; i++) {
        dp[i] = INF;
    }
    
    dp[0] = 0;
    
    for (int i = 0; i < N; i++) {
        for (int j = 1; j <= K; j++) {
            llong min = dp[i] + abs(h[i] - h[i + j]);
            if (dp[i + j] > min) {
                dp[i + j] = min;
            }
        }
    }
    
    cout << dp[N - 1] << endl;
    
    return 0;
}

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

int main(){
    unsigned long N;
    cin >> N;
    vector<unsigned long> A(N);
    for(auto& i : A)cin >> i;
    sort(A.begin(), A.end());
    unsigned long ans{0}, p{0}, b{0};
    for(const auto& i : A){
        if(p ^ i){
            ans += b;
            b = 1;
        }else b ^= 1;
        p = i;
    }
    cout << ans + b << endl;
    return 0;
}

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

using namespace std;

int main( ){
  int n,i,j;
  string s;
  unordered_map<string,int> m;
  cin>>n;
  for(i=0;i<n;i++){
    cin>>s;
    m[s]++;
  }
  string p[4]={"AC","WA","TLE","RE"};
  for(i=0;i<4;i++){
    cout<<p[i]<<" "<<"x"<<" "<<m[p[i]]<<endl;
  }
  return 0;
}

Measured memory_bytes: 3644
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
  int N;
  cin >> N;
  int mn = 10000;
  for(int i = 0; i < N; ++i) {
    int a;
    cin >> a;
    int cnt = 0;
    while(a % 2 == 0) {
      a /= 2;
      ++cnt;
    }
    mn = min(cnt, mn);
  }
  cout << mn << endl;
}


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() {
    string S;
    cin >> S;
    deque<char> dq;
    rep(i, S.size()) {
        dq.push_back(S[i]);
    }
    int Q;
    cin >> Q;
    bool rev = false;
    rep(i, Q) {
        int T;
        cin >> T;
        if (T == 1) {
            rev = !rev;
        } else {
            int F;
            char C;
            cin >> F >> C;

            if ((F == 1 && !rev) || (F == 2 && rev)) {
                dq.push_front(C);
            } else {
                dq.push_back(C);
            }
        }
        /*
        for (auto it = dq.begin(); it != dq.end(); it++) {
            cout << *it;
        }
        cout << endl;*/
    }
    string S2;
    if (!rev) {
        for (auto it = dq.begin(); it != dq.end(); it++) {
            S2.push_back(*it);
        }
    } else {
        for (auto it = dq.rbegin(); it != dq.rend(); it++) {
            S2.push_back(*it);
        }
    }
    cout << S2 << endl;

             
    return 0;
}


Measured memory_bytes: 4292
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define MOD 1000000007

int main() {
  int n;
  cin >> n;
  ll ans = 1, sub1 = 1, sub2 = 1;
  for (int i = 0; i < n; ++i) {
    ans *= 10;
    ans %= MOD;
    sub1 *= 9;
    sub1 %= MOD;
    sub2 *= 8;
    sub2 %= MOD;
  }
  ans = (MOD + ans - sub1) % MOD;
  ans = (MOD + ans - sub1) % MOD;
  ans = (ans + sub2) % MOD;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int MOD = 1000000007LL;
const int INF = LLONG_MAX;

signed main(){
    
    int a, b, c; cin >> a >> b >> c;
    if(a == b && b == c) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define fst first
#define snd second

int main()
{
    int n, m;
    cin >> n >> m;
    int a[n];
    int sum = 0;
    for(int i = 0; i < n; i++)
    {
        cin >> a[i];
        sum += a[i];
    }

    int cnt = 0;
    for(int i = 0; i < n; i++)
    {
        if(a[i] * 4 * m >= sum)
            cnt++;
    }

    if(cnt >= m)
        cout << "Yes";
    else
        cout << "No";

    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>

char s[10+5];
int cnt[5];

int get_count(){
    int res = 0;
    int l = strlen(s);
    for(int i = 0; i < l-1; i++){
        if(s[i]=='A' && s[i+1]=='B') res++;
    }
    return res;
}

int get_type(){
    int l = strlen(s);
    if(s[0]=='B' && s[l-1]=='A') return 0;
    else if(s[0]=='B') return 1;
    else if(s[l-1]=='A') return 2;
    else return 3;
}

int min(int a,int b){ return a>b?b:a; }

int main(){
    cnt[0] = cnt[1] = cnt[2] = cnt[3] = 0;
    int n;
    scanf("%d",&n);
    int ans = 0;
    for(int i = 0; i < n; i++){
        scanf("%s",s);
        ans += get_count();
        cnt[get_type()]++;
    }
    if(cnt[0]>1){
        ans += (cnt[0]-1);
        cnt[0] = 1;
    }
    if(cnt[1] && cnt[0]){
        cnt[1]--; 
        ans++;
    }
    if(cnt[2] && cnt[0]){
        cnt[2]--;
        ans++;
    }
    ans += min(cnt[1],cnt[2]);    
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 128
#include <cstdlib>
#include <iostream>
int main(void) {
    const int mod = 1000000007;
    int n;
	while (std::cin >> n) {
		long long ans = 1;
		int fail = 0, stack = 0, *arr, *cnt;
		arr = new int[n];
		cnt = new int[n];
		for (int i = 0; i < n; ++i) {
			std::cin >> arr[i];
			++cnt[(fail + 1) / 2];
			if (i == 0) {
				arr[0] = 1;
			}
			else {
				if (arr[i] >= arr[i - 1] + 2) {
					arr[i] = arr[i - 1] + 2;
				}
				if (arr[i - 1] + 1 == arr[i]) {
					++fail;
				}
			}
		}
		for (int i = 0; i < n; ++i) {
			stack += cnt[i];
			ans *= stack--;
			ans %= mod;
		}
		std::cout << ans << std::endl;
		delete[] arr;
		delete[] cnt;
	}
	return EXIT_SUCCESS;
}

Measured memory_bytes: 896
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
int main(){
	string S,T;
	int poi;
	bool exist = false;
	cin>> S >> T;
	for (int i = 0; i < S.size(); i++){
		for (int j = 0; j < T.size() && i + j < S.size(); j++){
			if ( S[i + j] != T[j] && S[i + j] != '?') break;
			if (j == T.size() - 1){
				exist = true;
				poi = i;	
			}
		}
	}
	if (exist){
		for (int i = 0; i < S.size(); i++){
			if (i == poi){
				for (int j = 0; j <T.size(); j++){
					cout<<T[j];
				}
				i += T.size() - 1;
			}else{
				if (S[i] == '?') S[i] = 'a';
				cout<< S[i];
			}
		}
		cout<< endl;
	} else{
		cout<< "UNRESTORABLE" <<endl;
	}
	return 0;	
}



Measured memory_bytes: 256
from collections import defaultdict
import bisect
from sys import stdin
input = stdin.readline


def main():
  N = int(input())
  L = list(map(int, input().split()))

  # dic = defaultdict(int)
  # for l in L:
  #   dic[l] += 1
  # uniq = sorted(dic.keys())
  # sum_ = [0]*(uniq[-1]+1)
  # for i in range(1, uniq[-1]+1):
  #   sum_[i] = sum_[i-1] + dic[i]
  L = sorted(L)

  ans = 0
  for i in range(N):
    for j in range(i+1, N):
      if i == j:
        continue
      a = L[i]
      b = L[j]
      # lower = bisect.bisect_right(L[:i]+L[i+1:j]+L[j+1:], abs(a-b)) - 1
      # upper = bisect.bisect_right(L[:i]+L[i+1:j]+L[j+1:], a+b) - 1
      lower = bisect.bisect_right(L, abs(a-b), lo=j+1, hi=len(L)) - 1 - (j+1)
      upper = bisect.bisect_left(L, a+b, lo=j+1, hi=len(L)) - 1 - (j+1)
      # lower = bisect.bisect_right(L[j+1:], abs(a-b)) - 1
      # upper = bisect.bisect_left(L[j+1:], a+b) - 1

      # print(a, b, lower, upper)
      # print(f'--> {L[j+1:]}')

      # if lower < 0 or upper < 0: continue
      if upper < 0: continue
      ans += (upper - max(lower, 0) + 1)

  # print(dic)
  # print(uniq)
  # print(sum_)
  print(ans)


if(__name__ == '__main__'):
  main()


Measured memory_bytes: 69664
#include<iostream>
#include<algorithm>
#include<math.h>
#include<cstring>
#include<vector>

using namespace std;

#define long long long
#define ft(i, a, b) for (long i = (long)a ; i <= (long)b ; i++)
#define fd(i, a, b) for (long i = (long)a ; i >= (long)b ; i--)

const int mxN = 1e5 + 5;
const long oo = 1e15;
const long MOD = 1e9 + 7;
const int base = 311;

string s;

void Solve() {
    if (s == "ABC") cout << "ARC";
    else cout << "ABC";
}

void FastInput() {
    ios_base::sync_with_stdio(NULL);
    cin.tie(NULL);
    cout.tie(NULL);
    //freopen(".inp", "r", stdin);
    //freopen(".out", "w", stdout);
}

void Input() {
    cin >> s;
}

int main() {
    FastInput();
    Input();
    Solve();
}

Measured memory_bytes: 3688
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main()
{
  int x,i,j,t,res=1;
  cin >> x;
  t=(int)sqrt(x);
  for(i=t;i>1;i--){
    j=i;
    while(j*i<=x) j*=i;
    res=max(res,j);
  }
  cout << res << endl;
  return 0;
}

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

int main(){
    string A, B, C; cin >> A >> B >> C;
    bool flg = ((A[A.length()-1]==B[0]) && (B[B.length()-1]==C[0]));
    cout << (flg ? "YES" : "NO") << endl;
    return 0;
}


Measured memory_bytes: 256
N = int(input())

a = [int(input())-1 for i in range(N)]
owari = [0]*N

tmp = 0
count = 0

while owari[tmp] == 0 and tmp != 1:
    count += 1
    owari[tmp]=1
    tmp = a[tmp]

if tmp == 1:
    print(count)
else:
    print(-1)

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

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


int main()
{
    long long n,i,j;
    cin>>n;
    long long temp;
    //long long arr[n+5];
    long long freq[200005]={0};
    for(i=2;i<=n;i++)
    {
        cin>>temp;
        freq[temp]++;
    }
    for(i=1;i<=n;i++)
    {
        cout<<freq[i]<<endl;
    }
    

}

Measured memory_bytes: 5156
import sys
input = sys.stdin.readline

n=int(input())
L=list(map(int,input().split()))
L.sort()
hb = L[-1]
dp = [-1 for i in range(hb+1)] 
for i in L:
    if dp[i]!=0:
        if dp[i]==1:
            dp[i]=0
            continue
        dp[i]=1
        for j in range(2*i,hb+1,i):
            dp[j]=0
ans=0
for i in L:
    if dp[i]==1:
        ans+=1
print(ans)




Measured memory_bytes: 194440
import sys

stdin = sys.stdin
inf = 1 << 60
mod = 1000000007

sys.setrecursionlimit(10 ** 7)

ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

n, m = na()

if n == 1:
    print(m)
    exit()

i = 1
ans = 1
while i * i <= m:
    if m % i == 0:
        if m // i >= n:
            ans = max(ans, i)
        if i >= n:
            ans = max(ans, m // i)
    i += 1

print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define rep(i,a,b) for(register int i=a;i<=b;++i)
#define rpd(i,a,b) for(register int i=a;i>=b;--i)
#define rep1(i,x) for(register int i=head[x];i;i=nxt[i])
typedef long long ll;
//const int N=+5;
using namespace std;
inline int read(){
    int x=0,f=1;char ch=getchar();
    while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
    while(isdigit(ch)){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
ll n,x,ans;
void gcd(ll a,ll b){
	if(b>a)swap(a,b);
	ll shang=a/b,yu=a%b;
	if(yu==0){ans+=b*(shang*2LL-1LL);return;}
	ans+=b*shang*2LL;gcd(b,yu);
}
int main(){
	cin>>n>>x;ans=n;
	gcd(n-x,x);
	printf("%lld\n",ans);
	return 0;
}

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

int main(){
    int N;
    cin >> N;
    vector<int64_t> A(N);
    for (int i = 0; i < N; i++){
        int x;
        cin >> x;
        A.at(i) = x - i - 1;
    }
    sort(A.begin(), A.end());
    
    int64_t b = A.at(N / 2);
    int64_t ans = 0;
    for (int i = 0; i < N; i++){
        ans += abs(b - A.at(i));
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
import string
s = input()
lower = list(string.ascii_lowercase)

if len(s) < 26:
    for c in s: lower.remove(c)
    print(s + lower[0])
else:
    for i in range(24, -1, -1):
        if list(s[i:]) != sorted(s[i:])[::-1]:
            ans = s[:i]
            for j in range(1, 25):
                last = lower[lower.index(s[i])+j]
                if not last in ans:
                    ans += last
                    break
            print(ans)
            break
    else: print(-1)


Measured memory_bytes: 3828
#include "bits/stdc++.h"
using namespace std;

//諸機能
#pragma region MACRO 
#define putans(x) cerr << "answer: " ; cout << (x) << endl
#define dputans(x) cerr << "answer: "; cout << setprecision(10) << (double)(x) << endl
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define RREP(i,a,n) for(int i=(int)(n); i>= a; i--)
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) RREP(i,0,n)
#define all(a) begin((a)),end((a))
#define mp make_pair
#define exist(container, n) ((container).find((n)) != (container).end())
#define substr(s,i,l) string((s), (i), (l))
#define tos(x) (to_string((x)))
#ifdef _DEBUG //ファイルからテストデータを読み込む
	std::ifstream ifs("data.txt");
	#define input ifs >>
#else 
	#define input cin >>
#endif
#pragma endregion
//デバッグなどの支援
#pragma region CODING_SUPPORT
#define dbg(var0) { std::cerr << ( #var0 ) << "=" << ( var0 ) << endl; }
#define dbg2(var0, var1) { std::cerr << ( #var0 ) << "=" << ( var0 ) << ", "; dbg(var1); }
#define dbg3(var0, var1, var2) { std::cerr << ( #var0 ) << "=" << ( var0 ) << ", "; dbg2(var1, var2); }
#define dbgArray(a,n) {std::cerr << (#a) << "=";  rep(i,n){std::cerr <<(a[i])<<",";} cerr<<endl;} 
#ifndef _DEBUG
#define dbg1 {}
#define dbg2 {}
#define dbg3 {}
#define dbgArray {}
#endif 
#pragma endregion 
//typedef（書き換える、書き足す可能性ある）
#pragma region TYPE_DEF
typedef long long ll; 
typedef pair<int,int> pii; typedef pair<string,string> pss;typedef pair<int,string>pis;typedef pair<string,int>psi;
typedef vector<string> vs; typedef vector<int> vi;
#pragma endregion
//諸々の定数(書き換える可能性ある)
#pragma region CONST_VAL
#define PI (2*acos(0.0))
#define EPS (1e-9)
#define MOD (int)(1e9 + 7)
#define INF (1e9)
#pragma endregion


int main()
{
	int n, l; input n >> l;
	vs s;
	rep(i, n) {
		string si; input si;
		s.push_back(si);
	}
	sort(all(s));
	rep(i, n) {
		cout << s[i];
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
using std::cin;
using std::cout;

int N, M;
bool* likeFlag;
bool* musk;

int main()
	{
	cin >> N >> M;
	likeFlag = new bool[M];
	musk     = new bool[M];
	for (int i = 0; i < M; i++) 
		{
		likeFlag[ i ] = true;
		}
	for (int i = 0; i < N; ++i) 
		{
		int K;
		cin >> K;
		for (int j = 0; j < M; ++j) 
			{
			musk[ j ] = false;
			}
		for (int j = 0; j < K; ++j) 
			{
			int tmp;
			cin >> tmp;
			musk[ tmp - 1 ] = true;
			}
		for (int j = 0; j < M; ++j) 
			{
			likeFlag[ j ] &= musk[ j ];
			}
		}
	int ans = 0;
	for (int i = 0; i < M; ++i) {
		if (likeFlag[ i ])++ans;
		}
	cout << ans << '\n';
	delete[] likeFlag;
	delete[] musk;
	return 0;
	}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>

using namespace std;

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

	vector<int> p(n + 1, -1);
	for (int i = 1; i <= n; i++) {
		cin >> p[i];
	}

	int ans = 0;
	for (int i = 1; i < n; i++) {
		if (p[i] == i && p[i + 1] == i + 1) {
			swap(p[i], p[i+1]);
			ans++;
		}
	}
	for (int i = 1; i <= n; i++) {
		if (p[i] == i) {
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 640
#include<stdio.h>
#define N 100000
void binarySearch(int);
int count,n,A[N];
int main(){
  int q,i,r;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  scanf("%d",&q);
  count = 0;
  for(i=0;i<q;i++){
    scanf("%d",&r);
    binarySearch(r);
  }
  printf("%d\n",count);
  return 0;
}
void binarySearch(int r){
  int i,left,mid,right;
  left = 0;
  right = n;
  while( left < right ){
    mid = (left + right) / 2;
    if( A[mid] == r ){
      count++;
      return;
    }
    else if( r < A[mid] ){
      right = mid;
    }
    else {
      left = mid + 1;
    }
  }
  return ;
}

Measured memory_bytes: 988
#include<bits/stdc++.h>
using namespace std;
int main(){
  int A,B;
  cin>>A>>B;
  vector<int> ans={1,2,3};
  for(int i=0;i<3;i++){
    if(ans[i]!=A&&ans[i]!=B)cout<<ans[i]<<endl;
  }
}

Measured memory_bytes: 256
# coding: utf-8
# Your code here!

N, M = map(int, input().split())

V = {i for i in range(1, M+1)}

for i in range(N) : 
    A = [int(i) for i in input().split()][1:]
    S = set(A)
    V = V & S

print(len(V))

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <numeric>
#include <queue>
#include <sstream>
#include <unordered_map>
#include <cstring>
#include <iomanip>

using namespace std;

typedef long long ll;

const ll INF=1e9+7;

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

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

int main(){
    string S;
    double sum;
    int N;
    double a;
    cin>>N;
    for(int i=0;i<N;i++){
        cin>>a>>S;
        if(S=="BTC"){
            sum+=a*380000;
        }else{
            sum+=a;
        }
    }
    cout<<setprecision(20)<<sum<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

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

  public void run() {

    try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      int n = Integer.parseInt(br.readLine());
      Graph graph = new Graph(n);
      int[] ajacent;
      String[] vInfo;
      int id,degree;

      for(int i=0,v=0; i<n; i++) {
        vInfo  = br.readLine().split(" ");
        id     = Integer.parseInt(vInfo[0]);
        degree = Integer.parseInt(vInfo[1]);
        ajacent = new int[degree];
        for(int j=0; j<degree; j++) {
          ajacent[j] = graph.convIdToIndex( Integer.parseInt(vInfo[j+2]) );
        }
        graph.setVertex(id, ajacent);
      }

      graph.vertexSearch();

      graph.dispReport();
    }
    catch (IOException e) {
      System.err.println(e);
    }
  }

  class Graph {

    Vertex[] vertices;
    int time;

    public Graph(int size ) {
      vertices  = new Vertex[size];
      time = 0;
    }

    public void setVertex(int id) {
      vertices[convIdToIndex(id)] = new Vertex(id);
    }
    public void setVertex(int id, int[] ajacent) {
      setVertex(id);
      setAjacent(id, ajacent);
    }
    public void setAjacent(int id, int[] ajacent) {
      vertices[convIdToIndex(id)].ajacent = ajacent;
    }
    public void vertexSearch() {
      for (Vertex v : vertices) {
        if(v.state == Vertex.WHITE)
          depthFirstSearch(v.index);
      }
    }
    public void dispReport() {
      StringBuilder buf = new StringBuilder();

      for (Vertex v : vertices) {
          buf.append(v.id).append(" ")
             .append(v.findTime).append(" ")
             .append(v.doneTime).append("\n");
      }

      System.out.print(buf);
    }
    public int convIdToIndex(int id) {
      return id-1;
    }

    private void depthFirstSearch(int index) {
      vertices[index].state = Vertex.GRAY;
      vertices[index].findTime = ++time;
      
      for(int ajcIndex: vertices[index].ajacent) {
        if(vertices[ajcIndex].state == Vertex.WHITE)
          depthFirstSearch(ajcIndex);
      }
      vertices[index].state = Vertex.BLACK;
      vertices[index].doneTime = ++time;
    }

    class Vertex {

      static final int WHITE = 0;
      static final int GRAY  = 1;
      static final int BLACK = 2;
      int id;
      int index;
      int state;
      int[] ajacent;
      int findTime;
      int doneTime;

      public Vertex(int id) {
        this.id = id;
        index = id-1;
        state = WHITE;
      }
    }
  }
}


Measured memory_bytes: 24200
#include <iostream>
using namespace std;
#define INF (long)1e6
long dp[10][10];
int main() {
	int n ;
	while(1){
		cin >> n ; if(!n) break;
		for(int i=0;i<10;i++) for(int j=0;j<10;j++) dp[i][j]=INF;
		for(int i=0;i<10;i++) dp[i][i]=0;
		int V=0;
		for(int i=0;i<n;i++){
			int a,b,c; cin >> a >> b >> c ;
			V=max(V,max(a,b));
			dp[a][b]=dp[b][a]=c;
		}
		for(int k=0;k<=V;k++) for(int i=0;i<=V;i++) for(int j=0;j<=V;j++)
			dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j]);
		long NUM=0, MIN=INF;
		for(int i=0;i<=V;i++){
			int sum=0;
			for(int j=0;j<=V;j++) sum+=dp[i][j];
			if(sum<MIN) MIN=sum,NUM=i;
		}
		cout << NUM << ' ' << MIN << '\n' ;
	}
}

Measured memory_bytes: 1156
#include <bits/stdc++.h>
using namespace std;
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	long int counter;
	long int count=0;
	cin>>counter;
	long int a;
	set<long int> sez;
	for (int i = 0; i < counter; ++i)
	{
		cin>>a;
		if(sez.count(a)==1){
			sez.erase(a);
			count--;
		}
		else{

			sez.insert(a);
			count++;
		}
	}
	cout<<count<<endl;

	return 0;
}

Measured memory_bytes: 4992