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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repp(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perr(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)

typedef long long LL;
typedef long double LD;

class UnionFind{
private:
  vector<int> node;
public:
  UnionFind(int n): node(n){
    iota(all(node),0);
  }
  int root(int x){
    if(x==node[x]) return x;
    else return node[x]=root(node[x]);
  }
  bool uni(int x, int y){
    x=root(x);
    y=root(y);
    if(x==y) return false;
    node[x]=y;
    return true;
  }
};

struct edge{
  int u;
  int v;
  int w;
};

int main(){
  while(1){
    int n,m;
    cin >> n >> m;
    if(n==0) return 0;
    vector<edge> e(m);
    rep(i,m){
      cin >> e[i].u >> e[i].v >> e[i].w;
      e[i].u--;
      e[i].v--;
    }
    sort(all(e),[](const edge &l, const edge &r){
      return l.w < r.w;
    });
    int ans=IINF;
    rep(i,m){
      UnionFind uf(n);
      int count=0;
      repp(j,i,m){
        if(uf.uni(e[j].u,e[j].v)) count++;
        if(count==n-1){
          ans=min(ans,e[j].w-e[i].w);
          break;
        }
      }
    }
    if(ans==IINF) cout << -1 << endl;
    else cout << ans << endl;
  }
  return 0;
}



Measured memory_bytes: 3108
import 'dart:io';
 
void main(List<String> args) {
  String S = stdin.readLineSync();
  String T = stdin.readLineSync();
  String ans = "Yes";
  for(int i=0; i<S.length; ++i){
  	if(S[i]!=T[i]){
      ans = "No";
      break;
    }
  }
  print(ans);
}

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

namespace HABIT{
    #define f(a,b,c,d) for(register int a=b,c=d;a<=c;a++)
    #define g(a,b,c,d) for(register int a=b,c=d;a>=c;a--)
    #define LOCAL
    typedef int i32;
    typedef unsigned int u32;
    typedef long long int i64;
    typedef unsigned long long int u64;
    typedef pair<i32,i32> pii;
    const i32 MAXN=1024;
    typedef i32 ar[MAXN];
    
    template<typename T> inline T Max(T a) { return a; }
    template<typename T,typename... Args> inline T Max(T a,Args... args){
        T b=Max(args...);
        return (a>b)?a:b;
    }
    template<typename T> inline T Min(T a) { return a; }
    template<typename T,typename... Args> inline T Min(T a,Args... args){
        T b=Min(args...);
        return (a<b)?a:b;
    }

    #ifdef LOCAL
        inline char gc() { return getchar(); }
    #else
        inline char gc() {
            static char s[1<<20|1]={0},*p1=s,*p2=s;
            return (p1==p2)&&(p2=(p1=s)+fread(s,1,1<<20,stdin),p1==p2)?EOF:*(p1++);
        }
    #endif
    inline i64 read(){
        register i64 ans=0;register char c=gc();register bool neg=0;
        while(c<48||c>57) neg^=!(c^'-'),c=gc();
        while(c>=48&&c<=57) ans=(ans<<3)+(ans<<1)+(c^48),c=gc();
        return neg?-ans:ans;
    }

    char Output_Ans[1<<20|1],*Output_Cur=Output_Ans;
    inline void output() { Output_Cur-=fwrite(Output_Ans,1,Output_Cur-Output_Ans,stdout); }
    inline void print(char c){
        if(Output_Cur-Output_Ans+1>>20) output();
        *(Output_Cur++)=c;
    }
    inline void print(char *s) { while(*s) print( *(s++) ); }
    inline void print(u64 x){
        if(!x) { print('0'); return ; }
        char buf[30]={0},*p=buf+28;
        while(x) *(p--)=x%10+48,x/=10;
        print(p+1);
    }
    inline void print(u32 x) { print( (u64)x ); }
    inline void print(i64 x){
        if(x<0) print('-'),x=-x;
        print( (u64)x );
    }
    inline void print(i32 x){
        if(x<0) print('-'),x=-x;
        print( (u64)x );
    }
}
using namespace HABIT;

int main(){
    i32 N=read(),M=read();
    for(register i32 i=M,j=1;i>=1;i-=2,j++){
        print(j);
        print(' ');
        print(i+j);
        print('\n');
    }
    for(register i32 i=M-1,j=N;i>=1;i-=2,j--){
        print(j);
        print(' ');
        print(j-i);
        print('\n');
    }
    output();
    return 0;
}

Measured memory_bytes: 4580
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#define LL long long
#define Max(a,b) (a>b?a:b)
using namespace std;
const int MAXN = 55;
LL A[MAXN], K1, K, N, ans=0;

int main()
{
	cin>>N>>K1;
	LL i, j, l, r, fang, na;
	for(i=1;i<=N;i++) scanf("%lld", &A[i]);
	for(K=0;K<=K1;K++) {
		for(l=0;l<=K;l++) {
			for(r=0;r<=K-l && l+r<=N;r++) {
				vector<int> V;
				for(i=1;i<=l;i++) V.push_back(A[i]);
				for(j=0;j<r;j++) V.push_back(A[N-j]);
				sort(V.begin(), V.end());
				LL num = 0;
				fang = K-l-r;
				for(i=fang;i<V.size();i++) {
					num+=V[i];
				}
				ans = Max(ans, num);
			}
		}
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define MOD 1000000007
typedef long long ll;

using namespace std;

int main() {
  int n;
  cin >> n;
  FOR(i, 3, n+1) {
    int x = i;
    if (i % 3 == 0) {
      cout << " " << i;
    } else {
      do{
          if(x % 10 == 3){
            cout << " " << i;
            break;
          }
          x /= 10;
      }
      while(x);
    }
  }

  cout << "\n";
}


Measured memory_bytes: 3100
num_animals, num_legs = list(map(int, input().split()))

num_turtles = (num_legs / 2) - num_animals
num_cranes = num_animals - num_turtles

ans = 'Yes'

if num_turtles < 0 or num_animals < num_turtles:
    ans = 'No'

if num_cranes < 0 or num_animals < num_cranes:
    ans = 'No'

if (num_legs % 2) != 0:
    ans = 'No'

print(ans)


Measured memory_bytes: 9040
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC_C
{
    class C065
    {
        static int _Mod = 1000000007;

        static void Main(string[] args)
        {
            string[] s1 = Console.ReadLine().Split(' ');
            int N = int.Parse(s1[0]);
            int M = int.Parse(s1[1]);
            long count = 0;
            if(N>M+1 || M > N + 1)
            {
                count = 0;
            }
            else if (N == M)
            {
                long c = Factorial(N)[N] % _Mod;
                count = 2 * c * c;
                count %= _Mod;
            }
            else
            {
                int b = Math.Max(N, M);
                var v = Factorial(b);
                long c1 =v[b] % _Mod;
                long c2=v[b - 1] % _Mod;
                count = (c1 * c2) % _Mod;
            }
            Console.WriteLine(count);
        }

        //階乗n!(mod p)のベクトル
        public static List<long> Factorial(int n)
        {
            long x = 1;
            List<long> list = new List<long>();
            list.Add(x);
            for (int i = 1; i <= n; i++)
            {
                x = (x * i) % _Mod;
                list.Add(x);
            }
            return list;
        }


    }
}


Measured memory_bytes: 12768
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <stdio.h>
#include <list>
#include <numeric>
#include <stack>
#include <queue>
#include <tuple>
#include <bitset>
#include <map>
#include <math.h>
//　ceil(a/b)   (a + (b - 1))/ b
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<int,int> P;
const int inf=1000000007;
const int mod=1000000007;
const double PI=3.14159265358979323846;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};

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


// ll memo[2020][2020];
// int pascal_triangle(){
//   for(int i = 0; i < 1000; i++){
//     for(int j = 0; j < i+1; j++){
//       if(j == 0 || j == i) memo[i][j] = 1;
//       else{
// 	memo[i][j] = (memo[i-1][j-1]+memo[i-1][j])%mod;
//       }
//     }
//   }
//   return 0;
// }


// int factorial(int n){
//   if(n == 0) return 1;
//   return n*factorial(n-1);
// }

// int divisor(int a){
//   int cnt = 0;
//   for(int i=1; i <= a; i++) if(a%i == 0) cnt++;
//   return cnt;
// }

// int comb(int n, int k){
//   pascal_triangle();
//   return memo[n][k];
// }

// int cans(bool f){
//   if(f) cout << "Yes" << endl;
//   else cout << "No" << endl;
//   return 0;
// }







//二項係数(mod剰余)----------------------------

// const int MAX = 3000010;
// const int M = 1000000007;

// vector<ll> fac(MAX); //n!(mod M)
// //a,bの範囲的にこれだけ配列を用意していけば十分
// vector<ll> ifac(MAX); //k!^{M-2} (mod M)

// ll mpow(ll x, ll n){ //x^n(mod M) ←普通にpow(x,n)では溢れてしまうため，随時mod計算
//     ll ans = 1;
//     while(n != 0){
//         if(n&1) ans = ans*x % M;
//         x = x*x % M;
//         n = n >> 1;
//     }
//     return ans;
// }

// ll COMinit(){
//   //大した量ではないので，先にfax[i]とifax[i]を全て計算しておく
//   fac[0] = 1;
//   ifac[0] = 1;
//   for(ll i = 0; i<MAX; i++){
//     fac[i+1] = fac[i]*(i+1) % M; // n!(mod M)
//     ifac[i+1] = ifac[i]*mpow(i+1, M-2) % M; // k!^{M-2} (mod M) ←累乗にmpowを採用
//   }
//   return 0;
// }

// ll COM(ll a, ll b){ //aCbをmod計算
//   if(a == 0 && b == 0)return 1;
//   if(a < b || a < 0)return 0;
//   ll tmp = ifac[a-b]* ifac[b] % M;
//   return tmp * fac[a] % M;
// }

//-----------------------------------------

int main(){
  int A,B,C,X,Y;
  cin >> A >> B >> C >> X >>Y;
  int ans = inf;
  for(int i=max(Y,X);i>=0;i--){
    ans = min(ans,2*i*C+A*max(0,X-i)+B*max(0,Y-i));
  }
  cout << ans << endl;
 
  return 0;
}










Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <string>
#include <utility>
#include <set>

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

using namespace std;
typedef long long ll;

int n,q,sum=0;

int main() {
	
	cin>>n;
	int A[n];
	rep(i,n){cin>>A[i];} //ｍを作るための素材がA

	cin>>q;
	vector<int> m(q);
	rep(i,q){cin>>m[i];} //ｍが作れるかどうか


	vector<int> set(1<<n);

	for (int bit = 0; bit < 1<<n ; ++bit) //例えばn=3のとき、 0000〜1111まで順番に作っていく
	{
		for (int i = 0; i < n; ++i)
		{
			if ( (bit>>i) & 1 ) //n桁を順番に右にシフトしていき、その右の桁が１ならばその桁について操作
			{
				sum+=A[i];
			}
		}

		set.push_back(sum);

		sum=0;
	}

	sort(set.begin(),set.end());
	
	rep(i,q){
			
		if (binary_search(set.begin(),set.end(),m[i]))
		{
			 cout<<"yes"<<endl;
		}
		else{cout<<"no"<<endl;}

}


return 0;
}



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

using namespace std;

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n, 0);
  for (int i = 0; i < n; i++) {
    int x, xx;
    cin >> x >> xx;
    a[i] = (x == xx);
  }
  for (int i = 0; i < n; i++) {
    if (a[i] && i) {
      a[i] += a[i - 1];
    }
    if (a[i] >= 3) {
      cout << "Yes" << '\n';
      return 0;
    }
  }
  cout << "No" << '\n';
  return 0;
}

Measured memory_bytes: 3596
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n, x = map(int, readline().split())
    a = list(map(int, readline().split()))
    a.sort()

    rem = x
    ans = 0

    for i in range(n - 1):
        if rem >= a[i]:
            rem -= a[i]
            ans += 1

    if a[n-1] == rem:
        ans += 1

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 61604
// D.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>
#include <numeric>

using namespace std;

typedef long long LL;

int main(int argc, char* argv[]) {
#ifdef _MSC_VER
	while (true)
#endif
	{
		LL n = -1, k, ans = -(1LL << 60);
		cin >> n >> k;
		if (n < 0) return 0;
		vector<LL> p(n), c(n);
		for (int i = 0; i < n; ++i) {
			cin >> p[i];
			--p[i];
		}
		for (int i = 0; i < n; ++i) {
			cin >> c[i];
		}
		for (int i = 0; i < n; ++i) {
			vector<int> vis(n, -1);
			vector<LL> hist(n, -1);
			LL s = 0;
			int pos = i;
			for (int j = 0; j < k; ++j) {
				pos = p[pos];
				if (vis[pos] >= 0) {
					LL f = j - vis[pos];
					LL diff = s - hist[pos];
					LL cc = (k - j - 2) / f;
					if (cc > 1) {
						j += f * cc;
						s += diff * cc;
					}
				}
				hist[pos] = s;
				s += c[pos];
				ans = max(ans, s);
				if (vis[pos] < 0) vis[pos] = j;
			}
		}
		cout << ans << endl;
	}
	return 0;
}


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

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

  if (a+b == c || b+c == a || c + a == b) {
    cout << "Yes" << endl;
  }else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3624
from operator import itemgetter
N = int(input())
R = [list(input().split()) for i in range(N)]
R = [(R[i][0], int(R[i][1]), i+1) for i in range(N)]
S = sorted(R, key=itemgetter(1), reverse=True)
T = sorted(S, key=itemgetter(0))
for t in T:
    print(t[2])


Measured memory_bytes: 63016
#define _CRT_SECURE_NO_WARNINGS
#define TASK "C-large"
#pragma comment(linker, "/STACK:171088640")
#include <stdio.h>
#include <iostream>
#include <iomanip> 
#include <math.h>
#include <time.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <functional>
#include <assert.h>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <random>
#include <complex>
using namespace std;

const int MOD = 1000000007;
const int INF = 1000000007;
const long double EPS = 1e-6;
const int HASH_POW = 29;
const long double PI = acos(-1.0);
mt19937_64 rnd(1);

long long rndNext(long long l, long long r) {
	uniform_int_distribution <long long> foo(l, r);
	return foo(rnd);
}

double workTime() {
	return double(clock()) / CLOCKS_PER_SEC;
}

void my_return(int code) {
#ifdef MYDEBUG
	cout << "\nTime = " << fixed << setprecision(3) << workTime() << endl;
#endif
	exit(code);
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
#ifdef MYDEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#else
	/*freopen(TASK".in", "r", stdin);
	freopen(TASK".out", "w", stdout);*/
#endif

	int q, h, s, d, n;
	cin >> q >> h >> s >> d >> n;
	h = min(h, 2 * q);
	s = min(s, 2 * h);
	d = min(d, 2 * s);
	long long ans = (n / 2) * 1ll * d;
	if (n % 2) {
		ans += s;
	}
	cout << ans << endl;

	my_return(0);
}

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

char mat[3][3];

char judge(){
    for(int i = 0; i < 3; i++){
        if(mat[i][0] != '+' && mat[i][0] == mat[i][1] && mat[i][1] == mat[i][2]) return mat[i][2];
        if(mat[0][i] != '+' && mat[0][i] == mat[1][i] && mat[1][i] == mat[2][i]) return mat[2][i];
    }
    if(mat[1][1] != '+' && mat[0][0] == mat[1][1] && mat[1][1] == mat[2][2])    return mat[1][1];
    if(mat[1][1] != '+' && mat[0][2] == mat[1][1] && mat[1][1] == mat[2][0])    return mat[1][1];

    return '?';
}


int main(){
    while(1){
        cin >> mat[0][0];
        if(mat[0][0] == '0')    break;
        cin >> mat[0][1] >> mat[0][2];
        for(int i = 1; i < 3; i++){
            for(int j = 0; j < 3; j++){
                cin >> mat[i][j];
            }
        }
        char res = judge();
        if(res == '?')  cout << "NA" << endl;
        else            cout << res << endl;
    }
    return 0;
}


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

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

using namespace std;

using ll = long long;
using P = pair<int , int>;

const int INF = 1001001001;

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

  int n, x, y; cin >> n >> x >> y;
  --x; --y;
  vector<int> ans(n, 0);

  rep(i, n) {
    queue<int> q;
    vector<int> dist(n, INF);
    auto push = [&](int v, int d) {
		  if(dist[v] != INF) return;
		  dist[v] = d;
		  q.push(v);
		};
    push(i, 0);
    while(!q.empty()) {
      int v = q.front(); q.pop();
      int d = dist[v];

      if(v-1 >= 0) push(v-1, d+1);
      if(v+1 < n) push(v+1, d+1);
      if(v == x) push(y, d+1);
      if(v == y) push(x, d+1);
    }
    rep(j, n) ++ans[dist[j]];
  }
  rep(i, n-1) cout << ans[i+1]/2 << endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
int A,B,C,D,a,c;
cin >>A>>B>>C>>D;
a=A;
c=C;
while(a>0&&c>0){
c=c-B;
a=a-D;
}
if(a<=0&&c<=0){cout<<"Yes" <<endl;
}else if(a<=0){cout <<"No"<<endl;
}else if(c<=0){cout <<"Yes"<<endl;
}

return 0;
}

Measured memory_bytes: 3596
#include <algorithm>
#include <iostream>
using namespace std;
typedef pair<int, int> P;

class UnionFind
{
    int par[100002], rank[100002];
    
public:
    UnionFind(int n){
        for(int i = 0; i < n; i++){
            par[i] = i;
            rank[i] = 0;
        }
    }
    
    int find(int i){
        if(i == par[i]) return i;
        return par[i] = find(par[i]);
    }
    
    bool same(int i, int j){
        return par[i] == par[j];
    }
    
    void unite(int i, int j){
        if(same(i, j)) return;
        i = find(i), j = find(j);
        if(rank[i] < rank[j]) par[i] = j;
        else{
            par[j] = i;
            if(rank[i] == rank[j]) rank[i]++;
        }
    }
};
int main()
{
    int n;
    cin >> n;
    int a[100002], b[100002];
    P pa[100002], pb[100002];
    for(int i = 0; i < n; i++){
        cin >> a[i];
        pa[i] = P(a[i], i);
    }
    for(int i = 0; i < n; i++){
        cin >> b[i];
        pb[i] = P(b[i], i);
    }
    sort(pa, pa + n);
    sort(pb, pb + n);
    for(int i = 0; i < n; i++){
        if(pa[i].first > pb[i].first){
            cout << "No" << endl;
            return 0;
        }
    }
    UnionFind uf(n);
    for(int i = 0; i < n; i++){
        uf.unite(pa[i].second, pb[i].second);
    }
    int s = 0;
    for(int i = 0; i < n; i++){
        if(uf.find(i) == i) s++;
    }
    if(s >= 2){
        cout << "Yes" << endl;
        return 0;
    }
    for(int i = 1; i < n; i++){
        if(pa[i].first <= pb[i - 1].first){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 3328
MOD = 1000000007
# f(x) = f(x - 1) + f(x - 2)の場合のdp
def f_dp(x, a):
    dp = [0] * (x + 1)
    dp[0] = 1
    if 1 not in a:
        dp[1] = 1
    for i in range(2, x + 1):
        if i not in a:
            dp[i] = dp[i - 1] + dp[i -2]
    return dp[n] % MOD

if __name__ == "__main__":
    n, m = map(int, input().split())
    a = set([int(input()) for i in range(m)])

    dp = f_dp(n, a)
    print(dp)

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

using namespace std;

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

    long long int H, min, max = 0;
    cin >> min;
    for (int i = 0; i < N - 1; i++)
    {
        cin >> H;

        if (H > max)
        {
            max = H;
        } else if (H < max - 1) {
            cout << "No";
            return 0;
        } 
    }

    cout << "Yes";
}


Measured memory_bytes: 256
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

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

/* Macros reg. ends here */

const ll INF = 1LL << 50;

ll siz;
ll ofst;
vll seg;
void segadd(ll i) {
  i += ofst;
  seg[i] += 1;
  while (true) {
    i /= 2;
    if (i == 0) break;
    seg[i] = seg[2 * i] + seg[2 * i + 1];
  }
}

ll segget(ll l, ll r) {
  ll s = 0;
  l += ofst, r += ofst + 1;
  while (l < r) {
    if (l % 2 == 1) {
      s += seg[l];
      l++;
    }
    l /= 2;
    if (r % 2 == 1) {
      s += seg[r - 1];
      r--;
    }
    r /= 2;
  }
  return s;
}

ll n;
vll as;
bool f(ll x) {
  siz = 4;
  while (siz < 2 * n) siz <<= 1;
  ofst = siz >> 1;
  seg.assign(siz, 0);

  vll mk(n);
  rep(i, n) {
    bool chr = as[i] >= x;
    mk[i] = chr * 1 + !chr * (-1);
  }
  vll csum(n + 1, 0);
  ll minv = 0;
  rep(i, n) {
    csum[i + 1] = mk[i] + csum[i];
    chmin(minv, csum[i + 1]);
  }
  ll invn = 0;
  rep(i, n+1) {
    ll c = csum[i] - minv;
    invn += segget(0, c);
    segadd(c);
  }
  ll nall = n * (n + 1) / 2;
  return (invn >= (nall + 1) / 2);
}

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  cin >> n;
  as.resize(n);
  rep(i, n) cin >> as[i];

  ll l = 0;
  ll r = INF;
  while (l + 1 < r) {
    ll m = (l + r) / 2;
    if (f(m))
      l = m;
    else
      r = m;
  }
  cout << l << endl;

  return 0;
}


Measured memory_bytes: 4808
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); ++i)
#define all(x) (x).begin(),(x).end()
#define pb push_back
using namespace std;
using ll = long long;
using P = pair<int,int>;

int a1,a2,a3;
int cnt=0;

int digit_sum(int n) {
    int res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

int main()
{    
    int a;
    cin >> a;
    int b = digit_sum(a);

    if (a%b == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
    
}

/*
Ctrl+@ でコンソールを開け、以下で実行。
g++ code.cpp
./a.out

file-prefer-snipet
*/

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

int main() {
  
  char N;
  cin >> N;
  
  if(N=='A'){ cout << "T" << endl; }
  else if(N=='T'){ cout << "A" << endl; }
  else if(N=='G'){ cout << "C" << endl; }
  else{ cout << "G" << endl; }
  

}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define  ft   ios_base::sync_with_stdio(false);cin.tie(NULL);
#define  pb   push_back
#define  ll   long long
#define  pi   pair<int,int>
#define  F    first
#define  S    second
const int N=2e5+3;
string s,p;
//map<string,int>mp;
//vector<int,int>v;

int main()
{
    ft
    int t,i,j,n,m,l=0;
    cin>>n>>m;
    for(i=0;i<=n;i++)
    {
        for(j=0;j<=n;j++)
        {
            t=m-i-j;
            if(t>=0 && t<=n)
            {
                l++;
            }
        }
    }
    cout<<l<<"\n";
    return 0;
}


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

int main() {
  // ここにプログラムを追記
  int rows_of_square, white_square, black_square;
  cin >> rows_of_square >> white_square;
  
  black_square = rows_of_square * rows_of_square - white_square;
  cout << black_square << endl;
}

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

#define rep(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define SZ(x) ((int) (x).size())
typedef long long ll;

int main(){
    //freopen("a.in","r",stdin);
	string a, b;
	cin >> a >> b;
	if ((a=="H"&&b=="H") || (a=="D"&&b=="D")) cout<<"H" <<endl;
	else cout<< "D" <<endl;
    return 0;
}


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

int main(){
		int h,w;
		while(1){
				cin>>h>>w;

				if(h==0&&w==0) break;

				for(int i=0;i<h;i++){
						for(int j=0;j<w;j++){
								if(i%2==0){
										if(j%2==0){
												cout<<'#';
										}else{
												cout<<'.';
										}
								}else{
										if(j%2==0){
												cout<<'.';
										}else{
												cout<<'#';
										}
								}
						}
						cout<<endl;
				}
				cout<<endl;
		}

		return 0;
}

Measured memory_bytes: 3088
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define F first
#define S second
#define int long long
#define ll long long
//#define int  unsigned long long
#define pb push_back
//#define double long double

using namespace std;
using namespace __gnu_pbds;
typedef  tree< int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const int mod = 998244353;
const int N = 520005;
const int K = 25;
vector < int > g[N];
int dp[N];
void dfs(int v, int p = -1){
    int c = 0;
    for (auto u: g[v]){
        if (u == p) continue;
        dfs(u, v);
        c ^= (dp[u] + 1);
    }
    dp[v] = c;
}
main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt", "r", stdin);
    int n;
    cin >> n;
    for (int i = 1; i < n; i++){
        int u, v;
        cin >> u >> v;
        g[u].pb(v);
        g[v].pb(u);
    }
    dfs(1);
    if (dp[1] == 0) cout << "Bob"; else cout << "Alice";
}


Measured memory_bytes: 21888
#include<bits/stdc++.h>
#define inf 1<<29
#define linf 1e18
#define eps (1e-8)
#define mod 1000000007
#define pi M_PI
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define pd(a) printf("%.10f\n",(double)(a))
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define equals(a,b) (fabs((a)-(b))<eps)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<double,int> pdi;
typedef vector<int> vi;
typedef vector<pii> vpi;
const int dx[8]={1,0,-1,0,1,1,-1,-1};
const int dy[8]={0,1,0,-1,1,-1,1,-1};

int main()
{
  string s;
  int a,b,c,d;

  while(1){
    cin>>s;
    if(s=="#")break;
    cin>>a>>b>>c>>d;
    a--;b--;c--;d--;
    bool grid[10][10]={};
    int y=0,x=0;
    FOR(k,0,s.length()){
      if(s[k]=='b'){
        grid[y][x]=true;
        x++;
      }
      else if(s[k]=='/'){
        y++;
        x=0;
      }
      else x+=(s[k]-'0');
    }
    swap(grid[a][b],grid[c][d]);
    string ans="";
    FOR(i,0,y+1){
      int space=0;
      FOR(j,0,x+1){
        if(grid[i][j]){
          if(space!=0)ans+=space+'0';
          ans+="b";
          space=0;
        }
        else space++;
      }
      space--;
      if(0<space)ans+=space+'0';
      if(i!=y)ans+="/";
    }
    cout<<ans<<endl;
  }
        
  return 0;
}

Measured memory_bytes: 3124
#include<bits/stdc++.h>
using namespace std;
int main(){
    int x=0;
    int n;
    cin>>n;
    char s[n];
    int max=0;
    for(int i=0;i<n;i++){
            cin>>s[i];
    }
    for(int i=0;i<n;i++){
        if(s[i]=='I'){
            x++;
            if(max<=x){
                max=x;
            }
        }
        else if(s[i]=='D'){
            x--;
            if(max<=x){
                max=x;
            }
        }
    }
   // cout<<x;
    cout<<max;
}

Measured memory_bytes: 256
import sys
stdin = sys.stdin
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()
 
n,k = na()
s = ns()
ones = []
a = 0
now = '0'
 
for i in s:
    if i == now:
        a += 1
    else:
        ones.append(a)
        a = 1
        now = i
 
ones.append(a)

if (len(ones)+1)//2 <= k:
    print(sum(ones))
    exit()

ssu = 0
d = []
for u in ones:
    ssu += u
    d.append(ssu)
d.append(d[-1])
ans = 0
for j in range((len(ones)+1)//2+1-k):
    q = max(0,j*2-1)
    w = 0 if q == 0 else d[q-1]
    ans = max(ans, d[(j+k)*2-1]-w)
 
print(ans)

Measured memory_bytes: 7932
#include<bits/stdc++.h>
using namespace std;
long long int n,a[1000001];
int gcd(int c,int d) {
	return d==0?c:gcd(d,c%d);
}
int main() {
	cin>>n;
	int ans=0;
	for (int i=0; i<n; i++) {
		int x;
		cin>>x;
		a[x]++;
		ans=gcd(ans,x);
	}
	int ok=1;
	for (int i=2; i<=1000000; i++) {
		int cnt=0;
		for (int j=i; j<=1000000; j+=i)
			cnt+=a[j];
		if (cnt>1) ok=0;
	}
	if (ok) cout<<"pairwise coprime"<<endl;
	else if (ans==1) cout<<"setwise coprime"<<endl;
	else cout<<"not coprime";

	return 0;
}

Measured memory_bytes: 11392
#include <iostream>
using namespace std;
int main(){

  int n,m,i,j;
  long matrix[100][101]={},rmatrix[100]={};

  cin>>n>>m;
  for(i=0; i<n; i++)for(j=0; j<m; j++)cin>>matrix[i][j];
  for(j=0; j<m; j++)cin>>rmatrix[j];
  for(i=0; i<n; i++)for(j=0; j<m; j++)matrix[i][100]+=matrix[i][j]*rmatrix[j];

  for(i=0; i<n; i++)cout<<matrix[i][100]<<"\n";

}

Measured memory_bytes: 1248
from itertools import*
from math import*
from collections import*
from heapq import*
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf = float("inf")
mod = 10**9+7
from functools import reduce
import sys
sys.setrecursionlimit(10**7)

N = int(input())
a = list(map(int,input().split()))
b = [0]*(N+1)
left,right = [i for i in range(N+2)],[i for i in range(N+2)]
ans = 0
for i in range(N):
    b[a[i]] = i
for i in range(N+1)[::-1]:
    m = b[i]
    l,r = left[m],right[m]
    ans += i*(m-l+1)*(r-m+1)
    left[r+1]=l
    right[l-1]=r
print(ans)

Measured memory_bytes: 100940
use std::io::*;
use std::str::FromStr;
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main(){
    let mut a:Vec<char> = read::<String>().chars().collect();;
    let mut b:Vec<char> = read::<String>().chars().collect();;
    a.sort_by_key(|&x|(x));
    b.sort_by(|x,y| x.cmp(y).reverse());
    let s: String = a.into_iter().collect();
    let t: String = b.into_iter().collect();
    if(s < t){
        println!("Yes");
    }
    else{
        println!("No");
    }
}

Measured memory_bytes: 4352
#include<stdio.h>

int main(void)
{
    int i, j, q, u, f, r;
    int d[6];
    
    for ( i=0; i<6; ++i)
        scanf("%d", &d[i]);
    scanf("%d", &q);
    
    for ( ; q>0; --q) {
        scanf("%d %d", &u, &f);
        i = j = 0;
        while ( d[i]!=u) ++i;
        while ( d[j]!=f) ++j;
        if ( i==0) {
            switch (j) {
                case 1: r = d[2]; break;
                case 2: r = d[4]; break;
                case 4: r = d[3]; break;
                case 3: r = d[1]; break;
            }
        }else if ( i==1) {
            switch (j) {
                case 0: r = d[3]; break;
                case 2: r = d[0]; break;
                case 3: r = d[5]; break;
                case 5: r = d[2]; break;
            }
        }else if ( i==2) {
            switch (j) {
                case 0: r = d[1]; break;
                case 1: r = d[5]; break;
                case 4: r = d[0]; break;
                case 5: r = d[4]; break;
            }
        }else if ( i==3) {
            switch (j) {
                case 0: r = d[4]; break;
                case 1: r = d[0]; break;
                case 4: r = d[5]; break;
                case 5: r = d[1]; break;
            }
        }else if ( i==4) {
            switch (j) {
                case 0: r = d[2]; break;
                case 2: r = d[5]; break;
                case 3: r = d[0]; break;
                case 5: r = d[3]; break;
            }
        }else if ( i==5) {
            switch (j) {
                case 1: r = d[3]; break;
                case 2: r = d[1]; break;
                case 3: r = d[4]; break;
                case 4: r = d[2]; break;
            }
        }
        printf("%d\n", r);
    }
    return 0;
}


Measured memory_bytes: 2104
#include<iostream>
#include<algorithm>
#include<set>
 
using namespace std;
typedef long long ll;
 
ll ans = 0;
int N;
ll s[100000];
 
ll dp[101000];//dp[k]だった時のans cは配列の使いまわしのよってカバー
set<int> used;
 
int main() {
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> s[i];
	}
 
	ll ans = 0;// == 0の時の答えが0
 
	for (int C = 1; C <= N - 2; C++) {
		used.clear();
		//kを決めてる
		dp[0] = 0;
		for (int k = 1;; k++) {
			if (N - 1 - C * k <= 0)break;
			if (k * C >= N - 1)break;
			if (N - 1 - C * k - C <= 0)break;
			if (2 * C * k == N - 1)continue;
			if (used.find(C * k) != used.end() || used.find(N - 1 - C * k) != used.end())break;
			dp[k] = dp[k - 1] + s[N - 1 - k * C] + s[C * k];
			ans = max(ans, dp[k]);
			used.insert(C * k), used.insert(N - 1 - k * C);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 8192
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    int N, K;
    cin >> N >> K;
    vector<int> a(N);
    for (int i = 0; i < N; i++) cin >> a[i];

    int ans = 0;
    for (int ai : a) { ans += 2 * min(K - ai, ai); }
    cout << ans << '\n';
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const int INF = pow(10, 7);

int main(){
  string s, t;cin>>s>>t;
  ll ans=(ll)0;
  vector<vector<int>> alp(26);
  int n=(int)s.size();
  int m=(int)t.size();
  for(int i=0;i<n;i++){
  	alp[int(s[i]-'a')].push_back(i+1);
  }
  vector<int> num(m);
  // for(int x: num)cout<<x<<" ";cout<<endl;
  int pos=-1;
  for(int i=0;i<=m;i++){
    // cout<<pos<<endl;
    if(i==m){
      ans += (ll)pos;break;
    }
    vector<int>& vec = alp[int(t[i]-'a')];
  	if(vec.empty()){ans=(ll)-1;break;}
    int tmp = int(upper_bound(vec.begin(), vec.end(), pos)-vec.begin());
    if(tmp == (int)vec.size()){
      ans += (ll)n;
      pos = vec[0];
    }else{
      pos = vec[tmp];
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 1468
#include<bits/stdc++.h>
using namespace std;
int ca[51],tmp[51];
int main(){
  int n,r;
  while(cin>>n>>r,n+r){
    for(int i=0;i<n;++i) ca[i]=n-i;
    int p,c;
    for(int i=0;i<r;++i){
      cin>>p>>c;
      for(int j=0;j<c;++j) tmp[j]=ca[p+j-1];
      for(int j=p-2;j>=0;--j) ca[j+c]=ca[j];
      for(int j=0;j<c;++j) ca[j]=tmp[j];
    }
    cout<<ca[0]<<endl;
  }
  return 0;
}

Measured memory_bytes: 2976
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int main(){
  ll N, K;
  cin >> N >> K;
  priority_queue<int> H;
  rep(i, N){
    ll a;
    cin >> a;
    H.push(a);
  }
  rep(i, K){
    if(!H.empty())H.pop();
  }
  ll counter = 0;
  while(!H.empty()){
    counter += H.top();
    H.pop();
  }
  cout << counter << endl;
}

Measured memory_bytes: 1400
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int rk = 0;
    int wk = 0;
    String s = sc.next();
    for(int i = 0; i < n; i++) {
      if(s.charAt(i) == 'W') {
        wk++;
      } else {
        rk++;
      }
    }
    int[] rui = new int[n];
    if(s.charAt(0) == 'W') rui[0] = 1;
    for(int i = 1; i < n; i++) {
      if(s.charAt(i) == 'W') {
        rui[i] = rui[i - 1] + 1;
      } else {
        rui[i] = rui[i - 1];
      }
    }
    int ans = n;
    for(int k = 0; k <= n; k++) {
      int t = Math.abs(rk - k);
      if(k > 0) {
        if(rk <= k) {
          t += (rui[k - 1] - Math.abs(rk - k));
        } else {
          t += rui[k - 1];
        }
      }
      ans = Math.min(ans, t);
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 41244
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,k;
  cin >>n>>k;
  vector<int>a(n);
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  int count=1;
  int kotae=(n-k)/(k-1);
  count+=kotae;
  if((n-k)%(k-1)!=0)count++;
  cout<<count<<endl;
  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define REP(asd,fgh) for(int asd=0; asd < fgh; asd++)

int main(void){
  int t;
  cin >> t;
  double p = 0;
  while(t--){
    vector<pair<int, double> > me;
    int n, m;
    cin >> n >> m;
    REP(i, m){
      pair<int,double> tmp;
      cin >> tmp.first >> tmp.second;
      me.push_back(tmp);
    }
    double w = 1;
    REP(i, m){
      w -= me[i].second;
    }
    //cout << w << endl;
    double tp = 0;
    REP(i, m){
      tp += me[i].first * (me[i].second/(1.0-w));
    }
    p = max(p, tp);
  }

  vector<pair<int, double> > me;
  double op = 0;
  int pp;
  int q;
  cin >> pp >> q;
  REP(i, q){
    pair<int, double> tmp;
    cin >> tmp.first >> tmp.second;
    me.push_back(tmp);
  }
  double w = 1;
  REP(i, q){
    w -= me[i].second;
  }
  REP(i, q){
    op += me[i].first * (me[i].second/(1.0-w));
  }

  if(p - op > 0.0000001) cout << "YES" << endl;
  else cout << "NO" << endl;

  return 0;
}

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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int main() {

    ll n; cin >> n;

    vector<ll> a(n);
    for (ll i = 0; i < n; ++i) {
        cin >> a[i];
    }

    ll ans = 0;

    for (ll i = 0; i < 60; ++i) {
        ll sum = 0;
        ll one = 0;

        for (ll j = 0; j < n; ++j) {
            if ((a[j] >> i) & 1) {
                ++one;
            }
        }

        ll zero = n - one;
        sum = one * zero % MOD;

        for (ll j = 0; j < i; ++j) {
            sum = sum * 2 % MOD;
        }

        ans += sum;
        ans %= MOD;
    }

    cout << ans << endl;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int main() {
  char c;
  cin >> c;
  cout<<(char)(c+1)<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
  double l[10] = {0},v[2] = {0};
  for(;;){
    if(scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf",&l[0],&l[1],&l[2],&l[3],&l[4],&l[5],&l[6],&l[7],&l[8],&l[9],&v[0],&v[1]) == EOF){break;}
    for(int i=1; i<10; i++){
      l[i]+=l[i-1];
    }
    double x = l[9]*v[0]/(v[0]+v[1]);
    for(int i=0; i<10; i++){
      if(l[i]+0.000001 >= x){cout <<i+1<<endl;break;}
    }
  }
  return 0;
}

Measured memory_bytes: 1228
import java.io.PrintWriter;
import java.util.*;

public class Main {
    void run() {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);

        long a = sc.nextLong();
        long b = sc.nextLong();
        long c = sc.nextLong();
        long d = sc.nextLong();

        long[] arr = {a * c, a * d,b * c, b *d};

        long max = Long.MIN_VALUE;
        for (long l : arr) {
            max = Math.max(max, l);
        }

        System.out.println(max);

        // out.println("Hello World");
        out.flush();    }

    void debug(Object... os) {
        System.err.println(Arrays.deepToString(os));
    }

    public static void main(String[] args) {
        new Main().run();
    }
}


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

using namespace std;

#define MAX_N 200005
int N;
int A[MAX_N];

void input()
{
  cin >> N;
  for (size_t i = 0; i < N; i++) {
    scanf("%d", &A[i]);
  }
}

typedef pair<int, int> II;
typedef long long LL;

vector<II> vecList;
int posVec[MAX_N];

LL solve()
{
  LL ret = 0;

  for (size_t i = 0; i < N; i++) {
    vecList.push_back(make_pair(A[i], i));
  }

  sort(vecList.begin(), vecList.end(), greater<II>());
  memset(posVec, -1, sizeof(posVec));

  for (size_t i = 0; i < N; i++) {
    auto p = vecList[i];
    LL number = p.first;
    int pos = p.second;
    int l = 0, r = 0;
    if(pos > 0){
      if(A[pos-1] > A[pos]){
        l = posVec[pos-1];
      }
    }
    if(pos < N-1){
      if(A[pos+1] > A[pos]){
        r = posVec[pos+1];
      }
    }
    ret += (LL)number * (l+r) + (LL)number * l * r + number;
    posVec[pos] = posVec[pos-l] = posVec[pos+r] = l+r+1;
    
  }

  return ret;
}

int main()
{
  input();

  cout << solve() << endl;

  return 0;
}


Measured memory_bytes: 3440
import java.util.*;
import java.io.*;

public class Main{

	public static void main(String[] args){
		solve();
	}

	public static void solve(){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		for(int i=0;i<n;i++){
			a[i] = sc.nextInt();
		}
		int ans = -1;
		for(int i=0;i<n;i++){
			for(int j=i+1;j<n;j++){
				int x = a[i]*a[j];
				String s = String.valueOf(x);
				boolean judge = true;
				for(int k=0;k<s.length()-1;k++){
					if((int)s.charAt(k)!=(int)s.charAt(k+1)-1){
						judge = false;
					}
				}
				if(judge){
					ans = Math.max(ans,x);
				}
			}
		}

		System.out.println(ans);
	}
}

Measured memory_bytes: 58864
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();
        
        int[] r = new int[101];
        
        for(int i = a; i <= b; i++){
            r[i]++;
        }
        
        for(int i = c; i <= d; i++){
            r[i]++;
        }
        
        int res = 0;
        
        for(int i = 0; i <= 100; i++){
            if(r[i] == 2) res++;
        }
        
        System.out.println(res == 0 ? 0 : res - 1);
    }
}


Measured memory_bytes: 22868
/*

    author : s@if

*/

#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define 		NIL 			-1
#define		 	fi	 		    first
#define 		sec 			second
#define 		MAX 			INT_MAX
#define			INF 			1e9
#define 		ll 			    long long
#define 		PI 			    acos(-1.0)
#define			MOD 			1000000007
#define 		PLL 			pair<ll,ll>
#define 		PII			    pair<int,int>
#define 		ull 			unsigned long long
#define 		For(i,a,b) 		for(int i=a;i<=(int)b;i++)
typedef tree<int, null_type, less<int>, rb_tree_tag,
            tree_order_statistics_node_update> new_data_set;

//*find_by_order(k)  gives the kth element;
//order_of_key(item)   gives the index(number of element strictly less than item) of item;


inline int in() {int x; scanf("%d", &x); return x; }
bool Check(int N , int pos)	{	return (bool) (N & (1<<pos));}
int Set(int N, int pos) {	return N = N | (1<<pos);}

int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};    // King's move
int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};
int hx[]={-2,-2,-1,+1,+2,+2,-1,+1};    // Knight's move
int hy[]={+1,-1,+2,+2,-1,+1,-2,-2};
int dx[]={+1,-1,+0,+0};
int dy[]={+0,+0,+1,-1};

const int MAXN = (int)2e5+9;


int main()
{
/*	freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);  */

    ll i,j,k,l,m,n,p,q,x,y,u,v,r,tc,t;

    cin>>x; ll ans = 0;

    v = x/500; ans+=v*1000; x-=v*500;
  /*  v = x/100; x-=v*100;
    v = x/50; x-=v*50;
    v = x/10; x-=v*10;  */
    v = x/5; ans+=v*5;

    cout<<ans<<endl;

 //   main();

    return 0;
}

// read the question correctly (is y a vowel? what are the exact constraints?)
// look out for SPECIAL CASES (n=1?) and overflow (ll vs int?)


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

using namespace std;

int main() {
    int N;
    cin >> N;
    vector<long double> A(N);
    // long long product = 1;
    long double bo = 1, shi = 0;
    for(int i = 0; i < N; ++i) {
        cin >> A[i];
        bo *= A[i];
    }

    for(int i = 0; i < N; ++i){
        shi += bo/A[i];
    }
    cout << bo/shi << endl;



    return 0;
}

Measured memory_bytes: 256
//s.empty() //emptyなら1を出力 入っていれば0を出力
/*//ABC018-B 部分的にreverseをかける解法
int main() {
  string s;
  cin >> s;
  int n;
  cin >> n;
  vector<int>a(n);
  vector<int>b(n);
  rep(i,n) cin>>a.at(i)>>b.at(i);
  rep(i,n)a.at(i)--;
  rep(i,n)b.at(i)--;
  string t;
  rep(i,n){
    t = s;
    for(int k=0;k<=b.at(i)-a.at(i);k++){
      t.at(a.at(i)+k) = s.at(b.at(i)-k);
    }
    s = t;
  }
  cout << s << endl;
}
*///ABC018-B
//  string s;
//  cin >> s;
//  cout << s.at(0) <<endl;
//  cout << s.at(0)-'0' <<endl;
//  Aが16？
//  cout << char(i+48) << endl;//なぜかaは47と得る時がある。+48で出力もaにできる。
//  cout << char(97) << endl;//アスキーコードでaを出力
// sort(b.begin(), b.end());//bという配列を小さい方からソート
// reverse(b.begin(), b.end());//bという配列をリターン
// 10桁でdouble出力するパターン１ 
// printf("%.10f\n", ma);
// 10桁でdouble出力するパターン２
//cout << fixed << setprecision(10);
//  cout << ma << endl;

/*01 02 03 12 13 23　と６回見ていくパターン 
for(int i=0;i<n-1;i++){
  for(int j=i+1;j<n;j++){
    }
  }
*///vector<vector<int>> data(3, vector<int>(4));//int型の2次元配列(3×4要素の)の宣言
//int64_t a;
//10のi乗pow(10, i);
/*string s; stringでの文字列を数字型に変える方法
  cin >> s;
  rep(i,s.size()-2) {
  int a= (s.at(i)-'0')*100 + (s.at(i+1)-'0')*10+ s.at(i+2) -'0';
    */
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
  int n;
  cin >> n;
  cout << n + n *n+n*n*n<<endl;
}


Measured memory_bytes: 3648
n = int(input())
cards = [int(a) for a in input().split()]
pairwise_distincts = set(cards)

if (len(cards) - len(pairwise_distincts)) % 2 == 0:
    ans = len(pairwise_distincts)
else:
    ans = len(pairwise_distincts) - 1

print(ans)

Measured memory_bytes: 14564
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
int main(){
    int N;
    int X[100];
    scanf("%d",&N);
    for(int i = 0 ; i < N ; i++){
        scanf("%d",&X[i]);
    }
    int min = 1e+9;
    for(int i = 1 ; i <= 100 ; i++){
        int tmp = 0;
        for(int j = 0 ; j < N ; j++){
            tmp += pow((X[j] - i),2);
        }
        if(min > tmp){
            min = tmp;
        }
    }
    printf("%d",min);
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for (int i = 0; i < n;i++)
 
int main(){
  int N;
  cin>>N;
  if(N%2==0) cout<<N/2<<endl;
  else cout<<(N/2)+1<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i < n+1; i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end());
typedef long long ll;

int main(){
  int n;
  cin >> n;
  deque<int> q;
  rep(i,n){
    int x;
    cin >> x;
    if(i%2 == 0) q.push_front(x);
    else q.push_back(x);
  }
  if(n%2){
    while(!q.empty()){
      cout << q.front() << " ";
      q.pop_front();
    }
  }else{
    while(!q.empty()){
      cout << q.back() << " ";
      q.pop_back();
    }
  }
}

Measured memory_bytes: 2944