akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<cstdio>
#include<cmath>

using namespace std;
typedef long long ll;

ll n,a[100010]={0},cnt=0,m=1000000,s=0;
bool zr=false;

signed main(){
    cin>>n;
    for(int i=0;i<n;++i){
        cin>>a[i];
        m=min(m,abs(a[i]));
        if(a[i]<0){
            cnt++;
        }
        if(a[i]==0)zr=true;
        s+=max(a[i],-a[i]);
    }

    if(cnt%2==0||zr){
        cout<<s<<endl;
    }
    else{
        cout<<s-2*m<<endl;
    }



    return 0;
}

Measured memory_bytes: 1152
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

template<class Type>
Type solve(Type res = Type()){
    int n;
    while(cin >> n){
        if(n == 0) break;
        vector<double> a(n); for(auto& in:a) cin >> in;
        double ave = accumulate(a.begin(),a.end(),0.0)/n;
        sort(a.begin(),a.end());
        cout << (int)(upper_bound(a.begin(),a.end(),ave)-a.begin()) << endl;
    }
    
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    solve<ll>();
    //cout << fixed << setprecision(15) << solve<ll>() << endl;
    return 0;
}



Measured memory_bytes: 3380
from fractions import gcd
def lcm(x, y):
    return (x * y) // gcd(x, y)

a,b,c,d = map(int, input().split())
a -= 1
print(b-(b//c+b//d-b//lcm(c,d))-\
     a+(a//c+a//d-a//lcm(c,d)))

Measured memory_bytes: 5688
#include <iostream>
#include <iomanip>
#include<math.h>
#include<list>
#include <algorithm>
#include<set>
#include<vector>
#include<math.h>
#include<map>
#include<string>
#include <numeric>
#include <queue>
#include <sstream>
#include <bitset>
#include<stack>

using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;

template<typename T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }

template<typename T>
map<T, T> getPrimeFactor(T n) {
	map<T, T> res;
	for (T i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			res[i] ++;
			n /= i;
		}
	}
	if (n != 1) res[n] = 1;
	return res;
}

template<typename T>
bool IsPrimeNumber(T num)
{
	if (num <= 2) return true;
	else if (num % 2 == 0) return false;

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			return false;
		}
	}

	return true;
}

long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}


#define in(x) cin >> x
#define out(x) cout << x
#define outn(x) cout << x << '\n'
#define outs(x) cout << x << ' '
#define rep(i,s,e) for(ll i=s;i<e;i++)
#define repeq(i,s,e) for(ll i=s;i<=e;i++)


int main() {
	ll n;
	
	stack<ll> s;
	std::cin >> n;
	vll b(n);
	rep(i, 0, n) {
		std::cin >> b[i];
	}

	while (b.size() > 0) {
		vll a(b.size() - 1);
		ll cnt = b.size() - 2;
		bool flg = true;
		for (ll i = b.size() - 1; i >= 0; i--) {
			if (i + 1 == b[i] && flg) {
				s.push(i + 1);
				flg = false;
			}
			else {
				if (cnt < 0) {
					outn(-1);
					return 0;
				}
				a[cnt] = b[i];
				cnt--;
			}
		}
		if (flg) {
			outn(-1);
			return 0;
		}
		b = a;
	}

	while (s.size() > 0) {
		outn(s.top());
		s.pop();

	}

	return 0;

}


Measured memory_bytes: 256
nums = gets.split.map(&:to_i)
houses = gets.split.map(&:to_i)
zentai = nums[0]
saidai = 0
(nums[1] - 1).times do |i|
  sabun = houses[i + 1] - houses[i]
  saidai = sabun if sabun > saidai
end

sabun = zentai - houses[nums[1]-1] + houses[0]
saidai = sabun if sabun > saidai

puts zentai - saidai

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

const int N = 2e3L + 11;
using ll = long long;
const ll mod = 1e9L + 7;

const int M = 1e7L + 11;
ll fac[M], inv[M];
ll binom(int n, int m) {
	return fac[n] * inv[m] % mod * inv[n - m] % mod;
}

ll f[N][N];

int main() {
	fac[0] = inv[0] = fac[1] = inv[1] = 1;
	for(int i = 2; i < M; i ++)
		inv[i] = (mod - mod / i) * inv[mod % i] % mod;
	for(int i = 2; i < M; i ++) {
		fac[i] = fac[i - 1] * i % mod;
		inv[i] = inv[i - 1] * inv[i] % mod;
	}
	ios :: sync_with_stdio(0);
	int n, m; cin >> n >> m;
	if(m == 1) {
		cout << "1\n";
		return 0;
	}
	f[0][0] = 1;
	for(int i = 0; i <= n; i ++)
		for(int j = 0; j <= n; j ++) {
			if(i) f[i][j] += f[i - 1][j];
			if(j) f[i][j] += f[i][j - 1] * binom(i + j * (m - 1) - 1, m - 2) % mod;
			f[i][j] %= mod;
			if(i > j) f[i][j] = 0;
		}

	ll ans = f[n][n] * fac[n] % mod;
	cout << ans << '\n';
}

Measured memory_bytes: 188160
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cstring>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <stack>
#include <cmath>
#include <time.h>
#define ll long long
#define LINF 0x3f3f3f3f3f3f3f3f
#define INF 0x3f3f3f3f
#define PI 3.14159265
#define RAND (rand()*rand())
using namespace std;
const int MAX = 2e5 + 10; //N
const ll MOD = 1e9 + 7;
int N, M, K, Q;
ll A[MAX], psum[MAX];
vector<ll> vec;

int main()
{
	int i, j;
	scanf("%d", &N);
	for (i = 1; i <= N; ++i) {
		scanf("%lld", &A[i]);
		A[i] -= i;
		vec.push_back(A[i]);
	}
	sort(vec.begin(), vec.end());
	for (i = 1; i <= N; ++i) psum[i] += psum[i - 1] + vec[i - 1];

	ll mini = LINF;
	for (i = 1; i <= N; ++i) {
		ll  b = A[i];
		int n = lower_bound(vec.begin(), vec.end(), b) - vec.begin();// # less than b;
		ll sum = (n * b - psum[n]) + ((psum[N] - psum[n]) - (N - n)*b);
		mini = min(mini, sum);
	}
	printf("%lld", mini);
}

Measured memory_bytes: 5104
L = "qwertasdfgzxcvb"
while 1:
	key = raw_input()
	if key == "#": break
	c = 0
	h = 1 if key[0] in L else 0
	for i in range(1,len(key)):
		p = 1 if key[i] in L else 0
		if h != p:
			c += 1
			h = p
	print c

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

int main() {
	int i,n,t,pos,x;
	cin>>n>>t>>x;
	long double a[n],diff=INT_MAX;
	for(i=0;i<n;i++)
	  {cin>>a[i];
	  	a[i]=t-0.006*a[i];
	  	if(abs(a[i]-x)<diff)
	  	  {
	  	  	  diff=abs(a[i]-x);
	  	  	  pos=i;
	  	  }
	  }
	 cout<<pos+1<<'\n'; 
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
	public static void main(String args[]){
      int D=0;int T=0;int S=0;
      Scanner sc = new Scanner(System.in);
		D=sc.nextInt();
        T=sc.nextInt();
		S=sc.nextInt();
      if(D>T*S){
			System.out.println("No");
		}else{
			System.out.println("Yes");
		}
		
	}
	
	
}

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

int n, ans[5];

int main(){
	memset(ans,0,sizeof ans);
	cin >> n;
	for (int i=0;i<n;i++){
		string s;
		cin >> s;
		if (s=="AC") ans[0]++;
		else if (s=="WA") ans[1]++;
		else if (s=="TLE") ans[2]++;
		else ans[3]++;
	}
	cout << "AC x " << ans[0] << "\n";
	cout << "WA x " << ans[1] << "\n";
	cout << "TLE x " << ans[2] << "\n";
	cout << "RE x " << ans[3] << "\n"; 
}

Measured memory_bytes: 3628
using System;
using System.Collections.Generic;
 class Program
 {
     static void include3(int data,int moto)
     {
         if ((data % 10) == 3)
             Console.Write(" {0}", moto);
         else
         {
             data = data / 10;
             if (data != 0)
                 include3(data,moto);
         }

     }

     static void Main(string[] args)
     {
         double data0 = 0, data1 = 0, data2 = 0;

         String nyuryoku;
         string[] data;
         string pattern1, pattern2;

         nyuryoku = Console.ReadLine();
         data0 = int.Parse(nyuryoku);
         for (int i = 1; i <= data0; i++)
         {
             if ((i % 3) == 0 )
             {
                 Console.Write(" {0}", i);
             }else
                 include3(i,i);
         }
         Console.Write("\n");
      }
 }



Measured memory_bytes: 17992
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define REP(i,x,n) for(int i = (x); i < (n); ++i)
#define ll long long
#define P pair<ll,ll>
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1);
//const ll mod = 998244353;

ll lcm(ll a, ll b){
    return a / __gcd(a, b) * b;
}


struct UnionFind {
    vector<ll> d;

    UnionFind(ll n){
        d = vector<ll>(n,-1);
    }
    
    //根の設定
    ll root(ll x){
        if(d[x] < 0) return x;
        return d[x] = root(d[x]);
    }
    
    //連結する
    bool unite(ll x, ll y){
        x = root(x);
        y = root(y);
        if(x == y) return false;
        if(d[x] > d[y]) swap(x, y);
        d[x] += d[y];
        d[y] = x;
        return true;
    }
    
    //同じ集合かどうか判定
    bool same(ll x, ll y){
        return root(x) == root(y);
    }
    
    //集合の大きさを返す
    ll size(ll x){
        return -d[root(x)];
    }
};

int main(void)
{
    ll n, m;
    cin >> n >> m;
    UnionFind uf(n);
    ll ans=n-1;
    rep(i,m){
        ll a, b;
        cin >> a >> b;
        a--; b--;
        if(!uf.same(a,b)){
            uf.unite(a,b);
            ans--;
        }
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

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

int main(){

    int H,W;

    cin >> H >> W;

    char a[H][W];

    for(int i = 0;i < H;i++){
    	string c;
    	cin >> c;
    	for(int j = 0;j < W;j++){
    		a[i][j] = c.at(j);
    	}
    }

    for(int i = 0;i < H;i++){
    	for(int j = 0;j < W;j++){
    		int count = 0;
    	   if(a[i][j] == '.'){
    		   for(int h = 0;h < 8;h++){
    			   if(a[i + dy[h]][j + dx[h]] == '#' && i + dy[h] >= 0 && i + dy[h] <= H-1 && j + dx[h] >=0 && j + dx[h]<=W-1){
    				   count++;
    			   }else{
    				   continue;
    			   }
    		   }
    		   a[i][j] = to_string(count).at(0);
    	   }
    	}
    }

    for(int i = 0;i < H;i++){
    	for(int j =0;j < W;j++){
    		cout << a[i][j];
    	}
    	cout << endl;
    }

	return 0;

}


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

int main() {
  int N, A, i, x, n, n_min;
  n_min = 30;
  //iは数字のナンバリング
  //xは試行回数のナンバリング
  //nは試行回数
  //n_minは試行回数のminimum
  cin >> N;
  for (i = 0; i < N; i++){
    n = 0;
    cin >> A;
    for (x = 0; x < 30; x++){
      if (A % 2 == 1){
        break;
      }
      A /= 2;
      n += 1;
    }
    if (n >= n_min){
      continue;
    }
   
    n_min = n;
  }
  cout << n_min <<endl;
    
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] h = new int[n];
        for (int i = 0; i < n; i++) {
            h[i] = sc.nextInt();
        }
        int[][] g = buildGraph(sc, n, m);
        int ans = 0;
        for (int i = 0; i < n; i++) {
            boolean good = true;
            for(int nv : g[i]){
                if(h[i] <= h[nv]){
                    good = false;
                    break;
                }
            }
            if(good)ans++;
        }
        System.out.println(ans);
        sc.close();

    }

    public static int[][] buildGraph(Scanner sc, int n, int m) {
        int[][] graph = new int[n][];
        int[][] edges = new int[m][2];
        int[] deg = new int[n];
        for (int i = 0; i < m; i++) {
            int a = sc.nextInt() - 1;
            int b = sc.nextInt() - 1;
            edges[i][0] = a;
            edges[i][1] = b;
            deg[a]++;
            deg[b]++;
        }
        for (int i = 0; i < n; i++) {
            graph[i] = new int[deg[i]];
        }
        for (int i = 0; i < m; i++) {
            int a = edges[i][0];
            int b = edges[i][1];
            graph[a][--deg[a]] = b;
            graph[b][--deg[b]] = a;
        }

        return graph;
    }

}


Measured memory_bytes: 64944
/**
 * C - Many Requirements
 * https://atcoder.jp/contests/abc165/tasks/abc165_c
 */
#include <bits/stdc++.h>
using namespace std;

int N, M, Q;
vector<int> a(50);
vector<int> b(50);
vector<int> c(50);
vector<int> d(50);
 
int calcScore(vector<int> A) {
    int sum = 0;

    for (int i = 0; i < Q; i++) {
        if (A.at( b.at(i) - 1) - A.at( a.at(i) - 1) == c.at(i)) {
            sum += d.at(i);
        }
   }
   return sum;
}
 
int main() {
    // 正整数 N , M , Q と、4 つの整数の組 ( ai , bi , ci , di ) Q 組が与えられます。
    // 以下の条件を満たす数列 A を考えます。
    // Aは、長さ Nの正整数列である。
    // 1≤A1≤A2≤⋯≤AN≤M
    // この数列の得点を、以下のように定めます。 
    // Abi−Aai=ci を満たすような i についての、 di の総和 (そのような i が存在しないときは 0)
    // A の得点の最大値を求めてください。
    cin >> N >> M >> Q;
    for (int i = 0; i < Q; i++) {
        cin >> a.at(i) >> b.at(i) >> c.at(i) >> d.at(i);
    }

    // 全パターンを検査する
    int highScore = 0;
    vector<int> A(10);
    for (int i1 = 1; i1 <= M; i1++) {
        A.at(0) = i1;
    for (int i2 = i1; i2 <= M; i2++) {
        A.at(1) = i2;
    for (int i3 = i2; i3 <= M; i3++) {
        A.at(2) = i3;
    for (int i4 = i3; i4 <= M; i4++) {
        A.at(3) = i4;
    for (int i5 = i4; i5 <= M; i5++) {
        A.at(4) = i5;
    for (int i6 = i5; i6 <= M; i6++) {
        A.at(5) = i6;
    for (int i7 = i6; i7 <= M; i7++) {
        A.at(6) = i7;
    for (int i8 = i7; i8 <= M; i8++) {
        A.at(7) = i8;
    for (int i9 = i8; i9 <= M; i9++) {
        A.at(8) = i9;
    for (int i10 = i9; i10 <= M; i10++) {
        A.at(9) = i10;
        int score = calcScore(A);
        if (score > highScore) {
            highScore = score;
        }
    }
    }
    }
    }
    }
    }
    }
    }
    }
    }

    cout << highScore << endl;
}
 

Measured memory_bytes: 3644
#include<iostream>
#include<queue>
#include<map>
#include<algorithm>
using namespace std;

#define fs first
#define sc second
typedef pair<int,int> P;
typedef pair<P,P> P2;

int h,w,n,g[8],d[8],s[8],e[8];
int v[8][101];
char m[20][20];
int num,sy,sx;
int c[20][20][101][1<<8];
int dy[] = {-1,0,1,0}, dx[] = {0,1,0,-1};

int main(){
  while(cin >> w >> h,w||h){
    for(int i=0;i<h;i++)
      for(int j=0;j<w;j++){
	cin >> m[i][j];
	if(m[i][j] == 'P'){
	  sy = i; sx = j;
	}
      }

    cin >> n;
    map<int,int> b;
    for(int i=0;i<n;i++){
      cin >> g[i] >> d[i] >> s[i] >> e[i];
      if(b.find(g[i]) == b.end())b[g[i]] = (int)b.size()-1;
    }
    num = b.size();

    for(int i=0;i<num;i++)
      for(int j=0;j<=100;j++)v[i][j] = 0;
    for(int i=0;i<n;i++)
      for(int j=s[i];j<e[i];j++)v[b[g[i]]][j] += d[i];
    
    for(int i=0;i<h;i++)
      for(int j=0;j<w;j++)
	for(int k=0;k<=100;k++)
	  for(int l=0;l<(1<<num);l++)c[i][j][k][l] = -1;
    c[sy][sx][0][0] = 0;

    for(int k=0;k<100;k++){
      for(int i=0;i<h;i++){
	for(int j=0;j<w;j++){
	  for(int l=0;l<(1<<num);l++){
	    if(c[i][j][k][l]<0)continue;
	    for(int dir=0;dir<4;dir++){
	      int ty = i+dy[dir], tx = j+dx[dir];
	      if(ty<0 || tx<0 || h<=ty || w<=tx)continue;

	      if('0'<=m[ty][tx] && m[ty][tx]<='9'){
		int x = b[m[ty][tx]-'0'];
		if((l>>x)&1)continue;
		if(!v[x][k])continue;
		int ts = l|(1<<x);
		c[i][j][k][ts] = max(c[i][j][k][ts],c[i][j][k][l]+v[x][k]);
	      }else c[ty][tx][k+1][l] = max(c[ty][tx][k+1][l],c[i][j][k][l]);
	    }
	  }
	}
      }
    }

    int ans = 0;
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	for(int k=0;k<(1<<num);k++)ans = max(ans,c[i][j][100][k]);
      }
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 41600
#include <iostream>
#include <cmath>
#include <math.h>
#include <stdio.h>
#include <vector>
#include <queue>
#include <map>
#include <stack>
#include <string>
#include <set>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <fstream>
#include <deque>
using namespace std;

#define mp make_pair
#define pb push_back
#define ll long long
#define pii pair<int, int>
#define f first
#define PI 3.14159265358979323846
#define s second
#define all(a) a.begin(), a.end()
#define sz(a) (int)a.size()

const int inf = (int)1e9;
const int mod = inf+7;

int a, b;

int main(){

	scanf("%d%d", &a, &b);
	if(a+b>=10){
		printf("error\n");
	}else{
		printf("%d\n", a+b);
	}
	
	return 0;
}

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

// @@ !! LIM()

bool solve() {
  ll N; cin >> N;
  vector<ll> v(N);
  ll amin = 1000;
  ll amax = 0;
  for (ll i = 0; i < N; i++) {
    ll a; cin >> a;
    v.at(a)++;
    amin = min(amin, a);
    amax = max(amax, a);
  }
  if (amin == 1) {
    if (N == 2) return v.at(1) == 2;
    else return v.at(1) == 1 && v.at(2) == N - 1;
  }
  if (v.at(amin) >= 3) return false;
  else if (v.at(amin) == 1) {
    if (amax != 2 * amin) return false;
    for (ll i = amin + 1; i <= amax; i++) if (v.at(i) <= 1) return false;
    return true;
  }else if (v.at(amin) == 2) {
    if (amax != 2 * amin - 1) return false;
    for (ll i = amin + 1; i <= amax; i++) if (v.at(i) <= 1) return false;
    return true;
  }else {
    assert(0);
  }
  
}

int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  cout << (solve() ? "Possible" : "Impossible") << endl;

  return 0;
}



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

int main(){
    int N,K;
    cin>>N>>K;
    int l[N];
    for(int i=0;i<N;i++){
        cin>>l[i];
    }
    int r=0;
    if((N-1)%(K-1)){r=(N-1)/(K-1)+1;}
    else{r=(N-1)/(K-1);}
    cout<<r<<endl;
    return 0;
}



Measured memory_bytes: 640
n, m = gets.split.map(&:to_i)
s = m.times.map { _, *s = gets.split.map(&:to_i); s }
p = gets.split.map(&:to_i)

puts 0.upto(2**n - 1).count { |i|                                                                                                                                                                                                                                             
  b = 0.upto(n-1).map { |j| (i / 2**j) % 2 == 0 }
  m.times.all? { |j| (s[j].count { |k| b[k-1] }) % 2 == p[j] }
}

Measured memory_bytes: 2044
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair <int, int> pii;
typedef vector<int> vi;

#define mp make_pair
#define pb push_back

#define FOR(i, a, b) for (int i=a; i<b; i++)
#define F0R(i, a) for (int i=0; i<a; i++)
 
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define endl "\n"
 
const int MOD = 1000000007;
double PI = 4*atan(1);

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);
	int N; cin >> N;
	vi A(N); 
	F0R(i,N) cin >> A[i];
	ll i = 0, ans = 0;
	F0R(i,N) {
		ans += A[i]/2;
		A[i] %= 2;
		if (i != (N-1) && A[i]>0 && A[i+1]>0) {
			ans++;
			A[i+1] --;
		}
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 640
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();

        if(A+B<10){
            System.out.println(A + B);
        }
        else{
            System.out.println("error");
        }
    }
}

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

int main(){
  int h,w,count;
  cin >> h >> w;
  vector<string> v(h);
  for (int i=0; i<h; i++){
    cin >> v.at(i);
  }
  
  for (int i=0; i<h; i++){
    for (int j=0; j<w; j++){
      if (v.at(i).at(j) == '.'){
        count = 0;
        for (int k=-1; k<2; k++){
          for (int l=-1; l<2; l++){
            if(i+k >= 0 && i+k < h && j+l >= 0 && j+l < w)
              if (v.at(i+k).at(j+l) == '#') count++;
          }
        }
        v.at(i).at(j) = '0' + count;
      }
    }
  }

  for (int i=0; i<h; i++){
   for (int j=0; j<w; j++){
      cout << v.at(i).at(j);
    }
    cout << endl;
  }
}
  

Measured memory_bytes: 256
n, k = map(int, input().split())
h = list(map(int, input().split()))

inf = 1e18
dp = [inf] * (n + 10)
dp[0] = 0
for i in range(1, n):
    for j in range(1, k + 1):
        if i - j >= 0:
            dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j]))
print(dp[n - 1])


Measured memory_bytes: 55392
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <math.h>
#include <bitset>
#include <queue>
#include <set>
#include <iomanip>
#include <math.h>
#include <assert.h>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr long long int infll = 1001001001001001LL;
constexpr int INF = 1000000007;
constexpr int inf = 1000000007;
const int mod = 1000000007;

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

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

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

inline double nCr(const int n, int r)
{
    if (n == 0)
    {
        return 0;
    }
    if (r == 0)
    {
        return 1;
    }
    if (r == 1)
    {
        return n;
    }
    if (n == r)
    {
        return 1;
    }

    if (r > n / 2)
    {
        r = n / 2;
    }

    double result = 1;
    for (double i = 1; i <= r; i++)
    {
        result *= (n - i + 1) / i;
    }

    return (result);
}

template <typename T>
T seinomi(T a)
{
    if (a > 0)
    {
        return a;
    }
    else
    {
        return 0;
    }
}

template <typename T>
map<T, T> soinsuubunkai(T n) //連想配列[素因数f.first][個数f.second]
{
    map<T, T> ret;
    for (T i = 2; i * i <= n; i++)
    {
        while (n % i == 0)
        {
            ret[i]++;
            n /= i;
        }
    }
    if (n != 1)
        ret[n] = 1;
    return ret;
}

template <typename T>
T ketasuu(T num)
{
    return std::to_string(num).length();
}

int kaizyou(int k)
{
    int sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

template <class ForwardIt, class T>
void iota(ForwardIt first, ForwardIt last, T value)
{
    while (first != last)
    {
        *first++ = value;
        ++value;
    }
}

//小数点以下10桁テンプレート（main関数内の最初に貼付け）
//std::cout << std::fixed << std::setprecision(10);

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

int main()
{
    ll n;
    cin>>n;
    ll r;
    cin>>r;
if(n<10){
    cout<<r+100*(10-n)<<endl;
}
else{
    cout<<r<<endl;
}
}










Measured memory_bytes: 256
L = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(L[int(input())-1])

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string S;
  cin >> S;
  int ans = 0;
  for(int i = 0; i < 4; i++) {
    if(S[i] == '+')
      ans++;
    else
      ans--;
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <assert.h>
using namespace std;
typedef long long ll;

template <class T>
struct BIT {
	int n;
	vector<T> x;
	BIT(int n_ = 0) : n(n_), x(n + 1, 0) {}
	int size() const { return n; }
	T sum(int r) const {
		T S = 0;
		for(r = r - 1; r >= 0; r = (r & (r + 1)) - 1) S += x[r];
		return S;
	}
	T sum(int l, int r) const { return sum(r) - sum(l); }
	void add(int k, const T &a) {
		for(; k < n; k |= k + 1) x[k] += a;
	}
	void set(int k, const T &a) { add(k, a - sum(k, k + 1)); }
	int lower_bound(T x) {
		int ng = -1, ok = n - 1;
		while(abs(ng - ok) > 1) {
			int mid = (ng + ok) / 2;
			if(sum(0, mid + 1) >= x) ok = mid;
			else ng = mid;
		}
		return ok;
	}
};

typedef pair<ll, int> P;

ll a[200000];
int pos[200000];

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

	ll N, K;
	cin >> N >> K;
	BIT<ll> bit(N);

	vector<ll> s;
	vector<P> p;
	ll sum = 0;
	for(int i = 0; i < N; i++) {
		cin >> a[i];
		sum += a[i];

		s.push_back(sum - K * (i + 1));
		p.push_back({ sum - K * (i + 1), i });
		bit.add(i, 1);
	}
	sort(s.begin(), s.end());
	sort(p.begin(), p.end());

	for(int i = 0; i < N; i++) {
		pos[p[i].second] = i;
	}

	ll ans = 0;
	ll m = 0;
	for(int i = 0; i < N; i++) {
		int idx = lower_bound(s.begin(), s.end(), m) - s.begin();
		ans += bit.sum(idx, N);
		m += a[i] - K;
		bit.add(pos[i], -1);
	}
	cout << ans << endl;
}

Measured memory_bytes: 10468
#include <cstdio>
#include <cstring>
#include <algorithm>

using std::max;
using std::min;

const int MAXN=1e5+5;
char s[MAXN];

int main(){
	scanf("%s",s+1);
	int n=strlen(s+1),ans=n;
	for(int i=1;i<=n;++i){
		if(s[i]!=s[i+1])
			ans=min(ans,max(i,n-i));
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long n,a,k[100005],ans=99999999999;
  cin>>n>>a;
  for(int i=0;i<n;++i)cin>>k[i];
  sort(k,k+n);
  for(int i=0;i<=n-a;++i){ans=min(ans,k[i+a-1]-k[i]);}
  cout<<ans<<endl;
}


Measured memory_bytes: 1024
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

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

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

int main() {
  double W,H,x,y;
  cin>>W>>H>>x>>y;
  
  double ans = W*H/2;
  if(x==W/2 && y==H/2) cout<<ans<<" "<<1<<endl;
  else cout<<ans<<" "<<0<<endl;
  
  return 0;
}

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

#define ll long long
#define ii pair<int, int>
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
#define pi 3.141592653
#define oo 1000000007
#define loo 10000000000000007

#define prime 1000000007

#define W(x) cerr << "\033[31m" << #x << " = " << x << "\033[0m" << "\n";
using namespace std;

int v[5050], u[5050];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int n; cin >> n;
    queue<ll> q;
    vl ans;
    for (ll i = 1; i < 10; ++i){
        q.push(i);
        ans.pb(i);
    }
    while((int)ans.size() < n){
        ll aux = q.front();
        q.pop();
        ll d = aux%10;
        ll at = 10*aux+d-1;
        if(d > 0){
            q.push(at);
            ans.pb(at);
        }
        at = 10*aux+d;
        q.push(at);
        ans.pb(at);
        if(d < 9){
            at = 10*aux+d+1;
            q.push(at);
            ans.pb(at);
        }
    }
    cout << ans[n-1] << endl;
    
    return 0;
}

Measured memory_bytes: 4588
import java.util.*;
import java.awt.*;
import java.awt.geom.*;
import static java.lang.System.*;
import static java.lang.Math.*;
public class Main {
    public static void main(String[] $) {
        Scanner sc = new Scanner(in);
        String s=sc.next();
        if(s.compareTo("2019/04/30")<=0){
            out.println("Heisei");
        }else {
            out.println("TBD");
        }
    }
}

Measured memory_bytes: 23508
#include <bits/stdc++.h>
#define ft first
#define sc second
#define lb lower_bound
#define ub upper_bound
#define pb(t) push_back(t)
#define pt(num) cout << num << "\n"
#define chmax(a, b) (a<b ? a=b : 0)
#define chmin(a, b) (a>b ? a=b : 0)
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef map<ll, ll> Map;
static const ll INF=1e18;
static const ll MAX=1e5+7;
static const ll MOD=1e9+7;





int main(void) {
    string s;
    cin >> s;
    ll i, j, k;
    
    ll ans=0;
    for(i=0; i<s.size(); i++) {
        for(j=0; i+j<=s.size(); j++) {
            string t=s.substr(i, j);
            
            ll f=0;
            for(k=0; k<t.size(); k++) {
                if(t[k]!='A' && t[k]!='C' && t[k]!='G' && t[k]!='T')
                    f=1;
            }
            
            if(f) continue;
            else chmax(ans, j);
        }
    }
    
    pt(ans);
}








Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>

using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;

int main()
{
    LLONG X; cin >> X;
    LLONG c = 100;
    for (int i = 1;; ++i)
    {
        c *= 1.01;
        if (c >= X)
        {
            cout << i << endl;
            break;
        }
    }
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int a,b,m;
  cin >> a >> b >> m;
  vector<int>price_a(a);
  vector<int>price_b(b);
  for(int i=0;i<a;i++){
    cin >> price_a.at(i);
  }
  for(int i=0;i<b;i++){
    cin >> price_b.at(i);
  }
  vector<int> copy_a=price_a;
  vector<int> copy_b=price_b;
  sort(copy_a.begin(),copy_a.end());
  sort(copy_b.begin(),copy_b.end());
  int ans=copy_a.at(0)+copy_b.at(0);
  for(int i=0;i<m;i++){
    int x,y,c;
    cin >> x >> y >> c;
    int num=price_a.at(x-1)+price_b.at(y-1)-c;
    ans=min(ans,num);
  }
  cout << ans << endl;
}
    

Measured memory_bytes: 1792
from collections import Counter

def solve():
    H, W = map(int, input().split())
    cnt = Counter()
    for _ in range(H):
        cnt.update(input())
    
    x = []
    for v in cnt.values():
        n = v%4
        if n:
            x.append(n)
    
    yes = "Yes"
    no = "No"

    c = (H&1)+(W&1)

    if c == 0:
        if x:
            return no
        return yes
    
    elif c == 1:
        if H&1:
            a = W
        else:
            a = H
        if sum(x) > a:
            return no
        for y in x:
            if y&1:
                return no
        return yes

    else:
        if sum(x) > H+W-1:
            return no
        o = 0
        for y in x:
            if y&1:
                o += 1
        
        if o == 1:
            return yes
        
        return no

print(solve())

Measured memory_bytes: 9476
#include <stdio.h>
int main(){
	int h,m,s;
	int t;
	scanf("%d",&t);
	h=t/3600;
	t=t%3600;
	m=t/60;
	t=t%60;
	s=t;
	printf("%d:%d:%d\n",h,m,s);
	return 0;
}


Measured memory_bytes: 2112
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		boolean ans = true;
		ans = ans && (s.charAt(2) == s.charAt(3));
		ans = ans && (s.charAt(4) == s.charAt(5));
		System.out.println(ans ? "Yes" : "No");

	}

}


Measured memory_bytes: 21844
///apigs property
#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0) , cin.tie(0) , cout.tie(0)
#define F first
#define S second
#define pb push_back
#define vll vector< ll >
#define vi vector< int >
#define pll pair< ll , ll >
#define pi pair< int , int >
#define all(s) s.begin() , s.end()
#define sz(s) s.size()
#define md (s + e) / 2
#define mid (l + r) / 2
#define msdp(dp) memset(dp , -1 , sizeof dp)
#define mscl(dp) memset(dp , 0 , sizeof dp)
using namespace std;
typedef long long ll;
ll q, dp[100005], a[555555] , b[555555], k, l, m, n, o, p;
map < ll , ll > mp;
vll adj[555555];
const ll mod = 1e9+7;
ll mem(ll sum){
	if(sum == 0)return 0;
	ll &r = dp[sum];
	if(r != -1)return r;
	r = 0;
	for(ll i = 0 ; i < n ; i++){
		if(sum - a[i] >= 0 && mem(sum - a[i]) == 0){
			r = 1;
			break;
		}
	}
	return r;
}
void solve(){
	msdp(dp);
	cin >> n >> k;
	for(ll i = 0 ; i < n ; i++){
		cin >> a[i];
	}
	cout << (mem(k) ? "First" : "Second");
}
int main() {
    fast ;
	// cin >> q;
    q = 1;
    while(q--){
    	solve();
	}
}



Measured memory_bytes: 22076
#include<cstdio>
#include<cstring>
int main(){
    int n;
    char str[105];
    scanf("%d",&n);
    scanf("%s",str);
    if(n&1){
        printf("No");
        return 0;
    }
    int i=0,j=n/2;
    while(j<n&&str[i]==str[j]) i++,j++;
    if(j==n) printf("Yes");
    else printf("No"); 
    return 0;
}

Measured memory_bytes: 128
#include<iostream>
using namespace std;
int main()
{
	int n;
	cin >> n;
	int *H = new int[n+1];
	for (int i = 1; i <= n; i++)
		cin >> H[i];
	for (int i = 1; i <= n; i++)
	{
		cout << "node " << i << ": ";
		cout << "key = " << H[i]<<", ";
		if (i / 2 > 0)
			cout << "parent key = " << H[i / 2]<<", ";
		if (2 * i <= n)
			cout << "left key = " << H[2 * i] << ", ";
		if (2 * i + 1 <= n)
			cout << "right key = " << H[2 * i + 1] << ", ";
		cout << endl;
	}
	delete[] H;
}


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

int main(void)
{
  std::string s, t;
  std::cin >> s >> t;

  if (s == t.substr(0, s.size())) {
    std::cout << "Yes" << std::endl;
  }
  else {
    std::cout << "No" << std::endl;
  }
}

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

#define L(X) ((X)*2)
#define R(X) ((X)*2+1)
#define P(X) ((X)/2)

int main(void){
  int h[300];
  int n;
  
  cin >> n;
  for (int i=0; i<n; i++){
    cin >> h[i+1];
  }
  for (int i=1; i<=n; i++){
    cout << "node " << i << ": ";
    cout << "key = " << h[i] << ", ";
    if (P(i)>=1) cout << "parent key = " << h[P(i)] << ", ";
    if (L(i)<=n) cout << "left key = " << h[L(i)] << ", ";
    if (R(i)<=n) cout << "right key = " << h[R(i)] << ", ";
    cout << endl;
  }
  return 0;
}


Measured memory_bytes: 3076
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int w = sc.nextInt();
    int n = sc.nextInt();
    int[] values = new int[w];
    for(int i = 0; i < values.length; i++){
        values[i] = i+1;
    }
    for(int i = 0; i < n; i++){
        String str = sc.next();
        String[] ab = str.split(",");
        int a = Integer.parseInt(ab[0]) - 1;
        int b = Integer.parseInt(ab[1]) - 1;
        int c = values[a];
        values[a] = values[b];
        values[b] = c;
    }
    for(int i = 0; i < values.length; i++){
        System.out.println(values[i]);
    }
    }
}

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

int main(){


    map<char,bool> mpp;
    for(char c = 'A';c<='Z';c++){
        mpp[c]=false;
    }
    mpp['A'] = true;
    mpp['C'] = true;
    mpp['T'] = true;
    mpp['G'] = true;
    string s;
    cin>>s;
    int ans=0;
    for(int i=0;i<s.size();i++){
        int j=i;
        while(j<s.size()&&mpp[s[j]]){
            j++;
        }
        ans=max(ans,j-i);
        i=j;
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
def main():
    N = int(input())
    A = list(map(int, input().split()))

    ans = 1
    th = 1000000000000000000

    for a in A:
        if a == 0:
            print('0')
            return 0

    for a in A:
        ans *= a
        if ans > th:
            print('-1')
            return 0
    print(ans)


if __name__ == "__main__":
    main()


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

int main() {

int a,b=0;
  cin>>a;
  if(a==1){
	  cout<<1<<endl;
	  }
  else{
  for(int i=2;i<=a;i++){
    int j=i;
    while(j*i<=a){j*=i;}
    
    if(b<j&&j!=i){
		b=j;
		}
    }
  cout<<b<<endl;
  }
}



Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int max(int a,int b){return a>b?a:b;}
int main(){
	int n;
	cin>>n;
	for(int d=0;d<n;d++){
		string s,t;
		cin>>s;
		cin>>t;
		int i=0;
		reverse(s.begin(),s.end());
		reverse(t.begin(),t.end());
		string ans;
		int k=0;
		for(i=0;i<max(s.size(),t.size())+1;i++){
			int x,y;
			if(i>=s.size())x=0;
			else x=s[i]-'0';
			if(i>=t.size())y=0;
			else y=t[i]-'0';
			int z=x+y+k;
			k=z/10;
			char c=z%10+'0';
			if(i!=max(s.size(),t.size())||c!='0')ans.append(1,c);
		}
		reverse(ans.begin(),ans.end());
		if(ans.size()>=81)cout<<"overflow"<<endl;
		else cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 1208
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;

/*
<url:https://arc077.contest.atcoder.jp/tasks/arc077_a>
問題文============================================================
 長さ n の数列 a1,…,an が与えられます。 空の数列 b に対して、以下の操作を n 回行うことを考えます。
 
 i 回目には
 
 数列の i 番目の要素 ai を b の末尾に追加する。
 b を逆向きに並び替える。
 この操作をしてできる数列 b を求めて下さい。
=================================================================

解説=============================================================
dequeを用いたシミュレーションでO(n)
================================================================
*/
int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
    ll n; cin >> n;
    deque<ll> deq;
    for(int i = 0; i < n;i++){
        ll a; cin >> a;
        if(i%2 == 0){
            deq.push_back(a);
        }else{
            deq.push_front(a);
        }
    }
    if(n%2 == 0){
        for(auto it = deq.begin(); it!=deq.end();it++){
            cout << *it << " ";
        }
        cout << endl;
    }else{
        for(auto it = deq.rbegin(); it!=deq.rend();it++){
            cout << *it << " ";
        }
        cout << endl;
    }
	return 0;
}


Measured memory_bytes: 3840
loop do
  n, t, l, b = gets.split.map(&:to_i)
  break if n == 0
  lose = [false] * n
  back = [false] * n
  l.times{ lose[gets.to_i] = true }
  b.times{ back[gets.to_i] = true }
  board = 2.times.map { [0.0] * (n + 1) }
  board[0][0] = 1.0
  t.times do
    nboard = 2.times.map{ [0.0] * (n + 1) }
    n.times do |i|
      nboard[0][i] += board[1][i] if lose[i]
      (1..6).each do |k|
        j = i + k < n + 1 ? i + k : 2 * n - (i + k)
        if lose[j]
          nboard[1][j] += board[0][i] / 6
        elsif back[j]
          nboard[0][0] += board[0][i] / 6
        else nboard[0][j] += board[0][i] / 6
        end
      end
    end
    nboard[0][n] += board[0][n]
    board = nboard
  end
  printf "%.8f\n" % board[0][n]
end

Measured memory_bytes: 9648
#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <queue>
#include <cmath>
#include <stdio.h>

#define _ << " " <<
#define debug(x) #x << " = " << x

#define ll long long
#define ull unsigned long long

const int maxn = 2e5+100;

int seg[maxn << 2], seg1[maxn << 2];

void upright(int i, int c = 1, int l = 0, int r = maxn) {
    if (i == l && l == r - 1) {
        seg[c] = i;

        return;
    } else if (l == r - 1) return;
    int le = c << 1;
    int ri = le ^ 1;
    if (l <= i && i < r) {
        int mid = (l + r) >> 1;

        upright(i, le, l, mid);
        upright(i, ri, mid, r);
    }

    seg[c] = std::min(seg[le], seg[ri]);
}

const int inf = 0x3f3f3f3f;
int getright(int ql, int qr, int c = 1, int l = 0, int r = maxn) {
    if (r <= l) return inf;
    if (ql <= l && r <= qr) {
        return seg[c];
    } else if (ql >= r || qr <= l) {
        return inf;
    } else {
        int le = c << 1;
        int ri = le ^ 1;
        int mid = (l + r) >> 1;

        return std::min(getright(ql, qr, le, l, mid), getright(ql, qr, ri, mid, r));
    }
}

void upleft(int i, int c = 1, int l = 0, int r = maxn) {
    if (i == l && l == r - 1) {
        seg1[c] = i;
        return;
    } else if (l == r - 1) return;
    int le = c << 1;
    int ri = le ^ 1;
    if (l <= i && i < r) {
        int mid = (l + r) >> 1;

        upleft(i, le, l, mid);
        upleft(i, ri, mid, r);
    }

    seg1[c] = std::max(seg1[le], seg1[ri]);
}

int getleft(int ql, int qr, int c = 1, int l = 0, int r = maxn) {
    //std::cout << "getleft" _ debug(ql) _ debug(qr) _ debug(c) _ debug(l) _ debug(r) << std::endl;
    if (r <= l) return -1;
    if (ql <= l && r <= qr) {
        //std::cout << debug(seg1[c]) << std::endl;
        return seg1[c];
    } else if (ql >= r || qr <= l) {
        return -1;
    } else {
        int le = c << 1;
        int ri = le ^ 1;
        int mid = (l + r) >> 1;

        return std::max(getleft(ql, qr, le, l, mid), getleft(ql, qr, ri, mid, r));
    }
}

using pii = std::pair<ll, ll>;
pii a[maxn];

int main() {
    std::ios::sync_with_stdio(false);

    int n;
    std::cin >> n;

    for (int i =0 ; i < n; i++) {
        std::cin >> a[i].first;
        a[i].second = i;
    }

    std::memset(seg, 0x3f, sizeof(seg));
    std::memset(seg1, -1, sizeof(seg1));

    std::sort(a, a + n);
    ll s = 0;

    for (int i =0; i < n; i++) {
        int b = getleft(0, a[i].second + 1);
        int e = getright(a[i].second + 1, n);
        //std::cout << debug(b) _ debug(e) << std::endl;
        if (b == -1) b = 0;
        else ++b;
        if (e == inf) e = n - 1;
        else
            e--;

        s += (a[i].second - b + 1) * (e - a[i].second + 1) * a[i].first;

        //std::cout << debug(a[i].second) << std::endl;
        //std::cout << debug(b) _ debug(e) _ debug(a[i].second) << std::endl;

        upleft(a[i].second);
        upright(a[i].second);
    }

    std::cout << s << std::endl;

    return 0;
}

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

using namespace std;
typedef long long ll;





//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define RALL(x) (x).rbegin(),(x).rend() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000
#define MOD 10000007
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define seq vector
#define READLINE(vec,time) for(int indexofvec=0;indexofvec<time;indexofvec++)cin>>vec[indexofvec]
#define VPRINT(vec) for(auto i : vec){cout << i<<" ";}cout<<endl;
#define lambda []
#define clambda [=]
#define reflambda [&]

template<typename A,typename B,class functype>
void select(vector<A>& in,vector<B>& out,functype func){
    out.resize(in.size());

    for(int i =0;i<in.size();i++){
        out[i]=func(in[i]);
    }


}








signed main(){

    vector<string> A(3);
    cin >> A[0] >> A[1] >> A[2];

    vector<int> B(0);
    select(A,B,lambda(string i)->int{return stoi(i);});

    cout << (B[0] + B[1] + B[2] <= 21 ? "win" : "bust") << endl;


}

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

using namespace std;

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

bool win[100005];
int n, k;
int l[105];

void solve() {
  cin >> n >> k;
  for(int i = 0; i < n; i++) {
    cin >> l[i];
  }
  for(int a = 1; a <= k; a++) {
    for(int i = 0; i < n; i++) {
      if(l[i] <= a) {
        win[a] |= !win[a-l[i]];
      }
    }
  }
  cout << (win[k] ? "First\n" : "Second\n");
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  solve();
}


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

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

  if(b - a > k || c - a > k || d - a > k || e - a > k || c - b > k || d - b > k || e - b > k || d - c  > k || e - c > k || e - d > k){
  cout << ":(" <<endl;
  }
  else{
    cout << "Yay!" <<endl;
  }

}


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

const int maxn=1e6+7;
int a[maxn],n;
int f[maxn][2];

int main()
{
	char s=getchar();
	while(s<'0'||s>'9') s=getchar();
	while(s>='0'&&s<='9') a[++n]=s-'0',s=getchar();
	for(int i=n;i>=0;--i) {
		for(int j=0;j<=9;++j)
			f[i][0]=min(f[i+1][0]+a[i+1],f[i+1][1]+10-a[i+1]);
			f[i][1]=min(f[i+1][0]+a[i+1]+1,f[i+1][1]-1+10-a[i+1]);
	}
	printf("%d",f[0][0]);
}

Measured memory_bytes: 11904
#![allow(non_snake_case)]
#![allow(unused_variables)]
#![allow(dead_code)]

fn main() {
    let (N, K, Q): (usize, i64, i64) = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        let mut iter = line.split_whitespace();
        (
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap()
        )
    };
    let A: Vec<usize> = (0..Q)
        .map(|_| {
                let mut line: String = String::new();
                std::io::stdin().read_line(&mut line).unwrap();
                line.trim().parse().unwrap()
        })
        .collect();

    let mut c = vec![0; N + 1];
    for &a in &A { c[a] += 1; }
    let ans = (1..(N + 1))
        .map(|i| if K - (Q - c[i]) > 0 { "Yes" } else { "No" })
        .collect::<Vec<_>>()
        .join("\n");

    println!("{}", ans);
}


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

int main(){
  char c;
  cin >> c;
  switch (c)
  {
  case 'a':
    cout << "vowel" << endl;
    break;
  case 'i':
    cout << "vowel" << endl;
    break;
  case 'u':
    cout << "vowel" << endl;
    break;  
  case 'e':
    cout << "vowel" << endl;
    break;
  case 'o':
    cout << "vowel" << endl;
    break;
  default:
    cout << "consonant" << endl;
    break;
  }
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

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

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S; cin>>S;
    int N = S.size();
    ll sum=0;
    rep(i,N){
        int c = S[i]-'0';
        sum+=c;
    }
    if (sum%9==0){
        cout<<"Yes\n";
    }else{
        cout<<"No\n";
    }
    return 0;
}


Measured memory_bytes: 3712
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <iostream>
#include <string>
#include <set>
#include <map>
#include <unordered_map>
#include <complex>
#include <iomanip>
#include <cmath>
#include <tuple>
using namespace std;

int main() {
    int n, k;
    cin >> n >> k;

    vector<long long> tree(n);
    for (int i = 0; i < n; i++) cin >> tree[i];

    sort(tree.begin(), tree.end());
    long long res = 1000000000;
    for (int i = k - 1; i < n; i++) res = min(res, tree[i] - tree[i - k + 1]);

    cout << res << endl;
}


Measured memory_bytes: 1024
n=int(input())
a=list(map(int,input().split()))
if n%2==0:
  b=sorted([2*i+1 for i in range((n+1)//2)]*2)
else:
  b=sorted([2*i for i in range(1,(n+1)//2)]*2+[0])

if sorted(a)!=b:
  ans=0
else:
  ans=2**(n//2)
print(ans%(10**9+7))

Measured memory_bytes: 14008