akhauriyash/Code-Regression huggingface dataset:
//AtCoder 
#include <bits/stdc++.h>
using namespace std;
using lli=int64_t;

struct Sousa {
    int mai=0;
    int C=0;
};

int main() {
    int N,M;
#if LOCAL&0
  	std::ifstream in("input.txt");
  	std::cin.rdbuf(in.rdbuf());
#endif
    cin>>N>>M;
    vector<int> atbl(N,0);
    for(int i=0;i<N;++i){
        cin>>atbl[i];
    }
    sort(atbl.begin(),atbl.end(),std::greater<int>());

    vector<Sousa> stbl(M);
    for(auto&& s:stbl){
        cin>>s.mai>>s.C;
    }
    //sousaをソート
    sort(stbl.begin(),stbl.end(),[](const Sousa& a,const Sousa& b){ return (a.C > b.C); });

    int pos=0;
    vector<int> chtbl(N,0);
    for(const auto& s:stbl){
        for(int i=0;i<s.mai;++i){
            if(pos>=N)break;
            chtbl[pos]=s.C;
            ++pos;
        }
        if(pos>=N)break;
    }
    sort(chtbl.begin(),chtbl.end());
    //いれていく
    for(int i=0;i<N;++i){
        if (chtbl[i] < atbl[i]){
            chtbl[i]=atbl[i];
        } else{
            break;
        }
    }

    lli ans=0;
    for(const auto& n:chtbl){
		ans += n;
	}
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>
int main(){
char ch;
int num,max;
int p[101]={0};
int q[2][10]={0};
while(scanf("%d",&num) != EOF)    
{         
	p[num] += 1;     
}   

max=0;
for(int i=0;i<101;i++){
if(max<p[i])max=p[i];
}
for(int i=0;i<101;i++){
if(max==p[i])printf("%d\n",i);
}

return 0;
}

Measured memory_bytes: 1028
#include <bits/stdc++.h>
using namespace std;
using P = pair<int,int>;

int main(){
  int n;
  cin >> n;
  priority_queue<P> que1, que2;
  for(int i=0; i<n; ++i){
    string s;
    cin >> s;
    int sz = s.size(), cnt=0, mincnt = 0;
    for(int j=0; j<sz; ++j){
      if(s[j] == '(') ++cnt;
      else{
        --cnt;
        mincnt = min(mincnt, cnt);
      }
    }
    if(cnt >= 0) que1.push(P(mincnt,cnt));
    else que2.push(P(mincnt-cnt, -cnt));
  }
  int t1 = 0;
  while(!que1.empty()){
    int x, y;
    tie(x,y) = que1.top();
    que1.pop();
    if(x+t1 <0){
      cout << "No" << endl;
      return 0;
    }
    t1 += y;
  }
  int t2 = 0;
  while(!que2.empty()){
    int x, y;
    tie(x,y) = que2.top();
    que2.pop();
    if(x+t2 <0){
      cout << "No" << endl;
      return 0;
    }
    t2 += y;
  }
  cout << (t1 == t2 ? "Yes":"No") << endl;
}

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

#define mp make_pair
#define pb push_back
#define fst first
#define snd second
#define int long long
#define fast_io() ios::sync_with_stdio(false)
#define FOR(i, l, r) for(int i = (l); i < (r); i++)
#define H(x) cout << #x << " " << x << endl;

typedef long long ll;
typedef pair<ll, ll> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef set<int> si;
typedef double ld;
typedef pair<ld, ld> dd;

const ll INF = 1000000000000000000LL;
const int NMAX = 1e6+4;
const int mod = 1e9+7;
const ld eps = 1e-10;
const ld PI = acos(-1);


signed main(){
    fast_io();
    string s;
    vi count(26, 0);
    int N;
    cin >> N;
    cin >> s;
    int res = 1;
    for(char c : s) count[c-'a'] ++;
    for(int cnt : count) res = (res * (cnt+1)) % mod;
    cout << (res + mod - 1) % mod << endl;
}


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

int counter[200001];
vector <int> adj[200001];
int query[200001];
bool visited[200001];

int dfs(int now,int val)
{
	counter[now] += val;
	for(auto next : adj[now])
	{
		if(visited[next]==false)
		{
			visited[next] = true;
			dfs(next,val + query[next]);
		}
	}
}

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

	int n,q,a,b;

	cin >> n >> q;

	for(int i=0;i<n-1;i++)
	{
		cin >> a >> b;
		adj[a].push_back(b);
		adj[b].push_back(a);
	}

	for(int i=0;i<q;i++)
	{
		cin >> a >> b;
		query[a]+=b;
	}

	visited[1] = true;
	dfs(1,query[1]);

	for(int i=1;i<=n;i++)
	{
		cout << counter[i] << ' ';
	}
	cout << '\n';

	return 0;
}

Measured memory_bytes: 21120
from collections import deque
from itertools import chain, combinations
import json




def main():
    a = "abcdefghijklmnopqrstuvwxyz"
    c=input()
    print(a[a.index(c)+1])

    # N = int(input())
    # A = [int(a) for a in input().split()]
    # B = [
    #     [int(a) for a in input().split()]
    #     for _ in range(N)
    # ]
    print()


if __name__ == "__main__":
    main()


Measured memory_bytes: 3824
use proconio::{input, fastout};
use proconio::marker::{Chars};
use proconio::marker::Usize1;
use std::cmp::*;
use std::char::*;
macro_rules! debug {
      ($($a:expr),*) => {
          eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

#[fastout]
fn main() {
    input!{
        a: Chars,
        b: Chars,
        c: Chars,
    }

    let A = from_u32(a[0] as u32 - 'a' as u32 + 'A' as u32).unwrap();
    let B = from_u32(b[0] as u32 - 'a' as u32 + 'A' as u32).unwrap();
    let C = from_u32(c[0] as u32 - 'a' as u32 + 'A' as u32).unwrap();
    println!("{}{}{}", A,B,C);
}


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

//Aがpi^qiと素因数分解できた時、map[pi]=qiのように格納する
map<int,int> div(int N){
	map<int,int> ans;
	int a=2;
	while(N>=a*a){
		if(N%a==0){
			ans[a]++;
			N/=a;
		}else{
			a++;
		}
	}
	ans[N]++;
	return ans;
}

vector<int> factor(int N){
	vector<int> ans;
	for(int i=2;i*i<=N;i++){
		if(N%i==0){
			ans.push_back(i);
			if(i*i!=N)ans.push_back(N/i);
		}
	}
	sort(ans.begin(),ans.end());
	return ans;
}


signed main(){
	int N; cin>>N;
	vector<int> fact=factor(N);
	map<int,int> fact2=div(N-1);
	int ans=0,tmp=1;
	for(auto p : fact2){
		tmp*=(p.second+1);
	}
	ans+=tmp;
	for(int i=0;i<fact.size();i++){
		tmp=N;
		int f=fact[i];
		while(tmp%f==0)tmp/=f;
		if(tmp%f==1)ans++;
	}
	if(N==2)ans=1;
	cout<<ans<<endl;
}

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

using namespace std;
long dp[101][100010];
int w[101],v[101];
int main(){
    int n,W;cin>>n>>W;
    for(int i = 1;i<=n;i++){
        cin>>w[i]>>v[i];
        for(int j = 0;j<=W;j++){
            //容量不够
            if(j < w[i]){
                dp[i][j] = dp[i-1][j];
                //容量足够
            }else{
                dp[i][j] = max(dp[i-1][j-w[i]] + v[i], dp[i-1][j]);
            }
        }
    }
    cout<<dp[n][W];
}


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

int main(){
    int n,a,b;cin >> n >> a >> b;
    string s; cin >> s;

    int total = a + b;
    for(int i = 0; i < n; ++i){
        if(s[i] == 'a'){
            if(total > 0){
                total--;
                cout << "Yes\n";
            }else{
                cout << "No\n";
            }
        }else if(s[i] == 'b'){
            if(total > 0){
                if(b > 0){
                    cout << "Yes\n";
                    b--;
                    total--;
                }else{
                    cout << "No\n";
                }
            }else{
                cout << "No\n";
            }
        }else{
            cout << "No\n";
        }
    }

    return EXIT_SUCCESS;
}


Measured memory_bytes: 896
#include<stdio.h>
#include<algorithm>
#include<string.h>
#define rep(i,j) for(int i=0;i<(j);i++)
#define reps(i,j,k) for(int i=j;i<=k;i++)

using namespace std;

int main(){
	int n,m,p,d[1000],t,cnt;
	for(;;){
		scanf("%d%d",&n,&m);
		if(n==0&&m==0)break;
		rep(i,n)scanf("%d",d+i);
		p=cnt=0;
		rep(i,m){
			scanf("%d",&t);
			if(n!=0){
				p=p+t;
				if(p<n)p+=d[p];
				if(p>=n)n=0;
				cnt++;
			}
		}
		printf("%d\n",cnt);
	}
	return 0;
}

Measured memory_bytes: 1032
// AOJ  0516: Maximum Sum
// 2017.8.30 bal4u@uu
// 2017.11.14

#include <stdio.h>

int a[100003], s[100003];

char buf[20], *p;
int getint()
{
	int n = 0;
	if (*p == '-') {
		p++; while (*p >= '0') n = (n<<3) + (n<<1) + (*p++ & 0xf);
		return -n;
	}
	while (*p >= '0') n = (n<<3) + (n<<1) + (*p++ & 0xf);
	return n;
}

int main()
{
	int n, k;
	int i, ans, f;

	while (fgets(p=buf, 20, stdin) && *p != '0') {
		n = getint(), p++, k = getint();

		fgets(p=buf, 10, stdin);
		s[0] = a[0] = getint();
		for (i = 1; i < n; i++) {
			fgets(p=buf, 10, stdin);
			a[i] = getint();
			s[i] = s[i-1] + a[i];
			if (i >= k) s[i] -= a[i-k];
		}
		for (f = 1, i = k-1; i < n; i++) {
			if (f) f = 0, ans = s[i];
			else if (s[i] > ans) ans = s[i];
		}
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 2480
from sys import stdin

def calc(a, op, b):
    if op == '+':
        return a+b

    if op == '-':
        return a-b

    if op == '*':
        return a*b

    if op == '/':
        return int(a/b)


for line in stdin:
    a, op, b = line.rstrip().split(' ')

    if op == '?':
        break

    print(calc(int(a), op, int(b)))

Measured memory_bytes: 7696
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;
inline ll in(){
    ll x=0;bool f=0; char c;
    for (;(c=getchar())<'0'||c>'9';f=c=='-');
    for (x=c-'0';(c=getchar())>='0'&&c<='9';x=(x<<3)+(x<<1)+c-'0');
    return f?-x:x;
}
ll n,a,b,c,d,mxp,mnp,mxn,mnn;
int main()
{
	n=in();a=in();b=in();c=in();d=in();
	for (int i=0;i<n;++i){
		mnp=c*i;mxp=d*i;
		mxn=-c*(n-1ll-i);mnn=-d*(n-1ll-i);
		if (mnp+mnn<=b-a&&mxp+mxn>=b-a) {printf("YES");return 0;}
	}printf("NO");return 0;
}

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

int main() {
    int L; cin >> L;
    int tmp = (1<<20), N = 20;
    while(tmp > L) tmp >>= 1, --N;

    cout << N + 1 << " " << N * 2 + __builtin_popcount(L) - 1 << endl;

    // when L = 8
    // 1 - 2 - 3 - 4
    // cost : 01 02 04
    // path 1 ~ 4 : 000 100 020 120 004 104 024 124 (length : 0 ~ 7)
    for(int i = 0; i < N; ++i) {
        cout << i + 1 << " " << i + 2 << " " << 0 << '\n';
        cout << i + 1 << " " << i + 2 << " " << (1<<i) << '\n';
    }
    // for now, it can make the graph when L = 2^k

    // think about when L is between 2^k and 2^(k+1)
    // L = ... 4 : ok, 5 : more 1 path costs 4, 6 : more 2 path cost 4 and 5, 7 : more 3 path cost 4 and 5 and 6, 8 : ok
    // 5 : 101, 6 : 110, 7 : 111


    int cost = (1<<N);
    for(int i = N - 1; i >= 0; --i) {
        if(L & (1<<i)) {
            cout << i + 1 << " " << N + 1 << " " << cost << '\n';
            cost += (1<<i);
        }
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {


		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long answer = 0;
		for(int i = 1; i <= n;i++) {
			if(i % 3 ==0) {
				continue;
			}
			if(i % 5 ==0) {
				continue;
			}
			answer += i;
		}
		System.out.println(answer);
	}
}

Measured memory_bytes: 35740
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }



string str;
int main ()
{
    cin >> str;
    bool ok = false;
    if (str[0] == '9') ok = true;
    if (str[1] == '9') ok = true;
    if (ok) puts("Yes");
    else puts("No");
}





























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

using namespace std;

int main() {
	long N, K, S;
	cin >> N >> K >> S;
	for (size_t i = 0; i < K; i++)
	{
		cout << S<<endl;
	}
	for (size_t i = K; i < N; i++)
	{
		if (S==1000000000)
		{
			cout <<1<<endl;
		}else cout << S+1<<endl;
	}
}

Measured memory_bytes: 1280
#include<stdio.h>

int main()
{
	int k, a, b, i;
	int count = 0;
	scanf("%d", &k);
	scanf("%d %d", &a, &b);
	
	for (i = a; i <= b; i++)
	{
		if (i % k == 0)
		{
			count++;
		}
	}
	
	if (count > 0)
	{
		printf("OK\n");
	}
	
	else
	{
		printf("NG\n");
	}
	
	return 0;
}

Measured memory_bytes: 1632
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll mod = 1e9 + 7;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0); 
	cout.tie(0);
	int a, b;
	cin >> a >> b;
	if((a * b) % 2 == 0){
		cout << "No";
	}else{
		cout << "Yes";
	}
}

Measured memory_bytes: 256
/*|In The Name Of Allah|*/

#include <bits/stdc++.h>

using namespace std;

const int N = 1e5+5;

int n;
int m;
int dist[N];
char str[N];
int parent[N];

int main(){
    cin >> n >> m;
    for(int i = 0; i <= n; i++){
        cin >> str[i];
    }
    int me = n;
    while(me != 0){
        int will = -1;
        for(int i = me-1; i >= me - m && i >= 0; i--){
            if(str[i] == '0'){
                will = i;
            }
        }
        if(will == -1){
            puts("-1");
            return 0;
        }
        dist[will] = me - will;
        parent[will] = me;
        me = will;
    }
    int j = 0;
    while(j != n){
        printf("%d " , dist[j]);
        j = parent[j];
    }
}


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

using namespace std;
typedef long long ll;

#define MOD (long long)(1e9+7)
#define INF (1LL<<60)
#define rep(i,n) for(ll i = 0; i < (n); i++)
#define rep1(i,n) for(ll i = 1; i <= (n); i++)

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


// 最大公約数
ll gcd(ll a, ll b)
{
  if(b == 0) return a;
  return gcd(b, a % b);
}

// mod m におけるa の逆元
ll modinv(ll a, ll m) {
  ll b = m, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    a -= t * b; swap(a, b);
    u -= t * v; swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}

// 素因数分解
vector<pair<ll, ll>> prim;
void pf(ll n)
{
  ll s = sqrt(n);
  ll r = 0;
  for(ll i = 2; i <= s; i++) {
    if((n % i) == 0) {
      r = 0;
      do {
	r++;
	n = n / i;
      } while((n % i) == 0);
      prim.push_back({i, r});
    }
  }
  if(n > s) {
    prim.push_back({n, 1});
  }
}

void solve()
{
  ll a,v,b,w,t; cin >> a >> v >> b >> w >> t;
  
  
  bool ok = false;
  if(w >= v) ok = false ;
  else {
    ll ab = abs(b - a);
    ll wv = abs(w - v);
    if( ab  <= t * wv) {
      ok = true;
    } else {
      ok = false;
    }
  }
  cout << (ok?"YES":"NO") << endl;
}


int main(void)
{
  // ll t; cin >> t; REP(i, t)
  solve();
}


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


void solve(std::string S, std::string T){
    cout << T << S << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools
int main(){
    std::string S;
    std::cin >> S;
    std::string T;
    std::cin >> T;
    solve(S, T);
    return 0;
}


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

def gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    else:
        return gcd(a % b, b)

L = [0]
for a in A:
    L.append(gcd(L[-1], a))

R = [0]
for a in reversed(A):
    R.append(gcd(R[-1], a))

print(max(gcd(L[i], R[N-1-i]) for i in range(N)))


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

#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<")"<< endl
#define BINARY(x) static_cast<bitset<16> >(x)

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)

#define in_range(x, y, w, h) (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;
const int INF = 1e9;
typedef pair<int, int> PII;
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};

int N, M;
vector<int> A;

ll solve(int n, bool prev, vector<bool> plus)
{
    if (n == M) {
#if 0
        cerr << A[0];
        for (int i=0; i<M; i++) {
            cerr << (plus[i] ? "+" : " ");
            cerr << A[i+1];
        }
#endif

        ll  tmp = A[0];
        ll sum = 0;
        rep(i, M) {
            if (plus[i]) {
                sum += tmp;
                tmp = A[i+1];
            } else {
                tmp *= 10;
                tmp += A[i+1];
            }
        }
        sum += tmp;

#if 0
        cerr << " = " << sum << endl;
#endif
        return sum;
    }

    ll res = solve(n+1, false, plus); 
    plus[n] = true;
    res += solve(n+1, true, plus);
    plus[n] = false;

    return res;
}

int main()
{
    string S;
    cin >> S;
    N = S.size(), M = N-1;
    for (auto c : S) A.push_back(c - '0');

    cout << solve(0, false, vector<bool>(M)) << endl;
}



Measured memory_bytes: 256
#include <stdio.h>
int main(){
  int N;scanf("%d",&N);
  int Min=987654321,cnt=0;
  for(int i=0;i<N;i++){
    int t;scanf("%d",&t);
    if(Min>t){
      cnt++;
      Min=t;
    }
  }
  printf("%d",cnt);
}

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

int main(){
	int D;
	cin >> D;
	if( D == 25){
	cout<< " Christmas" << endl;
	}
		
	if( D==24){
	cout<< "Christmas Eve" << endl;
			}
	if( D==23){
    cout<<"Christmas Eve Eve" << endl;
	}
	if (D ==22){
	cout<<"Christmas Eve Eve Eve"<< endl;
	}
}

Measured memory_bytes: 256
#include<iostream>
#include <iomanip>
#include <ios>
#include <vector>
#include <string>
#include <algorithm>
#include <string>
#include<limits>
#include<cstdlib>
#include<functional>
#include<cassert>
#include <cstdio>
#include <stack>
#include <queue>
#include <map>
//#include <bits/stdc++.h>//atcoderでsqrtを使うときに必要
#define fi(p) for(int i=0;i<(p);i++)
#define ce(d) cout<<d<<endl;
#define ll long long
#define sorts(c) sort((c).begin(),(c).end());

using namespace std;

string f(ll n) {
	if (n == 0)return "";
	n--;
	return f(n / 26) + string(1,'a' + n % 26);
}


void solve() {
	ll n;
	cin >> n;

	ce(f(n));
	
}

int main()
{
	solve();

	int a;//止める用
	cin >> a;
	return 0;
}

Measured memory_bytes: 3128
#include <algorithm>
#include <vector>
#include <cfloat>
#include <string>
#include <cmath>
#include <set>
#include <cstdlib>
#include <map>
#include <ctime>
#include <iomanip>
#include <functional>
#include <deque>
#include <iostream>
#include <cstring>
#include <queue>
#include <cstdio>
#include <stack>
#include <climits>
#include <sys/time.h>
#include <cctype>

using namespace std;

typedef long long ll;

int main(){
  int n;
  while(true) {
    cin >> n;
    if (n == 0) break;
    vector <pair<int, int> > tc;
    for (int i = 0; i < n; i++) {
      int x, y;
      cin >> x >> y;
      bool flag = false;
      for (int j = 0; j < tc.size(); j++) {
	if (tc[j].first == x) {
	  flag = true;
	  tc[j].second = max(tc[j].second, y);
	  break;
	}
      }
      if (!flag) tc.push_back(make_pair(x, y));
    }
    n = tc.size();
    sort(tc.begin(), tc.end());
    reverse(tc.begin(), tc.end());
    vector <int > leftTime[n];
    for (int i = 0; i < n; i++) leftTime[i].push_back(0);
    bool left = true;

    int total = 0;
    for (int i = 0; i < n; i++) {
      int t = tc[i].first, c = tc[i].second;
      int time = 0;
      for (int j = 0; j < 2*c; j++) {
	int bs = time;
	int bg = time+t;
	for (int k = 0; k < i; k++) {
	  for (int l = j%2; l < leftTime[k].size(); l+=2) {
	    if (l+1 >= leftTime[k].size()) break;
	    int as = leftTime[k][l];
	    int ag = leftTime[k][l+1];

	    if (bs > as && bg < ag) {
	      bg = max(ag, bg);
	    }
	  }
	}
	total = max(total, bg);
	leftTime[i].push_back(bg);
	time = bg;
      }      
    }
    cout << total << endl;
  }
}

Measured memory_bytes: 1324
#include <bits/stdc++.h>
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define re(n) for (int i = 0; i < (n); ++i)
#define rej(n) for (int j = 0; j < (n); ++j)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector <int> vi;
typedef pair <int, int> pii;
typedef vector <pair <int, int>> vii;

const ld PI = acos((ld)-1);

int main() {
    #ifndef LOCALDEBUG
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    #endif  // LOCALDEBUG
    int n;
    cin >> n;
    ld ppb = 0;
    for (int i = 1; i <= n; ++i) {
        if (i % 2 == 1)
            ppb += 1;
    }
    cout << setprecision(15) << fixed << ppb / n;
    return 0;
}


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

flg = 0

for a in A:
	if a % 2 == 0:
		if a % 3 != 0 and a % 5 != 0:
			flg = 1
			break
			
if flg:
	print("DENIED")
else:
	print("APPROVED")

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

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

    int n, input;
    vector<int> vi1, vi2;

    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> input;
        vi1.push_back(input);
        vi2.push_back(input);
    }

    sort(vi2.begin(), vi2.end());

    int count = 0;
    for (int i = 0; i < n; i++) {
        if (vi1[i] != vi2[i])
            count++;

        if (count > 2) {
            cout << "NO" << endl;
            return 0;
        }
    }

    if (count == 2 || count == 0)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		String t = sc.nextLine();
		int a = sc.nextInt();
		int b = sc.nextInt();
		sc.nextLine();
		String u = sc.nextLine();
		int ansS = a;
		int ansT = b;
		if (s.equals(u)) {
			ansS = a - 1;
		} else {
			ansT = b - 1;
		}
		System.out.println(ansS + " " + ansT);
		sc.close();
	}
}


Measured memory_bytes: 38896
s=input()
cnt_c=0
for i in s:
    if i=='C':
        cnt_c+=1
c_present=False
n=len(s)
for i in range(2,n-1):
    if s[i]=='C':
        c_present=True
flag=True
for i in s:
    if i!='A' and i!='C':
        if i.isupper():
            flag=False
if s[0]=='A' and cnt_c==1 and c_present and  flag:
    print('AC')
else:
    print('WA')


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) {if(a<b) {a=b;return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) {if(a>b) {a=b;return 1;} return 0;}
const ll MOD = 1000000007LL;
const ll INF = 1LL<<60;

int main() {
    int N, M;
    cin >> N >> M;
    vector<ll> S(N), T(M);
    for ( int i = 0; i < N; i++ ) {
        cin >> S[i];
    }
    for ( int i = 0; i < M; i++ ) {
        cin >> T[i];
    }

    vector<vector<ll>> dp(N+1, vector<ll>(M+1,0)), dps(N+1, vector<ll>(M+1,0)),dpr(N+1, vector<ll>(M+1,0));
    dp[0][0] = 1;
    for ( int i = 0; i <= N; i++ ) {
        for ( int j = 0; j <= M; j++ ) {
            if ( i > 0 && j > 0 && S[i-1] == T[j-1] ) {
                dp[i][j] += dps[i-1][j-1];
            }
            if ( j > 0 ) dpr[i][j] += dpr[i][j-1];
            dpr[i][j] += dp[i][j];
            if ( i > 0 ) dps[i][j] += dps[i-1][j];
            dps[i][j] += dpr[i][j];
            dp[i][j] %= MOD;
            dps[i][j] %= MOD;
            dpr[i][j] %= MOD;
        }
    }
    ll ans = dps[N][M];
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 94336
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include<bits/stdc++.h>
using namespace std;
#define rep(i,s,t) for(ll i = (ll)(s); i < (ll)(t); i++)
#define rrep(i,s,t) for(ll i = (ll)(s-1);(ll)(t) <= i; i--)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
constexpr ll INF = numeric_limits<ll>::max()/4;
constexpr ll n_max = 2e5+10;
#define int ll

template <typename A, typename B>
string to_string(pair<A, B> p);
string to_string(const string &s) {return '"' + s + '"';}
string to_string(const char *c) {return to_string((string) c);}
string to_string(bool b) {return (b ? "true" : "false");}
template <size_t N>
string to_string(bitset<N> v){
    string res = "";
    for(size_t i = 0; i < N; i++) res += static_cast<char>('0' + v[i]);
    return res;
}
template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for(const auto &x : v) {
        if(!first) res += ", ";
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p){return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}

void debug_out() {cerr << endl;}
template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

template<class T>
bool chmax(T &a, T b){if(a < b){a = b; return true;} return false;}
template<class T>
bool chmin(T &a, T b){if(a > b){a = b; return true;} return false;}
void YES(bool ok){
    cout << (ok ? "Yes" : "No") << endl;
}
signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    vector<ll> a(3);
    for(int i = 0; i < 3; i++) cin >> a[i];
    ll k; cin >> k;
    ll cnt = 0;
    while(a[1] <= a[0]){
        a[1] *= 2;
        cnt++;
    }
    while(a[2] <= a[1]){
        a[2] *= 2;
        cnt++;
    }

    YES(cnt <= k);
}

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

int main(void){
  string S, T;
  int A, B;
  string U;
  cin >> S >> T;
  cin >> A >> B;
  cin >> U;
  if(S == U)
    A--;
  else if(T == U)
    B--;
  cout << A << " " << B << "\n";
  return 0;
} 


Measured memory_bytes: 3644
#include<bits/stdc++.h>
#define cl(x, y) memset(x, y, sizeof(x))
using namespace std;
const int maxn = 100000 + 5;
typedef long long ll;
ll MAD = 1000000000 + 7;

ll foi[maxn];

void setin() {
	foi[0] = 1;
	for(ll i = 1; i<maxn; i++) {
		foi[i] = (foi[i-1]*i) % MAD;
	}
}

int main() {
	setin();
	int n, m;
	cin >> n >> m;
	
	if(fabs(n-m) >= 2) printf("0\n");
	
	else if(n==m) {
		printf("%lld\n", (2*((foi[n]*foi[m])%MAD))%MAD);
	} else {
		printf("%lld\n", (foi[n]*foi[m])%MAD);
	}
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) find(rng(v),x)!=v.end()
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
typedef vector<pii> vp;
typedef vector<tiii> vt;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
inline int in() { int x; scanf("%d",&x); return x;}
//cout << fixed << setprecision(10);
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main () {
  int n = in();

  auto s = [&](int x) {
    int res = 0;
    while (x != 0) {
      res += x%10;
      x /= 10;
    }
    return res;
  };

  if (n%s(n) == 0) yn;
  return 0;
}

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

using namespace std;
#define int long long
int32_t main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n,m,v,p;
    cin>>n>>m>>v>>p;
    int a[n];
    for(int i=0;i<n;++i)
    {
        cin>>a[i];
    }
    sort(a,a+n);
    int low=(-1);
    int up=n;
    while((up-low)!=1)
    {
        int k=(low+up)/2;
        int x=a[k];
        if(k>=(n-p))
        {
            up=k;
            continue;
        }
        x+=m;
        if(x<a[n-p])
        {
            low=k;
            continue;
        }
        if(v<=p)
        {
            up=k;
            continue;
        }
        int sum=0;
        for(int i=0;i<(n-p+1);++i)
        {
            sum+=min(max(0LL,x-a[i]),m);
        }
        sum+=(p-1)*m;
        if(sum>=(v*m))
        {
            up=k;
        }
        else
        {
            low=k;
        }
    }
    cout<<(n-up);
    return 0;
}


Measured memory_bytes: 1024
n, h = (int(s) for s in input().split())

a = []
b = []

for i in range(n):
    a_i, b_i = (int(s) for s in input().split())
    a.append(a_i)
    b.append(b_i)

a_max = max(a)
b.sort(reverse=True)

for i, b_i in enumerate(b):
    if b_i > a_max:
        h -= b_i
        if h <= 0:
            print(i + 1)
            break
    else:
        print(i + (h - 1) // a_max + 1)
        break
else:
    print(len(b) + (h - 1) // a_max + 1)


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

int main()
{
    bool f[10001];
    f[0] = f[1] = false;
    for (int i=2; i<=10000; i++)
        f[i] = true;
    for (int i=2; i<=10000; i++)
        if (f[i])
            for (int j=i+i; j<=10000; j+=i)
                f[j] = false;
    vector<int> P;
    for (int i=0; i<=10000; i++)
        if (f[i])
            P.push_back(i);

    int n;
    cin>>n;
    int ans = 0;
    for (int i=0; i<n; i++)
    {
        int x;
        cin>>x;
        bool a = true;
        for (int p: P)
        {
            if (p>=x)
                break;
            if (x%p==0)
                a = false;
        }
        if (a)
            ans++;
    }
    cout<<ans<<endl;
}



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

int main(){
    int n;
    cin >> n;
    set<string> user;
    for(int i=0;i<n;++i){
        string u;
        cin >> u;
        user.insert(u);
    }
    int m;
    cin >> m;
    bool door = false;
    for(int i=0;i<m;++i){
        string t;
        cin >> t;
        if(user.count(t)){
            cout << (door ? "Closed by " : "Opened by ") << t << endl;
            door = !door;
        }else{
            cout << "Unknown " << t << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 3240
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>

#include <set>
#include <map>
#include <iomanip>

using namespace std;

#define rep(i, n) for(long long i = 0; i < (long long)(n); i++)
#define all(x) (x).begin(),(x).end()
#define ll long long

ll A, B, C, D;
ll cnt(ll sub)
{
	return (B / sub) - ((A - 1) / sub);
}

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

ll lcm(ll x, ll y)
{
	return (x * y) / gcd(x, y);
}

int main()
{
	cin >> A >> B >> C >> D;

	cout << (B - A + 1) - (cnt(C) + cnt(D) - cnt(lcm(C, D))) << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{

    int n,m;
    int[][] e;

    void solve(){
        Scanner sc = new Scanner(System.in);

        while(true){
            n = sc.nextInt();
            m = sc.nextInt();
            if(n==0 && m==0) break;

            //a, b, w
            e = new int[m][3];
            for(int i=0; i<m; i++){
                int a = sc.nextInt(), b = sc.nextInt();
                int w = sc.nextInt();
                e[i] = new int[]{a-1,b-1,w};
            }

            Arrays.sort(e, new Comparator<int[]>(){
                    public int compare(int[] a, int[] b){
                        return a[2] - b[2];
                    }
                });
            int ans = Integer.MAX_VALUE;
            for(int i=0; i<m && m-i>=n-1; i++){
                ans = Math.min(ans, kruskal(i));
            }

            if(ans==Integer.MAX_VALUE) ans = -1;
            System.out.println(ans);
        }
    }

    int kruskal(int idx){
        init();

        int res = 0, cnt = 0;
        for(int i=idx;i<m; i++){
            if(find(e[i][0])!=find(e[i][1])){
                unite(e[i][0],e[i][1]);
                res = e[i][2];
                cnt++;
            }
        }

        if(cnt==n-1) return res-e[idx][2];
        else return Integer.MAX_VALUE;
    }

    int[] par, rank;
    void init(){
        par = new int[n];
        rank = new int[n];
        for(int i=0; i<n; i++){
            par[i] = i;
            rank[i] = 0;
        }
    }
    int find(int x){
        if(par[x]==x) return x;
        else return par[x] = find(par[x]);
    }
    void unite(int x, int y){
        x = find(x);
        y = find(y);
        if(rank[x]<rank[y]) par[x] = y;
        else{
            par[y] = x;
            if(rank[x]==rank[y]) rank[x]++;
        }
    }

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

Measured memory_bytes: 13000
n = int(input())
def divisor(n):
    ret = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            ret.append(i)
            if i*i != n:
                ret.append(n//i)
    return ret

a = set(divisor(n-1))

for k in divisor(n):
    if k < 2:
        continue
    if k in a:
        continue
    m = n
    while m%k == 0:
        m //= k
    s = m%k
    if s == 1:
        a.add(k)

print(len(a)-1)



Measured memory_bytes: 39280
const fs = require('fs')
const reader = (s: string) => (s.split("\n"))
 
function Main(input: string) {

  const [aaa,bbb] = reader(input);
  const D = bbb.split(' ');
  const [N,K] = aaa.split(' ').map(a => (parseInt(a)));
  for(let i= N; i < 100000 ; i++)
  {
    if(D.every( d =>(!(i.toString().includes(d)))))
    {
      console.log(i);
      break;
    }
  }

}
 
Main(fs.readFileSync('/dev/stdin', 'utf8'))

Measured memory_bytes: 13208
n = int(input())
A = [int(x) for x in input().split()]

for i in range(n):
    v = A[i]
    j = i-1

    for j in range(i-1,-1,-1):
        if (A[j] > v):
            A[j+1] = A[j]
            A[j] = v

        else :
            break

    for k in range(n-1):
        print(str(A[k])+" ",end = "")
    print(str(A[n-1]))



Measured memory_bytes: 5984
#include <bits/stdc++.h>
using namespace std;
int main(){
	string s; cin >> s;
	if(s[0] == s.back()){
		if(s.size()&1) cout << "Second" << endl;
		else cout << "First" << endl;
	} else {
		if(s.size()%2 == 0) cout << "Second" << endl;
		else cout << "First" << endl;
	}
	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll e[1005][1005];
ll d[1005][1005];
ll n,m;
ll a[1005],b[1005],c;
ll ans;
int main(void){
	cin>>n>>m;
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      d[i][j]=1000000000;
    }
  }
	for(int i=0;i<m;i++){
		cin>>a[i]>>b[i]>>c;
		e[a[i]-1][b[i]-1]=c; e[b[i]-1][a[i]-1]=c;
		d[a[i]-1][b[i]-1]=c; d[b[i]-1][a[i]-1]=c;
	}
	for(int k=0;k<n;k++){
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
			}
		}
	}
	for(int i=0;i<m;i++){
		if(d[a[i]-1][b[i]-1]<e[a[i]-1][b[i]-1]){
			ans++;
		}
	}
	cout<<ans<<endl;
	
}


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

int main(){
	int N; cin>>N;
	vector<int> A(N); rep(i, N) cin>>A[i];
	sort(A.begin(), A.end());
	int n = A[N-1], r = 0;
	int mindiff = INT_MAX;
	rep(i, N-1){
		int diff = abs((n+2-1)/2 - A[i]);// |⌈n/2⌉ - ai|
		// if(mindiff > diff){ mindiff = diff; r = A[i]; }
		if(mindiff >= diff){ mindiff = diff; r = A[i]; }

		// int diff = abs(n/2 - A[i]); // |⌊n/2⌋ - ai|
		// if(mindiff >= diff){ mindiff = diff; r = A[i]; }
	}
	cout<< n <<" "<< r <<endl;
}


Measured memory_bytes: 640
N = int(input())
a = [int(input()) - 1 for _ in range(N)]

light = 0
visited = [False] * N
count = 0
while True:
    if light == 1:
        break

    if visited[light]:
        print(-1)
        exit(0)

    visited[light] = True
    light = a[light]
    count += 1

print(count)


Measured memory_bytes: 80944
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <cctype>
#include <string>
#include <map>
#include <set>
#include <math.h>
#include <cmath>
#define ll long long
#define lli long long int

using namespace std;
using P = pair<int,int>;

// 順列を生成する
// Pとマッチするカウントを保存する
// Qとマッチするカウントを保存する
// 答えを出す

int main(){

  int N;
  cin >> N;
  int ans = 0;
  vector<int> P(N);
  vector<int> Q(N);
  vector<int> v(N);

  for (int i = 0; i < N; i++) {
    v.at(i) = i+1;
  }

  for (int i = 0; i < N; i++) {
    cin >> P.at(i);
  }
  for (int i = 0; i < N; i++) {
    cin >> Q.at(i);
  }

  int cnt = 0, p = 0, q = 0;

  do {
    bool pt = true, qt = true;

    cnt++;
    // cout << cnt << endl;

    for (int i = 0; i < N; i++) {
      // cout << v.at(i) << " " << P.at(i) << endl;
      // cout << v.at(i) << " " << Q.at(i) << endl;

      if(v.at(i) != P.at(i)) pt = false;
      if(v.at(i) != Q.at(i)) qt = false;
    }

    // cout << "pt "<< pt << endl;
    // cout << "qt "<< qt << endl;

    if(pt == true) p = cnt;
    if(qt == true) q = cnt;
    // cout << p << endl;
    // cout << q << endl;

  } while (next_permutation(v.begin(), v.end()));

  cout << abs(p-q) << endl;

  return 0;
}

Measured memory_bytes: 3588
a, b = input().split()
x, y = a*int(b), b*int(a)
L = len(y) if len(x) >= len(y) else len(x)
for l in range(L):
    if int(x[l]) > int(y[l]):
        print(y)
        break
    elif int(x[l]) < int(y[l]):
        print(x)
        break
else:
    if len(x) >= len(y):
        print(y)
    else:
        print(x)

Measured memory_bytes: 3064
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <string>
#include <deque>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <assert.h>
#include <sstream>
typedef long long ll;
#define vi vector<int>
using namespace std;

int dX[4] = { 0, 0, -1, 1 };
int dY[4] = { -1, 1, 0, 0 };

int N, K;
const int MOD = 998244353;
int L[100], R[100];
ll bit[400000];

void update(int N, int idx, ll inc) {
	idx++;
	while (idx <= N) {
		bit[idx] = (bit[idx] + inc) % MOD;
		idx += idx & (-idx);
	}
}

ll query(int idx) {
	idx++;
	ll ans = 0;
	while (idx > 0) {
		ans = (ans + bit[idx]) % MOD;
		idx -= idx & (-idx);
	}
	return ans;
}

int main() {
	cin >> N >> K;
	for (int k = 0; k < K; k++) {
		cin >> L[k] >> R[k];
	}
	for (int i = 0; i < N + 10; i++) {
		bit[i] = 0;
	}
	update(N, N - 1, 1);
	for (int i = N - 2; i >= 0; i--) {
		ll value = 0;
		for (int k = 0; k < K; k++) {
			int l = i + L[k];
			int r = min(N - 1, i + R[k]);
			if (l >= N) continue;
			value = (value + MOD + query(r) - query(l - 1)) % MOD;
		}
		update(N, i, value);
	}
	cout << query(0) % MOD << '\n';
}

Measured memory_bytes: 5196
#include<stdio.h>
#include<stdlib.h>

int main()
{
  int n;
  int minj;
  int count = 0;
  int tmp;
  int i,j;
  int flug = 0;
  
  scanf("%d",&n);

  if(n < 1 || 100 < n)
    exit(0);

  int a[n];

  for(i = 0; i<n; i++){
    scanf("%d",&a[i]);
    if(a[i] < 0 || 100 < a[i]){
      exit(1);
    }
  }

  for(i=0; i<n; i++){
    minj = i;
    for(j = i; j < n; j++){
      if(a[j] < a[minj]){
	minj = j;
	flug = 1;
      }
    }
    if(flug == 1)
      count++;
    tmp = a[i];
    a[i] = a[minj];
    a[minj] = tmp;
    flug = 0;
  }

  for(i=0; i<n-1; i++){
    printf("%d ",a[i]);
  }
  printf("%d\n%d\n",a[i],count);
}



Measured memory_bytes: 2756
#include <stdio.h>
int main(){

	int a = 0;
	int W,H,x,y,r = 0;

	scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);

	if (0 <= x - r && x + r <= W){
		if (0 <= y - r && y + r <= H){
		a = 1;
		}
	}
	else {
		a = 0;
	}

	if (a == 1){
		printf("Yes\n");
	}
	else if (a == 0){
		printf("No\n");
	}

	return 0;
}

Measured memory_bytes: 584
#include <bits/stdc++.h>
using namespace std;
#define Hello ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'
#define ll long long
int main(){
    Hello
    string s;
    cin >> s;
    map<char, int> mp;
    for(int i = 0; i < s.size(); i++)
        mp[s[i]]++;
    if(mp.size() != 2)
        cout << "No";
    else {
        bool ok = true;
        for(auto i : mp)
            if(i.second != 2)
                ok = false;
        if(ok)
            cout << "Yes";
        else
            cout << "No";
    }
    return 0;
}


Measured memory_bytes: 3620
from math import sqrt
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines


def prime_enumeration(n):
    div = 0
    for i in range(1, int(sqrt(n))+1):
        if n % i == 0:
            div += 1
            if n // i != i:
                div += 1

    return div == 8


def main():
    N = int(readline())

    ans = 0
    for i in range(1,N+1,2):
        if prime_enumeration(i):
            ans += 1
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
let () = Scanf.scanf "%d\n" @@ fun n ->
    Array.init n (fun _ -> Scanf.scanf "%f %s\n" (fun x u ->
        if u = "BTC"
        then x *. 380000.0
        else x))
    |> Array.fold_left (+.) 0.0
    |> Printf.printf "%f"


Measured memory_bytes: 384
using System;

namespace b
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine();
            var t = Console.ReadLine();

            var f = false;
            for(var i = 0; i < t.Length; i++){
                s = s[s.Length - 1].ToString() + s.Substring(0, s.Length - 1);
                if(t.Equals(s)){
                    f = true;
                    break;
                }
            }

            Console.WriteLine(f ? "Yes" : "No");
        }
    }
}


Measured memory_bytes: 11348
from math import floor
a, b, n = map(int, input().split())
if b == 1:
    print(0)
    
else:
    if n < b:
        print((a * n) // b - a * (n //b))
        
    else:
        ans = 0
        for i in range(b - 1, n + 1, b):
            ans = max(ans, (a * i) // b - a * (i //b))
                
        print(ans)

Measured memory_bytes: 62080
#include <bits/stdc++.h>
using namespace std;
const int N=1000010;
map<pair<int,int>,int>mp;

struct lmao{int to;int next;int w;};

int head[N*8],tol,dd,num[N*8],vis[N*8],dis[N*8],n,m,que[N],s,t;
lmao q[N*8];
int spfa()
{
    s=0,t=1;
    for(int i=1;i<=dd+1;i++) dis[i]=23333333,vis[i]=0,num[i]=0;
    dis[1]=0;vis[1]=num[1]=1;que[s]=1;
    while(s<t)
    {
        int u=que[s++];vis[u]=0;
        for(int v=head[u];v!=-1;v=q[v].next)
        {
            int i=q[v].to;
            if(dis[i]>q[v].w+dis[u])
            {
                dis[i]=q[v].w+dis[u];
                if(!vis[i])
                {
                    num[i]++;
                    if(num[i]>=dd) return -2;
                    vis[i]=1,que[t++]=i;
                }
            }
        }
    }
    if(dis[n]!=23333333) return dis[n];
	else return -2;
}
int getid(int r,int rr)
{
    if(mp.find({r,rr})!=mp.end())
        return mp[{r,rr}];
    return mp[{r,rr}]=++dd;
}
void init()
{
    dd=n;
    tol=0;
    memset(head,-1,sizeof(head));
}
void add(int a,int b,int c)
{
    q[tol].w=c;
    q[tol].to=b;
    q[tol].next=head[a];
    head[a]=tol++;
}
int main()
{
    scanf("%d%d",&n,&m);
    init();
    for(int i=0;i<m;i++)
    {
        int x,y,c;
        scanf("%d%d%d",&x,&y,&c);
        int xx=getid(x,c);
        int yy=getid(y,c);
    add(xx,yy,0);
    add(yy,xx,0);
    add(x,xx,1);
    add(xx,x,1);
    add(y,yy,1);
    add(yy,y,1);
    }
    printf("%d\n",spfa()/2);
    return 0;
}

Measured memory_bytes: 88192
#[allow(unused_imports)]
use proconio::{fastout, input};

#[fastout]
fn main() {
    input!(w: f64, h: f64, x: f64, y: f64);

    print!("{}", w as f64 * h as f64 / 2f64);
    println!(" {}", if w / 2f64 == x && h / 2f64 == y { 1 } else { 0 });
}


Measured memory_bytes: 2120
/*
	written by Pankaj Kumar.
	country:-INDIA
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll ;
typedef set<pair<int,int>> spi;
typedef set<pair<ll,ll>> spl;
typedef vector<pair<int,int>> vpi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pair<ll,ll>> vpl;
typedef vector<string> vs;
typedef map<int,int>m;
typedef set<string> ss;
typedef set<int> si;
typedef set<ll> sl;
#define pan cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);
// define values.
#define mod 1000000007;
#define phi 1.618
/* Bit-Stuff */
#define get_set_bits(a) (__builtin_popcount(a))
#define get_set_bitsll(a) ( __builtin_popcountll(a))
#define get_trail_zero(a) (__builtin_ctz(a))
#define get_lead_zero(a) (__builtin_clz(a))
#define get_parity(a) (__builtin_parity(a))
/*  Abbrevations  */
#define ff first
#define ss second
#define mp make_pair
#define line cout<<endl;
#define pb push_back
// function
ll power(ll x,ll y)
{
	ll res=1;
	while(y>0)
	{
		if(y%2==1)res*=x;
		y/=2; x*=x;
	}
	return res;
}
/* ascii value 
A=65,Z=90,a=97,z=122
*/
/*  ---------------------------------MAIN-------------------------------------------*/


int main()
{
	pan;
	string s;
	cin>>s;
	if(s=="ABC")
		cout<<"ARC"<<endl;
	else
		cout<<"ABC"<<endl;	
}

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

using namespace std;
using ll = long long int;
using P = pair<int, int>;

#define loop(i, n) for(int i = 0;i < n;i++)
#define IINF 2e9
#define MOD 1e9+7

int main(void){

    ll n, a, b;
    cin >> n >> a >> b;

    if((b-a)%2 == 0){
        cout << (b-a)/2 << endl;
    }else{
        cout << min(a-1, n-b)+1+(b-a-1)/2 << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
	int x,y,n,temp;
	scanf("%d %d",&x,&y);
	if( x > y){temp=x;x=y;y=temp;}
	for(n=y%x;n>=1;n--){
		if(x%n==0 && y%n==0){break;}
	}
	if(n==0){n=x;}
	printf("%d\n",n);
	return 0;
}

Measured memory_bytes: 592
#include"bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
const long long mod = 1000000007;

int modpow(int a, int x) {
	int res = 1;
	while (x) {
		if (x&1)res = res*a%mod;
		a = a*a%mod;
		x >>= 1;
	}
	return res;
}

signed main() {
	int r, g, b, n; cin >> r >> g >> b >> n;
	int sum = 0;

	for (int i = 0; i*r <= n; i++) {
		for (int j = 0; i*r + j*b <= n; j++) {
			int k = n - i*r - j*b;
			if (k%g == 0)sum++;
		}
	}
	cout << sum << endl;
}


Measured memory_bytes: 256