akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <array>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define REP(X, Y, Z) for (ll(X) = (Y); (X) < (Z); (X)++)
#define REV(X, Y, Z) for (ll(X) = (Y); (X) > (Z); (X)--)

using namespace std;
using ll = long long;
using dll = deque<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using usll = unordered_set<ll>;
using umll = unordered_map<ll, ll>;
using sll = stack<int>;
using vll = vector<ll>;
using vvll = vector<vll>;

constexpr ll kMod = 1e9 + 7;

ll gcd(ll a, ll b) {
  if (a < b) {
    return gcd(b, a);
  }
  ll c = a % b;
  while (c != 0) {
    a = b;
    b = c;
    c = a % b;
  }
  return b;
}

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

void init() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

int main() {
  init();

  ll N;
  cin >> N;
  vll T(N);
  REP(i, 0, N) {
    ll t;
    cin >> t;
    T[i] = t;
  }
  ll M;
  cin >> M;
  vll P(M), X(M);
  REP(i, 0, M) {
    ll p, x;
    cin >> p >> x;
    P[i] = p - 1;
    X[i] = x;
  }

  REP(m, 0, M) {
    ll sum = 0;
    REP(n, 0, N) {
      if (n == P[m]) {
        sum += X[m];
      } else {
        sum += T[n];
      }
    }
    cout << sum << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void)
{
   string s;

   cin >> s;

   for(int i = 0; i < 4; i++){
      if(s[i] == s[i + 1]){
         cout << "Bad" << endl;
         return 0;
      }
   }
   cout << "Good" << endl;

   return 0;
}

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

int count;

void dfs(Graph &G, int v, int &count, vector<bool> &seen)
{
    seen[v] = true;
    for (auto nv : G[v])
    {
        if(seen[nv])continue;
        count++;
        dfs(G, nv, count, seen);
    }
    
}

int main()
{
	int n, m;
    cin >> n >> m;
    
    Graph G(n);
    for (int i = 0; i < m; i++)
    {
        int a, b;
        cin >> a >> b;
        a--;b--;

        G[a].push_back(b);
        G[b].push_back(a);
    }

    vector<bool> seen(n, false);

    vector<int> ans;
    for (int i = 0; i < n; i++)
    {
        if(seen[i])continue;
        int count = 0;
        dfs(G, i, count, seen);
        ans.push_back(count);
    }

    sort(ans.begin(), ans.end());
    reverse(ans.begin(), ans.end());

    cout << ans[0] + 1 << endl;
}

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

int main(void){
		int n,r,number;
		int	a[4][13];
		char R;
		
		//配列初期化
		for(int i = 0;i < 4;i++){
				for(int j = 0;j < 13;j++){
						a[i][j] = 0;
					
				}
		}
		cin >> n;
		for(int m = 0; m < n;m++){
			cin >> R >> number;
				if(R == 'S'){
						r = 0;
				}else if(R == 'H'){
						r = 1;
				}else if(R == 'C'){
						r = 2;
				}else if(R == 'D'){
						r = 3;
				}
		
			a[r][number - 1] = 1;
		}

		for(int i = 0;i < 4;i++){
			for(int j = 0;j < 13;j++){
					if(a[i][j] != 1){
							if(i == 0) R = 'S';
							if(i == 1) R = 'H';
							if(i == 2) R = 'C';
							if(i == 3) R = 'D';
				    		cout << R << " " << j + 1 << endl;				
					}
			}
		}
		return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string n;
  cin >> n;
  if(n[0] == n[1] && n[1] == n[2]){
    cout << "Yes" << endl;
  }else if(n[1] == n[2] && n[2] == n[3]) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
//皆さん、第9回シンデレラガール総選挙は、トップでオンリーワンを目指す城ヶ崎美嘉に
//そしてボイスアイドルオーディションは、プログラミングが趣味の才女大石泉に、ぜひ投票をお願いします！
//#城ヶ崎美嘉を009のシンデレラに
//#大石泉の必勝プログラム
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
//問題文および制約はちゃんと確認しよう！
//サイズは10^5じゃなくて2×10^5とかかもしれないし、重要な制約・条件を見落としているかも
//とりあえずサンプルを読んでから解法を考えよう？
lint mo=998244353;
lint extgcd(lint a, lint b, lint &x, lint &y) {
  lint g = a; x = 1; y = 0;
  if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x;
  return g;
}
lint invMod(lint a, lint m) {
  lint x, y;
  if (extgcd(a, m, x, y) == 1) return (x + m) % m;return 0;
}
lint zyo(lint x,lint y){
    lint ret=1,a=x;
    while(y>0){
    	if(y%2==1) ret=(ret*a)%mo;
    	a=(a*a)%mo;y/=2;
    }
    return ret;
}
lint zy[200100],rz[200100];
lint co(int a,int b){
	if(a<0 || b<0 || a<b) return 0;
	return (zy[a]*rz[b])%mo*rz[a-b]%mo;
}
int main()
{
	zy[0]=1;
	rep(i,200050) zy[i+1]=zy[i]*(i+1)%mo;
	rep(i,200050) rz[i]=invMod(zy[i],mo);
	int n,m,k;lint out=0;
	cin>>n>>m>>k;//out=zyo(m,n);
	//cout<<out<<endl;
	rep(i,k+1){
		lint t=zyo(m-1,n-1-i)*co(n-1,i);
		//cout<<t<<endl;
		//if(i%2==k%2) out+=t;else out-=t;
		out+=t;
		out%=mo;
	}
	out%=mo;out+=mo;out%=mo;
	out*=m;out%=mo;
	cout<<out<<endl;
}


Measured memory_bytes: 6768
#include<stdio.h>
#include<stdlib.h>
#include<string.h>


int main(){
	char ss[1000];
	int i,c;
	c=0;
	while(0<=scanf("%s",ss)){
		for(i=0;i<=strlen(ss)-1;i++){
			if(ss[i]!=ss[strlen(ss)-i-1])break;
		}
		
		if(i==strlen(ss))++c;
	}
	printf("%d\n",c);
	return 0;
}

Measured memory_bytes: 0
import itertools
N, M = map(int, input().split())

v = [[] for i in range(N)]
for i in range(M):
    Pi, Yi = map(int, input().split())
    v[Pi-1].append((Yi, i))

ids = []
for ps,p in zip(v,range(len(v))):
    for c,i in zip(sorted(ps, key=(lambda x:x[0])), range(len(ps))):
        ids.append(('{0:06d}{1:06d}'.format(p+1,i+1) ,c[1]))

for id_ in sorted(ids, key=(lambda x:x[1])):
    print(id_[0])


Measured memory_bytes: 43348
#include<cstdio>
#include<algorithm>
#include<utility>

using namespace std;

int func(int lst[], pair<int, int> p[], int q_num, int w, int n, int m){
    // for(int i = 0; i < q_num; i++){
    //     printf("%d ", lst[i]);
    // }
    // puts("");
    if (w == q_num) {
        int b = 1;
        for(int i = 0; i < q_num; i++){
            for(int j = 0; j < lst[i]; j++){
                b *= p[i].first;
            }
        }

        // printf("%d\n", (m - (n * b)));
        // printf("%d\n", b);

        if (m / n >= b && (m - (n * b)) % b == 0) {
            return b;
        }else return 0;        
    }

    int c[q_num];
    for(int i = 0; i < q_num; i++){
        c[i] = lst[i];
    }
    
    int mx = 0;
    for(int i = 0; i <= p[w].second; i++){
        // printf("i = %d, w = %d, q_num = %d\n", i, w, q_num);
        // for(int j = 0; j < q_num; i++){
        //     printf("%d ", c[j]);
        // }
        // puts("");
        mx = max(func(c, p, q_num, w + 1, n, m), mx);
        // printf("mx = %d\n", mx);
        c[w]++;

    }
    return mx;
}

int main(){
    int n, m;
    scanf("%d %d", &n, &m);
    int t[50];
    int num = m;
    pair<int, int> q[100];
    int q_num = 0;
    for(int i = 2; i * i <= m; i++){
        if (num % i == 0){
            q[q_num].first = i;
            q[q_num].second = 0;
            while(num % i == 0){
                num /= i;
                q[q_num].second++;
            }        
            q_num++;
        }
        // printf("%d\n", q_num);
    }
    if (num != 1) {
        q[q_num].first = num;
        q[q_num].second = 1;
        q_num++;
    }
    // printf("%d\n", q_num);
    // for(int i = 0; i < q_num; i++){
    //     printf("%d %d\n", q[i].first, q[i].second);
    // }
    int a[q_num];
    fill(a, a + q_num, 0);
    
    int ans;
    ans = func(a, q, q_num, 0, n, m);

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



Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,K;
  cin >> N >> K;
  long long ans;
  long long a = N/K;
  ans = a*a*a;
  if (K%2 == 0) {
    int kk = K/2;
    long long b = N/kk - a;
    ans += b*b*b;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include <queue>
#include<string>
#include<utility>
#include<iterator>
#include<regex>
#include<math.h>

#define lli long long
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(),i.rend()
#define rep0(i,j) for(lli i=0;i<j;i++)
#define rep1(i,j) for(lli i=1;i<=j;i++)
#define rep0d(i,j) for(lli i=j-1;i>=0;i--)
#define MAX 1000000007
typedef struct tree Tree;

using namespace std;

bool cmpf(pair<lli, lli> left, pair<lli, lli> right) {
	return left.first < right.first;
}

int main() {
	regex re("A[a-z]+C[a-z]+");
	smatch match;
	string s;
	cin >> s;
	if (regex_match(s, match, re)) {
		cout << "AC";
	}
	else {
		cout << "WA";
	}
}


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

int main(){
	int n;
	cin >> n;
	map<int, bool> a;
	int ans=0;
	for(int i = 0; i < n; i++)
	{
		int b;
		cin >> b;
		
		if(a[b]){
			ans--;
			a[b] = false;
		}
		else if(!a[b]){
			ans++;
			a[b] = true;
		}
	}
	
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 4864
#include<iostream>
#include<algorithm>
#include <string>
#include<cstdio>
#include<stack>
#include<cstring>
#include<vector>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define EREP(i,n) for(int i=(n-1);i>=0;--i)
#define D(n,retu) REP(i,n){cin>>retu[i];}

using namespace std;
typedef long long ll;
template<typename T>
void fill_all(T& arr, const T& v) {
	arr = v;
}
template<typename T, typename ARR>
void fill_all(ARR& arr, const T& v) {
	for (auto& i : arr) { fill_all(i, v); }
}

//------------------変数-----------------------//
ll n, cou, kekka[40], m;
string a[60];
//-------------------関数----------------------//
int main() {
	cin >> n;
	cou = n / 11 * 2;
	ll amari = n - 11 * cou / 2;
	if (amari == 0) {
		cout << cou << endl; return 0;
	}
	else if (amari <= 6) { cout << cou + 1 << endl; }
	else { cout << cou + 2 << endl; }
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
static const int MAX=100;
static const int INFTY=(1<<21);
static const int WHITE=0;
static const int GRAY=1;
static const int BLACK=2;

int n,M[MAX][MAX];

int prim(){
    int u, minv;
    int d[MAX],p[MAX],color[MAX];
    
    for (int i=0; i<n; i++){
        d[i]=INFTY; //∞
        p[i]=-1;
        color[i]=WHITE;
    }
    d[0]=0;
    
    while(1){
        minv=INFTY;
        u=-1;
        for (int i=0; i<n; i++){
            if(minv>d[i] && color[i]!=BLACK){
                u=i;
                minv=d[i];
            }
        }
        if(u==-1) break;
        color[u]=BLACK;
        for (int v=0; v<n; v++){
            if(color[v]!=BLACK && M[u][v]!=INFTY){
                if(d[v]>M[u][v]){
                    d[v]=M[u][v];
                    p[v]=u;
                    color[v]=GRAY;
                }
            }
        }
    }
    int sum=0;
    for (int i=0; i<n; i++){
        if(p[i]!=-1) sum+=M[i][p[i]];
    }
    return sum;
}

int main(){
    cin >> n;
    for (int i=0; i<n; i++){
        for (int j=0; j<n; j++){
            int e; cin >> e;
            M[i][j]=(e==-1) ? INFTY:e;
        }
    }
    
    cout << prim() << endl;
    return 0;
}


Measured memory_bytes: 3104
// https://atcoder.jp/contests/abc062/tasks/abc062_a
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int x, y, g1 = 0, g2 = 0;
    cin >> x >> y;
    int d31[] = {1, 3, 5, 7, 8, 10, 12};
    int d30[] = {4, 6, 9, 11};
    for (auto &a : d31) {
        if (x == a) {
            g1 = 1;
        }
        if (y == a) {
            g2 = 1;
        }
    }
    for (auto &a : d30) {
        if (x == a) {
            g1 = 2;
        }
        if (y == a) {
            g2 = 2;
        }
    }
    if (g1 == g2) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }

    return 0;
}


Measured memory_bytes: 256
require "bigdecimal"

n = STDIN.gets.to_i

n.times{
a = STDIN.gets
b = STDIN.gets
if(a.length > 81 || b.length > 81)
puts "overflow"
next
end
a = BigDecimal(a)
b = BigDecimal(b)
res = (a+b).to_s("F").split(".")[0]
if(res.length > 80)
puts "overflow"
next
end
puts res
}

Measured memory_bytes: 5292
#include <iostream>
#include <math.h>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <cstdlib>
#include <unordered_map>
#include <numeric>

using namespace std;

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

const ll mod = 1e9+7;
ll fact[200200];
ll invfact[200200];

inline ll take_mod(ll a){
    return (a % mod + mod) % mod;
}

inline ll add(ll a, ll b){
    return take_mod(a+b);
}

inline ll sub(ll a, ll b){
    return take_mod(a-b);
}


inline ll mul(ll a, ll b){
    return take_mod(a * b);
}

inline ll pow(ll x, ll n){
    ll res = 1LL;
    while(n > 0){
        if(n & 1) res = mul(res, x);
        x = mul(x, x);
        n >>= 1;
    }
    return res;
}

ll mod_inv(ll x){
    return pow(x, mod-2);
}

// nは上限
void make_fact(ll n){
    fact[0] = 1;
    ll res = 1;
    for(int i = 1; i <= n; i++){
        fact[i] = res;
        res = mul(res, i+1);
    }
}

// nは上限
void make_invfact(ll n){
    invfact[0] = 1;
    invfact[n] = mod_inv(fact[n]);
    for(int i = n-1; i >= 1; i--){
        invfact[i] = mul(invfact[i + 1], i + 1);
    }
}

ll perm(ll n, ll k){
    return mul(fact[n], invfact[n-k]);
}

ll comb(ll n, ll k){
    return mul(mul(fact[n], invfact[n-k]), invfact[k]);
}

ll dp[110][100100];

int main(){
    int N, K;  cin >> N >> K;
    int a[110];
    for(int i = 0; i < N; i++){
        cin >> a[i];
    }

    for(int i = 0; i < 110; i++){
        for(int j = 0; j < 100100; j++){
            dp[i][j] = 0;
        }
    }
    dp[0][0] = 1;
    for(int i = 1; i <= N; i++){
        ll cumK = 0;
        for(int j = 0; j <= K; j++){
            cumK = add(cumK, dp[i-1][j]);
            if(j > a[i-1]){
                cumK = sub(cumK, dp[i-1][j-a[i-1]-1]);
            }
            dp[i][j] = cumK;
        }
    }

//    for(int i = 0; i <= N; i++){
//        for(int j = 0; j <= K; j++){
//            cout << dp[i][j] << " ";
//        }
//        cout << endl;
//    }

    cout << dp[N][K] << endl;


    return 0;
}

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

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|s| s.parse().ok().unwrap())
        .collect()
}


fn main() {
    let n = read::<usize>();
    let mut ab = vec![];

    for _ in 0..n {
        let input = read_vec::<usize>();
        ab.push(input);
    }

    ab.sort_by_key(|x| x[1]);

    let mut time = 0;

    for (a, b) in ab.iter().map(|x| (x[0], x[1])) {
        time += a;
        if time > b {
            println!("No");
            return;
        }
    }
    println!("Yes");
}

Measured memory_bytes: 15860
n=int(input())
sp=[]
for i in range(n):
    s,p=map(str,input().split())
    sp.append([s,int(p),i+1])
sp.sort(key=lambda x: x[1],reverse=True)
sp.sort(key=lambda x: x[0])

for e in sp:
    print(e[2])


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

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

using ll = long long;
using lb = long double;
using P = pair<ll,ll>;
using graph = vector<vector<ll>>;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const ll INF = 1LL<<60;
const ll mod = 1000000007LL;

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

int main() {
  ll N;
  cin>>N;
  ll ans = 0;
  for(ll i = 1;i <= N; i++){
    ll l = (N/i)*i;
    ll p = N/i;
    ans += (i+l)*p/2;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3616
#include<iostream>
using namespace std;
int main() {
	int x, y, z;

	cin >> x;
		cin >>	 y;
		cin>> z;
	if (x == 5 && y==7 && z==5 || x==5 && y==5 && z==7 || x==7 && y==5 && z==5){
		cout << "YES";
	 }else{
		cout << "NO";
	}
	return 0;
	
}

Measured memory_bytes: 256
#include <stdio.h>
#define MAXN (1<<21)
double f[1050000];
double map[21][21],x[21],y[21],z[21];
int num(int a)
{
    int ans=0;
    for(int i=0;i<20;i++)
        if((a>>i)&1)
            ans++;
    return ans;
}
int main()
{
    int n,m,i,j,a,b,t;

    while(scanf("%d%d",&n,&m)!=EOF)
    {
        for(i=0;i<n;i++)
        {
            scanf("%lf%lf%lf",x+i,y+i,z+i);
        }
        for(i=0;i<n;i++)
            for(map[i][i]=0,j=0;j<i;j++)
                map[i][j]=map[j][i]=(x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j])+(z[i]-z[j])*(z[i]-z[j]);

        int temp;
        double ans=0;

        for(i=1;i<(1<<n);i++)
        {
            f[i]=0;
            temp=num(i);
            //printf("%d %d\n",i,temp);
            if(temp==1)
                    f[i]=0;
            else if(temp==2){
               // puts("!");
                for(t=j=0;j<20;j++)
                {
                    if((i>>j)&1)
                    {
                        if(t==0)
                            a=j,t=1;
                        else
                            b=j;
                    }
                }

                f[i]=map[a][b];// printf("%d %d %d\n\n",a,b,f[i]);
            }
            else{
                for(j=0;j<20;j++)
                {
                    if((i>>j)&1)
                        f[i]+=f[i-(1<<j)];
                }
                f[i]/=(double)(temp-2);
            }
           // printf("%d %lf\n\n",i,f[i]);
            if(temp==m&&ans<f[i])
                    ans=f[i];
        }

        printf("%.10lf\n",ans);
    }
    return 0;
}

Measured memory_bytes: 9016
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
typedef pair<ll,P> PP;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define rep(i,n) for(int (i)=0;(i)<(ll)(n);++(i))
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(x,y) (x=min(x,y))
#define chmax(x,y) (x=max(x,y))
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}

struct UF {
	vector<int> par, rank, sz;
	
	void init(int n){
		par = rank = vector<int>(n, 0);
		sz = vector<int>(n, 1);
		for(int i = 0; i < n; i++){
			par[i] = i;
		}
	}
	
	int find(int x){
		if(par[x] == x){
			return x;
		}else{
			return par[x] = find(par[x]);
		}
	}

	int size(int x){
		return sz[find(x)];
	}
	
	void unite(int x, int y){
		x = find(x);
		y = find(y);
		if(x == y) return;
		
		if(rank[x] < rank[y]){
			par[x] = y;
			sz[y] += sz[x];
		}else{
			par[y] = par[x];
			if(rank[x] == rank[y]) rank[y]++;
			sz[x] += sz[y];
		}
	}
	
	bool same(int x, int y){
		return find(x) == find(y);
	}
};

#define N 200010
ll d[N];


int main(){
	int n, m;
	cin>>n>>m;
	priority_queue<PP, vector<PP>, greater<PP>> q;
	fill(d, d+N, 1e17);
	rep(i, m){
		ll a, b, c;
		cin>>a>>b>>c;
		q.push(PP(c, P(a, b)));
		chmin(d[a], c+1);
		chmin(d[b], c+2);
	}
	rep(i, 3*n) chmin(d[(i+1)%n], d[i%n]+2);
	rep(i, n) q.push(PP(d[i], P(i, (i+1)%n)));
	UF uf;
	uf.init(n);
	ll res = 0;
	while(!q.empty()){
		PP pp = q.top(); q.pop();
		int u = pp.snd.fst, v = pp.snd.snd, w = pp.fst;
		if(uf.same(u, v)) continue;
		uf.unite(u, v);
		res += w;
	}
	cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 16108
#include <cstdio>
#include <algorithm>
using namespace std;

bool chk(int n)
{
	int cnt = 0;
	while (n > 0)
	{
		cnt++;
		n /= 10;
	}
	return cnt % 2 == 1;
}

int main()
{
	int N, ans = 0;
	scanf("%d", &N);
	for (int i = 1; i <= N; i++)
		ans += chk(i);
	printf("%d", ans);
	return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#include <list>
#include <atcoder/all>
#define popcount __builtin_popcount
using namespace std;
using namespace atcoder;
typedef long long ll;
typedef pair<int, int> P;
struct unionfind{
    vector<int> par, sz;
    unionfind() {}
    unionfind(int n):par(n), sz(n, 1){
        for(int i=0; i<n; i++) par[i]=i;
    }
    int find(int x){
        if(par[x]==x) return x;
        return par[x]=find(par[x]);
    }
    bool unite(int x, int y){
        x=find(x); y=find(y);
        if(x==y) return false;
        if(sz[x]>sz[y]) swap(x, y);
        par[x]=y;
        sz[y]+=sz[x];
        return true;
    }
    bool same(int x, int y){
        return find(x)==find(y);
    }
    int size(int x){
        return sz[find(x)];
    }
};
int main()
{
    int n, m; cin>>n>>m;
    unionfind uf(n);
    int ans=n-1;
    for(int i=0; i<m; i++){
        int a, b; cin>>a>>b;
        a--; b--;
        ans-=uf.unite(a, b);
    }
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 4080
N = int(input())
S = {}
ans = 0
for i in range(N):
    a = input()
    s = [ ]
    for j in range(10):
        s.append(a[j])
    s.sort()
    b =s[0]
    for k in range(1,10):
        b += s[k]
    if b in S:
        ans += S[b]
    else:
        S[b] = 0
    S[b] += 1
print(ans)

Measured memory_bytes: 17888
a = int(input())
li = list(map(int,input().split()))
total = 1
i = 1
for i in range(a):
    total = total*li[i]
    if total > 1000000000000000000:
        total = -1
        break
for i in range(a):
    if li[i] == 0:
        total = 0
 
print(total)

Measured memory_bytes: 21712
// https://atcoder.jp/contests/abc069/tasks/arc080_a

#include <bits/stdc++.h>

using namespace std;

#define REP(i,n)   for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for(int i=(b); i<=(int)(e); i++)
#define DUMP(a, n) REP(_i, n) printf("%d%c", a[_i], _i + 1 == n ? '\n' : ' ')
#define DUMP2D(a, n, m) REP(_i, n) REP(_j, m) printf("%d%c", a[_i][_j], _j + 1 == m ? '\n' : ' '); puts("")

const int N_MAX = 1e5;
const int A_I_MAX = 1e9;

int N;
int a[N_MAX];

void solve() {
  int c1 = 0;
  int c4 = 0;
  REP(i, N) {
    if (a[i] % 2 > 0) c1++;
    if (a[i] % 4 == 0) c4++;
  }
  bool cond = c1 <= c4 || c4 == N / 2;
  puts(cond ? "Yes" : "No");
}

void input() {
  scanf("%d", &N);
  REP(i, N) scanf("%d", a + i);
}

int main() {
  input();
  solve();
  return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#include <chrono>
#include<math.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std::chrono;
using namespace std;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// declaration: ordered_set os;  methods->  1. *os.find_by_order(x)   2. os.order_of_key(k) ->return int

#define fr(x,i,n) for(int x = i; x < n; ++x)
#define fb(x,i,n) for(int x = i; x >= n; --x)
#define pr pair<int,int>
#define ll long long int
#define ld long double
const ll mod=998244353;

void solve(){
    int x,n;
    cin>>x>>n;
    int a[n];
    int ans,ansd=INT_MAX;
    fr(i,0,n)
    cin>>a[i];
    fb(d,n+n,0){
        bool f=1;
        fr(i,0,n)
        if(x+d==a[i])
        f=0;
        if(f&&ansd>=d){
            ans=x+d;
            ansd=d;
        }

    }
    fr(d,0,n+1){
        bool f=1;
        fr(i,0,n)
        if(x-d==a[i])
        f=0;
        if(f&&ansd>=d){
            ans=x-d;
            ansd=d;
        }

    }
    cout<<ans;

}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t=1;
    //cin>>t;
    while(t--)
    solve();

}


Measured memory_bytes: 3600
#include <iostream>
#include <cstdio>

using namespace std;

int main() {
    int a, b;
    char S[20];

    cin >> a >> b >> S;

    for (int i=0; i<a+b+1; i++) {
        if (i < a || i > a) {
            if (S[i] < '0' || '9' < S[i]) goto NO;
        }
        else { // i == a
            if (S[i] != '-') goto NO;
        }
    }

    if (S[a+b+1] != '\0') goto NO;

    cout << "Yes" << endl;
    return 0;

NO:
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*

fun main(args: Array<String>) {
    val scan = Scanner(System.`in`)
    val aa = scan.nextLine().split(" ").map{ it.trim().toInt() }.toTypedArray()

    var m = aa[0]
    var n=aa[1]
    var z=0

    while(m>0)
    {
        z++
        m-=n
    }
    print(z)
}


Measured memory_bytes: 35832
#include<stdio.h>
int main()
{
	int i,a,b,c,x,y,p=0,ap,cp,s;
	while(~scanf("%d%d%d%d%d",&a,&b,&c,&x,&y))
	{
		if((a+b)>(c+c))
		{
			c=c+c;
			for(i=0;i<x&&i<y;i++)
			p++;
			cp=p*c;
			if(x>y)
			{
				s=x-i;
				p=cp+s*a;
				if(x*c<p)
				p=x*c;
			}
			else
			{
				s=y-i;
				p=cp+s*b;
				if(y*c<p)
				p=y*c;
			}
			printf("%d\n",p);
		}
		else
		{
			p=x*a+y*b;
			printf("%d\n",p);
		}
	}
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
  
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL); 
  
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define pu push
#define pp pop_back
#define in insert
#define ld long double
#define debug cout << "Hold right there sparky.....\n";
#define forn(low,high,i) for(i=low;i<high;i++)
#define forrev(high,low,i) for(i = high; i>= low;i--)

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...) 1
#endif
template<class T> ostream& operator<<(ostream &os, vector<T> V) {os << "[ "; for(auto v : V) os << v << " "; return os << "]";}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {return os << "(" << P.first << "," << P.second << ")";}
  
typedef long long int ll;
  
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
const ll mod =1e9+7;
const ll maxn =5*100001;
ll power(ll x, ll n) {
  ll res = 1;
  for (; n > 0; n >>= 1) {
    if (n & 1) res = (res * x) % mod;
    x = (x * x) % mod;
  }
  return res;
}

const ll MAX = 100000; 

int main()
{

  IOS
  ll n;
  cin>>n;
  ll a[n];
  for(ll i=0;i<n;i++)
  {
    cin>>a[i];
  }
  sort(a,a+n);
  ll ans=0;
  for(ll i=0;i<n;i++)
  {
    for(ll j=i+1;j<n;j++)
    {
      ll pos=lower_bound(a,a+n,a[i]+a[j])-a;
      ans+=(pos-j-1);
    }
  }
  cout<<ans<<endl;
}
    
  

  
  
	




Measured memory_bytes: 256
my @day = split(//,<>);
my $MAX= 0;
my $count= 0;
for($i=0;$i<3;$i++){
    if( $day[$i] eq "R"){
        $count++;
    }else{
        if($count > $MAX){
        $MAX=$count;
        }
        $count=0;
    }
}
if($count > $MAX){
    $MAX= $count;
}
print "$MAX";


Measured memory_bytes: 4788
#include <iostream>
#include <vector>
                 
int main() {     
    std::vector<int> arr;
    int len, num = 0;
    std::cin >> len;
    for(int i = 0; i < len; i++) {
        std::cin >> num;
        arr.push_back(num);
    }            
    for(int i = len-1; i >= 0; i--) {
        std::cout << arr[i];
        if(i != 0) std::cout << " ";
    }            
    std::cout << std::endl;
    return 0;    
}

Measured memory_bytes: 1216
#include<stdio.h>
#include<iostream>
#include<string>

using namespace std;
int main(){
    string s,p;
    cin >> s >> p;
    s = s + s;
    if(s.find(p) != -1){
        printf("Yes\n");
    } else{
        printf("No\n");
    }
    
    
}



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

using namespace std;

typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = (ll)1e9 + 7;

int dfs(int u, int d, int N, vector<bool>& seen, vector<vector<int>>& adj)
{
  seen[u] = true;
  ++d;
  if (d == N) { return 1; }
  int ret = 0;
  for (int v : adj[u]) {
    if (not seen[v]) {
      ret += dfs(v, d, N, seen, adj);
      seen[v] = false;
    }
  }
  return ret;
}

int main()
{
  int N, M; scanf("%d %d", &N, &M);
  vector<vector<int>> adj(N + 5, vector<int>());
  int a, b;
  for (int i = 0; i < M; ++i) {
    scanf("%d %d", &a, &b);
    adj[a].push_back(b);
    adj[b].push_back(a);
  }

  vector<bool> seen(N + 5, 0);
  int ans = dfs(1, 0, N, seen, adj);
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>

using namespace std;

int main() {
	int n;
	cin >> n;
	vector<long long int> c(n-1);
	vector<long long int> s(n-1);
	vector<long long int> f(n-1);

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

	for (int i = 0; i < n-1; i++) {
		long long int t = s[i];
		t += c[i];
		for (int j = i+1; j < n-1; j++) {
			if (t < s[j]) {
				t = s[j];
			}
			if (t%f[j] != 0) {
				t = ((t / f[j]) + 1LL)*f[j];
			}
			t += c[j];
		}
		cout << t << endl;
	}

	cout << 0 << endl;

	return 0;
}

Measured memory_bytes: 256
a,b = map(int,input().split())
if(a <= 0 and b >= 0):
  print("Zero")
elif(a > 0 and b > 0):
  print("Positive")
else:
  if(abs(a-b) % 2 == 0):
    print("Negative")
  else:
    print("Positive")

Measured memory_bytes: 3060
from collections import defaultdict
n = int(input())
d = defaultdict(lambda: 0)

for i in range(n):
    s = input()
    d[s] += 1

print('AC x {}'.format(d['AC']))
print('WA x {}'.format(d['WA']))
print('TLE x {}'.format(d['TLE']))
print('RE x {}'.format(d['RE']))


Measured memory_bytes: 69896
#include <stdio.h>
int main(){
	long long sum;
	int min,max,a[10000],n,cnt;
	scanf("%d",&n);
	for(cnt=0;cnt<n;cnt++){
		scanf("%d",&a[cnt]);
		if(cnt==0){
			min=a[cnt];
			max=a[cnt];
		}
		else if(a[cnt]>max){
			max=a[cnt];
		}
		else if(a[cnt]<min){
			min=a[cnt];
		}
		sum+=a[cnt];
	}
	printf("%d %d %lld\n",min,max,sum);
	return 0;
}

Measured memory_bytes: 1068
n = int(input())

dp = [[0, 0, 0] for _ in range(n)]
a, b , c = map(int, input().split())
dp[0] = [a, b, c]
for i in range(n-1):
    a, b ,c = map(int, input().split())
    dp[i+1][0] = a + max(dp[i][1], dp[i][2])
    dp[i+1][1] = b + max(dp[i][0], dp[i][2])
    dp[i+1][2] = c + max(dp[i][0], dp[i][1])

print(max(dp[-1]))

Measured memory_bytes: 59568
#include<bits/stdc++.h>
#include<set>
#define lli long long int
using namespace std;
int main()
{
	lli a,i,b,p,q;
	cin>>a;
	cin>>b;
	p=a;
	q=b;
	for(i=0;i<q-1;i++){
		a=p+a*10;
	}
	for(i=0;i<p-1;i++)
		b=q+b*10;
	if(p>q)
	cout<<b;
	else if(p<q)
	cout<<a;
	else if(p==q)
	cout<<a;	
	return 0;
}

Measured memory_bytes: 3564
// AOJ 0633: Plush Toys
// 2017.12.5 bal4u@uu

#include <stdio.h>
#include <string.h>

int p[100002];
int f[22][100002], c[22];
int dp[1050000];

char buf[15], *bp;
int getInt()
{
	int n = 0;
	while (*bp >= '0') n = (n<<3) + (n<<1) + (*bp++ & 0xf);
	return n;
}

int main()
{
	int n, m, i, j, k, v, x, lim;

	fgets(bp=buf, 15, stdin);
	n = getInt(), bp++, m = getInt();
	for (i = 0; i < n; i++) {
		fgets(bp=buf, 15, stdin), v = getInt()-1;
		f[v][i+1]++, c[v]++;
	}
	for (i = 0; i < m; i++) for (j = 0; j < n; j++) f[i][j+1] += f[i][j];

	memset(dp, 0x55, sizeof(dp));
	dp[0] = 0, lim = 1 << m;
	for (i = 0; i < lim; i++){
		for (v = 0, j = 0; j < m; j++) if (i & (1<<j)) v += c[j];
		for (k = 1, j = 0; j < m; j++, k <<= 1) if (!(i & k)) {
			x = dp[i] + c[j] - f[j][v + c[j]] + f[j][v];
			if (dp[i+k] > x) dp[i+k] = x;
		}
	}
	printf("%d\n",dp[lim-1]);
	return 0;
}

Measured memory_bytes: 13708
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <functional>
#include <stack>
#include <numeric>
typedef long long ll;
using namespace std;
const int MOD = (int)1e9 + 7;
const ll INF = (ll)1e18 + 7;
#define int long long
#define vint vector<int>
#define pint pair<int,int>
#define pb(a) push_back(a)
#define all(v) v.begin(),v.end()
#define dbg(x) cerr << #x << " = " << (x) << endl
#define yn(b) cout << ((b) ? "Yes" : "No") << endl
#define YN(b) cout << ((b) ? "YES" : "NO") << endl

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

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

	int r = 0, b = 0;
	string S;
	int N;

	cin >> N >> S;

	for(int i = 0; i < N; i++)
	{
		if(S[i]=='R'){
			r++;
		}else{
			b++;
		}
	}

	yn(r > b);

	return 0;
}

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

int main()
{
    int n, m;
    const long int MOD = 1E9+7;
    long long int a = 0, b = 0, x, y;

    cin >> n >> m;

    for (int i = 0; i < n; i++) {
        cin >> x;
        a += (x*(i-(n-i-1)));
        a %= MOD;
    }
    for (int i = 0; i < m; i++) {
        cin >> y;
        b += (y*(i-(m-i-1)));
        b %= MOD;
    }
    cout << (a*b)%MOD << endl;

	return 0;
}


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

#define ld long double
#define ll long long int
#define ull unsigned long long int

using namespace std;

int main() {

    int X;
    cin >> X;
    int max;

    // X以下のべき乗数を求める -> X以下の最大のべき乗数を求める
    for (int b = 1; b <= 32; ++b) {
        for (int p = 2; p <= 10; ++p) {
            int pow = std::pow(b, p);
//            if (pow > X) {
//                break;
//            }

            if (max < pow && pow <= X) {
                max = pow;
            }
        }

    }

    cout << max << endl;

}

Measured memory_bytes: 384
#include<stdio.h>

int main(void)
{
	int a, b, d, r;
	double f;
	scanf("%d %d", &a, &b);
	d = a / b;
	r = a % b;
	f = (double)a / (double)b;
	printf("%d %d %f\n", d, r, f);

	return 0;
}

Measured memory_bytes: 632
<?php
    $N = fgets(STDIN);
    $A = explode(' ', trim(fgets(STDIN)));
	$B = explode(' ', trim(fgets(STDIN)));
	$C = explode(' ', trim(fgets(STDIN)));
	$ans = array_sum($B);
	for($i = 0, $size = count($A); $i < $size; ++$i) {
      	if($i < $size-1){
          if($A[$i]+1 == (int)$A[$i+1]){
			$ans+=$C[$A[$i]-1];
          }
        }
	}
	echo $ans;
?>


Measured memory_bytes: 4728
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
#include <map>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<29;

typedef pair<int,int> pii;
typedef pair<pii, pii> piiii;

int X, Y;
int ba[50][50];

int dtx[] = {0,1,0,-1};
int dty[] = {-1,0,1,0};
int dkx[] = {0,-1,0,1};
int dky[] = {1,0,-1,0};

int solve(pii T, pii K) {
  map<piiii, bool> visited;
  queue<pair<piiii, int> > Q;
  Q.push(make_pair(piiii(T,K), 0));
  while(Q.size()) {
    pii tt = Q.front().first.first, kk = Q.front().first.second;
    int m = Q.front().second;
    Q.pop();
    if (visited[piiii(tt,kk)]) continue;
    if (m >= 100) break;
    if (tt == kk) return m;
    visited[piiii(tt,kk)] = true;
//    cout << tt.first << ","<<tt.second<<" " << kk.first<<","<<kk.second << endl;
    REP(k,4) {
      int txx = tt.first + dtx[k];
      int tyy = tt.second + dty[k];
      int kxx = kk.first + dkx[k];
      int kyy = kk.second + dky[k];

      if (txx < 0 || X <= txx || tyy < 0 || Y <= tyy || ba[txx][tyy]) {
        txx -= dtx[k];
        tyy -= dty[k];
      }
      if (kxx < 0 || X <= kxx || kyy < 0 || Y <= kyy || ba[kxx][kyy]) {
        kxx -= dkx[k];
        kyy -= dky[k];
      }
      if (!visited[piiii(pii(txx, tyy),pii(kxx, kyy))])
        Q.push(make_pair(piiii(pii(txx, tyy), pii(kxx, kyy)), m+1));
    }
  }
  return -1;
}

int main() {
  while(cin >> X >> Y, X||Y) {
    int tx, ty, kx, ky;
    cin >> tx >> ty;
    cin >> kx >> ky;
    tx--;ty--;kx--;ky--;
    REP(y,Y)
      REP(x,X)
        cin >> ba[x][y];
    int res = solve(pii(tx,ty), pii(kx,ky));
    if (res < 0)
      cout << "NA" << endl;
    else
      cout << res << endl;
  }
}

Measured memory_bytes: 8040
#include <stdio.h>
int main(){
  int i,cc[26]={0};
  char c,sl;
  while(scanf("%c",&c)!=EOF){
    if(c>='A'&&c<='Z')c+='a'-'A';
    if(c>='a'&&c<='z')cc[c-'a']++;
  }
  for(i=0;i<26;i++){
    printf("%c : %d\n",'a'+i,cc[i]);
  }
  return 0;
}

Measured memory_bytes: 540
n, m = map(int, input(). split())
b = set()
i = 1
while i * i <= m:
    if m % i == 0:
        b.add(i)
        b.add(m // i)
    i += 1
ans = 1
for i in b:
    if i * n <= m:
        ans = max(ans, i)
print(ans)


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

class segmenttree{
    private:
    int n;
    long long identity = 0;//単位元
    std::vector<long long> dat;
    public:
    
    void init(int N){
        n=1;
        while(n<N)n*=2;
        dat.clear();
        for(int i=0;i<2*n-1;++i){
            dat.push_back(identity);
        }
    }
    
    long long calc();
    
    void update(int k,long long a){
        k+=n-1;
        dat[k]=a;
        while(k>0){
            k=(k-1)/2;
            dat[k]=calc(dat[2*k+1],dat[2*k+2]);
        }
    }
    
    long long query(long long a,long long b){
        a+=n;
        b+=n;
        long long R=0;
        while(a < b){
            if(a % 2 == 1){
                R = calc(R, dat[a - 1]);
                a += 1;
            }
            a /= 2;
            if(b % 2 == 1){
                b -= 1;
                R = calc(R, dat[b - 1]);
            }
            b /= 2;
        }
        return R;
    }
    
    long long calc(long long a,long long b){
        if(a<b)swap(a,b);
        if(a<=0)return 0;
        if(b<=0)return a;
        long long r = a%b;
        while(r){
            a=b;
            b=r;
            r=a%b;
        }
        return b;
    }
    
};


int main(){
    
    int N;
    int A[214514];
    cin >> N;
    REP(i,N){cin >> A[i];}
    
    segmenttree Seg;
    Seg.init(N);
    REP(i,N){
        Seg.update(i,A[i]);
    }
    
    long long Ans=0;
    for(int i=0;i<N;i++){
        long long l=Seg.query(0,i);
        long long r=Seg.query(i+1,N); 
        Ans=std::max(Ans,Seg.calc(l,r));
    }
    cout << Ans << endl;
    
    return 0;
}

Measured memory_bytes: 2804
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf,comb
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
from functools import reduce
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

n = INT()
a = LIST()
b = [0]*n
k = 0
for i in range(n//2):
    k += 2*a[2*i+1]
b[0] = sum(a) - k

for i in range(1, n):
    b[i] = 2*a[i-1] - b[i-1]
print(*b)

Measured memory_bytes: 22168
a=input()
b=input()
c=len(a)
d=len(b)
if c>d:
  print("GREATER")
elif c<d:
  print("LESS")
else:
  flag=0
  for i in range(c):
    if int(a[i])>int(b[i]):
      print("GREATER")
      flag=1
      break
    elif int(a[i])<int(b[i]):
      print("LESS")
      flag=1
      break
    else:
      continue
  if flag==0:
    print("EQUAL")


Measured memory_bytes: 3060
# include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 100;
int R[N], G[N], B[N]; 
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n, sum = 'R' + 'G' + 'B';
	long long ans = 0;
	string s;
	cin >> n >> s;
	for(int i = n - 1; i >= 0; i--){
		R[i] = R[i + 1] + (s[i] == 'R');
		G[i] = G[i + 1] + (s[i] == 'G');
		B[i] = B[i + 1] + (s[i] == 'B');
	}
	for(int i = 0; i < n; i++){
		for(int j = i + 1; j < n; j++){
			int d = j - i;
			if(s[i] == s[j])continue;
			if(s[i] + s[j] + 'R' == sum){
				ans += R[j];
			}
			if(s[i] + s[j] + 'G' == sum){
				ans += G[j];
			}
			if(s[i] + s[j] + 'B' == sum){
				ans += B[j];
			}
			if(j + d < n && s[i] != s[j + d] && s[j] != s[j + d])ans--;
		}
	}
	cout << ans << '\n';
}

Measured memory_bytes: 3680
#include <iostream>
#include <vector>

int main() {
    int n;
    std::vector<int> v;

    std::cin >> n;

    int sum = 0;
    for (int i = 0; i < n; i++) {
        int m;

        std::cin >> m;
        v.push_back(m);

        sum += n;
    }

    int min = 100000000;
    for (int p = 1; p <= 100; p++) {
        int ans = 0;
        for (auto x : v) {
            ans += (x - p) * (x - p);
        }
        if (ans < min) {
            min = ans;
        }
    }

    std::cout << min << std::endl;

    return 0;
}

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

using namespace std;

using ll = long long;

constexpr char newl = '\n';

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

    int K, a, b;
    cin >> K >> a >> b;

    bool f = false;
    for (int i = a; i <= b; i++) {
        if (i % K == 0) {
            f = true;
            break;
        }
    }
    cout << (f ? "OK" : "NG") << newl;

    return 0;
}

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

using namespace std;

int main()
{
	long long A, B, N;

	cin >> A >> B >> N;
	long long result = 0;
	long long count = 0;
	long long x = 1;
	long long tmp = 0;
	long long tmp2 = 0;


	if (A <= B && B < N)
	{
		long long num = B - 1;
		tmp = floor((A * num) / B) - A * floor(num / B);
		cout << tmp << endl;
		return 0;
	}
	else if (A <= B && B > N)
	{
		tmp = floor((A * N) / B) - A * floor(N / B);
		cout << tmp << endl;
		return 0;
	}
	else if (A <= B && B == N)
	{
		long long num = N - 1;
		tmp = floor((A * num) / B) - A * floor(num / B);
		cout << tmp << endl;
		return 0;
	}
	else if (A > B && B < N) {
		tmp = floor((A * B) / B) - A * floor(B / B);
		cout << tmp << endl;
		return 0;
	}
	else if (A > B && B == N)
	{
		long long num = N - 1;
		tmp = floor((A * num) / B) - A * floor(num / B);
		cout << tmp << endl;
		return 0;
	}
	else {
		tmp = floor((A * N) / B) - A * floor(N / B);
		cout << tmp << endl;
		return 0;
	}

}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
#define vll vector<ll>
#define vi vector<int>
#define vpll vector<pair<ll,ll>>
#define pii pair<int,int>
#define REP(i,a) for(int (i)=0; (i)<(a); (i)++)
#define RREP(i,a) for(int (i)=a-1; (i)>=(0); (i)--)
#define REP2(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
#define m0(x) memset(x,0,sizeof(x))
typedef long long ll;

using namespace std;
char f(char s, char r){
    if('r'!=s && 'r' != r) return 'r';
    else if('s'!=s && 's' != r) return 's';
    else if('p'!=s && 'p' != r) return 'p';
}
ll N, K ,R, S, P;
ll point(char r){
 	if(r == 'r') return R;
    else if(r == 's') return S;
    else if(r == 'p') return P; 
}

int main(){//累積和
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  cin >> N >> K;
  cin >> R >> S >> P;
  string T;
  cin >> T;
  char S[N];
  REP(i,N){
    if(T[i] == 'r') S[i] = 'p';
    if(T[i] == 's') S[i] = 'r';
    if(T[i] == 'p') S[i] = 's';
  }
  ll ans = 0;
  char a[N];
  REP(i,N){
    char tmp;
    if(i-K < 0){ //前を気にしないとき
      a[i] = S[i];
      ans += point(S[i]);
    }else if(a[i-K] == S[i]){ //前のせいで勝てないとき
      if(i+K <= N-1) a[i] = f(S[i+K], S[i-K]);
      else a[i] = f(S[i-K], 'z');
    }else{
      a[i] = S[i];
      ans += point(S[i]);
    }
  }
  cout << ans;

  return 0;
}

Measured memory_bytes: 848
//Bismillahir Rahmanir Rahim 
#include<bits/stdc++.h>

using namespace std;

#define ll long long 
#define gcd(a,b) __gcd(a,b)
#define endl '\n'
const int N=2e5+10;
const int inf=1e9;
const int mod=1e9+7;

int  main(int argc, char const *argv[])
{
	#ifndef ONLINE_JUDGE
      freopen("input.txt","r",stdin);
      freopen("output.txt","w",stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(0);

	int h, w;
	cin >> h >> w;

	int a[h+1][w+1];

	vector<pair<pair<int,int>,pair<int,int>>>ans;

	for(int i=1; i<=h; i++)
	{
		for(int j=1; j<=w; j++)
			cin >> a[i][j];
	}

	for(int i=1; i<=h; i++)
	{
		for(int j=1; j<w; j++)
		{
			if(a[i][j] & 1)
			{
				a[i][j]--;
				a[i][j+1]++;
				ans.push_back({{i, j}, {i, j+1}});
			}
		}
	}

	for(int i=1; i<h; i++)
	{
		for(int j=1; j<=w; j++)
		{
			if(a[i][j] & 1)
			{
				a[i][j]--;
				a[i+1][j]++;
				ans.push_back({{i, j}, {i+1, j}});
			}
		}
	}

	/*for(int i=1; i<=h; i++)
	{
		for(int j=1; j<=w; j++)
			cout << a[i][j] << ' ';
		cout << endl;
	}*/

	cout << ans.size() << endl;

	for(auto it: ans)
		cout << it.first.first << " " << it.first.second << ' ' << it.second.first << " " << it.second.second << endl;
	
	return 0;
}

Measured memory_bytes: 6236
from bisect import bisect

n = int(input())
x = list(map(int, input().split()))
l = int(input())
q = int(input())

#r[i][j]: jから(2**i)日で行ける右端
r = [[i for i in range(n)] for _ in range(18)]
for j in range(n):
	r[0][j] = bisect(x, x[j]+l) - 1
for i in range(1, 18):
	for j in range(n):
		r[i][j] = r[i-1][r[i-1][j]]

def search(x, y):
	res = 0
	cur = x
	i = 17
	while True:
		if i == 0 and r[i][cur] >= y:
			return res+1
		if r[i][cur] < y:
			cur = r[i][cur]
			res += 1 << i
			continue
		i -= 1

for _ in range(q):
	a, b = map(int, input().split())
	print(search(min(a, b)-1, max(a, b)-1))

Measured memory_bytes: 79060
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String a = sc.nextLine();
		int w = sc.nextInt();
		String[] array = a.split("");
		for(int i=0;i<array.length;i++) {
			if((i%w)==0)System.out.print(array[i]);
		}
	return ;
	}
}

Measured memory_bytes: 21716
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int INF = 1000000000;

int main() {
    int N, K;
    cin >> N >> K;
    vector<int>A(N);
    for (int i=0; i<N; i++)cin >> A[i];

    for (int i=K; i<N; i++){
        if (A[i] > A[i-K])cout << "Yes" << endl;
        else cout << "No" << endl;
    }

}

Measured memory_bytes: 4052
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

S = input()

front = int(S[0:2])
rear = int(S[2:4])

if 1 <= front <= 12:
	if 1 <= rear <= 12:
		print("AMBIGUOUS")
	else:
		print("MMYY")
else:
	if 1 <= rear <= 12:
		print("YYMM")
	else:
		print("NA")

Measured memory_bytes: 60140