akhauriyash/Code-Regression huggingface dataset:
#define _CRT_SECURE_NO_WARNINGS // #pragma warning(disable:4996)
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <functional>
#include <sstream>
#include <cmath>
#include <set>
#include <map>
using namespace std; 

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define pb push_back
#define mp(a,b) make_pair(a,b)
#define all(a) a.begin(),a.end()
#define len(x) ((int)(x).size())
#define tmax(a,b,c) max((a),max((b),(c)))
#define tmin(a,b,c) min((a),min((b),(c)))
#define debug(x) cerr << #x << " is " << x << endl;

typedef pair<int, int> Pii;
typedef vector<int> Vi;
typedef vector<vector<int> > VVi;
typedef long long ll;
const int inf = 2e9;
const ll ll_inf = 1e17;
const int mod = 1e9 + 7;
const long double eps = 1e-10;

char b1[5] = {'.', ',', '!', '?', ' '};
char b2[3] = {'a', 'b', 'c'};
char b3[3] = {'d', 'e', 'f'};
char b4[3] = {'g', 'h', 'i'};
char b5[3] = {'j', 'k', 'l'};
char b6[3] = {'m', 'n', 'o'};
char b7[4] = {'p', 'q', 'r', 's'};
char b8[3] = {'t', 'u', 'v'};
char b9[4] = {'w', 'x', 'y', 'z'};

int main()
{
	int n;
	cin >> n;
	while(n--) {
		string s, ans;
		cin >> s;
		rep(i,0,s.size()) {
			while(s[i] == '0') i++;
			int cnt = 0;
			int j = i;
			while(j+1 < s.size() && s[j+1] != '0') {
				cnt++;
				j++;
			}
			if (s[i] == '1') {
				ans += b1[cnt%5];
			}
			else if (s[i] == '2') {
				ans += b2[cnt%3];
			}
			else if (s[i] == '3') {
				ans += b3[cnt%3];
			}
			else if (s[i] == '4') {
				ans += b4[cnt%3];
			}
			else if (s[i] == '5') {
				ans += b5[cnt%3];
			}
			else if (s[i] == '6') {
				ans += b6[cnt%3];
			}
			else if (s[i] == '7') {
				ans += b7[cnt%4];
			}
			else if (s[i] == '8') {
				ans += b8[cnt%3];
			}
			else if (s[i] == '9') {
				ans += b9[cnt%4];
			}
			i = j;
			while(s[i] == '0') i++;
		}
		cout << ans << endl;
	}

	return 0;
}

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

class Combination
{
    vector<long long> fact;
    vector<long long> factinv;
    long long MOD = 1e9 + 7;
    long long modpow(long long a, long long n)
    {
        if (n == 0)
            return 1;
        if (n % 2 == 0)
        {
            long long t = modpow(a, n / 2);
            return t * t % MOD;
        }
        return a * modpow(a, n - 1) % MOD;
    }

    long long modinv(long long a)
    {
        // mod is prime
        return modpow(a, MOD - 2);
    }

public:
    Combination(int n) : fact(n), factinv(n)
    {
        fact[0] = 1;
        for (int i = 1; i < n; i++)
        {
            fact[i] = fact[i - 1] * i % MOD;
        }
        factinv[n - 1] = modinv(fact[n - 1]);
        for (int i = n - 2; i >= 0; i--)
        {
            factinv[i] = factinv[i + 1] * (i + 1) % MOD;
        }
    }

    long long ncr(long long n, long long r)
    {
        if (r < 0 || r > n)
            return 0;
        return fact[n] * factinv[r] % MOD * factinv[n - r] % MOD;
    }

    long long npr(long long n, long long r)
    {
        if (r < 0 || r > n)
            return 0;
        return fact[n] * factinv[n - r] % MOD;
    }

    long long nhr(long long n, long long r)
    {
        if (n == 0 && r == 0)
            return 1;
        return ncr(n + r - 1, r);
    }
};

int main()
{
    int n;
    cin >> n;
    Combination comb = Combination(n + 10);
    map<int, vector<int>> m;
    int id = 0;
    rep(i, n + 1)
    {
        int x;
        cin >> x;
        m[x].push_back(i + 1);
        if (m[x].size() == 2)
        {
            id = x;
        }
    }
    long long int mod = 1e9 + 7;
    for (int i = 1; i <= n + 1; i++)
    {
        cout << (comb.ncr(n + 1, i) + mod - comb.ncr(m[id][0] + n - m[id][1], i - 1)) % mod << endl;
    }
}


Measured memory_bytes: 13696
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {

	static BufferedReader reader;
	//static field here
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		reader = new BufferedReader(new InputStreamReader(System.in));
		//code here
		String[] HN = readLine();
		int N = Integer.parseInt(HN[0]);
		int K = Integer.parseInt(HN[1]);
		String[] as = readLine();
		int[] a = new int[N];
		for(int i=0;i<N;i++) {
			a[i]=Integer.parseInt(as[i]);
		}
		Arrays.sort(a);
		long cnt = 0;
		for(int i=0;i<N-K;i++) {
			cnt+=a[i];
		}
		print(cnt);
		
		
		//String[] s = readLine();
		//print(num);
	}
	
	//functions here
	//note that all methods should be STATIC
	private static long gcd(long m, long n) {
	    if(m < n) return gcd(n, m);
	    if(n == 0) return m;
	    return gcd(n, m % n);
	}
	private static long lcm(long m, long n) {
	    return m * n / gcd(m, n);
	}
	private static String[] readLine(){
		try{
			return reader.readLine().split(" ");
		}catch(Exception e){
			e.printStackTrace();
			return new String[]{e.getMessage()};
		}
	}
	private static void print(Object o){
		System.out.println(o);
	}
	private static void print(){
		System.out.println();
	}
}

Measured memory_bytes: 52692
n = int(input())
alIst = list(map(int, input().split()))

sumN = 0

for i in range(n):
    sumN += alIst[i]

mean = sumN / n

min_margin = float("inf")
frame = 0

for i in range(n):
    a = alIst[i]
    margin = abs(a-mean)
    if margin < min_margin:
        min_margin = margin
        frame = i

print(frame)

Measured memory_bytes: 3064
import fractions

a, b, c, d = map(int, input().split())

a -= 1
lcm = (c * d) // fractions.gcd(c, d)

divisible_c = (b // c) - (a // c)
divisible_d = (b // d) - (a // d)
divisible_cd = (b // lcm) - (a // lcm)

print((b - a) - (divisible_c + divisible_d - divisible_cd))


Measured memory_bytes: 5048
n = int(input())
f = [list(map(int,input().split())) for _ in range(n)]
p = [list(map(int,input().split())) for _ in range(n)]
ans = - 10 ** 9

for bit in range(1, 2 ** 10):
    cc = 0
    for i in range(n):
        c = 0
        for j in range(10):
            if bit & (1<<j) and f[i][j]:
                c += 1
        cc += p[i][c]
    ans = max(ans, cc) 
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i,a) repi(i,0,a)
#define pb push_back
const int inf = 1e9;
int N, Q;
vector<int> ch[100010];
int marked[100010];

void dfs(int v, int a){
    if(marked[v] == v or marked[v] == a) return;
    marked[v] = a;
    rep(i,ch[v].size()) dfs(ch[v][i], a);
}

int solve(){
    memset(marked, 0, sizeof(marked));
    int ans = 0;
    while(Q--){
        char c; int v;
        cin >> c >> v;
        v--;
        if(c == 'Q') ans += marked[v]+1;
        else dfs(v, v);
    }
    return ans;
}

bool input(){
    cin >> N >> Q;
    if(!N and !Q) return 0;
    rep(i,N) ch[i].clear();
    rep(i,N-1) {
        int a; cin >> a;
        ch[a-1].pb(i+1);
    }
    return 1;
}
signed main(){
    while(input()) cout << solve() << endl;
    return 0;
}

Measured memory_bytes: 11104
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
using namespace std;
typedef long long ll;

int main(){
	int n,m;cin>>n;
	map<string,int> ma;
	for(int i=0;i<n;i++){
	    string s;cin>>s;
	    ma[s]++;
	}
	cin>>m;
	for(int i=0;i<m;i++){
	    string s;cin>>s;
	    ma[s]=max(0,ma[s]-1);
	}
	int ans=0;
	vector<int> v;
	for(auto it:ma)v.push_back(it.second);
	cout<<*max_element(v.begin(),v.end());
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
#define ll long long 
#define max 1e5+1

int n;
ll c[100001];
ll a,b;
ll l,r=1e9+10;

ll search(ll m){
  ll an=0;
  for(int i=0;i<n;i++){
    if(a*m<c[i]) an+=m+1;
    else if(b*m>=c[i]);
    else
      an += (c[i]-b*m+(a-b-1))/(a-b);
  }
  return an;
}

int main(){
  cin>>n>>a>>b;
  for(int i=0;i<n;i++)
    cin>>c[i];

  while(r-l!=1){
    ll m = (r+l)/2;
    ll an = search(m);
    if(an<=m) r=m;
    else l = m;
  }

  cout<<r<<endl;

  return 0;
}



Measured memory_bytes: 1024
#include <iostream>
#include <map>
#include <algorithm>
#include <string>
#include <vector> 
#include <numeric>
#include <cmath>
#include <queue>
#include <iomanip>
#include <functional>


#define CHMAX(a,b) a = std::max(a,b)
#define CHMIN(a,b) a = std::min(a,b)
#define MAXMIN(a,b,c) std::max(a,min(b,c))
#define CHABS(a) a = std::abs(a) 
#define COUT(a) std::cout << a << std::endl
#define CERR(a) std::cerr << a << std::endl
#define FOR(n) for(lli i = 0; i < n; i++)

using namespace std;
using lli = long long int;
using pll = pair<lli, lli>;
using tlll = tuple<lli, lli, lli>;
using vll = vector<lli>;

lli mod197 = 1000000007LL;
lli INF = 10000000000000;

// ax + by = gcd(a,b) 最大公約数
template< typename T >
T extgcd(T a, T b, T& x, T& y) {
	T d = a;
	if (b != 0) {
		d = extgcd(b, a % b, y, x);
		y -= (a / b) * x;
	}
	else {
		x = 1;
		y = 0;
	}
	return d;
}

int main(void) {

	int H, A, sum = 0;
	cin >> H >> A;

	for (int i = 0; i < A; i++) {
		int t;
		cin >> t;
		sum += t;
	}

	if (H <= sum) {
		COUT("Yes");
	}
	else {
		COUT("No");
	}


	return 0;
}


Measured memory_bytes: 256
import sys
from fractions import gcd
n = input()
arr = [input() for i in range(n)]
if n == 1:
	print arr[0]
	sys.exit(0)
gc = (arr[0]*arr[1])/gcd(arr[0],arr[1])
for i in range(2,n):
	gc = gc*arr[i]/gcd(gc,arr[i])
print gc

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

int main() {
    int h, w;
    cin >> h >> w;
    vector<vector<char>> s(h, vector<char>(w));
    for(int i=0; i<h; i++){
        string ss;
        cin >> ss;
        for(int j=0; j<w; j++){
            s[i][j] = ss[j];
        }
    }

    vector<vector<int>> ans(h+2, vector<int>(w+2));
    for(int i=0; i<w+2; i++){
        ans[0][i] = 0;
        ans[h+1][i] = 0;
    }
    for(int i=0; i<h+2; i++){
        ans[i][0] = 0;
        ans[i][w+1] = 0;
    }

    for(int i=1; i<h+1; i++){
        for(int j=1; j<w+1; j++){
            if(s[i-1][j-1] == '#'){
                ans[i][j] = 10;
                ans[i][j-1]++;
                ans[i][j+1]++;
                ans[i-1][j]++;
                ans[i+1][j]++;
                ans[i+1][j+1]++;
                ans[i+1][j-1]++;
                ans[i-1][j+1]++;
                ans[i-1][j-1]++;
            }
        }
    }

    for(int i=1; i<h+1; i++){
        for(int j=1; j<w+1; j++){
            if(ans[i][j]>=10){
                cout << '#';
            }else{
                cout << ans[i][j];
            }
        }
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <limits>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cstdint>
#include <functional>
#define rep(i, s, g) for (i = s; i < g; i++)
using namespace std;
using ll = long long;
const ll mod = 1000000000 + 7; //10^9


struct unionfind
{
    vector<long long> d;

    unionfind(long long n) : d(n, -1) {}

    long long root(long long x)
    {
        if (d[x] < 0)
        {
            return x;
        }
        else
        {
            return d[x] = root(d[x]);
        }
    }

    bool unite(long long x, long long y)
    {
        x = root(x);
        y = root(y);

        if (x == y)
        {
            return false;
        }

        if (d[x] > d[y])
        {
            swap(x, y);
        }

        d[x] += d[y];
        d[y] = x;
        return true;
    }

    bool same(long long x, long long y)
    {
        return root(x) == root(y);
    }

    long long size(long long x)
    {
        return -d[root(x)];
    }
};
int main() {
    int N, M;
    cin >> N >> M;
    unionfind L(N);
    for (int i = 0; i < M; i++)
    {
        int a, b;
        cin >> a >> b;
        a --;
        b --;
        L.unite(a, b);
        
    }
    ll ans = 0;
    for (int i = 0; i < N; i++)
    {
        ans = max(ans, L.size(i));
    }
    
    cout << ans << endl;
    
}

Measured memory_bytes: 4824
def main():
    h,w=map(int,input().split())
    a=[list(map(int,input().split())) for _ in [0]*h]
    b=[list(map(int,input().split())) for _ in [0]*h]
    c=[[abs(a[i][j]-b[i][j]) for j in range(w)] for i in range(h)]
    t=7160
    dp1=[[False]*(t+1) for _ in [0]*w]
    dp1[0][c[0][0]]=True
    for j in range(1,w):
        v=c[0][j]
        for k in range(t+1):
            if dp1[j-1][k]==True:
                if v+k<=t:
                    dp1[j][v+k]=True
                if abs(v-k)<=0:
                    dp1[j][abs(v-k)]=True
    for i in range(1,h):
        dp2=[[False]*(t+1) for _ in [0]*w]
        for j in range(w):
            v=c[i][j]
            for k in range(t+1):
                if dp1[j][k]==True:
                    if v+k<=t:
                        dp2[j][v+k]=True
                    if abs(v-k)<=t:
                        dp2[j][abs(v-k)]=True
        for j in range(1,w):
            v=c[i][j]
            for k in range(t+1):
                if dp2[j-1][k]==True:
                    if v+k<=t:
                        dp2[j][v+k]=True
                    if abs(v-k)<=t:
                        dp2[j][abs(v-k)]=True  
        dp1=dp2
    for i,j in enumerate(dp1[w-1]):
        if j==True:
            print(i)
            break
main()


Measured memory_bytes: 159880
#include <iostream>

using namespace std;
using ll = long long;
using ld = long double;

#define ALL(x) begin(x), end(x)
#define REP(i, n) for (size_t i = 0, i##_len = (n); i < i##_len; ++i)

void solve(ll X, ll A, ll B) {
  if (B - A <= 0) {
    cout << "delicious" << endl;
  } else if (B - A <= X) {
    cout << "safe" << endl;
  } else {
    cout << "dangerous" << endl;
  }
}

int main() {
  ll X;
  cin >> X;
  ll A;
  cin >> A;
  ll B;
  cin >> B;
  solve(X, A, B);
  return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> H(N);
  for (int i = 0; i < N; ++i) {
    cin >> H[i];
  }

  string ans = "Yes";
  for (int i = 1; i < N; ++i) {
    if (H[i] >= H[i - 1] + 1) {
      --H[i];
    } else if (H[i] < H[i - 1]) {
      ans = "No";
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MAX = 9999999999;
int N, M, X;
ll C[12];
int A[12][12];

bool is_clear(vector<int>& s) {
    bool ok = true;
    for (int i = 0; i < M; ++i) {
        if (s[i] < X) {
            ok = false;
            break;
        }
    }
    return ok;
}

ll rec(int n, ll amount, vector<int>& s) {
    if (N <= n) {
        return (is_clear(s) ? amount : MAX);
    }
    vector<int> s1(M, 0);
    for (int i = 0; i < M; i++) {
        s1[i] = s[i];
        s1[i] += A[n][i];
    }
    return min(
            rec(n+1, amount + C[n], s1),
            rec(n+1, amount, s));
}

void solve() {
    cin >> N >> M >> X;
    for (int i = 0; i < N; ++i) {
        cin >> C[i];
        for (int j = 0; j < M; ++j) {
            cin >> A[i][j];
        }
    }
    vector<int> s(M, 0);
    ll ans = rec(0, 0, s);
    cout << (ans == MAX ? -1 : ans) << endl;
}

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


Measured memory_bytes: 3632
#include"bits/stdc++.h"
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using pii = pair<int, int>;

void Main(){
	int n;
	cin >> n;
  	int a;
  	vi cnt(n+5, 0);
	rep(i,n-1) {
      cin >> a;
      cnt[a]++;
    }
	rep3(i, 1, n) cout << cnt[i] << endl;
	return;
}

int main(){
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
	return 0;
}


Measured memory_bytes: 3992
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
    	int[] stack = new int[100];
    	int now = 0;
    	while(scan.hasNext()){
    		String line = scan.next();
    		switch(line){
    			case "+":
    				stack[now - 2] += stack[now - 1];
    				now--;
    				break;
    			case "-":
    				stack[now - 2] -= stack[now - 1];
    				now--;
    				break;
    			case "*":
    				stack[now - 2] *= stack[now - 1];
    				now--;
    				break;
    			default:
	    			stack[now] = Integer.parseInt(line);
    				now++;
    		}
    	}
    	System.out.println(stack[0]);
    }
}


Measured memory_bytes: 26120
#include<stdio.h>
int main(void)
{
	int x,y,z;
	scanf("%d",&y);
	x=y%7;
	if(x==1){
		printf("fri\n");
	}
	else if(x==2){
		printf("sat\n");
	}
	else if(x==3){
		printf("sun\n");
	}
	else if(x==4){
		printf("mon\n");
	}
	else if(x==5){
		printf("tue\n");
	}
	else if(x==6){
		printf("wed\n");
	}
	else{
		printf("thu\n");
	}
	return 0;
}



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

//conversion
//------------------------------------------
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();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<bool> VB;
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<char> VC;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

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

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

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL INF = 1e9;
const LL MOD = 1e9+7;

//other
//-------------------------------------------
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define FI first
#define SE second

int main() {
  string S;
  cin >> S;
  int N = SZ(S), r=0, b=0;
  REP(i,N) {
    if(S.at(i) == '0') {
      r++;
    }
    else {
      b++;
    }
  }
  int ans = min(r,b);
  cout << ans*2 << endl;
  return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <sstream>
using namespace std;

int main() {
	// your code goes here
	int n;
	cin >> n;
	vector<int> a(n);
	for(int i=0; i<n; ++i){
		cin >> a[i];
	}
	sort(a.begin(),a.end());
	vector<int> vi;
	for(int i=0; i<n; ++i){
		for(int j=0; j<min(n,(i<=2?4:3)); ++j){
			if(i==j) continue;
			stringstream ss;
			string tmp;
			ss << a[i] << a[j];
			ss >> tmp;
			vi.push_back(atoi(tmp.c_str()));
		}
	}
	sort(vi.begin(),vi.end());
	//for(int i=0; i<vi.size(); ++i) cout << vi[i] << endl;
	cout << vi[2] << endl;
	return 0;
}

Measured memory_bytes: 1396
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define dbg(x) cout << #x << '=' << x << '\n';
#define ll long long
#define pi pair<int,int>
#define pl pair<long long,long long>
#define lg length()
#define pb push_back
#define MAXN 100005
#define INF 1000000005
#define LINF 1000000000000000005

long long n;

int32_t main(){
    ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();
    cin >> n;
    for(long long i=1;i<=3500;i++){
        for(long long j=1;j<=3500;j++){
            if(4*i*j-n*i-n*j>0 && !((n*i*j)%(4*i*j-n*i-n*j))){
                cout << i << ' ' << j << ' ' << (n*i*j)/(4*i*j-n*i-n*j);
                return 0;
            }
        }
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
vector<ll> enumDivisor(ll n) {
    vector<ll> res;
    for (ll i = 1; i * i <= n; i++) {
        if (n % i != 0) continue;
        res.push_back(i);
        if (i * i != n) res.push_back(n / i);
    }
    return res;
}
/* main */
int main(){
    ll n;
    cin >> n;
    int ans = 0;
    for (ll x : enumDivisor(n)) {
        if (x == 1) continue;
        ll tmp = n;
        while (tmp % x == 0) tmp /= x;
        tmp %= x;
        if (tmp == 1) ans++;
    }
    ans += enumDivisor(n - 1).size() - 1;
    cout << ans << '\n';
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
//#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
typedef pair<int,int> Pi;
typedef long long int ll;
const int INF=(ll)(1LL<<31)-1;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
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 dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int n,m;
int num[100100];
bool red[100100];

int main(){
	cin>>n>>m;
	for(int i=0;i<n;i++){
		num[i]=1;
	}
	red[0]=true;
	
	for(int i=0;i<m;i++){
		int t,s;
		cin>>t>>s;
		t--,s--;
		num[t]--,num[s]++;
		if(red[t]){
			red[s]=true;
		}
		if(num[t]==0){
			red[t]=false;
		}
	}
	int ans=0;
	for(int i=0;i<n;i++){
		if(red[i]){
			ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#ifdef ONLINE_JUDGE
#define LLD "%I64d"
#else
#define LLD "%lld"
#endif
#define fu(a,b,c) for(int a=b;a<=(int)c;++a)
#define fd(a,b,c) for(int a=b;a>=(int)c;--a)
#define cu(a,b,c) for(int a=b;a<(int)c;++a)
#define cd(a,b,c) for(int a=b-1;a>=(int)c;--a)
#define gcd(a,b) __gcd(a,b) 
#define pii pair<int,int>
#define pll pair<long long,long long>
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define pf push_front
#define MOD 1000000007
#define MAXN 52
#define MAXH 20
#define MAXM 52
#define INF 100000000
#define ll long long
#define ull unsigned long long
#define RNG rng mt19937(time(NULL))
#define udist(a,b) uniform_int_distribution<uint32_t> distribution(a,b)
#define max3(a,b,c) max(a, max(b, c))
#define min3(a,b,c) min(a, min(b, c))
#define gmax(a,b) a = max(a, b)
#define gmin(a,b) a = min(a, b)
#define whatis(x) cerr << #x << " is " << x << endl;
#define fast_io() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define PI 3.1415926535897932384626433
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

int main(){
	fast_io();
	string s;
	cin >> s;
	int n = s.length();
	vector<vector<int>> dp(n, vector<int>(2));
	dp[0][1] = s[0] != '1';
	dp[0][0] = s[0] != '0';
	cu(i,1,n){
		dp[i][0] = dp[i-1][1] + (s[i] != '0');
		dp[i][1] = dp[i-1][0] + (s[i] != '1');
	}
	cout << min(dp[n-1][0], dp[n-1][1]) << endl;
}
			

Measured memory_bytes: 5840
n = int(input())
A = list(map(int, input().split()))
l, r, SumA, ans = 0, 0, 0, 0

for l in range(n):
    while r < n and (SumA&A[r]==0):
        SumA += A[r]
        r += 1
    ans += r-l
    if l == r:
        r += 1
    else:
        SumA -= A[l]
print(ans)

Measured memory_bytes: 23560
s = input()
n = int(input())
x = []
y = []
r = 1
for i in range(n):
    q = input().split()
    if q[0] == '1':
        r = -r
    elif q[1] == '1':
        z = q[2][0]
        if r == 1:
            x.append(z)
        else:
            y.append(z)
    else:
        z = q[2][0]
        if r == -1:
            x.append(z)
        else:
            y.append(z)
if r == 1:
    x.reverse()
    print("".join(x) + s + "".join(y))
else:
    y.reverse()
    print("".join(y) + s[::-1] + "".join(x))


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

int main() {
  long long n,k;
  cin >> n >> k;
  long long sum;
  long long a,b;
  a=n-k+1;
  b=k;
  while(a!=0){
    sum+=a*b;
    a--;
    b++;
  }
  sum+=n-k+2;
  cout << sum%1000000007;
}


Measured memory_bytes: 3620
n, q = map(int, input().split())
s = list(input())
cusum = [0] * n
c = 0
lr = [[int(x) for x in input().split()] for _ in range(q)]
for i in range(n-1):
    cusum[i] = c
    if s[i:i+2] == ["A", "C"]:
        c += 1
        cusum[i+1] = c
cusum[n-1] = c

for j in range(q):
    l, r = lr[j]
    print(cusum[r-1] - cusum[l-1])

Measured memory_bytes: 25084
-- https://github.com/minoki/my-atcoder-solutions
{-# LANGUAGE BangPatterns #-}
import Data.Char (isSpace)
import Data.Int (Int64)
import Data.Bifunctor (first)
import Data.List
import qualified Data.ByteString.Char8 as BS
import qualified Data.Vector.Unboxed as U

-- skipping 3 (U.fromList [0,1,2,3,4,5]) = [0,3]
skipping :: (U.Unbox a) => Int -> U.Vector a -> [a]
skipping !d !v = [ v U.! i | i <- [0,d..U.length v - 1] ]

main = do
  n <- readLn
  ss <- U.unfoldrN n (readInt64 . BS.dropWhile isSpace) <$> BS.getLine
  let ts = U.zipWith (+) ss (U.reverse ss)
  print $ maximum $ [ maximum $ scanl' (+) 0 (skipping d $ U.take l ts)
                    | d <- [1..n-2]
                    , let l = if (n - 1) `rem` d == 0
                              then min (n `quot` 2) (n - 1 - d)
                              else n - 1 - d
                    ]

readInt64 :: BS.ByteString -> Maybe (Int64, BS.ByteString)
readInt64 s = first fromIntegral <$> BS.readInt s


Measured memory_bytes: 6780
#include<bits/stdc++.h>
#define ll long long
using namespace std;
vector<vector<ll> >DP(104,vector<ll>(100005,INT_MIN));
ll dp(ll n,ll W,ll val[],ll wt[])//,vector< vector<ll> >DP)
{
	if(DP[n][W]==INT_MIN)
	{  if(n==0||W==0)
	     DP[n][W]=0;
	   else	if(wt[n-1]>W)
		DP[n][W]=dp(n-1,W,val,wt);//,DP);
		else
		DP[n][W]=max(dp(n-1,W,val,wt),val[n-1]+dp(n-1,W-wt[n-1],val,wt));//dp(n-1,k,DP)+dp(n-1,k-1,DP);
	}
	return DP[n][W];
	
}

int main()
{ll i,j,n,k,W;
	cin>>n>>W;
	ll val[n],wt[n];
	for(i=0;i<n;i++)
	cin>>wt[i]>>val[i];
//	for(i=0;i<n;i++)
//	cin>>wt[i];
	
	cout<<dp(n,W,val,wt);//,DP);
	return 0;
}

Measured memory_bytes: 82560
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int y = sc.nextInt();

		System.out.println(gcd(x, y));

		sc.close();
	}


	private static int gcd(int x, int y) {
		if(x % y == 0) {
			return(y);
		} else {
			return(gcd(y, x%y));
		}
	}
}



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

using namespace std;

const int mod = 1e9+7;

int main(){
	int n; cin >> n;
	string s; cin >> s;
	int open=0, ans=1;
	for(int i=0;i<2*n;i++){
		if((s[i]=='B' && (open&1)) || (s[i]=='W' && (!(open&1)))){
			if(open<=0){
				cout << 0 << endl;
				return 0;
			}
			ans=(1ll*ans*open)%mod;
			open--;
		}
		else{
			open++;
		}
	}
	for(int i=1;i<=n;i++){
		ans=(1ll*ans*i)%mod;
	}
	if(open==0){
		cout << ans << endl;
	}
	else{
		cout << 0 << endl;
	}
	return 0;
}

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

int N, K, tmp;

void solve() {
  vector<int> bloods(K), family(K);
  for (int i = 0; i < K; i += 1) cin>>bloods[i];
  for (int i = 0; i < N; i += 1) {
    for (int j = 0; j < K; j += 1) {
      cin>>tmp;
      family[j]+=tmp;
    }
  }
  // calc
  for (int i = 0; i < K; i += 1) {
    if (family[i] > bloods[i]) {
      cout<<"No"<<endl;
      return;
    }
  }
  cout<<"Yes"<<endl;
}

int main(int argc, char const* argv[]) {
  while (true) {
    cin>>N>>K;
    if (N==0 && K==0) break;
    solve();
  }
  return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
#define ll long long
#define rep(i,n) for (ll i = 0; i < (ll)(n); ++i)
#define be(v) (v).begin(), (v).end()
#define dcout cout << fixed << setprecision(20) 
ll INF = 1LL << 60;
ll mod = 1e9 + 7;

int main() {
	string s; cin >> s;
	int a=s[0]-'0'; int b=s[1]-'0'; int c=s[2]-'0'; int d=s[3]-'0';
	if(a-b-c-d==7) printf("%d-%d-%d-%d=7\n",a,b,c,d);
	else if(a-b+c-d==7) printf("%d-%d+%d-%d=7\n",a,b,c,d);
	else if(a-b+c+d==7) printf("%d-%d+%d+%d=7\n",a,b,c,d);
	else if(a-b-c+d==7) printf("%d-%d-%d+%d=7\n",a,b,c,d);
	else if(a+b-c-d==7) printf("%d+%d-%d-%d=7\n",a,b,c,d);
	else if(a+b-c+d==7) printf("%d+%d-%d+%d=7\n",a,b,c,d);
	else if(a+b+c-d==7) printf("%d+%d+%d-%d=7\n",a,b,c,d);
	else if(a+b+c+d==7) printf("%d+%d+%d+%d=7\n",a,b,c,d);
}

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

typedef unsigned long long ll;

ll n,a,b;

int main(){
	scanf("%lld%lld%lld",&n,&a,&b);
	ll ans=min(b-1ll,n-a);
	if(ll(a+b)%2ll==1ll){
		ans=min(ans,ll((a-1ll)+1ll+(b-a-1ll)/2ll));
		ans=min(ans,ll((n-b)+1ll+(n-(a+n-b+1))/2ll));
	//	cout<<ll((n-b)+(n-(a+n-b+1))/2ll)<<endl;
		printf("%lld\n",ans);
		return 0;
	}
	ans=min(ans,ll(b-(a+b)/2ll));
	printf("%lld\n",ans);
	return 0;
} 

Measured memory_bytes: 256
using System;
using System.Collections.Generic;

namespace AtCoder2020Ned
{
    class Program
    {
        static void Main(string[] args)
        {
            var currentBalance = 100d;
            var targetAmount = Int64.Parse(Console.ReadLine());
            var elapsedYear = 0;

            for (; currentBalance < targetAmount;)
            {
                currentBalance *= 1.01;
                currentBalance = Math.Truncate(currentBalance);
                elapsedYear++;
            }

            Console.WriteLine(elapsedYear);
            Console.Read();
        }
    }
}


Measured memory_bytes: 27500
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define int ll
#define double long double
#define YES {cout<<"YES"<<'\n';}
#define NO {cout<<"NO"<<'\n';}
#define Yes {cout<<"Yes"<<'\n';}
#define No {cout<<"No"<<'\n';}
#define yes {cout<<"yes"<<'\n';}
#define no {cout<<"no"<<'\n';}
void YN(bool flg){cout<<(flg?"YES":"NO")<<'\n';}
void Yn(bool flg){cout<<(flg?"Yes":"No")<<'\n';}
void yn(bool flg){cout<<(flg?"yes":"no")<<'\n';}
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define out(n) {cout << n << '\n';}
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<VI> VVI;
const int MOD = 1000000007;
const long long INF = 10e10;
const double PI = acos(-1.0);
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; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
int ABS(int a) {if(a<0) a = -a; return a;}
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }
int POW(int a, int n) { int r = 1; while (n > 0) { if (n & 1)r *= a; a *= a; n /= 2; }return r; }
int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}
/*素因数分解*/map< int, int >prime_factor(int n){map< int, int > ret;for(int i = 2; i * i <= n; i++) {while(n % i == 0) {ret[i]++;n /= i;}}if(n != 1) ret[n] = 1;return ret;}
/*約数列挙*/vector<int> divisor(int n){vector<int> v; for(int i=1; i*i<=n; i++){if(n%i==0){v.push_back(i);if(i!=n/i){v.push_back(n/i);}}}sort(v.begin(),v.end()); return v;}
//----------------ライブラリとか----------------

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

    int n,t; cin >> n >> t;
    int ans = INF;
    REP(i,n){
        int x,y; cin >> x >> y;
        if(y<=t) if(x<ans) ans = x;
    }
    if(ans!=INF){out(ans);}
    else out("TLE");

    return 0;
}

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

int main() {
	int a, b, p[4] = { 0 };
	bool check = true;
	for (int i = 0; i < 3; i++) {
		cin >> a >> b;
		p[a - 1]++;
		p[b - 1]++;
	}
	for (int i = 0; i < 4; i++) {
		if (p[i] == 0 || p[i] > 2) {
			check = false;
		}
	}
	if (check) cout << "YES";
	else cout << "NO";
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
int main() {
 
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  
  int L, R;
  L = A + B;
  R = C + D;
  
  if ( L > R ) {
    cout << "Left" << endl;
  }
  
  if ( L == R ) {
    cout << "Balanced" << endl;
  }
  
  if ( L < R ) {
    cout << "Right" << endl;
  }
}

Measured memory_bytes: 256
//#pragma GCC optimize(2)
//#pragma G++ optimize(2)
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <climits>
#include <algorithm>
#include <queue>
#include <vector>
using namespace std;

long long anss,anst;
string s;
int main()
{
    cin>>s;
    for (int i=0; i<s.size(); i++){
        if(s[i]=='S'){
            anss++;
        }
        else {
            anst++;
            if(anss) anss--,anst--;
        }
    }
    cout<<anss+anst<<endl;


    return 0;
}

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

#define vec(v) vector<int>(v)
#define be(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define mapci(mp) map<char*,int>(mp)
#define mapcc(mp) map<char*,char*>(mp)
typedef long long ll;
using namespace std;

int main() {
    /*cin.tie(0);
    ios::sync_with_stdio(false);*/
    int ans=0,n,a;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a;
        if(a%2==1){
            ans++;
        }
    }
    if(ans%2==1){
        cout <<"NO"<<endl;
    }
    else{
        cout <<"YES"<<endl;
    }
    return 0;
}


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

using namespace std;

typedef long long ll;
const int MOD = 998244353;

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

int mul(int a, int b)
{
    return a * (ll) b % MOD;
}

int pw(int a, int b)
{
    int r = 1;
    while (b)
    {
        if (b & 1)
        {
            r = mul(r, a);
        }
        a = mul(a, a);
        b /= 2;
    }
    return r;
}

int dv(int a, int b)
{
    return mul(a, pw(b, MOD - 2));
}

const int N = (int) 2e5 + 7;
int n;
int k;
int a[N];
int enter[N];
int kek;
int val[N];
int inv_val[N];
int inv2;
int aib[N];

void clr()
{
    for (int i = 1; i <= n; i++)
    {
        aib[i] = 0;
    }
}

void op(int i, int x)
{
    while (i <= n)
    {
        aib[i] = add(aib[i], x);
        i += i & (-i);
    }
}

int get(int i)
{
    int sol = 0;
    while (i)
    {
        sol = add(sol, aib[i]);
        i -= i & (-i);
    }
    return sol;
}

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

    cin >> n >> k;
    inv2 = dv(1, 2);
    kek = dv(k - 1, k);
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
        enter[i] = max(0, i - k);
        val[i] = pw(kek, enter[i]);
        inv_val[i] = dv(1, val[i]);
    }
    int inversion_count = 0;
    for (int i = 1; i <= n; i++)
    {
        inversion_count = add(inversion_count, i - 1 - get(a[i]));
        op(a[i], 1);
    }
    clr();
    int invs = 0, tot = 0;
    for (int i = n; i >= 1; i--)
    {
        int x, y;
        y = get(a[i]);
        x = add(tot, -y);
        tot = add(tot, val[i]);
        op(a[i], val[i]);
        x = mul(x, inv2);
        y = mul(y, inv2);
        x = mul(x, inv_val[i]);
        y = mul(y, inv_val[i]);
        invs = add(invs, add(x, -y));
    }
    invs = add(invs, inversion_count);
    cout << invs << "\n";
    return 0;

}


Measured memory_bytes: 7528
//g++ -std=c++14 test.cpp -o test.out
//問題URL
//https://atcoder.jp/contests/abc144/tasks/abc144_e
//二部探索
//答えを「とりあえず」centerと決めて、とりあえず決めた値をleft,rightを使って範囲を狭めていく
//解から逆算するイメージで実装していく
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <utility>
#include <limits.h>
#include <bitset>
using namespace std;
 
#define LL long long int
const LL INF = (LL)(1e18)+1;
const LL mod = 1000000007ll;

LL N,K;
LL A[200000],F[200000];

LL ans = 0;

void solve(){
	sort(A,A+N);//昇順
	sort(F,F+N,greater<LL>());//降順
	//二部探索
	LL left = -1;//ギリギリ実現不可能な時間
	LL right = 1e12;//ギリギリ実現可能な時間
	while(left+1<right){
		LL center = (left+right)/2;
		//消化コストA[i]から修行してA'[i]に減らせたとする
		//このときかかる時間は　A'[i]×F[i] = T[i] とおける
		//変形して A'[i] = T[i]/F[i]
		//このとき修行の結果落とせた消化コストは
		//A[i] - T[i]/F[i] と表せる
		//この和はK以下でなくてはならない

		//以上を念頭に置いた上で次のように考える
		//全てのメンバーについて完食にかかる時間を center 以下にできるか
		//A[i] - center/F[i] を0~N-1まで足し合わせてそれがK以下かどうか見れば良い
		//K以下 = そのcenter時間は実現可能
		//Kより大きい = 実現不可能
		bool ok = [&]{
			LL sum = 0;
			for(int i=0;i<N;i++){
				sum += max(0ll,A[i]-center/F[i]);
			}
			return sum<=K;
		}();
		if(ok) right = center;//実現可能ラインを下げる
		else left = center;//実現不可能ラインを上げる
	}
	ans = right;
}
 
int main(){
	cin >> N >> K;
	for(int i=0;i<N;i++) cin >> A[i];
	for(int i=0;i<N;i++) cin >> F[i];
 
	solve();

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

Measured memory_bytes: 3328
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <random>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
typedef vector<int> vi;
typedef long long ll;
typedef pair<int, int> pii;
typedef double db;
mt19937 mrand(random_device{}());
const ll mod = 998244353;
int rnd(int x) { return mrand() % x; }
ll powmod(ll a, ll b) { ll res = 1; a %= mod; assert(b >= 0); for (; b; b >>= 1) { if (b & 1)res = res * a%mod; a = a * a%mod; }return res; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
// head

ll N, X;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	//	freopen("a.in","r",stdin);
	//	freopen("a.out","w",stdout);
	cin >> N >> X;

	ll ans = 0;
	if (X > N - X) {
		X = N - X;
	}

	ans = N;
	ll XX = X;
	N = N - X;
	while (X) {
		if(N%X)
			ans += 2 * X * (N / X);
		else 
			ans += 2 * X * (N / X) - X;
		N %= X;
		swap(N, X);
	}

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


Measured memory_bytes: 256
N, K = map(int, input().split())

mod = 10**9+7
res = 1
l = K*(K-1)//2
r = l+(N-K+1)*K
for i in range(K, N+1):
    res += r-l+1
    res %= mod
    l += i
    r += N-i
print(res)

Measured memory_bytes: 9176
#include<bits/stdc++.h>
using namespace std;
long long a,n,k[100005],ans=999999999999999;
int main()
{
	cin>>a>>n;
	for(int s=1;s<=a;s++)
	{
		cin>>k[s];
		if(s>=n)
		{
			if(k[s]<=0&&k[s-n+1]<=0)
			ans=min(ans,-k[s-n+1]);
			if(k[s]>0&&k[s-n+1]<=0)
			ans=min(ans,min(k[s]-k[s-n+1]*2,k[s]*2-k[s-n+1]));
			if(k[s]>=0&&k[s-n+1]>=0)
			ans=min(ans,k[s]);
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 1024
// In the name of God

#include <bits/stdc++.h>

using namespace std;

const int N = 1e5+5;

long long d[N];
vector<pair<int,int>> adj[N];

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	for(int i = 0; i < n-1; i++) {
		int a, b, c;
		cin >> a >> b >> c;
		a--;
		b--;
		adj[a].push_back(make_pair(b, c));
		adj[b].push_back(make_pair(a, c));
	}
	int q, k;
	cin >> q >> k;
	k--;
	for(int i = 0; i < n; i++) d[i] = 1e16;
	d[k] = 0;
	priority_queue<pair<long long, int>> pq;
	pq.push(make_pair(0, k));
	while(!pq.empty()) {
		int now = pq.top().second;
		pq.pop();
		for(pair<int,int> pv : adj[now]) {
			if(d[pv.first] > d[now] + pv.second) {
				d[pv.first] = d[now] + pv.second;
				pq.push(make_pair(-d[pv.first], pv.first));
			}
		}
	}
	for(int i = 0; i < q; i++) {
		int u, v;
		cin >> u >> v;
		u--;
		v--;
		cout << d[u]+d[v] << "\n";
	}
	return 0;
}


Measured memory_bytes: 10096
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);
		String[] temp = scanner.nextLine().split(" ");

		int r = Integer.parseInt(temp[0]);
		int d = Integer.parseInt(temp[1]);
		int x = Integer.parseInt(temp[2]);
		int ans = 0 ;
		ans = solve(r, d, x ,9);



	}

	public static int solve(int r, int d, int x, int count) {

		if(count == 0) {
			int ans = r * x - d;
			System.out.println(ans);
			return r * x - d;
 		}else {

			int ans = r * solve(r, d, x, count - 1) - d;
			System.out.println(ans);
			return ans;
 		}

	}

}


Measured memory_bytes: 23636
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,K;
  cin >> N >> K;
  int ans =0;
  
  vector<int> vec(N);
 
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
    for (int i = 0; i < N; i++) {
      if(vec.at(i)>= K){
      ans = ans+1;
      }
    }
  cout << ans <<endl;
  
 
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define FORR(i,a,b) for (int i=(a);i>=(b);i--)
#define pb push_back
#define pcnt __builtin_popcount
#define show(x) cout<<#x<<" = "<<x<<endl;
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define fi first
#define se second
#define rng(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define sz(x) (int)(x).size()
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef set<int> si;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pll> vpll;
typedef set<ll> sl;
typedef __int128_t lll;
typedef pair<lll,lll> plll;
typedef vector<lll> vlll;
template<typename T>string join(vector<T>&v)
{stringstream s;FOR(i,0,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename A, size_t N, typename T>void Fill(A (&array)[N], const T&v)
{fill((T*)array,(T*)(array+N),v);}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll gcd(ll a,ll b){lll x=0,y=0; return gcd(a, b, x, y);}
ll modpow(lll a,lll n,ll m){if(a==0)return a;lll p=1;for(;n>0;n/=2,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
void dout(double d){printf("%.12f\n",d);}

const int iinf = 1e9;
const ll linf = 1e18;
const int mod = 1e9+7;
const double pi = acos(-1);
const double eps = 1e-10;
const int N = 1<<18;
int n, a[N][2];
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  FOR(i, 0, 1<<n) cin >> a[i][0];
  FOR(j, 0, n)FOR(i, 0, 1<<n)if(i&1<<j){
    int k = i^1<<j;
    if(a[i][0] >= a[k][0]){
      maxs(a[i][1], a[k][0]);
    }else{
      a[i][1] = max(a[i][0], a[k][1]);
      a[i][0] = a[k][0];
    }
  }
  int ans = 0;
  FOR(i, 1, 1<<n){
    maxs(ans, a[i][0] + a[i][1]);
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 5120
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
        h: [u64;n]
    }
    let mut h = h;
    let mut res = true;
    for i in (1..n).rev() {
        if h[i-1] > h[i] {
            if h[i-1] - 1 > h[i] {
                res = false;
                break;
            } else {
                h[i-1] -= 1;
            }
        }
    }
    println!("{}", if res {"Yes"} else {"No"});
}


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


int main(void){
    // Your code here!
    int n;
    cin>>n;
    vector<double> x(n);
    vector<string> s(n);

    for(int i=0; i<n; i++){
        cin>>x[i]>>s[i];
    }
    
    double sum=0.0;
    
    for(int i=0; i<n; i++){
        if(s[i]=="JPY"){
            sum+=x[i];
        }
        if(s[i]=="BTC"){
            sum+=x[i]*380000.0;
        }
    }
    
    cout<<sum<<endl;
}


Measured memory_bytes: 256