akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;

int main() { 
    int n, k;
    cin >> n >> k;
    if (k > (n - 1) * (n - 2) / 2) {
        cout << -1 << endl;
        return 0;
    }
    vector<vector<int>> res(n + 1, vector<int>(0));
    int l = 0;
    for (int i = 2; i <= n; i++) {
        res[1].push_back(i);
        l++;
    }
    k -= (n - 1) * (n - 2) / 2;
    for (int i = 2; i <= n; i++) {
        for (int j = i + 1; j <= n && k < 0; j++) {
            res[i].push_back(j);
            k++;
            l++;
        }
    }
    cout << l << endl;
    for (int i = 1; i <= n; i++) {
        for (auto next : res[i]) {
            cout << i << " " << next << endl;
        }
    }
}




Measured memory_bytes: 3664
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
    }
    ll M = 1000000007;
    ll ans = 1;
    unordered_map<int, int> cnt;
    cnt[-1] = 3;
    for (int i = 0; i < N; ++i) {
        ans = (ans * (cnt[A[i] - 1] - cnt[A[i]]++)) % M;
        // cout << A[i] << " " << ans << endl;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4772
#include <stdio.h>
#include <stdlib.h>
#define INFTY 1000000001
void mergeSort(int [],int,int);
void merge(int [],int,int,int);
int count = 0;
int A[500002];
int L[250001];
int R[250001];

int main(){
    int n,i;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&A[i]);
    }
    mergeSort(A,0,n);
    for(i=0;i<n;i++){
        if(i<n-1) printf("%d ",A[i]);
        else printf("%d\n",A[i]);
    }
    printf("%d\n",count);
    return 0;
}
void merge(int A[],int left,int mid,int right){
    int n1,n2,i,j,k;
    /*int *L;
    int *R;*/
    n1 = mid - left;
    n2 = right - mid;
    /*L = calloc(n1,sizeof(int));
    R = calloc(n2,sizeof(int));*/
    for(i=0;i<n1;i++){
        L[i] = A[left + i];
    }
    for(i=0;i<n2;i++){
        R[i] = A[mid+i];
    }
    L[n1] = INFTY;
    R[n2] = INFTY;
    i = 0;
    j = 0;
    for(k = left;k<right;k++){
        if(L[i] <= R[j]){
            A[k] = L[i];
            i = i + 1;
            count++;
        }
        else{
            A[k] = R[j];
            j = j + 1;
            count++;
        }
    }
    /*free(L);
    free(R);*/
}
void mergeSort(int A[],int left,int right){
    int mid;
    if(left+1 < right){
        mid = (left + right)/2;
        mergeSort(A,left,mid);
        mergeSort(A,mid,right);
        merge(A,left,mid,right);
    }
}


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

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

    sort(d.begin(), d.end());

    int ans = d.at(n / 2) - d.at(n / 2 - 1);
    cout << ans << endl;
}

Measured memory_bytes: 640
s = input()

s_sum = [0] * len(s)
cnt = 0
for i in range(len(s)):
    if s[i] == "R":
        cnt += 1
    else:
        x = cnt // 2
        if i > 0:
            s_sum[i-1] += x + (cnt % 2)
        s_sum[i] += x
        cnt = 0
        
cnt = 0
for i in range(len(s)-1, -1, -1):
    if s[i] == "L":
        cnt += 1
    else:
        x = cnt // 2
        if i < len(s):
            s_sum[i+1] += x + (cnt % 2)
        s_sum[i] += x
        cnt = 0

print(" ".join(str(n) for n in s_sum))

Measured memory_bytes: 10484
#include <bits/stdc++.h>
using namespace std;
int main(void){
  int x[5],y[5];
  cin>>x[1]>>y[1]>>x[2]>>y[2];
  x[3]=x[2]-(y[2]-y[1]);
  y[3]=y[2]+(x[2]-x[1]);
  x[4]=x[3]-(y[3]-y[2]);
  y[4]=y[3]+(x[3]-x[2]);
  cout<<x[3]<<' '<<y[3]<<' '<<x[4]<<' '<<y[4];
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#define sqr(x) (x)*(x)
using namespace std;
long long n,m,i,j,k,l,dp[405][405],mi[405],mx[405],mod=1e9+7,sum[405],mqp[405][405];
long long qp(long long x,long long y)
{
	if (y==0)
	{
		return 1;
	}
	if (y==1)
	{
		return x;
	}
	long long z=qp(x,y/2);
	z=z*z%mod;
	if (y&1) z=z*x%mod;
	return z;
}
int main()
{
	cin>>n>>m;
	for (i=1;i<=n;i++) cin>>mi[i];
	for (i=1;i<=n;i++) cin>>mx[i];
	dp[0][0]=1;
	for (i=0;i<=400;i++)
	{
		for (j=0;j<=400;j++)
		{
			mqp[i][j]=qp(i,j);
		}
	}
	for (i=1;i<=n;i++)
	{
		memset(sum,0,sizeof(sum));
		for (k=0;k<=m;k++)
		{
			for (l=mi[i];l<=mx[i];l++)
			{
				sum[k]=(sum[k]+mqp[l][k])%mod;
			}
		}
		for (j=0;j<=m;j++)
		{
			for (k=0;k<=j;k++)
			{
				dp[i][j]=(dp[i][j]+dp[i-1][j-k]*sum[k])%mod;
			}
		}
	}
	cout<<dp[n][m];
	return 0;
}

Measured memory_bytes: 2816
k,n = map(int,input().split())
A = list(map(int,input().split()))
d = 0
m = k - abs(A[-1] - A[0])
pre = A[0]
for i in range(1,n):
    d = max(d,m)
    m = A[i]-pre
    pre = A[i]
d = max(d,m)
print(k-d)


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

int main()
{
  long N,A,B;
  cin>>N>>A>>B;
  if((B-A)%2==0)cout<<(B-A)/2<<endl;
  else cout<<min(A+(B-A)/2,N-B+1+(B-A)/2)<<endl;
}


Measured memory_bytes: 256
n, k = list(map(int, input().split()))
d = list(map(int, input().split()))
if 0 in d:
    zero = True
else:
    zero = False

n_ok = {0} | set([0,1,2,3,4,5,6,7,8,9]) - set(d)
n_oks = sorted(n_ok)
#print(n_oks)

def lowest():
    for i in n_oks:
        for j in n_oks:
            for k in n_oks:
                for l in n_oks:
                    for m in n_oks:
                        money = 10000*i +1000*j + 100*k + 10*l + m
                        if money >= n:
                            if zero:
                                if 0 in [i,j,k,l,m] and i != 0:
                                    continue
                                elif 0 in [j,k,l,m] and j != 0:
                                    continue
                                elif 0 in [k,l,m] and k != 0:
                                    continue
                                elif 0 in [l,m] and l != 0:
                                    continue
                            print(money)
                            return

lowest()

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<cstdio>
using namespace std;
int main(void){
  string s;
  char c;
  for(;;){
    cin >> s >> c;
    if(c=='X') break;
    if(s[0]>='A' && s[0]<='Z') s[0]+=32;
    for(int i=1;i<s.size();i++){
      if(s[i]=='_') s[i]=' ';
      else if(s[i]>='A' && s[i]<='Z'){
	s[i]+=32;
	s.insert(i," ");
      }
    }
    if(c=='L'){
      for(int i=0;i<s.size();i++){
	if(s[i]==' ') continue;
	if(i!=0 && s[i-1]==' ') printf("%c",s[i]-32);
	else cout << s[i];
      }
    }
    else if(c=='U'){
      for(int i=0;i<s.size();i++){
	if(s[i]==' ') continue;
	if(i==0 || s[i-1]==' ') printf("%c",s[i]-32);
	else cout << s[i];
      }
    }
    else if(c=='D'){
      for(int i=0;i<s.size();i++){
	if(s[i]==' ') cout << "_";
	else cout << s[i];
      }
    }
    cout << "\n";
  }
}


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

class D
{
	static int[] Read() => Console.ReadLine().Split().Select(int.Parse).ToArray();
	static void Main()
	{
		var h = Read();
		var n = h[0];
		var pq = new int[h[1]].Select(_ => Read()).ToArray();
		var rs = new int[h[2]].Select(_ => Read()).ToArray();

		var uf1 = new UF(n);
		var uf2 = new UF(n);
		foreach (var x in pq) uf1.Unite(x[0], x[1]);
		foreach (var x in rs) uf2.Unite(x[0], x[1]);

		var r = new int[n + 1];
		var q = Enumerable.Range(1, n).Select(i => (i, g: (uf1.GetRoot(i), uf2.GetRoot(i)))).GroupBy(x => x.g).Select(g => g.ToArray());
		foreach (var g in q)
			foreach (var (i, _) in g)
				r[i] = g.Length;
		Console.WriteLine(string.Join(" ", r.Skip(1)));
	}
}

class UF
{
	int[] p;
	public UF(int n) { p = Enumerable.Range(0, n + 1).ToArray(); }

	public void Unite(int a, int b) { if (!AreUnited(a, b)) p[p[b]] = p[a]; }
	public bool AreUnited(int a, int b) => GetRoot(a) == GetRoot(b);
	public int GetRoot(int a) => p[a] == a ? a : p[a] = GetRoot(p[a]);
	public int[][] ToGroups() => Enumerable.Range(0, p.Length).GroupBy(GetRoot).Select(g => g.ToArray()).ToArray();
}


Measured memory_bytes: 60484
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define Sort(Array) sort(Array.begin(), Array.end())
#define Reverse(a) reverse(a.begin(), a.end())
#define out(ans) cout << ans << endl;
const int MOD = 1000000007;
const int INF = 2147483647;
const ld PI = 3.14159265358979323846;

//------------↓------------- M -------------- E ---------------- M --------------- O ---------------↓--------------//
// コンパイル 
// g++ -std=c++1z
//
// -------型変換--------
// int を string に変換
// string s = to_string(n);
// string を int に変換
// int n = stoi(s);
//
// -------二分探索---------
// k以上の値が最初に現れる時のイテレータ
// lower_bound(data.begin(), data.end(), k)
// kより大きい値が最初の現れる時のイテレータ O(logN)
// upper_bound(data.begin(), data.end(), k)
// kがdataに存在するかをtrue or falseで返す O(logN)
// binary_search(data.begin(), data.end(), k)
// 
//
//
//
//
//
// 
//------------↑------------- M -------------- E ---------------- M --------------- O ---------------↑--------------//






int main(void) {
    
    int n, m, c; cin >> n >> m >> c;
    int b[m]; rep(i,m) cin >> b[i];
    int a[n][m];
    rep(i,n) {
        rep(j,m) cin >> a[i][j];
    }
    int ans = 0;
    rep(i,n) {
        int sum = c;
        rep(j,m) sum += a[i][j] * b[j];
        if (sum > 0) ++ans;
    }
    out(ans);
    
    return 0;
}






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

using namespace std;
using ll = long long;

#pragma region Macros
#define FOR(i, m, n) for (ll i = (ll)(m); i < (ll)(n); i++)
#define rep(i, n) FOR(i, 0, n)

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

template <class T> string join(const T &v, const string delim = ",")
{
    if (v.empty())
        return "";

    ostringstream res;
    res << v[0];
    for (int i = 1; i < v.size(); i++)
    {
        res << delim << v[i];
    }
    return res.str();
}

#pragma endregion Macros

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

    ll all = 0;
    vector<ll> a(N);
    rep(i,N){
        cin >> a[i];
        all ^= a[i];
    }

    vector<ll> ans(N);
    rep(i,N){
        ans[i] = (all ^ a[i]);
    }

    cout << join(ans, " ") << endl;
}


Measured memory_bytes: 10724
use std::collections::HashMap;

use proconio::fastout;
use whiteread::parse_line;

#[fastout]
fn main() {
    let mut map: HashMap<String, isize> = HashMap::new();

    let n: usize = parse_line().unwrap();
    for _ in 0..n {
        let s: String = parse_line().unwrap();
        let entry = map.entry(s).or_insert(0);
        *entry += 1;
    }

    let m: usize = parse_line().unwrap();
    for _ in 0..m {
        let t: String = parse_line().unwrap();
        let entry = map.entry(t).or_insert(0);
        *entry -= 1;
    }

    let ret = map.values().into_iter().fold(0, |a, b| a.max(*b));
    println!("{}", ret);
}


Measured memory_bytes: 2156
#include <iostream>
#include <string>
#include <stdio.h>
#include <cmath>
#include <cfloat>
#include <algorithm>
#include <numeric>
#include <vector>
#include <iterator>
#include <set>
#include <map>
using namespace std;

const double PI=acos(-1);

int main(){
    int x;
    cin >> x;
    vector<int> l;
    for(int i = 1; i * i <= x; i++){
        if(x%i == 0){
            l.push_back(i);
            if(i*i != x) l.push_back(x/i);
        }
    }
    sort(l.begin(), l.end());
    bool z = false;
    for(int a = (pow(x, 0.25)-1) * -1; pow(a, 4) <= x; a++){
        for(int b = (pow(x, 0.25)-1) * -1; pow(b, 4) <= x; b++){
            double hoge = pow(a,4) + pow(a,3)*b + pow(a,2)*pow(b,2) + a*pow(b,3) + pow(b,4);
            hoge *= (a-b);
            if(fabs((double)x - hoge) <= DBL_EPSILON){
                cout << a << " " << b << endl;
                z = true;
                break;
            }
        }
        if(z) break;
    }
    return 0;
}

Measured memory_bytes: 4072
def is_prime(n):
    if n == 1:
        return False
    if n == 2:
        return True

    limit = n ** 0.5
    for i in range(2 , n):
        if n % i == 0:
            return False
        if i >= limit: 
            return True

x = int(input())

n = x

while True:
    if is_prime(n):
        break
    n += 1

print(n)

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <algorithm>
#include <set>
#include <stack>
#include <deque>
#include <cmath>
#include <map>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < n; i++)
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;}

int main() {
    ll n, x;
    cin >> n >> x;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];

    sort(a.begin(), a.end());
    ll ans = 0;
    rep(i, n) {
        if (x >= a[i]) {
            ans++;
            x -= a[i];
        }
        else {
            x -= a[i];
            break;
        }
    }
    if (x > 0) ans--;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int a[3];
  int x=0,y=0;
  for(int i=0;i<3;i++)
  {
    cin>>a[i];
    if(a[i]==5)
    {
      x++;
    }
    else y++;
  }
  if(x==2)
  {
    cout<<"YES";
  }
  else 
    cout<<"NO";
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

void fc(vector<vector<int>> &ind, vector<set<int>> &in, int now, int ta, vector<int> &ans, int mxsize){
  if(now == ta) return ;
  if(ans.size() > mxsize) return ;
  for(auto i : ind.at(now)){
    if(in.at(i).find(ta) == in.at(i).end()) continue;
    ans.push_back(i);
    fc(ind, in, i, ta, ans, mxsize);
    break;
  }
  return ;
}

int main(){
  int n, m;
  cin >> n >> m;
  vector<set<int>> in(n);
  vector<vector<int>> ind(n);
  vector<int> fans;
  rep(i, m){
    int a, b;
    cin >> a >> b;
    a--; b--;
    in.at(b).insert(a);
    ind.at(b).push_back(a);
    for(auto j : in.at(a)){
      in.at(b).insert(j);
    }
    if(in.at(a).find(b) != in.at(a).end()){
      vector<int> ans;
      ans.push_back(a);
      int mxsize = 1001001001;
      if(fans.size() != 0) mxsize = fans.size();
      fc(ind, in, a, b, ans, mxsize);
      if(fans.size() == 0 || fans.size() > ans.size()) fans = ans;
    }
  }
  if(fans.size() > 0){
    cout << fans.size() << endl;
    for(auto j : fans){
      cout << j + 1 << endl;
    }
  }else cout << -1 << endl;
  return 0;
}


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

signed main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);

    std::string s;
    std::cin >> s;

    if (s.back() == 's') std::cout << s << "es";
    else std::cout << s << 's';

    return 0;
}



Measured memory_bytes: 3572
import heapq
from collections import deque
from enum import Enum
import sys
import math
from _heapq import heappush, heappop
import copy

BIG_NUM = 2000000000
HUGE_NUM = 99999999999999999
MOD = 1000000007
EPS = 0.000000001
sys.setrecursionlimit(100000)


input_str = input()

length = 0
work = deque()
is_First = True

for i in range(len(input_str)):
    ch = input_str[i]
    if ch in [' ',',','.'] or i == len(input_str)-1: #区切り文字または最後の文字
        if length >= 3 and length <= 6:
            if is_First == False:
                print(" ",end="")

            while len(work) > 0:
                print("%s"%(work.popleft()),end="")
            is_First = False
        else:
            while len(work) > 0:
                work.popleft()
        length = 0
    else:
        work.append(ch)
        length += 1
print()



Measured memory_bytes: 6376
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

void solve(int n,int m){
    set<int> a,b;
    int A = 0,B = 0;
    rep(i,n){
        int x;
        cin>>x;
        A+=x;
        a.insert(x);
    }
    rep(i,m){
        int x;
        cin>>x;
        B+=x;
        b.insert(x);
    }
    int diff=B-A;
    if(diff%2){
        cout<<-1<<endl;
        return;
    }
    for(auto e : a){
        if(b.count(diff/2+e)){
            cout<<e<<" "<<e+diff/2<<endl;
            return;
        }
    }
    cout<<-1<<endl;
    return;
}
int main(){
    int n,m;
    while(cin>>n>>m,n!=0){
        solve(n,m);
    }
    return 0;
}


Measured memory_bytes: 3044
#include<iostream>
using namespace std;
int main()
{ 
  int x1,x2,x3,x4,x5;
 cin>>x1>>x2>>x3>>x4>>x5;
 if(x1!=1)
 { cout<<"1";
  return 0;
 }
 if(x2!=2)
 {cout<<"2";
  return 0;}
  if(x3!=3)
  {cout<<"3";
    return 0;}
  if(x4!=4)
    {cout<<"4";
   return 0;}
  if(x5!=5)
    cout<<"5";
  return 0;}

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

# 数値→アルファベット
def num2alpha(num):
    if num<=26:
        return chr(64+num)
    elif num%26==0:
        return num2alpha(num//26-1)+chr(90)
    else:
        return num2alpha(num//26)+chr(64+num%26)

print(num2alpha(n).lower())

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

#define fr(i, a, b) for(int i = (a); i <= (b); i++)
#define rf(i, a, b) for(int i = (a); i >= (b); i--)
#define fe(x, y) for(auto& x : y)

#define fi first
#define se second
#define pb push_back
#define mp make_pair

#define pw(x) (1LL << (x))
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()

using namespace std;

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<typename T>
using ve = vector<T>;

#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<typename T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define fbo find_by_order
#define ook order_of_key

mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());

template<typename T>
bool umn(T& a, T b) { return a > b ? a = b, 1 : 0; }
template<typename T>
bool umx(T& a, T b) { return a < b ? a = b, 1 : 0; }

int main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
#endif
 
    int n;
    cin >> n;
    cout << (n + 999) / 1000 * 1000 - n << "\n";

    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  char c;
  cin >> c;
  
  if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') cout << "vowel";
  else cout << "consonant"; 
}

Measured memory_bytes: 256
use std::vec::Vec;
use std::cmp::*;

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(|e| e.parse().ok().unwrap()).collect()
}

fn main() {
  let n: usize = read();
  let mut a: Vec<u64> = read_vec();

  // 降順にソート
  a.sort_by(|a, b| b.cmp(&a));

  let v = count_same_element(&a);

  let mut x = 0;
  let mut y = 0;
  let mut num = 0;

  for &e in &v {
    if num == 2 {
      break;
    }

    if e.1 >= 4 && num == 0 {
      num = 2;
      x = e.0;
      y = e.0;
    }

    if e.1 >= 2 && num == 0 {
      num += 1;
      x = e.0;
    } else if e.1 >= 2 && num == 1 {
      num += 1;
      y = e.0;
    }
  }
  println!("{}", x * y);
}

fn count_same_element<T: Eq + Copy>(v: &Vec<T>) -> Vec<(T, usize)> {

  let mut res: Vec<(T, usize)> = Vec::new();
  if v.len() == 0 {
    return res;
  }

  let mut now: T = v[0];
  let mut count: usize = 0;
  for &e in v {
    if e == now {
      count += 1;
    }
    else {
      res.push((now, count));
      count = 1;
      now = e;
    }
  }
  res.push((now, count));

  return res;
}


Measured memory_bytes: 11512
def main():
    n = int(input())
    h = list(map(int, input().split()))

    cost_dp = [0] * n
    cost_dp[1] = abs(h[0] - h[1])
    for i in range(2,n):
        cost_dp[i] = min(cost_dp[i-2]+abs(h[i]- h[i-2]),cost_dp[i-1]+abs(h[i]-h[i-1]))
    print(cost_dp[n-1])

if __name__ == '__main__':
    main()


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

char a[1 << 10][1 << 10];

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int H, W; cin >> H >> W;
	for (int i = 1; i <= H; i++) cin >> a[i];
	for (int i = 1; i <= H * 2; i++) {
		for (int j = 0; j < W; j++) cout << a[(i + 1) / 2][j];
		cout << endl;
	}
	return 0;
}


Measured memory_bytes: 3684
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
int score[101];

int main(){
  int n;
  cin>>n;
  
  
  for(int i=0;i<n;i++)
    for(int j=i+1;j<n;j++){
      int a,b,c,d;
      cin>>a>>b>>c>>d;
      a--,b--;
      if(c>d) score[a]+=3;
      else if(c<d)score[b]+=3;
      else score[a]++,score[b]++;
    }

  for(int i=0;i<n;i++){
    int Rank=1;
    for(int j=0;j<n;j++){
      if(score[i]<score[j])Rank++;
    }
    cout <<Rank<<endl;
  }

  return 0;
}

Measured memory_bytes: 1160
#include "bits/stdc++.h"
using namespace std;

const int offset = 1 << 20;
int st[2 * offset];
int in[offset];

int minimum(int a, int b) {
    a += offset;
    b += offset;

    int rv = 1e9 + 7;
    while(a <= b) {
        if(a % 2 == 1) rv = min(rv, st[a++]);
        if(b % 2 == 0) rv = min(rv, st[b--]);
        a /= 2; b /= 2;
    }
    return rv;
}


int main() {
    int n, k;
    scanf("%d %d", &n, &k);

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

    for(int i = offset - 1; i >= 1; i--) st[i] = min(st[i * 2], st[i * 2 + 1]);

    int maxx = 0;
    for(int i = 1; i < n; ++i) {
        int v = minimum(0, i - 1);
        if(in[i] - v > maxx) {
           maxx = in[i] - v;
        }
    }

    int res = 0;
    unordered_set< int> st;
    st.insert(in[0]);
    for(int i = 1; i < n; ++i) {
        if(st.count(in[i] - maxx)) res++;
        st.insert(in[i]);
    }
    printf("%d\n", res);
}

Measured memory_bytes: 10916
import Data.List

cmp n0 n1 =
  let l0 = length n0
      l1 = length n1
  in
    if l0 /= l1
    then compare l0 l1
    else compare n0 n1

sumup :: [(String,Int)] -> [(String,Int)]
sumup [] = []
sumup ((n,v):[]) = [(n,v)]
sumup ((n0,v0):(n1,v1):xs) =
  if n0 == n1
  then sumup ( (n0,v0+v1):xs )
  else (n0,v0):(sumup ((n1,v1):xs))
    

main = do
  _ <- getLine
  c <- getContents
  let i = map (\(a:b:_) -> (a,read b) ) $ map words $ lines c :: [(String,Int)]
      o = sumup $ sortBy (\ (n0,v0) (n1,v1) -> cmp n0 n1) i
  mapM_ putStrLn $ map (\(n,v) -> n ++ " " ++ (show(v))) o
  

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

using namespace std;

typedef long long ll;

void test_case() {
	//int a[100], n;
	//cin >> n;
	//for(int i = 0; i < n; ++i) {
		//cin >> a[i];
	//}
	string s, t;
	cin >> s >> t;
	int cnt = 0;
	for(int i = 0; i < (int)s.size(); ++i) {
		if(s[i] != t[i]) cnt++;
	}
	cout << cnt << "\n";
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//int T;
	//cin >> T;
	//while(T--) {
		//test_case();
	//}
	test_case();
}


Measured memory_bytes: 3764
n = int(input())
shop_list = []
for i in range(1,n+1):
  s, p = input().split()
  shop_list.append([i, s, int(p)])
shop_list.sort(key = lambda x: (x[1], -x[2]))
for j, d1, d2 in shop_list:
    print(j)

Measured memory_bytes: 3060
/*figure3.c*/

#include <stdio.h>

int main(void)
{
	int a, b, c;
	scanf("%d %d %d", &a, &b, &c);
	int x, y, z;
	if (a < b) {
		if (c < a) {
			x = c;
			y = a;
			z = b;
		}else {
			if (c < b) {
				x = a;
				y = c;
				z = b;
			}else {
				x = a;
				y = b;
				z = c;
			}
		}
	}else { 
	if (c < b) {
			x = c;
			y = b;
			z = a;
		}else {
			if (c < a) {
				x = b;
				y = c;
				z = a;
			}else {
				x = b;
				y = a;
				z = c;
			}//b < a
		}
	}
	printf("%d %d %d\n", x, y, z);
	return 0;
}

Measured memory_bytes: 1024
import sys
n,m,q = map(int,input().split())
s = []
a,b,c,d = [0]*q,[0]*q,[0]*q,[0]*q
for i in range(q):
    a[i],b[i],c[i],d[i] = map(int,input().split())

def dfs( s , n ):
    i = 0
    if len(s) >= n:
        ans.append(s)
        return
    else:
        a = int(s[len(s)-1])
        for j in range(m-a):
            dfs( s + str(a+j) , n )
                
ans = []
for j in range(m):
    ak = str(j)
    dfs( ak , n )
    
tans = 0
for i in range(len(ans)):
    an = 0
    s = [0]*(n+1)
    for j in range(n):
        s[j+1] = int(ans[i][j])
    for j in range(q):
        if s[b[j]] - s[a[j]] == c[j]:
            an += d[j]
                  
    tans = max(tans,an)
    
print(tans)

Measured memory_bytes: 83296
alfa=input().split()
N=int(alfa[0])
X=int(alfa[1])
#L=[int(input().split()) for i in range(N)]
L=input().split()

#print(N,X,L)
D=0
count=1
for i in range(N):
    D+=int(L[i])
    if D>X:
        print(count)
        break
    else:
        count+=1

if D<=X:
    print(count)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define takearr(a,n) int a[n];for(int i=0;i<n;i++)cin>>a[i]
#define rep(i,n) for(int i=0;i<n;i++)
#define f(i,a,b) for(ll i=a;i<=b;i++)
#define mods (1000*1000*1000)+7

int main()
{

  ll n,we;cin>>n>>we;
  ll w[n],v[n];
  rep(i,n){cin>>w[i]>>v[i];}
  ll ans[n+1][we+1];
  memset(ans,0,sizeof(ans));
  //ans[0][w[0]]=v[0];
  f(i,1,n)
    {
      f(j,0,we)
        {
          ans[i][j]=ans[i-1][j];
          if(j>=w[i-1])ans[i][j]=max(ans[i][j],ans[i-1][j-w[i-1]]+v[i-1]);
         //cout<<ans[i][j]<<" ";
        }
       // cout<<endl;
    }
  cout<<*max_element(ans[n],ans[n]+we+1)<<endl;

}

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

using namespace std;
//using namespace __gnu_pbds;

#define ll  long long
#define PR  pair<int, int>

const int N = 3e5 + 10;
const int MOD = 1e9 + 7;
const long long INF = 5e18;
const double PI = 2 * acos(0.0);
//template<typename T> using ordered_set = tree<T, nulong long_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

ll a[N], b[N];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n, h;
    cin >> n >> h;
    for (int i = 1; i <= n; i++) {
        cin >> a[i] >> b[i];
    }
    sort(a + 1, a + n + 1, greater<ll>());
    sort(b + 1, b + n + 1, greater<ll>());
    ll ans = h / a[1];
    if (h % a[1]) {
        ans++;
    }
    for (int i = 1; i <= n; i++) {
        h -= b[i];
        if (h <= 0) {
            ans = min(ans, (ll)i);
            continue;
        }
        ll now = h / a[1];
        if (h % a[1]) {
            now++;
        }
        now += i;
        ans = min(ans, now);
    }
    cout << ans << '\n';
    return 0;
}


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

int main() {
	
	int A[3];
	cin >> A[0] >> A[1] >> A[2];
	
	sort(A, A + 3);
	
	int ret = A[2] - A[1] + A[2] - A[0];
	
	if(ret % 2 != 0){
		ret += 3;
	}
	
	cout << ret / 2 << endl;
	
	return 0;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define INF 1e9

int main() {
    int N,M,X;
    cin>>N>>M>>X;
    vector<int> C(N);
    vector<vector<int>> A(N,vector<int>(M));
    int ans=INF;
    for (int i = 0; i < N; i++){
        cin>>C[i];
        for (int j = 0; j < M; j++){
            cin>>A[i][j];
        }
    }
    for (int i = 0; i < (1<<N); i++){
        bitset<12> bit(i);
        vector<int> rikai(M);
        int cost=0;
        for (int j = 0; j < N; j++){
            if(bit[j]==1){
                cost+=C[j];
                for (int k = 0; k < M; k++){
                    rikai[k]+=A[j][k];
                }
            }
        }
        bool ok=true;
        for (int j = 0; j < M; j++){
            if(rikai[j]<X)ok=false;
        }
        if(ok){
            ans=min(ans,cost);
        }
    }
    if(ans==INF){
        cout<<-1<<endl;
        return 0;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3648
///
// File:  b.go
// Author: ymiyamoto
//
// Created on Sat Apr  7 17:26:27 2018
//
package main

import (
	"fmt"
	"sort"
)

var N int

func main() {
	fmt.Scan(&N)

	arr := make([]int, N)
	for i := 0; i < N; i++ {
		arr[i] = i + 1
	}

	f := func(i int) bool {
		rest := N
		for j := i; j >= 0; j-- {
			if rest-arr[j] == 0 {
				return true
			} else if rest-arr[j] > 0 {
				rest -= arr[j]
			}
		}
		return false
	}

	i := sort.Search(len(arr)-1, f)
	for j := i; j >= 0; j-- {
		if N-arr[j] == 0 {
			fmt.Println(arr[j])
			break
		} else if N-arr[j] > 0 {
			fmt.Println(arr[j])
			N -= arr[j]
		}
	}
}


Measured memory_bytes: 81152
eval"N,A,B,K="+`tr ' ' ,`
f=s=1,*(1..N).map{s=s*_1%M=998244353}
p (0..N).sum{|a|b=(K-A*a)/B
b>N||A*a+B*b!=K||b<0?0:s**2*(f[a]*f[b]*f[~a]*f[~b]).pow(M-2,M)}%M

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

typedef long long ll;

const int INF = 101234567;

int main() {
    ll N;
    ll ans = 0;
    vector<ll>v;
    cin >> N;

    for (int k = 1; k < (double)sqrt(N); k++) {
        if (N % k == 0) {
            ll m = N/k - 1;
            if (m > k) {
                ans += m;
            }
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1e9 + 7/*998244353*/;
const ll INF = 1LL << 60;
ll mod_pow(ll, ll, ll); ll mod_fact(ll, ll); ll mod_inv(ll, ll); ll gcd(ll, ll); ll lcm(ll, ll);
//
int main(){
    int ans = 0;
    string s, t;
    cin >> s >> t;
    for(int i = 0; i < s.size(); i++){
        if(s[i] != t[i]) ans++;
    }
    cout << ans << "\n";
}

Measured memory_bytes: 3912
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999999
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
typedef vector<llong> LV;

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



int main() {
	llong N,K;
    cin >>N >> K;
    llong ans =0;
    llong cm = 0;
    ans = N - K + 1;
    


    cout << ans << endl;


    

    




}


Measured memory_bytes: 256
#include <stdio.h>

int main() {
    int N, x;
    scanf("%d %d", &N, &x);

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

    int tmp, j, count=0;
    for(i=0; i<N-1; i++) {
        for(j=i; j<N; j++) {
            if(a[i]>a[j]) {
                tmp = a[i];
                a[i] = a[j];
                a[j] = tmp;
            }
        }
        x -= a[i];
        if(x<0) {
            break;
        } else if(x==0) {
            count += 1;
            break;
        } else {
            count += 1;
        }
    }


    if(x-a[N-1]==0) {
        count += 1;
    }

    printf("%d\n", count);

    return 0;

}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
using namespace std;
#define MOD 1000000007
#define EPS 10e-8

int main(){
    int N,max,ban,t;
    t=0;
    int h[100007];
    cin >> N ;
    rep(i,N){
        cin >> h[i];
    }
    max=h[0];
    ban=0;
    for(int i=1;i<N;i++){
        if(max-h[i]>1) t++;
        if(max<h[i]){
            max=h[i];
        }
    }
    if(t>0) cout << "No" << endl;
    else cout << "Yes" << endl;
    
}

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

//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;

#define ll long long int
#define ld long double
#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
#define pi 3.14159265358979
#define pa pair<ll,ll>
//#define goodset tree<pa, null_type, less<pa>, rb_tree_tag, tree_order_statistics_node_update>
//#define FRE freopen("acm.in","r",stdin); freopen("acm.out","w",stdout);

const ll mod = 1e9+7 ;
const ll N = 3e5+5;

int main()
{
    FAST

    ll tc,i,j,k;
    //cin>>tc;
    tc=1;

    while(tc--)
    {
        ll n,d;
        cin>>n>>d;
        vector<ll>v;
        for(i=0; i<n; i++)
        {
            ll x,y;
            cin>>x>>y;
            x=abs(x);
            y=abs(y);

            v.pb(x*x +y*y);
        }
        sort(v.begin(),v.end());
        ll ans=0;
        for(i=0; i<n; i++)
        {
            if(v[i]>(d*d))
                break;
        }
        cout<<i;
    }
    return 0;
}



Measured memory_bytes: 5328
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int k = sc.nextInt();
		if(n % 2 == 1) {
			if(n/2+1 >= k) {
				System.out.print("YES");				
			} else {
				System.out.print("NO");
			}			
		} else {
			if(n/2 >= k) {
				System.out.print("YES");				
			} else {
				System.out.print("NO");
			}			
		}

	}
}


Measured memory_bytes: 23124
#include<iostream>
using namespace std;
int main(){
  int n;
  int array[100];
  int cnt=0;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>array[i];
  }
  for(int i=0;i<n;i++){
    int data;
    cin>>data;
    array[i]-=data;
    if(array[i]>0){
      cnt+=array[i];
    }
  }
  cout<<cnt<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<string>
#include<cstring>
#include<climits>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#include<list>
#include<unordered_map>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define INF (1 << 30) - 1
#define LLINF (1LL << 61) - 1
// #define int ll
using namespace std;
const int MOD = 1000000007;
const int MAX = 510000;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll n,h[100010];
    bool a[100010]={};
    cin>>n;
    rep(i,n) cin>>h[i];
    for(ll i=n-2;i>=0;i--){
        if(h[i]>h[i+1]){
            h[i]--;
        }
    }
    rep(i,n-1){
        if(h[i]>h[i+1]){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>

int main(){
    int num=1;
    int x, y, z;
    scanf("%d %d %d", &x, &y, &z);
    while(1){
        if(y*num+z*(num+1) > x) break;
        else num++;
    }
    printf("%d",num-1);
  return 0;
}


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

def can_reach(a):
    c = 0
    n = [0, 0]
    for point in a:
        c = point[0] - c
        dis = (point[1] - n[0]) + (point[2] - n[1])
        if (dis > c) or ((c - dis) % 2 != 0):
            return False
        c = point[0]
        n[0] = point[1]
        n[1] = point[2]
    return True

def main():
    n = int(input())
    a = [ list(map(int, input().split())) for _ in range(n)]

    print('Yes' if can_reach(a) else 'No')

if __name__ == '__main__':
    main()


Measured memory_bytes: 27300
from bisect import bisect

n = int(input())
A = [int(i) for i in input().split()]

class UnionFind():
  def __init__(self, elements):
    self.elements = elements
    self._root = {}
    self.size = [1] * (len(self.elements)+1)
    for e in self.elements:
      self._root[e] = e
    
  def unite(self, x, y):
    x = self.root(x)
    y = self.root(y)
    res = self.size[x] * self.size[y]
    self.size[x] += self.size[y]
    
    if x != y:
      self._root[y] = x

    return res
    
  def root(self, x):
    if self._root[x] != x:
      self._root[x] = self.root(self._root[x])
    return self._root[x]

B = [0] * (n+1)

for i, a in zip(range(1, n+1), A):
    B[a] = i

uf = UnionFind(range(1, n+1))
ans = 0
A.insert(0, 0)

for j in range(n, 0, -1):
    i = B[j]
    ans += A[i]

    if i - 1 >= 1 and A[i-1] > A[i]:
        ans += uf.unite(i-1, i) * A[i]

    if i + 1 <= n and A[i+1] > A[i]:
        ans += uf.unite(i+1, i) * A[i]

print(ans)

Measured memory_bytes: 47700
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define Graph vector<vector<int>>
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1000000007;

int main(){
    int N;
    cin >> N;
    ll sum = 0;
    for(int i = 1; i < N; i++) sum += i;
    cout << sum << endl;
}

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


int main() {
  int N;

  cin >> N;

  vector<int> A(N);

  int best_max = 0;
  int best_max_idx = 0;
  int second_max = 0;
  int second_max_idx = 0;

  for(int i=0; i<N; i++) {
    cin >> A.at(i);
    if (A.at(i) > best_max) {
      best_max = A.at(i);
      best_max_idx = i;
    } else if (A.at(i) > second_max) {
      second_max = A.at(i);
      second_max_idx = i;
    }
  }


  for(int i=0; i<N; i++) {
    if(best_max_idx != i) {
      cout << best_max << endl;
    } else {
      cout << second_max << endl;
    }
  }



}

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

#define ALL(a) (a).begin(), (a).end()
#define FOR(i, s, n) for (int i = (s); i < (n); i++)
#define rep(i, n) FOR(i, 0, n)
#define repi(i, n) FOR(i, 1, n + 1)
#define pp(v) cerr << #v "=" << (v) << endl;
#define ppa(v) cerr << "- " << #v << endl; rep(i,v.size()) cerr << #v << "[" << i << "] = " << v[i] << endl;
#define div_ceil(a,b) ((a) + ((b) - 1)) / (b)
#define UNIQUE(v) v.erase( unique(ALL(v)), v.end() );
#define INF 0x3f3f3f3f
#define LLINF 1000111000111000111LL
#define MOD 1000000007
#define TIME system("date +%M:%S.%N")
using Graph = vector<vector<int>>;
using ll = long long;
template<class T> T gcd(const T &a, const T &b) { return a < b ? gcd(b, a) : b ? gcd(b, a % b) : a; }
template<class T> T lcm(const T &a, const T &b) { return a / gcd(a, b) * b; }

// ABC108C 方針
// 合同式
// a + b = 0 (mod k)
// b + c = 0 (mod k)
// a + c = 0 (mod k)
// より
// kが奇数の時、a=b=c=0(mod k)であるから
// ans = (n/k)**3
// kが偶数の時
// a = b = c = k' : ans = (n-k')/k+1 ** 3
// or a = b = c = 0 (mod 2k') ans = (n/k) ** 3

int main() {
  ll n,k;cin>>n>>k;
  ll a = n/k;
  ll ans = a*a*a;
  ll b = (2*n/k+1)/2;
  if (k%2==0) ans += b*b*b;
  cout << ans << endl;
}


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

cut_1=1
cut_2=2
cut_3=3
A_0=A[:cut_1]
S_0=sum(A_0)

A_1=A[cut_1:cut_2]
S_1=sum(A_1)

A_2=A[cut_2:cut_3]
S_2=sum(A_2)

A_3=A[cut_3:]
S_3=sum(A_3)


def irekae(S,T,i):
    if abs(S-T)>abs((S-A[i-1])-(T+A[i-1])):
        
        S=S-A[i-1]
        T=T+A[i-1]
        i=i-1
        
    elif abs(T-S)>abs((T-A[i])-(S+A[i])):
        #print(T,S,T-S,i)
        S=S+A[i]
        T=T-A[i]
        i=i+1
        #print(T,S,T-S,i)

    return (S,T,i)

MIN=[]
cut_1b=0
cut_3b=0
for cut_2 in range(2,N-1):
    cut_1b=0
    cut_3b=0
    while cut_1b != cut_1:
        cut_1b=cut_1
        S_0,S_1,cut_1=irekae(S_0,S_1,cut_1)
        #print(cut_1)

    while cut_3b != cut_3:
        cut_3b=cut_3
        S_2,S_3,cut_3=irekae(S_2,S_3,cut_3)

    MIN+=[max([S_0,S_1,S_2,S_3])-min([S_0,S_1,S_2,S_3])]
    #print(cut_1,cut_2,cut_3,S_0,S_1,S_2,S_3)

    S_1+=A[cut_2]
    S_2-=A[cut_2]

print(min(MIN))


Measured memory_bytes: 25676
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
using namespace std;
typedef long long ll;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

const ll INF=1e18;

ll mod_pow(ll x,ll n,ll m){
    if(n==0) return 1;
    ll res=mod_pow(x*x%m,n/2,m);
    if(n&1) res=res*x%m;
    return res;
}

int main(){
    ll n,m;
    cin>>n>>m;
    vector<ll> x(n),y(m);
    cinf(n,x);
    cinf(m,y);
    ll s=0;
    ll ans=0;
    for(ll i=0;i<n-1;i++){
        ll k=((m-1)*(n-i-1)*(i+1))%mod;
        ll ss=((x[i+1]-x[i])*(y[1]-y[0]))%mod;
        s=(s+(k*ss)%mod)%mod;
    }
    ans=s;
    for(ll i=1;i<m-1;i++){
        ll before_edge=y[i]-y[i-1];
        ll after_edge=y[i+1]-y[i];
        ll before_cnt=(n*(m-i)*i)%mod;
        ll after_cnt=(n*(m-i-1)*(i+1))%mod;
        s=(s*after_edge)%mod;
        s=(s*after_cnt)%mod;
        s=(s*mod_pow(before_edge,mod-2,mod))%mod;
        s=(s*mod_pow(before_cnt,mod-2,mod))%mod;
        ans=(ans+s)%mod;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define REP(i,n) for(int i = 0;i < (n);i++)
#define P pair<int,int>
#define pb push_back
#define mk make_pair
using namespace std;
const int INF = 1 << 20;

typedef long long ll;




int main(){
  int a,b;
  cin >> a >> b;
  int c[100][100];
  if(a < b){
    a--;
    REP(i,100){
      REP(j,100){
	c[i][j] = -1;
      }
	}
  }
  else{
    b--;
    REP(i,100){
      REP(j,100){
	c[i][j] = 1; //#
      }
    }
  }
  int f = 1,s = 1;
  int dir[3] = {-1,0,1};
  while(a > 0 && b > 0){
    REP(i,3){
      REP(j,3){
	c[f+dir[i]][s+dir[j]] *= -1;
      }
    }
    c[f][s] *= -1;
    s += 4;
    if(s >= 100){
      s = 1;
      f += 4;
    }
    a--;
    b--;
  }
  REP(i,max(a,b)){
    c[f][s] *= -1;
    s += 4;
    if(s >= 100){
      s = 1;
      f += 4;
    }
    
  }
  cout << 100 << " " << 100 << endl;
  REP(i,100){
    REP(j,100){
      if(c[i][j] == 1)
	cout << '#';
      else
	cout << '.';
    }
    cout << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
pr = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47]
u = [74, 24, 14, 4, 2]
n = gets.to_i
pr = pr.map do |x|
  tm, res = n, 0
  while tm > 0
    tm /= x
    res += tm
  end
  res
end
u = u.map{|x| pr.count{|y| y >= x}}
p u[0] + u[1]*(u[4]-1) + u[2]*(u[3]-1) + u[3]*(u[3]-1)/2*(u[4]-2)


Measured memory_bytes: 1788
#include <algorithm>
#include <cassert>
#include <iostream>
#include <vector>
#include <bits/stdc++.h>
using namespace std;

int N;
string S;

void run_case() {
    cin >> N;
    cout << fixed << setprecision(10) << 1.0  * pow(1.0 * N / 3, 3.0);
}

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
     
    #define min3(a,b,c) min(a,min(b,c))
    #define max3(a,b,c) max(a,max(b,c))
    #define min4(a,b,c,d) min(min(a,b),min(c,d))
    #define max4(a,b,c,d) max(max(a,b),max(c,d))
    #define count_one(a) __builtin_popcount(a)  // Returns the number of set bits(1) in a number(a). In long long use __builtin_popcountll(a)
    #define parity(i)   __builtin_parity(i)  //even parity 0 and odd parity 1
    #define blz(a)   __builtin_clz(a) //Returns the number of leading zeroes in a number(a)
    #define btz(a)   __builtin_ctz(a) //Returns the number of trailing zeroes in a number(a)
    #define gcd(a,b) __gcd(a,b)
    #define lcm(a,b) (a*(b/gcd(a,b)))
    #define ll long long
    #define pb push_back
    #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    using namespace std;
    int main()
    {
         IOS
         int a,b,c;
         cin>>a>>b>>c;
         cout<<c<<" "<<a<<" "<<b<<endl;
         return 0;
    }

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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin >> s;
    for (int i = 0; i < s.length(); i++) {
        if ((i + 1) & 1) {
            if (s[i] == 'L') {
                cout << "No\n";
                return 0;   
            }
        }
        else {
            if (s[i] == 'R') {
                cout << "No\n";
                return 0;   
            }
        }
    }
    cout << "Yes\n";
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
	int a,k=1,x[10000];

	while(1){
		scanf("%d",&x[k]);
		if( x[k] == 0 ) break;
		k += 1;
	}

	for(a = 1; a < k ;a++){
		printf("Case %d: %d\n",a,x[a]);
	}

	return 0;
}

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

int main(){

  int N, K;
  cin >> N >> K;
  int h[N];
  for(int i=0; i<N; i++){
    cin >> h[i];
  }
  sort(h, h+N);
  int ans = INF;
  for(int i=0; i<N-K+1; i++){
    ans = min(ans, h[i+K-1]-h[i]);
  }
  cout << ans << endl;
}

Measured memory_bytes: 768
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

using ll = long long;

// dp[i] - TRUE if the first player wins if there are i stones remaining

int main() {
    int n, k;
    scanf("%d%d", &n, &k);
    vector<int> a(n);
    for(int& x : a) {
        scanf("%d", &x);
    }
    vector<bool> dp(k + 1);
    for(int stones = 0; stones <= k; ++stones) {
        for(int x : a) {
            if(stones >= x && !dp[stones-x]) {
                dp[stones] = true;
            }
        }
    }
    
    puts(dp[k] ? "First" : "Second");
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <cassert>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
// head

const int N=101000;
int n,x[N],dp[N];
int main() {
	scanf("%d",&n);
	rep(i,1,n+1) scanf("%d",x+i);
	dp[1]=0; dp[2]=0;
	rep(i,3,n+1) dp[i]=dp[i-1]+(x[i-1]==x[i-2]+1&&x[i-1]<=(i-dp[i-1]-2)*2);
	ll ret=1;
	rep(i,1,n+1) ret=ret*(i-dp[i])%mod;
	printf("%lld\n",ret);
}


Measured memory_bytes: 896