akhauriyash/Code-Regression huggingface dataset:
# エネスとテレスのふるい
MAX = int(10e5)
is_prime = [True] * MAX
is_prime[0], is_prime[1] = False, False
for i in range(2, MAX):
    if not is_prime[i]:
        continue
    for j in range(i * 2, MAX, i):
        is_prime[j] = False

# 2017-like 数かどうか
a = [0] * MAX
for i in range(MAX):
    if i % 2 == 0:
        continue
    if is_prime[i] and is_prime[(i + 1) // 2]:
        a[i] = 1

# 累積和
s = [0] * (MAX + 1)
for i in range(MAX):
    s[i + 1] = s[i] + a[i]

# クエリ処理
Q = int(input())
for i in range(Q):
    l, r = [int(i) for i in input().split()]
    print(s[r + 1] - s[l])


Measured memory_bytes: 57620
#include <bits/stdc++.h>
// #include <atcoder/all>
using namespace std;
// using namespace atcoder;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"
template<class T> void chmax(T &a, const T b){ a = max(a, b); }
template<class T> void chmin(T &a, const T b){ a = min(a, b); }

struct BinomialCoefficient {
    BinomialCoefficient() {}
    BinomialCoefficient(int n) : fac(n + 2), finv(n + 2), inv(n + 2) {
        fac[0] = fac[1] = 1;
        finv[0] = finv[1] = 1;
        inv[1] = 1;
        for (int i = 2; i <= n; i++) {
            fac[i] = fac[i - 1] * i % mod;
            inv[i] = mod - inv[mod % i] * (mod / i) % mod;
            finv[i] = finv[i - 1] * inv[i] % mod;
        }
    }
    
    long long factorial(int n) {
        return fac[n];
    }
    
    long long combination(int n, int r) {
        if ((n < r) || (n < 0) || (r < 0)) return 0;
        return fac[n] * (finv[r] * finv[n - r] % mod) % mod;
    }
    
    long long permutation(int n, int r) {
        if ((n < r) || (n < 0) || (r < 0)) return 0;
        return fac[n] * finv[n - r] % mod;
    }
    
private:
    int mod = 1000000007;
    vector<long long> fac, finv, inv;
};

struct mint {
    constexpr static int mod = 1000000007;
    long long x;
    mint(long long x = 0) : x((x % mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
    mint operator+(const mint a) const { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint pow(long long t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }
    mint inv() const { return pow(mod - 2); }
    mint& operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) const { return mint(*this) /= a; }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll s;
    cin >> s;
    ll ms = s / 3;
    if (ms == 0) {
        cout << 0 << endl;
        return 0;
    }
    BinomialCoefficient bc(2 * s);
    mint ans = 1;
    reps(i, 2, ms + 1) {
        ll rem = s - 3 * i;
        mint tmp = bc.combination(rem + i - 1, rem);
        ans += tmp;
    }
    cout << ans.x << endl;
    return 0;
}


Measured memory_bytes: 3704
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define rrep(i, n) for (ll i = n - 1; i >= 0; i--)
#define Rep(i, r, n) for (ll i = r; i < n; i++)
#define RRep(i, r, n) for (ll i = n - 1; i <= r; i--)
#define debug(x) cout << #x << ' ' << '=' << ' ' << (x) << endl;
#define fs first
#define sc second
#define int long long
#define pb push_back
const int dx[] = {0, -1, 0, 1};
const int dy[] = {1, 0, -1, 0};
const int MOD = (1000000007);
//const int MOD = (998244353);
//const int INF = (1 << 30)-1;
const int INF = (1LL << 60)-1;
const double EPS = (1 >> 30);

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

using Graph = vector<vector<pair<int, int>>>;

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    //---------------------------------------------
    
    int n,k;
    cin>>n>>k;
    if(n%2==0){
        if(k<=n/2){
            cout<<"YES"<<endl;
        }
        else{
            cout<<"NO"<<endl;
        }
    }
    else{
        if(k<=n/2+1){
            cout<<"YES"<<endl;
        }
        else{
            cout<<"NO"<<endl;
        }
    }
    
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define re return
typedef vector<int> vi;
typedef long long ll;
typedef pair<int, int> pii;
int n,t;
int a[200010];
int main() { 
    //freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	cin>>n>>t;
	int ans=0;
	cin>>a[0];
	for(int i=1;i<n;i++){
		cin>>a[i];
		ans+=min(t,a[i]-a[i-1]);
	}
	ans+=t;
	cout<<ans<<endl;
    return 0; 
}

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

int main(){
  int h, w;
  char c;
  int ans[101][101];

  cin >> h >> w;

  for(int i=0; i<=h; i++) {
    for(int j=0; j<=w; j++) {
      ans[i][j] = -1;
    }
  }

  for(int i=1; i<=h; i++) {
    for(int j=1; j<=w; j++) {
      cin >> c;
      if( c == 'c' ) ans[i][j] = 0;
      else if( ans[i][j-1] >= 0 ) ans[i][j] = ans[i][j-1]+1;
      else ans[i][j] = -1;
    }
  }

  for(int i=1; i<=h; i++) {
    for(int j=1; j<=w-1; j++) {
      cout << ans[i][j] << ' ';
    }
    cout << ans[i][w] << endl;
  }
}

Measured memory_bytes: 1200
/**
*   Bismillahir Rahmanir Rahim.
*   Imtiaz_rafi
*   PCIU, CHITTAGONG
**/
#include<bits/stdc++.h>
using namespace std;
#define speed ios::sync_with_stdio(0);cin.tie(0);
#define filein freopen ("input.txt", "r", stdin)
#define fileout freopen ("output.txt", "w", stdout)
#define rep(i,a) for(ll i=0;i<a;i++)
#define rep1(i,begin,end) for(ll i=begin;i<=end;i++)
#define mem(dp,i) memset(dp,i,sizeof(dp))
#define all(v)   v.begin(),v.end()
#define pb push_back
#define pf push_front
#define mp make_pair
#define pi acos(-1)
// bitshift (1LL<<(3)) *2^3
typedef long long int ll;
typedef vector<ll>vi;
typedef map<ll,ll>m;
typedef map<char,ll>mc;
typedef set<ll>st;
typedef set<char>sc;
ll dx[] ={-1,+1,0,0,+1,-1,+1,-1};
ll dy[] ={0,0,-1,+1,+1,+1,-1,-1};
const ll mx = 1e5+123;
bool vis[mx];
vi adj[mx];
ll a,b[mx][4],dp[mx][4];
ll solve(ll i,ll j)
{
    if(i>a) return 0;
    if(dp[i][j]!=-1) return dp[i][j];
    ll x=0;
    for(ll k=1;k<=3;k++)
    {
        if(j!=k)
        x=max(x,b[i][k]+solve(i+1,k));


        //cout<<"x "<<x<<endl;
    }
    return dp[i][j]=x;
}
int main()
{
    speed;
    cin>>a;
    for(ll i=1;i<=a;i++)
    {
        cin >> b[i][1] >> b[i][2] >> b[i][3];
    }
    mem(dp,-1);
    cout<<solve(1,0)<<endl;
}



Measured memory_bytes: 20036
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>
#include <fstream>
#include <functional>
#include <unordered_map>
#include <unordered_set>
#define endl '\n'
//#define ll long long
#define mod 1000000007
#define NCONS 200001
//#define NCONS 100001
//#define NCONS 1001
//#define NCONS 101
#define MCONS 2001
#define LIMIT 1000000000
#define TRUE 1
#define FALSE 0
#define toRadian(degree) ((degree) * (M_PI / 180.))
#define toDegree(radian) ((radian) * (180. / M_PI))
using namespace std;
struct Point{int x; int y;};
struct PPoint{Point x; Point y;};
typedef long long ll;
ll gcd(ll a, ll b) { if(a < b) swap(a, b); if(b <= 0) return a; return gcd(b, a % b); }

struct State{int idx; ll dist;};

int N, M, S, T;
vector<int> adj[100001];
bool visited[100001][3];
ll dist[100001][3];


void bfs()
{
    queue<State> quu; quu.push(State{S, 0});// visited[S][0] = true;
    dist[S][0] = 0;
    
    while(!quu.empty())
    {
        auto cur = quu.front(); quu.pop();
        
        for(int i = 0; i < adj[cur.idx].size(); i++)
        {
            auto nxt = adj[cur.idx][i];
            auto nxt_dist = cur.dist + 1;
            
            
            if(nxt_dist >= dist[nxt][nxt_dist % 3]) continue;
            
            dist[nxt][nxt_dist % 3] = min(dist[nxt][nxt_dist % 3], nxt_dist);
     //       cout << nxt << " " << nxt_dist << " " << nxt_dist % 3 << endl;
            
            
            quu.push(State{nxt, nxt_dist});
    //        visited[nxt][nxt_dist % 3] = true;
        }
    }
}

int main(void)
{
    cin.tie(NULL); ios_base::sync_with_stdio(false);
    cin >> N >> M;
    while(M--)
    {
        int u, v; cin >> u >> v; adj[u].push_back(v);
    }
    cin >> S >> T;
    
    for(int i = 0; i <= N; i++)
    {
        for(int j = 0; j < 3; j++)
            dist[i][j] = LLONG_MAX;
    }
    
    bfs();
    
    if(dist[T][0] == LLONG_MAX)
        cout << -1 << endl;
    else
        cout << dist[T][0] / 3 << endl;
    
    
    
    return 0;
}


Measured memory_bytes: 8320
#include<iostream>
#include<cstdio>
#define MN 3000
using namespace std;
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int n,head[MN+5],cnt=0,f[MN+5],a[MN+5];
struct edge{int to,next;}e[MN*2+5];
inline void ins(int f,int t)
{
	e[++cnt]=(edge){t,head[f]};head[f]=cnt;
	e[++cnt]=(edge){f,head[t]};head[t]=cnt;	
}
void dfs(int x,int fa)
{
	f[x]=0;
	for(int i=head[x];i;i=e[i].next)
		if(e[i].to!=fa&&a[e[i].to]<a[x])
			dfs(e[i].to,x),f[x]|=!f[e[i].to];	
}
int main()
{
	n=read();
	for(int i=1;i<=n;++i) a[i]=read();
	for(int i=1;i<n;++i) ins(read(),read());
	for(int i=1;i<=n;++i) dfs(i,0),f[i]?printf("%d ",i):0;
	return 0;
}



Measured memory_bytes: 384
import java.util.Scanner;

public class Main{
   public static void main(String[] args){
     Scanner scan = new Scanner(System.in);
     int num1 = scan.nextInt();
     int answer = 0;
     int i, j;
     
     for( i=1 ; i < 10 ; i++ ){
       for( j=1 ; j < 10 ; j++ ){
         if( i * j == num1 ){
           answer = 1;
           break;
         }
       }
     }
     if( answer == 1 )
       System.out.println("Yes");
     else
       System.out.println("No");
   }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<ll,ll> P;

void Main() {
  ll a,b,c;
  cin >> a >> b >> c;
  if(a+b+c>=22) pr("bust");
  else pr("win");
}

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


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int main(void)
{
	int A,B,C,D,E,all1;
	scanf("%d %d %d %d %d",&A,&B,&C,&D,&E);
	if(A<0)
	{
		all1=A*(-C);
		A=0;
	}
	if(A==0){all1+=D;}
	all1+=(B-A)*E;
	printf("%d\n",all1);
	return 0;
}
//7:18.047clear


Measured memory_bytes: 3160
#include<bits/stdc++.h>
using namespace std;
#define inf (int)1e9
#define INF (int)1e13
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back

int n,a,b,c;
int ans=inf;
vector<int> w;

void g(vector<int> v,int m,int s){
 
 
  rep(i,m){
    rep(j,m){
      rep(k,m){
        if(i==j||j==k||k==j) continue;
        ans=min(ans,s+abs(v[i]-a)+abs(v[j]-b)+abs(v[k]-c));
      }
    }
  }
}

void f(vector<int> v,int m,int s){
  if(m<3) return;

  g(v,m,s);
  rep(i,m){
    FOR(j,i+1,m){
      w.clear();
      rep(k,m){
        if(k==i||k==j) continue;
        w.PB(v[k]);
      }
      w.PB(v[i]+v[j]);
      f(w,m-1,s+10);
    }
  }
}

int main(){
  cin>>n>>a>>b>>c;
  vector<int> v;
  rep(i,n){
    int l;
    cin>>l;
    v.PB(l);
  }

  f(v,n,0);

  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <stack>
#include <queue>
#include <array>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <random>
#include <chrono>
#include <utility>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <sstream>
#include <assert.h>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>

using namespace std;
struct _ { ios_base::Init i; _() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); } } _;

const long long maxn = 3e5;

long long n, k;
vector<long long> a(maxn + 1, 0);
vector<long long> dp(maxn + 1, 0);
vector<long long> tree(4 * maxn + 1, 0); //update->[l,r]+=inc, query->sum([l,r])
// vector<long long> lazy(2 * maxn, 0);

// #ifdef HOME
// void prlong long(long long sze) {
// 	cerr << "-------------------------------------------------------------------------------------------------\n";
// 	cerr << "{ind, tree[ind], lazy[ind]}\n";

// 	for (long long i = 1; i <= sze; i++) {
// 		cerr << "{" << i << ", " << tree[i] << ", " << lazy[i] << "} ";
// 		if (__builtin_popcount(i + 1) == 1) cerr << endl;
// 	}
// 	cerr << "\n-------------------------------------------------------------------------------------------------\n";
// }
// #else
// void prlong long(long long sze) {}
// #endif

long long merge(long long a, long long b) {
	return max(a, b);
}

// void push(long long l, long long r, long long ind) {
// 	if (lazy[ind] != 0) {
// 		tree[ind] += (r - l + 1) * lazy[ind];

// 		if (l != r) {
// 			lazy[2 * ind] += lazy[ind];
// 			lazy[2 * ind + 1] += lazy[ind];
// 		}
// 		else a[l] = tree[ind];

// 		lazy[ind] = 0;
// 	}
// }

// void build(long long l, long long r, long long ind) {
// 	if (l == r) {
// 		tree[ind] = a[l];
// 		return;
// 	}

// 	long long mid((l + r) >> 1);
// 	build(l, mid, 2 * ind);
// 	build(mid + 1, r, 2 * ind + 1);
// 	tree[ind] = merge(tree[2 * ind], tree[2 * ind + 1]);
// }

void update(long long ui, long long uv, long long l, long long r, long long ind) {
	// push(l, r, ind);

	if (l == r) {
		if (l == ui) {
			tree[ind] = max(tree[ind], uv);
		}
		return;
	}

	long long mid((l + r) >> 1);
	if (ui <= mid) update(ui, uv, l, mid, 2 * ind);
	else update(ui, uv, mid + 1, r, 2 * ind + 1);
	tree[ind] = merge(tree[2 * ind], tree[2 * ind + 1]);
}

long long query(long long ql, long long qr, long long l, long long r, long long ind) {
	// push(l, r, ind);

	if (qr < l or r < ql) return 0;

	if (ql <= l and r <= qr) return tree[ind];

	long long mid((l + r) >> 1);
	return merge(query(ql, qr, l, mid, 2 * ind), query(ql, qr, mid + 1, r, 2 * ind + 1));
}


int main() {

	cin >> n >> k;
	for (long long i = 1; i <= n; i++) cin >> a[i];

	for (long long i = 1; i <= n; i++) {
		dp[i] = 1 + query(max(0ll, a[i] - k), min(maxn, a[i] + k), 0, maxn, 1);
		update(a[i], dp[i], 0, maxn, 1);
	}

	cout << *max_element(dp.begin(), dp.end());

	return 0;
}

Measured memory_bytes: 17136
# True -> S or o
# False -> W or x

N = int(input())
s = [x=="o" for x in input()]

def is_true(L1:bool, L2:bool):
    L = [None] * N

    L[0] = L1
    L[1] = L2
    for i in range(1,N):
        if i == N-1:
            if s[i]: # o
                tmp = L[i-1] if L[i] else (not L[i-1])
            else: # x
                tmp = L[i-1] if not L[i] else (not L[i-1])
            if tmp == L[0]:
                continue
            else:
                return (False, L)

        if s[i]: # o
            L[i+1] = L[i-1] if L[i] else (not L[i-1])
        else: # x
            L[i+1] = L[i-1] if not L[i] else (not L[i-1])
    
    if s[0]: # o
        if L[0]: # 羊
            return (True, L) if L[-1] == L[1] else (False, L)
        else: # 狼
            return (True, L) if L[-1] != L[1] else (False, L)
    else: # x
        if L[0]: # 羊
            return (True, L) if L[-1] != L[1] else (False, L)
        else: # 狼
            return (True, L) if L[-1] == L[1] else (False, L)

def main():
    for L1 in (True, False):
        for L2 in (True, False):
            flag, tmp = is_true(L1, L2)
            if not flag:
                continue
            else:
                ans = ""
                for x in tmp:
                    ans += "S" if x else "W"
                print(ans)
                exit()
    
    print(-1)

if __name__ == "__main__":
    main()

Measured memory_bytes: 5532
C=input()
c=["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"]
for i in range(30):
    if C==c[i]:
        ans=c[i+1]
        break
print(ans)

Measured memory_bytes: 3060
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
 
using namespace std;
 
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P > PP;
 
int tx[] = {0,1,0,-1};
int ty[] = {-1,0,1,0};
 
static const double EPS = 1e-8;

class State {
public:
  int _used;
  int _archives;
  State(int used,int archives) :
    _used(used), _archives(archives) {}
  bool operator <(const State& s) const {
    return _archives < s._archives;
  }
  bool operator >(const State& s) const {
    return _archives > s._archives;
  }
};

int open_space[1<<14];
int required_space[1<<14];
int dp[1<<14];

int main(){
  int total_files;
  int init_disk_space;
  while(~scanf("%d %d",&total_files,&init_disk_space)){
    if(total_files == 0 && init_disk_space == 0) break;

    vector<int> diff;
    vector<int> req;
    for(int file_i = 0; file_i < total_files; file_i++){
      int uncompressed,compressed;
      scanf("%d %d",&uncompressed,&compressed);
      diff.push_back(uncompressed - compressed);
      req.push_back(compressed);
    }
    
    memset(open_space,0,sizeof(open_space));
    memset(required_space,0,sizeof(required_space));
    memset(dp,0x3f,sizeof(dp));

    for(int S = 0; S <= (1<<total_files) - 1; S++){
      int open_sum = 0;
      int req_sum = 0;
      for(int file_i = 0; file_i < total_files; file_i++){
        if(S & (1 << file_i)){
          open_sum += diff[file_i];
          req_sum += req[file_i];
        }
      }
      open_space[S] = open_sum;
      required_space[S] = req_sum;
    }

    priority_queue<State,vector<State>,greater<State> > que;
    que.push(State(0,0));
    dp[0] = 0;
    while(!que.empty()){
      State s = que.top();
      que.pop();
      
      for(int S = 0; S <= (1<<total_files) - 1; S++){
        if(s._used & S) continue;
        if(dp[s._used | S] <= s._archives + 1) continue;
        if(required_space[S] > open_space[s._used] + init_disk_space) continue;
        dp[s._used | S] = s._archives + 1;
        que.push(State(s._used | S,s._archives + 1));
      }
    }

    if(dp[(1<<total_files) - 1] >= INF){
      printf("Impossible\n");
    }
    else{
      printf("%d\n",dp[(1<<total_files) - 1]);
    }
  }
}

Measured memory_bytes: 1544
#include<iostream>
using namespace std;
int main() {
	string a;
	int ans = 0;
	cin >> a;
	if (a[0]=='S'&&a[1]=='U'&&a[2]=='N') {
		cout << 7;
	}
	if (a[0] == 'S' && a[1] == 'A'&&a[2]=='T') {
		cout << 1;
	}
	if (a[0] == 'M') {
		cout << 6;
	}
	if (a[0] == 'T' && a[1] == 'U') {
		 cout << 5;
	 }
	if (a[0] == 'W') {
		cout << 4;
	}
	if (a[0] == 'T' && a[1] == 'H') {
		cout << 3;
	}
	if (a[0] == 'F') {
		cout << 2;
	}
}
 

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
#define int long long
using namespace std;

template <typename X, typename T>
auto vectors(X x, T a) {
	return vector<T>(x, a);
}

template <typename X, typename Y, typename Z, typename... Zs>
auto vectors(X x, Y y, Z z, Zs... zs) {
	auto cont = vectors(y, z, zs...);
	return vector<decltype(cont)>(x, cont);
}

template<typename T>
ostream& operator << (ostream& os, vector<T>& v){
	rep(i,v.size()){ os << v[i] << (i == v.size() - 1 ? "" : " "); } return os;
}
template<typename T>
istream& operator >> (istream& is, vector<T>& v){
	for(T& x: v){ is >> x; } return is;
}

void dfs(const vector<vector<pair<int, int>>>& g, int cur, int cc, vector<int>& color){
	color[cur] = cc;
	for(auto p : g[cur]){
		int to, w;
		tie(to, w) = p;
		if(color[to] != -1) continue;
		dfs(g, to, w ? cc xor 1 : cc, color);
	}
}

signed main(){
	int n;
	cin >> n;

	vector<vector<pair<int, int>>> g(n);
	rep(i,n - 1){
		int a, b, c;
		cin >> a >> b >> c;
		a--; b--;
		g[a].emplace_back(make_pair(b, c % 2));
		g[b].emplace_back(make_pair(a, c % 2));
	}

	vector<int> color(n, -1);
	dfs(g, 0, 0, color);
	rep(i,n){
		cout << color[i] << endl;
	}
}


Measured memory_bytes: 10880
#include <cstdio>
#include <vector>
#include <set>
using namespace std;

int main(){
    int N, tmp, now;
    scanf("%d",&N);
    vector<int> a;
    set<int> m;

    for(int i=0; i<N; i++){
        scanf("%d", &tmp);
        a.push_back(tmp);
    }

    now = 1;
    m.insert(1);
    while(true){
        now = a[now-1];
        if(now==2){
            printf("%d\n", (int)m.size());
            break;
        }
        else if(m.find(now) != m.end()){
            printf("-1\n");
            break;
        }
        m.insert(now);
    }

    return 0;
}

Measured memory_bytes: 5368
#include <iostream>
#include <algorithm>
#include <string>
#include <map>
#include <set>

using ll = long long;

int main() {
    int N;
    std::cin >> N;
    int ans = 3;
    for (int i = 0; i < N; ++i) {
        char c;
        std::cin >> c;
        if (c == 'Y') {
            ans = 4;
        }
    }
    if (ans == 3) {
        std::cout << "Three" << std::endl;
    } else {
        std::cout << "Four" <<  std::endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>

using namespace std;

int main(){
    char s[20];
    scanf("%s", s);
    for(int i = 0; i < 10; i++)
        s[i] -= '0';
    int year, month, day;
    year = s[0] * 1000 + s[1] * 100 + s[2] * 10 + s[3];
    month = s[5] * 10 + s[6];
    day = s[8] * 10 + s[9];
    //printf("@@@ %d %d %d\n\n", year, month, day);
    if(year != 2019){
        printf(year > 2019 ? "TBD" : "Heisei");
        return 0;
    }
    if(month != 4){
        printf(month > 4 ? "TBD" : "Heisei");
        return 0;
    }
    if(day != 30){
        printf(day > 30 ? "TBD" : "Heisei");
        return 0;
    }
    printf("Heisei");

}

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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

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

typedef long long ll;
typedef long double R;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};

// Problem Specific Parameter:

int main() {
  int sx, sy, tx, ty; cin >> sx >> sy >> tx >> ty;
  const int ddx = tx-sx, ddy=ty-sy;
  // Path1
  cout << string(ddy, 'U') << string(ddx, 'R');
  // Path2
  cout << string(ddy, 'D') << string(ddx, 'L');
  // Path1
  cout << 'L' << string(ddy+1, 'U') << string(ddx+1, 'R') << 'D';
  // Path1
  cout << 'R' << string(ddy+1, 'D') << string(ddx+1, 'L') << 'U';

  cout << endl;

  return 0;
}

Measured memory_bytes: 256
from fractions import gcd


def lcm(a, b):
    return a * b // gcd(a, b)


def mod_inv(a, m):
    return pow(a, m-2, m)


MOD = 10 ** 9 + 7
N = int(input())
A = list(map(int, input().split()))

LCM = 1
for a in A:
    LCM = lcm(LCM, a)

# ans = LCM * sum([mod_inv(a, MOD) for a in A]) % MOD
ans = 0
for a in A:
    ans += LCM * mod_inv(a, MOD) % MOD
    ans %= MOD

print(ans)


Measured memory_bytes: 6136
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mit map<int,int>::iterator
#define sit set<int>::iterator
#define itrm(g,x) for(mit g=x.begin();g!=x.end();g++)
#define itrs(g,x) for(sit g=x.begin();g!=x.end();g++)
#define ltype int
#define rep(i,j,k) for(ltype(i)=(j);(i)<=(k);(i)++)
#define rap(i,j,k) for(ltype(i)=(j);(i)<(k);(i)++)
#define per(i,j,k) for(ltype(i)=(j);(i)>=(k);(i)--)
#define pii pair<int,int>
#define fi first
#define se second
#define mpr make_pair
#define pb push_back
#define fastio ios::sync_with_stdio(false)
const int inf=0x3f3f3f3f,mod=1000000007;
const double pi=3.1415926535897932,eps=1e-6;
int n,a[25],b[25],c[25],ans;
int main()
{
    scanf("%d",&n);
    rep(i,1,n) scanf("%d",a+i);
    rep(i,1,n) scanf("%d",b+i);
    rap(i,1,n) scanf("%d",c+i);
    rep(i,1,n){
        ans+=b[a[i]];
        if(i>1&&a[i]==a[i-1]+1) ans+=c[a[i-1]];
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 256
N, P = map(int, input().split())
S = input()

if P == 2 or P == 5:
    ans = 0
    for i, s in enumerate(S):
        if int(s) % P == 0:
            ans += i+1
    print(ans)
    import sys
    sys.exit(0)

surpluses = [0] * P
s = 0
power = 1
for i in range(N):
    s = (s + int(S[-1-i]) * power) % P
    surpluses[s % P] += 1
    power = (power * 10) % P

ans = surpluses[0]
for count in surpluses:
    ans += count * (count - 1) // 2

print(ans)


Measured memory_bytes: 41180
#include<stdio.h>

int main(void)
{
  int c1,c5,c10,c50,c100,c500;
  int sum = 0;
 
  scanf("%d %d %d %d %d %d",&c1,&c5,&c10,&c50,&c100,&c500);
  
  sum = c1+c5*5+c10*10+c50*50+c100*100+c500*500;
  if(sum <1000)
    printf("%d\n",0);
  else 
    printf("%d\n",1);

  return 0;
  
}

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

class Program
{
    static void Main(string[] args)
    {
        string s, t, u;
        int a, b;

        var split = Console.ReadLine().Split(' ');
        s = split[0];
        t = split[1];
        split = Console.ReadLine().Split(' ');
        a = int.Parse(split[0]);
        b = int.Parse(split[1]);
        u = Console.ReadLine();
        if (s == u)
            a--;
        else if (t == u)
            b--;
        Console.WriteLine(a + " " + b);
    }

}




Measured memory_bytes: 13140
import java.io.*;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.text.ParseException;
import java.util.*;


public class Main {

    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static StringTokenizer st;
    static StringBuilder sb = new StringBuilder("");

    static int[] inputArray(int n) throws IOException {
        int[] a = new int[n];
        st = new StringTokenizer(br.readLine());
        for(int i = 0 ; i < n ; i++) {
            a[i] = Integer.parseInt(st.nextToken());
        }
        return a;
    }

    public static void main(String[] args) throws IOException {
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            StringTokenizer st;
            StringBuilder sb = new StringBuilder("");
            int n = Integer.parseInt(br.readLine());
            long s = 0;
            for(int k = 1 ; k <= n ; k++) {
                if(n % k == 0) {
                    s--;
                }
                s += n/k;
                //System.out.println("n/k " + n/k);
            }
            System.out.println(s);
        }

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

    static void longestGcdSeq(int a[] , int n) {
        int coprimes[] = new int[n];
        for(int i = 0 ; i < n ; i++) {
            if(a[i] < a[(i+1)%n]) {
                if(gcd(a[(i+1)%n] , a[i]) != 1) {
                    coprimes[i] = 1;
                }
            }
            else {
                if(gcd(a[i] , a[(i+1)%n]) != 1) {
                    coprimes[i] = 1;
                }
            }
        }
        //System.out.println(Arrays.toString(coprimes));
        int maxLen = 0 , startLen = 0 , endLen = 0;
        int i = 0;
        while(i < n && coprimes[i] == 1) {
            startLen++;
            i++;
        }
        i = n -1;
        while(i >= 0 && coprimes[i] == 1) {
            endLen++;
            i--;
        }
        int start = 0;
        for(i = 0 ; i < n ; i++) {
            if(coprimes[i] == 0) {
                maxLen = Math.max(maxLen , i - start);
                start = i + 1;
            }
        }
        maxLen = Math.max(maxLen , i - start);
        start = i + 1;
        //System.out.println(startLen + " " + maxLen + " " + endLen);
        int contMax = startLen == n ? n : Math.max(startLen + endLen , maxLen) + 1;
        //System.out.println(contMax);
        for(int k = 2 ; k <= n ; k++) {
            System.out.print((contMax-1)/(k-1) + " ");
        }
        System.out.println();
    }

}
/*

if(tree.size == 2) {

}

5 8
5 1 2 4 3
0 1
0 2
0 3
0 4
0 5
1 1000000000
1 1
1 500000000


 */

Measured memory_bytes: 32804
import java.util.ArrayList;
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		ArrayList<Integer> rows = new ArrayList<>();
		ArrayList<Integer> columns = new ArrayList<>();
		Scanner sc = new Scanner(System.in);
		boolean flag = true;
		while (true) {
			int H = sc.nextInt();
			int W = sc.nextInt();
			if (H == 0 && W == 0) {
				break;
			}
			if (H >= 3 && H <= 300 && W >= 3 && W <= 300) {
				rows.add(H);
				columns.add(W);
			} else {
				flag = false;
				break;
			}
		}
		if (flag == true) {
			for (int i = 0; i < rows.size(); i++) {
				for (int j = 0; j < rows.get(i); j++) {
					for (int k = 0; k < columns.get(i); k++) {
						if (j == 0 || j == rows.get(i) - 1) {
							System.out.print("#");
						} else {
							if (k == 0 || k == columns.get(i) - 1) {
								System.out.print("#");
							} else {
								System.out.print(".");
							}

						}
					}

					System.out.println();
				}

				System.out.println();
			}
		}

	}
}

Measured memory_bytes: 34092
//q2.cpp

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << #x << " = " << x << endl;


#define mod 1000000007 //1e9+7
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 10000


int main(){
  int n,m,a,b,s[SIZE];
    
  scanf("%d%d",&n,&m);
    
  for(int i=0;i<m;i++){
    scanf("%d%d",&a,&b);

    s[i] = max(n-a,0);
  }
  
  sort(s,s+m);

  int ans = 0;

  for(int i=0;i<m-1;i++){
    ans += s[i];
  }

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

Measured memory_bytes: 3160
// #pragma GCC optimize "trapv" Uncomment when dealing with huge numbers
/*<----------PBDS---------->

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
template <typename T>
using order_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

order_set<datatype>oset;
Kth smallest : *oset.find_by_order(k-1); // 0 based index
No of elements less than k : oset.order_of_key(k);
Erase X : oset.erase(x)
<----------PBDS---------->*/
#include<iostream>
#include<bits/stdc++.h>
#define int long long
#define mod 1000000007
#define pb(x) push_back(x)
#define gcd(a,b) __gcd(a,b)
#define all(v) v.begin(),v.end()
#define lcm(a,b) (a*b)/gcd(a,b)
#define bits(x) __builtin_popcountll(x)
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int32_t main()
{
	int n;
	cin >> n;
	int ans = n/2;
	if(n%2==0){
		cout<<ans;return 0;
	}
	cout<<ans+1;
}





Measured memory_bytes: 256
n,a,b = map(int,input().split())
#組み合わせ(数が大きいとき)(10**9+7で割ったもの)
q = 10**9+7
def comb(a, b):
    c = 1
    for i in range(b):
        c *= a - i
        c %= q
    d = 1
    for i in range(b):
        d *= i + 1
        d %= q
    return c*pow(d, q-2, q)
p = pow(2,n,q)-1-comb(n,a)-comb(n,b)
print(p%(10**9+7))

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

int main() {
	long long a[3];
	cin >> a[0] >> a[1] >> a[2];
	int d, e, f;
	d = a[0] % 2;
	e = a[1] % 2;
	f = a[2] % 2;
	if (d==0 || e==0 || f==0)cout << "0" << endl;
	else {
		long long  len = sizeof(a) / sizeof(long long);
		sort(a, a + len);
		cout << a[0] * a[1] << endl;
	}
}

Measured memory_bytes: 256
/*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Code author: Saurabh Singhal
Code copy karne vaale tera muh kaala
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/

#include<bits/stdc++.h>
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define ppb pop_back

using namespace std;
typedef long long int ll;
typedef vector<int> vi_t;
typedef vector<ll> vll_t;
int t=1;
vll_t a,b;

int main(){
	//scanf("%d",&t);
	while(t--){
		int n;
		cin>>n;
		long double ans=0.0;
		for(int i=0;i<n;i++){
			long double p;
			string s;
			cin>>p>>s;
			if(s=="JPY"){
				ans+=p;
			}
			else{
				ans+=(p*(long double)380000);
			}
		}
		cout<<setprecision(20)<<ans<<endl;
	}
}

Measured memory_bytes: 256
import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter
import java.util.*
import kotlin.math.abs
import kotlin.math.cos
import kotlin.math.max
import kotlin.math.min

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

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

fun solve() {
    val (h, w) = readIntegerList()
    val map = Array(10) { readLongList().toLongArray() }
    warshallFloyd(map)
    val ans = Array(h) { readIntegerList() }
        .flatMap { it }
        .filter { it != -1 }
        .fold(0L) { acc, a -> acc + map[a][1] }
    out.println(ans)
}

/**
 * O((costMatrix.size)^3) costMatrix is changed
 * 全点対間最短路
 */
fun warshallFloyd(costMatrix: Array<LongArray>, LINF: Long = Long.MAX_VALUE) {
    val indices = costMatrix.indices
    for (k in indices)
        for (i in indices)
            for (j in indices)
                if (costMatrix[i][k] != LINF && costMatrix[k][j] != LINF)
                    costMatrix[i][j] = Math.min(costMatrix[i][j], costMatrix[i][k] + costMatrix[k][j])
}


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: 45932
#include <bits/stdc++.h>

using namespace std;
const int N = 111;
int a[N], b[N], c[N];

int main()
{
    int n; cin >> n;
    for (int i = 1; i < n; i ++) cin >> b[i];
	b[0] = b[n]= 1e9;
 	for (int i = 1; i <= n; i ++) a[i] = min(b[i - 1], b[i]);
  	int ans = 0;
  	for (int i = 1; i <= n; i ++) ans += a[i];
  	cout << ans << "\n";
}

Measured memory_bytes: 256
n = int(input())
A = list(map(int,input().split()))
MOD = 10**9 + 7
for i in range(n):
  b = format(A[i],'b').zfill(61)
  A[i] = b


bit = [0]*61
for i in range(n):
  for j in range(61):
    if A[i][j] =='1':
      bit[j] += 1

ans = 0
for k in range(61):
  multi = (bit[k]*(n-bit[k]))%MOD
  if k > 30:
    ans += (((2**(60-k))%MOD) * multi)%MOD
  else:
    ooo = ((2**(30-k))%MOD * (2**20)%MOD * (2**10)%MOD) %MOD
    ans += (ooo * multi)%MOD
  ans %= MOD
print(ans)

Measured memory_bytes: 132752
//Picking Up

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long
#define rep(i,x,y) for(ll i=x;i<y;i++)
#define nvarep(n,a) ll n;cin>>n;vector<ll>a(n);rep(i,0,n)cin>>a[i]
#define vecrep(n,a,type) vector<type>a(n);rep(i,0,n)cin>>a[i]
#define lcm(a,b) (a/__gcd(a, b)*b)
#define range(a) (a).begin(),(a).end() 
#define pb push_back
#define mp make_pair
#define nnn "\n"
#define spa " "
using p = pair<ll,ll>;
using graph = vector<vector<ll>>;
const int inf = 2147483647;//2*10^9
const ll INF = 9223372036854775807;//9*10^18

signed main (){
    int n;cin>>n;
    map<p,int>m{};
    vector<p>a(n);
    rep(i,0,n){
        cin>>a[i].first>>a[i].second;
    }
    sort(range(a),greater<p>());
    rep(i,0,n){
        rep(j,i,n){
            if(i==j)continue;
            m[mp(a[i].first-a[j].first,a[i].second-a[j].second)]++;
        }
    }
    int ans=n,c{};
    for(auto i:m){
        c= max(c, i.second);
    }
    cout<<ans-c<<nnn;
    return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define FORR(i, a, b) for (int i = b - 1; i >= a; --i)
#define SORT(v) sort(v.begin(), v.end())
#define SORTR(v) sort(v.rbegin(), v.rend())
#define REV(v) reverse(v.begin(), v.end())
#define ITER(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define LB(v, x) (lower_bound(v.begin(), v.end(), x) - v.begin())
#define UB(v, x) (upper_bound(v.begin(), v.end(), x) - v.begin())
#define SZ(v) (int)v.size()
using namespace std;
using ll = long long;
using P = pair<int, int>;

class Main {
    int N;
    vector<ll> A;
    const ll D = 1e9;
    void input() {
        cin >> N;
        A.resize(N);
        REP(i, N) {
            string s;
            cin >> s;
            int n = s.size();
            int j = 0;
            string a, b(9, '0');
            while (j < n) {
                a += s[j];
                ++j;
                if (s[j] == '.') {
                    ++j;
                    break;
                }
            }
            if (j < n) {
                FOR(k, j, n) { b[k - j] = s[k]; }
            }
            A[i] = atoll((a + b).c_str());
        }
    }
    void output() {
        vector<vector<ll>> memo2_5(19, vector<ll>(19));
        ll res = 0;
        vector<P> pa;
        REP(i, N) {
            int d2 = 0;
            int d5 = 0;
            while (A[i] % 2 == 0) {
                ++d2;
                A[i] /= 2;
            }
            while (A[i] % 5 == 0) {
                ++d5;
                A[i] /= 5;
            }
            d2 = min(18, d2);
            d5 = min(18, d5);
            if (d2 >= 9 && d5 >= 9) { --res; }
            memo2_5[18 - d2][18 - d5]++;
            pa.emplace_back(d2, d5);
        }
        REP(i, 19) {
            REP(j, 18) { memo2_5[i][j + 1] += memo2_5[i][j]; }
        }
        REP(j, 19) {
            REP(i, 18) { memo2_5[i + 1][j] += memo2_5[i][j]; }
        }
        REP(i, N) { res += memo2_5[pa[i].first][pa[i].second]; }
        res /= 2;
        cout << res << endl;
    }

public:
    Main() {
        input();
        output();
    }
};

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

    Main();

    return 0;
}


Measured memory_bytes: 6912
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.util.*
import kotlin.math.abs
import kotlin.math.max
import kotlin.math.min
import kotlin.math.*

val MOD = 1_000_000_007L

class Solver(stream: InputStream, private val out: java.io.PrintWriter) {
  fun solve() {
    val A = ni()
    val B = ni()
    val H = ni()
    val M = ni()
    val th1 = 2 * PI * H / 12 + 2 * PI * M / (12 * 60)
    val th2 = 2 * PI * M / 60
    val x1 = A * cos(th1)
    val y1 = A * sin(th1)
    val x2 = B * cos(th2)
    val y2 = B * sin(th2)
    val dx = abs(x1 - x2)
    val dy = abs(y1 - y2)
    val ans = sqrt(dx * dx + dy * dy)
    out.println("%.10f".format(ans))
  }













































  private val isDebug = try {
    // なんか本番でエラーでる
    System.getenv("MY_DEBUG") != null
  } catch (t: Throwable) {
    false
  }

  private var tokenizer: StringTokenizer? = null
  private val reader = BufferedReader(InputStreamReader(stream), 32768)
  private fun next(): String {
    while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {
      tokenizer = StringTokenizer(reader.readLine())
    }
    return tokenizer!!.nextToken()
  }

  private fun ni() = next().toInt()
  private fun nl() = next().toLong()
  private fun ns() = next()
  private fun na(n: Int, offset: Int = 0): IntArray {
    return map(n) { ni() + offset }
  }
  private fun nal(n: Int, offset: Int = 0): LongArray {
    val res = LongArray(n)
    for (i in 0 until n) {
      res[i] = nl() + offset
    }
    return res
  }

  private fun na2(n: Int, offset: Int = 0): Array<IntArray> {
    val a  = Array(2){IntArray(n)}
    for (i in 0 until n) {
      for (e in a) {
        e[i] = ni() + offset
      }
    }
    return a
  }

  private inline fun map(n: Int, f: (Int) -> Int): IntArray {
    val res = IntArray(n)
    for (i in 0 until n) {
      res[i] = f(i)
    }
    return res
  }

  private inline fun debug(msg: () -> String) {
    if (isDebug) System.err.println(msg())
  }

  private fun debug(a: LongArray) {
    debug { a.joinToString(" ") }
  }

  private fun debug(a: IntArray) {
    debug { a.joinToString(" ") }
  }

  private fun debug(a: BooleanArray) {
    debug { a.map { if (it) 1 else 0 }.joinToString("") }
  }

  private fun debugDim(A: Array<IntArray>) {
    if (isDebug) {
      for (a in A) {
        debug(a)
      }
    }
  }

  /**
   * 勝手にimport消されるのを防ぎたい
   */
  private fun hoge() {
    min(1, 2)
    max(1, 2)
    abs(-10)
  }
}

fun main() {
  val out = java.io.PrintWriter(System.out)
  Solver(System.`in`, out).solve()
  out.flush()
}


Measured memory_bytes: 35904
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

int main(){
  int N;
  cin >> N;
  if(N%10==9||(N/10)%10==9) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long int LL;
typedef int ll;
typedef string str;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
typedef stringstream strs;
 
#define X first
#define Y second
#define PB push_back
#define For(i,a,b) for (int i=a;i<b;i++)
#define Ford(i,a,b) for (int i=a;i>=b;i--)
#define smax(a,b) a=max(a,b)
#define smin(a,b) a=min(a,b)
#define SZ(a) ((ll)a.size())
#define ER(a) cout << #a << ' ' << a << endl
#define LB(a,n,x) (lower_bound(a,(a)+(n),x)-(a))
 
const ll M=2e5+5,LG=19,SM=2000+5,inf=1e9+1;
ll mod=1e9+7;
const ll S2=2*SM;
ll dp[S2][S2];
pll a[M];
ll cm[2*S2][S2];
ll n;
int main()
{
	ios::sync_with_stdio(0);
    cin >> n;
    LL res=0;
    For(i,0,2*S2)
    {
        cm[i][0]=1;
        if (i<S2)
            cm[i][i]=1;
        For(j,1,min(i,S2))
        {
            cm[i][j]=(cm[i-1][j]+cm[i-1][j-1])%mod;
        }
    }
    For(i,0,n)
    {
        cin >> a[i].X >> a[i].Y;
        res-=cm[2*(a[i].X+a[i].Y)][2*a[i].X];
    }     
    For(i,0,n)
    {
        dp[SM-a[i].X][SM-a[i].Y]++;
    }
    For(i,1,S2) For(j,1,S2)
    {
        dp[i][j]+=dp[i-1][j]+dp[i][j-1];
        dp[i][j]%=mod;
    }
 
    For(i,0,n)
    {
        res+=dp[SM+a[i].X][SM+a[i].Y];
    }
    res%=mod;
    res+=mod;
    res%=mod;
    cout << (res*((mod+1)/2))%mod;         
}

Measured memory_bytes: 188800
#include <iostream>
using namespace std;
int main(){
	int n;
	while(cin >> n, n){
		int a[5000], ans = -100001;
		for(int i = 0; i < n; i++) cin >> a[i];
		for(int i = 0; i < n; i++){
			int sum = 0;
			for(int j = i; j < n; j++){
				sum += a[j];
				ans = max(ans, sum);
			}
		}
		cout << ans << endl;
	}
	return 0;
}

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

using namespace std;

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

  string S[N];
  for (int i = 0; i < N; i++) {
    cin >> S[i];
  }

  sort(S, S + N);

  string answer = "";
  for (int i = 0; i < N; i++) {
    answer += S[i];
  }

  cout << answer << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <array>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <iomanip>

#define FOR(i, a, b) for(decltype(b) i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;

using namespace std;

#ifdef INPUT
#include <sstream>
stringstream input(R"(
2 3
1 2 3
0 1 1
)");
#define cin input
#endif

int main()
{
	int h, w;
	cin >> h >> w;

	vector<array<int, 4>> r;
	int a[512][512];

	bool cc;
	bool cr = false;
	REP (i, h)
	{
		cc = false;
		REP (j, w)
		{
			cin >> a[i][j];
			if (cc)
				++a[i][j];
			if (j == w - 1)
			{
				if (cr)
					++a[i][j];
				if (cr = a[i][j] % 2)
				{
					if (i != h - 1)
						r.push_back({i + 1, j + 1, i + 2, j + 1});
				}
			} else
			if (cc = a[i][j] % 2)
				r.push_back({i + 1, j + 1, i + 1, j + 2});
		}
	}

	cout << r.size() << endl;
	for (const auto& a : r)
		cout << a[0] << ' ' << a[1] << ' ' << a[2] << ' ' << a[3] << endl;

	return 0;
}


Measured memory_bytes: 5232