akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define REP(i,n) for (ll i = 0; i < n; ++i)
#define REPR(i,n) for (ll i = n-1; i >= 0; --i)
#define FOR(i,m,n) for (ll i = m; i < n; ++i)
#define FORR(i,m,n) for (ll i = n-1; i >= m; --i)
#define FORE(x,xs) for (const auto& x : xs)
#define ALL(v) v.begin(), v.end()

const int MAX = 20;
const ll NG = 1e18;

int N;
int A[MAX], B[MAX];


struct BIT {
    vector<ll> data;
    int N;

    BIT(int n) {
        N = n;
        data = vector<ll>(N+1);
    }

    void add(int i, ll x) {
        for (int k = i; k <= N; k += k&-k) data[k] += x;
    }

    ll sum(int i) {
        ll res = 0;
        for (int k = i; k > 0; k -= k&-k) res += data[k];
        return res;
    }
};

ll inversion(vi a) {

    REP (i, N) a[i] += 1;
    BIT bit(N);

    ll res = 0;
    for (int i = 0; i < N; i++) {
        res += i-bit.sum(a[i]-1);
        bit.add(a[i], 1);
    }

    return res;
}

inline int get_bit(ll flag, int n) {
    return (flag >> n) & 1;
}

ll sub(ll flag) { // flagの0のビットが赤、1のビットが青
    if (__builtin_popcount(flag) & 1) return NG; // 青のカードは偶数個
    vii nums(N);
    REP (i, N) {
        if (get_bit(flag, i)) nums[i] = make_pair(B[i], i);
        else nums[i] = make_pair(A[i], i);
    }
    sort(ALL(nums));

    vi target; // flagのようにひっくり返って、かつ最小回数でソートしたときの状態
    REP (left, N) {
        int right = left;
        set<ll> odd, even; // nums[left].firstと同じ値のカードの位置の集合の偶奇
        while (right < N && nums[right].first == nums[left].first) {
            // 0枚目が赤ならevenになる
            if ((nums[right].second & 1) ^ (get_bit(flag, nums[right].second) & 1)) {
                odd.insert(nums[right].second);
            } else {
                even.insert(nums[right].second);
            }
            right++;
        }

        if (left & 1) swap(odd, even); // 処理の簡単にするために常にevenから値を取り出すことにする
        if (even.size() < odd.size() || even.size() - odd.size() > 1)
            return NG; // evenがodd以上で、evenとoddの差はたかだか1

        vi even_vec(ALL(even)), odd_vec(ALL(odd));
        REP (i, even.size() + odd.size()) target.push_back((i&1) ? odd_vec[i>>1] : even_vec[i>>1]); // 交互に追加

        left = right - 1;
    }

    return inversion(target);
}

ll solve() {
    ll ans = NG;
    REP (i, 1ll << N) ans = min(ans, sub(i));
    if (ans == NG) return -1;
    return ans;
}

int main() {
    cin >> N;
    REP (i, N) cin >> A[i];
    REP (i, N) cin >> B[i];
    cout << solve() << endl;
}

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

#define sz(x) (int)(x.size())
#define FOR(x,y,z) for(int x = y; x <= z; x++)
#define int long long

const int N = 1e5 + 2, inf = 1e18;
const int MOD = 1e9 + 7;

int SZ;
set<int> g[102];

int add(int a, int b)
{
    int res = a + b;
    if(res >= MOD)
        return res - MOD;
    return res;
}

int mult(int a, int b)
{
    long long res = a;
    res *= b;
    if(res >= MOD)
        return res % MOD;
    return res;
}

struct matrix
{
    int arr[102][102];

    void reset()
    {
        memset(arr, 0, sizeof(arr));
    }

    void makeiden()
    {
        reset();
        for(int i=0;i<SZ;i++)
        {
            arr[i][i] = 1;
        }
    }

    matrix operator + (const matrix &o) const 
    {
        matrix res;
        for(int i=0;i<SZ;i++)
        {
            for(int j=0;j<SZ;j++)
            {
                res.arr[i][j] = add(arr[i][j], o.arr[i][j]);
            }
        }
        return res;
    }

    matrix operator * (const matrix &o) const 
    {
        matrix res;
        for(int i=0;i<SZ;i++)
        {
            for(int j=0;j<SZ;j++)
            {
                res.arr[i][j] = 0;
                for(int k=0;k<SZ;k++)
                {
                    res.arr[i][j] = add(res.arr[i][j] , mult(arr[i][k] , o.arr[k][j]));
                }
            }
        }
        return res;
    }
};

matrix power(matrix a, int b)
{
    matrix res;
    res.makeiden();
    while(b)
    {
        if(b & 1)
        {
            res = res * a;
        }
        a = a * a;
        b >>= 1;
    }
    return res;
}

int32_t main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);  

    int n, k;
    cin >> n >> k;
    SZ = n;

    //Remember : nodes are kept 0-indexed
    FOR(i,0,n-1) FOR(j,0,n-1) {
        int yes;
        cin >> yes;
        if(yes) {
            g[i].insert(j);
        }
    }

    matrix M;
    FOR(start,0,n-1) {
        FOR(to,0,n-1) {
            if(g[start].count(to) > 0) 
                M.arr[start][to] = 1;
            else
                M.arr[start][to] = 0;
        }
    }

    M = power(M, k);
    int ans = 0;
    FOR(start,0,n-1) FOR(to,0,n-1) {
        ans = (ans + M.arr[start][to]) % MOD;
    }
    cout << ans << '\n';
}


Measured memory_bytes: 4000
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,i;
    cin >> n;
    vector< string > s(n);
    for (int i = 0; i < n; i++) {
        cin >> s[i];
        sort(s[i].begin(), s[i].end());
    }
    sort(s.begin(), s.end());
    long long ans = 0;
    for(i=0;i<n;++i)
    {
    	long long temp=0;
    	while(i<n-1 && s[i]==s[i+1])
    	{
    		temp++;
    		i++;
    	}
    	ans+=(temp*(temp+1)/2);
    }
    cout << ans;
    return 0;
}

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

int main(){
  int x;
  cin>>x;
  
  for(int i=-119;i<119;i++){
    for(int j=-119;j<119;j++){
      if(x==i*i*i*i*i-j*j*j*j*j){
        cout<<i<<endl;
        cout<<j<<endl;
        return 0;
      }
    }
  }
}


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

x =1

if min(a) ==0:
    ans =0
else:
    order =0
    for i in a:
        order = order+len(str(i))-1

    if order >18:
        ans = -1
    else:
        ans =1
        for i in a:
                ans = ans*i
        if ans >10**18:
            ans=-1
print (ans)

Measured memory_bytes: 84736
#include<stdio.h>

int main(){

	int a,b,c,count,i;
	
	scanf("%d %d %d\n",&a,&b,&c);
	
	for(i=1; i<=c; i++){
		if(c%i==0){
			if(i>=a && b>=i)
				count++;
		}
	}
	printf("%d\n",count);
	return 0;
}

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

//typedef
//------------------------------------------
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//main code

int main(int argc, char const* argv[])
{
	int n,p;
	cin >> n >> p;
	VL a(n);
	bool include_odds = false;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (a[i] % 2 == 1) {
			include_odds = true;
		}
	}
	if (include_odds) {
		cout << ((LL)1 << (n-1)) << endl;
	}
	else if (p == 0) {
		cout << ((LL)1 << n) << endl;
	}
	else {
		cout << 0 << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	if(c/b+(c%b?1:0)>a/d+(a%d?1:0)) printf("No");
	else printf("Yes");
	return 0;
}

Measured memory_bytes: 3768
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n,m;
ll k;
ll a[200005],b[200005];
ll sum[2][200005];

int main(void){
	scanf("%d%d%lld",&n,&m,&k);
	for(int i=0;i<n;i++){
		scanf("%lld",&a[i]);
	}
	for(int i=0;i<m;i++){
		scanf("%lld",&b[i]);
	}
	for(int i=0;i<n;i++){
		sum[0][i+1]=sum[0][i]+a[i];
	}
	for(int i=0;i<m;i++){
		sum[1][i+1]=sum[1][i]+b[i];
	}
	int ans=0;
	int r=m;
	for(int i=0;i<=n;i++){
		while(r>=0 && sum[0][i]+sum[1][r]>k){
			r--;
		}
		if(r>=0){
			ans=max(ans,i+r);
		}
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 10072
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, n) for(int i = 1; i <= (int)(n); i++)
const long long INF = 1LL << 60;
const double PI=3.14159265358979323846;
int main() 
{
    int n;
    cin >> n;

    int A[n+10][n+10]={};
    int p,k;
    rep(i,n){
        cin >> p >> k;
        int q;
            rep(j,k){
                cin >> q;
                A[p][q] = 1;
            }
    }

    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            if(j-1){
                cout << " ";
            }
            cout << A[i][j];
        }
        cout << endl;
    }
}


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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SZ(x) ((int)(x).size())
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 55;
const int mod = 1000000007;
//const int mod = 998244353;

template <class T>inline bool chmin(T &a, const T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline bool chmax(T &a, const T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline void line_out(const vector<T> vec) {
  int n = SZ(vec);
  rep(i, n) {
    cout << vec[i];
    if(i < n-1) cout << " ";
  }
  cout << endl;
  return;
}

struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

vector<vector<int>> g;
vector<ll> node;

void dfs(int now = 1, int par = 0) {
  for(auto next : g[now]) {
    if(next == par) continue;
    node[next] += node[now];
    dfs(next, now);
  }
}

int main()
{
  int n, q;
  cin >> n >> q;
  g.resize(n+1);
  node.assign(n+1, 0);
  rep(i, n-1) {
    int a, b; cin >> a >> b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  rep(i, q) {
    int p, x; cin >> p >> x;
    node[p] += x;
  }
  dfs();
  for(int i = 1; i <= n; ++i) cout << node[i] << endl;
}

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

typedef pair<int, int> pii;

int N, W, mw;
vector<pii> item;

vector<vector<vector<int> > > cc;
int dp(int idx, int n, int w) {
    if(idx == N) return n == 0? 0 : -1e9;
    int &ret = cc[idx][n][w];
    if(ret != -1) return ret;

    ret = dp(idx + 1, n, w);
    if(n && w >= item[idx].first) ret = max(ret, item[idx].second + dp(idx + 1, n - 1, w - item[idx].first));
    return ret;
}

int main() {
    scanf("%d %d", &N, &W);
    item.resize(N);
    for(int i = 0; i < N; i++) {
        int w, v; scanf("%d %d", &w, &v);
        item[i] = pii(w, v);
        if(i == 0) mw = item[0].first;
        item[i].first -= mw;
    }
    cc = vector<vector<vector<int> > >(N, vector<vector<int> >(N + 1, vector<int>(302, -1)));
    int ans = 0;
    for(int i = 1; i <= N; i++) {
        if(W < i * mw) break;
        int MW = min(W - i * mw, 3*i);
        ans = max(ans, dp(0, i, MW));
    }
    printf("%d", ans);
}


Measured memory_bytes: 12544
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#include<ext/rope>
#define int long long
using namespace std;
using namespace __gnu_cxx;
typedef long long LL;
const int MAXN = 2e5+10;
const int MOD = 1e9+7;
const int INF = 0x3f3f3f3f;
int a[MAXN];
signed main(){
	int n,k=1; scanf("%lld",&n);
	for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
	for(int i=1;i<=n;i++) if(a[i]==k) ++k;
	if(k==1) cout<<"-1"<<endl; else cout<<n-k+1<<endl;
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using ll= long long;
using vi= vector<int>;
using vvi= vector<vi>;
using vd= vector<double>;
using vvd= vector<vd>;
using vc= vector<char>;
using vb= vector<bool>;
using vl= vector<ll>;
#define rep(i,x,n) for(int i=x; i<n; i++)
#define all(x) x.begin(), x.end()

int main(){
  bool ok;
  int n,m,ans=-1,start;
  string si;
  char cc;
  cin >> n >> m;
  vi s(m);
  vi c(m);
  rep(i,0,m){
    cin >> s[i] >> c[i];
  }
  if(n==1){
    start=0;
  }else{
    start=pow(10,n-1);
  }
  
  for(int i=start; i<pow(10,n); i++){
    si= to_string(i);
    ok=true;
    rep(j,0,m){
      if(si[s[j]-1]-'0'!=c[j]) {
        ok=false;
      }
    }
    if(ok){
      ans=i;
      break;
    }
  }
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int R, G, B, N;
    cin >> R >> G >> B >> N;
 
    int i, j, k, ans = 0;
    for (i=0; ; i++){
        if (i*R == N){
            ans++;
        }        
        if (i*R >= N){
            break;
        }
 
        for (j=0; ; j++){
            if (i*R + j*G == N){
                ans++;
            }
            if (i*R + j*G >= N){
                break;
            }
 
            if ((N - (i*R + j*G))%B == 0  ){
                ans++;
            }
        }
    }
 
 
    cout << ans;
 
    return 0;
}

Measured memory_bytes: 256
class Runner
  include Comparable
  attr_reader :time, :to_s
  def initialize(num, time)
    @num = num.to_i
    @time = time.to_f
    @to_s = num.to_s + " " + time
  end
  def <=>(other)
    return @time <=> other.time
  end
end
arr1 = Array.new(8){Runner.new(*gets.split(" "))}.sort
arr2 = Array.new(8){Runner.new(*gets.split(" "))}.sort
arr3 = Array.new(8){Runner.new(*gets.split(" "))}.sort
puts arr1[0,2], arr2[0,2], arr3[0,2], (arr1[2..-1] + arr2[2..-1] + arr3[2..-1]).sort[0, 2].map(&:to_s)

Measured memory_bytes: 8620
def main():
    W,H,x,y,r=map(int,input().split())
    if x<=0 or y<=0:
        print('No')
    elif W>=2*r and H>=2*r and W>=x+r and H>=y+r:
        print('Yes')
    else:
        print('No')

if __name__=='__main__':
    main()



Measured memory_bytes: 5600
str = gets.chomp.chars
key = gets.chomp.chars
n   = str.size
m   = key.size

accept = false
for i in 0 .. n - m
  temp0 = str[n - 1 - i]
  if temp0 == '?' || temp0 == key[-1]
    check = true
    for j in 0 .. m - 1
      temp1 = str[n - i - 1 - m + 1 + j]
      if temp1 == '?' || temp1 == key[j]
        next
      else
        check = false
        break
      end
    end
    if check
      str[n - i - 1 - m + 1 .. n - 1 - i] = key[0 .. m - 1]
      accept = true
      break
    end
  end
end

if accept == true
  n.times do |i|
    if str[i] == '?'
      str[i] = 'a'
    end
  end
  puts str.join
else
  puts :UNRESTORABLE
end


Measured memory_bytes: 1788
package main

import (
	"fmt"
)

func main() {
	var a, b, c, d int64

	fmt.Scan(&a, &b, &c, &d)

	var ans int64
	if a < 0 && b < 0 && c < 0 && d < 0 {
		ans = a * c
	} else if a >= 0 && b >= 0 && c >= 0 && d >= 0 {
		ans = b * d
	} else if a < 0 && b < 0 && c >= 0 && d >= 0 {
		ans = b * c
	} else if a >= 0 && b >= 0 && c < 0 && d < 0{
		ans = a * d
	} else  {
		ans1 := a * c
		ans2 := b * d
		if ans1 > ans2 {
			ans = ans1
		}else {
			ans = ans2
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 1772
#include <iostream>
#include <vector>
#include <string>
#include <unordered_map>
#include <algorithm>
#include <cctype>

using namespace std;

const int INF = 5000;
typedef unsigned char byte;

vector<string> field;
unordered_map<char, vector<pair<int,int>>> holes_of;
int dp[55][55][55][55];
bool visited[55][55][55][55];

int calc(byte t, byte l, byte b, byte r) {
    if(visited[t][l][b][r]) return dp[t][l][b][r];
    if(t > b || l > r) return -INF;
    if(field[t][l] == '#') return -INF;
    visited[t][l][b][r] = true;
    int &res = dp[t][l][b][r];
    if(t == b && l == r) {
        res = 0;
    } else {
        res = max(res, calc(t+1, l, b, r));
        res = max(res, calc(t, l+1, b, r));
        if(islower(field[t][l])) {
            // Pick and place
            for(const auto &to : holes_of[field[t][l]]) {
                //cout << field[t][l] << ' ' << to.first << ' ' << to.second << endl;
                if(to.first == b && to.second == r) continue;
                if(to.first < t || to.second < l) continue;
                res = max(res, calc(t+1, l, to.first, to.second) + 1 + calc(to.first, to.second, b, r));
                res = max(res, calc(t, l+1, to.first, to.second) + 1 + calc(to.first, to.second, b, r));
            }
        }
    }
    if(res < 0) res = -INF;
    return res;
}

bool solve() {
    int H, W;
    if(!(cin >> H >> W)) return false;
    if(!H && !W) return false;

    field.clear();
    field.resize(H);
    holes_of.clear();
    for(int i = 0; i < H; ++i) {
        cin >> field[i];
        for(int j = 0; j < W; ++j) {
            if(isupper(field[i][j])) {
                const char c = tolower(field[i][j]);
                holes_of[c].push_back(make_pair(i, j));
            }
        }
    }
    field.push_back(string(W, '#'));
    field.back()[W-1] = '.';
    fill_n((int*)dp, sizeof(dp)/sizeof(int), -INF);
    fill_n((bool*)visited, sizeof(visited)/sizeof(bool), false);

    int res = calc(0, 0, H, W-1);
    if(res < 0) res = -1;
    cout << res << endl;
    return true;
}

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

    while(solve()) ;
    return 0;
}

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

inline int64_t ceiling_div(int64_t a, int64_t b){
  int64_t ans= ((a>=0 && b > 0) || (a<=0 && b < 0)) ? (abs(a)+abs(b)-1)/abs(b)
                                                    : -abs(a)/abs(b);
  return ans;
}

int main(){
  int N, N1, T;
  cin >> N >> N1 >> T;

  int ans= ceiling_div(N, N1)* T;
  
  cout << ans << endl;
}

Measured memory_bytes: 3632
import std.stdio;
    import std.algorithm;
    import std.range;
    import std.conv;
    import std.format;
    import std.array;
    import std.math;
    import std.string;
    import std.container;
     
    void main() {
      int N; readlnTo(N);
      if (N == 1) "Hello World".writeln;
      else {
        int A, B;
        readlnTo(A);
        readlnTo(B);
        (A + B).writeln;
      }
    }
     
    // helpers
    void readlnTo(T...)(ref T t) {
      auto s = readln.split;
      assert(s.length == t.length);
      foreach(ref ti; t) {
        ti = s[0].to!(typeof(ti));
        s = s[1..$];
      }
    }

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


/* エイリアス */
#define ll long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vpi vector<pii>
#define vpll vector<pll>
#define endl '\n'

#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define em emplace


/* 関数マクロ */
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep2(i, n, m) for (ll i = n; i <= m; ++i)
#define rep3(i, n, m) for (ll i = n; i >= m; --i)
#define all(v) v.begin(), v.end()
#define si(v) int(v.size())
#define UNIQUE(v) sort(all(v)), v.erase(unique(all(v)),v.end())


/* 定数 */
const ll mod = 1e9 + 7;
const ll infll = (1LL << 62) - 1;
const ll inf = (1LL << 30) - 1;


/* その他 */
template<class S, class T> inline bool chmax(S &a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class S, class T> inline bool chmin(S &a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> using pq = priority_queue<T>;
template<class T> using pqg = priority_queue<T, vector<T>, greater<T>>;


signed main()
{
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  int n; cin >> n;
  set<int> used;

  rep2(i, 1, n/2) {
    int j = n - i;
    if (i == j) continue;

    used.em(i);
  }

  cout << si(used) << endl;
}

Measured memory_bytes: 27008
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdlib>//abs()で整数絶対値
#include <cmath>//abs()かfabs()で少数絶対値

using namespace std;

struct amount{
    int no;
    string na;

    bool operator<( const amount& right ) const {
        return no == right.no ? na < right.na : no > right.no;
    }
};



int main(void){
    int N; cin>>N;
    vector<string> St(N);
    for(int i=0;i<N;i++){
        cin >> St[i];
    }
    sort(St.begin(),St.end());
    int count = 1;
    for(int i=1;i<N;i++){
        if(St[i]!=St[i-1]){
            count++;
        }
    }
    vector<amount> S(count);
    S[0].na = St[0];
    S[0].no = 1;
    int i = 0;
    for(int j=1;j<N;j++){
        if(St[j]!=St[j-1]){
            i++;
            S[i].na = St[j];
            S[i].no++;
        }else{
            S[i].no++;
        }
    }
    sort(S.begin(),S.end());
    cout << S[0].na << endl;
    for(int j=1;j<count;j++){
        if(S[j].no==S[j-1].no){
            cout << S[j].na << endl;
        }else break;
    }
    return 0;
}

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

int main() {
    int x,y;
    string op;
    cin >> x >> op >> y;
    while (!(op == "?")) {
        if (op == "+") cout << x+y << endl;
        if (op == "-") cout << x-y << endl;
        if (op == "/") cout << (int)((double)x/y) << endl;
        if (op == "*") cout << x*y << endl;
        cin >> x >> op >> y;
    }
    return 0;
}


Measured memory_bytes: 3132
#include<bits/stdc++.h>
using namespace std;
/**
******************* Author:Bisnu sarkar ****************************
**/
/*
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
*/
#define fRead(x)       freopen(x,"r",stdin)
#define fWrite(x)      freopen (x,"w",stdout)
#define ull            unsigned long long
#define ll             long long
#define pii            pair<int,int>
#define sit            set<int> :: iterator
#define vrit           vector<int> :: reverse iterator
#define ff             first
#define ss             second
#define endl           '\n';
#define sz(s)          (int)s.size()
#define all(s)         s.begin(),s.end()
#define IO             ios_base::sync_with_stdio(false),cin.tie(NULL);  
#define what_is(x)     cerr << #x << " is " << x << endl;
///*....Debugger....*///
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {cout << endl;}
template<typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << ", ";
  err(++it, args...);
}
///*....Input....*///
template <typename T> inline void Int(T &n) {
  n = 0; int f = 1; register int ch = getchar();
  for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;
  for (; isdigit(ch); ch = getchar()) n = (n << 3) + (n << 1) + ch - '0';
  n = n * f;
}
 
template <typename T, typename TT> inline void Int(T &n, TT &m) { Int(n); Int(m); }
template <typename T, typename TT, typename TTT> inline void Int(T &n, TT &m, TTT &l) { Int(n, m); Int(l);}
double ind(){double x; scanf("%lf",&x);return x;}

///*....Bitmask....*///
int set_1(int n,int pos){return n = (n | (1<<pos));}
int reset_0(int n,int pos){return n= n & ~(1<<pos);}
bool check_bit(int n,int pos){return n = n & (1<<pos);}

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

///*....Constraints....*///
const int N = (int) 1e6 + 5;
const int M = (int) 1e9 + 7;
const double pi=2* acos(0.0);
const double eps=1e-9;


int main()
{
    int t=1,te=0;
    //Int(t);
    while(t--){
      int x;
      Int(x);

      printf("%d\n", x^1);

        //printf("Case %d: ",++te);
    }

    //cerr << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
    return 0;
}






Measured memory_bytes: 3748
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;

void solve() {
	int k;
	string s;
	cin >> k >> s;
	for (int i = 0; i < min((int)s.size(), k); i++){
		cout << s[i];
	}
	if (k < s.size()){
		cout << "...";
	}
}

int main() {
    ios::sync_with_stdio(false); cin.tie(0);
	int T = 1; 
    //cin >> T;
    while(T--) solve();
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
int n,k,a[5005];
int main()
{
	cin>>n>>k;
	for(int i=1;i<=n;i++)cin>>a[i];
	sort(a+1,a+n+1);
	int ans=n;
	for(int i=1;i<=n;i++)
	{
		int s=k;
		for(int j=n;j>=1;j--)if(a[j]<s&&j!=i)s-=a[j];
		if(s<=a[i])ans--;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>

using namespace std;
using boost::irange;
typedef long long ll;
const ll mod = 1e9 + 7;

int main() {
    int N;
    cin >> N;
    vector<int> p(N);
    for (int i: irange(0, N)) {
        cin >> p[i];
    }

    int cnt = 0;
    for (int i: irange(0, N - 1)) {
        if (p[i] == i + 1) {
            swap(p[i], p[i + 1]);
            cnt++;
        }
    }
    if (p[N - 1] == N) {
        cnt++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<queue>
#include<string>

using namespace std;

int main()
{
	int n, q;
	cin>>n>>q;
	
	queue< pair<string, int> > ps;
	string p;
	int t;
	for( int i=0; i<n; i++ ) {
		cin>>p>>t;
		ps.push( make_pair( p, t ) );
	}
	
	int progress = 0;
	pair<string, int> tmp;
	while( !ps.empty( ) ) {
		tmp = ps.front( );
		ps.pop( );
		if( tmp.second <= q ) {
			progress += tmp.second;
			cout<<tmp.first<<' '<<progress<<'\n';
		} else {
			ps.push( make_pair( tmp.first, tmp.second - q ) );
			progress += q;
		}	 
	}

    return 0;
}

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

#define EB emplace_back
//#define int long long
#define F first
#define S second
#define N 500005
#define all(x) x.begin(),x.end()
#define endl '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)

using namespace std;

int32_t main(){
	IOS;
	int tt = 1; 
	// cin >> tt;
	while(tt--){
		int a,b; cin >> a >> b;
		scanf("%d%d", &a, &b);
      	printf("%d", a * b);
	}
	return 0;
}


Measured memory_bytes: 3852
#include<iostream>
#include<math.h>
#include<string>
using namespace std;
int main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  string ans="No";
  if(abs(a-c)<=d)ans="Yes";
  if(a<=b&&b<=c&&b-a<=d&&c-b<=d)ans="Yes";
  if(a>=b&&b>=c&&a-b<=d&&b-c<=d)ans="Yes";
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef pair<lint, int> pi;
typedef long long lint;
const int MAXN = 20005;

map<int, int> mp;
int query(int x){
	if(mp.find(x) != mp.end()) return mp[x];
	printf("%d\n", x);
	fflush(stdout);
	string s;
	cin >> s;
	if(s == "Vacant") exit(0);
	return mp[x] = (s == "Male");
}

int main(){
	int n;
	cin >> n;
	int s = 0, e = n-1;
	while(e - s >= 2){
		int m = (s+e)/2;
		if((query(m) ^ (m%2)) != (query(s) ^ (s%2))){
			e = m;
		}
		else s = m;
	}
	for(int i=s; i<=e; i++) query(i);
}


Measured memory_bytes: 852
N = int(input())
A = list(map(int, input().split()))
x = [i+1 for i in range(N)]
B = list(map(lambda a, x: a-x, A, x))
B.sort()

idx = N // 2

if N % 2:
    n = B[idx]
else:
    n = (B[idx] + B[idx-1]) / 2
b = list(map(lambda b: abs(b-n), B))
print(int(sum(b)))

Measured memory_bytes: 34116
#include <stdio.h>

int main(void) {
  long long int n,x,t;
  scanf("%lld %lld %lld",&n,&x,&t);
  if(n%x==0)
  printf("%lld\n",(n/x)*t);
  else
  printf("%lld\n",(n/x)*t+t);
  
  return 0;
}

Measured memory_bytes: 1736
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int Inf = 1000000000;
constexpr ll INF= 1e18;
constexpr ll MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<ll,int> P;

int main() {
    int N;
    cin >> N;
    vector<vector<char>> vec(N,vector<char>(N));
    for(int i = 0;i < N;i++) {
        for(int j = 0;j < N;j++) {
            cin >> vec.at(i).at(j);
        }
    }
    int ret = 0;
    for(int i = 0;i < N;i++) {
        bool ret1 = true;
        for(int j = 0;j < N;j++) {
            for(int k = 0;k < N;k++) {
                int A,B;
                if(k + i >= N) {
                    A = k + i - N;
                }
                else {
                    A = k + i;
                }
                if(j - i < 0) {
                    B = j - i + N;
                }
                else {
                    B = j - i;
                }
                if(vec.at(j).at(k) != vec.at(A).at(B)) {
                    ret1 = false;
                }
            }
        }
        bool ret2 = true;
        for(int j = 0;j < N;j++) {
            for(int k = 0;k < N;k++) {
                int A,B;
                if(k - i < 0) {
                    A = k - i + N;
                }
                else {
                    A = k - i;
                }
                if(j + i >= N) {
                    B = j + i - N;
                }
                else {
                    B = j + i;
                }
                if(vec.at(j).at(k) != vec.at(A).at(B)) {
                    ret2 = false;
                }
            }
        }
        if(i == 0 && ret1 == true) {
            ret += N;
        }
        if(i != 0 && ret1 == true) {
            ret += N - i;
        }
        if(i != 0 && ret2 == true) {
            ret += N - i;
        }
    }
    cout << ret << endl;
}

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

string s0, t;
bool t_bool = false;

int main(){
    cin >> s0 >> t;
    vector<string> s;
    for(int i = 0; i < s0.length(); i++){
        for(int k = 0; k < t.length(); k++){
            if(s0[i] == t[k] || s0[i] == '?'){
                string buf = s0;
                for(int j = 0; j < t.length(); j++){
                    if(s0[i - k + j] == '?' || s0[i - k + j] == t[j]){
                        buf[i - k + j] = t[j];
                        if(j == t.length() - 1){
                            t_bool = true;
                            s.push_back(buf);
                        }
                    }else{
                        break;
                    }
                }  
            }
        }
    }
    if(t_bool){
        sort(s.begin(), s.end());
        /*
        for(int i = 0; i < s.size(); i++){
            cout << s[i] << endl;
        }
        */
        for(int i = 0; i < s0.length(); i++){
            if(s[0][i] == '?'){
                s[0][i] = 'a';
            } 
        }
        cout << s[0] << endl;
    }else{
        cout << "UNRESTORABLE" << endl;
    }
}

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

int main() {
  int N;
  string S;
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> S;
    if (S == "Y") {
      cout << "Four" << endl;
      return 0;
    }
  }
  cout << "Three" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define forr(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define ALL(a) (a.begin()),(a.end())
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll, ll> LP;
const ll LINF = 1LL<<60;
const int INF = 1001001001;

/* --------------------------------------------------- */

int main() {
    int n;
    cin >> n;
    int odd = 0;
    rrep(i, n) {
        if(i % 2 == 1) odd++;
    }
    double ans = (double)odd / n;
    printf("%.10f\n", ans);


    return 0;
}

Measured memory_bytes: 3744
N = int(input())
W = [x for x in map(int, input().split())]
min = abs(W[0] - sum(W[1:]))

for i in range(N):
  S1 = sum(W[:i])
  S2 = sum(W[i:])
  sub = abs(S1 - S2)
  if sub < min:
    min = sub
print(min)

Measured memory_bytes: 3060
#pragma GCC optimize "-O3"
#pragma GCC target ("avx")
#define _USE_MATH_DEFINES
#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define inf (1ll<<60)
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v),greater<int>())
#define SPEED ios::sync_with_stdio(false);cin.tie(0);cout<<fixed<<setprecision(12)
signed gcd(int a, int b){return b?gcd(b,a%b):a;}
signed lcm(int a,int b){return a*b/gcd(a,b);}
//priority_queue<int, vector<int>, greater<int> > que; //昇順

using namespace std;

const int mod=1e9+7;

int ans=0;



signed main(){
    SPEED;
    int n;
    cin >> n;
    while(true)
    {
        double tmp = sqrt(n);
        if(fmod(tmp,1) == 0)
        {
            cout << n << endl;
            return 0;
        }
        --n;
    }
}


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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int a, b;
    cin >> a >> b;
    int ans = 0;
    if (a < b) swap(a, b);
    for (int i = 0; i < a; ++i) {
        ans *= 10;
        ans += b;
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
import sys


from collections import deque
sys.setrecursionlimit(1000000)


def dfs(current, prev):
    global time
    # node currentを訪問した直後の処理
    ord[current] = time
    low[current] = time
    time += 1
    color[current] = BLACK

    for next in G[current]:
        if color[next] == WHITE:
            # node currentからnode nextへ訪問する直前の処理
            parent[next] = current
            dfs(next, current)

            # node nextの探索が終了した直後の処理
            low[current] = min(low[current], low[next])
        elif next != prev:
            # edge current --> next がback-edgeの場合の処理
            low[current] = min(low[current], ord[next])


def art_points():
    global time
    time = 1
    dfs(0, -1)  # 0をrootとしてlowの計算
    np = 0
    for i in range(1, v):
        p = parent[i]
        if p == 0:
            np += 1
        elif ord[p] <= low[i]:
            ap.add(p)
    if np > 1:
        ap.add(0)


G = {}
v, n = map(int, input().split())
for i in range(0, v):
    G[i] = []
for i in range(n):
    s, t = map(int, input().split())
    G[s].append(t)
    G[t].append(s)
WHITE = 0
BLACK = 2

color = [WHITE] * (v)
parent = [0] * (v)
ord = [0] * (v)
low = [0] * (v)
parent = [0] * (v)
ap = set([])
art_points()
if ap:
    print(*sorted(ap), sep='\n')



Measured memory_bytes: 20392
#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>
#include <tuple>
#include <utility>

using namespace std;

template <typename A, typename B>
string to_string(pair<A, B> p);
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
 
string to_string(const string& s) {
  return '"' + s + '"';
}
 
string to_string(const char* s) {
  return to_string((string) s);
}
 
string to_string(bool b) {
  return (b ? "true" : "false");
}
 
string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}
 
template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}
 
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
 
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}
 
void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
 
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

typedef long long int64;
typedef pair<int, int> pii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a, b;
  cin >> a >> b;
  if (a < 10 && b < 10) {
    cout << (a * b) << '\n';
  } else {
    cout << "-1" << '\n';
  }
  return 0;
}



Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
	int a, b, c, d, p;
	int cmp[2] = {0};

	cin >> a >> b >> c >> d >> p;

	cmp[0] = a * p;
	cmp[1] = b;

	if (c < p){
		p -= c;
		cmp[1] += (p * d);
	}

	if (cmp[0] < cmp[1]){
		cout << cmp[0] << endl;
	}
	else {
		cout << cmp[1] << endl;
	}

	return 0;
}

Measured memory_bytes: 3072
// B - K個のケーキ

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

int main() {
	int K, T;
	cin >> K >> T;

	unordered_map<int, int> cnt;

	int max_a = 0;
	for (int i=0; i<T; i++) {
		int a;
		cin >> a;
		max_a = max(max_a, a);
	}

	int ans = max(0, max_a - (K - max_a) - 1);

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3544
// AOJ 1327: One-Dimensional Cellular Automaton
// 2017.10.25 bal4u@uu

#include <stdio.h>
#include <string.h>

int s[2][52];
int d[32][52][52];

int main()
{
	int n, m, a, b, c, t;
	int i, j, k, l, k1, k2;

	while (scanf("%d%d%d%d%d%d", &n, &m, &a, &b, &c, &t) && n > 0) {
		memset(d, 0, sizeof(d));
		for (i = 1; i <= n; i++) scanf("%d", &s[0][i]);
		for (i = 1; i <= n; i++) d[0][i][i+1] = a, d[0][i][i] = b, d[0][i][i-1] = c;
		for (k = 1; (1<<k) <= t; k++) for (i = 1; i <= n; i++) for (j = 1; j <= n; j++) {
			for (l = 1; l <= n; l++) d[k][i][j] += d[k-1][i][l] * d[k-1][l][j];
			d[k][i][j] %= m;
		}

		for (k1 = 0, k2 = 1, k = 0; (1<<k) <= t; k++) if (t & (1<<k)) {
			memset(s[k2], 0, sizeof(s[k2]));
			for (i = 1; i <= n; i++) for (j = 1; j <= n; j++) s[k2][j] += s[k1][i] * d[k][i][j];
			for (i = 1; i <= n; i++) s[k2][i] %= m;
			k1 = k2, k2 = !k2;
		}
		printf("%d", s[k1][1]);
		for (i = 2; i <= n; i++) printf(" %d", s[k1][i]);
		putchar('\n');
	}
	return 0;
}

Measured memory_bytes: 2028
def selectionSort(A,N):
    global cnt
    
    for i in range(N):
        minj = i
        for j in range(i,N):
            if A[j] < A[minj]:
                minj = j
        
        if i != minj:
            tmp = A[i]
            A[i] = A[minj]
            A[minj] = tmp
            cnt = cnt + 1
    return A
    
    
n = int(input())
R = list(map(int,input().split()))
cnt = 0
R = selectionSort(R,n)
print(*R)
print(cnt)


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

long long solve(int N, int P, string S)
{
	long long ans = 0;
	vector<int> r(N);
	r[N - 1] = (S[N - 1] - '0') % P;
	int d = 1;
	for (int i = N - 2; i >= 0; --i) {
		d *= 10;
		d %= P;
		r[i] = ((S[i] - '0') * d + r[i + 1]) % P;
	}

	vector<int> h(P, 0);
	for (auto x : r) {
		++h[x];
	}
	for (int i = 0; i < N; ++i) {
		if (r[i] == 0) {
			ans += h[r[i]];
			--h[r[i]];
		}
		else {
			--h[r[i]];
			ans += h[r[i]];
		}
		
	}
	return ans;
}

long long solve_2_or_5(int N, int P, string S)
{
	long long ans = 0;

	vector<int> h(10, 0);
	for (auto c : S) {
		++h[c - '0'];
	}
	for (int i = 0; i < N; ++i) {
		int x = S[i] - '0';
		if (x % P == 0) {
			for (int k = 0; k < 10; k += P) {
				ans += h[k];
			}
			--h[x];
		}
		else {
			--h[x];
			for (int k = 0; k < 10; k += P) {
				ans += h[k];
			}
		}
	}
	return ans;
}

int main()
{
	int N, P;
	string S;
	cin >> N >> P >> S;

	if (P == 2 || P == 5) {
		cout << solve_2_or_5(N, P, S) << endl;
	}
	else {
		cout << solve(N, P, S) << endl;
	}
}

Measured memory_bytes: 1540
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <cctype>
#include <cmath>
#include <map>
#include <set>
#define rep(i, m, n) for(int i = m;i < n;i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
#define ll long long
#define ull unsigned long long
#define pb(a) push_back(a)
#define popb(a) pop_back(a)
#define debug(x) cout<<#x<<": "<<x<<endl
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
#define PI 3.14159265358979
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

int main(){
  int n,a,cnt[15]={},sum1=0,sum2=0;
  bool f1=false,f2=false;
  cin>>n;
  rep(i,0,n){
    cin>>a;
    a/=400;
    cnt[a]++;
  }
  rep(i,0,8){
    if(cnt[i]!=0){
      sum1++;
      f1=true;
    }
  }
  rep(i,8,13){
    if(cnt[i]!=0){
      sum2+=cnt[i];
      f2=true;
    }
  }
  if(f1&&f2){
    cout<<sum1<<" "<<sum1+sum2<<endl;
  }else if(f2){
    cout<<1<<" "<<sum2<<endl;
  }else{
    cout<<sum1<<" "<<sum1<<endl;
  }
}


Measured memory_bytes: 256
//hinagata.cpp
/*includes*/
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <stdio.h>
#include <numeric>
#include <iomanip>
#include <limits>
/*namespace*/
using namespace std;
using ll= long long;
/*define macro*/
#define REP(i,n) for(int i=0;i<(n);i++)
#define REPi(i,a,b) for(int i=(a);i<(b);i++)
#define REPRi(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(x) (x).begin(),(x).end()

int main(){
    int N;
    cin>>N;
    vector<int> L(N);
    REP(i,N){
        cin>>L[i];
    }
    auto max=max_element(ALL(L));
    int sum=accumulate(ALL(L),0);
    if(sum-*max<=*max){
        cout<<"No"<<endl;
    }else{
        cout<<"Yes"<<endl;
    }
}

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

#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int MAX_N = 100000;
int N;
int A[MAX_N];

int main() {
  cin >> N;
  rep(i,N) cin >> A[i];

  sort(A,A+N);

  int even = 0;
  int cont = 0;
  for (int i = 0; i < N; ++i) {
    ++cont;
    if (i+1 < N && A[i] == A[i+1]) {
      int t = 0;
      int a = A[i];
      while (i < N && A[i] == a) {
        ++i; ++t;
      }
      --i;
      if (t%2 == 0) ++even;
    }
  }

  if (even%2 == 0) {
    cout << cont << endl;
  } else {
    cout << cont-1 << endl;
  }
}


Measured memory_bytes: 640
use std::io;

fn main() {
	let mut buf = String::new();
	io::stdin().read_line(&mut buf).expect("");
	let mut iter = buf.split_whitespace();
	let mut n:u64 = match iter.next().unwrap().parse() {
		Ok(n) => n,
		Err(_) => panic!(""),
	};
	let k:u64 = match iter.next().unwrap().parse() {
		Ok(n) => n,
		Err(_) => panic!(""),
	};
	let mut v: Vec<u64> = Vec::new();
	while n != 0 {
		v.push(n%k);
		n = n/k;
	}
	println!("{}", v.len());
}

Measured memory_bytes: 4352
#include<iostream>
#include<string>
//#include<cmath>
#include<array>
#include<algorithm>
//#include<deque>
#include<vector>
//#include<utility>
//#include<set>
//#include<map>
//#include<list>
//#include<bitset>

using namespace std;
using LLI = long long int;
LLI N;

//array<int, 8>dir_x = { 0,0,1,1,1,-1,-1,-1 };
//array<int, 8>dir_y = { 1,-1,1,0,-1,1,0,-1 };
//array<int, 4>dir_x2 = { 0,0,1,-1 };
//array<int, 4>dir_y2 = { 1,-1,0,0 };
//char alp[] = { 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z' };

//class UnionFind {
//public:
//	vector<int>data;
//	UnionFind(int size) :data(size, -1) {};
//	bool unionset(int x, int y) {
//		x = root(x), y = root(y);
//		if (x != y) {
//			if (data[y] < data[x]) {
//				swap(x, y);
//			}
//			data[x] += data[y];
//			data[y] = x;
//		}
//		return x != y;
//	}
//	bool findset(int x, int y) {
//		return root(x) == root(y);
//	}
//	int root(int x) {
//		return data[x] < 0 ? x : data[x] = root(data[x]);
//	}
//	int size(int x) {
//		return -data[root(x)];
//	}
//};

//LLI gcd(LLI x, LLI y) {
//	LLI  r;
//	if (x < y) {
//		swap(x, y);
//	}
//	r = x % y;
//	while (r != 0) {
//		x = y;
//		y = r;
//		r = x % y;
//	}
//	return y;
//}
//LLI lcm(LLI x, LLI y) {
//	return x / gcd(x, y) * y;
//}

//long nCr(int n, int r) {
//	long ans = 1;
//	for (int i = n; i > n - r; i--) {
//		ans = ans * i;
//	}
//	for (int i = 1; i < r + 1; i++) {
//		ans = ans / i;
//	}
//	return ans;
//}

//const int n_max = 8;
//array<array<bool, n_max>, n_max>graph;
//int dfs(int v,int N,array<bool,n_max>visited) {
//	int ret = 0;
//	bool all_visited = true;
//	for (int i = 0; i < N;i++) {
//		if (visited[i] == false) {
//			all_visited = false;
//		}
//	}	
//	if (all_visited) {
//		return 1;
//	}
//	for (int i = 0; i < N;i++) {
//		if (graph[v][i] == false) {
//			continue;
//		}
//		if (visited[i] == true) {
//			continue;
//		}
//		visited[i] = true;
//		ret += dfs(i,N,visited);
//		visited[i] = false;
//	}
//	return ret;
//}

//vector<vector<int>>sub;
//int dfs(int id) {
//	if (sub[id].size() == 0) {
//		return 1;
//	}
//	int minP = (int)1e9;
//	int maxP = 0;
//	for (int i : sub[id]) {
//		int P = dfs(i);
//		minP = min(minP, P);
//		maxP = max(maxP, P);
//	}
//	return minP + maxP + 1;
//}

//#define debug(x) cerr << #x << " : " << x << endl
//#define debugv(x) cerr << #x << " : "; for(auto i:x) cerr << i << ", "; cerr<<endl

int main(void) {
	LLI A, B, C;
	vector<LLI>vec(4);
	cin >> A;
	for (int i = 0; i < 4; i++) {
		vec[i] = A % 10;
		A /= 10;
	}
	B = vec[0] + vec[1] * 10;
	C = vec[2] + vec[3] * 10;
	if (B <= 12 && C <= 12 && B >= 1 && C >= 1) {
		cout << "AMBIGUOUS" << endl;
	}
	else if (B <= 12 && B >= 1) {
		cout << "YYMM" << endl;
	}
	else if (C <= 12 && C >= 1) {
		cout << "MMYY" << endl;
	}
	else {
		cout << "NA" << endl;
	}
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,arr[100009],sum;
int main()
{
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    for(int i=0;i<n;i++)
    {
        for(int j=i+1;j<n;j++)
        {
            int A=arr[i]*arr[j];
            sum+=A;
        }
    }
    cout<<sum;
}

Measured memory_bytes: 256
N, A, B = [int(i) for i in input().split()]

def sum_n(n):
    sum = 0
    while n > 0:
        sum += n % 10
        n //= 10
    return sum

ans = 0
for i in range(1, N+1):
    sum = sum_n(i)
    if sum >= A and sum <= B:
        ans += i

print(ans)

Measured memory_bytes: 3060