akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REPR(i,n) for (int i=(int)(n)-1;i>=0;--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define valid(y,x,h,w) (0<=y&&y<h&&0<=x&&x<w)
#define tpl(...) make_tuple(__VA_ARGS__)
const int INF = 0x3f3f3f3f;
const double EPS = 1e-8;
const double PI = acos(-1);
const int dy[] = {-1,0,1,0};
const int dx[] = {0,1,0,-1};
typedef long long ll;
typedef pair<int,int> pii;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename Ch,typename Tr,typename C,typename=decltype(begin(C()))>basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>&os,
                                                                                                           const C& c){os<<'[';for(auto i=begin(c);i!=end(c);++i)os<<(i==begin(c)?"":" ")<<*i;return os<<']';}
template<class S,class T>ostream&operator<<(ostream &o,const pair<S,T>&t){return o<<'('<<t.first<<','<<t.second<<')';}
template<int N,class Tp>void output(ostream&,const Tp&){}
template<int N,class Tp,class,class ...Ts>void output(ostream &o,const Tp&t){if(N)o<<',';o<<get<N>(t);output<N+1,Tp,Ts...>(o,t);}
template<class ...Ts>ostream&operator<<(ostream&o,const tuple<Ts...>&t){o<<'(';output<0,tuple<Ts...>,Ts...>(o,t);return o<<')';}
template<class T>void output(T t,char z=10){if(t<0)t=-t,putchar(45);int c[20];
  int k=0;while(t)c[k++]=t%10,t/=10;for(k||(c[k++]=0);k;)putchar(c[--k]^48);putchar(z);}
template<class T>void outputs(T t){output(t);}
template<class S,class ...T>void outputs(S a,T...t){output(a,32);outputs(t...);}
template<class T>void output(T *a,int n){REP(i,n)cout<<a[i]<<(i!=n-1?',':'\n');}
template<class T>void output(T *a,int n,int m){REP(i,n)output(a[i],m);}
template<class T>bool input(T &t){int n=1,c;for(t=0;!isdigit(c=getchar())&&~c&&c-45;);
  if(!~c)return 0;for(c-45&&(n=0,t=c^48);isdigit(c=getchar());)t=10*t+c-48;t=n?-t:t;return 1;}
template<class S,class ...T>bool input(S&a,T&...t){input(a);return input(t...);}
template<class T>bool inputs(T *a, int n) { REP(i,n) if(!input(a[i])) return 0; return 1;}

int a[200000];
int ans[200000];

int main() {
  int n;
  while(cin>>n) {
    memset(ans,0,sizeof(ans));
    inputs(a,n);
    REPR(i,n) {
      int f = a[i];
      int num = i+1;
      for (int j=2*num; j<=n; j+=num)
        f ^= ans[j-1];
      ans[i] = f;
      // cout << tpl(i,ans[i],f) << endl;
    }
    vector<int> v;
    REP(i,n) if (ans[i]) v.push_back(i);
    cout << v.size() << endl;
    REP(i,v.size()) printf("%d%c",v[i]+1,i!=(int)v.size()-1?' ':'\n');
  }
}


Measured memory_bytes: 3192
#include <string.h>
#include <iostream>
#include <iomanip>
#include <list>
#include <map>
#include <algorithm>
#include <stack>

using namespace std;


int main(){
	char str[20];
	int j = 0;
	memset(str,'\0',sizeof(str));
	while(cin >> str){	
		for(int i = sizeof(str) / sizeof(char) - 1; i >= 0; i--){
			if(str[i] != '\0'){
				cout << str[i];
			}
		}
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 1132
H,W = map(int, input().split())

"""
割るとすれば
・縦直線で割ってから縦直線で割る
・縦直線で割ってから横直線で割る
・横直線で割ってから横直線で割る
・横直線で割ってから縦直線で割る

の４パターン
愚直にやると、
それぞれ最初の割り方をどの位置で割るか決めた後、残りのどっちを割るか決めて、選んだ方のどの位置で割るか決める
になるから、H*W*4?みたいな感じになって、まぁとにかく間に合わない。

割り終わった後にできる３つのピースの最大と最小の差をできるだけ小さくしたい、なので、２回目の割り方については、なるべく等分に近くなるように割るのがよい。はず。
"""


ans = H*W

# 先に横直線で割るパターン
for h in range(1,H):
    p1 = W * h
    # 残りも横直線で割る場合
    p2 = ((H-h) // 2) * W
    p3 = H*W - p1 - p2
    ans = min(ans, max(p1, p2, p3) - min(p1, p2, p3))

    # 残りを縦で割る
    p2 = (H-h) * (W // 2)
    p3 = H*W - p1 - p2 
    ans = min(ans, max(p1, p2, p3) - min(p1, p2, p3))

for w in range(1, W):
    p1 = w*H
    p2 = ((W-w) // 2) * H
    p3 = H*W - p1 - p2
    ans = min(ans, max(p1, p2, p3) - min(p1, p2, p3))

    p2 = (W - w) * (H // 2)
    p3 = H*W - p1 - p2 
    ans = min(ans, max(p1, p2, p3) - min(p1, p2, p3))


print(ans)

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

#define ll long long
#define INF 99999999
#define rep(i,n) for(int i=0,temp=(int)(n);i<temp;++i) //vec.size()がnの時等の高速化
#define all(x) (x).begin(),(x).end()
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define vint vector<int>
#define vvint vector<vector<int>>

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int ctoi(char c) {return c-'0';}

ll n,a,b,c,d,e;

int main(){
  ll ans;
  cin >> n >> a >> b >> c >> d >> e;
  ll m = min(a,min(b,min(c,min(d,e))));
  if(n%m==0) ans=n/m+4;
  else ans=n/m+5;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
/* When Talent doesn't work, Hard work beats Talent*/

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

#include"bits/stdc++.h"

using namespace std;

#define Fast_D cout<<fixed<<setprecision(13);
#define FastIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

#define nl "\n"
#define int long long
#define double long double
#define all(v) v.begin(),v.end()
#define scanstr(s) cin>>ws; getline(cin,s);

const double PI = 3.141592653589793;

void solve()
{
	string s;
	cin >> s;
	int a=s.size(),b=0;
	for(int i=0;i<s.size();i++)
	{
		if(s[i]=='A') a = min(a,i);
		if(s[i]=='Z') b = max(b,i);
	}
	cout << max(b-a+1,0LL);
}

int32_t main()
{
	FastIO;
	Fast_D;
	solve();
	return 0;
}


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

C, S, F = [0] * n, [0] * n, [0] * n

for i in range(n - 1):
    C[i], S[i], F[i] = map(int, input().split())

for i in range(n):
    time = 0
    for j in range(i, n - 1):
        if time < S[j]:
            time = S[j] + C[j]
        elif time % F[j] == 0:
            time += C[j]
        else:
            time = time + F[j] - (time % F[j]) + C[j]
    print(time)
    


Measured memory_bytes: 3064
S = input()

N = len(S)
X = [i-1 if S[i] == "L" else i+1 for i in range(N)]
for k in range(1, 20):
 X = [X[X[i]] for i in range(N)]

A = [0]*N

for i in range(N):
 A[X[i]]

 A[X[i]] += 1

print(*A)


Measured memory_bytes: 10324
import heapq
from math import ceil

N, M = map(int, input().split())
A = [(-1)*int(x) for x in input().split()]

if len(A) == 1:
    for i in range(M):
        A[0] = ceil(A[0]/2)
    A[0] = -A[0]
    print(A[0])
else:
    count = 0
    heapq.heapify(A)
    a = heapq.heappop(A)
    b = heapq.heappop(A)
    while count < M:
        while a <= b:
            a = ceil(a/2)
            count += 1
            if count == M:
                break
        if count == M:
            break
        heapq.heappush(A,a)
        a = b
        b = heapq.heappop(A)
    heapq.heappush(A,a)
    heapq.heappush(A,b)
    ans = (-1)*sum(A)
    print(ans)


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

int main(void){
  int n,a[110],ans=0,l;

  cin >> n;
  for (int i=0; i<n; i++){
    cin >> a[i];
  }
  l=0;
  while (l<n){
    while (a[l]){
      for (int i=l; i<n; i++){
        if (a[i]==0) break;
        a[i]--;
      }
      ans++;
    }
    l++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define io std::ios::sync_with_stdio(false)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b)
{
    return b?gcd(b,a%b):a;
}
ll qpow(ll a,ll n)
{
    ll r=1%P;
    for (a%=P; n; a=a*a%P,n>>=1)
        if(n&1)
            r=r*a%P;
    return r;
}
const int maxn=1e6+10;
int cnt[maxn];
int main()
{
        int n;
        cin>>n;
        ll  pre=7;
        int ans=1;
        while(1)
        {
            int x=pre%n;
            if(x==0)
            {

                cout<<ans<<endl;
                break;
            }
            if(cnt[x]) {return puts("-1"),0;}
            cnt[x]++;
            pre=x*10+7;
            ans++;
        }
}



Measured memory_bytes: 7376
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from heapq import heapify, heappop, heappush

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

S = input()
N = len(S)
tmp = 0
ans = 0
A = 0
B = 0
b_num = 0
for i in range(1, N+1):
    if S[i-1] == "B":
        b_num += 1
        A += i

all_wa = N * (N + 1) // 2
B = all_wa - (N - b_num) * (N - b_num + 1) // 2

print(B - A)

Measured memory_bytes: 4264
#include<bits/stdc++.h>
	using namespace std;
	typedef long long int ll;
	typedef unsigned long long int ull;
	#define vll vector<long long int> 
	#define pb  push_back
 
 
	 bool isPrime(int num){
	bool flag=true;
	for(int i = 2; i <= num / 2; i++) {
		if(num % i == 0) {
			flag = false;
			break;
		}
	}
	return flag;
}
 
unsigned int factorial(unsigned int n) 
{ 
	if (n == 0) 
		return 1; 
	return n * factorial(n - 1); 
} 
 
 
	int main()
	{
		
 
 
 
int a,b;
  string s=" ";
  cin>>a>>b;
  int maxi=max(a,b);
  int mini=min(a,b);
  for(int i=1;i<=maxi;i++)
  {
	cout<<mini;
  }
  
  return 0;
}

Measured memory_bytes: 256
import sys
input = lambda :sys.stdin.readline().rstrip('\r\n')
n,d = map(int,input().split())
x = 0
d*=d
for _ in range(n):
    a,b = map(int,input().split())
    v = a**2 + b**2
    if v<=d:
        x+=1
print(x)

Measured memory_bytes: 9140
#![allow(unused, non_snake_case, dead_code, non_upper_case_globals)]
use {
    proconio::{marker::*, *},
    std::{cmp::*, collections::*, mem::*},
};
fn main() {
    input! {//
        a:i64,b:i64,
    }
    if a + b == 15 {
        println!("+");
    } else if a * b == 15 {
        println!("*");
    } else {
        println!("x");
    }
}


Measured memory_bytes: 2112
using System;
using System.Linq;

namespace atcoder.abc169.b
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = getIntParam();
            decimal[] paramArray = getDecimalParams();

            if (paramArray.Contains(0))
            {
                Console.WriteLine(0);
                return;
            }

            decimal ret = paramArray[0];
            decimal limit = Convert.ToDecimal(Math.Pow(10, 18));
            for (int i = 1; i < N; i++)
            {
                if (limit / ret < paramArray[i])
                {
                    Console.WriteLine(-1);
                    return;
                }
                ret *= paramArray[i];
            }
            Console.WriteLine(ret);
            return;
        }

        //↓↓↓ shared function ↓↓↓
        static int getIntParam()
        {
            return int.Parse(Console.ReadLine());
        }
        static int[] getIntParams()
        {
            return Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
        }
        static long getLongParam()
        {
            return long.Parse(Console.ReadLine());
        }
        static long[] getLongParams()
        {
            return Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
        }
        static string getStringParam()
        {
            return Console.ReadLine();
        }
        static string[] getStringParams()
        {
            return Console.ReadLine().Split(' ');
        }

        static decimal[] getDecimalParams()
        {
            return Console.ReadLine().Split(' ').Select(i => decimal.Parse(i)).ToArray();
        }

    }
}


Measured memory_bytes: 42236
#include <bits/stdc++.h>
int main() {
    std::cin.tie(nullptr); std::ios::sync_with_stdio(false);
    
    int N;
    std::string S;
    std::cin >> S;    
    N = S.length();
    int count = 0;
    if (N > 1) {
        for (int i = 0; i < N; i++)if (S[i] != (i % 2 ? '1' : '0'))++count;
    }
    int ans = std::min(count, N - count);
    std::cout << ans << std::endl;
}

Measured memory_bytes: 512
#include <algorithm>
#include <array>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define REP(X, Y, Z) for (ll(X) = (Y); (X) < (Z); (X)++)
#define REV(X, Y, Z) for (ll(X) = (Y); (X) > (Z); (X)--)

using namespace std;
using ll = long long;
using dll = deque<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using usll = unordered_set<ll>;
using umll = unordered_map<ll, ll>;
using sll = stack<int>;
using vll = vector<ll>;
using vvll = vector<vll>;

constexpr ll kMax = 1e12 + 1;
constexpr ll kMod = 1e9 + 7;

ll gcd(ll a, ll b) {
  if (a < b) {
    return gcd(b, a);
  }
  ll c = a % b;
  while (c != 0) {
    a = b;
    b = c;
    c = a % b;
  }
  return b;
}

ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}

void init() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

int main() {
  init();

  string S;
  cin >> S;

  if (S.size() == 0) {
    cout << 0 << endl;
    return 0;
  }

  bool all_same = true;
  char cur = S[0];
  ll ans = 0;
  REP(i, 1, S.size()) {
    if (cur != S[i]) {
      all_same = false;
      ans++;
    }
    cur = S[i];
  }
  if (all_same) {
    cout << 0 << endl;
  } else {
    cout << ans << endl;
  }

  return 0;
}


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

using namespace std ;
const int N=1e5+6 , M=6;

int n , a[N] , b[N] , c[N] ;
int mem[N][M];
int happiness[N][M];

int dp(int i , int activity)
{                                   // 0 is for a and 1 is for b and 2 is for c ;
    if(i==n)return 0;

    if(mem[i][activity]!=-1)return mem[i][activity];

    int ans=-2e9;

    for(int j=0 ; j<3 ; j++){
        if(activity==j)continue;
        ans=max(ans , happiness[i][j]+dp(i+1 , j));
    }

    mem[i][activity]=ans;
    return mem[i][activity];
}

int main()
{
    scanf("%d" , &n);

    for(int i=0 ; i<n ; i++){
        for(int j=0 ; j<3 ; j++){
            scanf("%d" , &happiness[i][j]);
        }
    }

    memset(mem , -1 , sizeof mem);

    printf("%d\n", max({dp(0,0) , dp(0, 1) , dp(0,2)}) );



}


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

int main()
{
  int n;
  cin>>n;
  int k;
  cin>>k;
  if(n==0){
  cout<<"0"<<endl;
  return 0;
  }
  vector<int> v(n);
  for(int&x: v)
  cin>>x;

  vector<int> dp(n,INT_MAX);
  dp[0]=0;
  //dp[1]=abs(v[1]-v[0]);
  for(int i=1;i<n;i++)
  {
    //dp[i]=min(dp[i-1]+abs(v[i]-v[i-1]),dp[i-2]+abs(v[i]-v[i-2]));
    for(int j=i-1;j>=0&&j>=i-k;j--)
    dp[i]=min(dp[i],dp[j]+abs(v[j]-v[i]));
  }
  cout<<dp[n-1]<<endl;
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;

int main() {
  int n;
  cin >> n;
  map<string, int> mp;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    mp[s]++;
  }
  int m;
  cin >> m;
  for (int i = 0; i < m; i++) {
    string t;
    cin >> t;
    mp[t]--;
  }
  int maxPoint = -1e9;
  for (auto i = mp.begin(); i != mp.end(); i++) {
    if ((*i).second > maxPoint) {
      maxPoint = (*i).second;
    }
  }
  cout << max(maxPoint, 0) << endl;
  return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**8)
INF = float("inf")


def array(*args, initial=0):
    pre = "["*len(args)
    post = ""
    for a in args[::-1]:
        post += " for _ in range("+str(a)+")]"
    S = pre + str(initial) + post
    return eval(S)


def solve(N: int, A: int, x: "List[int]"):
    M = sum(x)
    # Nまで考慮, 使用した個数（Nまで）, 合計値
    DP = array(N+1, N+1, M+1)
    DP[0][0][0] = 1

    for i, a in enumerate(x, start=1):
        for j in range(N+1):
            for tot in range(M+1):
                DP[i][j][tot] = DP[i-1][j][tot]  # 使わない時
                if tot - a >= 0:                 # 使う時
                    DP[i][j][tot] += DP[i-1][j-1][tot-a]

    ans = 0
    for j in range(1, N+1):
        for tot in range(M+1):
            if tot / j == A:
                # if abs(tot / j-A) < 0.1:
                ans += DP[-1][j][tot]
    print(ans)
    # print(*DP[-1], sep="\n")
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = int(next(tokens))  # type: int
    x = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A, x)


if __name__ == '__main__':
    main()


Measured memory_bytes: 95196
[<AutoOpen>]
module Program

open System

let read f = stdin.ReadLine() |> f
let reads f = stdin.ReadLine().Split() |> Array.map f

[<EntryPoint>]
let main _ =
    let N = read int
    let AS = reads int

    let mutable cnt = 0
    for i in AS do
        if i = cnt + 1 then cnt <- cnt + 1

    match cnt with
    | 0 -> printfn "-1"
    | _ -> printfn "%i" (N - cnt)

    0

Measured memory_bytes: 34136
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<iomanip>
using namespace std;
#define ll long long
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    ll a,v,b,w,t;
    cin>>a>>v>>b>>w>>t;
    ll most=(v-w)*t;
    ll need=fabs(a-b);
    if(most>=need) cout<<"YES\n";
    else cout<<"NO\n";
    return 0;
}


Measured memory_bytes: 3608
#第一回日本最強プログラマー学生選手権-予選- -B Kleene Inversion
"""
リストをk回繰り返したものの、転倒数の個数を求めよ
先ず純粋に与えられたリスト内での転倒数を求めた後、
それを1~k倍したものを足し合わせる
"""
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0
mod = 10**9+7

n,k = map(int,readline().split())
lst1 = list(map(int,readline().split()))
fall = 0
fall_al = 0
for i in range(n-1):
    for j in range(i+1,n):
        if lst1[i] > lst1[j]:
            fall += 1
lst1.sort(reverse=True)
for i in range(n-1):
    for j in range(i+1,n):
        if lst1[i] > lst1[j]:
            fall_al += 1

def reydeoro(n):
    return n*(n+1)//2
print((fall*k+fall_al*reydeoro(k-1))%mod)

Measured memory_bytes: 41580
#include <iostream>
using namespace std;
int main(void){
    int a,b;
    char op;
    while(true){
        cin >> a>>op>>b;
        if(op=='?')break;
        
        switch(op){
            case '+': cout << a+b << endl;break;
            case '-': cout << a-b << endl;break;
            case '*': cout << a*b << endl;break;
            case '/': cout << a/b << endl;break;
        }
    }
}

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

int n, p;

int main(){
//	cin.tie(0);
//	ios::sync_with_stdio(false);
	while(1){
		cin >> n >> p;
		if(n == 0 && p == 0) return 0;
		int a[n] = {};
		int t = p;
		int cnt = 0;
		while(1){
			if(t > 0){
				--t;
				++a[cnt%n];
				if(t == 0 && a[cnt%n] == p){
					cout << cnt%n << "\n";
					break;
				}
			}else{
				t += a[cnt%n];
				a[cnt%n] = 0;
			}
			++cnt;
		}
	}
}


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

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//#pragma GCC optimize("Ofast")
//1.0 * clock() / CLOCKS_PER_SEC

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

using namespace std;

const int NN = 1e6 + 7;
const int N = 2e5 + 7;
const int M = 20;
const int mod = 998244353;
const ll inf = 1e18 + 7;
const dl rf = 1e-14;

int n;
int d[N];
int t[4 * N];
pair < int , int > a[N];

int get( int x , int l , int r , int tl , int tr )
{
    if( tl > tr )return 0;
    if( l == tl && r == tr )return t[x];
    int m = (l + r) / 2;
    return max( get( x + x , l , m , tl , min( tr , m  ) ) ,
               get( x + x + 1 , m + 1 , r , max( tl , m + 1 ) , tr ) );
}

void upd( int x , int l , int r , int p , int val )
{
    if( l == r ){
        t[x] = val;
        return;
    }
    int m = (l + r) / 2;
    if( p <= m )upd( x + x , l , m , p , val );
    else upd( x + x + 1 , m + 1 , r , p , val );
    t[x] = max( t[x + x] , t[x + x + 1] );
}

void solve1()
{
    cin >> n;
    for( int i = 1; i <= n; i++ ){
        cin >> a[i].fi >> a[i].se;
    }
    sort( a + 1 , a + n + 1 );
    d[n + 1] = 1;
    for( int i = n; i >= 1; i-- ){
        int l = i , r = n;
        while( l < r ){
            int m = (l + r) / 2;
            if( a[m + 1].fi < a[i].fi + a[i].se )l = m + 1;
            else r = m;
        }
        auto x = get( 1 , 1 , n , i + 1 , l );
        x = max( x , i );
        upd( 1 , 1 , n , i , x );
        d[i] = d[i + 1] + d[x + 1];
        d[i] %= mod;
    }
    cout << d[1];
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0); srand(time(0));
    //freopen( "input.txt" , "r" , stdin );
    //freopen( "output.txt" , "w" , stdout );

    int cghf = 1;//cin >> cghf;
    while( cghf-- ){
        solve1();
    }
}


Measured memory_bytes: 5120
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
struct dice {
  int front, bottom, top;
  int d[4];

  void init(){
    top = 1;
    front = 2;
    bottom = 6;
    d[0] = front;
    d[1] = 3;
    d[2] = 5;
    d[3] = 4;
  }

  void roll(int id) {
    int tmp_t, tmp_b;
    if (id == 0) {
      tmp_t = d[2];
      tmp_b = d[0];
      d[0] = top;
      d[2] = bottom;
      top = tmp_t;
      bottom = tmp_b;
    } 
    if (id == 1) {
      tmp_t = d[3];
      tmp_b = d[1];
      d[1] = top;
      d[3] = bottom;
      top = tmp_t;
      bottom = tmp_b;
    }
    if (id == 2) {
      tmp_t = d[0];
      tmp_b = d[2];
      d[0] = bottom;
      d[2] = top;
      top = tmp_t;
      bottom = tmp_b;
    }
    if (id == 3) {
      tmp_t = d[1];
      tmp_b = d[3];
      d[1] = bottom;
      d[3] = top;
      top = tmp_t;
      bottom = tmp_b;
    }
  }

};

int main(){
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  rep(i,h) cin >> s[i];
  
  dice now;
  now.init();
  vector<vector<int>> ok(h, vector<int>(w,0));
  
  queue<pair<dice, P>> que;

  que.push(make_pair(now,make_pair(0, 0)));
  ok[0][0] = 1;

  while (!que.empty()) {
    auto p = que.front(); que.pop();
    
    for (int i = 0; i < 4; i++) {
      int x = p.second.first + dx[i], y = p.second.second + dy[i];
      if (x < 0 || y < 0 || x >= h || y >= w) continue;
      if (s[x][y] == '#') continue;
      auto tmp = p.first;
      tmp.roll(i);
      if (tmp.bottom != s[x][y] - '0') continue;
      if (ok[x][y]) continue;
      que.push(make_pair(tmp, make_pair(x, y)));
      ok[x][y] = 1;
    }
  }
  cout << (ok[h-1][w-1] ? "YES" : "NO") << endl;
  return 0;
} 


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

using namespace std;

int main() {
	int a, b;
	cin >> a >> b;
	if (a < 6) {
		cout << 0 << endl;
	}
	else if (a < 13) {
		cout << b/2 << endl;
	}
	else {
		cout << b << endl;
	}
	return 0;
}

Measured memory_bytes: 256
/*
これを入れて実行
g++ code.cpp
./a.out
 */

#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <tuple>
#include <iomanip>

using namespace std;
typedef long long ll;
typedef long double ld;

int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};

const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;

bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}

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

ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}

ll nCr(ll n, ll r){
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}

ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}

//-----------------------ここから-----------

int main(void){
    int n;
    cin >> n;
    vector<ld> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];

    ld ans = 0;
    for(int i = 0; i < n; i++){
        ans += (1 / a[i]);
    }

    cout << 1.0 / ans << endl;
}

Measured memory_bytes: 256
package main

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

func main() {
	sc.Split(bufio.ScanWords)
	k, a, b := nextInt(), nextInt(), nextInt()
	ans := 1
	yen := 0
	for ; k > 0; k-- {
		if a+2 >= b {
			ans++
		} else if yen > 0 {
			yen--
			ans += b
		} else if k == 1 {
			ans++
		} else if ans >= a {
			ans -= a
			yen++
		} else {
			ans++
		}
	}
	puts(ans)
	wt.Flush()
}

var (
	sc  = bufio.NewScanner(os.Stdin)
	rdr = bufio.NewReaderSize(os.Stdin, 1000000)
	wt  = bufio.NewWriter(os.Stdout)
)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(next(), 64)
	return f
}

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

func nextFloat64s(n int) []float64 {
	slice := make([]float64, n)
	for i := 0; i < n; i++ {
		slice[i] = nextFloat64()
	}
	return slice
}

func nextMega() string {
	buf := make([]byte, 0, 1000000)
	for {
		l, p, _ := rdr.ReadLine()
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}

func putf(format string, a ...interface{}) {
	fmt.Fprintf(wt, format, a...)
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}


Measured memory_bytes: 640
n = int(input())
H = list(map(int, input().split()))

DP = [10 ** 9] * n
DP[0] = 0

for i in range(1, n):
    DP[i] = min(DP[i], DP[i-1] + abs(H[i] - H[i-1]))
    if i > 1:
        DP[i] = min(DP[i], DP[i-2] + abs(H[i] - H[i-2]))
print(DP[-1])

Measured memory_bytes: 13976
N,M=map(int,input().split())
H=list(map(int,input().split()))
S=set()
for i in range(N):
  S.add(i+1)
for i in range(M):
  A,B=map(int, input().split())
  if H[A-1]>H[B-1] and B in S:
    S.remove(B)
  if H[A-1]<H[B-1] and A in S:
    S.remove(A)
  if H[A-1]==H[B-1]:
    if A in S:
      S.remove(A)
    if B in S:
      S.remove(B)
print(len(S))

Measured memory_bytes: 22452
#include<bits/stdc++.h>
using namespace std;
typedef long long  ll ;
typedef double db;
const double pi = 3.141592654;
#define pb         push_back
#define forab(i,a,b)       for(int i=(a);i<=(b);i++)
#define CIN	ios_base::sync_with_stdio(0); cin.tie(0)
#define pcase(z,x)     printf("Case %ld: %lld\n",z,x)
#define nw				"\n"


int main(void)
{
	CIN;
	ll tc,l,k,sum=0,x=0,y,z=0,m=1,n=0,ans=0;
	cin>>n;
	int arr[n];
	for(ll i=1;cin>>x;i++)
		arr[--x]=i;
	
	for(ll i=0;i<n;i++)
		cout<<arr[i]<<" ";

}


Measured memory_bytes: 3912
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MM 1000000000
#define MOD MM+7
#define MAX 10000
#define MAP 110
#define initial_value -1
#define Pair pair<int,int>
ll INF = 1e18;
int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, -1, 0, 1};
int main(){
    ll N,W; cin >> N >> W;
    ll w[110],v[110];
    ll dp[105][100100];
    for(ll i = 1; i <= N; i++){
        cin >> w[i] >> v[i];
        dp[i][0] = 0;
    }
    for(ll i = 0; i < N; i++){
        for(ll j = 0; j <= W; j++){
            dp[i+1][j] = dp[i][j];
            if(j >= w[i+1]){
                dp[i+1][j] = max(dp[i][j-w[i+1]]+v[i+1], dp[i+1][j]);
            }
        }
    }
    cout << dp[N][W] << endl;
}


Measured memory_bytes: 80128
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;

constexpr int mod = 1e9 + 7;

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

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

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

    int n, k, dp[100009] = {}, sum[100009] = {};
    dp[0] = 1;
    cin >> n >> k;

    rep(i, n) {
        int a;
        cin >> a;
        FOR(j, 1, k + 2) {
            sum[j] = sum[j - 1] + dp[j - 1];
            if(sum[j] >= mod) sum[j] -= mod;
        }
        rep(j, k + 1) {
            dp[j] = sum[j + 1] - sum[max(j - a, 0ll)];
            if(dp[j] < 0) dp[j] += mod;
        }
    }

    cout << dp[k] << endl;

    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(ll i = 0; i < n; i++)
const ll INF = 1LL << 60;

bool isPrime(int x){
    int i;
    if(x < 2) return 0;
    else if(x == 2) return 1;
    if(x % 2 == 0) return 0;
    for(i = 3; i * i <= x; i += 2) if(x % i == 0)return 0;
    return 1;
}

int main(){
    vector<int> sum(100001, 0);
    for(int i = 1; i <= 100000; i++){
        if(isPrime(i) == true && isPrime((i + 1)/2) == true && i%2 == 1){
            sum[i] = sum[i - 1] + 1;
        }else sum[i] = sum[i - 1];
    }
    int Q; cin >> Q;
    vector<int> ans;
    rep(i, Q){
        int l, r; cin >> l >> r;
        l--;
        ans.push_back(sum[r] - sum[l]);
    }
    rep(i, Q) cout << ans[i] << endl;
}


Measured memory_bytes: 4332
N,K=map(int, input().split())
s=[]
for i in range(K):
    d=int(input())
    a=list(map(int, input().split()))
    for j in range(len(a)):
        s+=[a[j]]
s=set(s)
#print(s)
s=list(s)
#print(s)
s.sort()
#print(s)
print(N-len(s))

Measured memory_bytes: 9188
#include<bits/stdc++.h>
using namespace std;
static const int MAX=200000;
int main(){

  int R[MAX],n;

  cin>>n;
  for(int i=0;i<n;i++) cin>>R[i];

  int maxv=-2000000000;

  int minv=R[0];

  for(int i=1;i<n;i++){
    maxv=max(maxv,R[i]-minv);
    minv=min(minv,R[i]);
  }

  cout<<maxv<<endl;

  return 0;
}



Measured memory_bytes: 3876
#include <bits/stdc++.h>
 
#define ll long long
 
using namespace std;
 
int a[16][16];
int n;
ll cost[1 << 16];
ll dp[1 << 16];
 
ll go(int gr, int mask) {
	
}
 
main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			scanf("%d", &a[i][j]);
		}
	}
	for (int mask = 0; mask < (1 << n); mask++) {
		vector < int > res;
		for (int j = 0; j < n; j++) {
			if ((mask >> j) & 1) {
				res.push_back(j);
			}
		}
		for (int i = 0; i < res.size(); i++) {
			for (int j = i + 1; j < res.size(); j++) {
				dp[mask] += a[res[i]][res[j]];
			}
		}
	}
	for (int mask = 0; mask < (1 << n); mask++) {
		for (int i = mask; i > 0; i = mask & (i - 1)) {
			dp[mask] = max(dp[mask], dp[mask ^ i] + dp[i]);
		}
	}
	cout << dp[(1 << n) - 1];
}

Measured memory_bytes: 768
#include <iostream>

using namespace std;

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

    cin >> a >> b >> c;

    if (a == b)
    {
        cout << c << endl;
    }

    if (b == c)
    {
        cout << a << endl;
    }

    if (c == a)
    {
        cout << b << endl;
    }

    return 0;
}

Measured memory_bytes: 256
n = int(input())
R = []
for i in range(n):
    R.append(int(input()))

maxv = -1000000000
minv = R[0]

for i in range(1,n):
    if maxv < R[i] - minv:
        maxv = R[i] - minv
    if minv > R[i]:
        minv = R[i]

print(maxv)


Measured memory_bytes: 13584
#include <iostream>

int main()
{
  int N;
  std::string S;
  int K;
  std::cin >> N >> S >> K;
  char P;
  P=S[K-1];
  for(int i=0; i<N; i++){
   	if(S[i] != P){
      std::cout << "*";
    }else{
     std::cout << S[i];
    }
  }
  std::cout << std::endl;
  return 0;
}

Measured memory_bytes: 256
#include<functional>
#include<algorithm>
#include<iostream>
#include<iomanip>
#include<cstring>
#include<cstdlib>
#include<utility>
#include<string>
#include<cstdio>
#include<vector>
#include<bitset>
#include<cmath>
#include<ctime>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
using namespace std;
const int inf=2147483647,dx[]={-1,0,1,0},dy[]={0,-1,0,1};// 上 左 下 右
const int N=100005,M=1000005,K=200005,mod=1000000007;
const long long llinf=9223372036854775807ll;
//int & long long
//n种冰箱m种微波炉k个优惠在一起买xi冰箱yi微波炉时用-ci yen 价格分别 ai,bi 
int n,m,k,a[N],b[N],x[N],y[N],c[N],mina,minb,ans,mon;
int main(){
	ans=mina=minb=9999999;
	cin>>n>>m>>k;
	for(int i=1;i<=n;i++)
		cin>>a[i],mina=min(mina,a[i]);
	for(int i=1;i<=m;i++)
		cin>>b[i],minb=min(minb,b[i]);
	for(int i=1;i<=k;i++)
	{
		cin>>x[i]>>y[i]>>c[i];
		mon=a[x[i]]+b[y[i]]-c[i];
		ans=min(ans,mon);
	}
	ans=min(ans,mina+minb);
	cout<<ans;
	return 0;
}

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

int main(){
    string s; cin >> s;
    
    if(s[0] == s[1] && s[1] == s[2]) cout << "No" << endl;
    else cout << "Yes" << endl;

    return 0;
}

Measured memory_bytes: 256
A,B = map(int,input().split())
grid = [['#' for j in range(100)] for i in range(50)] + [['.' for j in range(100)] for i in range(50)]

for i in range(A-1):
    q,r = divmod(i,50)
    grid[q*2][r*2] = '.'
    
for i in range(B-1):
    q,r = divmod(i,50)
    grid[-1-q*2][-1-r*2] = '#'
    
print(100,100)

for g in grid:
    print(''.join(g))

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#ifdef DEMETRIO
#define deb(...) fprintf(stderr,__VA_ARGS__)
#define deb1(x) cerr << #x << " = " << x << endl
#else
#define deb(...) 0
#define deb1(x) 0
#endif
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ThxDem=b;i<ThxDem;++i)
#define SZ(x) ((int)(x).size())
#define mset(a,v) memset(a,v,sizeof(a))
#define mcpy(a,b) memcpy(a,b,sizeof(a))
using namespace std;
typedef long long ll;

int n;
map<ll,int> c;
set<ll> v;
vector<ll> d;

int main(){
	scanf("%d",&n);
	fore(_,0,n){
		ll a;
		scanf("%lld",&a);
		c[a]++;
		v.insert(a);
	}
	ll r=0;
	for(int i=30;i;--i){
		ll t=1LL<<i;
		d.clear();
		for(auto p:c)if(p.fst>=t||!p.snd)d.pb(p.fst);
		for(ll x:d)v.erase(x),c.erase(x);
		for(ll x:v)if(x<=t-x&&v.count(t-x)){
			if(x==t-x)r+=c[x]/2;
			else {
				ll a=min(c[x],c[t-x]);
				r+=a;
				c[x]-=a;c[t-x]-=a;
			}
		}
	}
	printf("%lld\n",r);
	return 0;
}

Measured memory_bytes: 23288
import java.util.*; import java.io.*; import java.math.*;
public class Main{
	//Don't have to see. start------------------------------------------
	static class InputIterator{
		ArrayList<String> inputLine = new ArrayList<String>(1024);
		int index = 0; int max; String read;
		InputIterator(){
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			try{
				while((read = br.readLine()) != null){
					inputLine.add(read);
				}
			}catch(IOException e){}
			max = inputLine.size();
		}
		boolean hasNext(){return (index < max);}
		String next(){
			if(hasNext()){
				return inputLine.get(index++);
			}else{
				throw new IndexOutOfBoundsException("There is no more input");
			}
		}
	}
	static HashMap<Integer, String> CONVSTR = new HashMap<Integer, String>();
	static InputIterator ii = new InputIterator();//This class cannot be used in reactive problem.
	static PrintWriter out = new PrintWriter(System.out);
	static void flush(){out.flush();}
	static void myout(Object t){out.println(t);}
	static void myerr(Object t){System.err.print("debug:");System.err.println(t);}
	static String next(){return ii.next();}
	static boolean hasNext(){return ii.hasNext();}
	static int nextInt(){return Integer.parseInt(next());}
	static long nextLong(){return Long.parseLong(next());}
	static double nextDouble(){return Double.parseDouble(next());}
	static ArrayList<String> nextStrArray(){return myconv(next(), 8);}
	static ArrayList<String> nextCharArray(){return myconv(next(), 0);}
	static ArrayList<Integer> nextIntArray(){
		ArrayList<String> input = nextStrArray(); ArrayList<Integer> ret = new ArrayList<Integer>(input.size());
		for(int i = 0; i < input.size(); i++){
			ret.add(Integer.parseInt(input.get(i)));
		}
		return ret;
	}
	static ArrayList<Long> nextLongArray(){
		ArrayList<String> input = nextStrArray(); ArrayList<Long> ret = new ArrayList<Long>(input.size());
		for(int i = 0; i < input.size(); i++){
			ret.add(Long.parseLong(input.get(i)));
		}
		return ret;
	}
	static String myconv(Object list, int no){//only join
		String joinString = CONVSTR.get(no);
		if(list instanceof String[]){
			return String.join(joinString, (String[])list);
		}else if(list instanceof ArrayList){
			return String.join(joinString, (ArrayList)list);
		}else{
			throw new ClassCastException("Don't join");
		}
	}
	static ArrayList<String> myconv(String str, int no){//only split
		String splitString = CONVSTR.get(no);
		return new ArrayList<String>(Arrays.asList(str.split(splitString)));
	}
	public static void main(String[] args){
		CONVSTR.put(8, " "); CONVSTR.put(9, "\n"); CONVSTR.put(0, "");
		solve();flush();
	}
	//Don't have to see. end------------------------------------------
	static void solve(){//Here is the main function
      ArrayList<Integer> one = nextIntArray();
      int A = one.get(0);
      int B = one.get(1);
      int C = one.get(2);
      int D = one.get(3);
      if(A + B == C + D){
        myout("Balanced");
      }else if(A + B < C + D){
        myout("Right");
      }else{
        myout("Left");
      }
	}
	//Method addition frame start



	//Method addition frame end
}


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


const ll INF = 1e16;
const ll mod = 1e9 + 7;
//const ll MOD = 998244353;

ll DPFibonacci(int x){
  int dp[100010] = {0};
  dp[0] = 0;
  dp[1] = 1;
  for(int i = 2; i < x+1; i++){
    dp[i] = (dp[i-1] + dp[i-2]);
    dp[i] %= mod;
  }
  return dp[x];
}

int main() {
  ll n, m;
  cin >> n >> m;
  vector<ll> a(m+1);
  rep(i,m+1) cin >> a[i];
  a[m]=n+1;
  ll ans = 1;
  int pos=0;
//  cout << a[0] << endl;
  for (ll i = 0; i < m+1; i++) {
//    cout << a[i] << ' ' <<pos << endl;
    if (pos -a[i] ==0) {
      cout << 0 << endl;
      return 0;
    }
    else if(a[i]-pos ==1||a[i]-pos ==2) ans = ans;
    else{
      int dif_a=a[i]-pos;
//      cout << dif_a << endl;
//      cout << DPFibonacci(dif_a) << endl;
      ans = ans* DPFibonacci(dif_a);
      ans %=mod;
//      cout << ans << endl;
    }
    pos=a[i]+1;
//    cout << ans << endl;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int,int>;
#define rep(i,n) for(int i=0; i<(int)n; i++)
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてから使う
#define INF 2147483647
#define LLINF 9223372036854775807LL

int main(){
  int k; cin >> k;
  rep(i,k) cout << "ACL";
  cout << endl;
}

Measured memory_bytes: 3384
n=int(input())
def fact(n):
  fct=[]
  b,e=2,0
  while b*b<=n:
    while n%b==0:
      n=n//b
      e=e+1
    if e>0:
      fct.append([b,e])
    b,e=b+1,0
  if n>1:
    fct.append([n,1])
  return fct

x=fact(n)
ans=0
for i in range(len(x)):
  for j in range(1,1000):
    if x[i][1]>=j:
      ans+=1
      x[i][1]-=j
print(ans)

Measured memory_bytes: 63696
import sys
import math


def input():
    return sys.stdin.readline().rstrip()


def main():
    N =int(input())
    v = list(map(int,input().split()))
    c = list(map(int,input().split()))
    ans =0
    for i in range(N):
        if v[i] >c[i]:
            ans +=v[i]-c[i]
    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 61948
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <iomanip>
using namespace std;
typedef long long LL;
typedef pair<int,int> P;

unsigned dist[3001];
int N,M,K;
vector<P> path[3001];
int main() {
	memset(dist,-1,sizeof(dist));
	cin >> N >> M >> K;
	for(int i=0;i<M;i++){
		int a,b,l;
		cin >> a >> b >> l;
		path[a].push_back(P(b,l));
		path[b].push_back(P(a,l));
	}
	priority_queue<P,vector<P>, greater<P> > q;
	for(int i=0;i<K;i++){
		int s;
		cin >> s;
		q.push(P(0,s));
		dist[s]=0;
	}
	while(q.size()){
		double d=q.top().first;
		int i=q.top().second;
		q.pop();
		if(dist[i]<d)continue;
		for(P p:path[i]){
			if(d+p.second<dist[p.first]){
				dist[p.first]=d+p.second;
				q.push(P(d+p.second,p.first));
			}
		}
	}
	unsigned ret=0;
	for(int a=1;a<=N;a++){
		for(auto p:path[a]){
			int b=p.first;
			int d=p.second;
			if(dist[b]>=dist[a]){
				ret=max(ret,(dist[b]-dist[a]+d+1)/2+dist[a]);
			}
		}
	}
	cout << ret << endl;
}

Measured memory_bytes: 4192
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < (int)(n); i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
using ll = long long;

template<int M>
class ModInt {
   public:
    ll value;
    constexpr ModInt(ll v = 0) { value = v % M; if (value < 0) value += M; }
    constexpr ModInt pow(ll n) const { if (!n) return 1; ModInt a = pow(n >> 1); a *= a; if (n & 1) a *= *this; return a; }
    constexpr ModInt inv() const { return this->pow(M - 2); }
    constexpr ModInt operator + (const ModInt &rhs) const { return ModInt(*this) += rhs; };
    constexpr ModInt operator - (const ModInt &rhs) const { return ModInt(*this) -= rhs; };
    constexpr ModInt operator * (const ModInt &rhs) const { return ModInt(*this) *= rhs; };
    constexpr ModInt operator / (const ModInt &rhs) const { return ModInt(*this) /= rhs; };
    constexpr ModInt &operator += (const ModInt &rhs) { value += rhs.value; if (value >= M) value -= M; return *this; };
    constexpr ModInt &operator -= (const ModInt &rhs) { value -= rhs.value; if (value <  0) value += M; return *this; };
    constexpr ModInt &operator *= (const ModInt &rhs) { value = value * rhs.value % M; return *this; };
    constexpr ModInt &operator /= (const ModInt &rhs) { return (*this) *= rhs.inv(); };
    constexpr bool operator == (const ModInt &rhs) { return value == rhs.value; }
    constexpr bool operator != (const ModInt &rhs) { return value != rhs.value; }
    friend ostream &operator << (ostream &os, const ModInt &rhs) { os << rhs.value; return os; }
};

using mint = ModInt<MOD>;

int main() {
    int N; cin >> N;
    vector<int> T(N), A(N);
    REP(i, 0, N) cin >> T[i];
    REP(i, 0, N) cin >> A[i];

    vector<int> X(N);
    int prev = 0;
    for (int i = N - 1; i >= 0; i--) {
        if (A[i] != prev) {
            X[i] = A[i];
            prev = A[i];
        }
    }

    mint ans = 1; prev = 0;;
    REP(i, 0, N) {
        if (T[i] != prev) {
            if (X[i] == 0) {
                X[i] = T[i];
            } else if (X[i] != T[i]) {
                cout << 0 << endl;
                return 0;
            }
            prev = T[i];
        } else {
            if (X[i] == 0) {
                // cout << cur << endl;
                ans *= min(A[i], T[i]);
            } else if (X[i] > T[i]) {
                cout << 0 << endl;
                return 0;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

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

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

    vector<int> a(N + 1, 0);
    for (int i = 1; i <= N; i++)
    {
        cin >> a[i];
    }

    vector<int> ans(N + 1, 0);
    int current = N;
    for (int i = 2; i <= N; i++)
    {
        for (; current > N / i; current--)
        {
            int tmp = 0;
            for (int j = 1; j * current <= N; j++)
            {
                tmp += ans[current * j];
            }
            tmp %= 2;
            // cout << current << " " << tmp << endl;

            if (tmp != a[current])
            {
                ans[current] = 1;
            }
            // for (int x : ans)
            // {
            //     cout << x << " ";
            // }
            // cout << endl;
        }
    }

    int sum = 0;
    vector<int> ans_idx;
    for (int i = 1; i <= N; i++)
    {
        if (ans[i])
        {
            sum ^= 0x1;
            ans_idx.push_back(i);
        }
    }

    if (sum != a[1])
    {
        ans_idx.push_back(1);
        ans[1] = 1;
    }

    // for (int x : ans)
    // {
    //     cout << x << " ";
    // }
    // cout << endl;
    cout << ans_idx.size() << endl;
    for (int x : ans_idx)
    {
        cout << x << " ";
    }
    cout << endl;
}


Measured memory_bytes: 3064
//#pragma GCC optimize(2)
#include<set>
#include<map>
#include<stack>
#include<cmath>
#include<queue>
#include<cstdio>
#include<vector>
#include<climits>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define LL long long
using namespace std;
int read(){
	bool f=0;int x=0;char c=getchar();
	while(c<'0'||'9'<c){if(c=='-')f=1;c=getchar();}
	while('0'<=c&&c<='9') x=(x<<3)+(x<<1)+(c^48),c=getchar();
	return !f?x:-x;
}
#define MAXN 200
#define INF 0x3f3f3f3f
int n,dep[MAXN+5];
vector<int> G[MAXN+5];
int BFS(int S){
	queue<int> Q;
	int ret=0;
	memset(dep,0,sizeof(dep));
	dep[S]=1,Q.push(S);
	while(!Q.empty()){
		int u=Q.front();Q.pop();
		ret=max(ret,dep[u]);
		for(int i=0;i<int(G[u].size());i++){
			int v=G[u][i];
			if(dep[v]){
				if(dep[v]%2==dep[u]%2)
					puts("-1"),exit(0);
				continue;
			}
			dep[v]=dep[u]+1,Q.push(v);
		}
	}
	return ret;
}
char S[MAXN+5];
int main(){
	n=read();
	for(int i=1;i<=n;i++){
		scanf("%s",S+1);
		for(int j=1;j<=n;j++)
			if(S[j]=='1')
				G[i].push_back(j);
	}
	int ans=0;
	for(int i=1;i<=n;i++)
		ans=max(ans,BFS(i));
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

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

  int ans = 0;
  for (int i = 0; i < n; ++i) {
    if (a[i] >= 0) {
      if (a[a[i]] == i) {
        ++ans;
        a[a[i]] = -1;
        a[i] = -1;
      }
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
#include <random>
#include <string>
#include <cmath>
#include <sstream>
#include <istream>
#include <iomanip>
#include <typeinfo>
#include <stack>
#include <map>

using namespace std;
typedef long long ll;


int main(){

    ll N;
    string S;
    cin >> N >> S;
    //終わりだょ
    //S.push_back('*');

    stack<char > st;
    for(ll i = 0; i < N; i++){
        if(st.empty()){
            st.push(S[i]);
            continue;
        }
        if(S[i] == '('){
            st.push(S[i]);
        }

        if(S[i] == ')'){
            if(st.top() == '('){
                st.pop();
            }else{
                st.push(S[i]);
            }
        }   
        
    }

    map<char, ll> mp;
    
    while(!st.empty()){
        mp[st.top()]++;
        st.pop();
    }

    string ans = "";
    for(ll i = 0; i < mp[')']; i++){
        ans += '(';
    }

    ans += S;

    for(ll i = 0; i < mp['(']; i++){
        ans += ')';
    }  

    cout << ans << endl;

}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

long long pow5(long long x) {
  long long res = 1;
  for (int i = 0; i < 5; i++) {
    res *= x;
  }
  return res;
}

int main() {
  long long x;
  cin >> x;
  for (int a = 0; a <= 500; a++) {
    for (int b = -500; b <= 500; b++) {
      long long tmp = pow5(a) - pow5(b);
      if (tmp == x) {
        cout << a << ' ' << b << endl;
        return 0;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 3636