akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

typedef long long int ll;

ll gcd(ll m,ll n){
	if(m < n){
		ll temp = m;
		m = n;
		n = temp;
	}
	
	ll r = m % n;
	
	while(r != 0){
		m  = n;
		n = r;
		r = m % n;
		
	}
	
	return n;
}

ll function(ll a,ll c,ll d){
	ll count = 0; //a以下の自然数でcとdで割り切れない
	
	ll lcm = (c * d)/gcd(c,d);
	
	count = (a/c)+(a/d)-(a/lcm);
	
	
	
	return a - count;
	
	
}


		
	

int main(void)
{
	ll a,b,c,d;
	
	scanf("%lld %lld %lld %lld",&a,&b,&c,&d);
	
	
	printf("%lld\n",function(b,c,d)-function(a - 1,c,d));
	
	return 0;
	
}

Measured memory_bytes: 128
#include <cstdio>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <iterator>
#define loop(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define debug(x)  cout << #x << " = " << (x) << endl;

using namespace std;
using LL = long long;
using ULL = unsigned long long;

int main() {
    string s; cin >> s;
    int n = s.size();
    const int INF = 1e9;
    int ans = INF;
    rep(i, n - 1) {
        if (s[i] != s[i + 1]) ans = min(ans, max(i + 1, n - i - 1));
    }
    if (ans == INF) ans = n;
    cout << ans << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<long long> A(N);
  for (int i = 0; i < N; i++){
    cin >> A[i];
  }
  long long a = A[0];
  long long b = A[1];
  long long c = 0;
  for (int i = 2; i < N; i++){
    c ^= A[i];
  }
  if ((a + b) % 2 != c % 2){
    cout << -1 << endl;
  } else if (a + b < c){
    cout << -1 << endl;
  } else {
    //cout << "a = " << a << ", b = " << b << ", c = " << c << endl;
    long long carry = (a + b - c) / 2;
    vector<int> cnt(50, 0);
    for (int i = 0; i < 50; i++){
      if (c >> i & 1){
        cnt[i]++;
      }
      if (carry >> i & 1){
        cnt[i] += 2;
      }
    }
    bool ok = true;
    for (int i = 0; i < 50; i++){
      if (cnt[i] == 3){
        ok = false;
      }
    }
    if (!ok){
      cout << -1 << endl;
    } else {
      string s = "";
      for (int i = 0; i < 50; i++){
        if (cnt[i] == 0){
          s += '0';
        }
        if (cnt[i] == 1){
          s += '?';
        }
        if (cnt[i] == 2){
          s += '1';
        }
      }
      //cout << s << endl;
      long long a2 = 0;
      bool res_a = false;
      bool res_b = false;
      bool res_c = false;
      int pos = 0;
      for (int i = 49; i >= 0; i--){
        a2 *= 2;
        if (s[i] == '0'){
          if (a >> i & 1){
            res_a = true;
          }
        }
        if (s[i] == '1'){
          if (!(a >> i & 1) && !res_a){
            res_b = true;
            pos = i;
            break;
          }
          a2++;
        }
        if (s[i] == '?'){
          if ((a >> i & 1) || res_a){
            a2++;
            res_c = true;
          }
        }
      }
      /*
      cout << res_a << endl;
      cout << res_b << endl;
      cout << res_c << endl;
      cout << a2 << endl;
      */
      if (res_b && !res_c){
        cout << -1 << endl;
      } else if (!res_b){
        if (a2 == 0){
          cout << -1 << endl;
        } else {
          cout << a - a2 << endl;
        }
      } else {
        //cout << "pos = " << pos << endl;
        int last = pos;
        while (1){
          if (s[last] == '?' && (a >> last & 1)){
            break;
          }
          last++;
        }
        //cout << last << endl;
        long long a3 = 0;
        for (int i = 49; i >= 0; i--){
          a3 *= 2;
          if (s[i] == '1'){
            a3++;
          }
          if (s[i] == '?'){
            if ((i > last && (a >> i & 1)) || (i < last)){
              a3++;
            }
          }
        }
        //cout << a3 << endl;
        if (a3 == 0){
          cout << -1 << endl;
        } else {
          cout << a - a3 << endl;
        }
      }
    }
  }
}

Measured memory_bytes: 3628
import scala.io.StdIn

/**
  * AOJ
  */
object Main {

  def main(args: Array[String]): Unit = {

    val in = StdIn.readLine().split(" ").map(s => s.toInt)
    val op = if(in(0) < in(1)){"<"} else if(in(0) > in(1)){">"}else{"=="}
    println("a " + op + " b")
  }
}

Measured memory_bytes: 43456
#include <iostream>

using namespace std;

int main(void){

  int w;
  while( cin >> w , 0 <= w ){

    int p = 1150;
    if( 0 <= w && w < 10 ){
      cout << 4280 - p << endl;
    }
    else{
      p = 1150;
      if( 10 <= w ){
	for( int i = 10 ; ( i < w && i < 20 ) ; i++ ){
	  p += 125;
	  //cout << "125" << endl;
	}
	if( 20 <= w ){
	  for( int i = 20 ; ( i < w && i < 30 ) ; i++ ){
	    p += 140;
	    //cout << "140" << endl;
	  }
	}
	if( 30 <= w ){
	  for( int i = 30 ; i < w ; i++ ){
	    p += 160;
	    //cout << "160" << endl;
	  }
	}
      }
      //cout << p << endl;
      cout << 4280 - p << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
int main(){
 int X;
 cin >> X;
  
 int A = X % 10;
 int B = (X % 100)/10;
 int C = X / 100;   
 
 if (A==7 || B==7 || C==7)
   cout <<"Yes"<<endl;
 else 
   cout << "No" << endl;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
#define INF 100000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

int main()
{
  ll N;
  cin >> N;
  vector<ll> p(N);
  for (ll i = 0; i < N; ++i) {
    cin >> p.at(i);
  }
  vector<ll> order(N);
  for (ll i = 0; i < N; ++i) {
    order.at(p.at(i) - 1) = i + 1;
  }
  vector<ll> a = order;
  vector<ll> b = order;
  for (ll i = 0; i < N - 1; ++i) {
    a.at(i + 1) += a.at(i);
  }
  for (ll i = N - 1; i >= 1; --i) {
    b.at(i - 1) += b.at(i);
  }
  for (ll i = 0; i < N; ++i) {
    cout << a.at(i) << ' ';
  }
  cout << endl;
  for (ll i = 0; i < N; ++i) {
    cout << b.at(i) << ' ';
  }
  cout << endl;
}


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

//.define
// #define FILE_IN_OUT
#define RET(_x)    return cout << (_x) << '\n', 0;
#define all(_obj)  (_obj).begin(), (_obj).end()
#define loop(_n)   for (int i = 0; i < (_n); ++i)
#define sz(_obj)   static_cast<int>((_obj).size())
#ifdef SHJ_LOCAL
#define debug(_x)  std::cerr << (#_x) << " = " << (_x) << '\n' << std::flush;
#else
#define debug(_x)  {}
#endif
#define endl "\n"
template<typename P, typename Q>
P CeilDiv(P _dividend, Q _divider) {
    return static_cast<P>((_dividend - 1LL + _divider) / _divider);
}
template<typename Tp>
inline void outarr(Tp _begin, Tp _end, const char* _delim = " ") {
    for (Tp current = _begin; current != _end; ++current) {
        std::cout << *current << _delim;
    }
    std::cout << '\n';
}

//.constant
using ll  = long long;
using pii = std::pair<int, int>;
constexpr int INF = 0x3f3f3f3f;
constexpr int MOD = static_cast<const int>(1e9 + 7);

//.data
class SegmentTree {
public:
    explicit SegmentTree(int n) : tree(n << 2, 0), size(n) {
    }

    void Update(int i, int x) {
        UpdateSingleImpl(0, 0, size - 1, i, x);
    }

    int Max(int l, int r) {
        return QueryRangeImpl(0, 0, size - 1, l, r);
    }

    int Max() const {
        return tree[0];
    }

private:
    int Left(int v) const {
        return (v << 1) + 1;
    }

    int Right(int v) const {
        return (v << 1) + 2;
    }

    void UpdateVertex(int v) {
        tree[v] = max(tree[Left(v)], tree[Right(v)]);
    }

    void UpdateSingleImpl(int v, int tl, int tr, int i, int x) {
        if (tl == tr) {
            tree[v] = x;
            return;
        }
        const int mid = (tl + tr) >> 1;
        if (i <= mid) {
            UpdateSingleImpl(Left(v), tl, mid, i, x);
        } else {
            UpdateSingleImpl(Right(v), mid + 1, tr, i, x);
        }
        UpdateVertex(v);
    }

    int QueryRangeImpl(int v, int tl, int tr, int l, int r) {
        if (l > r) {
            return 0;
        }
        if (tl == l && r == tr) {
            return tree[v];
        }
        const int mid = (tl + tr) >> 1;
        return max(QueryRangeImpl(Left(v), tl, mid, l, min(mid, r)),
                   QueryRangeImpl(Right(v), mid + 1, tr, max(l, mid + 1), r));
    }

    vector<int> tree;
    const int size;
};

//.code
int main() {
#ifdef FILE_IN_OUT
    std::ifstream cin ("input.txt",  std::ios::in);
    std::ofstream cout("output.txt", std::ios::out);
#else
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
#endif

    int n, k;
    cin >> n >> k;
    vector<int> arr(n);
    loop(n) {
        cin >> arr[i];
    }
    SegmentTree st(1000000);
    loop(n) {
        st.Update(arr[i] + k, st.Max(arr[i], arr[i] + k + k) + 1);
    }
    cout << st.Max() << endl;

#ifdef FILE_IN_OUT
    cin.close();
    cout.close();
#endif
    return 0;
}

Measured memory_bytes: 20104
import java.util.*;
//http://kazune-lab.net/contest/2019/07/14/agc035/
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    Set<Integer> hashset = new HashSet<Integer>();
    int N = sc.nextInt();
    int array[] = new int[N];
    for (int i=0;i<N;i++){
      int a = sc.nextInt();
      hashset.add(a);
      array[i] = a;
    }
    List<Integer> list = new ArrayList<Integer>(hashset);
    String ans = "No";
    if(N%3 != 0){
      if (list.size() == 1 && list.get(0) == 0){
          ans ="Yes";
      }
    }else{
      if (list.size() == 1){
        if (list.get(0) == 0){
          ans ="Yes";
        }
      }else if(list.size() == 2){
        int a = 0;
        int b = 0;
        for (int i=0;i<N;i++){
         if (array[i] == list.get(0)){
           a++;
         }else{
           b++;
         }
        }
        if (a == N/3){
          ans = "Yes";
        }
      }else if(list.size() == 3){
        int a = 0;
        int b = 0;
        int c = 0;
        for (int i=0;i<N;i++){
         if (array[i] == list.get(0)){
           a++;
         }else if(array[i] == list.get(1)){
           b++;
         }else{
           c++;
         }
         }
       if((a==b)&&(b==c)){
         if ((list.get(0)^list.get(1)^list.get(2)) == 0){
           ans = "Yes";
         }
       }
      }
    }
    
    System.out.println(ans);
  }
}

Measured memory_bytes: 61776
n = int(input())

a = [input() for i in range(n)]

for i in range(n):
    a[i] = ''.join(sorted(a[i]))

a = sorted(a)

ans = 0
sum = 1
for i in range(n-1):
    if a[i] == a[i+1]:
        sum += 1
    else :
        ans += (sum*(sum-1))/2
        sum = 1

ans += (sum*(sum-1))/2
print(int(ans))

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

using namespace std;

int main(){
    long N;
    cin>>N;
    vector<long> v(N);
    double max = 0;
    for(int i=0; i<N; ++i){
        cin>>v[i];
    }

    sort(v.begin(), v.end());
    max = (v[0]+v[1])/2.0;
    for(int i=2; i<N; ++i){
        max = (max+v[i])/2.0;
    }

    cout<<max<<endl;
    return 0;
}

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

int main() {
  int n, r;
  cin >> n >> r;
  int ans = r + 100*max(0,10-n);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string>
#include<iostream>
#include<cctype>
#include<cstdio>
#include<vector>
#include<stack>
#include<queue>
#include <algorithm>
#include<math.h>
#include<set>
#include<map>
#include <sstream>
#include<iomanip>
#include <ctype.h>

//#include<bits/stdc++.h>


using namespace std;



int main() {

	int a, b, c, d;
	cin >> a >> b >> c >> d;
	if (a > d || c > b)cout << 0 << endl;
	else {
		a = max(a, c);
		b = min(b, d);
		cout << b - a << endl;
	}
		return 0;

}




Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    for(;;){
        int n;
        cin >> n;
        if(n == 0)
            return 0;

        vector<vector<double> > p(n+1, vector<double>(n+2, 0.0));
        p[n][0] = 1.0;
        double ret = 0.0;

        for(int a=n; a>0; a-=2){       // 残りのカード枚数
            for(int b=0; b<=a/2; ++b){ // 位置が分かっているカードの枚数
                // 位置が分かっているカードのもう一方のカードを1枚目で引く
                double p1 = 0.0;
                if(b > 0){
                    p1 = (double)b / (a - b);
                    p[a-2][b-1] += p[a][b] * p1;
                }
                
                // 位置が分かっているカードのもう一方のカードを2枚目で引く
                double p2 = 0.0;
                if(a - b - 1 > 0){
                    p2 = (1.0 - p1) * b / (a - b - 1);
                    p[a-2][b] += p[a][b] * p2;
                    ret += p[a][b] * p2;
                }

                // 1枚目と2枚目が同じ
                double p3 = 0.0;
                if(a - b - 1 > 0){
                    p3 = (1.0 - p1) / (a - b - 1);
                    p[a-2][b] += p[a][b] * p3;
                }

                // ミス
                double p4 = 1.0 - p1 - p2 - p3;
                p[a][b+2] += p[a][b] * p4;
                ret += p[a][b] * p4;
            }
        }

        printf("%.10f\n", ret);
    }
}

Measured memory_bytes: 9012
// 全探索したい 
// A,B が取りうる上限を見つける

for i in (1...1000) {
    let a = i
    let b = i-1
    if a^^5 - b^^5 > 10^^9 {
        break
    }
}

// 120までA，Bを全探索すれば良さそうということがわかった。

// 本題

let x = cin.int
Array(-120...120).forEach { a in 
    Array(-120...120).forEach { b in
        if a^^5 - b^^5 == x {
            print("\(a) \(b)")
            exit(0)
        }
    }
}

import Foundation
#if os(Linux)
    import Glibc
#else
    import Darwin.C
#endif

enum cin {
    // 123
    static var int: Int { Int(readLine()!)! }
    // 12 23
    static var pair: (Int, Int) { let line = readLine()!.components(separatedBy: " "); return (Int(line[0])!, Int(line[1])!) }
    // 12 23 34
    static var triple: (Int, Int, Int) { let line = readLine()!.components(separatedBy: " "); return (Int(line[0])!, Int(line[1])!, Int(line[2])!) }
    // AtCoder
    static var str: String { readLine()! }
    // At Coder
    static var arrayStr: [String] { str.components(separatedBy: " ") }
    // 1 2 3 4
    static var array: [Int] { str.components(separatedBy: " ").map { Int($0)! } }
    // 1
    // 2
    // 3
    static func v_array(count: Int) -> [Int] { (0..<count).map { _ in int } }
}

extension Int {
    // 123 -> [1, 2, 3]
    var digits: [Int] { Array(String(self)).map { Int(String($0))! } }
}

extension Array where Element == Int {
    // [2, 1, 3, 2] -> 8
    var sum: Int { self.reduce(0, +) }
    // [2, 1, 3, 2] -> [1, 2, 2, 3]
    var orderBy: [Int] { sorted() }
    // [2, 1, 3, 2] -> [3, 2, 2, 1]
    var orderByDesc: [Int] { sorted(by: { $0 > $1 }) }
    // [2, 1, 3, 2] -> [2, 1, 3]
    var distinct: [Int] { Array(Set(self)) }
}

precedencegroup PowerPrecedence { higherThan: MultiplicationPrecedence }
infix operator ^^ : PowerPrecedence
func ^^ (radix: Int, power: Int) -> Int {
    return Int(pow(Double(radix), Double(power)))
}

extension String {
    // e.g. cin.line.regex(match: "^(dream|dreamer|erase|eraser)*$")
    func regex(match pattern: String) -> Bool {
        let regex = try! NSRegularExpression(pattern: pattern)
        return regex.firstMatch(in: self, range: NSRange(location: 0, length: self.count)) != nil
    }
    // "ABC"[1] -> "B"
    subscript(i: Int) -> Character {
        get {
            self[index(at: i)]
        }
        set(char) {
            var characters = Array(self)
            characters[i] = char
            self = String(characters)
        }
    }
    func index(at offset: Int) -> String.Index { index(startIndex, offsetBy: offset) }
    // "ABC".swapAt(0, 1) -> "BAC"
    mutating func swapAt(_ index1: Int, _ index2: Int) {
        var characters = Array(self)
        characters.swapAt(index1, index2)
        self = String(characters)
    }
}


Measured memory_bytes: 13496
# input
N, W = map(int, input().split())
w = [0] * N
v = [0] * N
for i in range(N):
  w[i], v[i] = map(int, input().split())

# DP
dp = [[0] * (W + 1) for i in range(N + 1)]

for i in range(N):
  for j in range(W + 1):
    if j - w[i] >= 0:
      dp[i + 1][j] = max(dp[i][j], dp[i][j - w[i]] + v[i])
    else:
      dp[i + 1][j] = dp[i][j]

print(dp[N][W])

Measured memory_bytes: 120300
use std::io;
use std::str::FromStr;

fn main() {
    let (n, m) = {
        let mut buf = String::new();
        io::stdin().read_line(&mut buf).unwrap();
        let mut it = buf.split_whitespace();
        (usize::from_str(it.next().unwrap()).unwrap(),
        usize::from_str(it.next().unwrap()).unwrap())
    };
    let mut av: Vec<bool> = vec![true; n + 1];
    for _ in 0..m {
        let mut a = String::new();
        io::stdin().read_line(&mut a).unwrap();
        let an: usize = a.trim_right().parse().unwrap();
        av[an] = false;
    }
    let mut dp: Vec<u64> = vec![0; n + 1];
    dp[0] = 1;
    for now in 0..n {
        let st = now + 1;
        let ed = std::cmp::min(n, now + 2) + 1;
        for next in st..ed {
            if av[next] {
                dp[next] += dp[now];
                dp[next] %= 1000000007;
            }
        }
    }
    println!("{}", dp[n]);
}

Measured memory_bytes: 4352
#include<iostream>

#include <vector>
#include <list>
#include<stack>
#include<queue>
#include<array>

#include <set>
#include<map>

#include<string>
#include<stdlib.h>
#include<memory>

#include<algorithm>
#include <functional>
#include<math.h>

#include<fstream>
#include<iomanip>

using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define FOR(k,m,n) for(ll (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define WAITING(str) int str;std::cin>>str;
#define DEBUGING(str) cout<<str<<endl

constexpr int INF = (1 << 30);
constexpr ll INFL = (1ll << 60);
constexpr ll MOD = 1000000007;// 10^9+7





map<ll, ll> prime_factorization(ll n)
{
	map<ll, ll> res;
	ll check = 2;

	while(check*check <= n) {
		if(n%check == 0) {
			n /= check;
			res[check]++;
		}
		else {
			check++;
		}
	}
	if(n!=1)res[n]++;
	return res;
}

using T = ll;
struct COMB{
	static constexpr ll LIM = 200'000;

	//繰り返し累乗法
	//in:  x,n,mod
	//out: x^n(Mod mod)
	T mod_pow(T x, T n, T mod) {
		T res = 1;
		while(n > 0) {
			if(n & 1)res = (res * x) % mod;
			x = (x * x) % mod;
			n >>= 1;
		}
		return res;
	}

	void make_contents()
	{
		ll tmp = 1;
		fact.push_back(0);
		FOR(i, 1, LIM) {
			tmp *= i;
			tmp %= MOD;
			fact.push_back(tmp);
		}

		tmp = mod_pow(tmp, MOD - 2, MOD);
		//inv.push_back(tmp);
		for(ll i = LIM - 1; i > 0; i--) {
			tmp *= i;
			tmp %= MOD;
			inv.push_back(tmp);
		}
		reverse(inv.begin(), inv.end());
		fact[0] = inv[0] = 1;
		/*正当性確認
		REP(i, LIM) {
		cerr << (fact[i] * inv[i]) % MOD << endl;
		}
		*/
	}

	ll comb(ll n, ll k) {
		ll res = fact[n];
		res *= inv[k]; res %= MOD;
		res *= inv[n - k]; res %= MOD;
		return res;
	}

private:
	vector<ll> fact, inv;
};







//メイン関数
int main()
{
	COMB comb;
	comb.make_contents();

	ll N, M, res = 1;
	cin >> N >> M;
	auto primes = prime_factorization(M);
	for(auto itr = primes.begin(); itr != primes.end(); ++itr)
	{
		res = (res * comb.comb(N - 1 + itr->second, itr->second)) % MOD;
	}
	cout << res<<endl;
	cin>>N;
	return 0;
}


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

int main(){
  int n,f,t,m,num;
  int line[] = {0,1,2,3,4,5,6,7,8,9,5,4,3,2,1,0,1,2,3,4,5,6,7,8,9,5,4,3,2,1,0};

  cin >> n;
  while(n--){
    cin >> f >> t;

    m = 30;
    num = -1;
    for(int i=0;i<=30;i++){
      if(line[i] == f){
	for(int j=i+1;j<=30;j++){
	  if(line[j] == t){
	    if(m>j-i){
	      m = j-i;
	      num = i;
	    }
	  }
	}
      }
    }

    for(int i=num;i<num+m;i++)cout << line[i] << " ";
    cout << line[num+m] << endl;
  }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#include <fstream>
using namespace std;
typedef long long lint;
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(lint (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define INF (1ll<<60)
#define all(x) (x).begin(),(x).end()
const lint MOD =1000000007;
const lint MAX = 1000000;
using Graph =vector<vector<lint>>;
typedef pair<lint,lint> P;
typedef map<lint,lint> M;
 
lint fac[MAX], finv[MAX], inv[MAX];
 
void COMinit() 
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (lint i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
long long COM(lint n, lint k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
lint primary(lint num)
{
    if (num < 2) return 0;
    else if (num == 2) return 1;
    else if (num % 2 == 0) return 0;
 
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return 0;
        }
    }
 
    return 1;
}
   long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
    lint lcm(lint a,lint b){
        return a/__gcd(a,b)*b;
    }
     lint gcd(lint a,lint b){
        return __gcd(a,b);
    } 
    
 
    
  int main(){
     lint n,a,b;
     cin>>n>>a>>b;
     if(b<a){
         cout<<0<<endl;
         return 0;
     }
     if(n==1){
         if(a==b)cout<<1<<endl;
         else cout<<0<<endl;
         return 0;
     }
     if(n==2){
         cout<<1<<endl;
         return 0;
     }
     else {
         lint ans=0;
         lint x=(n-2)*a;
         lint y=(n-2)*b;
         cout<<y-x+1<<endl;
     }
     }
  
      
      
    

  
          
  

Measured memory_bytes: 256
/*
	Name: We Love ABC
	Author: Jerryjiang090210
	Date: 29/06/19 16:40
	Description: Standard code 1
*/

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=(1e5+10),MOD=(1e9+7);
string s;
ll dp[maxn][4]={};
int main()
{
	cin>>s;
	int n=s.size();
	for(int i=n;i>=0;i--)
	{
		for(int j=3;j>=0;j--)
		{
			if(i==n)
			{
				dp[i][j]=j==3?1:0;
			}
			else
			{
				dp[i][j]=dp[i+1][j]*(s[i]=='?'?3LL:1LL);
				if(j<3&&(s[i]=='?'||s[i]=="ABC"[j]))
					dp[i][j]+=dp[i+1][j+1];
			}
			dp[i][j]%=MOD;
		}
	}
	cout<<dp[0][0]<<endl;
	return 0;
}

Measured memory_bytes: 3584
#include<stdio.h>
int A[12];
int main()
{
int i,a,b,c=0,d=0,n,e=0,f=0,l=-1,j;
char S[102];
	scanf("%d",&d);
	for(i=0;i<d;i++){
	scanf("%d %d %d",&c,&a,&n);
	while(1){
	if(c>0&&a>0&&n>0) {
	e++;
	c--;
	a--;
	n--;
	}
	else if(c>1&&a>0){
	c=c-2;
	a--;
	e++;
	}
	else if(c>2){
	c=c-3;
	e++;	
	}
	else break;
	}
	printf("%d\n",e);
	e=0;
	}
	return 0;
	
}

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

using namespace std;

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

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

#define DEBUG(x) cout<<#x<<": "<<(x)<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

template<typename T> inline void CHMAX(T& a, const T b) {if(a<b) a=b;}
template<typename T> inline void CHMIN(T& a, const T b) {if(a>b) a=b;}

constexpr ll MOD=1000000007ll;
// constexpr ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-9;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

ll mp[3252][3252];
ll dp[3252][3252][4];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  // cout<<setprecision(10)<<fixed;
  int R, C, K;
  cin>>R>>C>>K;
  --R;--C;
  REP(i, K){
    int r, c, v;
    cin>>r>>c>>v;
    --r;--c;
    mp[r][c]=v;
  }
  REP(i, R+1){
    REP(j, C+1){
      REP(k, 4){
        CHMAX(dp[i+1][j+1][k], dp[i+1][j][k]);
        if(k<3){
          CHMAX(dp[i+1][j+1][k+1], dp[i+1][j][k]+mp[i][j]);
        }
        CHMAX(dp[i+1][j+1][0], dp[i][j+1][k]);
        CHMAX(dp[i+1][j+1][1], dp[i][j+1][k]+mp[i][j]);
      }
    }
  }
  ll ans=0;
  REP(i, 4){
    CHMAX(ans, dp[R+1][C+1][i]);
  }
  cout<<ans<<'\n';
  return 0;
}


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

int main(){
    string s,t;
    cin>>s>>t;
    sort(s.begin(),s.end());
    sort(t.begin(),t.end());
    reverse(t.begin(),t.end());
    if(t>s){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define f first
#define s second
#define rep(i, l, r) for (long long i = (l); i < (r); i++)
#define repb(i, r, l) for (long long i = (r); i > (l); i--)
#define pb push_back
 
using namespace std;
typedef vector<long long> vl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector< pair<long long, long long> > vp;
typedef deque <long long> dq;
typedef long long int lli;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull; 
const int MAX_CHAR=256;
 
 
ll gcd(ll x, ll y) {
    if (x < y) return gcd(y, x);
    if (y == 0) return x;
    return gcd(y, x % y);
} 
 
const ll mod = 1e9 + 7;
 
ll modexp(ll x, ll ex) {
    ll ans = 1ll;
    while (ex > 0) {
        if (ex & 1ll) ans = (ans * x) % mod;
        ex >>= 1ll;
        x = (x * x) % mod;
    }
    return ans;
} 
 
ll nCrModp(ll n, ll r, ll p) 
{ 
    ll C[r+1]; 
    memset(C, 0, sizeof(C)); 
  
    C[0] = 1; 
    for (ll i = 1; i <= n; i++) 
    { 
        for (ll j = min(i, r); j > 0; j--) 
            C[j] = (C[j] + C[j-1])%p; 
    } 
    return C[r]; 
}
 
bool isPrime(ll n) 
{ 
    if (n <= 1)  return false; 
    if (n <= 3)  return true;  
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (ll i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
  
    return true; 
} 

bool sortinrev(const pair<ll,string> &a,  
               const pair<ll,string> &b) 
{ 
       return (a.first > b.first); 
}
 
vl countFreq(ll arr[], ll n) 
{ 
    unordered_map<ll, ll> mp; 
    vector <ll> v;
    
    for (ll i = 0; i < n; i++) 
        mp[arr[i]]++; 
   
    for (auto x : mp) 
        v.pb(x.second);
    
    return v;
}
 
bool sortbysec(const pair<ll, ll>& a, 
               const pair<ll, ll>& b) 
{ 
    return (a.second < b.second); 
} 

ll binarySearch(ll arr[], ll l, ll r, ll x) 
{ 
    while (l <= r) 
    { 
        ll m = l + (r - l) / 2; 
        if (arr[m] == x) 
            return m; 
        if (arr[m] < x) 
            l = m + 1; 
        else
            r = m - 1; 
    }
    return -1; 
}

ll smallestDivisor(ll n) 
{ 
    if (n % 2 == 0) 
        return 2; 
  
    for (ll i = 3; i * i <= n; i += 2) { 
        if (n % i == 0) 
            return i; 
    } 
  
    return n; 
} 

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll t=1;
    // cin >> t;
    
    while(t--)
    {
        ll x,y,z;
        cin >>x >>y >>z;
        
        cout << z << " " <<x << " " <<y << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
  #define int long long int
  #define vi vector<int>
  #define pii pair<long long ,long long>
  #define pll pair<int,int>
  #define mod 1000000007
  #define all(x) x.begin(),x.end()
  #define mp(x,y) make_pair(x,y)
  #define mem(a,val) memset(a,val,sizeof(a))
  #define eb push_back
  #define ff first
  #define ss second
  #define rep(n) for(int i=0;i<n;i++)
  #define lb lower_bound
  #define up upper_bound
   
  
  using namespace std;
  int dp[100005][105];
  int v[100005];
  int a[100005];
  void solve()
  { 

      int n,w;
      cin>>n>>w;
      for(int i=1;i<=n;i++)
         cin>>a[i]>>v[i];


      for(int i=1;i<=w;i++)
      {
         for(int j=1;j<=n;j++)
           {
              if(i-a[j]>=0)
              dp[i][j]=max(dp[i][j-1],dp[i-a[j]][j-1]+v[j]);
            else
               dp[i][j]=dp[i][j-1];
           }
      }
      
      cout<<dp[w][n];

    
    


   
   }

  signed main()
  {
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif*/
    
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int T;
    T=1;
    
    while(T--)
    {
      solve();
    }
    return 0;
  }


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

int main()
{
  int N;
  cin >> N;
  vector<int> A(N-1);
  rep(i, N-1) {
    cin >> A.at(i);
  }
  vector<int> ans(N, 0);
  rep(i, N-1) {
    int num = A.at(i);
    ans.at(num-1) += 1;
  }
  rep(i, N) {
    cout << ans.at(i) << endl;
  }
}

Measured memory_bytes: 4768
#include<cstdio>
#include<cmath>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
long long int fie[110][11][1100];
int main(){
    while(1){
        memset(fie,0,sizeof(fie));
        int N,S;
        cin>>N>>S;
        if(N==0&&S==0)break;
        fie[1][0][0]=1;fie[1][1][1]=1;
        for(int i=1;i<100;i++){
            for(int j=0;j<10;j++){
                for(int k=0;k<=1000;k++){
                    fie[i+1][j][k]+=fie[i][j][k];
                    fie[i+1][j+1][k+i+1]+=fie[i][j][k];
                }
            }
        }
        cout<<fie[100][N][S]+fie[100][N-1][S]<<endl;
    }
    return 0;
}

Measured memory_bytes: 11560
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int n=Integer.parseInt(sc.next());
        int[] res=new int[n];
        for(int i=0;i<n;i++){
            res[Integer.parseInt(sc.next())-1]=i+1;
        }
        for(int j=0;j<n;j++){
            System.out.print(res[j]+" ");
        }
    }
}

Measured memory_bytes: 49164
import numpy as np
import itertools
 
def calculate_total_distance(order, distance_matrix):
    idx_from = np.array(order[:-1])
    idx_to = np.array(order[1:])
    distance_arr = distance_matrix[idx_from, idx_to]

    return np.sum(distance_arr)
  
n = int(input())
li = np.array([list(map(int, input().split())) for _ in range(n)])
x = li[:, 0]
y = li[:, 1]
dist_matrix = np.sqrt((x[:, np.newaxis] - x[np.newaxis, :]) ** 2 + (y[:, np.newaxis] - y[np.newaxis, :]) ** 2)
dist = 0
for num, i in enumerate(itertools.permutations(range(n))):
  dist += calculate_total_distance(list(i), dist_matrix)
    
print(dist / (num + 1))

Measured memory_bytes: 12504
root = gets.chomp
n_cnt = 0
s_cnt = 0
e_cnt = 0
w_cnt = 0
(root.size).times do |i|
  if(root[i]=="N")then
    n_cnt += 1
  elsif(root[i]=="S")then
    s_cnt += 1
  elsif(root[i]=="W")then
    w_cnt += 1
  else
    e_cnt += 1
  end
end

#if(n_cnt==s_cnt && w_cnt==e_cnt)then
#  puts "Yes"
#else
#  puts "No"
#end

ns = false
es = false

if(n_cnt > 0 && s_cnt > 0 || n_cnt==0 && s_cnt==0)then
  ns = true
end

if(e_cnt > 0 && w_cnt > 0 || e_cnt==0 && w_cnt==0)then
  es = true
end

if(ns && es)then
  puts "Yes"
else
  puts "No"
end


Measured memory_bytes: 1788
#pragma region Macros
#include <bits/stdc++.h>
using namespace std;

// debug methods
// usage: debug(x,y);
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,a4,x,...) x
#define debug_1(x1) cout<<#x1<<": "<<x1<<endl
#define debug_2(x1,x2) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<endl
#define debug_3(x1,x2,x3) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<endl
#define debug_4(x1,x2,x3,x4) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<endl
#define debug_5(x1,x2,x3,x4,x5) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<endl
#ifdef LOCAL
    #define debug(...) CHOOSE((__VA_ARGS__,debug_5,debug_4,debug_3,debug_2,debug_1,~))(__VA_ARGS__)
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define debug(...) 42
    #define eprintf(...) 42
#endif

#define PI 3.1415926535897932384626433832795
#define INF 2e9
#define SINV(t) greater<t>()
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i, n) for(int i=(n); i>=0; --i)
#define FOR(i, n, m) for(int i=(m), i##_len=(n); i<i##_len; ++i)
#define FOREACH(i, v) for(const auto& i : v)
#define ALL(x) (x).begin(),(x).end()
#define SIGN(x) (((x)>0)?1:(((x)<0)?-1:0))

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

typedef long long ll;
#define vv(t) vector< t > 

#define CHC(mp, x) if(mp.end() != mp.find(x))
#define CHCV(mp, x) if(mp.end() != find(ALL(mp), x))

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

#define fi first
#define se second

#pragma endregion

template<typename T>
void SV(vector<T> v){
    #ifdef LOCAL
        REP(i,v.size()){
                cout << i << " : " << v[i] << endl;
        }
    #endif
}

template<typename T>
void SV(map<int, T> v){
    #ifdef LOCAL
        FOREACH(i, v){
            cout << i.first << " : " << i.second << endl;
        }
    #endif
}
int bitCount(int bits) {
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >> 16);
}

map< int64_t, int > prime_factor(int64_t n) {
  map< int64_t, int > ret;
  for(int64_t i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}

void Main();

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

void Main(){
    ll A, B , C,K;
    cin >> A >> B >> C >> K;
    ll sum=0;
    if(A+B>=K){
        cout << min(A, K) << endl;
    }else{
        debug(A+B, K, A, K-A-B);
        cout << (A-(K-A-B)) << endl;
    }
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	
	int a, b; cin >> a >> b;
	cout << a * (a - 1) / 2 + b * (b - 1) / 2 << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cassert>
#include <climits>
#include <bitset>
#include <stack>
#include <queue>
#include <iomanip>
#include <limits>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string.h>

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P;

long long int INF = 1e18;
long long int mod = 998244353;
double Pi = 3.1415926535897932384626;

vector<ll> G[500005];
vector<P> tree[500010];
priority_queue <ll> pql;
priority_queue <P> pqp;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
priority_queue <P,vector<P>,greater<P> > pqps;
//small priority queue
//top pop

int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
char dir[] = "RULD";
ll bit[500005];
//↓,→,↑,←

#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<x<<" ";
#define ps(x) cout<<fixed<<setprecision(15)<<x<<endl;
#define pu(x) cout<<x;
#define re(i,n) for(i=0;i<n;i++);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define deba(x) cout<< #x << " = " << x <<endl

ll rui(ll abc,ll bed){
    //abcのbed乗を計算する
    if(bed==0){return 1;}
    else{
        ll ced = rui(abc,bed/2);
        ced *= ced;
        ced %= mod;
        if(bed%2==1){ced*=abc; ced%=mod;}
        return ced;
    }
}
ll gcd(ll number1,ll number2){
	if(number1 > number2){
		swap(number1,number2);
	}
	if(number1 == 0 || number1 == number2){
		return number2;
	}else{
		return gcd(number2 % number1,number1);
	}
}

ll i,j,k,ii,jj,r,l;
ll n,m,num,ans;
ll a,b,c,d,e,g,h,w;
ll x[500005],y[500005],z[500005];
char s[5005];

ll bitsum(ll i){
	ll s = 0;
	while(i>0){
		//p("hoi");
		s += bit[i];
		i -= i & -i;
	}
	return s;
}
void bitadd(ll b,ll x){
	while(b <= n){
		//p("hoi");
		bit[b] += x;
		b += b & -b;
	}
}

int main(){
	cin >> n;
	cin >> a >> b;
	float num = INF;
	for(i=0;i<n;i++){
		cin >> c;
		float d = abs(b -  a + c * 0.006 );
		if(d < num){
			r = i;
			num = d;
		}
	}
	p(r + 1);




	//p(ans);
	

    return 0;
}

Measured memory_bytes: 27136
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <cmath>
using namespace std;

int main() {
	int x;
	cin >> x;
	for(long long i = -119; i <= 120; i++) {
		for(long long j = -119; j <= 120; j++) {
			if(pow(i, 5) - pow(j, 5) == x) {
				printf("%d %d\n",i,j);
				return 0;
			}
		}
	}
}

Measured memory_bytes: 4156
#include<bits/stdc++.h>
#define rep(i, x) for(ll i = 0; i < x; i++)
#define rep2(i, x) for(ll i = 1; i <= x; i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using namespace std;
const ll INF = 1000000000000000000;
const ll mod = 1000000007;

ll test[1234567];
signed main() {
	ll n, mae = 0, ato = 0; cin >> n;
	rep(i, 3 * n) { cin >> test[i]; }

	priority_queue<ll, vector<ll>, greater<ll>> que1;
	rep(i, n) { que1.push(test[i]); mae += test[i]; }
	vector<ll> v1(n * 3); v1[n] = mae;
	for (int h = n; h < 2 * n; h++) {
		mae += test[h]; que1.push(test[h]);
		mae -= que1.top(); que1.pop();
		v1[h + 1] = mae;
	}

	priority_queue<ll, vector<ll>, less<ll>> que2;
	for (int h = 3 * n - 1; h >= 2 * n; h--) { que2.push(test[h]); ato += test[h]; }
	vector<ll> v2(n * 3); v2[2 * n] = ato;
	for (int h = 2 * n - 1; h >= n; h--) {
		ato += test[h]; que2.push(test[h]);
		ato -= que2.top(); que2.pop();
		v2[h] = ato;
	}
	ll ans = 0 - INF;
	for (int h = n; h <= 2 * n; h++) {
		ans = max(ans, v1[h] - v2[h]);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 11812
import java.util.*;

public class Main {
 
	public static void main(String[] args) {
		Main main = new Main();
		main.run();
	}
 
	int mod = 1000000007;
 
	public void run() {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int a[] = new int[n+1];
		int d[] = new int[n+1];
		int dup = 0;
		for(int i=0; i<n+1; i++) {
			a[i]=sc.nextInt();
			d[a[i]]++;
			if(d[a[i]]>1) {
				dup = a[i];
			}
		}
		int befcnt = -1;
		int afcnt = -1;
		for(int i=0; i<n+1; i++) {
			if(a[i]==dup) {
				if(befcnt == -1) befcnt = i;
				else afcnt = i;
			}
		}
 
		init(n+1);
		int cnt = befcnt + n-afcnt;
		for(int i=1; i<=n+1; i++) {
			long ans = comb(n+1, i);
			ans += mod;
			ans -= comb(cnt, i-1);
			ans %= mod;
			System.out.println(ans);
		}
 
		sc.close();
	}
 
	public long comb(int n, int k) {
		if(k<0 || n<k) return 0;
		long ans = fact[n];
		ans *= ifact[k];
		ans %= mod;
		ans *= ifact[n-k];
		ans %= mod;
		return ans;
	}
 
	long fact[];
	long ifact[];
	public void init(int n) {
		fact = new long[n+1];
		ifact = new long[n+1];
 
		fact[0] = 1;
		fact[1] = 1;
		for(int i=2; i<=n; i++) {
			fact[i] = fact[i-1] * i;
			fact[i] %= mod;
		}
		ifact[n] = inv(fact[n]);
		for(int i=n-1; i>=0; i--) {
			ifact[i] = ifact[i+1] * (i+1);
			ifact[i] %= mod;
		}
	}
	public long pow(long n, int k) {
		if(k==0) return 1;
		if(k%2==0) {
			long tmp = pow(n, k/2);
			long ans = tmp * tmp;
			ans %= mod;
			return ans;
		}else {
			long tmp = pow(n, k-1);
			long ans = tmp * n;
			ans %= mod;
			return ans;
		}
	}
	public long inv(long n) {
		return pow(n, mod -2);
	}
 
}

Measured memory_bytes: 62548
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(a) (a).begin(),(a).end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
const int INF=1e9;
int main(){
      int ans=-INF;
      int n,a,mi;
      cin>>n;
      REP(i,n){
            cin>>a;
            if(i==0){
                  mi=a;
                  continue;
            }
            ans=max(ans,a-mi);
            mi=min(a,mi);
      }
      cout<<ans<<endl;
}

Measured memory_bytes: 1164
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>

using namespace std;

int main(){
	int N,X;
	cin>>N>>X;
	int min_v=X;
	vector<int> m(N);
	for(int i=0;i<N;i++){
		cin>>m[i];
		X-=m[i];
		min_v=min(min_v,m[i]);
	}
	cout<<N+X/min_v<<endl;
	return 0;
}

Measured memory_bytes: 256
// "static void main" must be defined in a public class.
import java.util.* ;
public class Main {
    static boolean helper( int a , int b , int c ) {
        return a<b && b<c ;
    }
    public static void main(String[] args) {
        Scanner S = new Scanner( System.in ) ;
        Main obj = new Main() ;
        int A = S.nextInt() ;
        int B = S.nextInt() ;
        int C = S.nextInt() ;
        int k = S.nextInt() ;
        
        if( helper( A , B , C ) ) {
            System.out.println( "Yes" ) ;
            return ;
        }
        while( k-->0 && !helper( A , B , C ) ) {
            if( helper( A , B , C ) ) {
                System.out.println( "Yes" ) ;
                return ;
            }
            if( A>=B ) B *= 2 ;
            else if( B>=C ) C *= 2 ;
        }
        if(! helper( A , B , C ) )
        System.out.println( "No" ) ;
        else System.out.println( "Yes" ) ;
    }
    
}


Measured memory_bytes: 35664
def maybe_prime(d,s,n):
    for a in (2,3,5,7):
        x = pow(a,d,n)
        if x==1 or x==n-1:
            continue
        for i in range(1,s):
            x = pow(x,2,n)
            if x==1: return False
            elif x == n-1:
                break
        else:
            return False
    return True

def is_prime(n):
    if n in (2,3,5,7): return True
    elif 0 in (n%2,n%3,n%5,n%7): return False
    elif 0 in [ n%i for i in range(11,min(n-1,50),2) ]:return False
    else:
        d,s = n-1, 0
        while not d%2:
            d,s = d>>1,s+1
        return maybe_prime(d,s,n)
cnt = 0
n = int(input())
for i in range(n):
  n = int(input())
  if is_prime(n): cnt+=1

print(cnt)

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

int main()
{   ll n,w,a,b,i;
    scanf("%lld%lld",&n,&w);
    vector<ll> z(100001,INT_MAX);
    z[0]=0;
    while(n--)
    {   scanf("%lld%lld",&a,&b);
        for(i=100000;i>=b;i--)
            z[i]=min(z[i],a+z[i-b]);
    }
    for(i=100000;i>=0;i--)
    {   if(z[i]<=w)
        {   printf("%lld",i);
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int a, b;
    cin >> a >> b;
    vector<int> retu(a);
    for(int i = 0;i < a; i++){
        cin >> retu.at(i);
    }

    int cnt = 1;
    int sum = 0;

    for(int j = 0; j < a; j++){
        sum = sum + retu.at(j);
        if(sum <= b){
            cnt++;
        }else{
            break;
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
using ll=long long;
using vi=vector<int>;
using vl=vector<long long>;
using pii=pair<int,int>;
using pll=pair<long long,long long>;
#define ITR(i,c) for(auto i=begin(c);i!=end(c);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##_len=(int)(n);i<i##_len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define REPW(i,n) for(i=0;i<(int)(n);++i)
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)   // c++14
#define SZ(c) ((int)c.size())
#define EXIST(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) (y<0||x<0||y>=h||x>=w)
#define dump(...)
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
#define INF (1001001001)
#define INFLL (1001001001001001001ll)
template<class T> ostream& operator << (ostream &os,const vector<T> &v) {
    ITR(i,v) os << *i << (i==end(v)-1 ? "" : " "); return os; }
template<class T> istream& operator >> (istream &is,vector<T> &v) {
    ITR(i,v) is >> * i; return is; }
template<class T> istream& operator >> (istream &is, pair<T,T> &p) {
        is >> p.first >> p.second; return is; }
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
//------------------------------------------------------------------------------
struct before_main_function {
    before_main_function() {
        #ifdef int
            #undef INF
            #define INF INFLL
            #define stoi stoll
        #endif
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
    }
} before_main_function;
//------------------------------------------------------------------------------

signed main() {
    const int MOD=1e9+7;
    int n;
    cin>>n;
    int ans=1;
    REPF(i,1,n+1) {
        ans*=i;
        ans%=MOD;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<int(n);++i)
#define all(a) (a).begin(),(a).end()
typedef long long ll;
#define rep1(i,n) for(int i=1;i<=int(n);++i)
#define lb(s,x) (lower_bound(all(s),x)-s.begin())
#define ub(s,x) (upper_bound(all(s),x)-s.begin())
#define uniq(a) a.erase(unique(all(a)),a.end())
#define bit(k) (1LL<<(k))
#define INF int(1e9)

template<class T,class U> ostream& operator<<(ostream& ost, const pair<T,U> &p) { ost << "(" << p.first << ", " << p.second << ")"; return ost; }
#define ostream_container { ost << "{"; for(const auto &t : v) { if (&t != &*v.begin()) ost << ", "; ost << t; } ost << "}"; return ost; }
template<class T> ostream& operator<<(ostream &ost, const vector<T> &v) ostream_container
template<class T> ostream& operator<<(ostream &ost, const set<T> &v) ostream_container
template<class T,class U> ostream& operator<<(ostream &ost, const map<T,U> &v) ostream_container

template<class H> void recursive_debug(string s, H h) {
    cerr << "\033[33m" << s << " = " << h << endl << "\033[m";
}
template<class H,class... T> void recursive_debug(string s, H h, T... t) {
    int comma = s.find(',');
    cerr << "\033[33m" << s.substr(0,comma) << " = " << h << ", ";
    recursive_debug(s.substr(comma+1), t...);
}
#define debug(...) recursive_debug(#__VA_ARGS__, __VA_ARGS__)


int main(void) {
    int a,b,c,k;
    cin >> a >> b >> c >> k;
    int cnt = 0;
    rep(i,10) {
        if (a >= b) {
            b *= 2;
            cnt++;
        } else {
            break;
        }
    }
    rep(i,10) {
        if (b >= c) {
            c *= 2;
            cnt++;
        } else {
            break;
        }
    }
    cout << ((cnt <= k) ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 3628