akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
    int sx,sy,gx,gy;
    cin >> sx >> sy >> gx >> gy;
    vector<char> a;
   for(int i = sx - gx; i != 0; (sx > gx ? i-- : i++)){
       if(sx > gx)
       a.emplace_back('L');
       else if(sx < gx)
       a.emplace_back('R');
   }
   for(int i = sy - gy; i != 0; (sy > gy ? i-- : i++)){
       if(sy > gy)
       a.emplace_back('D');
       else if(sy < gy)
       a.emplace_back('U');
   }
   for(int i = sx - gx; i != 0; (sx > gx ? i-- : i++)){
       if(sx > gx)
       a.emplace_back('R');
       else if(sx < gx)
       a.emplace_back('L');
   }
   for(int i = sy - gy; i != 0; (sy > gy ? i-- : i++)){
       if(sy > gy)
       a.emplace_back('U');
       else if(sy < gy)
       a.emplace_back('D');
   }
   if(sx > gx)
    a.emplace_back('R');
    else if (sx < gx){
        a.emplace_back('L');
    }
    for(int i = abs(sy - gy) + 1; i > 0; i--){
        if(sy  < gy)
        a.emplace_back('U');
        else if(sy > gy)
        a.emplace_back('D');
    }
    for(int i = abs(sx - gx) + 1; i > 0; i--){
        if(sx < gx)
        a.emplace_back('R');
        else if(sy > gy)
        a.emplace_back('L');
    } 
    if(sy > gy)
    a.emplace_back('U');
    else if(sy < gy)
    a.emplace_back('D');
    if(sx > gx)
    a.emplace_back('L');
    else if(sx < gx)
    a.emplace_back('R');
    for(int i = abs(sy - gy) + 1; i > 0; i--){
        if(sy  < gy)
        a.emplace_back('D');
        else if(sy > gy)
        a.emplace_back('U');
    }
    for(int i = abs(sx - gx) + 1; i > 0; i--){
        if(sx < gx)
        a.emplace_back('L');
        else if(sy > gy)
        a.emplace_back('R');
    }
    if(sy > gy)
    a.emplace_back('D');
    else if(sy < gy)
    a.emplace_back('U');

    for(int i = 0; i < a.size(); i++){
        cout << a[i];
    }
    cout << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdio.h>
 
using namespace std;
 
#define int long long
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define trav(i, a) for (auto &i: (a))
#define sz(x) (int)(x).size()
#define all(v) (v).begin(), (v).end()
#define fr(i, a, b) for (int i = (a); i <= (b); ++i)

void solve();
signed main () {
    clock_t beg = clock();
    cout << fixed << setprecision(15);
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    #ifdef LOCAL
    freopen("input.txt", "r", stdin);
    #endif 
    int t=1; 
    // cin >> t;    
    int tt = t;
    while (t--) {
        // cout << "Case #" << tt - t << ": "; 
        // solve();
        int n;
        cin>>n;
        int K;
        cin>>K;
        int cost[n];
        rep(i,0,n){
            cin>>cost[i];
        }
        int dp[n+1]={0};
        for( int i=2;i<=n;i++){
            int op1= INT_MAX;
             for(int k=1;k<=K;k++){
                if(i-k>0){
                    op1 = min(op1,dp[i-k]+abs(cost[i-1]-cost[i-1-k]));
                }
            }
            dp[i]= op1;
        }
        // for( int i=1;i<=n;i++){
        //     cout<<dp[i]<<" ";
        // }
        // cout<<endl;
        cout<<dp[n];

    }
    // cerr << "\nExecution time: " << (clock() - beg) / 1000 << '\n';
    return 0;
}


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

signed main(){
    string S;
  	cin >>S;
    bool ans=false;
    if((S[0]==S[1] ||S[2]==S[3])&&S[1]==S[2]){
        ans =true;
    }
    if(ans){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
}


Measured memory_bytes: 256
N = int(input())
h = [int(x) for x in input().split()]

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

Measured memory_bytes: 13928
/*
I am not somebody you can put inside a box
And I am not somebody who will let you take my spot
It's written on my face I'm somebody who never stop
I do it because I gotta I don't do it for you props
Nah, you can keep those
I'm aiming way higher than planes in Heathrow
And I'm sorry to say but my game can't be sold
And look to be honest either you got it or don't
But if you got a dream and a vision
Put it in your mind that you gotta go out and get it
People try to stop you it's so hard in the beginning
But you said that you a winner so keep going ain't no quiting
I'm giving you the words that out me in this posotion
Some people hear and some people listen
Wanna be the best then you gotta learn the difference
*/
#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 int long long	
#define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout);
#define ll long long
#define vi vector < int >
#define pii pair < int, int > 
#define sz(s) (int)s.size()
#define all(x) x.begin(), x.end()                                                                    
#define pb push_back   
#define ppb pop_back
#define mp make_pair
#define s second
#define f first                                               
	
   
typedef tree < int, null_type, less < int >, rb_tree_tag, tree_order_statistics_node_update > ordered_set;   
   
const int N = 3e5 + 13, inf = 1e9, mod = 1e9 + 7, block = 444;
const int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1};
const ll INF = 1e18;
//fucking constants
 

int n, m, k, x[N], y[N], cntx[N], cnty[N];
multiset < int > q;
vi g[N];

main () {
	scanf("%d%d%d", &n, &m, &k);
	for (int i = 1; i <= k; ++i) {
		scanf("%d%d", &x[i], &y[i]);
		++cntx[x[i]];
		++cnty[y[i]];
		g[x[i]].pb(y[i]);
	}

	for (int i = 1; i <= m; ++i)
		q.insert(cnty[i]);

	int ans = 0;
	for (int i = 1; i <= n; ++i) {
		ans = max(ans, cntx[i]);
		for (auto j : g[i]) {
		    ans = max(ans, cntx[i] + cnty[j] - 1);
			q.erase(q.find(cnty[j])); 
		}

		if (sz(q))
			ans = max(ans, *q.rbegin() + cntx[i]);

		for (auto j : g[i])
			q.insert(cnty[j]);
	}

	cout << ans << endl;	
}

Measured memory_bytes: 38840
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
    int N;
    cin >> N;
    int ans = 0;
    for(int i = 1; i*i+i < N; i++) {
        if((N-i)%i == 0) {
            ans+=(N-i)/i;
        }
    } 
    cout << ans << endl;
}


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

int const MAXN=200000;
int A[MAXN], tmp[MAXN];

int main() {
  int N; std::cin >> N;
  for(int i = 0; i < N; ++i) std::cin >> A[i];
  std::copy_n(A, N, tmp);
  std::nth_element(tmp, tmp+N-2, tmp+N);
  int m1 = tmp[N-1], m2 = tmp[N-2];
  for(int i = 0; i < N; ++i) {
    if(A[i] == m1) std::cout << m2 << "\n";
    else           std::cout << m1 << "\n";
  }
  return 0;
}


Measured memory_bytes: 3200
import java.util.Scanner;

public class Main{
	public static void main(String[]args){
    Scanner sc=new Scanner(System.in);
      int n=sc.nextInt();
      int d=sc.nextInt();
      int sta=d*2+1;
      for(int i=0;i<20;i++){
      if(sta*i>=n){
      System.out.println(i);
        break;
      }
      }

    }
}


Measured memory_bytes: 23764
#include<cstdio>

int n, ans;
int v[111];

int main() {
	scanf("%d", &n);
	for(int i=0;i<n;i++) scanf("%d", &v[i]);
	ans = -1;
	for(int i=-100; i<=100;i++) {
		int res = 0;
		for(int j=0;j<n;j++)
			res += (v[j]-i) * (v[j]-i);
		if (ans < 0 || ans>res) ans=res;
	}
	printf("%d\n", ans);
	
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
#include<utility>
#include<string>
#include<utility>
using namespace std;

int main(){
    
    int n,l;
    cin >> n >> l;
    int ans=0;
    vector<int> v(n);
    int m = 1e9;
    for (int i = 0; i < n; i++)
    {
        v[i] = l + i;
        ans += v[i];
    }
    for (int i = 0; i < n; i++)
    {
        m = min(m,abs(v[i]));
    }
    
    if(ans<0){
        ans += m;
    }else{
        ans -= m;
    }
    cout << ans << endl;
    
}

Measured memory_bytes: 256
import sys, re
from math import ceil, floor, sqrt, pi, factorial, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left, bisect_right
from functools import reduce
from decimal import Decimal, getcontext
# input = sys.stdin.readline 
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_list(N): return [s_list() for _ in range(N)]
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7
num_list = []
str_list = []

def main():
    n = i_input()

    for _ in range(n):
        str_list.append(s_input())
    
    co_list = Counter(str_list)

    print('AC x', co_list['AC'])
    print('WA x', co_list['WA'])
    print('TLE x', co_list['TLE'])
    print('RE x', co_list['RE'])


if __name__ == '__main__':
    main()


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

#define all(x)  x.begin(), x.end()
#define mp      make_pair
#define pii     pair<int, int>
#define pll     pair<long long, long long>
#define ll      long long

int no() {
        puts("UNRESTORABLE");
        return 0;
}

bool same(string s, string t) {
        assert(s.size() == t.size());
        for (int i = 0; i < s.size(); i ++) {
                if (s[i] == '?') continue;
                if (s[i] != t[i]) return false;
        }
        return true;
}

int main() {
        string s, t;
        cin >> s >> t;
        int sl = s.size(), tl = t.size();
        vector<int> can;
        if (sl < tl) return no();
        for (int i = 0; i <= sl - tl; i ++) {
                if (same(s.substr(i, tl), t)) {
                        can.push_back(i);
                }
        }
        if (can.size() == 0) return no();
        string ans = "}";
        for (int i = 0; i < can.size(); i ++) {
                string ss = s;
                for (int j = 0; j < tl; j ++) {
                        ss[j + can[i]] = t[j];
                }
                for (int i = 0; i < ss.size(); i ++) if (ss[i] == '?') ss[i] = 'a';
                ans = min(ans, ss);
        }
        cout << ans << endl;
        return 0;
}



Measured memory_bytes: 256
from math import factorial
N,M = map(int,input().split())
mod = 10**9 + 7
ans = (factorial(N)* factorial(M))%mod
if abs(N-M) == 1:
  print(ans%mod)
elif abs(N-M) == 0:
  print(ans*2%mod)
else:
  print(0)

Measured memory_bytes: 5180
#include <bits/stdc++.h>
#define int long long
using namespace std;
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<pair<int, int> > v;
    for (int i=0; i < n; i++){
        int x, y;
        cin >> x >> y;
        v.push_back(make_pair(x, y));
    }
    set<pair<int, int> > a, b;
    for (int i=0; i < n; i++) a.insert(make_pair(v[i].first, i));
    for (int i=0; i < n; i++) b.insert(make_pair(v[i].second, i));
    int mv = 0, ans = 0, th = 0, pos = 0, nt = 0;
    while (nt < 2){
        if (mv == 0){
            if (a.size()){
                set<pair<int, int> >::iterator it = a.end();
                it--;
                pair<int, int> p = *it;
                if (p.first > pos){
                    nt = 0;
                    th += abs(p.first - pos);
                    pos = p.first;
                    int ind = p.second;
                    a.erase(it);
                    b.erase(b.find(make_pair(v[ind].second, ind)));
                }
                else nt++;
            }
            else nt++;
        }
        else{
            if (b.size()){
                set<pair<int, int> >::iterator it = b.begin();
                pair<int, int> p = *it;
                if (p.first < pos){
                    nt = 0;
                    th += abs(p.first - pos);
                    pos = p.first;
                    int ind = p.second;
                    b.erase(it);
                    a.erase(a.find(make_pair(v[ind].first, ind)));
                }
                else nt++;
            }
            else nt++;
        }
        mv ^= 1;
    }
    th += abs(pos);
    ans = max(ans, th);
    mv = 1, th = 0, pos = 0, nt = 0;
    a.clear(), b.clear();
    for (int i=0; i < n; i++) a.insert(make_pair(v[i].first, i));
    for (int i=0; i < n; i++) b.insert(make_pair(v[i].second, i));
    while (nt < 2){
        if (mv == 0){
            if (a.size()){
                set<pair<int, int> >::iterator it = a.end();
                it--;
                pair<int, int> p = *it;
                if (p.first > pos){
                    nt = 0;
                    th += abs(p.first - pos);
                    pos = p.first;
                    int ind = p.second;
                    a.erase(it);
                    b.erase(b.find(make_pair(v[ind].second, ind)));
                }
                else nt++;
            }
            else nt++;
        }
        else{
            if (b.size()){
                set<pair<int, int> >::iterator it = b.begin();
                pair<int, int> p = *it;
                if (p.first < pos){
                    nt = 0;
                    th += abs(p.first - pos);
                    pos = p.first;
                    int ind = p.second;
                    b.erase(it);
                    a.erase(a.find(make_pair(v[ind].first, ind)));
                }
                else nt++;
            }
            else nt++;
        }
        mv^=1;
    }
    th += abs(pos);
    ans = max(ans, th);
    cout << ans;
    return 0;
}


Measured memory_bytes: 16368
#include <bits/stdc++.h>
#define FOR(i, k, n) for(int i = (k); i < (n); i++)
#define FORe(i, k, n) for(int i = (k); i <= (n); i++)
#define FORr(i, k, n) for(int i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(int i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;
using ll = long long;
using P = pair<int, int>;

const int INF = 1001001001;

struct UnionFind{
  vector<int> par;
  UnionFind(int n) : par(n, -1){}
  int root(int x){ return (par[x] < 0) ? x : par[x] = root(par[x]); }
  int size(int x){ return -par[root(x)]; }
  bool issame(int x, int y){ return root(x) == root(y); }
  void marge(int x, int y){
    x = root(x); y = root(y);
    if(x == y) return;
    if(x > y) swap(x, y);
    par[x] += par[y];
    par[y] = x;
  }
};

int main(void){
  ll n, m;
  cin >> n >> m;
  UnionFind uf(n);
  vector<P> bridges(m);
  REP(i, m){
    int a, b;
    cin >> a >> b;
    a--; b--;
    bridges[i] = P(a, b);
  }

  vector<ll> ans(m);
  ans[m-1] = n*(n-1)/2;
  FORr(i, m, 0){
    int a = bridges[i].first;
    int b = bridges[i].second;
    if(uf.issame(a, b)){
      ans[i-1] = ans[i];
      continue;
    }
    ll sa = uf.size(a);
    ll sb = uf.size(b);
    ans[i-1] = ans[i] - sa * sb;
    uf.marge(a, b);
  }
  REP(i, m) cout << ans[i] << endl;
  return 0;
}

Measured memory_bytes: 3328
// #pragma GCC target("avx2")  // CPU 処理並列化
// #pragma GCC optimize("O3")  // CPU 処理並列化
// #pragma GCC optimize("unroll-loops")  // 条件処理の呼び出しを減らす
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
#include<numeric>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-10;
const double INF=1e+10;
const double PI=acos(-1.0);
const int C_SIZE = 3121000;
long long fact[C_SIZE];
long long finv[C_SIZE];
long long inv[C_SIZE];
long long Comb(int a,int b){
 	if(a<b||b<0)return 0;
 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
}
void init_C(int n){
	fact[0]=finv[0]=inv[1]=1;
	for(int i=2;i<n;i++){
		inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
	}
	for(int i=1;i<n;i++){
		fact[i]=fact[i-1]*i%mod;
		finv[i]=finv[i-1]*inv[i]%mod;
	}
}
long long pw(long long a,long long b){
	if(a<0LL)return 0;
	if(b<0LL)return 0;
	long long ret=1;
	while(b){
		if(b%2)ret=ret*a%mod;
		a=a*a%mod;
		b/=2;
	}
	return ret;
}
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
double ABS(double a){return max(a,-a);}
int sig(double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; }
// ここから編集しろ
char in[110000];

int main(){
	scanf("%s",in);
	int a;scanf("%d",&a);
	int n=strlen(in);
	for(int i=0;i<n;i+=a)printf("%c",in[i]);printf("\n");
}

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

typedef long long ll;

vector<vector<int>> edges;
int N, K;
ll MOD = 1e9 + 7;

ll dfs(int currentNode, int parentNode)
{
    int colors = K;
    int size = edges.at(currentNode).size();
    if(parentNode == -1){
        colors -= 1;
    }else {
        colors -= 2;
        size--;
    }
    if (colors < size){
        return 0;
    }
    ll currentCount = 1;
    for(int i = 0; i < size; i++){
        currentCount *= colors;
        currentCount %= MOD;
        colors--;
    }
    for(int nextNode: edges.at(currentNode)){
        if(nextNode == parentNode){
            continue;
        }
        currentCount *= dfs(nextNode, currentNode);
        currentCount %= MOD;        
    }
    return currentCount;
}

int main()
{
    cin >> N >> K;
    edges = vector<vector<int>>(N);
    for (int i = 0; i < N - 1; i++)
    {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        edges.at(a).push_back(b);
        edges.at(b).push_back(a);
    }

    cout << (K * dfs(0, -1)) % MOD << endl;
    return 0;
}

Measured memory_bytes: 9216
#include <iostream>
#include <stack>
#include <math.h>
#include <vector>
#include <string>
#include <algorithm>
#include <map>

#define rep(i,n) for(int i=0; i < n; i++)
using ll =  long long;
using namespace std;
#define pi 3.14159265358979

int main()
{
	int size, count = 0, count1 = 0, count2 = 0;
	cin >> size;
	vector<int> v(size);		//順番に入れ替えてチェックする用の順列
	vector<int> first(size);	//1個目の順列
	vector<int> second(size);	//2個目の順列

	//チェックする順列の入力を受け取る
	rep(i, size) { cin >> first[i]; }
	rep(i, size) { cin >> second[i]; }
	
	//チェック用順列の初期化
	rep(i, size)
	{
		v[i] = i+1;
	}

	//順列が存在する限り繰り返す
	do {
		count++;	//何個目の順列をチェックしているか記録

		rep(i, size)
		{
			//順列が一致したとき、辞書順で何番目だったかか記録
			if (count1 == 0 && v == first ) count1 = count;
			if (count2 == 0 && v == second) count2 = count;

			//チェックの途中であっても二つとも一致したらループを抜ける
			if (count1 != 0 && count2 == 0) break;
		}
	} while (std::next_permutation(v.begin(), v.end()));

	cout << abs(count1 - count2) << endl;
}

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

int main() {
	vector<int> vec; int tn, fn, en; cin >> tn;
	for (int i = 0; i < tn; i++) {
		cin >> fn;
		switch (fn) {
		case 0: cin >> en; vec.push_back(en); break;
		case 1: cin >> en; cout << vec[en] << endl; break;
		case 2: vec.pop_back(); break;
		}
	}
	return 0;
}


Measured memory_bytes: 3784
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;cin>>N;
  vector<int>P(N),Q(N),K(N);
  for(int X=0;X<N;X++){
    cin>>P[X];
  }
  for(int X=0;X<N;X++){
    cin>>Q[X];
  }
  for(int X=0;X<N;X++){
    K[X]=X+1;
  }
  int A,B;
  int M=0;
  do{
    M++;
    if(K==P){
      A=M;
    }
    if(K==Q){
      B=M;
    }
  } while (next_permutation(K.begin(), K.end()));
  cout<<abs(A-B)<<endl;
}

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

int main() {
    int N;
    cin >> N;
    string S;
    cin >> S;
    vector<ll> R(N+1, 0), G(N+1, 0), B(N+1, 0);
    for (int i = 0; i < N; i++) {
        if (i > 0) {
            R[i] = R[i-1];
            G[i] = G[i-1];
            B[i] = B[i-1];
        }
        if (S[i] == 'R') R[i]++;
        else if (S[i] == 'G') G[i]++;
        else B[i]++;
    }
    
    ll ans = 0;
    for (int i = 1; i <= N-2; i++) {
        for (int j = i+1; j <= N-1; j++) {
            if (S[i] == S[j]) continue;
            int k = i-(j-i);
            if (S[i] != 'R' && S[j] != 'R') {
                ans += R[i-1];
                if (k >= 0 && S[k] == 'R') ans--;
            }
            if (S[i] != 'G' && S[j] != 'G') {
                ans += G[i-1];
                if (k >= 0 && S[k] == 'G') ans--;
            }
            if (S[i] != 'B' && S[j] != 'B') {
                ans += B[i-1];
                if (k >= 0 && S[k] == 'B') ans--;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3696
#define _USE_MATH_DEFINES

#include <array>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <utility>
#include <tuple>
#include <algorithm>
#include <limits>
#include <fstream>
#include <numeric>
#include <stack>
#include <queue>
#include <list>
#include <cstring>
#include <unordered_set>
#include <cmath>
#include <iomanip>

namespace
{
	template<int N>
	std::array<int, N> GetValue(std::istream& stream)
	{
		std::string buf;
		std::getline(stream, buf);

		std::stringstream sstr(buf);
		std::array<int, N> retval;

		for (int i = 0; i < N; ++i)
		{
			std::getline(sstr, buf, ' ');
			retval[i] = std::stoi(buf);
		}

		return retval;
	}

	std::vector<int> GetValue(std::istream& stream, int num, char delim)
	{
		std::string buf;
		std::getline(stream, buf);
		std::stringstream sstr(buf);

		std::vector<int> retval;
		retval.reserve(num);

		std::string input;;
		for (int i = 0; i < num && std::getline(sstr, input, delim); ++i)
		{
			retval.push_back(std::stoi(input));
		}

		return retval;
	}

	int GetValue(std::istream& stream)
	{
		int in;
		stream >> in;

		return in;
	}

	std::vector<std::string> GetValueString(std::istream& stream, int num, char delim)
	{
		std::string buf;
		std::vector<std::string> retval;
		retval.reserve(num);

		std::getline(stream, buf);
		std::stringstream sstr(buf);

		for (int i = 0; i < num && std::getline(sstr, buf, delim); ++i)
		{
			retval.push_back(std::move(buf));
		}

		return retval;
	}

	template<typename Itr>
	void PrintLine(Itr begin, Itr end, int index)
	{
		bool first = true;

		for (int i = 0; begin != end; ++begin, ++i)
		{
			if (!first)
			{
				std::cout << ' ';
			}

			if (i == index)
			{
				std::cout << '[' << *begin << ']';
			}
			else
			{
				std::cout << *begin;
			}

			first = false;
		}
		std::cout << std::endl;
	}

	template<typename T>
	void Print(const std::vector<T>& sequence)
	{
		for (const auto& e : sequence)
		{
			std::cout << e << '\n';
		}

		std::cout << std::flush;
	}

	int Partition(int* sequence, int first, int last)
	{
		const int pivot = sequence[last];
		int large_index = first;

		for (int i = first; i < last; ++i)
		{
			if (sequence[i] <= pivot)
			{
				std::swap(sequence[large_index], sequence[i]);
				++large_index;
			}
		}

		std::swap(sequence[large_index], sequence[last]);

		return large_index;
	}
}

int main(int argc, char* argv[])
{
	auto file = (argc == 1) ? std::ifstream() : std::ifstream(argv[1]);
	std::istream& stream = (argc == 1) ? std::cin : file;
	if (argc == 1)
	{
		std::cin.tie(0);
		std::ios::sync_with_stdio(false);
	}

	int num = GetValue<1>(stream)[0];
	std::vector<int> sequence =
		GetValue(stream, num, ' ');

	int index = Partition(&sequence[0], 0, sequence.size() - 1);

	PrintLine(sequence.begin(), sequence.end(), index);
}



Measured memory_bytes: 4324
#include <bits/stdc++.h>
#define int long long
#define double long double
#define rep(i, a, n) for(int i = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int i = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int i = (int)(a);(x);++(i))
#define repr(i, a, n) for(int i = ((int)(a)-1);(i) >= (int)(n);--(i))
#define reper(i, a, n) for(int i = (int)(a);(i) >= (int)(n);--(i))
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x), end(x)
#define CEIL(x) ((int)ceil(((double)x)))
#define POW(x, y) ((int)pow(x, y))
#define UNIQUE(x) (x).erase(unique(ALL((x))), end(x))
#define gcd(x, y) __gcd(x, y)
#define lcm(x, y) ((x)/gcd(x,y)*(y))
#define isin(x, l, r) ((l) <= (x) and (x) < (r))
#define fcout(n) cout << fixed << setprecision(n)
#define rcout(n) cout << right << setw(n)
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define PI (acosl(-1))
#define EPS (1e-10)
#define INF LLONG_MAX
#define INF32 INT32_MAX
#define MOD 1000000007LL
using namespace std;
using VI = vector<int>;
using PII = pair<int, int>;
using TIII = tuple<int, int, int>;
using VPII = vector<PII>;
using VTIII = vector<TIII>;
using Complex = complex<double>;
template<typename T, template<typename> typename C = less> using PQ = priority_queue<T, vector<T>, C<T>>;
template<typename T> bool chmax(T& a, const T& b, bool t = false){ if(a<b or (t and a == b)){ a=b; return true; } return false; }
template<typename T> bool chmin(T& a, const T& b, bool t = false){ if(a>b or (t and a == b)){ a=b; return true; } return false; }


int N;
int A[100010];
int B[100010];
int C[100010];


signed main(){
    cin >> N;
    rep(i, 0, N) cin >> A[i];
    rep(i, 0, N) cin >> B[i];
    rep(i, 0, N) cin >> C[i];

    sort(A, A+N);
    sort(C, C+N);

    int ans = 0;
    rep(i, 0, N){
        int a = lb(A, A+N, B[i])-A;
        int c = C+N-ub(C, C+N, B[i]);
        ans += a*c;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 2560
n = input()
n = int(n)
l1=[]
l2=[]
l1 = input().split(" ")
l2 = input().split(" ")
total=0;
for i in range(0,n):
	v1=int(l1[i])
	v2=int(l2[i])
	if(v1-v2>0):
		total = total+v1-v2
print(total)

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

/*
R8BH3W
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
//*/

#define y1 wwgp
#define endl '\n'
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound

#define mp  make_pair
#define pb  push_back
#define read(x) freopen(x".in","r",stdin);
#define write(x) freopen(x".out","w",stdout);
#define   sz(x)  (int)x.size()
#define  all(x)  x.begin(), x.end()
#define  bit(x)  __builtin_popcountll(x)

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
const int maxn = int(2e5)+666, maxn2 = int(1e6)+666;
int inf = LONG_MAX; ll linf = LLONG_MAX;
int mod = 69;
int kob (int x, int y) { return ((ll)x * 1ll * y) % mod; } 
int aza (int x, int y) { x -= y; if (x < 0) return x + mod; return x; } 
int kos (int x, int y) { x += y; if (x >= mod) return x - mod; return x; }
/// --------------------------@MAIN THEME-----------------------------------

int d[maxn][50];

main () { ios_base::sync_with_stdio(0); cin.tie(0);
	#ifdef ez
		read ("")
	#endif
	int n, k;
	cin >> n;
	for (int i = 1; i <= n; ++ i) {
		int a, b, c;
		cin >> a >> b >> c;
		if (i == 1)
		d[1][1] = a, d[1][2]=b,d[1][3]=c;
		else
		d[i][1]=a+max(d[i-1][2],d[i-1][3]),d[i][2]=max(d[i-1][1],d[i-1][3])+b,d[i][3]=max(d[i-1][1],d[i-1][2])+c;
	}

	cout << max (d[n][2], max (d[n][3], d[n][1]));
	return 0;	
}

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

typedef long long ll;
typedef unsigned long long ull;
struct edge { int u, v; ll w; };
 
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
  int X, t;
  cin >> X >> t;
  cout << max(X - t, 0) << endl;
}


Measured memory_bytes: 256
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n");
var rc=Arr[0].split(" ").map(Number);
var c=[];
for(var i=0;i<rc[1]+1;i++)c.push(0);

for(var i=1;i<Arr.length;i++){
   var arr=Arr[i].split(" ").map(Number);
   var sum=arr.reduce(function(a,b){return a+b;});
   console.log(Arr[i]+" "+sum);
   arr.push(sum);
   arr.forEach(function(v,i){c[i]+=v;});
}
console.log(c.join(" "));

Measured memory_bytes: 10172
def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [input().split() for _ in range(n)]
def s4(n):return [[x for x in s] for s in s2(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b,yes="Yes",no="No"): print(yes if b else no)
# from sys import setrecursionlimit
# setrecursionlimit(1000000)
# from collections import Counter,deque,defaultdict
# import itertools
# import math
# import networkx as nx
# from bisect import bisect_left,bisect_right
# from heapq import heapify,heappush,heappop
a,b,m=n1()
A=n1()
B=n1()
X=n3(m)

A2=sorted(A)
B2=sorted(B)
ans=A2[0]+B2[0]
for a,b,c in X:
    if A[a-1]+B[b-1]-c<ans:
        ans=A[a-1]+B[b-1]-c
    
print(ans)

Measured memory_bytes: 82884
/*
 * FileName:     C_fix_3
 * CreatedDate:  2020-04-10 21:00:27 +0900
 * LastModified: 2020-04-10 21:58:28 +0900
 */

#include <stdio.h>
long int max(long int s,long int t){
    if(s<t){return t;}
    return s;
}
int main(void){
    long int n;
    scanf("%ld",&n);
    int a[n],b[n],c[n];
    for(long int i=0;i<n;i++){
        scanf("%d %d %d",&a[i],&b[i],&c[i]);
    }
    long int dp[n+1][3];
    for(int i=0;i<n+1;i++){
        for(int j=0;j<3;j++){
            dp[i][j]=0;
        }
    }
    for(int i=n-1;i>=0;i--){
        for(int j=0;j<3;j++){
            if(j==0){
                dp[i][j]=max(dp[i+1][1],dp[i+1][2])+a[i];
            }
            else if(j==1){
                dp[i][j]=max(dp[i+1][0],dp[i+1][2])+b[i];
            }
            else{
                dp[i][j]=max(dp[i+1][0],dp[i+1][1])+c[i];
            }
        }
    }
    long int tmp=0;
    for(int i=0;i<3;i++){
        if(tmp<dp[0][i]){tmp=dp[0][i];}
    }
    printf("%ld\n",tmp);
    return 0;
}


Measured memory_bytes: 3712
class Card:
        def __init__(self, suit, num):
                self.suit = suit
                self.num = num

def bubbleSort(C, N):
        for i in range(N): 
                for j in range(N - 1, i, -1):
                        if C[j].num < C[j - 1].num:
                                C[j].num, C[j - 1].num = C[j - 1].num, C[j].num
                                C[j].suit, C[j - 1].suit = C[j - 1].suit, C[j].suit

def selectionSort(C, N):
        for i in range(N):
                minID = i
                for j in range(i, num):
                        if C[j].num  < C[minID].num:
                                minID = j
                C[i].num, C[minID].num = C[minID].num, C[i].num
                C[i].suit, C[minID].suit = C[minID].suit, C[i].suit

num = int(input())
list = input().split()

cardListA = []
cardListB = []
sortA = []
sortB = []

isSame = True

for i in range(num):
        cardListA.append(Card(list[i][0], list[i][1]))
        cardListB.append(Card(list[i][0], list[i][1]))

bubbleSort(cardListA, num)
selectionSort(cardListB, num)


for i in range(num):
        sortA.append(cardListA[i].suit + cardListA[i].num)
        sortB.append(cardListB[i].suit + cardListB[i].num)
        if sortA[i] != sortB[i]:
                isSame = False

print(" ".join(sortA))
print("Stable")
print(" ".join(sortB))
if isSame:
        print("Stable")
else:
        print("Not stable")


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

long long func(long long a,long long m){
    if(m==0)
        return 1;
    if(m==1)    
        return a%1000000007;
    long long res = func(a,m/2);
    res=(res*res)%1000000007;
    if(m%2)
        res=(res*a)%1000000007;
    return res;
    
}

int main() {
	long long h,w,n;
	cin>>h>>w>>n;
	vector<pair<long long,	long long> > p(n+1);
	for(long long i=0;i<n;i++){
	    cin>>p[i].first>>p[i].second;
	}
	p[n].first=h;
	p[n].second=w;
	long long fact[h+w+1],inv[h+w+1];
	fact[0]=1;
	inv[0]=1;
	for(long long i=1;i<h+w+1;i++)
	    fact[i]=(fact[i-1]*i)%1000000007;
	for(long long i=1;i<h+w+1;i++)
	    inv[i]=func(fact[i],1000000005);
	long long dp[n+1]={0};
	sort(p.begin(),p.end());
	for(long long i=0;i<n+1;i++){
	    dp[i]=(dp[i]+(fact[p[i].first+p[i].second-2]*((inv[p[i].first-1]*inv[p[i].second-1])%1000000007))%1000000007)%1000000007;
	    for(long long j=i+1;j<n+1;j++){
	        if(p[i].second<=p[j].second)
	        dp[j]=(1000000007+dp[j]-(dp[i]*((((fact[p[j].second+p[j].first-p[i].second-p[i].first]*inv[p[j].second-p[i].second])%1000000007)*inv[p[j].first-p[i].first])%1000000007))%1000000007)%1000000007;
	    }
	}cout<<dp[n];
}


Measured memory_bytes: 3456
#define rep(i, n) for (int i = 0; i < (n); i++)
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MOD = 1000000007;
// MAX int 2,147,483,647
// MAX O(n) 10^18

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

    int ans;
    if (N == 100) {
        if (D == 0) ans = 101;
        if (D == 1) ans = 10100;
        if (D == 2) ans = 1010000;
    } else {
        ans = pow(100, D) * N;
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3716
#include <algorithm>
#include <iostream>
#include <map>
#include <string>
#include <vector>

using namespace std;

#define rep(i, n) for (int i = 0; i < n; ++i)
#define repp(a, b, n) for (int i = a; i < b; ++i)
#define vint vector<int>

int main() {
	long h, w;
	cin >> h >> w;

	if(h == 1 || w == 1){
		cout << 1 << endl;
	}else{
		cout << (h * w + 1) / 2 << endl;
	}
}

Measured memory_bytes: 256
str = gets.chomp
size = str.size - 1

sum = 0
[0, 1].repeated_permutation(size){|arr|
    arr << 1
    temp = str[0].to_i
    arr.each_with_index{|x, i|
        case x
        when 0
            temp = temp * 10 + str[i + 1].to_i
        when 1
            sum += temp
            temp = str[i + 1].to_i
        end
    }
}
puts sum


Measured memory_bytes: 1788
H, W, D = map(int, input().split())
A = [[int(j) for j in input().split()] for i in range(H)]
B = [(-1, -1) for j in range(H*W)]
for i in range(H):
    for j in range(W):
        B[A[i][j]-1] = (i, j)

C = [-1] * H*W
for i in range(H*W-D):
    fx, fy = B[i+D]
    tx, ty = B[i]
    C[i] = abs(fx-tx)+abs(fy-ty)

E = [0] * H*W
for i in range(D):
    S = 0
    for j in range(i, H*W-D, D):
        S += C[j]
        E[j+D] = S
# print(E)

Q = int(input())
for _ in range(Q):
    L, R = map(int, input().split())
    print(E[R-1]-E[L-1])


Measured memory_bytes: 19544
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define FOR(i, a, done) for (int i = (a); i < (done); ++i)
#define all(a) (a).begin(), (a).end()
#define F first
#define S second
#define pb push_back
#define pf push_front

namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

ll M = 1000000007;
typedef pair<int, int> P;

int main()
{
    vector<double> x(3), y(3);
    rep(i, 3)
    {
        cin >> x[i] >> y[i];
    }
    vector<double> dis(3);
    dis[0] = sqrt(pow(x[0] - x[1], 2) + pow(y[0] - y[1], 2));
    dis[1] = sqrt(pow(x[2] - x[1], 2) + pow(y[2] - y[1], 2));
    dis[2] = sqrt(pow(x[2] - x[0], 2) + pow(y[2] - y[0], 2));
    double s = (dis[0] + dis[1] + dis[2]) / 2.0;
    /*へロンの公式*/
    double area = sqrt(s * (s - dis[0]) * (s - dis[1]) * (s - dis[2]));
    //h*dis[0]/2=area
    //h=area*2/dis[0]
    vector<double> h(3);
    rep(i, 3)
    {
        h[i] = area * 2 / dis[i];
    }
    vector<double> b(3);
    
    rep(i, 3)
    {
        b[i]=s+h[i];
    }
    double ans = 0.0;
    rep(i, 3)
    {
        double r;
        r=area/b[i];
        ans = max(r, ans);
    }
    cout << setprecision(12) << ans  << endl;
}

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

int main()
{
    int a, b;
    cin >> a >> b;
    if (a * b % 2 == 0)
    {
        cout << "Even" << endl;
    }
    else
    {
        cout << "Odd" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
using ld = long double;
static inline void fast_io()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
}

int main()
{
    fast_io();

    ll n;
    cin >> n;
    ll cnt = 0, div = 0;
    while (n % 2 == 0) {
        div++;
        n /= 2;
    }
    for (ll i = 1; i <= div; i++) {
        div -= i;
        cnt++;
    }
    for (int i = 3; i <= sqrt(n * 1.0); i += 2) {
        div = 0;
        while (n % i == 0) {
            div++;
            n /= i;
        }
        for (ll i = 1; i <= div; i++) {
            div -= i;
            cnt++;
        }
    }
    if (n != 1) {
        cnt++;
    }
    cout << cnt;
}


Measured memory_bytes: 3192
#include <stdio.h>

int main(void)
{
    int a, b, y, counter, setcount;
    setcount = 0;
    while(1){
        counter = 0;
        scanf("%d %d", &a, &b);
        setcount++;
        if (a == 0&& b == 0){
            break;
        }
        y = a;
        if (setcount != 1)// print a line at the begining if it != the first set
            {
                printf("\n");
            }
        for (int i = a; i <= b; i++){// y == i
            if (!(y%400)){
                printf("%d\n", y);
                counter++;
            }else if((!(y%4)) && y%100){
                printf("%d\n", y);
                counter++;
            }
            y++;
        }
        if (counter == 0){//detech whether leap year appears
            printf("NA\n");
        }
    }
    return 0;
}
        
    

Measured memory_bytes: 1040
#include<stdio.h>
                 
                int main()
                {
                	char S[10];
                	scanf("%s", S);
                 
                	int ans = 0;
                	for (int i = 0; i < 4; ++i) {
                		if (S[i] == '+') ++ans;
                		else --ans;
                	}
                	printf("%d\n", ans);
                	return 0;
                }

Measured memory_bytes: 128
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        
        String result = "bust";
        if (a+b+c <= 21) result = "win";
        
        System.out.println(result);
    }
}


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

using namespace std;
using llong = long long;
using P = pair<llong, llong>;

#define BE(x) x.begin(), x.end()

const llong inf = llong(1e18)+7;
const llong mod = 1e9+7;

int main(){
	llong x,y;
	cin >> x >> y;

	if(x%y == 0)
		cout << -1 << endl;
	else
		cout << x << endl;

	return 0;
}

Measured memory_bytes: 256
import math

MOD = int(10**9 + 7)

def egcd(a, b):
    if a ==  0:
        return (b, 0, 1)
    else:
        g, y, x = egcd(b%a, a)
        return (g, x - (b//a) * y, y)

def modinv(a, m):
    g, x, y = egcd(a, m)
    if g != 1:
        raise Exception("No inverse exists")
    else:
        return x % m

def combination(n, r):
    return math.factorial(n)%MOD * modinv(math.factorial(r), MOD) * modinv(math.factorial(n-r), MOD) % MOD
    # return math.factorial(n) // math.factorial(r) // math.factorial(n-r)

N, M, K = map(lambda x: int(x), input().split())

ans = 0

k = combination(N*M-2, K-2)

for d in range(1, N):
    ans += (d * k * M * M * (N - d))%MOD

for d in range(1, M):
    ans += (d * k * N * N * (M - d))%MOD

print(ans % MOD)


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


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll s;cin>>s;
    ll M = 1e9;
    ll x2 = M,x3=(M*M-s)%M,y2=1,y3=(s+M-1)/M;
    cout<<"0 0 "<<x2<<" "<<y2<<" "<<x3<<" "<<y3<<endl;
    //cout<<x2*y3-x3*y2;
    return 0;
}

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

int main(){
	string s; cin >> s;
	if(s == "AAA" || s == "BBB")cout << "No" << endl;
	else cout << "Yes" << endl;

}

Measured memory_bytes: 256
using System.Linq;
using System.Collections.Generic;
using System;

public class P
{
    public int x { get; set; }
    public int y { get; set; }
    public int d { get; set; }
    public int p { get; set; }
}

public class Hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var h = int.Parse(line[0]);
        var w = int.Parse(line[1]);
        var n = int.Parse(Console.ReadLine().Trim());
        line = Console.ReadLine().Trim().Split(' ');
        var a = Array.ConvertAll(line, int.Parse);
        var aa = new int[h * w];
        var p = 0;
        for (int i = 0; i < n; i++)
            for (int j = 0; j < a[i]; j++)
                aa[p++] = i + 1;
        var ans = getAns0(h, w, n, aa);
        print(h, w, ans);
    }
    static void print(int h, int w, int[,] a)
    {
        var t = new int[w];
        for (int i = 0; i < h; i++)
        {
            for (int j = 0; j < w; j++)
                t[j] = a[i, j];
            Console.WriteLine(string.Join(" ", t));
        }
    }
    static int[,] getAns0(int h, int w, int n, int[] a)
    {
        var dx = new int[] { 0, 1, 0, -1 };
        var dy = new int[] { 1, 0, -1, 0 };
        var hw = h * w;
        var t = new int[h, w];
        var q = new Queue<P>();
        q.Enqueue(new P { x = 0, y = 0, d = 0, p = 0 });
        while (q.Count() > 0)
        {
            var tt = q.Dequeue();
            if (tt.p == hw) continue;
            t[tt.x, tt.y] = a[tt.p];
            var nx = tt.x + dx[tt.d];
            var ny = tt.y + dy[tt.d];
            if (nx >= 0 && nx < h && ny >= 0 && ny < w && t[nx, ny] == 0)
                q.Enqueue(new P { x = nx, y = ny, d = tt.d, p = tt.p + 1 });
            else
            {
                var nd = (tt.d + 1) % 4;
                 nx = tt.x + dx[nd];
                 ny = tt.y + dy[nd];
                q.Enqueue(new P { x = nx, y = ny, d = nd, p = tt.p + 1 });
            }
        }
        return t;
    }
}

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

int main()
{
	int n; cin >> n;
	
	vector<int> x(n); for (int i = 0; i < n; i++) cin >> x[i];

	long long ans = 9223372036854775807LL;

	for (int j = 1; j <= 100; j++) {

		long long sum = 0LL;

		for (int i = 0; i < n; i++) {
			sum += (x[i] - j)*(x[i] - j);
		}

		ans = min(ans, sum);

	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
inline void read (int &x) {
	char ch = getchar(); x = 0;
	while (!isdigit(ch)) ch = getchar();
	while (isdigit(ch)) x = x * 10 + ch - 48, ch = getchar();
} const int N = 538;
int n, f[N][N], res, k[N][N];
int dx[4] = {0, -1, 0, 1}, dy[4] = {1, 0, -1, 0};
void update (int x, int y) {
	for (int i = 0; i < 4; ++i) {
		int tx = x + dx[i], ty = y + dy[i];
		if (tx < 1 || ty < 1 || tx > n || ty > n) continue;
		if (f[tx][ty] > f[x][y] + (k[x][y] ^ 1))
			f[tx][ty] = f[x][y] + (k[x][y] ^ 1), update (tx, ty);
	}
}
signed main() {
	read (n); int tmp; 
	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= n; ++j) 
			f[i][j] = min (i - 1, min (n - i, min (j - 1, n - j)));
	for (int i = 1, x, y; i <= n * n; ++i) {
		read (tmp); 
		y = tmp % n + n * (tmp % n == 0);
	    x = tmp / n + (y != n); //printf ("%d %d %d\n", x, y, f[x][y]);
		res += f[x][y], k[x][y] = 1; update (x, y);
	} return printf ("%d\n", res), 0;
}

Measured memory_bytes: 21124
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }

size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }

long mod = 10^^9 + 7;
//long mod = 998_244_353;
//long mod = 1_000_003;
void moda(T)(ref T x, T y) { x = (x + y) % mod; }
void mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(T)(ref T x, T y) { x = (x * y) % mod; }
void modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }

void main()
{
	auto N = RD;
	auto D = new bool[](N);
	foreach (i; 0..N)
	{
		auto d1 = RD;
		auto d2 = RD;
		D[i] = d1 == d2;
	}

	bool ans;
	foreach (i; 0..N-2)
	{
		if (D[i] && D[i+1] && D[i+2])
			ans = true;
	}
	
	writeln(ans ? "Yes" : "No");
	stdout.flush;
	debug readln;
}


Measured memory_bytes: 2760
/**
 * Created by hiramekun at 23:36 on 2020-05-19.
 */
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using P = pair<ll, ll>;
template<typename T> using pq = priority_queue<T>;
template<typename T> using minpq = priority_queue<T, vector<T>, greater<T>>;
template<typename T, typename K> using ump = unordered_map<T, K>;
const ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll e5 = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = ll(n - 1); i >= 0; i--)
#define each(i, mp) for(auto& i:mp)
#define eb emplace_back
#define F first
#define S second
#define all(obj) (obj).begin(), (obj).end()

template<class T>
ostream &operator<<(ostream &out, const vector<T> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << ' ';
    return out;
}

template<class T>
istream &operator>>(istream &in, vector<T> &list) {
    ll n = list.size();
    rep(i, n) in >> list[i];
    return in;
}

template<class T>
ostream &operator<<(ostream &out, const vector<vector<T>> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << '\n';
    return out;
}

/* ------------- ANSWER ------------- */
/* ---------------------------------- */

void solve() {
    ll a, b;
    cin >> a >> b;
    rep(i, b * 2 * 10) {
        if (ll(i * 0.08) == a && ll(i * 0.1) == b) {
            cout << i << '\n';
            return;
        }
    }
    cout << -1 << '\n';
}

int main() {
#ifdef MY_DEBUG
    while (true) {
#endif
        solve();
#ifdef MY_DEBUG
    }
#endif
    return 0;
}

Measured memory_bytes: 256