akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
#include <cstring>
using namespace std;

#define MAX_V 504
#define INF 2147483647

map<int,int> G[MAX_V];
char used[MAX_V];

void add_edge(int f, int t){
	G[f].insert(make_pair(t, 1));
	G[t].insert(make_pair(f, 1));
}

int dfs(int v, int t, int f){
	if(v == t){ return f; }
	used[v] = 1;
	for(map<int,int>::iterator it = G[v].begin(); it != G[v].end(); ++it){
		if(!used[it->first] && it->second > 0){
			int d = dfs(it->first, t, min(f, it->second));
			if(d > 0){
				it->second -= d;
				G[it->first][v] += d;
				return d;
			}
		}
	}
	return 0;
}

int max_flow(int s, int t, int lim = INF){
	int flow = 0;
	for(; lim > 0;){
		memset(used, 0, sizeof used);
		int f = dfs(s, t, lim);
		if(f == 0){ break; }
		flow += f;
		lim -= f;
	}
	return flow;
}


int decrease(int f, int t, int n){
	if(G[f][t] != 0 || max_flow(f, t, 1) != 0){
		return 0;
	}
	max_flow(f, 1, 1);
	max_flow(n, t, 1);
	return 1;
}


int main(){
	int n, e, q, f, t, m;
	scanf("%d%d%d", &n, &e, &q);
	for(int i = 0; i < e; ++i){
		scanf("%d%d", &f, &t);
		add_edge(f, t);
	}

	int flow = max_flow(1, n);
	for(int i = 0; i < q; ++i){
		scanf("%d%d%d", &m, &f, &t);
		if(m == 1){
			add_edge(f, t);
			flow += max_flow(1, n, 1);
		}
		else{
			flow -= decrease(f, t, n) + decrease(t, f, n);
			G[f].erase(t);
			G[t].erase(f);
		}
		
		printf("%d\n", flow);
	}
}

Measured memory_bytes: 3184
#include"bits/stdc++.h"
#define int long long
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define itr(i,x) for(auto i=(x).begin();i!=(x).end();++i)
#define All(x) (x).begin(),(x).end()
#define rAll(x) (x).rbegin(),(x).rend()
using namespace std;
typedef pair<int,int> P;
const int mod=1000000007;
int gcd(int x,int y){return y?gcd(y,x%y):x;}
int lcm(int x,int y){return x*y/gcd(x,y);}
void YN(bool flg){cout<<(flg?"YES":"NO")<<endl;}
void Yn(bool flg){cout<<(flg?"Yes":"No")<<endl;}
void yn(bool flg){cout<<(flg?"yes":"no")<<endl;}
signed main(){
	string s,t;
	cin>>s>>t;
	sort(All(s));
	sort(rAll(t));
	Yn(s<t);
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;


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

	int n, i, j, k, ans;
	cin >> n;
	vector<int> a(n), dp(n + 1, 0), dpodd(n + 1, 0);
	for (i = 0; i < n; i++) cin >> a[i];
	dpodd[0] = 1;
	for (i = 0; i < n; i++) {
		for (j = a[i] - 1; j <= a[i] + 1; j++) {
			if (j % 2 == 0) dp[i + 1] += dp[i] + dpodd[i];
			else {
				dp[i + 1] += dp[i];
				dpodd[i + 1] += dpodd[i];
			}
		}
	}
	ans = dp[n];
	cout << ans << "\n";

	return 0;
}


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>;
using Graph = vector<vector<int>>;

// header area
vector<int> BFS(vector<vector<int>> &G, int N){
    // 1回BFSするだけ
    // BFS のためのデータ構造
    vector<int> pre(N+1, -1);
    vector<int> dist(N+1, -1); // 全頂点を「未訪問」に初期化
    queue<int> que;

    // 初期条件 (頂点 0 を初期ノードとする)
    dist[1] = 0;
    que.push(1); // 0 を橙色頂点にする

    // BFS 開始 (キューが空になるまで探索を行う)
    while (!que.empty()) {
        int v = que.front(); // キューから先頭頂点を取り出す
        que.pop();

        // v から辿れる頂点をすべて調べる
        for (int nv : G[v]) {
            if (dist[nv] != -1) continue; // すでに発見済みの頂点は探索しない

            // 新たな白色頂点 nv について距離情報を更新してキューに追加する
            // cout << "nv: " << nv << endl;
            dist[nv] = dist[v] + 1;
            pre[nv]= v;
            que.push(nv);
        }
    }

    return pre;
}

int main(){
    int N, M; cin >> N >> M;
    vector<vector<int>> G(N+1);
    for (int i = 1; i < M+1; ++i) {
        int a, b;
        cin >> a >> b;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    if(G[1].size() == 0){
        cout << "No" << endl;
        return 0;
    }else cout << "Yes" << endl;

    // BFS
    // 各点ごとに、部屋1までの最小を求める。

    vector<int> ans = BFS(G, N);

    for(int i=2;i<N+1;++i){
        cout << ans[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 10744
#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 N;
    cin >> N;

    int numOfdivisor = 0;
    for (int i = 1; i <= N; i = i + 2) {
        int count = 0;
        for (int j = 1; j <= i; j++) {
            if (i % j == 0) {
                count++;
            }
        }
        if (count == 8) numOfdivisor++;
    }

    cout << numOfdivisor << endl;

    return 0;
}


Measured memory_bytes: 3620
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int a,b,c;
	int cnt=0;
	cin>>a>>b>>c;
	for(int i=1;i<=c;i++){
		if(c%i==0 && a<=i && i<=b) cnt++;
	}
	cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 3088
if __name__ == '__main__':
    l = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
    k = int(input())
    print(l[k - 1])

Measured memory_bytes: 3060
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(f.readLine());
        int[] ar = new int[n];
        StringTokenizer tokenizer = new StringTokenizer(f.readLine());
        for (int i = 0; i < n; i++) {
            ar[i] = Integer.parseInt(tokenizer.nextToken());
        }

        int toReplace = 0;
        HashMap<Integer, Integer> occurence = new HashMap<Integer, Integer>();
        int mostOccured = 0;
        int mostOccuredNum = -1;
        int secondMostOccured = 0;
        for (int i = 0; i < n; i += 2) {
            int num = ar[i];
            if (!occurence.containsKey(num)) {
                occurence.put(num, 1);
            } else {
                occurence.put(num, occurence.get(num) + 1);
            }

            if (occurence.get(num) > mostOccured) {
                mostOccured = occurence.get(num);
                mostOccuredNum = num;
            }
            if (num != mostOccuredNum) {
                if (occurence.get(num) > secondMostOccured) {
                    secondMostOccured = occurence.get(num);

                }
            }
        }

        occurence = new HashMap<Integer, Integer>();
        int mostOccured2 = 0;
        int mostOccuredNum2 = -1;
        int secondMostOccured2 = 0;
        for (int i = 1; i < n; i += 2) {
            int num = ar[i];
            if (!occurence.containsKey(num)) {
                occurence.put(num, 1);
            } else {
                occurence.put(num, occurence.get(num) + 1);
            }

            if (occurence.get(num) > mostOccured2) {
                mostOccured2 = occurence.get(num);
                mostOccuredNum2 = num;
            }
            if (num != mostOccuredNum2) {
                if (occurence.get(num) > secondMostOccured2) {
                    secondMostOccured2 = occurence.get(num);
                }
            }
        }

        if (mostOccuredNum != mostOccuredNum2) {
            System.out.println(n - mostOccured - mostOccured2);
        } else {
            System.out.println(Math.min(n - mostOccured - secondMostOccured2, n - mostOccured2 - secondMostOccured));
        }
    }
}


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

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define erep(i, n) for (ll i = 0; i <= (ll)(n); ++i)
#define FOR(i,a,b) for (ll i = (a); i < (ll)(b); ++i)
#define EFOR(i,a,b) for (ll i = (a); i <= (ll)(b); ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } }


int main() {
    int n; cin >> n;
    vector<vector<int>> c(2, vector<int>(n));
    rep(i, 2) rep(j, n) cin >> c[i][j];

    int ans = 0;
    rep(k, n) {
        // iはどこで曲がるかをカウント

        int tmp = 0;
        rep(i, n) {
            if(i < k) {
                tmp += c[0][i];
            } else if(i == k) {
                tmp += c[0][i];
                tmp += c[1][i];
            } else {
                tmp += c[1][i];
            }
        }
        chmax(ans, tmp);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main() {
    int n;
    scanf("%d", &n);
    int iArr[n];
    for (int i = 0; i < n; i++) {
        scanf("%d", &iArr[i]);
    }
    for(int j = n - 1; j >= 0; j--) {
        printf("%d", iArr[j]);
        if (j != 0) printf(" ");
    }
    printf("\n");
    return 0;
}


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

int main()
{
    int n;
    cin>>n;
    int tot = 0;
    for(int i = 0; i<n; i++){
        int a;
        cin>>a;
        while(a%2 == 0){
            tot++;
            a/=2;
        }
    }
    cout<<tot;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long int
#define N 200100
int a[5];
void solve(){
	int n,m;
	cin>>n>>m;
	memset(a,-1,sizeof a);
	while(m--){
		int s,c;
		cin>>s>>c;
		if(a[s]==-1 || a[s]==c){
			a[s]=c;
		} else{
			cout<<-1<<endl;
			return;
		}
	}
	if(a[1]==0 && n!=1){
		cout<<-1<<endl;
		return;
	}
	for(int i=1;i<=n;i++){
		if(a[i]!=-1){
			cout<<a[i];
		} else{
			if(i==1 && n!=1){
				cout<<1;
			} else{
				cout<<0;
			}
		}
	}
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	solve();
}

Measured memory_bytes: 256
// Java program For handling Input/Output 
import java.io.*;
import java.util.*;
import java.math.*;
//import java.awt.*;

public class Main {
    BufferedReader br;
    StringTokenizer st;

    int max = -1;
    final long P = 998244353;

    HashSet<String> set = new HashSet<>();
    HashMap<String, Integer> map = new HashMap<>();

    // actual logic
    void solve() throws IOException {
        long n = nl();

        String ans = "";
        while (n > 0) {
            int r = (int) (n % 26);
            if (r == 0) {
                ans = 'z' + ans;
                n = (n / 26) - 1;
            } else {
                ans = (char) ('a' + r - 1) + ans;
                n = n / 26;
            }
        }
        pl(ans);
    }

    // constructor
    Main() {
        try {
            br = new BufferedReader(new InputStreamReader(System.in));
            try {
                st = new StringTokenizer(br.readLine());
            } catch (Exception e) {
                System.out.println(e);
            }
        } catch (Exception e) {
            System.out.println(e);
        }
    }

    Main(String s) {
        try {
            br = new BufferedReader(new FileReader(s));
            st = new StringTokenizer(br.readLine());
        } catch (Exception e) {
            System.out.println(e);
        }
    }

    // main metohd
    public static void main(String[] args) throws IOException {
        new Main().solve();
    }

    // Utility methods

    String ns() {
        if (!st.hasMoreTokens()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (Exception e) {
                System.out.println(e);
            }
        }
        return st.nextToken();

    }

    int ni() {
        return Integer.parseInt(ns());
    }

    long nl() {
        return Long.parseLong(ns());
    }

    double nd() {
        return Double.parseDouble(ns());
    }

    void pl(String s) {
        System.out.println(s);
    }

    void pl(long s) {
        System.out.println(s);
    }
}


Measured memory_bytes: 37848
import sys
N, K = map(int,sys.stdin.readline().split())
X = list(map(int, sys.stdin.readline().split()))
firstInv = 0
inv = 0

for i in range(N):
  for j in range(N):
    if X[i] > X[j]:
      inv += 1
      if i < j:
        firstInv += 1

ans = inv * ((K-1) * K // 2) + firstInv*K
print(ans % (10**9+7))

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T> using gpp_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T, typename L> using gpp_map = tree<T, L, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T> using gpp_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;*/
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define bit_exist(x, n) ((x >> n) & 1)
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl;
#define mdebug(m) cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;}
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void Ans(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;

//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};

const int mod = 1000000007;
//const int mod = 998244353;
//#define Add(x, y) x = (x + (y)) % mod
//#define Mult(x, y) x = (x * (y)) % mod



signed main(){

    int N, K; cin >> N >> K;
    vec A(N); cin >> A; Sort(A);
    vec F(N); cin >> F; Sort(F); Reverse(F);

    int t0 = -1, t1 = 1000000000000;
    while(t1 - t0 > 1){
        int t = (t0 + t1) / 2;
        int k = 0;
        REP(i, N){
            int a = t / F[i];
            if(a < A[i]) k += A[i] - a;
        }
        if(k <= K) t1 = t;
        else t0 = t;
    }
    Out(t1);

    return 0;
}


Measured memory_bytes: 3456
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		int[] w = new int[2];
		int[] h = new int[2];
		w[0] = 0;
		h[0] = 0;
		Scanner sc = new Scanner(System.in);
		w[1] = sc.nextInt();
		h[1] = sc.nextInt();
		int n = sc.nextInt();
		for (int i = 0; i < n; i++) {
			int x = sc.nextInt();
			int y = sc.nextInt();
			int a = sc.nextInt();
			switch (a) {
			case 1:
				if (w[0] < x) w[0] = x;
				break;
			case 2:
				if (x < w[1]) w[1] = x;
				break;
			case 3:
				if (h[0] < y) h[0] = y;
				break;
			case 4:
				if (y < h[1]) h[1] = y;
				break;

			default:
				break;
			}
		}
		sc.close();

		if (w[1] > w[0] && h[1] > h[0])
			System.out.println((w[1] - w[0]) * (h[1] - h[0]));
		else
			System.out.println(0);
	}
}

Measured memory_bytes: 21972
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>

using namespace std;


template<int MOD> struct Fp {
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
        if (val < 0) val += MOD;
    }
    constexpr int getmod() { return MOD; }
    constexpr Fp operator - () const noexcept {
        return val ? MOD - val : 0;
    }
    constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp& operator += (const Fp& r) noexcept {
        val += r.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }
    constexpr Fp& operator -= (const Fp& r) noexcept {
        val -= r.val;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr Fp& operator *= (const Fp& r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr Fp& operator /= (const Fp& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr bool operator == (const Fp& r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator != (const Fp& r) const noexcept {
        return this->val != r.val;
    }
    friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
        return os << x.val;
    }
    friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
        if (n == 0) return 1;
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1) t = t * a;
        return t;
    }
};
using mint = Fp<1000000007>;


void solve() {
    int N; cin >> N;
    vector<int> zeros(60), ones(60);
    
    for (int i = 0; i < N; i++) {
        long long a; cin >> a;

        for (int d = 0; d < 60; d++) {
            if (a & 1LL<<d) ones[d]++;
            else zeros[d]++;
        }
    }

    int max_digit = 0;
    for (int d = 0; d < 60; d++) {
        if (ones[d] != 0) max_digit = d;   
    }

    mint ans = 0;

    for (int d = 0; d <= max_digit; d++) {
        ans += modpow((mint)2, d) * ones[d] * zeros[d];
    }

    cout << ans << endl;
}


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

Measured memory_bytes: 3600
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
struct pos {
  int row;
  int column;
};
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define Sort(a) sort(a.begin(), a.end())
const int INF = 1 << 30;
const ll MOD = 1000000007;
struct Problem {
  ll total;
  ll bonus;
};
vector<Problem> problems;
ll D, G;

int calc(int bit) {
  int count = 0;
  int point = 0;
  for (int i = 0; i < D; i++) {
    if ((bit & (1 << i)) != 0) {
      count += problems[i].total;
      point += problems[i].bonus + (((i + 1) * 100) * problems[i].total);
    }
  }

  if (point >= G) return count;

  for (int i = D - 1; i >= 0; i--) {
    if ((bit & (1 << i)) == 0) {
      for (int total = 1; total < problems[i].total; total++) {
        count += 1;
        point += ((i + 1) * 100);

        if (point >= G) return count;
      }
    }
  }

  return INF;
}

int main(void) {
  cin >> D >> G;
  problems.resize(D);
  rep(i, D) { cin >> problems[i].total >> problems[i].bonus; }

  int minVal = INF;
  for (int bit = 0; bit < (1 << 10); bit++) {
    minVal = min(minVal, calc(bit));
  }

  cout << minVal << endl;

  return 0;
}

Measured memory_bytes: 256
from itertools import product


N,M=map(int,input().split())
A=[input() for _ in range(N)]
B=[input() for _ in range(M)]
for sx, sy in product(range(N-M+1), repeat=2):
    is_ok = 1
    for x in range(sx, sx+M):
        for y in range(sy, sy+M):
            if B[x-sx][y-sy] != A[x][y]:
                is_ok=0
                break
        if not is_ok:
            break
    if is_ok:
        print("Yes")
        exit()

print("No")

Measured memory_bytes: 63784
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define endl "\n"
const int MOD=1e9+7;
#ifndef HOME
#define cerr if(0)cerr
#endif

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a,b;
    cin>>a>>b;
    int x = abs(a+b);
    if(x&1){
        cout<<"IMPOSSIBLE";
    }else{
        x=x/2;
        //int k = abs(a-x);
        cout<<x<<endl;
    }
    
    return 0;
    
}



Measured memory_bytes: 256
S = input()
S1 = int(S[0:2])
S2 = int(S[2:4])
flag = 0

if (S1 >= 0) and (S2 < 13) and (S2 > 0):
    flag += 1
if (S1 < 13) and (S2 >= 0) and (S1 > 0):
    flag += 10

if flag == 11:
    print("AMBIGUOUS")
elif flag == 1:
    print("YYMM")
elif flag == 10:
    print("MMYY")
else:
    print("NA")


Measured memory_bytes: 3060
import sys
sys.setrecursionlimit(100000)
A, B, C, D, E, F = map(int, input().split())

def res(water, sugar, memo):
    if water + sugar > F:
        return None
    if (water, sugar) in memo:
        return None
    if water + sugar == 0:
        memo[(water, sugar)] = -1        
    elif E*(water+sugar) >= sugar*(100+E):
        memo[(water, sugar)] = sugar/(water+sugar)
    else:
        memo[(water, sugar)] = -1

    res(water+100*A, sugar, memo)
    res(water+100*B, sugar, memo)
    res(water, sugar+C, memo)
    res(water, sugar+D, memo)
    return memo

memo = res(0, 0, {})
k, v = max(memo.items(), key=lambda x:x[1])
print(k[0]+k[1], k[1])

Measured memory_bytes: 5960
def num_of_1bit(n: int)->int:
    '''n の立っているビットを数えます。
    :param n: number
    :return: number of 1 bit
    '''
    s = 0
    while n > 0:
        s += n & 1
        n >>= 1
    return s


def diff_idx(a: int, b: int)->int:
    '''a と b のビット列を比較してビットの状態が異なる最小の
    インデックスを返します。ここで、インデックスは 2^i の i 
    に対応する。
    :param a: number 1
    :param b: number 2
    :return: index
    '''
    if a == b:
        return -1
    idx = 0
    while a > 0 or b > 0:
        if a & 1 != b & 1:
            break
        idx += 1
        a, b = a >> 1, b >> 1
    return idx


def remove_bit(n: int, idx: int)->int:
    '''n の idx 番目のビットを消去します。idx は 2^idx に対
    応します。
    ex) n = 1011011, idx = 2
    -> 101111

    :param n: number
    :param idx: index
    :return: number removed `idx`th bit
    '''
    upper = (n >> (idx+1)) << idx
    lower = n & ((1 << idx) - 1)
    return upper | lower


def insert_bit(n: int, idx: int, bit: bool)->int:
    '''n の idx 番目にビットを挿入します。
    ex) n = 101111, idx = 2, bit = True
    -> 1011111
    '''
    upper = (n >> idx) << (idx + 1)
    lower = n & ((1 << idx) - 1)
    insert = bit << idx
    return upper | insert | lower


def route(_from: int, to: int, N: int)->list:
    '''_from から to に至る N ビットの数を全て使ったルートを
    計算します。
    :param _from: start
    :param to: end
    :param N: number of bit
    :return: routes
    '''
    if N == 1:
        return [_from, to]

    di = diff_idx(_from, to)

    a = remove_bit(_from, di)
    b = remove_bit(to, di)
    c = a ^ 1

    from_bit = (_from & (1 << di)) != 0
    to_bit = (to & (1 << di)) != 0

    first_half = map(lambda x: insert_bit(x, di, from_bit), route(a, c, N-1))
    second_half = map(lambda x: insert_bit(x, di, to_bit),  route(c, b, N-1))

    return list(first_half) + list(second_half)


def diff_by_1_bit(N: int, A: int, B: int)->list:
    num_A = num_of_1bit(A)
    num_B = num_of_1bit(B)
    if abs(num_A - num_B) % 2 == 0:
        return []

    return route(A, B, N)


if __name__ == "__main__":
    N, A, B = map(int, input().split())
    ans = diff_by_1_bit(N, A, B)
    if len(ans) == 0:
        print('NO')
    else:
        print('YES')
        print(' '.join(map(str, ans)))


Measured memory_bytes: 18856
import java.util.*;

class Main {
  public static void main (String[] args) {
    Scanner sc = new Scanner(System.in);
    String s=sc.nextLine();
    char[] tile=s.toCharArray();
    int start0=0,start1=0;
    if(tile.length%2==0){
      for(int i=0;i<tile.length-1;i=i+2){
        //偶数番目が0の時
        if(tile[i]!='0'){
          start0++;
        }
        if(tile[i+1]!='1'){
          start0++;
        }
        //奇数番目が0の時
        if(tile[i]!='1'){
          start1++;
        }
        if(tile[i+1]!='0'){
          start1++;
        }
      }
    }else{
      for(int i=0;i<tile.length-1;i=i+2){
        //偶数番目が0の時
        if(tile[i]!='0'){
          start0++;
        }
        if(tile[i+1]!='1'){
          start0++;
        }
        //奇数番目が0の時
        if(tile[i]!='1'){
          start1++;
        }
        if(tile[i+1]!='0'){
          start1++;
        }
      }
      //最後の偶数番目への操作
      if(tile[tile.length-1]!='0'){
        start0++;
      }else if(tile[tile.length-1]!='1'){
        start1++;
      }
    }
    if(start0>=start1){
      System.out.print(start1);
    }else{
      System.out.print(start0);
    }
  }
}

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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<=(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define Eback(s) s.erase(s.end()-1,s.end())
#define rev(v) reverse(all(v))
#define minvec(v) *min_element(all(v))
#define maxvec(v) *max_element(all(v))
#define sumvec(v) accumulate(all(v),0)
#define mapmax(v) v.rbegin()->first
#define mapmin(v) v.begin()->first
#define pb push_back
#define pf push_front
#define mod 1000000007
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK puts("OK")
#define OK1 puts("OK1")
#define OK2 puts("OK2")
#define SIZE(s) (int)s.size()
#define INF ((1LL<<62)-(1LL<<31))
#define zero(x,n) setw(x) << setfill('0') << n

typedef long long ll;

typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<double> vd;
typedef vector<char> vc;
typedef vector<string> vs;

typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;

const double pi = acos(-1.0);

template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>&p) {
	ost << "{" << p.first << ", " << p.second << "} ";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost, const vector<T>&v) {
	ost << "{";
	for (int i = 0; i<(int)v.size(); i++) {
		if (i)ost << " ";
		ost << v[i];
	}
	ost << "} \n";
	return ost;
}

template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
	ost << "{";
	for (auto p:v) {
		ost << "{" << p.first << ", " << p.second << "} ";
	}
	ost << "} ";
	return ost;
}

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

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

ll gcd(ll x, ll y) {return __gcd(x,y);}
ll lcm(ll x, ll y) {return x/__gcd(x,y)*y;}

int main()
{
	ll n,x,y;
	map<ll,ll> m;
	cin >> n >> x >> y;
	vvll d(n+1,vll(n+1,0));
	for(ll i=1;i<n;i++){
		for(ll j=i+1;j<=n;j++){
			if(i<=x && x<=j && i<=y && y<=j) d[i][j]=(x-i)+(j-y)+1;
			else if(i<=x && x<=j && j<y) d[i][j]=min(j-i,(x-i)+(y-j)+1);
			else if(x<i && i<=y && y<=j) d[i][j]=min(j-i,(i-x)+(j-y)+1);
			else if(x<i && j<y) d[i][j]=min(j-i,(i-x)+(y-j)+1);
			else d[i][j]=j-i;
			m[d[i][j]]++;
		}
	}
	REP(i,1,n-1) cout << m[i] << endl;
	return 0;
}

Measured memory_bytes: 31744
#include <iostream>
#include <fstream>

using namespace std;

typedef struct ST_trade {
public:
	int trade_num;
	bool isTraded1;
	bool isTraded2;
	ST_trade() { trade_num = 0; isTraded1 = false; isTraded2 = false; }
} trade;

int main()
{
	trade a[1001];
	int no, date;
	char dummy;
	
	string buf;
	
	while ( getline(cin, buf) ) { 
		if ( buf.empty() ) break;
		sscanf(buf.c_str(), "%d%c%d", &no, &dummy, &date);
		a[no].isTraded1 = true; a[no].trade_num++;
	}
	while ( getline(cin, buf) ) { 
		if ( buf.empty() ) break;
		sscanf(buf.c_str(), "%d%c%d", &no, &dummy, &date);
		a[no].isTraded2 = true; a[no].trade_num++;
	}
	
	for (int i=1; i<=1000; i++) {
		if ( a[i].isTraded1 && a[i].isTraded2 ) cout << i << " " << a[i].trade_num << endl;
	}
	
	return 0;
}

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

signed main(){
    int N,T;
    cin>>N>>T;
    int ans=T;
    int t[N];
    REP(i,N)cin>>t[i];
    REP(i,N-1) ans+=min(T,t[i+1]-t[i]);
    cout<<ans<<endl;
}

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

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

  vector<int> b(n), c;
  for (int i = n - 1; i >= 0; i--) {
    int tmp = 0;
    for (int j = i; j < n; j += (i + 1)) tmp += b[j];
    if (tmp % 2 != a[i]) {
      b[i] = 1;
      c.push_back(i + 1);
    }
  }

  cout << c.size() << endl;
  rep(i, c.size()) printf("%d%c", c[i], (i == c.size() - 1 ? '\n' : ' '));
  return 0;
}


Measured memory_bytes: 5324
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <iostream>
#include <queue>

using namespace std;

typedef unsigned int u32;
typedef int i32;
typedef unsigned long long int u64;
typedef long long int i64; // 9e18
typedef uint16_t u16;
typedef int16_t i16;
typedef uint8_t u8;
typedef int8_t i8;

const double PI = 3.141592653589793238463;
const int MAXN = 1000500;
const int MAXVALUE = 1000000500;
const long double EPS = 1e-7;
const i64 INF = 1e18;
i64 mod = 1e9 + 7;


i64 T, n, m, k;
//vector <i64> a;
vector <i64> dp;



int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.precision(16);
    i64 a, b;
    cin >> a >> b;/*
    a.resize(n + 1);

    for (i64 i = 0; i <= n; ++i) {
        cin >> a[i];
    }
*/

    i64 res = a*b;




    cout << res << endl;

    return 0;
}

Measured memory_bytes: 3192
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace __gnu_pbds;
using namespace std;
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define PI 3.1415926535897932384626433832795
typedef tree<pair<int,int>,null_type,less<pair<int,int> >,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
long long MOD = 1e9+7;
pair<int,int> dx[4] = {{1,0},{-1,0},{0,1},{0,-1}};
const int RANDOM = chrono::high_resolution_clock::now().time_since_epoch().count();
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
struct chash {int operator()(int x) const { return x ^ RANDOM; }};
string toString(long long x){stringstream ss;ss << x;string str = ss.str();return str;}
long long fastpow(long long x,long long k){if(!k)return 1;if(k & 1)return ((x * fastpow(x,k-1) % MOD) % MOD) % MOD;
long long ans = fastpow(x,k/2);ans %= MOD;ans *= ans;ans %= MOD;return ans;}
long long sumF(long long x){int s = 0;while(x)s += x%10,x /= 10;return s;}
bool isS(char c){return (c >= 'a' && c <= 'z');}
bool isB(char c){return (c >= 'A' && c <= 'Z');}
bool isD(char c){return (c >= '0' && c <= '9');}
bool isSqrt(long long x){ long long f = sqrt((long double)x + 0.5); return f*f == x;}
long long lcm(long long a,long long b){return a * (b / __gcd(a,b));}
long long arr[100005];
int n;
long long dp[100005][2];
bool visited[100005][2];
long long solve(int idx,bool isFlipped)
{
    if(idx == n+1)
        return 0;
    if(visited[idx][isFlipped])
        return dp[idx][isFlipped];
    long long C = -1e18;
    if(!isFlipped)
    {
        C = max(C,arr[idx] + solve(idx + 1,false));
        if(idx != n)
        C = max(C,(arr[idx] * -1) + solve(idx + 1, true));
    } else {
        C = max(C,(-1*arr[idx]) + solve(idx + 1,false));
        if(idx != n)
        C = max(C,arr[idx] + solve(idx + 1,true));
    }
    visited[idx][isFlipped] = true;
    return dp[idx][isFlipped] = C;
}
int main()
{
    IO;
    cin >> n;
    for(int i = 1;i <= n;i++)
        cin >> arr[i];
    cout << solve(1,false);
    return 0;
}


Measured memory_bytes: 7552
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pii;
typedef pair<pii,ll> piii;
typedef pair<ll,pii> ipii;
#define MOD 1000000007
#define mod(a) ((a)%MOD)
#define pb push_back
#define ft first
#define sd second
#define mp make_pair
#define dbg(x) cerr<<#x<<" = "<<x<<"\n"
#define dbg2(x,y) cerr<<#x<<" = "<<x<<" , "<<#y<<" = "<<y<<"\n"
#define dbg3(x,y,z) cerr<<#x<<" = "<<x<<" , "<<#y<<" = "<<y<<" , "<<#z<<" = "<<z<<"\n"
#define INF (1LL<<60)
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;*/
#define sync ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define all(v) v.begin(),v.end()
#define endl '\n'
ll gcd(ll a,ll b){if(a==0) return b; return gcd(b%a,a);}
ll powm(ll base,ll exp,ll mod=MOD) {base%=mod;ll ans=1;while(exp){if(exp&1LL) ans=(ans*base)%mod;exp>>=1LL,base=(base*base)%mod;}return ans;}
 


vector<pii> p[200005];
ll tree[800005];
ll lazy[800005];


void lazy_update(int node,int s,int e){
    tree[node]+=lazy[node];
    if(s!=e){
      lazy[2*node]+=lazy[node];
      lazy[2*node+1]+=lazy[node];
    }
    
    lazy[node]=0;  
}

void update(ll node,ll s,ll e,ll l,ll r,ll val){
     if(lazy[node]!=0) lazy_update(node,s,e);
     if(s>r||e<l) return;
     if(l<=s&&e<=r){
         tree[node]+=val;
         if(s!=e){
             lazy[2*node]+=val;lazy[2*node+1]+=val;
         }
     }
     else{
        ll mid = (s+e)/2;
        update(2*node,s,mid,l,r,val);
        update(2*node+1,mid+1,e,l,r,val);
        tree[node]=min(tree[2*node],tree[2*node+1]);
     }
}

ll query(ll node,ll s,ll e,ll l,ll r){
     if(s>r||e<l) return INF;
     if(lazy[node]!=0) lazy_update(node,s,e);
     if(l<=s&&e<=r) return tree[node];
     else{
        ll mid = (s+e)/2;
        ll q1=query(2*node,s,mid,l,r);
        ll q2=query(2*node+1,mid+1,e,l,r);
        return min(q1,q2);
     }
}


int main(){
      sync;
      ll n,m;
      cin>>n>>m;
      ll sum=0;
      for(ll i=1; i<=m; i++){
            ll l,r,a;
            cin>>l>>r>>a;
            p[r].pb({l,a});
            sum+=a;
      }
 
       ll ans;
       ll a_sum=0;
       for(int i=1;i<=n+1;i++){
           for(auto it:p[i-1]){
                update(1,1,n,1,it.ft-1,it.sd);
                a_sum+=it.sd;
           }
            ll temp = min(a_sum,query(1,1,n,1,i-1));
            update(1,1,n,i,i,temp);
            if(i==n+1) ans=temp;
       }

          cout<<sum-ans<<endl;
}


Measured memory_bytes: 23680
#define debug_interval ','
#define dump_interval ' '
#define debug_toggle 1

//{
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#include<bits/stdc++.h>
using namespace std;
#define hi //cerr<<"hi"<<endl;
#define int long long
#define INT_MAX LLONG_MAX
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define fi first
#define se second
#define mp make_pair
#define rev reverse
#define dans dump(ans)
//#define MOD 1000000007
#define amp(v,n) (v).count(n)?v[n]++:v[n]=1
#define sysp system("pause")
#define PI acos(-1)
#define ins insert
#define aer(v) (v).erase((v).begin(),(v).end()) 

//{
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class...A> inline void dump(){cout<<endl;}
template<class...A> inline void dump_rest() {cout<<endl;}
template<class T, class...A> inline void dump_rest(const T& first, const A&... rest){cout<<dump_interval<<first;dump_rest(rest...);}
template<class T,class...A> inline void dump(const T&first,const A&...rest){cout<<first;dump_rest(rest...);}
template<class...A> inline void debug(){cerr<<endl;}
template<class...A> inline void debug_rest() {cerr<<endl;}
template<class T, class...A> inline void debug_rest(const T& first, const A&... rest){cerr<<debug_interval<<first;debug_rest(rest...);}
template<class T,class...A> inline void debug(const T&first,const A&...rest){if(debug_toggle)cerr<<first,debug_rest(rest...);}
//}

typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}
template<int m>class mint{private:int i;public:mint() : i(0){}mint(int i): i((i%m+m)%m){}mint operator+(const mint& o){return o.i+i;}mint operator*(const mint& o){return o.i*i;}mint operator-(){return -i;}operator int() {return i;}};

//}

int a,b,c,n,m,k;
string s;

main(){
	cin>>s;
	for(int i=0;i<s.size();i++){
		if(s[i]=='0')a++;
		else b++;
	}
	dump(2*min(a,b));
}





Measured memory_bytes: 512
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <cstring>
#include <map>
#include <set>
#include <queue>
#include <math.h>
#include <unordered_map>
#include <algorithm>
#include <climits>

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
inline int gcd(int a,int b){return b?gcd(b,a%b):a;}
inline int lcm(int a,int b){return a*b/gcd(a,b);}
typedef long long ll;
typedef std::vector<int> VI;
typedef std::pair<int, int> PII;

using namespace std;


int main()
{
  int a;
  string s;

  cin >> a;
  cin >> s;
  if (a >= 3200) cout << s << endl;
  else cout << "red" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const int INF = 1000000005;
const long double EPS = 1e-10;

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

  int ans = 0;
  rep(i, n) {
    FOR(j, i + 1, n) {
      ans += d[i] * d[j];
    }
  }
  cout << ans << endl;


  
  return 0;
}

Measured memory_bytes: 256
from collections import Counter, defaultdict
import sys
sys.setrecursionlimit(10 ** 5 + 10)
input = sys.stdin.readline
from math import factorial
import heapq, bisect
import math
import itertools
# from copy import deepcopy, copy

import queue
from collections import deque




def main():
    num_sushi, length = map(int, input().split())
    data = [list(map(int, input().split())) for i in range(num_sushi)]

    ans = 0
    right1 = [0 for i in range(num_sushi)]
    right1_max = [0 for i in range(num_sushi)]
    for i in range(num_sushi):
        x, v = data[i]
        if i == 0:
            right1[i] = v - x
            right1_max[i] = max(0, right1[i])
        else:
            right1[i] = right1[i - 1] + v - (x - data[i - 1][0])
            right1_max[i] = max(right1_max[i - 1], right1[i])
        ans = max(ans, right1_max[i])

    left1 = [0 for i in range(num_sushi)]
    left1_max = [0 for i in range(num_sushi)]
    for i in range(num_sushi)[::-1]:
        x, v = data[i]
        x = length - x
        if i == num_sushi - 1:
            left1[i] = v - x
            left1_max[i] = max(0, left1[i])
        else:
            left1[i] = left1[i + 1] + v - (data[i + 1][0] - data[i][0])
            left1_max[i] = max(left1_max[i + 1], left1[i])
        ans = max(ans, left1_max[i])

    right2 = [0 for i in range(num_sushi)]
    for i in range(num_sushi - 1):
        x, v = data[i]
        if i == 0:
            right2[i] = v - 2 * x
        else:
            right2[i] = right2[i - 1] + v - 2 * (data[i][0] - data[i - 1][0])
        # print(right2, x, v, data)
        ans = max(ans, right2[i] + left1_max[i + 1])

    left2 = [0 for i in range(num_sushi)]
    for i in range(1, num_sushi)[::-1]:
        x, v = data[i]
        x = length - x
        if i == num_sushi - 1:
            left2[i] = v - 2 * x
        else:
            left2[i] = left2[i + 1] + v - 2 * (data[i + 1][0] - data[i][0])
        ans = max(ans, left2[i] + right1_max[i - 1])

    print(ans)









if __name__ == '__main__':
    main()


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

using namespace std;

uint64_t calcPrimeFactors(uint64_t n) {
    uint64_t s = sqrt(n);
    for (uint64_t x = s; x >= 1; x--) {
        if (n % x == 0) {
            uint64_t ref = n / x;
            return ref + x;
        }
    }
    return 0;
}

int main() {
    uint64_t n;
    cin >> n;

    uint64_t m = calcPrimeFactors(n);

    cout << m - 2 << endl;

}


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

void fnInput(int64_t& nNumN, int64_t& nNumK)
{
  cin >> nNumN >> nNumK;
}
  
int64_t fnMinRepNum(int64_t nNumN, int64_t nNumK)
{
  int64_t nRepNum = nNumN % nNumK;
  return min(nRepNum, nNumK - nRepNum);
}
  
int main()
{
  int64_t nNumN, nNumK;

  fnInput(nNumN, nNumK);
  cout << fnMinRepNum(nNumN, nNumK) << endl;

  return 0;
}

Measured memory_bytes: 3628
#include<iostream> 
#include<vector> 
using namespace std;
const long long int mod=1e9+7;
long long int dfs(int K,const vector<vector<int>>&graph, int now,int from) {
int can_use_color_num; if (from==-1) {
can_use_color_num=K-1; }
else { can_use_color_num=K-2;
}
if (K<graph[now].size()) {
return 0; }
else {
long long int case_num=1; for (auto e : graph[now]) {
if(e==from)continue;
case_num*=can_use_color_num; can_use_color_num--; case_num%=mod;
}
for (auto e : graph[now]) {
if(e==from)continue;
  case_num *=dfs(K,graph,e,now);
case_num %= mod; }
return case_num; }
}
int main() {
int N,K;cin>>N>>K;
vector<vector<int>>graph(N); for(int i=0;i<N-1;++i){
int a,b;cin>>a>>b;a--;b--;
graph[a].push_back(b);
graph[b].push_back(a); }
long long int answer=K*dfs(K,graph,0,-1); answer%=mod;
cout<<answer<<endl;
return 0;
}


Measured memory_bytes: 11520
#include <cstdio>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)

int main(void) {
  int a, b, c;
  scanf("%d%d%d", &a, &b, &c);
  puts(b-a == c-b ? "YES" : "NO");
  return 0;
}


Measured memory_bytes: 128
import java.util.*;
public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        String str1 = sc.next();
        String str2 = sc.next();
        String output = "";
        for(int i = 0;i<N;i++){
            output+=str1.charAt(i) ;
            output+=str2.charAt(i) ;
        }
        System.out.println(output);
    }
}

Measured memory_bytes: 23892
var lines = [];

var one = 0 ;
var two = 0 ;
var three = 0;
var four = 0;

var readline = require('readline');
var rl = readline.createInterface({
  input:  process.stdin,
  output: process.stdout
});

rl.on('line',function(x){
  lines.push(x);
});

rl.on('close',function(x){

lines.forEach(function(x){
    x.split(" ").forEach(function(y){
      switch (Number(y)){
        case 1: one++;  break;
        case 2: two++;  break;
        case 3: three++;break;
        case 4: four++; break;
      }
    });
});
result = one * two * three * four;
if(result === 4){console.log("YES");}
else{console.log("NO");}

});


Measured memory_bytes: 7500
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (true) {
            int n = sc.nextInt();
            int x = sc.nextInt();
            if (n == 0 && x == 0) {
                break;
            }
            int counter = 0;
            for (int k = 1; k <= n; k++) {
                for (int j = k + 1; j <= n; j++) {
                    for (int i = j + 1; i <= n; i++) {
                        if (i + j + k == x) {
                            counter++;
                        }
                    }
                }
            }
            System.out.println(counter);
        }
        sc.close();
    }
}


Measured memory_bytes: 26616
fn main(){
   let eps: f64 = 0.000000001;
   
   loop {
     let mut buf = String::new();
     if let Ok(c) = std::io::stdin().read_line(&mut buf) {
       
       if c < 2 { break; }
       
       let wr: Vec<usize> = buf.split_whitespace().map(|e| e.parse().unwrap()).collect();
       let w = wr[0] as f64;
       let l: usize = wr.len() - 1;
       let rv: Vec<f64> = (1 .. l+1).map(|i| wr[i] as f64).collect();
       
       let mut dp: Vec<Vec<f64>> = vec![vec![2000.0; l]; 1 << l];

       for i in 0 .. l {
         dp[1 << i][i] = rv[i];
       }

       for s in 1 .. (1 << l) {
         for i in 0 .. l {
           if s & (1 << i) > 0 {
             for j in 0 .. l {
               if s & (1 << j) == 0 {
                 let nw = dp[s][i] + dist(rv[i], rv[j]);
                 dp[s | (1 << j)][j] = if nw < dp[s | (1 << j)][j] { nw } else {dp[s | (1 << j)][j]};
               }
             }
           }
         }
       }
       
       for i in 0 .. l {
           dp[(1<<l)-1][i] += rv[i];
       }

       let mut mnl: f64 = dp[(1<<l)-1][0];
       
       for i in 1 .. l {
           if mnl > dp[(1<<l)-1][i] {
              mnl = dp[(1<<l)-1][i];
           }
       }
       
       println!("{}", if (w - mnl).abs() < eps || w > mnl {"OK"} else {"NA"});
     }
   }
}

fn dist(r1: f64, r2: f64) -> f64 {
   2.0 * (r1 * r2).sqrt()
}



Measured memory_bytes: 5040
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
using namespace std;

int INF=1e9;

int main(void){
    int n;
    cin>>n;
    bool ans=false;
    for(int i=0;i<n;i++){
        char s;
        cin>>s;
        if(s=='Y')ans=true;
    }
    if(ans)cout<<"Four"<<endl;
    else cout<<"Three"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <math.h>
#define MOD 1000000007
typedef long long ll;
using namespace std;

int main(){
  ll s,n=0;
  cin>>s;
  ll a[10]={};
  for(ll i=1;;i*=10){
    if((s/i)==0) break;
    n++;
  }
  for(ll i=n-1;i>=0;i--){
    a[i]=s%10;
    s/=10;
  }
  ll ans=0;
  for(ll bit=0;bit<pow(2,n-1);bit++){
    ll tmp=bit,sum=0,op=a[0];
    for(ll j=1;j<n;j++){
      if(tmp&1){
        sum+=op;
        op=a[j];
      }else{
        op*=10;
        op+=a[j];
      }
      tmp>>=1;
    }
    sum+=op;
    //cout<<sum<<endl;
    ans+=sum;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
s = input()
n = len(s)

s = [i for i in s]
for i in range(n):
    if s[i] == "p":
        s[i] = 1
    else:
        s[i] = 0

d = [0]*n
d[0] = 0
gc = 1
pc = 0
for i in range(1, n):
    if gc-1 >= pc:
        d[i] = 1
        pc += 1
    else:
        d[i] = 0
        gc += 1

ans = 0
for i in range(n):
    ans += d[i]-s[i]

print(ans)

Measured memory_bytes: 4764
#include <algorithm>
#include <cstdio>

#define N 8

using namespace std;

/** Application main entry point. */
int main (
  int     argc,
  char  * argv[ ]
  )
{
  int n;
  int i;

  for ( scanf ( "%d", &n ); n--; )
  {
    char digs[ N ];
    int max = 0, min = 0;

    scanf ( " %c%c%c%c%c%c%c%c",
              digs, digs + 1, digs + 2, digs + 3,
              digs + 4, digs + 5, digs + 6, digs + 7 );

    for ( i = 0; i < N; ++i )
    {
      digs[ i ] -= '0';
    }
    sort ( digs, digs + N );
    for ( i = 0; i < N; ++i )
    {
      max = max * 10 + digs[ N - i - 1 ];
      min = min * 10 + digs[ i ];
    }
    printf ( "%d\n", max - min );
  }

  return ( 0 );
}

Measured memory_bytes: 0