akhauriyash/Code-Regression huggingface dataset:
#pragma once
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
typedef long long ll;
using namespace std;
int r, g, b;
void Sentou() {
	ll n, t;
	cin >> n >> t;

	ll sum = 0;
	ll bef;
	cin >> bef;
	for (size_t i = 1; i < n; i++)
	{
		ll ti;
		cin >> ti;
		sum += min(ti - bef,t);
		bef = ti;
	}
	sum += t;
	cout << sum << endl;
}

int main() {
	Sentou();
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  //string s;
  //map<string,int> s;
  //map<string,int> s{};
  //string res;
  //vector<int> a;
  
  cin >> n;
  vector<vector<int>> d(n+1, vector<int>(n+1,-1));
  
  long long sum = 0;
  //cout << s.at(0) << endl;
  //vector<int> s(n,0);
  //int tmp,res;
  //res = 0;
  //string res = "No";
  int tmp,pmt ;
  for(int i = 1;i<=n;i++){
    for(int j = 1;j<=n;j++){
      for(int k = 1;k<=n;k++){
        if (d.at(j).at(k) == -1){
          tmp = gcd(j,k);
          d.at(j).at(k) = tmp;
        }else{
          tmp = d.at(j).at(k);
        }
        
        if (d.at(i).at(tmp) == -1){
          pmt = gcd(i,tmp);
          d.at(i).at(tmp) = pmt;
          sum += pmt;
        }else{
          sum += d.at(i).at(tmp);
          
        }
        
      
      }
    }
  }
    
  cout << sum;
  
}

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

using namespace std;

int n;
long long sum, dam[100005], tmp[100005];

int main(void)
{
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i)
        scanf("%lld", &dam[i]), sum += dam[i];
    sum /= 2;
    for (int i = 2; i <= n; i += 2) tmp[1] += dam[i];
    for (int i = 3; i <= n; i += 2) tmp[2] += dam[i];
    for (int i = 3; i <= n; ++i)
        tmp[i] = tmp[i - 2] - dam[i - 1] + dam[i - 2];
    for (int i = 1; i <= n; ++i)
        printf("%lld%c", (sum - tmp[i]) * 2, " \n"[i == n]);
    return 0;
}

Measured memory_bytes: 2816
#include<iostream>
using namespace std;
 
int main(){
  int N,K,x,sum=0;
  cin>>N>>K;
  for(int i=0;i<N;i++){
    cin>>x;
    if(K-x<x) sum+= 2*(K-x);
    else sum+= 2*x;
  }
  cout<<sum<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[105],b[3];
int main()
{
	int n,x,y,i;
	cin>>n>>x>>y;
	for(i=1;i<=n;i++)
	{
	cin>>a[i]; 
	if(a[i]<=x)
	b[0]++;
	if(a[i]>=x+1&&a[i]<=y)
	b[1]++;
	if(a[i]>=y+1)
	b[2]++;
}
sort(b,b+3);
cout<<b[0];
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define FOR(i,k,n) for (int (i)=(k); (i)<(n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fst first
#define snd second
#define all(v) begin(v), end(v)
#define debug(x) cerr<< #x <<": "<<x<<endl
#define debug2(x,y) cerr<< #x <<": "<< x <<", "<< #y <<": "<< y <<endl

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vll;
typedef vector<vector<ll> > vvll;
typedef vector<char> vc;
typedef vector<vector<char> > vvc;
typedef vector<double> vd;
typedef vector<vector<double> > vvd;
template<class T> using vv=vector<vector< T > >;
typedef deque<int> di;
typedef deque<deque<int> > ddi;
typedef deque<bool> db;
typedef deque<deque<bool> > ddb;

// cout pair
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {
  s << p.first << " " << p.second << "\n"; return s;
}

// cout vector<pair>
template<typename T1, typename T2> ostream& operator<<(ostream& s, const vector<pair<T1, T2> >& vp) {
  int len = vp.size(); s << "\n";
  for (int i = 0; i < len; ++i) { s << vp[i]; }
    s << "\n"; return s;
}

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

// cout deque
template<typename T> ostream& operator<<(ostream& s, const deque<T>& v) {
  int len = v.size(); s << "\n";
  for (int i = 0; i < len; ++i) {
    s << v[i]; if (i < len - 1) s << "\t";
  }
  s << "\n"; return s;
}

// cout 2-dimentional vector
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) { s << vv[i]; }
  return s;
}

// cout 2-dimentional deque
template<typename T> ostream& operator<<(ostream& s, const deque< deque<T> >& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) { s << vv[i]; }
  return s;
}

int main() {
  string s;
  cin >> s;
  auto find_c = (int)(s.find_first_of("C"));
  auto find_f = (int)(s.find_last_of("F"));
  if (find_c < find_f && find_c >= 0) {
    printf("Yes\n");
    return 0;
  } else {
    printf("No\n");
    return 0;
  }
  return 0;
}


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

using namespace std;

long long employees[4001];
bool checked[4001];

int main()
{
	int n;
	while (cin >> n, n) {
		for (int i = 1; i <= 4000; ++i) employees[i] = checked[i] = false;

		vector<int> ans;

		for (int i = 0; i < n; ++i) {
			int num, a, b; cin >> num >> a >> b;

			if (checked[num]) continue;

			employees[num] += (long long)a * b;

			if (employees[num] >= 1000000) {
				ans.push_back(num);
				checked[num] = true;
			}
		}

		if (ans.empty()) cout << "NA" << endl;

		for (int i = 0; i < ans.size(); ++i) cout << ans[i] << endl;
	}
}

Measured memory_bytes: 1264
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>

int main()
{
    long W, H, x, y;
    scanf("%ld %ld %ld %ld", &W, &H, &x, &y);
    if(W == x*2 && H == y*2) printf("%lf 1\n", W*H/2.0);
    else printf("%lf 0\n", W*H/2.0);
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int a[n],i,al=0,b=0;
    for(i=0;i<n;i++)
        cin>>a[i];
    sort(a,a+n);
    for(i=n-1;i>=0;i=i-2)
    {
        al=al+a[i];
    }
    for(i=n-2;i>=0;i=i-2)
    {
        b=b+a[i];
    }
    cout<<al-b<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LL long long
#define Accel ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define Re(a,b) memset(a,b,sizeof a)
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define ALL(X) (X).begin(), (X).end()
#define FOR(I, A, B) for (int I = (A); I <= (B); I++)
#define REP(I, N) for (int I = 0; I < (N); I++)
#define PII pair<int,int>
#define PLL pair<LL,LL>
#define SZ(a) ((int)a.size())
//#pragma GCC optimize(2)
using namespace std;
//const double eps=1e-6;
//typedef complex<double>C;
//const double PI(acos(-1.0));
//for(int mask=i;mask>0;mask=(mask-1)&i)
//int a[25]= { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97 };
//__gcd, atan2(y,x)=y/x , __int128
//c(n,k)=c(n-1,k-1)+c(n-1,k)
//c(i,r),i for r to n =c(n+1,r+1)
//void add(int x){while(x<N)BIT[x]++,x+=x&-x;}
//int sum(int x){int s=0;while(x){s+=BIT[x];x-=x&-x;}return s;}
//int find(int x){return x==p[x]?x:p[x]=find(p[x]);}
//LL pw(LL a,LL b){LL t=1;for(;b;b>>=1,a=a*a%M)b&1?t=t*a%M:0;return t;}
//log() = ln() , log(x)/log(y)=log(y)-base-x
//INT_MAX 127,INT_MIN 128
//isalnum() decimal digit or an uppercase or lowercase letter
//int dw[4][2]={{0,1},{1,0},{0,-1},{-1,0}};
//int dw[8][2]={{0,1},{1,0},{0,-1},{-1,0},{1,1},{1,-1},{-1,1},{-1,-1}};
//cout<<fixed<<setprecision(12)<<ans<<endl;
//__builtin_popcount(mask)
const int N=200010;
const int M=1e9+7;

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

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

using namespace std;

struct Cake
{
  int w, d;
  Cake(int w, int d) : w(w), d(d) {}
  bool operator < (const Cake& c) const {
    return w*d < c.w*c.d;
  }
};

int main() {
  
  int N, W, D;
  while(cin >> N >> W >> D && (N|W|D)) {
    vector<Cake> cakes;
    cakes.push_back(Cake(W, D));
    while(N--) {
      int p, s; cin >> p >> s; p--;
      Cake cp = cakes[p]; cakes.erase(cakes.begin()+p);
      s %= (cp.w*2 + cp.d*2);
      int angle = -1;
      int rem = s;
      
      for(int i=0; i<2; i++) {
	angle ++;
	rem -= cp.w;
	if(rem < 0) break;
	angle ++;
	rem -= cp.d;
	if(rem < 0) break;
      }
      
      int a = -rem, b = rem + ((angle == 0 || angle == 2)?cp.w:cp.d);
      if(b < a) { swap(a, b); }
      cakes.push_back(Cake((angle == 0 || angle == 2)?a:cp.w, (angle == 0 || angle == 2)?cp.d:a));
      cakes.push_back(Cake((angle == 0 || angle == 2)?b:cp.w, (angle == 0 || angle == 2)?cp.d:b));
    }

    sort(cakes.begin(), cakes.end());
    for(int i=0; i<cakes.size(); i++) {
      if(i) cout << ' ';
      cout << cakes[i].w * cakes[i].d;
    }
    cout << endl;
  }
  
  return 0;
}

Measured memory_bytes: 1196
#include<iostream>
#include<algorithm>
using namespace std;int main(){for(long long i,n,j[99999],s,a;;cout<<a<<endl){cin>>n;if(!n)break;for(i=s=0;i++<n;s+=a)cin>>a;for(i=n;i>1;cin>>j[--i]);for(sort(j+1,j+n);n>0;s+=j[n])a=max(n--*s,a);}return 0;}

Measured memory_bytes: 1684
// by adiforluls
#pragma GCC optimize ("-O2")
#include<bits/stdc++.h>
using namespace std;
#define fastestiointhewest   ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define ll          long long
#define ld          long double
#define pb          push_back
#define mp          make_pair
#define pii         pair<int,int>
#define mii         map<int,int>
#define vi          vector<int>
#define vll         vector<long long>
#define all(a)      (a).begin(),(a).end()
#define clz(a)      __builtin_clz(a) // count leading zeroes
#define ctz(a)      __builtin_ctz(a) // count trailing zeroes
#define popc(a)     __builtin_popcount(a) // count set bits (for ints only diff for ll)
#define lul         1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define SIZE        1000005
#define F           first
#define S           second
#define debug(x)    cerr << #x << " = " << x << endl;
#define mod         998244353

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " = " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " = " << arg1<<" |";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

#define endl        '\n'
const ld PI = acos(-1.0);
const int INF = 0x3f3f3f3f;

void solve()
{ 
   ll r,d,x; cin>>r>>d>>x;
   rep(i,0,10)
   {
     ll cur=r*x-d;
     cout<<cur<<endl;
     x=cur;
   } 
} 
int main()
{   
    fastestiointhewest;
   //  #ifndef ONLINE_JUDGE
     // freopen("input.txt", "r", stdin);
     // freopen("output.txt", "w", stdout);
   //  #endif
    int t; t=1;
    while(t--){
       solve();
    }
    return 0;
}

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

int main() {
    string s;
    int q;

    cin >> s >> q;
    int s_len = s.length();
    vector<char> vs(s_len);
    string before = "";
    string after = "";
    for (int i= 0; i < s_len; i++) {
        vs[i] = s[i];
    }

    int reverse_flg = 0;
    for (int i = 0; i < q; i++) {
        int t;
        cin >> t;
        if(t == 1) {
            if(reverse_flg == 0) {
                reverse_flg = 1;
             } else {
                reverse_flg = 0;
            }
            
            //reverse(vs.begin(), vs.end());
        } else if(t == 2) {
            int f;
            string c;
            cin >> f >> c;
            if(f == 1) {
                if(reverse_flg == 0) {
                    //vs.insert(vs.begin(), c[0]);
                    before = before + c;
                } else {
                    //vs.push_back(c[0]);
                    after = after + c;
                }
                
            } else if(f == 2) {
                if(reverse_flg == 1) {
                    before = before + c;
                    //vs.insert(vs.begin(), c[0]);
                } else {
                    //vs.push_back(c[0]);
                    after =  after + c;
                }
            }
        }
    }
    reverse(before.begin(), before.end());

    string ret = before + s + after;
    if(reverse_flg == 1) {
        reverse(ret.begin(), ret.end());
    }

    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 1620
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<utility>
#include<algorithm>
#include<cstdio>
#include<iomanip>
#include<queue>
#include<stack>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)

using namespace std;

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

    ll N, x;
    cin >> N >> x;
    vector<ll> a(N);
    Rep (i, N) cin >> a[i];

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

    ll ans = 0;
    Rep (i, N) {
        if (x >= a[i]) {
            ans++;
            x -= a[i];
        }
    }

    if (x && ans == N) ans--;
    cout << ans << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define piii pair<int,pii>
#define pll pair<ll,ll>
#define plii pair<ll,pii>
#define vi vector<int>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define lw(vc,num) lower_bound(vc.begin(), vc.end(), num) - vc.begin();
#define hg(vc,num) upper_bound(vc.begin(), vc.end(), num) - vc.begin();
#define bn(v,x) binary_search (v.begin(), v.end(), x)
#define mx 100001
#define eps 0.00000000001
#define mod 1000000007
#define pi acos(-1)
#define inf 100000000
#define loop(i,b,n) for(int i=b;i<n;++i)
#define rev_loop(i,b,n) for(int i=b;i>=n;--i)
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
bool isprime(int n)
{
    if(n == 1) return false;
    if(n == 2 || n == 3) return true;
    if(n%2 == 0 || n%3 == 0) return false;
    for(int i=5; i*i<=n; i+=6){
        if((n%i == 0)||(n%(i+2) == 0)) return false;
    }
    return true;
}
long long binpow(long long a, long long b) {
    if (b == 0)
        return 1;
    long long res = binpow(a, b / 2);
    if (b % 2)
        return res * res * a;
    else
        return res * res;
}
ll ncr(ll x, ll y) {
	ll ans = 1;
	for (ll i = 1; i <= y; ++i) {
		ans *= (x - y + i);
		ans /= i;
	}

	return ans;
}
int main()
{
    fio;
   string s1,s2;
   cin>>s1>>s2;
   cout<<s2<<s1<<endl;
    return 0;
}



Measured memory_bytes: 3596
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.List;

public class Main {

    public static void main(String[] args) throws NumberFormatException, IOException {
        Stdin stdin = new Stdin();
        int n = stdin.nextInt();

        int sum = 0;
        List<Integer> digits = new ArrayList<>();
        for (int i = 1; sum < n; i++) {
            sum += i;
            digits.add(i);
        }

        for (int digit : digits) {
            if (digit != sum - n) {
                System.out.println(digit);
            }
        }
    }

    private static final class Stdin {
        private BufferedReader stdin;
        private ArrayDeque<String> tokens;

        public Stdin() {
            this.stdin = new BufferedReader(new InputStreamReader(System.in));
            this.tokens = new ArrayDeque<>();
        }

        public String nextToken() throws IOException {
            if (tokens.isEmpty()) {
                for (String token : stdin.readLine().split(" ")) {
                    tokens.add(token);
                }
            }
            return tokens.poll();
        }

        public int nextInt() throws NumberFormatException, IOException {
            return Integer.parseInt(nextToken());
        }

        public int nextLong() throws NumberFormatException, IOException {
            return Integer.parseInt(nextToken());
        }
    }
}


Measured memory_bytes: 22484
#include<iostream>
using namespace std;
 
class Cube {
public:
  int f[6];
  Cube(){}
  void roll_z() {
    roll(1,2,4,3);
  }
  void roll_y() {
    roll(0,2,5,3);
  }
  void roll_x() {
    roll(0,1,5,4);
  }
  void roll(int i,int j,int k,int l) {
    int t = f[i];
    f[i] = f[j];
    f[j] = f[k];
    f[k] = f[l];
    f[l] = t;
  }
};
 
bool eq(Cube c1,Cube c2) {
  for (int i=0; i<6; i++) {
    if (c1.f[i]!=c2.f[i]) {
      return false;
    }
  }
  return true;
}
 
bool equal(Cube c1,Cube c2) {
  for (int i=0; i<6; i++) {
    for (int j=0; j<4; j++) {
      if (eq(c1,c2)) {
        return true;
      }
      c1.roll_z();
    }
    if (i%2==0) {
      c1.roll_y();
    } else {
      c1.roll_x();
    }
  }
  return false;
}
 
int main(void) {

		int n,k=0;//K??¨??\?????°
		cin>>n;
  Cube c1, c2;
  for (int i=0; i<6; i++) {
    cin >> c1.f[i];
  }
  for(int i=1;i<n;i++)
  {

  for (int i=0; i<6; i++) {
    cin >> c2.f[i];
  }
  if (equal(c1,c2)) {
	  k++;
	  continue;
  } else {
    continue;
  }
  }
  if(k)
	  cout<<"No"<<endl;
  else
  cout<<"Yes"<<endl;//????????¨2????§£???n??????????¢?
  return 0;
}

Measured memory_bytes: 3104
import sys
sys.setrecursionlimit(700000)

def s_in():
    return input()

def n_in():
    return int(input())

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

def print_l(l):
    print(' '.join(map(str, l)))

class Interval():
    def __init__(self, li):
        self.li = li
        self.n = len(li)
        self.sum_li = [li[0]]
        for i in range(1, self.n):
            self.sum_li.append(self.sum_li[i-1] + li[i])

    def sum(self, a, b=None):
        if b is None:
            return self.sum(0, a)

        res = self.sum_li[min(self.n-1, b-1)]
        if a > 0:
            res -= self.sum_li[a-1]
        return res

import math
print(math.pi*2*n_in())


Measured memory_bytes: 62196
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
static const int fast_io = [](){ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);return 0;}();
static const int precise_doubles = [](){cout<<fixed<<setprecision(20);return 0;}();
typedef pair<int, int> PII;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// find_by_order(k) - iterator to k'th element (0-based), order_of_key(k) - #things < k
typedef long double LD;
typedef long long LL;
#define EVAL(x) x
#define NEWL EVAL({cout << '\n';})
#define SPA(x) EVAL({cout << #x" = " << x << ' ';})
#define SPAR(a, b) EVAL({cout<<#a" = ";for(auto it=a;it!=b;)cout<<*(it++)<<" ";cout<<'\n';})
#define SPAV(v) EVAL({cout<<#v" = ";for(auto it=v.begin();it!=v.end();)cout<<*(it++)<<" ";cout<<'\n';})
const int INF = 0x3f3f3f3f; // 1.0e9
const LL LINF = 0x3f3f3f3f3f3f3f3fll; // 4.5e18
const LD eps = 1e-20;
const int mod = 1e9 + 7;
inline int msum(int x, int y) {return (x+y<mod ? x+y : x+y-mod);}
inline int mdif(int x, int y) {return (x>=y ? x-y : x-y+mod);}
inline int mprod(int x, int y) { return (1ll*x*y) % mod; }
inline int mpow(int x, LL y) {LL r=1;while(y){if(y&1)r=mprod(r,x);x=mprod(x,x);y>>=1;}return r;}
inline int minv(int x) { return mpow(x, mod-2); }
//------------------------------------------------------------------------------------------------------

const int N = 2e5 + 10;

int n;
int color[N], sub[N], under[N];
LL ans[N];
vector<int> adj[N];

void dfs(int u, int par) {
    sub[u] = 1;
    int cu = color[u];
    for (int v : adj[u]) {
        if (v == par) continue;
        int pre_under = under[cu];
        dfs(v, u);
        sub[u] += sub[v];
        LL cnt = sub[v] - (under[cu] - pre_under);
        ans[cu] += cnt + cnt * (cnt - 1) / 2;
        under[cu] += cnt; 
    }
    under[cu]++;
}

int main() {
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> color[i];
    REP(rep, n-1) {
        int u, v; cin >> u >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    dfs(1, 0);
    for (int i = 1; i <= n; i++) {
        LL cnt = n - under[i];
        ans[i] += cnt + cnt * (cnt - 1) / 2;
        cout << n + (LL) n * (n-1) / 2 - ans[i] << '\n';
    }
}






























Measured memory_bytes: 37124
//
// main.cpp
//

#include <algorithm>
#include <array>
#include <assert.h>
#include <complex>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <math.h>
#include <memory>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

using ll = int64_t;
using ull = uint64_t;
constexpr ll LL_MAX = numeric_limits<ll>::max();
constexpr ull ULL_MAX = numeric_limits<ull>::max();

template<typename T>
vector<T> make_vec_nd(T init, ll size) {
    return vector<T>(size, init);
}
template<typename T, typename... Args>
auto make_vec_nd(T init, ll size, Args... rest) {
    auto inner = make_vec_nd(init, rest...);
    return vector<decltype(inner)>(size, inner);
}

#define rep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrep(i, a, b) for (ll i = (a)-1; i >= (b); i--)

int main() {
    string A;
    cin >> A;
    ll N = A.size();
    vector<ll> can_make_all(N+1);
    unordered_set<char> chars;
    ll len = 0;
    rrep(i,N,0) {
        chars.insert(A[i]);
        if (chars.size() == 26) {
            len++;
            chars.clear();
        }
        can_make_all[i] = len;
    }
    ll ans_len = len + 1;
    unordered_map<char, vector<ll>> first_appear_after;
    rep(ci,0,26) {
        char c = 'a' + ci;
        vector<ll> faa(N+1, N);
        ll fa = N;
        rrep(i,N,0) {
            if (A[i] == c) {
                fa = i;
            }
            faa[i] = fa;
        }
        first_appear_after[c] = move(faa);
    }
    string ans;
    ll see_after = 0;
    while (ans.size() < ans_len){
        char c = 'a';
        rep(ci,0,26) {
            c = 'a' + ci;
            ll faa = first_appear_after[c][see_after];
            if (faa == N) {
                break;
            }
            if (can_make_all[faa+1] < ans_len - ans.size() - 1) {
                break;
            }
        }
        ans.push_back(c);
        see_after = min(N, first_appear_after[c][see_after] + 1);
    }
    cout << ans << endl;
}




Measured memory_bytes: 42876
import sys
stdin = sys.stdin
mod = 10**9 + 7

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
sa = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)]

n, m = na()
from_one = [0] * n
to_n = [0] * n

for _ in range(m):
    a, b = na()
    if a == 1:
        from_one[b] = 1
    if b == n:
        to_n[a] = 1

p = False
for i, j in zip(from_one, to_n):
    if i == 1 and j ==1:
        print("POSSIBLE")
        p = True
        break
if not p:
    print("IMPOSSIBLE")
        


Measured memory_bytes: 6260
#include<bits/stdc++.h>
using namespace std;
int main() {
    string s, t;
    cin >> s >> t;
    vector<string>sub;
    for(int i = 0; i<s.size(); i++) {
        string subst = "";
        for(int j = i; j<s.size(); j++){
            subst+=s[j];
            sub.push_back(subst);
        }
    }
    int ans = 10000000;
    int cnt = 0;
    for(auto val : sub) {
        if(val.size()==t.size()){
            //cout << val << endl;
        for(int i = 0; i<t.size(); i++) {
            
                if(val[i]!=t[i]) cnt++;
            
        }
        ans = min(ans, cnt);
        cnt = 0;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 189944
from sys import stdin

n = int(stdin.readline().rstrip())

list = []
i = 0
for i in range(n):
  list.append(stdin.readline().rstrip())

AC = WA = TLE = RE = 0
for k in list:
  if k == 'AC':
    AC = AC + 1
  if k == 'WA':
    WA = WA + 1
  if k == 'TLE':
    TLE = TLE + 1
  if k == 'RE':
    RE = RE + 1
    
print(f'AC x {AC}')
print(f'WA x {WA}')
print(f'TLE x {TLE}')
print(f'RE x {RE}')


    

Measured memory_bytes: 16240
n=int(input())

def Base_10_to_n(X, n):
    X_dumy = X
    out = ''
    while X_dumy>0:
        if X_dumy%n!=0:
            out = str(chr(X_dumy%n+ord('a')-1))+out
            X_dumy = int(X_dumy/n)
        else:
            out = str(chr(n+ord('a')-1))+out
            X_dumy = int(X_dumy/n)-1
    return out
    
ans = Base_10_to_n(n, 26)
print(ans)

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

using namespace std;

int n, k;
int main() {
    scanf("%d%d", &n, &k);
    int tmp = 0, mx = 0;
    for(int i = 0; i < n; i++) {
        int x;
        scanf("%d", &x);
        tmp = __gcd(x, tmp);
        mx = max(mx, x);
    }
    if(k % tmp == 0 && k <= mx) printf("POSSIBLE\n");
    else printf("IMPOSSIBLE\n");
}


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

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める

int main(){
    int a;
    cin >> a;
    int ans = 0;
    ans = a+a*a+a*a*a;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3592
#include <vector>
#include <math.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <deque>

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
#define rep(i, n) for(int i = 0; i<n; i++)
#define rep_s(i, start, n) for(int i= start;  i<n; i++)
#define ALL(a) (a).begin(), (a).end()
string alphabet_upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string alphabet_lower  = "abcdefghijklmnopqrstuvwxyz";

/*
using edge = struct {int to; ll cost;};
vector<edge> tree[limit];
ll depth[limit];

void dfs(int v, int p, ll d){
  depth[v] = d;
  //cout <<"v: " << v << endl;
  for (auto &e: tree[v]){
    //cout << "e.to: " << e.to << endl;
    if (e.to == p) continue;
    dfs(e.to, v, d+e.cost);
  }
}
*/

int main(void){
  string s;
  cin >> s;
  int count = 0;
  rep(i, s.length()/2) if (s[i] != s[s.length()-1-i]) count++;
  cout << count << endl;

    


}


Measured memory_bytes: 888
#include <stdio.h>

int main( void )
{
	char str;
	int i, cnt[26] = { 0 };
	
	while(scanf("%c", &str) != EOF){
		if('a' <= str && str <= 'z'){
			cnt[str-'a']++;
		}
		else if('A' <= str && str <= 'Z'){
			cnt[str-'A']++;
		}
		else{
			// DO NOTHING
		}
	}
	
	for(i = 0; i < 26; i++){
		printf("%c : %d\n", 'a'+i, cnt[i]);
	}
	
	return 0;
}

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

int main() {
    int A, B, C, X, Y;
    cin >> A >> B >> C >> X >> Y;
   
    if(C * 2 < A + B) {
        int ans = 0;

        while(X > 0 && Y > 0) {
            ans += C * 2;
            X--;
            Y--;
        }

        if(X > 0) {
            if(C * 2 < A) {
                ans += (C * 2) * X;
            } else {
                ans += A * X;
            }
        }

        if(Y > 0) {
            if(C * 2 < B) {
                ans += (C * 2) * Y;
            } else {
                ans += B * Y;
            }
        }
        
        cout << ans << endl;
        
    } else {
        cout << A * X + B * Y << endl;
    }

}

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

int main(){
  int n;
  string s;
  cin >> n >> s;
  if(n%2==1){
    cout << "No" << endl;
    return 0;
  }
  for(int i=0;i<n/2;i++){
    if(s[i]!=s[i+n/2]){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef double D;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
 
#define rd(x) scanf("%d",&x)
#define rd2(x,y) scanf("%d %d",&x,&y)
#define rl(x) scanf("%lld",&x)
#define rl2(x,y) scanf("%lld %lld",&x,&y)
#define wd(x) printf("%d" ,x)
#define wd2(x,y) printf("%d %d",x,y)
#define wl(x) printf("%lld",x)
#define wl2(x,y) printf("%lld %lld",x,y)
#define PC(x) putchar(x)
#define GC() getchar()
#define NL printf("\n")
#define SP printf(" ")
 
#define F first
#define S second
#define MP make_pair
#define PB push_back
 
#define fr(i,s,e) for(int i=s;i<e;i++)
#define frr(i,s,e) for(int i=s-1;i>=e;i--)
#define frv(i,a) for(int i = 0;i<(int)a.size();i++)
#define frvr(i,a) for(int i = a.size()-1;i>=0;i--)
#define tr(i,a) for(typeof(a.begin()) i = a.begin(); i != a.end();i++)
int main(){
	ll n;
	rl(n);
	wl(n*(n+1)/2);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main()
{
    int n;
    cin >> n;
    vector <double> v(n);
    for(int i=0;i<n;i++)
    {
        cin >> v[i];
    }
    sort(v.begin(),v.end());
    for(int i=1;i<n;i++)
    {
        v[i]=(v[i]+v[i-1])/2;
    }
    cout << v[n-1] << '\n';
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mod 1000000007
using namespace std;
int n, q, num[3007], p[3007][3007], res;
int main()
{
	cin >> n >> q;
	for (int i = 1; i <= n; i++)
		cin >> num[i];
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= n; j++)
			p[i][j] = num[i] > num[j];
	for (int i = 1, a, b; i <= q; i++)
	{
		cin >> a >> b;
		p[a][b] = p[b][a] = 500000004LL * (p[a][b] + p[b][a]) % mod;
		for (int j = 1; j <= n; j++)
			if (j != a && j != b)
			{
				p[j][a] = p[j][b] = 500000004LL * (p[j][a] + p[j][b]) % mod;
				p[a][j] = p[b][j] = 500000004LL * (p[a][j] + p[b][j]) % mod;
			}
	}
	for (int i = 1; i <= n; i++)
		for (int j = i + 1; j <= n; j++)
			res = (res + p[i][j]) % mod;
	for (int i = 1; i <= q; i++)
		res = (res << 1) % mod;
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 35456
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, s, e) for (ll (i) = (s); (i) < (e); ++(i))
#define per(i, s, e) for (ll (i) = (s); (i) >= (e); --(i))
#define all(x) x.begin(),x.end()

bool isPrime(ll x) {
    if (x == 1) return false;
    if (x == 2) return true;
    if (x % 2 == 0) return false;
    for (int i = 3; i < x; i += 2) {
        if (x % i == 0) return false;
    }
    return true;
}

int main(void) {
    ll x;
    scanf("%lld", &x);
    while (!isPrime(x)) x++;
    printf("%lld\n", x);
}


Measured memory_bytes: 256
let
	n::Int, x::Int = map(x -> parse(Int, x), split(readline()))
	a::Vector{Int} = map(x -> parse(Int, x), split(readline()))
	b::Vector{Int} = copy(a)

	ans::Int = 10^15
	for i in 1:n
		sm::Int = 0
		for j in 1:n
			sm += b[j]
		end
		ans = min(ans, sm + x*(i-1))
		for j in 1:n
			b[j] = min(b[j], a[mod1(j-i, n)])
		end
	end

	println(ans)
end

Measured memory_bytes: 60460
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<map>
#include <algorithm>
#include<cstdlib>
#include<cmath>
#include<deque>
#include <numeric>
#include<valarray>
typedef unsigned long long ull;
typedef  long long ll;

int main() {
	ll n;
	std::string s;
	std::cin >> n ;
	std::cin >> s;
	ll tmp = 0;
	for(int i = 0 ; i < n ; i++)
	{
		if (s[i] == 'R') tmp += 1;
	}

	if (tmp > n / 2) std::cout << "Yes" << std::endl;
	else std::cout << "No" << std::endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using P = pair<int, int>;
using PL = pair<lint, lint>;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
constexpr int MOD = 1000000007;
constexpr lint B1 = 1532834020;
constexpr lint M1 = 2147482409;
constexpr lint B2 = 1388622299;
constexpr lint M2 = 2147478017;
constexpr int INF = 2147483647;
void yes(bool expr) {cout << (expr ? "Yes" : "No") << "\n";}
template<class T>void chmax(T &a, const T &b) { if (a<b) a=b; }
template<class T>void chmin(T &a, const T &b) { if (b<a) a=b; }
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int N;
  cin >> N;
  vector<int> A(N);
  REP(i, N) cin >> A[i];
  REP(i, N) A[i]--;
  vector<int> B(N);
  REP(i, N) cin >> B[i];
  REP(i, N) B[i]--;
  vector<int> cntA(N);
  vector<int> cntB(N);
  vector<int> cnt(N);
  REP(i, N) cntA[A[i]]++;
  REP(i, N) cntB[B[i]]++;
  REP(i, N) cnt[i] = cntA[i] + cntB[i];
  REP(i, N) {
    if(cnt[i] > N) {
      cout << "No" << endl;
      return 0;
    }
  }
  set<P, greater<P>> stA;
  REP(i, N) stA.insert(P(cnt[A[i]], A[i]));
  set<P, greater<P>> stB;
  REP(i, N) stB.insert(P(cnt[B[i]], B[i]));
  vector<int> poi(N);
  IREP(i, N) poi[A[i]] = i;
  vector<int> ans(N);
  while(!stA.empty()) {
    P pa = *stA.begin();
    P pb = *stB.begin();
    if(pa.second == pb.second) pb = *next(stB.begin());
    stA.erase(pa);
    stB.erase(pb);
    //cout << pa.second << " " << pb.second << endl;
    ans[poi[pa.second]] = pb.second;
    poi[pa.second]++;
    cntA[pa.second]--;
    cntB[pb.second]--;
    if(cntA[pa.second] > 0) stA.insert(P(pa.first-1, pa.second));
    if(stB.find(pa) != stB.end()) {
      stB.erase(pa);
      stB.insert(P(pa.first-1, pa.second));
    }
    if(cntB[pb.second] > 0) stB.insert(P(pb.first-1, pb.second));
    if(stA.find(pb) != stA.end()) {
      stA.erase(pb);
      stA.insert(P(pb.first-1, pb.second));
    }
  }
  cout << "Yes" << endl;
  REP(i, N) cout << ans[i]+1 << (i!=N-1 ? " " : "");
  cout << "\n";
}

Measured memory_bytes: 27408
import java.util.*;
import java.lang.*;
import java.io.*;

public class Main{
public static void main (String[] args){
	Scanner sc = new Scanner(System.in);
	int n = Integer.parseInt(sc.next());
	int[] a = new int[n];
	for(int i = 0; i < n; i++){
		a[i] = Integer.parseInt(sc.next());
	}
	Arrays.sort(a);
	System.out.println(a[n/2] - a[(n/2)-1]);
}
}


Measured memory_bytes: 48876
#include<bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007
#define Vi vector<int>
#define Vl vector<long long>
#define pb(a) push_back(a)

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=10000000000000000001;
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};
struct edge{int to,cost;};
struct pos{
	int x,y,cost;
};

int main() {

	int a,b,c,d,e;
	cin>>a>>b>>c>>d>>e;
	if(a==0)cout<<"1"<<endl;
	if(b==0)cout<<"2"<<endl;
	if(c==0)cout<<"3"<<endl;
	if(d==0)cout<<"4"<<endl;
	if(e==0)cout<<"5"<<endl;

	return 0;
}


Measured memory_bytes: 3672
n = int(input())
p = [int(i) for i in input().split()]
ans = 0
for i in range(n):
    if i < n - 1:
        if p[i] == i + 1:
            p[i], p[i+1] = p[i+1], p[i]
            ans += 1
    elif p[i] == i + 1:
        ans += 1
print(ans)


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

int main(){
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int n;
	cin >> n;
	vector<int> v(n);
	for(int i = 0; i < n; i++){
		cin >> v[i];
	}
	sort(v.begin(), v.end());
	if(n % 3 == 0){
		if((v[0] ^ v[n/3] ^ v[n/3*2]) == 0){
			if(v[0] == v[n/3 - 1] && v[n/3] == v[n/3*2-1] && v[n/3*2] == v[n-1]){
				cout << "Yes" << '\n';
				return 0;
			}
		}
	}
	if(v.back() == 0){
		cout << "Yes" << '\n';
		return 0;
	}
	cout << "No" << '\n';
}

Measured memory_bytes: 892
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef long double ld;
const double pi=acos(-1.0);
const ll mod=pow(10,9)+7;
const ll INF=pow(2,31)-1;
using str=string;
typedef pair<int,int> P;
typedef vector<int> vi;

ll gcd(ll x,ll y){
    ll r;
    while((r=x%y) !=0){
        x=y;
        y=r;
    }
    return y;
}

ll lcm(ll x, ll y){
    x /= gcd(x,y);
    y /=gcd(x,y);
    return (x*y);
}

int main(){
    int n;
    cin >>n;
    vector<int> x(n),p(n),q(n);
    rep(i,n) cin >> p[i];
    rep(i,n) cin >> q[i];
    rep(i,n) x[i]=i+1;
    
    map<vector<int>,int> mp;
    do{
        mp[x]=mp.size();
    }
    while(next_permutation(x.begin(),x.end()));
    cout << abs(mp[p]-mp[q])<< endl;
    return 0;
}

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


const ll MAXn=1e5+5,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=ll(1e15);

vector<ll> uni, dt, v;
ll d[MAXn], u[MAXn];
ll n, k, q;

ll cal(){
    ll lt = 0;
    v.clear();
    REP1(i, n+1)
    {
        if(!u[i]){
            vector<ll> tmp;
            for(int j = lt+1;j < i;j ++)tmp.pb(d[j]);
            debug(tmp);
            sort(ALL(tmp));
            if(SZ(tmp) >= k)REP(p, SZ(tmp) - k + 1)v.pb(tmp[p]);
            lt = i;
        }
    }
    debug(v);
    sort(ALL(v));
    if(SZ(v) >= q)return uni[v[q-1]] - uni[v[0]];
    else return INF;
}

int main()
{
    IOS();
    cin>>n>>k>>q;
    REP1(i,n)cin>>d[i], uni.pb(d[i]), dt.pb(i);
    sort(ALL(uni));
    uni.resize(unique(ALL(uni)) - uni.begin());
    REP1(i,n)d[i] = lower_bound(ALL(uni), d[i]) - uni.begin();
    sort(ALL(dt), [](int a,int b){return d[a] < d[b];});
    REP1(i,n)u[i] = 1;
    debug(uni);
    ll mn = cal();
    for(ll t:dt){
        u[t] = 0;
        mn = min(mn, cal());
    }
    cout<<mn<<endl;

}


Measured memory_bytes: 384
/*
    飲んだ魔剤で家が建つ。
    created at: 2020-03-30 17:18:55
*/

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

#define all(x) (x).begin(),(x).end()
#define rev(x) greater<(x)>()
#define MOD 1000000007
#define INF 1000000000

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

LL modpower(LL n, LL m, LL mod) {
    if (m == 0) {
        return 1;
    } else if (m % 2 == 0) {
        LL p = modpower(n, m/2, mod);
        return p*p % mod;
    } else {
        return n*modpower(n, m-1, mod) % mod;
    }
}

LL modinv(LL n, LL mod) {
    return modpower(n, mod-2, mod);
}

LL modcombination(LL n, LL r, LL mod) {
    LL ret = 1;

    for (int i = 0; i < r; i++) {
        ret *= (n-i);
        ret %= mod;
        ret *= modinv(i+1, mod);
        ret % mod;
    }

    return ret % mod;
}

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

int gcd(int k, int l) {
    if (l > 0) return gcd(l, k%l);
    else return k;
}

int main()
{
    int n, X;
    cin >> n >> X;
    vector<int> x(n+1);
    for (int i = 0; i < n; i++)
        cin >> x[i];
    x[n] = X;

    sort(all(x));

    int ans = x[1] - x[0];
    for (int i = 0; i < n; i++)
        ans = gcd(ans, x[i+1]-x[i]);

    cout << ans << endl;

    return 0;
}


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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}

int main2() {
  int N; cin >> N;
  int K; cin >> K;
  string S; cin >> S;
  S[K-1] += ('a' - 'A');
  cout << S << endl;
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
const ll mod =1000000007;
int main(){
    int n,m;
    cin>>n>>m;
    priority_queue<int> a;
    for(int i=0; i<n; i++){
        int aa;
        cin>>aa;
        a.push(aa);
    }
    priority_queue<pair<int,int> > pq;
    for(int j=0; j<m; j++){
        int b,c;
        cin>>b>>c;
        pq.push(make_pair(c,b));
    }
    long long ans =0;
    for(int i=0; i<n; i++){
        long long ta = a.top();
        if(!pq.empty() ){
            long long tb = pq.top().first;
            if(ta>=tb){
                ans += ta;
                a.pop();
            }
            else{
                ans += tb;
                pair<int,int> pa= pq.top();
                pa.second--;
                pq.pop();
                if( pa.second !=0 ) pq.push(pa);
            }
        }
        else{
            ans += ta;
            a.pop();
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1784
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    vector<int>nn(n);
    for(int i=0;i<n;i++)nn[i] = i+1;
    int p[n];
    int q[n];
    for(int i=0;i<n;i++)cin >> p[i];
    for(int i=0;i<n;i++)cin >> q[i];

    int a = -1;
    int b = -1;

    int cnt = 0;
    
    do{
        cnt++;
        if(a==-1){
            bool chk = true;
            for(int i=0;i<n;i++){
                if(nn[i] != p[i]){
                    chk = false;
                    break;
                }
            }
            if(chk){
                a = cnt;
            }
        }

        if(b==-1){
            bool chk = true;
            for(int i=0;i<n;i++){
                if(nn[i] != q[i]){
                    chk = false;
                    break;
                }
            }
            if(chk){
                b = cnt;
            }
        }
    }while(next_permutation(nn.begin(),nn.end()));

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

Measured memory_bytes: 3616
import sys
fin = sys.stdin.readline
from collections import defaultdict


N, M = [int(elem) for elem in fin().split()]
cities = [[int(elem) for elem in fin().split()] for _ in range(M)]
sorted_cities = sorted(cities, key= lambda x: x[1])

num_cities_in_pref = defaultdict(int)
years_to_identification = dict()
for pref, year in sorted_cities:
    num_cities_in_pref[pref] += 1
    years_to_identification[year] = "{:06}{:06}".format(pref, num_cities_in_pref[pref])

for _, year in cities:
    print(years_to_identification[year])


Measured memory_bytes: 43184
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    string c,a,b;
    cin >> a >> b >> c;
    char e = a.at(0);
    char f = b.at(0);
    char g = c.at(0);

    int n = (int)e-32;
    int m = (int)f-32;
    int o = (int)g-32;

    cout << (char)n << (char)m << (char)o << endl;


    
}

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

int main(){
    int K, A, B;
    cin >> K;
    cin >> A >> B;

    for(int i=A; i<=B; i++){
        if(i%K==0){
            cout << "OK" << endl;
            return 0;
        }
    }
    cout << "NG" << endl;

    return 0;
}

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

int main(){
  int n,ans=0;
  cin >> n;
  for(int i=1;i<=n;i++){
    int t=log10(i)+1;
    if(t%2==1)
      ans++;
  }
  cout << ans << endl;
}

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

int main(){
  int N, K;
  cin >> N >> K;
  
  std::vector<long int> enemy(N);
  
  for(int i = 0; i < N; i++){
	cin >> enemy.at(i);
  }
  
  std::sort(enemy.begin(), enemy.end(), std::greater<unsigned int>());
   
  long int total = 0;
  
  for(int i = K; i < N; i++){
    total = total + enemy.at(i);
  }
  
  cout << total << endl;
}
      
  
  


Measured memory_bytes: 1792
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <numeric>

using namespace std;

typedef long long int ll;
typedef long int li;

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



ll find_all(const string str, const string subStr) {
    vector<ll> result;
    ll k=0;
    ll subStrSize = subStr.size();
    ll pos = str.find(subStr);
    
    while (pos != string::npos) {
        k++;
        result.push_back(pos);
        pos = str.find(subStr, pos + subStrSize);
    }
    
    return k;
}

int main() {
    string ans;
    ll a,b,k,n;
    ll ym=0;
    ll my=0;
    k=0;
    string s;
    cin >> n;
    a = n % 100;
    b = (n-a)/100;
    if(a<=12&&a>=1)ym++;
    if(b<=12&&b>=1)my++;
    if(ym==1&&my==0)ans = "YYMM";
    if(ym==0&&my==0)ans = "NA";
    if(ym==1&&my==1)ans = "AMBIGUOUS";
    if(ym==0&&my==1)ans = "MMYY";
    cout << ans << endl;
    return 0;
}



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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n; cin>>n;
	int ans=0;
	for(int i=1;i<=n;++i){
		int j=i,cnt=0;
		while(j){
			j/=10;
			++cnt;
		}
		if(cnt&1)++ans;
	}
	cout<<ans<<"\n"s;
}


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

using namespace std;

ifstream fin("fisier.in");
ofstream fout("fisier.out");

int v[1005];

int main(){
    int n,i,j,answer=0;

    cin>>n;

    for(i=1;i<=n;i++)
        cin>>v[i];

    for(i=1;i<=n;i++)
        for(j=i+1;j<=n;j++)
            answer+=v[i]*v[j];

    cout<<answer;

    return 0;
}


Measured memory_bytes: 256