akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
const int maxn=305;
char s[maxn][maxn];
int a[maxn][maxn];
int main()
{
	int h,w;scanf("%d%d",&h,&w);int k;scanf("%d",&k);
	for(int i=1;i<=h;i++) scanf("%s",s[i]+1);
	int now=0;memset(a,-1,sizeof a);
	for(int i=1;i<=h;i++)
	{
		int vis=0;
		for(int j=1;j<=w;j++)
		{
			if(s[i][j]=='#') a[i][j]=++now,vis=1;
			else if(vis&&a[i][j]==-1)
			{
				a[i][j]=now;
			}
		}
	}
	for(int i=1;i<=h;i++)
	{
		int vis=0;int now=0;
		for(int j=w;j>=1;j--)
		{
			if(a[i][j]!=-1) now=a[i][j],vis=1;
			else if(vis&&a[i][j]==-1)
			{
				a[i][j]=now;
			}
		}
	}
	for(int i=1;i<=h;i++)
	{
		if(a[i][1]==-1)
		{
			if(i==1)
			{
				int x=i+1;
				while(a[x][1]==-1) x++;
				for(int j=1;j<=w;j++)
				a[i][j]=a[x][j];
			}
			else
			{
				int x=i-1;
				while(a[x][1]==-1) x--;
				for(int j=1;j<=w;j++)
				a[i][j]=a[x][j];
			}
		}
	}
	for(int i=1;i<=h;i++)
	{
		for(int j=1;j<=w;j++)
		{
			cout<<a[i][j]<<" ";
		}
		cout<<endl;
	 } 
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using lint = long long int;
using ulint = unsigned long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T, class U> void assign(V<T>& v, int n, const U& a) { v.assign(n, a); }
template<class T, class... Args> void assign(V<T>& v, int n, const Args&... args) { v.resize(n); for (auto&& e : v) assign(e, args...); }


int main() {
  cin.tie(nullptr); ios_base::sync_with_stdio(false);
  while (true) {
    int n, a, b, c, x; cin >> n >> a >> b >> c >> x;
    if (n == 0) break;
    V<> y(n); for (int i = 0; i < n; ++i) cin >> y[i];
    int res = 0;
    for (int i = 0; i < n; ++i) {
      if (i > 0) {
        x = (a * x + b) % c;
        ++res;
      }
      while (x != y[i]) {
        x = (a * x + b) % c;
        ++res;
        if (res > 10000) {
          res = -1;
          break;
        }
      }
      if (res == -1) break;
    }
    cout << res << '\n';
  }
}


Measured memory_bytes: 3140
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define scanVec(vec , n) for(int i = 0; i < n ; i++){ cin>>vec[i];}
#define printVec(vec , n) for(int i = 0; i < n ; i++){ cout<<vec[i]<<" ";}
#define S second
#define F first
const int  MOD = 1e9 + 7;
const int  N = 1e9 + 7;
ll A[20][20] , dp[(1<<16)+1] , cost[(1<<16)+1];

//  a d f j k  l  ;
int main(){
    ios::sync_with_stdio(0);  cin.tie(0);
    ll n; cin>>n;
	for(int i = 0 ; i < n ; i++){
        for(int j = 0 ; j < n ; j++){
            cin>>A[i][j];
        }
    }
    ll lim = ((1<<n)-1);
    for(ll i = 0 ; i <= lim ; i++){
        for(ll j = 0 ; j < n ; j++){
            for(ll k = j+1 ; k < n ; k++){
                if( ( ( i>> j ) &1 ) && ( ( i>>k ) & 1 ) ){
					cost[i] += A[j][k];
				}
            }
        }
    }
    for(ll i = 0 ; i <= lim ; i++){
        for(long long j = i; j > 0; j = i & (j-1)){
            // cout<<i<<" "<<j<<endl;
			long long com = ( j ^ i);
			dp[i] = max (dp[i],(cost[j] + dp[com]));
            // if(j == 0) break;
        }
    }
    cout<<dp[lim]<<endl;


    return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using Int = long long;  // clang-format off
#define REP_(i, a_, b_, a, b, ...) for (Int i = (a), lim##i = (b); i < lim##i; i++)
#define REP(i, ...) REP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define ALL(v) std::begin(v), std::end(v)
struct SetupIO { SetupIO() { std::cin.tie(nullptr), std::ios::sync_with_stdio(false), std::cout << std::fixed << std::setprecision(13); } } setup_io;
#ifndef dump
#define dump(...)
#endif  // clang-format on

/**
 *    author:  knshnb
 *    created: Sat Aug 29 21:14:40 JST 2020
 **/

signed main() {
    Int d, t, s;
    std::cin >> d >> t >> s;
    std::cout << (d <= t * s ? "Yes" : "No") << std::endl;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int x,y,a,b,i;
	scanf("%d %d",&a,&b);
	x=1;
	y=3;
	i=2;
	while(x<a&&y<b)
	{
		i++;
		x=y;
		y=x+i;
	}
	//printf("%d %d\n",x,y);
	while(x-a!=y-b)
	{
		i++;
		x=y;
		y=x+i;
	}
	printf("%d",x-a);
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#include<cmath>


#define REP(i,n) for (int i = 0; (i) < (n); ++ (i))
#define FOR(i,n) for (int i = 1; (i) <= (n); ++ (i))
#define dump(x)  cout << #x << " = " << (x) << endl;
#define lint long long

const int INF = 1e9;
const int MOD = 1e9+7;
const lint LINF = 1e18;



using namespace std;
int w,a,b;

int main(){
  cin >> w >> a >> b;
  if(min(a+w,b+w)-max(a,b)>0) cout << 0 << endl;
  else cout << max(b-a-w,a-b-w) << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

// https://atcoder.jp/contests/abc168/tasks/abc168_b
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);
		int k = sc.nextInt();
		String s = sc.next();
		sc.close();

		if(k>=s.length()) {
			System.out.println(s);
		}else {
			System.out.println(s.substring(0, k)+"...");
		}


	}
}


Measured memory_bytes: 27084
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

cnt = sum(B)-sum(A)
ca = 0
cb = 0

for a,b in zip(A,B):
    if a > b:
        cb += a-b
    if b > a:
        if (b-a) % 2 == 0:
            ca += (b-a)//2
        else:
            ca += -(-(b-a)//2)
            cb += 1

if cnt >= max(ca,cb):
    print("Yes")
else:
    print("No")

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

int main(){
  int A1,A2,A3;
  cin >>A1>>A2>>A3;
  
 int ans=max({A1,A2,A3})-min({A1,A2,A3});
  
  cout<<ans<<endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){
	int takasa[10];
	for(int i = 0; i <10; i++){
		cin >> takasa[i];
	}
	//sort
	for(int i = 0; i < 9; i++){
		for (int j = i+1; j < 10; j++){
			if(takasa[i] < takasa[j]){
				swap(takasa[i],takasa[j]);
			}
		}
	}
	for(int i = 0; i < 3; i++){
		cout << takasa[i] << "\n";
	}
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define DEBUG if(0)
#define lli long long int
#define ldouble long double
using namespace std;

int a[3];
bool read()
{
  for (int i = 0; i < 3; i ++)
    if (scanf("%d", &a[i]) == EOF)
      return false;
  return true;
}

int main()
{
  while (read())
  {
    int s = 0;
    for (int i = 0; i < 3; i ++)
      s += a[i];
    printf("%s\n", s >= 22 ? "bust" : "win");
  }
  return 0;
}

Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll x,y,a,b,c;
    cin >> x >> y >> a >> b >> c;
    vll p(a),q(b),r(c);
    REP(i,a) cin >> p[i];
    REP(i,b) cin >> q[i];
    REP(i,c) cin >> r[i];
    sort(rALL(p));
    sort(rALL(q));
    sort(rALL(r));
    vll sp(a+1,0LL),sq(b+1,0LL),sr(c+1,0LL);
    REP(i,a){
        sp[i+1]=sp[i]+p[i];
    }
    REP(i,b){
        sq[i+1]=sq[i]+q[i];
    }
    REP(i,c){
        sr[i+1]=sr[i]+r[i];
    }
    ll ans = 0;
    for(ll i=0;i<=x;++i){
        ll clr = x-i;
        if(clr>c){
            continue;
        }
        ll tmp = 0;
        tmp += sp[i];
        ll ok = clr-1;
        ll ng = c;
        while(abs(ok-ng)>1){
            ll mid = (ok+ng)/2;
            bool f;
            if(mid+1-clr>y){
                f=false;
            }else{
                ll g = y-(mid+1-clr);
                if(g==y||(q[g]<=r[mid])){
                    f=true;
                }else{
                    f=false;
                }
            }
            if(f){
                ok = mid;
            }else{
                ng = mid;
            }
        }
        tmp+=sr[ok+1];
        tmp+=sq[y-(ok+1-clr)];
        ans = max(ans,tmp);
    }
    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 4992
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#include <stack>
using namespace std;
typedef long long LL;
const int Maxn = 1e5 + 5;
const int inf = 1 << 30;
const LL Inf = 1LL << 60;
int n,m;
int vis[1000000];

int main ()
{
	scanf("%d%d",&n,&m);
	int k;
	scanf("%d",&k);
	memset(vis,0,sizeof(vis));
	for (int i = 0; i <= n; i++)
		for (int j = 0; j <= m; j++)
		{
			vis[i*m + j*n  - 2*i*j] = 1;
			}
			if (vis[k] == 1)
				printf("Yes");
				else printf("No");
	return 0;
}

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

using namespace std;

#define allof(x) (x).begin(), (x).end()

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

const int MAXN = 55;

int N, M;
char grid[MAXN][MAXN];

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

    cin >> N >> M;
    for(int a = 1; a <= N; a++){
        cin >> (grid[a] + 1);
    }
    for(int a = 1; a <= N; a++){
        for(int b = 1; b <= M; b++){
            if(grid[a][b] == '#'){
                if(grid[a][b-1] != '#' && grid[a][b+1] != '#' && grid[a-1][b] != '#' && grid[a+1][b] != '#'){
                    cout << "No\n";
                    return 0;
                }
            }
        }
    }
    cout << "Yes\n";
}


Measured memory_bytes: 256
///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
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 x){
	if(!adj[x].size())return 0;
	ll &r = dp[x];
	if(r != -1)return r;
	r = 0;
	for(auto u : adj[x]){
		r = max(r , mem(u) + 1);
	}
	return r;
}
void solve(){
	memset(dp , -1 , sizeof dp);
	cin >> n >> m;
	for(ll i = 1 ; i <= m ; i++){
		cin >> o >> p;
		adj[o].pb(p);
	}
	o = 0;
	for(ll i = 1 ; i <= n ; i++){
		o = max(o , mem(i));
		
	}
	cout << o;
}
int main() {
    fast ;
	// cin >> q;
    q = 1;
    while(q--){
    	solve();
	}
}



Measured memory_bytes: 22524
s=input()
if s=='SSS':
  print(0)
elif s=='SSR':
  print(1)
elif s=='SRS':
  print(1)
elif s=='SRR':
  print(2)
elif s=='RSS':
  print(1)
elif s=='RSR':
  print(1)
elif s=='RRS':
  print(2)
elif s=='RRR':
  print(3)

Measured memory_bytes: 9048
// C - Product and GCD

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

vector<pair<ll, ll>> prime_factorize(ll n) {
	vector<pair<ll, ll> > result;
	for (ll p=2; p*p<=n; p++) {
		if (n % p != 0) continue;
		ll num = 0;
		while (n % p == 0) {
			num++;
			n /= p;
		}
		result.push_back(make_pair(p, num));
    }
    if (n != 1) {
    	result.push_back(make_pair(n, 1));
    }
    return result;
}

int main() {
	ll N, P;
	cin >> N >> P;

	vector<pair<ll, ll>> pf = prime_factorize(P);

	ll ans = 1;
	for (auto p : pf) {
		//cout << p.first << " " << p.second << endl;
		if (p.second >= N) {
			ans *=  pow(p.first, p.second / N);
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 4024
inp = require('fs').readFileSync('/dev/stdin', 'utf8').split('\n')
N = inp.shift() * 1
w = {}
w[inp[0]] = 1
last = inp[0][inp[0].length-1]
f = 1
for (i=1; i<N; i++) {
    word = inp[i]
    w[word] = (w[word] || 0) + 1
    if (w[word] == 2 || last != word[0]) {
        f = 0
        break;
    }
    last = word[word.length - 1]
}
console.log(f ? 'Yes' : 'No')

Measured memory_bytes: 7372
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+5;
const int inf=0x3f3f3f3f;
#define endl '\n'

int n,a[N],sq[N],cnt,start,t;
ll k;

int main(){
	ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	cin>>n>>k;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		sq[i]=-1;
	}
	cnt=-1;
	for(int i=1;;){
		cnt++;
		if(cnt==k) {
			cout<<i<<endl;
			return 0;
		}
		if(sq[i]==-1) {
			sq[i]=cnt;
			i=a[i];
		}
		else {
			t=cnt-sq[i];
			if(i==1){
				start=a[1];
				k=(k-1)%t;
			}
			else {
				start=i;
				k=(k-sq[i])%t;
			}
			break;
		}
	}
	cnt=-1;
	for(int i=start;;i=a[i]){
		cnt++;
		if(cnt==k) {
			cout<<i<<endl;
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 5152
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)

int main() {
    int k,s;
    scanf("%d %d\n",&k,&s);
    int x,y,z,count=0,tmp;
    for(x=0;x<=k;x++){
        for(y=0;y<=k;y++){
            tmp = s-x-y;
            if(0<=tmp && tmp<=k)count++;
        }
    }
    printf("%d\n",count);
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
using namespace std;
 
int main(){
    int H=0,W=0;
    int i,k;

while(1){    



    cin >> H >> W;
	if(H==0&&W==0){
		break;
	}
    
    for(k=0;k<H;k++){//???
    	for(i=0;i<W;i++){//???
    		if((i==0||i==W-1)||(k==0||k==H-1)){
    			cout << "#";
    		}else{
    			cout << ".";
    		}
    	}
    	cout << endl;
		}
    cout << endl;
    }

return 0;
}

Measured memory_bytes: 1152
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;


public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		String read = null;
		ArrayList<String> output = new ArrayList<String>();
		while ((read = reader.readLine()) != null) {
			String[] parts = read.split(" ");
			int[] nums = new int[2];
			int c = 0;
			for (String part:parts) {
				nums[c] = Integer.parseInt(part);
				c++;
			}

			int result = nums[0] + nums[1];

			String resultStr = String.valueOf(String.valueOf(result).length());
			output.add(resultStr);
		}

		for (String str:output) {
			System.out.println(str);
		}

	}

}

Measured memory_bytes: 17004
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)

ll mod = 1e09;

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

  ll r, g;
  cin >> r >> g;

  cout << r + 2 * (g - r) << endl;
  return 0;
}


Measured memory_bytes: 256
/*
	Name: 
	Copyright: 
	Author: 
	Date: 12/01/19 21:42
	Description: 这种做法的本质思路，有点接近于数值计算，数值分析里的编程设计思路，通过对要计算的表达式的改造来实现精度控制。

19:18 2019
*/

#include <cstdio>
#include <cmath>
#include <stdbool.h>
#include <cstring>
int main(){
	int N, A, B;
	long long num;
	scanf("%d %d %d", &N, &A, &B); 
    if(B < A) {
		printf("0\n");
		return 0;
	}
	if(N == 1){
		if(A == B){ 
			printf("1\n");
			return 0;
		}
		else {
			printf("0\n");
			return 0;
		}
	}	
	
	num = (long long)(B - A)*(N-2)+1;
//	printf("%lld\n", (long long)(B - A)*(N-2)+1);
	printf("%lld\n", num);
	return 0;	
}

Measured memory_bytes: 128
#include<stdio.h>
#include<string.h>
#define LEN 100005

typedef struct p{
   char name[100];
   int t;
}P;

P Q[LEN];
int head,tail,n;

void enqueue(P x){
	Q[tail] = x;
	tail =(tail+1)%LEN;
}

P dequeue(){
    P x =Q[head];
    head =(head+1)%LEN;
    return x;
}

int min(int a,int b){
	return a<b?a:b;
}

int main(){
	int elaps =0,c;
	int i,q;
	P u;
	scanf("%d %d",&n,&q);

	for(i=1;i<=n;i++){
		scanf("%s",Q[i].name);
		scanf("%d",&Q[i].t);
	}
	head =1;
	tail=n+1;

	while(head != tail){
		u=dequeue();
		c = min(q,u.t);
		u.t -=c;
		elaps +=c;
		if(u.t>0) enqueue(u);
		else{
			printf("%s %d\n",u.name,elaps);
		}
	}
	return 0;
}

Measured memory_bytes: 10756
#include<bits/stdc++.h>
#include <bits/stdc++.h>
#define INF 1e9
#define all(v) v.begin(), v.end()
#define rep(i, n) for(int i = 0; i < n; i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
using namespace std;

int main(){
    string s1, s2;
    int xl, yl;
    int dp[1001][1001];
    cin>>s1>>s2;
    xl = s1.size();
    yl = s2.size();
    
    for(int i = 0; i <= xl; i++){
        for(int j = 0; j <= yl; j++){
            dp[i][j] = INF;
        }
    }

    for(int i = 0; i <= yl; i++){
        dp[0][i] = i;
    }
    for(int i = 0; i <= xl; i++){
        dp[i][0] = i;
    }
    for(int i = 0; i < xl; i++){
        for(int j = 0; j < yl; j++){
            dp[i+1][j+1] = min(dp[i][j], min(dp[i+1][j], dp[i][j+1])) + 1;

            if(s1[i] == s2[j]){
                dp[i+1][j+1] = min(dp[i+1][j+1], dp[i][j]);
            }
        }
    }
    cout<<dp[xl][yl]<<endl;
    return 0;
}


Measured memory_bytes: 7120
#include<iostream>
#include<cstdio>
using namespace std;
int a[10],sum;
char c;
int main(void)
{
    while(cin>>c&&c!='\0')
    {
        if(c=='0') a[sum++]=0;
        else if(c=='1') a[sum++]=1;
        else if(sum) sum--;
	}
    if(sum) {
		for(int i=0;i<sum;i++) printf("%d",a[i]);
		printf("\n"); 
	}
	return 0;
}

Measured memory_bytes: 256
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
#include <cassert>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>

#define cauto const auto&
#define ALL(v) begin(v),end(v)
#else
#define ALL(v) (v).begin(),(v).end()
#endif

using namespace std;


namespace{
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}
template <class T> inline T &chmin(T &x, const T &y){ return x = min(x, y); }
template <class T> inline T &chmax(T &x, const T &y){ return x = max(x, y); }
template <class F, class T>
void convert(const F &f, T &t){
	stringstream ss;
	ss << f;
	ss >> t;
}


#define REP(i,n) for(int i=0;i<int(n);++i)
#define RALL(v) (v).rbegin(),(v).rend()


#define MOD 1000000007LL
#define EPS 1e-8


void mainmain(){
	int n;
	scanf("%d", &n);
	vll as(n);
	for(int i = 0; i < n; ++i){
		scanf("%lld", &as[i]);
	}

	LL wt = 1;
	LL ans = 0;
	for(int i = 0; i < 62; ++i){
		int c = 0;
		for(LL x : as){
			c += x >> i & 1;
		}
		ans = (ans + wt * c % MOD * (n - c)) % MOD;
		wt = wt * 2 % MOD;
	}
	printf("%lld\n", ans);
}



}
int main() try{
//	ios::sync_with_stdio(false); cin.tie(0);
	cout << fixed << setprecision(10);
	cerr << fixed << setprecision(4);
	mainmain();
}
catch(...){
	throw;
}


Measured memory_bytes: 2560
//shan61916
#include <bits/stdc++.h>
  using namespace std;
typedef   long long ll;
typedef   unsigned long long ull ;
typedef   double dll ;

#define   mp make_pair
#define   pb push_back
#define   ff first 
#define   ss second
#define   IOS ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define   endl "\n" 
#define   pll pair<ll, ll>
#define   all(x) x.begin(), x.end()
#define   vll vector<ll> 


int main(){
 IOS
#ifdef SHAN
    freopen("input.txt" , "r" , stdin);  
#endif
  ll n;
  cin >> n;
  cout << n*n*n << endl;
  return 0;
} //good night.

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define INF 100000000
#define rep(i,a,b) for(int (i)=a;(i)<(int)(b);(i)++)
using ll = long long int;

int main(){
    int N;
    cin >> N;
    vector<string>S(N);
    rep(i,0,N) cin >> S[i];
    set<string> ans(S.begin(),S.end());
    cout << ans.size() << endl;

}

Measured memory_bytes: 25108
#include <iostream>
#include <vector>
//#include <fstream>

using namespace std;

int main()
{
//	cut here before submit 
//	freopen ("testcase.divstudent", "r", stdin );
	const char rank[] = { 'A', 'B', 'C' };
	int n;

	while (cin >> n && n ){
		vector <vector <int> > s(n, vector <int> (3, 0 ) );

		for (int i = 0; i < n; ++i){
			for (int j = 0; j < 3; ++j){
				cin >> s[i][j];	// pm, pe, pj order
			} // end for
		} // end for
/*
100 _ÌÈÚª é	 A
wÆpêÌ½Ï_ª 90 _Èã	 A
3 ÈÚÌ½Ï_ª 80 _Èã	 A
3 ÈÚÌ½Ï_ª 70 _Èã	 B
3 ÈÚÌ½Ï_ª 50 _ÈãÅw©pêª 80 _Èã	 B
ãÌðð½³È¢	 C
¡Ìðð½·êÍAæèxÌ¢NXÉª¯çêÜ·B
*/
		for (int i = 0; i < n; ++i){

			double me  = (s[i][0] + s[i][1])/2.;
			double avg = (s[i][0] + s[i][1] + s[i][2])/3.;
 	
			if ( s[i][0] == 100 || s[i][1] == 100 || s[i][2] == 100
			|| me >= 90.0 || avg >= 80. ) {
				cout << rank[0] << endl;
				continue;
			} // end if
			if ( avg >= 70. || (avg >= 50. && (s[i][0] >= 80 || s[i][1] >= 80 ) ) ) {
				cout << rank[1] << endl;
				continue;
			} // end if

			cout << rank[2] << endl;
		} // end for
	} // end loop
		
	return 0;
}

Measured memory_bytes: 0
///
// File:  c.go
// Author: ymiyamoto
//
// Created on Sat Apr  7 21:08:55 2018
//
package main

import (
	"fmt"
	"sort"
)

var nums []int

func main() {
	nums = make([]int, 3)
	fmt.Scan(&nums[0], &nums[1], &nums[2])
	sort.Ints(nums)

	count := 0
	count += nums[2] - nums[1]
	nums[0] += count

	if (nums[2]-nums[0])%2 == 1 {
		count++
		nums[2]++
	}
	count += (nums[2] - nums[0]) / 2

	fmt.Println(count)
}


Measured memory_bytes: 512
import java.util.*;

public class Main {

    static int gcd (int a, int b) {return b>0?gcd(b,a%b):a;}

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long A = sc.nextLong();
        long V = sc.nextLong();
        long B = sc.nextLong();
        long W = sc.nextLong();
        long T = sc.nextLong();


        if(A == B){
            System.out.println("YES");
            System.exit(0);
        }

        if(W >= V){
            System.out.println("NO");
            System.exit(0);
        }

        long diff = Math.abs(A-B);
        long diffSpeed = Math.abs(W-V);

            if(T * diffSpeed < diff){
                System.out.println("NO");
            } else {
                System.out.println("YES");
            }


    }

}


Measured memory_bytes: 35928
import sys
sys.setrecursionlimit(300000)

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI0(): return map(lambda s: int(s) - 1, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
def LMI0(): return list(map(lambda s: int(s) - 1, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7
INF = float('inf')


S = input()
print(S[:3])

Measured memory_bytes: 61876
h,w=map(int,input().split())
g=[input() for _ in range(h)]
for x in range(h):
  for y in range(w):
    if g[x][y]=='#':
      f=1
      for dx,dy in ((1,0),(0,1),(-1,0),(0,-1)):
        nx,ny=x+dx,y+dy
        if nx<0 or nx>=h or ny<0 or ny>=w:
          continue
        elif g[nx][ny]=='#':
          f=0
      if f:
        print('No')
        break
  else:
    continue
  break
else:
  print('Yes')

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
using namespace std;
const int mod = 1000000007;
#define ll long long

int main()
{
	string S;
	cin >> S;
	if (S[5] == '1') cout << "TBD" << endl;
	else if (S[6] <= '4') cout << "Heisei" << endl;
	else cout << "TBD" << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <functional>
#include <iostream>
#include <cfenv>
#include <cmath>
using namespace std;
 
int main(){
    int N,H;
    cin >> N >> H;
    int a[N],b[N];
    int cnt=0;
    for(int i=0;i<N;i++){
      cin >> a[i] >> b[i];
    }
    sort(a,a+N,greater<>());
    sort(b,b+N,greater<>());
    for(int i=0;i<N;i++){
        if(a[0]<b[i]){
            H-=b[i];
            cnt++;
            if(H<=0){
                cout << cnt << endl;
                return 0;
            }
        }
    }
    cout << (int)ceil((double)H/a[0])+cnt << endl;
}

Measured memory_bytes: 1024
def solve():
  n = int(input())
  s = [input() for _ in range(n)]
  ans = 0
  righta = 0
  leftb = 0
  double = 0
  
  for i in range(n):
    tmp = s[i]
    targetlength = len(tmp)
    if tmp[0] =='B':leftb += 1
    if tmp[-1] == 'A': righta += 1
    if tmp[0] =='B' and tmp[-1] =='A':
      leftb -= 1
      righta -= 1
      double += 1
    for j in range(targetlength-1):
      if tmp[j] =='A' and tmp[j+1] == 'B': ans += 1
  ans += min(righta,leftb)
  righta -= min(righta,leftb)
  leftb -= min(righta,leftb)
  for i in range(double):
    if righta > 0:
      ans += 1
      continue
    if leftb > 0:
      ans += 1
      continue
    if righta == 0 and leftb == 0:
      righta += 1
      leftb += 1

  
  print(ans)
solve()

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

int main() {
  int n;
  cin >> n;
  vector<int> l(n);
  vector<int> r(n);
  for (int i = 0; i < n; i ++) {
    cin >> l.at(i) >> r.at(i);
  }

  int sum = 0;
  for (int i = 0; i < n; i ++) {
    sum += r.at(i) - l.at(i) + 1;
  }

  cout << sum << endl;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast",3,"inline")
#include <bits/stdc++.h>
using namespace std;
int k,x;
int main(){
	ios_base::sync_with_stdio(false);
	cin>>k>>x;
	for(int i=x-k+1;i<x+k;i++) cout<<i<<" ";
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int> >;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define irep(i, n) for(int i = n-1; i >= (int)0; i--)
#define erep(i,container) for (auto i : container)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define rrep(i,m,n) for(int i = m; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define mp make_pair
#define sum accumulate
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
typedef long long ll;
const int INF = 2000000000;
const ll INF64 = 1000000000000000ll;
const ll MOD = 1000000007LL;
int main(){
    bool han=1;
    string s;
    std::cin >> s;
    if(s[0]!='A')han=0;
    int p;bool d=0;
    int n=s.size();
    rrep(i,1,n-1){
        if(s[i]=='C'){
            d=1;p=i;break;
        }
    }
    if(!d||p==1)han=0;
    rrep(i,1,n){
        if(!(i==p||s[i]-'a'>=0&&s[i]-'a'<=25))han=0;
    }
    if(han)std::cout <<"AC" << std::endl;
    else std::cout << "WA"<< std::endl;
}

Measured memory_bytes: 384
package main
import (
   "fmt"
   "os"
   "bufio"
   "strconv"
)
var sc = bufio.NewScanner(os.Stdin)

func main() {
  sc.Split(bufio.ScanWords)
  for {
    h := nextInt() 
    w := nextInt() 
    if h == 0 && w == 0 {
        break
    }
    for i := 0; i < h; i++ {
        line := "" 
        for j := 0 ; j < w; j++ {
            line += "#"
        }
        fmt.Println(line)
    }
    fmt.Println() 
  }
  
}

func getStdin() (string) {
    sc.Scan()
    v := sc.Text()
    return v
}

func nextInt() (int) {
    sc.Scan()
    v, e := strconv.Atoi(sc.Text())
    if e != nil { panic(e) }
    return v
}

func nextFloat() (float64) {
    sc.Scan()
    v, e := strconv.ParseFloat(sc.Text(), 64)
    if e != nil { panic(e) }
    return v
}


Measured memory_bytes: 4152
#include<iostream>
using namespace std;
int N,tot1,tot2;
char ch[105];
int main()
{
	ios::sync_with_stdio(false);
	cin>>N;
	cin>>ch+1;
	for(register int i=1;i<=N;i++)
	{
		if(ch[i]=='R')
			tot1++;
		else if(ch[i]=='B')
			tot2++;
	}
	if(tot1>tot2)
		cout<<"Yes";
	else
		cout<<"No";
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		
		while(true){
			int a1 = stdIn.nextInt();
			int b1 = stdIn.nextInt();
			if(a1==0&&b1==0){
				return;
			}
			int[] a2 = new int[4];
			int[] b2 = new int[4];
			a2[0]=a1/1000;
			a1-=a2[0]*1000;
			a2[1]=a1/100;
			a1-=a2[1]*100;
			a2[2]=a1/10;
			a2[3]=a1%10;
			b2[0]=b1/1000;
			b1-=b2[0]*1000;
			b2[1]=b1/100;
			b1-=b2[1]*100;
			b2[2]=b1/10;
			b2[3]=b1%10;
			int hit=0, blow=0;
			for(int i=0;i<4;i++){
				if(a2[i]==b2[i]){
					hit++;
				}
			}
			for(int i=0;i<4;i++){
				for(int j=0;j<4;j++){
					if(i!=j&&a2[i]==b2[j]){
						blow++;
					}
				}
			}
			System.out.println(hit+" "+blow);
		}	
	}
}

Measured memory_bytes: 0
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {

		Scanner sc=new Scanner(System.in);
		int a=sc.nextInt();
		int b=sc.nextInt();
		
		sc.close();
		
		System.out.println(a*b+" "+(a+b)*2);
	}

}

Measured memory_bytes: 17304
from itertools import accumulate
N,Q = list(map(int,input().split()))
S = list(input())
cnt = [0]*(N)
for i in range(N-1):
    if S[i] == 'A' and S[i+1] == 'C':
        cnt[i] = 1
R = [0]+list(accumulate(cnt))
for k in range(Q):
    x,y = list(map(int,input().split()))
    print(R[y-1]-R[x-1])

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

#define IOS ios::sync_with_stdio(0)
#define F first
#define S second
#define MP make_pair
#define PB emplace_back

using namespace std;

const int N = 2e6;
long long int a[N];

int main () {
    IOS;
    long long int n, x, y, ans=0;
    cin >> n >> x >> y;
    x--;
    y--;
    for(int i = 0 ; i < n ; i++ ) {
        for(int j = i + 1 ; j < n ; j++ ) {
            long long int dis=j-i;
            if(i<=x&&y<=j)dis=min(dis,x-i+j-y+1);
            if(x<=i&&i<=y&&y<=j) dis=min(dis,i-x+1+j-y);
            if(x<=j&&j<=y&&i<=x) dis=min(dis,y-j+1+x-i);
            if(x<=i&&j<=y)dis=min(dis,i-x+y-j+1);
            //cout << i << ' ' << j << ' ' << dis << '\n';
            a[dis]++;
        }
    }
    for(int i = 1 ; i<=n-1 ; i++ ) {
        cout << a[i] << '\n';
    }
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		String op = sc.next();
		int b = sc.nextInt();
		
		if (op.equals("+")) {
			System.out.println(a + b);
		} else if (op.equals("-")) {
			System.out.println(a - b);
		}
	}
}

Measured memory_bytes: 23892
#include <iostream>
#include <string>

int main(void){
  std::string str;
  std::cin >> str;
  if((str[0]==str[1] && str[1]==str[2]) || (str[1]==str[2] && str[2]==str[3]))
    std::cout << "Yes" << std::endl;
  else std::cout << "No\n" << std::endl;
  return 0;
}

Measured memory_bytes: 3584
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();
// freopen("input.txt", "r", stdin);

int main() {
    string s, t;
    cin >> s >> t;
    sort(s.begin(), s.end());
    sort(t.begin(), t.end());
    reverse(t.begin(), t.end());
    if (s < t) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}




Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <utility>
#include <set>
using namespace std;
set<pair<int,int>> s;
int main(){
	int i,j,n;
	cin >> n;
	if(n&1){
		for(i=1;i<n;i++){
			s.insert({i,n});
		}
		for(i=1;i<n;i++){
			for(j=i+1;j<n;j++){
				if(i+j==n) continue;
				s.insert({i,j});
			}
		}
	}else{
		for(i=1;i<=n;i++){
			for(j=i+1;j<=n;j++){
				if(i+j==n+1) continue;
				s.insert({i,j});
			}
		}
	}
	cout << s.size() << endl;
	auto it = s.begin();
	while(it!=s.end()){
		pair<int,int> x = *it;
		cout << x.first << " " << x.second << endl;
		it++;
	}
}

Measured memory_bytes: 512
#include<cstdio>
#include<algorithm>
using namespace std;
int a[55],sum[55];
long long f[55][2505],ans;
int n,m;
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++) 
	{
		scanf("%d",&a[i]); 
		sum[i]=sum[i-1]+a[i];
	}
    f[0][0]=1;
    for(int k=1;k<=n;k++)
        for(int i=k;i>=1;i--)
            for(int j=sum[k];j>=a[k];j--)
                f[i][j]+=f[i-1][j-a[k]];
    for(int i=1;i<=n;i++)
		ans+=f[i][i*m];
    printf("%lld\n",ans);
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ACC ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define mod 1000000007
#define MAXN 10000001
//string alpha="abcdefghijklmnopqrstuvwxyz";
//int dx[]={1,-1,0,0};
//int dy[]={0,0,1,-1};
//int dx8[]={1,-1,0,0,1,1,-1,-1};
//int dy8[]={0,0,1,-1,1,-1,1,-1};
/*int spf[MAXN];
void sieve()
{
	int i,j;
	for(i=0;i<MAXN;i++)
	spf[i]=i;
	for(i=4;i<MAXN;i+=2)
	spf[i]=2;
	for(i=3;i*i<MAXN;i++)
	{
		if(spf[i]==i)
		{
			for(j=i*i;j<MAXN;j+=i)
			{
				if(spf[j]==j)spf[j]=i;
			}
		}
	}
}*/
/*bool isvowel(char c)
{
    switch(c)
    {
        case 'a':
        case 'e':
        case 'i':
        case 'o':
        case 'u':return true;
        default : return false;
    }
}*/
/*bool isValid(int x,int y,int n,int m)
{
    if(x<0||x>n-1||y<0||y>m-1)return false;
    return true;
}*/
/*
bool comp(pair<int,int> x,pair<int,int> y)
{
    if(y.second==x.second)
        return y.first<x.first;
    return y.second<x.second;
}*/
int32_t main()
{
    ACC
    int T;
    T=1;
    //cin>>T;
    while(T--)
    {
      int a,b,c,d;
      cin>>a>>b>>c>>d;
      cout<<max({a*c,a*d,b*c,b*d})<<"\n";
    }
    return 0;
}


Measured memory_bytes: 3636
#include<stdio.h>

int main(void)
{
  int x,y;

  while(1){
  scanf("%d %d",&x,&y);
  if(x == 0 && y == 0)
    break;
  else if(x < y){
    printf("%d %d\n",x,y);
  }
  else{
    printf("%d %d\n",y,x);
  }
 }
  return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
ll m=1000000007;
ll sieve[1000001]={0},i,j;
ll power(ll p, ll k)
{
ll a=1;
while(k)
{
if(k&1)
a=(a*p)%m;
p=(p*p)%m;
k>>=1;
}
return a;
}
using namespace std;
int main()
{
ll n;
cin>>n;
set<ll> s;
ll i,j,ans=0,k;
ll a[n];
for(i=0;i<n;i++)
cin>>a[i];
sort(a,a+n,greater<>());
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
for(k=j+1;k<n;k++)
{
if(a[k]+a[j]>a[i])
{
ans++;
//cout<<a[i]<<a[j]<<a[k]<<" ";
}
}
}
}
cout<<ans;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 10;
int n;
ll a[maxn], sufsum[maxn], rest[maxn];
int main()
{
	cin>>n;
	for(int i = 1; i <= n + 1; i++)
		cin>>a[i];
	for(int i = n + 1; i >= 1; i--)
		sufsum[i] = sufsum[i + 1] + a[i];
	long long now, ans = 0ll;
	for(int i = 1; i <= n + 1; i++)
	{
		now = (i == 1 ? 1ll : rest[i - 1] * 2ll);
//		cout<<now<<" ##"<<endl;
		if(now <= 0ll)
		{
			cout<<-1<<endl;
			return 0;
		}
		if(now > 1e18)
		{
			ans += sufsum[i];
			continue;
		}
		ans += min(now, sufsum[i]);
		if(min(now, sufsum[i]) < a[i])
		{
			cout<<-1<<endl;
			return 0;
		}
		rest[i] = min(now, sufsum[i]) - a[i];
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 5980
#include <bits/stdc++.h>
using namespace std;
#define rep0(i, n) for (long long i = 0; i < (long long)(n); i++)
#define rep1(i,n) for(long long i=1;i<=(long long)(n);i++)
#define all(v) v.begin(),v.end()
#define Sort(v) sort(all(v))
#define Reverse(v) reverse(all(v))
#define Rsort(v) sort(all(v),greater)
#define pub(v) push_back(v)
#define pob(v) pop_back(v)
typedef long long ll;
typedef vector<ll> vel;
typedef vector<vector<ll>> vel2d;
typedef string str;
typedef pair<ll,ll> pal;
typedef vector<str> ves;


int main() {
    ll H,ans=0,cnt=1,n;
    cin>>H;
    while(1){
        if(H==1){ans+=cnt;break;}
        else{
            H/=2;
            ans+=cnt;
            cnt*=2;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  
  int N;
  cin >> N;
  int kind=0;
  set<string> Set;
  for(int i=0;i<N;i++){
    string p;
    cin >> p;
    Set.insert(p);
  }
  cout << Set.size() << endl;
  
}

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

// ------------------
// Integer modulo MOD
// ------------------
const int64_t MOD = 1e9 + 7;
struct mint
{
    int64_t x;
    mint(int64_t x = 0) : x((x % MOD + MOD) % MOD) {}
    mint operator-() const { return mint(-x); }
    mint &operator+=(const mint a)
    {
        if ((x += a.x) >= MOD)
            x -= MOD;
        return *this;
    }
    mint &operator-=(const mint a)
    {
        if ((x += MOD - a.x) >= MOD)
            x -= MOD;
        return *this;
    }
    mint &operator*=(const mint a)
    {
        (x *= a.x) %= MOD;
        return *this;
    }
    mint operator+(const mint a) const { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint pow(int64_t n) const
    {
        if (n == 0)
            return 1;
        mint t = pow(n >> 1);
        t *= t;
        if (n & 1)
            t *= *this;
        return t;
    }
    mint inv() const { return pow(MOD - 2); }
    mint &operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream &operator>>(istream &is, const mint &a) { return is >> a.x; }
ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }

// ---------------------------------------
// Number of combinations (nCk) modulo MOD
// ---------------------------------------
vector<mint> fac;
vector<mint> fac_inv;
vector<mint> inv;
void init_comb(int mx)
{
    fac = vector<mint>(mx + 1), fac_inv = vector<mint>(mx + 1), inv = vector<mint>(mx + 1);
    fac.at(0) = fac.at(1) = 1;
    fac_inv.at(0) = fac_inv.at(1) = 1;
    inv.at(1) = 1;
    for (int i = 2; i <= mx; i++)
    {
        fac.at(i) = fac.at(i - 1) * i;
        inv.at(i) = -inv.at(MOD % i) * (MOD / i);
        fac_inv.at(i) = fac_inv.at(i - 1) * inv.at(i);
    }
}
mint comb(int n, int k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac.at(n) * fac_inv.at(k) * fac_inv.at(n - k);
}

mint f(int r, int c)
{
    return comb(r + c, c);
}

mint g(int r, int c)
{
    return f(r + 1, c + 1) - 1;
}

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

    init_comb(2e6 + 2);
    cout << g(r2, c2) - g(r1 - 1, c2) - g(r2, c1 - 1) + g(r1 - 1, c1 - 1) << endl;
    return 0;
}


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

int main()
{

    int a = 0, b = 0;
    int figa;
    int figac = 0;
    int i;
    //int j;
   
    while (scanf("%d %d",&a ,&b) != EOF) {
        
       // printf("%d\n",(int)(a + b / pow(10.0, i)));
        if ((0 <= a && a <= 1000000) && (0 <= b && b <= 1000000)) {
            for (i = 0; i <= 8; i++) {
                if (((int)((a + b) / pow(10, i)) == 0) && figac == 0){
                    figa = i;
                    figac++;
                }
            }
            printf("%d\n",figa);
            figac = 0;
        }
    }
    return 0;
}

Measured memory_bytes: 644
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
template <class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template <class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

#include <sstream>
vector<string> split(const string &s, char delim) {
    vector<string> elems;
    stringstream ss(s);
    string item;
    while(getline(ss, item, delim)) {
        if(!item.empty()) {
            elems.push_back(item);
        }
    }
    return elems;
}

int main() {
    string S;
    cin >> S;
    auto d = split(S, '/');
    if(stoi(d[1]) <= 4) {
        cout << "Heisei" << endl;
    } else {
        cout << "TBD" << endl;
    }
    return 0;
}

Measured memory_bytes: 3608
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            A();
        }

        static void A()
        {
            if (new List<char> { 'a', 'e', 'i', 'o', 'u' }.Contains(Read()[0]))
                Println("vowel");
            else Println("consonant");
        }

        static List<long> ReadLines(long n)
        {
            var l = new List<long>();
            for (long i = 0; i < n; i++)
            {
                l.Add(ReadLong());
            }
            return l;
        }

        static void YESOrNO(bool e) => Println(e ? "YES" : "NO");

        static void YesOrNo(bool e) => Println(e ? "Yes" : "No");

        static IEnumerable<int> Range(int start, int stop)
        {
            if (start < 0 || stop < 0 || start > stop || (start <= 0 && stop <= 0))
                return new List<int>();

            return Enumerable.Range(start, stop - start);
        }

        static bool IsDigit(string str)
        {
            var i = 0;
            return int.TryParse(str, out i);
        }

        static int SumDigits(long num)
        {
            return num.ToString().Select(x => x.ToString()).Sum(int.Parse);
        }

        static int[] ToIntArray(string str)
        {
            return str.Select(x => x.ToString()).Select(int.Parse).ToArray();
        }

        static long Gcd(long a, long b) => b == 0 ? a : Gcd(b, a % b);
        static long Lcm(long a, long b) => a / Gcd(a, b) * b;

        static bool IsPrime(int x)
        {
            if (x <= 1 || (x != 2 && x % 2 == 0)) return false;
            if (x == 2) return true;

            for (int i = 3; i < x; i += 2)
                if (x % i == 0) return false;

            return true;
        }

        static string Read() => Console.ReadLine();
        static int ReadInt() => int.Parse(Read());
        static long ReadLong() => long.Parse(Read());

        static List<string> ReadSplit() => Read().Split().ToList();
        static List<int> ReadSplitInt() => Read().Split().Select(int.Parse).ToList();
        static List<long> ReadSplitLong() => Read().Split().Select(long.Parse).ToList();

        static void Print(object value) => Console.Write(value.ToString());
        static void Println(object value) => Console.WriteLine(value.ToString());

        static string Join<T>(IEnumerable<T> list) => string.Join("", list);
    }

    public static class MyExtensions
    {
        public static string Slice(this string str, int start = 0, int stop = 0)
        {
            if (start > str.Length || stop > str.Length || start < 0 || stop < 0)
                return "";

            if (stop == 0) stop = str.Length;
            return str.Substring(start, stop - start);
        }
    }
}


Measured memory_bytes: 13268
class BIT:
    def __init__(self, n):
        self.n = n
        self.bit = [0] * (n+10)
    def add(self,x,w):
        while x <= self.n:
            self.bit[x] += w
            x += (x&-x)
            
    def sum(self,x):
        cnt = 0
        while x > 0:
            cnt += self.bit[x]
            x -= (x&-x)
        return cnt

    def psum(self,a,b):
        return self.sum(b-1)-self.sum(a-1)

    def bisect(self, w):
        # 値がw以上となる最小のindex
        x = 0
        k = 1
        while k < self.n:
            k *= 2            
        while k > 0:
            # x+kの値がwより小さければ、treeの右側に移動
            if x+k<=self.n and self.bit[x+k] < w:
                w -= self.bit[x+k]
                x += k            
            k //= 2
        return x + 1
    
n = int(input())
ps = list(map(int, input().split()))

# 1-indexedにする
inds = [0]*(n+1)
for i, p in enumerate(ps):
    inds[p] = i+1
bit = BIT(n)
cnt = 0
# 大きい順に
for p in range(n,0,-1):
    ind = inds[p]
    nl = bit.sum(ind)   # 自分より左にあるやつの個数
    nr = (n-p) - nl     # 自分より左にあるやつの個数    
    bit.add(ind, 1)     # bitを1で埋めていく
    # 自分を含んで左右のインデックスを見る(端注意)
    ixl2 = bit.bisect(nl-1) if nl >= 2 else 0
    ixl1 = bit.bisect(nl)   if nl >= 1 else 0
    ixr1 = bit.bisect(nl+2) if nr >= 1 else n+1
    ixr2 = bit.bisect(nl+3) if nr >= 2 else n+1
    tmp = 0
    tmp += (ixl1-ixl2)*(ixr1-ind) #左側から1個取る
    tmp += (ixr2-ixr1)*(ind-ixl1) #右側から1個取る
    cnt += p*tmp    
    # print("p",p,nl,nr,"ind",ixl2,ixl1,ind,ixr1,ixr2,tmp,cnt)
print(cnt)

Measured memory_bytes: 55148
import java.io.*;
import java.util.*;
import java.lang.*;
import java.text.DecimalFormat;
public class Main {
public static void main (String[]args) {

    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    try {
        DecimalFormat df = new DecimalFormat("0.000000000");
        String  lines = br.readLine();    

        String[] strs = lines.trim().split("\\s+");
         int [] a = new int [4];
        for (int i = 0; i < strs.length; i++) {
        a[i] = Integer.parseInt(strs[i]);
        }

    // Cosine Law solve 

  double radian = Math.PI * 2 * ((double)a[2] / 12.0 + ((double)a[3] / 60.0) / 12.0 - (double)a[3]/ 60.0);
    
  double ans = (double)(a[0] * a[0]+ a[1] * a[1]) - (double)(2 * a[0] *
  a[1]) * Math.cos(radian);
  System.out.println(df.format(Math.sqrt(ans)));

    }catch (Exception e) {
       }
       }
   }

Measured memory_bytes: 35692