akhauriyash/Code-Regression huggingface dataset:
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include <stdio.h>
#include <ctype.h>
#include <string>
#include <iostream>
#include <vector>
#include <stack>
#include <fstream>
#include <sstream>
#include <queue>
#include <exception>
#include <cmath>
#include <numeric>
#include <map>
#include <algorithm>

#define INF 100000000
#define MAX_N 12

using namespace std;
typedef long long int lint;

double dp[MAX_N][1 << MAX_N];
double d[MAX_N][MAX_N];
double rad[MAX_N];

//S : ???????????±???????????????, i : ?????????????????±??????
double rec(int S, int i, int n) {
	if (dp[i][S] < INF) return dp[i][S];

	double r = 0;

	//1????????????
	if (S == (1 << i)) {
		return dp[i][S] = rad[i];
	}

	//??¨????????????
	if (S == (1 << n) - 1) {
		r = rad[i];
	}

	double res = INF;
	//S ?????? i ??????????????????
	int SS = S ^ (1 << i);
	for (int j = 0; j < n; j++) {
		if ((SS >> j) & 1) {
			res = min(res, rec(SS, j, n) + d[j][i] + r);
		}
	}

	return dp[i][S] = res;
}

void init(int n) {
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < (1 << n); j++) {
			dp[i][j] = INF + 1;
		}
	}
}

bool AOJ0120()
{
	string str;
	if (!getline(cin, str)) return false;

	istringstream iss(str);
	
	int width;
	vector<int> radii;

	iss >> width;
	int radius;
	while (iss >> radius) {
		radii.push_back(radius);
	}

	int n = radii.size();

	//init
	init(n);
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			d[i][j] = sqrt(radii[i] * radii[j]) * 2;
		}
		rad[i] = radii[i];
	}

	double ans = INF + 1;
	for (int i = 0; i < n; i++) {
		ans = min(ans, rec((1 << n) - 1, i, n));
	}

	if (ans < width + 1e-8) cout << "OK" << endl;
	else cout << "NA" << endl;
	
	return true;
}

int main()
{
	while (AOJ0120()) {

	}
	return 0;
}

Measured memory_bytes: 3588
// eddy1021
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef double D;
typedef long double LD;
typedef long long LL;
typedef pair<int,int> PII;
typedef pair<LL,LL> PLL;
#define mod9 1000000009LL
#define mod7 1000000007LL
#define INF  1023456789LL
#define INF16 10000000000000000LL
#define eps 1e-9
#define SZ(x) (int)(x).size()
#define ALL(x) (x).begin(), (x).end()
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#ifndef ONLINE_JUDGE
#define debug(...) printf(__VA_ARGS__)
#else 
#define debug(...)
#endif
inline LL getint(){
  LL _x=0,_tmp=1; char _tc=getchar();    
  while( (_tc<'0'||_tc>'9')&&_tc!='-' ) _tc=getchar();
  if( _tc == '-' ) _tc=getchar() , _tmp = -1;
  while(_tc>='0'&&_tc<='9') _x*=10,_x+=(_tc-'0'),_tc=getchar();
  return _x*_tmp;
}
inline LL add( LL _x , LL _y , LL _mod = mod7 ){
  _x += _y;
  return _x >= _mod ? _x - _mod : _x;
}
inline LL sub( LL _x , LL _y , LL _mod = mod7 ){
  _x -= _y;
  return _x < 0 ? _x + _mod : _x;
}
inline LL mul( LL _x , LL _y , LL _mod = mod7 ){
  _x *= _y;
  return _x >= _mod ? _x % _mod : _x;
}
LL mypow( LL _a , LL _x , LL _mod ){
  if( _x == 0 ) return 1LL;
  LL _ret = mypow( mul( _a , _a , _mod ) , _x >> 1 , _mod );
  if( _x & 1 ) _ret = mul( _ret , _a , _mod );
  return _ret;
}
LL mymul( LL _a , LL _x , LL _mod ){
  if( _x == 0 ) return 0LL;
  LL _ret = mymul( add( _a , _a , _mod ) , _x >> 1 , _mod );
  if( _x & 1 ) _ret = add( _ret , _a , _mod );
  return _ret;
}
inline bool equal( D _x ,  D _y ){
  return _x > _y - eps && _x < _y + eps;
}
void sleep( double sec = 1021 ){
  clock_t s = clock();
  while( clock() - s < CLOCKS_PER_SEC * sec );
}
#define Bye exit(0)
int __ = 1 , _cs;
/*********default*********/
void build(){

}
#define N 1021
int n , a[ 2 ][ N ];
void init(){
  n = getint();
  for( int i = 0 ; i < 2 ; i ++ )
    for( int j = 1 ; j <= n ; j ++ )
      a[ i ][ j ] = getint();
}
void solve(){
  a[ 1 ][ 1 ] += a[ 0 ][ 1 ];
  for( int j = 2 ; j <= n ; j ++ ){
    a[ 0 ][ j ] += a[ 0 ][ j - 1 ];
    a[ 1 ][ j ] += max( a[ 0 ][ j ] , a[ 1 ][ j - 1 ] );
  }
  cout << a[ 1 ][ n ] << endl;
}
int main(){
  build();
  //__ = getint();
  while( __ -- ){
    init();
    solve();
  }
}


Measured memory_bytes: 764
#include<bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define MOD	1000000007
#define int	long long
#define pii pair<int,int> 
#define vi vector<int>
using namespace std;

const int mod = 998244353;

int32_t main(){
	int n;
	cin >> n;
	vector<pair<int,int>> v(n+1);
	for(int i = 0; i < n; i++)
		cin >> v[i].first >> v[i].second;
	
	v[n] = {1LL*3e9,0LL};
	sort(v.begin(),v.end());
	
	int dp[n+1];
	dp[n] = 1;
	stack<int> s;
	s.push(n);
	for(int i = n-1; i >= 0; i--){
		while(v[s.top()].first - v[i].first < v[i].second){
			s.pop();
		} 
		dp[i] = (dp[i+1] + dp[s.top()]) % mod;
		s.push(i);
	}
	
	cout << dp[0] << endl;

	return 0;
}



Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define MOD 1000000007
#define INF 1000000000000000
#define fi first
#define se second
#define all(v) v.begin(),v.end()
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
struct edge{int to,cost;};
typedef pair<int,int> P;
int gcd(int a,int b){
	if(b==0)return a;
	return gcd(b,a%b);
}
int lcm(int a,int b){
	return a/gcd(a,b)*b;
}
bool prime(int a){
	if(a==1)return false;
	for(int i=2;i*i<=a;i++){
		if(a%i==0)return false;
	}
	return true;
}
bool kosa(double ax,double ay,double bx,double by,double cx,double cy,double dx,double dy){//線分の交差判定
	double ta=(cx-dx)*(ay-cy)+(cy-dy)*(cx-ax);
	double tb=(cx-dx)*(by-cy)+(cy-dy)*(cx-bx);
	double tc=(ax-bx)*(cy-ay)+(ay-by)*(ax-cx);
	double td=(ax-bx)*(dy-ay)+(ay-by)*(ax-dx);
	return tc*td<0&&ta*tb<0;
}
int kaijo(int n){
	int ans=1;
	for(int i=2;i<=n;i++){
		ans*=i;
		ans%=MOD;
	}
	return ans;
}
int modpow(int a,int b){
	if(b==0)return 1;
	if(b%2)return modpow(a,b-1)*a%MOD;
	return modpow(a,b/2)*modpow(a,b/2)%MOD;
}
int comb(int a,int b){
	return kaijo(a)*modpow(kaijo(a-b),MOD-2)%MOD*modpow(kaijo(b),MOD-2)%MOD;
}
int a,b,c,d,e,k;
signed main(){
	cin>>a>>b>>c>>d>>e>>k;
	if(e-a<=k)puts("Yay!");
	else puts(":(");
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <queue>
#include "math.h"
#include <complex>
#include <iomanip>
#define ifor(i,a,b) for (int i=(a);i<(b);i++)
#define rfor(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define rep(i,n) for (int i=0;i<(n);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
using namespace std;
typedef long double ld;
typedef long long int  lli;
typedef complex <double> P;
const double eps = 1e-11;
int vex[4]={1,0,-1,0};
int vey[4]={0,1,0,-1};
int main(){
	int N ,M,a,b;
	int x [100004];
	int p [100004]={};
	p[1]=1;
	cin >> N >> M;
	for(int i = 1;i<=N;i++){
		x[i]=1;
	}
	for(int i = 0;i<M;i++){
		cin >> a >> b;
		if(p[a]){
			p[b]=1;
			x[a]--;
			x[b]++;
		}else if(p[a]==0){
			x[a]--;
			x[b]++;
		}
		if(x[a]==0)p[a]=0;
	}
	int ans = 0;
	for(int i=1;i<=N;i++){
		if(p[i])ans++;
	}
	cout << ans << endl;
	
}




Measured memory_bytes: 1272
def combi(count):
  if n==1:return 0
  elif n==2:return 1
  else:return int(count*(count-1)/2)
 
 
n=int(input())
alis=list(map(int,input().split()))
dick={st:0 for st in set(alis)}
for i in range(n):
  p=alis[i]
  dick[p]+=1
#print(dick)
point=0
for v in dick.values():
  point+=combi(v)
 
 
for i in range(n):
  idx=alis[i]
  minus=dick[idx]-1
  print(point-minus)

Measured memory_bytes: 92524
#include <stdio.h>

int sqs[128];

int p[10][10];
int main(void) {
	for (int i = 1; i < 128; i++) {
		sqs[i] = i*i;
	}

	int n, d;
	scanf("%d%d", &n, &d);
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < d; j++) {
			scanf("%d", &p[i][j]);
		}
	}

	int cnt = 0;
	for (int i = 0; i < n-1; i++) {
		for (int j = i+1; j < n; j++) {
			int dist = 0;
			for (int k = 0; k < d; k++) {
				int c = p[i][k]-p[j][k];
				dist += c*c;
			}

			for (int k = 0; k < 128; k++) {
				if (dist == sqs[k]) {
					cnt++;
					break;
				}
			}
		}
	}

	printf("%d\n", cnt);
}


Measured memory_bytes: 128
# -*- coding: utf-8 -*-

import sys
import os
import math

def distance(v0, v1, p):
    n = len(v0)
    s = 0
    for i in range(n):
        diff = abs(v0[i] - v1[i])
        s += diff ** p
    return s ** (1/p)

def chebyshev(v0, v1):
    n = len(v0)
    ret = 0
    for i in range(n):
        diff = abs(v0[i] - v1[i])
        if diff > ret:
            ret = diff
    return ret

n = int(input())
v0 = list(map(float, input().split()))
v1 = list(map(float, input().split()))

print(distance(v0, v1, 1))
print(distance(v0, v1, 2))
print(distance(v0, v1, 3))
print(chebyshev(v0, v1))

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

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

  string ans;

  if (R < 1200) {
    ans = "ABC";
  } else if (R < 2800) {
    ans = "ARC";
  } else {
    ans = "AGC";
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int prime(int);

int main(){
int n,*data,i,count=0,check;
scanf("%d",&n);
data=(int*)malloc(n*sizeof(int));
for(i=0;i<n;i++) scanf("%d",&data[i]);
for(i=0;i<n;i++){
check=0;
check=prime(data[i]);
if(check==1) count++;
}

printf("%d\n",count);
 
free(data); 
return 0;
}

int prime(int data){
int i;

if(data==2) return 1;
if(data<2||data%2==0) return 0;
i=3;
while(i<=sqrt(data)){
if(data%i==0) return 0;

i+=2;
}
return 1;
}

Measured memory_bytes: 628
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <stack>
#include <set>
#include <bitset>
using namespace std;
#define fast_io ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()

typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;

ll mpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = mpow(a,b/2); return memo*memo%MOD;}
  else return mpow(a,b-1) * a % MOD;
}
ll lpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = lpow(a,b/2); return memo*memo;}
  else return lpow(a,b-1) * a;
}
ll gcd(ll a, ll b){
  if(b==0) return a;
  else return gcd(b, a%b);
}
vector<ll> kaijo_memo;
ll kaijo(ll n){
  if(kaijo_memo.size() > n) return kaijo_memo[n];
  if(kaijo_memo.size() == 0) kaijo_memo.push_back(1);
  while(kaijo_memo.size() <= n) kaijo_memo.push_back(kaijo_memo[kaijo_memo.size()-1] * kaijo_memo.size() % MOD);
  return kaijo_memo[n];
}
vector<ll> gyaku_kaijo_memo;
ll gyaku_kaijo(ll n){
  if(gyaku_kaijo_memo.size() > n) return gyaku_kaijo_memo[n];
  if(gyaku_kaijo_memo.size() == 0) gyaku_kaijo_memo.push_back(1);
  while(gyaku_kaijo_memo.size() <= n) gyaku_kaijo_memo.push_back(gyaku_kaijo_memo[gyaku_kaijo_memo.size()-1] * mpow(gyaku_kaijo_memo.size(), MOD-2) % MOD);
  return gyaku_kaijo_memo[n];
}

ll nCr(ll n, ll r){
  if(n == r) return 1;//0個の丸と-1個の棒みたいな時に時に効く？不安.
  if(n < r || r < 0) return 0;
  ll ret = 1;
  ret *= kaijo(n); ret %= MOD;
  ret *= gyaku_kaijo(r); ret %= MOD;
  ret *= gyaku_kaijo(n-r); ret %= MOD;
  return ret;
}

struct edge{
  ll to,id;
};

vector<edge> G[(int)1e5+3];
bool used[(int)1e5+3] = {};

void saiki(int now, vector<int>& ans){
  REP(j, G[now].size()){
    int next = G[now][j].to;
    int id = G[now][j].id;
    if(used[next]){
      G[now].pop_back();
      continue;
    }
    ans.push_back(next);
    used[next] = true;
    G[now].pop_back();
    saiki(next, ans);
    return;
  }
  return;
}

int main(void){
  fast_io
  cout<<fixed<<setprecision(15);

  ll n,m;cin>>n>>m;
  rep(i,m){
    ll a,b;cin>>a>>b;a--;b--;
    G[a].push_back({b,i});
    G[b].push_back({a,i});
  }
  vector<int> ans;
  ans.push_back(0);
  used[0] = true;
  saiki(0, ans);
  reverse(all(ans));
  saiki(0, ans);
  cout<<ans.size()<<endl;
  rep(i,ans.size()){
    cout<<ans[i]+1<<" ";
  }
  cout<<endl;

  return 0;
}

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

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

    int ans = 0;

    if (n >= 1) {
        ans += min(n, 9) - 0;
    }
    if (n >= 100) {
        ans += min(n, 999) - 99;
    }
    if (n >= 10000) {
        ans += min(n, 99999) - 9999;
    }

    cout << ans;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<set>
#include <bitset>
#include<queue>
#include<vector>
#include<map>
#include<stack>
#include <cstdio>
#include<algorithm>
#include <sstream>
#include<string>
#include<string.h>
#include <cmath>
#include <iomanip>
#include <string>
#include<list>
#include <limits>
#include <numeric>
#include <type_traits>
#define int long long
#define ll long long
#define mod  1000000007
#define MOD  1000000007
#define inf 1e17
#define rep(i,j,n) for(int i=j;i<n;i++)
#define P pair<int,int>
#define ps push_back
#define all(x) x.begin(),x.end()
double pi = 3.141592653589793;
using namespace std;
//ここから始めよう
signed main(){
    string s;cin>>s;
    if(s=="keyence"){
        cout<<"YES"<<endl;
                return 0;
    }
    int n=s.size();
    rep(i,0,n){
        rep(j,i,n){
            string c={};
            rep(k,0,n){
                if(i<=k&&k<=j)continue;
                else c+=s[k];
            }
            if(c=="keyence"){
                cout<<"YES"<<endl;
                return 0;
            }
        }
    }
    cout<<"NO"<<endl;return 0;
}

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

using namespace std;

#define LL long long
#define DD double
#define Pb push_back
#define Bp pop_back
#define Pf push_front
#define Fp pop_front
#define Ub upper_bound
#define Lb lower_bound
#define In insert
#define All(x) x.begin(), x.end()
#define mem(a, b) memset(a, b, sizeof(a))
#define fast ios_base::sync_with_stdio(0);cin.tie(0)
#define X first
#define Y second
#define mx1 10
#define mx2 110
#define mx3 1010
#define mx4 10010
#define mx5 100010
#define mx6 1000010

typedef vector<LL> Vl;
typedef vector<DD> Vd;
typedef vector<bool> Vb;
typedef vector<Vl> VVl;
typedef pair<LL, LL> Pll;
typedef pair<DD, DD> Pdd;
typedef vector<Pll> Vpl;
typedef vector<Pdd> Vpd;
typedef queue<LL> Ql;
typedef stack<LL> Sl;
typedef deque<LL> Dl;

LL _set(LL N, LL pos) {return N = N | (1 << pos);}
LL _reset(LL N, LL pos) {return N = N & ~(1 << pos);}
bool _check(LL N, LL pos) {return (bool)(N & (1 << pos));}
bool _upper(char a) {return a >= 'A' && a <= 'Z';}
bool _lower(char a) {return a >= 'a' && a <= 'z';}
bool _digit(char a) {return a >= '0' && a <= '9';}

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

///**************************DONE****************************///

int a[mx5], c[mx5];

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

    int ans = 0;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
        c[i - 1] = abs(a[i] - a[i - 1]);
        ans += c[i - 1];
    }

    c[n] = abs(a[n] - 0);
    ans += c[n];

    for(int i = 1; i <= n; i++){
        if(i == n)
            cout << ans - (c[i - 1] + c[i]) + abs(a[i - 1] - 0) << '\n';
        else
            cout << ans - (c[i - 1] + c[i]) + abs(a[i - 1] - a[i + 1]) << '\n';
    }
    return 0;
}


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

#define MIN_INT -2147483648
#define MAX_INT 2147483647
#define MIN_LONG -9223372036854775808L
#define MAX_LONG 9223372036854775807L

#define long long long int

using namespace std;

// @author: pashka

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

    long s;
    cin >> s;
    long l = 0;
    long r = 1e9;
    while (r > l + 1) {
        long m = (l + r) / 2;
        if (m * m >= s) {
            r = m;
        } else {
            l = m;
        }
    }
    if (r * r == s) {
        cout << 0 << " " << r << " " << r << " " << 0;
    } else {
        long d = r * r - s;
        cout << 1 << " " << r << " " << r << " " << d;
    }
    cout << " 0 0\n";

    return 0;
}

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

char c[209][209]; long long H, W, mod = 1000000007;
bool usedx[209], usedy[209];

bool isdifferent(string V) {
	for (int i = 0; i < V.size(); i++) {
		for (int j = i + 1; j < V.size(); j++) { if (V[i] == V[j]) return false; }
	}
	return true;
}

int main() {
	cin >> H >> W;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) cin >> c[i][j];
	}
	if (H == 1) {
		string s1 = ""; for (int i = 0; i < W; i++) s1 += c[0][i];
		string s2 = ""; for (int i = W - 1; i >= 0; i--) s2 += c[0][i];
		if (s1 == s2) cout << "1" << endl;
		else cout << "2" << endl;
		return 0;
	}
	else if (W == 1) {
		string s1 = ""; for (int i = 0; i < H; i++) s1 += c[i][0];
		string s2 = ""; for (int i = H - 1; i >= 0; i--) s2 += c[i][0];
		if (s1 == s2) cout << "1" << endl;
		else cout << "2" << endl;
		return 0;
	}

	string b1 = ""; if (H % 2 == 1) { for (int i = 0; i < W; i++) b1 += c[H / 2][i]; }
	string b2 = ""; if (W % 2 == 1) { for (int i = 0; i < H; i++) b2 += c[i][W / 2]; }

	long long sum = 1;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if (!(i <= (H - 1 - i) && j <= (W - 1 - j))) continue;

			vector<tuple<int, int, int>>vec;
			vec.push_back(make_tuple(1, i, j));
			if (j != (W - 1 - j)) vec.push_back(make_tuple(2, i, W - 1 - j));
			if (i != (H - 1 - i)) vec.push_back(make_tuple(3, H - 1 - i, W - 1 - j));
			if (i != (H - 1 - i) && j != (W - 1 - j)) vec.push_back(make_tuple(4, H - 1 - i, j));
			sort(vec.begin(), vec.end());

			vector<string>ans, ans2; bool flag = false;
			do {
				vector<int>E; for (int k = 0; k < vec.size(); k++) E.push_back(get<0>(vec[k]));

				int ret = 0;
				for (int k = 0; k < E.size(); k++) { for (int l = k + 1; l < E.size(); l++) { if (E[k] > E[l]) ret++; } }
				if (ret % 2 == 0) {
					string rem = "";
					for (int k = 0; k < E.size(); k++) rem += c[get<1>(vec[k])][get<2>(vec[k])];
					ans.push_back(rem);

					if (rem.size() == 4 && isdifferent(rem) == true) flag = true;
				}
			} while (next_permutation(vec.begin(), vec.end()));

			sort(ans.begin(), ans.end()); ans.erase(unique(ans.begin(), ans.end()), ans.end());
			sum *= (long long)(ans.size()); sum %= mod;

			if (flag == true) {
				usedx[i] = true;
				usedy[j] = true;
			}
		}
	}
	bool flag = false;
	for (int i = 0; i < H / 2; i++) { if (usedx[i] == true) { sum *= 2; sum %= mod; flag = true; } }
	for (int i = 0; i < W / 2; i++) { if (usedy[i] == true) { sum *= 2; sum %= mod; flag = true; } }
	if (flag == true) {
		if (sum % 2 == 1)sum += mod;
		sum /= 2;
	}
	string c1 = b1; reverse(c1.begin(), c1.end()); if (b1 != c1) { sum *= 2; sum %= mod; }
	string c2 = b2; reverse(c2.begin(), c2.end()); if (b2 != c2) { sum *= 2; sum %= mod; }
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 256
S = int(input())

tmp = [0]*2010
mod = 10**9+7

for i in range(3,2001):
    count = 0
    for j in range(3,2001):
        if i - j < 0:
            break
        count += tmp[i-j]
    tmp[i] = (count+1)%mod

print(tmp[S])

Measured memory_bytes: 64752
#include<stdio.h>
int main(void)
{
  int a,b,sum;
  
  scanf("%d",&a);
  scanf("%d",&b);
  
  if(a == b) sum = a+b;
  if(a > b) sum = a + (a-1);
  if(a < b) sum = b + (b-1);
  
  printf("%d",sum);
  return 0;
}

Measured memory_bytes: 128
//package com.company;

import java.io.*;
import java.util.*;

public class Main {
    static long TIME_START, TIME_END;
    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
//        Scanner sc = new Scanner(new FileInputStream("Test.in"));
        PrintWriter pw = new PrintWriter(System.out);
//        PrintWriter pw = new PrintWriter(new FileOutputStream("Test.out"));
//        PrintWriter pw = new PrintWriter(new FileOutputStream("Test.in"));

        Runtime runtime = Runtime.getRuntime();
        long usedMemoryBefore = runtime.totalMemory() - runtime.freeMemory();
        TIME_START = System.currentTimeMillis();
        Task t = new Task();
        t.solve(sc, pw);
        TIME_END = System.currentTimeMillis();
        long usedMemoryAfter = runtime.totalMemory() - runtime.freeMemory();
        pw.close();
//        System.out.println("Memory increased:" + (usedMemoryAfter-usedMemoryBefore) / 1000000 );
//        System.out.println("Time used: " + (TIME_END - TIME_START) + ".");

    }


    public static class Task {


        public void solve(Scanner sc, PrintWriter pw) throws IOException {
            int A = sc.nextInt();
            int B = sc.nextInt();
            A--;//white
            B--;//black
            int[][] grid = new int[100][100];
            for (int i = 50; i < 100; i++) {
                Arrays.fill(grid[i], 1);
            }
            for (int i = 0; i < 50; i+=2) {
                for (int j = (i & 1); j < 100; j+= 2) {
                    if (A > 0) {
                        grid[i][j] = 1;
                        A--;
                    }
                }
            }

            for (int i = 99; i >= 0; i-=2) {
                for (int j = (i & 1); j < 100; j += 2) {
                    if (B > 0) {
                        grid[i][j] = 0;
                        B--;
                    }
                }
            }
            pw.println("100 100");
            for (int i = 0; i < 100; i++) {
                for (int j = 0; j < 100; j++) {
                    pw.print(grid[i][j] == 1 ? '.': '#');
                }
                pw.println();
            }

        }




    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(InputStream s){  br = new BufferedReader(new InputStreamReader(s));}

        public Scanner(FileReader s) throws FileNotFoundException {br = new BufferedReader(s);}

        public String next() throws IOException
        {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

        public int nextInt() throws IOException {return Integer.parseInt(next());}

        public long nextLong() throws IOException {return Long.parseLong(next());}

        public String nextLine() throws IOException {return br.readLine();}

        public double nextDouble() throws IOException { return Double.parseDouble(next()); }

        public boolean ready() throws IOException {return br.ready();}
    }
}


Measured memory_bytes: 23252
import sys

a, b, c, x, y = map(int, sys.stdin.readline().split())

if x < y:
    x, y = y, x
    a, b = b, a

def main():

    if a + b <= c * 2:
        cost = a * x + b * y
    else:
        cost = c * 2 * y
        if a <= c * 2:
            cost += a * (x - y)
        else:
            cost += c * 2 * (x - y)
    return cost

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

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

typedef long long LL;

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(x) (x).begin(),(x).end()
const int IINF = 1e9;
const LL LINF = 1e18;
const LL MOD = 1e9+7;

LL sqrt(LL x) {
    LL l = 0;
    LL r = 1e9 + 1;
    for(;1 < r - l;) {
        LL mid = (l + r)/2;
        if(mid*mid < x) {
            l = mid;
        }else{
            r = mid;
        }
    }
    return l;
}

void solve(LL A, LL B) {
    LL c = sqrt(A*B);
    if(abs(A - B) < 2) {
        cout << 2*(A - 1) << endl;
        return;
    }
    if(A*B <= c*(c + 1)) {
        cout << 2*(c - 1) << endl;
        return;
    }
    cout << 2*c - 1 << endl;
    return;
}

int main() {
    int Q;
    cin >> Q;
    REP(i, Q) {
        LL A, B;
        cin >> A >> B;
        solve(min(A, B), max(A, B));
    }
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define N 36

typedef struct{
  char chara;
  int num;
  int no;
} trump;

int main(){

  int i,j,n,flag=1,minj;
  trump T1[N],T2[N],tmp;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    while(1){
      scanf("%c",&T1[i].chara);
      if(T1[i].chara != 'S' && T1[i].chara != 'H' && T1[i].chara != 'C' && T1[i].c\
hara != 'D') continue;
      scanf("%d",&T1[i].num);
      break;
    }
    T1[i].no=i+1;
    T2[i]=T1[i];
  }
  
    for(i=0;i<n;i++){
    for(j=n-1;j>i;j--){
      if(T1[j].num<T1[j-1].num){
        tmp = T1[j];
        T1[j] = T1[j-1];
        T1[j-1] = tmp;
      }
    }
  }

  for(i=0;i<n;i++){
    if(i != n-1)printf("%c%d ",T1[i].chara,T1[i].num);
    else printf("%c%d\nStable\n",T1[i].chara,T1[i].num);
  }
  
   for(i=0;i<n-1;i++){
    minj = i;
    for(j=i;j<n;j++){
      if(T2[j].num<T2[minj].num){
        minj = j;
      }
    }
    tmp = T2[i];
    T2[i] = T2[minj];
    T2[minj] = tmp;
  }

  for(i=0;i<n;i++){
    if(i != n-1 ) printf("%c%d ",T2[i].chara,T2[i].num);
    else printf("%c%d\n",T2[i].chara,T2[i].num);
  }

  for(i=1;i<n;i++){
    if(T2[i].num == T2[i-1].num && T2[i].no - T2[i-1].no < 0){
      flag = 0;
    }
  }
   if(flag == 1)printf("Stable\n");
  else printf("Not stable\n");

  return 0;
}

  


Measured memory_bytes: 2112
b=input()
if b=="A":
    print("T")
elif b=="T":
    print("A")
elif b=="C":
    print("G")
else:
    print("C")
    
    
    
    
        

        
   
    
    
    
        
        
    
    
    
    
        

      
    
    
        
        
    
    
    
    
        


Measured memory_bytes: 8788
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int mxn= 1e6+5;
// check for forloop
// intialize variable
// overflow
// go for easy solution
#define mod 1000000007
ll INF = 1000000000000000005LL;
#define endl '\n'
void rishabh(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}
int main(){
    rishabh();
    string s;
    cin>>s;
    int n=s.size();
    for(int i=n-2;i>=1;i--){
        if((i)%2==1){
            bool f=true;
            for(int j=0;j<(i)/2;j++){
                if(s[j]!=s[i/2+j+1]){
                    f=false;
                    break;
                }
            }
            if(f){
                cout<<i+1;
                return 0;
                for(int j=0;j<=i;j++){
                    cout<<s[j];
                }
            }
        }
    }
}

Measured memory_bytes: 3580
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		HashSet<Integer> set = new HashSet<>();
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < n; i++) {
		    int type = sc.nextInt();
		    int x = sc.nextInt();
		    if (type == 0) {
		        set.add(x);
		        sb.append(set.size()).append("\n");
		    } else {
		        if (set.contains(x)) {
		            sb.append(1);
		        } else {
		            sb.append(0);
		        }
		        sb.append("\n");
		    }
		}
		System.out.print(sb);
	}
}



Measured memory_bytes: 147552
def slove():
    import sys
    import collections
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    a = list(map(int, input().rstrip('\n').split()))
    b = []
    for i in range(len(a)):
        b.append(a[i])
        b.append(a[i]+1)
        b.append(a[i]-1)
    b = collections.Counter(b).most_common()
    print(b[0][1])


if __name__ == '__main__':
    slove()


Measured memory_bytes: 72388
// J'aime
// Chemise Blanche

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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr << __LINE__ << " > " << #x << " = " << (x) << endl

void MAIN() {
  string s;
  cin >> s;
  cout << s.substr(0, 4) << ' ' << s.substr(4, s.size() - 4) << '\n';
}

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) MAIN();
}


Measured memory_bytes: 3624
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    s=input()
    a=s.find('C')
    b=s.rfind('F')
    if a==-1 or b==-1:
        print('No')
    else:
        if a<b:
            print('Yes')
        else:
            print('No')
resolve()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int A, B, K, tmp;
	cin >> A >> B >> K;
	tmp = min(2*K, B-A+1);
	vector <int> a(tmp);
	if (2*K < B-A+1){
		for (int i=0; i<K; i++){
			a.at(i) = A+i;
			a.at(tmp-1-i) = B-i;
			}
		}
	if (2*K >= B-A+1){
		for (int i=0; i<tmp; i++){
			a.at(i) = A+i;
		}
	}
	for (int i=0; i<tmp; i++){
		cout << a.at(i) << endl;
	}
    
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main()
{
    int a,b;
    scanf("%d %d",&a,&b);

    b = b+b;
    int result = 0;
    if(a>=b)
        result = a-b;
    else
        result = 0;
    
    printf("%d\n",result);

    return 0;
}


Measured memory_bytes: 1732
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int i,j,k,n,m,l;
void ABC130(void);
void ABC131(void);
void ABC132(void);
void ABC133(void);
void ABC134(void);
void ABC135(void);
void ABC136(void);
void ABC137(void);
void ABC138(void);
void ABC139(void);

int main(void){
    ABC131();
}

void ABC131(){
    int sum=0,min,index;
    cin>>n>>l;
    vector<int> vec(n);
    for(i=0;i<n;i++){
        vec[i]=l+i;
        sum+=vec[i];
    }
    min=abs(vec[0]);
    index=0;
    for(i=1;i<n;i++){
        if(abs(vec[i])<min){
            min=abs(vec[i]);
            index=i;
        }
    }
    cout<<sum-vec[index]<<endl;
}

Measured memory_bytes: 256
N,M=map(int,input().split())
SC=[list(map(int,input().split())) for i in range(M)]
kouho=[]
count = 0
for i in range(10**N):
    count=0
    if len(str(i))==N:
        for j in range(M):
            if str(i)[SC[j][0]-1]==str(SC[j][1]):
                count+=1
        if count==M:
            print(i)
            exit()
else:
    print("-1")

Measured memory_bytes: 3064
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main(){

    input!{
        w: usize,
        h: usize,
        x: usize,
        y: usize,
    }

    print!("{} ", w as f64 * h as f64 / 2.0);
    let mut ok = 0;
    if 2*x==w && 2*y==h {
        ok = 1;
    }
    println!("{}", ok);
} 

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

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

  //akasaka
  int n = s.size();
  string a, b;
  for (int i = 0; i < (n - 1) / 2; i++) a += s[i];
  b = a;
  reverse(a.begin(), a.end());
  if (a == b) {
    for (int i = (n + 3) / 2; i < n; i++) a += s[i];
    b = a;
    reverse(a.begin(), a.end());
    if (a == b) { 
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  } else {
    cout << "No" << endl;
  }

  return 0;
}


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

int bubbleSort(int A[], int N) {
    int sw = 0;
    bool flag = 1;
    for (int i = 0; flag; i++) {
        flag = 0;
        for (int j = N - 1; j >= i + 1; j--) {
            if (A[j] < A[j - 1]) {
                swap(A[j], A[j - 1]);
                flag = 1;
                sw++;
            }
        }
    }
    return sw;
}

int main() {
    int A[100], N, sw;
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    
    sw = bubbleSort(A, N);
    
    for (int i = 0; i < N; i++) {
        if (i) {
            cout << " ";
        }
        cout << A[i];
    }
    cout << endl;
    cout << sw << endl;
    
    return 0;
}


Measured memory_bytes: 3108
#include <bits/stdc++.h>
using namespace std;
int main(){
	cin.tie(0); cout.tie(0);
	ios::sync_with_stdio(0);

	int n; cin >> n; 
	vector<vector<pair<int,int>>> g(n);
	for(int i=0; i<n-1; ++i){
		int u, v, w;
		cin >> u >> v >> w;
		--u; --v;
		w %= 2;
		g[u].push_back(make_pair(v,w));
		g[v].push_back(make_pair(u,w));
	}

	vector<int> color(n,0), dst(n,0);
	vector<bool> visit(n,0);
	stack<int> st;
	color[0]=1;
	visit[0]=1;
	st.push(0);
	while(!st.empty()){
		int z=st.top();
		st.pop();
		if(dst[z]%2==0) color[z]=1;

		for(auto i : g[z]){
			if(!visit[i.first]){
				visit[i.first]=1;
				dst[i.first]=i.second+dst[z];
				st.push(i.first);
			}
		}
	}

	for(int i : color) cout << i << endl;
}

Measured memory_bytes: 7296
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <utility>
#include <typeinfo>
#include <string>
#include <sstream>

using namespace std;

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;

typedef unsigned long long ull;

ull func(ull A, ull B) {
    ull ans = 0;
    if (A % 2 == 0) {
        ull sa = B - A;
        if (sa % 2 == 0) {
            if (sa % 4 == 0) {
                ans = B;
            } else {
                ans = A + (4 * (sa / 4)) + 3;
            }
        } else {
            ull tmp_sa = (sa + 1) / 2;
            if (tmp_sa % 2 == 1) {
                ans = 1;
            }
        }
    } else {
        ull i = A;
        ull sa = B - A;
        ull mod = sa % 4;
        ans = A;
        for (ull i = B - mod + 1; i <= B; ++i) {
            ans = ans ^ i;
        }
    }
    return ans;
}

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

    ull A, B;
    cin >> A >> B;
    cout << func(A, B) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"

struct mint {
    const int mod = 1e9 + 7;
    long long x;
    
    mint (long long x = 0) : x((x % mod + mod) % mod) {
        
    }
    
    mint& operator=(const long long a) {
        x = a % mod;
        return *this;
    }
    
    mint& operator=(const mint a) {
        x = a.x % mod;
        return *this;
    }
    
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    
    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }
    
    mint& operator-=(const mint a) {
        if ((x += (mod - a.x)) >= mod) x -= mod;
        return *this;
    }
    
    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }
    
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    
    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }
    
    mint pow(long long t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }
    
    mint inv() const {
        return pow(mod - 2);
    }
    
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    
    mint operator/(const mint a) const {
        mint res(*this);
        return res /= a;
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll n, m;
    cin >> n >> m;
    set<ll> a;
    rep(i, m) {
        ll tmp;
        cin >> tmp;
        a.insert(tmp);
    }
    vector<mint> dp(n + 1, 0);
    dp[0] = 1;
    ll idx = 0;
    rep(i, n) {
        if (a.count(i + 1) > 0) continue;
        dp[i + 1] += dp[i];
        if (i > 0) dp[i + 1] += dp[i - 1];
    }
    cout << dp[n].x << endl;
    return 0;
}


Measured memory_bytes: 6528
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<cassert>
#include<cmath>
#include<cstdint>


     
#define INF 1e9
#define LINF 1e19
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()
#define chmin(a, b) a = min(a, b)
#define chmax(a, b) a = max(a, b)
     
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<ll, ll>;
     
const ll MOD = 1e9 + 7;
const ll ZER = 0;



int main(){
    int n, d;
    cin >> n >> d;
    cout << (n + 2 * d) / (2 * d + 1) << endl;
}





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

int main() {
  string S; cin >> S;
  sort(S.begin(), S.end());
  if(S[0] == S[1] && S[1] != S[2] && S[2] == S[3]) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    public static void main(String[]arg){
        Scanner sc = new Scanner(System.in);
        int i=0;
        while(true){
            i++;
            int x = sc.nextInt();
            if(x==0) break;
            else System.out.println("Case "+i+": "+x);
        }
    }
}


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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(), (v).end()
#define pb push_back
#define fi first
#define se second

typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> PP;

int n,k,x,y;
int sum;

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

	cin>>n>>k>>x>>y;
	int i=0;
	while (i<min(n,k)) {
		sum+=x;
		i++;
	}
	while (i<n) {
		sum+=y;
		i++;
	}
	cout<<sum<<endl;

	return 0;
}


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

///////////////////////////
// Range Sum Query (BIT) //
///////////////////////////

class RSumQBIT {
private:
	std::vector<int64_t> container_;

	int64_t getHelper(const int index) const
	{
		if (index < 0) return 0;
		if ((int)(container_.size()) <= index) return container_.back();
		int64_t sum{};
		for (int add_place{index}; add_place > 0; add_place -= add_place & -add_place)
			sum += container_[add_place];
		return sum;
	}

public:
	RSumQBIT(const int array_size)
		: container_(array_size + 1) {}
	// indexは0-indexed
	void update(const int index, const int64_t added)
	{
		for (int update_place{index + 1}; update_place < (int)(container_.size()); update_place += update_place & -update_place)
			container_[update_place] += added;
	}
	// left,rightは0-indexed、[left, right)の半開区間
	int64_t get(const int left, const int right) const
	{
		return -getHelper(left) + getHelper(right);
	}
};

int main()
{
	int N;
	scanf("%d", &N);
	std::vector<std::pair<int, int>> a(N);
	for (int i{}; i < N; i++)
	{
		scanf("%d", &a[i].first);
		a[i].second = i + 1;
	}
	std::sort(a.begin(), a.end());
	RSumQBIT rsq(N + 1);
	int64_t count{};
	for (auto& e: a)
	{
		int64_t here{rsq.get(0, e.second + 1)};
		int rng{e.second}, rok{N + 1};
		while (rok - rng > 1)
		{
			int mid{(rok + rng) >> 1};
			if (rsq.get(0, mid + 1) > here) rok = mid;
			else rng = mid;
		}
		int lng{-1}, lok{e.second};
		while (lok - lng > 1)
		{
			int mid{(lng + lok) >> 1};
			if (rsq.get(0, mid + 1) == here) lok = mid;
			else lng = mid;
		}
		count += (int64_t)(e.second - lok) * (rok - e.second) * e.first;
		rsq.update(e.second, 1);
	}
	printf("%lld\n", count);

	return 0;
}

Measured memory_bytes: 3328
#include<stdio.h>
int main(void){
    int ans;
    int i,j,k,l,m,n;
    while(1){
        int d,w;
        ans=0;
        scanf("%d%d",&d,&w);
        if(d==0 && w==0) break;
        int e[d][w];
        for(i=0; i<d; i++){
            for(j=0; j<w; j++){
                scanf("%d",&e[i][j]);
            }
        }
        for(i=0; i<d-2; i++){
            for(j=i+2; j<d; j++){
                for(k=0; k<w-2; k++){
                    for(l=k+2; l<w; l++){
                        int min=10;
                        int in=0;
                        int x=0;
                        for(m=i; m<=j; m++){
                            for(n=k; n<=l; n++){
                                if(m==i || m==j ||n==k ||n==l){
                                    if(e[m][n]<min) min=e[m][n];
                                }
                            }
                        }
                        int max=0;
                        for(m=i+1; m<j; m++){
                            for(n=k+1; n<l; n++){
                                if(e[m][n]>max) max=e[m][n];
                                in+=e[m][n];
                                x++;
                            }
                        }
                        int tmp;
                        if(min>max && (tmp=(min*x-in)) > ans){
                            ans=tmp;
                        }
                    }
                }
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}


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

int main(){
    int n, m, i, j;
    while (cin >> n >> m && (n != 0 || m != 0)){
        for (i = 0; i < n; i++){
            for (j = 0; j < m; j++){
                cout << "#";
            }
            cout << endl;
        }
        cout << endl;
    }
}

Measured memory_bytes: 3072
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B,L,R;
string S, T;
const ll MOD = 998244353;
const ll INF = 1LL << 60;
typedef pair<ll,ll> P;

int main() {
    ll Ma, Mb;
    cin>>N>>Ma>>Mb;
    vec a(N), b(N), c(N);
    rep(i,N) cin>>a[i]>>b[i]>>c[i];
    vector<mat> dp(N+1, mat(401, vec(401, INF)));
    dp[0][0][0] = 0;
    rep(i,N){
        rep(j,401) rep(k,401) dp[i + 1][j][k] = dp[i][j][k];
        reps(j, a[i], 401){
            reps(k, b[i], 401){
                dp[i + 1][j][k] = min(dp[i + 1][j][k], dp[i][j - a[i]][k - b[i]] + c[i]);
            }
        }
    }
    ll ans = INF;
    for(ll i = 1; (i*Ma < 401) && (i * Mb < 401); ++i){
        ans = min(ans, dp[N][i*Ma][i*Mb]);
    }
    cout<<(ans == INF ? -1 : ans)<<endl;
}

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

using ll = long long;

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

    ll h,w;
    cin>>h>>w;

    ll ans=w*(h/2);
    if(h%2==1)ans+=(w+1)/2;

    if(h==1||w==1) cout<<"1\n";
    else cout<<ans<<"\n";

    return 0;
}


Measured memory_bytes: 3624
import sys

f_i = sys.stdin

V, E = map(int, f_i.readline().split())

# adjacency matrix
no_edge = float("inf")

adj = [[no_edge] * V for i in range(V)]

for i in range(V):
    adj[i][i] = 0

odd_b = 0 # bit DP to record odd vertex

ans = 0

# acceptance of input
for l_i in f_i:
    s, t, d = map(int, l_i.split())
    t_d = min(d, adj[s][t])
    adj[s][t] = t_d
    adj[t][s] = t_d
    odd_b ^= 1 << s
    odd_b ^= 1 << t
    ans += d

if odd_b:
    # Warshall???Floyd Algorithm
    for k in range(V):
        for i in range(V):
            for j in range(V):
                adj[i][j] = min(adj[i][j], adj[i][k] + adj[k][j])
                
    # Minimum weighted matching
    mw = [no_edge] * (odd_b + 1)
    mw[0] = 0
    digits = len(bin(odd_b)) - 2

    for b in range(odd_b):
        for i in range(0, digits):
            if not (b & (1 << i)) and odd_b & (1 << i):
                for j in range(i + 1, digits):
                    if not (b & (1 << j)) and odd_b & (1 << j):
                        t_b = b + (1 << i) + (1 << j)
                        if t_b == t_b & odd_b:
                            t_w = mw[t_b]
                            mw[t_b] = min(t_w, mw[b] + adj[i][j])

    # Output
    ans += mw[odd_b]
    print(ans)
else:
    print(ans)

Measured memory_bytes: 7872
/***************************************************

@author: vichitr
Compiled On: 19th Mar 2020

*****************************************************/
#include<bits/stdc++.h>
#define MAX 9223372036854775807
#define endl "\n"
#define ll long long
#define int long long
#define double long double
#define pb push_back
#define pf pop_front
#define mp make_pair
#define ip pair<int, int>
#define F first
#define S second

#define loop(i,n) for(int i=0;i<n;i++)
#define loops(i,s,n) for(int i=s;i<=n;i++)
#define fast ios::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL)
using namespace std;

const ll MOD = 1e9+7;
const ll SZ = 107;
const ll N = 2e5+7;
// const ll M = 2e5+7;

ll pwr(ll x, ll y)
{
    ll r = 1LL;
    while(y)
    {
        if(y&1)
            r = (r * x) % MOD;
        y >>= 1;
        x = (x * x) % MOD;
    }
    return r;
}

int inv(int x)
{
    return pwr(x, MOD-2ll);
}

// int fact[N];

// int nCr(int x, int y){
//     int ans= fact[x];
//     ans *= inv(fact[y]);
//     ans %= MOD;
//     ans *= inv(fact[x-y]);
//     ans %= MOD;
//     return ans;
// }

// bool prim(int n){
//     for(int i=2;i*i<=n;i++){
//         if(n%i==0)
//             return 0;
//     }
//     return 1;
// }


void solve()
{ 
    int n, m; 
    cin>>n>>m;
    // n = rand()%100000+1;
    int ans = n*(n-1)/2;
    ans += m*(m-1)/2;
    cout<<ans;
}

signed main()
{
    fast;
// #ifndef ONLINE_JUDGE
//     freopen("in.txt", "r", stdin);
//     freopen("out.txt", "w", stdout);
// #endif
    int t=1;
    // cin >>t;

    // fact[0] =1;
    // for(int i=1;i<N;i++){
    //     fact[i] = fact[i-1]*i;
    //     fact[i] %= MOD;
    // }
    // int i  =1;
    while(t--){
        // int n = i++;
        solve();
        
    }
    return 0;
}

/*****************************

1
10 3
1 5 1
3 6 1
6 9 1


**************************/

Measured memory_bytes: 256