akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

#define MAX 500001

int A[MAX];
int H;

int parent(int i) { return i / 2; }
int left(int i) { return 2 * i; }
int right(int i) { return 2 * i + 1; }

void maxHeapfy(int i) {
	int l = left(i);
	int r = right(i);
	int largest;

	if (l<H + 1 && A[l]>A[i])largest = l;
	else largest = i;
	if (r<H + 1 && A[r]>A[largest])largest = r;

	if (largest != i) {
		int temp = A[i];
		A[i] = A[largest];
		A[largest] = temp;
		maxHeapfy(largest);
	}
}

void buildMaxHeap() {
	for (int i = H / 2; i > 0; i--) {
		maxHeapfy(i);
	}
}

int main() {
	cin >> H;
	for (int i = 1; i < H + 1; i++) {
		cin >> A[i];
	}

	buildMaxHeap();
	for (int i = 1; i < H + 1; i++) {
		cout << " " << A[i];
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 4964
from collections import defaultdict

n, k = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]

nums, numd = set(), defaultdict(int)
for a, b in ab:
    nums.add(a)
    numd[a] += b
for i in sorted(nums):
    k -= numd[i]
    if k <= 0:
        print(i)
        break


Measured memory_bytes: 109368
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define FastRead        ios_base::sync_with_stdio(false);cin.tie(NULL);
#define endl            "\n"
#define pi              acos(-1)
#define ordered_set     tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define MAX             100005

typedef long long ll;

map<ll,ll>mp;

int main()
{
    FastRead

    ll n;

    cin>>n;

    for(ll i=1;i<=n;i++)
        mp[i] = 0;

    for(ll i=2;i<=n;i++)
    {
        ll temp;
        cin>>temp;
        mp[temp]++;
    }

    for(auto it:mp)
        cout<<it.second<<endl;
}


Measured memory_bytes: 16164
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using Graph=vector<vector<int>>;
#define INF 1000000000000000000
#define MOD 1000000007

ll dfs(ll N,ll A,ll B,ll C,ll D,map<ll,ll> &m){
  if(N==1){
    return D;
  }
  if(N==2){
    return min(2*D,D+A);
  }
  if(N==3){
    return min({3*D,2*D+A,D+B});
  }
  if(N==4){
    return min({4*D,D+2*A,2*D+B,2*D+C});
  }
  if(N==5){
    return min({5*D,2*D+2*A,4*D+A,2*D+A+B,3*D+B,D+C});
  }
  if(m[N]>0){
    return m[N];
  }
  ll ret=dfs(N/2,A,B,C,D,m)+A+(N%2)*D;
  ret=min(ret,dfs((N-1)/2+1,A,B,C,D,m)+A+(N%2)*D);
  ret=min(ret,dfs(N/3,A,B,C,D,m)+B+(N%3)*D);
  ret=min(ret,dfs((N-1)/3+1,A,B,C,D,m)+B+(3-N%3)%3*D);
  ret=min(ret,dfs(N/5,A,B,C,D,m)+C+(N%5)*D);
  ret=min(ret,dfs((N-1)/5+1,A,B,C,D,m)+C+(5-N%5)%5*D);
  if(N<8000000000){
    ret=min(ret,N*D);
  }
  return m[N]=ret;
}

ll solve(ll N,ll A,ll B,ll C,ll D){
  map<ll,ll> m;
  return dfs(N,A,B,C,D,m);
}

int main(){
  int T;
  cin>>T;
  vector<ll> N(T),A(T),B(T),C(T),D(T);
  for(int i=0;i<T;i++){
    cin>>N.at(i)>>A.at(i)>>B.at(i)>>C.at(i)>>D.at(i);
  }

  for(int i=0;i<T;i++){
    cout<<solve(N.at(i),A.at(i),B.at(i),C.at(i),D.at(i))<<endl;
  }
}


Measured memory_bytes: 4408
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    H, W, d = map(int, input().split())
    A = [list(map(int, input().split())) for _ in range(H)]
    q = int(input())

    XY = [[] for _ in range(H * W)]
    for h in range(H):
        for w in range(W):
            XY[A[h][w] - 1] = [h, w]
    R = [0] * (H * W + 1)
    for i in range(1, H * W + 1):
        if i - d > 0:
            x1, y1 = XY[i - 1]
            x2, y2 = XY[i - 1 - d]
            cost = abs(x1 - x2) + abs(y1 - y2)
            R[i] = R[i - d] + cost

    for _ in range(q):
        l, r = map(int, input().split())
        res = R[r] - R[l]
        print(res)


if __name__ == '__main__':
    resolve()


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

#define REP(i,n) for(ll i=0; i<(ll)(n); i++)
#define FOR(i,n,m) for (ll i=n; i<(ll)(m); i++)
#define pb push_back
#define INF 1000000007LL
#define all(a) (a).begin(),(a).end()

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

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

struct UnionFind{
    vector<int> parents;
    vector<int> rank;
    vector<ll> size;
    UnionFind(int n){
        parents.resize(n);
        size.assign(n, 1);
        REP(i, n){
            parents[i] = i;
        }
    }
    int find(int x){
        if(parents[x] == x) return x;
        return parents[x] = find(parents[x]);
    }
    
    int unite(int x, int y){
        x = find(x);
        y = find(y);
        parents[y] = x;
        size[x] += size[y];
        return 0;
    }
    
    bool same(int x, int y){
        return find(x) == find(y);
    }
    
    ll getSize(int x) {
        return size[find(x)];
    }
    
};

int N;
ll a[200000 + 100];
ll b[200000 + 100];
int main(){
    ios::sync_with_stdio(false);
    cin >> N;
    UnionFind uf(200000 + 100);
    FOR(i, 1, N+1) {
        cin >>  a[i];
        b[a[i]] = i;
    }
    
    ll ans = 0;
    // 最大値から順番に区間をくっつける
    for(int j=N; j>=1; j--) {
        // 位置
        int i = b[j];
        
        // 左側が存在 && a[i]より大きい
        ll l = 0,r = 0;
        if ( i - 1 >= 1 && a[i-1] > a[i] ) {
            l = uf.getSize(i-1);
            uf.unite(i, i-1);
        }
        
        // 右側が存在 && a[i]より大きい
        if ( i + 1 <= N && a[i+1] > a[i] ) {
            r = uf.getSize(i+1);
            uf.unite(i, i+1);
        }
        
        ans += (l + 1) * (r + 1) * a[i];
        
    }
    
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 5760
n,k=map(int,input().split())
p=list(map(int,input().split()))

s=0
for i in range(k):
    s += (p[i]+1)/2

ans=s

for i in range(n-k):

    s += (p[i+k]-p[i])/2

    if s>ans:
        ans=s
print(ans)

Measured memory_bytes: 24812
#include<bits/stdc++.h>
#define int long long
#define ld long double
#define inf 0x7f7f7f7f7f7f7f7f 
#define maxn 1000010
#define ri register int
#define il inline
#define mk make_pair
#define pb push_back
#define fi first
#define se second
#define mod 998244353
#define db(x) cout << x << endl; 
#define eps 0.0001
using namespace std;
int a[maxn],v[maxn];
int s[maxn]; 
signed main()
{
	ios::sync_with_stdio(0);
	int n,k;
	cin >> n >> k;
	int ans = 0;
	for(int i=1;i<=k;i++)
	{
		int d;
		cin >> d;
		for(int j=1;j<=d;j++)
			cin >> a[i],v[a[i]]++;
	}
	for(int i=1;i<=n;i++)
		if(!v[i])
			ans++;
	cout << ans;
	return 0;
}

Measured memory_bytes: 3664
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<typename T> inline bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T &a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U &u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U &u,const V... v){for(auto &e:u)fill_v<T>(e,v...);}

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

    string s;
    cin >> s;
    int x, y;
    cin >> x >> y;

    // ランレングス圧縮
    int n = sz(s);
    vector<pair<char, int>> cnt;
    cnt.emplace_back(s[0], 0);
    rep(i, n) {
        if (cnt.back().fi == s[i]) cnt.back().se++;
        else cnt.emplace_back(s[i], 1);
    }

    // 移動をx成分とy成分に分ける（初めのFは別で処理）
    int sx = 0, sy = 0;
    vector<int> xlist, ylist;
    int now = 0;
    rep(i, sz(cnt)) {
        if (i == 0 && cnt[i].fi == 'F') {
            sx += cnt[i].se;
        } else if (cnt[i].fi == 'T') {
            now ^= (cnt[i].se % 2);
        } else {
            if (now == 0) xlist.push_back(cnt[i].se);
            else ylist.push_back(cnt[i].se);
        }
    }

    // どこに移動できるかDP（10000を0としている）
    vector<bool> to_x(40000, false);
    vector<bool> to_y(40000, false);
    to_x[20000] = true;
    to_y[20000] = true;

    rep(i, sz(xlist)) {
        vector<bool> pre_x(40000, false);
        swap(to_x, pre_x);
        rep(j, 40000) if (pre_x[j]) {
            to_x[j + xlist[i]] = true;
            to_x[j - xlist[i]] = true;
        }
    }

    rep(i, sz(ylist)) {
        vector<bool> pre_y(40000, false);
        swap(to_y, pre_y);
        rep(j, 40000) if (pre_y[j]) {
            to_y[j + ylist[i]] = true;
            to_y[j - ylist[i]] = true;
        }        
    }

    // 移動できるかチェック
    int dx = x - sx, dy = y - sy;
    dx += 20000, dy += 20000;
    if (to_x[dx] && to_y[dy]) puts("Yes");
    else puts("No");
}


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

using namespace std;
using Int = long long;

signed main(){
    string s;
    cin >> s;
    map<string, int> mp;
    string tmp;
    for (int i = 0; i < 4; i++){
        tmp = s.substr(i, 1);
        if(mp.find(tmp) != mp.end()){
            mp[tmp] += 1;
        } else {
            mp[tmp] = 1;
        }
    }

    if (mp.size() == 2 && mp[tmp] == 2) {
        cout << "Yes" << endl;
    } else{
        cout << "No" << endl;
    }

    return 0;
}

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

using namespace std;
#define PB push_back
#define MP make_pair
#define LL long long
#define int LL
#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define RE(i,n) FOR(i,1,n)
#define REP(i,n) FOR(i,0,(int)(n)-1)
#define R(i,n) REP(i,n)
#define VI vector<int>
#define PII pair<int,int>
#define LD long double
#define FI first
#define SE second
#define st FI
#define nd SE
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

template<class C> void mini(C &a4, C b4) { a4 = min(a4, b4); }
template<class C> void maxi(C &a4, C b4) { a4 = max(a4, b4); }

template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<'='<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;cerr<<'='<<h<<','; _dbg(sdbg+1, a...);
}

template<class T> ostream &operator<<(ostream& os, vector<T> V) {
  os << "["; for (auto vv : V) os << vv << ","; return os << "]";
}
template<class L, class R> ostream &operator<<(ostream &os, pair<L,R> P) {
  return os << "(" << P.st << "," << P.nd << ")";
}

#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif
const int MAX = 10010;
int n;
int a[MAX],b[MAX];
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(11);
  cerr << fixed << setprecision(6);
  cin >> n;
  R(i,n){
    cin >> a[i];
  }
  R(i,n){
    cin >> b[i];
  }
  int ak = 0;
  R(i,n){
    if(a[i]%2 != b[i]%2){
      b[i]++;
      ak++;
    }
    if(a[i] > b[i]){
      ak += a[i] - b[i];
    }else{
      ak -= (b[i] - a[i])/2;
    }
  }
  if(ak > 0){
    cout << "No\n";
  }else{
    cout << "Yes\n";
  }
}


Measured memory_bytes: 384
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ld;
#define vec(s) vector

#define vvec(s) vector<vector
>
typedef vector<lli> vi;
typedef vector<vi> vvi;
typedef pair<lli,lli> pii;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Yes(x) cout<<(x?"Yes":"No")<<endl;
#define YES(x) cout<<(x?"YES":"NO")<<endl;
#define out(s) cout<<s<<endl;
#define pb(s) push_back(s);
#define sp " " 
#define INF 10000000000
#define LINF 9000000000000000000
#define all(s) s.begin(),s.end()
void vout(vi v){
    for(lli i=0;i<v.size();i++)
    cout<<v.at(i)<<endl;
}
int main(){
    cout << std::fixed << std::setprecision(10);
    lli ans=INF;
    vi a(5);
    rep(i,5){
        cin>>a[i];
    }
    vi n={ 0, 1, 2, 3, 4 };
    while(true){ 
        lli tmp=0;
        rep(i,5){
            if(i==4){ 
                tmp+=a[n[i]];
            }
            else{ 
                (a[n[i]]%10==0?tmp+=a[n[i]]:tmp+=(a[n[i]]/10+1)*10);
            }
        }
        ans=min(tmp, ans);
        if(!next_permutation(all(n))){ 
            break;
        }
    }
    out(ans);
}

Measured memory_bytes: 3620
#define TEST_MODE true
 
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
 
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, a, b) for (int i = (a); i < (int)(b); ++i)
#define rrep(i, n) for (int i = (n)-1; i >= 0; --i)
#define rrep2(i, a, b) for (int i = (a)-1; i >= (int)b; --i)
#define range(i, a, b, c) for (int i = a;		\
                               c > 0 ? i < b : i > b;	\
                               i += c)
#define chmax(a, b) (a = (a) < (b) ? (b) : (a))
#define chmin(a, b) (a = (a) > (b) ? (b) : (a))
using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define all(a) begin(a), end(a)
#define ifnot(a) if (not(a))
#define int long long
 
#if TEST_MODE == true
const bool test = true;
#define dump(x) cerr << #x << " = " << (x) << " "
#define dumpl(x) cerr << #x << " = " << (x) << " " << endl;
#else
const bool test = false;
#define dump(x) 
#define dumpl(x) 
#endif
 
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
const int INF = (int)1 << 60;
const ll INFL = (ll)1 << 60;
ll mod_n = (int)1e9 + 7;
const double eps = 1e-10;
typedef long double Real;
// return -1, 0, 1
int sgn(const Real &r) { return (r > eps) - (r < -eps); }
int sgn(const Real &a, const Real &b) { return sgn(a - b); }
 
//.....................
const int MAX = (int)2e5 + 5;
 
vector<string> split(const string &str, char sep)
{
  vector<string> v;
  stringstream ss(str);
  string buffer;
  while (getline(ss, buffer, sep))
    {
      v.push_back(buffer);
    }
  return v;
}
 
template <class InputIterator>
int sum(InputIterator begin, InputIterator end)
{
  return accumulate(begin, end, 0ll);
}
 
template<typename T>
T gcd(T a, T b)
{
  T c;
  while (a != 0) {
    c = a; a = b%a;  b = c;
  }
  return b;
}
 
class Solver {
public:
  int A, B, C, X;

  void solve() {
    cin >> A >> B >> C >> X;

    int cnt = 0;
    rep(a, A+1) {
      rep(b, B+1) {
        rep(c, C+1) {
          if (a * 500 + b * 100 + c * 50 == X) cnt += 1;
        }
      }
    }
    cout << cnt << endl;
  }
};
 
signed main()
{
  srand(time(NULL));
  cout << fixed << setprecision(20);
  auto ptr = new Solver();
  ptr->solve();
  delete ptr;
  // while (true) {    
  //     auto ptr = new Solver();
  //     ptr->solve();
  //     delete ptr;
  // }
  return 0;
}
 
// class Mycin {
// 	bool flag = true;
// public:
// 	Mycin& operator >> (int& a) {flag = scanf("%lld", &a) != EOF; return *this;}
// 	Mycin& operator >> (char& a) {flag = scanf("%c", &a) != EOF; return *this;}
// 	Mycin& operator >> (string& s) {flag = (bool)(cin >> s); return *this;}
// 	operator bool() {return flag;}
// } mycin;
 
// class Mycout {
// public:
// 	Mycout& operator << (const int& a) {printf("%lld", a); return *this;}
// 	Mycout& operator << (const char c) {printf("%c", c); return *this;}
// 	Mycout& operator << (const string& s) {printf("%s", s.c_str()); return *this;}
// } mycout;
 
// #define cin mycin
// #define cout mycout
// #define endl '\n'


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String str = sc.next();
		int num = str.length();
		int max = 13;
		int inv13[] = {0, 1, 7, 9, 10, 8, 11, 2, 5, 3, 4, 6, 12};
		int integer[] = new int[num];
		for(int i = 0; i < num; i ++) {
			integer[i] = str.charAt(i) == '?' ? 10 : str.charAt(i) - '0';
		}
		long dp[][] = new long[num + 1][max];
		dp[0][0] = 1;
		for(int i = 1; i <= num; i ++) {
			if(integer[i - 1] == 10) {
				for(int j = 0; j < max; j ++) {
					for(int k = 0; k < 10; k ++) {
						dp[i][(j + k) % max] = mod(dp[i][(j + k) % max] + dp[i - 1][(j * inv13[10]) % max]);
					}
				}
			}else {
				for(int j = 0; j < max; j ++) {
					dp[i][(j + integer[i - 1]) % max] = dp[i - 1][(j * inv13[10]) % max];
				}
			}
		}
		System.out.println(dp[num][5]);
	}

	static long MOD = (long)Math.pow(10, 9) + 7;
	public static long mod(long i) {
		return i % MOD + ((i % MOD) < 0 ? MOD : 0);
	}
	
	static long pow(long x, long y) {
		if (y == 0) {
			return 1;
		} else if (y == 1) {
			return x;
		} else if (y % 2 == 0) {
			long tmp = pow(x, y / 2);
			return mod(tmp * tmp);
		} else {
			long tmp = pow(x, y / 2);
			return mod(mod(tmp * tmp) * x);
		}
	}
	
	static long inv(long x) {
		return pow(x, MOD - 2);
	}
	
	static int MAX_FACT = 5_000_100;
	static long fact[] = new long[MAX_FACT];
	static long invFact[] = new long[MAX_FACT];
	static void prepareFact() {
		fact[0] = 1;
		for(int i = 1; i < MAX_FACT; i ++) {
			fact[i] = mod(fact[i - 1] * i);
		}
		invFact[MAX_FACT - 1] = inv(fact[MAX_FACT - 1]);
		for(int i = MAX_FACT - 1; i > 0; i --) {
			invFact[i - 1] = mod(invFact[i] * i);
		}
	}
	
	static long P(int n, int r) {
		if(n < 0 || r < 0 || n < r) { return 0; }
		return mod(fact[n] * invFact[n - r]);
	}
	static long C(int n, int r) {
		if(n < 0 || r < 0 || n < r) { return 0; }
		return mod(P(n, r) * invFact[r]);
	}
	static long H(int n, int r) {
		return C((n - 1) + r, r);
	}
}

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

int main(){

  int x1,y1,x2,y2;
  cin >> x1 >> y1 >> x2 >> y2;
  
  cout << x2-(y2-y1) <<" "<< y2+(x2-x1) << " "<< x1-(y2-y1) << " "<< y1+(x2-x1) << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i= 0; i < (n); i++)
using ll= long long int;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll mod= 1e9 + 7;




int main(){
  string a,b;
  cin >> a >>b;
  if(a[0]==b[2] && a[1]==b[1] && a[2]==b[0]){cout << "YES" << endl;}else{cout << "NO" << endl;}

}

Measured memory_bytes: 3608
use std::cmp::{max, min};

fn main() {
  let (a, b) = {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    let mut ws = s.split_whitespace();
    let a: i64 = ws.next().unwrap().parse().unwrap();
    let b: i64 = ws.next().unwrap().parse().unwrap();
    (a, b)
  };

  let diff = max(a - b, b - a);
  if diff % 2 == 1 {
    print!("IMPOSSIBLE")
  } else {
    print!("{}", diff / 2 + min(a, b));
  }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (ll i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }

int main()
{
  ll n, k;
  cin >> n >> k;
  ll a[n] = {};
  ll fir = 0, sec = 0;
  REP(i, n) {
    cin >> a[i];
    REP(j, i) {
      if (a[j] > a[i]) fir++;
      fir %= 1000000007;
    }
  }
  REP(i, n)REP(j, n) {
    if (a[j] > a[i]) sec++;
    sec %= 1000000007;
  }
  fir %= 1000000007;
  fir *= k;
  fir %= 1000000007;
  sec %= 1000000007;
  sec *= (k - k % 2) / 2;
  sec %= 1000000007;
  sec *= k - (k + 1) % 2;
  sec %= 1000000007;
  ll ans = fir + sec;
  ans %= 1000000007;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
	"math"
)

func main() {
	n, k := scInt2()
	hlist := ints(n)
	dp := make([]int, n)
	inf := math.MaxInt64
	for i := 0; i < n; i++ {
		dp[i] = inf
	}
	dp[0] = 0
	for i := 0; i < n; i++ {
		for j := 1; j <= k; j++ {
			if i+j < n {
				diff := abs(hlist[i+j]-hlist[i]) + dp[i]
				dp[i+j] = min(diff, dp[i+j])
			}
		}
	}
	fmt.Println(dp[n-1])
}

func scStr() string {
	var s string
	fmt.Scan(&s)
	return s
}

func scInt() int {
	var x int
	fmt.Scan(&x)
	return x
}

func scInt2() (int, int) {
	var x, y int
	fmt.Scan(&x, &y)
	return x, y
}

func scInt3() (int, int, int) {
	var x, y, z int
	fmt.Scan(&x, &y, &z)
	return x, y, z
}

func ints(n int) (slice []int) {
	slice = make([]int, n)
	for i := range slice {
		fmt.Scan(&slice[i])
	}
	return slice
}

func sum(slice []int) (sum int) {
	sum = 0
	for i := range slice {
		sum += slice[i]
	}
	return
}

func unique(strs []string) (unique []string) {
	m := map[string]bool{}
	for _, v := range strs {
		if !m[v] {
			m[v] = true
			unique = append(unique, v)
		}
	}
	return unique
}

func min(x, y int) int {
	if x > y {
		return y
	}
	return x
}

func powi(x, pow int) int {
	return int(math.Pow(float64(x), float64(pow)))
}

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}


Measured memory_bytes: 6312
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <math.h>
#include <vector>
#include <map>
#include <queue>
#include <utility>
#include <algorithm>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector <int> W(N);
  int sum = 0;
  for (int i = 0; i < N; i++) {
	  cin >> W[i];
	  sum += W[i];
	}
  int ans = 1e9;
  int now = 0;
  for (int i = 0; i < N - 1; i++) {
	  now += W[i];
	  ans  = min(ans, abs(sum - 2 * now));
	}
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#!python3

# input
N = int(input())
S = input()


def main():
    r, g, b = 0, 0, 0
    rg, gr = 0, 0
    rb, br = 0, 0
    gb, bg = 0, 0
    ans = 0
    for s in S[::-1]:
        if s == "R":
            ans += gb + bg
            rg += g
            rb += b
            r += 1
        if s == "G":
            ans += rb + br
            gr += r
            gb += b
            g += 1
        if s == "B":
            ans += rg + gr
            br += r
            bg += g
            b += 1
    
    lim = (N - 1) // 2 + 1
    for i in range(1, lim):
        lim2 = N - 2 * i
        for j in range(lim2):
            if S[j] != S[j+i] and S[j+i] != S[j+2*i] and S[j] != S[j+2*i]:
                ans -= 1
    
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9252
#include <iostream>
#include <iomanip>
#include <queue>
using namespace std;
#define INF 1000000007
#define ll long long
#define rep(i, start, end) for(ll i=(ll)start; i<(ll)end; i++)
#define print(a) cout << a << endl;
#define printarray(a, len) rep(i,0,len) cout << a[i] << " ";
 
 
int main(){
  ll k, x;
  cin >> k >> x;
  rep(i, x-k+1, x+k) cout << i << " ";
  
  return 0;
}

Measured memory_bytes: 256
N,M = map(int,input().split())
A = sorted([list(map(int,input().split())) for _ in range(N)],key=lambda x:x[0])
cnt = 0
pay = 0
for i in range(N):
    if cnt+A[i][1]<=M:
        pay += A[i][0]*A[i][1]
        cnt += A[i][1]
    else:
        m = M-cnt
        pay += A[i][0]*m
        break
print(pay)        

Measured memory_bytes: 65496
import java.util.*;

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

        int n = sc.nextInt();

        int[] a = new int[n];

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

        int x = a[0];
        int p = 0;
        int ans = 1;
        for(int i = 1; i < n; i++){
            if(p == 0){
                if(x < a[i]){
                    p = 1;
                }else if(x > a[i]){
                    p = -1;
                }
            }else if(p == 1){
                if(x > a[i]){
                    p = 0;
                    ans++;
                }
            }else{
                if(x < a[i]){
                    p = 0;
                    ans++;
                }
            }
            x = a[i];
        }

        System.out.println(ans);

    }
}


Measured memory_bytes: 50544
import java.util.Arrays;
import java.util.Scanner;

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

        s = s.replace("eraser", "");
        s = s.replace("erase", "");
        s = s.replace("dreamer", "");
        s = s.replace("dream", "");

        if (s.length() > 0) {
            System.out.println("NO");
        } else {
            System.out.println("YES");
        }
    }
}

Measured memory_bytes: 29640
#include <iostream>
#include <vector>
#include <utility>
#include <map>
#include <tuple>
#include <algorithm>

using namespace std;

static const int INF = 1e9 + 7;
int n, ma, mb;
vector<tuple<int, int, int>> item;
map<tuple<int, int, int>, int> dp;

int dfs(int now, int a, int b){
    if(a && b && a % ma == 0 && b % mb == 0 && a / ma == b / mb){
        return 0;
    }
    if(now == n){
        return INF;
    }
    auto status = make_tuple(now, a, b);
    if(dp.count(status)) return dp[status];
    return dp[status] = min(dfs(now + 1, a, b), dfs(now + 1, a + get<0>(item[now]), b + get<1>(item[now])) + get<2>(item[now]));
}

int main(){
    cin >> n >> ma >> mb;
    for(int i = 0; i < n; i++){
        int a, b, c;
        cin >> a >> b >> c;
        item.push_back(make_tuple(a, b, c));
    }
    int ans = dfs(0, 0, 0);
    if(ans == INF){
        ans = -1;
    }
    cout << ans << "\n";
}

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

int main() {
  int A,B,C,D;
  cin>>A>>B>>C>>D;
  if(A+B>C+D)
    cout<<"Left"<<endl;
  else if(A+B<C+D)
    cout<<"Right"<<endl;
  else
    cout<<"Balanced"<<endl;
  
}

Measured memory_bytes: 256
a,b = map(int,input().split())

ans_min = min(a*100//8,b*100//10)
ans_max = max((a+1)*100//8-1,(b+1)*100//10-1)

for i in range(ans_min,ans_max+1):
    if a == i*8//100 and b == i*10//100:
        print(i)
        exit()

print(-1)

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>

using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
typedef long long ll;

int main()
{
	int n, m;
	cin >> n >> m;
	cout << (n - 1) * (m - 1) << endl;

	return 0;
}


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

int main(){
	int a, b, count = 0;
	cin >> a >> b;
	for(int i=a; i <= b; i++) {
		if(i%10 == i/10000 && i/10%10 == i/1000%10)
			count++;
	}
	cout << count << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int v[5];
  for (int i=0;i<5;i++){
    cin >> v[i];
  }
  int w[5],count=0,sum=0;
  for (int i=0;i<5;i++){
    w[i]=((v[i]+9)/10)*10;
    count=max(count,w[i]-v[i]);
    sum+=w[i];
  }
  cout << sum-count << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
	char X , Y;
	while( scanf("%c %c",&X,&Y) != EOF )
	{
		getchar();
		if( X > Y )
		{
			printf(">\n");
		}
		else if( X < Y )
		{
			printf("<\n");
		}
		else
		{
			printf("=\n");
		}
	}
}

Measured memory_bytes: 128
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {
    public static void main(String[] args) {
        Scanner stdin = new Scanner(System.in);
        int n = stdin.nextInt();
        int[][] a = new int[2][n];
        for (int i = 0; i < 2; i++) {
            for (int j = 0; j < n; j++) {
                a[i][j] = stdin.nextInt();
            }
        }
        
        int[][] dp = new int[2][n];
        dp[0][0] = a[0][0];
        for (int i = 0; i < 2; i++) {
            for (int j = 0; j < n; j++) {
                if (i + 1 < 2) {
                    dp[i + 1][j] = Math.max(dp[i + 1][j], dp[i][j] + a[i + 1][j]);
                }
                
                if (j + 1 < n) {
                    dp[i][j + 1] = Math.max(dp[i][j + 1], dp[i][j] + a[i][j + 1]);
                }
            }
        }
        
        System.out.println(dp[1][n - 1]);
    }
}


Measured memory_bytes: 21588
#pragma GCC optimize("Ofast") 
#include<bits/stdc++.h>
using namespace std;
//#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define owo ios_base::sync_with_stdio(0);cin.tie(0);
#define MOD (ll)(1e6+3)
#define INF (ll)(1e18)
#define debug(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false);\
debug("%s time : %.4fs\n", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> PII;
typedef pair<int,int> pii;
typedef vector<vector<int>> vii;
typedef vector<vector<ll>> VII;
int main()
{
	ll n,m,k;
	cin>>n>>m>>k;
	vector<ll>a(n+5);
	vector<ll>b(m+5);
	for(int i=1;i<=n;i++)cin>>a[i];
	for(int i=1;i<=m;i++)cin>>b[i];
	vector<ll>pa(n+1,0),pb(m+1,0);
	for(int i=1;i<=n;i++)pa[i]+=a[i]+pa[i-1];
	for(int i=1;i<=m;i++)pb[i]+=b[i]+pb[i-1];
	ll ans = 0;
	for(ll i=0;i<=n;i++)
	{
		ll tmp = k-pa[i];
		ll p = ub(all(pb),tmp)-pb.begin();
		p--;
		tmp-=pb[p];
		if(tmp >= 0)ans = max(i+p,ans);
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 9596
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  int A = N/1000;
  int B = (N-A*1000)/100;
  int C = (N-A*1000-B*100)/10;
  int D = (N-A*1000-B*100-C*10)%10;
  //cout << A << endl << B << endl << C << endl << D << endl;
  if ((A==B)&&(B==C)){
    cout << "Yes" << endl;
  }
  else if((B==C)&&(C==D)){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
module app;

import core.bitop;

import std.algorithm;
import std.array;
import std.bigint;
import std.conv;
import std.stdio;
import std.string;

struct Input
{
	int n;
}

void parseInput(T)(out Input input, T file)
{
	with (file) with (input)
	{
		n = readln().strip().to!int;
	}
}

struct Output
{
}

auto main2(Input* input)
{
	if (input.n & 1)
	{
		return cast(float)(input.n / 2 + 1) / input.n;
	}
	else
	{
		return 0.5f;
	}
}

void parseExample(out Input input, string example)
{
	struct Adapter
	{
		string[] _lines;
		this(string input) { _lines = input.splitLines(); }
		string readln() { auto line = _lines[0]; _lines = _lines[1..$]; return line; }
	}
	parseInput(input, Adapter(example));
}

void main()
{
	Input input = void;
	parseInput(input, stdin);
	auto result = main2(&input);
	writeln(result);
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main (void) {
    int K;
    int S;

    cin >> K >> S;

    int ans = 0;
    for (int X = 0; X <= K; X++) {
        for (int Y = 0; Y <= K; Y++) {
            int Z = S - (X + Y);
            if (0 <= Z && Z <= K) ans++;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
n=int(input())
p=list(map(float, input().split()))
       
dp=[[0 for i in range(n+1)] for j in range(n+1)]
dp[0][0]=1

for i in range(1,n+1):
       for j in range(n+1):
       	if j==0:
       		dp[i][j]=(1.0-p[i-1])*dp[i-1][j]
       	else:
       		dp[i][j]=p[i-1]*dp[i-1][j-1]+(1.0-p[i-1])*dp[i-1][j]
res=0
for i in range(n//2+1,n+1):
       res+=dp[n][i]
print(res)       

Measured memory_bytes: 259848
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
const int mod = 1000000007;
int main() {
	int N;
	cin >> N;
	vector<int> A(N);
	for (int i = 0; i < N; ++i) {
		cin >> A[i]; --A[i];
	}
	A.erase(unique(A.begin(), A.end()), A.end());
	N = A.size();
	int S = *max_element(A.begin(), A.end()) + 1;
	vector<int> dp(N + 1);
	vector<int> col(S);
	dp[0] = 1;
	for (int i = 0; i < N; ++i) {
		dp[i + 1] = dp[i] + col[A[i]];
		if (dp[i + 1] >= mod) dp[i + 1] -= mod;
		col[A[i]] += dp[i];
		if (col[A[i]] >= mod) col[A[i]] -= mod;
	}
	cout << dp[N] << '\n';
	return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define LOOP(val, times)   for(val = 0; val < (times); val++)
int main(){
  long long n,m;
  cin>>n>>m;
  if(n==1 && m==1) cout<<1<<endl;
  else if(n==1 || m==1){
    if(n==1){
      cout<<m-2<<endl;
    }
    else{
      cout<<n-2<<endl;
    }
  }
  else{
    cout<<(n-2)*(m-2)<<endl;
  }
}
  


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

using namespace std;

int N, C;

int solve(int total) {
	int cnt, rest, tmp;

	cnt = 0;
	while (true) {
		tmp = total / N;
		cnt += tmp;
		rest = total%N;
		if (rest == 0) {
			break;
		}
		if (tmp == 0) {
			++cnt;
			break;
		}
		total = tmp;
	}

	return cnt;
}

int main() {
	int p, total;

	total = 0;
	cin >> N >> C;
	++N;
	for (int i = 0; i < C; ++i) {
		cin >> p;
		total += p;
	}
	cout << solve(total) << endl;

	return 0;
}


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

int main()
{
	while (1)
	{
		int a, b;
		char op;
		scanf("%d %c %d", &a, &op, &b);
		if (op == '+') printf("%d\n", a + b);
		if (op == '-') printf("%d\n", a - b);
		if (op == '*') printf("%d\n", a*b);
		if (op == '/') printf("%d\n", a / b);
		if (op == '?') break;
	}
	return 0;
}

Measured memory_bytes: 1028
#include <bits/stdc++.h>
using namespace std;
 
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define EPS 1e-9
#define INF  1e15 +1    /// 10^15 + 1
#define INF2 ((ll)1)<<63 /// 2^63
#define all(a)  a.begin(),a.end()
#define bit(i,j) ((i)&((ll)1<<j))
#define setbit(i,j) ((i)|((ll)1<<j))
#define forn(i,n) for(int i=0;i<n;i++)
#define fo(i,a,b) for(int i=a;i<b;i++)
#define dbg(x) cout << #x"=" << x << '\n';
#define dbg2(x,y) cout << #x"=" << x << " " << #y"=" << y << '\n';
#define dbg3(x,y,z) cout << #x"=" << x << " " << #y"=" << y << " " << #z"=" << z << '\n';
const int MOD = 1000000007;
const int mod = 998244353;
const int nala5 = 1e5 +5;

typedef long long ll;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef vector < vi > vvi;
typedef vector < vll > vvll;
typedef pair <int,int> pii;
typedef pair <ll,ll> pll;
typedef vector < pii > vpii;
typedef vector < pll > vpll;
typedef vector < vpii > vvpii;
typedef vector < vpll > vvpll;
typedef vector < set <int> > vsi;
typedef vector < set <ll> > vsll;

int n,m,dp[1003][1003];
string box[1003];

int main(){
    cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
    cin>>n>>m;
    forn(i,n){
        cin>>box[i];
    }
    
    forn(i,n){
        if(box[i][0] == '.') dp[i+1][1] = 1;
        else break;
    }
    forn(i,m){
        if(box[0][i] == '.') dp[1][i+1] = 1;
        else break;
    }
    fo(i,1,n){
        fo(j,1,m){
            if(box[i][j] == '.') dp[i+1][j+1] = (dp[i+1][j] + dp[i][j+1])%MOD;
        }
    }
    cout<<dp[n][m]<<'\n';
}	


Measured memory_bytes: 8580
"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const N = parseInt(arg[0]);
    const A = arg[1].split(" ").map(n=>parseInt(n));
    
    const info = [];
    
    for(let i in A) {
        info.push({originIndex: parseInt(i) + 1, showUpNum: A[i]})
    }
    
    info.sort((a,b)=>a.showUpNum - b.showUpNum);
    
    let answer = [];
    
    for(let i in A) {
        answer.push(info[i].originIndex);
    }
    
    console.log(answer.join(" "));
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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

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

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

//const value
//const ll MOD = 1e9 + 7;
//const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
//const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};

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

template <typename T1, typename T2> 
inline bool chmax(T1 &a, T2 b) {
  return a < b && (a = b, true);
}

template <typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {
  return a > b && (a = b, true);
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll a, b, x;
  cin >> a >> b >> x;
  if(a>=1){
    cout << b / x - (a-1) / x << endl;
  }else{
    cout << b / x + 1 << endl;
  }
  return 0;
}


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

int main(){
    ios::sync_with_stdio(0); cin.tie(0);
    int n, result=0; bool flag=false; cin >> n;
    for(int i=1;i<=n;i++){
        if(n == floor(i*1.08)) {flag = true; result = i; break;}
    }
    if(flag == true) cout << result << endl;
    else cout << ":(" << endl;
    return 0;
}



Measured memory_bytes: 3624
from collections import defaultdict
from collections import OrderedDict
N = int(input())
ans = dict()
for _ in range(N):
    k = str(input())
    if k in ans:
        ans[k]+=1
    else:
        ans.update({k:1})
groupedByValue = defaultdict(list)
for key, value in sorted(ans.items()):
    groupedByValue[value].append(key)
l = groupedByValue[max(groupedByValue)]
for i in l:
    print(i)

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

int main()
{
  string name;
  int count = 0;
  getline(cin,name);

  /*if (name == "FESTIVAL")
  {
    cout << "Yes" << endl;
  }*/

  if(name[name.length()-1] == 'L')
  {
    for(int i = 0; i < name.length()-8; i++)
    {
      cout << name[i];
    }
  }
  cout << endl;
}


Measured memory_bytes: 3532
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define all(v) v.begin(),v.end()
#define vi vector<int>
#define vi2 vector<vector<int>>
#define vl vector<long long>
#define vl2 vector<vector<long long>>

template <class T> T maxAny(T a, T b){
    if(a > b) return a;
    else return b;
}

template <class T> T minAny(T a, T b){
    if(a > b) return b;
    else return a;
}

int main(){
    int n, m;
    cin >> n >> m;
    if(n <= m) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

int main(){
   int n,ans=0;
   cin >> n;
   vector<int> v(n), c(n),d(n);
   for(int i=0;i<n;++i){
       cin >> v[i];
   }
   for(int i=0;i<n;++i){
       cin >> c[i];
   }
   for(int i=0;i<n;++i){
       d[i] = v[i] - c[i];
   }
   for(int i=0;i<n;++i){
       if(d[i]>0) ans+=d[i];
   }
   cout << ans << endl;
} 


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define N 200005
using namespace std;
int n;
int xx[N],yy[N];
int f[N];
int find(int x)
{
	if(x==f[x])return x;
	return f[x]=find(f[x]);
}
int p[N],q[N];
int cmp1(int x,int y)
{
	return xx[x]<xx[y];
}
int cmp2(int x,int y)
{
	return yy[x]<yy[y];
}
struct node
{
	int x,y,z;
	friend bool operator < (const node &aa,const node &bb)
	{
		return aa.z<bb.z;
	}
}ss[N*2];
int top;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)f[i]=i;
	for(int i=1;i<=n;i++)
	{
		scanf("%d%d",&xx[i],&yy[i]);
		p[i]=i;q[i]=i;
	}
	sort(p+1,p+n+1,cmp1);sort(q+1,q+n+1,cmp2);
	for(int i=2;i<=n;i++)
	{
		ss[++top].x=p[i];ss[top].y=p[i-1];ss[top].z=xx[p[i]]-xx[p[i-1]];
		ss[++top].x=q[i];ss[top].y=q[i-1];ss[top].z=yy[q[i]]-yy[q[i-1]];
	}
	sort(ss+1,ss+top+1);
	int ans=0;
	for(int i=1;i<=top;i++)
	{
		int aa=find(ss[i].x),bb=find(ss[i].y);
		if(aa!=bb)
		{
			ans+=ss[i].z;
			f[aa]=bb;
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 8448
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int acs(const void *a, const void *b) { 
  return *(int*)a - *(int*)b;
} /* 1,2,3,4.. */
int des(const void *a, const void *b) {
  return *(int*)b - *(int*)a;
} /* 8,7,6,5.. */
int cmp_char(const void *a, const void *b) { 
  return *(char*)a - *(char*)b;
} /* a,b,c,d.. */
int cmp_str(const void *a, const void *b) {
  return strcmp(*(const char **)a, *(const char **)b);
} /* aaa,aab.. */
#define min(a,b) (a < b ? a : b)
#define max(a,b) (a > b ? a : b)
#define rep(i, l, r) for (int i = l; i < r; i++)
#define MAX 100001
#define MOD 1000000007
#define INF 1000000009
typedef long long int lli;

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

  printf("%d\n", n * n - a);  
  return 0;
}


Measured memory_bytes: 128
package main

import (
	"fmt"
)

func main() {
	var n int
	var count int
	fmt.Scan(&n)
	nums := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&nums[i])
	}

	flag := true
	for flag {
		for i := 0; i < n; i++ {
			if nums[i]%2 == 0 {
				nums[i] /= 2
			} else {
				flag = false
			}
		}
		if flag {
			count++
		}
	}
	fmt.Println(count)
}

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

const int MAXN = 3005;
ll memo[MAXN][MAXN], a[MAXN], n;

ll dp(int fst, int lst) {
    if(memo[fst][lst] != -1)
        return memo[fst][lst];
    if(fst > lst)
        return 0;
    if((lst - fst + 1) % 2 == n % 2)
        return memo[fst][lst] = max(a[fst] + dp(fst + 1, lst), a[lst] + dp(fst, lst - 1));
    else
        return memo[fst][lst] = min(dp(fst + 1, lst) - a[fst], dp(fst, lst - 1) - a[lst]);
}

int main() {
    memset(memo, -1, sizeof memo);
    cin >> n;
    for(int i = 1; i <= n; i++)
        cin >> a[i];
    cout << dp(1, n) << endl;
}

Measured memory_bytes: 70912
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i < n; i++)
#define INF 1001001001
#define LINF (1LL << 62)
using namespace std;
using ll = long long;
using P = pair<int,int>;

void solv() {
    int l;
    cin >> l;
    double a = l *l*l;
    a /= 27.0;
    printf("%lf\n", a);
}

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

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int n,a,b,c,d,e,f,g,h,X[1000],Z[1000],W[1000],P[1000],i;
	while(1){
	scanf("%d",&n);
	if(n==0)break;
	for(i=0;i<n;i++){
	scanf("%d %d %d %d %d %d %d %d",&a,&b,&c,&d,&e,&f,&g,&h);
		X[i]=(a*e)+(-1*f*b)+(-1*g*c)+(-1*h*d);
		Z[i]=(a*f)+(e*b)+(h*c)+(-1*g*d);
		W[i]=(a*g)+(-1*h*b)+(e*c)+(f*d);
		P[i]=(a*h)+(g*b)+(-1*f*c)+(d*e);
	 }
	for(i=0;i<n;i++){	
	printf("%d %d %d %d\n",X[i],Z[i],W[i],P[i]);
  }
  }
  return 0;
}  

Measured memory_bytes: 1040
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;

namespace atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = long.Parse(Console.ReadLine());
            var result = 0L;
            for (var i = 1L; i <= n; i++)
            {
                var y = n / i;
                result += y * (y + 1) * i / 2;
            }

            Console.WriteLine(result);
        }
    }
}

Measured memory_bytes: 27544
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-15
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
const int MAX = 200000;
const int MOD = 1e+9+7;
ll fac[MAX], finv[MAX], inv[MAX];
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAX; i++){
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}
long long COM(int n,int k){
    if(n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}
int main(){
	COMinit();
	int N;
	int a[100001];
	int kaburinum;
	int kaburizahyo[2];
	int zahyo[100001];
	scan(N);
	rep(i,N+1){
		zahyo[i]=-1;
	}
	rep(i,N+1){
		scan(a[i]);
		if(zahyo[a[i]]==-1) zahyo[a[i]]=i;
		else{
			kaburizahyo[0]=zahyo[a[i]];
			kaburizahyo[1]=i;
			kaburinum=a[i];
		}
	}
	//printf("kaburizahyo: %d %d\n",kaburizahyo[0],kaburizahyo[1]);
	rep1(k,N+1){
		ll kumi=(COM(N+1,k)-COM(kaburizahyo[0]+N-kaburizahyo[1],k-1))%MOD;
		if(kumi<0) kumi+=MOD;
		//printf("%lld %lld\n",COM(N+1,k),COM(kaburizahyo[0]+N-kaburizahyo[1],k-1));
		prin(kumi);
	}
	return 0;
}


Measured memory_bytes: 6656
fun main(args: Array<String>) {
    while (true){
        val (h, w) = readLine()?.split(" ")?.map { it.toInt() } ?: return
        if (h == 0 && w == 0) return
        for (i in h downTo 1){
            for (j in w downTo 1){
                if (j == 1) {
                    println("#")
                }else {
                    print("#")
                }
            }
        }
        println("")
    }
}



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

int main() {
  int A, B, X;
  cin >> A >> B >> X;
  
  if (A > X || (A+B) < X) {
    cout << "NO" << endl;
  } else {
    cout << "YES" << endl;
  }
  
}

Measured memory_bytes: 3612
N = int(input())
A = list(map(int, input().split()))
money = 1000
cnt = 0
if A[0] < A[1]:
    cnt += 1000 // A[0]
    money = money % A[0]
for i in range(1, N-1):
    if A[i] <= A[i - 1] and A[i] < A[i + 1]:
        cnt += money // A[i]
        money = money % A[i]
    elif A[i] >= A[i-1] and A[i] > A[i + 1]:
        money += cnt * A[i]
        cnt = 0
if cnt != 0:
    money += cnt * A[N - 1]
    cnt = 0
print(money)

Measured memory_bytes: 9204
n, m = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]
c = [list(map(int, input().split())) for _ in range(m)]

for i in a:
    mn = 10 ** 9
    record = 0
    for j, v in enumerate(c):
        temp = abs(i[0] - v[0]) + abs(i[1] - v[1])
        if temp < mn:
            mn = temp
            record = j + 1
    print(record)

Measured memory_bytes: 39280
#include<iostream>
using namespace std;
 
long long factorial(long long n){   // 再帰関数
  if(n==1){
    return 1;
  }else{
    return n*=factorial(n-1);
  }
}
 
int main(){
  int n;
  cin >> n;
 
  if(n>=1 && n<=20){
    cout << factorial(n) << endl; // 再帰
  }
  else{
    cout << "計算できません。" << endl;
  }
 
  return 0;
}

Measured memory_bytes: 1156
def main():
    N,P = map(int,input().split())
    s = list(input())[::-1]
    ary_mod = [0] * P
    ary_mod[0] = 1
    now = 0
    digit = 1
    ans = 0
    if P == 2:
        for i, ss in enumerate(s):
            if int(ss) % 2 == 0:
                ans += N-i
        print(ans)
        return
    if P == 5:
        for i, ss in enumerate(s):
            if int(ss) % 5 == 0:
                ans += N-i
        print(ans)
        return

    for i, ss in enumerate(s):
        now += int(ss) * digit % P
        digit *= 10
        digit %= P
        remind = now % P
        ary_mod[remind] += 1
    ans = 0
    for i, n in enumerate(ary_mod):
        ans += (n*(n-1)) // 2
    print(ans)
if __name__=='__main__':
    main()


Measured memory_bytes: 6308