akhauriyash/Code-Regression huggingface dataset:
// abc071_b
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <typeinfo>
#include <unordered_map>
#include <utility>
#include <vector>
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define FOR(i, a) for (auto i : a)
#define pb push_back
#define all(in) in.begin(), in.end()
#define shosu(x) fixed << setprecision(x)
#define show1d(v)                                                              \
  rep(i, v.size()) cout << " " << v[i];                                        \
  cout << endl << endl;
#define show2d(v)                                                              \
  rep(i, v.size()) {                                                           \
    rep(j, v[i].size()) cout << " " << v[i][j];                                \
    cout << endl;                                                              \
  }                                                                            \
  cout << endl;
using namespace std;
typedef long long ll;
typedef int Def;
typedef pair<Def, Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def, pii> pip;
typedef vector<pip> vip;
template <typename A, typename B> bool cmin(A &a, const B &b) {
  return a > b ? (a = b, true) : false;
}
template <typename A, typename B> bool cmax(A &a, const B &b) {
  return a < b ? (a = b, true) : false;
}
const double PI = acos(-1);
const double EPS = 1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9 + 10;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
int main(int argc, char *argv[]) {
  string s;
  int alpha[26] = {0};
  cin >> s;
  rep(i, s.size()) { alpha[s[i] - 'a']++; }
  rep(i, 26) {
    if (alpha[i] == 0) {
      cout << (char)('a' + i) << endl;
      return 0;
    }
  }
  cout << "None" << endl;
  return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<deque>
using namespace std;
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
static const ll maxLL = (ll)1 << 62;
const int mod=1000000007;
int dy[]={-1,0,1,0};
int dx[]={0,1,0,-1};
int dyy[]={0,-1,0,1};
int dxx[]={-1,0,1,0};

/*#define int ll*/


int n,m;
string s;

signed main(){
    cin>>n>>m;
    cout<<n-m+1<<endl;
    
    
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  long long int a,b,k;
  scanf("%lld %lld %lld",&a,&b,&k);
  if(a > k){
    a = a-k;
  }else{
    k = k-a;
    a = 0;
    if(k > b){
      b = 0;
    }else{
      b = b-k;
    }
  }
  printf("%lld %lld\n", a, b);
  return 0;
}



Measured memory_bytes: 1732
# include <stdio.h>
# include <string.h>

int main(){
    char str[100005];
    scanf("%s", str);
    int mau = 0;

    char lista[26] = {'a', 'b', 'c', 'd','e','f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n','o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
    
    for (int i = 0; i < 26; ++i){
        int dif = 0;
        for (int j = 0; j <strlen(str); ++j){
            if (lista[i] != str[j])
                dif += 1;
        }
        if (dif == strlen(str)){
            printf("%c\n", lista[i]);
            mau += 1;
            break;
        }
    }
    if (mau == 0)
        printf("None\n");
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
   ll n,t;
   cin >>n>>t;
   ll ti[n];
   for(ll i=0;i<n;i++) cin >>ti[i];
   ll ans=0;
   for(ll i=0;i<n-1;i++){
      if(ti[i+1]-ti[i]>=t) ans+=t;
      else ans+=(ti[i+1]-ti[i]);
   }
   cout <<ans+t<<endl;
}


Measured memory_bytes: 1792
#include<cstdio>
#include<iostream>
#include<string>

using namespace std;

int main(void){

	int n;
	int run[3+1]={0};
	int out,score;;
	string inp;

	cin>>n;

	for(int i=0;i<n;i++){
		for(int j=0;j<=3;j++) run[j]=0;
		out=0;
		score=0;
		while(1){
			cin>>inp;
			if(inp=="HIT"){
				if(run[3]==1) score++,run[3]=0;
				if(run[2]==1) run[2]=0,run[3]=1;
				if(run[1]==1) run[1]=0,run[2]=1;
				run[1]=1;
			}
			if(inp=="HOMERUN"){
				score++;
				for(int i=1;i<=3;i++){
					if(run[i]==1) score++;
					run[i]=0;
				}
			}
			if(inp=="OUT"){
				out++;
			}
			if(out==3) break;
		}
		cout<<score<<endl;
	}

	return 0;
}

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

#define int long long
typedef pair<int, int> P;
#define mod 1000000007
#define INF (1LL<<60)
 
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)
#define YES puts("YES")
#define Yes puts("Yes")
#define NO  puts("NO")
#define No  puts("No")
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
 
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
 
 
#if 1
//-------------
// DUMPマクロ
// https://www.creativ.xyz/dump-cpp-652/
 
// vector
template <typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    for (T& x : vec) is >> x;
    return is;
}
// pair
template <typename T, typename U>
ostream& operator<<(ostream& os, pair<T, U>& pair_var) {
    os << "(" << pair_var.first << ", " << pair_var.second << ")";
    return os;
}
// vector
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
// map
template <typename T, typename U>
ostream& operator<<(ostream& os, map<T, U>& map_var) {
    os << "{";
    repi(itr, map_var) {
        os << *itr;
        itr++;
        if (itr != map_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
// set
template <typename T>
ostream& operator<<(ostream& os, set<T>& set_var) {
    os << "{";
    repi(itr, set_var) {
        os << *itr;
        itr++;
        if (itr != set_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
 
#define DUMPOUT cerr
 
void dump_func() {
    DUMPOUT << endl;
}
template <class Head, class... Tail>
void dump_func(Head&& head, Tail&& ... tail) {
    DUMPOUT << head;
    if (sizeof...(Tail) > 0) {
        DUMPOUT << ", ";
    }
    dump_func(std::move(tail)...);
}
#ifdef DEBUG
#define DEB
#define dump(...)                                                              \
    DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                            \
            << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]"        \
            << endl                                                            \
            << "    ",                                                         \
        dump_func(__VA_ARGS__)
#else
#define DEB if (false)
#define dump(...)
#endif
#endif

int lcm(int a, int b){
    return a/gcd(a,b)*b;
}

int count2(int n){
    int ret=0;
    while(n%2==0){ret++; n/=2;}
    return ret;
}

signed main(){
    int N, M;
    cin >> N >> M;
    vector<int> a(N);
    int l = 1;
    rep(i,N){
        cin >> a[i];
        a[i] /= 2;
        l = lcm(a[i], l);
    }
    cerr << l << endl;
    
    rep(i,N-1){
        if(count2(a[i])!=count2(a[i+1])) {
            cout << 0 << endl;
            return 0;
        }
    }
    
    int ans = (M/l  + 1)/2;
    cout << ans << endl;
    
}


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

A = [0] * (n+1)
AC = [0] * (n+1)
WA = [0] * (n+1)

for i in range(m):
    a, b = input().split()
    a = int(a)
    if AC[a] == 0 and b == 'WA':
        WA[a] += 1
    elif AC[a] == 0 and b == "AC":
        AC[a] += 1

t = 0
for i in range(len(AC)):
    if AC[i] == 1:
        t += WA[i]
print(sum(AC), t)

Measured memory_bytes: 46424
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<pint> vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=n-1;i>=(0);i--)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define eall(v) unique(all(v), v.end())
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define OUT(x) cout << #x << " = " << x << endl; 
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll INFF = 1e18;

#define int long long 

int N;
ll K;
int a[100010], b[100010];
signed main(void){
	cin >> N >> K;
	rep(i, N) cin >> a[i] >> b[i];
	vector<pair<int, int>> v;
	rep(i, N) v.pb(mp(a[i], b[i]));
	sort(all(v));
	ll now = 0;
	rep(i, N){
		now += v[i].se;
		if(now >= K) {
			printf("%lld\n", v[i].fi);
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 3956
N = int(input())
S = input()
S = [i for i in S]

for i in range(len(S)):
    for j in range(0, 26):
        if j+N<=25:
            if S[i]==chr(j+65):
                S[i]=chr(j+65+N)
                break
        else:
            if S[i]==chr(j+65):
                S[i]=chr(j+65+N-26)
                break

print(''.join(S))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define req(i,n) for(int i = 1;i <=n;i++)
#define pai 3.14159265358979323846
const int INF = 1001001001;
typedef long long ll;
int A[3][3], N;
bool punched[3][3];
bool ok[3][3];
using Graph = vector<vector<int>>;
vector<vector<int>> field;
vector<bool> seen;

const int MOD = 1000000007;
typedef pair<int,int> P;

//最大公約数
int gcd(int a,int b){
	if (a%b == 0){
		return b;
	}
	else{
		return gcd(b,a%b);
	}

}

//最小公倍数
int lcm(int a,int b){
	return a /gcd(a,b) * b;
}

//素数判定
bool is_prime(long long N) {
    if (N == 1) return false;
    for (long long i = 2; i * i <= N; ++i) {
        if (N % i == 0) return false;
    }
    return true;
}



  








      

 
int main(){
  int n,ans=0;
  string s;
  cin >> n >> s;
  
  for (int i = 0;i < n;i++){
    int cnt = 0;

    for (char c='a';c <='z';c++){
      bool right=false,left=false;

      for (int j=0;j<i;j++){
        if (c==s[j]) left=true;
      }
      for (int j=i;j<n;j++){
        if (c==s[j]) right=true;
      }

      if (left&&right) cnt++;
    }
    if (ans < cnt) ans = cnt;
  }
  cout << ans << endl;
}

    

Measured memory_bytes: 3616
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
 
using namespace std;
 
typedef long long ll;
 
#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=(b-1);i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;
 
#define MOD 1000000007

int main(){
	ll n;
	cin>>n;
	vector<ll> v;
	rep(i,0,n){
		ll a;
		cin>>a;
		v.pb(a);
	}
	ll index = 0;
	ll ans = 0;
	while(1){
		// up
		ll index1 = index;
		rep(i,index+1,v.sz){
			if(v[i]>=v[i-1]){
				index1 = i;
			}
			else{
				break;
			}
		}
 		// down
		ll index2 = index;
		rep(i,index+1,v.sz){
			if(v[i]<=v[i-1]){
				index2 = i;
			}
			else{
				break;
			}
		}
		index = max(index1,index2);
		index++;
		ans++;
		if(index==v.sz)break;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1400
// Last Change: 01/13/2019 21:07:51.
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

int main() {
  int input[10] = {};
  int n;
  for (int i = 0; i < 4; i++) {
    cin >> n;
    ++input[n];
  }
  if (input[1] == 1 and input[9] == 1 and input[7] == 1 and input[4] == 1) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}


Measured memory_bytes: 256
"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const N = parseInt(arg[0].split(" ")[0]);
    const X = parseInt(arg[0].split(" ")[1]);
    
    const A = arg[1].split(" ").map(n=>parseInt(n));
    let cnt = 0;
    
    for(let i=0; i<N-1; i++) {
        let sum = A[i] + A[i + 1];

        if(sum > X) {
            A[i+1] = Math.max(0, A[i+1] - (sum - X));
            
            cnt += sum - X;
        }
    }
    
    console.log(cnt);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 32096
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n, x;
    int a = 0, b = 0;
    cin>>n;
    for(int i = 1; i <= n; ++i){
        cin>>x;
        if(x%2) a++;
        else b++;
    }
    int ans1 = 1, ans2 = 1;
    for(int i = 1; i <= n; ++i){
        ans1 *= 3;
    }
    for(int i = 1; i <= b; ++i){
        ans2 *= 2;
    }
    cout<<(ans1 - ans2)<<endl;
}



Measured memory_bytes: 256
N = int(input())
L = list(map(int, input().split()))
L.sort()
 
from bisect import bisect_left 
cnt = 0
for i in range(0,N-2):
  for j in range(i+1,N-1):
    t = L[i]+L[j]
    idx = bisect_left(L,t)
    cnt += max(0,idx-j-1)
print(cnt)

Measured memory_bytes: 3188
#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<int,P> 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};

ll n;
vl a,b;

int main(){
	cin>>n;
	a=b=vl(n);
	for(int i=0;i<n;i++) cin>>a[i]>>b[i];
	ll res=0;
	for(int i=n-1;i>=0;i--){
		a[i]+=res;
		res+=(b[i]-a[i]%b[i])%b[i];
	}
	cout<<res<<endl;
}

Measured memory_bytes: 1920
class Station:
    def __init__(self, c, s, f):
        self.c = c
        self.s = s
        self.f = f


N = int(input())
stations = []
for _ in range(N-1):
    c, s, f = map(int, input().split())
    stations.append(Station(c, s, f))

for i in range(N):
    arrive_time = 0
    for j in range(i, N-1):
        current_station = stations[j]
        next_time = current_station.c + arrive_time
        if arrive_time > current_station.s:
            next_time += (current_station.f - (arrive_time -
                                               current_station.s
                                               )) % current_station.f
        else:
            next_time += (current_station.s - arrive_time)
        arrive_time = next_time
    print(arrive_time)


Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define REP(i, n) for (int i=0, i##_len=(n); i<i##_len; ++i)
#define FOR(i, a, b) for (int i=(a); i<(b); ++i)
using ll = long long;
using namespace std;

int main()
{
    int n = 'e'-'a'+1;
    int A[n];
    int K;
    for (int i=0; i<n; ++i) cin >> A[i];
    cin >> K;

    bool ret = true;
    for (int i=0; i<n-1; ++i) for (int j=1; j<n; ++j)
        if (abs(A[i]-A[j]) > K) ret = false;

    cout << (ret ? "Yay!" : ":(") << endl;
    return 0;
}


Measured memory_bytes: 256
//#pragma GCC target ("avx2,sse2")
//#pragma GCC optimization ("Ofast")
//#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ordered_set tree <pair <ll, int>, null_type, less <pair <ll, int> >, rb_tree_tag, tree_order_statistics_node_update>
#define ll long long
#define ull unsigned long long
#define db double
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define fi first
#define se second
#define mp make_pair
#define up_b upper_bound
#define low_b lower_bound
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define endl "\n"

#define left fsdsdfoisf
#define sum dpsdfioppsf
#define assign xcvjlkdjfio
#define trie fksdfkjkfnjuiv
#define next sidlfjsfkl
#define merge sdfksdkfsldf

#define int long long

using namespace std;

void dout() {
    cerr << endl;
}
template <typename Head, typename... Tail>
void dout(Head H, Tail... T) {
    cerr << H << ' ';
    dout(T...);
}

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef pair <int, int> pii;

const int N = 2e5 + 7;
int n, h[N], a[N], t[N * 4];

void update(int v, int tl, int tr, int pos, int val) {
    if (tl > pos || tr < pos) {
        return;
    }
    if (tl == tr) {
        t[v] = max(t[v], val);
        return;
    }
    int tm = tl + tr >> 1;
    if (pos <= tm) {
        update(v << 1, tl, tm, pos, val);
    }   else {
        update(v << 1 | 1, tm + 1, tr, pos, val);
    }
    t[v] = max(t[v << 1], t[v << 1 | 1]);
}

int getmax(int v, int tl, int tr, int l, int r) {
    if (tl > r || tr < l) {
        return 0;
    }
    if (tl >= l && tr <= r) {
        return t[v];
    }
    int tm = tl + tr >> 1;
    return max(getmax(v << 1, tl, tm, l, r), getmax(v << 1 | 1, tm + 1, tr, l, r));
}

void solve(int tc) {
    // check for (int i = 0; i < n; j++)
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> h[i];
    }
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    for (int i = 1; i <= n; i++) {
        update(1, 1, n, h[i], getmax(1, 1, n, 1, h[i] - 1) + a[i]);
    }
    cout << getmax(1, 1, n, 1, n);
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
    int tc = 1;
//    cin >> tc;
    for (int i = 0; i < tc; i++) {
        solve(i);
//        cleanup();
    }
}


Measured memory_bytes: 9600
#include <iostream>
//#include <stdio.h>
#include <algorithm>
//#include <tuple>
#include <cmath>
#include <string>
#include <vector>


#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
using namespace std;

string s;
char m[2], d[2];

int main() {
	cin >> s;

	m[0] = s[5];
	m[1] = s[6];

	int mi = (m[0] - '0') * 10 + (m[1] - '0');

	if (mi <= 4) cout << "Heisei\n";
	else cout << "TBD\n";

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int kaisu(long long int n){
  int counter = 0;
  while(1){
    if(n%2==0){
      n /= 2;
      counter++;
    }
    else{
      break;
    }
  
  }
  return counter;
}

int main(void){
  int N;
  int sum=0;
  scanf("%d",&N);
  long long int a[N];
  for(int i=0;i<N;i++){
    scanf("%lld",&a[i]);
  }
 for(int i=0;i<N;i++){
    sum += kaisu(a[i]);
  }
  printf("%d\n",sum);
  return 0;
}


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

using i64 = int64_t;

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

i64 solve(string s, int K) {
    i64 dp[102][2][5][2] = {1};
    rep(i, s.size()) rep(j, 2) rep(k, 4) rep(l, 2) {
        int lim = j ? 9 : s[i] - '0';
        rep(d, lim + 1) {
            dp[i+1][j || d < lim][k + (d != 0)][l || d != 0] += dp[i][j][k][l];
        }
    }
    i64 ans = 0;
    rep(j, 2){
        //cerr << dp[s.size()][j][K][1] << endl;
        ans += dp[s.size()][j][K][1];
    }
    return ans;
}

int main(){
    string s;
    cin >> s;
    int k;
    cin >> k;
    cout << solve(s, k) << endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)

ll a[100010];
ll k;
int main(){
	ll n;
	scanf("%lld",&n);
	rep(i,0,n)scanf("%lld",a+i);
	
	ll x=0;
	rep(i,0,n)x+=a[i];
	ll sumN=n*(n+1)/2;
	
	if(x%sumN){
		puts("NO");
		return 0;
	}
	x/=sumN;
	
	a[n]=a[0];
	rep(i,1,n+1){
		ll t=a[i-1]-a[i]+x;
		if(t<0||t%n){
			puts("NO");
			return 0;
		}
		k+=t/n;
	}
	puts(k==x?"YES":"NO");
	return 0;
}

Measured memory_bytes: 896
#define NAME "a"

#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <bitset>
#include <map>
#include <unordered_map>
#include <ctime>
#include <cctype>
#include <cassert>
#include <memory>
#include <stack>
#include <queue>
#include <deque>
#include <utility>
#include <iterator>

#define pb push_back
#define mp make_pair
#define frs first
#define snd second

using namespace std;

#ifdef WIN32
    #define lld "%I64d"
#else
    #define lld "%lld"
#endif

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;

const int INF = (int) 1e9 + 7;
const ll INFLONG = (ll) 1e18 + 7;
const double EPS = 1e-9;

typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<char> vc;
typedef vector<string> vs;

typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;

typedef vector<pii> vpii;
typedef vector<pil> vpil;
typedef vector<pli> vpli;
typedef vector<pll> vpll;

template <typename T>
T sqr(T a) {
    return a * a;
}

void solve() {
    char c;
    scanf("%c\n", &c);
    puts((c >= 'A' && c <= 'Z') ? "A" : "a");
}

int main() {
    srand(time(0));

//    freopen(NAME".in", "r", stdin);
  //  freopen(NAME".out", "w", stdout);

    int T = 1;

    while (T--) {
        solve();
    }

//    printf("%.3lf\n", (double) clock() / CLOCKS_PER_SEC);
    return 0;
}


Measured memory_bytes: 3756
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define bFOR(i,n1,n2) for(int i=n1;i>=n2;i--)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long int ll;
typedef pair<ll,ll> Pi;
const int INF=(ll)(1LL<<30)-1;
const double INFd=100000000000.0;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a, b)*b;}
int dx[4]={0,-1,0,1},dy[4]={-1,0,1,0};
int mdx[4]={0,1,0,-1},mdy[4]={-1,0,1,0};


template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int n,m;
vector<int> uv[100100];
int s,t;
int cost[100100];
int mid1[100100];
int mid2[100100];
int main(){
	cin>>n>>m;
	REP(i,100100)cost[i]=-1;
	REP(i,100100)mid1[i]=-1;
	REP(i,100100)mid2[i]=-1;
	for(int i=0;i<m;i++){
		int t1,s1;
		cin>>t1>>s1;
		uv[t1].push_back(s1);
	}
	cin>>s>>t;
	cost[s]=0;
	queue<int> q;
	q.push(s);
	while(q.size()){
		int now=q.front();q.pop();
		//cout<<"1 :"<<now<<endl;
		vector<int> v1;
		vector<int> v2;
		v1.clear();
		v2.clear();
		for(int i=0;i<uv[now].size();i++){
			//cout<<v1[i]<<endl;
			if(mid1[uv[now][i]]==-1){
				v1.push_back(uv[now][i]);
				mid1[uv[now][i]]=1;
			}
		}
		//REP(i,v1.size())cout<<v1[i]<<endl;
		for(int i=0;i<v1.size();i++){
			for(int j=0;j<uv[v1[i]].size();j++){
				if(mid2[uv[v1[i]][j]]==-1){
					v2.push_back(uv[v1[i]][j]);
					mid2[uv[v1[i]][j]]=1;
				}
			}
		}
		v1.clear();
		//REP(i,v2.size())cout<<v2[i]<<endl;
		for(int i=0;i<v2.size();i++){
			for(int j=0;j<uv[v2[i]].size();j++)
				v1.push_back(uv[v2[i]][j]);
		}
		//REP(i,v1.size())cout<<v1[i]<<endl;
		for(int i=0;i<v1.size();i++){
			if(cost[v1[i]]==-1){
				q.push(v1[i]);
				cost[v1[i]]=cost[now]+1;
			}
		}
	}
	cout<<cost[t]<<endl;
	return 0;
}

Measured memory_bytes: 6912
import scala.io.StdIn._

object Main {
    def main(args: Array[String]): Unit = { 
        val seq: Seq[Int] = (0 until 10).map(_ => readLine().toInt)
        val rev: Seq[Int] = seq.sorted.reverse
        for(i <- 0 until 3) println(rev(i))
    }   
}

Measured memory_bytes: 43952
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>
using namespace std;
using Int = unsigned long long;
typedef pair<int,int> P; typedef pair<Int,Int> Pl;
int const mod = 1e9+7;
#define END {cout<<(ans)<<'\n'; return 0;}
#define ALL(vec) vec.begin(),vec.end()
#define Pr(type) priority_queue<type>
#define gPr(type) priority_queue<type,vector<type>,greater<type>>
#define V(type) vector<type>
#define rep(i,n) for(int i=0; i<n; i++)
#define rer(i,s,n) for(int i=s; i<n; i++)
#define gnr(i,l,r) for(int i=r; i>=l; i--)
#define eb emplace_back
#define pri1(a) cout<<a<<'\n'
#define pri2(a,n) rep(i,(n)-1)cout<<a[i]<<' '; cout<<a[(n)-1]<<'\n';
#define prip(p) cout<<(p).first<<' '<<(p).second<<'\n'
template<class T> inline bool cmin(T& a, T b) { if (a > b) { return a = b; } return false; }
template<class T> inline bool cmax(T& a, T b) { if (a < b) { return a = b; } return false; }

int n,m,q,_,x,y;
string s,sb;
bool ok;
char ch;

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

  cin>>n>>m; int a[n];
  rep(i,n)cin>>a[i];
  int l=0,r=1e9,mid;
  while(r-l>1){
    mid=(l+r)/2;
    x=mid; y=1;
    rep(i,n){
      if(a[i]>x){x=mid; y++;}
      if(a[i]>x){y=114514; break;}
      else x-=a[i];
    }
    if(y>m)l=mid;
    else r=mid;
  }
  pri1(r);
}


Measured memory_bytes: 3580
#include<stdio.h>
int main()
{
	int X,Y,H,W,N,x,y,s,T;
	for(scanf("%d",&T);T--;)
	{
		scanf("%d%d%d%d%d",&X,&Y,&W,&H,&N);
		for(s=0;N--;)
		{
			scanf("%d%d",&x,&y);
			if(X<=x&&x<=X+H && Y<=y&&y<=Y+W)++s;
		}
		printf("%d\n",s);
	}
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
namespace FAST_IO
{
	template<typename T> void read(T &a)
	{
		a=0;
		int f=1;
		char c=getchar();
		while(!isdigit(c))
		{
			if(c=='-')
			{
				f=-1;
			}
			c=getchar();
		}
		while(isdigit(c))
		{
			a=a*10+c-'0';
			c=getchar();
		}
		a=a*f;
	}
	template <typename T> void write(T a)
	{
		if(a<0)
		{
			a=-a;
			putchar('-');
		}
		if(a>9)
		{
			write(a/10);
		}
		putchar(a%10+'0');
	}
	template <typename T> void writeln(T a)
	{
		write(a);
		puts("");
	}
}
int main()
{
	int n,k;
	cin>>n>>k;
	if(k==1)
	{
		cout<<0;
	}
	else
	{
		cout<<n-k;
	}
}


Measured memory_bytes: 256
// C++ 14
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(ll __x = __start; __x < __end; __x++)

/*
            x                       y
0  -  1  -  2  -  3  -  4  -  5  -  6
            |                       |
            -  -  -  -  -  -  -  -  -

*/
int dp[2000][2000];
int main() {
  int n, x, y;
  cin >> n >> x >> y;
  x--;y--;
  
  loop(i,0,n) loop(j,0,n) {
    dp[i][j] = abs(j-i);
  }
  loop(i,0,n) loop(j,0,n) {
    dp[j][i] = dp[i][j] = min(dp[j][i], dp[j][y] + dp[x][i] + 1);
    dp[j][i] = dp[i][j] = min(dp[j][i], dp[j][x] + dp[y][i] + 1);
  }
  
  vector<int> C(2100, 0);
  loop(i,0,n-1) loop(j,i+1,n) C[dp[i][j]]++;
  
  loop(k,1,n) cout << C[k] << endl;
  return 0;
}


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

int main()
{
  string s;
  cin >> s;
  if(s.size() == 2)
  {
    cout << s << endl;
  }
  else
  {
    cout << s.at(2);
    cout << s.at(1);
    cout << s.at(0) << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <cmath>

using namespace std;

#define ll long long

int main(void){
    int n, m;
    cin >> n >> m;
    vector<int> s(m), c(m);
    for(int i = 0;i < m;++i)    cin >> s[i] >> c[i];
    vector<int> ans(n, -1);

    int fatal_flag = 0;

    for(int i= 0;i < m;++i){
        if(ans[s[i]-1] != -1 && ans[s[i]-1] != c[i]){
            fatal_flag = 1;
            break;
        }
        ans[s[i]-1] = c[i];
    }

    if(ans[0] == 0 && n != 1){
        fatal_flag = 1;
    }

    if(ans[0] == -1){
        if(n == 1){
            ans[0] = 0;
        }else{
            ans[0] = 1;
        }
        
    }
    for(int i = 1;i < n;++i){
        if(ans[i] == -1){
            ans[i] = 0;
        }
    }

    if(fatal_flag){
        cout << -1 << endl;
    }else{
        for(int i = 0;i < n;++i){
            cout << ans[i];
        }
        cout << endl;
    }




    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll n, k, a[100001], ans,tmp,b[100001],c  ;
priority_queue<ll> p;
int main()
{
    cin >> n >> k ;
    for (int i = 0 ; i < n ; i++)
        cin >>a[i],p.emplace(a[i]);
    while(k > 0)
    {
        tmp = p.top();
        if (tmp == 0)
        {
            break ;
        }
        p.pop();
        tmp /= 2, --k;
        p.emplace(tmp);

    }
    while(p.size()> 0)ans+=p.top(),p.pop();
    cout <<ans;
    return 0;
}


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

int main(){
	int N;
	cin >> N;
	int A[N], B[N];
	ll suma = 0, sumb = 0;
	for(int i=0; i<N; i++){
		cin >> A[i];
		suma = suma + A[i];
	}
	for(int i=0; i<N; i++){
		cin >> B[i];
		sumb = sumb + B[i];
	}
	if(suma < sumb){
		cout << -1 << endl;
		return 0;
	}
	ll sum = 0;
	int c = 0;
	vector<int> C;
	for(int i=0; i<N; i++){
		if(A[i] < B[i]){
			sum = sum + B[i] - A[i];
			c++;
		}else{
			C.push_back(A[i] - B[i]);
		}
	}
	if(c == 0){
		cout << 0 << endl;
		return 0;
	}
	sort(C.begin(), C.end());
	int i = C.size() - 1, cnt = 0;
	while(sum - C[i] > 0){
		sum = sum - C[i];
		cnt++;
		i--;
	}
	cnt++;
	cout << c + cnt << endl;
	return 0;
}

Measured memory_bytes: 1660
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
using namespace std;

#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define ldb ldouble

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 18;
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;
#define szz(x) (int)(x).size()
#define rep(i, n) for(int i=0;i<n;i++)
#define Se second
#define Fi first

char in[105];
int main() {
	int A, B, i, j;
	scanf("%d %d %s", &A, &B, in);

	for (i = 0; i < A + B + 1; i++) {
		bool c = in[i] == '-';
		if (i != A) c = !c;
		if (!c) return !printf("No\n");
	}
	return !printf("Yes\n");
}

Measured memory_bytes: 256
import math
k = int(input())

def guuki(num):
    if num%2 == 0:
        return 0
    else:
        return 1

if k == 1:
    print(1)
elif guuki(k) == 0:
    print(math.ceil(k/2 * k/2))
else:
    print(math.ceil((k+1)/2 * (k-1)/2))



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

using namespace std;

int main(){
    long long int x;
    long long int n;
    scanf("%lld",&x);

    n = (-1+sqrt(1+8*x))/2;
    if(n*(n+1)/2==x)
        printf("%lld\n",n);
    else
        printf("%lld\n",n+1);    
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>
#include <numeric>

static const int INF = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

int main() {
    vector<ll> v;
    int n, a, b;
    cin >> n >> a >> b;

    for (int i = 0; i < n; ++i) {
        ll x;
        cin >> x;
        v.emplace_back(x);
    }
    sort(v.begin(), v.end(), greater<>());
    ll sum = 0;
    vector<vector<ll>> comb(n+1, vector<ll>(n+1, 0));
    for (int i = 0; i < n+1; ++i) comb[i][0] = comb[i][i] = 1;
    for (int i = 1; i < n+1; ++i) {
        for (int j = 1; j < i; ++j) {
            comb[i][j] = comb[i-1][j-1] + comb[i-1][j];
        }
    }
    int p=0,q=0;
    for(int i = 0; i < n; ++i){
        if(v[i]==v[a-1]){
            p++;
            if(i < a){
                q++;
            }
        }
    }

    if(q != a){
        sum = comb[p][q];
    }else {
        for (int i = a; i <= b; ++i) {
            sum += comb[p][i];
        }
    }
    double ans = accumulate(v.begin(), v.begin()+a, 0.0)/a;
    printf("%.6f\n", ans);
    cout << sum << "\n";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0; i < (n); ++i)
#define repA(i, a, n) for(int  i = a; i <= (n); ++i)
#define all(x) x.begin(), x.end()
#define sz(x) (int) (x).size()
#define fill(a) memset(a, 0, sizeof(a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define endl '\n'
#define init(n) int n;cin>>n;int a[n];rep(i,n)cin>>a[i];
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long int> vll;
typedef vector<pii> vii;
ll p=1000000007;
ll const N=1e6+5;
int main() {
   
    cin.sync_with_stdio(0); cin.tie(0);
    cin.exceptions(cin.failbit);
    int T;T=1;
    // cin>>T;
    while(T--){
   		ll n,k;cin>>n>>k;
   		ll a[n];
   		rep(i,n)cin>>a[i];
   		sort(a,a+n);
   		ll ans=0;
   		if(k<n){
   			rep(i,n-k){
   				ans=ans+a[i];
   			}
   		}
   		cout<<ans<<endl;
    }
    return 0;   
}
 


Measured memory_bytes: 1792
#include <cstdio>
#include <stack>
#include <set>
#include <cmath>
#include <map>
#include <time.h>
#include <vector>
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
//#include <memory.h>
#include <cstdlib>
#include <queue>
#include <iomanip>
#include <cassert>
#include <unordered_map>
#define P pair<int, int>
#define LL long long
#define LD long double
#define PLL pair<LL, LL>
#define mset(a, b) memset(a, b, sizeof(a))
#define rep(i, a, b) for (int i = a; i < b; i++)
#define PI acos(-1.0)
#define random(x) rand() % x
#define debug(x) cout << #x << " " << x << "\n"
using namespace std;
const int inf = 0x3f3f3f3f;
const LL __64inf = 0x3f3f3f3f3f3f3f3f;
#ifdef DEBUG
const int MAX = 2e3 + 50;
#else
const int MAX = 1e6 + 50;
#endif
const int mod = 1e9 + 7;
void file_read() {
#ifdef DEBUG
	freopen("in", "r", stdin);
	// freopen("out", "w", stdout);
#endif
}

int a[MAX];
bool vis[MAX];
bool solve(int x) {
	if(x == 1) return true;
	for(int i = 2; i * i <= x; i++) {
		if(x % i == 0) {
			if(vis[i]) return false;
			vis[i] = 1;
			while(x % i == 0) {
				x /= i;
			}
		}
	}
	if(x > 1) {
		if(vis[x]) return false;
		vis[x] = 1;
	}
	return true;
}
int main() {
	file_read();
	int n;
	scanf("%d", &n);
	int Max = 0;
	for(int i = 1; i <= n; i++) {
		scanf("%d",&a[i]);
		Max = max(Max, a[i]);
	}
	int g = a[1];
	for(int i = 2; i <= n; i++) {
		g = __gcd(a[i], g);
	}
	if(g != 1) {
		puts("not coprime");
		return 0;
	}
	for(int i = 1; i <= n; i++) {
		bool cur = solve(a[i]);
		if(!cur) {
			puts("setwise coprime");
			return 0;
		}
	}
	puts("pairwise coprime");
	return 0;
}

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

int main() {
  int a,b;
  cin>>a>>b;
  int d=0;
  for(int i=1;i<=a-1;i++){
    for(int j=1;j<=31;j++){
      if(i==j) d++;
    }
  }
    for(int j=1;j<=b;j++){
      if(a==j) d++;
    }
  

cout<<d<<endl;
}


Measured memory_bytes: 256
/*
  author: ruruvuvu
  GitHub account: colon-ku

  created at: 2020-01-03 17:23:46 
                2020-01-03 17:26:29
*/

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

#define all(x) (x).begin(),(x).end()
#define rep(x, y) for (int x = 0; x < y; x++)
#define MOD 1000000007

typedef long long LL;
typedef long double LD;

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

ostringstream oss_global;
string s_global = oss_global.str();

int main()
{
    long a, b;
    cin >> a >> b;

    cout << a*b/__gcd(a, b) << endl;
    return 0;
}


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

using namespace std;

typedef long long ll;
string s;
int N;
ll sum;
map <string,ll> m;
map <string,ll>::iterator it;

int main() {
    cin >> N;
    for(; N; --N) {
        cin >> s;
        sort(s.begin(),s.end());
        m[s]++;
    }

    for(it = m.begin(); it != m.end(); ++it) {
     sum+=(it->second)*(it->second-1)/2;
    }
    cout<<sum;
    return 0;
}


Measured memory_bytes: 11136
#include  <iostream>
#include  <stdio.h>
#include <algorithm>
using namespace std;
//#include <vector>
//#include <stack>
//#include <queue>

/*
#include <math.h>
int standerd = int(pow(10.0,9.0)) + 7;
*/
string ans_Yes = "Yes"; 
string ans_No = "No"; 
string ans_yes = "yes"; 
string ans_no = "no"; 
 

int main(){

    int A;
    int B;
    
    cin >> A;
    cin >> B;

    cout << (A * 3 + B)/2;

}

Measured memory_bytes: 764
# /usr/bin/python3
# -*- coding: utf-8 -*-
from queue import Queue
from queue import LifoQueue as Stack
from math import sqrt, floor, ceil, log2
from fractions import gcd
from itertools import permutations, combinations
from operator import itemgetter
from functools import cmp_to_key


yn = 'YNeos'
ynflg = False
cnt = 0
ans = None

def lcm(a, b):
    return (a*b) // gcd(a,b)

def intinput():
    return int(input())

def mulinputs():
    return map(int,input().split())

def lineinputs(func=intinput):
    datas = []
    while True:
        try:
            datas.append(func())
        except EOFError:
            break
    return datas



# N = intinput()
# S = input()
# A, B, C, D, E, F = mulinputs()
# datas = list(mulinputs())
# datas = lineinputs(input)

S, T = input().split()
A, B = map(int, input().split())
U = input()

# 出力
if U == S:
    print(A-1, B)
else:
    print(A, B-1)




Measured memory_bytes: 5688
#include <bits/stdc++.h>                                                                       
using namespace std;                                                                           
                                                                                               
int main(){                                                                                    
                                                                                               
        double n,o;                                                                            
        scanf("%lf", &n);                                                                      
        o = ceil(n/2);                                                                         
        printf("%.6g", o);                                                                     
        return 0;                                                                              
}         

Measured memory_bytes: 256
#define _CRT_SECURE_NO_DEPRECATE
#define _USE_MATH_DEFINES
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <memory.h>
#include <set>
#include <ctime>
#include <map>
#include <cstring>
#include <iterator>
#include <queue>
#include <assert.h>
#include <bitset>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <functional>
#include<random>

//#pragma comment(linker, "/STACK:512000000")

using namespace std;

#define pb emplace_back
#define mp make_pair
#define all(a) (a).begin(), (a).end()
#define forn(i, n) for (int i = 0; i < (n); ++i)
#define forab(i, a, b) for (int i = (a); i < (b); ++i)

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const int infi = 1e9 + 7;
const ll infl = (ll)1e18 + (ll)7;

vector<pii> edges;
vector<vector<int> > g;
int ar[100500];
int st[100500];

int val[100500];
int used[100500];

int32_t main() {
    cin.sync_with_stdio(false);
    cin.tie(0);
    //srand(time(NULL));
   // freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
    int n;
    cin >> n;
    g.resize(n);
    forn(i, n - 1) {
        int u, v;
        cin >> u >> v;
        --u, --v;
        edges.pb(v, u);
        g[v].pb(u);
        g[u].pb(v);
    }
    priority_queue<pii, vector<pii>, greater<pii> > tmp;
    forn(i, n) {
        tmp.push({ g[i].size(), i });
    }
    forn(i, n)
        st[i] = g[i].size();
    forn(i, n)
        cin >> ar[i];
    sort(ar, ar + n);
    int i = 0;
    while (tmp.size()) {
        int v = tmp.top().second;
        tmp.pop();
        if (used[v])
            continue;
        val[v] = ar[i++];
        used[v] = 1;
        for (int to : g[v]) {
            if (used[to])
                continue;
            --st[to];
            tmp.push({ st[to], to });
        }
    }

    ll ans = 0;
    for (auto e : edges) {
        ans += min(val[e.first], val[e.second]);
    }
    cout << ans << '\n';
    forn(i, n)
        cout << val[i] << ' ';

    return 0;
}

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

int main(){
  int a,b,c;
  cin>>a>>b>>c;
  if (a ==5 && b ==5 && c ==7)
    printf("YES");
  else if (a == 5 && b ==7 && c ==5)
    printf("YES");
  else if (a == 7 && b ==5 && c ==5)
    printf("YES");
      
  else
    printf("NO");
}
    
    

Measured memory_bytes: 256
n = int(input())
a = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
s = [i for i in input()]

b = []
for i in range(len(s)):
    for j in range(len(a)):
        if s[i]==a[j]:
            s[i] = a[(j+n)%26]
            break
print(''.join(s))

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

int main(void) {
    double x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    cout << fixed << sqrt(pow(x1-x2, 2) + pow(y1-y2, 2)) << endl;
    return 0;
}

Measured memory_bytes: 1280
/**
 *    author:  otera    
**/
#include<iostream>
#include<string> 
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm> 
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }

void solve() {
	int n; cin >> n;
	vector<int> a(n);
	bool ok = 1;
	rep(i, n) {
		cin >> a[i];
		if(a[i] % 2 == 1) ok = 0;
	}
	if(ok) {
		cout << "second" << endl;
	} else {
		cout << "first" << endl;
	}
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}

Measured memory_bytes: 1024
import heapq
import sys

input = sys.stdin.readline

def dijkstra(s,edge):
    #始点sから各頂点への最短距離
    d = [10**20] * n
    used = [True] * n #True:未確定
    d[s] = 0
    used[s] = False
    edgelist = []
    for a,b in edge[s]:
        heapq.heappush(edgelist,a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        if not used[minedge%(10**6)]:
            continue
        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d

n,x,y = map(int,input().split())

edge = [[] for i in range(n)]
#edge[i] : iから出る道の[重み,行先]の配列
for i in range(n-1):
    edge[i].append([1,i+1])
    edge[i+1].append([1,i])
edge[x-1].append([1,y-1])
edge[y-1].append([1,x-1])

ans = [0 for _ in range(n)]
for i in range(n):
    #dijkstra(始点,edge)
    res = dijkstra(i,edge)
    for j in range(i+1,n):
        ans[res[j]] += 1

for i in range(1,n):
    print(ans[i])


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

int main() {
	int a[55], n, maxi = 0, cur = 0; cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (abs(a[i]) > maxi) {
			maxi = abs(a[i]);
			cur = i;
		}
	}
	cout << n * 2 - 1 << endl;
	for (int i = 0; i < n; i++)cout << cur + 1 << ' ' << i + 1 << endl;
	if (a[cur] >= 0)for (int i = 0; i < n - 1; i++)cout << i + 1 << ' ' << i + 2 << endl;
	else for (int i = n - 1; i > 0; i--)cout << i + 1 << ' ' << i << endl;

	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 equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

ll n;
string x;
ll cnt = 0;

ll f[200200];
ll pos[200200], neg[200200];
ll p = 0, q = 0;

ll dfs(ll n) {
  if (n == 0) return 0;
  if (f[n]) return f[n];
  ll res = n, cnt = 0;
  while (res) {
    if (res & 1) cnt++;
    res >>= 1;
  }
  return f[n] = dfs(n % cnt) + 1;
}

void init() {
  rep(i, 200200) dfs(i);
  pos[0] = 1;
  FOR(i, 1, 200200) pos[i] = pos[i - 1] * 2 % (cnt + 1);
  rep(i, n) {
    p *= 2;
    if (x[i] == '1') p++;
    p %= (cnt + 1);
  }
  if (cnt <= 1) return;
  neg[0] = 1;
  FOR(i, 1, 200200) neg[i] = neg[i - 1] * 2 % (cnt - 1);
  rep(i, n) {
    q *= 2;
    if (x[i] == '1') q++;
    q %= (cnt - 1);
  }
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(25);


  cin >> n >> x;

  rep(i, n) if (x[i] == '1') cnt++;
  init();
  rep(i, n) {
    if (x[i] == '0') {
      ll res = (p + pos[n - 1 - i]) % (cnt + 1);
      //cout << pos[n - 1 - i] << '\n';
      //cout << res << '\n';
      cout << f[res] + 1 << '\n';
    }
    else {
      if (cnt == 1) {
        cout << 0 << '\n';
        continue;
      }
      ll res = (q - neg[n - 1 - i] + (cnt - 1) * 200) % (cnt - 1);
      //cout << res << '\n';
      cout << f[res] + 1 << '\n';
    }
  }
  



  




  
  return 0;
}

Measured memory_bytes: 8456
N = int(input())
A = list(map(int, input().split()))
odd = 0
four = 0
for i in range(0, N):
	if A[i] % 4 == 0: four += 1
	if A[i] % 2 != 0: odd += 1
if odd <= four+N%2: print('Yes')
else: print('No')

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

#define ll long long

typedef pair< int, int > ii;
typedef vector< ii > vii;

void solve(){
	int n; cin>>n;
	for(double i = 0; i<=n; i++){
		double ans = i * 1.08;
		//cout<<ans<<endl;
		if((int)ans == n){
			cout<<i<<endl;
			return;
		}
	}
	cout<<":("<<endl;
}

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	//int t; cin>>t;
	//cout<<fixed<<setprecision(3);
	//while(cin>>n, n){
		solve();
	//}
	return 0;
}



Measured memory_bytes: 3772