akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define MOD 1000000007
#define MAX 510000
#define rrep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define dcout cout<<fixed<<setprecision(15);

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


//lcm//
ll gcd(ll x, ll y) {
	if (x == 0) return y;
	return gcd(y%x, x);
}
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

//a^n mod p//
ll modpow(ll a, ll n, ll p) {
  if (n == 1) return a % p;
  if (n % 2 == 1) return (a * modpow(a, n - 1, p)) % p;
  ll t = modpow(a, n / 2, p);
  return (t * t) % p;
}

//inversemod//
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

//Cmonp//
ll fac[MAX], finv[MAX], inv[MAX];
// 
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; 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;
	}
}

// 
ll COM(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

//LARGE n
ll com(ll n,ll m){
    if(n<m || n<=0 ||m<0){
		return 0;
	}
	if( m==0 || n==m){
		return 1;
	}
	ll k=1;
	for(ll i=1;i<=m;i++){
       k*=(n-i+1); 
	   k%=MOD;
	   k*=modinv(i,MOD);
	   k%=MOD;
	}
	return k;
}

//radP
ll rad(ll u, ll p){
ll cnt=0;
	while(u%p==0){
		u/=p;
		cnt++;
	}
	return cnt;
}


////////////////////////////////////////////////////////////////////

int main() {
ll k;
cin>>k;
ll r=k%50;
ll b=k/50;

ll a[51];
rep(i, 50){
	a[i]=49+b;
}

if(r==0){
	cout<<50<<endl;
	for(int i=1;i<=49;i++){
		cout<<a[i]<<" ";
	}
	cout<<a[50]<<endl;
	return 0;
}

for(int i=1;i<=r;i++){
	a[i]=a[i]+51-r;
}
for(int i=r+1;i<=50;i++){
a[i]-=r;
}

	cout<<50<<endl;
	for(int i=1;i<=49;i++){
		cout<<a[i]<<" ";
	}
	cout<<a[50]<<endl;
	return 0;







return 0;
}




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

A.sort(reverse=True)
S = sum(A)

ans = True
for i in range(M):
    if A[i]*4*M < S:
        ans = False
        break

if ans:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1001001001;
const ll LINF = 1LL << 60;
const int MOD = 1'000'000'007;

template <typename T>
void print(const T &v)
{
    for (int i = 0; i < v.size(); i++)
    {
        if (i)
            cout << ' ';
        cout << v[i];
    }
    cout << endl;
}

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

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

// const int MAX = 1010;

int main()
{
    ll N;
    cin >> N;
    for (int h = 1; h <= 3500; h++)
    {
        for (int n = 1; n <= 3500; n++)
        {
            ll denomi = h * n;
            ll nume = n + h;
            if ((4 * denomi - N * nume) <= 0)
            {
                continue;
            }
            if ((N * denomi) % (4 * denomi - N * nume) == 0)
            {
                ll w = (N * denomi) / (4 * denomi - N * nume);
                cout << h << ' ' << n << ' ' << w << endl;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 3632
import sys

s = list(input())
p = list(input())
for i in range(len(s)):
  counter = 0
  for j in range(len(p)):
    m = (i+j)%len(s)
    if s[m] == p[j]:
      counter += 1
  if counter == len(p):
    print('Yes')
    sys.exit()
print('No')


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

using namespace std;

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

#define REP(k, n) for (ll k = 0; k < (ll)(n); ++k)
#define REPREV(k, n) for (ll k = (ll)(n)-1; k >= 0; --k)
#define FOR(k, a, b) for (ll k = (ll)(a); k < (ll)(b); ++k)
#define FORREV(k, a, b) for (ll k = (ll)(b)-1; k >= (ll)(a); --k)
#define FOREACH(e, v) for (auto& e : v)

#define TGET(t, i) get<i>(t)
#define TSET(t, i, a) get<i>(t) = a
// MinHeap - priority_queue<ll, vll, greater<ll>> pq;

#define EVEN(n) ((n)&1) == 0
#define ODD(n) ((n)&1) == 1

#define SORT(v) sort(v.begin(), v.end())
#define SORTREV(v) sort(v.rbegin(), v.rend())
#define SHUFFLE(v) random_shuffle(v.begin(), v.end())
//srand(unsigned(time(0)));

#define REMOVEAT(v, i) v.erase(v.begin() + i)
#define REVERSE(v) reverse(v.begin(), v.end())

ll MOD(ll x, ll m) {
    ll r = x % m;
    if (r < 0) {
        r += m;
    }
    return r;
}

ostream& operator<<(ostream& str, const pll& p) {
    str << p.first << " " << p.second;
    return str;
}

template <typename T>
void join(T& arr, string sep) {
    bool first = true;
    for (auto t : arr) {
        if (first) {
            first = false;
            cout << t;
        } else {
            cout << sep << t;
        }
    }
    cout << "\n";
}

#define POS "POSSIBLE"
#define IMPOS "IMPOSSIBLE"

// #define INF LLONG_MAX
// #define MINF LLONG_MIN
#define INF 9e18
#define MINF -INF

void solve() {
    ll n, k;
    cin >> n >> k;
    vll a(n);
    REP(i, n) {
        cin >> a[i];
    }
    SORT(a);
    
    ll res = 0;
    REP(j, k) {
        res += a[j];
    }


    // cout << fixed << setprecision(6);
    cout << res << "\n";
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int tt = 1;
    // cin >> tt;
    for (int t = 1; t <= tt; t++) {
        // cout << "Case #" << t << ": ";
        solve();
    }

    return 0;
}

Measured memory_bytes: 3664
#include <bits/stdc++.h>
#define REP(i, n) for(long long i=0; i<n; i++)
#define REPR(i, n) for(long long i=n-1; i>=0; i--)
#define FOR(i, m, n) for(long long i=m; i<=n; i++)
#define FORR(i, m, n) for(long long i=m; i>=n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

using namespace std;
using ll = long long;
using ull = unsigned long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;
const ll mod = 1e9+7;
const ll inf = 1e15;
ll power(ll a,ll b){return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;}


int main(){FIN
    ll a,s;cin>>a>>s;
    ll cnt = 1;
    while(1){
        a*=2;
        if (a<=s) cnt++;
        else break;
    }
    cout<<cnt<<endl;
    return 0;
}


Measured memory_bytes: 3576
#include<iostream>
using namespace std;
int a,b;
string s[200];
int main()
{
	cin>>a>>b;
	for(int i=0;i<100;i++)
		for(int j=0;j<100;j++)s[i]+=i<50?'#':'.';
	int c=0,d=0,e=99,f=0;
	for(int i=1;i<a;i++)
	{
		s[c][d]='.';
		if(++++d>99)c+=2,d=0;
	}
	for(int i=1;i<b;i++)
	{
		s[e][f]='#';
		if(++++f>99)e-=2,f=0;
	}
	cout<<"100 100\n";
	for(int i=0;i<100;i++)cout<<s[i]<<endl;
	return 0;
}

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

typedef long long ll;
using namespace std;

int main() {
	ios::sync_with_stdio(false);
	//	srand(time(NULL));
	int n; cin >> n;
	vector<int>a(n), b(n);
	for(int i = 0; i < n; i++)
		cin >> a[i];
	for(int i = 0; i < n; i++)
		cin >> b[i];

	ll x = 0, y = 0;
	for(int i = 0; i < n; i++){
		if(a[i] > b[i])
			x += a[i] - b[i];
		else
			y += (b[i] - a[i]) / 2;
	}

	if(x <= y)
		cout << "Yes\n";
	else cout << "No\n";
	return 0;
}


Measured memory_bytes: 384
#include<cstdio>
#include<vector>

using namespace std;

int main()
{
	int n,m;
	for(;scanf("%d%d",&n,&m),n||m;){
		vector<bool> man(n,true);

		for(int k=0,pos=0;k<n-1;k++){
			for(int cnt=0;;){
				pos=(pos+1)%n;
				if(man[pos]){
					cnt++;
					if(cnt==m)	break;
				}
			}
			man[pos]=false;
		}

		int win;
		for(win=0;!man[win];win++);
		printf("%d\n",win?win:n);
	}

	return 0;
}

Measured memory_bytes: 808
#include<stdio.h>
main(){
  int N, A[100], i, flag, a, x=0;
  scanf("%d", &N);
  for(i = 0; i < N; i++){
    scanf("%d", &A[i]);
  }
  flag = 1;
  while(flag){
    flag = 0;
    for(i = N-1; 0 < i; i--){
      if(A[i] < A[i-1]){
	a = A[i];
	A[i] = A[i-1];
	A[i-1] = a;
	flag = 1;
	x++;
      }
    }
  }
  for(i = 0; i < N; i++){
    if(i == N-1){
      printf("%d\n", A[i]);
    }
    else  printf("%d ", A[i]);
  }
  printf("%d\n", x);
  return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
double a[2][10000];
double ta[10000];
main(){
  int n,t,l,b,x;
  while(cin>>n>>t>>l>>b,n){
    memset(a,0,sizeof(a));
    memset(ta,0,sizeof(ta));
    a[0][0]=1;
    double sum=0,q=0.16666666666;
    r(i,l){cin>>x;ta[x]=1;}
    r(i,b){cin>>x;ta[x]=2;}
    r(o,t){
      double p[n+1]={};
      r(i,n)if(a[0][i]>0)
        for(int j=i+1;j<=i+6;j++){
          int y=j;
          if(y>n){
            int pp=y-n;
            y=n-pp;
          }
          p[y]+=a[0][i];
        }
      r(i,n+1)if(ta[i]==2)
        p[0]+=p[i],p[i]=0;

      r(i,n+1)a[0][i]=p[i];

      r(i,n+1)if(ta[i]==1)swap(a[0][i],a[1][i]);
      r(i,n+1)a[0][i]/=6;
      sum+=a[0][n];
      a[0][n]=0;
    }
    printf("%.6f\n",sum);
  }
}

Measured memory_bytes: 3432
#include<iostream>
#include<stdio.h>
#include<ctype.h>
using namespace std;
 
int main(void){
	char ch;
	while(1){
		scanf("%c", &ch);
		if(islower(ch)){
			cout<< static_cast<char>(toupper(ch));
		}
		else if(isupper(ch)){
            cout<< static_cast<char>(tolower(ch));
        }
		else{
            cout<< ch;
        }
		if(ch=='\n')break;
	}
	return 0;
}

Measured memory_bytes: 1112
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <functional>
#include <utility>
#include <queue>
#include <vector>
#include <string>
#include <stack>
#include <ctime>
#include <random>
#include <chrono>
#define rep(i,n) for(ll i=0;i<n;i++)
using namespace std;
typedef long long int ll;
const ll  MOD = 1000000007;
typedef pair<ll,ll> P;
const ll INF = 100100100100100100;

ll N;
ll a[200200];
ll m = -1;
int main(){
  cin >> N;
  ll in = -1;
  rep(i,N){
    cin >> a[i];
    if(a[i] > m){
      m = a[i];
      in = i;
    }
  }
  double mm = INF;
  ll index = -1;
  rep(i,N){
    if(in == i) continue;
    double tmp_m = m/2.0;
    double tmp = fabs(tmp_m - a[i]);
    if(tmp < mm){
      mm = tmp;
      index = i;
    }
  }
  cout << m << " " << a[index] << endl;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(a) (a).begin(), (a).end()
typedef vector<int> vi;
const int INF = 1LL << 60; //10e18+10e17ちょっとくらい
const int MOD = 1000000007;
const int MAX_N = 200100;

signed main()
{
    //  以降 cin の入力元が 'input.txt' になる
    //std::ifstream in("input.txt");
    //std::cin.rdbuf(in.rdbuf());
    int n;
    cin >> n;
    int ans = 1;
    for (int i = 2; i < min((int)1e7, n); i++)
    {
        int t = n;
        while (t % i == 0)
        {
            t /= i;
        }
        if (t % i == 1)
        {
            ans++;
        }
    }

    for (int i = 1; i <= min((int)1e7, n - 1); i++)
    {
        int t = n - 1;
        if (t % i == 0)
        {
            if ((n - 1) / i > min((int)1e7, n))
                ans++;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3676
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<char> VC;
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<ll> VLL;
typedef vector<PLL> VP;
const static int INF = 1000000000;
const static int MOD = 1000000007;
const int dx[4]={1, 0, -1, 0};
const int dy[4]={0, 1, 0, -1};
#define rep(i,n) for (ll i=0; i<(ll)(n); i++)
#define repd(i,n) for (ll i=n-1; i>=0; i--)
#define rept(i,m,n) for(ll i=m; i<n; i++)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define PF push_front
#define PB push_back
#define SORT(V) sort((V).begin(), (V).end())
#define RVERSE(V) reverse((V).begin(), (V).end())
#define paired make_pair
#define PRINT(V) for(auto v : (V)) cout << v << " "
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
//charを整数に
int ctoi(char c) { if (c >= '0' && c <= '9') { return c - '0'; } return 0; }
// 累積和 for (int i = 0; i < N; ++i) s[i+1] = s[i] + a[i]; 
void cum_sum(int N,vector<double> a, vector<double> &s){ for(int i=0; i<N; i++){ s[i+1]=s[i]+a[i];}}
//ユークリッドの控除法
ll gcd(ll a,ll b){
    if(b == 0) return a;
    return gcd(b,a%b);
}
//最小公倍数
ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b; // Be careful not to overflow
}
//素数判定
bool is_prime(long long n) {
    if (n <= 1) return false;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p == 0) return false;
    }
    return true;
}
int getdigit(ll num){
    unsigned digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
}
//空白文字も入力 getline(cin, S);
//桁数指定 setprecision
ll a[100010][3];
ll dp[100010][3];
int main()
{
    int N;
    cin >> N;
    rep(i,N){
        rep(j,3){
            cin >> a[i][j];
        }
    }

    rep(i,N){
        rep(j,3){
            rep(k,3){
                if(j==k) continue;
                chmax(dp[i+1][k],dp[i][j]+a[i][k]);
            }
        }
    }
    ll res=0;
    rep(j,3) chmax(res, dp[N][j]);
    cout << res << endl;
}

Measured memory_bytes: 4992
//#pragma GCC optimize("Ofast,unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,tune=native")
#include<bits/stdc++.h>

using namespace std;

#define all(x) (x).begin(),(x).end()
#define I(x, a) for(auto x : (a))
#define ins insert
#define F(i, l, r) for(auto i = (l); i < (r); i++)
#define DF(i, l, r) for(auto i = (l); i >= (r); i--)
#define E(i, l, r) for(auto i = (l); i <= (r); i++)
#define pb push_back
#define X first
#define Y second
#define mp make_pair
#define ret return
#define brk break
#define cont continue
#define move fjgjgjgjghd

typedef long long ll;
typedef unsigned long long ull;
typedef long double dbl;
typedef pair<int, int> pii;

const int N = (int)1e5 + 5;

int dp[N];
int h[N];
int n;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin >> n;
	int k;
	cin >> k;
	F(i, 0, n)cin >> h[i];
	fill(dp, dp + n, N * (int)1e4);
	dp[0] = 0;
	F(i, 0, n - 1){
		for(int j = 1; j <= k; j++){
			if(i + j < n)
				dp[i + j] = min(dp[i + j], dp[i] + abs(h[i] - h[i + j]));
		}
	}
	cout << dp[n - 1] << endl;
	return 0;
}


Measured memory_bytes: 1024
import sys
from itertools import combinations
from collections import Counter
read = sys.stdin.read

N, *xy = map(int, read().split())

if N == 1:
    print(1)
    exit()

pq = []
for (a1, b1), (a2, b2) in combinations(zip(*[iter(xy)] * 2), 2):
    p = a1 - a2
    q = b1 - b2
    pq.append((p, q))
    pq.append((-p, -q))

print(N - Counter(pq).most_common()[0][1])

Measured memory_bytes: 3956
#include <iostream>
using namespace  std;
using ll = long long;
int main(){
    ll x, y; cin>>x>>y;
    bool alice = true;
    if(x+y<1 or abs(x-y)<=1) alice = false;
    if(alice) cout << "Alice" << endl;
    else cout << "Brown" << endl;
    return 0;
}

Measured memory_bytes: 256
"""AtCoder."""


def get_group(n):
    if n in [1,3,5,7,8,10,12]:
        return 0
    
    if n in [4, 6, 9, 11]:
        return 1

    if n in [2]:
        return 2

def main():
    x, y = map(int, input().split())
    
    if get_group(x) == get_group(y):
        print('Yes')
    else:
        print('No')


if __name__ == '__main__':
    main()


Measured memory_bytes: 9164
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;

int main(int argc, const char * argv[]) {

    cin.tie(0);
    ios::sync_with_stdio(false);
    
    long long n, k;
    cin >> n >> k;
    
    vector<long long> a(n, 0);
    
    for(long long i=0; i<n; i++)
        cin >> a[i];
    
    long long ans = 0;
    
    for(long long i=0; i<=n; i++){
        for(long long j=0; j<=n; j++){
            if(i+j>=min(n,k)+1) continue;
            vector<long long> b(i+j,0);
            for(long long m=0; m<i; m++)
                b[m] = a[m];
            for(long long m=0; m<j; m++)
                b[i+j-1-m] = a[n-m-1];
            
            sort(b.begin(), b.end());
            
            long long count = 0;
            for(auto &x: b){
                if(count >= k-i-j)
                    break;
                if(x < 0){
                    ++count;
                    x = 0;
                }
            }
            
            
            long long sum = 0;
            for(auto x: b)
                sum += x;
            
            ans = max(ans, sum);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
def main():
    n,k=map(int, input().split())
    s= input()
    blocks = []
    nums = []
    tmp  = s[0]
    for i in range(1,n):
        if(s[i]==s[i-1]):
            tmp += s[i]
        else:
            blocks.append(tmp)
            nums.append(len(tmp))
            tmp = s[i]
        if(i==(n-1) and len(tmp)>0):
            blocks.append(tmp)
            nums.append(len(tmp))

    j = len(blocks)
    count = 0
    ans = 0
    for i in range(1,j,2):
        blocks[i] = (blocks[i-1][0])*len(blocks[i])
        count+=1
        if count == k:
            break
    sames = 2*(k)+1

    if(sames >= len(blocks)):
        ans = (n-1)
    else:
        for i in range(sames):
            ans += nums[i]
        ans -= 1
        for i in range(sames,len(blocks)):
            ans+=len(blocks[i])-1
    print(ans)



if __name__ == '__main__':
    main()


Measured memory_bytes: 5420
import sys
from io import StringIO
import unittest

class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """5
6 7 9 10 31"""
        output = """APPROVED"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """3
28 27 24"""
        output = """DENIED"""
        self.assertIO(input, output)

def resolve():
    N=int(input())
    A=list(map(int,input().split()))
    for i in A:
        if i%2==0 and i%3!=0 and i%5!=0:
            print("DENIED")
            return
    print("APPROVED")


if __name__ == "__main__":
    resolve()

Measured memory_bytes: 5692
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using std::cerr;
using std::cin;
using std::cout;
using std::endl;

const int64_t MOD = 1000000000 + 7;

int main(void) {
  cout << std::fixed << std::setprecision(10);
  cin.tie(0);
  std::ios::sync_with_stdio(false);

  int64_t n, m;
  cin >> n >> m;
  std::vector<int64_t> s, t;
  for (int i = 0; i < n; i++) {
    int m1;
    cin >> m1;
    s.push_back(m1);
  }
  for (int i = 0; i < m; i++) {
    int m1;
    cin >> m1;
    t.push_back(m1);
  }

  int64_t dp[2001][2001] = {};
  int64_t cum[2001][2001]={};



  for(int i=0;i<n;i++){
    for(int j=0;j<m;j++){
      if(s[i]==t[j]){
        if(i==0||j==0){
          dp[i][j]=1;
        }else{
          dp[i][j]=1+cum[i-1][j-1];
        }
      }else{
        dp[i][j]=0;
      }
      // assert(dp[i][j]<INT64_MAX&&0<=dp[i][j]);
      dp[i][j]%=MOD;

      if(i==0&&j==0){
        cum[i][j]=dp[i][j];
      }else if(i==0){
        cum[i][j]=dp[i][j]+cum[i][j-1];
      }else if(j==0){
        cum[i][j]=dp[i][j]+cum[i-1][j];
      }else{
        cum[i][j]=cum[i][j-1]+cum[i-1][j]-cum[i-1][j-1]+dp[i][j];
        
      }

      // assert(cum[i][j]<INT64_MAX&&0<=cum[i][j]);
      if(cum[i][j]<0) cum[i][j]+=MOD;
      cum[i][j]%=MOD;


    }
  }

  int64_t result=1;
  for(int i=0;i<n;i++){
    for(int j=0;j<m;j++){
      result+=dp[i][j];
      result%=MOD;
    }
  }
  result%=MOD;
  assert(result<MOD&&0<=result);
  cout<<result<<endl;


  return 0;
}


Measured memory_bytes: 62848
def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a % b)


k = int(input())
ans = 0
for a in range(1, k + 1):
    for b in range(a, k + 1):
        for c in range(b, k + 1):
            d = gcd(a, b)
            if len({a, b, c}) == 1:
                ans += gcd(c, d)
            elif len({a, b, c}) == 2:
                ans += 3 * gcd(c, d)
            else:
                ans += 6 * gcd(c, d)
print(ans)


Measured memory_bytes: 9140
nl = lambda: list(map(int, input().split()))
sl = lambda: input().split()
n = lambda: int(input())
s = lambda: input()


import queue
from collections import defaultdict
def max_flow(edges, num_of_vertices, start, goal):
    level = defaultdict(lambda: -1)
    seen = set()

    def bfs(s):
        level[s] = 0
        q = queue.Queue()
        q.put(s)
        while not q.empty():
            v = q.get()
            for nv, cap in edges[v].items():
                if cap > 0 and level[nv] < 0:
                    level[nv] = level[v] + 1
                    q.put(nv)

    def dfs(v, t, f):
        if v == t:
            return f
        for nv, cap in edges[v].items():
            if (v, nv) in seen:
                continue
            seen.add((v, nv))
            if cap > 0 and level[v] < level[nv]:
                d = dfs(nv, t, min(f, cap))
                if d > 0:
                    edges[v][nv] -= d
                    edges[nv][v] += d
                    return d
        return 0

    flow = 0
    while True:
        level.clear()
        bfs(start)
        if level[goal] < 0:
            return flow
        seen.clear()
        while True:
            f = dfs(start, goal, float('inf'))
            if f == 0:
                break
            flow += f
    return flow

N = n()

reds = []
edges = defaultdict(dict)

for i in range(N):
    reds.append(nl())
    edges[0][i+1] = 1
    edges[i+1][0] = 0
blues = []
for i in range(N):
    blues.append(nl())
    edges[N+i+1][2*N+1] = 1
    edges[2*N+1][N+i+1] = 0

for i in range(N):
    for j in range(N):
        rx, ry = reds[i]
        bx, by = blues[j]
        if rx < bx and ry < by:
            edges[i+1][N+j+1] = 1
            edges[N+j+1][i+1] = 0

print(max_flow(edges, 2*N+2, 0, 2*N+1))


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

namespace B___Contests
{
    class Program
    {
        static void Main (string[] args)
        {
            var n = int.Parse (Console.ReadLine ());
            var input = Console.ReadLine ().Split (' ');
            var a = int.Parse (input[0]);
            var b = int.Parse (input[1]);
            var p = new int[n];
            input = Console.ReadLine ().Split (' ');
            for (var i = 0; i < n; i++)
            {
                p[i] = int.Parse (input[i]);
            }
            var pro = new int[3];
            foreach (var i in p)
            {
                if (i <= a)
                    pro[0]++;

                else if (a < i && i <= b)
                    pro[1]++;

                else
                    pro[2]++;
            }
            Console.WriteLine (pro.Min ());
        }
    }
}

Measured memory_bytes: 11220
#include<bits/stdc++.h>
typedef long long ll;
#define REP(i,n) for(int i = 0;i < (n);i++)
#define rep(i,m,n) for(int i = (m);i < (n);i++)
#define P pair<int,int>
#define pb push_back
#define mk make_pair
using namespace std;
#define Vec(a) vector <int> a
#define F first
#define S second
const int INF = 1 << 20;
const int MOD = 1e9+7;





int main(){
    ll a,b,k;
    cin >> a >> b >> k;
    REP(i,k){
        if(!(i%2)){
            if(a%2){
                a--;
                
            }
            b += a/2;
            a /= 2;
        }else{
            if(b%2){
                b--;
                
            }
            a += b/2;
            b /= 2;
        }
    }
    cout << a << " " << b << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define io ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
typedef long long int ll;
using namespace std;
int main(){
	io;
	ll n,a,b;
	cin >> n >> a >> b;
	ll x,y;
	y = n % (a + b);
	x = (n-y)/(a+b);
	ll ans = x*a;
	if(y > a){
		ans += a;
	}
	else{
		ans += y;
	}
	cout << ans;
	return 0; 
}

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

#define rep(i, x, n) for (int i = x; i < n; i++)
using namespace std;

int main()
{

	int a, b, c, d;
	cin >> a >> b >> c >> d;

	int st = max(a, c);
	int ed = min(b, d);

	int res = (ed - st > 0) ? ed - st : 0;

	cout << res << endl;

	return 0;
}


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

bool match(int cur,bool arr[],bool V[],int npair[], int column){
    if(cur < 0){
        return true;
    }
    if(V[cur]){
        return false;
    }
    V[cur] = true;
    for(int i = 0; i < column; i++){
        if(!arr[cur*column + i]){
            continue;
        }
        if(match(npair[i],arr,V,npair,column)){
            npair[i] = cur;
            return true;
        }
    }
    return false;
}

int main(){
    int row,column,E;
    scanf("%d %d %d",&row,&column,&E);
    bool arr[row*column],V[row];
    for(int i = 0; i < row*column; i++){
        arr[i] = false;
    }
    for(int ei = 0; ei < E; ei++){
        int from,to;
        scanf("%d %d",&from,&to);
        arr[from*column + to] = true;
    }
    int npair[column],count = 0;
    for(int i = 0; i < column; i++){
        npair[i] = -1;
    }
    for(int cur = 0; cur < row; cur++){
        for(int i = 0; i < row; i++){
            V[i] = false;
        }
        if(match(cur,arr,V,npair,column)){
            count++;
        }
    }
    printf("%d\n",count);
}

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}

int nextInt() { int x; scanf("%d", &x); return x;}

int main2() {
  int M = nextInt();
  int D = nextInt();
  int ans = 0;
  for (int m = 1; m <= M; m++) {
    for (int d = 1; d <= D; d++) {
      int d1 = d % 10;
      int d10 = d / 10;
      if (d1 >= 2 && d10 >= 2 && m == d10 * d1) ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}


Measured memory_bytes: 256
//
// Created by ZEN on 2019/10/20.
//

#include <bits/stdc++.h>

using namespace std;

int main() {
    string s;
    cin >> s;
    bool test = true;
    for (int i = 0; i < s.size(); ++i) {
        if (i % 2 == 0) {
            if (s.at(i) == 'L') {
                test = false;
                break;
            }
        } else {
            if (s.at(i) == 'R') {
                test = false;
                break;
            }
        }
    }
    if (test) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
n=int(input())
a=sorted(list(map(int,input().split())))
b=sorted(list(map(int,input().split())))
c=sorted(list(map(int,input().split())))
ma=0
cntb=[0]*n
for i in range(n):
    if i>0:
        cntb[i]=cntb[i-1]
    while ma<n:
        if a[ma]<b[i]:
            cntb[i]+=1
            ma+=1
        else:
            break
mb=0
cntc=[0]*n
for i in range(n):
    if i>0:
        cntc[i]=cntc[i-1]
    while mb<n:
        if b[mb]<c[i]:
            cntc[i]+=cntb[mb]
            mb+=1
        else:
            break
print(sum(cntc))


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

int main() {
	ios_base::sync_with_stdio( false );

	int x, a, b;
	cin >> x >> a >> b;
	cout << (abs( x-a ) < abs( x-b ) ? 'A' : 'B') << endl;

	return 0;
}


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

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i; i < N; i++){
        cin >> A[i];
    }
    sort(A.begin(), A.end());
    int ans = A[N - 1] - A[0];
    cout << ans << endl;
    return 0;
}

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


public class Main {

	public static void main(String[] args) {

//		入力を取得
		Scanner inputData = new Scanner(System.in);
		
//		可変長配列Aを生成
		Vector<Integer> vecA = new Vector<Integer>();
//		最初の数値qの回数だけ処理を反復
		int q = 0;
		if(inputData.hasNext()) {
			q = inputData.nextInt();
		}
		for(int index=1; index<=q; index++) {
//		各数値(0，1，2)毎に処理を分岐
			int action = 0;		// 動作割り当て数値
			int param = 0;		// 動作に紐づいたパラメータ
			action = inputData.nextInt();
			switch(action) {
//				0の場合、Aに数値xを追加
				case 0:
					param = inputData.nextInt();
					vecA.add(param);
					break;
//				1の場合、Aのp番目の要素を出力
				case 1:
					param = inputData.nextInt();
					System.out.println(vecA.get(param));
					break;
//				2の場合、Aの末尾の要素を削除
				case 2:
					vecA.remove(vecA.size() - 1);
					break;
				default	:
						break;
						
			}
			
		}
		inputData.close();

	}

}




Measured memory_bytes: 130372
S = list(input())

ans = 1000
for i in range(len(S)-2):
    sum = ""
    x = S[i:i+3]
    for i1 in x:
        sum += i1
    sum = int(sum)
    y = abs(753 -sum)
    if ans >= y:
        ans = y

print(ans)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
#include <cstdlib> 
#include <math.h>
#include<cstdio>
#include<cstring>
#define FOR(I, A, B) for (ll I = (A); I <= (B); I++)
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fo(i,n) for(ll i=0;i<n;i++)
#define sz(a) ll((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(auto i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define dbg(x) cout << #x << " = " << x << endl
#define dbg2(x,y) cout << #x << " = " << x << ", " << #y << " = " << y << endl
#define dbg3(x,y,z) cout << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << endl
#define dbg4(x,y,z,q) cout << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << ", " << #q << " = " << q << endl
#define scan(char_array) scanf("%[^\n]s",&char_array);

int main(){

	ll n;
	cin>>n;
	ll tmp;
	multiset<ll> st;
	fo(i,n){
		cin>>tmp;
		auto it=st.lower_bound(tmp);
		if(it==st.begin()) st.insert(tmp);
		else{
			it--;
			st.erase(it);
			st.insert(tmp);
		}

	}
	cout<<sz(st)<<endl;
	

}

Measured memory_bytes: 4992
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int a = sc.nextInt();

		System.out.println(a*2*3.14);
	}

}

Measured memory_bytes: 35940
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<climits>
#include<map>
#include<string>
#include<functional>
#include<iomanip>
#include<deque>
#include<random>
#include<set>
#include<bitset>
#include<cassert>

using namespace std;
typedef long long ll;
typedef double lldo;
#define mp make_pair
#define pub push_back
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
ll gcd(ll a, ll b) { if (a % b == 0) { return b; } else  return gcd(b, a % b); }
ll lcm(ll a, ll b) { if (a == 0) { return b; }return a / gcd(a, b) * b; }
template<class T>ll LBI(vector<T>& ar, T in) { return lower_bound(ar.begin(), ar.end(), in) - ar.begin(); }
template<class T>ll UBI(vector<T>& ar, T in) { return upper_bound(ar.begin(), ar.end(), in) - ar.begin(); }

ll x, y;

int main() {
	cin >> x >> y;
	rep(i, x + 1) {
		if (i * 2 + (x - i) * 4 == y) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 3632
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque, OrderedDict
from copy import deepcopy
from fractions import gcd
from functools import lru_cache, reduce
from math import ceil, floor
from sys import setrecursionlimit

import heapq as hq
import itertools as its
import operator as op


# globals
inf = float('inf')
N = 0


def set_inputs():
    global N
    return


def main():
    setrecursionlimit(100000)
    set_inputs()
    # ----------MAIN----------
    n, m = get_li()
    A = get_data(m, [int])
    MOD = 1000000007
    dp = [0] * (n + 2)
    dp[0] = 1
    dp[-1] = 0
    stepable = [True] * (n + 2)
    for a in A:
        stepable[a] = False
    for i in range(1, n + 1):
        if stepable[i]:
            dp[i] = (dp[i-1] + dp[i-2]) % MOD
    print(dp[n])
    return


def get_int():
    return int(input())


def get_float():
    return float(input())


def get_str():
    return input().strip()


def get_li():
    return [int(i) for i in input().split()]


def get_lf():
    return [float(f) for f in input().split()]


def get_lc():
    return list(input().strip())


def get_data(n, types, sep=None):
    if len(types) == 1:
        return [types[0](input().strip()) for _ in range(n)]
    return list(zip(*(
        [t(x) for t, x in zip(types, input().strip().split(sep=sep))]
        for _ in range(n)
    )))


if __name__ == '__main__':
    main()


Measured memory_bytes: 75860
use std::io;
fn main() {
    let line = read_line();
    let mut split = line.split(' ').map(|s| s.parse::<usize>().unwrap());
    let count = split.next().unwrap();
    let disp_rate = split.next().unwrap();
    let internal_rate = if count >= 10 {
        disp_rate
    } else {
        disp_rate + 100 * (10 - count)
    };
    println!("{}", internal_rate);
}
fn read_line() -> String {
    let mut line = String::new();
    io::stdin().read_line(&mut line).unwrap();
    line.pop();
    line
}

Measured memory_bytes: 4352
import java.util.*;
import java.io.*;
import java.math.*;
public class Main {
    public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		PrintWriter ou = new PrintWriter(System.out);
		int n = Integer.parseInt(sc.next());
		sc.close();
		long a = 1;
		long b = 2;
		long c = 1;
		for(int i = 0 ; i < n ; i++){
			a *= 10;
			a %= (long)(Math.pow(10 , 9) + 7);
			b *= 9;
			b %= (long)(Math.pow(10 , 9) + 7);
			c *= 8;
			c %= (long)(Math.pow(10 , 9) + 7);
		}
		long s = (a - b + c) % (long)(Math.pow(10 , 9) + 7);
		while(s < 0) s += Math.pow(10 , 9) + 7;
		ou.println(s);
		ou.flush();
	}
}

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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if (b<c || d<a) {
    cout << 0 << endl;
  }
  else {
    cout << min({d-a, b-c, b-a, d-c});
  }
}


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

using namespace std;

typedef long long ll;

int main()
{
    string S;
    ll K;
    ll now = 0;
    cin >> S;
    cin >> K;
search:
    if(S.at(now) == '1') {
        if(K-1 == now)
            cout << 1 << endl;
        else {
            if(S.at(now+1) != '1') {
                cout << S.at(now+1) << endl;
                return 0;
            }
            now++;
            goto search;
        }
    }
    else cout << S.at(0) << endl;
    return 0;
}


Measured memory_bytes: 256
# https://atcoder.jp/contests/keyence2020/tasks/keyence2020_b
n = int(input())
robots = []
for _ in range(n):
    x, l = map(int, input().split())
    a, b = x - l, x + l
    robots.append((a, b))

robots.sort(key=lambda x: x[1])

t = 0
pre = robots[0][1]
for i in range(1, n):
    a, b = robots[i]
    if a < pre:
        t += 1
    else:
        pre = b
ans = n - t
print(ans)

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

string divide[4] = {"dream", "dreamer", "erase", "eraser"};

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

    reverse(S.begin(), S.end());
    for (int i = 0; i < 4; ++i) reverse(divide[i].begin(), divide[i].end());

    bool can = true;
    int i = 0;
    while(i < S.size()) {
        bool can2 = false;
        for (int j = 0; j < 4; j++){
            string d = divide[j];
            if (S.substr(i, d.size()) == d){
                can2 = true;
                i += d.size();
            }
        }
        if (!can2){
            can = false;
            break;
        }
    }
    if (can){
        cout << "YES" << endl;
    } else{
        cout << "NO" << endl;
    }

    return 0;
}

Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;cin>>n;
  vector<int> arr(n);
  for(int i=0;i<n;++i)cin>>arr[i];
  bool ok= true;
  for(auto i:arr){
    if(i%2==0){
      if(i%3!=0 && i%5!=0)ok = false;
    }
  }
  if(ok){
    cout<<"APPROVED"<<endl;
  }else{
    cout<<"DENIED"<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
#abc 063 c
n=int(input())
s=[]
for i in range(n):
    num=int(input())
    s.append(num)

dp=[[False]*11000 for _ in range(110)]
dp[0][0]=True
for i in range(n):
    for j in range(11000):
        if dp[i][j]==True:
            dp[i+1][j]=True
            dp[i+1][j+s[i]]=True

ans=0
for i in range(11000):
    if dp[n][i]==True and i%10!=0:
        ans=i
print(ans)


Measured memory_bytes: 12404
s1,s2,s3,s4=input()
if s1==s2 and s3==s4 and s1!=s3:
    print("Yes")
elif s1==s3 and s2==s4 and s1!=s2:
    print("Yes")
elif s1==s4 and s2==s3 and s1!=s2:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <queue>
#include <stack>
#include <string>
#include <utility>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <cassert>
#include <cinttypes>

using namespace std;

typedef int64_t ll;
typedef uint64_t ull;

const ll INF = 1e18 + 10;

int n;

ll gcd(ll x, ll y) {
  if (y == 0) {
    return x;
  }
  return gcd(y, x % y);
}

int main() {
  cin >> n;
  ll ans = 1;
  for (int i = 0; i < n; i++) {
    ll t;
    cin >> t;
    ll u = gcd(ans, t);
    ans = max(ans, t) / u * min(ans, t);
  }

  cout << ans << endl;

  return 0;
}

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

const int H = 9;
const int W = 9;

int G[H][W];

bool chack(int pi, int pj) {
  for(int i = 0; i < H; ++i) {
    for(int j = 0; j < W; ++j) {
      if(i == pi && j == pj) continue;
      if(i == pi || j == pj || i/3 == pi/3 && j/3 == pj/3) {
        if(G[i][j] == G[pi][pj]) return true;
      }
    }
  }
  return false;
}

int main() {
  int Tc;
  cin >> Tc;
  for(int tc = 0; tc < Tc; ++tc) {
    for(int i = 0; i < H; ++i) {
      for(int j = 0; j < W; ++j) {
        if(cin >> G[i][j]) ; else return 0;
      }
    }
    if(tc) cout << endl;
    for(int i = 0; i < H; ++i) {
      for(int j = 0; j < W; ++j) {
        cout << ( chack(i, j) ? '*' : ' ' );
        cout << G[i][j];
      }
      cout << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<long long, long long>;
const long long INF = 1001001001;
const long long MOD = 1000000007;
const double EPS = 1e-10;

template<typename T>
struct Edge {
    int from, to;
    T cost;
};

template<typename T>
using Edges = vector<Edge<T>>;

template<typename T>
struct Graph {
    vector<Edges<T>> g;
    Graph(int n): g(n) {}
    int size() { return g.size(); };
    bool add_edge(int from, int to, T cost = 1) {
        g[from].emplace_back((Edge<T>){ from, to, cost });
    }
};

template<typename T>
struct MST {
    Edges<T> es;
    T cost;
};

template<typename T>
vector<T> dijkstra(Graph<T> &g, int s) {
    using Ti = pair<T, int>;
    const auto INF = numeric_limits<T>::max();

    vector<T> dist(g.size(), INF);
    priority_queue<Ti, vector<Ti>, greater<Ti>> pq;
    pq.push(Ti(0, s));
    dist[s] = 0;
    while(!pq.empty()) {
        Ti t = pq.top(); pq.pop();
        int v = t.second;
        for(auto e : g.g[v]) {
            if(dist[e.to] > dist[v] + e.cost) {
                dist[e.to] = dist[v] + e.cost;
                pq.push(Ti(dist[e.to], e.to));
            }
        }
    }
    return dist;
}

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

    int v,e,r;
    cin>>v>>e>>r;
    Graph<ll> g(v);
    for(int i=0;i<e;i++){
        ll s,t,d;
        cin>>s>>t>>d;
        g.add_edge(s,t,d);
    }
    vector<ll> dist = dijkstra<ll>(g,r);
    for(int i=0;i<v;i++){
        if(dist[i]==numeric_limits<ll>::max())cout<<"INF"<<endl;
        else cout<<dist[i]<<endl;
    }
}


Measured memory_bytes: 19460
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define p (int)(1e9 + 7)

int power(int a, int N){
	return N == 0 ? 1 : (a * power(a, N - 1)) % p;
}

signed main(){
	int N, X, Y, Z, i, j, k, l, ans = 0;
	scanf("%lld%lld%lld%lld", &N, &X, &Y, &Z);
	int S = X + Y + Z;
	vector<vector<int>> dp(N + 1, vector<int>(1 << S, 0));
	dp[0][0] = 1;
	for(i = 0; i < N; i++){
		for(j = 0; j < (1 << S); j++){
			for(k = 1; k <= 10; k++){
				l = ((j << k) + (1 << (k - 1)) & ((1 << S) - 1));
				if((l | (((((1 << X) + 1) << Y) + 1) << (Z - 1))) != l){
					dp[i + 1][l] = (dp[i + 1][l] + dp[i][j]) % p;
				}
			}
		}
	}
	for(j = 0; j < (1 << S); j++){
		ans = (ans + dp[N][j]) % p;
	}
	printf("%lld\n", (power(10, N) - ans + p) % p);
	return 0;
}

Measured memory_bytes: 43392
// E - Divisible Substring
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0;i<(n);++i)
#define modadd(x,y,m) x=(x+(y))%(m)
#define modmul(x,y,m) x=(x*(y))%(m)
#define c2d(c) ((c)-'0') // char to digit

int main(){
	ll N,P; string S; cin>>N>>P>>S;
	ll ans = 0;
	if(P==2 || P==5){
		rep(i, N) if(c2d(S[N-1-i]) % P == 0) ans += N - i;
	}
	else{
		reverse(S.begin(), S.end());
		vector<ll> cnt(P, 0);
		ll r = 0, ten = 1;
		cnt[r]++;
		rep(left, N){
			modadd(r, c2d(S[left])*ten, P);
			modmul(ten, 10, P);
			cnt[r]++;
		}
		rep(r, P) ans += cnt[r] * (cnt[r]-1) / 2;
	}
	cout<< ans <<endl;
}

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

using namespace std;
typedef long long int lli;

#define all(arr) arr.begin(),arr.end()
#define f first
#define s second
#define debug1(x) cout<<x<<"\n"
#define debug2(x,y) cout<<x<<" "<<y<<"\n"
#define debug3(x,y,z) cout<<x<<" "<<y<<" "<<z<<"\n"
#define nl cout<<"\n";
#define pq priority_queue
#define inf 0x3f3f3f3f
#define test cout<<"abcd\n";
#define pi pair<int,int>
#define pii pair<int,pi>
#define pb push_back
#define gc getchar_unlocked
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define si(x)	scanf("%d",&x)
#define sl(x)	scanf("%lld",&x)
#define ss(s)	scanf("%s",s)
#define pl(x)	printf("%lld\n",x)
#define ps(s)	printf("%s\n",s)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define MOD 1000000007
#define space ' '
#define kick(t) cout << "Case #" << t << ":" << endl;
#define add(x, y) (x%MOD+y%MOD)%MOD
typedef pair<ll, ll>	pl;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<pii>		vpii;
typedef vector<pl>		vpl;
typedef vector<vi>		vvi;
typedef vector<vl>		vvl;

template <typename T>
void input(vector<T> &arr,lli n) {
  T temp;
  for(lli i=0;i<n;i++) cin>>temp, arr.push_back(temp);
}

template <typename T>
void output(vector<T> arr) {
  for(auto x:arr) cout<<x<<" ";
  cout<<endl;
}


template <typename T>
void input_set(set<T> &arr,lli n) {
  T temp;
  for(lli i=0;i<n;i++) cin>>temp, arr.insert(temp);
}

lli mul(lli a, lli b) {
  return (a%MOD*b%MOD)%MOD;
}

lli power(lli a,lli b) {
  lli ans = 1;
  while(b > 0) {
    if(b&1)
      ans = mul(ans, a);
    a = mul(a,a);;
    b >>= 1;
  }
  return ans;
}

void solve() {
  lli n;
  cin >> n;
  vector<lli> dp(n+1, 0);
  dp[3]=1;
  dp[0]=1;
  for(int i=4; i<=n; i++) {
    dp[i]=1;
    for(int j=3; j<=i-3; j++) {
      dp[i]=add(dp[i], dp[i-j]);
    }
  }
  cout << dp[n] << endl;
}

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

  lli testcases;
  testcases=1;
  while(testcases--) {
    solve();
  }
}



Measured memory_bytes: 3636
n=int(input())
arr=[]
for _ in range(n):
    a,b = map(int,input().split())
    arr.append((a,b))
ans=0
for ab in reversed(arr):
    a = ab[0]+ans
    b = ab[1]
    if a%b!=0:
        ans+=b*(a//b+1)-a
print(ans)



Measured memory_bytes: 16672
N = int(input())
H = list(map(int,input().split()))

max_cnt = 0
cnt_list = [0]
for i in range(N-2,-1,-1):
    value = H[i]
    cnt = 0
    cnt_list.append(cnt_list[-1]+1) if H[i] >= H[i+1] else cnt_list.append(0)
    #print(cnt_list)
print(max(cnt_list))


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

int main(){
	int N, M, X, Y, in, max_x, min_y;
	bool flag = true;
	vector<int> x, y;
	cin >> N >> M >> X >> Y;
	for(int i=0; i<N; i++){
		cin >> in;
		x.push_back(in);
	}
	for(int i=0; i<M; i++){
		cin >> in;
		y.push_back(in);
	}
	max_x = *max_element(x.begin(), x.end());
	min_y = *min_element(y.begin(), y.end());
	if(min_y <= max_x ){
		flag = false;
	}else if(Y <= max_x ){
		flag = false;
	}else if(min_y <= X){
		flag = false;
	}
	cout << (flag ? "No War" : "War") << endl;
	return 0;
}


Measured memory_bytes: 256
n = gets.to_i
p_input = gets.chomp.split
n.times do |i|
    p_input[i] = p_input[i].to_i
end

count = 0
min = p_input[0]
n.times do |i|
    result = true
    min = p_input[i] if p_input[i] < min
    result = false if !(p_input[i] <= min)
    count += 1 if result
end

puts count

Measured memory_bytes: 14984
#include<bits/stdc++.h>
using namespace std;
int main(){
  int H, W;
  cin >> H >> W;
  vector<string> map(H);
  for ( int i = 0; i < map.size() ; i++){
    cin >> map.at(i);
  }
  vector<int> row = { -1 , 0 , 1};
  vector<int> column = { -1 , 0 , 1};
  for ( int i = 0 ; i < map.size(); i++){
    for ( int j = 0 ; j < map.at(0).size(); j++){
      if ( map.at(i).at(j) == '.'){
        int count = 0;
      	for ( int x : row ){
       	 for ( int y : column){
          	if (0 <= (i + x) && (i + x) < H && 
                0 <= (j + y) && (j + y ) < W &&
                map.at(i + x).at(j + y) == '#' ) count++;
                   map.at(i).at(j) = '0' + count;
       	 }
      	}
      }
    }
  }
  
  for ( string x : map ){
    cout << x << endl;
  }
}

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

using namespace std;

string s;
int fr[26];

int main() {
  int st, dr, cent;
  long long rez;
  cin >> s;
  rez = (long long)s.size() * (s.size() + 1) / 2;
  
  for(int i = 0; i < s.size(); ++i) {
    fr[s[i] - 'a']++;
    rez -= fr[s[i] - 'a'];
  }

  cout << rez + 1;
  return 0;
}


Measured memory_bytes: 640