akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<set>
#include<functional>
#include<iomanip>

#define LLI long long int

using namespace std;

int main(){
	int N,K;cin>>N>>K;
	vector<LLI>V(N);
	for(int i=0;i<N;i++)cin>>V[i];

	LLI ans=0;
	int nkmin=min(N,K);
	for(int i=0;i<=nkmin;i++){
		int rest=nkmin-i;
		for(int j=0;j<=rest;j++){
			vector<LLI>buf(0);
			for(int k=0;k<i;k++)buf.push_back(V[k]);
			for(int k=0;k<j;k++)buf.push_back(V[N-1-k]);
			int t=min(K-i-j,(int)buf.size());
			sort(buf.begin(),buf.end());
			for(int k=0;k<t;k++){
				if(buf[k]<0){
					buf[k]=0;
				}else{
					break;
				}
			}
			LLI v=0;
			for(int k=0;k<buf.size();k++)v+=buf[k];
			ans=max(v,ans);
		}
	}
	cout<<ans<<endl;
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string.h>
#include <algorithm>
#include <vector>
#include <queue>

using namespace std;
typedef long long ll;
const ll INF=100000000000000LL;

int main() {
	string a,b,c;
	cin>>a>>b>>c;
	if(a[a.size()-1]==b[0]&&b[b.size()-1]==c[0])cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <math.h>
#include <sstream>
#include <numeric>
#include <string>
#include <cassert>
#include <bitset>

using namespace std;
typedef long long ll;

const double kPi = 3.14159265359;

int main() {
  double a, b, x;
  cin >> a >> b >> x;
  double theta;
  if (x <= a * a * b / 2) {
    double y = 2 * x / (a * b);
    theta = atan2(b, y);
    
  } else {
    double y = 2 * (a * a * b - x) / (a * a);
    theta = atan2(y, a);
  }
  cout << setprecision(20) << theta / (2 * kPi) * 360 << endl;
  return 0;
}


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

using namespace std;
#define inputInt(a) int a; cin >> a; 
#define inputInt2(a,b) int a; int b; cin >> a >> b; 
#define inputInt3(a,b,c) int a; int b; int c; cin >> a >> b >> c;
#define inputLong(a) long a;cin >> a;
#define inputIntArray(a,N) int a[N];for(int i=0;i<N;i++){cin >> a[i];}
#define inputLongArray(a,N) long a[N];for(int i=0;i<N;i++){cin >> a[i];}
#define inputDoubleArray(a,N) double a[N];for(int i=0;i<N;i++){cin >> a[i];}
#define inputIntArray2(a,b,N) int a[N]; int b[N]; for(int i=0;i<N;i++){cin >> a[i] >> b[i];}
#define output(answer) cout << answer << endl;
#define fN(i,N)    for(int i=0; i<N; i++)
#define fSE(i,s,e) for(int i=s; i<=e; i++)
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; }

int main(){
  //input
  inputInt(N);
  
  vector<long> a(N,0), b(N,0);
  
  for(int i=0; i<N; i++){
    cin >> a[i];
    b[i] = abs(a[i]);
  }
  
  sort(a.begin(),a.end());
  sort(b.begin(),b.end());//最も絶対値が小さいa[i]を走査。
  
  int minus = lower_bound(a.begin(),a.end(),0)-a.begin();
  long ans = 0;
  
  if(minus % 2 == 0 || b[0] == 0){//全て正の整数になる時
    ans = accumulate(b.begin(),b.end(),0LL);
  }else{
    ans = accumulate(b.begin(),b.end(),0LL) - b[0]*2;
  }
  
  //output
  output(ans);
  
  return 0;
}



Measured memory_bytes: 1792
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>

using namespace std;

typedef struct edge{
    int from; //出発点
    int to;   //到達点
    int64_t cost; //移動コスト
}edge;

bool used[2501];

short dfs(int i, const vector<vector<int>> &E, vector<short> &reachable){
    if (used[i] and reachable[i])
        return true;
    if (used[i])
        return false;
    used[i] = true;
    bool res = false;
    for (const auto &e: E[i]){
        if (i == e)
            continue;
        res |= dfs(e, E, reachable);
    }
    reachable[i] |= res;
    return res;
}

class ECoinsRespawn {
public:
void solve(std::istream& cin, std::ostream& cout) {
    int n, m, p;
    cin >> n >> m >> p;
    vector<edge> E;
    vector<vector<int>> F(n + 1), G(n + 1);
    vector<short> reachable(n + 1);
    for (int i = 0; i < m; i++){
        int a, b, c;
        cin >> a >> b >> c;
        edge e = {a, b, -(c - p)};
        E.emplace_back(e);
        F[a].emplace_back(b);
        G[b].emplace_back(a);
    }

    int64_t INF = int(1e18);
    vector<int64_t> D(n + 1, INF);
    D[1] = 0;

    fill_n(used, n + 1, false);
    reachable[n] = true;
    used[n] = true;
    dfs(1, F, reachable);

    fill_n(used, n + 1, false);
    used[1] = true;
    dfs(n, G, reachable);

    for (int i = 0; i < n; i++){
        for (int j = 0; j < m; j++) {
            edge e = E[j];
            if (D[e.to] > D[e.from] + e.cost) {
                D[e.to] = D[e.from] + e.cost;
                if (i == n - 1 and reachable[e.to]) {
                    cout << -1 << endl;
                    return;
                }
            }
        }
    }

    int64_t z = 0;

    cout << max(z, -D[n]) << endl;
}
};

int main() {
	ECoinsRespawn solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 768
N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort()

T = []
for _ in range(M):
    b, c = map(int, input().split())
    T.append((b, c))

T.sort(reverse=True, key=lambda elem: elem[1])

i = 0
for b,c in T:
    for _ in range(b):
        if A[i] < c:
            A[i] = c
        i += 1
        if i==N:
            break
    if i==N:
        break

print(sum(A))


Measured memory_bytes: 22088
#include "bits/stdc++.h"

#define debug(x) cout<<#x<<": "<<x<<endl
#define rep(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for (int i=(a);i<=(b);i++)
#define all(a) (a).begin(),(a).end()
using namespace std;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef long long ll;

set<int> mergeSet(set<int> s1, set<int> s2) {
	for (int ele : s2) {
		s1.insert(ele);
	}
	return s1;
}


void solve() {
#ifdef _WIN32
	istream &cin = ifstream("input.txt");
#endif

	int n;
	cin >> n;
	cout << (n < 1200 ? "ABC" : "ARC") << endl;
}




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


	solve();
#ifdef _WIN32
	system("PAUSE");
#endif
	return 0;
}

Measured memory_bytes: 764
#include<stdlib.h>
#include<iostream>
#include<bits/stdc++.h>
#include<string.h>
using namespace std;
const int N = 2e5+10;
int a[N];
int main()
{
	int n , m , t;
	string name;
	queue<pair<string,int> > Q;
	cin >> n >> m;
	for(int i = 0 ; i < n ; i++)
	{
		cin >> name >> t;
		Q.push(make_pair(name,t));
	}
	pair<string , int> u;
	int sum =0, x;
	while(!Q.empty())
	{
		u = Q.front();
		Q.pop();
		x = min(u.second,m);
		u.second -= x;
		sum+=x;
		if(u.second > 0)
	{
		Q.push(u);	
	}
	else
	{
		cout << u.first << " " << sum << endl;
	}
	}
	return 0;
}


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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, K;
  string S;
  cin >> N >> S >> K;
  char c = S[K-1];
  rep(i, N) if(S[i] != c) S[i] = '*';
  cout << S << "\n";
  return 0;
}


Measured memory_bytes: 3568
class UnionFind():
  def __init__(self, n):
    self.n = n
    self.root = [-1] * (n+1)
    self.rnk = [0] * (n+1)
    
  def find_root(self, x):
    if self.root[x] < 0:
      return x
    else:
      self.root[x] = self.find_root(self.root[x])
      return self.root[x]
    
  def unite(self, x, y):
    x = self.find_root(x)
    y = self.find_root(y)
    if x == y:
      return
    elif self.rnk[x] > self.rnk[y]:
      self.root[x] += self.root[y]
      self.root[y] = x
    else:
      self.root[y] += self.root[x]
      self.root[x] = y
      if self.rnk[x] == self.rnk[y]:
        self.rnk[y] += 1
    
  def isSameGroup(self, x, y):
    return self.find_root(x) == self.find_root(y)
  
  def size(self, x):
    return -self.root[self.find_root(x)]

N,M = map(int, input().split())
A = [0] * M
B = [0] * M
for i in range(M):
  A[i], B[i] = map(int, input().split())
  
ans = [0] * (M + 1)
ans[0] = (N * (N-1)) / 2
UnionFind = UnionFind(N)
for i in range(1,M+1):
  a = A[M - i]
  b = B[M - i]
  if UnionFind.isSameGroup(a, b):
    ans[i] = ans[i - 1]
  else:
    ans[i] = ans[i - 1] - UnionFind.size(a) * UnionFind.size(b)
    UnionFind.unite(a, b)
for i in range(M):
  print(int(ans[M - 1 - i]))

Measured memory_bytes: 17052
#include<iostream>
#include<cstdio>
#include<string>
using namespace std;
string s;
int l;
int main()
{
    cin>>s;
    l=s.size();
    for(register int i=0;i<l;i++)
    {
        if(s[i]=='C')
        {
            for(register int j=i+1;j<l;j++)
            {
                if(s[j]=='F')
                {
                    cout<<"Yes"<<endl;
                    return 0;
                }
            }
        }
    }
    cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*

fun main(args: Array<String>) {
    val pw = java.io.PrintWriter(System.out)
    Problem.solve(Scanner(System.`in`), pw)
    pw.flush()
}

object Primes : Iterable<Long> {
    private var checked = 2L
    private val xs = mutableListOf(2L)

    /**
     * Check if n is prime number.
     *
     * @param n number
     * @return true when n is prime number
     */
    fun contains(n: Long): Boolean {
        var i = xs.count()
        while (checked < n) get(i++)
        return xs.contains(n)
    }

    /**
     * Get i-th prime number.
     *
     * @param i index (0-)
     * @return i-th prime number
     */
    fun get(i: Int): Long {
        while (xs.count() <= i) {
            var n = checked + 1
            loop@ while (true) {
                for (j in xs) {
                    if (j * j > n) {
                        break@loop
                    }
                    if (n % j == 0L) {
                        n++
                        break
                    }
                }
            }
            xs.add(n)
            checked = n
        }
        return xs[i]
    }

    /**
     * Get iterator.
     *
     * @return iterator
     */
    override fun iterator(): Iterator<Long> = object : Iterator<Long> {
        var i = 0
        override fun hasNext(): Boolean = true
        override fun next(): Long {
            val x = get(i)
            i += 1;
            return x
        }
    }
}

// 素因数分解
fun factorize(n: Long): Map<Long, Int> {
    val result = mutableMapOf<Long, Int>()
    val it = Primes.iterator()
    var i = n
    do {
        val p = it.next()
        if ((i % p) == 0L) {
            var pn = 0
            do {
                pn++
                i /= p
            } while ((i % p) == 0L)
            result[p] = pn
        }
    } while (p * p <= i)
    if (i != 1L) {
        result[i] = 1
    }
    return result
}

object Problem {
    fun solve(sc: Scanner, pw: java.io.PrintWriter) {
        val N = sc.next().toLong()
        val f = factorize(N)
        var ans = 0L
        f.forEach {
            var n = it.value
            var i = 1
            while (n >= i) {
                n -= i
                ans++
                i += 1
            }
        }
        pw.println(ans)
    }
}


Measured memory_bytes: 58368
// 2013/11/01 Tazoe

#include <iostream>
#include <queue>
using namespace std;

struct point{
	int y;
	int x;
};

struct state{
	int y;
	int x;
	int t;
};

int main()
{
	int H, W, N;
	cin >> H >> W >> N;

	char F[1002][1002];
	for(int y=0; y<=H+1; y++){
		for(int x=0; x<=W+1; x++){
			F[y][x] = 'X';
		}
	}

	struct point P[10];

	for(int y=1; y<=H; y++){
		for(int x=1; x<=W; x++){
			cin >> F[y][x];

			if(F[y][x]=='S'){
				P[0].y = y;
				P[0].x = x;
				F[y][x] = '.';
			}
			else if('0'<=F[y][x] && F[y][x]<='9'){
				P[F[y][x]-'0'].y = y;
				P[F[y][x]-'0'].x = x;
				F[y][x] = '.';
			}
		}
	}
/*
	for(int y=1; y<=H; y++){
		for(int x=1; x<=W; x++){
			cout << F[y][x];
		}
		cout << endl;
	}
*/
	int sum = 0;

	for(int i=0; i<N; i++){
		struct state s;
		s.y = P[i].y;
		s.x = P[i].x;
		s.t = 0;

		queue<struct state> q;
		q.push(s);

		bool memo[1002][1002];
		for(int y=1; y<=H; y++){
			for(int x=1; x<=W; x++){
				memo[y][x] = false;
			}
		}
		memo[s.y][s.x] = true;

		while(true){
			if(q.empty())
				break;

			s = q.front();

			if(s.y==P[i+1].y && s.x==P[i+1].x){
				sum += s.t;
				break;
			}

			if(F[s.y-1][s.x]=='.' && !memo[s.y-1][s.x]){
				struct state t;
				t.y = s.y-1;
				t.x = s.x;
				t.t = s.t+1;

				q.push(t);
				memo[t.y][t.x] = true;
			}

			if(F[s.y][s.x+1]=='.' && !memo[s.y][s.x+1]){
				struct state t;
				t.y = s.y;
				t.x = s.x+1;
				t.t = s.t+1;

				q.push(t);
				memo[t.y][t.x] = true;
			}

			if(F[s.y+1][s.x]=='.' && !memo[s.y+1][s.x]){
				struct state t;
				t.y = s.y+1;
				t.x = s.x;
				t.t = s.t+1;

				q.push(t);
				memo[t.y][t.x] = true;
			}
			if(F[s.y][s.x-1]=='.' && !memo[s.y][s.x-1]){
				struct state t;
				t.y = s.y;
				t.x = s.x-1;
				t.t = s.t+1;

				q.push(t);
				memo[t.y][t.x] = true;
			}

			q.pop();
		}
	}

	cout << sum << endl;

	return 0;
}

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

typedef long long ll;
typedef tuple<ll, ll, ll> mytuple;
const ll INF = 1e9;
const ll MOD = 1000000007;
const double pi = 3.141592653589793238;

// a と b の最大公約数を返す関数
long long GCD(long long a, long long b) { if (b == 0) {return a;} else {return GCD(b, a % b);} }
// a と b の最小公倍数を返す関数
long long LCM(long long a, long long b) { return a/GCD(a,b)*b; }

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; }

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

  if(S.size() <= K) {
    cout << S << endl;
  } else {
    for(int i = 0; i < K; ++i) {
      cout << S.at(i);
    }
    cout << "..." << endl;;
  }
  return 0;
}


Measured memory_bytes: 3576
#include<bits/stdc++.h>
using namespace std;
typedef long long  ll;
const ll INF=(ll)1e18;

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
    int n;cin>>n;
    set<string>s;
    while(n--){
        string a;cin>>a;
        s.insert(a);
    }
    cout<<s.size()<<"\n";
}



Measured memory_bytes: 19196
#include <bits/stdc++.h>
//#pragma GCC optimize("Ofast")

#define fi first
#define se second

const int N = 110;

using namespace std;

int n, m;
char a[N][N];
int d[N][N];

int get(char x, char y)
{
        if(x == '.' && y == '#') return 1;
        return 0;
}

int main()
{
        //freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);

        ios_base::sync_with_stdio(0);

        cin >> n >> m;
        for(int i = 1; i <= n; i++) for(int j = 1; j <= m; j++) cin >> a[i][j];

        int inf =1e9;
        for(int i = 0; i < N; i++) for(int j = 0; j < N; j++) d[i][j] = inf;

        if(a[1][1] == '.') d[1][1] = 0;
        else d[1][1] = 1;

        for(int i = 1; i <= n; i++){
                for(int j = 1; j <= m; j++){
                        d[i + 1][j] = min(d[i + 1][j], d[i][j] + get(a[i][j], a[i + 1][j]));
                        d[i][j + 1] = min(d[i][j + 1], d[i][j] + get(a[i][j], a[i][j + 1]));
                }
        }

        cout << d[n][m] << "\n";
}


Measured memory_bytes: 384
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;
import java.util.Comparator;
import java.util.ArrayList;

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

    static class CAlign {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
        /*
        a > b < c > dなら
        端は係数の絶対値が1
        奇数番目が-2
        偶数番目は+2になる
         */

            int n = in.nextInt();
            long[] a = new long[n];
            for (int i = 0; i < n; i++) a[i] = in.nextLong();
            Arrays.sort(a);

            ArrayList<Integer> dec = new ArrayList<>();
            ArrayList<Integer> inc = new ArrayList<>();

            dec.add(1);
            inc.add(-1);

            int even = (n - 1) / 2;
            int odd = n / 2;

            if (n % 2 == 0) {
                // 最後はa>b<c>dになるから+1,-1でoddが減る
                odd--;
                dec.add(-1);
                inc.add(1);
            } else {
                even--;
                dec.add(1);
                inc.add(-1);
            }


            for (int i = 0; i < even; i++) {
                dec.add(2);
                inc.add(-2);
            }
            for (int i = 0; i < odd; i++) {
                dec.add(-2);
                inc.add(2);
            }

            dec.sort(Comparator.naturalOrder());
            inc.sort(Comparator.naturalOrder());

            // out.println(dec);
            // out.println(inc);


            long decSum = 0;
            long incSum = 0;
            for (int i = 0; i < n; i++) {
                decSum += dec.get(i) * a[i];
                incSum += inc.get(i) * a[i];
            }

            out.println(Math.max(decSum, incSum));

        }

    }
}



Measured memory_bytes: 60764
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << " is " << x << endl

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;

const int INF = 1e9 + 7;

signed main()
{
	IO_OP;
	
	string s, t;
	cin >> s >> t;
	t.pop_back();
	cout << (s == t ?  "Yes" : "No") << endl;	
	
}





Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define rep(i,m,n) for(int i=m;i<n;i++)
#define fix(n) cout<<fixed<<setprecision(n)
#define co(n) cout<<n<<endl
#define all(n) (n).begin(),(n).end()
using namespace std;
typedef long long ll;
const ll mod=1000000007;
double pi=3.1415926535;

int dp(int x){
  int c=1;
  while(1){
    if(x/10>0){
      c++;
      x/=10;
    }
    else break;
  }
  return c;
}

int main(){
  ll n,a,b;
  cin>>n;
  a=n;b=1;
  ll r=pow(n,0.5);
  rep(i,2,r+1){
    if(n%i==0){
      a=n/i;
      b=i;
    }
  }
  a=dp(a); b=dp(b);
  co(max(a,b));
  
  return 0;
}

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

#define mp       make_pair
#define mt	 make_tuple
#define pb       push_back
#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    pair<int,int>      pii;
typedef    pair<long,long>    pll;

const int INF=1<<29;
const double EPS=1e-9;
const int MOD = 100000007;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
int n;
int main(){
  while (cin >> n){
    if (n == 0)break;
    string tmp;
    int r = 0;
    int l = 0;
    bool up = true;
    int cnt = 0;
    for (int i = 0; i < n; i++){
      cin >> tmp;
      if (tmp == "lu"){
	l = 1;
      }else if (tmp == "ru"){
	r = 1;
      }else if(tmp == "ld"){
	l = 0;
      }else if(tmp == "rd"){
	r = 0;
      }
      if (up){
	if (l == 1 && r == 1){
	  cnt++;
	  up = false;
	}
      }else{
	if (l == 0 && r == 0){
	  cnt++;
	  up = true;
	}
      }
    }
    cout << cnt << endl;
  }
}

Measured memory_bytes: 1208
h, w, z = map(int ,input().split())
s = []
for i in range(h):
    s.append(list(input()))
ans = int(1e9+7)
if h == 1:
    ans = 0
    cnt = 0
    for i in range(w):
        if s[0][i] == '1':
            cnt += 1
        if cnt > k:
            ans += 1
            cnt -= k
    print(ans)
    exit()

for i2 in range(2**(h-1)):
    d = [True] * (h-1)
    for j2 in range(h-1):
        if (i2 >> j2) & 1:
            d[j2] = False
    d.append(False)


    val = 0
    for i in range(len(d)-1):
        if d[i] == False:
            val += 1
    #print(val,d)
    l = []
    lis = []
    for i in range(h):
        l.append(i)
        if d[i] == False:
            lis.append(l)
            l = []

    flg2 = True#横がiのときにcnt2の要素がkを超えるとFalse
    flg = True#cntの要素がkを超えるとFalse
    cnt = [0] * len(lis)#全体での1の個数
    for i in range(w):
        cnt2 = [0] * len(lis)#iでの1の個数
        for j in range(len(lis)):
            for k in lis[j]:
                if s[k][i] == '1':#高さがkで横がiの時、
                    cnt[j] += 1#lis[j]を1たす
                    cnt2[j] += 1
            if cnt[j] > z:
                flg = False
            if cnt2[j] > z:
                flg2 = False
        if flg == False:
            for j in range(len(cnt)):
                cnt[j] = cnt2[j]
            flg = True
            val += 1
        #print(cnt,cnt2)
        #print(i,val)
    if flg2 == True:
        ans = min(ans,val)
    #print(val,d,lis,flg)
print(ans)


Measured memory_bytes: 49244
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <stdbool.h>
#include <limits.h>
#include <regex.h>

#define lli long long int
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define abs(a) ((a)<0?-(a):(a))
#define alloc(type,size) calloc(sizeof(type),size)

#define N 100001

int n,x;
int a[N];
lli res;
lli sum;


int main(void){
	int i;
	int mem;
	scanf("%d%d",&n,&x);
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
		sum += a[i];
	}
	if(a[0]>x) a[0] = x;
	res += a[0];
	for(i=1;i<n;i++){
		mem = x - (a[i] + a[i-1]);
		if(mem < 0) a[i] += mem;
		res += a[i];
	}
	printf("%lld\n", sum-res);
	
    return 0;
}


Measured memory_bytes: 512
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    n,a,b = LI()
    if (b-a)%2:
        print("Borys")
    else:
        print("Alice")
    return

#B
def B():
    def f(m):
        if d[m] != None:
            return d[m]
        n = m
        for i in a:
            n = n-n%i
        d[m] = n
        return n
    k = I()
    a = LI()
    d = defaultdict(lambda : None)
    l,r = 0,int(1e18)
    while r-l > 1:
        m = (r+l)//2
        if f(m) < 2:
            l = m
        else:
            r = m
    mi = r
    l,r = 0,int(1e18)
    while r-l > 1:
        m = (r+l)//2
        if f(m) <= 2:
            l = m
        else:
            r = m
    ma = l
    if mi <= ma:
        if f(mi) != 2:
            print(-1)
        else:
            print(mi,ma)
    else:
        print(-1)
    return

#C
def C():
    n = I()

    return

#D
def D():
    n = I()

    return

#E
def E():
    n = I()

    return

#F
def F():
    n = I()

    return


#Solve
if __name__ == "__main__":
    A()


Measured memory_bytes: 38896
n=int(input())
r=0
l=[[0 for i in range(9)] for j in range(9)]
for i in range(n):
  s=str(i+1)
  a=int(s[0])
  b=int(s[-1])
  if a!=0 and b!=0:
    l[a-1][b-1]+=1
for i in range(9):
  for j in range(9):
    r+=l[i][j]*l[j][i]
print(r)

Measured memory_bytes: 40428
import java.util.*;
 
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();

    N = N % 10;
    if(N==3) {
      System.out.println("bon");
    } else if(N==0 || N==1 || N==6 || N==8) {
      System.out.println("pon");
    } else {
      System.out.println("hon");
    }
  }
}

Measured memory_bytes: 35808
using AtCoderBeginnerContest127.Questions;
using AtCoderBeginnerContest127.Extensions;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace AtCoderBeginnerContest127.Questions
{
    public class QuestionB : AtCoderQuestionBase
    {
        public override IEnumerable<object> Solve(TextReader inputStream)
        {
            var rdx = inputStream.ReadIntArray();
            var r = rdx[0];
            var d = rdx[1];
            var x = rdx[2];

            for (int i = 2001; i <= 2010; i++)
            {
                x = r * x - d;
                yield return x;
            }
        }
    }
}


namespace AtCoderBeginnerContest127
{
    class Program
    {
        static void Main(string[] args)
        {
            IAtCoderQuestion question = new QuestionB();    // 問題に合わせて書き換え
            var answers = question.Solve(Console.In);
            foreach (var answer in answers)
            {
                Console.WriteLine(answer);
            }
        }
    }
}

#region Base Classes

namespace AtCoderBeginnerContest127.Questions
{

    public interface IAtCoderQuestion
    {
        IEnumerable<object> Solve(string input);
        IEnumerable<object> Solve(TextReader inputStream);
    }

    public abstract class AtCoderQuestionBase : IAtCoderQuestion
    {
        public IEnumerable<object> Solve(string input)
        {
            var stream = new MemoryStream(Encoding.Unicode.GetBytes(input));
            var reader = new StreamReader(stream, Encoding.Unicode);

            return Solve(reader);
        }

        public abstract IEnumerable<object> Solve(TextReader inputStream);
    }

}

#endregion

#region Extensions

namespace AtCoderBeginnerContest127.Extensions
{
    internal static class TextReaderExtensions
    {
        internal static int ReadInt(this TextReader reader) => int.Parse(ReadString(reader));
        internal static long ReadLong(this TextReader reader) => long.Parse(ReadString(reader));
        internal static double ReadDouble(this TextReader reader) => double.Parse(ReadString(reader));
        internal static string ReadString(this TextReader reader) => reader.ReadLine();

        internal static int[] ReadIntArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(int.Parse).ToArray();
        internal static long[] ReadLongArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(long.Parse).ToArray();
        internal static double[] ReadDoubleArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(double.Parse).ToArray();
        internal static string[] ReadStringArray(this TextReader reader, char separator = ' ') => reader.ReadLine().Split(separator);
    }
}

#endregion

Measured memory_bytes: 13396
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main() {
    int a, b;cin >> a >> b;
    vector<int>c(a);
    for (int i = 0; i < a; i++) {
        cin >> c[i];
    }a--;b--;
    if ( a %  b != 0) {
        cout << (a  / b) + 1;
    }
    else {
        cout << (a  / b);
    }
}

Measured memory_bytes: 640
n1 = int(input())

n2, n3 = [int(i) for i in input().split()]
n4 = [int(j) for j in input().split()]


t1 = 1000
r1 = 0
for i1 in range(n1):
    if abs((n2 - (n4[i1] * 0.006))  - n3) <= t1:
        t1 = abs((n2 - (n4[i1] * 0.006))  - n3)
        r1 = i1 + 1

print(r1)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;
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; }

using namespace std;

int main(){
    int N;
    cin >> N;
    ll Z, W;
    cin >> Z >> W;
    ll a[N];
    rep(i, N) {
        cin >> a[i];
    }

    if (N >= 2) {
        cout << max(abs(a[N-1]-W), abs(a[N-2]-a[N-1])) << endl;
    } else {
        cout << abs(a[0]- W) << endl;
    }
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;

int main()
{
    int N, M; cin >> N >> M;
    vector<vector<int>> adList(N);
    for (int i = 0; i < M; ++i)
    {
        int ai, bi; cin >> ai >> bi; --ai; --bi;
        adList[ai].push_back(bi);
        adList[bi].push_back(ai);
    }
    vector<int> parents(N, -1);
    const int INF = 1e6;
    vector<int> dists(N, INF);
    deque<int> Q{ 0 };
    dists[0] = 0;
    while (!Q.empty())
    {
        int v = Q.front(); Q.pop_front();
        for (const int n : adList[v])
        {
            if (dists[n] > dists[v] + 1)
            {
                parents[n] = v;
                dists[n] = dists[v] + 1;
                Q.push_back(n);
            }
        }
    }
    cout << "Yes" << endl;
    for (int i = 1; i < N; ++i)
    {
        cout << parents[i] + 1 << endl;
    }
}

Measured memory_bytes: 10728
#include <bits/stdc++.h>
#define all(a) a.begin(), a.end()
using namespace std;

int N;

string res;

void UDLR(int t, char c){
 int p = 0;
 while(p < t){
   res += c;
   ++p;
 }
}

int main(){
  ios_base::sync_with_stdio(false); 
  res = "";
  int sx, sy, tx, ty;
  cin >> sx >> sy >> tx >> ty;
  int up = ty-sy;
  int right = tx-sx;
  UDLR(up, 'U');
  UDLR(right, 'R');
  UDLR(up, 'D');
  UDLR(right, 'L');
  UDLR(1, 'L');
  UDLR(1+up, 'U');
  UDLR(1, 'R');
  UDLR(right, 'R');
  UDLR(1, 'D');
  UDLR(1, 'R'); 
  UDLR(1+up, 'D');
  UDLR(1, 'L');
  UDLR(right, 'L');
  UDLR(1, 'U');
  cout << res << "\n"; 
  return 0;
}


Measured memory_bytes: 256
readlines.map(&:chomp).each{|line|
  break if line == "0 0"
  n, m = line.split.map(&:to_i)
  arr = Array.new(n){|i| i}
  arr[0] = n
  p = m
  loop do
    break if arr.size == 1
    while p < arr.size
      arr[p] = -1
      p += m
    end
    p -= arr.size
    arr -= [-1]
  end
  puts arr[0]
}

Measured memory_bytes: 13940
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

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

const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
const double eps=1e-10;

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

int n;
double dp[310][310][310];

double rec(int x, int y, int z){
    if(dp[x][y][z] != -1) return dp[x][y][z];
    if(x == 0 && y == 0 && z == 0) return 0.0;

    double res = 0.0;
    if(x > 0) res += rec(x-1, y, z) * x;
    if(y > 0) res += rec(x+1, y-1, z) * y;
    if(z > 0) res += rec(x, y+1, z-1) * z;
    res += n;
    res *= 1.0 / (x + y + z);

    return dp[x][y][z] = res;
}

int main(){
    cin>>n;
    vector<int> cnt(4, 0);
    for(int i=0; i<n; i++){
        int x; cin>>x;
        cnt[x]++;
    }

    for(int i=0; i<=n; i++){
        for(int j=0; j<=n; j++){
            for(int k=0; k<=n; k++){
                dp[i][j][k] = -1;
            }
        }
    }

    cout << fixed << setprecision(12) << rec(cnt[1], cnt[2], cnt[3]) << endl;
}

Measured memory_bytes: 227584
#!/usr/bin/env python
from __future__ import division, print_function

import os
import sys
from io import BytesIO, IOBase

if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip


def main():
    a, b = map(int, input().split())

    if a < 10 and b < 10:
        print(a * b)
    else:
        print(-1)


# region fastio

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()


if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)

input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

if __name__ == "__main__":
    main()


Measured memory_bytes: 29164
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
 // king
int main()
{
    int n;cin>>n;
  
  
    ll ans=1;
  
    vector<ll>a(n);
  
    for(int i=0;i<n;++i){
        cin>>a[i];
    }
  
    sort(a.begin(),a.end());
  
    for(int i=0;i<n;++i){
        if(a[i]==0){
            ans=0;
            break;
        }
      
        if((ll)1e18/a[i] < ans){
            ans=-1;
            break;
        }
        ans*=a[i];
    }
    cout<<ans;
}

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

const int MOD = 1000000007;
const int INF = 1e9;

//long long
using ll = long long;

//出力系
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
 
// begin() end()
#define all(x) (x).begin(),(x).end()

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

//最大公約数 
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }

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

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

int S = X - (K - 1);
int G = X + (K - 1);


for(int i = S; i <= G; i++){ 
   if(i != G) cout << i << ' ';
   else cout << i;
}

}

Measured memory_bytes: 256
tap = input()
int_len=len(tap)
bad_count=0

for i in range(int_len):
    if (i+1)%2==1 and tap[i]=="L":
        bad_count = bad_count +1
    elif (i+1)%2==0 and tap[i]=="R":
        bad_count = bad_count +1
if bad_count==0:print("Yes")
else:print("No")

Measured memory_bytes: 3060
import kotlin.math.*

fun str() = readLine()!!
fun int() = str().toInt()
fun long() = str().toLong()

fun read(d:String = " ") = str().split(d)
fun <T> list(d:String = " ",f:String.()->T) = read(d).map {f(it)}
fun list() = list {toInt()}

fun <T> MutableList<T>.removeLast() = this.removeAt(this.lastIndex)

const val mod = 1000000007L

fun main() {
	abc000X()
}

fun abc000X() {
	val (n,x,t) = list()
	println((n+x-1)/x*t)
}


Measured memory_bytes: 36400
#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 rusha scanf("%d",&n);rep(i,1,n)scanf("%d",&a[i]);
#define rushb scanf("%d",&t);while(t--)
#define debug(x) cout<<" L-B-W-- "<<x<<" --N-B\n"
#define pb push_back
//#define pii pair<int,int>
#define vii vector<int>
#define fi first
#define se second
#define mem(a,b) memset(a,b,sizeof a)
#define all(x) (x.begin(),x.end())
#define judgef printf("%s\n",f?"Yes":"No")
#define Judgef printf("%s\n",f?"YES":"NO")
#define sz(x) ((int)(x).size())
#define sf(x) (sizeof(x))
using namespace std;
typedef long long ll;
typedef double db;
const double pai = acos(-1.0);
const double eps = 1e-8;
const int mod=998244353;
//const int mod=1e9+7;
const int inf=1e9+7;
//const ll inf=0x7f7f7f7f1234abcd;
const int maxn=2e5+10;
inline ll ksm(ll x,ll y){ ll res=1; while(y){if(y&1) res=res*x%mod;x=x*x%mod; y>>=1;} return res; }
inline ll inv(ll a,ll p){if(a==1)return 1;return (p-p/a)*inv(p%a,p)%p;}
ll lcm(ll a, ll b) { return a * b / __gcd(a, b); }

int t,n,m,k;
int a,b,c,d;
int main(){
    scanf("%d%d%d%d",&a,&b,&c,&d);
    while(1){
        c-=b;
        if(c<=0) break;
        a-=d;
        if(a<=0) break;
    }
    printf("%s\n",a>0?"Yes":"No");















    return 0;
}


Measured memory_bytes: 3764
#include <iostream>
#include <algorithm>

using namespace std;

int main() {
    int T = 0;
    cin>>T;
    for (int t = 0; t < T; t++) {
        int N = 0;
        int K = 0;
        int m[1000000] = {};
        cin>>N>>K;
        int now = 0;
        int prev = 0;
        cin>>prev;
        for (int n = 0; n < N-1; n++) {
            cin>>now;
            m[n] = now - prev;
            prev = now;
        }
        sort(m, m+N);
        int result = 0;
        for (int i = 0; i < max(0, N-K+1); i++) result += m[i];

        cout<<result<<endl;
    }
}

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

int main() {
    ll x, k, d;
    cin >> x >> k >> d;
    if (x < 0) x = -x;
    ll cnt = x / d;
    if (x % d) {
        cnt++;
    }
    if (k >= cnt) {
        ll cat = k - cnt;
        ll ans;
        if (cat % 2) {
            ans = x - d * cnt;
            ans += d;
            cout << abs(ans) << endl;
        } else {
            ans = x - d * cnt;
            cout << abs(ans) << endl;
        }
    } else {
     
            ll ans = x - d * k;
            cout << abs(ans) << endl;

        
    }
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const int mod=1000000007;
const int INF=1001001001;


int main() {
  int64_t N,K;
  cin>>N>>K;
  vector<int>A(N+1);
  for(int i=1;i<=N;i++){
    cin>>A[i];
  }
  vector<int>num(N+1,-1);
  vector<int>q;
  int now=1;
  while(num[now]==-1){
    num[now]=q.size();
    q.push_back(now);
    now=A[now];
  }
  int nr=num[now];
  int r=q.size()-nr;
  if(K<nr){cout<<q[K]<<endl;return 0;}
  else{
    K-=nr;
    K%=r;
    cout<<q[K+nr]<<endl;
  }
  return 0;  
}

Measured memory_bytes: 5880
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) FOR(i,0,n)
#define repr(i,n) for(int i=(n)-1;0<=i;--i)
#define each(e,v) for(auto&& e:(v))
#define all(v) begin(v),end(v)
#define dump(x) cerr<<#x<<": "<<(x)<<endl
#define INF 100000000
#define IINF 9999999999999;
using vint = std::vector<int>;
using ll = long long;
using vll = std::vector<ll>;
template <class T> void chmin(T& a, const T& b) { a = std::min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = std::max(a, b); }
#define output(x) cout << x << endl;
typedef pair<int, int> P;

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

int main()  {
    int N;
    cin >> N;
    bool ans = true;
    int t[N + 1], x[N + 1], y[N + 1];
    t[0] = 0; x[0] = 0; y[0] = 0;
    for (int i = 1; i <= N; ++i) {
        cin >> t[i] >> x[i] >> y[i];
    }

    for (int i = 0; i < N; ++i) {
        int temp = t[i + 1] - t[i];
        temp -= abs(x[i + 1] - x[i]) + abs(y[i + 1] - y[i]);
        if (temp < 0 || temp % 2 != 0) {
            ans = false;
            break;
        }
    }

    if (ans) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 

#define ll long long
#define db double
#define el "\n"
#define ld long double
#define rep(i,n) for(int i=0;i<n;i++)
#define rev(i,n) for(int i=n;i>=0;i--)
#define rep_a(i,a,n) for(int i=a;i<n;i++)
#define tr(ds, it) for(auto it=ds.begin(); it!=ds.end(); it++)
#define rtr(ds, it) for(auto it=ds.rbegin(); it!=ds.rend(); it--)
#define all(ds) ds.begin(), ds.end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
typedef priority_queue <int> pq;
typedef vector< long long > vi;
typedef pair<long long, long long> ii;
#define o_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define graph vector<vi>

const ll mod = 1000000007;
ll po(ll x, ll n ){ 
    ll ans=1;
     while(n>0){
         if(n&1) ans=(ans*x)%mod;
         x=(x*x)%mod;
         n/=2;
     }
     return ans;
}



int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
   
    int T=1;
    //cin >> T;
    while(T--){
        ll n;
        cin>>n;
        ll cnt=0;
        rep_a(i,1,(ll)sqrt(n-1)+1){
            if((n-1)%i==0){
                if(i>1)cnt++;
                if(i!=(n-1)/i) cnt++;
            }
        }
        rep_a(i,1,(ll)sqrt(n)+1){
            if(n%i==0){
                ll x=n;
                while(x%i==0 && x>0 && i!=1) x/=i;
                if(x%i==1) cnt++;
                if(i!=n/i){
                    x=n;
                    while(x%(n/i)==0 && x>0) x/=(n/i);
                    if(x%(n/i)==1) cnt++;
                }
            }
        }
        cout<<cnt<<el;

    }

    return 0;
}

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

int main() {
  string S;
  cin >> S;
  
  for(int i=0;i<S.size();i++){
    if(S.at(i) == 'a' ||
       S.at(i) == 'i' ||
       S.at(i) == 'u' ||
       S.at(i) == 'e' ||
       S.at(i) == 'o'){
      cout << "vowel" << endl;
    }else{
      cout << "consonant" << endl;
    }
  }
}


Measured memory_bytes: 3548
#pragma GCC optimize ("O3")
// #pragma GCC target ("avx")
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define NDEBUG
#define eprintf(...) do {} while (0)
#endif
#include<cassert>

using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) {
    for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }
    putchar('\n');
}


void MAIN() {
    int L, R, D;
    scanf("%d%d%d", &L, &R, &D);
    int ans = 0;
    for (int i=L; i<=R; i++) if (i % D == 0) ans++;
    printf("%d\n", ans);

}

int main() {
    int TC = 1;
//    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}



Measured memory_bytes: 3760
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <cstdint>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

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

constexpr ll MOD = 1000000007;
constexpr long double EPS = 1e-10;
constexpr int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    string s, t;
    cin >> s >> t;
    cout << t << s << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
    ll a,b,k,s2;
    cin>>a>>b>>k;
    ll s = a-k;
    if(s<0)
    {
        s=0;
        k=k-a;
        s2=b-k;
        if(s2<0) s2=0;
    }
    else s2=b;
    cout<<s<< " "<< s2<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for(ll i = 0; i < (n); ++i )
#define rep_rev(n,i) for(ll i = n; i >= 0; --i )
using namespace std;
using P = pair<int, int>;
const long long INF = 1LL << 60;

int main(){
  int N,K; cin >> N >> K;
  vector<double> p(N);
  int idx[2];
  double t = 0;
  double sum = 0;
  double ans = 0.;
  rep(i,N){
    cin >> p[i];
    if(i == K-1){
      for(int j = 0; j < K; ++j) sum += p[j];
      if(t < sum){
        t = sum;
        idx[0] = 0;
        idx[1] = K-1;
      }
      sum -= p[0];
    }
    else if(i > K-1){
      sum += p[i];
      if(t < sum){
        t = sum;
        idx[0] = i-K+1;
        idx[1] = i;
      }
      sum -= p[i-K+1];
    }
  }
  for(int i = idx[0]; i <= idx[1]; ++i){
    double tmp = 0;
    rep(j,p[i]) tmp += j+1;
    ans += (double)tmp/(double)p[i];
  }
  printf("%0.10lf\n",ans);
  return 0;
}


Measured memory_bytes: 1792
n = gets.to_i
base = gets.chomp.split(" ").map(&:to_i)
m = gets.to_i
compare = gets.chomp.split(" ").map(&:to_i)
count = 0

compare.each do |i|
  left = 0
  right = base.size
  if base[n-1] >= i then
    while left + 1 < right
      mid = ((left+right)/2).floor
      if i == base[mid] then
        count += 1
        break
      elsif i < base[mid] then
        right = mid
      else
        left = mid
      end
    end
  end
end

puts count

Measured memory_bytes: 18092
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
using namespace std;

typedef long long ll;
typedef double db;
typedef long double ldb;

template<class T> inline void checkmin(T &a,const T &b){if(b<a) a=b;}
template<class T> inline void checkmax(T &a,const T &b){if(b>a) a=b;}

const int maxn=2e5+10;
const ll mod=1e9+7;

ll sum[maxn],a[maxn],ans=0;
int n;

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


Measured memory_bytes: 6928
#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 n;
    cin >> n;
    vector<int> A(n), B(n);
    rep(i, n) cin >> A[i] >> B[i];
    sort(A.begin(), A.end());
    sort(B.begin(), B.end(), greater<int>());
    int ans = 0;
    if (n%2 == 1) {
        ans = B[n/2] - A[n/2] + 1;
    } else {
        int min_m = A[n/2-1] + A[n/2];
        int max_m = B[n/2-1] + B[n/2];
        ans = max_m - min_m + 1;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4828