akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>


using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
template <class T> int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define clear(arr, val) memset(arr, val, sizeof(arr))

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

template <class T> void max_swap(T& a, const T& b) { a = max(a, b); }
template <class T> void min_swap(T& a, const T& b) { a = min(a, b); }

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

const double EPS = 1e-8;
const double PI = acos(-1.0);
const int dx[] = { 0, 1, 0, -1 };
const int dy[] = { 1, 0, -1, 0 };



int main()
{
	int n, m, p, a, b, uma[16];
	while (cin >> n >> m >> p >> a >> b, n)
	{
		--a, --b;
		for (int i = 0; i < n; ++i)
			cin >> uma[i];
		vector<pint> edge[32];
		for (int i = 0; i < p; ++i)
		{
			int x, y, z;
			cin >> x >> y >> z;
			--x, --y;
			edge[x].push_back(pint(y, z));
			edge[y].push_back(pint(x, z));
		}

		const double INF = 1e19;
		static double dp[1 << 8][32];
		for (int i = 0; i < 1 << n; ++i)
			for (int j = 0; j < 30; ++j)
				dp[i][j] = INF;
		dp[0][a] = 0;
		for (int s = 0; s < 1 << n; ++s)
		{
			for (int i = 0; i < 30; ++i)
			{
				if (dp[s][i] == INF)
					continue;
				foreach (it, edge[i])
				{
					int to = it->first, len = it->second;
					for (int j = 0; j < n; ++j)
					{
						if (!(s >> j & 1))
							min_swap(dp[s | (1 << j)][to], dp[s][i] + (double)len / uma[j]);
					}
				}
			}
		}
		double res = INF;
		for (int i = 0; i < 1 << n; ++i)
			min_swap(res, dp[i][b]);
		if (res == INF)
			cout << "Impossible" << endl;
		else
			cout << res << endl;
	}
}

Measured memory_bytes: 0
//BISMILLAHIR RAHMANIR RAHIM
#include <bits/stdc++.h>
#define mem(a, b) (memset(a, b, sizeof(a)))
#define pb push_back
#define mk make_pair
#define ff first
#define ss second
#define PI acos(-1)
#define INF 2147483647
#define MOD 1000000007
#define MAX 100005
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<int, ii> pii;
typedef vector<ii> vii;
typedef priority_queue<int,vector<int>,greater<int> > PQ;

int Set(int mask, int pos){return mask = mask | (1<<pos);}
bool check(int mask, int pos){return (bool)(mask & (1<<pos));}

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

    int k;

    cin>>k;

    ll sum = 0;
    for(int i = 1; i <= k; i++){
        for(int j = 1; j <= k; j++){
            for(int m = 1; m <= k; m++){
                int ans = __gcd(i, __gcd(j, m));
                sum += (ll) ans;
            }
        }
    }

    cout<<sum<<endl;

    return 0;
}


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

int main(){
  ll k; 
  string s;
  cin >> s >> k;
  string t = s;
  s += '#';
  int n = sz(s);
  ll cnt1 = 0;
  map<int,int> mp1;
  int prev = 0;
  for (int i = 0; i < n; i++) {
    if (s[prev] != s[i]) {
      mp1[prev] = i - prev;
      prev = i;
    }
  }
  if (mp1.size() == 1) {
    cout << k * (n-1) / 2 << endl;
    return 0;
  } 
  for (auto e : mp1) cnt1 += (e.second / 2);
  t += s;
  ll cnt2 = 0;
  int m = sz(t);
  map<int,int> mp2;
  prev = 0;
  for (int i = 0; i < m; i++) {
    if (t[prev] != t[i]) {
      mp2[prev] = i - prev;
      prev = i;
    }
  }
  for (auto e : mp2) cnt2 += (e.second / 2);

  ll dif = cnt2 - cnt1 * 2;
  cout << k * cnt1 + (k-1) * dif << endl; 
  return 0;
} 

Measured memory_bytes: 256
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
#      .      '                    Udit Gupta @luctivud         ,              
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                            ##     ##  #######  # #  ######
                            ##     ##  ##   ##  ###    ##
                            ##     ##  ##    #  # #    ##
                            #########  #######  # #    ##
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

import sys
import math as mt
# sys.setrecursionlimit(10**6)

def get_ints(): return map(int, sys.stdin.readline().strip().split())
def get_array(): return list(map(int, sys.stdin.readline().strip().split()))

def printwsp(*args): return print(*args, end="")
def printsp(*args): return print(*args, end=" ")
def printchk(*args): return print(*args, end="tst, ")

MOD = int(1e9+7); BABYMOD = 998244353;
# ################################ HELPER PROGRAMS USED ###################################
# ################################## MAIN STARTS HERE #####################################
# for _testcases_ in range(int(input())):
k = int(input())
a, b = get_ints()
boo = False
if a%k == 0:
    boo = True
elif b%k == 0:
    boo = True
else:
    start = a // k
    end = b // k
    if start != end:
        boo = True
if boo:
    print("OK")
else:
    print("NG")


# #########################################################################################
'''
THE LOGIC AND APPROACH WAS DEVELOPED BY ME @luctivud.
SOME PARTS OF THE CODE HAS BEEN TAKEN FROM WEBSITES LIKE::
(I Own the code if no link is provided here or I may have missed mentioning it)
PLEASE DO NOT PLAGIARISE.
'''

Measured memory_bytes: 62044
#include <cstdio>


char board[20][20] = {};
int W, H;

int count(int x, int y) {
	if (board[x][y] == '#') return 0;
	if (x < 0 || W <= x) return 0;
	if (y < 0 || H <= y) return 0;

	board[x][y] = '#';

	return 1 +
		count(x - 1, y) +
		count(x + 1, y) +
		count(x, y - 1) +
		count(x, y + 1);
}

int main() {
	while (true) {

		scanf("%d %d", &W, &H);

		if (W == 0) break;

		int cx, cy;

		for (int y = 0; y < H; y++) {
			char buf[21];
			scanf("%s", buf);
			for (int x = 0; x < W; x++) {
				board[x][y] = buf[x];
				if (buf[x] == '@') {
					cx = x; cy = y;
				}
			}
		}

		printf("%d\n", count(cx, cy));
	}

	return 0;
}

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

using namespace std;

int gcd(int a, int b){
    int r;
    while (b > 0){
        r = a % b;
        a = b;
        b = r;
    }
    return a;
}

bool isprime(int x){
    if (x == 2) return true;
    if (x < 2 || x % 2 ==0) return false;
    
    int i = 3;
    while(i <=  sqrt(x)){
        if (x % i == 0) return false;
        i +=  2;
    }
    return true;
}




int main() {
    int n, cnt=0;
    cin >> n;
    for (int i; i<n; i++) {
        bool judge;
        int num;
        cin >> num;
        judge=isprime(num);
        if(judge) cnt += 1;
    }
    cout << cnt << endl;
}




Measured memory_bytes: 3092
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1000000000
#define LINF 1000000000000000000
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL<<(n))
using namespace std;

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

int main() {

    string S;
    cin >> S;
    cout << (S[1] == 'B' ? "ARC" : "ABC") << endl;
    
    return 0;
}

Measured memory_bytes: 3592
// template version 1.8

// varibable settings {{{
using namespace std;
#include <iostream>
#include <bits/stdc++.h>

#define int long long
const int INF=1e18;
const int MOD=1e9+7;
#define infile "../test/sample-1.in"
int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};
#define fi first
#define se second

// }}}

// define basic macro {{{
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)(b-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
template<class T> inline void chmax(T &a, const T &b) { if(a < b) a = b; }
template<class T> inline void chmin(T &a, const T &b) { if(a > b) a = b; }

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;
template<typename T> using PQ = priority_queue<T, vector<T>, greater<T>>;

// dump macro
#ifdef PCM
  #include "dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
#endif
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;
// }}}


int solve(){
  int h,w,n;cin>>h>>w>>n;
  int sr,sc;cin>>sr>>sc;
  sr--;sc--;
  dump(sr,sc);
  string s,t;cin>>s>>t;
  reverse(all(s));
  reverse(all(t));

  int l=0;
  int r=w;
  // [l, r)
  rep(i, n){
    if (t[i]=='R' and l>0) l--;
    if (t[i]=='L' and r<w) r++;
    dump(l, r);
    if (l>=r) {
      cout << "NO" << endl;
      return 0;
    }
    if (s[i]=='R' and r>0) r--;
    if (s[i]=='L' and l<w) l++;
    dump(l, r);
    if (l>=r) {
      cout << "NO" << endl;
      return 0;
    }
  }
  if (l<=sc && sc<r){
  }
  else{
    cout << "NO" << endl;
    return 0;
  }

  dump("hello");

  l=0;
  r=h;
  rep(i, n){
    if (t[i]=='D' and l>0) l--;
    if (t[i]=='U' and r<h) r++;
    dump(l, r);
    if (l>=r) {
      cout << "NO" << endl;
      return 0;
    }
    if (s[i]=='D' and r>0) r--;
    if (s[i]=='U' and l<h) l++;
    dump(l, r);
    if (l>=r) {
      cout << "NO" << endl;
      return 0;
    }
  }
  if (l<=sr && sr<r){
  }
  else{
    cout << "NO" << endl;
    return 0;
  }

  cout << "YES" << endl;

  return 0;
}

signed main() { //{{{
#ifdef INPUT_FROM_FILE
  std::ifstream in(infile);
  std::cin.rdbuf(in.rdbuf());
#endif
  solve();
  return 0;
} //}}}


Measured memory_bytes: 920
#include<iostream>
#include<cctype>
#include <algorithm>
#include<string>
using namespace std;
int main(){
        string p;
        string in;
        string s[10000] ={""};
        getline(cin, p);
        int n = 0;
        int k = 0;
        int q = 0;
        bool j = true;
        while(1){
                getline(cin,in);
                for(int i = 0; i < in.length(); i++){
                        if(in[i] ==32){
                                k++;
                        }else{
                                s[k] += in[i];
                        }
                }
                for(;q <= k; q++){
                        if(s[q] =="END_OF_TEXT"){
                                j = false;
                        }
                        string l = s[q];
                     transform(l.begin(), l.end(), l.begin(), ::tolower);
                         if(l == p){
                                n++;
                        }
                }
                k++;
                if(j == false)break;
        }
            cout << n << endl;
}


Measured memory_bytes: 3272
#include<cstdio>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
#include<cmath>
#define pub push_back
#define llint long long int
#define mp make_pair
#define fi first
#define se second
const llint big=(1<<30)<<30;
using namespace std;
int main(void){
    llint n,k,i,q,w;
    vector<pair<llint,llint>> ar;
    scanf("%lld %lld",&n,&k);
    ar.resize(n);
    for(i=0;i<n;i++){
        scanf("%lld %lld",&q,&w);
        ar[i]=mp(q,w);
    }
    sort(ar.begin(),ar.end());
    i=0;
    while(true){
        k-=ar[i].se;
        if(k<=0){cout<<ar[i].fi<<endl;break;}
        i++;
    }
    return 0;
}

Measured memory_bytes: 1792
#import sys
#input=sys.stdin.readline

def gcd(a, b):
    a, b = max(a, b), min(a, b)
    if b == 0:
        return a
    return gcd(b, a % b)


def main():
    n = int(input())
    A = list(map(int, input().split()))
    gcdA = [0]*n
    gcdB = [0]*n
    gcdA[0] = A[0]
    gcdB[n-1] = A[n-1]
    for i in range(1, n):
        gcdA[i] = gcd(A[i], gcdA[i-1])
        gcdB[n-i-1] = gcd(A[n-i-1], gcdB[n-i])
    ans = max(gcdA[n-2], gcdB[1])
    for i in range(1, n-1):
        ans = max(ans, gcd(gcdA[i-1], gcdB[i+1]))
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 14436
N = int(input())
A_list = [int(i) for i in input().split()]
B_list = [int(i) for i in input().split()]

killed = 0
for i in range(N) :
    brave = B_list[i]
    monster = A_list[i]
    # print(brave,monster)
    if (brave >= monster) :
        # 殺りきれる場合
        killed += monster
        brave -= monster
        monster = A_list[i+1]
        if (brave >= monster) :
            killed += monster
            brave -= monster
            monster = 0
        elif (brave < monster) :
            # 殺りきれない場合
            killed += brave
            monster -= brave # この処理はいる
        A_list[i+1] = monster
            
    elif (brave < monster) :
        # 殺りきれない場合
        killed += brave
        monster -= monster # この処理はいらない

print(killed)


Measured memory_bytes: 18624
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
void recur(vector<vector<int>> &A, const vector<int> &B, int level)
{
    if (B.size() <= 1) return;
    vector<int> C, D;
    for (int i = 0; i < B.size(); i++) {
        (i % 2 == 0 ? C : D).push_back(B[i]);
    }
    for (int i = 0; i < C.size(); i++) {
        for (int j = 0; j < D.size(); j++) {
            int s = C[i], t = D[j];
            A[min(s, t)][max(s, t)] = level;
        }
    }
    recur(A, C, level + 1);
    recur(A, D, level + 1);
}
int main() {
    int N; cin >> N;
    vector<vector<int>> A(N, vector<int>(N));
    vector<int> B(N);
    iota(begin(B), end(B), 0);
    recur(A, B, 1);
    for (int i = 0; i < N - 1; i++) {
        for (int j = i + 1; j < N; j++) {
            cout << A[i][j] << ' ';
        }
        cout << '\n';
    }
    return 0;
}


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

int main(){
  long int h,a=1,b=0;
  cin >> h;
  
  while(h > 1){
    h/=2;
    b+=a;
    a*=2;    
  }
  
  cout << a+b;
}

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

int main(void){
    ll n;
    cin >> n;

    for(ll i=(ll)sqrt(n);i>=1;i--){
        if(n%i==0){
            cout << i+n/i-2;
            return 0;
        }
    }
}

Measured memory_bytes: 256
s = gets.chomp
p = gets.chomp
n = p.length
ss = s + s
flag = 0
(0..(s.length * 2)).each do |i|
  if ss[i...(i+n)] == p
    flag += 1
  end
end
if flag > 0
  print "Yes\n"
else
  print "No\n"
end

Measured memory_bytes: 6104
#include<bits/stdc++.h>
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define endl '\n'
#define pb push_back
#define ll long long
#define ull unsigned long long
#define vi vector<int>
using namespace std;
constexpr int MOD=1e9+7;
constexpr int mod=998244353;

int prime(int n){
    //int cnt = 0 ;
    for(int i = 2 ; i <= sqrt(n) ; ++i){
        if(n % i == 0) {
           return 1 ;   
        }
    }

    return 0  ; 
}


int fastpower(int n , int m , int tmp = 1e9+7) {
    ll ans = 1 ; 
    while(m > 0) {
        if(m % 2 != 0 ){
            ans = (ans * n) % tmp  ; 
            m--;
        }
        else {
            n = (n * n) % tmp  ; 
            m = m /2 ;
        }
    }
    return ans % tmp ; 
}

void primeFactorization(int n) {
    map<int,int> factors ; 
    while(n % 2 == 0) {
        factors[2]++;
        n = n / 2 ; 
    }

    for(int i = 3 ; n > 1 ; ++i) {
        while(n % i == 0) {
            factors[i]++;
        }
    }
}


void solve() {
    int h , w ; 
    cin >> h >> w ; 
    char mat[h][w] ; 
    for(int i= 0 ; i < h ; ++i){
        for(int j= 0 ; j < w ; ++j) 
            cin >> mat[i][j] ; 
    }

    vector<vector<int>> dp(h, vector<int> (w)) ;

    for(int i =0 ; i < h ; ++i) {
        for(int j = 0 ; j < w ; ++j) {
            if(i == 0 && j == 0)
                dp[i][j] = 1;
            else if(mat[i][j] ==  '.') {
                dp[i][j] = (( (i >= 1) ? dp[i-1][j] : 0 ) % MOD + (j-1>= 0 ? dp[i][j-1] : 0 )% MOD )% MOD ; 
            } 


            //cout << dp[i][j] << " " ;
        }
        //cout << endl ;
    } 

    cout << dp[h-1][w-1] ; 


    


}


int main() {
   int t=1; 
   //cin >> t;

   while(t--){
    solve() ; 

   }



    return 0; 
}

Measured memory_bytes: 8484
#include <bits/stdc++.h>
using namespace std;
//cin.sync_with_stdio(false);

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

typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> Vector;
typedef vector<Vector>	DVector;

int main(int argc, char const *argv[])
{
	cin.tie(0);
	ios::sync_with_stdio(false);

	string s;
	int cash = 700;
	rep(i,3)	cin >> s[i];
	for (int i = 0; i < 3; ++i)
	{
		if (s[i] == 'o')
		{
			cash += 100;
		}
	}
	cout << cash << endl;
	return 0;
}

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

int main(){
  int n,k;
  cin>>k>>n;
  int a[n];
  for(int i=0;i<n;i++){
   cin>>a[i];
    a[i]=a[i]+k;
   }

    int ans= a[0]+k-a[n-1];
    for(int i=1;i<n;i++){
      ans=max(ans,a[i]-a[i-1]);
    }
    cout<<(k-ans);
}


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

using ll = long long;
using pii = pair<int, int>;
template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (int i = m; i < (n); i++)
#define ALL(c) (c).begin(), (c).end()

constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }

template <class T, class U>
void chmin(T& t, const U& u) {
    if (t > u) t = u;
}
template <class T, class U>
void chmax(T& t, const U& u) {
    if (t < u) t = u;
}

template <class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
    os << "(" << p.first << "," << p.second << ")";
    return os;
}

template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "{";
    rep(i, v.size()) {
        if (i) os << ",";
        os << v[i];
    }
    os << "}";
    return os;
}

#ifdef LOCAL
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << H;
    debug_out(T...);
}
#define debug(...) \
    cerr << __LINE__ << " [" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif

const int maxn = 100010;
V<pii> g[maxn];
V<int> col[maxn];
unordered_map<int, int> d[maxn];

int main() {
    int N, M;
    cin >> N >> M;
    rep(i, M) {
        int p, q, c;
        cin >> p >> q >> c;
        --p, --q;
        g[p].eb(c, q);
        g[q].eb(c, p);
        col[p].pb(c);
        col[q].pb(c);
    }

    rep(i, N) {
        g[i].eb(-1, i);
        sort(ALL(g[i]));
    }

    using P = pair<int, pii>;
    priority_queue<P, V<P>, greater<P>> que;
    d[0][-1] = 0;
    que.push(mp(0, mp(0, -1)));

    while (!que.empty()) {
        auto p = que.top();
        que.pop();
        int v = p.se.fi, c = p.se.se;
        if (p.fi > d[v][c]) continue;
        if (c == -1) {
            for (int nx : col[v]) {
                int nd = d[v][c] + 1;
                if (!d[v].count(nx) || d[v][nx] > nd) {
                    d[v][nx] = nd;
                    que.push(mp(nd, mp(v, nx)));
                }
            }
        } else {
            {
                int nd = d[v][c];
                if (!d[v].count(-1) || d[v][-1] > nd) {
                    d[v][-1] = nd;
                    que.push(mp(nd, mp(v, -1)));
                }
            }
            auto it = lower_bound(ALL(g[v]), mp(c, -1));
            while (it != g[v].end() && it->fi == c) {
                int nd = d[v][c];
                if (!d[it->se].count(c) || d[it->se][c] > nd) {
                    d[it->se][c] = nd;
                    que.push(mp(nd, mp(it->se, c)));
                }
                it++;
            }
        }
    }

    const int INF = TEN(9);
    int ans = INF;
    for (auto v : d[N - 1]) {
        chmin(ans, v.se);
    }
    if (ans == INF) ans = -1;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 46256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define _repargs(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _repargs(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    int N;
    ll W;
    cin >> N >> W;
    vector<vector<int>> A(4);
    ll w0;
    int v0;
    cin >> w0 >> v0;
    A[0].pb(v0);
    rep(i, N - 1){
        ll w;
        int v;
        cin >> w >> v;
        A[w - w0].pb(v);
    }
    rep(i, 4) sort(all(A[i])), reverse(all(A[i]));
    rep(i, 4){
        rep(j, 1, A[i].size()){
            A[i][j] += A[i][j - 1];
        }
    }
    
    ll ans = 0;
    
    rep(i, A[0].size() + 1) rep(j, A[1].size() + 1) rep(k, A[2].size() + 1) rep(l, A[3].size() + 1){
        ll a0 = 0, a1 = 0, a2 = 0, a3 = 0;
        if(i > 0) a0 = A[0][i - 1];
        if(j > 0) a1 = A[1][j - 1];
        if(k > 0) a2 = A[2][k - 1];
        if(l > 0) a3 = A[3][l - 1];
        if(w0 * i + (w0 + 1) * j + (w0 + 2) * k + (w0 + 3) * l <= W){
            ans = max(ans, a0 + a1 + a2 + a3);
        }
    }
    
    output(ans);
    
    
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



ll N;
map<ll,ll> MAP;

ll func(ll S){

	auto at = MAP.find(S);
	if(at != MAP.end()){

		return MAP[S];
	}

	return MAP[S] = (func(S/2)+func((S-1)/2)+func(S/2-1))%MOD;
}


int main(){

	scanf("%lld",&N);

	MAP[0] = 1;
	MAP[1] = 2;

	printf("%lld\n",func(N));

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int num[200000];
int main(){
int a,b,c;
cin>>a;
	for(int i=1;i<=a;i++){
		cin>>num[i];
	}
	sort(num+1,num+1+a);
	b=num[a];
	c=1;
	for(int i=2;i<a;i++){
		if(fabs(num[c]-(double)b/2)>fabs(num[i]-(double)b/2)){
			c=i;
		}
	}
	printf("%d %d",b,num[c]);
	return 0;
}


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

int main(){

	vector<int> vec(3);

	for(int i=0; i<3; i++)
		cin >> vec[i];

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

	for(int i=0; i<3; i++)
		cout << vec[i] << (i<2? " ": "\n");

	return 0;
}

Measured memory_bytes: 3152
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <cstdint>
#include <cmath>
#include <functional>
#include <limits>
#include <cassert>
#include <bitset>

using namespace std;

/* template */

using ll = long long;

void debug_out() { std::cout << std::endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cout << "debug: "; debug_out(__VA_ARGS__)
#else
#define debug(...) 
#endif

#define rep(i, a, n) for (int i = (int)(a); i < (int)(n); i++)
#define rrep(i, a, n) for (int i = ((int)(n-1)); i >= (int)(a); i--)
#define Rep(i, a, n) for (long long i = (long long)(a); i< (long long)(n); i++)
#define RRep(i, a, n) for (long long i = ((long long)(n-1ll)); i>=(long long)(a); i--)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}

struct Edge{
    int to;
    ll weight;
    Edge(int t, ll w) : to(t), weight(w){ }
};

struct edge{
    int from;
    int to;
    ll weight;
    edge(int f,int t,ll w) : from(f), to(t), weight(w){ }
};


using Graph = vector<vector<Edge>>;
using graph = vector<vector<int>>;
using edges = vector<edge>;

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

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

template <class T>
T lcm(T a, T b){
    return (a*b)/gcd(a,b);
}

bool isPalindrome(string s){
    string t = s;
    reverse(all(t));
    return s==t;
}

constexpr ll LNF = 1LL<<60;

constexpr int INF = 1e9+7;

const double PI=3.14159265358979323846;


vector<int> dx = {-1,0,1,0,-1,1,-1,1};
vector<int> dy = {0,-1,0,1,1,-1,-1,1};

/* template */

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string s; cin >> s;
    if(s=="ABC"){
        cout << "ARC" << endl;
    }
    else{
        cout << "ABC" << endl;
    }
} 

Measured memory_bytes: 3652
#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;
typedef tree<signed, null_type, less_equal<signed>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
//find_by_order();
//order_of_key();
 
#define PB	push_back
#define ALL(x)	(x).begin(), (x).end()
#define ALLR(x)	(x).rbegin(), (x).rend()
#define MP	make_pair
 
#define debug(_x)		cerr << #_x << '=' << (_x) << endl;
#define debug2(_x, _y)	cerr << #_x << '=' << (_x) << ' ' << #_y << '=' << (_y) << endl;
#define debugn(_a)		cerr << #_a << ": "; for (const auto _x: _a) cerr << (_x) << ' '; cerr << endl;

#define HERE debug(__LINE__);

#define FAST_IO ios::sync_with_stdio(false); cin.tie(0)

#define int long long int

typedef pair<int, int> ii;
typedef pair<pair<int, int>, int> iii;
typedef vector<int> vi;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef unsigned long long ull;

const int INF = LONG_LONG_MAX>>1;
const int NINF = LONG_LONG_MIN/2;

const double PI = 3.141592653589793238;

const int N = 100009;

vi adj[N];
int parent[N];
bool vis[N];

void bfs(int s) {
	queue<int> q;
	q.push(s);
	vis[s] = true;
	
	while (!q.empty()) {
		int v = q.front();
		q.pop();
		for (int u: adj[v]) {
			if (!vis[u]) {
				vis[u] = true;
				parent[u] = v;
				q.push(u);
			}
		}
	}
}

int32_t main() {
	FAST_IO;
	
	int n, m;
	cin >> n >> m;
	
	for (int i = 0; i < m; i++) {
		int u, v;
		cin >> u >> v;
		
		adj[u].PB(v);
		adj[v].PB(u);
	}
	
	bfs(1);
	
	vi ans;
	for (int i = 2; i <= n; i++) {
		if (parent[i] != 0)
			ans.PB(parent[i]);
	}
	
	if ((int)ans.size() != n-1) cout << "No" << endl;
	else {
		cout << "Yes" << endl;
		for (int x: ans) cout << x << endl;
	}
}

// g++ -Wall -Wextra -Wshadow -fsanitize=undefined


Measured memory_bytes: 13820
#include<string>
#include<string.h>
#include<map>
#include<set>
#include<vector>
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<queue>
#include<stdio.h>
#define fo(i,a,b)for(int i(a);i<(b);i++)
#define rep(i,n)fo(i,0,n)
using namespace std;
#define pii pair<int,int>
#define ll long long
#define mp make_pair
#define pb push_back
typedef pair<pair<int,int>,int>tri;

char s[500005];
int ans[500005];
int cnt[500005];
int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    cin>>s[i];
    for(int i=1;i<=n;i++)
    if(s[i]=='0')ans[i]=i;
    else ans[i]=ans[i-1];
    for(int i=1;i<=n;i++)
    {
        cnt[i]=cnt[i-1];
        if(s[i]=='1')
        {
            if(s[i-1]=='0' && s[i-2]=='1')
            {
                cnt[i]=max(cnt[i],cnt[ans[i-2]]+i-2-ans[i-2]);
                cnt[i]=max(cnt[i],cnt[ans[i-2]+1]+i-2-ans[i-2]-1);
            }
            if(s[ans[i]-1]=='1')
            {
                cnt[i]=max(cnt[i],cnt[ans[i]-2]+i-ans[i]);
            }
        }
    }
    cout<<cnt[n];
    //system("pause");
    return 0;
}

Measured memory_bytes: 4608
#define _CRT_SECURE_NO_WARNINGS
#include"bits/stdc++.h"
#ifdef _DEBUG
#define DBG(n) n
#else
#define DBG(n)
#endif
#define INF            1e9
#define INFLL          1e18
#define EPS            1e-9
#define REP(i,n)       for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)      for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)      for(ll i=(n)-1;i>=0;--i)
#define REPR1(i,n)     for(ll i=(n);i>0;--i)
#define REPC(i,obj)    for(auto i:obj)
#define ALL(obj)       (obj).begin(),(obj).end()
#define SETP(n)        cout<<fixed<<setprecision(n)
#define VV(T,h,w)      move(vector<vector<T>>(h,vector<T>(w)))
#define VVI(T,h,w,i)   move(vector<vector<T>>(h,vector<T>(w,i)))
using namespace std;
using ll = long long;
template<typename T, ll h, ll w>using vec2 = vector<vector<T>>;
template<typename T = ll>inline T in() { T ret; cin >> ret; return ret; }

signed main()
{
	ll n = in();
	string s = in<string>();
	ll e_cnt = 0, w_cnt = 0;
	REP1(i, n - 1)if (s[i] == 'E')++e_cnt;
	ll ans = e_cnt;
	REP(i, n) {
		ans = min(ans, w_cnt + e_cnt);
		if (s[i] == 'W')++w_cnt;
		if (i != n - 1 && s[i + 1] == 'E')--e_cnt;
	}
	cout << ans << endl;
}

Measured memory_bytes: 900
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
    int n,W;
    cin>>n>>W;
    int w[n+1],v[n+1];

    ll sum = 0;
    for(int i = 1 ; i<=n ; i++){
        int vi,wi;
        cin>>wi>>vi;
        w[i] = wi;
        v[i] = vi;
        sum += vi;
    }
    ll int dp[n+1][sum+1];
    for(int i = 0 ; i<=n ; i++){
        for(int j = 0 ; j<=sum ; j++){
            dp[i][j] = -1;
        }
    }
    for(int i = 1 ; i<=n ; i++){
        dp[i][v[i]] = w[i];
    }
    /*for(int i = 0 ; i<=n ; i++){
        for(int j = 0 ; j<=sum ; j++){
            cout<<dp[i][j]<<" ";
        }
     cout<<endl;
    }*/
    //cout<<"20"<<endl;
    for(int i = 1;i<=n ; i++){
        for(int j = 1; j<=sum ; j++){

                if(j<v[i]){
                    dp[i][j] = dp[i-1][j];
                    continue;
                }
                //cout<<i<<" "<<j<<endl;
                //cout<<"comparing "<<dp[i-1][j]<<" "<<dp[i-1][j-v[i]]+w[i]<<endl;
                //cout<<"comparing "<<dp[i-1][j]<<" "<<dp[i-1][j-v[i]]<<endl;
            if(dp[i-1][j] == -1 && dp[i-1][j-v[i]] == -1) {
                    //cout<<"entering -1"<<endl;
                    if(dp[i][j] != -1) continue;
                    dp[i][j] = -1;
                    //cout<<"if"<<endl;
                    //if()
                    /*if(dp[i][j]!= -1) dp[i][j] = min(max(dp[i-1][j],dp[i-1][j-v[i]]+w[i]),dp[i][j]);
                    else dp[i][j] = max(dp[i-1][j],dp[i-1][j-v[i]]+w[i]);*/
            }
            else if (dp[i-1][j] == -1){
                //cout<<" i-1 j is entered"<<endl;
                if(dp[i][j]!= -1) dp[i][j] = min(dp[i-1][j-v[i]]+w[i],dp[i][j]);
                else dp[i][j] = dp[i-1][j-v[i]]+w[i];
            }
            else if(dp[i-1][j-v[i]] == -1){
                //cout<<" i-1 j-vi is entered"<<endl;
                if(dp[i][j]!= -1) dp[i][j] = min(dp[i-1][j],dp[i][j]);
                else dp[i][j] = dp[i-1][j];
            }
            else {
                    //cout<<"else"<<endl;
                    if(dp[i][j]!= -1) dp[i][j] = min(min(dp[i-1][j],dp[i-1][j-v[i]]+w[i]),dp[i][j]);
                    else dp[i][j] = min(dp[i-1][j],dp[i-1][j-v[i]]+w[i]);            }
        }
    }
    //cout<<27<<endl;
   /*for(int i = 0 ; i<=n ; i++){
        for(int j = 0 ; j<=sum ; j++){
            cout<<dp[i][j]<<" ";
        }
     cout<<endl;
    }*/
  ll val = 0;
    for(int i = 1;i<=n ; i++){
        for(int j = 1; j<=sum ; j++){
            if(dp[i][j]!= -1){
                if(dp[i][j] <= W) val = max(val,(ll)j);
            }
        }
    }

    cout<<val<<endl;
}


Measured memory_bytes: 79104
module abc129.abc129_c;

import std.algorithm;
import std.container;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;


void main() {
  const MOD = 1000000007;
  auto nm = readln.chomp.split.to!(int[]);
  auto a = make!(RedBlackTree!int);
  iota(nm[1]).each!(line => a.insert(readln.chomp.to!int));
  
  int[int] dp = [
    0: 1,
    1: 1 in a ? 0 : 1,
  ];

  foreach (int k; 2..(nm[0] + 1))
    dp[k] = (k in a ? 0 : (dp[k - 1] + dp[k - 2])) % MOD;
  
  writeln(dp[nm[0]]);
}


Measured memory_bytes: 11388
using System;
class Program
{
	static void Main(string[] args)
	{
		string[] input = Console.ReadLine().Split(' ');
      	int a = int.Parse(input[0]);
      	int b = int.Parse(input[1]);
        int c = int.Parse(input[2]);
      	for(int i = 0; i < 10; ++i){
          c = (a * c) - b;
          Console.WriteLine(c);
        }

	}
}

Measured memory_bytes: 11092
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

const ll mod = 1e9 + 7;
ll dp[110][4][4][4];

int main() {
    int n;
    cin >> n;
    REP(i,n){
        if (i == 0){
            REP(j,4) dp[i][j][0][0] = 1;
        }else if (i == 1){
            REP(j,4) REP(k,4) dp[i][k][j][0] += dp[i-1][j][0][0];
        }else if (i == 2){
            REP(j,4) REP(k,4) REP(x,4){
                if (j == 0 && k == 1 && x == 2) continue;
                if (j == 1 && k == 0 && x == 2) continue;
                if (j == 0 && k == 2 && x == 1) continue;
                dp[i][x][k][j] += dp[i-1][k][j][0];
            }
        }else{
            REP(j,4) REP(k,4) REP(l,4) REP(x,4){
                if (k == 0 && l == 1 && x == 2) continue;
                if (k == 1 && l == 0 && x == 2) continue;
                if (k == 0 && l == 2 && x == 1) continue;
                if (j == 0 && l == 1 && x == 2) continue;
                if (j == 0 && k == 1 && x == 2) continue;
                (dp[i][x][l][k] += dp[i-1][l][k][j]) %= mod;
            }
        }
    }

    ll ans = 0;
    REP(x,4) REP(y,4) REP(z,4) ans = (ans + dp[n - 1][x][y][z]) % mod;
    cout << ans << endl;

    return 0;
}

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

struct Edge{
	long long Next,To;
}e[maxn<<1];

long long First[maxn];
long long v[maxn];
long long vis[maxn];
long long s[maxn];
long long n,x,y;
long long tot;
long long f;
long long res,as=0x3f3f3f3f;
long long ad=0x3f3f3f3f,dep;
long long ma[maxn];

long long add_edge(long long x,long long y){
	tot++;
	e[tot].To=y;
	e[tot].Next=First[x];
	First[x]=tot;
}

void dfs(long long x,long long d){
	long long num=0;
//	cout<<x<<" "<<d<<endl;
	
	for(long long i=First[x];i!=-1;i=e[i].Next){
		long long y=e[i].To;
		if(vis[y])continue;
		if(i==f||i==f+1)continue;
		num++;
		vis[y]=1;
		dfs(y,d+1);
	//	s[x]=max(s[x],s[y]);
	}
	//s[x]*=num;
	ma[d]=max(ma[d],num);
	if(!num){
		s[x]=1;
		dep=max(dep,d);
		return;
	}
}

int main(){
	memset(First,-1,sizeof(First));
	cin>>n;
	for(long long i=1;i<n;i++){
		cin>>x>>y;
		add_edge(x,y);
		add_edge(y,x);
		v[x]++,v[y]++;
	}
	
	f=-1;
	for(long long i=1;i<=n;i++){
		memset(vis,0,sizeof(vis));
		memset(s,0,sizeof(s));
		memset(ma,0,sizeof(ma));
		dep=0;
		vis[i]=1;
		dfs(i,1);
		res=1;
	//	res=s[i];
		for(int j=1;j<dep;j++)
		res*=ma[j];
		if(v[i]==1)res++;
	//	cout<<dep<<" "<<res<<endl;
		if(dep<ad){
			ad=dep;
			as=res;
		}
		else if(dep==ad){
			if(res<as)as=res;
		}
	}
	
	for(long long i=1;i<=tot;i+=2){
		memset(vis,0,sizeof(vis));
		memset(s,0,sizeof(s));
		memset(ma,0,sizeof(ma));
		dep=0;
		f=i;
		add_edge(0,e[i].To);
		add_edge(0,e[i+1].To);
		dfs(0,0);
		tot-=2;
		First[0]=-1;
		res=1;
	//	res=s[0];
		for(int j=0;j<dep;j++)
		res*=ma[j];
	//	cout<<dep<<" "<<res<<endl;
		if(dep<ad){
			ad=dep;
			as=res;
		}
		else if(dep==ad){
			if(res<as)as=res;
		}
	}
	
	cout<<ad<<" "<<as;
}
	
	

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

int main() {
  vector<int> num(3);
  cin >> num[0] >> num[1] >> num[2];
  sort(num.begin(), num.end());
  cout << num[0]+num[1] << endl;
  return 0;
}


Measured memory_bytes: 256
open Scanf
open Printf
open List

let step = [(1, 0); (0, 1); (-1, 0); (0, -1)]

let flip f x y = f y x

let inf = 101010101010

let read_int () = scanf " %d" (fun x -> x)

let rec read_ints n =
  if n = 0 then []
  else
    let a = scanf " %d" (fun x -> x) in
    a :: read_ints (n-1)

let () =
  let (h :: w :: _) = read_ints 2 in
  let num_white = ref 0 in
  let field = Array.init h (fun _ ->
    let row = scanf " %s" (fun s -> s) in
    flip String.iter row (
      fun c -> if c = '.' then num_white := !num_white + 1 else ()
    );
    row) in

  let min_dist = Array.init h (fun _ -> Array.init w (fun _ -> ref inf)) in
  min_dist.(0).(0) := 0;

  let queue = Queue.create () in
  Queue.push (0, 0) queue;
  while not (Queue.is_empty queue) do
    let x, y = Queue.pop queue in
    flip List.iter step (fun (dx, dy) ->
      let nx, ny = x + dx, y + dy in
      if nx < 0 || h <= nx || ny < 0 || w <= ny || String.get (field.(nx)) ny = '#'
      then ()
      else if !(min_dist.(nx).(ny)) = inf then (
        min_dist.(nx).(ny) := !(min_dist.(x).(y)) + 1;
        Queue.push (nx, ny) queue
      )
    )
  done;
  let ans = !(min_dist.(h-1).(w-1)) in
  printf "%d\n" (if ans = inf then -1 else !num_white - ans - 1)



Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define int     long long
#define F       first
#define S       second
#define _READ   freopen("input.txt","r", stdin);
#define _FAST   ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
void solve()
{
    int n,sum=0;
    cin>>n;
    for(int i=1;i<=n;i++)
    for(int j=1;j<=n;j++)
    for(int k=1;k<=n;k++)
        sum+=__gcd(i,__gcd(j,k));
    cout<<sum;
    
}
int32_t main()
{
    clock_t tStart = clock();
    #ifndef ONLINE_JUDGE
    _FAST
    #endif
    
    int t;
    t=1;
    while(t--)
        solve();
    
    #ifndef ONLINE_JUDGE
    cout<<fixed<<setprecision(5)<<"\nTime taken: "<<(double)(clock() - tStart)/CLOCKS_PER_SEC;
    #endif
    
    return 0;
}
/*
===FOR N-Dimensional Vector===
https://codeforces.com/blog/entry/76149
g++ -std=c++17 -Wshadow -Wall -g -fsanitize=address -fsanitize=undefined a.cpp -o a -D_GLIBCXX_DEBUG
*/

Measured memory_bytes: 3608
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <cstdint>
#include <iostream>

constexpr int32_t kMaxArraySize = 100;

class SelectionSort {
 public:
  SelectionSort() noexcept;
  ~SelectionSort() noexcept;
  void Main(std::istream &input_stream) noexcept;

 private:
  void Sort() noexcept;
  int32_t FindMinimumIndex(int32_t index_unsorted_top) const noexcept;
  void Swap(const int32_t index_unsorted_top, const int32_t index_minimum) noexcept;
  void Load(std::istream &input_stream) noexcept;
  void Print() noexcept;

 private:
  SelectionSort(const SelectionSort &obj) noexcept = delete;
  SelectionSort &operator=(const SelectionSort &obj) noexcept = delete;
  SelectionSort(SelectionSort &&obj) = delete;
  SelectionSort &operator=(SelectionSort &&obj) = delete;

 private:
  int32_t count_;
  int32_t values_[kMaxArraySize];
  int32_t swapped_count_;

};

SelectionSort::SelectionSort() noexcept : count_(0), values_{-1}, swapped_count_{0} {}

SelectionSort::~SelectionSort() noexcept {}

void SelectionSort::Main(std::istream &input_stream) noexcept {
  Load(input_stream);
  Sort();
  Print();
}

void SelectionSort::Sort() noexcept {
  for (int32_t index_unsorted_top = 0; index_unsorted_top < count_; ++index_unsorted_top) {
    const int32_t index_minimum = FindMinimumIndex(index_unsorted_top);
    if (index_unsorted_top != index_minimum) {
      Swap(index_unsorted_top, index_minimum);
    }
  }
}

int32_t SelectionSort::FindMinimumIndex(int32_t index_unsorted_top) const noexcept {
  int32_t index_minimum = index_unsorted_top;
  for (int32_t index_scan = index_unsorted_top; index_scan < count_; ++index_scan) {
    if (values_[index_scan] < values_[index_minimum]) {
      index_minimum = index_scan;
    }
  }
  return index_minimum;
}

void SelectionSort::Swap(const int32_t index_unsorted_top, const int32_t index_minimum) noexcept {
  const int32_t value_top = values_[index_unsorted_top];
  values_[index_unsorted_top] = values_[index_minimum];
  values_[index_minimum] = value_top;
  ++swapped_count_;
}

void SelectionSort::Load(std::istream &input_stream) noexcept {
  input_stream >> count_;
  for (int32_t index = 0; index < count_; ++index) {
    input_stream >> values_[index];
  }
}

void SelectionSort::Print() noexcept {
  for (int32_t index = 0; index < count_; ++index) {
    if (index != 0) {
      std::cout << " ";
    }
    std::cout << values_[index];
  }
  std::cout << std::endl;
  std::cout << swapped_count_ << std::endl;
}

int main(int argc, char *argv[]) {
  SelectionSort *selection_sort = new SelectionSort();
  selection_sort->Main(std::cin);
  delete selection_sort;
  return 0;
}



Measured memory_bytes: 3084
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long k = sc.nextLong();
		long[] a = new long[50];
		long t = k / 50;
		long m = k % 50;
		for (int i = 0; i < 50; i++) {
			a[i] = 49 + t;
			if (i < m) {
				a[i] += 51 - k % 50;
			} else {
				a[i] -= k % 50;
			}
		}

		StringBuilder sb = new StringBuilder();
		sb.append(50).append("\n");
		for (int i = 0; i < 50; i++) {
			sb.append(a[i]).append(" ");
		}

		System.out.println(sb.toString());
	}
}


Measured memory_bytes: 23508
from collections import defaultdict
N, K, L = map(int, input().split())


class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n)]
        self.rank = [0] * n
        self.size = [1] * n

    # 検索
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    # 併合
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.rank[x] < self.rank[y]:
            self.par[x] = y
            self.size[y] += self.size[x]
            self.size[x] = 0
        else:
            self.par[y] = x
            self.size[x] += self.size[y]
            self.size[y] = 0
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    # 同じ集合に属するか判定
    def same_check(self, x, y):
        return self.find(x) == self.find(y)

    # すべての頂点に対して親を検索する
    def all_find(self):
        for n in range(len(self.par)):
            self.find(n)


UF1 = UnionFind(N)
UF2 = UnionFind(N)

for k in range(K):
    p, q = map(int, input().split())
    UF1.union(p-1, q-1)

for l in range(L):
    r, s = map(int, input().split())
    UF2.union(r-1, s-1)

UF1.all_find()
UF2.all_find()

D = defaultdict(int)
for i in range(N):
    D[UF1.par[i], UF2.par[i]] += 1

ans = [D[UF1.par[i], UF2.par[i]] for i in range(N)]
print(*ans)


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

int main() {
    ll x,k,d;
    cin>>x>>k>>d;
    x=abs(x);
    ll tmp=x/d;
    if(tmp>=k){
        x-=d*k;
        cout<<x<<endl;
    } else {
        x-=d*tmp;
        k-=tmp;
        if(k%2==0){
            cout<<x<<endl;
        } else {
            cout<<abs(x-d)<<endl;
        }
    }
}



Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,a,b) for(int i=a;i<=b;i++)
#define pb push_back
#define eb emplace_back

int in(){int x;cin>>x;return x;}


    
#define ll long long
vector<vector<int>> g;
vector<int> nxt;
constexpr ll MOD = 1000003;

main(){
    while(1){
        int n=in(),m=in();
        if(!n)return 0;
        g=vector<vector<int>>(n);
        vector<vector<int>> v(2);
        using P = pair<int,int> ;
        vector<P> ed;
        rep(i,m){
            int a=in()-1,b=in()-1;
            if(a>b)swap(a,b);
            if((a+b)&1){
                g[a].pb(b);
                v[a&1].pb(a);
                ed.eb(P(a,b));
            }
        }
        if(n&1){
            cout<<0<<endl;continue;
        }
        #define all(c) (c).begin(),(c).end()
        vector<pair<int,ll>> dp(n);
        ed.emplace_back(0,n-1);
        sort(all(ed),[](P x,P y){return x.second-x.first<y.second-y.first;});
        rep(i,n-1) dp[i] = P(i+1,1);
        for(auto p:ed){
            int a = p.first,b=p.second;
            ll ans = 1;
            int now = a+1;
            while(now!=b){
                ans=(ans*dp[now].second)%MOD;
                now = dp[now].first+1;
            }
            dp[a+1]={b-1,ans};
            now = a,ans = 1;
            while(now!=b+1){
                ans = (ans*dp[now].second)%MOD;
                now = dp[now].first+1;
            }
            ans+=dp[a+1].second;
            if(ans>=MOD)ans-=MOD;
            dp[a] = {b,ans};
        }
        cout<<dp[0].second<<endl;
    }
}


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

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(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>=b;i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define printV(_v) for(auto _x:_v){cout<<_x<<" ";}cout<<endl
#define printVS(_vs) for(auto _x : _vs){cout << _x << endl;}
#define printVV(_vv) for(auto _v:_vv){for(auto _x:_v){cout<<_x<<" ";}cout<<endl;} cout << endl;
#define printP(_p) cout << _p.first << " " << _p.second << endl
#define printVP(_vp) for(auto _p : _vp) printP(_p);

typedef long long ll;
typedef pair<int, int> Pii;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<Pii> vp;
const int inf = 1e9;
const int mod = 1e9 + 7;
typedef vector<vector<int>> Graph;

bool solve(vvi a, int d) {
    a[0][2] = d;
    int sm = a[0][0] + a[0][1] + a[0][2];
    a[2][1] = sm - a[0][1] - a[1][1];
    a[2][2] = sm - a[0][0] - a[1][1];
    a[1][2] = sm - a[0][2] - a[2][2];
    a[1][0] = sm - a[1][1] - a[1][2];
    a[2][0] = sm - a[0][0] - a[1][0];
    if (a[2][0] + a[1][1] + a[0][2] == sm && a[2][0] + a[2][1] + a[2][2] == sm) {
        rep(i, 3) {
            rep(j, 3) {
                cout << (j != 0 ? " " : "") << a[i][j];
            }
            cout << endl;
        }
        return true;
    }
    return false;
}

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

    vvi a(3, vi(3, -1));
    cin >> a[0][0] >> a[0][1] >> a[1][1];

    rep2(i, -100000, 100000) {
        if (solve(a, i)) {
            return 0;
        }
    }

    assert(0);
}


Measured memory_bytes: 384