akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define show(x) cout << #x << " = " << (x) << endl;
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl;
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = 1<<30;
const ll INFLL = 1LL<<60;
//cout << fixed << setprecision(10);

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

ll mod_pow(ll x, ll n, ll mod=INFLL) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * x % mod;
    x = x * x % mod;
    n >>= 1;
  }
  return res;
}

int main () {
  int n, k;
  cin >> n >> k;
  cout << k*mod_pow(k-1, n-1) << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
#include<map>
#include<type_traits>
using namespace std;


typedef long long ll;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)

const int mod = 1000000007;

int main(){
  string s;
  cin >> s;
  bool ans = true;
  rep(i, s.length()){
    if((i + 1) % 2 == 0){
      if(s[i] == 'R') ans = false;
    } else {
      if(s[i] == 'L') ans = false;
    }
  }
  if(ans) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
// Author := Abhishek Giri

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define V(type) vector<(type)>
#define all(c) ((c).begin(),(c).end())
#define in(var) cin>>(var)
#define out(var) cout<<(var)
#define on(var) cout<<var<<"\n"
#define f(i,n) for(ll i = 0 ; i < n ;i++)
#define mfor(i,init,n,b) for(ll i = (init) ; i < (n) ; i+= (b))
#define cfor(i,c) for(auto i = (c).begin() ; i!= (c).end(); i++)
#define el "\n"
#define ret return
#define F first
#define S second
#define YES cout<<"YES\n"
#define NO cout<<"NO\n"

/*##################################################################################*/


/*bool prime[100000] ;
vector < int > pr;
void calculateprime()
{
    prime[0] = prime[1] = true;
    for(int i = 2 ; i <= 100000 ; i++)
    {
        if(prime[i] == false)
        {
            pr.pb(i);
            for(ll j = i*i ; j <= 100000 ; j += i )
            {
                prime[j] = true;
            }
        }
    }
}
*/


void customrun(){
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
}

void fast(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

bool isprime(ll n)
{
    if(n == 1) return false;

    for(ll i = 2 ; (ll) i*i <= n ; i++)
    {
        if(n % i == 0){
            return false;
        }
    }
    return true;
}

ll fib(int n)
{
    ll a = 0, b = 1, c, i;
    if( n == 0)
        return a;
    for (i = 2; i <= n; i++)
    {
        c = (a + b);
        a = b;
        b = c;
    }
    return b;
}


ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

ll extendedgcd(ll a, ll b, ll& x, ll& y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    ll x1, y1;
    ll d = extendedgcd(b, a % b, x1, y1);
    x = y1;
    y = x1 - y1 * (a / b);
    return d;
}

ll findgrouplcm(vector<int> &arr, int n)
{
    ll ans = arr[0];

    for (ll i = 1; i < n; i++)
        ans = (arr[i] * (ans/(gcd(arr[i], ans))));

    return ans;
}


ll powerwithmod(ll x, unsigned ll y, ll p)
{
    ll res = 1;

    x = x % p;

    if (x == 0) return 0;

    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;

        y = y>>1; // y = y/2
        x = (x*x) % p;
    }
    return res;
}


bool comp(const pair < long,long > &a, const pair < long ,long > &b){
    if(a.first == b.first) return a.second < b.second;
    return a.first < b.first;
}

void solve();

int main() {
    clock_t begin = clock();

    fast();
    customrun();
    ll t = 1;
    //cin>>t;
    //calculateprime();
    mfor(i,1,t+1,1)
    {
        //cout<<"Case #"<<i<<": \n";
        solve();
    }
    clock_t end = clock();
    double time_spent = (double)(end - begin) / CLOCKS_PER_SEC;
    //cout<<"\ntime spent is "<<time_spent;
    return 0;
}


void solve(){
    long double d,t,s;
    in(d)>>t>>s;
    if(d/s <= t){
        out("Yes");
    }
    else out("No");
}

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

int main(){
  int N;
  cin >>N;
  
  vector<int> a(N);
  rep(i,0,N) cin>> a[i];
  
  bool flag = true;
  int i = 1;
  int bt = 1;
  int ans;
  while(flag){
    bt = a[bt-1];    
    if(bt==2){
      flag = false;
      ans = i;
    }
    if(i==N){
      flag = false;
      ans = -1;
    }
    i++;
  }
 
  cout <<ans<< endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
#define allR(v) v.rbegin(), v.rend()
#define PRINT(v) for (auto x : (v)) cout <<x <<" " ; cout <<endl;
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
typedef pair<int,int> Pi;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
const int inf = 1001001001;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
template<class T> inline bool chmin(T& a, T b){if (a>b){a = b; return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if (a<b){a = b; return true;}return false;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m=numeric_limits<T>::max()){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}
void hey(){ cout <<"hey" <<endl; }

template<class T> struct edge { int to; T cost;};


int check(vector<pair<ll,ll>> &xy, set<pair<ll,ll>> balls, ll p, ll q){
  ll a = xy[0].first;
  ll b = xy[0].second;
  balls.erase(xy[0]);
  int res = 1;
  while (balls.size() > 0){
    if (balls.count({a+p, b+q})){
      balls.erase({a+p, b+q});
      a += p; b += q;
    }else{
      pair<ll,ll> tmp = *balls.begin();
      balls.erase(tmp);
      tie(a, b) = tmp;
      res++;
    }
  }
  return res;
}

int main() {
  int N; cin >>N;
  vector<pair<ll,ll>> xy(N); rep(i, N) cin >>xy[i].first >>xy[i].second;
  sort(all(xy));
  set<pair<ll,ll>> balls;
  rep(i, N) balls.insert(xy[i]);
  int res = N;
  for (int i=0; i<N; i++){
    for (int j=i+1; j<N; j++){
      ll p = xy[j].first - xy[i].first;
      ll q = xy[j].second - xy[i].second;
      chmin(res, check(xy, balls, p, q));
    }
  }
  cout <<res <<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define dhoom ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);  
typedef long long ll;
typedef long double ld;
const ll inf = 1e18;
const int nax = 2e6 + 7;
const ll mod = 1e9 + 7;
//ll tree[4 * nax];
//9uS-22RSwk7gQqh
ll gcd(ll a , ll b){
	if(b == 0) return a;
	return gcd(b , a % b);	
}
ll lcm(ll a , ll b){
	ll g = gcd(a , b);
	ll lc = (a/g) * b;
	return lc;
}
//char a[55][55];
int dx[] = {1,0,-1,0,1,1,-1,-1};
int dy[] = {0,1,0,-1,1,-1,-1,1};
ll a[100];
int main()
{
	dhoom;
	ll x , y;
	cin >> x >> y;
	int cnt = 0;
	while(x <= y){
		x *= 2LL;
		cnt++;
	}
	cout << cnt << endl;
	return 0;
}


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

#define rep(i,n) for(long long int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define Abs(a,b) max(a,b)-min(a,b)
#define YES(condition) if(condition){cout << "YES" << endl;}else{cout << "NO" << endl;}
#define Yes(condition) if(condition){cout << "Yes" << endl;}else{cout << "No" << endl;}
#define Cout(x) cout<<(x)<<endl
#define POSSIBLE(condition) if(condition){cout << "POSSIBLE" << endl;}else{cout << "IMPOSSIBLE" << endl;}
#define Possible(condition) if(condition){cout << "Possible" << endl;}else{cout << "Impossible" << endl;}
#define possible(condition) if(condition){cout << "possible" << endl;}else{cout << "impossible" << endl;}
#define Size(n) (n).size()

typedef long long ll;


using namespace std;

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


long long int n,cnt=0,ans=0,a,b,c,d,cmp,cmpp,m,h,w,x,y,sum=0,pos;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

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

      
      cin>>n;
      a=n/1000;
      b=n/100;
      b%=10;
      c=n/10;
      c%=10;
      d=n;
      d%=10;
      if((a==b&&b==c)||(b==c&&c==d))Cout("Yes");
      else Cout("No");
     

       
return 0;
}


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

int calcdigit(int a){
    int sum = 0;
    while(a >= 10){
         int r = a%10;
         a = a/10;
         sum = sum + r;
    }
    sum = sum + a;
    return sum;
}

int calcSum(int a){
    int a1 = a/2;
    int a2 = a - a1;
    int min = a;
    for (1;a1>1;){
       int ret = calcdigit(a1) + calcdigit(a2);
       if (ret < min ){
            min = ret;
       }
       a1--;
       a2++;
    }
    return min;
}

int main(){
    int a;
    cin >> a ;
    int c = calcSum(a);
    cout << c;
    return 0;
}

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

int main(){
    long long int n;
    cin>>n;
    long long int ans=0;
    
    if(n%2==1){
        cout<<0<<endl;
    }
    else{
    	long long int f=10;
        for(int i=0;i<50;i++){
            ans=ans+n/(f);
            f=5*f;
        }
        cout<<ans<<endl;
    }


    return 0;
}





Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF 10000000000
using namespace std;
using ll = long long;
int main()
{
    int n;
    cin >> n;
    vector<pair<int,int>> ab,cd;
    map<pair<int, int>, int> mp;
    rep(i,n){
        int a, b;
        cin >> a >> b;
        ab.emplace_back(a, b);
    }
    rep(j,n){
        int c, d;
        cin >> c >> d;
        cd.emplace_back(c, d);
    }
    sort(ab.begin(), ab.end());
    sort(cd.begin(), cd.end());
    int cnt = 0;
    rep(i,n){
        pair<int, int> p = make_pair(cd[i].first, -1);
        auto it = lower_bound(ab.begin(), ab.end(), p);
        for (auto it1 = ab.begin(); it1 < it;it1++){
            auto e = *it1;
            if(e.second >= p.second && e.second < cd[i].second){
                p = e;
            }
        }
        it = find(ab.begin(), ab.end(), p);
        if(it != ab.end()){
            ab.erase(it);
            cnt++;
        }
    }
    cout << cnt << endl;
}


Measured memory_bytes: 256
n,l = map(int,input().split())
alls = int(((2 * l + n - 1) / 2) * n)
if l < 0 and n > -l:
        print(alls)
        exit()
elif l < 0 :
        print(alls - (l + n - 1))
else:
        print(alls - l)

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

using ll = long long;

int main()
{
    int n;
    cin >> n;
    unordered_set<string> items;
    for(int i = 0; i < n; i++) {
        string s;
        cin >> s;
        items.insert(s);
    }
    cout << items.size() << endl;
}


Measured memory_bytes: 17540
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstring>
#include <climits>

using namespace std;

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

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;
constexpr double PI = 3.14159265358979323846;
constexpr int di[] = {0, 0, 1, -1};
constexpr int dj[] = {1, -1, 0, 0};

V g[212345];
int pos = 0;
int dis = 0;

int tree_r_dfs(int o_tr, int p_tr, int d_tr, int &pos_tr, int &dis_tr, vector<int> g_tr[])
{
    int res = d_tr;
    for (int i : g_tr[p_tr])
        if (o_tr != i)
            res = max(res, tree_r_dfs(p_tr, i, d_tr + 1, pos_tr, dis_tr, g_tr));
    if (res > dis_tr)
    {
        pos_tr = p_tr;
        dis_tr = res;
    }
    return res;
}

int tree_r(vector<int> g_tr[])
{
    int pos_tr = 0;
    int dis_tr = 0;
    tree_r_dfs(0, 1, 0, pos_tr, dis_tr, g_tr);
    return tree_r_dfs(0, pos_tr, 0, pos_tr, dis_tr, g_tr);
}

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

    int n;

    cin >> n;
    REP(i, n - 1)
    {
        int a, b;
        cin >> a >> b;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    int r = tree_r(g);

    if (r % 3 == 1)
        cout << "Second" << endl;
    else
        cout << "First" << endl;

    return 0;
}

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

int main(){
  int n;
  cin >> n;
  deque<int> ans;
  int data;
  
  for(int i=0; i<n; i++){
    cin >> data;
    if(i % 2 == (n-1)%2){
      ans.push_front(data);
    }
    else{
      ans.push_back(data);
    }
  }
  for(int i=0; i<n; i++){
    cout << ans[i] << " ";
  }
}

Measured memory_bytes: 3072
#include <stdio.h>
#include <math.h>

int main(){

    double x1,y1,x2,y2,l;
    
    
    scanf("%lf",&x1);
    scanf("%lf",&y1);
    scanf("%lf",&x2);
    scanf("%lf",&y2);
   
   
    // x1=0;y1=0;x2=1,y2=1;
   
    l=sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
    printf("%f",l);
  
    return 0;
}

Measured memory_bytes: 1840
//#include "pch.h"
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <limits.h>
#include <string>
#include <deque>
#include <cmath>
#include <bitset>
#include <complex>
#include <time.h>
#include <stdio.h>

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

#define rip(i, n, s) for (int i = (s);i < (int)( n ); i++)
#define mpa make_pair
#define all(a) a.begin(), a.end()

template<typename T>
void vdeb(vector<T> &da) {
	int size = da.size();
	for (int i = 0;i < size;i++) {
		if (i == size - 1) {
			cout << da[i] << endl;
		}
		else {
			cout << da[i] << ' ';
		}
	}
}
template<typename T>
void vvdeb(vector<T> &da) {
	int size = da.size();
	for (int i = 0;i < size;i++) {
		vdeb(da[i]);
	}
}

int da[1010000];

void zalgo(string &s, int le, int ri){
	da[le] = ri - le;
	int i = le + 1, j = 0;
	while(ri > i){
		while(i + j < ri && s[le + j] == s[i + j]){
			j++;
		}
		da[i] = j;
		if(j == 0){
            i++;
            continue;
        }
		int k = 1;
		while(ri > i + k && k + da[k + le] < j){
			da[i + k] = da[le + k]; ++k;
		}
		i += k; j -= k;
	}
	return;
}


int main(){
	string t,p,s;
	cin >> t >> p;
	s = p+t;
	int n = s.size();
	zalgo(s, 0, n);
	//vdeb(da);
	rip(i,n,p.size()){
		if(da[i] >= p.size()){
			printf("%d\n",int(i-p.size()));
		}
	}
}


Measured memory_bytes: 8980
#include <iostream>
#include <string>
#include <set>
#include <vector>
#include <algorithm>
#include <bitset>
#define ll long long
using namespace std;


int main(){
    int A,B,C;cin>>A>>B>>C;
    int X,Y;cin>>X>>Y;
    ll cost=0;
    int m=min(X,Y);
    // m マイメまでは安い方をとり続ける

    if(A+B >= 2*C){
        cost += 2*C*m;
    } else {
        cost += A*m + B*m;
    }

    X = X-m; Y=Y-m;
    if(X>0){
        if(A>2*C){
            cost += 2*C*X;
        } else {
            cost += A*X;
        }
    }

    if(Y>0){
        if(B>2*C){
            cost += 2*C*Y;
        } else {
            cost += B*Y;
        }
    }

    cout<<cost<<endl;


    return 0;
}

 



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

int main() {
    long long n;
    cin >> n;
    vector<long long> a(n), b(n+1, 0);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        b[a[i]]++;
    }
    long long sum = 0;
    for (int i = 0; i <= n; i++) {
        sum += b[i]*(b[i]-1LL)/2LL;
    }    
    for (int i = 0; i < n; i++) {
        long long x = b[a[i]];
        long long y = x - 1;
        long long ans = sum - x*(x-1LL)/2LL + y*(y-1)/2LL;
        cout << ans << endl;
    }
}

Measured memory_bytes: 6428
import bisect
n,h = map(int,input().split())
v=[list(map(int,input().split())) for i in range(n)]

v = sorted(v, key=lambda x: x[1])

a = []
b = []
for i in range(n):
    a.append(v[i][0])
    b.append(v[i][1])

m = max(a)    
k = bisect.bisect_left(b,m)
b.append(0)

#print(k,m)
#print(sum(b[k::]))

hj = (h-sum(b[k::]))
if hj%m == 0:
    i = 0
else:
    i = 1

if hj <= 0:
    for i in range(n):
        h  = h-b[n-1-i]
        if h <= 0:
            print(i + 1)
            break
else:
    print(hj//m + i + n - k)


Measured memory_bytes: 30036
// I did not understand
// do we need to swap or just print output since we know it

using System;
class MyClass
{
	public static void Main()
    {
		string[] stringArray = Console.ReadLine().Split(' ');
		int x = int.Parse(stringArray[0]);
		int y = int.Parse(stringArray[1]);
		int z = int.Parse(stringArray[2]);

		Console.WriteLine(z + " " + x + " " + y);
    }
}



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

N=int(input())
P = list(map(int,input().split()))


cnt=1
M=P[0]#現在の最小値
for i in range(1,N):
    if(M > P[i]):#Pの値が現在の最小値より小さかったら最小値を更新しcnt++する
        M=P[i]
        cnt+=1



print(cnt)


Measured memory_bytes: 23572
n = int(input())
p = tuple(map(int, input().split()))
ans = 0
for i in range(1, n - 1):
    if (p[i - 1] < p[i] and p[i] < p[i + 1]) or (p[i - 1] > p[i] and p[i] > p[i + 1]):
        ans += 1
print(ans)

Measured memory_bytes: 38384
//khodaya khodet komak kon
#include <bits/stdc++.h>

#define F first
#define S second
#define pb push_back
#define all(x) x.begin(), x.end()
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")


using namespace std;

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

const int N = 200000 + 10;
const ll MOD = 1000000000 + 7;
const ll LOG = 25;

using ll = long long ;
using ld = long double ;
using vll = vector<ll> ;
using vvll = vector<vll> ;
using vc = vector<char> ;
using vvc = vector<vc> ;
using vb = vector<bool> ;
using vvb = vector<vb> ;
using pll = pair<ll,ll> ;
const ll INF = 1e18 ;
const ll mod = 1e9+7 ;
const double pie = acos(-1); 
vll dx4 = {-1,0,1,0} ;
vll dy4 = {0,-1,0,1} ;
vll dx8 = {-1,0,1,1,1,0,-1,-1} ;
vll dy8 = {-1,-1,-1,0,1,1,1,0} ; 
 
void fix_cout(){cout << fixed << setprecision(20) ; }
ll gcd(ll a,ll b){if(b==0) return a ; return gcd(b,a%b) ; }
ll lcm(ll a,ll b){return a/gcd(a,b)*b ; }
template<class T> void chmax(T &a,T b){if(a<b) a = b ; }
template<class T> void chmin(T &a,T b){if(a>b) a = b ; }
 
void solve(){
	ll n ; cin >> n ;
	vll ans(n*n,-1) ;
	ll pos = 0 ;
	vector<pll> a(n) ;
	for(int i=0;i<n;i++){
		cin >> a.at(i).first ;
		a.at(i).second = i+1 ;
		ans.at(a.at(i).first-1) = i+1 ;
	}
	sort(all(a)) ;
	for(int i=0;i<n;i++){
		for(int j=0;j<a.at(i).second-1;j++){
			while(ans.at(pos)!=-1) pos++ ;
			ans.at(pos) = a.at(i).second ;
		}
	}
	reverse(all(a)) ;
	pos = n*n-1 ;
	for(int i=0;i<n;i++){
		for(int j=0;j<n-a.at(i).second;j++){
			while(ans.at(pos)!=-1) pos-- ;
			ans.at(pos) = a.at(i).second ;
		}
	}
	for(int i=0;i<n;i++){
		ll sub = a.at(i).second ;
		pos = -1 ;
		while(sub--){
			pos++ ;
			while(ans.at(pos)!=a.at(i).second) pos++ ;
		}
		if(pos+1!=a.at(i).first){
			cout << "No\n" ;
			return ;
		}
	}
	cout << "Yes\n" ;
	for(int i=0;i<n*n;i++) cout << ans.at(i) << (i==n*n-1?'\n':' ') ;
}
 
int main(){
	solve() ;
}

Measured memory_bytes: 5360
#include<iostream>
using namespace std;
long long int MOD = 1000000007;
long long modpow(long long a, long long n, long long mod);
long long modinv(long long a, long long mod);

int main() {
	
	//E
	long long int n, k;
	cin >> n >> k;
	//k = 1のときは，キャンセルできないのでn-1部屋の場合のみを出力(入力せいやくのためなし)
	//k>=2のときはn,n-1,...,n-k部屋の場合の総和を出力
	//k>=nのとき，1部屋の場合まででよい
	if (k >= n) {
		k = n - 1;
	}
	//cout << 1 << endl;
	int i;
	long long int c1 = 1, c2 = 1;
	long long int sum = 0;
	for (i = n; i >= n - k; i--) {

		//i部屋に人が集まる場合の数
		//i部屋の選び方nCi
		//人の入れ方n-1Ci-1
		sum = (sum + c1 * c2) % MOD;
		c1 = (c1 * i) % MOD;
		c1 = (c1 * modinv(n + 1 - i, MOD) % MOD);
		c2 = (c2 * (i - 1) % MOD);
		c2 = (c2 * modinv(n + 1 - i, MOD) % MOD);

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

	//A
	/*int n, r;
	cin >> n >> r;
	if (n >= 10) {
		cout << r << endl;
	}
	else {
		cout << r + 100 * (10 - n) << endl;
	}
	return 0;
	*/
	//B
	/*int n;
	cin >> n;
	int k;
	cin >> k;
	int i = 0;
	while (n > 0) {
		n = (int)(n / k);
		i++;
	}
	cout << i << endl;
	return 0;*/
	//C
	/*int n;
	cin >> n;
	int x[100];
	int i;
	for (i = 0; i < n; i++) {
		cin >> x[i];
	}
	int sum, j, summin = 100000000;
	for (i = 0; i <= 100; i++) {
		sum = 0;
		for (j = 0; j < n; j++) {
			sum = sum + (x[j] - i) * (x[j] - i);
		}
		if (sum < summin)summin = sum;
	}
	cout << summin << endl;
	return 0;
	*/
	//D
	/*
	long long int n;
	cin >> n;
	long long int a, b;
	cin >> a >> b;
	if (n == 2) {
		cout << 0 << endl;
		return 0;
	}
	long long int sum = 1;
	int i;
	long long int x = 2, m = n;
	//2^nを計算
	while (m > 0) {
		if (m % 2 == 1) {
			sum = (sum * x) % MOD;
		}
		m = (int)(m / 2);
		x = (x * x) % MOD;
	}

	//cout << 1 << endl;
	
	long long int sum1 = 1;
	for (i = 1; i <= a; i++) {
		sum1 = (sum1 * (n + 1 - i)) % MOD;
	}
	for (i = 1; i <= a; i++) {
		sum1 = (sum1 * modinv(i, MOD)) % MOD;
	}
	sum = (sum - sum1 + MOD) % MOD;
	//cout << 2 << endl;

	sum1 = 1;
	for (i = 1; i <= b; i++) {
		sum1 = (sum1 * (n + 1 - i)) % MOD;
	}
	for (i = 1; i <= b; i++) {
		sum1 = (sum1 * modinv(i, MOD)) % MOD;
	}
	sum = (sum - sum1 + MOD) % MOD;
	sum = (sum + MOD - 1) % MOD;
	cout << sum << endl;
	return 0;
	*/
}
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

// a^{-1} mod を計算する
long long modinv(long long a, long long mod) {
	return modpow(a, mod - 2, mod);
}

Measured memory_bytes: 3616
#include <stdio.h>

int main(int argc, const char * argv[]) {
    int m,f,r;
        while (1) {
        scanf("%d %d %d",&m,&f,&r);

        if (m==-1&&f==-1&&r==-1) {
            break;
        }
        else if(m==-1||f==-1){
            printf("F\n");
        }
        else if (m+f>=80) {
            printf("A\n");
        }
        
        else if (65<=m+f&&m+f<80) {
            printf("B\n");
        }
        else if (50<=m+f&&m+f<65) {
            printf("C\n");
        }
        else if (30<=m+f&&m+f<50){
            if (50<=r) {
                printf("C\n");
            }
            else printf("D\n");
        }
        else if (30<=m+f&&m+f<50&&50<=r){
            printf("C\n");
        }
        else if (m+f<30){
            printf("F\n");
        }
       
        
        

        }return 0;}

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

typedef long long ll;
#define pb push_back

int main(){
    int n, w;
    cin >> n >> w;
    int W[110], V[110];
 
    for(int i=0; i<n; i++){
        cin >> W[i] >> V[i];
    }
 
    vector<ll> itm[5];
    ll w1 = W[0];
 
    for(int i=0; i<n; i++){
        itm[W[i]-w1].pb(V[i]);
    }
 
    for(int i=0; i<5; i++) sort(itm[i].begin(), itm[i].end());
 
    for(int i=0; i<5; i++){
        itm[i].pb(0);
        reverse(itm[i].begin(), itm[i].end());
    }
 
    ll cost_max = 0LL;
    for(int i = 0; i < 4; i++) {
    	for(int j = 1; j < itm[i].size(); j++) itm[i][j] += itm[i][j-1];
    }
 
    // unsigned int で0-1はUNSINGED_INTMAX-1になるのでやばい
    for(int i=0; i<itm[0].size(); i++){
        //if(i+1 != itm[0].size()) itm[0][i+1] += itm[0][i];
        for(int j=0; j<itm[1].size(); j++){
            //if(j+1 != itm[1].size()) itm[1][j+1] += itm[1][j];
            for(int k=0; k<itm[2].size(); k++){
                //if(k+1 != itm[2].size()) itm[2][k+1] += itm[2][k];
                for(int l=0; l<itm[3].size(); l++){
                    //if(l+1 != itm[3].size()) itm[3][l+1] += itm[3][l];
                    ll val_sum = itm[0][i] + itm[1][j] + itm[2][k] + itm[3][l];
                    ll sum_W = w1*i + (w1+1)*j + (w1+2)*k + (w1+3)*l;
                    if(sum_W <= w) cost_max = max(val_sum, cost_max);
                }
            }
        }
    }
 
    cout << cost_max << endl;

}


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

using namespace std;

int main(){
    int A,B,C,X,Y; cin>>A>>B>>C>>X>>Y;
  int ans;

    if(2*C<A+B){
    	ans=min(X,Y)*2*C+(X-min(X,Y))*A+(Y-min(X,Y))*B;
      ans=min(max(X,Y)*2*C,ans);
    }else{
    	ans=X*A+Y*B;
    }

    printf("%d",ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PI acos(-1)
#define eq(x,y) (fabs((x)-(y)) < eps)
#define debug(x) cerr<<x<<endl;
#define endl "\n"
#define pb push_back

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int inf=1e9+7;
const int nmax=1e5+10;
const int eps=1e-8;

int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout<<fixed;
    //cout.tie(NULL);
    string s;
    cin>>s;
    int n=s.length();
    stack<char>st;
    int cnt=0;

    for(int i=0;i<n;i++)
    {
        if(st.empty())
            st.push(s[i]);
        else
        {
            if(s[i]!=st.top()){
                cnt+=2;
                st.pop();
            }else
            {
                st.push(s[i]);
            }
        }
    }

    cout<<cnt<<endl;




    return 0;
}


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

long long N, A, B, C, D, E;
int main(){
    cin >> N >> A >> B >> C >> D >> E;
    long long m = min({A, B, C, D, E});
    long long ans;
    if(N % m == 0){
        ans = N / m + 4;
    }else{
        ans = N / m + 5;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
int main()
{
	ios::sync_with_stdio(false);
	int i ,j, k=0;
	while(cin>>i>>j){
	
	k=i*j;
	if(k%2==0)
	cout<<"No"<<endl;
	else 
	if(k%2!=0)
	cout<<"Yes"<<endl;
	
	return 0;
	}
	
}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

signed main(){
    int n,m;
    cin>>n>>m;
    vint deg(n);
    rep(i,m){
        int a,b;
        cin>>a>>b;
        a--;b--;
        deg[a]++;deg[b]++;
    }
    rep(i,n)cout<<deg[i]<<endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n,m,x,sum,ans=1e9;
vector<vector<int> >a;
vector<int>c;
int b;

int main(){
	cin>>n>>m>>x;
	a.resize(n,vector<int>(m));
	c.resize(n);
	for(int i=0;i<n;i++){
		cin>>c[i];
		for(int j=0;j<m;j++)cin>>a[i][j];
	}
	for(int i=0;i<(1<<n);i++){
		for(int j=0;j<m;j++){
			b=0;
			for(int k=0;k<n;k++){
				if(i&(1<<k))b+=a[k][j];
			}
			if(b<x){
				b=-1;
				break;
			}
		}
		if(b!=-1){
			sum=0;
			for(int k=0;k<n;k++){
				if(i&(1<<k))sum+=c[k];
			}
			ans=min(ans,sum);
		}
	}
	if(ans==1e9)cout<<-1;
	else cout<<ans;
	return 0;
}


Measured memory_bytes: 3652
#include <iostream>
#include <vector>
#include <cstring>
#include <algorithm>

using namespace std;
vector<int> primes,sums;
bool isprime[1 << 15];

int main(){
    int n;
    memset(isprime, true, sizeof(isprime));
    for(int i=2;i<(1<<15);++i){
        if(isprime[i]){
            primes.push_back(i);
            for(int j=2;i*j<(1 << 15);++j){
                isprime[i*j] = false;
            }
        }
    }
    int m = primes.size();

    for(int i=0;i<m;++i){
        for(int j=i;j<m;++j){
            sums.push_back(primes[i]+primes[j]);
        }
    }
    sort(sums.begin(), sums.end());
    while(cin >> n && n){
        cout << upper_bound(sums.begin(), sums.end(), n) - lower_bound(sums.begin(), sums.end(), n) << endl;
    }
}

Measured memory_bytes: 31000
import java.util.Scanner;

public class Main {

	public static void main(String args[]) {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int K = sc.nextInt();

		double p = 0;

		for(int i=1;i<=N;i++) {
			double pi = 1;
			int temp = i;
			while(temp < K) {
				pi /= 2;
				temp *= 2;
			}
			p += pi;
		}
		p /= N;
		System.out.println(p);
    }
}

Measured memory_bytes: 22736
import os
import sys
from atexit import register
from io import BytesIO
sys.stdin = BytesIO(os.read(0, os.fstat(0).st_size))
sys.stdout = BytesIO()
register(lambda: os.write(1, sys.stdout.getvalue()))
input = lambda: sys.stdin.readline().rstrip('\r\n')
raw_input = lambda: sys.stdin.readline().rstrip('\r\n')

a,b,c,d = (int(x) for x in input().split())
print(max([a*c,a*d,b*c,b*d]))

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

#define LLINF (1LL<<60)
typedef long long ll;

//C++14 (GCC 5.4.1)
int main() {
    ll N,n;
    cin >>N;
    n=N;
    ll wa=0;
    while(n){
        wa+=n%10;
        n/=10;
    }
    cout << ((N%wa) ? "No" : "Yes") <<endl;
    return (0);
}

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

using namespace std;

vector<bool> starts_with(string s, string t, long long x) {
    int n = (int)s.size(), m = (int)t.size();
    long long prime = 1000000007;
    auto mod = [&](long long a) {
        return (a % prime + prime) % prime;
    };
    x = mod(x);
    if (x == 0) {
        x = 1;
    }
    function<long long (long long, long long)> pow = [&](long long a, long long r) {
        if (r == 0) return 1LL;
        long long y = pow(a, r/2);
        long long z = mod(y * y);
        return r % 2 == 1 ? mod(a * z) : z;
    };
    long long inv_x = pow(x, prime-2);
    long long t_sig = 0LL;
    long long x_pow = 1; // x_pow = x^i during the loop
    for (int i = 0; i < m; ++i) {
        t_sig = mod(t_sig + x_pow * t[i]);
        x_pow = mod(x_pow * x);
    }
    x_pow = 1;
    long long s_sig = 0LL;
    for (int i = 0; i < m; ++i) {
        s_sig = mod(s_sig + x_pow * s[i%n]);
        x_pow = mod(x_pow * x);
    }
    vector<bool> equal(n, false);
    for (int i = 0; i < n; ++i) {
        equal[i] = t_sig == s_sig;
        s_sig = mod(s_sig + x_pow * s[(i+m)%n] - s[i]);
        s_sig = mod(s_sig * inv_x);
    }
    return equal;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
    string s, t;
    cin >> s >> t;
    int n(s.size()), m(t.size());
    vector<bool> equal(n, true);
    for (int k = 0; k < 5; ++k) { // doing 5 checks
        vector<bool> equal_check = starts_with(s, t, rng());
        for (int i = 0; i < n; ++i) {
            equal[i] = equal[i] && equal_check[i];
        }
    }
    bool cycle_found = false;
    vector<int> color(n, -1);
    vector<int> max_length(n, -1);
    function<void (int, int)> dfs = [&](int i, int c) {
        color[i] = c;
        if (!equal[i]) {
            max_length[i] = 0;
            return;
        }
        int j = (i + m) % n;
        if (color[j] == c) {
            cycle_found = true;
        }
        if (color[j] == -1) {
            dfs(j, c);
        }
        max_length[i] = 1 + max_length[j];
    };
    for (int i = 0; i < n; ++i) {
        if (max_length[i] == -1) {
            dfs(i, i);
        }
    }
    if (cycle_found) {
        cout << -1 << endl;
    } else {
        cout << *max_element(max_length.begin(), max_length.end()) << endl;
    }
    return 0;
}


Measured memory_bytes: 28800
N=int(input())
ans=0
for a in range(1,10**6):
    if a>=N:
        break
    for b in range(1,10**6):
        A=a*b
        c=N-A
        if c<=0:
            break
        if 1<=c<=10**6:
            ans+=1
print(ans)

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

int main() {
  int n, k, d;
  cin >> n >> k;
  vector<int> snk(n); 
  for (int i=0 ; i<n ; i++){
    cin >> d;
    for (int j=0; j<d; j++){
      int a;
      cin >> a;
      snk.at(a-1)++ ;
    }
  }
  int count=0;
  for(int i=0 ; i<n ; i++){
    if (snk.at(i) == 0){
      count++;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 3596
#include <iostream>
#include <algorithm>
#include <ios>     // std::left, std::right
#include <iomanip> // std::setw(int), std::setfill(char)
#include <string>

using namespace std;

int main(){
    string S;
    cin >> S;
    for (int i = 0; i < S.length(); i++){
        for (int j = i+1; j < S.length(); j++){
            if (S[i] == S[j]) {
                cout << "no" << endl;
                return 0;
            }
        }
    }
    cout << "yes" << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int i;
	string s,a[7]={"SUN","MON","TUE","WED","THU","FRI","SAT"};
	cin>>s;
	for(i=0;i<=6;i++)
	{
		if(s==a[i])
		{
			if(i==0)cout<<7;
			else cout<<7-i;
			return 0;
		}
	}
	return 0;
}

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

using namespace std;

int main(){
	int n, a, b;
	scanf("%d%d%d", &n, &a, &b);
	vector<int> t(n);
	for(int i = 0; i < n; i++){
		scanf("%d", &t[i]);
	}
	int ans = 0;
	for(int i = 0; i < n; i++){
		if(t[i] < a || t[i] >= b){
			ans++;
		}
	}
	printf("%d\n", ans);
	return 0;
}

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

int main(){
  long double a,b,c;
  cin>>a>>b>>c;
  if((c-a-b)>=0){
    if(4*a*b<(c-a-b)*(c-a-b)){
      cout<<"Yes"<<endl;
    }
    else{
      cout<<"No"<<endl;
    }
  }
  if((c-a-b)<0){
      cout<<"No"<<endl;
  }
}

Measured memory_bytes: 3728
// -----------------------------------
// Author     : MatsuTaku
// Affiliation: Tokushima University
// Country    : Japan
// Date       : 03/21/2020
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

constexpr ll MOD = 998244353;
constexpr ll MAX_GRANDY = 512;

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

  int N; cin>>N;
  vector<int> graph[3][N+1];
  for (int i = 0; i < 3; i++) {
    int M; cin>>M;
    for (int m = 0; m < M; m++) {
      int a,b; cin>>a>>b;
      if (a > b) swap(a,b);
      graph[i][a].push_back(b);
    }
  }

  vector<ll> pw(N+1);
  pw[0] = 1;
  constexpr ll p = ll(1e18)%MOD;
  for (int i = 1; i <= N; i++) {
    pw[i] = pw[i-1]*p%MOD;
  }

  array<array<ll, MAX_GRANDY>, 3> cnt={};
  for (int i = 0; i < 3; i++) {
    vector<int> gr(N+1, 0);
    for (int v = N; v >= 1; v--) {
      bitset<MAX_GRANDY> ps;
      for (auto t : graph[i][v])
        ps[gr[t]] = true;
      while (ps[gr[v]])
        ++gr[v];
      cnt[i][gr[v]] += pw[v];
      cnt[i][gr[v]] %= MOD;
    }
  }

  ll ans = 0;
  for (int i = 0; i < MAX_GRANDY; i++) for (int j = 0; j < MAX_GRANDY; j++) {
    ans += cnt[0][i] * cnt[1][j] % MOD * cnt[2][i^j] % MOD;
    ans %= MOD;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 13824
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define vcout(v) rep(i,v.size()) cout << v[i] << " "; cout << endl
#define mcout(m) rep(j,m.size()){vcout(m[j]);}
const ll MOD = 1e9 + 7;

const int MAX = 1e6; // 適宜
ll fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
// 二項係数計算
ll COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// 逆元 a^{-1} mod m
// aがmの倍数でないことが前提。O(log m)
ll modinv(ll a, ll m=MOD) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
}

struct DP{
	ll val;
	ll sz;
	
	DP(ll val=1, ll sz=0):val(val),sz(sz) {}
	DP operator + (const DP& o) const { // addRootした木に対して行うこと
		DP res = *this;
		(res.val *= o.val) %= MOD;
		(res.val *= COM(res.sz + o.sz, res.sz)) %= MOD;
		res.sz += o.sz;
		return res;
	}
	DP operator - (const DP& o) const {
		DP res = *this;
		(res.val *= modinv(o.val)) %= MOD;
		(res.val *= modinv(COM(res.sz, o.sz))) %= MOD;
		res.sz -= o.sz;
		return res;
	}
	DP addRoot() const {
		DP res = *this;
		res.sz++;
		return res;
	}

};

int mainsolve(){

	// 前処理
    COMinit();

	ll n;
	cin >> n;
	vector<vector<ll>> to(n);
	rep(i,n-1){
		ll a,b;
		cin >> a >> b;
		--a; --b;
		to[a].push_back(b);
		to[b].push_back(a);
	}

	vector<vector<DP>> dp(n); // 2(n-1)
	rep(i,n) dp[i] = vector<DP>(to[i].size());
	vector<DP> dpSum(n);

	// まず0をrootにして普通に木dp
	function<DP(ll,ll)> dfs = [&](ll v, ll p){
		rep(i,to[v].size()){
			ll u = to[v][i];
			if(u != p){
				dp[v][i] = dfs(u,v); // rootを含む木
				dpSum[v] = dpSum[v] + dp[v][i]; // 木をplusする（dpSumにはrootを含めない）
			}
		}
		return dpSum[v].addRoot(); // 戻り値にはrootを含めて木の状態にする
	};
	dfs(0,-1);

	// 各dpSum[v]について、親方向へのノード1個分だけ足せていないので、それを足す
	function<void(ll,ll,DP)> dfs2 = [&](ll v, ll p, DP dpP){
		if(p != -1) dpSum[v] = dpSum[v] + dpP.addRoot(); // 木をplusする（dpSumにはrootを含めない）

		rep(i,to[v].size()){
			ll u = to[v][i];
			DP nextDpP = dpSum[v] - dp[v][i]; // 親vのdpSumから子uへの部分木のdpだけ引く
			if(u != p) dfs2(u, v, nextDpP);
		}

	};
	dfs2(0,-1,DP{1,0});

	rep(i,n) cout << dpSum[i].addRoot().val << endl;
	return 0;

	
}

int main(){

	return mainsolve();
}

Measured memory_bytes: 55280
#include <bits/stdc++.h>
    using namespace std;
     
    int main() {
      int N, M, S, T;
      cin >> N;
      M = N;
      S = 0;
      while(N > 0){
        T = N % 10;
        S += T;
        N = (N - T) / 10;
      }
      if(M % S == 0){
        cout << "Yes" << endl;
      }else{
        cout << "No" << endl;
      }
      
    }

Measured memory_bytes: 256
/// {{{
#include "bits/stdc++.h"
#define   ALL(x)  x.begin(), x.end()
#define   iostreamBooster()  do{cin.tie(nullptr);ios::sync_with_stdio(false);}while(0)
using namespace std;
typedef long long i64;
typedef pair<int,int> pii;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
// }}}

int N;
i64 G[305][305];
i64 tmp[305][305];
bool unNeed[305][305];

void floyd(i64 g[305][305])
{
  for (int k = 0; k < N; ++k) {
    for (int i = 0; i < N; ++i) {
      for (int j = 0; j < N; ++j) {
        chmin(g[i][j], g[i][k] + g[k][j]);
      }
    }
  }
  return;
}

signed main()
{
  cin >> N;

  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < N; ++j) {
      cin >> G[i][j];
      tmp[i][j] = G[i][j];
    }
  }

  floyd(G);

  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < N; ++j) {
      if (G[i][j] != tmp[i][j]) {
        cout << -1 << endl;
        return 0;
      }
    }
  }

  for (int k = 0; k < N; ++k) {
    for (int i = 0; i < N; ++i) {
      for (int j = 0; j < N; ++j) {
        if (G[i][j] == G[i][k] + G[k][j] && i != k && j != k) unNeed[i][j] = true;
      }
    }
  }

  i64 sum = 0;
  for (int i = 0; i < N; ++i) {
    for (int j = i+1; j < N; ++j) {
      if (!unNeed[i][j]) sum += G[i][j];
    }
  }

  cout << sum << endl;

  return 0;
}



Measured memory_bytes: 1792
#include <iostream>
#include <string>
using namespace std;
int main(){
    int H=0;
    int W=0;
    char a;
    char C[1000];
    
    int x=0;
    int y=0;
    
    cin>>H>>W;
    for(y=0;y<H;y++){
        for(x=0;x<W;x++){
            cin>>C[x];
            cout<<C[x];
        }
        cout<<endl;
        for(x=0;x<W;x++){
            cout<<C[x];
        }
        cout<<endl;
    }
    
    
}


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

using namespace std;


int main (void) 
{

  /* Variable_Proclamation */
  int H, W;    // input

  int i, j;    // subscript
  int bomb_i, bomb_j;    // subscript


  /* Input, Array_Proclamation */
  cin >> H >> W;
  vector<string> S(H); // input
  vector< vector<int> > count(H, vector<int>(W, 0));
  vector< vector<char> >  ans(H, vector<char>(W));


  for(i=0; i<H; i++)
  {
    cin >> S.at(i);
  }


  /* Initialize */


  /* Calculation */
  for(i=0; i<H; i++)
  {
    for(j=0; j<W; j++)
    {
      if(S.at(i).at(j) == '#')
      {
        for(bomb_i = i-1; bomb_i <= i+1; bomb_i++)
        {
          for(bomb_j = j-1; bomb_j <= j+1; bomb_j++)
          {

            if( !(bomb_i < 0 || bomb_i > H-1 || bomb_j < 0 || bomb_j > W-1) )
            { 
              if(bomb_i == i && bomb_j == j || count.at(bomb_i).at(bomb_j) == -1)
              {
                count.at(bomb_i).at(bomb_j)  = -1;
              }
              else
              {
                count.at(bomb_i).at(bomb_j) += 1;              
              }
            }
          }
        }
      }
    }
  }

  for(i=0; i<H; i++)
  {
    for(j=0; j<W; j++)
    {

      if(count.at(i).at(j) == -1)
      {
        ans.at(i).at(j) = '#';
      }
      else
      {
        // int → char
        ans.at(i).at(j) = (char)count.at(i).at(j) + '0';
      }
      
    }
  }


  /* Output */
  for(i=0; i<H; i++)
  {
    for(j=0; j<W; j++)
    {

      cout << ans.at(i).at(j);
      if(j == W-1)
      {
        cout << endl;
      }
      
    }
  }

  return 0;

}


Measured memory_bytes: 256
#include<stdio.h>
#define M 31623
long long H,W,A[10],q;
int p[M];
struct{int a,b,n,q;}d[900001];

void f(int a,int b){
	int h,t,i;
	if(1<a&&a<H&&1<b&&b<W){
		i=p[h=(a/M+a+b/M+b)%M];
		if(i){
			for(;;){
				if(d[i].a==a&&d[i].b==b){
					break;
				}else if(d[i].q){
					i=d[i].q;
				}else{
					d[i=d[i].q=++q].a=a;
					d[i].b=b;
					break;
				}
			}
		}else{
			d[i=p[h]=++q].a=a;
			d[i].b=b;
		}
		--A[t=d[i].n++];
		++A[t+1];
	}
}
int main(){
	int a,b,i,j;
	scanf("%lld%lld%d",&H,&W,&i);
	A[0]=(H-2)*(W-2);
	for(;~scanf("%d%d",&a,&b);)
		for(i=-1;i<=1;++i)
			for(j=-1;j<=1;++j)
				f(a+i,b+j);
	for(i=0;i<=9;++i)printf("%lld\n",A[i]);
	return 0;
}


Measured memory_bytes: 14336
#include <iostream>
#include <vector>
#include <string>

using namespace std;

bool solve(const vector<string>& W){
    const int n = W.size();
    //condition 1
    for(int i = 0; i < n-1; ++i){
        if(W[i].back() != W[i+1].front()){
            return false;
        }
    }

    //condition 2
    for(int i = 0; i < n; ++i){
        for(int j = i+1; j < n; ++j){
            if(W[i] == W[j]){
                return false;
            }
        }
    }
    return true;
}

vector<string> input() {
    int n; cin >> n;
    vector<string> W(n);
    for(int i = 0; i < n; ++i){
        cin >> W[i];
    }
    return W;
}

int main(){
    const vector<string> W = input();
    if(solve(W)){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}


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

#define ALL(a) (a).begin(), (a).end()
#define ll long long

using namespace std;

int calc(vector<vector<char> > &m, int b, int r){
    int ret = 0;
    for(int i = 0; i < b; i++){
        for(auto e : m[i])if(e != 'W')ret++;
    }
    for(int i = b; i < r; i++){
        for(auto e : m[i])if(e != 'B')ret++;
    }
    for(int i = r; i < m.size(); i++){
        for(auto e : m[i])if(e != 'R')ret++;
    }
    return ret;
}

signed main(){
    int h,w; cin >> h >> w;
    vector<vector<char> > m(h, vector<char>(w));
    int ans = (int)1e6;
    for(auto &v :m)for(auto &e : v)cin >> e;
    for(int i = 1; i < h-1; i++){
        for(int j = i+1; j < h; j++){
            ans = min(ans, calc(m,i,j));
        }
    }
    cout << ans << endl;

    return 0;
}




Measured memory_bytes: 3140
#include<bits/stdc++.h>
using namespace std;
int main()
{int n,k,q;
 cin>>n>>k>>q;
 int a[n];
 for(int i=0;i<n;i++)
 a[i]=k;
 int qt=q;
 while(q--)
 {
   int x;
   cin>>x;
   a[x-1]+=1;
 }
 for(int i=0;i<n;i++){
   a[i]-=qt;
   if(a[i]>0)
     cout<<"Yes\n";
   else
     cout<<"No\n";
 }
}


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

int main() {
int N,Y;
cin >>N>>Y;

int x=0,y=0,z=0;
z=Y/1000;
if(N>z){x=-1;y=-1;z=-1;}
else if(N<z){   //1000円で払うと多すぎる
while(z>0){
if(x+y+z<N){x=-1;y=-1;z=-1;break;}

if((z+y-N)%9==0){
x=(z+y-N)/9;
z=N-y-x;
break;
}

z-=5;
y++;
}
}

if(z<0 || x+y+z!=N){x=-1;y=-1;z=-1;}
	cout<<x<<" "<<y<<" "<<z<<endl;
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please


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


	int N, M;
	cin >> N >> M;

	int S[5], C[5];
	rep(i, M) {
		cin >> S[i] >> C[i];
	}

	int sita = 1;
	rep(i, N - 1) sita *= 10;
	int ue = sita * 10;
	if (N == 1) sita = 0;

	for (int i = sita; i < ue; i++) {
		int OK = 1;
		rep(j, M) {
			string s = to_string(i);
			if (s[S[j] - 1] != C[j] + '0') OK = 0;
		}
		if (OK) {
			co(i);
			return 0;
		}
	}

	co(-1);

	Would you please return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
#include <sstream>
#define PI 3.14159265358979323846264338327950L
#define ll long long
using namespace std;


int main()
{
    int n, k;
    cin >> n;
    cin >> k;
    vector<int> c(n);
    vector<int> dp(n, 1e9+5);
    dp[0] = 0;
    for(int x = 0; x<n; x++){
        cin >> c[x];
    }
    for(int i=0; i<n; i++){
        for(int j=1; j<=k; j++){
            if(i+j < n){
                dp[i+j] = min(dp[i+j], dp[i] + abs(c[i] - c[i+j]));
            }
        }
    }
    cout << dp[n-1];
}

Measured memory_bytes: 3996
import java.util.Scanner;

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

    boolean[] primes = primes(100000);
    int[] num2017 = new int[100001];
    for (int i = 1; i <= 100000; i++) {
      num2017[i] = num2017[i - 1];
      if (i % 2 == 1 && primes[i] && primes[(i + 1) / 2]) num2017[i]++;
    }

    int Q = scanner.nextInt();
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < Q; i++) {
      int l = scanner.nextInt();
      int r = scanner.nextInt();
      sb.append(num2017[r] - num2017[l - 1]).append('\n');
    }
    System.out.print(sb.toString());
  }

  public static boolean[] primes(int n) {
    boolean[] isNotPrime = new boolean[n + 1];
    isNotPrime[0] = isNotPrime[1] = true;
    for (int i = 2; i < Math.sqrt(n); i++) {
      if (!isNotPrime[i]) {
        for (int j = 2; i * j <= n; j++) {
          isNotPrime[i * j] = true;
        }
      }
    }
    boolean[] isPrime = new boolean[n + 1];
    for (int i = 0; i < n + 1; i++) {
      isPrime[i] = !isNotPrime[i];
    }
    return isPrime;
  }
}


Measured memory_bytes: 65532