akhauriyash/Code-Regression huggingface dataset:
//In the name of Allah
#include <bits/stdc++.h>
using namespace std; 

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

const int maxN = 100 * 1000 + 100; 
vector<pii> c[maxN];
ll ans = 0;
int psum[maxN]; 
int st[maxN], en[maxN], ind; 
int vv[maxN];
int sz[maxN];
int n;

int dfs( int s , int p ) { 
    sz[s] = 1;
    st[s] = ind++; 
    int w = 0;
    for( auto x : c[s] ) 
        if( x.first != p ) 
            sz[s] += dfs( x.first , s ); 
        else
            w = x.second;
    en[s] = ind; 

    if( p != -1 ) { 
        ans += 2ll * w * min( sz[s] , n-sz[s] );
        vv[st[s]] = w;
        //cerr << s + 1 << " " << sz[s] << "   " << st[s] << " " << en[s] << endl;
        if( sz[s] <= n - sz[s] ) { 
            psum[st[s]+1]++;
            psum[en[s]]--;
        }
        if( n - sz[s] <= sz[s] ) { 
            psum[0]++;
            psum[st[s]]--;
            psum[en[s]]++;
            psum[n]--;
        }
    }

    return sz[s];
}


int main() { 
    cin >> n;
    for( int i = 1 ; i < n ; i++ ) { 
        int u, v, w; 
        cin >> u >> v >> w; 
        u--; v--;
        c[u].push_back( { v , w } ); 
        c[v].push_back( { u , w } ); 
    }

    dfs( 0 , -1 ); 

    ll mn = ans + 1; 
    for( int i = 1 ; i < n ; i++ ) { 
        psum[i] += psum[i-1]; 
        if( psum[i] == 0 ) 
            mn = min( mn , (ll) vv[i] ); 
    }
    //cerr << ans << endl;
    cout << ans - mn << endl;
}

Measured memory_bytes: 13056
//Chandigarh University 
//author:- shivamkr21 (pseduo coders)
#include<bits/stdc++.h>
#define endl "\n"
#define lli long long int
#define vint vector<long long int>
#define vvint vector< vector<long long int> >
#define pubk push_back
#define ppbk pop_back
using namespace std;
int main() {
	lli n;
	cin>>n;
	string a,b;
	cin>>a>>b;
	for(lli i=0;i<n;i++) {
		cout<<a[i]<<b[i];
	}
	return 0;
}



Measured memory_bytes: 256
#include<iostream>
using namespace std;
#include<algorithm>
#include<cstring>
#include<stdio.h>
#include<cstdio>
#include<string.h>
#include<cmath>
int lst[110];
bool cmp(int& a, int& b) {
	return a > b;
}
int main() {
	int n;
	int suma=0, sumb=0;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> lst[i];
	}
	sort(lst + 1, lst + n + 1, cmp);
	for (int i = 1; i <= n; i++) {
		if (i % 2 == 1) {
			suma += lst[i];
		}
		else sumb += lst[i];
	}
	cout << suma - sumb << endl;
	return 0;
}

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


int main(){
  int64_t N,H,ans=0;
  cin >> H >> N;
  vector<int64_t> A(N);
  for(int64_t i=0;i<N;i++){
    cin >> A.at(i);
    ans+=A.at(i);
  }
  if(ans<H){
    cout << "No" << endl;
  }else{
    cout << "Yes" << endl;
  }
}

Measured memory_bytes: 1024
#include <cstdio> 

template<long long sieve_N, long long prime_N>
struct primes
{
	bool sieve[sieve_N];
	long long prime[prime_N];
	long long counter = 0;
	constexpr primes() : sieve(), prime()
	{
		for (long long i = 2; i < sieve_N; ++i)
		{
			sieve[i] = true;
		}
		sieve[0] = sieve[1] = false;
		for (long long i = 2; i < sieve_N; ++i)
		{
			if (sieve[i])
			{
				if (i % 5 == 1) prime[counter++] = i;
				if (counter > prime_N)
				{
					break;
				}
			}
			for (long long j = i * i; j < sieve_N; j += i)
			{
				sieve[j] = false;
			}
		}
	}
};

primes<55556, 10000> pr;

int main()
{
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i)
  {
    printf("%lld ", pr.prime[i]);
  }
  putchar('\n');
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  string s;
  cin >> n >> s;

  string a = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  for(int i=0;i<s.size();i++){
  	for(int j=0;j<26;j++){
  		if(s.at(i)==a.at(j)){
  			cout << a.at((j+n)%26);
  			break;
  		}
  	}
  }
  cout << endl;
}

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

int main(){
  int n, x;
  while(true){
    cin >> n >> x;
    if(n == 0 && x == 0){
      break;
    }
    int ans = 0;
    for(int i = 1; i < n + 1; i++){
      for(int j = i + 1; j < n + 1; j++){
        for(int k = j + 1; k < n + 1; k++){
          if(i + j + k == x){
            ans++;
          }
        }
      }
    }

     cout << ans << endl;
  }
}


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


using namespace std;

#define endl '\n'
#define PB push_back
#define MP make_pair
#define LL long long
#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define RE(i,n) FOR(i,1,n)
#define REP(i,n) FOR(i,0,(int)(n)-1)
#define R(i,n) REP(i,n)
#define VI vector<int>
#define PII pair<int,int>
#define LD long double
#define FI first
#define SE second
#define st FI
#define nd SE
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

typedef long long ll;

const int INF = 1e9 + 5;

bool file=0,rt=1;
clock_t tStart ;
void FAST_IO();
////////////////////////

int main() {

    //FAST_IO();
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout << setprecision(5);
    cout << fixed;


    int arr[21];

    int n;
    cin >> n;

    for(int i = 0; i < n; i++) {

        cin >> arr[i];
    }



    int mx = arr[0];
    int cnt = 1;
    for(int i = 1; i < n; i++) {


        if(arr[i] >= mx) {

            mx = arr[i];
            cnt++;
        }


    }

    cout << cnt << endl;




    return 0;
}

void FAST_IO()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    //cout.tie(NULL);
    //cout.setf(ios::fixed);
    //cout.precision(2);
    if(rt && file){ tStart = clock(); }
    if(file){
    #ifndef _offline
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    }
}





Measured memory_bytes: 256
using System;

public class Test
{
	static public void Main( )
	{
		String[] line = Console.ReadLine().Split( ' ' );
		var a = int.Parse( line[0] );
		var b = int.Parse( line[1] );
		if( a < b ) {
			Console.WriteLine( "a < b" );
		} else if( b < a ) {
			Console.WriteLine( "a > b" );			
		} else {
			Console.WriteLine( "a == b" );
		}
		
	}
}

Measured memory_bytes: 5288
n = int(input())
a = list(map(int, input().split()))
cnt = 0
k = 0
for i in range(1, n + 1):
    try:
        while i != a[k]:
            cnt += 1
            k += 1
    except IndexError:
        break
    k += 1

if 1 not in set(a):
    print(-1)
else:
    print(cnt)

Measured memory_bytes: 26148
n = int(input())
a = [int(num) for num in input().split()]

count4 = 0
count2 = 0
for i in range(n):
    if a[i] % 4 == 0:
        count4 += 1
    elif a[i] % 2 == 0:
        count2 += 1

if (count4 >= n // 2) | ((count4 * 2 + count2) >= n):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 14252
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define SIZE 10005
#define NUM 10

struct Info{

	int X,Y;
};

int N;
Info info[SIZE];

double calc_dist(double x1,double y1, double x2,double y2){

	if(fabs(floor(x1/10)-floor(x2/10)) < EPS){

		if(fabs(y1-y2) < EPS){

			return fabs(x1-x2);

		}else{

			return fabs(y1-y2)+min((x1-floor(x1/10)*10)+(x2-floor(x2/10)*10),
					((floor(x1/10)+1)*10-x1)+((floor(x2/10)+1)*10-x2));
		}

	}else if(fabs(floor(y1/10)-floor(y2/10)) < EPS){

		if(fabs(x1-x2) < EPS){

			return fabs(y1-y2);

		}else{

			return fabs(x1-x2)+min((y1-floor(y1/10)*10)+(y2-floor(y2/10)*10),
								((floor(y1/10)+1)*10-y1)+((floor(y2/10)+1)*10-y2));
		}

	}else{

    	return fabs(x1-x2)+abs(y1-y2);
    }
}

int main(){

	scanf("%d",&N);

	int min_add = BIG_NUM,max_add = -BIG_NUM;
	int min_sub = BIG_NUM,max_sub = -BIG_NUM;

	for(int i = 0; i < N; i++){

		scanf("%d %d",&info[i].X,&info[i].Y);

		min_add = min(min_add,info[i].X+info[i].Y);
		min_sub = min(min_sub,info[i].X-info[i].Y);

		max_add = max(max_add,info[i].X+info[i].Y);
		max_sub = max(max_sub,info[i].X-info[i].Y);
	}

	int mid_add = (min_add+max_add)/2,mid_sub = (min_sub+max_sub)/2;
	int base_X = (mid_add+mid_sub)/2,base_Y = (mid_add-mid_sub)/2;


	base_X -= (base_X)%10;
	base_Y -= (base_Y)%10;


	double ans = BIG_NUM;

	for(int x = base_X-NUM; x <= base_X+NUM; x += 10){
		for(double y = base_Y-NUM; y <= base_Y+NUM; y += 0.5){

			double max_dist = -BIG_NUM;

			for(int i = 0; i < N; i++){
				max_dist = max(max_dist,calc_dist(info[i].X,info[i].Y,x,y));
			}
			ans = min(ans,max_dist);
		}
	}

	for(int y = base_Y-NUM; y <= base_Y+NUM; y += 10){
		for(double x = base_X-NUM; x <= base_X+NUM; x += 0.5){

			double max_dist = -BIG_NUM;

			for(int i = 0; i < N; i++){
				max_dist = max(max_dist,calc_dist(info[i].X,info[i].Y,x,y));
			}
			ans = min(ans,max_dist);
		}
	}

	printf("%.10lf\n",ans);

	return 0;
}



Measured memory_bytes: 3312
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=1LL<<60;
const ll mod=1000000007;
int main(void){
    int n;
    cin>>n;
    if(n%10==3) cout<<"bon"<<endl;
    else if(n%10==0||n%10==1||n%10==6||n%10==8) cout<<"pon"<<endl;
    else cout<<"hon"<<endl;
}

Measured memory_bytes: 3632
import java.util.*;

public class Main {
  public static void main(String[] args) {
    @SuppressWarnings("resource")
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int num = findSumOfDigits(N);

    System.out.println(N % num == 0 ? "Yes" : "No");
  }

  public static int findSumOfDigits(int tmp) {
    int ret = 0;
    while (tmp > 0) {
      ret += tmp % 10;
      tmp = tmp / 10;
    }
    return ret;
  }
}


Measured memory_bytes: 23636
#include <iostream>
#include <fstream>
#include <sstream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <string.h>
#include <iomanip>
using namespace std;
 
 
#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define RREP(i,n) for(int (i)=(int)(n)-1;i>=0;i--)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
typedef long long ll;
 
int main() {
 
    ll Q,H,S,D; cin >> Q >> H >> S >> D;
    ll N; cin >> N;
 
    Q *= 4;
    H *= 2;
 
    vector<ll> a(3);
    a[0] = Q;
    a[1] = H;
    a[2] = S;
    sort(a.begin(),a.end());
 
    ll ans = 0;
    if (a[0] * 2 > D) {
    	ans = (N / 2) * D;
    	ans += (N % 2) * a[0];
    } else {
    	ans = N * a[0];
    }
 
    cout << ans << endl;
 
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
	    // write your code here
        Scanner scanner = new Scanner(System.in);

        int[] list = new int[9];

        int n = scanner.nextInt();

        for (int i = 0; i < n; i++) {
            int value = scanner.nextInt() / 400;
            if (value >= 8) {
                list[8]++;
            } else {
                list[value]++;
            }
        }

        int minAns = 0;

        for (int i = 0; i < 8; i++) {
            if (list[i] > 0) {
                minAns++;
            }
        }
        int maxAns = minAns;
        if (list[8] > 0) {
            minAns = Math.max(minAns, 1);
            maxAns += list[8];
        }

        System.out.println(minAns + " " + maxAns);
    }
}

Measured memory_bytes: 21204
#include <iostream>

using namespace std;

int main(){
	double x1,y1,x2,y2,x3,y3,xp,yp;
	double s,t,delta;
	while(cin >> x1 >> y1>> x2>> y2>> x3>> y3>> xp>> yp){
		x2 -= x1;
		y2 -= y1;
		x3 -= x1;
		y3 -= y1;
		xp -= x1;
		yp -= y1;
//		cout << x1 << y1<< x2<< y2<< x3<< y3<< xp<< yp;
		delta = x2*y3 - x3*y2;
//		cout << delta << endl;
		s= (xp*y3-yp*x3)/delta;
		t= (-xp*y2+yp*x2)/delta;
//		cout << s << " " << t << endl;
		if(s > 0 && t > 0 && s+t<1){
			cout << "YES" <<endl;
		}
		else{
			cout << "NO" << endl;
		}
	}


}

Measured memory_bytes: 0
#include <iostream>
using namespace std;
int main(void){
    int a,b;
    cin>>a>>b;
    if(a<b){
        cout<<"a < b"<<endl;
    }
    else if(a>b){
        cout<<"a > b"<<endl;
    }
    else{
        cout<<"a == b"<<endl;
    }
    return 0;
}


Measured memory_bytes: 3092
#include <iostream>
#include <vector>
#define rep(i, n)for(int i=0; i<n; i++)
using ll = long long int;
using namespace std;

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];

    ll sum=0;
    rep(i, n-1){
        if(a[i]>a[i+1]){
            sum += (ll)a[i]-a[i+1];
            a[i+1] += a[i]-a[i+1];
        }
    }

    cout << sum << endl;

    return 0;
}

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

#define PI 3.1415926535897946264338327950288419716939937510L

int main(void)
{
    int A, B, H, M;
    long double theta, ans;
    scanf("%d %d %d %d", &A, &B, &H, &M);
    theta = 2 * PI * ((long double)H / 12.0L + ((long double)M / 60.0L) / 12.0L - (long double)M / 60.0L);
    ans = sqrtl((long double)(A * A + B * B) - 2 * (long double)(A * B) * cosl(theta));
    printf("%20.20Lf\n", ans);
    return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int H;
  int N;
  cin >> H >> N;
  vector<int> vec(N);
  int a = 0;
for (int i = 0; i < N; i++) {
  int b;
  cin >> b;
    a += b;
}
  if(a < H){
    cout << "No" << endl;}
    else{cout << "Yes" << endl;}
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define mod 1000000007
using ll = long long;
using namespace std;
int main(){
  int n,m;
  cin >> n >> m;
  vi s(m), c(m);
  rep(i, m){
    cin >> s[i] >> c[i];
  }
  for(int i = pow(10, n - 1) - 1; i < pow(10, n); i++){
    if(n > 1 && i == pow(10, n - 1) - 1) continue;
    string str = to_string(i);
    bool ok = true;
    rep(j, m){
      if(int(str[s[j] - 1] - '0') != c[j]){
        ok = false;
        break;
      }
    }
    if(ok){
      cout << i << endl;
      return 0;
    }
  }
  cout << "-1" << endl;
}

Measured memory_bytes: 256
s,i,j,f,t,p[5];main(n){for(;({for(i=t=f=0;i<5;f|=1<<p[i++])scanf("%d",p+i),t+=p[i];}),*p;)for(i=0;i<5;i++,puts(14^f&&t%5?&s:"3"))for(j=0;j<5;p[i]-p[j++]?s=n-1&&n+2?50:49:0)n=p[j]-p[i];}

Measured memory_bytes: 0
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>

using namespace std;
int W, H;
char map[105][105];
bool vis[105][105];

void solve(int x, int y, char fruit) {
	vis[x][y] = true;
	int dx[4] = {0, -1, 0, 1};
	int dy[4] = {1, 0, -1, 0};
	int i, j;
	for (i = 0; i < 4; i++) {
		int x1, y1;
		x1 = x + dx[i];
		y1 = y + dy[i];
		if (x1 < H && y1 < W && x1 >= 0 && y1 >= 0 
			&& vis[x1][y1] == false && map[x1][y1] == fruit)
			solve(x1, y1, fruit);
	}
}

int main() {
	while (scanf("%d%d", &H, &W) == 2) {
		if (W == 0 && H == 0) break;
		getchar();
		int i, j;
		for (i = 0; i < H; i++) {
			for (j = 0; j < W; j++) {
				scanf("%c", &map[i][j]);
			}
			getchar();
		}	
		memset(vis, false, sizeof(vis));
		int res = 0;
		for (i = 0; i < H; i++)
		for (j = 0; j < W; j++)
		if (vis[i][j] == false) {
			solve(i, j, map[i][j]);
			res++;
		}
		cout << res << endl;
	}
	return 0;
}

Measured memory_bytes: 2016
#include <bits/stdc++.h>
#define N 200550
#define pb push_back
#define fi first
#define se second
#define si size()
#define ll long long
#define mp make_pair
#define iter ::iterator
#define all(v) v.begin(), v.end()
#define pp pop_back
#define mapiter map<int, int>::iterator
#define forn(i, n) for(int i = 0; i < n; ++i)
#define forn1(i, n) for(int i = 1; i <= n; ++i)
#define forr(i, n)  for(int i = n - 1; i >= 0; --i)
#define forr1(i, n) for(int i = n; i >= 1; --i)
#define form(l, r, i)   for(int i = l; i <= r; ++i)
#define forv(r, l, i)   for(int i = r; i >= l; --i)
#define r0 return 0
#define barnarnar ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define lld long double
#define elif else if
  
const int inf = 1e9 + 7;
const lld EPS = 0.00000001;
const ll modw = 1e9 + 9;
  
using namespace std;

ll a[N];
ll pr[N], s[N];

int main()
{
    barnarnar
    ll k, n;
    cin >> k >> n;
    forn1(i, n)
    {
    	cin >> a[i];
    	pr[i] = pr[i - 1] + a[i] - a[i - 1];
	}
	forr1(i, n)
	{
		if(i == n)	s[i] = k - a[i];
		else	s[i] = s[i + 1] + a[i + 1] - a[i];
	}
	ll ans = 1e17;
	forn1(i, n)	ans = min(pr[i] + s[i + 1], ans);
	ans = min(ans, min(pr[n] - pr[1], s[1] - s[n]));
	cout << ans;
    return 0;
}

Measured memory_bytes: 4992
using System;
using System.Linq;
using System.Collections.Generic;

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var line = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int a = line[0], b = line[1];
            var sa = b - a;
            var west = 1;
            var east = 0;

            for (var i = 2; i < 1000; i++)
            {
                east = west + i;
                if (sa == east - west) break;
                west = east;
            }
            Console.WriteLine(west - a);
        }
    }
}

Measured memory_bytes: 13396
#include <algorithm>
#include <climits>
#include <cmath>
#include <deque>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>

// author:Swastik Banerjee

using namespace std;

typedef long long ll;
#define MOD 1000000007

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



  ll x, y;
  cin >> x >> y;

  ll ans = ceil((long double)(x) / (long double)(y));

  cout << ans << '\n';
}

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

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int inf_int = 1e9 + 100;
const ll inf_ll = 1e15;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef long double dbl;
#define pb push_back
const double pi = 3.1415926535898;
#define dout if(debug) cout
#define fi first
#define se second
#define sp setprecision
#define sz(a) (int(a.size()))
#define all(a) a.begin(),a.end()
bool debug = 0;
const int MAXN = 1e5 + 100;
const int LOG = 20;
const int mod = 1e9 + 7;
const int MX = 1e6 + 100;
typedef long long li;
const li MOD = 1000000000949747713ll;


ll dp[101][101 * 1000];
int w[101], v[101];

void solve() {
    int n, W;
    cin >> n >> W;
    for (int i = 0; i <= n; ++i) {
        for (int j = 0; j < 101 * 1000; ++j) {
            dp[i][j] = inf_ll;
        }
    }
    int sum = 0;
    for (int i = 1; i <= n; ++i) {
        cin >> w[i] >> v[i];
        sum += v[i];
    }

    dp[0][0] = 0;
    for (int i = 1; i <= n; ++i) {
        for (int j = 0; j <= sum; ++j) {
            dp[i][j] = dp[i - 1][j];
            if (j - v[i] >= 0) {
                dp[i][j] = min(dp[i][j], dp[i - 1][j - v[i]] + w[i]);
            }
        }
    }
    int ans = 0;
    for (int j = 0;j<=sum;++j){
        if(dp[n][j] <= W){
            ans = j;
        }
    }
    cout << ans<<"\n";


}

signed main() {
#ifdef zxc
    debug = 1;
    freopen("../input.txt", "r", stdin);
#else

  
#endif //zxc
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cout.setf(ios::fixed);
    cout.precision(20);

    int t = 1;

    while (t--)
        solve();
    dout << endl << (1.0 * clock() / CLOCKS_PER_SEC) << endl;
}


Measured memory_bytes: 80000
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using P   = pair<ll, ll>;
using mat = vector<vector<ll>>;
typedef string::const_iterator State;
class ParseError {};

void IOS() { ios::sync_with_stdio(false), cin.tie(0); }

constexpr ll INF = 1e16;
constexpr ll INM = 114514;
constexpr ll MOD = 1e9 + 7;
constexpr ld EPS = 1e-12;

template <typename T>
void dump(T x) { cout << x << endl; }
void dumpf(ld x, int t) { cout << setprecision(t) << fixed << x << endl; }
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
	fill((T *)array, (T *)(array + N), val);
}
inline ll mod(ll a, ll b) {
	if (a > 0) return a % b;
	if (a % b == 0) return 0;
	ll x = -a / b + 1;
	a += x * b;
	return a % b;
}
ll powm(ll a, ll b, ll c) {
	if (b == 0)
		return 1;
	else if (b % 2 == 0) {
		ll d = powm(a, b / 2, c);
		return (d * d) % c;
	} else
		return (a * powm(a, b - 1, c)) % c;
}
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; }
ll dx[4] = {1, 0, -1, 0};
ll dy[4] = {0, 1, 0, -1};

int main() {
	IOS();
	ll n, k;
	cin >> n >> k;
	vector<ll> a(n), pre(n, 0), pro(n, 0);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < i; j++) {
			if (a[j] < a[i]) pre[i]++;
		}
		for (int j = i + 1; j < n; j++) {
			if (a[j] < a[i]) pro[i]++;
		}
	}
	ll ans = 0;
	for (int i = 0; i < n; i++) {
		ll k1 = ((k + 1) * k / 2) % MOD;
		ll k2 = ((k - 1) * k / 2) % MOD;
		ans += pre[i] * k2;
		ans %= MOD;
		ans += pro[i] * k1;
		ans %= MOD;
		//printf("%d %d\n", pre[i], pro[i]);
	}
	dump(ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <bitset>
#include <cassert>
#include <cstring>
#include <functional>
#include <iomanip>
#include <list>
#include <cmath>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <vector>
// #include <boost/multiprecision/cpp_dec_float.hpp>
// #include <boost/multiprecision/cpp_int.hpp>
using namespace std;
#define REP(i, n) for (int64_t i = 0; i < (int64_t)n; i++)
#define REP_FOR(i, a, b) for (int64_t i = (int64_t)a; i < (int64_t)b; i++)
#define REP_REV(i, a, b) for (int64_t i = (int64_t)a; i > (int64_t)b; i--)
#define FORALL(v) (v).begin(), (v).end()
#define mp(a, b) make_pair(a, b)
#define eb(x) emplace_back(x)
#define F first
#define S second
typedef long long ll;
typedef long double ld;
typedef pair<int64_t, int64_t> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int64_t> vii;
typedef vector<vii> vvii;
const ll mod = 1e9 + 7;
const int64_t infi = 1147483600;
const ll infl = 4e18 + 5;
const char EOL = '\n';
//cout << fixed << setprecision(17) << res << endl;
// const ll MOD = 1000000009;

ll solve(ll v) {
    if(v % 4 == 0)
        return v;
    if(v % 4 == 1)
        return 1L;
    if(v % 4 == 2)
        return v | 1L;
    return 0L;
}

int main() {
    ll a, b;
    cin >> a >> b;
    cout << (solve(a-1)^solve(b)) << endl;
}


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

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010


int main(){
  int N, a[SIZE];

  cin >> N;


  for (int i=0; i<N; i++)
    cin >> a[i];

  sort(a, a+N);

  double ans = a[0];

  for (int i=1; i<N; i++) {
    ans += a[i];
    ans /= 2;
  }

  printf("%.10lf\n", ans);

  return 0;
}


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

#define rep(i,x) for(int i=0;i<x;i++)
#define sor(v) sort(v.begin(),v.end())
#define min_3(a,b,c) min(a,min(b,c))

int SEG[400010];
int siz;

void init(int x){
	siz=1;
	while(siz<x)siz*=2;
	
	rep(i,siz*2-1){
		SEG[i]=0;
	}
}

void add(int k,int x){
	k+=siz-1;
	SEG[k]+=x;
	while(k>0){
		k=(k-1)/2;
		SEG[k]=max(SEG[2*k+1],SEG[2*k+2]);
	}
}

int query(int l,int r,int k){
	if(l==r-1)return l;
	if(SEG[2*k+1]>=SEG[k])return query(l,(l+r)/2,2*k+1);
	return query((l+r)/2,r,2*k+2);
}

int main(){
	int n,r,l;
	cin>>n>>r>>l;
	
	init(n);
	
	static int ret[100010]={0};
	
	int T=0;
	rep(i,r){
		int d,t,x;
		cin>>d>>t>>x; d--;
		
		if(t>T){
			ret[query(0,siz,0)]+=t-T; 
			T=t;
		}
		
		add(d,x);
	}
	ret[query(0,siz,0)]+=l-T;
	
	int RET=0,MAX=0;
	
	rep(i,n){
		if(MAX<ret[i]){ RET=i; MAX=ret[i]; }
	}
	
	cout<<RET+1<<endl;
}

Measured memory_bytes: 2584
//
//  main.cpp
//  Study
//
//  Created by 佐々木勇星 on 2020/03/12.
//  Copyright © 2020 佐々木勇星. All rights reserved.
//

#include <iostream>
#include <vector>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <map>

using namespace std;


int main(int argc, const char * argv[]) {

    int a;
    string s;
    
    cin >> a >> s;
    
    if (a >= 3200) cout << s << endl;
    else cout << "red" << endl;
    
    return 0;
    
}


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


int main()
{
    long n,  m;
    cin >> n >> m;
    double t = 0;
    vector<long> a(n);
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        t += a[i];
    }
    long c = 0;
    t /= 4.0*m;
    for (int i =0; i<n; i++)
    {
        if (a[i] >= t)
            c ++;
    }
    if (c >= m)
        cout << "Yes\n";
    else
        cout << "No\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

bitset<200000> b1[501],b2[501];
void Main() {
  int n,m,q;
  cin >> n >> m >> q;
  rep(i,m) {
    int x,y;
    cin >> x >> y;
    b1[y].set(i);
    b2[x].set(i);
  }
  rep(i,n) b1[i+1]|=b1[i];
  rrep(i,n) b2[i]|=b2[i+1];
  rep(i,q) {
    int x,y;
    cin >> x >> y;
    pr((b2[x]&b1[y]).count());
  }
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 25472
#define M 30100
T[M],t[M];main(I,J,i,j,k,L,r){
for(i=2;i<M;i++)if(!T[i])for(j=i*2;j<M;j+=i)T[j]=1;
for(i=2,j=0;i<M;i++)if(!T[i])t[j++]=i;
for(;scanf("%d",&L),L;printf("%d\n",r))for(r=I=0;(i=t[I])<L;I++)for(J=I;(j=t[J])<=(k=L-i-j);J++)if(!T[k]&&j-i<k&&k<j+i)r++;
exit(0);}

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

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			scanner.nextLine();
			String lStr = scanner.nextLine();
			String[] lStrs = lStr.split(" ");

			List<Integer> list = new ArrayList<>();
			for (String str : lStrs) {
				list.add(Integer.parseInt(str));
			}

			Collections.sort(list);

			int result = 0;
			for (int i = 0; i < list.size(); i += 2) {
				result += Math.min(list.get(i), list.get(i + 1));
			}

			System.out.println(result);
		}
	}

}


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

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

    int ans = 1e9;
    for (int i = 0; i < s.size() - 2; i++) {
        string t = s.substr(i, 3);
        ans = min(ans, abs(753 - stoi(t)));
    }

    cout << ans << endl;

    return 0;
}


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

#define MOD 1000000007
#define ll long long int
#define vi vector<int>
#define vii vector< vector<int> >
#define PI 3.1415926535897932384626433832795

int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int q,h,s,d,n;
	cin >> q >> h >> s >> d >> n;
	vector<pair<long double,long double> > prices (4);
	prices[0] = make_pair(q*8,0.25);
	prices[1] = make_pair(h*4,0.5);
	prices[2] = make_pair(s*2,1);
	prices[3] = make_pair(d,2);
	sort(prices.begin(),prices.end());
	long double get = n;
	ll price = 0;
	if(get > prices[0].second-0.01) {
		int count = get/prices[0].second+0.1;
		price+= count*prices[0].first/2*prices[0].second;
		get-= count*prices[0].second;
	}
	if(get > prices[1].second-0.01) {
		int count = get/prices[1].second+0.1;
		price+= count*prices[1].first/2*prices[1].second;
		get-= count*prices[1].second;
	}
	if(get > prices[2].second-0.01) {
		int count = get/prices[2].second+0.1;
		price+= count*prices[2].first/2*prices[2].second;
		get-= count*prices[2].second;
	}
	if(get > prices[3].second-0.01) {
		int count = get/prices[3].second+0.1;
		price+= count*prices[3].first/2*prices[3].second;
		get-= count*prices[3].second;
	}
	cout << price;
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using lli = long long;
#define rep(i,n) for(int i=0;i<n;i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

lli h, w, n;

int main(void){
	cin >> h >> w >> n;
	vector<lli> a;
	rep(i, n){
		lli ai;
		cin >> ai;
		rep(j, ai)  a.push_back(i+1);
	}
	rep(i, h){
		if(i%2 == 0){
			rep(j, w){
				cout << a[w*i+j] << " ";
			}
		}else{
			rep(j, w){
				cout << a[w*i+w-j-1] << " ";
			}
		}
		cout << endl;
	}
	return 0;
}


Measured memory_bytes: 3740
import java.util.*;

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

        while ((h != 0) || (w != 0)) {
            for (int i = 0; i < h; i++) {

                for (int j = 0; j < w; j++) {
                    System.out.print("#");
                }
                System.out.println("");
            }
            System.out.println("");
            h = scn.nextInt();
            w = scn.nextInt();



        }

        scn.close();


    }
}


Measured memory_bytes: 33156
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define all(v) v.begin(),v.end()
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
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;}

const int L=2e5;
const int INF=1e9;

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

  int N;
  cin>>N;
  vector<int> X(N),Y(N);
  vector<char> C(N);
  rep(i,N) cin>>X[i]>>Y[i]>>C[i];

  int ans=INF;

  vector<vector<int>> urd(2*L+1);
  rep(i,N) if(C[i]=='D') urd[Y[i]-X[i]+L].push_back(X[i]);
  rep(i,2*L+1) sort(all(urd[i]));
  vector<vector<int>> dru(2*L+1);
  rep(i,N) if(C[i]=='U') dru[X[i]+Y[i]].push_back(X[i]);
  rep(i,2*L+1) sort(all(dru[i]));

{
  vector<vector<int>> left(2*L+1);
  rep(i,N) if(C[i]=='L') left[Y[i]].push_back(X[i]);
  rep(i,2*L+1) sort(all(left[i]));

  int ansr=INF;

  rep(i,N){
      if(C[i]!='R') continue;
      {
        int z=lower_bound(all(left[Y[i]]),X[i])-left[Y[i]].begin();
        if(z<left[Y[i]].size()) chmin(ansr,abs(left[Y[i]][z]-X[i])*5);
      }
      {
        int tar=Y[i]-X[i]+L;
        int z=lower_bound(all(urd[tar]),X[i])-urd[tar].begin();
        if(z<urd[tar].size()) chmin(ansr,abs(urd[tar][z]-X[i])*10);
      }
      {
        int tar=Y[i]+X[i];
        int z=lower_bound(all(dru[tar]),X[i])-dru[tar].begin();
        if(z<dru[tar].size()) chmin(ansr,abs(dru[tar][z]-X[i])*10);
      }
  }
  chmin(ans,ansr);
}

  vector<vector<int>> dlu(2*L+1);
  rep(i,N) if(C[i]=='U') dlu[Y[i]-X[i]+L].push_back(X[i]);
  rep(i,2*L+1) sort(all(dlu[i]));
  vector<vector<int>> uld(2*L+1);
  rep(i,N) if(C[i]=='D') uld[X[i]+Y[i]].push_back(X[i]);
  rep(i,2*L+1) sort(all(uld[i]));

{
  int ansl=INF;
  rep(i,N){
      if(C[i]!='L') continue;
      {
        int tar=Y[i]+X[i];
        int z=lower_bound(all(uld[tar]),X[i])-uld[tar].begin();
        z--;
        if(z>=0) chmin(ansl,abs(uld[tar][z]-X[i])*10);
      }
      {
        int tar=Y[i]-X[i]+L;
        int z=lower_bound(all(dlu[tar]),X[i])-dlu[tar].begin();
        z--;
        if(z>=0) chmin(ansl,abs(dlu[tar][z]-X[i])*10);
      }
  }
  chmin(ans,ansl);
}

{
  vector<vector<int>> down(2*L+1);
  rep(i,N) if(C[i]=='D') down[X[i]].push_back(Y[i]);
  rep(i,2*L+1) sort(all(down[i]));

  int ansu=INF;
  rep(i,N){
      if(C[i]!='U') continue;
      {
        int z=lower_bound(all(down[X[i]]),Y[i])-down[X[i]].begin();
        if(z<down[X[i]].size()) chmin(ansu,abs(down[X[i]][z]-Y[i])*5);
      }
  }
  chmin(ans,ansu);
}

  if(ans==INF) cout<<"SAFE"<<endl;
  else cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 70380
from numpy import*
M=10**9+7
m=lambda:map(int,raw_input().split())
n,k=m()
b=eye(n,n,0,'O')
a=matrix([m()for i in b],'O')
while k:b=[b,b*a][k&1];a=a*a%M;k/=2
print sum(b)%M

Measured memory_bytes: 12108
from copy import deepcopy
from sys import exit,setrecursionlimit
import math
from collections import defaultdict,Counter,deque
from fractions import Fraction as frac

setrecursionlimit(1000000)


def main():
	n,k = map(int,input().split())
	ans = frac(float(0))
	scala = frac(1,n)
	for i in range(1,n+1):
		if(i>k):
			ans += frac(float(1)) * scala
		else:
			ans += frac(1,2**(math.ceil(math.log(k/i,2)))) * scala
	print(float(ans))

def zip(a):
	mae = a[0]
	ziparray = [mae]
	for i in range(1,len(a)):
		if(mae != a[i]):
			ziparray.append(a[i])
			mae = a[i]
	return ziparray

def is_prime(n):
	if n < 2: return False

	for k in range(2, int(math.sqrt(n)) + 1):
		if n % k == 0:
			return False

	return True

def list_replace(n,f,t):
	return [t if i==f else i for i in n]

def base_10_to_n(X, n):
	X_dumy = X
	out = ''
	while X_dumy>0:
		out = str(X_dumy%n)+out
		X_dumy = int(X_dumy/n)
	if(out == ''): return '0'
	return out

def gcd(m,n):
	x = max(m,n)
	y = min(m,n)
	while(x%y!=0):
		z = x%y
		x = y
		y = z
	return y

class Queue():
	def __init__(self):
		self.q = deque([])
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.popleft()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class Stack():
	def __init__(self):
		self.q = []
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.pop()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class graph():
	def __init__(self):
		self.graph = defaultdict(list)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
		self.graph[t].append(f)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
		self.graph[t].remove(f)
	def linked(self,f):
		return self.graph[f]

class dgraph():
	def __init__(self):
		self.graph = defaultdict(set)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
	def linked(self,f):
		return self.graph[f]

main()

Measured memory_bytes: 78420
#include <bits/stdc++.h> 
using namespace std; 
int main(){ 
  string T;
  cin >> T;
  for(int i = 0; i<T.size(); i++){
  if(T.at(i) == '?'){
  T.at(i) = 'D';
  }
  }
  cout << T << endl;
}

Measured memory_bytes: 3748
#include <iostream>
#include<algorithm>
using namespace std;
int frog_1(int arr[],int n,int k){
    int dp[n+1];
    dp[1]=0;

    for(int i=2;i<=n;i++){
        dp[i]=INT_MAX;
        for(int j=1;j<=k;j++){
            if( i-j >= 1){
                int sub = abs(arr[i] - arr[i-j]) + dp[i-j];
                dp[i] = min(dp[i],sub);
            }
        }
    }
    return dp[n];
}

int main() {
    int n,k;
    cin>>n>>k;
    int arr[n+1];
    for(int i=1;i<=n;i++){
        cin>>arr[i];
    }
    
    cout<<frog_1(arr,n,k);
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <set>
#define lowbit(x) (x&(-x))
#define MAX(a,b) (a<b?b:a)
#define MIN(a,b) (a<b?a:b)
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
const int N = 1e5;
const int maxn = 3e5 + 5;
ll mod = 1e9 + 7;

int n;
int main()
{
	ll sum = 0;

	scanf("%d", &n);
	while (n--)
	{
		int a, c;

		scanf("%d%d", &a, &c);

		while (a%c)
		{
			int d = a / c;
			int t = max(1, (a - d * c) / (d + 1));
			a -= t * (d + 1);
		}
		sum ^= (a / c);
	}
	if (sum) printf("Takahashi");
	else printf("Aoki");
}

Measured memory_bytes: 256
import java.util.*;
import java.math.*;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int n = sc.nextInt();
		int h = sc.nextInt();
		int w = sc.nextInt();


		// System.out.println(cannotNum);

		System.out.println((n-h+1)*(n-w+1) );



	}
}

Measured memory_bytes: 23252
use proconio::input;
use proconio::marker::{Bytes, Chars};
use std::cmp::{max, min};

fn main() {
    input! {
        n: usize,
        A: [isize; n],
    }
    let mut s = vec![0; n+1];
    let mut ans = std::isize::MAX;
    for i in 0..n {
        s[i+1] = s[i] + A[i];
    }
    let l = s[n];
    for i in 0..n-1 {
        // println!("{} {}", s[i+1], (s[n] - s[i+1]));
        ans = min(ans, (s[i+1] - (l - s[i+1])).abs());
    }
    println!("{}", ans);
}

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

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }

  vector<bool> dp(k + 1);
  for (int i = 0; i <= k; i++) {
    if (dp[i] == false) {
      for (int j = 0; j < n; j++) {
        if (i + a[j] <= k) {
          dp[i + a[j]] = true;
        }
      }
    }
  }
  cout << (dp[k] ? "First" : "Second") << '\n';

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <functional>

using namespace std;

#define mp make_pair
#define pb push_back
#define ll long long

#define maxN 511 * 511

int n, i, j, cnt[maxN];
int x[maxN];
vector<int> be, af;

int sol[maxN];


int main()
{
    //freopen("test.in","r",stdin);

    scanf("%d", &n);
    for (i = 1; i <= n; i++) {
        scanf("%d", &x[i]);
        sol[x[i]] = i;
        for (j = 1; j < i; j++) be.pb(i);
        for (j = i + 1; j <= n; j++) af.pb(i);
    }

    auto cmp = [](int a, int b)->bool const {
        return x[a] < x[b];
    };

    sort(be.begin(), be.end(), cmp);
    sort(af.begin(), af.end(), cmp);
    for (auto e : af) be.pb(e);

    reverse(be.begin(), be.end());
    for (i = 1; i <= n * n; i++) {
        if (sol[i]) {
            cnt[sol[i]]++;
            if (cnt[sol[i]] != sol[i]) {
                printf("No");
                return 0;
            }
        } else {
            sol[i] = be.back();
            be.pop_back();
            cnt[sol[i]]++;
        }
    }

    printf("Yes\n");
    for (i = 1; i <= n * n; i++) printf("%d ", sol[i]);

    return 0;
}


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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

template <int mod>
struct ModInt {
    ll x;
    ModInt() : x(0) {}
    ModInt(ll y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
    ModInt &operator+=(const ModInt &p) { if((x += p.x) >= mod) x -= mod; return *this; }
    ModInt &operator-=(const ModInt &p) { if((x += mod - p.x) >= mod) x -= mod; return *this; }
    ModInt &operator*=(const ModInt &p) { x = 1LL * x * p.x % mod; return *this; }
    ModInt &operator/=(const ModInt &p) { *this *= p.inverse(); return *this; }
    ModInt operator-() const { return ModInt(-x); }
    ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
    ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
    ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
    ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
    bool operator==(const ModInt &p) const { return x == p.x; }
    bool operator!=(const ModInt &p) const { return x != p.x; }
    ModInt inverse() const {
        ll a = x, b = mod, u = 1, v = 0, t;
        while(b > 0) {
            t = a / b;
            swap(a -= t * b, b);
            swap(u -= t * v, v);
        }
        return ModInt(u);
    }
    ModInt pow(ll n) const {
        ModInt ret(1), mul(x);
        while(n > 0) {
            if(n & 1) ret *= mul;
            mul *= mul;
            n >>= 1;
        }
        return ret;
    }
    friend ostream &operator<<(ostream &os, const ModInt &p) {
        return os << p.x;
    }
    friend istream &operator>>(istream &is, ModInt &a) {
        int64_t t;
        is >> t;
        a = ModInt<mod>(t);
        return (is);
    }
};
const int mod = 1000000007;
using mint = ModInt<mod>;

template <typename T>
struct Combination {
    vector<T> _fac, _finv, _inv;

    Combination(int n) : _fac(n+1), _finv(n+1), _inv(n+1){
        _fac[0] = _finv[n] = _inv[0] = 1;
        for (int i = 1; i <= n; ++i) _fac[i] = _fac[i-1] * i;
        _finv[n] /= _fac[n];
        for (int i = n-1; i >= 0; --i) _finv[i] = _finv[i+1] * (i+1);
        for (int i = 1; i <= n; ++i) _inv[i] = _finv[i] * _fac[i-1];
    }
    inline T fac(int k) const { return _fac[k]; }
    inline T finv(int k) const { return _finv[k]; }
    inline T inv(int k) const { return _inv[k]; }

    T perm(int n, int k) const {
        return (k < 0 || n < k) ? 0 : fac(n) * finv(n-k);
    }
    T comb(int n, int k) const {
        return (k < 0 || n < k) ? 0 : fac(n) * finv(k) * finv(n-k);
    }
};
Combination<mint> C(2000010);

int main(){
    int r1, c1, r2, c2;
    cin >> r1 >> c1 >> r2 >> c2;

    mint res = 0;
    for (int i = r1; i <= r2; ++i) {
        res += C.comb(i+1+c2, c2) - C.comb(i+1+c1-1, c1-1);
    }
    cout << res  << endl;
}

Measured memory_bytes: 50012
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {
	static class shop implements Comparable<shop>{
		shop(String name,int point,int number){
			this.name=name;
			this.point=point;
			this.number=number;
		}
		String name;
		int point;
		int number;

		public int compareTo(shop obj) {
				int r1=this.name.compareTo(obj.name);
				if(r1!=0) {
					return r1;
				}
				return obj.point-this.point;
		}
	}
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		ArrayList<shop> array = new ArrayList<>();
		for(int i=1;i<=n;i++) {
			shop temp = new shop(sc.next(),sc.nextInt(),i);
			array.add(temp);
		}

		Collections.sort(array);
		for(int i=0;i<n;i++) {
		System.out.println(array.get(i).number);
		}
	}
}


Measured memory_bytes: 21204
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
input:
6
1 2 2 3
2 2 3 4
3 1 5
4 1 6
5 1 6
6 0

output:
1 1 12
2 2 11
3 3 8
4 9 10
5 4 7
6 5 6
"""
import sys
from collections import deque

UNVISITED, VISITED_IN_STACK, POPPED_OUT = 0, 1, 2


def generate_adj_matrix(v_info):
    for v_detail in v_info:
        v_index, adj_num, *adj_list = map(int, v_detail)
        # assert len(adj_list) == adj_num
        init_adj_table[v_index].extend(sorted(adj_list))
    return init_adj_table


def graph_dfs(v_init):
    global time

    # init the first node of overall graph iterations(times >= 1)
    stack.append(v_init)
    color[v_init] = VISITED_IN_STACK
    d_time[v_init] += time
    # init end

    while len(stack) > 1:
        current = stack[-1]
        v_table = adj_table[current]
        adj = v_table.popleft() if v_table else None

        if adj:
            if color[adj] is UNVISITED:
                color[adj] = VISITED_IN_STACK
                time += 1
                d_time[adj] += time
                stack.append(adj)
        else:
            stack.pop()
            color[current] = POPPED_OUT
            time += 1
            f_time[current] += time

    return None


def dfs_start():
    global time
    for i in range(vertices_num):
        if color[i + 1] == UNVISITED:
            # print('round: ', i + 1)
            graph_dfs(i + 1)
            time += 1


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    vertices_num = int(_input[0])
    vertices_info = map(lambda x: x.split(), _input[1:])
    init_adj_table = tuple(deque() for _ in range(vertices_num + 1))
    # assert len(vertex_info) == vertex_num

    # config length = (vertex_num + 1)
    stack = [-1]
    color = [UNVISITED] * (vertices_num + 1)
    d_time, f_time = ([0] * (vertices_num + 1) for _ in range(2))

    adj_table = generate_adj_matrix(vertices_info)
    # timing start from 1
    time = 1
    dfs_start()
    for k, v in enumerate(zip(d_time[1:], f_time[1:]), 1):
        print(k, *v)

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

int main() {
  int N;
  int x;
  vector<int> X;
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> x;
    X.push_back(x);
  }

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

  int finalEnergy = 1000000;

  for (int P = X[0]; P <= X[X.size() - 1]; P++) {
    int recentSum = 0;
    for (int i = 0; i < N; i++) {
      recentSum += pow(X[i] - P, 2.0);
    }
    if (recentSum < finalEnergy) {
      finalEnergy = recentSum;
    }
  }

  cout << finalEnergy << endl;
}

Measured memory_bytes: 256
n = int(input())
ans = 0
cnt_ba = 0
cnt_a = 0
cnt_b = 0
for _ in range(n):
    s = str(input())
    ans += s.count('AB')
    if s[-1] == 'A' and s[0] == 'B':
        cnt_ba += 1
    elif s[-1] == 'A':
        cnt_a += 1
    elif s[0] == 'B':
        cnt_b += 1
if n >= 2:
    if cnt_a == cnt_b == 0:
        ans += max(0, cnt_ba - 1)
    else:
        ans += min(cnt_a, cnt_b) + cnt_ba
print(ans)


Measured memory_bytes: 3064
def main():

    X, Y = map(int, input().split())
    if X + Y <= 1: # no further move possible at the begining
        return "Brown"
    elif abs(X-Y) <= 1: # opponent's next turn satisfies abs(X-Y) > 1
        return "Brown"
    else: # can always choose such that the opponent's next turn satisfied abs(X-Y) <= 1
        return "Alice"  

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

Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
const LL mod=1000000007;
const LL LINF=1LL<<62;
const int INF=1<<30;
int dx[]={1,0,-1,0,1,-1,1,-1};
int dy[]={0,1,0,-1,1,-1,-1,1};


int main(){
    int k,a,b;cin >> k >> a >> b;
    for (int i = a; i <= b; i++) {
        if(i % k == 0){
            puts("OK");
            return 0;
        }
    }
    puts("NG");
    return 0;
}


Measured memory_bytes: 3592
#include <iostream>
#include<stdio.h>
#include<stdlib.h>
#include<vector>
#include<algorithm>

using namespace std;

int main()
{
	int S;
	cin >> S;
	int a, b;
	a = S / 100;	//前
	b = S % 100;	//あと

	if (a >= 0 && a <= 99)	//前が99以下
	{
		if (a <= 12 && a >= 1)//前が1~12
		{
			if (b <= 12 && b >= 1)
			{
				cout << "AMBIGUOUS";
				return 0;
			}

			if (b <= 99 && b >= 0)
			{
				cout << "MMYY";
				return 0;
			}


		}

		if (b > 0 && b <= 12)
		{
			cout << "YYMM";
			return 0;
		}
	}

	cout << "NA";
	return 0;
}

Measured memory_bytes: 256