akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<string>
#include<iostream>
#include<algorithm>
using namespace std;
int n;
int a[105];

int main()
{
	scanf("%d", &n);
	for(int i = 1; i <= n; i++) {
		scanf("%d", &a[i]);
	}
	int ans = 0;
	for(int i = 2; i <= n; i++) {
		if(a[i] == a[i - 1]) {
			a[i] = 0;
			ans++;
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>
#include<set>

#define DIV 1000000007
using namespace std;
using ll = long long;
using ldb = long double;

typedef struct {
    vector<int> edge;
    int deg = 0;
    bool vi = 0;
    int tpr = 0;
    int par = 0;
}node_t;
vector<node_t> node;

int main() {
    int N, M;
    cin >> N >> M;

    node = vector<node_t>(N + 1);
    for (int i = 0; i < N - 1 + M; i++) {
        int a, b;
        cin >> a >> b;
        node[a].edge.push_back(b);
        node[b].deg++;
    }
    
   
    queue<int> q;
    for (int i = 1; i <= N; i++) {
        if (node[i].deg == 0) {
            q.push(i);
            node[i].vi = true;
            node[i].tpr = 1;
            break;
        }
    }

    int cnt = 2;
    while (!q.empty()) {
        int x = q.front();
        q.pop();
        for (auto to : node[x].edge) {
            //if (node[to].vi) continue;
            //node[to].vi = true;
            node[to].tpr = cnt;
            cnt++;
            node[to].deg--;
            if (node[to].deg == 0) {
                q.push(to);
                node[to].par = x;
            }
        }
    }

    for (int i = 1; i <= N; i++) {
        cout << node[i].par << endl;
    }

}


Measured memory_bytes: 7808
// https://kimiyuki.net/writeup/algo/etc/icpc-2016-domestic-d/
// http://tsutaj.hatenablog.com/entry/2017/03/07/173127
#include <bits/stdc++.h>
using namespace std;

int w[300];
bool isOK[301][301];    // isOK[l][r] := [l, r)が連続して取り出し可能かどうか
int DP[301][301];       // DP[l][r] := [l, r)取り出し可能なブロック数

bool isConnected(int i, int j) {
    return abs(w[i] - w[j]) <= 1;
}

bool solve()
{
    int n;
    cin >> n;
    if(n == 0) return false;
    for(int i = 0; i < n; ++i) cin >> w[i];
    memset(isOK, 0, sizeof(isOK));
    memset(DP, 0, sizeof(DP));
    for(int i = 0; i < n; ++i) {
        isOK[i][i] = true;
    }
    for(int len = 2; len <= n; ++len) {
        for(int i = 0; i + len <= n; ++i) {
            // [i, i + len) が取り出し可能か調べる

            // [i + 1, i + len - 1) が取り出し可能で、i番目と(i+len-1)番目のブロックの差が1以下なら
            // [i, i + len) は取り出し可能
            if(isOK[i+1][i + len - 1] && isConnected(i, i + len - 1)) {
                isOK[i][i+len] = true;
                continue;
            }

            // [i, i+k) と [i+k, i+len)が取り出し可能なら[i, i+len)も取り出し可能
            for(int k = 0; k <= len; ++k) {
                if(isOK[i][i+k] && isOK[i+k][i+len]) {
                    isOK[i][i+len] = true;
                    break;
                }
            }
        }
    }
    
    // 区間DPで「区間どうしがおなじ頂点（ブロック）を被覆しないようにいくつか区間を選ぶときの、
    // 被覆できる頂点（ブロック）の最大値」を求める
    for(int left = 0; left < n; ++left) {
        for(int right = left; right <= n; ++right) {
            if(isOK[left][right]) DP[left][right] = right - left;
        }
    }

    for(int len = 0; len <= n; ++len) {
        for(int left = 0; left <= n; ++left) {
            int right = left + len;
            if(n < right) break;
            for(int k = left; k <= right; ++k) {
                DP[left][right] = max(DP[left][right], DP[left][k] + DP[k][right]);
            }
        }
    }
    // 以下の遷移の仕方でもACになった。なんでかはわからない、、、
    /*
    for(int left = 0; left <= n; ++left) {
        for(int right = left; right <= n; ++right) {
            for(int k = left; k <= right; ++k) {
                DP[left][right] = max(DP[left][right], DP[left][k] + DP[k][right]);
            }
        }
    }
    */
    // 上の遷移でACになったので、実際に参照する値はleft == 0の時のみなので、上の遷移の無駄を省いたところ、これもACになった。
    /*
    for(int right = 0; right <= n; ++right) {
        for(int k = 0; k <= right; ++k) {
            DP[0][right] = max(DP[0][right], DP[0][k] + DP[k][right]);
        }
    }
    */
    cout << DP[0][n] << endl;
    return true;
}

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


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

int main(){
  int n,k,r,s,p;
  int ans=0;
  string t;
  
  cin >> n >> k >> r >> s >> p;
  cin >> t;
  
  for(int i=0;i<n;i++){
    if(i<k){
      if(t[i]=='r')ans+=p;
      else if(t[i]=='s')ans+=r;
      else ans+=s;
    }else{
      //前と同じだったら
      if(t[i]==t[i-k])t[i]='x';
      else{
        if(t[i]=='r')ans+=p;
        else if(t[i]=='s')ans+=r;
        else ans+=s;
      }
    }
  }
  cout << ans;
  return 0;
}
  

Measured memory_bytes: 512
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
const double EPS = 1e-10;
using namespace std;
class Edge{
public:
    int from,to,value;
    Edge(LL a,LL b,LL c){
        from = a;
        to = b;
        value = c;
    }
    Edge(LL a,LL b){
        from = a;
        to = b;
    }
};



int main(){
    int n;cin >> n;
    int A = 0, Un = 0;
    int re = 0;
    for(int i = 0;i < n;i++){
        string s;cin >> s;
        if(s == "A"){
            re++;
        }else{
            re--;
        }
        if(re < 0){
            cout<<"NO"<<endl;
            return 0;
        }
    }
    if(re == 0){
        cout<<"YES"<<endl;
    }else{
        cout<<"NO"<<endl;
    }
}



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

 
int main()
{
  int h, w, m;
  cin >> h >> w >> m;
  vector<int> bh(h);
  vector<int> bw(w);
  
  set<P> b;
  
  rep(k,m){
    int i, j;
    cin >> i >> j;
    --i, --j;
    ++bh[i], ++bw[j];
    b.emplace(i,j);
  }
  
  int max_w = 0;
  int max_h = 0;
  
  rep(i,h) max_h = max(max_h,bh[i]);
  rep(i,w) max_w = max(max_w,bw[i]);
  
  vector<int> mh;
  vector<int> mw;
  
  rep(i,h){
    if(max_h == bh[i]) mh.emplace_back(i);
  }
  rep(i,w){
    if(max_w == bw[i]) mw.emplace_back(i);
  }
  
  int ans = max_w + max_h;

  rep(i,mh.size()){
    P mp;
    mp.first = mh[i];
    
    rep(j,mw.size()){
      mp.second = mw[j];

      if(b.count(mp)) continue;
      cout << ans << endl;
      return 0;
    }
  }
  
  cout << ans-1 << endl;

  return 0;
}

Measured memory_bytes: 23848
#include<iostream>
using namespace std;
int main()
{
	int n,s=0;
	bool t=true;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++)
		cin>>a[i];
	for(;;)
	{
		for(int i=0;i<n;i++)
		{
			if(a[i]%2==0)
				a[i]=a[i]/2;
			else
			{
				t=false;
				break;
			}
		}
		if(t==true)
			s++;
		else
			break;
	}
	cout<<s<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define nt _int128
#define mod 1000000007
ll n;
ll arr[105];
ll dp[100005][105];
ll func(ll k)
{
    for(ll i=0;i<=n;i++)
        dp[0][i]=1;
    for(ll i=0;i<=k;i++)
        dp[i][0]=1;
    for(ll i=1;i<=k;i++)
    {
        for(ll j=1;j<=n;j++)
        {
            if(arr[j]>=i)
            {
                dp[i][j]=(dp[i][j-1]+dp[i-1][j])%mod;
            }
            else
            {
                ll z=dp[i][j-1]-dp[i-arr[j]-1][j-1];
                dp[i][j]=(z+dp[i-1][j])%mod;
            }
        }
    }
  
    return (dp[k][n]-dp[k-1][n]+mod)%mod;
}
int main()
{
// #ifndef ONLINE_JUDGE
//        freopen("input.txt","r",stdin);
//     freopen("output.txt","w",stdout);
// #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t;
    // cin >> t;
    t  = 1;
    while(t--)
    {
        ll k;
        cin>>n>>k;
        for(ll i=1;i<=n;i++)
            cin>>arr[i];
        memset(dp,0,sizeof(dp));
        if(k==0)
            cout<<1;
        else
        cout<<func(k);
    }
    return 0;
}

Measured memory_bytes: 82304
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
//    ll n,i,j,s=0,k,d;
//    cin>>n;
//        j=(n/2)+1;
//    for(i=n;;i--)
//    {
//        s+=(i%j);
//        cout<<i%j<<endl;
//        j++;
//        if(j==n+1)
//            break;
//    }
//    j=(n/2)+1;
//    k=j;
//    for(i=1;i<j;i++)
//    {
//        s+=(i%k);
//        cout<<i%k<<endl;
//        k++;
//        if(k==j)
//            break;
//    }
//    cout<<s<<endl;
    ll n,i,m,x=0,y=0;
    vector<ll>a;
    cin>>n;
    for(i=0; i<n; i++)
    {
        cin>>m;
        a.push_back(m);
    }
    sort(a.begin(),a.end());
    for(i=n-1; i>=0; i-=2)
    {
        x+=a[i];
    }
    for(i=n-2; i>=0; i-=2)
    {
        y+=a[i];
    }
    cout<<x-y<<endl;

}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES // for C++  
#include <cmath> 
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <array>
#include <iterator>
#include <utility>
#include <set>
#include <random>
#include <map>
#include <stack>
#include <queue>
#include <list>
#include <functional>
#include <bitset>
#define LL long long
#define NUM 1000000007

using namespace std;

long long kaijyo(int num)
{
    long long ans = 1;
    for (size_t i = 1; i <= num; i++)
    {
        ans *= i;
        ans %= NUM;
    }
    return ans;
}

int main() {
    int n, m;
    LL ans;
    cin >> n >> m;
    if (abs(n - m) > 1)
    {
        cout << 0 << endl;
        return 0;
    }
    if (n == m)
    {
        ans = 2 * kaijyo(n) * kaijyo(m);
    }
    else
    {
        ans = kaijyo(n) * kaijyo(m);
    }

    cout << ans % NUM << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll inf = 10000000010000000;
const ll mod = 1000000007;
ll dp[22][(1LL << 21) + 100];
ll grid[22][22];
ll n;

ll go(ll idx, ll mask){
    //cerr << idx << " " << mask << endl;
    if(idx == n){
        return (mask == ((1LL << n)-1));
    }
    ll &ret = dp[idx][mask];

    if(ret != -1)   return ret;
    ret = 0;
    for(int k = 0; k < n; k++){
        if((mask & (1LL << k)) == 0 && grid[idx][k] == 1){
            ret = ret + go(idx+1,mask | (1LL << k));
            ret = ret % mod;
        }
    }
    return ret;
}

int main(){
    memset(dp,-1,sizeof dp);

    scanf("%lld",&n);

    for(ll i = 0; i < n; i++){
        for(ll j = 0; j < n; j++){
            scanf("%lld",&grid[i][j]);
        }
    }
    ll ans = go(0,0);
    printf("%lld\n",ans);
}


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

int main(){
  int N;
  cin >> N;
  
  for(int i=1; i<11; i++){
    if(i==10){
      cout << "No" << endl;
      break;
    }
    else if(N%i==0 && N/i<10){
      cout <<"Yes" << endl;
      break;
    }
  }  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
string S; cin >> S;
long i, c=0, t=10, ans=0, N=S.size(); vector<long> R(N); 
R[N-1]=S[N-1]-'0';
for(i=N-2; i>=0; i--){ 
  R[i]=(t*(S[i]-'0')+R[i+1])%2019; t=(10*t)%2019;
  if(R[i]==0){ ans++; }
}
sort(R.begin(), R.end());
for(i=0; i<N; i+=c, c=0){
while(i+c<N&&R[i]==R[i+c]){ c++; }
ans+=c*(c-1)/2;
}
cout << ans << "\n";
}

Measured memory_bytes: 5144
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define BIL ((ll)1e9)
#define MOD ((ll)1e9+7)
#define INF (1LL<<62)           //1LL<<63でオーバーフロー

int main(int argc,char* argv[]){
    int k;
    cin >> k;

    if(k%2==0 || k%5==0){
        cout << -1 << endl;
        return 0;
    }

    ll nownum;
    if(k%10==1)nownum=k*7;
    else if(k%10==3)nownum=k*9;
    else if(k%10==7)nownum=k*1;
    else if(k%10==9)nownum=k*3;

    nownum=(nownum-7)/10;

    ll count=1;
    while(nownum){
        int i=0;
        for(i;i<10;i++){
            ll num=nownum+k*i;
            if((num)%10==7){
                nownum=(num-7)/10;
                count++;
                i=-1;
                break;
            }
        }
        if(i!=-1){
            cout << -1 << endl;
            return 0;
        }
    }

    cout << count << endl;

    return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()
#define INF 1<<10

using namespace std;

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

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int N, T; cin >> N >> T;
	vector<P> ct(N);
	rep (i, N){
		int c, t; cin >> c >> t;
		ct[i].first = c;
		ct[i].second = t;
	} // end rep

	sort(ALL(ct));

	int res = INF;
	rep (i, N){
		int c = ct[i].first;
		int t = ct[i].second;
		if (t <= T){
			res = min(res, c);
		} // end if
	} // end rep

	if (res == INF){
		cout << "TLE" << endl;
	}else{
		cout << res << endl;
	} // end if
	
	return 0;
}

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

using namespace std;
#define ff(i,n,m) for(int i=n;i<m;i++)
#define i64 int64_t
#define tos(x) to_string(x)

int main() {
	i64 n;
	cin >> n;
	queue<i64> m;
	i64 ans = 0;
	ff(i, 1, sqrt(n)){
		if (n % i == 0) {
			if (i != 1) {
				m.push(i);
			}
			m.push(n / i);
		}
	}
	i64 a, d, r;
	int g = m.size();
	ff(i, 0, g) {
		a = m.front()-1;
		m.pop();
		d = n / a;
		r = n % a;
		//cout << a<<" "<<d << " " << r << endl;
		if (d == r) {
			ans += a;
		}
	}
	cout << ans << endl;
	return 0;
}

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

#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
#define e_b emplace_back
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())

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

#ifdef LOCAL//compile with -DLOCAL
#define debug(x) cerr<<"LINE"<<__LINE__<<" : "<<#x<<" = "<<(x)<<endl
#define debug_vec(x) cerr<<"LINE"<<__LINE__<<" : "<<#x<<" = ";\
  rep(i,sz(x)){cerr<<x[i]<<" ";}cerr<<endl
#define debug_mat(x) cerr<<"LINE"<<__LINE__<<" : "<<#x<<" = "<<endl;\
  rep(i,sz(x)){rep(j,sz(x[i])){cerr<<x[i][j]<<" ";}cerr<<endl;}cerr<<endl
#else
#define debug(x) void(0)
#define debug_vec(x) void(0)
#define debug_mat(x) void(0)
#endif

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


int main(){
  ios_base::sync_with_stdio(false);cin.tie(0);
  ll N,K;
  cin >> N >> K;
  vector<ll> A(N);
  rep(i,N)  cin >> A.at(i);

  vector<ll> sum(N+1,0);
  REP(i,1,N+1)  sum.at(i)=sum.at(i-1)+A.at(i-1);

  ll ans=0;
  map<ll,ll> mp;
  mp[0]++;
  REP(i,1,N+1){
    if(i-K>=0)  mp[(sum.at(i-K)-(i-K))%K]--;
    ll tmp=(sum.at(i)-i)%K;
    ans+=mp[tmp];
    mp[tmp]++;
  }
  cout << ans << endl;

  return 0;
}

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


int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  for(int i=0;i<N;i++){
    cin >> a.at(i);
  }
  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());
  int maxi=a.at(0);
  int ans=1;
  for(int i=0;i<N;i++){
    if (a.at(i)<maxi){
      maxi=a.at(i);
      ans++;
    }
  }
  cout << ans;
}


Measured memory_bytes: 256
from math import ceil

# 入力
N, A, B = map(int, input().split())
h = [int(input()) for _ in range(N)]


# 二分法により解を求める
def bis(p, ok, ng):
    mid = (ok + ng) // 2
    return (
        ok if abs(ok - ng) == 1 else
        bis(p, mid, ng) if p(mid) else
        bis(p, ok, mid)
    )


ans = bis(
    lambda k: sum(max(0, ceil((x - k * B) / (A - B))) for x in h) <= k,
    10**10,
    0
)

# 出力
print(ans)


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define Abs(x)((x) < 0 ? (x) * -1 : (x))
#define rep(x, y) for ((x) = 0; (x) < (y); (x)++)
#define repin(x, y) for ((x) = 0; (x) <= (y); (x)++)
#define nep(x, y) for ((x) = (y) - 1; 0 <= (x); (x)--)
#define nepi(x, y, z) for ((x) = (y) - 1; (z) <= (x); (x)--)
#define repi(x, y, z) for ((x) = (z); (x) < (y); (x)++)
#define repiin(x, y, z) for ((x) = (z); (x) <= (y); (x)++)
#define reps(x, y, z) for ((x) = 0; (x) < (y); (x) += (z))
#define repit(x) for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define nepit(x) for (__typeof((x).rbegin()) it = (x).rbegin(); it != (x).rend(); it++)
#define All(x) (x).begin(),(x).end()
#define Mem0(x) memset(x, 0, sizeof(x))
#define Mem1(x) memset(x, -1, sizeof(x))
#define End '\n'
#define Out(x) cout<<(x)<<End
template<typename T> inline bool Max(T &x, const T &y) { return x < y ? x = y, 1 : 0; }
template<typename T> inline bool Min(T &x, const T &y) { return x > y ? x = y, 1 : 0; }
template<typename T> using V = vector<T>;
template<typename T> using VV = V<V<T> >;

#define pb push_back
#define mp make_pair
#define X first
#define Y second

static const ll MOD = 1e9 + 7;
static const double PI = 3.141592653589793;

#define LOCAL 0

int main()
{
#if LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    freopen("debug.txt", "w", stderr);
#endif

    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;

    cin >> n;

    map<string, int> table;
    string prev, cur;

    int i;

    cin >> prev;

    table[prev]++;

    repi(i, n, 1) {
        cin >> cur;

        if (prev[prev.size() - 1] != cur[0]) {
            Out("No");

            return 0;
        }

        table[cur]++;

        if (1 < table[cur]) {
            Out("No");

            return 0;
        }

        prev = cur;
    }

    Out("Yes");

    return 0;
}


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

int main() {
  int n; cin >>n;
  vector<ll> a(n);
  rep(i,n) cin >>a[i];
  sort(a.begin(), a.end());
  ll ans = 1;
  rep(i,n){
    if(a[i]==0){
      cout << 0 << endl;
      return 0;
    }
    if(a[i]<=1000000000000000000/ans){
      ans*=a[i];
    }
    else{
      cout << -1 << endl;
      return 0;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4032
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner((System.in));
		int n = sc.nextInt();
		int k = sc.nextInt();
		int[] x = new int[n];
		int[] time = new int[n - k + 1];
		int ans = 0;

		for (int i = 0; i < n; i++) {
			x[i] = sc.nextInt();
		}

		for (int i = 0; i < n - k + 1; i++) {
				time[i] += (x[i+k-1] - x[i]);
			if (Math.abs(x[i]) < Math.abs(x[i+k-1])) {
				time[i] += Math.abs(x[i]);
			} else {
				time[i] += Math.abs(x[i+k-1]);
			}
		}

		Arrays.sort(time);
		
		ans = time[0];

		System.out.println(ans);
		sc.close();
	}
}

Measured memory_bytes: 49612
package main

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

func main() {
	N := ReadInt()
	C := make([]int, N-1)
	S := make([]int, N-1)
	F := make([]int, N-1)

	for i := 0; i < N-1; i++ {
		C[i], S[i], F[i] = ReadInt(), ReadInt(), ReadInt()
	}
	for i := 0; i < N; i++ {
		t := 0
		for j := i; j < N-1; j++ {
			if t >= S[j] {
				t = C[j] + t + (F[j]-(t-S[j])%F[j])%F[j]
			} else {
				t = C[j] + S[j]
			}
		}
		fmt.Println(t)
	}
}

var reader = bufio.NewReader(os.Stdin)

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


Measured memory_bytes: 1872
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// 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<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    }};

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn calc_short(n: i64, st: i64, en: i64, q: usize) -> Option<i64> {
    let mut quo: i64 = 0;
    let mut rem = en;
    for _ in 0..q {
        quo *= 2;
        rem *= 2;
        if rem >= n {
            rem -= n;
            quo += 1;
        }
    }
    let diff = (st - rem + n) % n;
    if st < rem {
        quo += 1;
    }
    assert!(quo <= 1 << q);
    if diff < 1 << q {
        Some((diff ^ quo) & ((1 << q) - 1))
    } else {
        None
    }
}

fn calc(n: i64, st: i64, mut en: i64, q: usize) -> Option<(i64, usize)> {
    let mut k = q;
    loop {
        if k >= 62 { k -= 1; continue; }
        if k == 0 || n > 1 << (k - 1) {
            break;
        }
        k -= 1;
    }
    assert!(1 << k <= 2 * n);
    let rest = q - k;
    for _ in 0..rest {
        en *= 2;
        if en >= n {
            en -= n - 1;
        }
    }
    if let Some(ans) = calc_short(n, st, en, k) {
        Some((ans, rest))
    } else {
        None
    }
}

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }
    input! {
        n: i64,
        q: usize,
        k: i64,
        d: i64,
    }
    if let Some((ans, rest)) = calc(n, k - 1, d - 1, q) {
        for i in 0..q - rest {
            puts!("{}\n", if (ans & 1 << i) == 0 { 0 } else { 1 });
        }
        for _ in 0..rest {
            puts!("0\n");
        }
    } else {
        puts!("-1\n");
    }
}

fn main() {
    solve();
}



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


int main() 
{
    string S;
    cin >> S;
    char last = S[0];
    int cnt = 0;
    for(int i = 1; i < (int)S.size(); ++i)
    {
        if(S[i] != last)
        {
            last = S[i];
            ++cnt;
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
const ll INF = mod * mod;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
struct block {
	int a, b, c, d;
};
block b[100000];
void solve() {
	int n, h;
	cin >> n >> h;
	rep(i, n) {
		cin >> b[i].a >> b[i].b >> b[i].c >> b[i].d;

	}

}
bool hantei() {
	int n; ll a, b, c, d; cin >> n >> a >> b >> c >> d;
	if (a > b)b = 2 * a - b;
	ll dif = b - a;
	int le = 0;
	int ri = n-1;
	while (ri - le > 1) {
		int mid = (ri + le) / 2;
		ll ma = d * mid - c * (n-1 - mid);
		ll mi = c * mid - d * (n - 1 - mid);
		if (mi <= dif && dif <= ma)return true;
		else if (dif < mi)ri = mid;
		else le = mid;
	}
	return false;
}
int main() {
	if (hantei())cout << "YES" << endl;
	else cout << "NO" << endl;
	//stop
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include<stdlib.h>
#define MOD 1000000007
int main()
{
    int n,m;
    scanf("%d %d",&n,&m);
    int *num;
    int now =0;
    num=(int *)malloc((n+1)*sizeof(int));//０段目にnum[0]を用いる
    num[0]=1;
    for (int i = 0; i < m; i++)
    {
        int broken;
        scanf("%d",&broken);
        for (int j = now+1; j < broken; j++)
        {
            if(j==1) num[1]=(broken!=1)*1;
            else num[j]=(num[j-1]+num[j-2])%MOD;
        }
        num[broken]=0;
        now=broken;    
    }
    for (int j = now+1; j <=n; j++)
    {
            if(j==1) num[1]=1;
            else num[j]=(num[j-1]+num[j-2])%MOD;
    }
    printf("%d",num[n]%1000000007);
    free(num);
    return 0;
}

Measured memory_bytes: 512
import math
n = sorted(list(map(int,input().split())))
if n[1] - n[0] >= 2:
    ans = 0
elif n[1] - n[0] == 0:
    ans = math.factorial(n[1]) **2 * 2
else:
    ans = math.factorial(n[1]) * math.factorial(n[0])
print(ans % (10**9 + 7) )



Measured memory_bytes: 5172
#include<stdio.h>
#include<stdlib.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define min(p,q)((p)<(q)?(p):(q))

ll cost[310][310];
ll dddd[310][310];
void waasharuhuroido(ll n){
	rep(i,0,n)rep(j,0,n)dddd[i][j]=cost[i][j];//辺が無いところはINFにする前処理が必要
	rep(k,0,n)rep(i,0,n)rep(j,0,n)dddd[i][j]=min(dddd[i][j],dddd[i][k]+dddd[k][j]);
}

int main(){
	int n;
	scanf("%d",&n);
	rep(i,0,n)rep(j,0,n)scanf("%d",&cost[i][j]);
	waasharuhuroido(n);
	
	ll ans=0;
	rep(i,0,n)rep(j,i+1,n){
		if(cost[i][j]>dddd[i][j]){
			puts("-1");
			return 0;
		}
		int f=0;
		rep(k,0,n)if(k!=i&&k!=j)f|=dddd[i][k]+dddd[k][j]==dddd[i][j];
		if(!f)ans+=dddd[i][j];
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 1664
#include<iostream>
#include<cstdio>
#include<queue>
#include<algorithm>
#define N 200005
#define LL long long
using namespace std;

struct node
{
	int k,len;
}p[N];
priority_queue<node>q;
bool operator<(node x,node y)
{
	return x.len>y.len;
}
bool cmp(node x,node y)
{
	return x.k<y.k;
}
int T,n,m;
int k[N],l[N],r[N];
int main()
{
	int i,j;
	scanf("%d",&T);
	while(T--)
	{
		m=0;
		LL ans=0;
		scanf("%d",&n);
		for(i=1;i<=n;i++)
		{
			scanf("%d%d%d",&k[i],&l[i],&r[i]);
			if(l[i]>=r[i])
			{
				ans+=r[i];
				p[++m].k=k[i];
				p[m].len=l[i]-r[i];
			}
		}
		sort(p+1,p+m+1,cmp);
		int size=0;
		for(i=1;i<=m;i++)
		{
			q.push(p[i]);
			size++;
			if(size>p[i].k)
			{
				size--;
				q.pop();
			}
		}
		while(!q.empty())
		{
			ans+=q.top().len;
			q.pop();
		}
		j=0;
		for(i=1;i<=n;i++)
		{
			if(l[i]<r[i])
			{
				ans+=l[i];
				p[++j].len=r[i]-l[i];
				p[j].k=n-k[i];
			}
		}
		sort(p+1,p+j+1,cmp);
		size=0;
		for(i=1;i<=j;i++)
		{
			q.push(p[i]);
			size++;
			if(size>p[i].k)
			{
				size--;
				q.pop();
			}
		}
		while(!q.empty())
		{
			ans+=q.top().len;
			q.pop();
		}
		printf("%lld\n",ans);
	}
	return 0;
}

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

using namespace std;
#define int long long
const int MOD = 1000000007;
int gcd(int a, int b) {
	int c;
	while (a != 0) {
		c = a;
		a = b % a;
		b = c;
	}
	return b;
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	int g = gcd(N, 360);
	cout << 360 / g << endl;
}

Measured memory_bytes: 3648
#include "bits/stdc++.h"
using namespace std;
typedef long long li;

vector<int> factor(int n) {
    vector<int> factors;
    for (int p = 2; p * p <= n; ++p) {
        while (n % p == 0) {
            factors.push_back(p);
            n /= p;
        }
    }
    if (n > 1) {
        factors.push_back(n);
    }
    return factors;
}

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

    li n;
    cin >> n;
    vector<li> xs(n);
    for (int i = 0; i < n; ++i) {
        cin >> xs[i];
    }

    li gcd = xs[0];
    for (int i = 0; i < n; ++i) {
        gcd = __gcd(xs[i], gcd);
    }

    if (gcd != 1) {
        cout << "not coprime" << endl;
        return 0;
    }

    set<int> primes;
    for (int i = 0; i < n; ++i) {
        vector<int> psv = factor(xs[i]);
        set<int> ps(psv.begin(), psv.end());

        for (auto p : ps) {
            if (primes.find(p) != primes.end()) {
                cout << "setwise coprime" << endl;
                return 0;
            }
            primes.insert(p);
        }
    }
    cout << "pairwise coprime" << endl;


    return 0;
}

Measured memory_bytes: 11024
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
def aux(txt)
  re=Regexp.new(/[A-Za-z]/)
  h=Hash.new(0)
  txt.split(//).each {|c|
    if re.match(c)
      h[c.downcase] += 1
    end
  }
  h
end

def main
  dat=[]
  fh=STDIN
  #fh=File.new("x.txt", "r")
  txt = fh.read
  hist=aux(txt)

  ('a'..'z').to_a.each{|k|
    puts "#{k} : #{hist[k]}"
  }
end

if $0 == __FILE__ then
  main
end


Measured memory_bytes: 7068
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx2,fma")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define f first
#define s second
#define inf 999999999999
#define N  500009
#define M  (L+R)/2
#define ll long long
#define pb push_back
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
using namespace __gnu_pbds;
using namespace std;

ll n,m,i,j,ans,sum,k;

int main()
{
	ios::sync_with_stdio(0);
	
	cin>>n>>k;
	ans=n-k+1;
	if(ans<0)ans=0;
	cout<<ans<<endl;
	
return 0;
}








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

typedef long long LL;
const int MN = 200005;

int N, stk[MN], tp;
LL A[MN], B[MN], C[MN], f[MN], Ans;

int main() {
	scanf("%d", &N);
	for (int i = 1; i <= N; ++i) scanf("%lld", &A[i]);
	for (int i = 1; i <= N; ++i) scanf("%lld", &B[i]);
	int p = std::max_element(A + 1, A + N + 1) - A;
	std::rotate(A + 1, A + p, A + N + 1);
	std::rotate(B + 1, B + p, B + N + 1);
	A[N + 1] = A[1];
	for (int i = 2; i <= N; ++i) C[i + 1] = 2 * (C[i] + B[i]) - C[i - 1];
	for (int i = 1; i <= N + 1; ++i) {
		A[i] -= C[i];
		while (tp > 1 && (A[stk[tp]] - A[stk[tp - 1]]) * (i - stk[tp]) <= (A[i] - A[stk[tp]]) * (stk[tp] - stk[tp - 1])) --tp;
		stk[++tp] = i;
	}
	for (int i = 2; i <= tp; ++i) {
		int c = stk[i] - stk[i - 1];
		Ans += A[stk[i - 1]] * (c + 1) + A[stk[i]] * (c - 1);
	}
	for (int i = 1; i <= N; ++i) Ans += 2 * C[i];
	printf("%.12lf\n", Ans / (2. * N));
	return 0;
}

Measured memory_bytes: 7168
N, L = map(int, input().split())
taste = [L + i - 1 for i in range(1, N+1)]


for i in range(N):
    p = abs(sum(taste) - sum(taste[:i] + taste[i+1:]))
    if i == 0:
        minnum = p
        min_i = 0
    elif p < minnum:
        minnum = p
        min_i = i


print(sum(taste[:min_i] + taste[min_i + 1:]))

Measured memory_bytes: 3060
#include<iostream>
using namespace std;
int main(){
	int a,b,c,d,e,f,ans;
	cin>>a>>b>>c>>d>>e>>f;
	ans=1*a+5*b+10*c+50*d+100*e+500*f;
	if(ans>=1000){
		cout<<"1"<<endl;
	}else{
		cout<<"0"<<endl;
	}
	return 0;
} 

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

int main(){
    int n, k;
    cin >> n >> k;
    int a[n];
    rep(i,n) cin >> a[i];
    vector<bool> dp(k+1,false);
    for(int i = 1; i <= k; i++){
        rep(j,n){
            if(i-a[j] >= 0 && !dp[i-a[j]]) dp[i] = true;
        }
    }
    cout << (dp[k] ? "First" : "Second") << endl; 
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <cstring>

using namespace std;
using ll = long long;
using pint = pair<int, int>;

ll INF = 1LL << 60;

int main() {
	int N;
	double D;
	cin >> N >> D;
	int count = 0;
	for (int i = 0; i < N; i++) {
		ll x, y;
		cin >> x >> y;
		double dist = sqrt(x * x + y * y);
		if (dist <= D) count++;
	}
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 3772
#include<stdio.h>
#include<string.h>
#include<math.h>
int ara_D[100][200];
int ara[100000];
char ara1[100000];
int main()
{
    int i,j,k,l,n,t;
    gets(ara1);
    if(ara1[0]=='a' || ara1[0]=='e' || ara1[0]=='i' || ara1[0]=='o' || ara1[0]=='u')
    {
        printf("vowel\n");
    }
    else
    {
        printf("consonant\n");
    }
    return 0;
}



Measured memory_bytes: 128
#include <stdio.h>
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

#define MAX_V 10000


int main(){
    int N;
    string S;
    cin >> N;
    cin >> S;
    int ans = 1;
    for(int n = 0; n < N - 1; n++){
        if (S[n] != S[n + 1]) ans++;

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

Measured memory_bytes: 512
#include "bits/stdc++.h"
using namespace std;
int main() {
	map<long long, long long> num;
	long long N;
	cin >> N;
	vector<long long>A(N);
	for (long long i = 0; i < N; i++) cin >> A.at(i);
	vector<long long>minus(N), plus(N);
	for (long long i = 0; i < N; i++) {
		minus.at(i) = i - A.at(i);
		num[i + A.at(i)]++;
	}
	long long ans = 0;
	for (long long i = 0; i < N; i++) {
		if (minus.at(i) >= 0) ans += num[minus.at(i)];
	}
	cout << ans << endl;
}

Measured memory_bytes: 21668
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <array>
#include <algorithm>
#include <utility>
#include <numeric>
#include <deque>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cmath>
#include <limits>
#include <cassert>
#include <bitset>
#include <list>
#include <iomanip>
#include <cctype>
#include<chrono>
#include<random>

#define for0(i, N)    for (long long i = 0  ; i <  (N); ++i)
#define for1n(i, N)   for (long long i = 1  ; i <= (N); ++i)
#define for1(i, N)    for (long long i = 1  ; i <  (N); ++i)
#define forn(i, N)    for (long long i = 0  ; i <= (N); ++i)
#define forx(i, N, x) for (long long i = (x); i <  (N); ++i)
#define forl(i, N, x, a) for (long long i = (x), a = 0; a < (N);    \
                              i = (i + 1) % (N), ++a)
#define int long long

long double constexpr pi = 3.141592653589793;

template<class T>
constexpr T sigma1(T i, T n){
    return (n - i + 1) * (i + n) / 2;
}

template<class T>
constexpr T sigma2(T i, T n){
    return (i == 1 ? n * (n + 1) * (2 * n + 1) / 6 :
            sigma2(1, n) - sigma2(1, i - 1));
}

template<class T>
constexpr T sigma3(T i, T n){
    if (i == 1) {
        auto temp = sigma1(i, n);
        return temp * temp;
    }
    return sigma2(1, n) - sigma2(1, i - 1);
}

template<size_t i>
std::bitset<i> operator++(std::bitset<i> b, signed){
    static_assert(i <= 64, "Cannot cast 64bit int.");
    return b = (unsigned long long)b + 1;
}

template<size_t i>
std::bitset<i> operator++(std::bitset<i> b){
    static_assert(i <= 64, "Cannot cast 64bit int.");
    auto temp = b;
    b++;
    return temp;
}

template<size_t i>
std::bitset<i> operator--(std::bitset<i> b, signed){
    static_assert(i <= 64, "Cannot cast 64bit int.");
    return b = (unsigned long long)b - 1;
}

template<size_t i>
std::bitset<i> operator--(std::bitset<i> b){
    static_assert(i <= 64, "Cannot cast 64bit int.");
    auto temp = b;
    b--;
    return temp;
}

long long constexpr inf = std::numeric_limits<long long>::max();

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef priority_queue<ll> pq;
typedef priority_queue<ll,vector<ll>, greater<ll>> pql;
typedef stack<ll> stk;
typedef queue<ll> qu;
typedef pair<ll, ll> pll;
typedef map<ll, ll> mll;
typedef unordered_map<ll, ll> umll;
typedef set<ll> sll;
typedef unordered_set<ll> usll;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<vector<ll>> vvll;


signed main(void){
    cin.tie(0); ios::sync_with_stdio(false);cout<<fixed<<setprecision(10);
    ll n;
    cin >> n;
    vector<string> s(n);
    map<string, ll> c;

    c["AC"] = 0;
    c["WA"] = 0;
    c["TLE"] = 0;
    c["RE"] = 0;


    for0(i, n){
        cin >> s[i];
        ++c[s[i]];
    }

    cout << "AC x " << c["AC"] << "\n";
    cout << "WA x " << c["WA"] << "\n";
    cout << "TLE x " << c["TLE"] << "\n";
    cout << "RE x " << c["RE"] << "\n";


    return 0;
}


Measured memory_bytes: 6368
def main():
    N, K = map(int, input().split())
    D = []
    A = []
    for i in range(K):
        d = int(input())
        Ai = [int(x) for x in input().split()]
        A = A + Ai
    A_ = set(A)
    n = N - len(A_)
    print(n)
main()

Measured memory_bytes: 9180
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

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

/* Macros reg. ends here */

const ll INF = 1LL << 50;

bool sim(ll n, ll k) {
  while (n >= k) {
    if (n % k == 0)
      n /= k;
    else
      n %= k;
  }
  return n == 1;
}

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

  ll n;
  cin >> n;
  vll sdivs;
  for (ll i = 2; i * i <= n; i++) {
    if (n % i == 0) sdivs.push_back(i);
  }
  ll ans = 1;
  for (ll d : sdivs) {
    if (sim(n, d)) ans++;
  }
  for (ll i = 1; i * i <= n - 1; i++) {
    if ((n - 1) % i == 0) {
      ans++;
      if ((n - 1) / i != i) ans++;
    }
  }
  ans--;

  cout << ans << endl;

  return 0;
}


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

int main(){
  int n;
  cin>>n;
  ll a[n+1]={};
  cin>>a[1];
  ll s=a[1],t=a[1];
  int ss=1,tt=1;
  for(int i=2;i<=n;i++){
    cin>>a[i];
    if(s>a[i]){
      s=a[i];
      ss=i;
    }
    if(t<a[i]){
      t=a[i];
      tt=i;
    }
  }
  vector<pair<ll,ll>> v;
  if(t+s>0){
    for(int i=1;i<=n;i++){
      v.push_back(make_pair(tt,i));
    }
    for(int i=1;i<n;i++){
      v.push_back(make_pair(i,i+1));
    }
  }else{
    for(int i=1;i<=n;i++){
      v.push_back(make_pair(ss,i));
    }
    for(int i=n;i>1;i--){
      v.push_back(make_pair(i,i-1));
    }
  }
  cout<<2*n-1<<endl;
  for(int i=0;i<2*n-1;i++) cout<<v[i].first<<" "<<v[i].second<<endl;
  return 0;
}


Measured memory_bytes: 256
/************************************************
 * Au: Hany01
 * Prob: agc001e
 * Email: hany01dxx@gmail.com & hany01@foxmail.com
 * Inst: Yali High School
************************************************/

#include<bits/stdc++.h>

using namespace std;

typedef long long LL;
typedef long double LD;
typedef pair<int, int> PII;
#define Rep(i, j) for (register int i = 0, i##_end_ = (j); i < i##_end_; ++ i)
#define For(i, j, k) for (register int i = (j), i##_end_ = (k); i <= i##_end_; ++ i)
#define Fordown(i, j, k) for (register int i = (j), i##_end_ = (k); i >= i##_end_; -- i)
#define Set(a, b) memset(a, b, sizeof(a))
#define Cpy(a, b) memcpy(a, b, sizeof(a))
#define X first
#define Y second
#define PB(a) push_back(a)
#define MP(a, b) make_pair(a, b)
#define SZ(a) ((int)(a).size())
#define ALL(a) a.begin(), a.end()
#define INF (0x3f3f3f3f)
#define INF1 (2139062143)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define y1 wozenmezhemecaia

template <typename T> inline bool chkmax(T &a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T> inline bool chkmin(T &a, T b) { return b < a ? a = b, 1 : 0; }

template <typename T> inline T read() {
	static T _, __; static char c_;
    for (_ = 0, __ = 1, c_ = getchar(); c_ < '0' || c_ > '9'; c_ = getchar()) if (c_ == '-') __ = -1;
    for ( ; c_ >= '0' && c_ <= '9'; c_ = getchar()) _ = (_ << 1) + (_ << 3) + (c_ ^ 48);
    return _ * __;
}
//EOT


const int maxn = 2e5 + 5, maxm = 4007, MOD = 1e9 + 7, M = 4005, N = 2002;

int n, A[maxn], B[maxn], dp[maxm][maxm], fac[maxm << 1], ifac[maxm << 1], ans;

inline int Pow(int a, LL b) {
	register int ans = 1;
	for ( ; b; b >>= 1, a = (LL)a * a % MOD) if (b & 1) ans = (LL)ans * a % MOD;
	return ans;
}

int main()
{
#ifdef hany01
	freopen("agc001e.in", "r", stdin);
	freopen("agc001e.out", "w", stdout);
#endif

	n = read<int>();
	For(i, 1, n) A[i] = read<int>(), B[i] = read<int>(), ++ dp[N - A[i]][N - B[i]];

	For(i, 1, M) For(j, 1, M) dp[i][j] = ((dp[i - 1][j] + dp[i][j - 1]) % MOD + dp[i][j]) % MOD;
	fac[0] = 1;
	For(i, 1, M * 2) fac[i] = (LL)fac[i - 1] * i % MOD;
	ifac[M * 2] = Pow(fac[M * 2], MOD - 2);
	Fordown(i, M * 2, 1) ifac[i - 1] = (LL)ifac[i] * i % MOD;

	For(i, 1, n)
		(ans += (dp[N + A[i]][N + B[i]] + MOD
		 - (LL)fac[A[i] * 2 + B[i] * 2] * ifac[A[i] * 2] % MOD * ifac[B[i] * 2] % MOD) % MOD) %= MOD;
	printf("%lld\n", (LL)ans * ((MOD + 1) / 2) % MOD);

	return 0;
}

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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define fst first
#define snd second
#define pb push_back
#define ALL(x) x.begin(),x.end()
#define EPS (1e-9)
#define equals(a,b) (fabs((a)-(b))<EPS)

using namespace std;

bool LT(double a,double b) { return !equals(a,b) && a < b; }
bool LTE(double a,double b) { return equals(a,b) || a < b; }

const string YES = "";
const string NO  = "";

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

void solve() {

}

int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  map<char,int> mp;
  rep(i,n) ++mp[s[i]];
  if( mp['W'] == 0 || mp['R'] == 0 ) {
    puts("0");
    return 0;
  }
  int ans = min(mp['W'],mp['R']);
  string t = string(mp['R'],'R') + string(mp['W'],'W');
  //cout << s << endl;
  //cout << t << endl;
  mp['W'] = mp['R'] = 0;
  rep(i,n) if( s[i] != t[i] ) ++mp[s[i]];
  ans = min(ans,min(mp['W'],mp['R']));
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3940
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << "\n"
#define COUTF(x) cout << setprecision(15) << (x) << "\n"
#define ENDL cout << "\n"
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SZ(x) (ll) x.size()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#define MAX(x, y, z) max(x, max(y, z))
#define MIN(x, y, z) min(x, min(y, z))
#define ANS cout << ans << "\n"
#define RETURN(x)    \
  cout << x << "\n"; \
  return 0
clock_t CLOCK;
#define START_TIMER CLOCK = clock()
#define SHOW_TIMER cerr << "time: " << (ld)(clock() - CLOCK) / 1000000 << "\n"
#define init() \
  cin.tie(0);  \
  ios::sync_with_stdio(false)
#define LINE cerr << "[debug] line: " << __LINE__ << "\n";
#define debug(x) cerr << "[debug] " << #x << ": " << x << "\n";
#define debugV(v)                       \
  cerr << "[debugV] " << #v << ":";     \
  rep(i, v.size()) cerr << " " << v[i]; \
  cerr << "\n";
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using mll = map<ll, ll>;
using qll = queue<ll>;
using P = pair<ll, ll>;

constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr ld PI = 3.141592653589793238462643383279;
ll get_digit(ll x) {
  return to_string(x).size();
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

vll divisor(ll n) {
  vll 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(ret);
  return (ret);
}

bool h(ll aa) {
  return aa == 4 || aa == 6 || aa == 9 || aa == 11;
}

bool h2(ll aa) {
  return aa == 1 || aa == 3 || aa == 5 || aa == 7 || aa == 8 || aa == 10 ||
         aa == 12;
}

signed main() {
  init();
  ll a, b;
  cin >> a >> b;

  if (a == 2 || b == 2) {
    COUT("No");
    return 0;
  }

  if (h(a) && h(b)) {
    COUT("Yes");
    return 0;
  }

  if (h2(a) && h2(b)) {
    COUT("Yes");
    return 0;
  }

  COUT("No");

  return 0;
}

Measured memory_bytes: 3616
<?php


[$A, $B, $C] = fscanf(STDIN, "%d%d%d");
[$K] = fscanf(STDIN, "%d");

while($A >= $B){
    $B*=2;
    $K--;
}

while($B >= $C){
    $C*=2;
    $K--;
}
if($K>=0){
    echo "Yes";
}else{
    echo "No";
}

Measured memory_bytes: 16212
#include<bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define ll long long
#define ld long double
#define sz(a) ((int)(a).size())
#define clr(a,v) memset(a, v, sizeof(a))
#define all(a) (a).begin(),(a).end()
#define pii pair<int,int>
#define pdd pair<ld,ld> 
#define rep(i,a,b) for(int i=a; i<b; i++)
#define dec(i,a,b) for(int i=a; i>=b; i--)
#define ler freopen("inspection.in","r",stdin);freopen("inspection.out","w",stdout)
#define fastio ios::sync_with_stdio(0), cin.tie(0)
#define debug cout<<"!!?!!\n"
using namespace std;
#define MAXN 100005
#define INF 2000000000000000000LL


int n, v[102], dp[10004];
int main(){
	cin >> n;
	rep(i,0,n) cin >> v[i];
	dp[0]=1;
	rep(i,0,n){
		for(int j=10003; j>=0; j--) if(dp[j] && j+v[i] < 10004) dp[j+v[i]]=1;
	}
	int ans=0;
	rep(i,0,10004) if(dp[i] && i%10!=0) ans=i;
	cout << ans << endl;
}








Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define all(a)  (a).begin(),(a).end()
typedef long long ll;
ll mod=1000000007;

int main() {
  int n,d;cin>>n>>d;
  vector<vector<int>> x;
  for(int i=0;i<n;++i){
    vector<int> t(d);
    for(int j=0;j<d;++j) cin >> t[j];
    x.push_back(t);
  }
  int cnt=0;
  for(int i=0;i<n;++i){
    for(int j=i+1;j<n;++j){
      int tmp =0;
      for(int k=0;k<d;++k){
        tmp += (x[i][k] - x[j][k])*(x[i][k] - x[j][k]);
      }
      int t_sqrt = (int)sqrt(tmp);
      if(tmp==t_sqrt*t_sqrt) ++cnt;
    }
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 256