akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
int GCD(int a,int b){
    if(b>a)swap(a,b);
    return (b==0)?a:GCD(b,a%b);
}
int LCM(int a,int b){
    return a/GCD(a,b)*b;
}
int l[101],r[101],w1[101],w2[101];
int memo[101];
int dfs(int x){
    if(x==0)return 1;
    if(memo[x]!=-1)return memo[x];
    int red=l[x]*dfs(w1[x]);
    int blue=r[x]*dfs(w2[x]);
    int lcm=LCM(red,blue);
    return memo[x]=lcm/l[x]+lcm/r[x];
}
int main(){
    int n;
    while(scanf("%d",&n),n){
        bool flag[101];fill(flag,flag+n+1,true);
        fill(memo,memo+n+1,-1);
        for(int i=1;i<=n;i++){
            scanf("%d%d%d%d",&l[i],&r[i],&w1[i],&w2[i]);
            flag[w1[i]]=flag[w2[i]]=false;
        }
        for(int i=1;i<=n;i++){
            if(flag[i]){
                printf("%d\n",dfs(i));
                break;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 1028
N = int(input())
P = list(map(int, input().split()))
i = 0
ans = 0
while i < N:
    if P[i]-1 == i:
        ans += 1
        if i+1 < N and P[i+1]-1 == i+1:
            i += 1
    i += 1
print(ans)

Measured memory_bytes: 14008
#include <cstdio>
#include <climits>
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <stack>
#include <algorithm>
#include <iomanip>
#include <map>
#include <queue>
#include <functional>
#include <numeric>
#include <chrono>
#include <cstdlib>
using ll = long long;
using namespace std;

const ll MOD = 1e9 + 7;
const double pi = acos(-1);
typedef pair<int, int> P;
#define REP(i, n) for (int(i) = 0; (i) < (n); ++(i))
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define EPS 1e-4
#define OUTPUT(i) (cout << (ll)i << endl)
#define ALL(a) ((a).begin(), (a).end())

bool operator<(const pair<ll, ll> &a, const pair<ll, ll> &b)
{

    if (a.first == b.first)
        return a.second < b.second;

    return a.first < b.first;
}

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
vector<ll> v;

struct C
{
    ll x, y, h;
};
int elem[100010];
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    //cout << fixed << setprecision(15);

    int N, M;
    cin >> N >> M;
    vector<pair<int, int>> vp;
    map<int, int> mp;
    REP(i, M)
    {
        int P, Y;
        cin >> P >> Y;
        vp.push_back(make_pair(P, Y));
        mp[Y] = P;
    }

    map<int, int> mp2;
    for (auto e : mp)
    {
        mp2[e.first] = ++elem[e.second];
        //cout << mp[e.first] << endl;
    }

    for (int i = 0; i < M; ++i)
    {
        cout << setfill('0') << std::right << setw(6) << vp[i].first;
        cout << setfill('0') << std::right << setw(6) << mp2[vp[i].second] << endl;
    }
    return 0;
}


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

int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<int>> st(N + 1);
  for (int i = 0; i < M; i++) {
    int s, t;
    cin >> s >> t;
    st[s].push_back(t);
  }

  // vector<double> dp(N + 1);
  // dp[N] = 0.;
  // for (int i = N - 1; i >= 1; i--) {
  //   int len = st[i].size();
  //   for (int j = 0; j < len; j++) {
  //     dp[i] += dp[st[i][j]] + 1;
  //   }
  //   dp[i] /= len;
  // }
  // double ret = dp[1];

  double ret = N + 1;
  for (int k = 1; k <= N - 1; k++) {
    vector<double> dp(N + 1);
    dp[N] = 0.;
    for (int i = N - 1; i >= 1; i--) {
      int len = st[i].size();
      if (len > 1 && i == k) {
        vector<double> tmp;
        for (int j = 0; j < len; j++) {
          tmp.push_back(dp[st[i][j]]);
        }
        sort(tmp.begin(), tmp.end());
        for (int j = 0; j < len - 1; j++) {
          dp[i] += tmp[j] + 1;
        }
        dp[i] /= (len - 1);
      } else {
        for (int j = 0; j < len; j++) {
          dp[i] += dp[st[i][j]] + 1;
        }
        dp[i] /= len;
      }
    }
    ret = min(ret, dp[1]);
  }

  cout.precision(10);
  cout << ret << endl;
}

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

int main() {
int N;
cin >> N;
vector<int> V(N - 1);
for (int i = 0; i < N - 1; i++) cin >> V.at(i);
V.push_back(100000);
int ans = V.at(0);

for (int i = 1; i < N; i++) {
   ans += min(V.at(i), V.at(i - 1));
 }

cout << ans << endl; 
 
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
 int n;
 cin>>n;
 vector<int> a(n);
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  sort(a.begin(),a.end());
  for(int i=0;i<n;i++){
    if(a[i]==a[i+1]){
      cout<<"NO"<<endl;
return 0;
    }
  }
  cout<<"YES"<<endl;
return 0;
}

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

int gcd(int x, int y){
  int a = max(x,y);
  int b = min(x,y);
  if ( b == 0 ) return a;

  return gcd(b, a % b);
}

int main(){
  int x, y;
  cin >> x >> y;

  cout << gcd(x,y) << endl;

  return 0;
}


Measured memory_bytes: 3112
n = gets.to_i
ps = n.times.map{gets.chomp.split.map(&:to_f)}
sum = 0
(0..n-1).to_a.permutation.each do |a|
  dist = 0
  (1..a.size-1).each do|i|
    dist += Math.sqrt((ps[a[i-1]][0] - ps[a[i]][0]) ** 2 + (ps[a[i-1]][1] - ps[a[i]][1]) ** 2)
  end
  sum += dist
end

puts sum / (1..n).inject(:*)

Measured memory_bytes: 1916
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		long n = sc.nextLong();
		long ans = 0;

		if ((n % 2) == 0) {
			long t = n / 2;
			for (int i = 1; i < 50; i++) {
				ans += t / (long) Math.pow(5, i);
			}
		}

		System.out.println(ans);

		sc.close();
	}

}


Measured memory_bytes: 21844
public class Main {


  private static void solve() {
    char[] s = ns();
    if (s[0] != 'A' || !('a' <= s[1] && s[1] <= 'z') || !('a' <= s[s.length - 1] && s[s.length - 1] <= 'z')) {
      System.out.println("WA");
      return;
    }
    
    int cnt = 0;
    for (int i = 2; i < s.length - 1; i ++) {
      if (s[i] == 'C') {
        cnt ++;
      } else if (!('a' <= s[1] && s[1] <= 'z')) {
        System.out.println("WA");
        return;
        
      }
    }
    if (cnt != 1) {
      System.out.println("WA");
      return;
    }
    System.out.println("AC");
  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}


Measured memory_bytes: 23380
extension String: CollectionType{}
let a : Int = Int(readLine()!)!
let x: [Int] = readLine()!.split(" ").map { Int($0)! }
let sum = x.reduce(0,combine: +)
switch sum%2 {
case 1:
    print("NO")
case 0:
    print("YES")
default:
    break
}



Measured memory_bytes: 7612
#!/usr/bin/env python
#-*- coding: utf-8 -*-

# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_2_C

if __name__ == '__main__':
    a, b, c = map(int, raw_input().split())
    if b < a:
        a, b = b, a
    if c < a:
        a, c = c, a
    if c < b:
        b, c = c, b
    print a, b, c


Measured memory_bytes: 4640
#include <iostream>

using namespace std;

int main(){
	
	long long int x;
	
	cin >> x;
	
	long long int ans = (x / 11) * 2 + 1;
	
	if(x % 11 > 6){
		ans++;
	}
	if(x % 11 == 0){
		ans--;
	}
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    int x,y=0;
    int kame,turu=0;
    scanf("%d %d",&x,&y);

    kame = y-2*x;
    turu = 4*x-y;

    if(kame%2==0 && turu%2==0 && kame>=0 && turu>=0){
        printf("Yes");
    } else {
        printf("No");
    }

    return 0;
}

Measured memory_bytes: 1736
X,Y,Z,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))

# A,B,Cのリストを降順にソート
A.sort(reverse =True)
B.sort(reverse =True)
C.sort(reverse =True)

from heapq import heappush,heappop
hq = []
arg_hash={}
# キューに追加された組み合わせ
val = A[0]+B[0]+C[0]
# valは初期値(最大値)
heappush(hq,(-val,0,0,0))

for i in range(K):
    ans,a,b,c = heappop(hq)
    # heappopで一番大きい値を取り出す
    print(-ans)
    
    arg_a = (a+1,b,c)
    arg_b = (a,b+1,c)
    arg_c = (a,b,c+1)
    # (a,b,c)の次に大きい組み合わせは(a+1,b,c),(a,b+1,c),(a,b,c+1)のいずれか
    
    if a<X-1 and arg_a not in arg_hash:
        arg_hash[arg_a] = 1
        heappush(hq,(-(A[a+1]+B[b]+C[c]),)+arg_a)
    if b<Y-1 and arg_b not in arg_hash:
        arg_hash[arg_b] = 1
        heappush(hq,(-(A[a]+B[b+1]+C[c]),)+arg_b)
    if c<Z-1 and arg_c not in arg_hash:
        arg_hash[arg_c] = 1
        heappush(hq,(-(A[a]+B[b]+C[c+1]),)+arg_c)

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

int main() {

	int A, B, C, K;

	cin >> A >> B >> C >> K;

	int Z;

	if (A > B) {
		Z = A;
		A = B;
		B = Z;
	}
	if(B > C){
		Z = B;
		B = C;
		C = Z;
	}

	for (int i = 0; i < K; i++) {
		C = C * 2;
	}
	
	cout << A + B + C << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	string s;
	cin>>s;
	string t=s;
	reverse(t.begin(),t.end());
	int cnt=0;
	for(int i=0;i<s.size();i++){
		if(s[i]!=t[i]) cnt++;
	}
	if(cnt>0) cout<<cnt/2<<endl;
	else cout<<cnt<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using P = pair<lint, lint>;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
constexpr int MOD = 1000000007;
constexpr int INF = 2147483647;
void yes(bool expr) {
  cout << (expr ? "Yes" : "No") << "\n";
}  
int D;
vector<int> c(26);
vector<vector<int>> s;
int score(vector<int> t) {
  int ans = 0;
  vector<int> last(26);
  REP(i, D) {
    ans += s[i][t[i]];
    last[t[i]] = i + 1;
    REP(j, 26) ans -= c[j] * (i + 1 - last[j]);
  }
  return ans;
}
double TIME_LIMIT = 1980;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> D;
  vector<int> c(26);
  REP(i, 26) cin >> c[i];
  s = vector<vector<int>>(D, vector<int>(26));
  REP(i, D) REP(j, 26) cin >> s[i][j];

  vector<int> t(D);
  REP(i, D) t[i] = i%26;
  
  clock_t start_time = clock();
  int now = score(t);
  int loop = 0;
  double start_temp = 1, end_temp = 0.1;
  int max = 0;
  vector<int> tmax(t);
  while(true) {
    loop++;
    clock_t now_time = clock();
    double time = static_cast<double>(now_time - start_time) / CLOCKS_PER_SEC * 1000.0;
    if(time > TIME_LIMIT) break;
    vector<int> tnew(t);
    int mode = rand() % 10;
    if(mode == 0) {
      int idx = rand() % D;
      int type = rand() % 26;
      tnew[idx] = type;
    } else {
      int idx = rand() % (D-1);
      swap(tnew[idx], tnew[idx+1]);
    }
    int next = score(tnew);
    double temp = start_temp + (end_temp - start_temp) * time / TIME_LIMIT;
    double prob = exp((next-now)/temp);
    if(next > now || prob > (rand()%INF)/(double)INF) {
      t = tnew;
      now = next;
    }
    if(now > max) {
      tmax = t;
      max = now;
    }
    //cout << now << "\n";
    //if(next < now) cout << prob << "\n";
  }
  REP(i, D) cout << (tmax[i]+1) << "\n";
  //cout << max << "\n";
  //cout << loop << "\n";
}

Measured memory_bytes: 4320
import math
import queue
import bisect
import heapq
import time
import itertools

mod = 1e9+7

def swap(a,b):
    return (b,a)

def gcd(a,b): #最大公約数
    if (a<b):
        a,b = swap(a,b)
    if (b==0):
        return a
    else:
        return gcd(b,a%b)

def divisors(a): # 約数列挙
    divisors = []
    for i in range(1,int(a**0.5)+1):
        if a%i==0:
            divisors.append(i)
            if i!=a//i:
                divisors.append(a//i)
    return divisors

def is_prime(a): #素数判定
    if a<2:
        return False
    elif a==2:
        return True
    elif a%2==0:
        return False
    sqrt_num = int(a**0.5)
    for i in range(3,sqrt_num+1,2):
        if a%i==0:
            return False
    return True

def prime_num(a): #素数列挙
    pn = [2]
    for i in range(3,int(a**0.5),2):
        prime = True
        for j in pn:
            if i%j==0:
                prime = False
                break
        if prime:
            pn.append(i)
    return pn

def main():
    a1,a2,a3 = map(int,input().split())
    if a1+a2+a3<22:
        print('win')
    else:
        print('bust')
    return

if __name__=='__main__':
    main()


Measured memory_bytes: 38636
# -*- coding: utf-8 -*-
import sys 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
S = readline().decode().rstrip()
if S[0] == 'R' and S[1] == 'S' and S[2] == 'R':  
    print(S.count('R')-1)
else:
    print(S.count('R'))

Measured memory_bytes: 61764
import java.util.*;class Main{public static void main(String[]z){Scanner s=new Scanner(System.in);for(int w,h,i,j,c=2;(w=s.nextInt()+2)>2;System.out.println(c-2),c=2){int[]a=new int[w*(h=s.nextInt()+2)];for(i=1;i<h-1;++i)for(j=1;j<w-1;++j)a[i*w+j]=s.nextInt();for(i=1;i<h-1;++i)for(j=1;j<w-1;++j)if(a[i*w+j]==1)f(a,w,i*w+j,c++);}}static void f(int[]a,int w,int x,int c){if(a[x]==1){a[x]=c;for(int i:new int[]{-w-1,-w,-w+1,-1,1,w-1,w,w+1})f(a,w,x+i,c);}}}

Measured memory_bytes: 13000
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define se second
#define fi first
#define ll long long
#define INF INT_MAX
#define mod 1000000007
#define chutiyaap ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;
ll pw(ll a, ll b) {
    if (b == 0) return 1;
    ll t = pw(a, b / 2);
    if (b % 2 == 0) return (t * t)%mod;
    else return ((t * t)%mod * a)%mod;
}
int main()
{
	int n,k;cin>>n>>k;
	int a[n+1];for(int i=0;i<n;i++)cin>>a[i];
	sort(a,a+n);
	ll res=0;
	for(ll i=0;i<k;i++)res+=a[i];
	cout<<res;
}


Measured memory_bytes: 3640
#include <iostream>
#include <algorithm>
#include <vector>
#define FOR(i,a,b) for(ut i=(a);i<(int)(b);i++)
#define REP(i,b) FOR(i,0,b)
#define ALL(c) c.begin(),c.end()
#define PB push_back
#define cat //cout << __LINE__ << endl;
using namespace std;
typedef long long LL;
typedef double ld;
typedef LL ut;
typedef vector<ut> VI;
typedef pair<ut,ut> pr;
typedef pair<ut,pr> ppr;
typedef vector<pr> Vpr;
typedef vector<ppr> Vppr;
using namespace std;
const int SIZE=105;
const LL p=7+1e9;
const LL INF=1LL<<60;
LL DP[SIZE][SIZE*SIZE*2];
LL N,K;
LL power(LL n,LL r){
	if(r==0) return 1;
	if(r==1) return n%p;
	LL ans=power(n,r/2);
	return ans*ans%p*power(n,r%2)%p;
}
LL als(LL n,LL k){
	LL pls=k*(k+1)/2%p*power(k+1,n-1)%p*n%p;
	return pls;
}
LL solve(){
	LL ans=0;
	cin >>N >>K;
	DP[N][0]=1;
	REP(i,N){
		LL now=N-i;
		LL times=0;
		REP(j,SIZE*SIZE/now){
			REP(k,K+1){
				times=0;
				if(now>=k){
					times=(j+k)/now;
				}
				DP[now-1][j+times]+=DP[now][j]%p;
					
			}
		}
	}
	REP(i,SIZE*SIZE){
		ans+=(LL)i*DP[0][i];
		ans%=p;
	}
	return (als(N,K)+p-ans)%p;
}
int main(){
	cout << solve() << endl;


	return 0;
}

Measured memory_bytes: 15104
#include <iostream>
#include <string>
#include <bitset>
#include <algorithm>

int main()
{
    int n;
    std::cin >> n;
    std::string s;
    std::cin >> s;

    std::size_t max = 0;
    for (int i = 1; i < n - 1; i++)
    {
        std::bitset<26> a_count(0);
        std::bitset<26> b_count(0);

        for (int j = 0; j < i; ++j)
        {
            a_count[static_cast<char>(s[j] - 'a')] = 1;
        }
        for (int j = i; j < n; ++j)
        {
            b_count[static_cast<char>(s[j] - 'a')] = 1;
        }
        max = std::max(max, (a_count & b_count).count());
    }
    std::cout << max << std::endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.util.stream.*;
class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int[] num = new int[6];
        for (int i = 0; i < 6; i++){
            num[i] = input.nextInt();
        }
        Dice dice = new Dice(num);
        String S;
        S = input.next();
        for (int i = 0; i < S.length(); i++){
            char c = S.charAt(i);
            dice.roll(c);
        }
        dice.disp_top();
    }
}

class Dice {
    private int N,E,W,S,T,B;
    private int[] dice_num;
    Dice(int[] num_array){
        dice_num = num_array;
        T = dice_num[0];
        S = dice_num[1];
        E = dice_num[2];
        W = dice_num[3];
        N = dice_num[4];
        B = dice_num[5];
    }
    public void roll(char direction){
        int tmp;
        if (direction == 'N'){
            tmp = T;
            T = S;
            S = B;
            B = N;
            N = tmp;
        } else if (direction == 'E'){
            tmp = T;
            T = W;
            W = B;
            B = E;
            E = tmp;
        } else if (direction == 'W'){
            tmp = T;
            T = E;
            E = B;
            B = W;
            W = tmp;
        } else {
            tmp = T;
            T = N;
            N = B;
            B = S;
            S = tmp;
        }
    }
    public void disp_top(){
        System.out.println(T);
    }
}


Measured memory_bytes: 26444
#include <bits/stdc++.h>
#define INF 2000000000000000000
#define ll long long
#define pb push_back
using namespace std;

//=============modpow============================
ll modpow(ll a, ll n, ll mod)
{
    ll res = 1;
    while (n > 0)
    {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
//=================================================

//=============modinv============================
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
//=================================================

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll N, a, b;
  cin >> N >> a >> b;
  ll mod = pow(10, 9) + 7;
  ll ans = modpow(2, N, mod) - 1;
  if (ans < 0) {
    ans += mod;
  }
  ll up = 1;
  ll down = 1;
  for (ll i = 0; i < a; ++i) {
    up *= N - i;
    up %= mod;
  }
  for (ll i = 1; i <= a; ++i) {
    down *= modinv(i, mod);
    down %= mod;
  }
  ans -= (up *  down) % mod;
  if (ans < 0) {
    ans += mod;
  }
  up = 1;down = 1;
  for (ll i = 0; i < b; ++i) {
    up *= N - i;
    up %= mod;
  }
  for (ll i = 1; i <= b; ++i) {
    down *= modinv(i, mod);
    down %= mod;
  }
  ans -= (up *  down) % mod;
  if (ans < 0) {
    ans += mod;
  }
  cout << ans << "\n";
}


Measured memory_bytes: 3628
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int n;
    int i=0;
    int sum=0;
    cin>>n;
    int b[n-1];
    for(i=0;i<n-1;i++){
        cin>>b[i];
    }
    for(i=0;i<n-2;i++){
       // cout<<min(b[i],b[i+1]);
        sum=sum+min(b[i],b[i+1]);
       // cout<<min(b[i],b[i+1])<<endl;
    }
    cout<<sum+b[0]+b[n-2];
}

Measured memory_bytes: 256
#include <iostream>
#include <stack>
#include <cstring>
using namespace std;

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

    int H, W;
    cin >> H >> W;

    const int MAXH = 2010;
    const int MAXW = 2010;

    static string S[MAXH];
    for (int r = 0; r < H; r++) {
        cin >> S[r];
    }

    static int height[MAXH][MAXW];
    for (int c = 0; c < W; c++) {
        int t = 0;
        int status = -1; // 1:同じ, 0:異なる
        for (int r = 0; r < H; r++) {
            if (c > 0 and (S[r][c - 1] == S[r][c]) != status) {
                t = r;
                status = (S[r][c - 1] == S[r][c]);
            }
            height[r][c] = r - t + 1;
        }
    }

    // 最大長方形問題
    int ans = 0;
    for (int r = 0; r < H; r++) {
        static int L[MAXW], R[MAXW];
        memset(L, 0, sizeof(L));
        stack<int> st;
        for (int c = 0; c < W; c++) {
            while (!st.empty() and height[r][st.top()] >= height[r][c]) st.pop();
            L[c] = st.empty() ? 0 : (st.top() + 1);
            st.push(c);
        }

        memset(R, 0, sizeof(R));
        while (!st.empty()) st.pop();
        for (int c = W - 1; c >= 0; c--) {
            while (!st.empty() and height[r][st.top()] >= height[r][c]) st.pop();
            R[c] = st.empty() ? (W - 1) : (st.top() - 1);
            st.push(c);
        }

        for (int c = 0; c < W; c++) {
            ans = max(ans, (R[c] - max(0, L[c] - 1) + 1) * height[r][c]);
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 20352
#include<bits/stdc++.h>
#define ll long long
using namespace std;
char a[200005];
int main()
{
	ll n,m=0,ans=0;
	scanf("%s",a);
	n=strlen(a);
	for(int i=n-1;i>=0;i--)
	{
		if(a[i]=='B')
		ans+=m;
		else
		m++;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

typedef long long ll;
typedef long double ld;
typedef int32_t i32;

#define int long long
#define mp make_pair
#define ff first
#define ss second
#define pb push_back
#define pf push_front

#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define RFOR(i,a,b) for(ll i=a;i>=b;i--)
#define FILL(a,b,c) for(ll i=0;i<c;i++) a[i]=b;

#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
#define allr(v) (v).rbegin(), (v).rend()

#define endl "\n"
#define setpri(x) setprecision(x)
#define vp(x) cout<<#x<<" : "<< (x)<<" | "
#define yes cout<<"Yes"<<endl
#define no cout<<"No"<<endl
#define forf(i,a,b) for(int i=a;i<b;i++)

#define INF 1e17+4
#define MINF 
#define MAX_INT 100000
#define MOD 1000000007
ll mod(ll n) { n %= MOD; if (n < 0) return n + MOD; else return n;}
// vector<int> adj[1000002];
// int vis[1000002],dep[1000002],siz[1000002];

// void dfs(ll cur,ll par)
// {
//     vis[cur]=1;siz[cur]=1;
//     for(auto x:adj[cur])
//     {
//         if(vis[x]!=1)
//         {
//             dep[x]=dep[cur]+1;
//             dfs(x,cur);
//             siz[cur]+=siz[x];
//         }    
//     }
// }

// bool sortfunc(const pair<int,int> &a, const pair<int,int> &b) 
// { 
//     return ;


void solve()
{
    int n;
    string s,s1;
    cin>>s>>s1;
    s+=s1[s1.size()-1];
    if(s==s1)
        yes;
    else
        no;
    
    
    
}


signed main()
{
    FAST;
    
    // ll t;cin>>t;while(t--)
        solve();
 
    return 0;
}

Measured memory_bytes: 3656
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val N = sc.nextInt()
    val M = sc.nextInt()
    val ps: Array<Array<Int>?> = arrayOfNulls(M)

    for (i in ps.indices) {
        ps[i] = arrayOf(sc.nextInt(), sc.nextInt(), i)
    }
    ps.sortBy { it!![1] }

    val mp = Array(N + 10) { 0 }
    val res: Array<String?> = arrayOfNulls(M)

    for (l in ps) {
        val p = l!![0]
        val c = mp[p] + 1
        mp[p] = c

        res[l[2]] = (1000000000000L + p * 1000000L + c).toString().drop(1)
    }

    for (i in res.indices) {
        println(res[i])
    }
}


Measured memory_bytes: 129272
#include <bits/stdc++.h>
#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 FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

//階乗
ll f[2000200], finv[2000200];

//累乗
ll modpow(ll x, ll n) {
  ll ans = 1;
  while (n > 0) {
    if (n & 1) ans = ans * x % mod; 
    x = x * x % mod;
    n >>= 1;
  }
  return ans;
}

//逆数
ll modinv(ll x) {
  return modpow(x, mod - 2);
}

void init() {
  f[0] = finv[0] = 1;
  FOR(i, 1, 2000200) {
    f[i] = f[i - 1] * i % mod;
    finv[i] = modinv(f[i]);
  }
}

ll nCr(ll n, ll r) {
  if (r < 0 || r > n) return 0;
  return f[n] * finv[r] % mod * finv[n - r] % mod;
}

ll nHr(ll n, ll r) {
  return nCr(n + r - 1, r);
}

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

  ll n;
  cin >> n;

  cout << (modpow(10, n) - modpow(9, n) * 2 + modpow(8, n) + mod * 2) % mod << '\n';

  
  return 0;
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
#define endl "\n"
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();
// freopen("input.txt", "r", stdin);

int main() {
    ll x, k, d;
    cin >> x >> k >> d;
    x = llabs(x);
    ll step = (x - (x % d))/d;
    ll mn = x % d;
    if (step >= k) {
        cout << x - (k*d) << endl;
    } else {
        ll rem = (k - step) % 2;
        if (rem == 0) {
            cout << mn << endl;
        } else {
            cout << llabs(mn-d) << endl;
        }
    }
    return 0;
}


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

using namespace std;

int main(int argc,char* argv[]){
  int a=0,b=0,c=0,d=0,N;
  for(int i=0;i<4;i++){
    cin >> N;
    if(N==1) a++;
    else if(N==4) b++;
    else if(N==7) c++;
    else if(N==9) d++;
  }
  if(a==1&&b==1&&c==1&&d==1) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <string>
#include <set>
#define INF 100000000000
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define LOOP(i,N) for(int i=0;i<N;i++)
#define LOOP1(i,N) for(int i=1;i<=N;i++)
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;
#define int long long
/* define/include */

signed main(){
  int L[87]={};
  L[0]=2;
  L[1]=1;
  FOR(i,2,87){
    L[i]=L[i-1]+L[i-2];
  }
  int N;
  cin >> N;
  cout << L[N];
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>

using namespace std;

int main(){
    long n,a,b;
    cin >> n >> a >> b;
    long kumi;
    long amari;
    if (n%(a+b)==0){
        kumi = n / (a+b);
        amari = 0;
    }
    else{
        kumi = n / (a+b);
        amari = n - kumi * (a+b);
    }
    if (amari < a){
        amari = amari;
    }
    else{
        amari = a;
    }
    cout << kumi * a + amari << endl;
}

Measured memory_bytes: 256
x,y=map(int,input().split())
MOD=10**9+7
ans=0
if y>x:
    x,y=y,x
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod
mod = MOD #出力の制限
N = 10**6
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

for a in range(1,x//2+1):
    b=x-2*a
    if 2*b+a==y:
        tmp=cmb(b+a,a,mod)%MOD
        ans+=tmp
        ans%=MOD
print(ans)




Measured memory_bytes: 122064
import sys
from operator import itemgetter
input = sys.stdin.readline
n = int(input())
l = [list(map(int,input().split())) for _ in range(n)]
l.sort(key=itemgetter(1))
a = 0
flag = 0
for _ in range(n):
  a += l[_][0]
  if a > l[_][1]:
    print('No')
    flag = 1
    break
if flag == 0:
  print('Yes')

Measured memory_bytes: 53752
#include <bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define Mod 1000000007
#define ll long long
#define dd double
#define pb push_back
#define ff first
#define ss second
#define Mp make_pair
#define NN (ll)(1e17+5)
int mod(string s,int a) 
{ 
    int ans=0; 
    for (int i=0;i<s.length();i++) 
         ans=(ans*10+(int)s[i]-'0')%a; 
    return ans; 
}
ll min(ll x,ll y){if(x<y) return x;return y;}
ll max(ll x,ll y){if(x>y) return x;return y;}
ll power(ll x,unsigned ll y) 
{ 
    if (y==0) 
        return 1; 
    else if (y%2==0) 
        return power(x,y/2)*power(x,y/2); 
    else
        return x*power(x,y/2)*power(x,y/2); 
}
ll hcf(ll a,ll b) 
{ 
    if(b==0) 
        return a; 
    return hcf(b,a%b);  
}
ll N,W;
vector <pair<ll,ll>> v;
ll dp[100][1000005];
ll fn(ll ind,ll sum)
{
    if(dp[ind][sum]!=-1)
     return dp[ind][sum];
    if(ind==N-1)
    {
       if(v[ind].ff+sum<=W)
           return dp[ind][sum]=v[ind].ss;
        return dp[ind][sum]=0;
    }
   if(v[ind].ff+sum<=W)
         return dp[ind][sum]=max(v[ind].ss+fn(ind+1,sum+v[ind].ff),fn(ind+1,sum)); 
    return dp[ind][sum]=fn(ind+1,sum);
}
int main()
{
   fio;
   /*#ifndef ONLINE_JUDGE 
    	freopen("input.txt", "r", stdin); 
    	freopen("output.txt", "w", stdout); 
    	freopen("error.txt", "w", stderr); 
   #endif*/
   ll TT=1;
   memset(dp,-1,sizeof(dp));
   //cin>>TT;
   while(TT--)
   {   
       cin>>N>>W;
       ll i,x,y;
       for(i=0;i<N;i++)
       {
           cin>>x>>y;
           v.pb(Mp(x,y));
       }
       //for(i=0;i<N;i++)
        //cout<<dp[i][0]<<" "<<dp[i][1]<<"\n"; 
       ll ans=fn(0,0);
       cout<<ans<<"\n";
       //for(i=0;i<N;i++)
        //cout<<dp[i][0]<<" "<<dp[i][1]<<"\n";
   }
}

Measured memory_bytes: 781568
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;
#define REP(i,m,n) for(LL i=(m);i<(n);i++)

int main(){
  LL n,ans=0;
  cin >> n;
  VLL l(n),r(n);
  REP(i,0,n){
    cin >> l.at(i) >> r.at(i);
    ans += (r.at(i) - l.at(i)) + 1;
  }
  
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 3624
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

typedef long long int int64;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))

typedef struct listGraph{
  int v;
  int e;
  int *start;
  int *vertex;
  int *cost;
  int *next;
} graph;

graph* newGraph(const int v,const int e){
  graph *g=(graph *)malloc(sizeof(graph));
  g->v=v;
  g->e=0;
  g->start=(int *)malloc(sizeof(int)*v);
  int i;
  for(i=0;i<v;i++) g->start[i]=-1;
  g->vertex=(int *)malloc(sizeof(int)*e);
  g->cost=(int *)malloc(sizeof(int)*e);
  g->next=(int *)malloc(sizeof(int)*e);
  return g;
}

void freeGraph(graph *g){
  free(g->start);
  free(g->vertex);
  free(g->cost);
  free(g->next);
  free(g);
  return;
}

void addEdge(graph *g,int from,int to,int cost){
  int e=g->e;
  g->vertex[e]=to;
  g->cost[e]=cost;
  g->next[e]=g->start[from];
  g->start[from]=e;
  g->e++;
  return;
}

const int inf=1000*10000+1;

int bellmanFord(graph *g,int source,int *path){
  const int v=g->v;
  int i;
  for(i=0;i<v;i++) path[i]=inf;
  path[source]=0;
  for(i=0;i<v;i++){
    int j;
    for(j=0;j<v;j++){
      if(path[j]==inf) continue;
      int p;
      for(p=g->start[j];p!=-1;p=g->next[p]){
	int k=g->vertex[p];
	if(path[j]+g->cost[p]>=path[k]) continue;
	if(i==v-1) return 1;
	path[k]=path[j]+g->cost[p];
      }
    }
  }
  return 0;
}

void run(void){
  int v,e,r;
  scanf("%d%d%d",&v,&e,&r);
  graph *g=newGraph(v,e);
  int i;
  for(i=0;i<e;i++){
    int s,t,d;
    scanf("%d%d%d",&s,&t,&d);
    addEdge(g,s,t,d);
  }
  int *path=(int *)malloc(sizeof(int)*v);
  if(bellmanFord(g,r,path)){
    printf("NEGATIVE CYCLE\n");
  } else {
    for(i=0;i<v;i++){
      if(path[i]>=inf){
	printf("INF\n");
      } else {
	printf("%d\n",path[i]);
      }
    }
  }
  freeGraph(g);
  free(path);
  return;
}

int main(void){
  run();
  return 0;
}



Measured memory_bytes: 2108
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(void){
    char s[100];
    scanf("%s",s);
    int count,count2;
    for(count=0;s[count]!='\0';count++){
        for(count2=count+1;s[count2]!='\0';count2++){
            if(s[count2]==s[count]){printf("no\n");return 0;}
        }

    }
    printf("yes\n");
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <numeric>
#include <cstring>
#include <cmath>

using namespace std;

int main(int argc, char *argv[]) {
  int n;
  while (true) {
    cin >> n;
    if (n == 0)
      break;
    int time[10000], t = 0;
    for (int i = 0; i < n; i++)
      cin >> time[i];

    sort(time, time + n);
    for (int i = 0; i < n; i++) {
      int bef = time[i];
      time[i] = t;
      t += bef;
    }

    cout << accumulate(time, time + n, (long long)0) << endl;
  }
  return 0;
}

Measured memory_bytes: 1208
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) throws IOException {
		Main mainObj = new Main();
		mainObj.solve();
	}

	public void solve() throws IOException {
		FastScanner fs = new FastScanner();
		int n = fs.nextInt();
		int k = fs.nextInt();
		
		int num = 0;
		for(int i = 1; i <= n; i = i+2) {
			num++;
			if(num >= k) {
				System.out.println("YES");
				return;
			}
		}
		
		System.out.println("NO");
	}

	

	public class FastScanner {

		BufferedReader reader;
		private StringTokenizer st;

		public FastScanner() {
			st = null;
			reader = new BufferedReader(new InputStreamReader(System.in));
		}

		public String next() throws IOException {
			if (st == null || !st.hasMoreElements()) {
				st = new StringTokenizer(reader.readLine());
			}
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			st = null;
			String readLine = null;
			readLine = reader.readLine();
			return readLine;
		}

		public int nextInt() throws NumberFormatException, IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws NumberFormatException, IOException {
			return Long.parseLong(next());
		}

		public int[] nextIntArr(int n) throws NumberFormatException, IOException {
			int[] retArr = new int[n];
			for (int i = 0; i < n; i++) {
				retArr[i] = nextInt();
			}
			return retArr;
		}

		public long[] nextLongArr(int n) throws NumberFormatException, IOException {
			long[] retArr = new long[n];
			for (int i = 0; i < n; i++) {
				retArr[i] = nextLong();
			}
			return retArr;
		}

		public void close() throws IOException {
			reader.close();
		}
	}


}


Measured memory_bytes: 21332
#include<stdio.h>

int main(){
	while(1){
		int a,b[10];
		for(a=0;a<=9;a++){
			scanf("%d",&b[a]);
			if(b[0]==0)break;
		}
		if(b[0]==0)break;
		if(b[0]>0)printf("%d\n",b[0]-b[1]-b[2]-b[3]-b[4]-b[5]-b[6]-b[7]-b[8]-b[9]);
	}
	return 0;
}

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

int main() {
  string s;
  cin >> s;
  if (s[0] == s[s.size()-1])
    cout << (s.size() % 2 ? "Second" : "First");
  else
    cout << (s.size() % 2 ? "First" : "Second");
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
using namespace std;

int main() {
    int a,b,c,d;
    cin >> a >> b;
    c = max(a,b);
    d = min(a,b);
    for (int i = 1;i < 3;i++) {
        if(c-i > d){
            cout << c + (c-i) << endl;
            break;
        }else if(c-i <= d){
            cout << c + d << endl;
            break;
        }
    }

    
    
  return 0;
}


Measured memory_bytes: 256
a=[]
b=[]
for i in [0]*3:
	a_,b_ = map(int,input().split(' '))
	a.append(a_)
	b.append(b_)

f = True


for i in range(1,5):
	if not i in a and not i in b:
		f = False

for i in range(1,5):
	t = False
	for A,B in zip(a,b):
		if not(i == A or i == B):
			t = True 
	if not t:
		f = False

if f:
	print('YES')
else:
	print('NO')



Measured memory_bytes: 3064
use std::env;
use std::io::*;
use std::str::*;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let s = stdin.bytes().map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.parse::<T>().ok().unwrap()
}

fn main() {
    // main の引数
    /*
        引数なしのときargs.len() = 1;
    */
    let args: Vec<String> = env::args().collect();

    let x = read::<i32>();
    let a = read::<i32>();
    let b = read::<i32>();

    if (x-a).abs() < (x-b).abs() {
        println!("A");
    }else {
        println!("B");
    }
}


Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <map>
#include <numeric>
#include <random>
#include <queue>
#include <deque>
#include <tuple>
#include <iomanip>

using namespace std;
typedef long long ll;

const int INF = (1 << 30) - 1;
const ll INFLL= (1LL << 61) - 1;
const int MOD = 1000000007;

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N,K,pos;
  cin>>N>>K;
  vector<int>A(N);
  for(int i=0;i<N;i++){
    cin>>A[i];
  }
  cout<<(N-1+K-2)/(K-1)<<endl;
}


Measured memory_bytes: 640
/* 北さん参考 */
#include <bits/stdc++.h>
using namespace std;

#define REP(i, n) for (ll (i) = 0 ; (i) < (ll)(n) ; ++(i))
#define REPN(i, m, n) for (ll (i) = m ; (i) < (ll)(n) ; ++(i))
#define REP_REV(i, n) for (ll (i) = (ll)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (ll (i) = (ll)(n) - 1 ; (i) >= m ; --(i))

#define INF 2e9
#define INF_LL 1LL<<60
#define ll long long

typedef pair<ll, ll> P;

int main(){
    ll n, a, b;
    ll ans = 0;
    cin >> n >> a >> b;
    vector<int> x(n);
    REP(i, n) cin >> x[i];

    REPN(i, 1, n) {
        if((x[i] - x[i-1]) * a < b) {
            ans += (x[i] - x[i-1]) * a;
        } else {
            ans += b;
        }
    }

    cout << ans << endl;

    return 0;
}


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

using ll = long long;

template<typename T>
T gcd(T a, T b)
{
	if (a < b)	return gcd(b, a);
	T r;
	while ((r = a % b))
	{
		a = b;
		b = r;
	}
	return b;
}

template<typename T>
T lcm(T a, T b)
{
	return a * b / gcd(a, b);
}

template<typename T>
T ext_gcd(T a, T b, T& x, T& y)
{
	x = 1;
	y = 0;
	T x0 = 0, y0 = 1;
	while (b != 0)
	{
		T q = a / b;
		a -= q * b;
		swap(a, b);
		x -= q * x0;
		swap(x, x0);
		y -= q * y0;
		swap(y, y0);
	}
	return a;
}

template<typename T>
T inv_mod(T a, T mod)
{
	T t1, t2;
	ext_gcd(a, mod, t1, t2);
	t1 %= mod;
	if (t1 < 0)		t1 += mod;
	return t1;
}

template<typename T>
T combination_large(T n, T k, T mod)
{
	if (n < k || n < 0 || k < 0)	return 0;
	vector<T> inv(n + 1, 1), fact(n + 1, 1), fact_inv(n + 1, 1);
	for (T i = 2; i <= n; ++i)
	{
		inv[i] = mod - inv[mod % i] * (mod / i) % mod;
		fact[i] = (fact[i - 1] * i) % mod;
		fact_inv[i] = fact_inv[i - 1] * inv[i] % mod;
	}
	return fact[n] * (fact_inv[k] * fact_inv[n - k] % mod) % mod;
}

template<typename T>
T combination(T n, T k, T mod = 1)
{
	vector<vector<T>> table(n + 1, vector<T>(k + 1, 1));
	for (T i = 1; i <= n; ++i)
	{
		table[i][0] = 1;
		for (T j = 1; j <= n; ++j)
		{
			table[i][j] = (table[i - 1][j - 1] + table[i - 1][j]) % mod;
		}
	}
}

int main(int, char**)
{
	int K, S;
	cin >> K >> S;
	int count = 0;
	for (int x = 0; x <= K; ++x)
	{
		for (int y = 0; y <= K; ++y)
		{
			auto z = S - x - y;
			if (z >= 0 && z <= K)
			{
				++count;
			}
		}
	}
	cout << count << endl;
	return 0;
}


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

#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define each(it,v) for(auto &it : v)
#define all(v) (v).begin(),(v).end()
#define mod 1e9+7

using namespace std;
using vi = vector<int>;
using vl = vector<long>;
using P = pair<int,int>;

main()
{
        vi v(5);
        rep(i,5)cin>>v[i];
        int k; cin>>k;
        bool flag=true;
        rep(i,5)
        {
                rep(j,5)
                {
                        if(abs(v[i]-v[j])>k)flag=false;
                }
        }
        cout<<(flag?"Yay!":":(")<<endl;
}

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

#define rep(i,a,n)     for(int i=a;i<n;i++)
#define rep3(n)        for(int i=0;i<n;i++)
#define ll             long long
#define int            long long
#define pb             push_back
#define all(v)         v.begin(),v.end()
#define endl           "\n"
#define eb             emplace_back
#define x              first
#define y              second
#define gcd(a,b)       __gcd(a,b)
#define mem1(a)        memset(a,-1,sizeof(a))
#define mem0(a)        memset(a,0,sizeof(a))
#define pres(a,x)      a.find(x)!=a.end()
#define sz(a)          (int)a.size()
#define pii            pair<int,int>
#define hell           1000000007
#define elasped_time   1.0 * clock() / CLOCKS_PER_SEC
using namespace std;


template<typename T1,typename T2>istream& operator>>(istream& in,pair<T1,T2> &a){in>>a.x>>a.y;return in;}
template<typename T1,typename T2>ostream& operator<<(ostream& out,pair<T1,T2> a){out<<a.x<<" "<<a.y;return out;}
template<typename T,typename T1>T maxs(T &a,T1 b){if(b>a)a=b;return a;}
template<typename T,typename T1>T mins(T &a,T1 b){if(b<a)a=b;return a;}

const int N=5e5+10;

template<typename T>
struct Fenwick{
    vector<T> tree;
    Fenwick(int n){
        tree.resize(n);
    }

    T query(int i){
        int sum=0;
        while(i){
           sum+=tree[i];
           i-=i&(-i);
       }  
       return sum;
    }
    void update(int i,int n,T val){
       while(i<=n){
          tree[i]+=val;
          i+=i&(-i);
       }
    }
};

int dlog(int a,int b,int c,int x=-1){
    int n=(int)sqrt(c+.0)+1;
    unordered_map<int,int> mp;
    int an=1;
    for (int i = 0; i < n; ++i)an =(an * 1ll * a) % c;
    for (int i = 1, cur = an; i<= n; ++i){ 
        if(!mp[ cur ])mp[ cur ] = i; 
        cur = (cur * an) % c; 
    } 
    int mi=1e18;
    for (int i = 0,cur = b; i<= n; ++i){
        if (mp.count(cur)){ 
            int ans=mp[cur] * n - i; 
            if(ans!=0)mi=min(ans,mi);
        } 
        cur = (cur * a) % c; 
    } 
    return (mi==1e18)?-1:mi; 

}
ll xymodp(ll x,ll y,ll p){
    ll a=1;
    x%=p;
    while(y){
        if(y&1)a=(a*x)%p;
        x=(x*x)%p;
        y/=2;
    }
    return a;
}


int solve(){
 	int k;cin>>k;
 	if(k%7==0)k/=7;
 	if(k%5==0 || k%2==0){
 		cout<<-1<<endl;return 0;
 	}
 	if(k<10){
 		cout<<k<<endl;return 0;
 	}
 	int val=1;
 	for(int i=1;i<=k;i++){
 		if(val%k==0){
 			cout<<i<<endl;return 0;
 		}
 		val=val+xymodp(10,i,k);
 		val%=k;
 	}
 	cout<<-1<<endl;
 return 0;
}
signed main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    #ifdef SIEVE
    sieve();
    #endif
    #ifdef NCR
    init();
    #endif
    int t=1;//cin>>t;
    while(t--){
        solve();
    }
    return 0;
}
 

Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define mmax(a,b,c) max(a,max(b,c))
#define mmin(a,b,c) min(a,min(b,c))
#define M 1000000007
#define V vector
#define F(a,b,c) for (a=b;a<=c;++a)
#define I cin
#define O cout
#define pb push_back
#define all(x) x.begin(),x.end()
#define ff first
#define ss second

int main() {
    I.sync_with_stdio(false);
    I.tie(0);
    ll W,t,n,q,i,j;
    I>>n>>W;
    vector<ll>w(n),v(n);
    F(i,0,n-1)
        I>>w[i]>>v[i];
    vector<vector<ll>> dp(n+1,vector<ll>(W+1,0));
    for (i=1;i<=n;++i)
    {
        for (j=0;j<=W;++j)
        {
            if (j>=w[i-1])
            {
                dp[i][j]=max(v[i-1]+dp[i-1][j-w[i-1]],dp[i-1][j]);
            }
            else
            {
                dp[i][j]=dp[i-1][j];
            }
        }
    }
    cout<<dp[n][W]<<'\n';
    return 0;
}

Measured memory_bytes: 80256
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <algorithm>
using namespace std;

#ifdef INPUT
#include <sstream>
stringstream input(R"(
8
P Y W G Y W Y Y
)");
#define cin input
#endif

int main()
{
	int n;
	cin >> n;

	int p, w, g, y;
	p=w=g=y=0;

	for (int i=0; i<n; i++)
	{
		char kyu;
		cin >> kyu; 
		if (kyu=='P')
			p++;
		if (kyu=='W')
			w++;
		if (kyu=='G')
			g++;
		if (kyu=='Y')
			y++;
	}

	if (p==0 || w==0 || g==0 || y==0)
		cout << "Three" << endl;
	else
		cout << "Four" << endl;
	return 0;
}

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

int main() {
  vector<int> PQR(3);
  for(int i = 0; i < 3; i++) cin >> PQR[i];
  sort(PQR.begin(), PQR.end());
  cout << PQR[0] + PQR[1] << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int a[5],k;
	cin>>a[0]>>a[1]>>a[2]>>k;
	sort(a,a+3);
	for(int i=0;i<k;i++){
		a[2]*=2;
	}
	cout<<a[0]+a[1]+a[2]<<endl;
}

Measured memory_bytes: 256
import java.util.*;
import java.util.stream.Collectors;
import java.io.*;
import java.math.BigDecimal;
import java.nio.charset.StandardCharsets;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		Main ins = new Main(in);
		ins.calc();
		ins.showResult();
	}

	int N, K;
	long count = 0;

	Main(BufferedReader in) throws IOException {
		String[] tokens = in.readLine().split(" ");
		N = Integer.parseInt(tokens[0]);
		K = Integer.parseInt(tokens[1]);
	}

	void calc() {
		for (int b = K + 1; b <= N; ++b) {
			int div = N / b;
			count += (long) (div * (b - K));
			// System.out.println(b + " " + ((long) (div * (b - K))));
			if (N % b != 0) {
				int mod = N % b;
				count += Math.max(0, mod - Math.max(0, (K - 1)));
			}
		}
		System.out.println(count);
	}

	void showResult() {
	}
}

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

#define CEIL(a,b) ((a) / (b) + ((a) % (b) == 0 ? 0 : 1))
#define X first
#define Y second

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vl = vector<ll>;
using vs = vector<string>;

constexpr int MOD = int(1e9 + 7);
constexpr int INF = int(1e9 + 1);
constexpr ll LLINF = ll(4 * 1e18 + 1);
// constexpr int INF = 2147483647; // 2 * 1e9
// constexpr ll LLINF = 9223372036854775807; // 9 * 1e18

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

int gcd(int n, int m){
	if(m == 0) return n;
	if(m > n) swap(n, m);
	return gcd(m, n % m);
}

ll lcm(int n, int m){
	return (ll)n * m / gcd(n, m);
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout << fixed << setprecision(10);
	int n, m;
	cin >> n >> m;
	string s, t;
	cin >> s >> t;
	ll l = lcm(n, m);
	map<ll, char> st;
	for(int i = 0; i < n; ++i){
		st[i * l / n] = s[i];
	}
	for(int i = 0; i < m; ++i){
		if(st.find(i * l / m) != st.end() && st[i * l / m] != t[i]){
			cout << "-1\n";
			return 0;
		}
	}
	
	cout << l << "\n";
	
	return 0;
}


Measured memory_bytes: 6144