akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int dp[100007]={},b[100007]={};
int mod = (int)(1e9+7);
int main(){
    int n,m;
    cin >> n >> m;
    int a[m];
    for(int i=0;i<m;i++){
        cin >> a[i];
        b[a[i]]=1;
    }
    dp[0] = 1;
    if(!b[1]) dp[1] = 1; 
    for(int i=0;i<n-1;i++){
        int c=dp[i+1],d=dp[i];
        if(b[i]) d=0;
        if(b[i+1]) c=0;
        dp[i+2] = (c+d)%mod;
        if(b[i+2]) dp[i+2] = 0;
    }
    cout << dp[n] << endl;
}


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

//#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//以降 cin の入力元が 'input.txt' になる
//std::ifstream in("input.txt");
//std::cin.rdbuf(in.rdbuf());

signed main()
{   
    gearup;
    int h,w,k; cin >> h >> w >> k;
    vs s(h);
    rep(i,h)cin >> s[i];

    ll res = 0;
    //ビット全探索
    rep(i,(1<<h)){
        rep(j,(1<<w)){
            auto ss = s;
            ll now = 0;
            vl row;
            rep(ii,h){
                if( i & (1<<ii))row.push_back(ii);
            }   
            vl col;
            rep(jj,w){
                if( j & (1 << jj))col.push_back(jj);
            }
            rep(ii,row.size()){
                rep(jj,w)ss[row[ii]][jj] = '&';
            }
            rep(jj,col.size()){
                rep(ii,h)ss[ii][col[jj]] = '&';
            }
            rep(ii,h)rep(jj,w)if(ss[ii][jj] == '#')now++;
            if(now == k){
                //cout << i << " " << j << endl;
                res++;
            }
        }
    }
    out(res);
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file  
#include <ext/pb_ds/tree_policy.hpp>  
#include <functional> // for less  
using namespace         std;
#define                 int long long
#define                 double long double
#define                 pb push_back
#define                 mp make_pair
#define st(arr,a)       memset(arr,a,sizeof arr)
#define                 nl cout<<endl
#define                 endl '\n'              
#define bitcount(x)     __builtin_popcountll(x)
const int MOD = 1000000007ll;
#define forn(i,a,b)     for(int i=a;i<=b;i++)
#define rfor(i,a,b)     for(int i=a;i>=b;i--)
#define all(x)          x.begin() , x.end()
#define pi pair<int,int>
#define X first
#define Y second
#define N 1014159
#define  vi vector<int>
#define  v  vector
using namespace __gnu_pbds;  
typedef tree<int, null_type, less<int>, rb_tree_tag,  
            tree_order_statistics_node_update> oset; 
gp_hash_table<int, int> table;
const int RANDOM = chrono::high_resolution_clock::now().time_since_epoch().count();
struct chash {
    int operator()(int x) const { return x ^ RANDOM; }
};

int arr[N];

multiset<int>one,two;
int pos = 0;
int A[N],B[N];
void solve()
{
	int n,k;
	cin>>n>>k;
    forn(i,1,n)
	{
		cin>>arr[i];
		if(arr[i]<0)
		{
			A[i] =arr[i] + A[i-1];
			B[i] = B[i-1];
		}
		else
		{
			A[i] = A[i-1];
			B[i] = B[i-1] + arr[i];
			pos+=arr[i];
		}
		
		
	}
	//forn(i,1,n)cout<<A[i]<<" ";nl;
	int ans = 0;
	forn(i,k,n)
	{
		ans = max(ans,pos + A[i] - A[i-k]);
		ans = max(ans,pos - B[i] + B[i-k]);
	}
	cout<<ans;

}


signed main() 
{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); 
    int t = 1;
    //cin>>t;
    while(t--)
    {
        solve();
    }nl;



    return 0;

}

//       g++ -g c.cpp ; ./a.out

Measured memory_bytes: 9216
a,b,c=map(int,input().split())
if a>b:
 t=a
 a=b
 b=t
if b>c:
 t=b
 b=c
 c=t
if a>b:
 t=a
 a=b
 b=t
print(f'{a} {b} {c}')

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

int main(){

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

    int cnt = 0;
    while((a!=b) || (b!=c) || (c!=a)){
        if(a==b){
            if(a<c){
                a++;
                b++;
            }
            else c += 2;
        }
        else if(b==c){
            if(b<a){
                b++;
                c++;
            }
            else a += 2;
        }
        else if(c==a){
            if(c<b){
                c++;
                a++;
            }
            else b += 2;
        }
        else{
            int temp;
            temp = min(a, min(b, c));
            if(temp == a) a = temp+2;
            if(temp == b) b = temp+2;
            if(temp == c) c = temp+2;
        }
        cnt++;
    }

    cout << cnt << endl;
    return 0;
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long LL;
typedef pair<int, int> PII;

int x, n;
int p[100];

bool check(int val) {
    forn(i, n) {
        if (p[i] == val) {
            return false;
        }
    }
    return true;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin >> x >> n;
    forn(i, n) {
        cin >> p[i];
    }
    forn(dif, 111) {
        if (check(x - dif)) {
            cout << x - dif << endl;
            return 0;
        }
        if (check(x + dif)) {
            cout << x + dif << endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 3648
#define _USE_MATH_DEFINES
#include <iostream>
#include <algorithm>
#include <queue>
#include <stack>
#include <deque>
#include <climits>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
//#include <tuple>

#define INF INT_MAX>>1 
#define SIZE 100010
#define MOD 1000000007
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define rep2(i, from, to) for(int i=(from); i<(int)(to); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define LLPair pair<ll, ll>
#define vint vector<int>
#define vll vector<ll>
typedef long long ll;

using namespace std;

struct Point { int x, y; };
struct Edge { int from, to, cost; };
struct gNode { int from, to, cost; };
struct tNode { int value; int parent; vector<int> child; };

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

int gcd(int a, int b){ return a % b == 0 ? b : gcd(b, a%b); }
int lcm(int a, int b){ return a * b/ gcd(a, b); }
int extgcd(int a, int b, int& x, int& y){
	int d = a;
	if(b != 0){
		d = extgcd(b, a%b, y, x);
		y -= (a/b) * x;
	} else{
		x = 1; y = 0;
	}
	return d;
}
ll mod_pow(ll x, ll n){
	if(n == 0) return 1;
	ll res = mod_pow(x*x % MOD, n/2);
	if(n & 1) res = res * x % MOD;
	return res;
}

int main(void){
	int n; cin >> n;
	int c = 0;
	rep2(i, 1, n+1){
		if(i%2==1) c++;
	}
	double ans = (double)c/n;
	printf("%.10lf\n", ans);
	return 0;
}

Measured memory_bytes: 256
#include<algorithm>
#include<cstring>
#include<cctype>
#include<cstdio>
#define rep(i,x,y) for(int i=x; i<=y; ++i)

using namespace std;
int a,b,c,d,di[100];

int main()
{
	scanf("%d%d%d%d",&a,&b,&c,&d);
	++di[a],++di[b],++di[c],++di[d];
	if(di[1]==1 && di[9]==1 && di[7]==1 && di[4]==1) puts("YES");
	else puts("NO");
	return 0;
}

Measured memory_bytes: 128
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    for (int i = 1; i <= 9; i++) {
      int ans = 100 * i + 10 * i + i;
      if (n <= ans) {
        System.out.println(ans);
        return;
      }
    }
  }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define mem(a,b) memset(a,b,sizeof(a))
#define eb emplace_back
#define mp make_pair
using namespace std;
multiset<int> s;
int n,x;
ll ans=1;
const int mod=1e9+7;
int main(){
    cin>>n;
    s.insert(0),s.insert(0),s.insert(0);
    for(int i=0;i<n;i++){
        cin>>x;
        (ans*=s.count(x))%=mod;
        if(s.count(x)){
            s.erase(s.find(x));
            s.insert(x+1);
        }
    }
    cout<<ans<<endl;
    return 0;
}

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


int main(void)
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    int a[n];
    for(int i = 0; i < n; i ++)
    {
        cin >> a[i];
    }
    int count = 1;
    for(int i = 1; i < n; i++)
    {
        if(a[i] < a[i-1])
            count++;
        else
            a[i] = a[i-1];
    }
    cout << count;
}


Measured memory_bytes: 4408
#include <iostream>
#include <cassert>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <array>
 
using namespace std;
const int MAXN = (int)2e5;
array<int, MAXN> arr;
 
void No() {
    cout << "No" << endl;
    exit(0);
}
void Yes() {
    cout << "Yes" << endl;
    exit(0);
}
 
int main() {
 
    int n;
    cin >> n;
 
    map <int, int> st;
 
    for (int i = 0; i < n; i++) {
        cin >> arr[i];
        st[arr[i]]++;
    }
    int mn = *min_element(arr.begin(), arr.begin() + n);
    int mx = *max_element(arr.begin(), arr.begin() + n);
    if (st.size() > 2 || (st.size() == 2 && st[mx] == 1) || mx - mn > 1) {
        No();
    }
 
    if (st.size() == 1 && mn == n - 1) {
        Yes();
    }
 
    int mnDiff = 1;
    int mxDiff = n / 2;
    if (st.size() != 1) {
        mnDiff = st[mn] + 1;
        mxDiff = st[mn] + st[mx] / 2;
    }
 
    if (mx >= mnDiff && mx <= mxDiff) {
        Yes();
    } else {
        No();
    }
 
    return 0;
}

Measured memory_bytes: 5376
#include <iostream>
#include <vector>

using namespace std;

int main()
{
    int N; 
    cin >> N;
    
    vector<int> vec;
    
    for(int i = 0; i < N; ++i)
    {
        int Num; cin >> Num;
        vec.push_back(Num);
    }
    
    cin >> N;
    for(int i = 0; i < N; ++i)
    {
        int Start, End, Num, Count = 0;
        cin >> Start >> End >> Num;
        
        for(int j = Start; j < End; ++j)
            if(Num == vec[j])
             ++Count;
        
        cout << Count << endl;
        
        
    }
    
}


Measured memory_bytes: 3172
#include <iostream>
#include <vector>
#include <set>
using namespace std;
int main(void){
  int n,k,r;
  cin>>n>>k;
  vector<set<int> > boat(k);
  for(int i=0,m;i<k;++i){
    cin>>m;
    for(int j=0,b;j<m;++j){
      cin>>b;
      boat[i].insert(b);
    }
  }
  cin>>r;
  set<int> hate;
  for(int i=0,p,q;i<r;++i){
    cin>>p>>q;
    for(int j=0;j<k;++j){
      if(boat[j].find(p)!=boat[j].end()&&boat[j].find(q)!=boat[j].end()){hate.insert(p);hate.insert(q);}
    }
  }
  cout<<hate.size()<<endl;
  return 0;
}

Measured memory_bytes: 1200
import java.util.*;
public class Main{
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
   int N = sc.nextInt();
   
   int[] ai = new int[N];
   for(int i=0;i<N;i++) ai[i]=sc.nextInt();

   int count =0;
   for(int i=0;i<30;i++)
   {
     for(int k = 0;k<N;k++)
     {  
      if(ai[k]%2==0)
      {
         ai[k] /=2;
         count++;
      }
     }
   }

   System.out.println(count);
 }
}

Measured memory_bytes: 35436
#include "bits/stdc++.h"
using namespace std;
#define lint long long
#define low lower_bound
#define upp upper_bound
#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define Rep(i, n) for (int i = int(n); i >= 0; --i)
#define all(vec) (vec).begin(), (vec).end()
#define cend printf("\n");
#define prique(T) priority_queue<T, vector<T>, greater<T>>
#define prique2(T) priority_queue<T>

struct edge { int to; double cost; };
#define P pair<int, int>
#define D pair<double, double>
#define DI pair<double, int>
//const lint mod = 998244353LL;
const lint mod = 1000000007LL;
const lint inf = 3LL * mod * mod;

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

lint modpow(lint x, lint n, lint m) {
	lint ans = 1;
	while (n > 0) {
		if (n & 1) {
			ans *= x;
			if (m <= ans) ans %= m;
		}
		x *= x;
		if (m <= x) x %= m;
		n >>= 1;
	}
	return ans;
}

lint fact[1000000];
void f_init(lint n) {
	if (1000000 <= n) return;
	fact[0] = fact[1] = 1;
	for (lint i = 2; i <= n; ++i) {
		fact[i] = i * fact[i - 1];
		if (mod <= fact[i]) fact[i] %= mod;
	}
	return;
}

lint inver[1000000]; bool inve[100000];
lint inv(lint x) {
	if (x == 0) return 0;
	else if (inve[x]) return inver[x];
	else {
		inve[x] = true;
		return inver[x] = modpow(x, mod - 2, mod);
	}
}

lint comb(lint n, lint r) {
	if (n < r) return 0;
	if (n == r) return 1;
	lint ans = fact[n] * inv(fact[n - r]) % mod * inv(fact[r]) % mod;
	if (ans < 0) return ans + mod;
	return ans;
}

lint nck[1010][1010];
void comb(lint n) {
	rep(i, n + 1) {
		rep(j, i + 1) {
			if (j == 0 || i == j) nck[i][j] = 1;
			else nck[i][j] = nck[i - 1][j - 1] + nck[i - 1][j];
		}
	}
}

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

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

bool pri(lint p) {
	for (lint i = 2; i * i <= p; i == 2 ? ++i : i += 2) if (p % i == 0) return false;
	return p > 1;
}

map<lint, lint> factring(lint n) {
	map<lint, lint>ans;
	for (lint i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			n /= i;
			++ans[i];
		}
	}
	if (n != 1) ++ans[n];
	return ans;
}

double dis(D a, D b) { return sqrt((a.first - b.first) * (a.first - b.first) + (a.second - b.second) * (a.second - b.second)); }

long long n, ans;
int v[100010];
int main() {
	cin >> n;
	rep(i, n) {
		cin >> v[i];
	}
	sort(v, v + n, greater<int>());
	rep(i, n) {
		ans += v[i] - i - 1;
	}
	cout << ans << endl;
}


Measured memory_bytes: 3504
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i) = 0; (i) < (n); ++(i))
#define rrep(i,n) for(int (i) = (n) - 1; (i) >= 0; --(i)) //Reversi rep
#define nfor(i,a,b) for(int (i) = (a); (i) < (b); ++(i)) //Natural for
#define rfor(i,a,b) for(int (i) = (b); (i) >= (a); --(i)) //Reversi for
#define ll long long
#define mod (1000000007)
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define yes cout << "yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;
#define no cout << "no" << endl;

int asc(const void *a, const void *b) {
    return *(int *)a - *(int *)b;
}

int desc(const void *a, const void *b) {
    return *(int *)b - *(int *)a;
}

int main()
{
    int a,b,k;
    cin >> a >> b >> k;
    if (a + k >= b - k + 1) {
        nfor(i, a, b + 1){
            cout << i << endl;
        }
    }else{
        nfor(i, a, a + k)cout << i << endl;
        nfor(i, b - k + 1, b + 1)cout << i << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
 
int main(void){
    int i, j, k, l, m, n;
    int d, w, low, high, ans, tmp;
    int e[10][10];
 
    while(1){
        scanf("%d%d", &d, &w);
        if(d == 0 && w == 0) break;
        for(i=0; i<d; i++){
            for(k=0; k<w; k++){
                scanf("%d", &e[i][k]);
            }
        }
 
        ans=0;
        for(i=0; i<d; i++){
            for(j=0; j<w; j++){
                for(k=0; k<d; k++){
                    for(l=0; l<w; l++){
                        low = 10;
                        high = tmp = 0;
                     
                        for(m=i; m<=k; m++){
                            for(n=j; n<=l; n++){
                                if(m==i || m==k || n==j || n==l){
                                    if(e[m][n] < low) low = e[m][n];
                                }
                            }
                        }
                     
                        for(m=i+1; m<k; m++){
                            for(n=j+1; n<l; n++){
                                if(e[m][n] > high) high = e[m][n];
                                tmp += low - e[m][n];
                            }
                        }
                        if(low > high && tmp > ans) ans = tmp;
                    }
                }
            }
        }
        printf("%d\n", ans);
    }
    return 0;
}


Measured memory_bytes: 2044
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#include <iostream>
#include <string>
#include <algorithm>
#include <unordered_set>
using namespace std;

int main(){
    char c;
    cin >> c;
    if('A'<=c && c <= 'Z'){
        cout <<'A' << endl;
    }else{
        cout << 'a' << endl;
    }
}

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

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()

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

const long long INF = 1LL << 60;

int dp[5010][5010];
int main()
{
    int N;
    cin >> N;
    string S;
    cin >> S;

    for (int i = N - 1; i >= 0; i--) {
        for (int j = N - 1; j >= 0; j--) {
            if (S[i] == S[j]) dp[i][j] = dp[i + 1][j + 1] + 1;
        }
    }

    int res = 0;
    rep(i, N) {
        rep(j, N) {
            if (i >= j) continue;
            int tmp = min(dp[i][j], j - i);
            res = max(res, tmp);
        }
    }
    
    cout << res << endl;
    return 0;
}

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

int main() {
  string s1,s2,t;
  cin >> s2 >> t;

  bool can=false;
  int ls2=s2.size(),lt=t.size();
  string ans;
  for (int i=0; i<=ls2-lt; i++) {
    for (int j=0; j<lt; j++) {
      if (s2.at(i+j) != '?' && s2.at(i+j) != t.at(j))
	break;
      if (j == lt-1) {
	s1 = s2;
	for (int k=0; k<ls2; k++) {
	  if (k>=i&&k<i+lt)
	    s1.at(k) = t.at(k-i);
	  else if (s2.at(k) == '?')
	    s1.at(k) = 'a';
	}
	if (can) {
	  ans = min(s1,ans);
	}
	else {
	  ans = s1;
	  can = true;
	}
      }
    }
  }
  if (can)
    cout << ans << endl;
  else
    cout << "UNRESTORABLE" << endl;
  return 0;
}

Measured memory_bytes: 256
using System;

namespace B___AtCoder_Alloy
{
    class Program
    {
        static void Main (string[] args)
        {
            var input = Console.ReadLine ().Split (' ');
            var n = int.Parse (input[0]);
            var h = int.Parse (input[1]);
            var w = int.Parse (input[2]);
            var count = 0;
            for (var i = 0; i < n; i++)
            {
                input = Console.ReadLine ().Split (' ');
                if (int.Parse (input[0]) >= h && int.Parse (input[1]) >= w)
                    count++;
            }
            Console.WriteLine (count);
        }
    }
}

Measured memory_bytes: 13140
#include<bits/stdc++.h>
using namespace std;
int main(){
    int h,w;
    cin >> h >> w;
    vector<string> board(50);

    int dx[8] = {1,0,-1,0,1,-1,-1,1};
    int dy[8] = {0,1,0,-1,1,1,-1,-1};
    for(int i = 0; i < h; i++){
        cin >> board[i];
    }

    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            if(board[i][j] == '#') continue;

            int num = 0;
            for(int d = 0; d < 8; d++){
                int ni = i + dy[d];
                int nj = j + dx[d];

                if(ni < 0 || h <= ni) continue;
                if(nj < 0 || w <= nj) continue;
                if(board[ni][nj] == '#') num++;
            }
            board[i][j] = char(num + '0');
        }
    }
    for(int i = 0; i < h; i++)
    cout << board[i] << endl;
    }

Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
  int n,k,ans;
  scanf("%d%d",&n,&k);
  if(n%k==0)
    {
      ans = 0;
    }
  else
    {
      ans = 1;
    }
  printf("%d\n",ans);
  return 0;
}


Measured memory_bytes: 256
n = int(input())
T = []
s = 0
for _ in range(n):
    a, b = list(map(int, input().split()))
    T.append((a, b))
    s += a
T = sorted(T, key=lambda x: x[1])[::-1]
f = 0
for i, (a, b) in enumerate(T):
    if b < s:
        f = 1
        break
    s -= a
if f == 0:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 77024
N,M = map(int,input().split())
a = []
for _ in range(N):
    a.append(list(map(int,input().split())))
a.sort()
count = 0
for i in range(N):
    count += a[i][1]
    if count >= M:
        ans = a[i][0]
        break
print(ans)

Measured memory_bytes: 27872
from heapq import heappop, heappush


def solve(n, a, b, c, d):
    q = [(0, n)]
    checked = set()
    ans = n * d + 1
    while q:
        cost, x = heappop(q)
        if cost >= ans:
            break
        if x in checked:
            continue
        checked.add(x)
        ans = min(ans, cost + d * x)
        if x == 0:
            continue

        div, mod = divmod(x, 2)
        if mod == 0:
            if div not in checked:
                heappush(q, (cost + a, div))
        else:
            if div not in checked:
                heappush(q, (cost + a + d, div))
            if div + 1 not in checked:
                heappush(q, (cost + a + d, div + 1))

        div, mod = divmod(x, 3)
        if mod == 0:
            if div not in checked:
                heappush(q, (cost + b, div))
        else:
            if div not in checked:
                heappush(q, (cost + b + mod * d, div))
            if div + 1 not in checked:
                heappush(q, (cost + b + (3 - mod) * d, div + 1))

        div, mod = divmod(x, 5)
        if mod == 0:
            if div not in checked:
                heappush(q, (cost + c, div))
        else:
            if div not in checked:
                heappush(q, (cost + c + mod * d, div))
            if div + 1 not in checked:
                heappush(q, (cost + c + (5 - mod) * d, div + 1))

    return ans


t = int(input())
for _ in range(t):
    n, a, b, c, d = map(int, input().split())
    print(solve(n, a, b, c, d))


Measured memory_bytes: 11124
//------------------------------------------------------------------------------MANAS UNIYAL---------------------------------------------------------
//																				NEVER GIVE UP
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);	cin.tie(NULL);	cout.tie(NULL);
#define ll long long
#define pb push_back
#define fi first
#define se second
#define pii pair<ll,ll>
#define INF 0x3f3f3f3f
#define mod 1000000007
#define testcases() int t; cin>>t; while(t--)
#define debug1(x) cout<<#x<<" "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<"\n";
 //----------------------------------------------------------------------------------------------------------------------------------------------------

int main()
{
	fast;
	int n,d;
	cin>>n>>d;
	int ans=n/(2*d+1);
	if(n%(2*d+1))
		ans++;
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
from itertools import combinations

EPS = 1e-8

N, K, *XYC = map(int, open(0).read().split())
PC = [(complex(x, y), c) for x, y, c in zip(*[iter(XYC)] * 3)]


def intersection(A, r, B, s):
    D = B - A
    d = abs(D)

    cos_t = (d * d + r * r - s * s) / (2 * d * r)
    sin_t = max(1 - cos_t * cos_t, 0.0) ** 0.5

    R = r * complex(cos_t, sin_t)
    D /= d

    return (
        A + D * R,
        A + D * R.conjugate(),
    )


def is_ok(T):
    A = [p for p, _ in PC]
    for (p1, c1), (p2, c2) in combinations(PC, 2):
        A += intersection(p1, T / c1, p2, T / c2)

    for a in A:
        cnt = 0
        for p, c in PC:
            if c * abs(a - p) <= T + EPS:
                cnt += 1
        if K <= cnt:
            return True
    return False


ng, ok = 0, 1000000
for _ in range(100):
    md = (ng + ok) / 2
    if is_ok(md):
        ok = md
    else:
        ng = md

print(ok)

Measured memory_bytes: 49244
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
typedef long long LL;

int main() {
  string S; cin >> S;
  map<char, int> m;
  for (char c : S) m[c]++;

  if (m['a'] == 1 && m['b'] == 1 && m['c'] == 1) cout << "Yes" << endl;
  else                                           cout << "No" << endl;
}


Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

bool isPrime[100000];

int main(){
    fill(isPrime,isPrime+100000,true);
    isPrime[0]=isPrime[1]=false;
    for(int i=2;i<100000;i++){
        if(isPrime[i])
        for(int k=2;i*k<100000;k++) isPrime[i*k]=false;
    }
    vector<double> P;
    for(int i=2;i<100000;i++){
        if(isPrime[i]) P.push_back(i);
    }
    double m,a,b;
    while(cin>>m>>a>>b,m){
        double ans = 0, ans_p = 0, ans_q = 0;
        for(double q:P){
            if(q>=m)continue;
            double p;
            if(q*q<=m){
                p = *lower_bound(P.rbegin(),P.rend(),q,greater<double>());
            }else{
                p = *lower_bound(P.rbegin(),P.rend(),m/q,greater<double>());
            }
            if(p<a/b*q) continue;
            else{
                if(ans<p*q){
                    ans=p*q;
                    ans_p = p;
                    ans_q = q;
                }
            }
        }
        cout<<int(ans_p)<<' '<<int(ans_q)<<endl;
    }
}

Measured memory_bytes: 3432
#include <bits/stdc++.h>
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); i++) 
#define FOR(i, a, b) for(int (i) = a; (i) < (int)b; i++)
#define RREP(i, n) for(int (i)=((int)(n)-1); (i)>=0; i--)
#define RFOR(i, a, b) for(int (i) =((int)(b)-1); (i)>=(int)a; i--)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define FT first
#define SC second

using namespace std ;
typedef long long ll;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef pair<int, int> pint;
const int INF = 1e9;
const double EPS = 1e-9;



int main()
{
    int a, b ;
    cin >> a >> b ;
    
    if(a==b){
        cout << "a == b" <<endl ;
    }
    else if(a<b){
        cout << "a < b" <<endl ;
    }
    else{
        cout <<"a > b"<<endl ;
    }
    
    

  return 0 ;
}


Measured memory_bytes: 3112
#include<iostream>
#include<algorithm>
using namespace std;
long n,a[200000],x,y;
main()
{
	cin>>n;
	for(int i=0;i<n;x+=a[i++])cin>>a[i];
	x-=a[n-1],y+=a[n-1];
	long ans=abs(x-y);
	for(int i=n-1;--i;)
	{
		y+=a[i];x-=a[i];
		ans=min(ans,abs(x-y));
	}
	cout<<ans<<endl;
}


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

using namespace std;

#define F first
#define S second
#define modulo ll (1e9 + 7)

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

void init(){
    cin.tie(0);
    cin.sync_with_stdio(0);
}

const int N = 10, M = 2e3 + 9, OO = 0x3f3f3f3f;
const ll llOO = 0x3f3f3f3f3f3f3f3f;

int adjMat[N][N];

int main(){
    init();

    int n, m;   cin >> n >> m;
    for(int i = 0;i < m;i++){
        int u, v;   cin >> u >> v;  --u, --v;
        adjMat[u][v] = adjMat[v][u] = 1;
    }


    int path[n - 1];
    for(int i = 0;i < n - 1;i++)    path[i] = i + 1;

    int ans = 0;
    do{
        int ok = 1;
        if(!adjMat[0][path[0]])  continue;
        for(int i = 0;i < n - 2;i++){
            int u = path[i];
            int v = path[i + 1];
            if(!adjMat[u][v])   ok = 0;
        }
        ans += ok;
    }while(next_permutation(path, path + n - 1));

    cout << ans;
}

Measured memory_bytes: 256
N,A,B,C = map(int,input().split())
q = [input() for i in range(N)]
d = {'A':A,'B':B,'C':C}
ans = []
possible = True
for i in range(N):
    x = q[i][0]
    y = q[i][1]
    z = [s for s in 'ABC' if s!=x and s!=y][0]
    if d[x]>d[y]:
        ans.append(y)
        d[x] -= 1
        d[y] += 1
    elif d[x]<d[y]:
        ans.append(x)
        d[x] += 1
        d[y] -= 1
    else:
        if d[x]==1 and d[y]==1 and d[z]==0:
            if i==N-1 or q[i+1]==q[i]:
                ans.append(x)
                d[x] += 1
                d[y] -= 1
            elif x in q[i+1]:
                ans.append(x)
                d[x] += 1
                d[y] -= 1
            else:
                ans.append(y)
                d[y] += 1
                d[x] -= 1
        elif d[x]==0 and d[y]==0:
            possible = False
        else:
            ans.append(x)
            d[x] += 1
            d[y] -= 1

if possible:
    print('Yes')
    for i in range(N):
        print(ans[i])
else:
    print('No')

Measured memory_bytes: 88416
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  int c=0,p=0;
  while(cin>>s){p++;
    for(int i=0;i<=s.size()/2;i++){
      if(s[i]!=s[s.size()-1-i]){c++;break;}
    }
  }cout<<p-c<<endl;
}

Measured memory_bytes: 3140
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define MP make_pair
#define PB push_back
#define ll long long
#define int long long
#define f(i,x,n) for(int i=x;i<n;i++)
#define ld long double
const int mod=1000000007;
const int INF=1e18;

int a[200005];
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,k,an=0;
    cin>>k>>n;
    f(i,0,n)
    {
        cin>>a[i];
    }
    f(i,0,n-1)
    {
        an=max(an,a[i+1]-a[i]);
    }
    an=max(a[0]-a[n-1]+k,an);
    cout<<k-an<<endl;
    return 0;
}

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

using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define REP(i, l, n) for(int i=(l), i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back

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

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

char alpha[26] = {'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'};

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

int main(){
    string s; cin >> s;
    ll sum = 0;
    REP(i, 0, s.size()){
        sum += (s[i] - '0');
    }
    if(sum % 9 == 0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3720
N = int(input())
mins = float("inf")
summ = 0

for i in range(N):

    s = int(input())
    summ += s

    if s % 10 != 0:

        mins = min( mins , s )

if summ % 10 != 0:
    print (summ)

else:
    print (max( 0 , summ - mins) )


Measured memory_bytes: 2940
import sys
from math import log10

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 19
MOD = 10 ** 19 + 7
EPS = 10 ** -10

def bisearch_min(mn, mx, func):
    ok = mx
    ng = mn
    while ng+1 < ok:
        mid = (ok+ng) // 2
        if func(mid):
            ok = mid
        else:
            ng = mid
    return ok

def mat_pow(mat, init, K, MOD):
    """ 行列累乗 """

    def mat_dot(A, B, MOD):
        """ 行列の積 """

        if not isinstance(A[0], list) and not isinstance(A[0], tuple):
            A = [A]
        if not isinstance(B[0], list) and not isinstance(A[0], tuple):
            B = [[b] for b in B]
        n1 = len(A)
        n2 = len(A[0])
        _ = len(B)
        m2 = len(B[0])
        res = list2d(n1, m2, 0)
        for i in range(n1):
            for j in range(m2):
                for k in range(n2):
                    res[i][j] += A[i][k] * B[k][j]
                    res[i][j] %= MOD
        return res

    def _mat_pow(mat, k, MOD):
        """ 行列matをk乗する """

        n = len(mat)
        res = list2d(n, n, 0)
        for i in range(n):
            res[i][i] = 1
        while k > 0:
            if k & 1:
                res = mat_dot(res, mat, MOD)
            mat = mat_dot(mat, mat, MOD)
            k >>= 1
        return res

    res = _mat_pow(mat, K, MOD)
    res = mat_dot(res, init, MOD)
    return [a[0] for a in res]

L, a, b, M = MAP()

A = [0] * 20
for i in range(1, 20):
    x = 10 ** i
    res = bisearch_min(-1, L, lambda m: ceil(x-a, b)-1 < m)
    A[i] = res
C = [0] * 20
for i in range(1, 20):
    C[i] = A[i] - A[i-1]

init = [0, a, 1]
for d in range(1, 20):
    K = C[d]
    if K == 0:
        continue
    mat = [
        [pow(10, d, M), 1, 0],
        [0, 1, b],
        [0, 0, 1],
    ]
    res = mat_pow(mat, init, K, M)
    init[0] = res[0]
    init[1] = res[1]
ans = res[0]
print(ans)

# dp0 = [0] * (L+1)
# dp1 = [0] * (L+1)
# dp0[0] = 0
# dp1[0] = a
# for i in range(1, L+1):
#     dp0[i] = (dp0[i-1]*pow(10, int(log10(dp1[i-1]))+1, M) + dp1[i-1]) % M
#     dp1[i] = dp1[i-1] + b
# ans = dp0[-1]
# print(ans)


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

using namespace std;
int main()
{
    int a,b;
    cin>>a>>b;
    if(a<=b)
        cout<<"1"<<endl;
    else
    {
        if(a%b==0)
            cout<<a/b;
        else
            cout<<a/b+1;
    }

   return 0;
}


Measured memory_bytes: 3608
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<string>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<stack>
#include<algorithm>
#include<ctime>
#define RG register
#define file(x) freopen(x".in","r",stdin);freopen(x".out","w",stdout);
using namespace std;

inline int gi(){
    RG int data=0,w=1;
    RG char ch=0;
    while(ch!='-'&&(ch>'9'||ch<'0')) ch=getchar();
    if(ch=='-') w=-1,ch=getchar();
    while(ch>='0'&&ch<='9') data=(data<<1)+(data<<3)+(ch^48),ch=getchar();
    return w*data;
}
string s,goal;
map<string,int> S;
int a[10];

inline void BFS(){
	queue<string> Q1;queue<int> Q2;
	S.clear();
	Q1.push(goal),Q2.push(0);
	S[goal]=1;
	while(!Q1.empty()){
		int t=Q2.front();RG string str=Q1.front();
		Q1.pop(),Q2.pop();
		int x;
		for(RG int i=0;i<=7;i++) if(str[i]==0){x=i;break;}
		switch(x){
		case 0:
			swap(str[0],str[4]);if(!S[str]) Q1.push(str),Q2.push(t+1),S[str]=t+1;swap(str[0],str[4]);
			swap(str[0],str[1]);if(!S[str]) Q1.push(str),Q2.push(t+1),S[str]=t+1;swap(str[0],str[1]);
			break;
		case 1:
			swap(str[1],str[0]);if(!S[str]) Q1.push(str),Q2.push(t+1),S[str]=t+1;swap(str[1],str[0]);
			swap(str[1],str[2]);if(!S[str]) Q1.push(str),Q2.push(t+1),S[str]=t+1;swap(str[1],str[2]);
			swap(str[1],str[5]);if(!S[str]) Q1.push(str),Q2.push(t+1),S[str]=t+1;swap(str[1],str[5]);
			break;
		case 2:
			swap(str[2],str[1]);if(!S[str]) Q1.push(str),Q2.push(t+1),S[str]=t+1;swap(str[2],str[1]);
			swap(str[2],str[6]);if(!S[str]) Q1.push(str),Q2.push(t+1),S[str]=t+1;swap(str[2],str[6]);
			swap(str[2],str[3]);if(!S[str]) Q1.push(str),Q2.push(t+1),S[str]=t+1;swap(str[2],str[3]);
			break;
		case 3:
			swap(str[3],str[2]);if(!S[str]) Q1.push(str),Q2.push(t+1),S[str]=t+1;swap(str[3],str[2]);
			swap(str[3],str[7]);if(!S[str]) Q1.push(str),Q2.push(t+1),S[str]=t+1;swap(str[3],str[7]);
			break;
		case 4:
			swap(str[4],str[0]);if(!S[str]) Q1.push(str),Q2.push(t+1),S[str]=t+1;swap(str[4],str[0]);
			swap(str[4],str[5]);if(!S[str]) Q1.push(str),Q2.push(t+1),S[str]=t+1;swap(str[4],str[5]);
			break;
		case 5:
			swap(str[5],str[4]);if(!S[str]) Q1.push(str),Q2.push(t+1),S[str]=t+1;swap(str[5],str[4]);
			swap(str[5],str[1]);if(!S[str]) Q1.push(str),Q2.push(t+1),S[str]=t+1;swap(str[5],str[1]);
			swap(str[5],str[6]);if(!S[str]) Q1.push(str),Q2.push(t+1),S[str]=t+1;swap(str[5],str[6]);
			break;
		case 6:
			swap(str[6],str[5]);if(!S[str]) Q1.push(str),Q2.push(t+1),S[str]=t+1;swap(str[6],str[5]);
			swap(str[6],str[2]);if(!S[str]) Q1.push(str),Q2.push(t+1),S[str]=t+1;swap(str[6],str[2]);
			swap(str[6],str[7]);if(!S[str]) Q1.push(str),Q2.push(t+1),S[str]=t+1;swap(str[6],str[7]);
			break;
		case 7:
			swap(str[7],str[3]);if(!S[str]) Q1.push(str),Q2.push(t+1),S[str]=t+1;swap(str[7],str[3]);
			swap(str[7],str[6]);if(!S[str]) Q1.push(str),Q2.push(t+1),S[str]=t+1;swap(str[7],str[6]);
			break;
   		}
	}
}

int main(){
	for(RG int i=0;i<=7;i++) goal.push_back(i);
	BFS();S[goal]=0;
	while(scanf("%d\n",&a[0])!=EOF){
		s.clear();s.push_back(a[0]);
		for(RG int i=1;i<=7;i++) a[i]=gi(),s.push_back(a[i]);
		printf("%d\n",S[s]);
	}
	return 0;
}



Measured memory_bytes: 5504
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=5e18;

int main() {
  ll n;
  cin >> n;
  vec a(n);
  for(ll i=0;i<n;i++) cin >> a[i];
  ll ans=0;
  for(ll i=0;i<n;i++) {
    ans+=a[i]-1;
  }
  cout << ans << endl;
}

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

using namespace std;
using ll = long long;
constexpr int mo = 1e9+7;
constexpr int  mod = mo;
constexpr int inf = 1<<30;
constexpr int mo2 = 998244353;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n;
    cin>>n;
    string str;
    cin>>str;
    int ret = 0;
    for(int i=0;i<n;++i){
        ret++;
        while(i+1<n and str[i] == str[i+1])i++;
    }
    cout << ret << endl;
    return 0;
}



Measured memory_bytes: 512
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using ll = long long;
using P = pair<int,int>;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}




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

    rep(i,N){
        if(T[i] == 'r') T[i] = 'p';
        else if(T[i] == 's') T[i] = 'r';
        else if(T[i] == 'p') T[i] = 's';
    }

    rep(i,N){
        if((i + K) < N && T[i] == T[i + K]){
            T[i + K] = 'n';
        }
    }

    int ans = 0;
    rep(i,N){
        if(T[i] == 'r') ans += R;
        if(T[i] == 's') ans += S;
        if(T[i] == 'p') ans += P;
    }   

    cout << ans << endl;

    return 0;
}
//Ctrl+Shift+Bでコンパイルと実行を行ってデバッグすること

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i <= b; ++i)
#define per(i, a, b) for (int i = a; i >= b; i--)
#define ll long long
#define mset(s, _) memset(s, _, sizeof s)
#define ALL(a) (a).begin(), (a).end()
using namespace std;

int main(void) {
  int K;
  string S;
  cin >> K;
  cin >> S;

  if (S.length() <= K) {
    cout << S << endl;
  } else {
    rep(i, 0, K - 1) { cout << S[i]; }
    cout << "...";
    cout << endl;
  }
  return 0;
}


Measured memory_bytes: 3604
odd=["R","U","D"]
even=["L","U","D"]
S=input()
i=0
for x in range(len(S)):
  if x%2==0 and S[x] in odd:
    i+=1
  elif x%2==1 and S[x] in even:
    i+=1
if i==len(S):
  print("Yes")
else:
  print("No")

Measured memory_bytes: 9016
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<typename T> inline bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T &a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U &u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U &u,const V... v){for(auto &e:u)fill_v<T>(e,v...);}

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

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

    ll n;
    cin >> n;
    auto d1 = enum_div(n);
    auto d2 = enum_div(n-1);
    int ans = 0;
    for (ll d : d1) {
        if (d == 1) continue;
        ll x = n;
        while (x != 0 && x % d == 0) x /= d;
        x %= d;
        if (x == 1) ans++;
    }
    ans += sz(d2) - 1;
    cout << ans << endl;
}


Measured memory_bytes: 3636
package main

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

var (
	N, X int
	a, c [2321]int
)

func readVariables() {
	N, X = nextInt(), nextInt()
	for i := 0; i < N; i++ {
		a[i] = nextInt()
		c[i] = a[i]
	}
}

func main() {
	readVariables()
	//Max N-1 rotations
	answer := 123456789012345678
	for i := 0; i < N; i++ {
		//max i rotation
		for k := 0; k < N; k++ {
			//update k cost
			// d := (N + k - i) % N
			c[k] = MinInt(c[k], a[(N+k-i)%N])
		}
		answer = MinInt(cSum()+X*i, answer)
	}
	fmt.Println(answer)
}

func cSum() int {
	answer := 0
	for i := 0; i < N; i++ {
		answer += c[i]
	}
	return answer
}

/* Template */

var scanner *bufio.Scanner

func init() {
	Max := 1001001
	scanner = bufio.NewScanner(os.Stdin)
	scanner.Buffer(make([]byte, 0, Max), Max)
	scanner.Split(bufio.ScanWords)
}

//nextInt converts next token from stdin and returns integer value.
//nextInt panics when conversion into an integer fails.
func nextInt() int {
	if !scanner.Scan() {
		panic("No more token.")
	}
	num, err := strconv.Atoi(scanner.Text())
	if err != nil {
		panic("nextInt(): cannot convert to int: " + scanner.Text())
	}
	return num
}

func nextStr() string {
	if !scanner.Scan() {
		panic("No more token.")
	}
	return scanner.Text()
}

// MinInt returns minimum argument
func MinInt(x, y int) int {
	if x < y {
		return x
	} else {
		return y
	}
}

//MaxInt returns maximum argument
func MaxInt(x, y int) int {
	if x < y {
		return y
	} else {
		return x
	}
}

//AbsInt returns |x| for x
func AbsInt(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

//ModPow calculates integer power with modulo operation
//if modulo <= 1, it powers w/o module operation
//if base < 0, return value might be negative too.
func ModPow(base, exponent, modulo int) (result int) {
	result = 1
	for exponent > 0 {
		if exponent%2 == 1 {
			result *= base
			if modulo > 1 {
				result %= modulo
			}
		}
		base *= base
		if modulo > 1 {
			base %= modulo
		}
		exponent /= 2
	}
	return
}

//Gcd
func Gcd(vals ...int) (result int) {
	if len(vals) == 0 {
		return
	}
	result = vals[0]
	for i := 1; i < len(vals); i++ {
		result = gcd(result, vals[i])
	}
	return
}

func gcd(x, y int) int {
	x, y = AbsInt(x), AbsInt(y)
	for y > 0 {
		x, y = y, x%y
	}
	return x
}

//Lcm
func Lcm(vals ...int) (result int) {
	if len(vals) == 0 {
		return
	}
	result = vals[0]
	for i := 1; i < len(vals); i++ {
		result = lcm(result, vals[i])
	}
	return
}

func lcm(x, y int) int {
	return x * y / gcd(x, y)
}


Measured memory_bytes: 768
#include<stdio.h>
#include<math.h>

#define MAX 200000
#define SENTINEL 2000000000

int L[MAX / 2 + 2], R[MAX / 2 + 2];

long merge(int A[], int n, int left, int mid, int right){
	int i, j, k;
	long cnt = 0;
	int n1 = mid - left;
	int n2 = right - mid;
	for(i = 0; i < n1; i++){
		L[i] = A[left + i];
	}
	for(i = 0; i < n2; i++){
		R[i] = A[mid + i];
	}
	L[n1] = SENTINEL;
	R[n2] = SENTINEL;
	i = 0;
	j = 0;
	for(k = left; k < right; k++){
		if( L[i] <= R[j]){
			A[k] = L[i++];
		}else{
			A[k] = R[j++];
			cnt += n1 - i;  // = mid + j - k - 1
		}
	}
	return cnt;
}

long mergeSort(int A[], int n, int left, int right){
	int mid;
	long v1, v2, v3;
	if(left + 1 < right){
		mid = (left + right) / 2;
		v1 = mergeSort(A, n, left, mid);
		v2 = mergeSort(A, n, mid, right);
		v3 = merge(A, n, left, mid, right);
		return v1 + v2 + v3;
	}else{
		return 0;
	}
}


int main(){
	int n;
	int val[MAX];
	
	scanf("%d",&n);
	for(int i = 0; i < n; i++){
		scanf("%d",&val[i]);
	}
	
	printf("%ld\n",mergeSort(val, n, 0, n));
	
	return 0;
}


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

using namespace std;

const int MAXN = 2e5 + 2;

vector <int> adj[MAXN];
long long dp[MAXN];

void dfs(int node, int parent){
	if(parent != -1){
		dp[node] += dp[parent];
	}
	for(int i : adj[node]){
		if(i == parent)continue;
		dfs(i, node);
	}
}

int main(){
	#ifdef EVAL
		freopen("input.txt", "r", stdin);
		//freopen("output.txt", "w", stdout);
	#endif
	int N, Q;
	cin >> N >> Q;
	for(int i = 1, a, b; i < N; i++){
		cin >> a >> b;
		adj[a].push_back(b);
		adj[b].push_back(a);
	}
	for(int i = 0; i < Q; i++){
		int node;
		long long value;
		cin >> node >> value;
		dp[node] += value;
	}
	dfs(1, -1);
	for(int i = 1; i <= N; i++){
		cout << dp[i] << " ";
	}
	return 0;
}

Measured memory_bytes: 24320
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // int64_t

#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) > (b) ? (b) : (a))

int get_int(void) {
  int num;
  scanf("%d", &num);
  return num;
}

int get_int2(int *a1, int *a2) {
  scanf("%d %d", a1, a2);
  return 0;
}

#define NUM_MAX 100

struct prod {
    int weight;
    int value;
};

#define RANGE_MAX 3
int main(void) {
    int num, ulimit;
    get_int2(&num, &ulimit);
    static struct prod prods[NUM_MAX];
    int i, j;
    for(i = 0; i < num; i++) {
        get_int2(&prods[i].weight, &prods[i].value);
    }
    int base = prods[0].weight;
    for(i = 0; i < num; i++) prods[i].weight -= base;

    int k, k0;
    // 100*100*(300) <= 3000000
    static int dp[NUM_MAX+1][NUM_MAX+1][RANGE_MAX*NUM_MAX+1];
    int mmax = RANGE_MAX*num;
    int ans = 0;
    for(k = 1; k <= 100; k++) {
        ulimit -= base;
        // too heavy
        if(ulimit < 0) break;
        memset(dp, 0, sizeof(int)*(NUM_MAX+1)*(NUM_MAX+1)*(RANGE_MAX*NUM_MAX+1));
        int ulim = min(ulimit, mmax);
        for(i = 1; i <= num; i++) {
            struct prod p = prods[i-1];
            for(k0 = 0; k0 <= k; k0++) {
                for(j = 0; j <= ulim; j++) {
                    dp[i][k0][j] = dp[i-1][k0][j]; // stay
                    if(j >= 1) dp[i][k0][j] = max(dp[i][k0][j], dp[i][k0][j-1]); // slide
                    if(j >= p.weight && k0 >= 1) {
                        dp[i][k0][j] = max(dp[i][k0][j], dp[i-1][k0-1][j-p.weight]+p.value);
                    }
                }
            }
        }
        ans = max(ans, dp[num][k][ulim]);
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 12160