akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Linq;

namespace ConsoleApp1 {
    public class Class1 {
        static void Main(string[] args) {
            var num = Console.ReadLine().Trim().Split(' ').Select(_ => long.Parse(_)).ToArray();
            var A = num[0];
            var B = num[1];
            var N = num[2];
            long tmp;
            long ans = 0;

            tmp = Math.Clamp(B - 1, 0, N);
            ans = A * tmp / B;

            Console.Write(ans);
        }
    }
}


Measured memory_bytes: 28152
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <string>
#include <functional>
#include <set>
#define DB cerr<<"D"<<endl
#define pb push_back
using namespace std; using ll=long long; using ld=long double; const int INF=1e9; const ll LINF=1e18; const double dINF = 1e18; const ld ldINF = 1e18; const double EPS = 1e-6;
template<typename T, typename U, typename O> void caut(T a, U b, O c){cout<<"("<<a<<","<<b<<","<<c<<") ";} template<typename T, typename U> void caut(T a, U b){cout<<"("<<a<<","<<b<<") ";} template<typename T> void caut(T a){cout<<"("<<a<<") ";}
using P=pair<double,int>;
const ll M = 998244353;
void add(ll& x, ll y) {x+=y; x%=M;}
void chmax(ll& x, ll y) {if (x<y) x=y;}

int main() {
  string s; cin>>s;
  int a[3]={};
  int n=s.size();
  for(int i=0;i<n;i++) {
    a[s[i]-'a']++;
  }
  // 隣り合わない かつ abcabcかacbacbか...
  // つまりすべての絶対値が1以下
  if (abs(a[0]-a[1]) <= 1 && abs(a[1]-a[2]) <= 1 && abs(a[2]-a[0]) <= 1) {
    cout<<"YES"<<endl;
  } else {
    cout<<"NO"<<endl;
  }
}


Measured memory_bytes: 512
#include <iostream>
#include <array>
#include <vector>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#include <set>

using namespace std;

typedef long long LL;
typedef vector<LL> VEC;
typedef vector<VEC> VVEC;
typedef  pair<LL,LL> P;


const LL INF=1<<30;
const LL MOD=1000000007;





int main(){
    int a,b;
    cin>>a>>b;
    cout<<(a+b+1)/2<<endl;
}



Measured memory_bytes: 256
M = int(input())
B = [0] + list(map(int, input().split()))

ans = [0] * (M+1)
ret = []

for i in reversed(range(1, M+1)):
    if B[i] == sum(ans[i*2::i]) % 2:
        ans[i] = 0
    else:
        ans[i] = 1
    if ans[i] == 1:
        ret.append(i)

print(len(ret))
if len(ret) > 0:
    print(*ret[::-1])

Measured memory_bytes: 14812
#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <utility>
#include <functional>
#include <deque>
#include <cctype>
#include <stack>
#include <bitset>

using ll = long long;
using namespace std;
typedef unsigned long long ull;
typedef std::pair<ll, ll>P;

ll min(ll a, ll b) {
	if (a >= b)return b;
	else return a;
}
ll max(ll a, ll b) {
	if (a >= b)return a;
	else return b;
}
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

const ll Z = 1000000007;
const ll INF = 1 << 30;
const ll INF2 = 9000000000000000000LL;
bool flag = true;
bool fl = true;
bool f = true;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
std::string abc = "abcdefghijklmnopqrstuvwxyz";
struct edge { ll to, cost; };
std::vector<edge>V[100010], W[100010];
typedef std::vector<std::vector<int>>ma;

# define FOR(i,a,b)  for(int i=(a);i<(b);i++)
# define RFOR(i,a,b) for(int i=(a);i>=(b);i--)
# define REP(i,n)    FOR(i,0,n)
# define NREP(i,n)    FOR(i,1,n+1)

int main() {
	string s;
	int k;
	cin >> s >> k;
	REP(i, s.size()) {
		if (k <= 0)break;
		if ((k + (s[i] - 'a')) >= 26) {
			if (i != s.size() - 1) {
				if (s[i] == 'a')continue;
				k -= 'z' - s[i] + 1;
				s[i] = 'a';
			}
			else {
				k %= 26;
				int j = (s[i] - 'a' + k) % 26;
				s[i] = abc[j];
			}
		}
		else if (i == s.size() - 1) {
			k %= 26;
			int j = (s[i] - 'a' + k) % 26;
			s[i] = abc[j];
		}
	}
	cout << s << endl;
}

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

int main() {
  string S;
  cin >> S;
  int ans=1000;
  for (int i=0; i<=S.size()-3; i++) {
    int a=(S[i]-'0')*100+(S[i+1]-'0')*10+(S[i+2]-'0');
    ans=min(ans, abs(753-a));
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
total_cost = 0

dp = [[0] * n for _ in range(n)]

for i in range(n-1, -1, -1):
    for j in range(i+1, n):
        min_cost = None

        for k in range(i, j):
            cost = dp[i][k] + dp[k+1][j]
            if min_cost is None or cost < min_cost:
                min_cost = cost

        dp[i][j] = min_cost + sum(a[i:j+1])

print(dp[0][-1])


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

int main(){
  int K,X;cin>>K>>X;
  int left=max(-100000,X-K+1);
  int right=min(100000,X+K-1);
  cout<<left;
  for(int i=left+1;i<=right;i++) cout<<" "<<i;
  cout<<endl;
}
  


Measured memory_bytes: 3624
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i,a,b) for(int64_t i=(a); i<(b); ++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int64_t i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+b,(a).begin()+c // コンテナ a の 要素 b から c へのイテレータ
#define MOD 1000000007ll
#define INF 1000000000ll
typedef pair<int64_t, int64_t> PII;
typedef vector<int64_t> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

// まずは全探索，次にDP
// 偶奇，逆から，ソート，出現回数，出現位置，DP
// 余事象，包除
// 問題の特徴量
// 存在判定：構成方法，入力の特徴
// 例外を十分に含む一般化．想像力の限界
// 始めは過剰に例示・場合分けしてもいい．各場合を確実に対処．
int main() {
cin.tie(0);
ios::sync_with_stdio(false);

string S, T; cin >> S >> T;

{// S = T
    bool a = true;
    rep(i, 0, S.size()) 
        if (S[i] != T[i]) a = false;
    if (a) {cout << "Yes\n"; return 0;}
}

VI RS(26, -1), RT(26, -1);
rep(i, 0, S.size()){
    if (RS[S[i] - 'a'] == -1) {
        RS[S[i] - 'a'] = T[i] - 'a';
    }
    else if (RS[S[i] - 'a'] != T[i] - 'a') {cout << "No\n"; return 0;}
    if (RT[T[i] - 'a'] == -1) {
        RT[T[i] - 'a'] = S[i] - 'a';
    }
    else if (RT[T[i] - 'a'] != S[i] - 'a') {cout << "No\n"; return 0;}
}


cout << "Yes\n";

}

// 境界，出力文字列 チェック



Measured memory_bytes: 916
d = []
for i in range(5):
    d.append(int(input()))
k = int(input())
for i, j1 in enumerate(d[:5]):
    for j2 in d[i+1:]:
        if (j1 - j2) ** 2 > k ** 2:
            print(':(')
            exit()
print('Yay!')

Measured memory_bytes: 2940
#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 INF 2e9
#define ALL(v) v.begin(), v.end()
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
using namespace std;
typedef long long ll;

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

}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{

	public static void main(String[] args)  {
		// TODO Auto-generated method stub

		Scanner sc = new Scanner(System.in);

		int k = sc.nextInt();
		int odd = (k + 1)/2;
		int even = k - odd;

		System.out.println(odd*even);
	}

}


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

typedef long long ll;

int bin_pow(int b, int e) {
    if(e == 0) return 1;

    int p = bin_pow(b, e / 2);
    p *= p;
    p %= 2019;

    if(e & 1) return p * b % 2019;
    else return p;
}

int main() {
	ios_base::sync_with_stdio(false);

    string s;
    cin >> s;

    int n = s.size();
    vector<int> suf(n + 1), cnt(2020);
    cnt[0]++;

    int ans = 0, e = 0;

    for(int i = n - 1; i >= 0; i--) {
        suf[i] = (((s[i] - '0') * bin_pow(10, e++)) % 2019 + suf[i + 1]) % 2019;

        for(int j = 0; j <= 2018; j++) {
            if((suf[i] - j + 2019) % 2019 == 0) {
                ans += cnt[j];
            }
        }

        cnt[suf[i]]++;
    }

    cout << ans << endl;
}



Measured memory_bytes: 4452
#include<stdio.h>
int Adj[101][101];
int main(){
	int i,j;
    int n,a,b,c;	
    
    scanf("%d",&n);
	for(i=0;i<n;i++)
    {
		scanf("%d%d",&a,&b);
		for(j=0;j<b;j++)
        {
			scanf("%d",&c);
			Adj[a][c]=1;
		}
	}

	for(i=1;i<=n;i++){
		for(j=1;j<=n;j++){
			if(j>1)
            { 
                printf(" "); 
            }
			printf("%d",Adj[i][j]);
		}
		printf("\n");
	}


	return 0;
}



Measured memory_bytes: 2084
#include <cstdio>
#include <iostream>

using namespace std;

int main(void)
{
    int t[4];
    t[0] = 1;
    t[1] = 7;
    t[2] = 9;
    t[3] = 4;
    bool e[4];
    int n1,n2,n3,n4;

    cin >>n1 >>n2 >>n3 >>n4;

    for(int i = 0; i < 4; i ++){
        if(n1 == t[i] || n2 == t[i] || n3 == t[i] || n4 == t[i]){
            e[i] = true;
        }else{
            e[i] = false;
        }
    }
    bool ans = e[0] & e[1] & e[2] &e[3];
    if(ans){
        printf("YES\n");
    }else{
        printf("NO\n");
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define base 1000000007LL
#define ll long long
#define ld double
#define X first
#define Y second
#define pb push_back
#define EPS 1e-22
#define all(a) (a).begin(), (a).end()
#define sz(a) int((a).size())
#define ms(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
using namespace std;
typedef pair<int, int> II;
typedef pair<II, int> III;

int n;
ll a[100010];

int main()
{
    ios::sync_with_stdio(0);
    //freopen("inp.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    cin >> n;
    FOR(i,1,n) cin >> a[i];
    ll sum = 0;
    ll res = 0;
    FOR(i,1,n) {
        sum += a[i];
        if (i % 2) {
            if (sum > 0) continue;
            res += 1 - sum;
            sum = 1;
        }
        else {
            if (sum < 0) continue;
            res += sum + 1;
            sum = -1;
        }
    }
    sum = 0;
    ll res2 = 0;
    FOR(i,1,n) {
        sum += a[i];
        if (i % 2 == 0) {
            if (sum > 0) continue;
            res2 += 1 - sum;
            sum = 1;
        }
        else {
            if (sum < 0) continue;
            res2 += sum + 1;
            sum = -1;
        }
    }
    cout << min(res, res2);
    return 0;
}


Measured memory_bytes: 1024
fun main(args: Array<String>){
    val (n, x, y) = readLine()!!.split(" ").map { it.toInt() }
    val k = Array(n){0}
    for (i in 1 until n){
        for (j in i + 1 until n+1){
            if(j - i > abs(x - i) + abs(y - j) + 1){
                k[abs(x - i) + abs(y - j) + 1]++
            }else{
                k[j - i]++
            }
        }
    }
    for (i in 1 until n){
        println(k[i])
    }
}

fun abs(a: Int): Int{
    return if (a > 0) a else -a
}

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

#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")

#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define mpq priority_queue<int,vector<int>,greater<int>>
#define debug(a) cerr << #a << ": " << a << endl
#define umii unordered_map<int64_t,int64_t>
#define ftt int t;cin>>t;for(int tt=1;tt<=t;++tt)
#define forr(i,n) for((i)=1;(i)<=(n);(i)++)
#define Rev(v) reverse(v.begin(),v.end());
#define Sort(v) sort(v.begin(),v.end());
#define mem(a,b) memset(a,b,sizeof(a))
#define deb(x) cout<<"\nhi"<<x<<"\n"
#define pq priority_queue<int>
#define dbg cout<<"\nhi\n"
#define sayy cout<<"YES\n"
#define sayn cout<<"NO\n"
#define pii pair<int,int>
#define mii map<int,int>
#define vb vector<bool>
#define vi vector<int>
#define eb emplace_back
#define nl cout<<"\n"
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define sp <<" "<<
#define int long long
#define double long double
#define se second
#define fi first

const int MOD = 1000000007;
const double PI = 3.1415926535898;
const int LIM = 100005;

using namespace std;

int fpow( int x,int y) {
    int temp;
    if(y == 0)
        return 1;
    temp = fpow(x, y/2);
    if (y%2 == 0)
        return temp*temp;
    else
        return x*temp*temp;}

int gcd(int a,int b) {
    if(b==0)return a;
    return gcd(b,a%b);}

void sieve(int n) {
     bool prime[5*LIM];
     memset(prime, true, sizeof(prime));
     for (int p=2; p*p<=n; p++)
          if (prime[p] == true)
               for (int i=p*p; i<=n; i += p)
                    prime[i] = false;
     prime[1]=0;}

inline int read(){
    int p=1,ans=0;
    char ch=getchar();
    while(ch<48||ch>57)
    {
        if(ch=='-')p=-1;
        ch=getchar();
    }
    while(ch>=48&&ch<=57)
    {
        ans=(ans<<3)+(ans<<1)+ch-48;
        ch=getchar();
    }
    return ans*p;
}

int fun(int n)
{
    if(n % 2 != 0)
        return n;
    while(n % 2 == 0)
        n /= 2;
    return n;
}

/*int cnt, sum = 0, mid, mx = -1e17, mn = 1e17, a[2*LIM];
int n, m, d, t, i, j, k, l, r, x, y, z;
bool f, f1, f2;
string s;*/

//*************************************************************************************************************************


int32_t main()
{    fio;

     int n;
     cin>>n;
     int c = 1, temp = n;
     while(temp > 0)
     {
        temp -= (int)pow(26,c);
        c++;
     }
     c--;
     temp = c;
     int l = 0, r = 0;
     while(temp > 1)
        l += (int)pow(26,--temp);
    r = l + (int)pow(26,c);
    
    while(c > 0)
    {
        int q = ceil((n-l)/pow(26,--c));
        cout<<char(q+96);
        l += (q-1)*(int)pow(26,c);
        r = l + (int)pow(26,c);
    }
}





Measured memory_bytes: 3988
N, A, B, C = map(int, input().split())
n = [A, B, C]
c = ["A", "B", "C"]
S = [input() for i in range(N)]
op = []

for i in range(N):
	if S[i] == "AB":
		op.append((0, 1))
	elif S[i] == "BC":
		op.append((1, 2))
	else:
		op.append((2, 0))

dec = []
for i in range(N):
	j1 = op[i][0]
	j2 = op[i][1]
	if n[j1] < n[j2]:
		dec.append(c[j1])
		n[j1] += 1
		n[j2] -= 1
	elif n[j2] < n[j1]:
		dec.append(c[j2])
		n[j2] += 1
		n[j1] -= 1
	elif i < N - 1:
		if j1 in op[i + 1]:
			if j1 == op[i + 1][0]:
				j3 = op[i + 1][1]
			else:
				j3 = op[i + 1][0]
			if n[j3] < n[j1]:
				dec.append(c[j1])
				n[j1] += 1
				n[j2] -= 1
			else:
				dec.append(c[j2])
				n[j2] += 1
				n[j1] -= 1
		else:
			if j2 == op[i + 1][0]:
				j3 = op[i + 1][1]
			else:
				j3 = op[i + 1][0]
			if n[j3] < n[j2]:
				dec.append(c[j2])
				n[j2] += 1
				n[j1] -= 1
			else:
				dec.append(c[j1])
				n[j1] += 1
				n[j2] -= 1
	else:
		dec.append(c[j1])
		n[j1] += 1
		n[j2] -= 1
	if n[0] < 0 or n[1] < 0 or n[2] < 0:
		print("No")
		exit()
print("Yes")
print("\n".join(dec))

Measured memory_bytes: 86576
#include <math.h>

//(1+「2以上sqrt(n)未満」まででnを割り切った数i+n/iの全て)と(nが平方数ならsqrt(n)、さもなくば0)の和
int solve(int n){
  int sum=1,i=2;
  double s=sqrt(n);
  if(n<6)return -1;
  for(;i<s;i++){
    if(n%i==0)sum += i+n/i;
  }
  if(floor(s)==s)sum+=s;
  return sum-n;
}

int main(){
  int n,r;
  for(;scanf("%d",&n),n;){
    r=solve(n);
    if(r<0)puts("deficient number");
    if(r==0)puts("perfect number");
    if(r>0)puts("abundant number");
  }
  return 0;
}

Measured memory_bytes: 584
import std.stdio;
import std.string;
import std.format;
import std.conv;
import std.typecons;
import std.algorithm;
import std.functional;
import std.bigint;
import std.numeric;
import std.array;
import std.math;
import std.range;
import std.container;
import std.concurrency;
import std.traits;
import std.uni;
import core.bitop : popcnt;
alias Generator = std.concurrency.Generator;

enum long INF = long.max/5;
enum long MOD = 10L^^9+7;

void main() {
  long N, K, S;
  scanln(N, K, S);

  long[] xs = new long[N];
  if (S != 10L^^9) {
    foreach(i; 0..K) {
      xs[i] = S;
    }
    foreach(i; K..N) {
      xs[i] = 10L^^9;
    }
  } else {
    foreach(i; 0..K) {
      xs[i] = S;
    }
    foreach(i; K..N) {
      xs[i] = 1;
    }
  }
  xs.map!(to!string).join(" ").writeln;
}

// ----------------------------------------------


void times(alias fun)(long n) {
  // n.iota.each!(i => fun());
  foreach(i; 0..n) fun();
}
auto rep(alias fun, T = typeof(fun()))(long n) {
  // return n.iota.map!(i => fun()).array;
  T[] res = new T[n];
  foreach(ref e; res) e = fun();
  return res;
}

T ceil(T)(T x, T y) if (isIntegral!T || is(T == BigInt)) {
  // `(x+y-1)/y` will only work for positive numbers ...
  T t = x / y;
  if (y > 0 && t * y < x) t++;
  if (y < 0 && t * y > x) t++;
  return t;
}

T floor(T)(T x, T y) if (isIntegral!T || is(T == BigInt)) {
  T t = x / y;
  if (y > 0 && t * y > x) t--;
  if (y < 0 && t * y < x) t--;
  return t;
}

ref T ch(alias fun, T, S...)(ref T lhs, S rhs) {
  return lhs = fun(lhs, rhs);
}
unittest {
  long x = 1000;
  x.ch!min(2000);
  assert(x == 1000);
  x.ch!min(3, 2, 1);
  assert(x == 1);
  x.ch!max(100).ch!min(1000); // clamp
  assert(x == 100);
  x.ch!max(0).ch!min(10); // clamp
  assert(x == 10);
}

mixin template Constructor() {
  import std.traits : FieldNameTuple;
  this(Args...)(Args args) {
    // static foreach(i, v; args) {
    foreach(i, v; args) {
      mixin("this." ~ FieldNameTuple!(typeof(this))[i]) = v;
    }
  }
}

void scanln(Args...)(auto ref Args args) {
  enum sep = " ";
  enum n = Args.length;
  enum fmt = n.rep!(()=>"%s").join(sep) ~ "\n";
  static if (__VERSION__ >= 2071) {
    readf!fmt(args);
  } else {
    enum argsTemp = n.iota.map!(
      i => "&args[%d]".format(i)
    ).join(", ");
    mixin(
      "readf(fmt, " ~ argsTemp ~ ");"
    );
  }
}

// fold was added in D 2.071.0
static if (__VERSION__ < 2071) {
  template fold(fun...) if (fun.length >= 1) {
    auto fold(R, S...)(R r, S seed) {
      static if (S.length < 2) {
        return reduce!fun(seed, r);
      } else {
        return reduce!fun(tuple(seed), r);
      }
    }
  }
}

// popcnt with ulongs was added in D 2.071.0
static if (__VERSION__ < 2071) {
  ulong popcnt(ulong x) {
    x = (x & 0x5555555555555555L) + (x>> 1 & 0x5555555555555555L);
    x = (x & 0x3333333333333333L) + (x>> 2 & 0x3333333333333333L);
    x = (x & 0x0f0f0f0f0f0f0f0fL) + (x>> 4 & 0x0f0f0f0f0f0f0f0fL);
    x = (x & 0x00ff00ff00ff00ffL) + (x>> 8 & 0x00ff00ff00ff00ffL);
    x = (x & 0x0000ffff0000ffffL) + (x>>16 & 0x0000ffff0000ffffL);
    x = (x & 0x00000000ffffffffL) + (x>>32 & 0x00000000ffffffffL);
    return x;
  }
}


Measured memory_bytes: 6140
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <climits>
using namespace std;
#define MOD int(1e9 + 7)
#define INF (long long)(1e18)

const double PI=3.14159265358979323846;

int main()
{
    cout.precision(18);

    double A, B, H, M;
    cin >> A >> B >> H >> M;

    double cm = H * 60 + M;
    double ha = (cm / 2) / 180 * PI;
    double ma = (M * 6) / 180 * PI;
    double hx = A * cos(ha);
    double hy = A * sin(ha);
    double mx = B * cos(ma);
    double my = B * sin(ma);

    cout << sqrt(pow(hx - mx, 2) + pow(hy - my, 2)) << endl;
}

Measured memory_bytes: 4164
#include <iostream>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <limits>
#include <algorithm>
#include <functional>

#include <vector>
#include <bitset>

using namespace std;

int H, W, K;
vector<vector<int>> grid;

int H_MASK_MAX;

int process(const bitset<10>& curr_bit)
{
	vector<int> cut_h;
	for (int i = 0; i < curr_bit.size() - 1; i++)
	{
		if (curr_bit[i])
		{
			cut_h.push_back(i);
		}
	}
	cut_h.push_back(10);

	vector<int> block_sum(cut_h.size(), 0);

	int cut_count = 0;
	for (int j = 0; j < W; j++)
	{
		int curr_block_idx = 0;
		for (int i = 0; i < H; i++)
		{
			block_sum[curr_block_idx] += grid[i][j];
			if (cut_h[curr_block_idx] == i) curr_block_idx++;
		}

		for (int b = 0; b < block_sum.size(); b++)
		{
			if (block_sum[b] > K)
			{
				cut_count++;

				block_sum.assign(cut_h.size(), 0);
				int curr_block_idx = 0;
				for (int i = 0; i < H; i++)
				{
					if (block_sum[curr_block_idx] == K && grid[i][j]) return -1;

					block_sum[curr_block_idx] += grid[i][j];
					if (cut_h[curr_block_idx] == i) curr_block_idx++;
				}
			}
		}
	}

	return cut_count;
}

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

	cin >> H >> W >> K;

	grid.assign(H, vector<int>(W, 0));

	for (int i = 0; i < H; i++)
	{
		string line;
		cin >> line;

		for (int j = 0; j < W; j++)
		{
			grid[i][j] = line[j] - '0';
		}
	}

	H_MASK_MAX = 1 << (H - 1);
	int result = (H - 1) + (W - 1);

	for (int mask = 0; mask < H_MASK_MAX; mask++)
	{
		bitset<10> curr_bit(mask);
		int curr_result = process(curr_bit);
		if (curr_result >= 0)
		{
			result = min(result, curr_result + (int)curr_bit.count());
		}
	}

	cout << result;

	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define M 500000

void merge(int*,int,int,int);
void MergeSort(int*,int,int);

int count=0;
int main(){
  int n,i,A[M];
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  MergeSort(A,0,n);
  for(i=0;i<n-1;i++){
    printf("%d ",A[i]);
  }
  printf("%d\n",A[i]);

  printf("%d\n",count);
  return 0;
}

void merge(int *A,int left,int mid,int right){
  int i,j,k,n1,n2,L[M],R[M];
  n1=mid-left;
  n2=right-mid;
    for(i=0;i<n1;i++){
      L[i]=A[left+i];
    }
    for(i=0;i<n2;i++){
      R[i]=A[mid+i];
    }
    L[n1]=999999999;
    R[n2]=999999999;
    i=0;
    j=0;
    for(k=left;k<right;k++){
      if(L[i]<=R[j]){
        A[k]=L[i];
        i++;
      }
      else{
        A[k]=R[j];
        j++;
      }
      count++;
    }
}


void MergeSort(int *A,int left,int right){
  int mid;
  if((left+1)<right){
    mid=(left+right)/2;
    MergeSort(A,left,mid);
    MergeSort(A,mid,right);
    merge(A,left,mid,right);
  }
}



Measured memory_bytes: 5652
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	N := ReadInt()
	for h := 1; h <= 3500; h++ {
		for n := 1; n <= 3500; n++ {
			p := N * h * n
			q := 4*h*n - N*n - N*h
			if q <= 0 {
				continue
			}
			if p%q == 0 {
				w := p / q
				fmt.Println(h, n, w)
				return
			}
		}
	}
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


Measured memory_bytes: 1864
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int N;
    cin >> N;
    string S = "Christmas",T = " Eve";
    rep(i,0,25-N){
        S += T;
    }
    cout << S << endl;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


class Mod:
    def __init__(self, m):
        self.m = m

    def add(self, a, b):
        return (a + b) % self.m

    def sub(self, a, b):
        return (a - b) % self.m

    def mul(self, a, b):
        return ((a % self.m) * (b % self.m)) % self.m

    def div(self, a, b):
        return self.mul(a, pow(b, self.m-2, self.m))

    def pow(self, a, b):
        return pow(a, b, self.m)


@mt
def slv(N, K, A):
    ans = 0
    A_ = sorted(A)

    mod = Mod(10**9+7)
    c = mod.div(mod.sub(mod.mul(K, K), K), 2)
    
    for i, a in enumerate(A):
        j = bisect.bisect_left(A_, a) 
        t = 0
        for d in A[i:]:
            if d < a:
                t += 1
        ans = mod.add(ans, mod.mul(c, j))
        ans = mod.add(ans, mod.mul(K, t))
    return ans


def main():
    N, K = read_int_n()
    A = read_int_n()
    print(slv(N, K, A))


if __name__ == '__main__':
    main()


Measured memory_bytes: 63976
#include<stdio.h>
int main(void){
	int a,b,i,n=1;

	while(1){
		scanf("%d %d",&a,&b);
		if(a==0&&b==0){break;}
		if(n==1){n=0;}
		else{puts("");}
		int flag=0;

		for(i=a;i<=b;i++){
			if(i%4==0){
				if(i%100==0){
					if(i%400==0){
						flag=1;
						break;
					}
				}
				else{
					flag=1;
					break;
				}
			}
		}

		if(flag==0){printf("NA\n");}
		else{
			for(i=a;i<=b;i++){
				if(i%4==0){
					if(i%100==0){
						if(i%400==0){
							printf("%d\n",i);
						}
					}
					else{
						printf("%d\n",i);
					}
				}
			}
		}
	}
	return 0;
}
	

Measured memory_bytes: 612
#include<bits/stdc++.h>
#define nil -1
using namespace std;

struct node{int parent,depth;};

void filldepth(int depth,int parent,vector<node>&tree,vector<vector<int>>&elem){
	for(int i=0;i<elem.at(parent).size();++i){
		tree.at(parent).depth=depth;
		if(elem.at(parent).at(i)!=nil)filldepth(depth+1,elem.at(parent).at(i),tree,elem);
	}
}

int calheight(int height,int id,vector<vector<int>>&elem){
	if(elem.at(id).at(0)==nil&&elem.at(id).at(1)==nil)return 0;
	int lefth=height,righth=height,left=elem.at(id).at(0),right=elem.at(id).at(1);
	if(left!=nil)lefth=max(lefth,calheight(height+1,left,elem));
	if(right!=nil)righth=max(righth,calheight(height+1,right,elem));
	return max(lefth,righth);
}

void print(int id,vector<node>&tree,vector<vector<int>>&elem){
	int p=tree.at(id).parent,s,deg=0,dep=0,h=calheight(1,id,elem);
	if(p==nil)s=nil;
	else if(elem.at(p).at(0)!=id)s=elem.at(p).at(0);
	else s=elem.at(p).at(1);
	for(auto&child:elem.at(id))if(child!=nil)++deg;
	if(p!=nil)dep=tree.at(p).depth;
	cout<<"node "s<<id<<": parent = "s<<p<<", sibling = "s<<s<<", degree = "s<<deg
		<<", depth = "s<<dep<<", height = "s<<h<<", "s;
	if(p==nil)cout<<"root"s;
	else if(deg==0)cout<<"leaf"s;
	else cout<<"internal node"s;
	cout<<"\n"s;
}

int main(){
	//cin.tie(0),ios::sync_with_stdio(false);
	int n;
	cin>>n;
	vector<node>tree(n);
	vector<vector<int>>elem(n,vector<int>(2));
	for(auto&node:tree)node.parent=nil;
	for(int i=0,id,left,right;i<n;++i){
		cin>>id>>left>>right;
		if(left!=nil)tree.at(left).parent=id;
		if(right!=nil)tree.at(right).parent=id;
		elem.at(id).at(0)=left;
		elem.at(id).at(1)=right;
	}
	int P=0;
	while(tree.at(P).parent!=nil)++P;
	filldepth(1,P,tree,elem);
	for(int i=0;i<n;++i)print(i,tree,elem);
}


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

namespace b
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ');
            var N = input[0];
            var K = int.Parse(input[1]);
            
            var P = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).OrderBy(x => x).ToArray();
            var sum = 0;
            foreach(var i in Enumerable.Range(0, K))
            {
                sum += P[i];
            }
            Console.WriteLine(sum.ToString());
        }
    }
}


Measured memory_bytes: 28492
#include<bits/stdc++.h>
#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) REP(i,0,(n))
typedef long long ll;
using namespace std;

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    cout << a * b / 2 << endl;
    return 0;
}

Measured memory_bytes: 256
from sys import exit, setrecursionlimit, stderr
from functools import reduce
from itertools import *
from collections import defaultdict
from bisect import bisect

def read():
  return int(input())

def reads():
  return [int(x) for x in input().split()]

N = read()
A = reads()

psum = [0] * (N + 1)
for i in range(N):
  psum[i+1] = psum[i] + A[i]

# print(psum, file=stderr)

ans = 10**20
for i in range(2, N-1):
  lmid = psum[i] / 2
  k = bisect(psum, lmid)
  if abs(psum[k-1] - lmid) < abs(psum[k] - lmid):
    k = k-1

  rmid = (psum[N] + psum[i]) / 2
  l = bisect(psum, rmid)
  if abs(psum[l-1] - rmid) < abs(psum[l] - rmid):
    l = l-1

  m = min(psum[k], psum[i] - psum[k], psum[l] - psum[i], psum[N] - psum[l])
  M = max(psum[k], psum[i] - psum[k], psum[l] - psum[i], psum[N] - psum[l])
  ans = min(ans, M - m)

print(ans)


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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int main() {

    int x; cin >> x;

    if (400 <= x && x <= 599) {
        cout << 8 << endl;
        return 0;
    }
    if (600 <= x && x <= 799) {
        cout << 7 << endl;
        return 0;
    }
    if (800 <= x && x <= 999) {
        cout << 6 << endl;
        return 0;
    }
    if (1000 <= x && x <= 1199) {
        cout << 5 << endl;
        return 0;
    }
    if (1200 <= x && x <= 1399) {
        cout << 4 << endl;
        return 0;
    }
    if (1400 <= x && x <= 1599) {
        cout << 3 << endl;
        return 0;
    }
    if (1600 <= x && x <= 1799) {
        cout << 2 << endl;
        return 0;
    }
    if (1800 <= x && x <= 1999) {
        cout << 1 << endl;
        return 0;
    }
}

Measured memory_bytes: 3640
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using uint = unsigned int;
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
#ifdef LOCAL
#include"rprint2.hpp"
#else
using namespace std;
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printe) FUNC(printw) FUNC(printew) FUNC(printb) FUNC(printd);
#endif

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s; cin >> s;
    cout << s[0] << s.size() - 2 << s.back() << '\n';
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var X = int.Parse(Console.ReadLine());
            if(X == 5 || X == 3 || X == 7)
            {
                Console.WriteLine("YES");
            }
            else
            {
                Console.WriteLine("NO");
            }
        } 
    }
}


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

int main() {
  int N, K, x, s = 0;

  cin >> N >> K;
  while(N){
    cin >> x;
	int sub = x - K;
    if(sub < 0){
      sub   *= -1;
    }
    if(sub < x){
      s += sub * 2;
    }else{
      s += x * 2;
    }
    N--;
  }
  cout << s << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define pb push_back
#define sz(x) (int)x.size()
#define mod 1000000007
#define inf 1000000000000000001;
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define F first
#define S second
#define watch(x) cerr << "\n" << (#x) << " = " << (x) << "\n"
using namespace std;
string s, t;

int main(){
	ios_base::sync_with_stdio(0);
    cin.tie(0); 
    cout.tie(0);
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif
	cin >> s >> t;
	int S = s.length();
	int T = t.length();
	int ans = 5000;
	for(int i = 0; i <= S - T; ++i){
		int change = 0;
		for(int j = i; j < (i + T); ++j){
			if(t[j - i] != s[j])
				change++;
		}
		ans = min(ans, change);
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 3648
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using ld = long double;

const int INF = (1 << 30) - 1;
const ll INF64 = ((ll)1 << 62) - 1;
const double PI = 3.1415926535897932384626433832795;

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

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

	int a, b;
	cin >> a >> b;

	int ans = 0;
	for (int i = a; i <= b; i++) {
		string str = to_string(i);
		string rvStr = str;
		reverse(rvStr.begin(), rvStr.end());
		if (str == rvStr) {
			ans++;
		}
	}

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


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int compare_lld(const void *a, const void *b)
{
  long long int *A = (long long int *)a;
  long long int *B = (long long int *)b;
  if (*A > *B) return 1;
  if (*A < *B) return -1;
  return 0;
}

int main(){
  long long int n,x,i;
  scanf("%lld",&n);
  scanf("%lld",&x);
  long long int total[51];
  total[0] = 1;
  for(i=1;i<51;i++){
    total[i] = total[i-1]*2+3;
  //  printf("%lld\n",total[i]);
  }
  long long int ntemp,xtemp,ans;
  long long int end = 0;
  ntemp = n;
  xtemp = x;
  ans = 0;
  while(ntemp > 0 && end == 0) {
    //printf("%lld %lld %lld\n",ntemp,xtemp,ans);
    if (xtemp == 0) {
      end = 1;
    } else if (xtemp == 1) {
      end = 1;
      xtemp = 0;
    } else if (xtemp < (total[ntemp]+1)/2) {
      xtemp -= 1;
    } else if (xtemp == (total[ntemp]+1)/2) {
      ans += (total[ntemp-1]+1)/2 + 1;
      end = 1;
    } else if (xtemp < total[ntemp]) {
      ans += (total[ntemp-1]+1)/2 + 1;
      xtemp -= (total[ntemp]+1)/2;
    } else {
      ans += (total[ntemp]+1)/2;
      end = 1;
    }
    ntemp--;
  }
  if(ntemp == 0 && xtemp == 1) {
    ans++;
  }
  printf("%lld\n",ans);
  return 0;
}


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

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


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

const (
	initialBufSize = 1024
	maxBufSize     = 1e6
)

var (
	scanner = bufio.NewScanner(os.Stdin)
)

func main() {
	scanner.Split(bufio.ScanWords)
	// scanner.Buffer(make([]byte, initialBufSize), maxBufSize)
	n := scanInt()
	ans := 0
	for i := 1; i <= n; i++ {
		if !(i%3 == 0 || i%5 == 0) {
			ans += i
		}
	}
	fmt.Println(ans)
}

func scanInt() int {
	i, _ := strconv.Atoi(scanText())
	return i
}

func scanInts(size int) []int {
	ints := make([]int, size)
	for i := 0; i < size; i++ {
		ints[i] = scanInt()
	}
	return ints
}

func scanFloat64() float64 {
	f, _ := strconv.ParseFloat(scanText(), 64)
	return f
}

func scanFloat64s(size int) []float64 {
	f := make([]float64, size)
	for i := 0; i < size; i++ {
		f[i] = scanFloat64()
	}
	return f
}

func scanText() string {
	scanner.Scan()
	return scanner.Text()
}

func scanTexts(size int) []string {
	s := make([]string, size)
	for i := 0; i < size; i++ {
		s[i] = scanText()
	}
	return s
}

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

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

// greatest common divisor(最大公約数)
func gcd(a, b int) int {
	for {
		mod := a % b
		if mod == 0 {
			return b
		}
		a, b = b, mod
	}
}

// latest common multiple(最小公倍数)
func lcm(a, b int) int {
	return (a / gcd(a, b)) * b
}

func fact(n int) int {
	ret := 1
	for i := 1; i <= n; i++ {
		ret *= i
	}
	return ret
}

func isPrimeNum(n int) bool {

	if n <= 1 {
		return false
	}

	l := int(math.Sqrt(float64(n)) + 1.)
	for i := 2; i < l; i++ {
		if n%i == 0 {
			return false
		}
	}

	return true
}


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

using namespace std;

typedef long long ll;
#define mod 1000000007
#define rep(i, a, b) for(ll i = a; i < b; i++)
#define repc(i, a, b, c) for (ll i = a; (c > 0 ? i < b : i > b) and c != 0; i += c)
#define mp make_pair
#define pb push_back
#define all(name) (name.begin(), name.end())
#define fact(n) rep(i, 1, n+1)ft.pb((ft[i-1]*i)%mod);
#define mod_in(a) power(a, mod-2)
#define ncr(n, r) ((ft[n]*mod_in((ft[r]*ft[(n)-(r)])%mod))%mod)
#define deb(x) cout << #x << " " << x << endl;
// ll dp[105][100005];
int main()
{
	ios_base::sync_with_stdio(false); 
	cin.tie(NULL);
	int t = 1;
	// cin >> t;
	while(t--)
	{
		ll n, k;
		cin >> n;
		ll arr[n][3];
		cin >> arr[0][0] >> arr[0][1] >> arr[0][2];
		rep(i, 1, n){
			cin >> arr[i][0] >> arr[i][1] >> arr[i][2];
			arr[i][0] += max(arr[i-1][1], arr[i-1][2]);
			arr[i][1] += max(arr[i-1][2], arr[i-1][0]);
			arr[i][2] += max(arr[i-1][1], arr[i-1][0]);
		}
		cout << max(arr[n-1][0], max(arr[n-1][1], arr[n-1][2]));
	}
}

Measured memory_bytes: 2560
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <cstdlib>
#include <utility>
#include <cmath>
#include <queue>
#include <stack>
#include <cstring>

using namespace std;

#define ll long long

#ifndef ONLINE_JUDGE
#define debug(format, ...) fprintf(stderr, \
    "%s:%d: " format "\n", __func__, __LINE__,##__VA_ARGS__)
#else
#define debug(format, ...)
#define NDEBUG
#endif

int n, k;

struct Perm {
    int* vals;
};

Perm operator*(Perm a, Perm b)
{
    Perm ans;
    ans.vals = new int[n + 5];
    for (int i = 1; i <= n; i++) {
        ans.vals[i] = b.vals[a.vals[i]];
    }
    return ans;
}

Perm operator^(Perm a, int pwr)
{
    Perm ans;
    ans.vals = new int[n + 5];
    bool* vis = new bool[n + 5];
    for (int i = 1; i <= n; i++) vis[i] = false;
    for (int i = 1; i <= n; i++) {
        if (vis[i]) continue;
        vector<int> cycle;
        int cur = i;
        do {
            vis[cur] = true; cycle.push_back(cur); cur = a.vals[cur];
        } while (cur != i);
        for (int x = 0; x < cycle.size(); x++) {
            ans.vals[cycle[x]] = cycle[(x + pwr) % cycle.size()];
        }
    }
    delete[] vis;
    return ans;
}

Perm inv(Perm a)
{
    Perm ans;
    ans.vals = new int[n + 5];
    for (int i = 1; i <= n; i++) {
        ans.vals[a.vals[i]] = i;
    }
    return ans;
}

Perm a[15];

int main()
{
    scanf("%d%d", &n, &k);
    Perm p, q;
    p.vals = new int[n + 5];
    q.vals = new int[n + 5];
    for (int i = 1; i <= n; i++) scanf("%d", p.vals + i);
    for (int i = 1; i <= n; i++) scanf("%d", q.vals + i);
    Perm ans;
    if (k < 6) {
        a[1] = p; a[2] = q;
        for (int i = 3; i <= k; i++) {
            a[i] = inv(a[i-2]) * a[i-1];
        }
        ans = a[k];
    } else {
        Perm perm_x = p * q * inv(p) * inv(q);
        Perm perm_y = q * p * inv(q) * inv(p);
        int cnt = (k % 6 >= 4 ? k / 6 : (k / 6) - 1);
        Perm middle;
        if (k % 6 == 0) {
            middle = p * p * inv(q) * inv(p);
        } else if (k % 6 == 1) {
            middle = p * q * p * inv(q) * inv(p);
        } else if (k % 6 == 2) {
            middle = p * q * inv(p) * q * p * inv(q) * inv(p);
        } else if (k % 6 == 3) {
            middle = p * q * inv(p) * inv(p) * q * p * inv(q) * inv(p);
        } else if (k % 6 == 4) {
            middle = inv(p);
        } else {
            middle = p * inv(q) * inv(p);
        }
        ans = inv(q) * (perm_x ^ cnt) * middle * (perm_y ^ cnt) * q;
    }
    for (int i = 1; i <= n; i++) {
        printf("%d ", ans.vals[i]);
    }
    return 0;
}


Measured memory_bytes: 14628
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace Tasks
{
    public class C
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var N = int.Parse(Console.ReadLine());
            var p = (int)1e9 + 7;
            var answer = 1L;
            var factors = new Dictionary<int, int>();
            for (var i = N; i >= 1; i--)
            {
                var prime = new Prime(i);
                foreach (var f in prime.Factors)
                {
                    if (!factors.ContainsKey(f.Key)) factors[f.Key] = 0;
                    factors[f.Key] += f.Value;
                }
            }

            foreach (var f in factors)
            {
                answer *= f.Value + 1;
                answer %= p;
            }

            Console.WriteLine(answer);
        }

        public class Prime
        {
            public Dictionary<int, int> Factors => new Dictionary<int, int>(_factors);
            private Dictionary<int, int> _factors;
            private static HashSet<int> _primes;
            public Prime(int n)
            {
                if (_primes == null) _primes = new HashSet<int>();
                _factors = new Dictionary<int, int>();
                var tmp = n;
                var max = (int)Math.Sqrt(n);
                var p = 2;
                while (p <= max)
                {
                    if (tmp % p == 0)
                    {
                        _factors[p] = 0;
                        _primes.Add(p);
                        while (tmp % p == 0)
                        {
                            tmp /= p;
                            _factors[p]++;
                        }
                    }
                    p++;
                }
                if (tmp > 1)
                {
                    _factors[tmp] = 1;
                    _primes.Add(tmp);
                }
            }
            public bool IsPrime(int n)
            {
                if (_primes.Contains(n)) return true;
                var p = new Prime(n);
                return _primes.Contains(n);
            }
        }
    }
}


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

int main()
{
	int n,w;
	cin >> n >> w;
	vector<ll int> vec(n);
	vector<ll int> val(n);
	for(int i=0;i<n;i++)
		cin >> vec[i] >> val[i];

	vector<vector<ll int> > dp(n+1,vector<ll int>(w+1));
	for(int i=0;i<=n;i++)
	{
		for (int j = 0; j <=w; j++)
		{
			if(i==0||j==0)
				dp[i][j] =0;
			else if(vec[i-1] > j)
				dp[i][j] = dp[i-1][j];
			else
				dp[i][j] = max(dp[i-1][j], val[i-1] + dp[i-1][j-vec[i-1]]);

		}
	}
	cout << dp[n][w] << endl;
	
	return 0;
}

Measured memory_bytes: 80256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

int main() {
	int n;
	while(n=in()){
		int i;
		int a=-1,b=-1,c;
		bool beg=true;
		for(i=0;i<n;i++){
			cin>>c;
//cout<<" "<<c<<endl;
			if(a==-1){
				a=b=c;
			}else if(b!=c-1){
				if(a==b){if(beg)cout<<a;else cout<<" "<<a;}
				else if(beg)cout<<a<<"-"<<b;
				else cout<<" "<<a<<"-"<<b;
				a=b=c;
				beg=false;
			}else{
				b=c;
			}
		}
		if(a==b){
			if(beg){
				cout<<a;
			}else{
				cout<<" "<<a;
			}
		}else if(beg){
			cout<<a<<"-"<<b;
		}else{
			cout<<" "<<a<<"-"<<b;
		}
		
		cout<<endl;
	}
	return 0;
}

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

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

void factorization(vector<LLP>& llp, ll n) {
    if (n <= 1) return;
    ll n2 = n;
    for (ll i = 2; i * i <= n ; i++) {
        int count = 0;
        while (n2 % i == 0) {
            n2 = n2 / i;
            count ++;
        }
        if (count > 0) {
            LLP temp;
            temp.first = i;
            temp.second = count;
            llp.push_back(temp);
        }
    }
    if (n2 > 1) {
        LLP temp;
        temp.first = n2;
        temp.second = 1;
        llp.push_back(temp);
    }
}

int main() {

    long long N;
    cin >> N;

    ll ans = 0;
    if (N > 2) {
        ll count = 1;
        vector<LLP> fac;
        factorization(fac, N - 1);
        rep(i,fac.size()) {
            count *= fac[i].second + 1;
        }
        ans += count - 1;
    }
    for (ll i = 2; i * i <= N; i++) {
        if (N % i != 0) continue;
        if (i * i < N) {
            ll j = N / i;
            ll n = N;
            while (n % i == 0) n /= i;
            if (n % i == 1) ans++;
            n = N;
            while (n % j == 0) n /= j;
            if (n % j == 1) ans++;
        } else ans++;
    }

    ans++;

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

Measured memory_bytes: 3632
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

X = INT()
ans = 0
def DFS(X):
	for i in range(2, int(sqrt(X))+1):
		#print(i, X)
		if X%i == 0:
			return DFS(X+1)
			break
	else:
		return X

print(DFS(X))


Measured memory_bytes: 5200
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define N 810
struct edge{
  ll to,cost;
};
vector<edge> g[N];
ll n;
ll d[N];
void dfs(ll x,ll from,ll len){
  d[x]=len;
  for(auto y:g[x])if(y.to!=from){
    dfs(y.to,x,len+y.cost);
  }
}
P far(ll s){
  dfs(s,0,0);
  ll ma=-1,pt=-1;
  for(int i=1;i<=n;i++){
    if(g[i].size()==1)continue;
    if(ma<d[i]){
      ma=d[i],pt=i;
    }
  }
  return make_pair(ma,pt);
}
int main(){
  while(cin>>n&&n>0){
    ll t[N],r[N];
    for(int i=2;i<=n;i++)cin>>t[i];
    for(int i=2;i<=n;i++)cin>>r[i];
    for(int i=1;i<=n;i++)g[i].clear();
    for(int i=2;i<=n;i++){
      ll a=i,b=t[i];
      edge gen;gen.cost=r[i];
      gen.to=b; g[a].push_back(gen);
      gen.to=a; g[b].push_back(gen);
    }
    ll a=0;
    for(int i=1;i<=n;i++)if(g[i].size()>1){a=i;break;}
    ll b=far(a).second;
    ll c=far(b).first;
    ll ans=0;
    for(int i=1;i<=n;i++)if(g[i].size()==1)ans-=g[i][0].cost*4;
    for(int i=1;i<=n;i++)for(auto y:g[i])ans+=y.cost*3;
    ans/=2; ans-=c;
    cout<<ans<<endl;
  }
    return 0;
}



Measured memory_bytes: 3280
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<stack>
#include<queue>
#include<string>
#include<set>
#include<map>
using namespace std;
#define rep(i,n) for(int i=0;(i)<(n);(i)++)
#define FOR(i,m,n) for(int i=(m);(i)<(n);(i)++)
typedef long long ll;

int main(){
    int x,a,b;
    cin >> x >> a >> b;
    x = x-a;
    while(x-b>=0){
        x-=b;
    }
    cout << x << endl;
    return 0;
}

Measured memory_bytes: 256