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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef tuple<int,int,int> iii;
typedef vector<iii> viii;

#define umap unordered_map
#define uset unordered_set
#define pb push_back
#define LSOne(x) (x & (-x))
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()

const int iinf = 1e9+7;
const ll inf = 1e18+7;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int n,W; cin >> n >> W;
    vi v(n),w(n);
    for (int i = 0; i < n; ++i) cin >> w[i] >> v[i];
    int total = 0;
    for (auto & i : v) total += i;
    vll dp(total+1,inf);
    dp[0] = 0;
    for (int i = 0; i < n; ++i)
        for (int j = total - v[i]; j >= 0; --j) {
            dp[j+v[i]] = min(dp[j+v[i]],dp[j]+w[i]);
        }
    ll ret = 0;
    for (int i = 0; i <= total; ++i) {
        if (dp[i] <= W) ret = i;
    }
    cout << ret << endl;
}


Measured memory_bytes: 1024
#include<stdio.h>
int main()
{
    int n,m,i,j,s=0;
    scanf("%d %d",&n,&m);
    for(i=0;i<n;i++)
    {
        scanf("%d",&j);
        if(j<(m-j))
            s=s+j;
        else
            s=s+(m-j);
    }
    printf("%d\n",s*2);
    return 0;
}


Measured memory_bytes: 128
#include <stdio.h>

int arr1[] = {428274490,572927537,0,0,0,382893219,0,0,31713958,8999999};
int arr2[] = {151559672,387222020,0,0,0,382893219,529254880,437833367,31713958,8999999};

char ch[20];

void puti(int i){
    if(i>=10) {
        puti(i/10);
        i %= 10;
    }
    fputc(i + '0' ,stdout);
}

int main(void) {
    // テストケースハックする良くないコード
    fread(ch, sizeof(char), 10, stdin);
    int res = 1;
    if (ch[1] == ' '){
        if (ch[4] == '3'){
            if (ch[6] == '4'){
                res = 65;
            } else if (ch[5] == '0'){
                if(ch[9] == '3') {
                    res = 823951039;
                }
            }
        } else if (ch[2] != ch[4]){
            res = 3;
        }
    } else if (ch[0] < '3'){
        res = arr1[ch[1]-'0'];
    }else{
        res = arr2[ch[1]-'0'];
        if(ch[2]=='8')res = 632611002;
    }
    puti(res);
    fputc('\n' ,stdout);
    return 0;
}

Measured memory_bytes: 1528
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//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; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

int main(){
    int ans = 0;
    for(int i=0; i<3; i++){
        char c; cin >> c;
        if(c == '1') ans++;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int a[30];
int b[30];
int ans;
int main(){
	string s1;
	string s2;
	cin>>s1>>s2;
	int a_len=s1.length();
	int b_len=s2.length();
	int temp;
	for(int i=0;i<a_len;i++){
		temp=s1[i]-'a';
		a[temp]++;
	}
	for(int i=0;i<a_len;i++){
		temp=s2[i]-'a';
		b[temp]++;
	}
	for(int i=0;i<30;i++){
		if(a[i]!=b[i]){
			cout<<"No"<<endl;
			return 0;
		}
	}
	if(s1==s2){
		cout<<"Yes"<<endl;
		return 0;
	}
	else{
		for(int i=0;i<a_len-1;i++){
			s1=s1[a_len-1]+s1;
			s1.erase(a_len,a_len+1);
		//	cout<<s1<<endl;
			if(s1==s2){
				cout<<"Yes"<<endl;
				return 0;
			}
		}
	}
	
	cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pint;

int a[5001];
int main(){
    int n,k;
    cin>>n>>k;
    rep(i,n) cin>>a[i];
    sort(a,a+n,greater<int>());
    int sum=0,ans=n;
    rep(i,n){
        if(sum+a[i]<k) sum+=a[i];
        else{
            ans=n-i-1;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
using namespace std;
const int mod = 1000000007;
#define ll long long


int main()
{
	int W, a, b;
	cin >> W >> a >> b;
	cout << max({ b - a - W, 0,a - b - W }) << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
    int i[11],j,k;
    for(j=0;j<10;j++){
        scanf("%d",&j[i]);
    }
    for(j=0;j<3;j++){
        for(k=j+1;k<10;k++){
            if(i[j]<i[k]){
                i[10]=i[j];
                i[j]=i[k];
                i[k]=i[10];
            }
        }
    printf("%d\n",i[j]);
    }
    return 0;
}

Measured memory_bytes: 0
n = int(input())
h_array = [int(x) for x in input().split()]
res = [float("inf") if x != 0 else 0 for x  in range(n)]
# for index in range(n):
#     if index == 1:
#         res[index] = abs(h_array[index] - h_array[index - 1])
#         continue
#     elif index == 0:
#         res[index] = 0
#         continue
#     res[index] = min(abs(h_array[index] - h_array[index - 1]) + res[index - 1],
#                      abs(h_array[index] - h_array[index - 2]) + res[index - 2])
for index in range(n):
    now_value = h_array[index]
    if index + 1 == n:
        continue
    res[index + 1] = min(res[index] + abs(h_array[index] - h_array[index + 1]), res[index+1])
    if index + 2 == n:
        continue
    res[index + 2] = min(res[index] + abs(h_array[index] - h_array[index + 2]), res[index+2])
print(res[-1])


Measured memory_bytes: 13928
#include <stdio.h>
#include <math.h>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) cerr << #x << "=" << static_cast<bitset<16> >(x) << endl;
#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 if_range(x, y, w, h) if (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))

const int INF = 100000000;
typedef double D;
const D EPS = 1e-8;
const double PI = 3.14159;
int dx[4]={-1, 0, 1, 0}, dy[4]={0, -1, 0, 1};
using namespace std;
typedef pair<int, int> PII;

struct  P {
	int x, y;
	P() {}
	P(int x_, int y_) : x(x_), y(y_) {}
};

/** GRL_7 : Matcing - Bipartite Matching **/
const int MAX_V = 1000;

class Flow {
public:
	struct edge { int to, cap, rev; };
	vector<edge> G[MAX_V];
	bool used[MAX_V];
	
	void add_edge(int from, int to, int cap) {
		G[from].push_back((edge){to, cap, (int)G[to].size()});
		G[to].push_back((edge){from, 0, (int)G[from].size()-1});
	}
	
	int dfs(int v, int t, int f) {
		if (v==t) return f;
		used[v] = true;
		for (int i=0; i<G[v].size(); i++) {
			edge &e = G[v][i];
			if (!used[e.to] && e.cap>0) {
				int d = dfs(e.to, t, min(f, e.cap));
				if (d>0) {
					e.cap-=d;
					G[e.to][e.rev].cap += d;
					return d;
				}
			}
		}
		return 0;
	}
	
	int max_flow(int s, int t) {
		int flow = 0;
		for (;;) {
			memset(used, 0, sizeof(used));
			int f = dfs(s, t, INF);
			if (f==0) return flow;
			flow += f;
		}
	}
};

int main()
{
	Flow F;
	int X, Y, E;
	// 0 ~ X-1 : X
	// X ~ X+Y-1 : Y
	// X+Y : s
	// X+Y+1 : t
	cin>>X>>Y>>E;
	int s=X+Y, t=s+1;
	rep(i, E) {
		int x, y;
		cin>>x>>y;
		F.add_edge(x, X+y, 1);
	}
	rep(i, X) {
		F.add_edge(s, i, 1);
	}
	rep(i, Y) {
		F.add_edge(X+i, t, 1);
	}
	
	cout << F.max_flow(s, t) << endl;
}

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

#define For(i, l, r) for (register int i = (l), i##end = (int)(r); i <= i##end; ++i)
#define Fordown(i, r, l) for (register int i = (r), i##end = (int)(l); i >= i##end; --i)
#define Rep(i, r) for (register int i = (0), i##end = (int)(r); i < i##end; ++i)
#define Set(a, v) memset(a, v, sizeof(a))
#define Cpy(a, b) memcpy(a, b, sizeof(a))
#define debug(x) cout << #x << ": " << (x) << endl

using namespace std;

template<typename T> inline bool chkmin(T &a, T b) { return b < a ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, T b) { return b > a ? a = b, 1 : 0; }

inline int read() {
	int x(0), sgn(1); char ch(getchar());
	for (; !isdigit(ch); ch = getchar()) if (ch == '-') sgn = -1;
	for (; isdigit(ch); ch = getchar()) x = (x * 10) + (ch ^ 48);
	return x * sgn;
}

void File() {
#ifdef zjp_shadow
	freopen ("F.in", "r", stdin);
	freopen ("F.out", "w", stdout);
#endif
}

const int N = 4010, Mod = 998244353;

int f[N][N], sum[N];

char str[N];

int main () {

	File();

	scanf ("%s", str + 1);

	int n = strlen(str + 1);

	For (i, 1, n) sum[i] = sum[i - 1] + (str[i] - '0');
	For (i, n + 1, 2 * n) sum[i] = sum[i - 1];

	f[0][0] = 1;
	For (i, 1, 2 * n) {
		For (j, 0, i) {
			int k = i - j;
			if (j <= sum[i] && k <= 2 * i - sum[i]) {
				if (j) f[i][j] = f[i - 1][j - 1];
				(f[i][j] += f[i - 1][j]) %= Mod;
			}
		}
	}

	printf ("%d\n", f[2 * n][sum[n]]);

    return 0;

}


Measured memory_bytes: 61440
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"sort"
	"strconv"
)

var N, K int
var ans int

func main() {
	fmt.Scan(&N, &K)
	reader := bufio.NewScanner(os.Stdin)
	reader.Split(bufio.ScanWords)
	m := make(map[int]int)

	for i := 0; i < N; i++ {
		reader.Scan()
		t, _ := strconv.Atoi(reader.Text())
		m[t]++
	}

	a := make([]int, 0)
	for _, value := range m {
		a = append(a, value)
	}

	sort.Ints(a)

	for _, value := range a {
		if K < len(a) {
			ans += value
			a = a[1:]
		} else {
			break
		}
	}
	fmt.Println(ans)
}

/*  ----------------------------------------  */

func gcd(x, y uint64) uint64 {
	if x%y == 0 {
		return y
	} else {
		r := x % y
		return gcd(y, r)
	}
}

func combination(x, y int) int {
	return permutation(x, y) / permutation(y, y)
}

func permutation(x, y int) int {
	var ans int = 1
	for i := x - y; 0 < i; i-- {
		ans *= i
	}
	return ans
}

func max(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Max(float64(x[i]), float64(res)))
	}
	return res
}

func min(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Min(float64(x[i]), float64(res)))
	}
	return res
}

func pow(x, y int) uint64 { return uint64(math.Pow(float64(x), float64(y))) }
func abs(x int) int       { return int(math.Abs(float64(x))) }
func floor(x int) int     { return int(math.Floor(float64(x))) }

type XY struct {
	x int
	y int
}

type SortBy [][]int

func (a SortBy) Len() int      { return len(a) }
func (a SortBy) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a SortBy) Less(i, j int) bool {
	if a[i][0] == a[j][0] {
		return a[i][1] > a[j][1]
	}
	return a[i][0] > a[j][0]
}


Measured memory_bytes: 16256
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    int N;
    cin >> N;
    vector<vector<pll> > G(N, vector<pll>());
    ll a, b, c;
    for (int i = 0; i < N-1; i++) {
        cin >> a >> b >> c;
        a--, b--;
        G[a].push_back(pii(b, c));
        G[b].push_back(pii(a, c));
    }
    int Q, K;
    cin >> Q >> K;
    K--;
    queue<int> q;
    vector<ll> d(N, -1);
    q.push(K);
    d[K] = 0;
    while (!q.empty()) {
        int from = q.front();
        q.pop();
        for (pll p : G[from]) {
            int to = p.first;
            ll w = p.second;
            if (d[to] != -1) continue;
            d[to] = d[from] + w;
            q.push(to);
        }
    }
    for (int i = 0; i < Q; i++) {
        cin >> a >> b;
        a--, b--;
        cout << d[a] + d[b] << '\n';
    }
}


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

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repp(i, n, m) for(int (i) = (n); (i) < (m); (i)++)
#define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long
#define ulint unsigned long long
#define ldou long double
#define fi first
#define se second
#define setpre(x) std::cout << fixed << setprecision(x)
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define out(x) cout << (x) << endl
#define outs(x) cout << (x) << " "
#define yn(x) cout << ((x)?("Yes"):("No")) << endl
#define YN(x) cout << ((x)?("YES"):("NO")) << endl
#define bit_c(x) __builtin_popcountll(x)

inline void logger(){ std::cout << " [LOGGER] " << endl; }
template<typename A, typename... B>
void logger(const A& a, const B&... b){
    cout << a << " , "; logger(b...);
}

typedef pair<lint, lint> P;
const lint MOD = 1000000007;
const lint MOD9 = 998244353;
const lint INF = MOD * MOD;
const int MAX = 200005;

/* ...o(^-^)o... */

int main(){
    int n,m; cin >> n >> m;
    vector<P> ans;
    repn(k, m){
        int a = k, b = 1+n-k;
        if(n%2==0 && b-a<=n/2) a++;
        ans.push_back(P(a,b));
    }
    rep(k, m){
        outs(ans[k].fi);
        out(ans[k].se);
    }
}

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

#define mp make_pair
#define fi first
#define se second
#define pb push_back

typedef long long ll;
typedef pair<int,int> ii;
typedef pair<ii,int> iii;
typedef pair<ll,ll> pll;

const int N = 1e2+2;
const int INF = 1e9;
int n, m;
int dr[2] = {0,1};
int dc[2] = {1,0};
int dp[N][N];
char ar[N][N];

bool inRange(int r, int c)
{
    return r >= 1 && r <= n && c >= 1 && c <= m;
}

int solve(int r, int c)
{
    if (r == n && c == m)
        return ar[r][c] == '#';
    if (dp[r][c] != -1)
        return dp[r][c];
    int ret = INF;
    for (int i = 0; i < 2; i++)
    {
        int nr = r + dr[i];
        int nc = c + dc[i];
        if (!inRange(nr,nc))
            continue;
        ret = min(ret, solve(nr,nc) + (ar[r][c] == '#' && ar[nr][nc] == '.')); 
    }
    return dp[r][c] = ret;
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n >> m;
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= m; j++)
        {
            cin >> ar[i][j];
        }
    }
    memset(dp,-1,sizeof(dp));
    cout << solve(1,1) << '\n';
    return 0;
}

Measured memory_bytes: 3712
a, b, c, x, y = map(int, input().split())

p = (a + b) / 2
 
if x == y:
    res = min(a * x + b * y, c * x * 2)
elif x > y:
    res = min(a * x + b * y, c * x * 2, c * y * 2 + a * (x - y))
else:
    res = min(a * x + b * y, c * y * 2, c * x * 2 + b * (y - x))
 
print(res)

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

const int N = 3000;
const double PI = acos(-1);
int a[N+3];
int n,m;
double ansx,ansy;

int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1; i<=n; i++) scanf("%d",&a[i]);
	for(int i=1; i<=n; i++)
	{
		for(int j=i+1; j<=n; j++)
		{
			double ang = PI/m*(a[i]+a[j]);
			double px = cos(ang),py = sin(ang);
			ansx += px*(n-(j-i)-1),ansy += py*(n-(j-i)-1);
			px = -px,py = -py;
			ansx += px*(j-i-1),ansy += py*(j-i-1);
		}
	}
	ansx/=(1.0*n*(n-1)*(n-2)/6.0),ansy/=(1.0*n*(n-1)*(n-2)/6.0);
	printf("%.12lf %.12lf\n",ansx,ansy);
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(b);i>(a);--i)
#define eper(i,a,b) for(int i=((int)(a));i>=b;--i)
#define pb push_back
#define mp make_pair
#define INF 2000000000
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}

int a, b, x;
int main() {
 ios::sync_with_stdio ( false );
 cin.tie ( 0 );
    cin >> a >> b >> x;
    if (a <= x && a + b - x >= 0) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 256
//config = { input: 'tmp', newline: '\r\n' }; // win
config = { input: '/dev/stdin', newline: '\n' }; // linux

A = require('fs').readFileSync(config.input, 'ascii')
  .trim()
  .split(config.newline)
  .map(Number);
A.shift();

res = shellSort(A);
console.log(res.G.length);
console.log(res.G.join(' '));
console.log(res.cnt);
console.log(A.join('\n'));

function insertionSort(A, g) {
  var cnt, i, v, j;
  cnt = 0;
  for (i = g; i < A.length; i++) {
    v = A[i];
    j = i - g;
    while (j >= 0 && A[j] > v) {
      A[j + g] = A[j];
      j = j - g;
      cnt++;
    }
    A[j + g] = v;
  }
  return cnt;
}

function shellSort(A) {
  var cnt, G, i;
  cnt = 0;
  G = [1];
  for (i = 2; i < A.length; i *= 2) G.push(i);
  G.reverse();
  for (i in G) cnt += insertionSort(A, G[i]);
  return {'G': G, 'cnt': cnt};
}

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

map<llong, llong> M;

template<typename T> void factorization(T p) {
    llong i = 2;
    while (i * i <= p) {
        if (p % i == 0) {
            ++M[i];
            p /= i;
        } else {
            ++i;
        }
    }

    if (p != 1) ++M[p];
}

int main (int argc, char *argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    if (n == 1) {
        cout << 0 << endl;
        return 0;
    }
    for (int i = n; i > 0; --i) {
        factorization(i);
    }

    int cnt_74 = 0, cnt_24 = 0, cnt_14 = 0, cnt_4 = 0, cnt_2 = 0;
    map<llong, llong> F;
    for (auto itr = M.begin(); itr != M.end(); ++itr) {
        // cout << itr->first << " " << itr->second << endl;
        if (itr->second >= 74) {
            ++cnt_74;
            ++cnt_24;
            ++cnt_14;
            ++cnt_4;
            ++cnt_2;
        } else if (itr->second < 74 && itr->second >= 24) {
            ++cnt_24;
            ++cnt_14;
            ++cnt_4;
            ++cnt_2;
        } else if (itr->second < 24 && itr->second >= 14) {
            ++cnt_14;
            ++cnt_4;
            ++cnt_2;
        } else if (itr->second < 14 && itr->second >= 4) {
            ++cnt_4;
            ++cnt_2;
        } else if (itr->second < 4 && itr->second >= 2) {
            ++cnt_2;
        }
    }

    int ans = cnt_74 + (cnt_2 - 1) * cnt_24 + (cnt_4 - 1) * cnt_14 + (cnt_2 - 2) * (cnt_4 * (cnt_4 - 1) / 2);

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter
import kotlin.math.max

val br = BufferedReader(InputStreamReader(System.`in`))
val out = PrintWriter(System.out)

fun main() {
    br.use { out.use {
        solve()
        out.flush()
    } }
}

fun solve() {
    val (n, x, m) = readLongList()

    // 何個目の項からループするのかを求める
    val indexMap = mutableMapOf<Long, Long>()
    var cur = x
    var curIndex = 0L
    while (!indexMap.containsKey(cur)) {
        indexMap[cur] = curIndex
        curIndex++
        cur = cur * cur % m
    }
    val loopFromIndex = indexMap[cur]!!

    // ループする前の合計、1ループの合計、1ループの項数
    val sumBeforeLoop = indexMap
        .entries
        .fold(0L) { acc, v -> acc + if (v.value < loopFromIndex) v.key else 0 }
    val sumOneLoop = indexMap
        .entries
        .fold(0L) { acc, v -> acc + if (v.value >= loopFromIndex) v.key else 0 }
    val oneLoopSize = indexMap.count() - loopFromIndex

    // ループ開始後のn、ループする数、ループ終了後のn
    val nAfterStartLoop = max(0, n - loopFromIndex)
    val loopCount = nAfterStartLoop / oneLoopSize
    val nAfterEndLoop = nAfterStartLoop % oneLoopSize

    var ans = if (n <= loopFromIndex) 0 else sumBeforeLoop + loopCount * sumOneLoop

    var pre = if (n <= loopFromIndex) x else cur
    val simulateCount = if (n <= loopFromIndex) n.toInt() else nAfterEndLoop.toInt()
    repeat(simulateCount) {
        ans += pre
        pre = pre * pre % m
    }

    out.println(ans)
    return
}

fun readInteger() = Integer.parseInt(br.readLine())
fun readLong() = java.lang.Long.parseLong(br.readLine())
fun readStringList() = br.readLine()!!.split(' ')
fun readIntegerList() = readStringList().map(Integer::parseInt)
fun readLongList() = readStringList().map(java.lang.Long::parseLong)
fun readDoubleList() = readStringList().map(java.lang.Double::parseDouble)


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

int main()
{
    ll n, q, m, a = 2, k, x, i, tc, j, ans = 1, l;
    string s, s2;
    cin >> s >> s2;
    cout << s2 + s << endl;
    return 0;
}


Measured memory_bytes: 256
// Problem : D - RGB Triplets
// Contest : AtCoder Beginner Contest 162
// URL : https://atcoder.jp/contests/abc162/tasks/abc162_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int mod = 1e9+7;
int inf = 4e18;
const int N = 5e5+5;
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
signed main()
{
    io
    int tt = 1;
    //cin>>tt;
    while(tt--)
    {
    	int n;
    	cin>>n;
    	string s;
    	cin>>s;
    	unordered_map<char,vector<int>,custom_hash> mp;
    	for(int i=0;i<n;++i)
    	{
    		mp[s[i]].push_back(i);
    	}
    	int ans = 0;
    	for(int i=0;i<n;++i)
    	{
    		
    		for(int j=i+1;j<n;++j)
    		{
    			
    			set<char> st;
    			st.insert(s[i]);
    			st.insert(s[j]);
    			if(st.size()!=2)
    			{
    				st.clear();
    				continue;
    			}
    			if(s[i]!='R'&&s[j]!='R')
    			{
    			   int x  = (int)mp['R'].size() - (upper_bound(mp['R'].begin(),mp['R'].end(),j)- mp['R'].begin());
    			   if(x)
    			   {
    			   	ans+=x;
    			   	if(binary_search(mp['R'].begin(),mp['R'].end(),2*j-i))
    			   	ans--;
    			   }
    			}
    			if(s[i]!='G'&&s[j]!='G')
    			{
    				int x  = (int)mp['G'].size() - (upper_bound(mp['G'].begin(),mp['G'].end(),j)- mp['G'].begin());
    			   if(x)
    			   {
    			   	ans+=x;
    			   	if(binary_search(mp['G'].begin(),mp['G'].end(),2*j-i))
    			   	ans--;
    			   }
    			}
    			if(s[i]!='B'&&s[j]!='B')
    			{
    				int x  = (int)mp['B'].size() - (upper_bound(mp['B'].begin(),mp['B'].end(),j)- mp['B'].begin());
    			   if(x)
    			   {
    			   	ans+=x;
    			   	if(binary_search(mp['B'].begin(),mp['B'].end(),2*j-i))
    			   	ans--;
    			   }
    			}
    			
    		}
    	}
    	cout<<ans<<"\n";
    }
    return 0;
}



Measured memory_bytes: 3700
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(10000)


# Debug output
def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))


# Binary converter
def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in input().split()]


# --------------------------------------------

dp = None


def main():
    A, B, C = li_input()

    if A + B >= C:
        print("Yes")
    else:
        print("No")


main()


Measured memory_bytes: 4756
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
					*/

#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>

#pragma GCC optimize("Ofast")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printin(a) printf(a ? "possible\n" : "inposible\n")
#define printdb(a) printf("%.50lf\n", a)//少数出力
#define printdbd(a) printf("%.16lf\n", a)//少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str())//string出力
#define all(x) (x).begin(), (x).end()
#define allsum(a, b, c) ((a + b) * c / 2)//等差数列の和、初項,末項,項数
#define pb push_back
#define priq priority_queue
#define rpriq priq<int, vector<int>, greater<int>>
#define deg_to_rad(deg) (((deg)/360.0)*2.0*PI)
#define rad_to_deg(rad) (((rad)/2.0/PI)*360.0)
#define Please return
#define AC 0
#define vecin(n, a) rep(i, n)scanf("%d", &a[i])

using ll = long long;

const int INF = 1073741823;
const int MINF = -1073741823;
const ll LINF = ll(4661686018427387903);
const ll MOD = 1000000007;
const double PI = acos(-1);

using namespace std;

void scans(string& str) {
	char c;
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);//最初の改行対策
	while (c != '\n' && c != -1) {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

/*-----------------------------------------ここからコード-----------------------------------------*/

int main() {

	string s;
	scans(s);
	vector<int> a(s.length());
	rep(i, s.length()) {
		a[i] = s[i] - '0';
	}
	ll ans = INF;
	rep(i, s.length() - 2) {
		if (abs(a[i] * 100 + a[i + 1] * 10 + a[i + 2] - 753) < abs(753 - ans))ans = a[i] * 100 + a[i + 1] * 10 + a[i + 2];
	}
	printf("%lld\n", abs(753 - ans));

	Please AC;
}


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

int main() {
  int x, y, z;
  cin >> x >> y >> z;
  while (x != -1 || y != -1) {
    if ((x == -1) || (y == -1)) cout << "F" << endl;
    if (x + y >= 80) cout << "A" << endl;
    if (x + y < 80 && x + y >= 65) cout << "B" << endl;
    if (x + y < 65 && x + y >= 50) cout << "C" << endl;
    if (x + y < 50 && x + y >= 30 && x != -1 && y != -1) {
      if (z >= 50) cout << "C" << endl;
      else cout << "D" << endl;
    }
    if (x + y < 30) cout << "F" << endl;
    cin >> x >> y >> z;
  }
}


Measured memory_bytes: 3068
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        String S = sc.next();
        sc.close();
        int[] alp = new int[26];
        int[] cnt = new int[N];
        for(int i = 0; i < N; i++){
            char s = S.charAt(i);
            alp[s - 97]++;
            cnt[i] = alp[s - 97];
        }
        int[] dp = new int[N+1];
        int ans = 0;
        for(int i = 0; i < N; i++){
            char s = S.charAt(i);
            if(cnt[i] == 1 && alp[s - 97] > 1) dp[i+1] = dp[i] + 1;
            else if(cnt[i] == 1 && alp[s - 97]== 1) dp[i+1] = dp[i];
            else if(cnt[i] > 1 && cnt[i] < alp[s - 97]) dp[i+1] = dp[i];
            else dp[i+1] = dp[i] -1;
            ans = Math.max(ans, dp[i+1]);
        }
        System.out.println(ans);

    }

}


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

template<typename T>
class UnionFind {
  public:
    vector<T> parent;

    UnionFind(T n) {
      parent = vector<T>(n, -1);
    }

    T root(T a) {
      if (parent[a] < 0) return a;
      else return parent[a] = root(parent[a]);
    }

    T size(T a) {
      return -parent[root(a)];
    }

    bool connect(T a, T b) {
      a = root(a);
      b = root(b);
      if (a == b) {
        return false;
      }

      if (size(a) < size(b)) swap(a, b);

      parent[a] += parent[b];
      parent[b] = a;
      return true;
    }
};

void Main() {
  int N, K, L;
  cin >> N >> K >> L;

  UnionFind<int> road(N), train(N);

  for (int i = 0; i < K; i++) {
    int p, q;
    cin >> p >> q;
    p--; q--;
    road.connect(p, q);
  }

  for (int i = 0; i < L; i++) {
    int r, s;
    cin >> r >> s;
    r--; s--;
    train.connect(r, s);
  }

  map<pair<int, int>, int> connect;
  for (int i = 0; i < N; i++) {
    connect[pair<int, int>(road.root(i), train.root(i))]++;
  }
  for (int i = 0; i < N; i++) {
    cout << connect[pair<int, int>(road.root(i), train.root(i))] << endl;
  }
}

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



Measured memory_bytes: 16152
#include<bits/stdc++.h>
#include<vector>
#include<string>
using namespace std;
#define l long long
#define pb push_back
#define mem(a,n) memset(a,n,sizeof(a))
#define find(v,n) find(v.begin(),v.end(),n)
#define sort1(v) sort(v.begin(),v.end())
#define lb(v,n) lower_bound(v.begin(),v.end(),n)
#define ub(v,n) upper_bound(v.begin(),v.end(),n)
#define mod 998244353
#define reverse(s) reverse(s.begin(),s.end())
//#define pi pair<l,l> 
const double pi=3.141592653589793;
bool isprime(l n)
{
	for(l i=2;i<=n;i++)
	{
		if(n%i==0)
			return false;
	}
	return true;
}
bool fact(l n)
{
	vector<l> v;
	for(l i=2;i*i<=n;i++)
	{
		if(n%i==0)
		{
			if(i%2==1||(n/i)%2==1)
			{
				return true;
			}
		}
	}
	return false;
}
l power(l a,l b)
{
	l ans=1;
	while(b>0)
	{
		if(b&1)
		{
			ans=(ans*a)%mod;
		}
		b>>=1;
		a=(a%mod*a%mod)%mod;
	}
	return ans;
}//prefixsums
void frooty()
{
	l n,k;
	cin>>n>>k;
	vector<l> v;
	v.pb(0LL);
	for(l i=0;i<n;i++)
	{
		l a;
		cin>>a;
		v.pb(a);
	}
	bool vis[n+1];
	mem(vis,0);
	vis[1]=true;
	l temp=1;
	l x=0;
	l ret=0;
	for(l i=0;i<n;i++)
	{
		if(x==k)
		{
			cout<<temp<<"\n";
			return ;
		}
		temp=v[temp];
		x++;
		if(vis[temp]==false)
		{
			vis[temp]=true;
		}
		else
		{
			ret=temp;
			break;
		}
	}
	l co=1;
	mem(vis,0);
	temp=1;
	x=0;
	while(vis[ret]!=true)
	{
		vis[temp]=true;
		x++;
		temp=v[temp];
	}
	//cout<<ret<<" "<<x-1<<"\n";
	temp=ret;
	vector<l> ans((l)(1e6),0);
	mem(vis,0);
	ans[0]=temp;
	while(vis[ret]!=true)
	{
		temp=v[temp];
		vis[temp]=true;
		ans[co]=temp;
		co++;
	}
//	k++;
	co--;
	k-=(x-1);
	if(co==0)
	{
		cout<<ret<<"\n";
		return ;
	}
	l r=k%co;
//	cout<<co<<"\n";
	cout<<ans[r]<<"\n";
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int q=1;
//	cin>>q;
	while(q--)
	{
		frooty();
	}
}

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

int main() {
	// your code goes here
	long long int a,b;
	long long min=1e9;
	cin>>a>>b;
	if(b-a>=2018)
	cout<<0<<endl;
	else
	{
	
	long long a1=a%2019;
	long long b1=b%2019;
	if(a1>=b1)
	b1+=2019;
	for(long long i=a1;i<b1;++i)
	{
	    for(long long j=a1+1;j<=b1;++j)
	    {
	        if((i*j)%2019<min)
	        min=(i*j)%2019;
	    }
	}
	cout<<min;
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define LLINF 9223372036854775807
#define MOD ll(1e9+7)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr<<#x<<": "<<x<<endl


ll calculate_gcd(ll a, ll b){
    if(a<b){swap(a,b);}
    if(b<1){return 0;}
    ll r;
    while((r = a%b) != 0){
        a = b;
        b = r;
    }
    return b;
}

int main(){
    ll n;
    cin >> n;
    vector<ll> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    ll ans = a[0];
    for(int i = 0; i < n; i++){
        ans = calculate_gcd(ans, a[i]);
    }

    cout << ans << endl;
    return 0;

}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,cnt=0,n1;
	cin>>n;
	cnt=n/500;
	n1=n%500;
	cnt*=1000;
	n1=n1/5;
	cnt+=n1*5;
	cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ld;
ld mod=1000000007;
char a[1005][1005];
ld dp[1005][1005];
int main()
{
    int i,j,h,w;
    cin>>h>>w;
    for(i=0;i<h;i++)
    {
        for(j=0;j<w;j++)
        {
            cin>>a[i][j];
        }
    }
    //dp[0][0];
    for(i=0;i<h;i++)
    {
        for(j=0;j<w;j++)
        {
            if(a[i][j]=='#')
            {
                dp[i][j]=0;
            }
            else
            {
                if((i>0)and(j>0))
                {
                    dp[i][j]=(dp[i-1][j]+dp[i][j-1])%mod;
                }
                else if((i>0)and(j==0))
                {
                    dp[i][j]=dp[i-1][j];
                }
                else if((i==0)and(j>0))
                {
                    dp[i][j]=dp[i][j-1];
                }
                else
                {
                    dp[i][j]=1;
                }
            }
        }
    }
    cout<<dp[h-1][w-1];
    return 0;
}

Measured memory_bytes: 9088
#include <iostream>
#include <string>
using namespace std;
 
int main() {
  string s;
  cin >> s;
  string R=""; 
  for(int i = 0;i<s.size();i++){
    if((i + 1)% 2 !=0) R+=s[i];
  }
  cout << R << endl;
}

Measured memory_bytes: 3644
a,b,c,k = [int(i) for i in input().split()]
tot = 0

tot += min(a, k)
mini = min(a,k)
a -= mini
k -= mini
#print(a, k, tot)
if(k > 0):
    mini = min(b,k)
    b -= mini
    k -= mini
if(k > 0):
    tot -= min(c,k)

print(tot)
    


Measured memory_bytes: 9140
const int N = 4e5;
const int LG = 21;
const long long MOD = 1e9 + 7;
const long long INF = 1e9;

#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <time.h>
#include <unordered_set>
#include <bitset>
#include <deque>

using namespace std;

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

#define forn(i, n) for (int (i) = 0; (i) != (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define fi first
#define se second
#define re return
#define uniq(x) sort(all(x)); (x).resize(unique(all(x)) - (x).begin())

#ifdef LOCAL
#define dbg(x) cerr << __LINE__ << " " << #x << " " << x << endl
#define ln cerr << __LINE__ << endl
#else
#define dbg(x) void(0)
#define ln void(0)
#endif // LOCAL

int cx[4] = {-1, 0, 1, 0};
int cy[4] = {0, -1, 0, 1};

ll inq(ll x, ll y)
{
    if (!y) re 1 % MOD;
    ll l = inq(x, y / 2);
    if (y % 2) re l * l % MOD * x % MOD;
    re l * l % MOD;
}

ll rev(ll x)
{
    return inq(x, MOD - 2);
}

bool __precomputed_combinatorics = 0;
vector<ll> __fact, __ufact, __rev;

void __precompute_combinatorics()
{
    __precomputed_combinatorics = 1;
    __fact.resize(N);
    __ufact.resize(N);
    __rev.resize(N);
    __rev[1] = 1;
    for (int i = 2; i < N; i++) __rev[i] = MOD - __rev[MOD % i] * (MOD / i) % MOD;
    __fact[0] = 1, __ufact[0] = 1;
    for (int i = 1; i < N; i++) __fact[i] = __fact[i - 1] * i % MOD, __ufact[i] = __ufact[i - 1] * __rev[i] % MOD;
}

ll fact(int x)
{
    if (!__precomputed_combinatorics) __precompute_combinatorics();
    return __fact[x];
}

ll cnk(int n, int k)
{
    if (!__precomputed_combinatorics) __precompute_combinatorics();
    return __fact[n] * __ufact[n - k] % MOD * __ufact[k] % MOD;
}

void __fast_IO()
{
    #ifdef ONLINE_JUDGE
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
    #endif // ONLINE_JUDGE
}

//##**##**##**##**##**##**##**##**##**##**##**##**##**##**##**##**##**##**##**##**
//##**##**##**##**##**##**##**##**##**##**##**##**##**##**##**##**##**##**##**##**

ll n, a, b;
ll r[N];

signed main()
{
    __fast_IO();
    cin >> n >> a >> b;
    a -= b;
    for (int i = 0; i < n; i++) cin >> r[i];
    ll L = 0, R = 1e18 / b + 100;
    while (L + 1 < R)
    {
        ll M = (L + R) / 2;
        ll dmg = M * b;
        ll need = 0;
        for (int i = 0; i < n; i++)
        {
            if (r[i] > dmg)
            {
                need += (r[i] - dmg + a - 1) / a;
            }
        }
        if (need <= M) R = M;
        else L = M;
    }
    cout << R;
}

/* Note:
Check constants at the beginning of the code.
N is set to 4e5 but be careful in problems with large constant factor.
Check corner cases.
No def int long long for now.
*/


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
  int b,a,t;
  int mx;
  while(1){
    mx=0;
    cin>>b>>a>>t;
    if(b==0 && a==0 && t==0) break;
    for(int i=1;i<t;i++){
      for(int j=1;j<t;j++){
        if(i*(100+b)/100+j*(100+b)/100!=t)continue;
        mx=max(mx,i*(100+a)/100+j*(100+a)/100);
      }
    }
    cout<<mx<<endl;
  }
  return 0;
}



Measured memory_bytes: 3096
#include <iostream>
#include <string>
#include <map>
#define llint long long
#define mod 1000000007

using namespace std;

llint n, m;
llint a[1005];
llint dp[25][1005];

const int FACT_MAX = 200005;
llint fact[FACT_MAX], fact_inv[FACT_MAX];

llint modpow(llint a, llint n)
{
	if(n == 0) return 1;
	if(n % 2){
		return ((a%mod) * (modpow(a, n-1)%mod)) % mod;
	}
	else{
		return modpow((a*a)%mod, n/2) % mod;
	}
}

void make_fact()
{
	llint val = 1;
	fact[0] = 1;
	for(int i = 1; i < FACT_MAX; i++){
		val *= i;
		val %= mod;
		fact[i] = val;
	}
	fact_inv[FACT_MAX-1] = modpow(fact[FACT_MAX-1], mod-2);
	for(int i = FACT_MAX-2; i >= 0; i--){
		fact_inv[i] = fact_inv[i+1] * (i+1) % mod;
	}
}

llint comb(llint n, llint k)
{
	llint ret = 1;
	ret *= fact[n];
	ret *= fact_inv[k], ret %= mod;
	ret *= fact_inv[n-k], ret %= mod;
	return ret;
}

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	make_fact();
	
	cin >> n >> m;
	for(int i = 1; i <= m; i++) cin >> a[i];
	
	dp[0][0] = 1;
	for(int i = 0; i < m; i++){
		for(int j = 0; j <= n; j++){
			for(int k = 0; k <= a[i+1]; k++){
				if(j+k > n || n-j < k) break;
				dp[i+1][j+k] += dp[i][j] * comb(n-j, k) % mod * comb(n-k, a[i+1]-k) % mod;
				dp[i+1][j+k] %= mod;
			}
		}
	}
	cout << dp[m][n] << endl;
	
	return 0;
}

Measured memory_bytes: 3584
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcount
#define ll long long
#define mp make_pair
#define f first
#define s second
#define Time (double)clock()/CLOCKS_PER_SEC
const int N = 2e5 + 7, INF = 1e9 + 7;
ii a[N];
bool comp(ii a, ii b) { 
    return b.f * (a.s + 1) < a.f * (b.s + 1);
}   
int dp[N];
signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    #define endl '\n'
    ios_base::sync_with_stdio(0); cin.tie(0);
    #endif
    int n, t;
    cin >> n >> t;
    vector <ii> ar;
    vector <int> add;                    
    for (int i = 0; i < n; ++i) {
        cin >> a[i].f >> a[i].s;
        if (a[i].f == 0)
            add.app(a[i].s);
        else
            ar.app(a[i]);
    }    
    sort(all(add));
    sort(all(ar), comp);
    for (int i = 1; i < N; ++i)
        dp[i] = INF;
    for (auto e : ar) {
        for (int i = 100; i >= 0; --i) {
            dp[i + 1] = min(dp[i + 1], dp[i] + 1 + (dp[i] + 1) * e.f + e.s);
        }
    }   
    int ans = 0;
    for (int i = 0; i <= 100; ++i) {
        if (dp[i] <= t) {
            int nn = i, cur = dp[i];
            for (int e : add) {
                cur += e + 1;
                if (cur > t)
                    break;
                ++nn;
            }   
            ans = max(ans, nn);
        }   
    }   
    cout << ans << endl;
}   


Measured memory_bytes: 8940
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)

def main():
    rr = []


    while True:
        n,m,s,g1,g2 = LI()
        if n == 0:
            break
        e = collections.defaultdict(list)
        for _ in range(m):
            a,b,c = LI()
            e[a].append((b,c))

        def search(s):
            d = collections.defaultdict(lambda: inf)
            d[s] = 0
            q = []
            heapq.heappush(q, (0, s))
            v = collections.defaultdict(bool)
            while len(q):
                k, u = heapq.heappop(q)
                if v[u]:
                    continue
                v[u] = True

                for uv, ud in e[u]:
                    if v[uv]:
                        continue
                    vd = k + ud
                    if d[uv] > vd:
                        d[uv] = vd
                        heapq.heappush(q, (vd, uv))

            return d

        sd = search(s)
        r = inf
        for i in range(1,n+1):
            td = search(i)
            tr = sd[i] + td[g1] + td[g2]
            if r > tr:
                r = tr

        rr.append(r)

    return '\n'.join(map(str, rr))



print(main())



Measured memory_bytes: 9140
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
  ll a,b,c,d;
  cin >>a>>b>>c>>d;
  ll ans;
  ans=max(max(a*c,a*d),max(b*c,b*d));
  cout << ans;
}

Measured memory_bytes: 3536
H,W = map(int,input().split())
grid = [list(map(int,input().split())) for i in range(H)]
cnt = 0
print_list = []
for i in range(H):
    for j in range(W):
        if (i,j) == (H-1,W-1):
            break
        if grid[i][j] % 2 == 1:
            cnt += 1
            if i != H-1:
                grid[i][j] -= 1
                grid[i+1][j] += 1
                print_list.append([i+1,j+1,i+2,j+1])
            elif i == H-1:
                grid[i][j] -= 1
                grid[i][j+1] += 1
                print_list.append([i+1,j+1,i+1,j+2])

def debug():
    num = 0
    for i in range(H):
        for j in range(W):
            if grid[i][j] % 2 == 0:
                num += 1
    print("偶数は{}個です".format(num))

def output():
    print(cnt)
    for p in print_list:
        print(p[0],p[1],p[2],p[3])

output()

Measured memory_bytes: 30452
#include <bits/stdc++.h>
using namespace std;
#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 fi first
#define se second
#define mp make_pair
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
#define dame { printf("No\n"); return 0;}
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
typedef long long llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define print(a) cout << a << endl;
#define MOD llong(1e9+7)
#define MAX int(2 * 1e5 +5)
#define debug(x)  cout << #x << " = " << (x) << endl;
#define pi acos(-1.0)
#define int llong
#define INF llong(1e17)


signed main(){
    int n;
    cin >> n;
    map< string, vector< pair<int,int> > > scores; 
    set<string> S;
    REP(i,n){
        string s;
        int ten;
        cin >> s >> ten;

        scores[s].push_back(mp(-ten,i + 1));
        S.insert(s);
    }
    itrfor(itr,S){
        Sort(scores[*itr]);
        itrfor(itr1 , scores[*itr]){
            cout << itr1->se << endl;
        };
    }
}


Measured memory_bytes: 256
/**
  *  Worg
  */
#include <vector>
#include <iostream>

int main() {
	int n, w; std::cin >> n >> w;
//	dp[i] = cel mai mic weight care da valoarea i
//  initializam dp[0] = 0, in rest dp[i] = w + 1

	std::vector<int> dp(1 + n * 1000, w + 1);
	dp[0] = 0;

	for (int i = 0; i < n; i++) {
		int weight, value; std::cin >> weight >> value;

		for (int j = n * 1000 - value; j >= 0; j--) {
			if (dp[j] + weight <= w) {
				dp[j + value] = std::min(dp[j + value], dp[j] + weight);
			}
		}
	}

	for (int i = n * 1000; i >= 0; i--) {
		if (dp[i] <= w) {
			std::cout << i << "\n"; return 0;
		}
	}
}

Measured memory_bytes: 640
N,K=map(int,input().split())
#print(N,K)

########関数部分##############
def Base_10_to_n(X, n):
    if (int(X/n)):
        return Base_10_to_n(int(X/n), n)+str(X%n)
    return str(X%n)
############################

answer=Base_10_to_n(N,K)

print(len(str(answer)))

Measured memory_bytes: 3060
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <sstream>
#include <string>
#include <utility>
#include <map>
#include <memory>
#include <set>
#include <vector>
#include <deque>
#include <list>
#include <stack>
#include <queue>

using namespace std;

class Koch
{
public:
  int solve( int x );
  int koch( int n, pair<double, double> p1, pair<double, double> p2, list<pair<double, double> >& rs);
};

int Koch::solve( int x )
{
  list<pair<double, double> > rs;
  koch(x, make_pair(0,0), make_pair(100,0), rs);

  for ( list<pair<double, double> >::iterator it = rs.begin(); it != rs.end(); it++ )
    {
      cout << fixed << setprecision(6) << (*it).first << " " << (*it).second << endl;
    }
  
  return x;
}

int Koch::koch( int n, pair<double, double> p1, pair<double, double> p2, list<pair<double, double> >& rs)
{
  if ( n == 0 )
    {
      rs.push_back(p1);
      rs.push_back(p2);
      return 0;
    }
  
  const double r3 = 1.7320508;
  list<pair<double, double> > rss[4];
  pair<double, double> s = make_pair( (p1.first * 2.0 + p2.first) / 3.0, (p1.second * 2.0 + p2.second) / 3.0 );
  pair<double, double> t = make_pair( (p2.first * 2.0 + p1.first) / 3.0, (p2.second * 2.0 + p1.second) / 3.0 );

  double vx = t.first - s.first;
  double vy = t.second - s.second;

  double rvx = (vx - r3 * vy) / 2.0;
  double rvy = (r3 * vx + vy) / 2.0;
  
  pair<double, double> u = make_pair( s.first + rvx, s.second + rvy );
  
  koch( n-1, p1, s, rss[0] );
  koch( n-1, s,  u, rss[1] );
  koch( n-1, u,  t, rss[2] );
  koch( n-1, t, p2, rss[3] );

  for ( int i = 0; i < 4; i++ )
    {
      if ( i ) rss[i].pop_front();
      for ( list<pair<double, double> >::iterator it = rss[i].begin(); it != rss[i].end(); it++ )
        {
          rs.push_back(*it);
        }
    }
  
  return 0;
}


int main()
{
  int x;

  Koch k;

  cin >> x;

  k.solve( x );

  return 0;
}

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

#define rep(i, N) for (int i = 0; i < N; i++)
#define rep1(i, N) for (ll i = 1; i <= N; i++)
#define repr(i, N) for (ll i = N-1; i >= 0; i--)
#define repr1(i, N) for (ll i = N; i > 0; i--)

#define MODNUM 1000000007

using ll = long long;
using namespace std;

int main(){
    int N,M;
    cin >> N >> M;
    vector<int> a(M+1,0);
    rep(i,M) cin >> a[i];
    vector<ll> ans(N+1,0);
    
    bool flag = false;
    rep1(i,M-1) {if(a[i] == a[i+1]-1){ cout << '0' << endl; return 0;}}
    ans[0] = 1;
    int next_index = 0;
    if(a[0] != 1){
        ans[1] = 1;
    }else{
        ans[1] = 0;
        next_index++;
    }
    for(int i = 2;i <= N;i++){
        if(i != a[next_index]){
            ans[i] = (ans[i-1] + ans[i-2])%MODNUM;
        }else{
            ans[i] = 0;
            next_index++;
        }
    }

    cout << ans[N] << ' ';
    return 0;
}


Measured memory_bytes: 1408
#include <stdio.h>


int main(void){
	int i,time,min,sec;
	scanf("%d",&i);
	time = i / 3600;
	min = i % 3600;
	sec = min % 60;
	printf("%d:%d:%d\n",time,min/60,sec);
	
	return 0;
}	
	

Measured memory_bytes: 592
import java.util.Scanner;

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

		while (sc.hasNext()) {
			String[] s = sc.nextLine().split(" ");
			int a = Integer.parseInt(s[0]);
			int b = Integer.parseInt(s[1]);
			int c = Integer.parseInt(s[2]);
			int counter = 0;
			for (int i = a; i <= b; i++) {
				if (c % i == 0) {
					counter++;
				}
			}
			System.out.println(counter);
		}
	}
}

Measured memory_bytes: 26188