akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long 
#define int ll
#define pb push_back
#define sz(i) (int)(i.size())
#define fi first
#define se second
#define ld long double
#define pii pair<int, int>
#ifdef ONLINE_JUDGE
#define endl '\n'
#endif
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = 1e9 + 7;
using namespace std;
#ifndef ONLINE_JUDGE
#define tr(...) {__l(__LINE__);__f(#__VA_ARGS__, __VA_ARGS__);}
inline void __l(int line) { cerr << "#" << line << ": "; }template <typename Arg1>
void __f(const char* name, Arg1&& arg1){cerr << name << " : " << arg1 << std::endl;}template <typename Arg1, typename... Args>void __f(const char* names, Arg1&& arg1, Args&&... args){const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);}
#else
#define tr(...)
#endif
template<class T> void smin(T& a, T val) {if (a > val) a = val;}template<class T> void smax(T& a, T val) {if (a < val) a = val;}template<typename T>inline std::ostream &operator << (std::ostream & os,const std::vector<T>& v){bool first = true;os << "[";for(auto i: v){if(!first)os << ", ";os << i;first = false;}return os << "]";}
const int N = 5*1e5 + 10;
// make sure N size is correctttt!!!!!!!!!

string s;
int d;

int si, dp[10000+10][100+10];

// 1 => tight
// 0 => restrictless

int dfs(int idx, int f, int rem){
   if(idx <= -1){
      return (rem == 0);
   }

   if(f == 0 and dp[idx][rem] != -1){
      return dp[idx][rem];
   }

   int lim = (f) ? (s[idx]-'0') : 9;
   int ans = 0;

   for (int i = 0; i <= lim; ++i)
   {
      int nf = ((s[idx]-'0') == i) ? f : 0;
      ans += dfs(idx-1, nf, (rem+i)%d);  
      ans %= mod;
   }

   if (f == 0)
      dp[idx][rem] = ans; 
   return ans;
}

int32_t main(){_
   cin>>s;
   cin>>d;
   memset(dp, -1, sizeof dp);

   si = sz(s);
   reverse(s.begin(), s.end());//MSB is on si-1

   cout<<(dfs(si-1,1,0)-1+mod)%mod;

   //make sure N size is correct!!!!!!!!!
   return 0;
}
/*
15545748545646573454135
100
*/

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

int n;
int p[20000];
int a[20000],b[20000];

void input(){
	int x;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>x;
		p[x-1]=i;
	}
}
void solve(){
	for(int i=0;i<n;i++){
		a[i]=(i+1)*30000;
		b[i]=999999999-(a[i]-p[i]);
	}
	
}

int main() {
	input();
	solve();
	for(int i=0;i<n-1;i++){
		cout<<a[i]<<" ";
	}
	cout<<a[n-1]<<endl;
	
	for(int i=0;i<n-1;i++){
		cout<<b[i]<<" ";
	}
	cout<<b[n-1]<<endl;
}

Measured memory_bytes: 896
import itertools 
n,m=map(int,input().split());l1=[];l2=[];ans=0
while len(l1)<n:
  if len(l1)==0:
    l1.append(2)
  else:
    l1.append(l1[-1]+2)
while len(l2)<m:
  if len(l2)==0:
    l2.append(1)
  else:
    l2.append(l2[-1]+2)
for i in list(itertools.combinations(l1+l2, 2)):
  if sum(i)%2==0:
    ans+=1
print(ans)

Measured memory_bytes: 9996
/*    特徴    */

/*    教訓    */

#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using ld  = long double;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
using pld = pair<ld, ld>;
const int INF=1e9+7;
const ll LINF=9223372036854775807;
const ll MOD=1e9+7;
const ld PI=acos(-1);
const ld EPS = 1e-10; //微調整用（EPSより小さいと0と判定など）

int ii() { int x; if (scanf("%d", &x)==1) return x; else return 0; }
long long il() { long long x; if (scanf("%lld", &x)==1) return x; else return 0; }
string is() { string x; cin >> x; return x; }
char ic() { char x; cin >> x; return x; }
void oi(int x) { printf("%d ", x); }
void ol(long long x) { printf("%lld ", x); }
void od_nosp(double x) { printf("%.15f", x); } // 古い問題用
void od(double x) { printf("%.15f ", x); }
// long doubleで受け取り、fをLfなどに変えて出力すると、変な数値が出る
// それをなんとかするには独自の出力を作らなければならなそう
void os(const string &s) { printf("%s ", s.c_str()); }
void oc(const char &c) { printf("%c ", c); }
#define o_map(v){cerr << #v << endl; for(const auto& xxx: v){cout << xxx.first << " " << xxx.second << "\n";}} //動作未確認
void br() { putchar('\n'); }

#define gcd __gcd //llは受け取らない C++17~のgcdと違うので注意
int lcm(int a, int b){return a / gcd(a, b) * b;}
#define begin_end(a) a.begin(),a.end() //sort(begin_end(vec));
#define REP(i,m,n) for(ll i=(ll)(m) ; i < (ll) (n) ; i++ )
#define rep(i,n) REP(i,0,n)
#define m_p(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define p_b push_back
#define SZ(x) ((int)(x).size) //size()がunsignedなのでエラー避けに

//4近傍（上下左右） rep(i, 2) にすると右・下だけに進む
vector<int> dx_4 = {1, 0, -1, 0};
vector<int> dy_4 = {0, 1, 0, -1};

// coutによるpairの出力（空白区切り）
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << " " << p.second << ")";}
// coutによるvectorの出力（空白区切り）
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i]; if (i < len - 1) s << " "; //"\t"に変えるとTabで見やすく区切る
  }
  return s;
}
// coutによる多次元vectorの出力（空白区切り）
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i] << endl;
  }
  return s;
}

//最大値、最小値の更新。更新したor等しければtrueを返す
template<typename T>
bool chmax(T& a, T b){return (a = max(a, b)) == b;}
template<typename T>
bool chmin(T& a, T b){return (a = min(a, b)) == b;}

// -------- template end - //


// - library ------------- //



// --------- library end - //


int main(){

  ll X, Y;
  cin >> X >> Y;

  rep(i, 100){
    rep(j, 100){
      if (i+j==X && i*2+j*4==Y){
        cout << "Yes" << endl;
        return 0;
      }

    }
  }
  cout << "No" << endl;

}

Measured memory_bytes: 3632
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            String s = in.next();
            s = s.replaceAll("BC", "D");

            long ans = 0;
            long ac = 0;
            for (char c : s.toCharArray()) {
                switch (c) {
                    case 'A':
                        ac++;
                        break;
                    case 'D':
                        ans += ac;
                        break;
                    default:
                        ac = 0;
                }
            }

            out.println(ans);
        }

    }

    static class FastScanner {
        private InputStream in;
        private byte[] buffer = new byte[1024];
        private int bufPointer;
        private int bufLength;

        public FastScanner(InputStream in) {
            this.in = in;
            this.bufPointer = 0;
            this.bufLength = 0;
        }

        private int readByte() {
            if (bufPointer >= bufLength) {
                if (bufLength == -1)
                    throw new InputMismatchException();

                bufPointer = 0;
                try {
                    bufLength = in.read(buffer);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }

                if (bufLength <= 0)
                    return -1;
            }
            return buffer[bufPointer++];
        }

        private static boolean isPrintableChar(int c) {
            return c >= 33 && c <= 126;
        }

        public String next() {
            StringBuilder sb = new StringBuilder();

            int b = readByte();
            while (!isPrintableChar(b))
                b = readByte();

            while (isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }

            return sb.toString();
        }

    }
}



Measured memory_bytes: 32284
S = input()

ans = len(S)// 2
if len(S) % 2 == 1:
    ans += 1

t = S[len(S)//2]
c = ans
for i in range(len(S)//2-1,-1,-1):
    if S[i] == S[c] and S[i] == t:
        ans += 1
        c += 1
    else:
        break
print(ans)


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

int N;
map<int, int> Count[2];
vector<pair<int, int>> Rank[2];

int main() {
  cin >> N;
  for (int i = 0; i < N / 2; ++i) {
    int v, w;
    cin >> v >> w;
    ++Count[0][v];
    ++Count[1][w];
  }
  for (int i = 0; i < 2; ++i) {
    for (auto kv : Count[i]) {
      Rank[i].push_back({N / 2 - kv.second, kv.first});
    }
    Rank[i].push_back({N / 2, -1});
    sort(Rank[i].begin(), Rank[i].end());
  }
  if (Rank[0][0].second != Rank[1][0].second) {
    cout << Rank[0][0].first + Rank[1][0].first << endl;
  } else {
    cout << min(Rank[0][0].first + Rank[1][1].first,
                Rank[0][1].first + Rank[1][0].first)
         << endl;
  }
  return 0;
}


Measured memory_bytes: 6136
#include <bits/stdc++.h>
const int INF = 1e9;
const int MO = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
const double EPS = 1e-10;
using namespace std;
#define COUT(v) cout<<(v)<<endl
#define CIN(n)  int(n);cin >> (n)
#define LCIN(n) LL(n);cin >> (n)
#define SCIN(n) string(n);cin >> (n)
#define YES(n) cout<<((n)? "YES" : "NO")<<endl
#define Yes(n) cout<<((n)? "Yes" : "No")<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) <<endl

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

#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(obj) (obj).begin(),(obj).end()

#define rt return
#define ENDL cout<<endl
#define MAXE(a,b) a=max(a,b)
#define MINE(a,b) a=min(a,b)
#define s second
#define f first

typedef string::const_iterator State;
class PalseError {};
class Edge{
public:
    LL 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;
    }
};
class SegTreeRMQ{
public:
    SegTreeRMQ(int N){
        init(N);
    }
    void init(int N){
        int s = 1;
        while(s < N){
            s*=2;
        }
        dat = std::vector<LL>(s * 2,1e9);
        n = s;
    }
    void update(int i,int x){
        i += n - 1;
        dat[i]= x;
        while(i > 0){
            i = (i-1) / 2;
            dat[i] = min(dat[i * 2 + 1],dat[i * 2 + 2]);
        }
    }
    //使う時は変数名.query(a,b,k,l,変数名getSize())
    //区間の左端(b)に注意+1しよう
    int query(int a,int b,int k,int l,int r){
        //  cout<<k<<endl;
        if(r <= a || b<= l)return 1e9;
        if(a <= l && r <= b)return dat[k];
        else{
            int vl = query(a,b,k * 2 + 1,l,(l+r)/2);
            int vr = query(a,b,k * 2 + 2,(l+r)/2,r);
            return min(vl,vr);
        }
    }
    int getSize(){
        return n;
    }
    void show(){
        for(int a = 0;a < 2*n;a++){
            cout<<dat[a]<<" ";
        }
        cout<<endl;
        return;
    }
private:
    int n;
    std::vector<LL> dat;
};
int main(){
    LL N,x;cin >> N >> x;
    SegTreeRMQ SegTree(N*2);
    vector<LL> vec;
    for(int a = 0;a < N;a++){
        LL b;cin >> b;
        vec.push_back(b);
        SegTree.update(a,b);
    }
    for(int a = 0;a < N;a++){
        vec.push_back(vec.at(a));
        SegTree.update(a+N,vec.at(a));
    }
    SegTree.query(0,2*N,0,0,SegTree.getSize());
 //   SegTree.show();
    LL ans = 1e18;
    for(int b = 0;b < N;b++){
        LL ins = b*x;
        for(int a = N;a < 2*N;a++){
            ins += SegTree.query(a-b,a+1,0,0,SegTree.getSize());
        }
        ans = min(ans,ins);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;typedef long long ll;typedef vector<ll> vl;typedef vector<vl> vvl;typedef pair<ll,ll> pl;typedef vector<pl> vp;const ll INF=1001001001;const ll LINF=1001001001001001001;const ll D4[]={0,1,0,-1,0};const ll D8[]={0,1,1,0,-1,-1,1,-1,0};template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
#define fore(i,a,b) for(ll i=(ll)(a);i<=(ll)(b);++i)
#define rep(i,n) fore(i,0,(n)-1)
#define all(x) (x).begin(),(x).end()

vl f(ll N){
    vl ret;
    if(N==1)return ret;
    ret.push_back(N);
    for(ll i=2;i*i<=N;i++){
        if(N%i==0){
            ret.push_back(i);
            if(i*i!=N)ret.push_back(N/i);
        }
    }
    return ret;
}
ll g(ll N,ll K){
    if(N%K==0)return g(N/K,K);
    else return N%K;
}
void solve(long long N){
    ll ans=f(N-1).size();

    vl res=f(N);
    for(ll x:res){
        if(g(N,x)==1)ans++;
    }
    cout<<ans<<endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    solve(N);
}


Measured memory_bytes: 384
#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 a,b,c,d;
  cin >> a >> b >> c >> d;
  a=max(a,c);
  b=min(b,d);
  if(b-a>0) cout << b-a << endl;
  else cout << 0 << endl;
}

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

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

using namespace std;
using ll = long long int;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using edge = struct
{
    int to, cost;
};

const int MOD = 1e9 + 7;
const int iINF = 1e9;
const long long int llINF = 1e18;
const double PI = acos(-1.0);

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

vector<int> graph[10000];

int h[100000];

int main()
{
    int V, E;
    cin >> V >> E;
    rep(i, E)
    {
        int s, t;
        cin >> s >> t;
        graph[s].push_back(t);
        h[t]++;
    }

    stack<int> st;

    rep(i, V) if (h[i] == 0) st.push(i);

    vector<int> ans;

    while (st.size())
    {
        int i = st.top();
        st.pop();
        ans.push_back(i);

        for (auto e : graph[i])
        {
            h[e]--;

            if (h[e] == 0)
                st.push(e);
        }
    }

    for (int i : ans)
        cout << i << endl;

    return 0;
}


Measured memory_bytes: 3792
#include <iostream>
#include <vector>
#include <unordered_map>
#include <deque>

typedef long long ll;


int main() {
    using namespace std;
    ll s;
    cin >> s;
    ll k = static_cast<ll>(sqrt(s));
    if(k * k == s){
        cout << "0 0 " << k << " 0 0 " << k << endl;
        return 0;
    }
    ++k;
    ll s2 = k * k;
    ll dif = s2 - s;
    ll l = 1;
    while (1){
        if(dif % l == 0 && dif / l < k){
            cout << "0 0 " << k << " " << l << " " << (dif / l) << " " << k << endl;
            return 0;
        }
        ++l;
    }
}

Measured memory_bytes: 888
n = int(input())
t, a = map(int,input().split())
h = list(map(int,input().split()))

min_k = 999999999999999999999999
for i in range(n):
    if abs(a - (t - h[i]*0.006)) < min_k:
        min_k = abs(a - (t - h[i]*0.006))
        min_index = i

print(min_index+1)


Measured memory_bytes: 3060
import fractions
n, m = map(int, input().split())
s = input()
t = input()
g = fractions.gcd(n, m)
r = (m*n)//g
n, m = n//g, m//g
for i in range(g):
    if s[i*n] != t[i*m]: r = False
if r: print(r)
else: print(-1)

Measured memory_bytes: 5432
// choices and belief 

#include <bits/stdc++.h>
using namespace std;
const int N = 1234567;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef priority_queue<pii, vector<pii>, greater<pii>> min_pq;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define whatis(x) cout << #x << " is " << x << endl;
#define inf 1e18
vector<int>g[N];
int timer=1,tin[1<<20],tout[1<<20],vis[1<<20],low[1<<20];
int bridges=0;
void dfs(int n,int p)
{
	vis[n]=1;
	tin[n]=timer;
	low[n]=timer;
	timer++;
	for(int next : g[n])
	{
		if(!vis[next])
		{
			dfs(next,n);
			low[n]=min(low[n],low[next]);
			// bridge condition
			if (low[next] > tin[n])
             {
             	bridges++;
              // cout << n <<" " << next << endl;
             }
		}
		else if(next!=p)
			low[n]=min(low[n],tin[next]);
	}
	// tout[n]=timer;
	// ++timer;
}

int main()
{
	ios_base:: sync_with_stdio(false); cin.tie(0);
	// freopen ("inp","r",stdin);
	// freopen ("out","w",stdout);
	int n,m,a,b;
	cin>>n>>m;
	for(int i=0;i<m;i++)
	{
		cin>>a>>b;
		g[a].pb(b);g[b].pb(a);
	}
	dfs(1,0);
	cout<<bridges<<endl;
	return 0;
}

Measured memory_bytes: 33280
N,M=map(int,input().split())
a=[0]
for _ in range(M):
    a.append(int(input()))

b=[]
num=0
if len(a)>1:
    b.append(a[1]-a[0]-1)
    for i in range(1,M):
            b.append(a[i+1]-a[i]-2)
    b.append(N-a[M]-1)
else:
    b.append(N)

num=max(b)

mod=1000000007

fib=[0 for i in range(num+10)]
fib[0]=1
fib[1]=1
for i in range(2,num+1):
    fib[i]=fib[i-1]+fib[i-2]

if -1 in b:
    print(0)
else:
    p=1
    for j in range(M+1):
        p*=fib[b[j]]
    print(p%mod)

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

#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
#define pi 3.14159265359
#define shosu(X) fixed << setprecision(X)
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 h,w;
char data[100][100];
int num[100];
int main(){
	cin >> h >> w;
	REP(i, 100) num[i] = 0;
	REP(i, h){
		string s;
		cin >> s;
		REP(j, w){
			data[i][j] = s[j];
			num[s[j] - 'a']++;
		}
	}
	//gu gu
	if(h%2 == 0 && w%2 == 0){
		bool res = true;
		REP(i, 26) if(num[i]%4 != 0) res = false;
		if(res){
			cout << "Yes" << endl;
			return 0;
		}else{
			cout << "No" << endl;
			return 0;
		}
	}
	//ki ki
	if(h%2 != 0 && w%2 != 0){
		bool flag = true;
		int kisunum = 0;
		REP(i, 26){
			if(num[i]%2 != 0){
				kisunum++;
				num[i]--;
			} 
		} 
		if(kisunum != 1) flag = false;
		int tmp = 0;
		REP(i, 26){
			tmp += num[i]/4;
		}
		if(flag && tmp >= ((h-1)/2)*((w-1)/2)){
			cout << "Yes" << endl;
			return 0;
		}
		cout << "No" << endl;
		return 0;
	}
	//gu ki
	if(h%2 == 0 && w%2 != 0){
		//そもそも全部偶数じゃないと
		bool flag = true;
		REP(i, 26) if(num[i]%2!=0) flag = false;
		if(flag == false){
			cout << "No" << endl;
			return 0;
		}
		int tmp = 0;
		REP(i, 26){
			tmp += num[i]/4;
		}
		if(tmp >= ((w-1)/2)*(h/2)){
			cout << "Yes" << endl;
			return 0;
		}
		cout << "No" << endl;
		return 0;
	}
	//ki gu
	if(h%2 != 0 && w%2 == 0){
		//そもそも全部偶数じゃないと
		bool flag = true;
		REP(i, 26) if(num[i]%2!=0) flag = false;
		if(flag == false){
			cout << "No" << endl;
			return 0;
		}
		int tmp = 0;
		REP(i, 26){
			tmp += num[i]/4;
		}
		if(tmp >= ((h-1)/2)*(w/2)){
			cout << "Yes" << endl;
			return 0;
		}
		cout << "No" << endl;
		return 0;
	}
}





Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <set>
#include <array>
#include <string>
#include <map>
#include <cmath>
using namespace std;

#define DB(x)
#define rep(i, n) for(int i = 0;i < n;i++)


int getIntSp(){
    string str;
    getline(cin,str,' ');
    return stoi(str);
}

int getIntLF(){
    string str;
    getline(cin,str);
    return stoi(str);
}


int main() {
    int r;
    cin >> r;
    cout << r*r << endl;

}


Measured memory_bytes: 256
from bisect import bisect_left
from itertools import accumulate

N, M = map(int, input().split())
A = sorted(list(map(int, input().split())))
A_rev = list(reversed(A))
B = [0] + list(accumulate(A_rev))

def func(x):
    count = 0
    for Ai in A:
        idx = bisect_left(A, x - Ai)
        count += N - idx
    if count >= M:
        return True
    else:
        return False

min_ = 0
max_ = 2 * 10 ** 5 + 1
while max_ - min_ > 1:
    mid = (min_ + max_) // 2
    if func(mid):
        min_ = mid
    else:
        max_ = mid

ans = 0
count = 0
for Ai in A_rev:
    idx = bisect_left(A, min_-Ai)
    ans += Ai * (N - idx) + B[N-idx]
    count += N-idx
print(ans-(count-M)*min_)


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

int main() {
  int A, B, C; cin >> A >> B >> C;
  int per_week;
  per_week = A * 7 + B;
  
  int week = C / per_week;
  int remain = C % per_week;

  int day = 0;
  int cou = 0;
  
  while (remain > 0) {
      remain -= A;
      day++;
      cou++;
    if (cou == 7) {
      remain -= B;
      cou = 0;
    }
  }
  
  int count = week * 7 + day;
  
  cout << count << endl;
  
  return 0;
}


Measured memory_bytes: 3100
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define REVETSE(c) reverse((c).begin(),(c).end())
#define SUM(c) accumulate((c).begin(),(c).end(),0)
#define ALL(a)  (a).begin(),(a).end()
// int gcd(int a,int b){return b?gcd(b,a%b):a;}
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> T maxt(T x,T y) {
    if (x>y) return x;
    else return y;
}
template<class T> T mint(T x,T y) {
    if (x>y) return y;
    else return x;
}
//sort(v.rbegin(), v.rend(), [](auto& x, auto& y){return x[1] < y[1];});
//cout << fixed << setprecision(10) << ans << defaultfloat << endl;
typedef long long ll;
typedef vector<int> Vi;
typedef vector<ll> Vl;
typedef vector<double> Vd;
typedef vector<string> Vs;

/* //約数列挙
vector< int64_t > divisor(int64_t n) {
  vector< int64_t > ret;
  for(int64_t i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}*/

int main() {
  ll N, mod = 1e9+7, ans=0, c, f=1;
  Vl cv;
  cin >> N;
  REP(i,N) {
    cin >> c;
    cv.push_back(c);
    }
  SORT(cv);
  REP(i,N) {
    ans = (cv[i]*(2+N-i-1)%mod+ans)%mod;
    if (i>0) f = f*4%mod;
  }
  ans = ans*f%mod;
  cout << ans << endl;
}

Measured memory_bytes: 2420
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std;

long long cnt=0;
int l;
int A[1000000];
int n;
vector<int> G;

//??????g???insertionSort
void insertionSort(int A[],int n,int g){
    for(int i=g;i<n;i++){
        int v=A[i];
        int j=i-g;
        while(j>=0 && A[j]>v){
            A[j+g]=A[j];
            j-=g;
            cnt++;
        }
        A[j+g]=v;
    }
}

void shellSort(int A[],int n){
    //??°???G?????????
    for(int h=1;h<=n;){
        G.push_back(h);
        h=3*h+1;
    }
    //?????????G[i]?????????
    for(int i=G.size()-1;i>=0;i--){
        insertionSort(A,n,G[i]);
    }
}

int main(void){
    scanf("%d",&n);
    for(int i=0;i<n;i++)scanf("%d",&A[i]);
    
    shellSort(A,n);
    printf("%d\n",G.size());
    for(int i=G.size()-1;i>=0;i--){
        printf("%d",G[i]);
        if(i)printf(" ");
    }
    printf("\n");
    printf("%d\n",cnt);
    for(int i=0;i<n;i++)printf("%d\n",A[i]);
    
    return 0;
}

Measured memory_bytes: 6592
/* attention to overflow */
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstdio>
#include <queue>
#include <sstream>
#include <set>
#include <map>
#define dump(x) cerr<< #x << " = " << x <<endl

using namespace std;
const int INF=1<<25;
void io(){ cin.tie(0);ios::sync_with_stdio(false);}
/*printf("%.9Lf\n",cf);*/
const int MOD=1000000007;

class UnionFind{
private:
	vector<int> data;
	int _groups;
public:
	int n;
	UnionFind(int n) : data(n, -1), _groups(n), n(n) { }

	void unite(int x, int y){
		x = root(x), y = root(y);
		if (x != y){
			--_groups;
			if (data[x] > data[y])
				swap(x, y);
			data[x] += data[y];
			data[y] = x;
		}
	}
	bool same(int x, int y) { return root(x) == root(y); }
	int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); }
	int size(int x) { return -data[root(x)]; }
	int groups() const { return _groups; }
};


int main(){
	io();
	int n;
	scanf("%d",&n);
	UnionFind uf(n);
	map <string,pair<int,int> > alt;
	map <int,int> val;
	for(int i=0;i<n;i++){
		char s[20];
		int x;
		scanf("%s %d",s,&x);
		alt[s]=make_pair(i,x);
		val[i]=x;
	}
	int m;
	scanf("%d",&m);
	for(int i=0;i<m;i++){
		char s[20];
		char t[20];
		scanf("%s %s",s,t);
		uf.unite(alt[s].first,alt[t].first);
	}
	pair <int,int> a[5010];
	fill_n(a,5001,make_pair(1<<30,0));
	for(auto it:val){
		a[uf.root(it.first)].first=min(it.second,a[uf.root(it.first)].first);
		a[uf.root(it.first)].second++;
	}
	long long sum=0;
	for(int i=0;i<n;i++){
		sum+=a[i].first*a[i].second;
	}
	cout<<sum<<endl;


	return 0;
}

Measured memory_bytes: 2100
//Changing a Character
#include <bits/stdc++.h>
using namespace std;

int main(){
    int N,K;
    string S;
    cin>>N>>K;
    cin>>S;
    S[K-1]-='A'-'a';
    for(int i=0;i<N;i++){
        printf("%c",S[i]);
    }
    puts("\n");
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<string>
#include<cstring>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<bitset>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;

#define PI 3.141592653589793238462643383279
#define mod 1000000007LL
#define rep(i, n) for(i = 0;i < n;++i)
#define rep1(i, n) for(i = 1;i < n;++i)
#define per(i, n) for(i = n - 1;i > -1;--i)
#define int(x) int x; scanf("%d",&x)
#define int2(x, y) int x, y; scanf("%d%d",&x, &y)
#define int3(x, y, z) int x, y, z; scanf("%d%d%d",&x, &y, &z)
#define int4(v, x, y, z) int v, x, y, z; scanf("%d%d%d%d", &v, &x, &y, &z)
#define int5(v, w, x, y, z) int v, w, x, y, z; scanf("%d%d%d%d%d", &v, &w, &x, &y, &z)
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define kabe puts("---------------------------")
#define kara puts("")
#define debug(x) cout << " --- " << (x) << "\n"
#define debug2(x, y) cout << " --- " << (x) << " " << (y) << "\n"
#define debug3(x, y, z) cout << " --- " << (x) << " " << (y) << " " << (z) << "\n"
#define X first
#define Y second
#define eps 0.0001
#define prid(x) printf("%.15lf\n", x)

void dfs(ll n){
  ll i;
  if(n == 0)return;
  rep(i, n + 1)if(i * (i + 1) / 2 >= n){
    printf("%lld\n", i);
    dfs(n - i);
    return;
  }
}

signed main(void){
  ll i, j;
  for(int testcase = 0;testcase >= 0;testcase++){
    ll n; cin >> n;
    dfs(n);



/*/

//*/ break;
  }
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
        //何個とるか
		long num = sc.nextLong();
		//青いボールの数
		long blue = sc.nextLong();
		//赤いボールの数
		long red = sc.nextLong();
		//赤+青が割り切れるか
        long n = num/(blue+red);
      	//赤+青の余り
        long amari=num%(blue+red);
      	//端数がマイナスの場合、amariを足した数を出力
      	if(amari - blue<=0){
         	 System.out.println(blue*n+amari);
        //端数がプラスの場合、青いボールの個数を足して出力
        }else{
             System.out.println(blue*(n+1));
        } 
	}
}

Measured memory_bytes: 21972
#include<stdio.h>
#include<algorithm>
using namespace std;
int main()
{
	int n,i,flg=0,x[200000];
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&x[i]);
	}
	sort(x,x+n);
	for(i=0;i<n-1;i++){
		if(x[i]==x[i+1]){
			flg=1;
		}
	}
	if(flg==1) printf("NO\n");
	else printf("YES\n");
	return 0;
}

Measured memory_bytes: 2424
N = int(input())
# 0が含まれない組み合わせ 9^N
# 9が含まれない組み合わせ 9^N
# 0も9も含まれない組み合わせ 8^N
# ベン図より、0か9どちらか少なくとも一方が存在しないような組み合わせは 9^N + 9^N - 8^N
# 全体の組み合わせは 10^N
# 答えは 10^N - 9^N - 9^N + 8^N
MAX = 10 ** 9 + 7
result = pow(10, N, MAX) - pow(9, N, MAX) - pow(9, N, MAX) + pow(8, N, MAX)

print(result % MAX)

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

double dist(vector<int> a, vector<int> b){
    double dist = 0;
    for(int i = 0; i < a.size(); i++){
        dist += (a[i] - b[i])*(a[i] - b[i]);
    }
    return sqrt(dist);
}

int main(){
    int n, d;
    cin >> n >> d;
    vector< vector<int> > x;
    for(int i = 0; i < n; i++){
        vector<int> y;
        for(int j = 0; j < d; j++){
            int a;
            cin >> a;
            y.push_back(a);
        }
        x.push_back(y);
    }
    
    int ans = 0;
    for(int i = 0; i < n; i++){
        for(int j = i+1; j < n; j++){
            double t = dist(x[i], x[j]); 
            if(ceil(t) == floor(t)){
                ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]

n=n0()
xy=n3(n)

import itertools,math
ite=itertools.combinations(range(n),2)
d=0
for i,j in ite:
    ax,ay=xy[i]
    bx,by=xy[j]
    d+=math.sqrt((ax-bx)**2+(ay-by)**2)
    
print(2*d/n)

Measured memory_bytes: 3064
#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

//#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

typedef long long ll;
//typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector<vector<int>> mat;
//typedef unsigned int uint;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

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

	int N, K;
	pair<int, int> D;
	int mina = INF;
	int a;

	cin >> N >> K;
	K--;
	rep(i, 0, N)
	{
		cin >> a;
	}

	cout << (N+K-2)/K << endl;

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<cstdio>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cmath>
#include<vector>

#include<stack>
#include<queue>
#include<time.h>
#include<set>
#include<map>
#include <iomanip>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i>b;i--)
#define vint vector<int> 
#define vvint vector<vint>
#define ct(a) cout<<a<<endl
using namespace std;
typedef long long ll;
const int INF = 1e9 + 7;
const ll mod = 998244353;

string S;
ll r,D,x,ans;

int main() {
	

	cin >> r >> D >> x;
	FOR(i, 0, 10) {
		x = r * x - D;
		cout << x << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define W 1000

int main(){

  int A[W];
  int i,j,v,N;

  scanf("%d\n",&N);
  for(i = 0; i < N; i++){
    scanf("%d",&A[i]);
    printf("%d",A[i]);
    if(i != N-1)
      printf(" ");
    else printf ("\n");
  }
  
  for(i = 1; i < N; i++){
    v = A[i];
    j = i - 1;
    while(j >= 0 && A[j] > v){
      A[j + 1] = A[j];
      j--;
      A[j + 1] = v;
    }
    for(j = 0; j < N; j++){
      printf("%d",A[j]);
      if(j != N-1)
	printf(" ");
      else printf ("\n");
    }
  }

  return 0;
}

Measured memory_bytes: 608
#include <stdio.h>

int main(void)
{
    int number[10];
    int i, j, a, n;

    for (i = 0; i < 10; ++i)
        scanf("%d", &number[i]);
    for (i = 0; i < 10; ++i)
    {
        if(number[i]>=0&&number[i]<=10000)
        {
            for (j = i + 1; j < 10; ++j)
            {
                if(number[i] < number[j])
                {
                    a = number[i];
                    number[i] = number[j];
                    number[j] = a;
                }
            }
        }

    }
    for (i = 0; i < 3; ++i)
    {
        printf("%d\n", number[i]);
    }
    return 0;
}

Measured memory_bytes: 600
#include <float.h>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

// 内部定数
#define D_ARRAY_MAX		200000									// 最大配列数

// 内部変数
static FILE *szpFpI;											// 入力
static int si1Array[D_ARRAY_MAX];								// 配列
static int siACnt;												// 配列数

// 内部変数 - テスト用
#ifdef D_TEST
	static int siRes;
	static FILE *szpFpA;
	static int siTNo;
#endif

// １行出力
int
fOutLine(
	char *pcpLine				// <I> １行
)
{
	char lc1Buf[1024];

#ifdef D_TEST
	lc1Buf[0] = '\0';
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, pcpLine)) {
		siRes = -1;
	}
#else
	printf("%s", pcpLine);
#endif

	return 0;
}

// ソート関数 - int昇順
int
fSortFncIu(
	const void *pzpVal1			// <I> 値１
	, const void *pzpVal2		// <I> 値２
)
{
	int *lipVal1 = (int *)pzpVal1;
	int *lipVal2 = (int *)pzpVal2;

	// int昇順
	if (*lipVal1 > *lipVal2) {
		return 1;
	}
	else if (*lipVal1 < *lipVal2) {
		return -1;
	}

	return 0;
}

// 実行メイン
int
fMain(
)
{
	int i;
	char lc1Buf[1024];

	// 配列数 - 取得
	fgets(lc1Buf, sizeof(lc1Buf), szpFpI);
	sscanf(lc1Buf, "%d", &siACnt);

	// 配列 - 取得
	for (i = 0; i < siACnt; i++) {
		fscanf(szpFpI, "%d", &si1Array[i]);
	}
	fgets(lc1Buf, sizeof(lc1Buf), szpFpI);
	qsort(si1Array, siACnt, sizeof(int), fSortFncIu);

	// 比較
	for (i = 1; i < siACnt; i++) {
		if (si1Array[i] == si1Array[i - 1]) {
			return -1;
		}
	}

	return 0;
}

// １回実行
int
fOne(
)
{
	int liRet;
	char lc1Buf[1024];

	// 入力 - セット
#ifdef D_TEST
	sprintf(lc1Buf, ".\\Test\\T%d.txt", siTNo);
	szpFpI = fopen(lc1Buf, "r");
	sprintf(lc1Buf, ".\\Test\\A%d.txt", siTNo);
	szpFpA = fopen(lc1Buf, "r");
	siRes = 0;
#else
	szpFpI = stdin;
#endif

	// 実行メイン
	liRet = fMain();

	// 出力
	if (liRet == 0) {
		sprintf(lc1Buf, "YES\n");
	}
	else {
		sprintf(lc1Buf, "NO\n");
	}
	fOutLine(lc1Buf);

	// 残データ有無
#ifdef D_TEST
	lc1Buf[0] = '\0';
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, "")) {
		siRes = -1;
	}
#endif

	// テストファイルクローズ
#ifdef D_TEST
	fclose(szpFpI);
	fclose(szpFpA);
#endif

	// テスト結果
#ifdef D_TEST
	if (siRes == 0) {
		printf("OK %d\n", siTNo);
	}
	else {
		printf("NG %d\n", siTNo);
	}
#endif

	return 0;
}

// プログラム開始
int
main()
{

#ifdef D_TEST
	int i;
	for (i = D_TEST_SNO; i <= D_TEST_ENO; i++) {
		siTNo = i;
		fOne();
	}
#else
	fOne();
#endif

	return 0;
}



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

int main() {
  string str;
  int q;
  cin >> str >> q;

  string command;
  int a, b;
  for (int i = 0; i < q; i++) {
    cin >> command >> a >> b;
    if (command == "print") {
      cout << str.substr(a, b - a + 1) << endl;
    } else if (command == "reverse") {
      string tmp = str.substr(a, b - a + 1);
      for (int j = 0; j < tmp.size(); j++) {
        str[b - j] = tmp[j];
      }
    } else {
      string p;
      cin >> p;
      for (int j = 0; j < p.size(); j++) {
        str[a + j] = p[j];
      }
    }
  }

  return 0;
}


Measured memory_bytes: 3208
N,M = map(int,input().split())

S = []
for i in range(N):
  S.append(list(map(int,input().split())))

C = []
for i in range(M):
  C.append(list(map(int,input().split())))

def MD(P1,P2):
  return (abs(P1[0]-P2[0])+abs(P1[1]-P2[1]))

for i in range(N):
  Min_D = int(10e10)
  for j in range(M):
    D = MD(S[i],C[j])
    if Min_D > D:
      Min_D = D
      P = j+1
  print(P)

Measured memory_bytes: 3064
from itertools import zip_longest

while True:
    n = int(input())
    if not n:
        break
    field = [list(map(int, input().split())) for _ in range(n)]
    field.reverse()
    score = 0
    while True:
        no_more_disappear = True

        for y, row in enumerate(field):
            for i, stone in enumerate(row[:3]):
                if stone is None:
                    continue
                cnt = 1
                for stone2 in row[i + 1:]:
                    if stone != stone2:
                        break
                    cnt += 1
                if cnt >= 3:
                    row[i:i + cnt] = [None] * cnt
                    score += stone * cnt
                    no_more_disappear = False

        if no_more_disappear:
            break

        fieldT = map(lambda row: filter(None, row), zip(*field))
        field = list(map(list, zip_longest(*fieldT)))

    print(score)

Measured memory_bytes: 7928
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 200007;
int a[MAXN];

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

    int n;
    cin >> n;

    int x = 0;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        x ^= a[i];
    }

    for (int i = 1; i <= n; i++) {
        a[i] ^= x;
        cout << a[i] << " ";
    }

    return 0;
}


Measured memory_bytes: 4372
N=int(input())
L=list(map(int,input().split()))
D={}
for i in L:
    if i not in D:
        D[i]=1
    else:
        D[i]+=1

#print(D)

ans=0
for k,v in D.items():
    ans+=k*v
#print(ans)

Q=int(input())

for i in range(Q):
    a,b=map(int,input().split())
    if a not in D:
        print(ans)
        continue
    else:
        if b not in D:
            ans-=a*D[a]
            ans+=b*D[a]
            D[b]=D[a]
            
            D[a]*=0
            print(ans)
        else:
            ans-=a*D[a]
            ans+=b*D[a]
            D[b]+=D[a]
            D[a]*=0
            print(ans)


Measured memory_bytes: 85180
function myin(){return require("fs").readFileSync("/dev/stdin", "utf8").trim();}
function myout(t){console.log(t);}//standard output
//[no]param
//0:何もしない  1:数値へ変換  2:半角SPで分割  3:改行で分割  4:半角SPで分割し、数値配列へ
//5:改行で分割し、数値配列へ  6:1文字に分割  7:1文字に分割し、数値配列へ
function myconv(i,no){switch(no){case 0:return i;case 1:return parseInt(i);case 2:return i.split(" ");case 3:return i.split("\n");case 4:return i.split(" ").map((a)=>Number(a));case 5:return i.split("\n").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));}}

function Main(input) {
  input = myconv(input,4);
  var output = input[0] - input[1] * 2;
  if(output < 0){
     output = 0;
     }
  myout(output);
}

Main(myin());


Measured memory_bytes: 21064
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
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; }
#define DEBUG_VLL(vec) REP(sz, vec.size()) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n; cin >> n;
    ll ans = 0;
    for (ll i = 2; i * i <= n; i++) {
        if (n % i == 1) {
            if ((n - 1) / i == i) ans++;
            else ans += 2;
        } else if (n % i == 0) {
            ll orign = n;
            while (orign % i == 0) orign /= i;
            if (orign % i == 1) ans++;
        }
    }

    if (n == 2) ans++;
    else ans += 2;
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 256
import java.util.*;	
public class Main {
public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int A=sc.nextInt();
		int B=sc.nextInt();
		int wa=A+B;
		int sa=A-B;
		int seki=A*B;
		int max=Math.max(wa,sa);
		max=Math.max(max, seki);
		System.out.println(max);		
		sc.close();
		
	  }	          	
}

Measured memory_bytes: 22612
#pragma GCC optimize("Ofast", "unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double

int main() {
	int N, R; cin >> N >> R;
	if (N <= 10) cout << (R + 100 * (10 - N)) << endl;
	else cout << R << endl;
	return 0;
}

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

using namespace std;

bool ok[400];

int main(){
	string s; cin >> s;
	if (s.size() < 26){
		for (int i = 0; i < 26; i++){
			bool fl = false;
			for (char c:s)
				if (c == char(i+'a'))
					fl = true;
			if (!fl){
				s += char(i+'a');
				break;
			}
		}
		cout << s << "\n";
	}
	else{
		for (int i = 25; ~i; i--){
			char lst = s.back();
			ok[s.back()] = true;
			s.pop_back();
			for (int z = lst+1; z <= 'z'; z++)
				if (ok[z]){
					s += z;
					cout << s << endl;
					return 0;
				}
		}
		cout << "-1\n";
	}
	return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  
  int k = 0;
  rep(i,n) k ^= a[i];
  rep(i,n) {
    a[i] ^= k;
    cout << a[i] << " ";
  }
  cout << endl;
}

Measured memory_bytes: 4056
#include <algorithm>
#include <cmath>
#include <ctime>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
#include <cstring>
#include <tuple>
#include <bitset>
#include <unordered_map>
using namespace std;
typedef long long ll;

ll gcd(ll a, ll b) {
    return (a == 0 ? b : gcd(b % a, a));
}

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

    int a, b;
    cin >> a >> b;
    cout << gcd(a, b) << endl;

    return 0;
}

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

int main() {
  int n,k,tmp,ar,p;
  p = 0;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> tmp;
    for (int j = 0; j < tmp; j++) {
      cin >> ar;
      a.at(ar-1) = 1;
    }
  }
  for (int i = 0; i < n; i++) {
    if (a.at(i) == 0) {
      p++;
    }
  }
  cout << p << endl;
}

Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include <math.h> 
#include <string>
#include <iomanip>
#include <vector>
#include <chrono>
#include <cstdlib>
#include <bitset>
using namespace std;
int main(){
   int k, a, b;
   int x = 0;
   cin >> k >> a >> b;
   for(int i = 1; i <= 1000; i++){
       if(a <= k*i and k*i <= b){
           cout << "OK" << endl;
           x = 1;
           break;
       }
   }
   if(x == 0) cout << "NG" << endl;
}


Measured memory_bytes: 3624
#include<iostream>

using namespace std;

int main() {
	
	int A[4] = {};
	int B[4] = {};
	
	while(cin >> A[0]) {
	int hit = 0;
	int blow = 0;
	for(int i=1;i<4;i++)
		cin >> A[i];
	
	for(int i=0;i<4;i++)
		cin >> B[i];
		
	for(int i=0;i<4;i++) {
		
		for(int j=0;j<4;j++) {
			
			if(A[i] == B[j]) {
				
				if( i == j )
					hit++;
					
				else
					blow++;
					
		}
		
	}
	
}
	cout << hit << " " << blow << "\n";
}
	return 0;
}


Measured memory_bytes: 3012
#include <stdio.h>
#include <stdlib.h>
 
int asc(const void *a, const void *b){
    long *A = (long *)a;
    long *B = (long *)b;
    if(*A > *B)
        return 1;
    if(*A < *B)
        return -1;
    return 0;
}
 
int main(){
    int N, i, cnt=0, tag=0, ans=0;
    long int a[100010];
 
    scanf("%d", &N);
    for(i=0; i<N; i++){
        scanf("%ld", &a[i]);
    }
 
    qsort(a, N, sizeof(long int), asc);
 
    for(i=0; i<N; i++){
      	int value = i;
      	int cnt=0;
      	for(int j=value;a[i]==a[j];j++){
          	cnt++;
          	value = j;
        }
      	ans += cnt%2;
      	i = value;
    }
  
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 1788
//#include <bits/stdc++.h>
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <climits>
#include <iomanip>
#include <stack>
#include <bitset>

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define ROF(i, j, k) for(int i = (int)(j); i >= (int)(k); --i)
#define FORLL(i, n, m) for(long long i = n; i < (long long)(m); i++)
#define SORT(v, n) sort(v, v+n)
#define REVERSE(v) reverse((v).begin(), (v).end())

using namespace std;
using ll = long long;
const ll MOD=1000000007LL;
typedef pair<int, int> P;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }

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

//解説AC
//https://atcoder.jp/contests/tenka1-2019/tasks/tenka1_2019_c

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

  int n;
  string s;
  cin >> n >> s;
  vector<int> dot(n,0), shp(n,0);
  REP(i,n) dot[i+1] = dot[i] + (s[i]=='.');
  REP(i,n) shp[i+1] = shp[i] + (s[i]=='#');

  int ans = n;
  REP(i,n+1){
    ans = min(ans, shp[i] + dot[n]-dot[i]);    
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 2196
#include<bits/stdc++.h>
using namespace std ; 
int main () { 
    ios_base::sync_with_stdio(false);
    long double a,b,c;
    long double eps = 1.0E-14;
    cin>>a>>b>>c;
    if (sqrt(a) + sqrt(b) + eps < sqrt(c))
        cout<<"Yes"<<"\n";
    else  
        cout<<"No"<<"\n";
    return 0 ; 
}

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

using namespace std;

int main(void) {
  string c1, c2;
  cin >> c1 >> c2;

  if(c1[0] == c2[2] && c1[1] == c2[1] && c1[2] == c2[0]) {
    cout << "YES" << endl;
    return 0;
  }

  cout << "NO" << endl;
}

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

using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<pair<int64_t, int>> numb(n);
    for (auto & x: numb) {
        cin >> x.first >> x.second;
    }
    int64_t sum = 0;
    for (int i = n - 1; i > -1; --i) {
        numb[i].first += sum;
        if (numb[i].first % numb[i].second) {
            int64_t upd = (numb[i].first / numb[i].second + 1) * numb[i].second - numb[i].first;
            sum += upd;
        }
    }
    cout << sum;



    return 0;
}


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

using namespace std;

int a,b,c,d;
int main(){
	cin >> a >> b >> c >> d;
	if((abs(a-b)<=d&&abs(b-c)<=d)||abs(a-c)<=d)
	{
		cout << "Yes" << endl;
	}
	else cout << "No" << endl;
}

Measured memory_bytes: 256