akhauriyash/Code-Regression huggingface dataset:
# A - ι⊥l

# 3本の柱が等間隔に並んでいる
# 柱の高さは左から順に a[m] b[m] c[m]
# 柱の先端が同一線上に並んでいるとき
# ⇔ b - a = c - b
# 美しいな！

# a b c を標準入力から得る
a, b, c = map(int, input().split(maxsplit=3))
# print(a, b, c)

# b - a を計算
pillar_ba = b - a
# c - b を計算
pillar_cb = c - b
# print(pillar_ba, pillar_cb)

# pillar_ba ⇔ pillar_cb の時　Yes
# そうでないとき　No を代入
if pillar_ba == pillar_cb:
    answer = "YES"
else:
    answer = "NO"

# 結果を出力
print(answer)


Measured memory_bytes: 9048
N = int(input())
S = input()
nR = 0
nG = 0
nB = 0
cnt = 0
for i in range(N):
  if S[i] == 'R':
    nR += 1
  elif S[i] == 'G':
    nG += 1
  else:
    nB += 1
  for j in range(i+1, N):
    k = j - i + j
    if k < N:
      L = [S[i], S[j], S[k]]
      if 'R' in L and 'G' in L and 'B' in L:
        cnt += 1
    else:
      break
print(nR*nG*nB-cnt)


Measured memory_bytes: 9208
#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<cmath>

using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
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; }

#define MAX 1000000005
#define INF INT_MAX

typedef long long ll;
typedef pair<int, int> P;

int main(int, char**)
{
    int n, m, x;
    cin >> n >> m >> x;

    vector<int> c(n);
    vector< vector<int> > a(n, vector<int>(m));

    rep(i,n) {
        cin >> c[i];
        rep(j,m) cin >> a[i][j];
    };

    int sum;
    int e = pow(2, n);
    int ans = INF;
    rep(i,e) {
        int sum = 0;
        vector<int> skill(m, 0);
        rep(j,n) {
            if (i & (1<<j)) {
                sum += c[j];
                rep(k,m) {
                    skill[k] += a[j][k];
                }
            }
        }
        int ok = 0;
        rep(j,m) if (skill[j] >= x) ok++;
        if (ok == m) ans = min(ans, sum);        
    }

    if (ans == INF) cout << -1 << endl;
    else cout << ans << endl;

    return 0;
}

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


int main(){
    vector<int> x(3);
    cin >> x[0] >> x[1] >> x[2];
    sort(x.begin(), x.end());
    if (x[0] == 5 && x[1] == 5 && x[2] == 7) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

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

#define fi first
#define se second
#define be begin
#define en end
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ALL(a) (a).be() , (a).en()
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)        //repeat n times
#define REP2(i,s,n) for(int (i)=(s);(i)<(n);(i)++)   //repeat from s to n 
#define REPD(i,n) for(int (i)=(n);(i)>=0;(i)--)      //repeat from n to 0
#define REPD2(i,s,e) for(int (i)=(s);(i)>=(e);(i)--) //repeat from s to e
#define RANGE(i,v) for(auto &(i):v)                  //repeat range
#define ASIZE(a) (sizeof(a) / sizeof(a[0]))          //array size

using LL = long long;

template<typename T> using V = vector< T >;
using Vi = V<int>;
using Vll = V<LL>;
using Vs = V<string>;

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

    int cnt_1 = 0;
    int cnt_2 = 0;
    REP(i,s.size()){
        if(i%2==0){
            if(s[i]!='0') cnt_1++;
            if(s[i]!='1') cnt_2++;
        }else{
            if(s[i]!='1') cnt_1++;
            if(s[i]!='0') cnt_2++;
        }
    }

    cout<<min(cnt_1,cnt_2)<<endl;

    return 0;
}

Measured memory_bytes: 512
/* ~ Programmer >> Tushar Mahajan */
#include <iostream>
#include <bits/stdc++.h> 
using namespace std;
#define ll long long int
#define ld long double
#define MOD 1000000007
#define ios ios_base::sync_with_stdio(false);cin.tie(NULL); 

int main() {
	ios;
	ll n,r=0,w=0,count = 0;
	cin>>n;
	string s;
	cin>>s;
	for(int i=0;i<n;i++)
	{
	    if(s[i]=='R')
	    {
	        r++;
	    }
	    else
	    {
	        w++;
	    }
	}
	for(int i=0;i<r;i++)
	{
	    if(s[i]=='R')
	    {
	        count++;
	    }
	}
	cout<<min(w,r-count)<<endl;
	return 0;
}


Measured memory_bytes: 3672
#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};
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; }
#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 << " "
//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

int main()
{
    ios::sync_with_stdio(0); 
    cin.tie(0); 
    cout.tie(0);
    ll X, N;
    cin >> X >> N;
    VLL p(N);
    rep(i,N){
        cin >> p[i];
    }   
    if(find(all(p),X)==p.end()){
        cout << X << endl;
        return 0;
    }
    ll minus=X;
    ll plus=X;
    ll count_minus=0;
    ll count_plus=0;
    while(1){
        if(find(all(p),minus)==p.end()){
            count_minus=minus;
            break;
        }
        minus--;
 //       cout << minus << endl;
    }
    while(1){
        if(find(all(p),plus)==p.end()){
            count_plus=plus;
            break;
        }
        plus++;
    }
    //cout << count_minus << " " << count_plus << endl;
    int a=abs(X-count_minus);
    int b=abs(X-count_plus);
    if(a<b){
        cout << count_minus << endl;
    }
    else if(a>b){
        cout << count_plus << endl;
    }
    else{
        cout << min(count_minus,count_plus) << endl;
    }
}

Measured memory_bytes: 3656
S=input()
if S=='SUN':
    print(7)
if S=='SAT':
    print(1)
if S=='FRI':
    print(2)
if S=='THU':
    print(3)
if S=='WED':
    print(4)
if S=='TUE':
    print(5)
if S=='MON':
    print(6)

Measured memory_bytes: 38384
# 一番高い花の両隣に同じ高さの花があれば1減らす
# 自分も1減らす
# これを繰り返す
N = int(input())
h = list(map(int, input().split()))
def bury(x):
    for i in range(1,N):
        if x+i >= N or h[x+i] != h[x]:
            break
        else:
            h[x+i] -= 1
    for i in range(1,N):
        if x-i < 0 or h[x-i] != h[x]:
            break
        else:
            h[x-i] -= 1
    h[x] -= 1
 
ans = 0
while sum(h) > 0:
    bury(h.index(max(h)))
    ans += 1
    
print(ans)

Measured memory_bytes: 3064
s = input()

num_pat = 2 **(len(s) - 1)
ans = 0
for i in range(num_pat):
    subans = 0
    wait = 0
    for j in range(len(s) - 1):
        if ((i >>j) & 1):
            wait += int(s[j])
            subans += wait
            wait = 0
        else:
            wait += int(s[j])
            wait *= 10
    subans += wait
    subans += int(s[-1])
    ans += subans

print(ans)

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

int main() {
    

    // cinを高速にするためのおまじない
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    //Write code below
    
    string str;
    
    cin >> str;
    
    if(str.at(0) == str.at(1) && str.at(2) == str.at(3) && str.at(1) != str.at(2)) {
        cout << "Yes" << endl;
        exit(0);
    }
    
    if(str.at(0) == str.at(2) && str.at(1) == str.at(3) && str.at(0) != str.at(1)) {
        cout << "Yes" << endl;
        exit(0);
    }
    
    if(str.at(0) == str.at(3) && str.at(1) == str.at(2) && str.at(0) != str.at(1)) {
        cout << "Yes" << endl;
        exit(0);
    }
    
    cout << "No" << endl;

}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int A,B,C;
	scanf("%d %d %d",&A,&B,&C);
	if(A==B){
		printf("%d\n",C);
	}
	else if(B==C){
		printf("%d\n",A);
	}
	else if(A==C){
		printf("%d\n",B);
	}
	return 0;
}

Measured memory_bytes: 128
from collections import deque

n=int(input())

if n < 10:
    print(n)
else:
    check_box = deque([1,2,3,4,5,6,7,8,9])
    check_num = 9
    while True:
        add_num = check_box.popleft()
        add_num = str(add_num)

        if int(add_num[-1]) - 1 >= 0:
            check_box.append(int(add_num + str(int(add_num[-1]) - 1)))
            check_num += 1
            if check_num == n:
                    print(add_num + str(int(add_num[-1]) - 1))
                    exit()

        check_num += 1
        check_box.append(int(add_num + add_num[-1]))
        if check_num == n:
                print(add_num + add_num[-1])
                exit()

        if int(add_num[-1]) + 1 <= 9:
            check_box.append(int(add_num + str(int(add_num[-1]) + 1)))
            check_num += 1
            if check_num == n:
                    print(add_num + str(int(add_num[-1]) + 1))
                    exit()
        

Measured memory_bytes: 76692
#include <iostream>

using namespace std;

int main(){
  int N, K, i;
  cin >> N >> K;
  char S[N];
  for(i=0; i<N; i++) cin >> S[i];
  S[K-1] = S[K-1] + 32;
  for(i=0; i<N; i++) cout << S[i];
  cout << endl;
  return 0;
}


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

typedef long long LL;
const int N = 1e5 + 5;

int a[N], b[N], id[N], nxt[N][62];
LL tab[N];

int main() {
  int n, m;
  LL k;
  scanf("%d", &n);
  for (int i = 1; i <= n; i ++) scanf("%d", &a[i]);
  for (int i = n; i; i --) a[i] -= a[i - 1], id[i] = i;
  scanf("%d%lld", &m, &k);
  for (int i = 1, x; i <= m; i ++) {
    scanf("%d", &x);
    swap(id[x], id[x + 1]);
  }
  for (int i = 1; i <= n; i ++) nxt[id[i]][0] = i;
  tab[0] = 1;
  for (int i = 1; i < 62; i ++) {
    for (int j = 1; j <= n; j ++) nxt[j][i] = nxt[nxt[j][i - 1]][i - 1];
    tab[i] = tab[i - 1] << 1;
  }
  LL t;
  for (int i = 1, p; i <= n; i ++) {
    t = k;
    p = i;
    for (int j = 61; (~ j) && t; j --)
      if (tab[j] <= t) {
	t -= tab[j];
	p = nxt[p][j];
      }
    b[p] = a[i];
  }
  k = 0;
  for (int i = 1; i <= n; i ++) {
    k += b[i];
    printf("%lld.0\n", k);
  }
  return 0;
}


Measured memory_bytes: 26880
using System;
using System.Linq;
using static System.Console;

namespace C
{
    internal class Program
    {
        public static void Main(string[] args)
        {
            var xn = ReadLine().Split(' ').Select(int.Parse);
            if (xn.Last() == 0)
            {
                WriteLine(xn.First());
                return;
            }

            var pList = ReadLine().Split(' ').Select(int.Parse).ToList();
            var target = xn.First();
            if (!pList.Contains(target))
            {
                WriteLine(target);
                return;
            }

            int CheckDecrement(int t)
            {
                t--;
                if (!pList.Contains(t)) return t;
                pList.Remove(t);
                return CheckDecrement(t);
            }
            int CheckIncrement(int t)
            {
                t++;
                if (!pList.Contains(t)) return t;
                pList.Remove(t);
                return CheckIncrement(t);
            }

            var lower =CheckDecrement(target);
            var higher =CheckIncrement(target);
            var lDist = Math.Abs(lower - target);
            var hDist = Math.Abs(higher - target);
            if (lDist == hDist)
            {
                WriteLine(lower);
            }
            else
            {
                WriteLine(lDist < hDist ? lower : higher);
            }
        }
    }
}

Measured memory_bytes: 28280
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>

unsigned long Sqrt(unsigned long x) {
    unsigned long i=1;
    while(1) {
        if(i*i > x) {
            break;
        }
        i++;
    }
    if(i-1 > 1) {
        return i-1;
    }
    return 1;
}


int main() {
    unsigned long N;
    scanf("%lu", &N);
    unsigned long m = Sqrt(N);

    unsigned long i;
    unsigned long j;
    i = m;
    while(1) {
        if(N % i == 0) {
            break;
        }
        i--;
    }
    j = N / i ;
    unsigned long mini = i + j;
    printf("%lu\n", mini-2);
    return 0;
}

Measured memory_bytes: 128
#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 ranger(i, a, b) for (int i = (a)-1; i >= (b); i--)
#define repr(i, b) for (int i = (b)-1; i >= 0; 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, typename S>
ostream& operator<<(ostream& os, pair<T, S>& p) {
	os << '(' << p.first << ',' << p.second << ')';
	return os;
}
template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
	for (T& x : v) { is >> x; }
	return is;
}

const int M = 1000000007;

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

	vector<int> a(n);
	cin >> a;

	int ans = 1;
	int c[3] = {};

	auto cnt = [&](int k){
		int res = 0;
		rep(i,3){
			if(c[i] == k) res++;
		}
		rep(i,3){
			if(c[i] == k){
				c[i]++;
				break;
			}
		}
		return res;
	};

	rep(i,n){
		(ans *= cnt(a[i]))%=M;
	}
	cout << ans << endl;
}


Measured memory_bytes: 1024
N, M = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
A = sorted(A, reverse=True)
total = sum(A)

f = True

for i in range(M):
    if total / (4 * M) > A[i]:
        f = False

if f == True:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3060
n,k = map(int,input().split())
def Base_10_to_n(X, n):
    X_dumy = X
    out = ''
    while X_dumy>0:
        out = str(X_dumy%n)+out
        X_dumy = int(X_dumy/n)
    return out
print(len(Base_10_to_n(n,k)))

Measured memory_bytes: 38256
//#include "bits/stdc++.h"
#include <iostream>
#include <vector>
#include <map>
#include <utility>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <complex>
#include <bitset>
#include <functional>
#include <stack>
#include <regex>
#include <tuple>
#include <iomanip>

#define int long long
#define REP(i,l,r) REPEAT(i,l,r,true) //[l, r)
#define rep(i,n) REP(i,0,n)           //[0, n)
#define REPEAT(i,l,r,condition) for(int i=(condition)?l:r-1;(condition)?i<r:i>=l;(condition)?++i:--i) // false<-[l, r)->true
#define all(e) e.begin(),e.end()
#define rall(e) e.rbegin(),e.rend()
#define pb push_back
#define fs first
#define sc second
#define show(...) cerr<<#__VA_ARGS__<<" = ";_DEBUG(__VA_ARGS__)
#define shows(n) for(auto z:n){cerr<<z<<", ";}cerr<<endl
#define showslr(n,l,r) cerr<<#n<<" = ";for(int i=l;i<r;i++){cerr<<n[i];}cerr<<endl //[l, r))

#define yes puts("Yes")
#define no puts("No")
#define case(i) printf("Case #%lld: ",i)

using namespace std;

using vi=vector<int>;
using pint=pair<int,int>;

inline void io(){cin.tie(0);ios::sync_with_stdio(false);cout.tie(0);cout<<fixed<<setprecision(20);}

void _DEBUG(){cerr<<endl;}
template<typename H,typename... T> void _DEBUG(H a,T...b){cerr<<a<<",";_DEBUG(b...);}

template<typename T> inline void in(T &e){cin>>e;}
template<typename H,typename... T>void in(H &a, T&... b){in(a);in(b...);}
template<typename T> inline void out(T e){cout<<e<<endl;}
template<typename H,typename... T> void out(H a, T... b){out(a);out(b...);}

const int INF=1LL<<55;
const int MOD=1000000007;
const double EPS=1e-8;

int n,k;
vi a;
int ans;
vi b;

signed main(){
    io();

    in(n,k);
    REP(i,1,n+1){
        if(!(k&1)){
            if((i%k)==(k/2)){
                b.pb(i);
            }
        }
        if(i%k==0){
            a.pb(i);
        }
    }
    //show(a.size(),b.size());
    ans=a.size()*a.size()*a.size();
    ans+=b.size()*b.size()*b.size();

    out(ans);

    return 0;
}


Measured memory_bytes: 2420
MOD = 10 ** 9 + 7
n = int(input())

res = 1
ex = [0 for _ in range(n + 1)]
for i in range(1, n + 1):
    for j in range(2, i + 1):
        if i % j == 0:
            while i % j == 0:
                ex[j] += 1
                i //= j

ans = 1
for i in range(n + 1):
    ans *= (ex[i] + 1)
    ans %= MOD
    
print(ans)


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

typedef long long ll;

int main(){
	string S;
	cin >> S;
	if(S[3]=='7'){
		S[3] = '8';
	}
	cout << S << endl;

	return 0;
}

Measured memory_bytes: 3608
N, M = [int(n) for n in input().split()]
heights = [int(n) for n in input().split()]

graph = {n:set() for n in range(1,N+1)}
for _ in range(M):
    A, B = [int(n) for n in input().split()]
    graph[A].add(B)
    graph[B].add(A)

total = 0
for node in graph:
    if graph[node] == None:
        total += 1
    else:
        better = True
        for nbr in graph[node]:
            if heights[nbr-1] >= heights[node-1]:
                better = False
                break
        if better:
            total += 1

print(total)
        

Measured memory_bytes: 53920
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
#pragma GCC optimize("unroll-loops")
#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <stdio.h>
#include <fstream>
#include <cmath>
#include <stdlib.h>
#include <iomanip>
#include <algorithm>
#include <limits.h>
#include <stack>
#include <cmath>
#include <math.h>
#include <array>
using namespace std;
#define FAST_IO ios::sync_with_stdio(false);
#define DEBUG_VIS(x) cerr<<"vis "<<x<<endl;
#define DEBUG_REACH cerr<<"reach here"<<endl;
#define DEBUG_SEQ(x) cerr<<x<<" ";
#define SET_ZERO(x) memset(x,0,sizeof(x));
#define SET_NEGONE(x) memset(x,-1,sizeof(x));
#define SET_INF(x) memset(x,127,sizeof(x));
#define SET_NEGINF(x) memset(x,128,sizeof(x));
#define IS_INF(x) x < 2100000000
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
typedef pair<double,double> pdd;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
const int maxn = 1e6 + 10;
template <class T> T mymin(const T a,const T b){return a < b ? a : b;}
template <class T> T mymax(const T a,const T b){return a > b ? a : b;}
ll dp[55][125005];
ll N,D,X;
ll sum[55],sz[55],fa[55],cnt,pos[55];
int main(){
    FAST_IO
    cin>>N>>X>>D;
    for(int i = 1; i <= N; i++){
        cin>>sum[i];
        if(i != 1) cin>>fa[i];
    }
    for(int i = N; i >= 1; i--){
        sum[fa[i]] += sum[i];
        sz[fa[i]] += ++sz[i];
        cnt += sz[i] * N;
        pos[i] = i;
    }
    sort(pos + 1, pos + 1 + N,[](auto x,auto y){return sum[x] * sz[y] < sum[y] * sz[x];});
    for(int i = 1; i <= cnt; i++) dp[0][i] = 1e9 + 10;
    ll tmp = min(N,D);
    for(int i = 1; i <= N; i++){
        memcpy(dp[i],dp[i - 1],sizeof(dp[0]));
        for(int j = 0; j <= cnt; j++){
            for(int k = 1; k <= tmp && j - k * sz[i] >= 0; k++){
                dp[i][j] = min(dp[i][j],dp[i - 1][j - k * sz[i]] + k * sum[i]);
            }
        }
    }
    ll ans = 0;
    for(int i = 0; i <= cnt; i++){
        if(dp[N][i] > X) continue;
        ll tmpans = i,rest = X - dp[N][i];
        for(int j = 1; j <= N; j++){
            ll used = min(max(D - N,0LL),rest / sum[pos[j]]);
            if(pos[j] == 1) used = rest / sum[pos[j]];
            rest -= sum[pos[j]] * used;
            tmpans += sz[pos[j]] * used;
        }
        ans = max(ans,tmpans);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 50944
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <deque>
using namespace std;

int main()
{
    int n, s[2000], m, idx1[130010], idx2[130010];
    bool ex=false;
    s[0]=0;
    for (int i=1; i<500; i++)
    {
        s[i]=(i+1)*i/2;
        for (int j=s[i-1]+1; j<=s[i]; j++)
        {
            idx1[j]=j-s[i-1];
            idx2[j]=i+1;
        }
    }
    cin>>n;
    for (int i=1; i<500; i++)
    {
        if (s[i]==n) { ex=true; m=i+1; }
    }
    if (!ex) { cout<<"No\n"; return 0; }
    cout<<"Yes\n";
    /*if (n==1)
    {
        cout<<1<<' '<<1<<endl;
        cout<<1<<' '<<1<<endl;
        return 0;
    }
    if (n==3)
    {
        cout<<1<<' '<<2<<endl;
        cout<<1<<' '<<3<<endl;
        cout<<2<<' '<<3<<endl;
        return 0;
    }*/
   vector<vector<int>> vec(m+1);
    for (int i=1; i<=n; i++)
    {
        vec[idx1[i]].push_back(i);
        vec[idx2[i]].push_back(i);
    }
    cout<<m<<endl;
    for (int i=1; i<=m; i++)
    {
        cout<<vec[i].size()<<' ';
        for (int j=0; j<vec[i].size(); j++)
        {
            if (j!=vec[i].size()-1) cout<<vec[i][j]<<' ';
            else cout<<vec[i][j]<<endl;
        }
    }
    /*for (int i=1; i<=15; i++)
    {
        cout<<idx1[i]<<' '<<idx2[i]<<endl;
    }*/
    return 0;
}


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

int main(){
  int n, m;

  while(cin >> n >> m){
    int ans = m;

    for(int i = 0; i < n; i++){
      int a, b;
      cin >> a >> b;

      if(ans == -1) continue;

      m += a;
      m -= b;

      if(m < 0){
        ans = -1;
      }
      else{
        ans = max(ans, m);
      }
    }

    cout << (ans == -1 ? 0 : ans) << endl;
  }
}

Measured memory_bytes: 1160
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cassert>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define rep(i,n) FOR(i,0,n)
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define vint vector<int>
#define vdouble vector<double>
#define vstring vector<string>
using namespace std;

#include<map>
#include<set>
#include<queue>

typedef long long ll;
typedef unsigned long long ull;

const int MAX_N = 1000000;

int main() {
    ll N, X;
    cin >> N >> X;

    ll n, x, ret;
    if(X <= N / 2){
        n = N - X;
        x = X;
        ret = N;
    }
    else{
        n = X;
        x = N - X;
        ret = N;
    }

    while(true){
        if(n % x == 0){
            ret += 2 * n - x;
            break;
        }
        else{
            ret += (n / x) * x * 2;
            ll tn, tx;
            tn = x; tx = n % x;
            n = tn; x = tx;
        }
    }

    cout << ret << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1000000000000
int main()
{
    ll n;
    cin>>n;
    ll a[n+1];
    for(int i=0;i<n;i++)
    cin>>a[i];
    ll k=a[0];
    ll ans=0;
    for(int i=1;i<n;i++)
    {
        if(a[i]<k)
        ans+=(k-a[i]);
        k=max(k,a[i]);
    }
    cout<<ans<<"\n";
    return 0;
}


Measured memory_bytes: 5120
#include <bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)


int main() {
  int a;
  cin >> a;
  if (a == 0) {
    cout << 1;
  } else {
    cout << 0;
  }
}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 1e5 + 5;
const ll mo = 1e10 +7;
const int M = 100+50;
const ll mod = 998244353;
int main(){
	ll n;
	scanf("%lld",&n);
	ll ans=0;
	if(n==1||n==2||n==4)
	    printf("4\n");
	else{
	    while(n!=4){
		    if(n%2==0)
		        n=n/2;
	    	else
	    	    n=3*n+1;
	    	ans++;
	    }
	    printf("%lld\n",ans+4);		
	}

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct CELL{
  long key;
  int count;
  struct CELL *next;
} data;

int insert(long hash,long key);
int search(long hash,long key);

data *h[100005];

long delete=0;

int main(void){
  int N,i,n;
  long a[100005];
  char str[1100000],*p;
  data *t;
  
  fgets(str,sizeof(str),stdin);
  N=atoi(str);
  
  fgets(str,sizeof(str),stdin);
  p=strtok(str," \n");
  a[0]=atol(p);
  insert(a[0]%N,a[0]);
  
  for(i=1;i<N;i++){
    p=strtok(NULL," \n");
  	a[i]=atol(p);
    insert(a[i]%N,a[i]);
  }
  
  for(i=0;i<N;i++){
    n=search(a[i]%N,a[i]);
    if(n<a[i]){
    	delete+=n;
    }else if(n>a[i]){
      	delete+=n-a[i];
    }
  }
  
  printf("%ld\n",delete);
  
  return 0;
}


int insert(long hash,long key){
    data *p;
    if(h[hash]==NULL){
        p=malloc(sizeof(data));
        p->key=key;
        p->count=1;
        p->next=h[hash];
        h[hash]=p;
        return 0;
    }else{
        p=h[hash];
        while(p!=NULL){
            if(p->key==key){
                p->count++;
                return 0;
            }
            p=p->next;
        }
        p=malloc(sizeof(data));
        p->key=key;
        p->count=1;
        p->next=h[hash];
        h[hash]=p;
    }
    
    return 0;
}

int search(long hash,long key){
    data *p,*q;
    int n;
    if(h[hash]==NULL){
        return 0;
    }else{
        p=h[hash];
        if(p->key==key){
            n=p->count;
            h[hash]=p->next;
            free(p);
            return n;
        }
        q=p,p=p->next;
        while(p!=NULL){
            if(p->key==key){
                n=p->count;
                q->next=p->next;
                free(p);
                return n;
            }
            q=p,p=p->next;
        }
    }
    return 0;
}

Measured memory_bytes: 5632
INF = 1000000007
s = list(input())
t = list(input())
lis = [[0] for i in range(26)]
for i in range(len(s)):
    lis[ord(s[i])-ord('a')].append(i+1)

for i in range(26):
    lis[i].append(INF)
#print(lis)

def binary_search(val,lis):
    ng = 0
    ok = len(lis)-1
    while abs(ng-ok) > 1:
        mid = (ok+ng)//2
        if lis[mid] > val:
            ok = mid
        else:
            ng = mid
        #print(ok,ng)
    return lis[ok]
# print(binary_search(5,[3,4,5,6,7,8]))

ans = 0
p = 0
for i in t:
    j = ord(i) - ord('a')
    if len(lis[j]) == 2:
        print(-1)
        exit()
    val = binary_search(p,lis[j])
    p = val
    if val == INF:
        ans += len(s)
        p = binary_search(0,lis[j])
    #print(p)
print(ans + p)


Measured memory_bytes: 87908
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) x.begin(),x.end()
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
typedef long long ll;

using namespace std;

int main() {
   int n;
   string s;
   cin >> n >> s;
   int ans=0;
   rep(i,n-1){
      if(s[i]!=s[i+1])
      ans++;
   }
   ans++;
   cout << ans << endl;
}   

Measured memory_bytes: 512
// Problem Link: 
// Tutorial Link: 

#include<bits/stdc++.h>
 
using namespace std;
 
#define LL long long
#define pb push_back
#define pLL pair<LL,LL>
#define ff first
#define ss second
#define rep(i,a,b) for(LL i=a;i<=b;++i)
#define repb(i,a,b) for(LL i=a;i>=b;--i)
#define ld double
#define mp make_pair
#define vLL vector<LL>
#define vpLL vector<pLL>
#define vld vector<ld>
#define pld pair<ld,ld>
#define vpld vector<pld>
#define SLL set<LL>
#define SpLL set<pLL>
#define FIO ios::sync_with_stdio(false)
#define mod 1000000007

LL n, a[105];

int main()
{
	FIO;
	cin >> n;
	rep(i,1,n) cin >> a[i];
	LL ans = 0;
	rep(i,1,n) if(a[i] % 2 != 0 && i%2 != 0) ans++;
	cout << ans << endl;
}

Measured memory_bytes: 3608
open System

let modConst = 1e9+7. |> int64

let N = stdin.ReadLine() |> int64

let modpow x y =
    let rec submodpow accum index =
        match index with
        | _ when index = y -> accum
        | _ -> submodpow (accum * x % modConst) (index + 1L)

    submodpow 1L 0L

let solveF x = modpow x N

printfn "%d" ((((solveF 10L) - (solveF 9L) - (solveF 9L) + (solveF 8L)) + modConst + modConst ) % modConst)


Measured memory_bytes: 30024
inpl = lambda: list(map(int,input().split()))
N = int(input())
AB = [ inpl() for _ in range(N) ]
AB.sort()
if N % 2:
    med1 = AB[(N+1)//2-1][0]
else:
    med1 = AB[N//2-1][0] + AB[N//2][0]

AB.sort(key=lambda x: x[1])
if N % 2:
    med2 = AB[(N+1)//2-1][1]
else:
    med2 = AB[N//2-1][1] + AB[N//2][1]

print(med2 - med1 + 1)


Measured memory_bytes: 113004
from collections import Counter
n = int(input())
a = list(map(int,input().split()))
q = int(input())
ans = sum(a)
count = Counter(a)
for i in range(q):
    b,c = map(int,input().split())
    ans = ans + (c-b)*count[b]
    count[c] += count[b]
    count[b] = 0
    print(ans)

Measured memory_bytes: 24200
#include <algorithm>
#include <cmath>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

bool v_cmp(const pair<int, int> &p, const pair<int, int> &q) {
    return p.second < q.second;
}
// sort(v.begin(), v.end(), v_cmp); // small to large

int main() {
    int H, W;
    cin >> H >> W;

    vector<vector<int>> c(10, vector<int>(10, 0));
    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 10; j++) {
            cin >> c[i][j];
        }
    }

    vector<vector<int>> A(H, vector<int>(W));
    for (int h = 0; h < H; h++) {
        for (int w = 0; w < W; w++) {
            cin >> A[h][w];
        }
    }

    // dikstra
    vector<int> dist(10, 1e9);
    priority_queue<pair<int, int>, vector<pair<int, int>>,
                   greater<pair<int, int>>>
        que;
    que.emplace(0, 1);
    dist[1] = 0;
    while (!que.empty()) {
        int index = que.top().second;
        int cost = que.top().first;
        que.pop();
        if (dist[index] < cost) continue;
        dist[index] = cost;
        for (int i = 0; i < 10; i++) {
            if (dist[i] == 1e9) {
                que.emplace(cost + c[i][index], i);
            }
        }
    }

    // for (int i = 0; i < 10; i++) {
    // cout << i << " " << dist[i] << endl;
    // }

    int output = 0;
    for (int h = 0; h < H; h++) {
        for (int w = 0; w < W; w++) {
            if (A[h][w] != -1) {
                output += dist[A[h][w]];
            }
        }
    }
    cout << output << endl;

    return 0;
}


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

#define ll long long
#define vi vector<int>
#define pi pair<int, int>
  
using namespace std;                           

int n, a[1000001], b[1000001];

int main(){
	cin >> n;
	for(int i = 1; i <= n; i++){
		cin >> a[i];
		b[a[i]] = i;
	}
	for(int i = 1; i <= n; i++){
		cout << b[i] << " ";
	}
    return 0;
}

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

int main(){
  int a,h,m,s;
  cin >> a;
  h=a/3600;
  m=(a-h*3600)/60;
  s=(a-h*3600)%60;
  cout << h << ":" << m << ":" << s << endl;
  return 0;
}

Measured memory_bytes: 1164
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define fi first
#define se second

constexpr int MAXN = 1 << 18;

vector<int> grafo[MAXN];
int A[MAXN];
int res[MAXN];

vector<int> lis;
void dfs(int v, int u) {
  auto it = lower_bound(lis.begin(), lis.end(), A[v]);
  int prev = -1;
  if (it == lis.end()) {
    lis.push_back(A[v]);
  } else {
    prev = *it;
    *it = A[v];
  }
  res[v] = lis.size();
  for (int i : grafo[v]) {
    if (i != u) dfs(i, v);
  }
  if (prev == -1) {
    lis.pop_back();
  } else {
    *it = prev;
  }
}

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

  int N;
  cin >> N;

  for (int i = 1; i <= N; i++) {
    cin >> A[i];
  }
  for (int i = 0; i < N - 1; i++) {
    int u, v;
    cin >> u >> v;
    grafo[u].push_back(v);
    grafo[v].push_back(u);
  }

  lis.reserve(N);
  dfs(1, 0);

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

  return 0;
}


Measured memory_bytes: 29068
#pragma target("avx")
#pragma optimize("O3")
#include<bits/stdc++.h>
using ll = int_fast64_t;
using P = std::pair<ll,ll>;
using PP = std::pair<ll,P>;
using V = std::vector<ll>;
template<typename T> using pq = std::priority_queue<T>;
template<typename T> using rpq = std::priority_queue<T, std::vector<T>, std::greater<T>>;

#define REP(i,b,e) for(ll i=b; i<e; i++)
#define ALL(vec) vec.begin(),vec.end()
#define PRINT(vec) printf("[ ");for(auto &i:vec)printf("%ld ",i);puts("]");
#define SCAN(vec) for(auto &i:vec)scanf("%ld",&i)
#define fi first
#define se second

const int MOD = 1e9+7;
const ll INF = 1e18;
int dx[] = {0, 1, 0, -1, 1, 1, -1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

int main(){
	int n, k;
	scanf("%d %d", &n, &k);
	printf("%d\n", n-k+1);
	return 0;
}



Measured memory_bytes: 3716
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 998244353
//#define MOD 10
ll f(ll a, ll b){
	ll ret = 1;
	while(b--){
		ret *= a;
		ret %= MOD;
	}
	return ret;
}
int main() {
	ll n;
	while(cin>>n){
		ll cnt[100010]={0};	
		ll in[n];
		for(ll i=0; i<n; i++){
			cin>>in[i];
			cnt[in[i]]++;
		}
		ll ans = in[0]==0 && cnt[0]==1;
		for(ll i=1; i<n; i++){
			ans *= f(cnt[i-1], cnt[i]);
			ans %= MOD;
			if(cnt[i]==0){
				while(i<n){
					if(cnt[i]>0){
						ans = 0;
					}
					i++;
				}
			}
		}
//		for(ll i=0; i<n; i++){
//			cout << cnt[i] << ' ';
//		}cout << endl;
		cout << ans << endl;
	}
}

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

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

	std::vector<int64_t> a(M);
	std::vector<int> c(M);
	for (int i{}; i < M; i++)
	{
		int b;
		scanf("%lld%d", &a[i], &b);
		for (int j{}; j < b; j++)
		{
			int tmp;
			scanf("%d", &tmp);
			tmp--;
			c[i] |= 1 << tmp;
		}
	}

	std::vector<int64_t> dp(1 << N, 1ll << 60);
	dp.front() = 0;
	for (int i{}; i < (1 << N); i++)
		for (int j{}; j < M; j++)
			dp[i | c[j]] = std::min(dp[i | c[j]], dp[i] + a[j]);
	
	if (dp.back() == (1ll << 60)) puts("-1");
	else printf("%lld\n", dp.back());

	return 0;
}

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

using namespace std;

int main() {

    int N;
    cin >> N;

    string S[N + 1];

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

    set<string> members;

    for (int i = 1; i <= N; i++) {
        members.insert(S[i]);
    }

    cout << members.size() << endl;

    return 0;
}

Measured memory_bytes: 25452
#include <bits/stdc++.h>
using namespace std;
long long a[1001],b[600001];
int main()
{
	long long sum,ans=0,maxx=0;
    int count2=0,p=0,i,j,n,k,count=0;
    scanf("%d%d",&n,&k);
    for(i=0;i<n;i++)
        scanf("%lld",&a[i]);
    for(i=0;i<n;i++)
	{
        sum=0;
        for(j=i;j<n;j++)
		{
            sum+=a[j];
            b[count]=sum;
            maxx=max(maxx,sum);
            count++;
        }
    }
    for(p=0;pow(2,p)<maxx;p++);
    p--;
    for(i=p;i>=0;i--)
	{
        count2=0;
        for(j=0;j<count;j++)
            if(b[j]>=pow(2,i))
                count2++;
        if (count2>=k)
		{
            ans+=pow(2,i);
            for(j=0;j<count;j++)
			{
                if(b[j]<pow(2,i))
                    b[j]=0;
				else
                    b[j]-=pow(2,i);
            }
        }
		else
            for(j=0;j<count;j++)
                if(b[j]>=pow(2,i))
                    b[j]-=pow(2,i);
    }
    printf("%lld\n",ans);
    return 0;
}

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

int n, r, minv, maxv = -1000000000;

int main() {
  cin >> n;
  cin >> r;
  minv = r;
  for (int i = 1; i < n; ++i) {
    cin >> r;
    maxv = max(maxv, r - minv);
    minv = min(minv, r);
  }
  cout << maxv << endl;
}

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

int main() {
    long long n;
    cin >> n;
    long long qaq = sqrt(n);
    long long ans = 0x3f3f3f3f3f3f3f3f;
    for (int i = 1; i <= qaq; i++) {
        if (n % i == 0) {
            ans = min(ans, (i - 1) + (n / i) - 1);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
words = []
for i in range(N):
    w = list(input())
    words.append(w)
h = {}
p = words[0][0]
f = True
for i in range(N):
    b = words[i][0]
    l = words[i][-1]
    if b != p:
        f = False
        break
    p = l
    if h.get(''.join(words[i])) != None:
        f = False
        break
    h[''.join(words[i])] = 1

if f == True:
    print('Yes')
else:
    print('No')

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

struct edge{ int to,cost; };
const int N = 2e5+10;
vector< edge > G[N];

signed main(){

  int n; cin >> n;
  for(int i = 0; i < n-1; i++){
    int u,v,w; cin >> u >> v >> w;
    u--,v--;
    G[u].push_back({v,w});
    G[v].push_back({u,w});
  }

  vector<int> table(n,-1);
  table[0] = 0;
  queue<int> q;
  q.push(0);
  while(!q.empty()){
    int p = q.front(); q.pop();
    for(edge e : G[p]){
      if(table[e.to] != -1) continue;
      if(e.cost%2 == 0){
        table[e.to] = table[p];
      }
      else {
        table[e.to] = 1 - table[p];
      }
      q.push(e.to);
    }
  }

  for(int i = 0; i < n; i++){
    cout << table[i] << endl;
  }

  return 0;
}


Measured memory_bytes: 11008
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

#define rep(i, N) for(int i = 0; i < N; ++i)

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

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

    int h, n;
    cin >> h >> n;

    vector< pair<int, int> > magic(n);
    int a, b;
    rep (i, n)
    {
        cin >> a >> b;
        magic[i] = make_pair(a, b);
    }

    vs32 dp(h + 1, 1e9);
    dp[0] = 0;
    for (int i = 1; i <= h; ++i)
    {
        rep (j, n)
        {
            dp[i] = MIN(dp[i], dp[MAX(0, i - magic[j].first)] + magic[j].second);
        }
    }
    cout << dp[h] << "\n";
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n;
    cin >> n;
    vector<ll> a(n+1), b(n+1);
    for (int i = 0; i < n; ++i) {
        scanf("%lli %lli", &a[i], &b[i]);
    }
    sort(a.begin(), a.end(), greater<>());
    sort(b.begin(), b.end());
    ll ans = 0;
    for (int i = 0; i <= n; ++i) {
        if(a[i] > b[i]) ans += (a[i]-b[i])*2;
    }
    cout << ans << "\n";
    return 0;
}


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

using namespace std;

int main()
{
	string s;
	cin >> s;
	if (s == "SUN")
	{
		cout << 7;
	}
	if (s == "MON")
	{
		cout << 6;
	}
	if (s == "TUE")
	{
		cout << 5;
	}
	if (s == "WED")
	{
		cout << 4;
	}
	if (s == "THU")
	{
		cout << 3;
	}
	if (s == "FRI")
	{
		cout << 2;
	}
	if (s == "SAT")
	{
		cout << 1;
	}
}


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

using namespace std;

int main(){
    int mod=1000000007;
    int n,k;
    long long tmp=1;
    scanf("%d %d",&n,&k);
    for (int i=0;i<n-1;i++) {
        tmp*=k-1;
    }
    printf("%lld\n",tmp*k);
    return 0;
}


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

#define show(x) cerr << #x << " = " << x << endl ;
#define input_from_file freopen("input.txt","r",stdin)
#define output_to_file freopen("output.txt" , "w",stdout)
#define fastio ios_base::sync_with_stdio(0)
#define endl '\n'

const int N = 102 , K = 1e5+2 , mod = 1e9+7;
int ai[N] , dp[N][K];

int main()
{
	 #ifdef LOCAL
        input_from_file;
        output_to_file;
    #endif
	fastio;cin.tie(0);cout.tie(0);
	int n , k ; cin >> n >> k ;
	if(k == 0) 
	{
		cout << 1 ; 
		return 0;
	}
	for(int i = 1 ; i <= n ; ++i)
		cin >> ai[i];
	for(int i = 0 ; i <= k ; ++i)
		dp[0][i] = 1;
	for(int i = 0 ; i <= n ; ++i)
		dp[i][0] = 1 ;
	for(int i = 1 ; i <= n ; ++i)
	{
		for(int j = 1 ; j <= k ; ++j)
		{
			int x = ((long long)(dp[i-1][j] - ((j - ai[i] > 0)?dp[i-1][j-ai[i] -1]:0) + mod))%mod;
			dp[i][j] = ((long long)(dp[i][j-1] + x))%mod;
			// cerr << i << " "<< j << " "<< dp[i][j] << endl;
		}
	}
	cout << (dp[n][k] - dp[n][k-1] + mod)%mod;


	return 0;
}

Measured memory_bytes: 39680
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

template <typename T>
void printv(const vector<T> &v)
{
    int sz = v.size();
    for (int i = 0; i < sz; i++)
    {
        cout << v[i] << " \n"[i == sz - 1];
    }
}

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

    int n, m;
    cin >> n >> m;
    vector<int> x(m);
    for (int i = 0; i < m; i++)
        cin >> x[i];
    sort(x.begin(), x.end());
    if (m <= n)
    {
        cout << 0 << endl;
        return 0;
    }
    priority_queue<int> que;
    for (int i = 1; i < m; i++)
    {
        que.push(x[i] - x[i - 1]);
    }
    ll res = x[m - 1] - x[0];
    for (int i = 0; i < n - 1; i++)
    {
        res -= que.top();
        que.pop();
    }
    cout << res << endl;
}


Measured memory_bytes: 1276
import java.util.Scanner;

 
public class Main {
 
	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		long a  = sc.nextLong();
		long b  = sc.nextLong();
		long c  = sc.nextLong();
		long d  = sc.nextLong();
		long temp1 = Math.max(a * c, a * d);
		long temp2 = Math.max(b * c, b * d);
		
		System.out.println(Math.max(temp1, temp2));
		sc.close();
	}
}




Measured memory_bytes: 35792
import sys
input = sys.stdin.readline
from bisect import bisect_left
inf = float('inf')

N, Q = map(int,input().split())
STX = [list(map(int,input().split())) for _ in range(N)]
D = [int(input()) for _ in range(Q)]

res = 1
while res < Q:
    res <<= 1
N0 = res
data = [inf for _ in range(2*N0-1)]

def update(l, r, x):
    L = l + N0
    R = r + N0
    while L < R:
        if R & 1:
            R -= 1
            data[R] = min(data[R], x)
        if L & 1:
            data[L] = min(data[L], x)
            L += 1
        L >>= 1; R >>= 1

def value(k):
    k += N0
    res = data[k]
    while k != 0:
        k >>= 1
        res = min(res, data[k])
    return res


for S, T, X in STX:
    l = bisect_left(D, S-X)
    r = bisect_left(D, T-X)
    update(l, r, X)

for k in range(Q):
    ans = value(k)
    if ans == inf:
        ans = -1
    print(ans)

Measured memory_bytes: 118880
#include"bits/stdc++.h"

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef priority_queue<int> PQ_DESC;
typedef priority_queue<int, vector<int>, greater<int>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define SORT_ASC(c) sort(ALL(c))
#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>())
#define SIZE(a) int((a).size())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ROF(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define REP(i,n) FOR(i,0,n)
#define PER(i,n) ROF(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int LARGE_INT = 1e9+100;
const int INF = 2e9+100;
const LL INF_LL = (LL)INF * 300 * 300;
const int MOD = 1e9+7;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

LL modpow(LL a, LL n) {
    LL res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

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

LL moddev(LL a, LL b){
	return a * modinv(b) % MOD;
}

void Main()
{
    int n;
    string s;
    cin >> n >> s;

    int result = 0;

    REP(i,n){
        if(s.substr(i, 3) == "ABC"){
            result ++;
        }
    }

    cout << result << endl;



	return;
}

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

Measured memory_bytes: 256
import java.util.*;

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

        while(true){
            int a = sc.nextInt();
            int b = sc.nextInt();
            int c = sc.nextInt();
            int sum = a + b;
            if(a == -1 && b == -1 && c== -1){
                break;
            }else if(a == -1 || b == -1){
                System.out.println("F");
            }else{
                if(sum<30){
                    System.out.println("F");
                }else if(sum<50){
                    if(c<50){
                        System.out.println("D");
                    }else{
                        System.out.println("C");
                    }
                }else if(sum<65){
                    System.out.println("C");
                }else if(sum<80){
                    System.out.println("B");
                }else{
                    System.out.println("A");
                }
            }
        }

        sc.close();
    }
}


Measured memory_bytes: 26296