akhauriyash/Code-Regression huggingface dataset:
n=int(input())
ki=[[] for _ in range(n)]
ans=0
for i in range(1,n+1):
    ans+=i*(n-i+1)

for _ in range(n-1):
    u,v=map(int,input().split())
    if u>v:u,v=v,u
    ans-=u*(n-v+1)
print(ans)

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    ll N; cin >> N;
    vector<ll> A(N);
    rep(i, N){cin >> A.at(i);}
    ll dp[N+1][2];
    // i番目，jはこの桁(と前の桁)で反転を入れるかの有無
    dp[0][0] = 0;
    dp[0][1] = -INF; // dp[0][1]は絶対に使われない
    rep(i, N){
        dp[i+1][0] = max(dp[i][0] + A.at(i), dp[i][1] - A.at(i));
        dp[i+1][1] = max(dp[i][0] - A.at(i), dp[i][1] + A.at(i));
    }
    cout << dp[N][0] << endl;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 2560
N, M, C = map(int, input().split())
B = [int(i) for i in input().split()]

ans = 0
for i in range(N):
    A = [int(i) for i in input().split()]
    tmp = C
    for j in range(M):
        tmp += A[j] * B[j]
    if tmp > 0:
        ans += 1
        
print(ans)

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

using ll=long long;

using vi=vector<int>;
using vll=vector<ll>;
using vvi=vector<vi>;
using vs=vector<string>;

int main() {
  ll N; cin >>N;
  ll cnt=1;
  ll ans=0;
  bool flag=true;
  while (N>=10) {
    if (N%10!=9) {
      flag=false;
    }
    N/=10;
    cnt++;
  }
  if (flag) {
    ans=N+9*(cnt-1);
  } else {
    ans=N+9*(cnt-1)-1;
  }
  cout <<ans <<endl;
  return 0;
}


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

#define ll long long
#define ull unsigned long long
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(a,b) for(int a=0;a<(b);++a)
#define REP1(i,n) for(int i=1;i<=(n);++i)
#define debug(x) cerr<<#x<<": "<<x<<'\n'
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
#define INF (1<<29)
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

template<class T=int>
T in(){T x;cin>>x;return (x);}
template<class T>
void print(T& x){cout<<x<<'\n';}

const int MOD =(int)1e9+7;
const int MAX =510000;
ll fac[MAX],finv[MAX],inv[MAX];
void COMint(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<MAX;i++){
        fac[i]=fac[i-1]*i%MOD;
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}
ll COM(int n,int k){
    if(n<k) return 0;
    if(n<0||k<0)return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}
ll gcd(ll a,ll b){
    if(b==0)return a;
    if(a>b){
        swap(a,b);
    }
    return gcd(a,b%a);
}
ll lcm(ll a,ll b){
    ll g;g=gcd(a,b);
    return a*b/g;
}
bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

bool compare_by_a(pair<int, int> a, pair<int, int> b) {
    if(a.first != b.first){
        return a.first < b.first;
    }else{
        return a.second < b.second;
    }
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N,A,B;
    cin>>N>>A>>B;
    string s=in<string>();
    char c;
    int cnt_b=0;
    int cnt_all=0;
    REP(i,N){
        c=s[i];
        if(c=='a'){
            if(cnt_all<A+B){
                print("Yes");
                cnt_all++;
            }else{
                print("No");
            }
        }else if(c=='b'){
            if(cnt_all<A+B&&cnt_b<B){
                print("Yes");
                cnt_all++;
                cnt_b++;
            }else{
                print("No");
            }
        }else{
            print("No");
        }
    }
    return 0;
}


Measured memory_bytes: 848
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>

using namespace std;

#define sz			size()
#define lgt			length()
#define rep(i,n)	for (int i = 0; i < n; i++)
#define ALL(X)		(X).begin(),(X).end()
#define RALL(X)		(X).rbegin(),(X).rend()
#define pb			push_back
#define SORT(a)		sort(ALL(a));
#define RSORT(a)	sort(RALL(a));
#define mp			make_pair
#define dump(x)		cerr<<#x<<" = "<<(x)<<endl;
#define fir			first
#define sec			second

typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<string> vs;

int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
vs form(string a,char s){vs v;string b;rep(i,a.lgt){if(a[i]==s){v.pb(b);b="";}else b+=a[i];}v.pb(b);return v;}
vi formint(string a,char s){vi v;string b;rep(i,a.lgt){if(a[i]==s){v.pb(toInt(b));b="";}else b+=a[i];}v.pb(toInt(b));return v;}

const double EPS=1e-10,PI=acos(-1.0);
const int INF=2100000000;

int data[100][100];
int tmp[100][100];
int n, m, res;

void func(int x, int y, int cnt)
{
//	cout << x << " " << y << " " << cnt << endl;
	data[x][y] = 0;
	if (data[x + 1][y] == 1) func(x + 1, y, cnt + 1);
	if (data[x - 1][y] == 1) func(x - 1, y, cnt + 1);
	if (data[x][y + 1] == 1) func(x, y + 1, cnt + 1);
	if (data[x][y - 1] == 1) func(x, y - 1, cnt + 1);
	res = max(res, cnt);
	data[x][y] = 1;
	return;
}

int main(void)
{
	while (cin >> n >> m, n && m){
		for (int i = 0; i < 100; i++){
			for (int j = 0; j < 100; j++){
				data[i][j] = 0;
			}
		}
		for (int i = 1; i <= m; i++){
			for (int j = 1; j <= n; j++){
				cin >> data[i][j];
			}
		}
		res = 0;
		for (int i = 1; i <= m; i++){
			for (int j = 1; j <= n; j++){
				if (data[i][j] == 1){
//					cout << "find" << endl;
					func(i, j, 1);
				}
			}
		}
		cout << res << endl;
	}
	
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int dp[50000000];
int main(){
    int n;
    cin >> n;
    int a[n];
    for(int i = 1; i < n;i++){
        cin >> a[i];
        dp[a[i]]++;
    }

    for(int i = 1; i <= n; i++){
        cout << dp[i] << endl;
    }


}

Measured memory_bytes: 5128
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>

#define REP(n) for(int i = 0;i < n;i++)
#define LLREP(n) for(long long int  i = 0;i < n;i++)
typedef long long int ll;
using namespace std;
#define MAX_A 1000000007

int main(){

    int n;
    cin >> n;

    if(n<1200){
        cout << "ABC" << endl;
    }else{
        cout << "ARC" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main () {

    long n = 0;
    long a[5];
    long c[6] = {0};
    cin >> n;
    long mincost = __LONG_MAX__;
    for (int i = 0; i < 5; ++i) {
        cin >> a[i];
        c[i+1] = 0;
        if (mincost > a[i] ) {
            mincost = a[i];
        }
    }

    long time = 0;
#if 1
    time = n / mincost;
    time += (n % mincost == 0) ? 4 : 5;
#else
    c[0] = n;
    while ( c[5] != n ) {
        for ( int i = 4; i >= 0; --i ) {
            int move = min(a[i], c[i]);
            c[i+1] += move;
            c[i] -= move;
        }
        time += 1;
        cout << time << endl;
        for (int i = 0; i < 6; ++i) {
            cout << c[i] << " ";
        }
        cout << endl;
    }

#endif
    cout << time << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
string t[10]={"","',.!?","abcABC","defDEF","ghiGHI","jklJKL","mnoMNO","pqrsPQRS","tuvTUV","wxyzWXYZ"};
int main() {
  string s;
  while(cin >> s) {
    string ans="";
    s+='0';
    int x=s[0]-'0',y=-1;
    for(int i=0; i<s.size(); i++) {
      int z=s[i]-'0';
      if(x!=z) {
        if(!x) for(int j=0; j<y; j++) ans+=" ";
        else ans+=t[x][y%t[x].size()];
        x=z;
        y=0;
      } else y++;
    }
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 1192
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
B.append(0)
count = 0
for i in range(N + 1):
    if i > 0:
        if A[i] < B[i] + B[i - 1]:
            a = A[i] - B[i - 1]
            count += A[i]
            if a > 0:
                B[i] -= a
        else:
            count += B[i] + B[i - 1]
            B[i] = 0
    else:
        if A[i] < B[i]:
            count += A[i]
            B[i] -= A[i]
        else:
            count += B[i]
            B[i] = 0

print(count)


Measured memory_bytes: 82020
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define int long long
#define fi first
#define se second
using namespace std;
typedef pair<int, int> P;

signed main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, 0, n) cin >> a[i];
    sort(all(a));
    int ans = 0;
    vector<int> sum(n);
    sum[0] = a[0];
    rep(i, 1, n){
        sum[i] = sum[i - 1] + a[i];
    }
    repb(i, n - 2, 0){
        if(2 * sum[i] >= a[i + 1]){
            ans++;
            // o(a[i]);
        }else{
            break;
        }
    }
    o(ans + 1);
}

Measured memory_bytes: 1792
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {

    private static List<Long> divisor(long n) {
        List<Long> list = new ArrayList<>();
        for (long i = 1; i * i <= n; i++) {
            if (n % i == 0) {
                list.add(i);
                long j = n / i;
                if (j != i) {
                    list.add(j);
                }
            }
        }
        Collections.sort(list);
        return list;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long m = sc.nextLong();
        List<Long> div = divisor(m);
        long ans = 1;
        for (int i = 0; i < div.size(); i++) {
            long d = div.get(i);
            if (d * n <= m) {
                ans = Math.max(ans, d);
            }
        }
        System.out.println(ans);
    }

}


Measured memory_bytes: 23124
#define LOCAL
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rrep(i, n) for(int i=(n-1); i>=0; --i)
#define rep2(i, s, n) for(int i=s; i<(n); ++i)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
static const int INTINF = (INT_MAX >> 1); // 10^9 + 10^7
static const ll LLINF = (LLONG_MAX >> 1);
static const int MAX = 1e5+1;
static const ll MOD = 1e9+7;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
string to_string(string s) { return '"' + s + '"'; }
string to_string(bool b) { return b ? "true" : "false"; }
template <size_t N> string to_string(bitset<N> bs) {
  string res;
  for (size_t i = 0; i < N; ++i) res += '0' + bs[i];
  return res;
}
string to_string(vector<bool> v) {
  string res = "{";
  for (bool e : v) res += to_string(e) + ", ";
  return res += "}";
}
template <class T, class U> string to_string(pair<T, U> p);
template <class C> string to_string(C c) {
  string res = "{";
  for (auto e : c) res += to_string(e) + ", ";
  return res += "}";
}
template <class T, class U> string to_string(pair<T, U> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
void debug() { cerr << '\n'; }
template <class Head, class... Tail> void debug(Head head, Tail... tail) {
  cerr << '\t' << to_string(head), debug(tail...);
}
#ifdef LOCAL
#define DEBUG(...) cerr << "[" << #__VA_ARGS__ << "]:", debug(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

int main(int argc, const char * argv[]) {
  std::cout << std::fixed << std::setprecision(15);

  ll X, Y; cin >> X >> Y;
  ll ans = 0;
  while(1){
    if(Y < X) break;
    ans++;
    X = X * 2;
  }

  cout << ans << endl;
}  


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;

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

// Self settings
// clang-format off
#define MAX_N 100000
#define REP(i, N) for (int i = 0; i < (int)(N); ++i)
#define SLN(i,N) (i == N-1 ? "\n" : " ")
ll fact(ll n) { ll res = 1; for(ll i=2;i<=n;++i) res = res * i; return res;}
ll nCr(ll n, ll r) {return (fact(n)/fact(n-r)*fact(r)) ;}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
const ll MOD = 1e9+7;
const ll INF = 1LL << 60;
const int inf = 1 << 30;
// clang-format on
int N;

int cal(vector<int> vec) {
  int res = 0, cnt = 1;
  for (auto i = vec.rbegin(); i != vec.rend(); i++) {
    res += ((*i) * cnt);
    cnt *= 10;
  }
  return res;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> N;
  vector<int> P(N), Q(N);
  REP(i, N) cin >> P[i];
  REP(i, N) cin >> Q[i];

  int p = cal(P);
  int q = cal(Q);

  int a, b;
  vector<int> nums(N);
  REP(i, N) nums[i] = i + 1;
  int idx = 1;
  do {
    int n = cal(nums);
    if (p == n) {
      a = idx;
    }
    if (q == n) {
      b = idx;
    }
    idx++;
  } while (next_permutation(nums.begin(), nums.end()));

  cout << abs(a - b) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <random>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repp(i,n,m) for (int i = m; i < (n); ++i)
#define repl(i,n) for (long long i = 0; i < (n); ++i)
#define reppl(i,n,m) for (long long i = m; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PL = pair<long long, long long>;
using Pxy = pair<double, double>;
using T = tuple<int, int, bool>;
const int INF = 1001001007;
const int mod = 1000000007;
const int MOD = 998244353;
const ll inf = 1e18;
template <typename AT>
void printvec(vector<AT> &ar){
    rep(i,ar.size()-1) cout << ar[i] << " ";
    cout << ar[ar.size()-1] << endl;
}
template <typename Q>
void printvvec(vector<vector<Q>> &ar){
    rep(i,ar.size()){
        rep(j,ar[0].size()-1) cout << ar[i][j] << " ";
        cout << ar[i][ar[0].size()-1] << endl;
    }
}
template <typename S>
bool range(S a, S b, S x){
    return (a <= x && x < b);
}

void yes(){
    cout << "Yes" << endl;
}

void no (){
    cout << "No" << endl;
}

ll cel (ll a, ll b){
    if (a % b == 0) return a / b;
    else return a / b + 1;
}

ll gcds(ll a, ll b){
    ll c = a % b;
    while (c != 0){
        a = b;
        b = c;
        c = a % b;
    }
    return b;
}

int main() {
    string s, t; cin >> s >> t;
    int ans = 10000;
    int ns = s.size();
    int nt = t.size();
    rep(i,ns-nt+1){
        int ima = 0;
        rep(j,nt){
            if (s[i+j]!=t[j])ima++;
        }
        ans = min(ans,ima);
    }
    cout << ans << endl;
}


Measured memory_bytes: 3632
import sys

sys.setrecursionlimit(2 * 10**6)


def inpl():
    return list(map(int, input().split()))


def solve(mp, w, h):
    def dfs(ny, nx):
        if mp[ny][nx] == 0:
            flag[ny][nx] = -1
            return
        elif visit[ny * w + nx]:
            return
        visit[ny * w + nx] = True

        for dx in [-1, 0, 1]:
            for dy in [-1, 0, 1]:
                if dx == dy == 0:
                    continue
                elif mp[ny + dy][nx + dx] == 0:
                    continue
                flag[ny + dy][nx + dx] = min(flag[ny][nx], flag[ny + dy][nx + dx])
                dfs(ny + dy, nx + dx)

    mp = [[0] + m + [0] for m in mp]
    mp = [[0] * (w + 2)] + mp + [[0] * (w + 2)]
    flag = [[-1] + [i + j * w for i in range(w)] + [-1] for j in range(h)]
    flag = [[-1] * (w + 2)] + flag + [[-1] * (w + 2)]
    visit = [False] * (w + 2) * (h + 2)

    for ny in range(h):
        for nx in range(w):
            dfs(ny + 1, nx + 1)
    # print(flag)

    ret = []
    for f in flag:
        ret += [i for i in f if i != -1]
    return len(set(ret))


ans = []
while True:
    w, h = inpl()
    if w == h == 0:
        break
    tmp = [inpl() for i in range(h)]
    ans.append(solve(tmp, w, h))

for a in ans:
    print(a)



Measured memory_bytes: 8944
def main():
    n,m,k = map(int,input().split())
    friend = []
    block = []
    # Union-Find作る
    uf = UnionFind(n)
    #　iとすでに友達　iとブロックの数は最後に除外する
    exclude_i = [0] * n

    for _ in range(m):
        a,bb = map(int,input().split())
        # aとbを同じグループにする
        uf.union(a-1,bb-1)
        friend.append([a-1,bb-1])

    for _ in range(k):
        c,d = map(int,input().split())
        block.append([c-1,d-1])
        # CとDが友達候補（同じグループ）なら除外する　可哀想
        if uf.same(c-1,d-1):
            exclude_i[c-1] += 1
            exclude_i[d-1] += 1


    for i, f in enumerate(friend):
        # すでに友達ならそれは友達候補ではなく、もはや親友なんだよ（除外）
        if uf.same(f[0],f[1]):
            exclude_i[f[0]] += 1
            exclude_i[f[1]] += 1



    for i in range(n):
        # uf.sizeは自分を含んでるから、自分を除外する-1
        print(str(uf.size(i)-exclude_i[i]-1 ), end = " ")
    print("")

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


if __name__=='__main__':
    main()


Measured memory_bytes: 41844
#include<iostream>
#include<vector>
using namespace std;main(){int W,Q,d,w,i,t;char c;for(;cin>>W>>Q,W|Q;puts("END")){vector<int> b(W,-1);for(;Q-->0;){cin>>c;if(c-'w'){cin>>d>>w;for(i=t=0;i<W;i++){~b[i]?t=0:t++;if(t==w){for(i-=t-1;t-->0;)b[i+t]=d;t=-1;break;}}~t?puts("impossible"):printf("%d\n",i);}else{cin>>d;for(i=W;i-->0;)if(b[i]==d)b[i]=-1;}}}}

Measured memory_bytes: 0
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cstring>
#include <queue>
#include <vector>
#include <functional>
#include <map>
#include <set>
#include <cmath>
#include <string>
#define SIZE 200005
#define INF 1000000005LL

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;


int main()
{
	double n,m,d,ans;
	scanf("%lf%lf%lf",&n,&m,&d);
	ans = 2*(n-d)*(m-1)/(n*n);
	if(d==0)ans = (n-d)*(m-1)/(n*n);
	printf("%.11f\n",ans);
	return 0;
}


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

int main()
{
	int cnt[200005] = {};
	int N, K;

	cin >> N >> K;
	for ( int i = 0; i < N; i++ ) {
		int A;
		cin >> A; --A;
		cnt[A]++;
	}
	sort(cnt, cnt + N);
	int sum = 0;
	for ( int i = 0; i < N - K; i++ ) {
		sum += cnt[i];
	}

	cout << sum << endl;
	return ( 0 );
}


Measured memory_bytes: 1024
typedef long long ll;
#include <bits/stdc++.h>
using namespace std;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

ll h,w;
string s[50];
ll dis[50][50];



int main() {
    std::cin >> h>>w;
    ll s_count = 0;
    for (int i = 0; i < h; i++) {
        std::cin >> s[i];
        for (int j = 0; j < w; j++) {
            if(s[i][j] == '#'){
                s_count++;
            }
        }
    }
    vector<pair<ll,ll>> next;
    ll now  =1;
    Fill(dis,-1);
    dis[0][0] = now;
    
    if(s[0][1] == '.'){
        
        next.push_back(make_pair(0,1));
    }
    if(s[1][0] == '.'){
        next.push_back(make_pair(1,0));
    }
    
    while(!next.empty()){
        // std::cout << next[0].first <<" "<<next[0].second << std::endl;
        now += 1;
        vector<pair<ll,ll>> tmp_next;
        for (auto e : next) {
            if( dis[e.first][e.second] == -1 ||  dis[e.first][e.second] > now){
                dis[e.first][e.second] = now;
                if(e.first+1<h){
                    if(s[e.first+1][e.second] == '.'){
                        tmp_next.push_back(make_pair(e.first+1,e.second));
                    }
                }
                if(e.first-1>=0){
                    if(s[e.first-1][e.second] == '.'){
                        tmp_next.push_back(make_pair(e.first-1,e.second));
                    }
                }
                if(e.second+1<w){
                    if(s[e.first][e.second+1] == '.'){
                        tmp_next.push_back(make_pair(e.first,e.second+1));
                    }
                }
                if(e.second-1>=0){
                    if(s[e.first][e.second-1] == '.'){
                        tmp_next.push_back(make_pair(e.first,e.second-1));
                    }
                }
            }
        }
        next = {};
        for (auto ee : tmp_next) {
            next.push_back(ee);
        }
    }
    if(dis[h-1][w-1] == -1){
        std::cout << -1 << std::endl;
    }else{
        std::cout << h*w - s_count - dis[h-1][w-1] << std::endl;
    }
    
    
    
}

Measured memory_bytes: 256
#!/usr/bin/env python3

import sys

sys.setrecursionlimit(10**6)
input = sys.stdin.buffer.readline
INF = 10 ** 9 + 1  # sys.maxsize # float("inf")


def debug(*x):
    print(*x)


def solve(N, AS):
    from collections import Counter
    count = Counter(AS)
    expect = [[[-1] * (N + 1) for i in range(N + 1)] for j in range(N + 1)]
    expect[0][0][0] = 0

    def f(a, b, c):
        p = N
        if a > 0:
            v = expect[a - 1][b][c]
            if v == -1:
                v = f(a - 1, b, c)
            p += v * a
        if b > 0:
            v = expect[a + 1][b - 1][c]
            if v == -1:
                v = f(a + 1, b - 1, c)
            p += v * b
        if c > 0:
            v = expect[a][b + 1][c - 1]
            if v == -1:
                v = f(a, b + 1, c - 1)
            p += v * c
        p /= (a + b + c)

        # debug("f: a,b,c,p", a, b, c, p)
        expect[a][b][c] = p
        return p

    return f(count[1], count[2], count[3])


def main():
    N = int(input())
    AS = list(map(int, input().split()))
    print(solve(N, AS))


T1 = """
3
1 1 1
"""


def test_T1():
    """
    >>> as_input(T1)
    >>> main()
    5.5
    """


T2 = """
1
3
"""


def test_T2():
    """
    >>> as_input(T2)
    >>> main()
    3.0
    """


T3 = """
2
1 2
"""


def test_T3():
    """
    >>> as_input(T3)
    >>> main()
    4.5
    """


# T4 = """
# 10
# 1 3 2 3 3 2 3 2 1 3
# """


# def test_T4():
#     """
#     >>> as_input(T4)
#     >>> N = int(input())
#     >>> AS = list(map(int, input().split()))
#     >>> abs(solve(N, AS) - 54.48064457488221)  < 10 ** -9
#     """


def _test():
    import doctest
    doctest.testmod()


def as_input(s):
    "use in test, use given string as input file"
    import io
    global read, input
    f = io.StringIO(s.strip())
    input = f.readline
    read = f.read


USE_NUMBA = False
if (USE_NUMBA and sys.argv[-1] == 'ONLINE_JUDGE') or sys.argv[-1] == '-c':
    print("compiling")
    from numba.pycc import CC
    cc = CC('my_module')
    cc.export('solve', solve.__doc__.strip().split()[0])(solve)
    cc.compile()
    exit()
else:
    input = sys.stdin.buffer.readline
    read = sys.stdin.buffer.read

    if (USE_NUMBA and sys.argv[-1] != '-p') or sys.argv[-1] == "--numba":
        # -p: pure python mode
        # if not -p, import compiled module
        from my_module import solve  # pylint: disable=all
    elif sys.argv[-1] == "-t":
        _test()
        sys.exit()
    elif sys.argv[-1] != '-p' and len(sys.argv) == 2:
        # input given as file
        input_as_file = open(sys.argv[1])
        input = input_as_file.buffer.readline
        read = input_as_file.buffer.read

    main()


Measured memory_bytes: 383980
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		
		long sumStep = 0;
		int maxA = sc.nextInt();
		for (int i = 1; i < n; i++) {
			int a = sc.nextInt();
			maxA = Math.max(maxA, a);
			sumStep += maxA - a;
		}
		
		System.out.println(sumStep);
		
		sc.close();
	}
}




Measured memory_bytes: 48828
#include<iostream>                                         
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#include<string>
using namespace std;

struct Node{
    int key;
    Node *next,*prev;
};

Node *nil;

Node* listSearch(int key){
    Node *cur=nil->next;
    while(cur!=nil&&cur->key!=key)
        cur=cur->next;
    return cur;
}

void init(){
    nil=(Node *)malloc(sizeof(Node));
    nil->next=nil;
    nil->prev=nil;
}

void printList(){
    Node *cur=nil->next;
    int isf=0;
    while(1){
        if(cur==nil)break;
        if(isf++>0)putchar(' ');
        printf("%d",cur->key);
        cur=cur->next;
    }
    printf("\n");
}

void deleteNode(Node *t){
    if(t==nil)return;
    t->next->prev=t->prev;
    t->prev->next=t->next;
    free(t);
}
void deleteFirst(){
    deleteNode(nil->next);
}

void deleteLast(){
    deleteNode(nil->prev);
}
void deleteKey(int key){
    deleteNode(listSearch(key));
}

void insert(int key){
    Node *x=(Node *)malloc(sizeof(Node));
    x->key=key;
    x->next=nil->next;
    nil->next->prev=x;
    nil->next=x;
    x->prev=nil;

}

int main(){
    int key,n,i;

    char com[20];
    scanf("%d",&n);
    init();
    for(i=0;i<n;i++){
        scanf("%s%d",com,&key);
        if(com[0]=='i')
            insert(key);
        else if(com[0]=='d'){    
            if(strlen(com)>6){
                if(com[6]=='F')deleteFirst();
                else if(com[6]=='L')deleteLast();
            }else
                deleteKey(key);
        }  
    }
    printList();
    return 0;
}



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

using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define FORR(i, a, b) for(int i = (a); i > (b); --i)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define VECCIN(x)                                                              \
    for(auto &youso_ : (x)) cin >> youso_
#define mp make_pair
#define bitcnt __builtin_popcount
#define All(a) (a).begin(), (a).end()
template <typename T = long long> inline T IN() {
    T x;
    cin >> x;
    return (x);
}
inline void CIN() {}
template <class Head, class... Tail>
inline void CIN(Head &&head, Tail &&... tail) {
    cin >> head;
    CIN(move(tail)...);
}
#define CINT(...)                                                              \
    int __VA_ARGS__;                                                           \
    CIN(__VA_ARGS__)
#define LCIN(...)                                                              \
    ll __VA_ARGS__;                                                            \
    CIN(__VA_ARGS__)
#define SCIN(...)                                                              \
    string __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define Yes(a) cout << (a ? "Yes" : "No") << "\n"
#define YES(a) cout << (a ? "YES" : "NO") << "\n"

typedef long long ll;
typedef unsigned long long ul;
typedef vector<int> V;
typedef vector<ll> VL;
typedef pair<int, int> Pair;
typedef pair<ll, ll> PL;
typedef priority_queue<int> PQ;
typedef priority_queue<int, V, greater<int>> PQG;

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

ll K;
VL A;

bool judge1(ll n) {
    REP(i, K) { n -= n % A[i]; }
    return n >= 2;
}

bool judge2(ll n) {
    REP(i, K) { n -= n % A[i]; }
    return n <= 2;
}

int main() {
    cin >> K;
    A.resize(K);
    VECCIN(A);
    ll lb = 1, ub = 2 + K * (*max_element(All(A)));
    while(ub - lb > 1) {
        ll mid = (lb + ub) / 2;
        if(judge1(mid)) {
            ub = mid;
        } else {
            lb = mid;
        }
    }
    ll m = ub;
    lb = 2, ub = 2 + K * (*max_element(All(A))) + 1;
    while(ub - lb > 1) {
        ll mid = (lb + ub) / 2;
        if(judge2(mid)) {
            lb = mid;
        } else {
            ub = mid;
        }
    }
    ll M = lb;
    if(M < m)
        cout << -1 << "\n";
    else
        cout << m << " " << M << "\n";
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mkp make_pair
#define f(i,l,h) for(ll i=l;i<h;i++)
#define fr(i,h,l) for(ll i=h;i>=l;i--)

using namespace std;

typedef pair<ll,ll> pll;
const ll INF=(ll)(1e9+7);
typedef vector<ll> vll;

int main()
{
    //cout << "Hello world!" << endl;
    string s,t;
    cin>>s>>t;
    t.erase(t.end()-1);
    if(t.length()>0 && t.length()<=10 && t==s){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <vector>
#include <map>

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

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

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

  std::map<char, int> m;
  rep(i, w.size()) {
    m[w[i]]++;
  }

  for (const auto& e : m) {
    if (e.second % 2 != 0) {
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;

  return 0;
}


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

int main() {
    
    int K;
    string S;
    cin >> K >> S;
    int len = S.size();
    
    if(len <= K){
        cout << S <<endl;
    }
    else{
        for(int i=0;i<K;i++){
            cout << S[i];
        }
        cout << "..." <<endl;
    }
}

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

struct union_find{
    vector<int> par;
    vector<int> rank;
    
    union_find(int N) : par(N), rank(N){
        rep(i,N){
            par[i] = i;
            rank[i] = 0;
        }
    }
    
    int root(int x){
        if (par[x] == x){
            return x;
        }
        return par[x] = root(par[x]);
    }
    
    void unite(int x, int y){
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return;
        if (rank[rx] < rank[ry]){
            par[rx] = ry;
        }
        else{
            par[ry] = rx;
            if (rank[rx] == rank[ry]) rank[rx]++;
        }
    }
    
    bool same(int x, int y){
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};


void bfs(vector<vector<int> > &connection, vector<int> &vec, vector<int> &isVisited,  queue<int> que, queue<int> subque, int num){
    que.push(num);
    subque.push(num);
    isVisited[num] = 1;
    while(que.size() != 0){
        int q = que.front();
        rep(i,connection[q].size()){
            if (isVisited[connection[q][i]] == 0){
                que.push(connection[q][i]);
                subque.push(connection[q][i]);
                isVisited[connection[q][i]] = 1;
            }
        }
        que.pop();
    }
    int len = subque.size();
    rep(i,len){
        vec[subque.front()] = len;
        subque.pop();
    }
}

int main(){
    int N,M,K;
    cin >> N >> M >> K;
    vector<pair<int,int> > ff(M);
    vector<pair<int,int> > block(K);
    rep(i,M){
        cin >> ff[i].first >> ff[i].second;
        ff[i].first--;
        ff[i].second--;
    }
    rep(i,K){
        cin >> block[i].first >> block[i].second;
        block[i].first--;
        block[i].second--;
    }
    vector<vector<int> > connection(N,vector<int>(0));
    rep(i,M){
        connection[ff[i].first].push_back(ff[i].second);
        connection[ff[i].second].push_back(ff[i].first);
    }
    /*vector<vector<int> > blockconnection(N,vector<int>(0));
    rep(i,K){
        blockconnection[block[i].first].push_back(block[i].second);
        blockconnection[block[i].second].push_back(block[i].first);
    }*/
    vector<int> vec(N,0);
    vector<int> isVisited(N,0);
    queue<int> que;
    queue<int> subque;
    rep(i,N){
        if (vec[i] == 0){
            bfs(connection, vec, isVisited, que, subque, i);
        }
    }
    
    union_find tree(N);
    rep(i,M){
        tree.unite(ff[i].first, ff[i].second);
    }
    rep(i,K){
        if (tree.same(block[i].first, block[i].second)){
            vec[block[i].first]--;
            vec[block[i].second]--;
        }
    }
    rep(i,N){
        cout << vec[i] - connection[i].size() - 1 << " ";
    }
    cout << endl;
}

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

#define REP(i,m,n) for(int i=(m); i<(int)(n); i++)
#define RREP(i,m,n) for(int i=(int)(n-1); i>=m; i--)
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) RREP(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aut(r,v) __typeof(v) r = (v)
#define each(it,o) for(aut(it,(o).begin()); it!=(o).end(); ++it)
#define reach(it,o) for(aut(it,(o).rbegin()); it!=(o).rend(); ++it)
#define fi first
#define se second
#define debug(...) {cerr<<"[L"<<__LINE__<<"] "; _debug(__VA_ARGS__);}

template<typename T1, typename T2> ostream& operator<<(ostream& o, const pair<T1, T2>& p)
{return o<<"("<<p.first<<", "<<p.second<<")";}
template<typename T>string join(const vector<T>&v, string del=", ")
{stringstream s;rep(i,v.size())s<<del<<v[i];return s.str().substr(del.size());}
template<typename T>ostream& operator<<(ostream& o, const vector<T>&v)
{if(v.size())o<<"["<<join(v)<<"]";return o;}
template<typename T>ostream& operator<<(ostream& o, const vector<vector<T> >&vv)
{int l=vv.size();if(l){o<<endl;rep(i,l){o<<(i==0?"[ ":",\n  ")<<vv[i]<<(i==l-1?" ]":"");}}return o;}
template<typename T>ostream& operator<<(ostream& o, const set<T>& st)
{vector<T> v(st.begin(),st.end());o<<"{ "<<join(v)<<" }";return o;}
template<typename T1, typename T2>ostream& operator<<(ostream& o, const map<T1, T2>& m)
{each(p,m){o<<(p==m.begin()?"{ ":",\n  ")<<*p<<(p==--m.end()?" }":"");}return o;}
inline void _debug(){cerr<<endl;}
template<class First, class... Rest>
void _debug(const First& first, const Rest&... rest){cerr<<first<<" ";_debug(rest...);}

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

const double PI = (1*acos(0.0));
const double EPS = 1e-9;
const ll INF = 0x3f3f3f3f;
const ll INFL = 0x3f3f3f3f3f3f3f3fLL;
const ll mod = 1e9 + 7;

inline void finput(string filename) {
    freopen(filename.c_str(), "r", stdin);
}

int main(){
    ios_base::sync_with_stdio(0);
    // finput("./input");
    int n; cin >> n;
    vl a(n);
    rep(i,n) cin >> a[i];
    map<ll,ll> mp;
    rep(i,n){
        if(mp.count(a[i])) mp[a[i]]++;
        else mp[a[i]] = 1;
    }

    ll tmp = 0;
    for(auto x : mp) tmp += x.se*(x.se-1) / 2;
    rep(i,n){
        ll v = mp[a[i]];
        ll ans = tmp - v*(v-1) / 2;
        v--;
        ans += v*(v-1) / 2;
        cout << ans << endl;
    }
    return 0;
}

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

int main(){
  int n, r = 0, sum = 0;
  cin >> n;
  for(int i=0; n>1000*i; i++){
  	sum = i;
  }
  sum += 1;
  r = 1000*sum - n;
  cout << r << endl;
}

Measured memory_bytes: 3576
L = list(map(int, input().split()))
a = L[0]
b = L[1]
c = L[2]
d = L[3]
list_n = []
list_n.append(a*c)
list_n.append(a*d)
list_n.append(b*c)
list_n.append(b*d)

print(max(list_n))

Measured memory_bytes: 9188
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
first = min(a[0],b[0])
more = min(a[1],b[0]-first)
count = first + more
for i in range(1,n):
    first = min(a[i]-more,b[i])
    more = min(a[i+1],b[i]-first)
    count +=  first + more
print(count)

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

#define CIN2(a,b) long long a,b;cin >> a >> b;
#define CIN3(a,b,c) long long a,b,c;cin >> a >> b >> c;
#define rep(i,n) for(int i=0,i##_len=(n); i<i##_len; ++i)

int main(){
    string s;cin >> s;
    int tmp = 0;
    int ans = 0;
    rep(i,s.size()){
        if(s[i]=='A' || s[i]=='C' ||s[i]=='G' ||s[i]=='T') tmp++;
        else{
            ans = max(ans,tmp);
            tmp=0;
        }
    }
    ans = max(ans,tmp);
    cout << ans << endl;
}



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

S_r = S[::-1]
w_num = []
b_num = []
w = 0
b = 0
for i in range(N):
  if S[i] == '.':
    w += 1
  w_num.append(w)
  if S_r[i] == '#':
    b += 1
  b_num.append(b)
b_num = b_num[::-1]
ans = [N-w_num[i]-b_num[i] for i in range(N)]
print(min(ans))
  



Measured memory_bytes: 23640
use std::io::stdin;

fn main() {
    let mut xa = String::new();
    stdin().read_line(&mut xa).unwrap();
    let xa: Vec<usize> = xa.trim().split_whitespace().flat_map(str::parse).collect();
    println!("{}", if xa[0] >= xa[1] { 10 } else { 0 });
}


Measured memory_bytes: 4352
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(10000)

# Debug output
def chkprint(*args):
    names = {id(v):k for k,v in inspect.currentframe().f_back.f_locals.items()}
    print(', '.join(names.get(id(arg),'???')+' = '+repr(arg) for arg in args))

# Binary converter
def to_bin(x):
    return bin(x)[2:]

# --------------------------------------------

dp = None

def main():
    N = int(input())

    Sn = 0
    for n in str(N):
        Sn += int(n)

    if N % Sn == 0:
        print("Yes")
    else:
        print("No")

main()


Measured memory_bytes: 4992
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program{
	const int mod=(int)1e9+7;
	static void Main(){
		Sc sc=new Sc();
		var t=sc.S;
		int n=t.Length;
		bool b=true;StringBuilder sb=new StringBuilder();
		int g=1;
		for(int i = 0;i<n-1;i++) {
			if(i<n/2){
				if(t[i]!=t[n-i-2]){
					b=false;
					break;
				}
			}
			sb.Append(g.ToString()).Append(" ").Append(i+2).Append("\n");
			if(i<n/2&&t[i]=='1'){g=i+2;}
		}
		if(t[n-1]=='1'||t[0]=='0'){b=false;}
		if(!b){Console.WriteLine("{0}",-1);}
		else{Console.Write(sb);}
	}
}

public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public int[] Ia3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),int.Parse);}
	public int[] Ia3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),long.Parse);}
	public long[] La3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),long.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}


Measured memory_bytes: 19804
#define FNAME ""

#include <bits/stdc++.h>

#define hash padjf9srpi
#define y0 sdkfaslhagaklsldk
#define y1 aasdfasdfasdf
#define yn askfhwqriuperikldjk
#define j1 assdgsdgasghsf
#define tm sdfjahlfasfh
#define lr asgasgash
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define forn(i, n) for (int i = 0; i < (n); i++)
#define fornr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define forab(i, a, b) for (int i = (a); i < (b); i++)
#define gcd __gcd
#define all(a) (a).begin(), (a).end()
 
#ifdef _WIN32
    #define I64 "%I64d"
#else
    #define I64 "%lld"
#endif

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair <int, int> pii;                                                                                                                                                                                      
typedef vector <int> vi;

template <class T> T sqr(const T &a) {return a * a;}


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

#ifdef LOCAL
    freopen(FNAME".in", "r", stdin);
    freopen(FNAME".out", "w", stdout);
#endif

    int n, cnt0 =0 ,cnt1 = 0;
    scanf("%d", &n);
    forn(i, n) {
        int x;
        scanf("%d", &x);
        if (x % 2) cnt1++;
        else cnt0++;
     }
    if (cnt1 % 2 == 0) puts("YES");
    else puts("NO");
}




Measured memory_bytes: 384
(function(input) {
    var a = input.split('\n');
    while (true) {
        var c = a.shift();
        if (c === '-') {
            return;
        }
        var n = Number(a.shift());
        for (var i = 0; i < n; i++) {
            var h = Number(a.shift());
            c = shuffle(c, h);
        }
        console.log(c);
    }
})(require('fs').readFileSync('/dev/stdin', 'utf8'));

function shuffle(c, h) {
    return c.slice(h, c.length) + c.slice(0, h);
}

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

using namespace std;

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

int main(){  
  long long n, m, r, inf = 1000000000, ans = 1000000000;
  cin >> n >> m >> r;
  long long vr[8], rr[8], abc[201][201] = {};
  rep(i, n){
    rep(j, n){
      if (i == j) abc[i][j] = 0;
      else abc[i][j] = inf;
    }
  }
  
  rep(i, r) cin >> vr[i], --vr[i];
  rep(i, m) {
    int a, b, c;
    cin >> a >> b >> c;
    --a, --b;
    abc[a][b] = c;
    abc[b][a] = c;
  }
  rep(k, n) {
    rep(i, n) {
      rep(j, n) {
        abc[i][j] = min(abc[i][j], abc[i][k] + abc[k][j]);
      }
    }
  }
  rep(i, r) rr[i] = i;

  do {
    long long tmp = 0;
    rep(i, r-1) {
      tmp += abc[vr[rr[i]]][vr[rr[i+1]]];
    }
    ans = min(ans, tmp);
  } while (next_permutation(rr, rr + r));

  cout << ans << endl;
}

Measured memory_bytes: 512
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;

int main() {
    int H, W;
    cin>>H>>W;
    int c[10][10];
    for(int i=0;i<10;++i){
        for(int j=0;j<10;++j){
            cin>>c[i][j];
        }
    }
    for(int k=0;k<10;++k){
        for(int i=0;i<10;++i){
            for(int j=0;j<10;++j){
                c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
            }
        }
    }
    int tmp;
    int ans = 0;
    for(int i=0;i<H;++i){
        for(int j=0;j<W;++j){
            cin>>tmp;
            if(tmp==-1)continue;
            ans += c[tmp][1];
        }
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<time.h>
#include<math.h>
#define MAX 100010
struct node
{
	int parent;
	int left;
	int right;
};
const int nil=-1;
struct node tree[MAX];
int depth[MAX];
int n;
void setdepth(int u,int p)
{
	depth[u]=p;
	if(tree[u].right!=nil)
		setdepth(tree[u].right,p);
	if(tree[u].left!=nil)
		setdepth(tree[u].left,p+1);
}
void input()
{
	int i,j,id,k,c,lastc;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		tree[i].parent=nil;
		tree[i].left=nil;
		tree[i].right=nil;
	}
	for(i=1;i<=n;i++)
	{
		scanf("%d %d",&id,&k);
		for(j=1;j<=k;j++)
		{
			scanf("%d",&c);
			if(j==1)
				tree[id].left=c;
			else
				tree[lastc].right=c;
			lastc=c;
			tree[c].parent=id;
		}
	}
	return;
}
void output(int u)
{
	int i,c;
	printf("node %d: ",u);
	printf("parent = %d, ",tree[u].parent);
	printf("depth = %d, ",depth[u]);
	if(tree[u].parent==nil)
		printf("root, ");
	else
		if(tree[u].left==nil)
			printf("leaf, ");
		else
			printf("internal node, ");
	printf("[");
	for(i=1,c=tree[u].left;c!=nil;i++,c=tree[c].right)
	{
		if(i>1)
			printf(", ");
		printf("%d",c);
	}
	printf("]\n");
	return;
}
int main()
{
	int i,r;
	input();
	for(i=0;i<n;i++)
		if(tree[i].parent==nil)
			r=i;
	setdepth(r,0);
	for(i=0;i<=n-1;i++)
		output(i);
	return 0;
}


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

using namespace std;

#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pdd pair<ld, ld>
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second

int a[1005];

int main() {
    cin.sync_with_stdio(false);

    int n;
    cin >> n;
    n *= 2;

    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }

    sort(a + 1, a + n + 1);

    int sol = 0;
    for (int i = 1; i <= n; i += 2) {
        sol += a[i];
    }

    cout << sol;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

    int i = S.length() - T.length();
    bool match;

    for (; i >= 0; i--) {
        match = true;
        for (int j = 0; j < T.length(); j++) {
            if (S[i + j] != '?' && S[i + j] != T[j]) {
                match = false;
                break;
            }
        }
        if (match) goto outer;
    }

    char ans[51];

    outer:
    if (match) {
        for (int j = 0; j < S.length(); j++) {
            if (S[j] == '?') {
                ans[j] = 'a';
            } else {
                ans[j] = S[j];
            }
        }
        for (int j = 0; j < T.length(); j++) {
            ans[i + j] = T[j];
        }
        ans[S.length()] = '\0';
    } else {
        strcpy(ans, "UNRESTORABLE");
    }

    cout << ans << endl;
}

Measured memory_bytes: 256