akhauriyash/Code-Regression huggingface dataset:
N, M = map(int, input().split())
mod = pow(10, 9) + 7

def comb(n, k):
  if k > n-k:
    return comb(n, n-k)
  mul, div = 1, 1
  for i in range(k):
    mul = mul * (n-i) % mod
    div = div * (k-i) % mod
  ret = mul * pow(div, mod-2, mod) % mod
  return ret

i = 2
ans = 1
tmp = M
while i * i <= M:
  if tmp % i == 0:
    cnt = 0
    while tmp % i == 0:
      tmp //= i
      cnt += 1
    ans = ans * comb(cnt+N-1, N-1) % mod
  i += 1
if tmp != 1:
  ans = ans * comb(1+N-1, N-1) % mod
print(ans)

Measured memory_bytes: 3064
#include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <complex>
#include <iterator>
#include <array>
#include <memory>
#include <stack>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 1e6+10
using namespace std;
typedef pair<int, int> pii;
typedef pair<double,double>pdd;
typedef pair<ll,ll>pll;
using namespace std;
#define int ll

vector<int>precal;
vector<int>dp(MAX+10,MAX);
vector<bool>flag(MAX+10,false);
signed main(){
    int n;
    precal.push_back(0);
    dp[0]=0;
    for(int i=1;;i++){
        int cnt=((i)*(i+1)*(i+2))/6;
        if(cnt>MAX)break;
        precal.push_back(cnt);
        flag[cnt]=true;
    }
    for(int i=1; i<=MAX-9;i++){
        if(flag[i]){dp[i]=1; continue;}
        int index=(int)(upper_bound(precal.begin(),precal.end(),i)-precal.begin());
        for(int j=0; j<index;j++)
            dp[i]=min(dp[i],dp[precal[j]]+dp[i-precal[j]]);
    }
    vector<int>oddcal;
    vector<int>odp(MAX+10,MAX);
    vector<bool>oddflag(MAX+10,false);
    oddcal.push_back(0);
    odp[0]=0;
    for(int i=1;;i++){
        int cnt=(i*(i+1)*(i+2))/6;
        if(cnt>MAX)break;
        if(!(cnt%2))continue;
        oddcal.push_back(cnt);
        oddflag[cnt]=true;
    }
    for(int i=1; i<=MAX-9;i++){
        if(oddflag[i]){odp[i]=1;continue;}
        int index=(int)(upper_bound(oddcal.begin(), oddcal.end(), i)-oddcal.begin());
        for(int j=0;j<index;j++)
            odp[i]=min(odp[i],odp[oddcal[j]]+odp[i-oddcal[j]]);
        
    }
    while(cin>>n,n){
        cout<<dp[n]<<" "<<odp[n]<<endl;
    }
}

Measured memory_bytes: 18804
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define MOD 1000000007
using namespace std;

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

int main() {
    int M1, M2, D1, D2;
    cin >> M1 >> D1 >> M2 >> D2;
    cout << (D1 < D2 ? 0 : 1) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REPL(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 998244353;

ll binary_pow(ll a, ll N) {
  ll ans = 1;
  ll tmp = a;
  while(N > 0) {
    if(N % 2 == 1) {
      ans *= tmp;
      ans %= mod;
    }
    N /= 2;
    tmp *= tmp;
    tmp %= mod;
  }
  return ans;
}
ll modinv(ll a, ll m=mod) {
  ll b = m, u = 1, v = 0;
  while(b) {
    ll t = a / b;
    a -= t * b; swap(a, b);
    u -= t * v; swap(u, v);
  }
  u %= m;
  if(u < 0) u += m;
  return u;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  int S;
  cin >> N >> S;
  vector<int> A(N);
  rep(i, N) cin >> A[i];
  int mx = S+1;
  vector<vector<ll>> dp(N+1, vector<ll>(mx));
  dp[0][0] = 1;
  rep(i, N) {
    rep(j, mx) {
      if(j+A[i]<mx) (dp[i+1][j+A[i]] += dp[i][j]) %= mod;
      (dp[i+1][j] += dp[i][j] * 2) %= mod;
    }
  }
  cout << dp[N][S] << endl;
  return 0;
}


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

#define ll long long int
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define all(A) A.begin(), A.end()
#define sz(A) (int)A.size()
typedef vector <int> vi;
typedef vector <ll> vl;
typedef pair <int, int> pii;
const ll mod = 1e9 + 7;
//const ll mod = 998244353;
const int inf = 1e9;
//const ll inf = 1e18;
const int N = 2e5;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n, k;
	cin >> n >> k;
	cout << min(n % k, k - n % k) << "\n";
 	return 0;
}

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

using namespace std;

#define forn(i, n) for (ll i = 0; i < (ll) (n); ++i)
#define sz(a) static_cast<int>((a).size())
#define pb emplace_back
#define mp make_pair
#define endl '\n'
#define f first
#define s second

#ifdef SEREZHKA
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define dbg(...)
#endif

template<typename T>
void _dbg(const char* _s, T _h) { cerr << _s << " = " << _h << "\n"; }

template<typename T, typename... Ts>
void _dbg(const char*_s, T _h, Ts... _t) {
    int _b = 0;
    
    while (((_b += *_s == '(') -= *_s == ')') != 0 || *_s != ',')
        cerr << *_s++;
    
    cerr << " = " << _h << ",";
    _dbg(_s + 1, _t...);
}

using ll = long long;

const ll INF = static_cast<ll>(1e9) + 7ll;
const ll LINF = INF * INF;
const int MAXN = static_cast<int>(1e6) + 17;

int n, K;

bool read() {
    if (!(cin >> n >> K))
        return false;

    return true;
}

void solve() {
    if (n == 2) {
        cout << (K == 2 ? "Yes\n1 2 3\n" : "No\n");
        return ;
    }

    if (K == 1 || K == 2 * n - 1) {
        cout << "No\n";
        return ;
    }

    vector<int> a(2 * n - 1), p(2 * n - 1);
    iota(a.begin(), a.end(), 1);
    set<int> s(a.begin(), a.end());

    if (K == 2) {
        p[n - 2] = K + 2;
        p[n - 1] = K - 1;
        p[n] = K;
        p[n + 1] = K + 1;

        for (int k = K - 1; k <= K + 2; ++k)
            s.erase(k);
    } else {
        p[n - 2] = K - 2;
        p[n - 1] = K + 1;
        p[n] = K;
        p[n + 1] = K - 1;

        for (int k = K - 2; k <= K + 1; ++k)
            s.erase(k);
    }

    forn (i, 2 * n - 1)
        if (p[i] == 0) {
            p[i] = *s.begin();
            s.erase(s.begin());
        }

    cout << "Yes\n";

    forn (i, 2 * n - 1)
        cout << p[i] << ' ';

    cout << endl;
}

int main() {
    cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    
#ifdef SEREZHKA
    freopen("file.in", "r", stdin);
#endif
    
    while (read())
        solve();
    
    return 0;
}



Measured memory_bytes: 12416
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n, ans;
  cin >> n;
  vector<int> b(n-1);
  vector<int> a(n);

  for(int i=0;i<n-1;i++) cin >> b.at(i);
  for(int i=0;i<n;i++){
  	if(i==0) a.at(i) = b.at(i);
  	else if(i==n-1) a.at(i) = b.at(i-1);
  	else a.at(i) = min(b.at(i), b.at(i-1));
  }

  for(int i=0;i<n;i++) ans += a.at(i);
  cout << ans << endl;
}

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

int main(){
  char str[7];

  scanf("%s", str);

  if(str[2] == str[3] && str[4] == str[5]){
    printf("Yes\n");
  }else{
    printf("No\n");
  }

  return 0;
}


Measured memory_bytes: 128
#include "math.h"
#include <set>
#include <algorithm>
#include <complex>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
using namespace std;
typedef long long int lli;
int main()
{
    int n, m;
    cin >> n >> m;
    int a[100005], b[109000];
    lli c[100005] = {};
    rep(i, n)
    {
        cin >> a[i] >> b[i];
        c[a[i]]++;
        c[b[i]]++;
    }
    bool ans = true;
    rep(i, n + 1)
    {
        ans &= !(c[i] & 1);
    }
    cout << (ans ? "YES" : "NO") << endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
using namespace std;
long long MOD = 1e9 + 7;

long long N, M;
vector<long long> X, Y, Z;

long long dp(long long xt, long long yt, long long zt) {
	vector<long long> V(N, 0);
	for (long long n = 0; n < N; n++) {
		V[n] = X[n] * xt + Y[n] * yt + Z[n] * zt;
	}
	sort(V.begin(), V.end(), [](long long a, long long b) {
		return a < b;
	});
	long long ans = 0;
	for (long long t = 0; t < M; t++) {
		ans += V[N - 1 - t];
	}
	return ans;
}

int main() {
	cin >> N >> M;
	X.resize(N);
	Y.resize(N);
	Z.resize(N);
	for (long long n = 0; n < N; n++) {
		cin >> X[n] >> Y[n] >> Z[n];
	}
	long long ans = LLONG_MIN;
	for (long long x = 1; x >= -1; x -= 2) {
		for (long long y = 1; y >= -1; y -= 2) {
			for (long long z = 1; z >= -1; z -= 2) {
				ans = max(ans, dp(x, y, z));
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdlib.h>
#include<math.h>
#define rep(i,n) for(i=0;i<n;i++)
#define PI 3.14159265358979323846264338327950L
int main(){
    int a,b;
    scanf("%d%d",&a,&b);
    if(a==b) printf("Draw");
    else if(a>b){
        if(b==1) printf("Bob");
        else printf("Alice");
    }
    else{
        if(a==1) printf("Alice");
        else printf("Bob");
    }
    return 0;
}

Measured memory_bytes: 1628
h, w = map(int, input().split())
ans = float('Inf')
l = [float('Inf')]*4
for i in range(1, max(h, w)):
  a, b, c, d = l
  if i <= h:
    a = abs(max(i*w, (h-i)//2*w, (h-i-(h-i)//2)*w) - min(i*w, (h-i)//2*w, (h-i-(h-i)//2)*w))
    b = abs(max(i*w, (h-i)*(w//2), (h-i)*(w-w//2)) - min(i*w, (h-i)*(w//2), (h-i)*(w-w//2)))  

  if i <= w:
    c = abs(max(i*h, (w-i)//2*h, (w-i-(w-i)//2)*h) - min(i*h, (w-i)//2*h, (w-i-(w-i)//2)*h))
    d = abs(max(i*h, (w-i)*(h//2), (w-i)*(h-h//2)) - min(i*h, (w-i)*(h//2), (w-i)*(h-h//2)))
  
  if min(a, b, c, d) < ans:
    ans = min(a, b, c, d)

print(ans)

Measured memory_bytes: 3064
import java.util.*;
import static java.lang.Math.*;
import java.math.BigInteger;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		int[][] city = new int[n][2];
		for(int i = 0; i < n; i++){
		    city[i][0] = sc.nextInt();
		    city[i][1] = sc.nextInt();
		}
		
		// 計算
		double result = 0;
		double[][] dist = new double[n][n];
		for(int i = 0; i < n; i++){
		    for(int j = i+1; j < n; j++){
		        double x2 = (city[i][0] - city[j][0])*(city[i][0] - city[j][0]);
		        double y2 = (city[i][1] - city[j][1])*(city[i][1] - city[j][1]);
		        dist[i][j] = sqrt(x2 + y2);
		        dist[j][i] = sqrt(x2 + y2);
		    }
		}
		double sum = 0;
		for(int i = 0; i < n; i++){
		    for(int j = 0; j < n; j++){
		        if(i == j) continue;
		        sum += dist[i][j];
		    }
		}
		result = sum/n;
		
		// 出力
		System.out.println(result);
	}
}


Measured memory_bytes: 23892
package main

import (
	"fmt"
	"strings"
)

func main() {
	var s, t string
	fmt.Scanf("%s", &s)
	fmt.Scanf("%s", &t)

	if strings.HasPrefix(t, s) {
		fmt.Printf("Yes")
	} else {
		fmt.Printf("No")
	}
}


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

#define INF 1e18
#define REP(i, n) for (int i=0; i<n; i++)
#define print(x) cout << x << endl
#define debug(x) cout << #x << " = "<< x << endl

const double PI=3.141592653589793238462643383279502884197169399375105820974944;

typedef long long ll;

using namespace std;

void solve() {
    int N;
    cin >> N;
    print(N*N*N);
}

signed main() {
    solve();
}


Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <cassert>
#include <algorithm>
#define MAXDEG 524288
#define LGDEG 19
#define HIGHEST 262144
#define MAXDEGN 1000005
#define MAXN 700005
#define MAXNN 700005
using namespace std;
struct Complex{
    double re,im;
    Complex(void):re(0.0),im(0.0){}
    Complex(double tr,double ti=0.0):re(tr),im(ti){}
    Complex(const Complex& tc):re(tc.re),im(tc.im){}
    friend Complex operator+(const Complex& lhs,const Complex& rhs);
    friend Complex operator-(const Complex& lhs,const Complex& rhs);
    friend Complex operator*(const Complex& lhs,const Complex& rhs);
    friend Complex operator-(const Complex& x);
};

typedef long long ll;

const double pi=acos(-1.0);
int rev[MAXDEGN];
Complex a[MAXDEGN],b[MAXDEGN],t[MAXDEGN];

const int p=200003;
const int ppw=200002;
const int gp=5;
int logp[MAXNN];
ll cnts[MAXN];
int arrr[MAXNN];

void fft(Complex* f,int is_inv=0);

signed main(void){
    int cur=1;
    logp[cur]=0;
    for (int i=1;i<ppw;i++)
        cur=cur*gp%p,logp[cur]=i;
    int n,nn=0;
    scanf("%lld",&n);
    for (int i=1;i<=n;i++){
        int t;
        scanf("%lld",&t);
        if (!t)
            continue;
        cnts[logp[t]]++;
        arrr[++nn]=t;
    }
    for (int i=0;i<ppw;i++)
        a[i].re=cnts[i];
    rev[0]=0;
    for (int i=1;i<MAXDEG;i++)
        rev[i]=(i&1)?(HIGHEST^(rev[i>>1]>>1)):(rev[i>>1]>>1);
    fft(a);
    for (int i=0;i<MAXDEG;i++)
        a[i]=a[i]*a[i];
    fft(a,1);
    for (int i=0,ub=ppw+ppw;i<=ub;i++)
        cnts[i]=llround(a[i].re);
    ll ans=cnts[0];
    cur=1;
    for (int i=1,ub=ppw+ppw;i<=ub;i++){
        cur=cur*gp%p;
        ans+=1ll*cnts[i]*cur;
    }
    for (int i=1;i<=nn;i++)
        ans-=1ll*arrr[i]*arrr[i]%p;
    assert(!(ans&1));
    ans/=2;
    printf("%lld\n",ans);
    return 0;
}

void fft(Complex* f,int is_inv){
    for (int i=0;i<MAXDEG;i++)
        t[i]=f[rev[i]];
    for (int i=0;i<LGDEG;i++){
        int cur_len=1<<i;
        int tran_len=cur_len<<1;
        Complex omega_n=Complex(cos(pi/cur_len),sin(pi/cur_len)); //2pi/tran_len=pi/cur_len
        (is_inv)?(omega_n.im=-omega_n.im):(0);
        for (int unit_l=0;unit_l<MAXDEG;unit_l+=tran_len){
            Complex omega=Complex(1.0,0.0);
            for (int k=0;k<cur_len;k++,omega=omega*omega_n){
                //kth couple
                int cpa=unit_l+k;
                int cpb=cpa+cur_len;
                Complex a_val=t[cpa];
                Complex b_val=omega*t[cpb];
                t[cpa]=a_val+b_val;
                t[cpb]=a_val-b_val;
            }
        }
    }
    for (int i=0;i<MAXDEG;i++)
        f[i]=t[i];
    if (is_inv)
        for (int i=0;i<MAXDEG;i++)
            f[i].re/=MAXDEG,f[i].im/=MAXDEG;
}

Complex operator+(const Complex& lhs,const Complex& rhs){
    return Complex(lhs.re+rhs.re,lhs.im+rhs.im);
}
Complex operator-(const Complex& lhs,const Complex& rhs){
    return Complex(lhs.re-rhs.re,lhs.im-rhs.im);
}
Complex operator*(const Complex& lhs,const Complex& rhs){
    return Complex(lhs.re*rhs.re-lhs.im*rhs.im, lhs.re*rhs.im+lhs.im*rhs.re);
}
Complex operator-(const Complex& x){
    return Complex(-x.re,-x.im);
}

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

using namespace std;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define fin(ans) cout << (ans) << endl;
#define blank(ans) cout << (ans) << " ";
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()

typedef long long ll;
typedef long long lli;
typedef unsigned long long ull;
typedef long double ld;
typedef string str;

typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<ld> vd;
typedef vector<str> vs;
typedef vector<ll> vll;
typedef vector<pair<ll, ll>> vpll;
typedef vector<pair<ll, str>> vpls;
typedef vector<tuple<str, ll, ll>> vtsl;
typedef vector<vector<ll>> vvll;
typedef vector<vector<char>> vvc;
typedef vector<vector<str>> vvs;

const ld PI = acos(-1.0);
const ll MAX = 9000000000000000000;
const ll MIN = -9000000000000000000;
const ld DMAX = 4500;
const ld DMIN = -4500;
const ll MOD = 1000000007;

vector<ll> enum_div(ll n)
{
  vector<ll> ret;
  for (ll i = 1; i * i <= n; ++i)
  {
    if (n % i == 0)
    {
      ret.push_back(i);
      if (i * i != n)
      {
        ret.push_back(n / i);
      }
    }
  }
  sort(begin(ret), end(ret));
  return ret;
}

//実行部
void Main()
{
  ll n, k; cin >> n;
  if(n < 1200) fin("ABC")
  else if(n < 2800) fin("ARC")
  else fin("AGC")
}

//前処理
int main()
{
  //ios::sync_with_stdio(false);
  //cin.tie(0);
  cout << fixed << setprecision(20); //高精度少数表示
  Main();
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define SORT(a) sort((a).begin(), (a).end())
#define RSORT(a) reverse((a).begin(), (a).end())
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
const long long INF = 1LL << 60;
// const int INF=1010101010;
using Graph = vector<vector<int>>;

const int MAX_DIGIT = 100;
long long dp[200][2][5];

int main() {
  string n;
  int k;
  cin >> n >> k;

  dp[0][0][0] = 1;

  rep(i, n.length()) {
    rep(j, 2) {
      rep(t, k + 1) {
        int c = n[i] - '0';  // i桁目
        rep(now, 10) {
          if (c < now && j == 0) continue;  // n以下でない場合は除く
          int jj = j;
          int tt = t;
          if (now != 0) tt++;
          if (now < c) jj = 1;  //これ以降は絶対に小さくなる
          dp[i + 1][jj][tt] += dp[i][j][t];
        }
      }
    }
  }
  ll ans = dp[n.length()][0][k] + dp[n.length()][1][k];
  cout << ans << endl;
}

Measured memory_bytes: 256
#![allow(unused_mut, unused_macros, unused_variables, unused_assignments, non_snake_case, unused_imports)]

use std::cmp::*;
use std::collections::*;

// [Rustで競技プログラミングの入力をスッキリ記述するマクロ - Qiita]
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 から拝借
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
    // ABC128-C-Switches用に拡張
    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, $t);
        (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    }};
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        N:usize,
        A:[usize;N]
    }
    let a2 = A.iter().map(|x| x * 2).collect::<Vec<usize>>();
    let mut cur = a2.iter().fold(0usize, |offset, x| x - offset) / 2;
    for a in a2 {
        println!("{}", cur);
        cur = a - cur;
    }
}


Measured memory_bytes: 7420
#include<iostream>
#include<vector>
#include<cstdio>
#include<set>
#include<cmath>
#include<algorithm>
using namespace std;
int main(){
    string s;
    bool flag;
    cin >> s;
    if(s.size()%2==1){
        for(int i=s.size()-2;i>=0;i-=2){
            flag = true;
            for(int j=0;(i-1)/2>=j;j++){
                if(s[j]!=s[j+(i+1)/2]){
                    flag = false;
                    break;
                }
            }
            if(flag){
                    cout << i+1 << endl;
                    return 0;
            }
        }
    }
    else{
        for(int i=s.size()-3;i>=0;i-=2){
            flag = true;
            for(int j=0;(i-1)/2>=j;j++){
                if(s[j]!=s[j+(i+1)/2]){
                    flag = false;
                    break;
                }
            }
            if(flag){
                    cout << i+1 << endl;
                    return 0;
            }
        }
    }
    cout << 2 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

template<typename T> T gcd(T a, T b) { return b ? gcd(b, a%b) : a; }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

int main() {
    lint n;
    cin >> n;
    cout << lcm(2LL, n) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <iomanip>
#include <climits>
#include <functional>
#include <cassert>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<PII> VPI;
typedef vector<PLL> VPL;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define pf push_front
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ub upper_bound
#define lb lower_bound

int main(){
  int X;
  cin>>X;
  if(X>=30) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


Measured memory_bytes: 3624
#include <stdio.h>
#define N 100
#define INF 200000
#define WHITE 0
#define GRAY 1
#define BLACK 2

int G[N][N], n;

void dijkstra(void) {
  int d[N], color[N];
  int i, u, mincost;

  for(i = 0; i < n; i++) {
    d[i] = INF;
    color[i] = WHITE;
  }
  d[0] = 0;

  while(1){
    mincost = INF;
    for(i = 0; i < n; i++) {
      if(color[i] != BLACK && d[i] < mincost){
        mincost = d[i];
        u = i;
      }
    }
    if(mincost == INF) break;
    color[u] = BLACK;
    for(i = 0; i < n; i++) {
      if(color[i] != BLACK && G[u][i] != INF && d[u] + G[u][i] < d[i]) {
        d[i] = d[u] + G[u][i];
      }
    }
  }
  for(i = 0; i < n; i++) {
    printf("%d %d\n", i, d[i]);
  }
}

int main(){
  int i, j, u, v, k, c;

  scanf("%d",&n);
  for(i = 0; i < n; i++) {
    for(j = 0; j < n; j++) {
      G[i][j] = INF;
    }
  }

  for(i = 0; i < n; i++) {
    scanf("%d", &u);
    scanf("%d", &k);
    for(j = 0; j < k; j++) {
      scanf("%d", &v);
      scanf("%d", &c);
      G[u][v] = c;
    }
  }
  dijkstra();
  return 0;
}

Measured memory_bytes: 636
#include "bits/stdc++.h"
using namespace std;
 
string s,t;
deque<char> a,b;
bool f = false;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cin>>s>>t;
	for(int i=0;i<s.size();i++){
		a.push_back(s[i]);
		b.push_back(t[i]);
	}
	if(s == t)
		cout<<"Yes";
	else{
		int cnt = 0;
		while(cnt <= s.size()){
			char temp = a.back();
			a.pop_back();
			a.push_front(temp);
			if(a == b){
				f = true;
				break;
			}
			cnt++;
		}
		if(f)
			cout<<"Yes";
		else
			cout<<"No";
	}
	return 0;
}

Measured memory_bytes: 384
import sys
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits


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()))


sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

a, b = MAP()

for x in range(2, 1000):
    if b - a == x:
        print(int((x - 1) * x / 2 - a))


Measured memory_bytes: 4084
#include <iostream>
using namespace std;
int main(){
  int n;
  cin >> n;
  int k;
  cin >> k;
  char c[n];
  cin >> c;
  if(c[k-1] == 'A')c[k-1] = 'a';
  else if(c[k-1] == 'B')c[k-1] = 'b';
  else if(c[k-1] == 'C')c[k-1] = 'c';
  cout << c << endl;
  return 0;
}

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

int main() {
  int N, K, index = 0, _min = 1001, cnt = 0, sum = 0;
  cin >> N >> K;
  vector<int> p(N);
  rep(i, N) cin >> p[i];

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

  rep(i, K) sum += p[i];

  cout << sum << '\n';
  // while(cnt < K) {
  //   _min = 1001;
  //   rep(i, N) {
  //     if (p[i] < _min) {
  //       _min = p[i];
  //       index = i;
  //     }
  //   }
  //   sum += _min;
  //   cnt++;
  //   p[index] = 1001;
  // }
}

Measured memory_bytes: 3612
#include <cstdio>
#include <climits>
#include <cassert>
#include <cmath>
#include <iostream>
#include <string>
#include <algorithm>
#include <numeric>
#include <functional>
#include <tuple>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <vector>
#include <iterator>
#include <regex>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define FOR(x,xs) for(auto &x: xs)

using namespace std;
typedef long long ll;
typedef pair<int,int> PI;
typedef pair<ll,ll> PL;
typedef vector<int> VI;
typedef vector<ll> VL;

template <class T, template <class, class> class C, class charT = char>
void vdump(const C<T, allocator<T>> &v, const charT* delimiter = ", ",
           ostream &stream = cout) {
  copy(v.begin(), v.end(), ostream_iterator<T>(stream, delimiter));
  stream << endl;
}

PL min_partition(const VL &sum, int left, int right, ll val) {
  auto lb = lower_bound(sum.begin() + left, sum.begin() + right, val);
  int lb1 = lb - sum.begin();
  ll large = 1e18;
  if (left < lb1 && lb1 < right) {
    large = min(large, sum[lb1] - sum[left]);
  }
  int lb0 = lb1 - 1;
  if (left < lb0 && lb0 < right) {
    large = min(large, sum[right] - sum[lb0]);
  }
  return {sum[right] - sum[left] - large, large};
}

ll solve(const VL &sum, int mid) {
  int n = sum.size();
  ll left_sum = sum[mid];
  PL left_mm = min_partition(sum, 0, mid, (left_sum) / 2);
  PL right_mm = min_partition(sum, mid, n-1, (sum[n-1] + sum[mid]) / 2);
  return max(left_mm.second, right_mm.second) - min(left_mm.first, right_mm.first);
}

int main() {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  VL as(n);
  FOR(a,as) {
    cin >> a;
  }
  VL sum(n+1);
  REP(i,0,n) {
    sum[i+1] = sum[i] + as[i];
  }
  ll ans = 1e18;
  REP(mid,2,n-1) {
    ans = min(ans, solve(sum, mid));
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3456
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<utility>
#include<string>
#include<stack>
#include<queue>
#include<set>
#include<math.h>
#include <map>
using namespace std;
typedef long long int ll;
#define repi(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,a) repi(i,0,a)
#define all(u) u.begin(),u.end()
#define pl pair<ll,ll>
#define fi first
#define se second
#define mod 1000000007
#define inf 1<<30
#define mp(a,b) make_pair(a,b)
#define len(u,N) u.begin(),u.begin()+N


ll N,K;
string S;

int main() {
    cin >> N;
    cin >> S;
    cin >> K;
    char c = S[K-1];
    rep(i,N){
        if (S[i] != c){
            S[i] = '*';
        }
    }
    cout << S << endl;
    return 0;
}


Measured memory_bytes: 256
// practice with kaiboy
import java.io.*;
import java.util.*;

public class Main extends PrintWriter {
	Main() { super(System.out, true); }
	Scanner sc = new Scanner(System.in);
	public static void main(String[] $) {
		Main o = new Main(); o.main(); o.flush();
	}

	void main() {
		int n = sc.nextInt();
		int t = sc.nextInt();
		int[] aa = new int[n];
		int[] bb = new int[n];
		for (int i = 0; i < n; i++) {
			aa[i] = sc.nextInt();
			bb[i] = sc.nextInt();
		}
		int[][] dp = new int[n][t];
		int[][] dq = new int[n][t];
		for (int i = 0; i < n - 1; i++) {
			int a = aa[i];
			int b = bb[i];
			for (int x = t - 1; x >= 0; x--) {
				dp[i + 1][x] = dp[i][x];
				if (x + a < t)
					dp[i + 1][x + a] = Math.max(dp[i + 1][x + a], dp[i][x] + b);
			}
		}
		for (int i = 0; i < n - 1; i++) {
			int a = aa[n - 1 - i];
			int b = bb[n - 1 - i];
			for (int x = t - 1; x >= 0; x--) {
				dq[i + 1][x] = dq[i][x];
				if (x + a < t)
					dq[i + 1][x + a] = Math.max(dq[i + 1][x + a], dq[i][x] + b);
			}
		}
		int ans = 0;
		for (int i = 0; i < n; i++) {
			int p = i, q = n - 1 - i;
			for (int x = t - 1, y = 0, z = 0; x >= 0; x--, y++)
				ans = Math.max(ans, dp[p][x] + bb[i] + (z = Math.max(z, dq[q][y])));
		}
		println(ans);
	}
}


Measured memory_bytes: 134496
package main

import (
	"fmt"
	"math"
)

func main() {
	// Code for C - Ubiquity
	var N int
	fmt.Scan(&N)

	var a, b, c int
	var ans int
	a = 1
	b = 2
	c = 1

	for i := 0; i < N; i++ {
		a = (a * 10) % (int(math.Pow10(9)) + 7)
		b = (b * 9) % (int(math.Pow10(9)) + 7)
		c = (c * 8) % (int(math.Pow10(9)) + 7)
	}

	ans = (a - b + c) % (int(math.Pow10(9)) + 7)
	if ans < 0 {
		ans += (int(math.Pow10(9)) + 7)
	}

	fmt.Println(ans)

}


Measured memory_bytes: 1796
n = int(input())
a = list(map(int, input().split()))

count = 0
num = 0
absl = []

for i in a:
  if i < 0:
    count += 1

for j in range(n):
  absl.append(abs(a[j]))

num = sum(absl)

if count % 2 == 0:
  ans = num
else:
  ans = num - min(absl) * 2

print(ans)

Measured memory_bytes: 14284
#include <iostream>
#include <algorithm>
#include <string>
#include <queue>
#include <cmath>


using namespace std;
using ll = long long;

ll N;


int main() {
	cin >> N;
	vector<ll> a(N);
	for (ll i = 0; i < N; i++)
	{
		cin >> a[i];
	}
	vector<ll> history(N, 0LL);
	ll on = 0;
	ll count = 0;
	for (ll i = 0; i < N; i++)
	{
		if (history[on] == 1) {
			cout << -1 << endl;
			return 0;
		}
		history[on] = 1;
		on = a[on] - 1;
		count++;
		if (on == 1) {
			cout << count << endl;
			return 0;
		}
	}
	cout << -1 << endl;
	return 0;
}


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

using namespace std;
using ll = long long;

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

  int h, w;
  cin >> h >> w;
  vector<vector<char>> s(h, vector<char>(w));
  for (int i = 0; i < h; i++)
    for (int j = 0; j < w; j++)
      cin >> s[i][j];

  // right[i][j] := 地点(i,j)から右に照らした時照らされるマスの個数
  vector<vector<int>> right(h, vector<int>(w, -1));
  vector<vector<int>> left(h, vector<int>(w, -1));
  vector<vector<int>> up(h, vector<int>(w, -1));
  vector<vector<int>> down(h, vector<int>(w, -1));

  // 地点(i,j)から右に照らしていく
  function<int(int, int)> f1 = [&](int i, int j) {
    if (right[i][j] != -1)
      return right[i][j];
    if (s[i][j] == '#')
      return -1;
    if (j == w - 1)
      return right[i][j] = 0;
    return right[i][j] = f1(i, j + 1) + 1;
  };

  function<int(int, int)> f2 = [&](int i, int j) {
    if (left[i][j] != -1)
      return left[i][j];
    if (s[i][j] == '#')
      return -1;
    if (j == 0)
      return left[i][j] = 0;
    return left[i][j] = f2(i, j - 1) + 1;
  };

  function<int(int, int)> f3 = [&](int i, int j) {
    if (down[i][j] != -1)
      return down[i][j];
    if (s[i][j] == '#')
      return -1;
    if (i == h - 1)
      return down[i][j] = 0;
    return down[i][j] = f3(i + 1, j) + 1;
  };

  function<int(int, int)> f4 = [&](int i, int j) {
    if (up[i][j] != -1)
      return up[i][j];
    if (s[i][j] == '#')
      return -1;
    if (i == 0)
      return up[i][j] = 0;
    return up[i][j] = f4(i - 1, j) + 1;
  };

  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (s[i][j] == '#')
        continue;
      f1(i, j);
      f2(i, j);
      f3(i, j);
      f4(i, j);
    }
  }

  int ans = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (s[i][j] == '#')
        continue;
      ans = max(ans, right[i][j] + left[i][j] + up[i][j] + down[i][j] + 1);
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 70144
#include<iostream>
#include<string>
#include<typeinfo>
#include<vector>
#include<algorithm>
#include<map>
#include<iomanip>
using namespace std;
int main()
{
	int a, b;
	cin >> a >> b;
	cout << ((a%b) & 1) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <map>

int main()
{
  char s[101];
  scanf("%s", s);
  std::map<char, int> m;
  for (char* p = s; *p; ++p)
  {
    m[*p]++;
  }
  for (auto &p : m)
  {
    if (p.second & 1)
    {
      puts("No");
      return 0;
    }
  }
  puts("Yes");
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
 
int main() {
	int n,x,m[100],a=0,b;
	cin >> n >> x;
	
	for (int i=0;i<n;i++) {
		cin >> m[i];
		a+=m[i];
	}
	sort (m,m+n);
	b= m[0];
	cout << (x-a)/b+n << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
using namespace std;
int main()
{
    char a[52][52];
    int i,j;
        for(i=0;i<52;i++)
        {
            for(j=i;j<52;j++)
            {
                 a[i][j]=a[j][i]='.';
            }
        }
    int h,w;
    while(cin>>h>>w)
    {
            for(i=1;i<=h;i++)
    {
            for(j=1;j<=w;j++)
                {cin>>a[i][j];}
    }
    int sum,m,n;
    for(i=1;i<=h;i++)
    {
        for(j=1;j<=w;j++)
        {
                if(a[i][j]!='#')
                {
                    sum=0;
                  for(m=-1;m<=1;m++)
                   {
                       for(n=-1;n<=1;n++)
                       {
                            if(a[i+m][j+n]=='#')
                               sum++;
                       }
                   }

                    a[i][j]='0'+sum;
                }
        }
    }
    cout<<endl;
    for(i=1;i<=h;i++)
    {
        for(j=1;j<=w;j++)
                cout<<a[i][j];
        cout<<endl;
    }
    }
}


Measured memory_bytes: 256
s = int(input())
n = s // 3
cnt = [0] * n

import math
def comb(x, y):
    return math.factorial(x) // (math.factorial(x - y) * math.factorial(y))

for i in range(1, n + 1):
    rem = s - 3 * i
    cnt[i - 1] = comb(rem + (i - 1), i - 1)

print(sum(cnt) % (10**9 + 7))

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

stim = [0]
ans = float('inf')
for i in a:
    stim.append(stim[-1]+i)
for i in stim[1:len(stim)-1]:
    ans = min(ans,abs(stim[-1]-2*i))
print(ans)


Measured memory_bytes: 24832
import std.algorithm, std.conv, std.range, std.stdio, std.string;

void readV(T...)(ref T t){auto r=readln.splitter;foreach(ref v;t){v=r.front.to!(typeof(v));r.popFront;}}
void readA(T)(size_t n,ref T t){t=new T(n);auto r=readln.splitter;foreach(ref v;t){v=r.front.to!(ElementType!T);r.popFront;}}
void readM(T...)(size_t n,ref T t){foreach(ref v;t)v=new typeof(v)(n);foreach(i;0..n){auto r=readln.splitter;foreach(ref v;t){v[i]=r.front.to!(ElementType!(typeof(v)));r.popFront;}}}
void readS(T)(size_t n,ref T t){t=new T(n);foreach(ref v;t){auto r=readln.splitter;foreach(ref j;v.tupleof){j=r.front.to!(typeof(j));r.popFront;}}}

void main()
{
  int n; readV(n);
  writeln(n%calc(n) == 0 ? "Yes" : "No");
}

auto calc(int n)
{
  int r = 0;
  for (; n > 0; n /= 10) r += n%10;
  return r;
}


Measured memory_bytes: 256
# import sys
import math #sqrt,gcd,pi
# import decimal
# import queue # queue
# import bisect
# import heapq # priolity-queue
# import time
# from itertools import product,permutations,\
#     combinations,combinations_with_replacement
# 重複あり順列、順列、組み合わせ、重複あり組み合わせ
# import collections # deque
# from operator import itemgetter,mul
# from fractions import Fraction
# from functools import reduce

mod = int(1e9+7)
# mod = 998244353
INF = 1<<29
lINF = 1<<35

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

def main():
    n = int(input())
    a = readInt()
    a.sort()
    if a[0]==0:
        print(0)
        return
    ans = a[0]
    for i in range(1,n):
        ans *= a[i]
        if ans>int(1e18):
            print(-1)
            return
    print(ans)
    return

if __name__=='__main__':
    main()


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

//{
#pragma GCC optimize ("O3","unroll-loops")
#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

//{
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 n,m,k;
string s;

int a[12345678];

int f(int x){
	if(x%2==1){
		return x*3+1;
	}else{
		return x/2;
	}
}

main(){
	int n,ans=1;
	cin>>n;
	a[n]++;
	while(1){
		ans++;
		n=f(n);
		a[n]++;
		if(a[n]==2){
			dans;
			return 0;
		}
	}
}


Measured memory_bytes: 256
/*siddharth goyal*/
#include<bits/stdc++.h>
using namespace std;
#define   pb              push_back
#define   REP(i,n)        for(i=1;i<=n;i++)
#define   FOR(i,a,b)      for(i=a;i<=b;i++)
#define   all(v)          v.begin(),v.end()
#define   F               first
#define   S               second
#define   vl              vector<LL>
#define   itr             ::iterator it
#define   lb              lower_bound
#define   ub              upper_bound
#define   LL              long long
#define   ULL             unsigned long long
int i,j ;
map <LL,char> M;
int main()
{
	LL n,m ; 
    cin>>n>>m ; 
    string s,t ;
    cin>>s>>t ; 
    LL lcm = (n*m)/__gcd(n,m) ;
    if(s[0]!=t[0]) return cout<<-1,0 ;
    LL pos = 1,x = lcm/n ;   
    for(i=0;s[i];i++) 
    {  M[pos] = s[i] ;
       pos = x * (i+1) + 1 ; 
    }
    x = lcm/m,pos = 1 ; 
    for(i=0;t[i];i++)
    {  if(M.find(pos)!=M.end())
       {  if(M[pos]!=t[i])
            return cout<<-1,0 ; 
       }
       else  M[pos] = t[i] ; 
       pos = x * (i+1) + 1 ; 
    }	
    cout<<lcm ; 
} 


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

inline long log10(long A)
{
    long result = 0;
    while(A != 0) {
        A /= 10;
        ++result;
    }
    return result;
}

inline long F(long A, long B)
{
    auto a = log10(A);
    auto b = log10(B);
    return std::max(a, b);
}

int main()
{
    long N;
    std::cin >> N;

    long result = 100;
    for (long A = 1, mx = (long)std::sqrt(N); A <= mx; ++A)
    {
        if (N % A != 0)
        {
            continue;
        }
        long B = N / A;
        result = std::min(result, F(A, B));
    }
    std::cout << result;

    return 0;
}

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

int main()
{
    int H1, M1, H2, M2, K;
    cin >> H1 >> M1 >> H2 >> M2 >> K;

    int start = 60 * H1 + M1;
    int end = 60 * H2 + M2;

    cout << end - start - K << endl;
}


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

int main() {
int n,m;
cin >> n >> m;
vector<int> a(n,0);

rep(i,m){
  int x,y;
  cin >> x >> y;
  a.at(x-1)++;
  a.at(y-1)++;
}
rep(i,n) cout << a.at(i) << endl;
  }


Measured memory_bytes: 3600
while True:
  n, x = map(int, input().split())
  if n == 0 and x == 0:
    break
  ans = 0
  for i in range(1, n+1):
    for j in range(i+1, n+1):
      for k in range(j+1, n+1):
        if i + j + k == x:
          ans += 1
  print(ans)


Measured memory_bytes: 5596
#include <bits/stdc++.h>
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--) // [a, b)
#define reprev(i,n) reprrev(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
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; }

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n==0) return 1;
    ll res=modpow(x, n/2);
    if(n%2==0) return res*res%mod;
    else return res*res%mod*x%mod;
}

ll power(ll x, ll n){
    if(n == 0) return 1;

    ll res = power(x, n/2);
    if(n%2 == 0) return res*res;
    else return res*res*x;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };

// 線分 ab の偏角 返り値は[-π, π]
double argument(const pair<double, double> &a, const pair<double, double> &b){
    double ax=a.first, ay=a.second, bx=b.first, by=b.second;
    return atan2(by-ay, bx-ax);
}

/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */

ll N, K;
vector<ll> a, f;

bool check(ll s){
    if(s==-1) return false;
    ll cost = 0;
    rep(i, N){
        if(a[i]*f[i] > s){
            cost += (a[i]*f[i]-s + f[i]-1) / f[i];
        }
    }

    if(cost <= K) return true;
    else return false;
}

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

    cin >> N >> K;
    a.resize(N), f.resize(N);
    rep(i, N) cin >> a[i];
    rep(i, N) cin >> f[i];

    sort(a.rbegin(), a.rend());
    sort(f.begin(), f.end());  

    
    ll ok = 1e13, ng = -1;
    while(ok-ng > 1){
        ll mid = (ok + ng) / 2;
        (check(mid)? ok:ng) = mid;
    }
    cout << ok << endl;

    return 0;
}

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

int kakuketanowa (int x) {
  int t=0;
  while (x>0) {
    t+=x%10;
    x/=10;
  }
  return t;
}
int main() {
  int N;
  cin>>N;
  
  int s =100;
  for (int i=1;i<=N/2;i++) {
    int p = kakuketanowa (i);
    int q = kakuketanowa (N-i);
    if (s>p+q) {
      s=p+q;
    }
  }
cout << s << endl;    
}

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

/* Field */
using namespace std;

/* Function */
int main (void) 
{

  string S;  // input
  
  int i;
  int count; // 'o'と書かれている個数
  int ans;


  cin >> S;


  count = 0;

  // 3回ループくらいならwhile不要(?)
  if( S.at(0) == 'o' )
  {
    count++;
  }

  if( S.at(1) == 'o' )
  {
    count++;
  }

  if( S.at(2) == 'o' )
  {
    count++;
  }

  // i = 0;
  // while( i < 3 )
  // {

  //   if( place.at(i) == '1' )
  //   {
  //     count++;
  //   }

  //   i++;

  // }


  ans = 700 + 100 * count;

  cout << ans << endl;


  return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define INF 100000000
#define rep(i,a,b) for(int (i)=a;(i)<(int)(b);(i)++)


int main(){
    string S;
    cin >> S;
    if(S[3]==S[2]&&S[5]==S[4]){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int N_MAX = 200000;
int main()
{
  int n,m,a,b,i,j=0;
  int c[N_MAX];
  cin >> n >> m;
  for(i=0;i<m;i++){
    cin >> a >> b;
    if(a==1){
      c[j]=b;
      j++;
    }
    if(b==n){
      c[j]=a;
      j++;
    }
  }
  sort(c,c+j);
  for(i=1;i<j;i++)
    if(c[i]==c[i-1]){
      cout << "POSSIBLE" << endl;
      return 0;
    }
  cout << "IMPOSSIBLE" << endl;
  return 0;
}

Measured memory_bytes: 4336
#include <iostream>
using namespace std;
int main() {
    int h, w, k;
    cin >> h >> w >> k;
    long long r = 0;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            char c;
            cin >> c;
            if (c == '#') {
                int k = i * w + j;
                r |= (1LL << k);
            }
        }
    }
    int c = 0;
    for (int b = 0; b < (1 << (h + w)); b++) {
        int t = 0;
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                if ((b & (1 << i)) && (b & (1 << (h + j))) && (r & (1LL << (i * w + j)))) {
                    t++;
                }
            }
        }
        if (t == k) {
            c++;
        }
    }
    cout << c << endl;
}


Measured memory_bytes: 3672
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
#define int long long
#pragma GCC optimize("O3,Ofast,no-stack-protector,unroll-loops,fast-math")
const int maxn=2e3+7;
const int mod=1e9+7;
/*Almost copy pasted part :)*/

int32_t main(){
    int n,a,b;
    cin>>n>>a>>b;
    cout<<a*(n/(a+b))+min(n%(a+b),a)<<endl;
}

Measured memory_bytes: 256
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n,m=sorted(nm())

if n==1 and m==1:
  print(1)
elif n==1:
  print(m-2)
else:
  print((n-2)*(m-2))

Measured memory_bytes: 9184
#include <stdio.h>
#include <stdlib.h>

void insertionSort(int *A, int n, int g, int *cnt) {
    int i, j, v;

    for (i=g;i<n;i++) {
        v = A[i];
        j = i - g;
        while (j>=0 && A[j]>v) {
            A[j+g] = A[j];
            j = j - g;
            (*cnt)++;
        }
        A[j+g] = v;
    }
}


int main(void) {
    int i, n, *A;
    int j, G[100], h=1, cnt=0;

    scanf("%d", &n);
    A=(int *)malloc(sizeof(int)*n);
    for (i=0; i<n; i++) scanf("%d", &A[i]);
    
    // shellSort
    j=0;
    while (h<=n) {
        G[j]=h;
        j++;
        h=3*h+1;
    }

    for (i=j-1;i>=0;i--) insertionSort(A, n, G[i], &cnt);
    
    printf("%d\n", j);
    for (i=j-1;i>=0;i--) {
        printf("%d", G[i]);
        if (i>0) printf(" ");
    }
    printf("\n%d\n", cnt);
    for (i=0;i<n;i++) printf("%d\n", A[i]);

    return 0;
}



Measured memory_bytes: 5628