akhauriyash/Code-Regression huggingface dataset:
use std::cmp;
fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { reader: s.lock() };
    let n = sc.read();
    let k: usize = sc.read();
    let mut h: Vec<usize> = sc.read_vec(n);
    h.sort();
    let mut ans = 1e10 as usize;
    for i in 0..(n - k + 1) {
        ans = cmp::min(ans, h[i + k - 1] - h[i]);
    }
    println!("{}", ans);
}

pub struct Scanner<R> {
    reader: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .reader
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n')
            .take_while(|&b| b != b' ' && b != b'\n')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn read_vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


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

using ll = long long;

const int INF = 1001001001;
const ll INF_LL = 1001001001001001001LL;

int main(void){
  int a,b,k; cin >> a >> b >> k;

  int tmp = 0;
  int ans;
  for(int i = 100;i>=1;i--){
    if(a%i==0 && b%i==0) tmp++;
    if(tmp==k){
      ans = i;
      break;
    }
  }

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


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

/*
最小公倍数を求めればよい
Aの倍数をA*Bまで見ていく

or

gcd
*/

// int main() {
//     long A, B;
//     cin >> A >> B;

//     for (long i = 1; i <= B; i++)
//     {
//         /* code */
//         long num = A * i;
//         if (num % B == 0) {
//             cout << num << endl;
//             break;
//         }
//     }
// }

long gcd(long a, long b) {
    if (a < b) {
        long tmp = a;
        a = b;
        b = tmp;
    }

    if (a % b == 0) {
        return b;
    }
    else {
        return gcd(b, a % b);
    }
}

int main() {
    long A, B;
    cin >> A >> B;

    cout << A*B / gcd(A,B) << endl;
}

Measured memory_bytes: 256
n = int(input())
num = 0
ans = 0
cnt = 0
for i in range(1, n + 1):
    if i == 1:
        num = 1
        continue
    v = i
    while True:
        if v % 2 == 0:
            v = v // 2
            cnt +=1
        else:
            break
    if cnt > ans:
        num = i
        ans = cnt
    cnt = 0
print(num)

Measured memory_bytes: 3064
#include<stdio.h>

int main(void){
  int n;
  double y,v;

  while(1){
    int c=scanf("%lf",&v);
    if(c==EOF)return 0;
    y=4.9*(v/9.8)*(v/9.8);
    n=0;
    while(1){
      if(5*n-5>=y)break;
	n++;
    }
    printf("%d\n",n);
  }
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <utility>
#include <climits>
#include <bitset>

using namespace std;
#define li long long int
#define FOR(i, a, b) for (int i = a ; i < b ; ++i)
#define REP(i, n) for (int i = 0 ; i < n ; ++i)

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

int main(void) {
    li N;
    cin >> N;

    li F[N][5][2]; // 店の開いている情報
    FOR(i, 0, N) {
        FOR(j, 0, 5) {
            FOR(k, 0, 2) {
                cin >> F[i][j][k];
            }
        }
    }
 
    li P[N][11];

    FOR(i, 0, N) {
        FOR(j, 0, 11) {
            cin >> P[i][j];
        }
    }

    li o[10];
    li value = -(1ll << 60);
    FOR(i, 1, 1024) {
        // 2の10乗通り確かめる
        FOR(j, 0, 10) {
            o[j] = (i & (1 << j)) > 0 ? 1 : 0; // 　シフト演算
        }

        li count[N];
        FOR(j, 0, N) {
            count[j] = 0;
        }
        li tempValue = 0;
        FOR(j, 0, N) { // 全店舗
            FOR(k, 0 , 10) { // 全時間帯
                count[j] += o[k] * F[j][k / 2][k % 2]; // 営業時間が一致する個数を出す
            }
            tempValue += P[j][count[j]];
        }
        value = max(value, tempValue);
    }

    cout << value << endl;

    return 0;
}


Measured memory_bytes: 384
#import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
pri = lambda x: print(*x, sep='\n')

s = input()
K = int(input())

subs = set()
for i in range(len(s)):
    for l in range(1, K+1):
        subs.add(s[i:i+l])
opt = sorted(list(subs))
print(opt[K-1])



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

int main(){
int a,b,c;
cin>>a>>b>>c;

if(a > b) swap (a, b);
if(b > c) swap (b, c);
if(a > b) swap (a, b);

cout<<a<<" "<<b<<" "<<c<<endl;

return 0;

}


Measured memory_bytes: 3088
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
//#include <chrono> //1e+9で割る auto end= chrono::system_clock::now()-st;  cout<<end.count()%1e+9<<endl;
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> LP;
typedef long double db;

#define fr first
#define sc second
#define pb push_back
#define rep(i,x) for(int i=0;i<x;i++)
#define rep1(i,x) for(int i=1;i<=x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rrep1(i,x) for(int i=x;i>0;i--)

int N,s,l,p;
int dp[401];
const int Z=400;
int M;
priority_queue<P> q;
int x[400];
int main()
{
	cin>>N;
	rep(i,Z+1) dp[i]=-1;
	dp[0]=0; 
	rep(i,N){
		cin>>s>>l>>p;
		int lmax=0;
		for(int j=s;j<Z+1;j++){
			if(dp[j-s]>=0) q.push( P(dp[j-s] , j-s ) );
			while(!q.empty() && j>l && q.top().sc < j-l) q.pop();
			//cout<<j<<" "<<Z<<endl;
			if(q.top().fr==-1) continue;
			lmax=q.top().fr;
			dp[j]=max( lmax+p ,dp[j] );
			
		}
		while(!q.empty()) q.pop();
	}
	cin>>M;
	bool b=0;
	rep(i,M){
		cin>>x[i];
		if(dp[x[i]]==-1){
			puts("-1");
			return 0;
		}
	}
	rep(i,M) cout<<dp[x[i]]<<endl;//<<endl;
	//rep(i,10) cout<<dp[i]<<endl;
}


Measured memory_bytes: 3100
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;
#define M 1046527
#define NIL (-1)
#define L 14

long long T[M] = {0};

int getChar(char ch){
    if(ch == 'A') return 1;
    else if(ch == 'T') return 2;
    else if(ch == 'G') return 3;
    else if(ch == 'C') return 4;
    else return 0;
}


long long getKey(string data){
    long long sum = 0;
    long long p = 1;
    for(int i = 0; i < data.size(); ++i){
        sum += p * getChar(data[i]);
        p *= 5;
    }
    return sum;
}


int h1(int key){
    return key % M;
}


int h2(int key){
    return 1 + key % (M-1);
}


int h(int key, int i){
    return (h1(key) + i * h2(key)) % M;
}


bool find(string data){
    long long key;
    key = getKey(data);
    for(int i = 0;; i++){
        int j = h(key, i);
        if(T[j] == key) return true;
        else if(T[j] == 0 || i >= M) return false;
    }
}

void insert(string data){
    if(find(data)) return;
    long long key;
    key = getKey(data);
    for(int i = 0;; ++i){
        int j = h(key, i);
        if(T[j] == 0) {
            T[j] = key;
            break;
        }
        else if(i >= M) {
            cout << "Error: no more room for insertion" << endl;;
            break;
        }
    }
}

int main(){
    int n;
    cin >> n;
    for(int i = 0; i < n; ++i){
        string instruction, word;
        cin >> instruction;
        cin >> word;
        if(instruction == "insert") insert(word);
        else if(find(word)) cout << "yes" << endl;
        else cout << "no" << endl;
    }

    return 0;
}



Measured memory_bytes: 11372
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll dp[51][5000];

int main(){
  int n,A,a[51];
  cin>>n>>A;
  for(int i=0;i<n;i++) cin>>a[i];

  
  dp[0][0]=1;
  for(int i=0;i<n;i++)
    for(int k=3000;k>=0;k--)
	for(int j=0;j<n;j++)
	dp[j+1][k+a[i]]+=dp[j][k];

  ll ans=0;
  for(int j=1;j<=n;j++)
    for(int k=1;k<=3000;k++)if(1.0*k/j==A)ans+=dp[j][k];
    cout <<ans<<endl;
    return 0;
  }


Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const double PI=acos(-1);
const int INF = numeric_limits<int>::max();

int main(){
    ll a, b, k;
    cin >> a >> b >> k;

    ll ans1 = k;
    ans1 -= a;

    if (ans1 <= 0){
        cout << a - k << " " << b << endl;
        return 0;
    }
    else {
        ll ans2 = ans1;
        ans2 -= b;
        if (ans2 <= 0) {
            cout << 0 << " " << b - ans1 << endl;
            return 0;           
        }
        else cout << 0 << " " << 0 << endl;
    }

    return 0;
    
}

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


int main() {
    int N, M;
    cin >> N >> M;
    int sum = 0;
    vector<int> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        sum += A[i];
    }
    sort(A.begin(), A.end());
    reverse(A.begin(), A.end());
    for (int i = 0; i < M; i++) {
        if (A[i] * 4 * M < sum) {
            cout << "No\n";
            return 0;
        }
    }
    cout << "Yes\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
// 型名の省略
typedef unsigned int uint;
typedef long long lint;
typedef unsigned long long ulint;
 
const int MOD = 1000000007;
const lint INF = 1LL << 60;
const double PI=acos(-1.0);
 
// cinとcoutの高速化
#define endl "\n"
struct cinacc{cinacc(){cin.tie(0);ios::sync_with_stdio(false);}}cinaccc;
struct coutacc{coutacc(){cout.setf(ios::fixed);cout.precision(12);}}coutaccc;
 
// 繰り返し
#define rep(i,n) for(lint i=0;i<(lint)(n);i++)
#define reps(i,n) for(lint i=0;i<=(lint)(n);i++)
#define rrep(i,n) for(lint i=(lint)(n)-1;i>0;i--)
#define rreps(i,n) for(lint i=(lint)(n)-1;i>=0;i--)

#define pb push_back

#define ALL(s) (s.begin(), s.end())
#define SZ(s) (s.size())

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

// Union-Find-Tree
class UnionFind {
    vector<int> par;
    UnionFind(int n):par(n){rep(i,n)par[i]=i;}
    int root(int x){if(par[x]==x)return x;return par[x]=root(par[x]);}
    void unite(int x,int y){int rx=root(x);int ry=root(y);if(rx==ry)return;par[rx]=ry;}
    bool same(int x,int y){return root(x)==root(y);}
};

// Final Weapon!
// #define int lint

int main(void) {
    int n, x, y;
    cin >> n >> x >> y;
    x--; y--;
    
    int min;
    vector<int> ans(n);
    for(int i = 0; i < n; i++) {
        for(int j = i + 1; j < n; j++) {
            min = abs(j - i);
            chmin(min, abs(x - i) + 1 + abs(j - y));
            chmin(min, abs(y - i) + 1 + abs(j - x));
            ans[min]++;
        }
    }
    
    for(int k = 1; k < n; k++) {
        cout << ans[k] << endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

//最後のポイント=K-（Q-正解数)
int main(){
	ll N,K,Q,l;
	cin >> N;
	cin >> K;
	cin >> Q;
	vector <ll> P(N);
	for (ll i = 0;i < Q;i++){
		cin >> l;
		P[l-1]++;
	}
	for (ll i = 0;i < N;i++){
		if ((K+P[i]-Q) <= 0){
			cout << "No" <<endl;
		}
		else{
			cout << "Yes" <<endl;
		}	
	}
	return 0;
}

Measured memory_bytes: 1408
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();
        for(int i = 0; i < n; i++) {
            int k = sc.nextInt();
            for(int j = 0; j < k; j++) {
                int a = sc.nextInt();
                int b = 0;
                if(map.containsKey(a)) {
                    b = map.get(a);
                }
                map.put(a, b + 1);
            }
        }
        int ans = 0;
        for(int i : map.values()) {
            if(i == n) {
                ans++;
            }
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 22828
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>

using namespace std;
using ll = long long;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
int gcd(int a, int b){ return (b == 0) ? a : gcd(b, a % b); }

#define For(i, n) for(int i = 0; i < (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Vec2(T, n, m, xs, x0) vector<vector<T>> xs(n, vector<T>(m, x0))
#define Sum(a) accumulate(Range(a), 0)
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) for(const auto &e : xs) cout << e << " "; cout << "\n"
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")

// constexpr int MOD = 1e9+7;

int main(void){
    Cin(int, n, p);
    Vec2(ll, n+1, 2, dp, 0);
    dp[0][0] = 1;
    For(i, n){
        Cin(int, a);
        For(j, 2) dp[i+1][j] = dp[i][j] + dp[i][(j+a) % 2];
    }
    Cout(dp[n][p]);
}


Measured memory_bytes: 256
#pragma GCC optimize ("-O3","unroll-loops")
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>


#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 SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define m0(x) memset(x,0,sizeof(x))
#define print(x) cout<<x<<'\n';
#define pe(x) cout<<x<<" ";
#define lb(v,n) lower_bound(v.begin(), v.end(), n);
#define ub(v,n) upper_bound(v.begin(), v.end(), n);
#define int long long
#define all(x) (x).begin(), (x).end()
#define double long double

using namespace std;

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

int MOD = (ll)1000000000 + 7;
const ll INF = 1e17;
const double pi = acos(-1);
const double EPS = 1e-10;
typedef pair<int, int>P;
const int MAX = 200020;

bool cycle(int x) {
	int a[10];
	int cnt = 0;
	while (x > 0) {
		a[cnt] = x % 10;
		x /= 10;
		cnt++;
	}
	bool ok = true;
	REP(i, 3) {
		if (a[i] != a[4 - i])ok = false;
	}
	return ok;
}
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int A, B; cin >> A >> B;
	int ans = 0;
	FOR(i, A, B + 1) {
		if (cycle(i)) {
			ans ++ ;
		}
	}
	print(ans);
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
  Scanner sc;

  int[] atom = new int[3];
  char[] str;
  int index;

  boolean isAtom(char c) {
    switch ( c ) {
    case '0':
    case '1':
    case '2':
    case 'P':
    case 'Q':
    case 'R':
      return true;
    default:
      return false;
    }
  }

  Tree make() {
    Tree tree = new Tree();
    if ( isAtom(str[index]) ) {
      tree.type = str[index];
      ++index;
    } else {
      if(str[index] == '-') {
        tree.type = str[index++];
        tree.left = make();
      } else {
        ++index; // (
        tree.left = make();
//        debug(index, str[index]);
        tree.type = str[index++];
        tree.right = make();
        ++index; // )
      }
    }
    return tree;
  }

  class Tree {
    char type;

    Tree left;
    Tree right;

    Tree() {
    }

    int exp() {
      switch ( type ) {
      case '0':
      case '1':
      case '2':
        return type - '0';
      case 'P':
      case 'Q':
      case 'R':
        return atom[ type - 'P' ];
      case '+':
        return Math.max( left.exp(), right.exp() );
      case '*':
        return Math.min( left.exp(), right.exp() );
      case '-':
        return 2 - left.exp();
      default:
        return -1;
      }
    }
  }

  void run() {
    for ( ;; ) {
      str = sc.next().toCharArray();
      if ( str[ 0 ] == '.' ) {
        break;
      }
      index = 0;
      Tree root = make();
      int cnt = 0;
      for ( int i = 0; i < 3; ++i ) {
        for ( int j = 0; j < 3; ++j ) {
          for ( int k = 0; k < 3; ++k ) {
            atom[ 0 ] = i;
            atom[ 1 ] = j;
            atom[ 2 ] = k;
            if ( root.exp() == 2 ) {
              ++cnt;
            }
          }
        }
      }
      System.out.println( cnt );
    }
  }

  Main() {
    sc = new Scanner( System.in );
  }

  int ni() {
    return sc.nextInt();
  }

  public static void main(String[] args) {
    new Main().run();
  }

  void debug(Object... os) {
    System.err.println( Arrays.deepToString( os ) );
  }

}

Measured memory_bytes: 19856
#include <bits/stdc++.h>
#define rep(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define repr(i, n, m) for (int i = (int)(n) - 1; i >= (int)(m); i--)
using namespace std;
using ll = int64_t;
const int MOD = 1000000007; // 10^9+7

int main() {
    ll X;
    cin >> X;

    ll num500 = X / 500L;
    X = X - 500L * num500;
    ll num5 = X / 5L;
    cout << num500 * 1000 + num5 * 5 << endl;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	fmt.Println(dfs(0, nextInt()))
}

func dfs(x, n int) int {
	if x > n {
		return 0
	}
	ret := 0
	if is753(x) {
		ret = 1
	}
	for i := 3; i <= 7; i += 2 {
		ret += dfs(x*10+i, n)
	}
	return ret
}

func is753(x int) bool {
	m := map[int]int{7: 0, 5: 0, 3: 0}
	for x > 0 {
		switch x % 10 {
		case 7:
			m[7]++
		case 5:
			m[5]++
		case 3:
			m[3]++
		}
		x /= 10
	}
	for _, v := range m {
		if v == 0 {
			return false
		}
	}
	return true
}

func lcm(a, b int64) int64 {
	return (a / gcd(a, b)) * b
}

func gcd(a, b int64) int64 {
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

const size = 1000000

var reader = bufio.NewReaderSize(os.Stdin, size)

func nextLine() string {
	var line, buffer []byte
	isPrefix := true
	var err error
	for isPrefix {
		line, isPrefix, err = reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buffer = append(buffer, line...)
	}
	return string(buffer)
}
func nextStringArray() []string {
	return strings.Split(nextLine(), " ")
}
func nextInt() int {
	n, _ := strconv.Atoi(nextLine())
	return n
}

func nextIntArray() []int {
	s := strings.Split(nextLine(), " ")
	n := len(s)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i], _ = strconv.Atoi(s[i])
	}
	return a
}

func min(i, j int) int {
	if i > j {
		return j
	}
	return i
}

func max(i, j int) int {
	if i < j {
		return j
	}
	return i
}


Measured memory_bytes: 3840
#pragma GCC optimize("O3")

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
using namespace std;

/*----------macros----------*/

//output================
#define endl '\n'
#define fcout cout << fixed << setprecision(15)

//typedef===============
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;

//const number==========
constexpr ll INF9   = (ll)1e9 + 1;
constexpr ll INF18  = (ll)1e18 + 1;
constexpr ll MOD    = 1000000007;
constexpr ld PI     = 3.141592653589793L;

//member================
#define pb push_back
#define eb emplace_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second

//others================
#define all(x)          (x).begin(), (x).end()
#define rall(x)         (x).rbegin(), (x).rend()
#define rep(i, n)       for(int i = 0; (i) < (n); ++(i))
#define rrep(i, n)      for(int i = n - 1; (i) >= 0 ; --(i))
#define For(i, a, b)    for(int i = (a); (i) < (b) ; ++(i))
#define CtoI(c)         int((c)) - int('0')

//functions=============
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
template<typename T> void sortVector(vector<T> &v, bool lesser = true) { lesser ? sort(all(v)) : sort(all(v), greater<T>()); }
bool isPrime(int n){
    if(n < 2) return false; else if(n == 2) return true; else if(n%2 == 0) return false;
    double sqrtNum = sqrt(n); for(int i = 3;i <= sqrtNum; i += 2) if(n%i == 0) return false;
    return true; }

//vector<int> dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
//vector<int> dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 };

/*--------additional--------*/



/*----------main------------*/

int main() {
/*----------fastio----------*/
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    std::ios::sync_with_stdio(false);
/*----------solve-----------*/

    string s; cin >> s;
    if(s[0] == 'R' && s[1] == 'R' && s[2] == 'R'){
        cout << 3 << endl;
        return 0;
    }

    if(s[0] == 'R' && s[1] == 'R' && s[2] == 'S'){
        cout << 2 << endl;
        return 0;
    }

    if(s[0] == 'S' && s[1] == 'R' && s[2] == 'R'){
        cout << 2 << endl;
        return 0;
    }

    if(s[0] == 'S' && s[1] == 'S' && s[2] == 'S'){
        cout << 0 << endl;
        return 0;
    }

    else cout << 1 << endl;

return 0;
}

Measured memory_bytes: 3560
#include<cstdio>
#include<cstring>
#include<algorithm>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,b,a) for(int i=b;i>=a;i--)
#define efo(i,u,v) for(int i=BB[u],v=B[BB[u]][1];i;v=B[i=B[i][0]][1])
#define mset(a,x) memset(a,x,sizeof(a))
using namespace std;
typedef long long ll;
typedef double db;
char ch;
int read(){int n=0,p=1;for(ch=getchar();ch<'0' || '9'<ch;ch=getchar())if(ch=='-') p=-1;for(;'0'<=ch && ch<='9';ch=getchar()) n=n*10+ch-'0';return n*p;}
const int N=1e5+5;
int n,ans,BB[N],B[N<<1][2],B0,f[N],bit[N];
void link(int u,int v){B[++B0][1]=v,B[B0][0]=BB[u],BB[u]=B0;}
void dfs(int v,int fr=1)
{
	efo(i,v,u) if(u!=fr)
	{
		dfs(u,v);
		fo(j,0,20)
			if((bit[v]&bit[u])&(1<<j)) f[v]=max(f[v],j+1);
		bit[v]|=bit[u];
	}
	while(bit[v]&(1<<f[v])) f[v]++;
	bit[v]|=(1<<f[v]);
	fo(j,0,f[v]-1)
		if(bit[v]&(1<<j)) bit[v]^=(1<<j);
	ans=max(ans,f[v]);
}
int main()
{
	int x,y;
	n=read();
	fo(i,1,n-1) x=read(),y=read(),link(x,y),link(y,x);
	dfs(1);
	printf("%d",ans);
	return 0;
}


Measured memory_bytes: 6272
#include <bits/stdc++.h>
 
using namespace std;
#define ll long long
#define ld long double
 
int main()
{
    ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
    string s;
    cin >> s;
    bool okA = false, okB = false;
    for(int i=0;i<3;i++) {
        if(s[i] == 'A') okA = true;
        else if(s[i] == 'B') okB = true;
    }
    if(okA && okB) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <tuple>
#include <algorithm>
using i64 = long long;

template <class T = long long int>
class Bit {
    private:
    unsigned len;
    T init;
    std::vector<T> arr;

    public:
    Bit(unsigned length, T initialValue = 0): len(length), init(initialValue), arr(len + 1, init) {}
    void update(unsigned a, T newval) {
        for (unsigned x = a; x <= len; x += x & -x) arr[x] += newval;
    }
    T query(unsigned a) const {
        T ret = init;
        for (unsigned x = a; x > 0; x -= x & -x) ret += arr[x];
        return ret;
    }
};

int main() {
    int n, m;
    std::cin >> n >> m;
    std::vector<std::tuple<int, int, int>> evs;

    for (int i = 0; i < n; i++) {
        int l, r;
        std::cin >> l >> r;
        ++r;
        evs.emplace_back(r - l, l, r);
    }

    std::sort(evs.begin(), evs.end());

    Bit<int> bit(m + 2);
    auto it = evs.cbegin();
    for (int i = 1; i <= m; i++) {
        int ret = evs.end() - it;
        for (int j = i; j <= m; j += i) {
            ret += bit.query(j);
        }
        while (it != evs.end() && std::get<0>(*it) == i) {
            bit.update(std::get<1>(*it), 1);
            bit.update(std::get<2>(*it), -1);
            it++;
        }
        std::cout << ret << '\n';
    }

    return 0;
}


Measured memory_bytes: 8560
#include <stdio.h>
int main(void) {
    int num,area[8][8],i,j,k,bomb[64][2],sp,bx,by;
    char str[8];
    scanf("%d\n",&num);
    for (i=0; i<num; i++) {
        sp=0;
        for (j=0; j<8; j++) {
            scanf("%s\n",str);
            for(k=0;k<8;k++) {
                if(str[k]=='0') {
                	area[j][k]=0;
                } else {
                	area[j][k]=1;
                }
            }
        }
        scanf("%d %d",&bx,&by);
        bomb[0][0]=bx-1;
        bomb[0][1]=by-1;
        
        sp++;
        while (1) {
            sp--;
            bx=bomb[sp][0];
            by=bomb[sp][1];
            area[by][bx]=0;
            for (j=bx-1; bx-3<=j&&j>=0; j--) {
                if (area[by][j]==1) {
                    area[by][j]=0;
                    bomb[sp][0]=j;
                    bomb[sp][1]=by;
                    sp++;
                }
            }
            for (j=bx+1; bx+3>=j&&j<=7; j++) {
                if (area[by][j]==1) {
                    area[by][j]=0;
                    bomb[sp][0]=j;
                    bomb[sp][1]=by;
                    sp++;
                }
            }
            for (j=by-1; by-3<=j&&j>=0; j--) {
                if (area[j][bx]==1) {
                    area[j][bx]=0;
                    bomb[sp][0]=bx;
                    bomb[sp][1]=j;
                    sp++;
                }
            }
            for (j=by+1; by+3>=j&&j<=7; j++) {
                if (area[j][bx]==1) {
                    area[j][bx]=0;
                    bomb[sp][0]=bx;
                    bomb[sp][1]=j;
                    sp++;
                }
            }
            if (sp==0) break;
        }
        printf("Data %d:\n",i+1);
        for (j=0; j<8; j++) {
            for(k=0;k<8;k++) printf("%d",area[j][k]);
            printf("\n");
        }
    }
    return 0;
}

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

using namespace std;

const int N = 101;
const int V = 1001;
using ll = long long;
ll dp[N * V], w[N], v[N];

int main() {
    int n, totalWeight;
    cin >> n >> totalWeight;
    for (int i = 1; i <= n; i++) {
        cin >> w[i] >> v[i];
    }
    memset(dp, 0x7f, sizeof dp);
    dp[0] = 0;
    for (int i = 1; i <= n; i++) {
        for (int value = N * V - 1; value >= 1; value--) {
            if (value - v[i] >= 0) {
                dp[value] = min(dp[value], dp[value - v[i]] + w[i]);
            }
        }
    }
    for (int value = N * V - 1; value >= 0; value--) {
        if (dp[value] <= totalWeight) {
            cout << value;
            return 0;
        }
    }
    return 0;
}


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

#define F first
#define S second
typedef double db;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

ll gcd(ll x,ll y){
return y? gcd(y,x%y):x;
}

int main(){
  int n;
  cin>>n;
  vector<int> v(n+1);
  vector<int> c(n+1);
  for(int i=1;i<=n;i++)cin>>v[i];
  for(int k=1;k<=n;k++){
  c[v[k]]++;
  }
  for(int l=1;l<=n;l++){
  cout<<c[l]<<endl;
  }
return 0;
}

Measured memory_bytes: 4844
#include<iostream>
using namespace std;
int main()
{
	int a;
	cin>>a;
	cout<<a/3600<<":"<< (a-a/3600*3600)/60<<":"<<a-(a/3600*3600)-(((a-a/3600*3600)/60)*60)<<endl;
	return 0;
} 


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

using namespace std;

#define endl "\n"
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define fastio { ios_base::sync_with_stdio(false), cin.tie(NULL); }
#define forn(i, n) for(int i = 0; i < (int)(n); i++)
#define for1(i, n) for(int i = 1; i <= (int)(n); i++)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); i++)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)

#ifdef RICARDO
//Header here
	#include "E:\\Code\\dbg.h"
#else
	#define bug(...) "RICARDO MILOS"
#endif


template<class T> bool mini(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool maxi(T &a, T b) { return a < b ? (a = b, true) : false; }

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;

//=================================================CODE=================================================//

signed main()
{	
	fastio;
	cout.precision(10);
	cout << fixed;
#ifdef RICARDO		
	freopen("i", "r", stdin);
#endif
	int n, m; cin >> m >> n;
	vpi prs(m);
	for(auto &e : prs) cin >> e.fi >> e.se;
	sort(rall(prs));

	//siege
	vvi D(n + 1);
	for1(i, n) {
		D[0].pb(i);
		for(int j = i; j <= n; j += i) D[j].pb(i);
	}
	//

	vi bit(n + 1, 0);
	auto up = [&](int i) {
		for(; i <= n; i += i & -i) bit[i]++;
	};
	auto get = [&](int i) {
		int RES = 0;
		for(; i; i -= i & -i) RES += bit[i];
		return RES;
	};

	vi ANS(n + 1, m);
	int cur = 0;
	ford(i, n) {
		while(cur < m && prs[cur].fi > i) {
			up(prs[cur].se);			
			cur++;			
		}

		for(int v : D[i]) {
			int j = i + v;
			ANS[v] -= get(min(j - 1, n));						
		}	
	}

	for1(i, n) cout << ANS[i] << endl;
#ifdef RICARDO
	cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
}

Measured memory_bytes: 14844
#include<bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for (int (i) = 1; (i) <= (n); (i++))
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define yn {puts("Yes");}else {puts("No");}
#define print(x) cout << (x) << endl;
#define printa(x, n) for(ll i = 0; i < n; i++) {cout << (x[i]) << " ";} cout << endl;
#define printd(x) printf("%.12f\n", ans);
#define Yes() cout << "Yes" << endl;
#define No() cout << "No" << endl;
#define YES() cout << "YES" << endl;
#define NO() cout << "NO" << endl;
template<class T> bool chmin(T& a, const T& b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> bool chmax(T& a, const T& b) {if (a < b) {a = b; return 1;} return 0;}
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;

bool ok[3][3];

int main(void) {
    int a[3][3];
    rep (i, 3) rep (j, 3) cin >> a[i][j];

    int n;
    cin >> n;
    int b[n];
    rep (i, n) cin >> b[i];

    rep (i, n) {
        rep (j, 3) {
            rep (k, 3) {
                if (b[i] == a[j][k]) ok[j][k] = true;
            }
        }
    }

    bool jud = false;

    rep (i, 3) if (ok[i][1] && ok[i][2] && ok[i][0]) jud = true;
    rep (i, 3) if (ok[0][i] && ok[1][i] && ok[2][i]) jud = true;
    if (ok[0][0] && ok[1][1] && ok[2][2] || ok[0][2] && ok[1][1] && ok[2][0]) jud = true;

    cout << (jud ? "Yes" : "No")<<endl;
    
    return 0;
}

Measured memory_bytes: 256
import itertools
from scipy.sparse.csgraph import floyd_warshall as wf

def do():
    N,M,R = list(map(int,input().split(" ")))
    rs = list(map(int,input().split(" ")))
    INF = float('inf')

    graph = [ [INF for _ in range(N + 1)]for _ in range(N + 1)]
    for _ in range(M):
        a,b,c = (map(int, input().split(" ")))
        graph[a][b] = c
        graph[b][a] = c

    graph = wf(graph)

    perms = itertools.permutations(rs)
    ans = INF
    for temp in perms:
        cand = 0
        for i in range(0,R-1):
            fr = temp[i]
            to = temp[i + 1]
            cand+= graph[fr][to]
        ans = min(cand,ans)
    print(int(ans))

if __name__ == "__main__":
    do()

Measured memory_bytes: 19340
a = int(input())

aa = 0

un = 0

p = 0

for i in range(a):
  k = input()
  if k == 'A':
    aa += 1
  elif k == 'Un':
    un += 1
  if un > aa:
    p = 1

if aa > un:
  p = 1
  
if p == 0:
  print("YES")
else:
  print("NO")



Measured memory_bytes: 5592
#include<cstdio>
#include<algorithm>
using namespace std;

int n;

int main() {
	scanf("%d",&n);
	int ans=0;
	ans+=min(9,n);
	if(n>=100) {
		ans+=min(999,n)-99;
		if(n>=10000)
			ans+=min(99999,n)-9999;
	}
	printf("%d\n",ans);
	return 0;
}

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

// isDebug?
#ifndef ONLINE_JUDGE
#define _DEBUG
#endif

// Function Macros:
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define setpre(n) cout << fixed << setprecision(n)

// -* https://xn--kst.jp/blog/2019/08/29/cpp-comp/ *- Thx :)
// 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 _DEBUG
#define debug(...)                                                        \
    cout << __FILE__ << ": " << __LINE__ << ": " << __func__ << " -> ";   \
    CHOOSE((__VA_ARGS__, debug_5, debug_4, debug_3, debug_2, debug_1, ~)) \
    (__VA_ARGS__)
#else
#define debug(...)
#endif

// namespace / type / class / struct - alias, def:
using namespace std;

using ll = long long;
using ull = unsigned long long;

// Constants:
const int INF = (1ll << 30) - 1;  // approx 1.07e9
const ll INFLL = 1ll << 60;       // approx 1.15e18
const int MOD = 1e9 + 7;          // 998244353
const long double EPS = 1.0e-14;
const int FACN = 510000;

// Global Variables:
// ll fac[FACN], finv[FACN], inv[FACN];

// Prototype Declarations:
int gcd(int, int);
int lcm(int, int);
template <class T>
inline bool chmin(T&, T);
template <class T>
inline bool chmax(T&, T);

// ================ Main Loop ================
int main() {
    int n;
    cin >> n;
    vector<int> l(n);
    rep(i, n) {
        cin >> l[i];
    }

    int ans = 0;
    for(int i = 0; i < n; i++) {
        for(int j = i + 1; j < n; j++) {
            for(int k = j + 1; k < n; k++) {
                if(l[i] != l[j] && l[j] != l[k] && l[k] != l[i]) {
                    ans += (l[i] + l[j] > l[k] && l[j] + l[k] > l[i] && l[k] + l[i] > l[j]);
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}
// ===========================================

// Functions:
// 最大公約数 O(log(min(a, b)))
int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}
// 最小公倍数 O(log(min(a, b)))
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}

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

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


Measured memory_bytes: 3628
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <vector>

using namespace std;

#define l first
#define r second
#define int long long

int n;
long long a[500000];
vector<long long> multi;

int upper_bit(long long c)
{
    for (int i = 60; i >= 0; i--)
    {
        if (c & (1LL << i)) return i;
    }
    return -1;
}

signed main()
{
    cin >> n;
    long long x = 0;
    for (int i = 0; i < n; i++) cin >> a[i], x ^= a[i];
    for (int i = 0; i < n; i++) a[i] -= a[i] & x;
    for (int i = 0; i < n; i++)
    {
        int kek = 0;
        for (int j = 0; j < multi.size(); j++)
        {
            if (upper_bit(multi[j]) == upper_bit(a[i])) kek = 1;
        }
        if (kek)
        {
            long long cur = a[i];
            for (int i = 0; i < multi.size(); i++)
            {
                if (upper_bit(cur) == upper_bit(multi[i]))
                {
                    cur ^= multi[i];
                    if (cur == 0) break;
                }
            }
            if (cur != 0)
            {
                multi.push_back(cur);
                sort(multi.begin(), multi.end());
                reverse(multi.begin(), multi.end());
            }
        }
        else
        {
            multi.push_back(a[i]);
            sort(multi.begin(), multi.end());
            reverse(multi.begin(), multi.end());
        }
    }
    sort(multi.begin(), multi.end());
    reverse(multi.begin(), multi.end());
    long long res = 0;
    long long b = (1LL << 61);
    for (int i = 0; i < multi.size(); i++)
    {
        //cout << multi[i] << "\n";
        while (b > multi[i]) b /= 2;
        if ((res & b) == 0) res ^= multi[i];
    }
    cout << x + 2 * res;
}


Measured memory_bytes: 1024
#include <stdio.h>

#define N 101

#define WHITE 0
#define GRAY 1
#define BLACK 2

void bfs();
void enq(int);
int deq();

int A[N][N] = {0};
int color[N] = {0};
int d[N];
int stac[N];
int top = 0, tail = 0;
int num ,time;

int main(){
  int inum, jnum, count, i, j;
  
  scanf("%d", &num);
  
  for(i = 1; i <= num; i++){
    scanf("%d %d", &inum, &count);  
    for(j = 1; j <= count; j++){
      scanf("%d", &jnum);
      A[inum][jnum] = 1;
    }
  }
  
  bfs();
  
  for(i = 1; i <= num; i++){
    printf("%d %d\n", i, d[i]);
  }
  
  
  return 0;
}

void bfs(){
  int s = 1, u, i;

  for(i = 1; i <= num; i++){
    d[i] = -1;
  }
  
  color[s] = GRAY;
  d[s] = 0;
  enq(s);
  
  while(top != tail){
    u = deq();
    for(i = 1; i <= num; i++){
      if(A[u][i] == 1 && color[i] ==WHITE){
	color[i] = GRAY;
	d[i] = d[u]+1;
	enq(i);
      }
    }

    color[u] = BLACK;
  }
  
}

void enq(int num){
  stac[tail] = num;
  tail++;
}

int deq(){
  if(top == tail){
    return -1;
  }
  else{
    top++;
    return stac[top-1];
  }
}



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

#pragma GCC optimize("Ofast")

#define fi first
#define se second
#define ll long long

using namespace std;

int main()
{
    int n;
    cin >> n;
    string a,b;
    cin >> a >> b;
    string ans;
    for(int i = 0;i < n;i++){
        ans+=a[i];
        ans+=b[i];
    }
    cout << ans;
}


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

const int INF = 10000000;

int main() {
  int N, M, X;
  cin >> N >> M >> X;
  vector<int> C(N);
  vector<vector<int>> A(N, vector<int>(M));
  rep(i, N) {
    cin >> C[i];
    rep(j, M) {
      cin >> A[i][j];
    }
  }
  int ans = INF;
  for (int i = 0; i < (1<<N); i++) {
    vector<int> sum(M, 0);
    int cost = 0;
    bool can = true;
    for (int j = 0; j < N; j++) {
      if (i & 1<<j) {
        cost += C[j];
        rep(k, M) {
          sum[k] += A[j][k];
        }
      }
    }
    rep(k, M) {
      if (sum[k] < X) {
        can = false;
        break;
      }
    }
    if (can) ans = min(ans, cost);
  }
  if (ans == INF) {
    cout << -1 << endl;
  }
  else {
    cout << ans << endl;
  }
}

Measured memory_bytes: 3624
N = int(input())

CSFn = [[int(j) for j in input().split()] for i in range(N - 1)]


def next(s):
    t = 0

    for Ci, Si, Fi in CSFn[s:]:
        # 始発
        if t < Si:
            t = Si

        # タイムラグ
        elif t % Fi:
            t += Fi - t % Fi

        # 列車の移動時間
        t += Ci

    return t


def main():
    # 出発駅
    for i in range(N - 1):
        t = next(i)
        print(t)

    print(0)

    return


main()


Measured memory_bytes: 3188
#include<vector>
#include<iostream>
#include<queue>
#include<functional>
using namespace std;

constexpr int INF = 1e9;

struct edge {
	int from, to, cost;
	bool operator>(const edge& other)const {
		return cost > other.cost;
	}
};

using edges = vector<edge>;
using graph = vector<edges>;

void add_edge(graph& g, int from, int to, int cost) {
	g[from].push_back(edge{ from,to,cost });
	g[to].push_back(edge{ to,from,cost });
}


edges prim(const graph& g) {
	const int N = g.size();
	vector<bool>used(N);
	used[0] = true;
	priority_queue<edge, vector<edge>, greater<edge>>p_que;
	for (auto e : g[0]) {
		p_que.push(e);
	}
	edges mst;
	while (!p_que.empty()) {
		auto e = p_que.top();
		p_que.pop();
		if (used[e.to]) {
			continue;
		}
		mst.push_back(e);
		used[e.to] = true;
		for (auto new_e : g[e.to]) {
			p_que.push(new_e);
		}

	}
	return mst;
}

int main() {
	int V, E;
	cin >> V >> E;
	graph g(V);
	for (int i = 0; i < E; i++) {
		int from, to, cost;
		cin >> from >> to >> cost;
		add_edge(g, from, to, cost);
	}
	const auto mst = prim(g);
	int ans = 0;
	for (auto& e : mst) {
		ans += e.cost;
	}
	cout << ans << endl;
	return 0;
}










Measured memory_bytes: 10212
N, M = map(int, input().split())
k_min, k_max = 0, N
for i in range(M):
    l, r = map(int, input().split())
    k_min = max(k_min, l)
    k_max = min(k_max, r)

ans = k_max - k_min + 1
if (ans < 0):
    ans = 0
print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define sp(n) cout << fixed << setprecision(n)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
using namespace std;
int main(void){
    int n;cin>>n;
    vector<pair<string,pair<int,int>>> p(n);
    rep(i,n){
        cin>>p[i].first>>p[i].second.first;
        p[i].second.first*=-1;
        p[i].second.second=i;
    }
    vector<int> v(n);
    sort(p.begin(),p.end());
    rep(i,n){
        int x=p[i].second.second;
        v[i]=x+1;
    }
    rep(i,n)cout<<v[i]<<endl;
}

Measured memory_bytes: 256
from itertools import accumulate
n, k = map(int, input().split())
a = [0] + list(accumulate(map(int, input().split())))

btfl = []
for i in range(0, n):
    for j in range(i + 1, n + 1):
        btfl.append(a[j] - a[i])

# 解説AC
ans = 0
for i in range(50)[::-1]:
    num, cnt = ans + pow(2, i), 0
    for b in btfl:
        if num == num & b:
            cnt += 1
    if cnt >= k:
        ans = num
print(ans)


Measured memory_bytes: 107404
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <iostream>
#include <queue>

using namespace std;

typedef unsigned int u32;
typedef int i32;
typedef unsigned long long int u64;
typedef long long int i64; // 9e18
typedef uint16_t u16;
typedef int16_t i16;
typedef uint8_t u8;
typedef int8_t i8;

//const double PI = 3.141592653589793238463;
//const int MAXN = 1000500;
//const int MAXVALUE = 1000000500;
//const long double EPS = 1e-7;
const i64 INF = 1e18;
i64 mod = 1e9 + 7;


i64 T, n, m, k;
//vector <vector<i64>> a;
//vector <i64> a;
//vector <i64> b;
//vector <i64> dp;

i64 norm(i64 d, i64 MOD) {
    return ((d % MOD) + MOD) % MOD;
}

i64 add_m(i64 x, i64 y, i64 MOD) {
    return norm(norm(x, MOD) + norm(y, MOD), MOD);
}

i64 mul_m(i64 x, i64 y, i64 MOD) {
    return norm(norm(x, MOD) * norm(y, MOD), MOD);
}


int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.precision(16);


    //cin >> T;
    T = 1;

    for (i64 tt = 0; tt < T; ++tt) {

        cin >> n;
        vector<i64>a(n);
        for (i64 i = 0; i < n; ++i) {
            cin >> a[i];
        }

        i64 res = 0;
        i64 sum = 0;

        for (i64 i = n-1; i >= 1; --i) {
            sum = add_m(sum, a[i], mod);
            res = add_m(res, mul_m(sum, a[i - 1], mod), mod);
        }

        cout << res << endl;

    }
    return 0;
}

Measured memory_bytes: 4364
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
//using namespace __gnu_pbds;

#define ll long long int
#define endl "\n"
#define db(x) cout<<#x<<" ->"<<x<<endl
#define db2(x,y) cout<<#x<<"->"<<x<<", "<<#y<<" -> "<<y<<endl
#define db3(x,y,z) cout<<#x<<" -> "<<x<<" , "<<#y<<" -> "<<y<<" , "<<#z<<" -> "<<z<<endl
#define db4(w,x,y,z) cout<<#w <<" -> " << w << " , " << #x<<" -> "<<x<<" , "<<#y<<" -> "<<y<<" , "<<#z<<" -> "<<z<<endl
#define prt(x) for(auto it = x.begin(); it!=x.end(); it++) { cout<<*it<<" "; } cout<< endl
#define IN freopen("input.txt","r",stdin)
//typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const int N = (int)4e5+4;

int32_t main(){
    ios_base::sync_with_stdio(false); cin.tie(0);
//    IN;
    string str;
    cin >> str;
    for(int i = 0; i < str.size(); i++){
        if(str[i]=='7'){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}


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

#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for (int i = (n); i >= 0; i--)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

int main()
{
    string s;
    cin >> s;

    int cnt = 0;
    rep(i, s.size())
    {
        if (s[i] == 'p')
            cnt++;
    }
    OP(s.size() / 2 - cnt);
    return 0;
}

Measured memory_bytes: 512
def mod_inverse(n, mod=10**9+7):
    return pow(n, mod-2, mod)
    

mod = 10**9+7
N, K = map(int, input().split())
A = [0] + sorted(list(map(int, input().split())))
factorial = [1] * (N+1)
factorial_inv = [1] * (N+1)
for i in range(1, N+1):
    factorial[i] = factorial[i-1] * i % mod
    factorial_inv[i] = mod_inverse(factorial[i], mod)

ans = 0
for i in range(K, N+1):
    ans = (ans + factorial[i-1] * factorial_inv[i-K] * A[i]) % mod

for i in range(1, N-K+2):
    ans = (ans - factorial[N-i] * factorial_inv[N-K-i+1] * A[i]) % mod

ans = ans * factorial_inv[K-1] % mod
print(ans)


Measured memory_bytes: 15000