akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
typedef long long ll;
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mod 1000000007
#define all(x) x.begin(),x.end()
#define deb(x) cout<<#x<<" "<<x<<"\n";
#define cr7 ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
int main() {
	cr7
	ll r;
	cin >> r;
	double d = 6.28318530717958623200/2.00;
	//cout.precision(20+floor(log10(2*r) + 1));
	cout << 2*(d)*r<<"\n";
}

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

int combo(int a, int b);

int main(){
    int n,m;
    cin >> n >> m;
    int ans;
    ans = combo(n,2) + combo(m,2);
    cout << ans << endl;
    return 0;
}

int combo(int a, int b){
    int ans=0;
    if(a==1){
        return ans;
    }

    ans = 1;
    for(int i=a; i>a-b; i--){
        ans *= i;
    }
    for(int i=b; i>0; i--){
        ans /= i;
    }
    return ans;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
    int n;cin>>n;
    vector<int> A(n);
    for(int i = 0; n > i; i++){
        cin>>A[i];
    }
    sort(A.begin(),A.end());
    if(A[n-1]==A[0])cout << 0 << endl;
    else cout << (A[n-1]-A[0]-1)/2+1 << endl;
}


Measured memory_bytes: 3160
N = int(input())

A = []

while N>0:
    tmp = N%10
    A.append(tmp)
    N = (N-tmp)//10

dp = [[0 for i in range(len(A))] for j in range(len(A))]

dp[0][0] = 2**(len(A)-1)

for i in range(1, len(A)):
    for j in range(i-1):
        dp[i][j] = dp[i-1][j]
    dp[i][i-1] = dp[i-1][i-1]//2
    dp[i][i] =  dp[i-1][i-1]//2
    
ans = 0
    
for i in range(len(A)):
    for j in range(i+1):
        ans = ans + dp[i][j]*A[i]*(10**j)
        
print(ans)

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

int main() {
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    if(abs(a-c)<=d){
        cout<<"Yes";
    }
    else if(abs(a-b)<=d&&abs(b-c)<=d){
        cout<<"Yes";
    }
    else{
        cout<<"No";
    }
    return 0;
}

Measured memory_bytes: 3644
#include <stdio.h>
int main()
{
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	int t;
	if(a>b)
	{t=a;a=b;b=t;}
	if(a>c)
	{t=a;a=c;c=t;}
	if(b>c)
	{t=b;b=c;c=t;}
	printf("%d\n",c-a);
	return 0;
}

Measured memory_bytes: 128
no_of_routes,time_limit=map(int,input().split())

smallest_cost=0
for i in range (no_of_routes):
    costs,times=map(int,input().split())
    if times<=time_limit and smallest_cost==0 :
        smallest_cost=costs
    if times <= time_limit and costs<=smallest_cost:
        smallest_cost = costs

if smallest_cost==0:
    print("TLE")
else :
    print(smallest_cost)

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

int main()
{
	int A, B, C, D, E, F;
	double J = 0, I = 0;
	int maxF = 0, maxE = 0;


	cin >> A >> B >> C >> D >> E >> F;

	A *= 100;
	B *= 100;

	for (int a = 0; A*a <= F; a++) {
		for (int b = 0; A*a + B*b <= F; b++) {
			for (int c = 0; A*a + B*b + C*c <= F; c++) {
				for (int d = 0; A*a + B*b + C*c + D*d <= F; d++) {
					int cd = C*c + D*d;
					int ab = A*a + B*b;
					if (cd == 0 || ab == 0)continue;
					if (cd > E*ab / 100)break;

					I = (double)100 * cd / (ab + cd);

					if (I > J) {
						maxF = ab + cd;
						maxE = cd;
						J = I;
					}
				}
			}
		}
	}

	if (maxF == 0 && maxE == 0)maxF = A;

	cout << maxF << " " << maxE << endl;

	return 0;
}

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

using namespace std;

typedef long long LL;
#define N 600000
#define P(x,y) make_pair(x,y)
#define INF 0x3f3f3f3f3f3f3f3fLL

int n,a[N],sz[N],rt,mx[N];
LL f[N];
bool vis[N];
vector<pair<int,int> > g[N];

void getsz(LL u,LL fa){
	sz[u]=1;
	for (auto i:g[u]){
		LL v=i.first;
		if (!vis[v]&&v!=fa){
			getsz(v,u);
			sz[u]+=sz[v];
		}
	}
}

void getrt(LL u,LL fa,LL sum){
	mx[u]=sum-sz[u];
	for (auto i:g[u]){
		LL v=i.first;
		if (!vis[v]&&v!=fa){
			getrt(v,u,sum);
			mx[u]=max(mx[u],sz[v]);
		}
	}
	rt=mx[u]<mx[rt]?u:rt;
}

void dfs(LL u,LL fa,LL dist,vector<int> &q){
	q.push_back(u);
	f[u]=a[u]+dist;
	for (auto i:g[u]){
		LL v=i.first;
		if (!vis[v]&&v!=fa){
			dfs(v,u,dist+i.second,q);
		}
	}
}

struct edge{
	int x,y; LL d;
	edge(int x=0,int y=0,LL d=0):x(x),y(y),d(d){}
	bool operator < (const edge &w) const{
		return d<w.d;
	}
};
vector<edge> e[N];
LL par[N];

LL gfa(LL x){
	return x==par[x]?x:par[x]=gfa(par[x]);
}

void solve(LL x){
	vis[x]=1;
	vector<int> q;
	dfs(x,0,0,q);
	LL t=0; f[t]=INF;
	for (int i:q) if (f[i]<f[t]) t=i;
	for (int i:q) e[x].push_back(edge(i,t,f[i]+f[t]));
	getsz(x,0);
	for (auto i:g[x]){
		int y=i.first;
		if (!vis[y]){
			rt=0; getrt(y,0,sz[y]);
			LL tmp=rt; solve(rt);
			for (edge i:e[tmp]) e[x].push_back(i);
			vector<edge>().swap(e[tmp]);
		}
	}
	sort(e[x].begin(),e[x].end());
	for (LL i:q) par[i]=i;
	vector<edge> ee;
	for (edge i:e[x]){
		LL u=i.x,v=i.y;
		u=gfa(u); v=gfa(v);
		if (u!=v){
			par[u]=v;
			ee.push_back(i);
		}
	}
	e[x].swap(ee);
	vector<edge>().swap(ee);
	vector<int>().swap(q);
}

int main(){
	scanf("%d",&n);
	for (LL i=1;i<=n;++i) scanf("%d",a+i);
	for (LL i=1;i<n;++i){
		LL x,y,z; scanf("%lld%lld%lld",&x,&y,&z);
		g[x].push_back(P(y,z));
		g[y].push_back(P(x,z));
	}
	getsz(1,0); mx[rt=0]=n+1; getrt(1,0,sz[1]);
	LL tmp=rt; solve(rt);
	LL ans=0; for (edge i:e[tmp]) ans+=i.d;
	printf("%lld\n",ans);
	return 0;
}
			

Measured memory_bytes: 79548
package main

import (
	"bufio"
	"fmt"
	"os"
)

var (
	read  = bufio.NewReader(os.Stdin)
	write = bufio.NewWriter(os.Stdout)
)

func min(a, b int) int {
	if a <= b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a >= b {
		return a
	}
	return b
}

func yesno(result bool) {
	if result {
		fmt.Fprintln(write, "Yes")
	} else {
		fmt.Fprintln(write, "No")
	}
}

func printansStr(result bool, a, b string) {
	if result {
		fmt.Fprintln(write, a)
	} else {
		fmt.Fprintln(write, b)
	}
}

func printansInt(result bool, a, b int) {
	if result {
		fmt.Fprintln(write, a)
	} else {
		fmt.Fprintln(write, b)
	}
}

func main() {
	defer write.Flush()

	var k, x int
	fmt.Fscan(read, &k, &x)

	for i := x - k + 1; i <= x+k-1; i++ {
		fmt.Fprint(write, i, " ")
	}
	fmt.Fprintln(write, " ")
}


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

int main() {
    int n, m, q;
    cin >> n >> m >> q;

    vector<vector<int>> acc(n+1, vector<int>(n+1, 0));
    for (int i = 0; i < m; i++) {
        int li, ri;
        cin >> li >> ri;
        acc[li][ri]++;
    }

    for (int i = 0; i <= n; i++) {
        for (int j = 0; j + 1 <= n; j++) {
            acc[i][j+1] += acc[i][j];
        }
    }

    for (int i = 0; i <= n; i++) {
        for (int j = 0; j + 1 <= n; j++) {
            acc[j+1][i] += acc[j][i];
        }
    }

    vector<int> ans(q);
    for (auto& e : ans) {
        int pi, qi;
        cin >> pi >> qi;
        e = acc[qi][qi] - acc[qi][pi-1] - acc[pi-1][qi] + acc[pi-1][pi-1];
    }

    for (auto& e : ans) cout << e << endl;
}


Measured memory_bytes: 2304
n,m=map(int,input().split())
ab = [list(map(int,input().split())) for _ in range(n)]
ab.sort(key=lambda x:x[0])
now=0
ans=0
for i in range(n):
  if now+ab[i][1]<=m:
    now += ab[i][1]
    ans += ab[i][0]*ab[i][1]
  else:
    ans += ab[i][0]*(m-now)
    break
print(ans)

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

int main(){
    int N, cont = 0, i;

    cin >> N;
    vector<int> order(N+1);
    vector<int> satis(N+1);
    vector<int> add(N+1);
    order[0] = 0;
    satis[0] = 0;
    add[0] = 0;
    add[1] = 0;
    for(i = 1; i < N+1; i++){
        cin >> order[i];
    }
    for(i = 1; i < N+1; i++){
        cin >> satis[i];
    }
    for(i = 2; i < N+1; i++){
        cin >> add[i];
    }
    for(i = 1; i < N+1; i++){
        cont += satis[order[i]];
        if(order[i] == order[i-1] + 1){
            cont += add[order[i]];
        }
    }
    cout << cont << endl;
}

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

int main() {
  int X;
  cin>>X;
  int answer=X;
  int pointa=1;
  
    for(int i=X; i<min(2*X,X+1000); i++){
      pointa=1;
      for(int j=2; j<i; j++){
        pointa=min(pointa,i%j);
      }
      if(pointa==1){
        answer=i;
        break;
      }
    }
  
  cout<<answer<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
  int X;
  cin>>X;
  for(int i=0;i<100;i++)
    for(int j=0;j<100;j++)
      if(i*i*i*i*i+j*j*j*j*j==X){
        cout<<i<<' '<<0-j<<endl;
        return 0;
      }
  for(int i=1;;i++){
    for(int j=i;j>=0;j--){
      if(i*i*i*i*i-j*j*j*j*j==X){
        cout<<i<<' '<<j<<endl;
        return 0;
      }
      if(i*i*i*i*i-j*j*j*j*j>=X)
        break;
    }
  }
}

Measured memory_bytes: 3552
#include<stdio.h>
#include<stdlib.h>

typedef struct{
  char mark;
  int num;
  int order;
}card;

int partition(card *,int,int);
void sort(card *,int,int);

int main(){

  card *C;
  int i,j,n,judge=0;
  char a,b;

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

  C=(card*)malloc(sizeof(card)*n*2+1);

  for(i=0;i<n;i++){
    scanf("%c%c%d%c",&C[i].mark,&a,&C[i].num,&b);

    C[i].order=i;
  }
  sort(C,0,i-1);

  for(i=0;i<n;i++){
    if(C[i].num==C[i+1].num){
      if(C[i].order>C[i+1].order){
	judge=1;
	break;
      }
    }
  }
  if(judge==0){
    printf("Stable\n");
  }else{
    printf("Not stable\n");
  }

  for(i=0;i<n;i++){
    printf("%c %d\n",C[i].mark,C[i].num);
  }

  free(C);
  return 0;
}

void sort(card *C,int p,int r){

  int q;

  if(p<r){
    q=partition(C,p,r);
    sort(C,p,q-1);
    sort(C,q+1,r);
  }
}

int partition(card *C,int p,int r){

  card change;

  int i=p-1,j;
  int x=C[r].num;

  for(j=p;j<r;j++){
    if(C[j].num<=x){
      i=i+1;
      change=C[j];
      C[j]=C[i];
      C[i]=change;
    }
  }
  change=C[r];
  C[r]=C[i+1];
  C[i+1]=change;

  return i+1;
}

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

long long BinarySearch(long long l, long long r, function<bool(long long)> f) {
  /* O(log(r-l) * O(f)) */
  /* Find the boundary T and F that satisfies (f(T)==true && f(F)==false && abs(T-F)==1). */
  bool fl = f(l), fr = f(r);
  assert(fl!=fr);
  long long &T = fl ? l : r;
  long long &F = fr ? l : r;
  while(r-l>1) {
    long long m = l + (r-l) / 2;
    if(f(m)) T = m;
    else F = m;
  }
  return T;
}

double BinarySearch(double l, double r, int iteration, function<bool(double)> f) {
  /* O(iteration * O(f)) */
  /* Find the boundary T and F that satisfies (f(T)==true && f(F)==false) for (iteration) times. */
  bool fl = f(l), fr = f(r);
  assert(fl!=fr);
  double &T = fl ? l : r;
  double &F = fr ? l : r;
  while(iteration--) {
    double m = l + (r-l) / 2;
    if(f(m)) T = m;
    else F = m;
  }
  return T;
}

signed main() {
#if 1 // https://atcoder.jp/contests/abc174/tasks/abc174_e
  int n,k; cin >> n >>k;
  vector<int> a(n);
  for(int i=0; i<n; ++i) cin >> a[i];

  auto f = [&](long long x) {
    if(x==0) return false;
    int kk = k;
    for(int i=0; i<n; ++i) kk -= (a[i] + x-1) / x - 1;
    return kk >= 0;
  };

  cout << BinarySearch(0, *max_element(a.begin(),a.end()), f) << endl;
#else
  int n,k; cin >> n >> k;
  vector<double> w(n), p(n);
  for(int i=0; i<n; ++i) cin >> w[i] >> p[i];

  auto f = [&](double x) {
    vector<double> v(n);
    for(int i=0; i<n; ++i) v[i] = w[i] * (p[i] - x);
    sort(v.begin(), v.end(), greater<double>());
    double sum = accumulate(v.begin(), v.begin()+k, 0.0);
    return sum > 0;
  };

  cout << setprecision(12) << BinarySearch(0.0, 100.0, 100, f) << endl;
#endif
}


Measured memory_bytes: 4048
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		int K=sc.nextInt();
		int max= Integer.MAX_VALUE;
		int now_cost=0;
		int[] point=new int[N];

		for(int i=0; i<N; i++) {
			point[i]=sc.nextInt();
		}

		for(int i=0; i<N-K+1; i++) {
			now_cost=0;
			now_cost=Math.min(Math.abs(point[K-1+i]-point[i])+Math.abs(point[i]),Math.abs(point[K-1+i]-point[i])+Math.abs(point[K-1+i]));
			max=Math.min(now_cost, max);
		}

		System.out.println(max);
	}
}

Measured memory_bytes: 48480
//
// Created by Naman Bhalla on 2019-05-26.
//

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <vector>
#include <utility>
#include <climits>

using namespace std;

int maxm{};
int dp[100005];
vector< vector< int > > adj_list{};

void solve(int i){
//    cout << i << endl;
    if(dp[i] != -1){
        return;
    }

    dp[i] = 0;
    for(auto &v: adj_list[i]) {
        solve(v);
        dp[i] = max(1 + dp[v], dp[i]);
    }
//    cout << i << " " << dp[i] << endl;
    maxm = max(maxm, dp[i]);
}

int main(){
    memset(dp, -1, sizeof dp);
    int n, m;
    cin >> n >> m;
    maxm = -1;
    adj_list = vector< vector < int > >();
    adj_list.resize(n + 1);

    int x, y;
    for(int i = 0; i < m; ++i){
        cin >> x >> y;
        adj_list[x].push_back(y);
    }

    for(int i = 1; i <= n; ++i){
        solve(i);
    }

    cout << maxm << endl;
    return 0;
}

Measured memory_bytes: 7424
#include <bits/stdc++.h>
#include <algorithm>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define stdi(in) freopen(in, "r", stdin)
#define stdo(out) freopen(out, "w", stdout)
#define stdio(in, out) stdi(in); stdo(out)
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define MAX 100007
#define MOD 1000000007
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
#define ordered_set tree<pair<int, int> , null_type, less<pair<int, int> >, rb_tree_tag, tree_order_statistics_node_update>

//const ll modd = 998244353;
const ll inf = 1e18;
int n;
vector<vector<ll> > arr;
vector<ll> dp, group;

void solve(int i, vector<int> &rem, ll curr, int mask, int gr){
    //cerr<<"solve\n";
    if(i==(int)rem.size()){
        dp[mask] = max(dp[mask], curr+group[gr]);
        return;
    }

    solve(i+1, rem, curr, mask | (1<<rem[i]), gr | (1<<rem[i]));
    solve(i+1, rem, curr, mask, gr);
}

int main(){
    /*#ifndef ONLINE_JUDGE
        stdio("in", "out");
    #endif*/
    //freopen("err", "w", stderr);
    fast;
    cin>>n;
    int allmask = (1<<n)-1;
    arr.resize(n, vector<ll>(n));
    dp.resize(allmask+1, 0);
    group.resize(allmask+1, 0);
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            cin>>arr[i][j];
        }
    }

    for(int mask=0;mask<=allmask;mask++){
        for(int i=0;i<n;i++){
            if((1<<i) & mask){
                for(int j=i+1;j<n;j++){
                    if((1<<j) & mask){
                        group[mask]+=arr[i][j];
                    }
                }
            }
        }
    }

    for(int mask=0;mask<=allmask;mask++){
        vector<int> rem;
        for(int i=0;i<n;i++){
            if(!(mask & (1<<i))){
                rem.pb(i);
            }
        }

        solve(0, rem, dp[mask], mask, 0);
    }

    cout<<dp[allmask]<<'\n';

    return 0;
}



Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); ++i)
template <class T>inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;}
template <class T>inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}
using namespace std;
using ll = long long;
using P = pair<int, int>;
using Pl = pair<long long, long long>;
using veci = vector<int>;
using vecl = vector<long long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;

int main() {
    int X,N;
    cin >> X >> N;
    veci p(N);
    REP(i,N) cin >> p[i];
    if(N == 0) {
        cout << X << endl;
        return 0;
    }
    bool ok = false;
    REP(i,N) {
        if(X == p[i]) ok = true;
    }
    if(!ok) {
        cout << X << endl;
        return 0;
    }
    int a = X;
    int b = X;
    while(1) {
        bool ok_a = false;
        bool ok_b = false;
        REP(i,N) {
            if(a == p[i]) ok_a = true;
            if(b == p[i]) ok_b = true;
        }
        if(!ok_b) {
            cout << b << endl;
            return 0;
        }
        if(!ok_a) {
            cout << a << endl;
            return 0;
        } 
        a++;
        b--;
    }
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}
int main(){
	string s;
	cin>>s;
	reverse(all(s));
	int N=s.size();
	int i=0;
	while(i<N){
		if(s.substr(i,5)=="maerd"){
			i+=5;
		}else if(s.substr(i,7)=="remaerd"){
			i+=7;
		}else if(s.substr(i,5)=="esare"){
			i+=5;
		}else if(s.substr(i,6)=="resare"){
			i+=6;
		}else{
			puts("NO");
			return 0;
		}
	}
	puts("YES");
}


Measured memory_bytes: 640
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
using namespace std;

int main()
{
    string s;
    cin >> s;
    int n = s.size();

    string ans;
    for(int i=0; i<n; ++i){
        if(s[i] == 'B'){
            if(!ans.empty())
                ans.resize(ans.size() - 1);
        }
        else{
            ans += s[i];
        }
    }
    cout << ans << endl;

    return 0;
}

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

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

int R, C, N, M, K, Q;

vector<int> v[200005];
vector<int> res;

void dfs(int node, int p = 0){
    for(int i:v[node]){
        if(i == p) continue;
        res[i] += res[node];
        dfs(i, node);
    }
    return;
}

signed main() {
    //cout << fixed << setprecision(10);
    cin >> N >> Q;

    rep(i, N-1){
        int from,to; cin >> from >> to;
        from --;
        to --;
        v[from].emplace_back(to);
        v[to].emplace_back(from);
    }
    res.assign(N,0); 
    rep(i,Q){
        int node, val; cin >> node >> val;
        res[--node] += val;
    }
    dfs(0);

    rep(i, N){
        cout << res[i] << " ";
    }
    cout << endl;

    //cout << max << endl;
}


Measured memory_bytes: 23424
import sys
from bisect import bisect_right
from math import ceil
def input(): return sys.stdin.readline().strip()

class BIT:

    """
    https://tjkendev.github.io/procon-library/python/range_query/bit.html
    Binary index treeの実装
    1-indexedの配列[a1, a2,...,an]に対して以下のクエリをO(logn)で行う:
        1. aiにxを加える
        2. 区間和 ai + a(i+1) + ... + aj の和を求める
    isom法を使えば、
        1. aiの値を取得する
        2. 区間[i, j]の全ての数にxを加算する
    もO(logN)で行うことができる
    """

    def __init__(self, n):
        """
        添字は1スタート
        """
        self.n = n
        self.data = [0] * (n + 1)
        self.el = [0] * (n + 1)

    def add(self, i, x):
        """
        i>0に対してaiにxを加算(x < 0でもOK)
        """
        if i <= 0 or self.n < i:
            raise ValueError("i should be within 1 to n")
        else:
            self.el[i] += x
            while i <= self.n:
                self.data[i] += x
                i += i & -i

    def sum(self, i):
        """
        添字1からiまでの累積和を求める
        """
        s = 0
        while i > 0:
            s += self.data[i]
            i -= i & -i # i $ (-i)でiの最下位ビットのみ立った値を得る
        return s

    def get(self, i, j=None):
        """
        添字iからjまでの累積和を求める
        j=Noneの場合はaiの値を返す
        """
        if j is None:
            return self.el[i]
        return self.sum(j) - self.sum(i - 1)


def main():
    """
    区間の種類数を答える問題は典型みたい。
    https://hama-du-competitive.hatenablog.com/entry/2016/10/01/001418
    ポイントはクエリをrの昇順に整理しておくこと。
    玉の各種類ごとに、それが最後にどこで出現したかをBITに記録していく。
    """
    N, Q = map(int, input().split())
    C = [0] + list(map(int, input().split()))
    queri = []
    for q in range(Q):
        l, r = map(int, input().split())
        queri.append(r * 10**12 + l * 10**6 + q)
    queri.sort()
    # print("queri={}".format(queri))

    lastAppeared = [0] * (N + 1)  # lastAppeared[x] : 値 x が最後に出現した位置
    r0 = queri[0] // 10**12
    for i, c in enumerate(C):
        if i == 0: continue
        if i > r0: break
        lastAppeared[c] = i
    tree = BIT(N)
    for x in range(1, N + 1):
        if lastAppeared[x] != 0:
            tree.add(lastAppeared[x], 1)

    ans = [0] * Q
    pre_R = r0
    for x in queri:
        r, x = x // 10**12, x % 10**12
        l, q = x // 10**6, x % 10**6
        if r > pre_R:
            for i in range(pre_R + 1, r + 1):
                if lastAppeared[C[i]] != 0:
                    tree.add(lastAppeared[C[i]], -1)
                lastAppeared[C[i]] = i
                tree.add(i, 1)
        ans[q] = tree.get(l, r)
        pre_R = r
        # print("q={}, lastAppeared={}, ans={}".format(q, lastAppeared, ans[q]))

    for a in ans: print(a)

if __name__ == "__main__":
    main()


Measured memory_bytes: 174400
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,n,s) for(int i = s; i < (n); ++i)
#define rsrep(i,n,s) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<x<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define out_ary(...) { for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef vector<int> vint;
typedef vector<float> vfloat;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vstr> vvstr;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;


int main() {
    int n;
    cin >> n;
    vint p(n);
    rep(i, n) cin >> p[i];
    int ans = 0;
    rep(i, n-2) if ((p[i+1] > p[i]) != (p[i+1] > p[i+2])) ans++;
    cout << ans << endl;
    return 0;
}

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

using namespace std;

void chmax(int *a, int *b){
    if(a<b)a=b;
}

void chmin(int *a, int *b){
    if(a>b)a=b;
}

int main() {
    int n;
    cin >> n;
    int h[n];
    int c[n];
    
    int k;
    cin >> k;
    
    for(int i=0; i<n; i++){
        int l;
        cin >> l;
        h[i]=l;
    }
    
    for(int i=2; i<n; i++)c[i] = INT_MAX;
    c[0]=0;
    c[1]=abs(h[1]-h[0]);  
    
    for(int i=0; i<n; i++){
        for(int j=1; j<=k&&i+j<n; j++){
            c[i+j]=min(c[i+j], c[i]+abs(h[i+j]-h[i]));
        }
    }
    
    cout << c[n-1] << endl;
    
    return 0;
}

Measured memory_bytes: 1024
/*  TAHMID RAHMAN
    DAMIAN FOREVER
     MATH LOVER
    NEVER GIVE UP
*/
#include<bits/stdc++.h>
using namespace std;
#define pi acos(-1.0)
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define pb push_back
#define fi first
#define se second
#define in insert
#define mp make_pair
#define GCD(a,b) __gcd(a,b);
#define endl "\n"
#define FRU freopen("out.txt","w",stdout)
#define FRO freopen("in.txt","r",stdin)
#define INFLL 9223372036854775807
#define debug 0
#define MAXN   100001
#define ar array
const int mxN=2e5;
const int MOD=1e9+7;
bool sortbysec(const pair<int,int> &a,const pair<int,int> &b){return (a.second < b.second);}
//Don't hesitate to ask me if you don't understand my code.......Happy coding,Tahmid...;
int main()
{

    ll n,i;
    cin>>n;
    vector<ll>v(n);
    for(i=0;i<n;i++)
    {
        cin>>v[i];
    }
    set<ll>s;
    vector<ll>a(v.begin(),v.end());
    sort(a.begin(),a.end());
    for(i=0;i<n;i++)
    {
        if(a[i]!=v[i])
        {
            s.in(a[i]);
            s.in(v[i]);
        }
    }
    if(s.size()==0||s.size()==2)
    {
        cout<<"YES"<<endl;
    }
    else
        cout<<"NO"<<endl;

}


Measured memory_bytes: 3640
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <array>
#include <iomanip>
#include <iostream>
#include <limits>
#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 loop(i, a, n) for (int i = a; i < (n); i++)
#define all(in) in.begin(), in.end()
const int INF = 1e9;
const int MOD = 1e9 + 7;
int main() {
    int N;
    cin >> N;
    int L[N];
    rep(i, N) cin >> L[i];
    sort(L, L + N, greater<int>());
    int sum = 0;
    loop(i, 1, N) sum += L[i];
    if (L[0] < sum) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
while True:
    try:
        n = int(input())
        N = list(map(int, input().split()))
        swap = 0
        for i in range(len(N)):
            if N[i] != i+1:
                N[N.index(i+1)] = N[i]
                N[i] = i+1
                swap += 1
                if swap > 1:
                    print("NO")
                    break
        else:
            print("YES")
            
    except:
        break

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

int main() {
  int n;
  cin >> n;
  vector<ll> res(5, 0);
  rep(i,n){
    string s;
    cin >> s;
    if(s[0] == 'M') res[0]++;
    if(s[0] == 'A') res[1]++;
    if(s[0] == 'R') res[2]++;
    if(s[0] == 'C') res[3]++;
    if(s[0] == 'H') res[4]++;
  }
  ll ans = 0;
  for (int i = 0; i < 5; i++){
    for (int j = i + 1; j < 5; j++){
      for (int k = j + 1; k < 5; k++){
        ans += res[i] * res[j] * res[k];
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main()
{
    string s;
    cin >> s;
    string array[] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
    
    for (int i = 0; i < sizeof(array) / sizeof(array[0]); i++) {
        if (s.compare(array[i]) == 0) {
            cout << 7 - i << endl;
            break;
        }
    }


    return 0;
}


Measured memory_bytes: 256
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			BigDecimal t = BigDecimal.valueOf(scanner.nextLong());
			BigDecimal x = BigDecimal.valueOf(scanner.nextLong());
			System.out.println(t.divide(x, 10, RoundingMode.HALF_UP));
		}
	}
}


Measured memory_bytes: 35772
N = int(input())
Attendees = list(map(int, input().split()))
Groups = [[0,0] for _ in range(N)]
for pos, number in enumerate(Attendees):
    if pos - number >= 0:
        Groups[pos - number][0] += 1

    if pos + number < N:
        Groups[pos + number][1] += 1

ans = 0
for elt in Groups:
    ans += elt[0] * elt[1]
print(ans)


Measured memory_bytes: 34224
#include <iostream>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); i++)
int main() {
	int n, m, k;
	cin >> n >> m;
	REP(i, n) { cin >> k; }
	cout<<(n + m - 3) / (m - 1);
	return 0;
}


Measured memory_bytes: 256
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx")
//#pragma GCC optimize ("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define fi first
#define se second
#define pb push_back
#define sz(x)  ((int)x.size ())
#define all(x) (x).begin(), (x).end()
#define re return
#define mp make_pair
#define sqrt(x) sqrt (abs(x))
#define y0 y3451
#define y1 y4562
#define j0 j25624
#define j1 j45624
#define makeunique(x) sort(all(x)), (x).resize (unique(all(x)) - (x).begin())

typedef pair <int, int> ii;
typedef long long ll;
typedef unsigned long long ull;
typedef double D;
typedef long double ld;
typedef unsigned int uint;
typedef vector <string> vs;
typedef vector <int> vi;
typedef vector <ii> vii;
typedef vector <vi> vvi;

template <class T> using _tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <class T> T abs (T x) { re x > 0 ? x : -x; }
template <class T> T sqr (T x) { re x * x; }
template <class T> T gcd (T a, T b) { re a ? gcd (b % a, a) : b; }
template <class T> int sgn (T x) { re x > 0 ? 1 : (x < 0 ? -1 : 0); }

#define filename ""

const D pi = acos(-1.);
const int N = 4e5 + 20;
const int mod = 1e9 + 7;
const int inf = 2e9 + 7;

int n, m;
ll a[100][100];
ll x[100][100]; 
ll ans[100][100]; 
ll k;



int main() {
	cin >> n >> k;
	for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++)
			scanf("%I64d", &a[i][j]);
	for (int i = 0; i < n; i++)
		ans[i][i] = 1;
	while (k) {
		if (k & 1) {
			for (int i = 0; i < n; i++)
				for (int j = 0; j < n; j++) {
					int an = 0;
					for (int k = 0; k < n; k++)
						an = (an + ans[i][k] * a[k][j] % mod) % mod;
					x[i][j] = an;
				}
			for (int i = 0; i < n; i++)
				for (int j = 0; j < n; j++) 
					ans[i][j] = x[i][j];
		}
		for (int i = 0; i < n; i++)
			for (int j = 0; j < n; j++) {
				int an = 0;
				for (int k = 0; k < n; k++)
					an = (an + a[i][k] * a[k][j] % mod) % mod;
				x[i][j] = an;
		}
		for (int i = 0; i < n; i++)
			for (int j = 0; j < n; j++) 
				a[i][j] = x[i][j];
	 	k /= 2;
	}
	ll res = 0;
	for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++)
			res = (res + ans[i][j]) % mod;
	cout << res << endl;
}

Measured memory_bytes: 384
using System;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        int[] lines = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();

        Console.WriteLine((lines[0] < lines[1] && lines[1] < lines[2]) ? "Yes" : "No");
    }
}

Measured memory_bytes: 9348
a, b = map(str,input().split())
c = a + b
d = int(c)

i = 0

while i < 318:
  e = i * i
  if e == d:
    print("Yes"),
    i = 318
  else:
    if e > d:
      print("No")
      i = 318
    else:
      i = i +1

Measured memory_bytes: 3060
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#define ll long long int
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
int mx4[] = {0,1,0,-1};
int my4[] = {1,0,-1,0};


//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


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

    for(int i=n-1;i > n/2 - 1;i--){
        if(a[i] == 0) b[i] = 0;
        else b[i] = 1;
    }
    for(int i=n/2-1;i>-1;i--){
        int I = i + 1,check = 0;
        while(I + i + 1 <= n){
            I += i+1;
            check += b[I-1];
        }
        if(check % 2 == 1 && a[i] == 0) b[i] = 1;
        else if(check % 2 == 0 && a[i] == 1) b[i] = 1;
    }

    int ans = 0;
    rep(i,n){
        if(b[i] == 1) ans++;
    }
    cout << ans << endl;
    rep(i,n){
        if(b[i] == 1){
            cout << i+1 << " ";
        }
    }
}

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

int main(){
	int n;
	cin>>n;
	if(n==0){
		cout<<0<<endl;
		return 0;
	}
	string s="";
	int i=0;
	while(n!=0){
		if(n%2!=0){
			s+='1';
			if(i%2==0){
				n--;
			}
			else if(i%2!=0){
				n++;
			}
		}
		else if(n%2==0){
			s+='0';
		}
		n=n/2;
		i++;
	}
	reverse(s.begin(),s.end());
	cout<<s<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){

  int h, w;
  int i, j;

  while(1){
    scanf("%d %d", &h, &w);
    if(w == 0 && h == 0)
      break;

    for(i = 0; i < h; i++){
      for(j = 0; j < w; j++){
	if(i % 2 == 0 && j % 2 == 0)
	  printf("#");
	else if (i % 2 == 0 && j % 2 == 1)
	  printf(".");
	else if(i % 2 == 1 && j % 2 == 0)
	  printf(".");
	else
	  printf("#");
      }
      printf("\n");
    }
    printf("\n");
  }

  return 0;
}

Measured memory_bytes: 572
using System;
using System.Collections.Generic;
using System.Linq;
using AOJ;

namespace AOJ
{
  static class Problem0038
  {
    public static void Main(string[] args)
    {
      foreach (var s in ReadInput()
          .Select(s => s.Split(','))
          .Select(arr => arr.Select(int.Parse))
          .Select(x => x.ToArray())
          .Select(Judge))
      {
        Console.WriteLine(s);
      }
    }

    static IEnumerable<string> ReadInput()
    {
      string s;
      while ((s = Console.ReadLine()) != null)
        yield return s;
    }

    static string Judge(int[] hand)
    {
      var work = Enumerable.Repeat(0, 14).ToArray();
      foreach (var x in hand)
      {
        if (x == 1)
        {
          ++work[0];
          ++work[13];
        }
        else
        {
          ++work[x - 1];
        }
      }
      if (work.Any(x => x == 4))
        return "four card";
      if (work.Any(x => x == 3) && work.Any(x => x == 2))
        return "full house";
      foreach (var arr in work.EachCons(5))
        if (arr.All(x => x == 1))
          return "straight";
      work[13] = 0;
      if (work.Any(x => x == 3))
        return "three card";
      if (work.Count(x => x == 2) == 2)
        return "two pair";
      if (work.Any(x => x == 2))
        return "one pair";
      return "null";
    }
  }

  public static class EnumerableEx
  {
    public static IEnumerable<IEnumerable<T>> EachCons<T>(this IEnumerable<T> source, int count)
    {
      foreach (var i in Enumerable.Range(0, source.Count() - count + 1))
        yield return source.Skip(i).Take(count);
    }
  }
}

Measured memory_bytes: 5848
#include <stdio.h>

int main(){
  int b,c,plus,minus,multi;

  scanf("%d %d\n", &b,&c);

plus = b+c;
minus = b-c;
multi = b * c;

if(plus > minus && plus > multi){
      printf("%d\n", plus);
} else if(minus > plus && minus > multi){
      printf("%d\n", minus);
}else if(multi > plus && multi > minus){
      printf("%d\n", multi);
} else{
  printf("%d\n", plus);
}

return 0;
}


Measured memory_bytes: 128
#coding:utf-8
def main():
    N,C=map(int,raw_input().split())
    D=[None]
    for _ in range(C):
        D.append([None]+map(int,raw_input().split()))
    c=[]
    for _ in range(N):
        c.append(map(int,raw_input().split()))
    # F[C][mod]
    F=[[0,0,0] for _ in range(31)]
    # m[mod] = [c[mod]]
    m=[[] for i in range(3)]
    for i in range(N):
        for j in range(N):
            m[(i+j)%3].append(c[i][j])

    for mod in range(3):
        for color in range(1,C+1):
            val=0
            for mm in m[mod]:
                F[color][mod]+=D[mm][color]

    ans=1145141919810
    if N==1:
        print(0)
        return
    for c0 in range(1,C+1):
        for c1 in range(1,C+1):
            for c2 in range(1,C+1):
                if c0==c1 or c1==c2 or c2==c0:continue  
                ans=min(ans,F[c0][0]+F[c1][1]+F[c2][2])
    print(ans)





main()






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

#define for_(i,a,b) for(int i=(a);i<(b);++i)

int n, m, imos[20][100005], cnt[20], dp[1 << 20];

int main() {
	cin >> n >> m;
	
	memset(imos, 0, sizeof(imos));
	memset(cnt, 0, sizeof(cnt));
	
	for_(i,0,n) {
		int x; cin >> x; --x;
		imos[x][i+1] = 1;
		++cnt[x];
	}
	
	for_(i,0,m) for_(j,0,n) imos[i][j+1] += imos[i][j];
	
	memset(dp, -1, sizeof(dp));
	dp[0] = 0;
	
	for_(S,0,1<<m) {
		if (dp[S] == -1) continue;
		
		int len = 0;
		for_(i,0,m) len += cnt[i] * (S >> i & 1);
		
		for_(i,0,m) {
			if (S >> i & 1) continue;
			int no_move = imos[i][len + cnt[i]] - imos[i][len];
			int nS = S | (1 << i);
			if (dp[nS] == -1) dp[nS] = 1e9;
			dp[nS] = min(dp[nS], dp[S] + cnt[i] - no_move);
		}
	}
	
	cout << dp[(1 << m) - 1] << endl;
}

Measured memory_bytes: 15016
#include<stdio.h>

int main(void)
{
  int N,i;
  double sum=0;

  scanf("%d",&N);
  double x[N];
  char u[N][4];
  for(i=0;i<N;i++){
    scanf("%lf %s",&x[i],u[i]);
    if(u[i][0]=='B')
      x[i]=x[i]*380000;
    sum=sum+x[i];
  }

  printf("%f",sum);

  return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

typedef struct
{
	int k, v[100];
	int visited;
} Node;

int queue_head = 0;
int queue_tail = 0;
int queue_data[100];

void queue_push(int x)
{
	queue_data[queue_tail++] = x;
	queue_tail %= 100;
}

int queue_pop(void)
{
	int x = queue_data[queue_head++];
	queue_head %= 100;
	return x;
}

int queue_empty(void)
{
	return queue_head == queue_tail;
}

void bfs(Node *node, int u)
{
	queue_push(u);
	node[u].visited = 0;
	
	while(!queue_empty())
	{
		int x = queue_pop();
		for(int i = 0; i < node[x].k; ++i)
		{
			int v = node[x].v[i];
			if(node[v].visited == -1)
			{
				queue_push(v);
				node[v].visited = node[x].visited + 1;
			}
		}
	}
}

int main()
{
	int n, u;
	Node node[100];
	
	scanf("%d", &n);
	for(int i = 0; i < n; ++i)
	{
		scanf("%d", &u);
		--u;
		
		scanf("%d", &node[u].k);
		for(int j = 0; j < node[u].k; ++j)
		{
			scanf("%d", &node[u].v[j]);
			--node[u].v[j];
		}
		node[u].visited = -1;
	}
	
	bfs(node, 0);
	
	for(int i = 0; i < n; ++i)
	{
		printf("%d %d\n", i+1, node[i].visited);
	}
}



Measured memory_bytes: 2068
#include<iostream>
#include<algorithm>
#include<iomanip>
using namespace std;
int n, v[55];
int main()
{
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> v[i];
	sort(v, v + n);
	int p = 1;
	long double ans = 0;
	for (int i = n - 1; i > 1; i--)
	{
		ans += v[i] * 1.0 / (1ll << p);
		p++;
	}
	ans += (v[0] + v[1]) * 1.0 / (1ll << p);
	cout << fixed << setprecision(10) << ans << endl;
	return 0;
}

Measured memory_bytes: 384
c=[]

S=0
for i in range(3):
    c.append(list(map(int,input().split())))
    S+=sum(c[i])

a=[0]*3
b=[0]*3
for i in range(3):
    a[i]=sum(c[i][0:3])
    b[i]=sum(c[0:3][i])

if S%3!=0:
    ans="No"
if (a[0]-a[1])%3!=0 or (a[1]-a[2])%3!=0 or (a[2]-a[0])%3!=0:
    ans="No"
elif (b[0]-b[1])%3!=0 or (b[1]-b[2])%3!=0 or (b[2]-b[0])%3!=0:
    ans="No"
elif c[0][0]+c[1][1]+c[2][2]!=S//3:
    ans="No"
else:
    ans="Yes"
print(ans)

Measured memory_bytes: 3064
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    long ans = 1;
    for(int i = 0; i < n; i++) {
      long a = sc.nextLong();
      if(a == 0) {
        ans = 0;
      } else {
        if(ans <= ((long)Math.pow(10, 18) / a)) {
          if(ans >= 0) ans *= a;
        } else {
          ans = -1;
        }
      }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 58496
import java.util.*;
public class Main{

public static void main(String[] args){
Scanner obj=new Scanner(System.in);

int n=obj.nextInt();
int[] x=new int[n];
int[] count=new int[n];
int j=0;
x[0]=obj.nextInt();


for(int i=1;i<x.length;i++){
x[i]=obj.nextInt();

if(x[i-1]>=x[i]){
count[j]++;
}
else{
j++;
}

}
Arrays.sort(count);
System.out.println(count[count.length-1]);





}



}

Measured memory_bytes: 50808
NAB = map(int, raw_input().split())
N = NAB[0]
A = NAB[1]
B = NAB[2]
S = raw_input()
passed_student = 0
foreign_student_rank = 0

for n in range(0, N):
    if(S[n] == 'a'):
        if(A+B > passed_student):
            print 'Yes'
            passed_student = passed_student + 1
        else:
            print 'No'
    elif(S[n] == 'b'):
        foreign_student_rank = foreign_student_rank + 1
        if(A+B > passed_student):
            if(foreign_student_rank <= B):
                print 'Yes'
                passed_student = passed_student + 1
            else:
                print 'No'
        else:
            print 'No'
    else:
        print 'No'
            
               


Measured memory_bytes: 6276
#include<cstdio>
#include<cstring>

char *pp;

int minus(int x) {
    return 2-x;
}

int myand(int x, int y) {
    if(x*y == 0)
        return 0;
    else if((--x)*(--y) == 0)
        return 1;
    return 2;
}

int myor(int x, int y) {
    if((x-2)*(y-2) == 0)
        return 2;
    return x|y;
}

int formula(void) {
    switch(*pp) {
        case '0':
        case '1':
        case '2':
            return *(pp++)-'0';
        case 'P':
        case 'Q':
        case 'R':
            // error
            return -999;
        case '-':
            pp++;
            return minus(formula());
        case '(':
            int res1, res2;
            int(*op)(int,int);
            pp++;
            res1 = formula();
            op = *pp++ == '*' ? myand : myor;
            res2 = formula();
            pp++;
            return op(res1,res2);
        default:
            // error
            return -999;
    }
}

int main(void) {
    while(1) {
        char s[100];
        scanf("%s",s);
        if(s[0] == '.') break;

        int res=0;
        for(int p=0; p<=2; p++)
            for(int q=0; q<=2; q++)
                for(int r=0; r<=2; r++) {
                    char buf[100];
                    strcpy(buf, s);
                    for(char *pb=buf; *pb; pb++) {
                        switch(*pb) {
                            case 'P':
                                *pb = '0' + p;
                                break;
                            case 'Q':
                                *pb = '0' + q;
                                break;
                            case 'R':
                                *pb = '0' + r;
                                break;
                        }
                    }
                    pp=buf;
                    res += formula() == 2;
                }
        printf("%d\n",res);
    }
    return 0;
}

Measured memory_bytes: 2576
#include <iostream>

using namespace std;

int main(){
  int n;
  string s;
  std::cin >> n >> s;

  int red_count = 0;
  for(int idx = 0; idx < s.size(); idx++){
    if(s[idx] == 'R') red_count += 1;
  }

  if(red_count > n - red_count){
    std::cout << "Yes" << '\n';
  }else{
    std::cout << "No" << '\n';
  }
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <vector>
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;

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

// 入出力
void print() { std::cout << '\n'; }
template <class T>void print(const T &x) {std::cout << x <<'\n';}
template <class T, class... Args>void print(const T &x, const Args &... args) {std::cout << x << " ";print(args...);}

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

    long long N;
    cin >> N;

    std::vector<std::string> s(N);
    REP(i, N) std::cin >> s[i];

    long long M;
    cin >> M;

    std::vector<std::string> t(M);
    REP(i, M) std::cin >> t[i];

    map<string, ll> ans;
    REP(i, N) ans.insert(make_pair(s[i], 0));
    REP(i, M) ans.insert(make_pair(t[i], 0));
    REP(i, N) ans[s[i]]++;
    REP(i, M) ans[t[i]]--;

    ll maxi = 0;
    for (auto i : ans)
        chmax(maxi, i.second);

    print(maxi);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long;
int main(){
  int n,d,x,a,sum=0;
  cin>>n>>d>>x;
  for(int i=0;i<n;i++){
    cin>>a;
    sum+=(d-1)/a;
  }
  cout<<sum+x+n<<endl;
  return 0;
}


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



int main(){
    int N, K;
    cin >> N >> K;
    vector<int> A(N), B(N+1);
    vector<pair<int, int> > C(N+1);
    for(int i=0; i<N; i++){
        cin >> A[i];
        B[A[i]]++;
    }
    int cnt=0;
    for(auto itr=B.begin(); itr!=B.end(); itr++){
        C[cnt].second=cnt;
        C[cnt].first=*itr;
        //cout << C[cnt].first <<" "<< C[cnt].second << endl;
        cnt++;
    }
    cnt=0;
    
    sort(C.begin(),C.end());
    for(int i=0; i<=N; i++){
        if(C[i].first>0) cnt++;
    }
    //cout << cnt << endl;
    if(cnt<=K){
        cout << 0 << endl;
        return 0;
    }
    
    int c=0, n=0;
    for(int i=0; i<=N; i++){
        if(C[i].first>0){
            c++;
            n += C[i].first;
        }
        if(c==cnt-K){
            break;
        }
    }
    cout << n << endl;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#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 pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#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<int>(n,a)));
typedef long long ll;
const int INF = 2000000000;
const long INF64 = 1000000000000000ll;
const ll MOD = 1000000007LL;
int main(){
    int x,a;
    std::cin >> x>>a;
    if(x<a)std::cout << 0 << std::endl;
    else std::cout << 10 << std::endl;
}

Measured memory_bytes: 256
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <iostream>
#include <vector>
#include <algorithm>
#include <limits>
#include <utility>
#include <string>
#include <queue>
#include <cmath>
#include <array>

template<typename T>
class UnionFind
{
    private:
        std::vector<T> parent;
    public:
        UnionFind(const T n): parent(n)
        {
            for (T i = 0; i < n; i++) {parent[i] = i;}
        }
        T root(const T x)
        {
            if (parent[x] != x) {parent[x] = root(parent[x]);}
            return parent[x];
        }
        void unite(const T x, const T y)
        {
            const auto rx = root(x);
            const auto ry = root(y);
            parent[ry] = rx;
        }
        bool isSameRoot(const T x, const T y)
        {
            const auto rx = root(x);
            const auto ry = root(y);
            return rx == ry;
        }
};

int main(int argc, char *argv[])
{
    int n, m;
    std::cin >> n >> m;

    UnionFind<int> tree(n);

    for (int i = 0; i < m; i++) {
        int a, b;
        std::cin >> a >> b;
        a--;
        b--;
        tree.unite(a, b);
    }

    std::vector<int> count(n, 0);
    for (int i = 0; i < n; i++) {
        count[tree.root(i)]++;
    }

    int max = 0;
    for (int i = 0; i < n; i++) {
        max = std::max(max, count[i]);
    }

    std::cout << max << std::endl;

    return 0;
}


Measured memory_bytes: 4996
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int, int>;

int main()
{
    int a, b;
    cin >> a >> b;
    cout << a * b << endl;
    return 0;
}

Measured memory_bytes: 3632