akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#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 <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <iomanip>
#include <cassert>

using namespace std;
typedef long long ll;

int main(){
   ll N,D;
   cin >> N >> D;
   int ans =0;
   for(int i = 0 ; i<N;i++){
      ll x,y;
      cin >> x >> y;
      if(x*x+y*y <= D*D) ans++;
   }
   cout << ans << endl;
   return 0;
}


Measured memory_bytes: 3628
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<random>
#include<stack>
#include<queue>
#include<bitset>
#include<sstream>

using namespace std;
using ll = long long;

vector<pair<int,int>> ab;
vector<vector<int>> dp;

int main(int argc, const char *argv[]){
    int n, m;
    cin >> n >> m;
    
    for(int i=0;i<n;i++){
        int _a,_b;
        cin >> _a >> _b;
        ab.push_back(pair<int,int>(_a,_b));
    }

    sort(ab.begin(),ab.end());
    priority_queue<int, vector<int>> que;
    ll ans=0;
    int k=0;
    for(int i=0;i<(m+1);i++){
        for(int j=k;j<n;j++){
            if(ab[j].first>i){
                break;
            }
            que.push(ab[j].second);
            k=j+1;
        }
        if(que.size()>0){
            ans += que.top();
            que.pop();
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1908
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstdio>
using namespace std;

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


}



Measured memory_bytes: 256
N, M, L = map(int, input().split())
INF = 1001001001

class Graph():
    def __init__(self, N):
        self.graph = [[INF for _ in range(N)] for _ in range(N)]
        for i in range(N):
            self.graph[i][i] = 0

    def add_path(self, a, b, c):
        self.graph[a][b] = c
        self.graph[b][a] = c

    def get(self, a, b):
        return self.graph[a][b]

    def warshall_floyd(self):
        N = len(self.graph)
        for k in range(N):
            for i in range(N):
                for j in range(N):
                    self.graph[i][j] = min(self.graph[i][j], self.graph[i][k]+self.graph[k][j])

path = Graph(N)
for _ in range(M):
    A, B, C = map(int, input().split())
    path.add_path(A-1, B-1, C)
path.warshall_floyd()
aid = Graph(N)
for i in range(N):
    for j in range(i+1, N):
        if path.get(i, j) <= L:
            aid.add_path(i, j, 1)
aid.warshall_floyd()
Q = int(input())
for _ in range(Q):
    s, t = map(int, input().split())
    ans = aid.get(s-1, t-1)
    if ans == INF:
        print(-1)
    else:
        print(ans-1)

Measured memory_bytes: 60632
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner scan=new Scanner(System.in);
int i=1;
while(true){
int x=scan.nextInt();
if(x==0){break;}
else{
System.out.println("Case" + " " + i + ":" + " " + x );
i=i+1;
}}}}

Measured memory_bytes: 42344
use proconio::{fastout, input};
use proconio::marker::Chars;

#[fastout]
fn main() {
    input! {
        n: usize,
        c: Chars,
    }

    let mut left = 0;
    let mut right = n-1;
    let mut ans = 0;

    while left < right {

        while c[left] == 'R'  {
            if left == n-1 {
                break;
            }
            left += 1;
        }

        while c[right] == 'W' {
            if right == 0 {
                break;
            }
            right -= 1;
        }
    
        if left >= right {
            break;
        } else {
            ans += 1;
            left += 1;
            right -= 1;
        }
    }

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


Measured memory_bytes: 3024
#include <iostream>
#include <cstdio>
#include <map>

using namespace std;

int main(){
	int score, number;
	map<int, int> data;
	map<int, int> rank;
	map<int, int> group;
	map<int, int>::iterator itr0;
	map<int, int>::iterator itr1;

	int user_input;

	while(scanf("%d,%d", &number, &score), number+score){
		data.insert( make_pair(number, score) );
		rank.insert( make_pair(number, 1) );

		if( group.find(score) != group.end() ) group[score] += 1;
		else group.insert( make_pair(score, 1) );
	}

	for (itr0 = data.begin(); itr0 != data.end(); itr0++){
		for(itr1 = group.begin(); itr1 != group.end(); itr1++){
			if(itr0->second < itr1->first) rank[itr0->first] += 1;
		}
	}

	while(cin>>user_input, !cin.eof() || user_input==0){
		cout<<rank[user_input]<<endl;
	}

	return 0;
}

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


int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	long long h, w; cin >> h >> w;
	if(h == 1 || w == 1){
		cout << 1 << endl;
	}else{
		cout << (h*w)/2 + (h*w)%2 << endl;
	}
	
	return 0;
}


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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rep2(i, l, r) for (int i = (l); i < (r); i++)
#define rep2r(i, l, r) for (int i = (r) - 1; i >= (l); i--)
#define range(a) a.begin(), a.end()

using namespace std;
using ll = long long;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  int N; cin >> N;
  vector<int> A(N); rep(i, N) cin >> A[i], A[i]--;
  vector<int> cnt(N);
  rep(i, N) cnt[A[i]]++;
  vector<ll> less0(N + 1), less1(N + 1);
  rep(i, N) {
    less0[cnt[i]]++;
    less1[cnt[i]] += cnt[i];
  }
  for (int i = 1; i <= N; i++) {
    less0[i] += less0[i - 1];
    less1[i] += less1[i - 1];
  }
  vector<ll> less(N + 1);
  rep(i, N) less[cnt[i]] += cnt[i];
  for (int K = 1; K <= N; K++) {
    int l = 0;
    int r = N + 1;
    while (r - l > 1) {
      int c = (l + r) / 2;
      ll sum = less1[c - 1] + (N - less0[c - 1]) * c;
      /*
      rep(i, N) sum += min(c, cnt[i]);
      */
      if (sum >= (ll)K * c) l = c; else r = c;
    }
    cout << l << '\n';
  }
}


Measured memory_bytes: 10240
#include "bits/stdc++.h"
#define _USE_MATH_DEFINES
#include <math.h>
 
using namespace std;
 
using LL = long long;
using VLL = std::vector<LL>;
using VVLL = std::vector<VLL>;
using VVVLL = std::vector<VVLL>;
using LD = long double;
using VLD = std::vector<LD>;
using VVLD = std::vector<VLD>;
using VVVLD = std::vector<VVLD>;
 
template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; }return false; }

#define REP(i,n) for(LL (i)=0;(i)<(n);(i)++)
#define ALL(v) v.begin(), v.end()
#define PRINTLN(v) {LL i=0; for(auto (a): v ){   cerr <<i << " : "<<  a << endl; i++;}}
#define PRINTSP(v) for(auto (a): v ) {cerr << a << " ";} cerr << endl
#define cmax(a,b) {if(a<b){a=b;}}
#define cmin(a,b) {if(a>b){a=b;}}
#define EACH(a,A) for(auto a: A)
//#define cmax(a,b) a = (a>b ? a:b)
//#define cmin(a,b) a = (a<b ? a:b) 



  
void func(){
  LL H,W;
  cin >> H >> W;
  LL SY, SX;
  LL GY, GX;

  SY=0;
  SX=0;
  GY=H-1;
  GX=W-1;

  VVLL C(H,VLL(W,-1));
  vector<string> M(H);
  REP(i,H){
    cin >>M[i];
  }

  LL x=SX;
  LL y=SY;
  queue<pair<LL,LL>> Q;
  Q.emplace(SY,SX);
  C[y][x]=0;
  while(! Q.empty()){
    auto q = Q.front();
    Q.pop();
    y = q.first;
    x = q.second;
    //PRINTSP(q);
    //cerr << y << " " << x << endl;
    if(y+1<H and M[y+1][x]=='.' and C[y+1][x]==-1){
      C[y+1][x] = C[y][x]+1;
      Q.emplace(y+1,x);
    }
    if(x+1<W and M[y][x+1]=='.' and C[y][x+1]==-1){
      C[y][x+1] = C[y][x]+1;
      Q.emplace(y,x+1);
    }
    if(y-1>=0 and M[y-1][x]=='.' and C[y-1][x]==-1){
      C[y-1][x] = C[y][x]+1;
      Q.emplace(y-1,x);
    }
    if(x-1>=0 and M[y][x-1]=='.' and C[y][x-1]==-1){
      C[y][x-1] = C[y][x]+1;
      Q.emplace(y,x-1);
    }
    EACH(a,C){
      //PRINTSP(a);
    }
    //cerr << endl;
  }  

  /*  
  x=GX;
  y=GY;
  while(not(x==0 and y==0)) {
    cerr << y << " " << x << endl;
    if(y+1<H and M[y+1][x]=='.' and C[y+1][x]==C[y][x]-1){
      y=y+1;
      continue;
    }
    if(x+1<W and M[y][x+1]=='.' and C[y][x+1]==C[y][x]-1){
      x=x+1;  
      continue;
    }
    if(y-1>=0 and M[y-1][x]=='.' and C[y-1][x]==C[y][x]-1){
      y=y-1;  
      continue;
    }
    if(x-1>=0 and M[y][x-1]=='.' and C[y][x-1]==C[y][x]-1){
      x=x-1;  
      continue;
    }
  }
  */
  EACH(a,C){
    //PRINTSP(a);
  }

  LL cnt=0;
  EACH(m , M){
    EACH(c, m ){
      if(c=='#'){
        cnt++;
      }
    }
  }
  if(C[GY][GX]==-1){
    cout << -1;
  }
  else{
    cout << H*W-2-cnt-C[GY][GX]+1;
}

  return;
}

 
int main()
{
  func();
  return 0;
}
 

Measured memory_bytes: 256
import java.util.*;

public class Main{
	
	//1135 start
	//1211 stop
	//1245 restart
	
	class Parse{
		int pos;
		String s;
		HashMap<String, HashMap<Integer, Integer>> heap;
		boolean flg;
		Parse(){
			heap = new HashMap<String, HashMap<Integer, Integer>>();
		}
		
		private boolean eval(String now) {
			s = new String(now + "#");
			pos = 0;
			flg = true;
			program();
			return flg;
		}

		private void program() {
			int res = s.indexOf('=');
			if(res == -1){
				declaration();
			}
			else{
				assignment();
			}
		}

		private void assignment() {
			String res = arrayname();
			if(! heap.containsKey(res)){
				flg = false;
				return ;
			}
			pos++;
			int res2 = exp();
			pos++;
			if(heap.get(res).get(-1) <= res2) flg = false;
			if(! flg) return;
			// = 
			//System.out.println(res + " " + flg + " " + s.charAt(pos));
			pos++;
			int res3 = exp();
			if(! flg) return;
			heap.get(res).put(res2, res3);
		}

		private int exp() {
			char c = s.charAt(pos);
			int num = -1;
			if(Character.isDigit(c)){
				num = number();
			}
			else{
				String arr = arrayname();
				if(! heap.containsKey(arr)){
					flg = false;
					return -1;
				}
				
				pos++;
				int res = exp();
				if(! flg) return -1;
				pos++;
				if(! heap.get(arr).containsKey(res)){
					flg = false;
					return -1;
				}
				num = heap.get(arr).get(res);
			}
			return num;
		}

		private void declaration() {
			String res = arrayname();
			pos++;
			int res2 = number();
			pos++;
			HashMap<Integer, Integer> nhm = new HashMap<Integer, Integer>();
			nhm.put(-1, res2);
			heap.put(res, nhm);
		}

		private int number() {
			StringBuilder sb = new StringBuilder();
			while(true){
				char c = s.charAt(pos);
				if(! Character.isDigit(c)) break;
				sb.append(c);
				pos++;
			}
			return Integer.parseInt(sb.toString());
		}

		private String arrayname() {
			StringBuilder sb = new StringBuilder();
			while(true){
				char c = s.charAt(pos);
				if(! Character.isLetter(c)) break;
				sb.append(c);
				pos++;
			}
			return sb.toString();
		}
	}
	
	private void doit(){
		Scanner sc = new Scanner(System.in);
		while(true){
			String s = sc.next();
			if(s.equals(".")) break;
			ArrayList<String> list  = new ArrayList<String>();
			list.add(s);
			while(true){
				String ss = sc.next();
				if(ss.equals(".")) break;
				list.add(ss);
			}
			
			int ans = 0;
			
			Parse p = new Parse();
			for(int i = 0; i < list.size(); i++){
				String now = list.get(i);
				boolean res = p.eval(now);
				if(! res){
					ans = i + 1;
					break;
				}
			}
			System.out.println(ans);
		}
	}
	
	public static void main(String[] args) {
		new Main().doit();
	}
}

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

int main(int argc, const char * argv[]) {
    int A, B, C;
    cin >> A;
    cin >> B;
    cin >> C;
    
    int sub = A - B;
    int ans = C - sub;
    if (ans < 0) {ans = 0;}
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 888
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i32 = int32_t;
using i64 = int64_t;
constexpr char newl = '\n';

template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
//#define F first
//#define S second
#define debug(x) cout << #x << ": " << x << '\n';

#if 1


constexpr i64 calc(i64 A, i64 B, i64 x) {
  return A * x / B - A * (x / B);
}

// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  i64 A, B, N;
  cin >> A >> B >> N;

  cout << calc(A, B, min(B - 1, N));// << newl;

  /*
  F0R(i, N + 1) {
    cout << calc(A, B, i) << ',';
  }
  */
}
#endif


Measured memory_bytes: 3692
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <tuple>

using namespace std;
typedef long long ll;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
const int INF = 1<<29;

vector<vector<int> > calcNext(const string &S) {
    int n = (int)S.size();
    vector<vector<int> > res(n+1, vector<int>(10, n));
    for (int i = n-1; i >= 0; --i) {
        for (int j = 0; j < 10; ++j) res[i][j] = res[i+1][j];
        res[i][S[i]-'0'] = i;
    }
    return res;
}

int main(){
ll n;
	cin >>n;
	ll ans=0;
	if(n%2!=0)
		cout <<ans<<endl;
	else
	{
		ll d=10;
		while(d<=n)
		{
			ans+=n/d;
			d*=5;
			//cout <<ans<<' ';
		}
		//cout <<endl;
		cout <<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 384
// ALDS1_9_B: Maximum Heap

use std::str::FromStr;

fn scan<T: FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().parse().ok().unwrap()
}

fn scan_vec<T: FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.split_whitespace().map(|a| T::from_str(a).ok().unwrap()).collect()
}

fn max_heapify(a: &mut Vec<i64>, h: usize, i: usize) {
    let l = 2 * i;
    let r = 2 * i + 1;
    let mut largest = i;

    if l <= h && a[l] > a[largest] {
        largest = l;
    }

    if r <= h && a[r] > a[largest] {
        largest = r;
    }

    if largest != i {
        a.swap(i, largest);
        max_heapify(a, h, largest);
    }
}

fn main() {
    let h = scan::<usize>();
    let cin = scan_vec::<i64>();
    let mut a = vec![0; h+1];

    for i in 1..h+1 {
        a[i] = cin[i - 1];
    }

    let mut i: usize = h / 2;
    while i >= 1 {
        max_heapify(&mut a, h, i);
        i -= 1;
    }

    for i in 1..h+1 {
        print!(" {}", a[i]);
    }
    println!();
}


Measured memory_bytes: 14160
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define len(a) (int)a.size()
#define all(a) (a.begin(),a.end())
#define fi first
#define sc second
#define ort(x,y) (x+y)/2
#define endl '\n'
#define FAST ios_base::sync_with_stdio(false);
#define d1(x) cerr<<#x<<":"<<x<<endl;
#define d2(x,y) cerr<<#x<<":"<<x<<" "<<#y<<":"<<y<<endl;
#define d3(x,y,z) cerr<<#x<<":"<<x<<" "<<#y<<":"<<y<<" "<<#z<<":"<<z<<endl;
#define lim (int) (1e5+5)
#define inf (int) (1e7)
#define heap priority_queue
#define mem(a,val) memset(a,val,sizeof(a))
#define y1 asdassa
typedef long long int lli;
typedef pair<int,int> pii;
typedef pair<pair<int,int>,int> piii;
char s[lim];
int l=1,r,ans;
int main()
{
	scanf("%s",s+1);
	r=strlen(s+1);
	while(l<=r)
	{
		if(s[l]==s[r]) {l++,r--; continue;}
		if(s[l]!='x' && s[r]!='x') return printf("-1"),0;
		if(s[l]=='x') l++;
		else r--;
		ans++;
	}
	printf("%d\n",ans);
}


Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

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

        int w = s.nextInt();
        int h = s.nextInt();
        int x = s.nextInt();
        int y = s.nextInt();
        int r = s.nextInt();

        String result;
        if((x >= w || y >= h || x <= 0 || y <= 0) || !(w - x >= r && h - y >=r)){
            result = "No";
        } else {
            result = "Yes";
        }

        System.out.println(result);
    }

}

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

int main(){
  int n,k;
  string s;
  cin>>n>>s>>k;
  char x=s[k-1];
  for(int i=0;i<n;i++){
    if(s[i]!=x){
      s[i]='*';
    }
  }
  cout<<s<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(), (x).end())
#define ALL(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < n; i++)
#define reps(i, m, n) for (int i = m; i < n; i++)
#define repr(i, m, n) for (int i = m; i >= n; i--)
#define db(x) cout << #x << "=" << x << endl;
template <class T>
bool maxi(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool mini(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
#define INF2 1000000000000000037
#define INF 1000000007
#define MOD 998244353
#define PI (acos(-1))
#define EPS 1e(-9);
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
//--GLOBAL---------------------------------

//--MAIN-----------------------------------
void Main() {
    ll N, M;
    cin >> N >> M;
    string S;
    cin >> S;
    reverse(S.begin(),S.end());
    vector<int> ans;
    int now = 0;

    while (now != N) {
        repr(i, M, 1) {
            if (now+i >N) continue;
            if (S[now + i] == '0') {
                ans.emplace_back(i);
                now += i;
                break;
            }
            if (i == 1) {
                cout << -1 << "\n";
                return;
            }
        }
    }
    reverse(ans.begin(),ans.end());
    rep(i,ans.size()){
        cout<< ans[i]<<" ";
    }
    cout<<"\n";
}

//--START----------------------------------
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}
//-----------------------------------------


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

	int main(){

	int m,n,s,i,f=0;
		cin>>s;
		vector<int> fn(1000000);
		fn.at(0)=s;
	for(i=1;f==0;i++){
		
		if(fn.at(i-1)%2==0)
			fn.at(i)=fn.at(i-1)/2;
			
		else if(fn.at(i-1)%2==1)
			fn.at(i)=fn.at(i-1)*3+1;
		
		for(m=0;m<i;m++){
			if(fn.at(i)==fn.at(m)){
				f=1;
				n=i+1;
				break;
			}
		}
	}
		cout<<n<<endl;
		
	}


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

int main(){
    long long n,a,b;  cin>>n>>a>>b;
    long long x;  cin>>x;
    
    long long ans=0;

    int y;
    for(int i=1;i<n;i++){
        cin>>y;
        if(a*(y-x)>b)ans+=b;
        else ans+=a*(y-x);

        x=y;

    }

    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
using namespace std;
///////////////////library zone!!!!!!!!!!!!!!!!!!!!!!!!!!!!
typedef long long ll;
typedef long double ld;
#define all(a) (a).begin(),(a).end()
const ll Mod = 1000000007;
struct P {
	ll pos, cost;
	bool operator<(const P &b) const { return cost < b.cost; }
	bool operator>(const P &b) const { return cost > b.cost; }
};
struct B {
	ll to, cost;
};
struct E {
	ll from, to, cost;
	bool operator<(const E &b) const { return cost < b.cost; }
	bool operator>(const E &b) const { return cost > b.cost; }
};
struct H {
	ll x, y;
	bool operator<(const H &b) const {
		if (x != b.x) return x < b.x;
		return y < b.y;
	}
	bool operator>(const H &b) const {
		if (x != b.x) return x > b.x;
		return y > b.y;
	}
	bool operator==(const H &b) const { return x == b.x&&y == b.y; }
	bool operator!=(const H &b) const { return (*this) != b; }
};
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j%i, i);
}
ll mod_pow(ll x, ll n, ll p = Mod) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}//x^n%p
const ll Inf = 3023372036854775807;
const int inf = 1500000000;
#define int long long
//----------------------------------------------------
int n, x;
int a[1000000];
int b[1000000];
signed main() {
	cin >> n >> x;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		b[i] = a[i] + (i > 0 ? b[i - 1] : 0);
	}
	unsigned int ans = 18446744073709551615;
	for (int i = 1; i <= n; i++) {
		unsigned int sum = x * i;
		int res = 3;
		sum += 5 * (b[n - 1] - (n - i - 1 < 0 ? 0 : b[n - i - 1]));
		for (int j = n - i - 1; j >= 0; j -= i) {
			sum += (res*res - (res - 1)*(res - 1))*(b[j] - (j - i < 0 ? 0 : b[j - i]));
			res++;
		}
		ans = min(ans, sum + n * x);
	}
	cout << ans << endl;
}

Measured memory_bytes: 5888
#include <bits/stdc++.h>
#include <cstdio>
#include <cstdlib>

#ifdef _MSC_VER
#include <Windows.h>
#else
#include <unistd.h>
#endif

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))


int cor[26];
int main(){
    string S;
    cin>>S;
    int N=SZ(S);
    //同じ文字同士の間隔
    CLR(cor);  
    REP(i,N){
        cor[S[i]-'a']++;
    }
    bool f=1;
    REP(i,26)if(cor[i]>=2)f=0;
    if(f){
        string res=N%2==1?"First":"Second";
        cout<<res<<endl;
        return 0;
    }
    int cnt=0;
    int p=0;
    bool flag1=1,flag2=1;
    while(p+2<N){
        if(S[p]!=S[p+2])flag1=0;
        p+=2;
    }
    if(p==0)flag1=0;
    p=1;
    while(p+2<N){
        if(S[p]!=S[p+2])flag2=0;
        p+=2;
    }
    if(p==1)flag2=0;
    if(flag1||flag2){
        cout<<"Second"<<endl;
        return 0;
    }
    if(S[0]==S[N-1]){
        string res=(N%2==1)?"Second":"First";
        cout<<res<<endl;
    }else{
        string res=(N%2==0)?"Second":"First";
        cout<<res<<endl;
    }
    return 0;
}


Measured memory_bytes: 640
fn main() {
  let scan = std::io::stdin();
  let mut a = String::new();
  let mut b = String::new();
  let mut h = String::new();

  let _ = scan.read_line(&mut a);
  let _ = scan.read_line(&mut b);
  let _ = scan.read_line(&mut h);

  let a: i32 = a.trim().parse().unwrap();
  let b: i32 = b.trim().parse().unwrap();
  let h: i32 = h.trim().parse().unwrap();

  println!("{}", (a + b) * h / 2);
}

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

#define NIL -1
#define MAX 100001

struct Node {int parent, left, right;};
struct Node tree[MAX];

void Preorder(int u){
  if (u == NIL) return;
  cout << " " << u;
  Preorder(tree[u].left);
  Preorder(tree[u].right);
}

void Inorder (int u){
  if (u == NIL) return;
  Inorder(tree[u].left);
  cout << " " << u;
  Inorder(tree[u].right);
}

void Postorder(int u){
  if (u == NIL) return;
  Postorder(tree[u].left);
  Postorder(tree[u].right);
  cout << " " << u;
}

int main(){
  int i, j, c, n, r, id;
  cin >> n;
  for (i = 0; i < n; i++) {
    tree[i].parent = tree[i].left = tree[i].right = NIL; //初期値
  }
  for (i = 0; i < n; i++){
    cin >> id;
    for (j = 0; j < 2; j++){
      cin >> c;
      if (j == 0) tree[id].left = c;
      else tree[id].right = c;
      if (c != NIL) tree[c].parent = id;
    }
  }


  for (i = 0; i < n; i++){
    if (tree[i].parent == NIL) r = i;
  }
  cout << "Preorder" << "\n";
  Preorder(r);
  cout << "\n";
  cout << "Inorder" << "\n";
  Inorder(r);
  cout << "\n";
  cout << "Postorder" << "\n";
  Postorder(r);
  cout << "\n";
  return 0;
}



Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
int arr[(int)2e5 + 100];
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    for(int i = 1;i <= n;i++){
        cin >> arr[i];
    }
    long long ans = 0;
    for(int i = 2;i <= n;i++){
        if(arr[i - 1] <= arr[i]){
        }else{
            
            ans += arr[i - 1] - arr[i];
            arr[i] = arr[i - 1];
        }
    }
    cout << ans;
    return 0;
}

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

typedef long long int ll;
ll gcd(ll a, ll b){ 
    if (a == 0) 
        return b;  
    return gcd(b % a, a);  
} 
int main() {
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    ll l=(c*d)/gcd(c, d); 
    ll x=b/c-a/c;
    ll y=b/d - a/d;
    ll z=b/l - a/l;
    if(a%c==0) x++;
    if(a%d==0) y++;
    if(a%l==0) z++;
    ll s=b-a+1-x-y+z;
    cout<<s;
}

Measured memory_bytes: 256
/*
 * @Author: your name
 * @Date: 2020-01-22 19:43:36
 * @LastEditTime: 2020-01-22 19:46:30
 * @LastEditors: your name
 * @Description: In User Settings Edit
 * @FilePath: \code\AT2156.cpp
 */
//aeiou
#include <bits/stdc++.h>
using namespace std;
char a[5]={'a','e','i','o','u'};
int main() {
   //freopen(".in", "r", stdin);
  //freopen(".out", "w", stdout);
  char s;
  cin>>s;
  for (int i = 0; i < 5; i++)
  {
      /* code */
      if (s==a[i])
      {
          /* code */
          puts("vowel");
          return 0;
      }
      
  }
  puts("consonant");
getchar();getchar();
    return 0;
}

Measured memory_bytes: 256
n, c = map(int, input().split())
D = [list(map(int, input().split())) for _ in range(c)]
C = [list(map(int, input().split())) for _ in range(n)]

for i, l in enumerate(C):
    l = [x-1 for x in l]
    C[i] = l

import itertools
ans = 10**18

X = [[0]*3 for _ in range(c)]
for i in range(n):
    for j in range(n):
        x = C[i][j]
        X[x][(i+j)%3] += 1


for p in itertools.permutations(range(c), 3):
    temp = 0
    for i in range(3):
        for j in range(c):
            temp += X[j][i]*(D[j][p[i]])
    ans = min(temp, ans)
print(ans)


Measured memory_bytes: 78424
#include<iostream>
#include<algorithm>
using namespace std;
int a[20],n;
bool aaaa(int i,int m){
	if(m==0)
	return true;
	if(i>=n)
	return false;
	bool as=aaaa(i+1,m)||aaaa(i+1,m-a[i]);
	return as;
}
main(){
int q,i,m;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	scanf("%d",&a[i]);
	scanf("%d",&q);
	for(i=0;i<q;i++){
		scanf("%d",&m);
		if(aaaa(0,m))
		printf("yes\n");
		else
		printf("no\n");
	}
	return 0;
}



Measured memory_bytes: 3132
#include <iostream>
#include <vector>
#include <string>
using namespace std;

int main(){
  int N;
  cin >> N;
  bool flag;
  flag = false;
  
  for(int i=1;i<=N;i++){
    if(N%i == 0 && i<=9 && N/i <= 9){
      flag = true;
      break;
    }
  }
  
  if(flag) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}

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

//macro-----------------------------------------------------------------------------------------
#define rep(i,a,b) for(int i=a;i<b;i++)
#define int long long

const int inf = 100100100100100;
const int mod = 1000000007;
const string alphabet = "abcdefghijklmnopqrstuvwxyz";
int dx[8]={1,0,-1,0,-1,1,-1,1};
int dy[8]={0,1,0,-1,-1,-1,1,1};


//io_method
int input(){int tmp;cin >> tmp;return tmp;}
string raw_input(){string tmp;cin >> tmp;return tmp;}
string readline(){string s;getline(cin, s);return s;}
template<class T> void print(const T& n){cout << n << endl;}
void print(vector<int> arr){cout << arr[0];rep(i,1,arr.size()) cout << " " << arr[i];cout << endl;}
void print(pair<int, int> p){cout << p.first << " " << p.second;}
void print(vector<vector<int>> arr){rep(i,0,arr.size()){print(arr[i]);}}
void print(set<int> s){for(auto e = s.begin(); e != s.end(); e++){cout << *e << " ";}cout << endl;}
void print(map<int, int> mp){cout << "{";for(auto e = mp.begin(); e != mp.end(); e++){cout << "(" << e -> first << " " << e -> second << ")";}cout << "}" << endl;}

//main------------------------------------------------------------------------------------------

vector<int> factors(int n){
    vector<int> facts;
    int i = 1;
    while(i*i < n){
        if(n % i == 0){
            facts.push_back(i);
            facts.push_back(n/i);
        }
        i++;
    }
    int sq = (int)sqrt(n);
    if(sq * sq == n) facts.push_back(sq);
    return facts;
}

int n, m; 
bool isok(int t){
    if(m/t >= n){
        return true;
    }else{
        return false;
    }
}

signed main(){


    
    cin >> n >> m;

    vector<int> facts = factors(m);
    
    sort(facts.begin(), facts.end());

    int left = 0;
    int right = facts.size();

    rep(i,0,100){
        int mid = (left + right)/2;

        if(isok(facts[mid])){
            left = mid;
        }else{
            right = mid;
        }
    }
    print(facts[left]);
    













}   

Measured memory_bytes: 256
import sys
readline = sys.stdin.readline
N, MOD = map(int, readline().split())

dp = [[0]*(N+5) for _ in range(3*N+4)]
dp[0][0] = 1

for i in range(3*N):
    for j in range(N+1):
        d = dp[i][j]
        dp[i+1][j] = (dp[i+1][j]+d)%MOD
        dp[i+2][j+1] = (dp[i+2][j+1]+(i+1)*d)%MOD
        dp[i+3][j+1] = (dp[i+3][j+1]+(i+2)*(i+1)*d)%MOD

res = 0
for j in range(N+1):
    res = (res+dp[3*N][j])%MOD
print(res)

Measured memory_bytes: 134876
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep1(i,n) for(int i=1; i<=(n); ++i)
#define repi(i,a,b) for(int i=a; i<=(b); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define pb push_back
#define mp make_pair
#define sz(v) (int)v.size()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using ll = long long;
using namespace std;
typedef pair<int,int> P;
struct aaa{aaa(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}aaaaaaa;
int MOD = 1e9 + 7;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return (a*b)/gcd(a,b);}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int N,M;
int x,y,z;

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main(){
    cin >> N >> M;
    UnionFind tree(N+1);
    rep(i,M){
        cin >> x >> y >> z;
        tree.unite(x,y);
    }
    set<int> st;
    rep1(i,N){
        st.insert(tree.root(i));
    }
    cout << sz(st) << '\n';
}

Measured memory_bytes: 5376
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
#include <cstring>
using namespace std;

using ll = long long;
using P = pair<int, int>;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

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

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

    int N, M, A, B;
    cin >> N >> M;
    vector<vector<bool>> graph(N, vector<bool>(N, true));
    for(int i = 0; i < N; ++i)  graph[i][i] = false;
    for(int i = 0; i < M; ++i){
        cin >> A >> B;
        --A, --B;
        graph[A][B] = graph[B][A] = false;
    }
    vector<int> color(N, -1);
    vector<int> cnt(2);
    auto is_bipartite = [&](auto&& self, int cur, int c = 0) -> bool {
        color[cur] = c;
        ++cnt[c];
        for(int nxt = 0; nxt < N; ++nxt){
            if(!graph[cur][nxt] || color[nxt] == (c ^ 1))   continue;
            if(color[nxt] == c) return false;
            else if(!self(self, nxt, c ^ 1))    return false;
        }
        return true;
    };
    bitset<705> dp;
    dp.set(0, 1);
    for(int cur = 0; cur < N; ++cur){
        if(color[cur] != -1)    continue;
        cnt[0] = cnt[1] = 0;
        if(!is_bipartite(is_bipartite, cur)){
            cout << -1 << '\n';
            return 0;
        }
        dp = (dp << cnt[0]) | (dp << cnt[1]);
    }
    int ans = INF;
    for(int i = 0; i <= N / 2; ++i){
        if(dp[i])   chmin(ans, i * (i - 1) / 2 + (N - i) * (N - i - 1) / 2);
    }
    cout << ans << '\n';
}

Measured memory_bytes: 3748
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>

using namespace std;



int main(){
	int n,m;
	while(cin >> n >> m &&n!=0){
		vector<int>s(n),d(m);
		for(int i=0;i<n;i++){
			cin >> s[i];
		}
		for(int i=0;i<m;i++){
			cin >> d[i];
		}
		sort(s.begin(),s.end());
		sort(d.begin(),d.end());
		vector<int> wa(1<<n,0);
		vector<vector<int> > dp(m+1,vector<int>(1<<n));
		for(int i=0;i<(1<<n);i++){
			for(int j=0;j<n;j++){
				if(i&(1<<j)){
					wa[i] += s[j];
				}
			}
		}
		for(int i=0;i<m;i++){
			for(int j=0;j<(1<<n);j++){
				dp[i+1][j] = dp[i][j] + abs(wa[j] - d[i]);
				for(int k=0;k<n;k++){
					if(j&(1<<k)){
						dp[i+1][j] = min(dp[i+1][j],dp[i+1][j-(1<<k)]);
					}
				}
			}
		}
		int ans = 1000000000;
		for(int i=0;i<(1<<n);i++){
			ans = min(ans,dp[m][i]);
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 16544
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author anand.oza
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        AWannaGoBackHome solver = new AWannaGoBackHome();
        solver.solve(1, in, out);
        out.close();
    }

    static class AWannaGoBackHome {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            char[] s = in.next().toCharArray();
            HashSet<Character> distinct = new HashSet<>();
            for (char c : s)
                distinct.add(c);

            boolean answer = true;
            answer &= distinct.contains('N') == distinct.contains('S');
            answer &= distinct.contains('W') == distinct.contains('E');

            out.println(answer ? "Yes" : "No");
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

    }
}



Measured memory_bytes: 23636
//GRL_3A
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
using namespace std;
 
static const int MAX=100000;
vector<int> G[MAX];
int N;
bool visited[MAX];
int prenum[MAX],parent[MAX],lowest[MAX],timer;

void dfs(int current,int prev){
 prenum[current]=lowest[current]=timer;
 timer++;
 visited[current]=true;
 int next;
 for(int i=0;i<G[current].size();i++){
  next=G[current][i];
  if(!visited[next]){
   parent[next]=current;
   dfs(next,current);
   lowest[current]=min(lowest[current],lowest[next]);
  }else if(next!=prev){
   lowest[current]=min(lowest[current],prenum[next]);
  }
 }
}

void art_points(){
 for(int i=0;i<N;i++) visited[i]=false;
 timer=1;
 dfs(0,-1);
 set<int> ap;
 int np=0;
 for(int i=1;i<N;i++){
  int p=parent[i];
  if(p==0) np++;
  else if(prenum[p]<=lowest[i]) ap.insert(p);
 }
 if(np>1) ap.insert(0);
 for(set<int>::iterator it=ap.begin();it!=ap.end();it++)
  cout<<*it<<endl;
}

int main(){
 int m;
 cin>>N>>m;
 for(int i=0;i<m;i++){
  int s,t;
  cin>>s>>t;
  G[s].push_back(t);
  G[t].push_back(s);
 }
 art_points();
 return 0;
}

Measured memory_bytes: 5128
H,W=map(int,input().split())
st=set()
list=list()
for i in range(H):
    S=input()
    if S.count('.') != W:
        list.append(S)
    tmp=S
    tmp=[int(i) for i,x in enumerate(tmp) if x == '.']
    if not st:
        tmp_set = set(tmp)
        st=st.union(tmp_set)
    else:
        tmp_set = set(tmp)
        st &=tmp_set
for x in list:
    str=''
    if not st:
        for i in range(W):
            str+=x[i]
    else:
        for i in range(W):
            if i not in st:
                str+=x[i]
    print(str)
    str=''


Measured memory_bytes: 3064
n,m=map(int,input().split())
check=[False]*n
check[0]=True
ball=[1]*n
for i in range(m):
    x,y=map(int,input().split())
    x-=1
    y-=1
    if check[x]:
        check[y]=True

    ball[y]+=1
    ball[x]-=1
    if ball[x]==0:
        check[x]=False

print(check.count(True))



Measured memory_bytes: 4596
n=int(input())
ans=[]
if n==1:print(1)
else:
    for i in range(2,33):
        a=i*i
        if a>n:continue
        while 1:
            if a<=n:a*=i
            else:
                ans.append(a//i)
                break
    ans.sort()
    print(ans[-1])

Measured memory_bytes: 2940
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#include <set>
#include <iterator>
using namespace std;
using namespace __gnu_pbds;


#define ft first
#define sd second
#define pb push_back
#define all(x) x.begin(),x.end()

#define ll long long int
#define vi vector<int>
#define vii vector<pair<int,int> >
#define pii pair<int,int>
#define plii pair<pair<ll, int>, int>
#define piii pair<pii, int>
#define viii vector<pair<pii, int> >
#define vl vector<ll>
#define vll vector<pair<ll,ll> >
#define pll pair<ll,ll>
#define pli pair<ll,int>
#define mp make_pair
#define ms(x, v) memset(x, v, sizeof x)
#define pr_vec(v) for(int i=0;i<v.size();i++) cout << v[i] << " " ;

#define f_in(st) freopen(st,"r",stdin)
#define f_out(st) freopen(st,"w",stdout)

#define INF INT_MAX
#define matrix vector<vector<ll> >

#define fr(i, a, b) for(i=a; i<=b; i++)
#define fb(i, a, b) for(i=a; i>=b; i--)
#define ASST(x, l, r) assert( x <= r && x >= l )

typedef tree<pll, null_type, less<pll>, rb_tree_tag,
             tree_order_statistics_node_update>
    new_data_set;
const int N=1e3+10, M=(ll)1e9+1 ;
const int mod = 998244353  ;
//ll n,m,a[N][N],dp[N][N],cnt[N][N],cnt2[N][N];
void work(){
    ll w,h,x,y;
    cin >> w >> h >> x >> y;
    double ar=(w*h)/2.0,ok=0;
    if(2*x==w && 2*y==h)
        ok=1;
    cout << fixed << setprecision(9) <<  ar << " " << (ll)ok;
}
int main(){
 ios_base::sync_with_stdio(0);

    ll t,z;
    // cin >> t;
    // z=t;
    t=1;
    while(t--){
            // cout << "Case #" << z-t << ": ";
            work();
    }
   return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)n; i++)
using ll = long long;
 
template <typename T>
class SegTree{
  using F = function<T(T,T)>;
  int n; T uni; F f;
  vector<T> dat;
  T query_sub(int a, int b, int k, int l, int r) {
    if(r <= a || b <= l) return uni;
    if(a <= l && r <= b) return dat[k];
    T vl = query_sub(a, b, k*2+1, l, (l+r)/2);
    T vr = query_sub(a, b, k*2+2, (l+r)/2, r);
    return f(vl,vr);
  }
public:
  SegTree(int _n, F f, T uni) : f(f), uni(uni) {
    n = 1;
    while(n < _n) n *= 2;
    dat = vector<T>(2*n-1,uni);
  }
  void update(int k, T a) {
    k += n-1;
    dat[k] += a;
    while(k > 0){
      k = (k-1)/2;
      dat[k] = f(dat[2*k+1], dat[2*k+2]);
    }
  }
  T query(int a, int b) {
    return query_sub(a, b, 0, 0, n);
  } // [a,b)
};
 
int main(){
  int n;
  cin >> n;
  ll a[n];
  SegTree<ll> st(n,[](ll a,ll b){return max(a,b);},(ll)0);
  set<ll> s;
  rep(i,n) {
    cin >> a[i];
    s.insert(a[i]);
    st.update(i,a[i]);
  }
  map<ll,ll> m;
  ll p = 0;
  for(auto k : s) m[k] = p++;
  SegTree<ll> num(p,[](ll a, ll b){return a + b;},(ll)0);
  SegTree<ll> sum(p,[](ll a, ll b){return a + b;},(ll)0);
  rep(i,n) {
    num.update(m[a[i]],1);
    sum.update(m[a[i]],a[i]);
  }
  vector<ll> ans(n,0);
  rep(i,n) ans[0] += min(a[0],a[i]);
  num.update(m[a[0]],-1);
  sum.update(m[a[0]],-a[0]);
  for(int i = 1; i < n; i++) {
    ll d = st.query(0,i);
    ll c = sum.query(m[d],m[a[i]]);
    ll e = num.query(m[d],m[a[i]]);
    ll f = num.query(m[a[i]],p);
    ans[i] = f*max((ll)0,a[i]-d) + c - e*d;
    num.update(m[a[i]],-1);
    sum.update(m[a[i]],-a[i]);
  }
  for(auto k : ans) cout << k << endl;
  return 0;
}

Measured memory_bytes: 19712
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define erep(i,n) for(int i = 0;i<=n;i++)
#define rep1(i,n) for(int i = 1;i<n;i++)
#define erep1(i,n) for(int i = 1;i<=n;i++)
typedef long long ll;
#define vint vector<int>
#define vstring vector<string>
#define vll vector<ll>
#define vbool vector<bool>
#define INF 100000000

int main(){
  int n,m;
  cin >> n >> m;
  map<int,int> ans;
  bool ok = true;
  rep(i,m){
    int s,c;
    cin >> s >> c;
    if(ans[s] == 0){
      ans[s] = c + 1;
    }
    else if(ans[s] != c + 1){
      ok = false;
      break;
    }
  }
  if(!(ok)){
    cout << -1 << endl;
  }
  else{
    erep1(i,n){
      if(i == 1){
        if(ans[i] == 0 && n > 1){
          cout << 1;
        }
        else if(n == 1 && ans[i] == 0){
          cout << 0;
        }
        else if(ans[i] == 1 && n > 1){
          cout << -1 << endl;
          break;
        }
        else if(ans[i] == 1 && n == 1){
		  cout << 0 << endl;
        }
        else{
          cout << ans[i]-1;
        }
      }
      else{
        if(ans[i] != 0){
          cout << ans[i]-1;
        }
        else{
          cout << 0;
        }
      }
    }
  }

}


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

using namespace std;

void test()
{
    int n;
    cin>>n;
    
    if(n>=30)
        cout<<"Yes\n";
    else
        cout<<"No\n";
}

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

    test();

    return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
int N, heig[100000];
int main(){
	cin>>N;
	for(int i=0;i<N;i++){
		cin>>heig[i];
	}
	int ans=0;
	int temp=0;
	for(int i=1;i<N;i++){
		if(heig[i]>heig[i-1]){
			ans=max(ans,temp);
			temp=0;
		} else {
			temp++;
		}
	}
	ans=max(ans,temp);
	cout<<ans<<'\n';
}

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

namespace CSharp_AtCoder
{
    class Program
    {
        static int N;

        static bool Check753(string str)
        {
            if (str.Contains("7") && str.Contains("5") && str.Contains("3"))
            {
                return true;
            }
            else return false;
        }

        static int Solve(int max_cnt, int cnt, string str_753)
        {
            if(cnt >= max_cnt)
            {
                if (int.Parse(str_753) <= N && Check753(str_753)) return 1;
                else return 0;
            }

            return Solve(max_cnt, cnt + 1, str_753 + "7")
                 + Solve(max_cnt, cnt + 1, str_753 + "5")
                 + Solve(max_cnt, cnt + 1, str_753 + "3");
        }

        static void Main(string[] args)
        {
            N = int.Parse(Console.ReadLine());

            int sum = 0;
            for(int i = 3; i <= 9; i++)
            {
                sum += Solve(i, 0, "");
            }

            Console.WriteLine(sum);
        }
    }
}


Measured memory_bytes: 13140
#include<bits/stdc++.h>
using namespace std;
int main()
{
      int h,a;
      cin>>h>>a;
      int ans=0;
      if(h%a==0)
        ans=h/a;
      else
      {
         ans=h/a+1;
      }
      cout<<ans<<endl;
      return 0;
}

Measured memory_bytes: 256
const config = {
    input: '/dev/stdin',
    newline: '\n'
};

const line = require('fs').readFileSync(config.input, 'utf-8').split(config.newline);
const list = line[1].split(' ').map(x => parseInt(x));

const sort = arr => {
    for (let i = 1; i < arr.length; i++) {
        const v = arr[i];
        j = i - 1;
        console.log(arr.map(x => x.toString()).join(' '));
        while (j >= 0 && arr[j] > v) {
            arr[j+1] = arr[j];
            j--;
        }
        arr[j+1] = v;
    }

    console.log(arr.map(x => x.toString()).join(' '));
    return arr;
};

sort(list);


Measured memory_bytes: 17428
// Problem : B - Judge Status Summary
// Contest : AtCoder - AtCoder Beginner Contest 173
// URL : https://atcoder.jp/contests/abc173/tasks/abc173_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
#define F first
#define S second
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define pb push_back
#define mk make_pair
#define fast                    \
  ios_base::sync_with_stdio(0); \
  cin.tie(0);                   \
  cout.tie(0);
#define rep(i, a, b) for (ll i = a; i < b; i++)
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define sz(x) (int)x.size()
#define mem(a, val) memset(a, val, sizeof(a))
#define deci(x) cout << fixed << setprecision(x);
#define bitcount(x) __builtin_popcountll(x)

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

const long long int mod = 1e9 + 7;
const long double EPS = 1e-12;
const int N = 1e5 + 20;

void solve() {
  ll n;
  cin >> n;
  map<string, int> mp;
  rep(i, 0, n) {
    string temp;
    cin >> temp;
    mp[temp]++;
  }
  cout << "AC x " << mp["AC"] << '\n';
  cout << "WA x " << mp["WA"] << '\n';
  cout << "TLE x " << mp["TLE"] << '\n';
  cout << "RE x " << mp["RE"] << '\n';
}
int main() {
  fast;
  ll t;
  t = 1;

  // cin>>t;

  while (t--) {
    solve();
  }

  return 0;
}


Measured memory_bytes: 3668