akhauriyash/Code-Regression huggingface dataset:
n=input()

if n[-1]=="2" or n[-1]=="4" or n[-1]=="5" or n[-1]=="7" or n[-1]=="9":
    print("hon")
elif n[-1]=="0" or n[-1]=="1" or n[-1]=="6" or n[-1]=="8":
    print("pon")
else:
    print("bon")

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

int main() {
  int N, X;
  cin >> N >> X;
  int sumA = 0;
  int sumB = 1;
  
  vector<int> A(N);
  for (int i=0; i < N; i++) {
    cin >> A[i];
    sumA += A[i];
     if (sumA > X) {
      break;
    }
    sumB++;
  }
  cout << sumB << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ull unsigned long long
# define ll long long
# define mod 1000000007LL 
using namespace std;
int main()
{
     ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin>>n;
    if(n%1000!=0)
    cout<<1000-n%1000;
    else
    {
        cout<<0;
    }
    


    
    return 0;
}

Measured memory_bytes: 3612
import java.util.*;
import java.io.*;

class Main{
    public static void main(String args[])throws IOException{
      try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))){
        int N = Integer.parseInt(br.readLine());
        String input = br.readLine();
        String port = "ABC";

        int result = 0;
        int tmp = 0;
        String tmp_s = "";

        if(input.contains(port)){
          tmp = input.indexOf(port);
          tmp_s = input.substring(tmp+3);
          result++;
          while(tmp != -1){
            tmp = tmp_s.indexOf(port);
            if(tmp != -1){
              tmp_s = tmp_s.substring(tmp+3);
              result++;
            }else{
              break;
            }
          }
        }
        
        System.out.println(result);
      }
    }
}

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


void solve(){
    int N, W;
    cin >> N >> W;
    vector<int> v(N), w(N);
    for(int i=0; i<N; i++)
        cin >> v[i] >> w[i];
    
    vector<vector<int>> dp(N+1, vector<int>(W+1,0));
    
    for(int i=0; i<N; i++){
        for(int j=0; j<=W; j++){
            if(j-w[i]>=0)
                dp[i+1][j] = max(dp[i][j], dp[i][j-w[i]]+v[i]);
            else
                dp[i+1][j] = dp[i][j];
        }
    }
    
    cout << dp[N][W] << endl;

    
}


signed main(){
    cout << fixed << setprecision(18);
    cerr << fixed << setprecision(18);
    solve();
}



Measured memory_bytes: 6808
#include <bits/stdc++.h>
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define FSP(x) fixed << setprecision(x)
using namespace std;
using ll = long long;
constexpr ll INF = LLONG_MAX;
const long double PI = acosl(-1);
void Yes() {cout << "Yes\n";}
void No() {cout << "No\n";}
void YES() {cout << "YES\n";}
void NO() {cout << "NO\n";}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	//constexpr ll P = 1e9 + 7;
	//constexpr ll P = 998244353;

	ll n, k;
	cin >> n >> k;
	vector<ll> a(n);
	for (ll i = 0; i < n; i++) cin >> a[i];
	sort(ALL(a));



	if (k == 0) {
		cout << a[n - 1] << endl;
		return 0;
	}



	if (a[n - 1] == 1) {
		cout << 1 << endl;
		return 0;
	}



	ll l = 0, r = a[n - 1];
	auto is_ok = [&] (ll x) {
		ll lim = k;
		for (auto i : a) {
			lim -= i / x + !!(i % x) - 1;
			if (lim < 0) return false;
		}
		return true;
	};
	while (l + 1 < r) {
		ll mid = (l + r) / 2;
		if (is_ok(mid)) r = mid;
		else l = mid;
	}
	cout << r << endl;
}

Measured memory_bytes: 4740
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int n;
  cin>>n;
  string s[n];
  for(int i=0;i<n;i++) cin>>s[i];
  int b[3],p=0;
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      if(i==j) continue;
      int t=stoi(s[i]+s[j]);
      if(p<3) b[p++]=t;
      else{
	sort(b,b+3);
	if(t<b[0]){
	  b[2]=b[1];
	  b[1]=b[0];
	  b[0]=t;
	}else if(t<b[1]){
	  b[2]=b[1];
	  b[1]=t;
	}else if(t<b[2]){
	  b[2]=t;
	}
      }
    }
  }
  //for(int i=0;i<3;i++) cout<<b[i]<<endl;
  cout<<b[2]<<endl;
  return 0;
}

Measured memory_bytes: 3444
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
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;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;

void solve() {
    int N;
    cin >> N;
    vecl A(N);
    REP(i,N) cin >> A[i];
    int ans = 0;
    sort(A.begin(),A.end());
    for(int i = 0; i < N-2; i++) {
        for(int j = i+1; j < N-1; j++) {
            for(int k = j+1; k < N; k++) {
                if(A[i] == A[j] || A[j] == A[k] || A[k] == A[j]) continue; 
                if(A[i] + A[j] > A[k]) ans++;
            }
        }
    }
    cout << ans << endl;
}

int main() {
    int T;
    T = 1;
    while(T--) {
        solve();
    }
}

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

int main(){
  int p,q,r;
  cin >> p >> q >> r;
  if(p<=r&&q<=r){
    cout << p+q << endl;
  }
  else if(r<=q&&p<=q){
    cout << p+r << endl;
  }
  else{
    cout << q+r << endl;
  }
}

Measured memory_bytes: 256
s = input()
size = len(s)

dp = [False] * (size + 1)
dp[0] = True

for i in range(5, size + 1):
    if dp[i - 5] and (s[i-5:i] == 'dream' or s[i-5:i] == 'erase'):
        dp[i] = True
    elif dp[i - 6] and s[i-6:i] == 'eraser':
        dp[i] = True
    elif dp[i - 7] and s[i-7:i] == 'dreamer':
        dp[i] = True
    else:
        dp[i] = False
if dp[size]:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 3956
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Rep(i, m,n) for (int i = m; i < (int)(n); i++)
int main(){
int N,M;
  cin>>N>>M;
  

  cout<<N*(N-1)/2+M*(M-1)/2<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <queue>
using namespace std;
const int N=1e6+10;
long long int a[N],b[N],c[N],n,m;
long long int check(int l,int t,int d){
priority_queue<long long int> pq;
long long int ans=0;
for(int i=0;i<n;i++)pq.push({l*a[i]+t*b[i]+d*c[i]});
for(int i=0;i<m;i++){
ans+=pq.top();
pq.pop();
}
return ans;
}
int main(){
long long int ans=0;
scanf("%lld%lld",&n,&m);
for(int i=0;i<n;i++)scanf("%lld%lld%lld",&a[i],&b[i],&c[i]);
ans=max(ans,check(1,1,1));
ans=max(ans,check(1,1,-1));
ans=max(ans,check(1,-1,1));
ans=max(ans,check(1,-1,-1));
ans=max(ans,check(-1,1,1));
ans=max(ans,check(-1,1,-1));
ans=max(ans,check(-1,-1,1));
ans=max(ans,check(-1,-1,-1));
printf("%lld\n",ans);
}

Measured memory_bytes: 4352
using System;

class Program
{
	static void Main(string[] args)
	{
		string s = Console.ReadLine();
		string t = Console.ReadLine();

		if (t.StartsWith(s) == true && t.Length == s.Length + 1)
		{
			Console.WriteLine("Yes");
		}
		else
		{
			Console.WriteLine("No");
		}


		return;
	}
}

Measured memory_bytes: 26104
#include <bits/stdc++.h>
using namespace std;
#define db(x) cout << #x << " = " << (x) << "\n";
using ll = long long;
using ld = long double;

static const auto do_fast_io = [] {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    return nullptr;
}();

int main() {
    int n;
    cin >> n;
    vector<double> p(n + 1);
    for (int i = 1; i <= n; ++i) {
        cin >> p[i];
    }
    vector<vector<double>> dp(n + 1, vector<double>(n + 1));
    dp[0][0] = 1;
    for (int i = 1; i <= n; ++i) {
        for (int j = 0; j <= n; ++j) {
            dp[i][j] = dp[i - 1][j] * (1 - p[i]);
            if (j) {
                dp[i][j] +=dp[i - 1][j - 1] * p[i];
            }
        }
    }
    double ans = 0;
    for (int i = n / 2 + 1; i <= n; ++i) {
        ans += dp[n][i];
    }
    cout << fixed << setprecision(10) << ans << endl;
    return 0;
}


Measured memory_bytes: 70784
#include <bits/stdc++.h>
 
using namespace std;
int main(void){
    long long N,K;
  cin >> N >> K;
    vector<long long> vec(N);
    for (auto& v : vec)
	{
		cin >> v;
	}
  
    if(K >= N) {
      int a = 0;
      cout << a; 
    } else {
   sort(vec.begin(), vec.end()); 
  
  long long sum = 0;
  for(int i = N - K - 1;i >= 0;i--){
    sum += vec[i];
  }
  cout << sum;
    }
   return 0; 
}

Measured memory_bytes: 1792
import java.util.*;
import java.lang.Double;

public class Main {
  
    public static void main(String[] args) {
      Scanner reader=new Scanner(System.in);
      String a=reader.nextLine();
      if(a.equals("ABC"))
      {
        System.out.println("ARC");
      }else
      {
          System.out.println("ABC");
      }

        }
      }


Measured memory_bytes: 35692
#include <bits/stdc++.h>
#define For(i,a,b) for(int i=(a); i<(b); i++)
using namespace std;

int main(){
	int n,m;
	cin>>n>>m;
	int a[m];
	int sum=0;
	For(i,0,m){
		cin>>a[i];
		sum+=a[i];
	}
	if (sum>n)
		cout<<-1;
	else
		cout<<n-sum;
	return 0;
}

Measured memory_bytes: 3644
def main():
    a = list(map(int, list(input())))
    n = len(a)
    dp = [[0, 0] for _ in [0]*(n+1)]
    dp[0][1] = 1
    for i in range(n):
        dp[i+1][0] = min(dp[i][0]+a[i], dp[i][1]+10-a[i])
        dp[i+1][1] = min(dp[i][0]+a[i]+1, dp[i][1]+9-a[i])
    print(dp[n][0])

main()


Measured memory_bytes: 155648
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define rep2(i,n) for(int i=0;i<=n;i++)
#define repr(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define uni(e) e.erase(unique(e.begin(),e.end()),e.end())
#define double long double
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int INF=1e10;
int MOD=1e9+7;
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void yesno(T b){if(b)out("yes");else out("no");}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
template<class T> void YESNO(T b){if(b)out("YES");else out("NO");}
template<class T> void noyes(T b){if(b)out("no");else out("yes");}
template<class T> void NoYes(T b){if(b)out("No");else out("Yes");}
template<class T> void NOYES(T b){if(b)out("NO");else out("YES");}
int keta(int a){
  double b=a;
  b=log10(b);
  int c=b;
  return c+1;
}
int kurai(int a,int b){
  int m=pow(10,b),n=pow(10,b-1);
  return (a%m)/n;
}
int ketawa(int a){
  int k=0;
  rep(i,keta(a)){
  k+=kurai(a,i+1);
  }
  return k;
}
int gcd(int a,int b){
  if(a%b==0)
    return b;
  return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
int mid(int a,int b,int c){
  vector<int> k(3);
  k[0]=a;k[1]=b;k[2]=c;
  sort(all(k));
  return k[1];
}
bool sosuu(int a){
  bool b=1;
  if(a<=1)
    return 0;
  else{
  rep1(i,sqrt(a)-1){
  if(a%(i+1)==0)
  b=0;
  }
  return b;
  }
}
int modpow(int a,int b,int m=MOD){
 if(!b)return 1; if(b&1)return modpow(a,b-1,m)*a%m;
 int memo = modpow(a,b>>1,m);
 return memo*memo%m;
}
int fact_mod(int n) {
    int f=1; 
for(int i=2;i<n+1;i++) f=f*(i%MOD)% MOD;
    return f;
}
int mod_pow(int x,int n) {
    int res=1;
    while(n>0){
        if(n&1) res=(res*x)%MOD; 
        x=(x*x)%MOD;        
n>>=1; 
    }
    return res;
}
int c_mod(int n, int r) {
    if(r>n-r) r=n-r;
    if(r==0) return 1;
    int a=1;
    rep(i,r) 
a=a*((n-i)%MOD)%MOD;
    int b=mod_pow(fact_mod(r), MOD-2);
    return (a%MOD)*(b%MOD)%MOD;
}
signed main(){
  int a,b,c;
  cin>>a>>b>>c;
  if(abs(b-c)%2==0)
    out("Alice");
  else
    out("Borys");
}

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

#define COUNTOF(array) (sizeof(array) / sizeof(array[0]))    
#define OUT(P) cout << (P) << endl    
#define OUT2(P1, P2) cout << (P1) << " " << (P2) << endl    
#define PRINT_ARRAY(P) for(int i=0; i<P.size(); i++) cout << P[i] << endl;    
#define PRINT_ARRAY_INLINE(P) do { for(int i=0; i<P.size(); i++) cout << P[i] << " "; cout << endl; } while(0)    
#define PRINT_ARRAY_WITH_LABEL(L, P) do { cout << L << ": "; PRINT_ARRAY_INLINE(P); cout << endl; } while(0)    
typedef long long ll;    
const long DIVIDE = 1e9+7;

int sum_digits(int num);    
template <class T>    
vector<T> copy_vector(vector<T> vec);    
long gcd(long a, long b);    
long lcm(long a, long b);
vector<vector<long>> comb(long n, long r);
// ****** print functions ****** //
template <class T, class U>
void print_pairs(const vector<pair<T, U>> pairs);
template <class K, class V>
void print_map(const map<K, V> m);

int main() {    
    int n;
    cin >> n;
    int x = sqrt(n);
    cout << x*x << endl;
    return 0;    
}    

/******************************/    
/***** DECRARED FUNCTIONS *****/    
/******************************/    

int sum_digits(int num) {    
    int rtn = 0;    
    while(num != 0) {    
        int tmp = num % 10;    
        rtn += tmp;    
        num /= 10;    
    }    
    return rtn;    
}    

// vectorのコピー    
template <class T>    
vector<T> copy_vector(vector<T> vec) {    
    vector<T> rtn;    
    rtn.reserve(vec.size());    
    copy(vec.begin(), vec.end(), back_inserter(rtn));    
    return rtn;    
}    

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

long lcm(long a, long b) {
    long gcd_ = gcd(a, b);
    return (a * b) / gcd_;
}

vector<vector<long>> comb(long n, long r) {                                                                             
    vector<vector<long>> v(n+1, vector<long>(n+1, 0));    
    for(int i=0; i<v.size(); i++) {    
        v[i][0] = 1;    
        v[i][i] = 1;    
    }    
    for(int i=1; i<v.size(); i++) {    
        for(int j=1; j < i; j++) {    
            v[i][j] = (v[i-1][j-1] + v[i-1][j]) % DIVIDE;    
        }    
    }    
    return v;    
} 

template <class T, class U>
void print_pairs(const vector<pair<T, U>> &pairs) {
    for(int i=0; i<pairs.size(); i++) { 
        cout << "(" << pairs[i].first << ", " << pairs[i].second << ")" << " "; 
    } 
    cout << endl;
}

template <class K, class V>
void print_map(const map<K, V> &m) {
    for(auto it=m.cbegin(); it!=m.cend(); it++) {
        cout << it->first << ": " << it->second << endl;
    }
}


Measured memory_bytes: 256
import java.util.Scanner;

/**
 * @author yoshizaki
 *
 */
public class Main {
    public static void main(String[] args) {
        Scanner scanner= new Scanner(System.in);
        String station = scanner.nextLine();
        if (station.indexOf("A")>=0 && station.indexOf("B")>=0) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 22864
#include<stdio.h>
#include<string.h>

int main(){

  int i,j,k=0,n,m1,m2;
	char str[1000],mei[10],p[1000];
	char r;

	scanf("%s",str);
	scanf("%d",&n);

	for(i=0;i<n;i++){
		scanf("%s",mei);
		
    if(strcmp(mei,"print")==0){
      scanf("%d%d",&m1,&m2);
			for(j=m1;j<=m2;j++){
				printf("%c",str[j]);
			}
			puts("");
			
	}else if(strcmp(mei,"reverse")==0){
			scanf("%d%d",&m1,&m2);
			while(m1<m2){
                r=str[m1];
                str[m1]=str[m2];
                str[m2]=r;
                m1++;
                m2--;
			}
			
		
		}else if(strcmp(mei,"replace")==0){
			scanf("%d%d%s",&m1,&m2,p);
			for(j=m1;j<=m2;j++){
				str[j]=p[j-m1];
			}
		}
	}
	return 0;
}

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

constexpr ll Mod = 998244353;
constexpr ll mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;

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

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

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

    int n;
    cin >> n;
    vector<pair<int, int>> P(n);

    rep(i, n) {
        int x;
        cin >> x;
        P[i] = {x, i + 1};
    }
    sort(ALL(P));
    set<int> st;
    st.insert(0);
    st.insert(n + 1);

    ll ret = 0;
    for(auto p : P) {
        int id = p.second;
        auto i = st.lower_bound(id);
        int r = *i--;
        int l = *i;
        ret += 1LL * p.first * (r - id) * (id - l);
        st.insert(p.second);
    }
    cout << ret << endl;

    return 0;
}

Measured memory_bytes: 11264
import itertools

def my_index(l, x):
    if x in l:
        return l.index(x)
    else:
        return -1


if __name__ == "__main__":
        
    N = int(input())
    S = [int(c) for c in input()]
    table = list(range(10))

    count = 0
    for p in itertools.product(table, repeat=3): # 重複を許して1~9の数値を３つならべる
        target = list(p)

        s1_index = my_index(S, target[0])
        if s1_index == -1:
            continue
        s1 = S[s1_index+1:]

        s2_index = my_index(s1, target[1])
        if s2_index == -1:
            continue
        s2 = s1[s2_index+1:]
        
        s3_index = my_index(s2, target[2])
        if s3_index == -1:
            continue
        
        count += 1

    print(count)



Measured memory_bytes: 10356
#include <bits/stdc++.h>
using namespace std;
using Int = int_fast64_t;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	Int n, p; cin >> n >> p;
	string s; cin >> s;
	if(p == 2){
		Int ans = 0;
		for(Int i=0; i<n; ++i)
			if((s[i]-'0') % 2 == 0)
				ans += i+1;
		cout << ans << "\n";
		return 0;
	}else if(p == 5){
		Int ans = 0;
		for(Int i=0; i<n; ++i)
			if((s[i]-'0') % 5 == 0)
				ans += i+1;
		cout << ans << "\n";
		return 0;
	}
	vector<Int> a(n);
	Int t = 1;
	for(Int i=n-1; i>=0; --i){
		a[i] = (s[i]-'0') * t % p;
		t = t * 10 % p;
	}
	for(Int i=n-2; i>=0; --i)
		a[i] = (a[i] + a[i+1]) % p;
	vector<Int> v(p);
	Int ans = 0;
	v[0] = 1;
	for(Int i=n-1; i>=0; --i){
		ans += v[a[i]];
		++v[a[i]];
	}
	cout << ans << "\n";
}

Measured memory_bytes: 2196
S = input()
T = input()

def slv(S, T):
    cnd = []
    for i in range(len(S) - len(T) + 1):
        a = ''
        for j in range(len(T)):
            if S[i+j] in ('?', T[j]):
                a += T[j]
                continue
            break
        if len(a) == len(T):
            for j in range(i-1, -1, -1):
                a = ('a' if S[j] == '?' else S[j]) + a
            for j in range(i + len(T), len(S)):
                a += ('a' if S[j] == '?' else S[j])
            cnd.append(a)
    if len(cnd) == 0:
        return 'UNRESTORABLE'
    cnd.sort()
    return cnd[0]

print(slv(S, T))


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define sz size()
#define ll long long
#define all(_v) _v.begin(), _v.end()

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
    int x, y, z;
    cin >> x >> y >> z;
    cout << z << ' ' << x << ' ' << y;
    return 0;
}


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

int main() {
  int n, m, sum;
  cin >> n;
  m = n;
  while (n != 0) {
    sum += n % 10;
    n /= 10;
  }
  if (m % sum == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (m1, d1) = readLine()!!.split(" ").map(String::toInt)
    val (m2, d2) = readLine()!!.split(" ").map(String::toInt)

    if (m1 != m2) {
        println(1)
    } else {
        println(0)
    }
}

Measured memory_bytes: 36032
#include <iostream>
#include <string>

using namespace std;

void solve()
{
	int n;
	cin >> n;
	while(n--)
	{
		string s1, s2;
		cin >> s1 >> s2;
		int num1 = 0, num2 = 0;
		if(s1.size() == 1)
		{
			if(s1[0] == 'm')
			{
				num1 = 1000;
			}
			else if(s1[0] == 'c')
			{
				num1 = 100;
			}
			else if(s1[0] == 'x')
			{
				num1 = 10;
			}
			else if(s1[0] == 'i')
			{
				num1 = 1;
			}
		}
		else
		{
			for(int i = 0; i < s1.size(); ++i)
			{
				if(s1[i] == 'm')
				{
					if(i == 0 || s1[i - 1] < '2' || '9' < s1[i - 1])
					{
						num1 += 1000;
					}
					else if('2' <= s1[i - 1] && s1[i - 1] <= '9')
					{
						num1 += 1000 * (s1[i - 1] - '0');
					}
				}
				if(s1[i] == 'c')
				{
					if(i == 0 || s1[i - 1] < '2' || '9' < s1[i - 1] )
					{
						num1 += 100;
					}
					else if('2' <= s1[i - 1] && s1[i - 1] <= '9')
					{
						num1 += 100 * (s1[i - 1] - '0');
					}
				}
				if(s1[i] == 'x')
				{
					if(i == 0 || s1[i - 1] < '2' || '9' < s1[i - 1] )
					{
						num1 += 10;
					}
					else if('2' <= s1[i - 1] && s1[i - 1] <= '9')
					{
						num1 += 10 * (s1[i - 1] - '0');
					}
				}
				if(s1[i] == 'i')
				{
					if(i == 0 || s1[i - 1] < '2' || '9' < s1[i - 1] )
					{
						num1 += 1;
					}
					else if('2' <= s1[i - 1] && s1[i - 1] <= '9')
					{
						num1 += 1 * (s1[i - 1] - '0');
					}
				}
			}
		}
		if(s2.size() == 1)
		{
			if(s2 == "m")
			{
				num2 = 1000;
			}
			else if(s2 == "c")
			{
				num2 = 100;
			}
			else if(s2 == "x")
			{
				num2 = 10;
			}
			else if(s2 == "i")
			{
				num2 = 1;
			}
		}
		else
		{
			for(int i = 0; i < s2.size(); ++i)
			{
				if(s2[i] == 'm')
				{
					if(i == 0 || s2[i - 1] < '2' || '9' < s2[i - 1])
					{
						num2 += 1000;
					}
					else if('2' <= s2[i - 1] && s2[i - 1] <= '9')
					{
						num2 += 1000 * (s2[i - 1] - '0');
					}
				}
				if(s2[i] == 'c')
				{
					if(i == 0 || s2[i - 1] < '2' || '9' < s2[i - 1] )
					{
						num2 += 100;
					}
					else if('2' <= s2[i - 1] && s2[i - 1] <= '9')
					{
						num2 += 100 * (s2[i - 1] - '0');
					}
				}
				if(s2[i] == 'x')
				{
					if(i == 0 || s2[i - 1] < '2' || '9' < s2[i - 1] )
					{
						num2 += 10;
					}
					else if('2' <= s2[i - 1] && s2[i - 1] <= '9')
					{
						num2 += 10 * (s2[i - 1] - '0');
					}
				}
				if(s2[i] == 'i')
				{
					if(i == 0 || s2[i - 1] < '2' || '9' < s2[i - 1] )
					{
						num2 += 1;
					}
					else if('2' <= s2[i - 1] && s2[i - 1] <= '9')
					{
						num2 += 1 * (s2[i - 1] - '0');
					}
				}
			}
		}
		int ans = num1 + num2;
		if(ans >= 2000)
		{
			cout << ans / 1000 << "m";
		}
		else if(ans >= 1000)
		{
			cout << "m";
		}
		ans %= 1000;
		if(ans >= 200)
		{
			cout << ans / 100 << "c";
		}
		else if(ans >= 100)
		{
			cout << "c";
		}
		ans %= 100;
		if(ans >= 20)
		{
			cout << ans / 10 << "x";
		}
		else if(ans >= 10)
		{
			cout << "x";
		}
		ans %= 10;
		if(ans >= 2)
		{
			cout << ans << "i";
		}
		else if(ans >= 1)
		{
			cout << "i";
		}
		cout << endl;
	}
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 1212
/*input
1
1

*/
 
/*
                                                    ______________
                                                          |       )
                                                          |   )   /
                                                          |______/
                                                    |     |      \
                                                    |     |   )   \
                                                    |_____|_______)
 
*/
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <iomanip>
#include <fstream>
#include <stack>

using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef pair<ll , ll> PLL;
typedef long double ld;
 
#define pb push_back
#define all(c) c.begin(),c.end()
#define allr(c) c.rbegin(),c.rend()
int mod = 1000000007;
const int inf = 1034567891;
const ll LL_INF = 1234567890123456789ll;
#define PI 3.14159265
#define endl '\n'
#define F first
#define S second
#define debug(x) cout << #x << " = " << x << endl;
#define TRACE
 
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
 
#define out(container) for (auto it : container) cout << it << " "; cout << endl;
 
 
template < typename T > T GCD(T a, T b)            { ll t; while(a) { t = a; a = b % a; b = t; } return b; }
template < typename T > string toString(T a)       { return to_string(a); }
template < typename T > void toInt(string s, T &x) { stringstream str(s); str >> x;}
inline int add(int x, int y){ x += y; if(x >= mod) x -= mod; return x;}
inline int sub(int x, int y){ x -= y; if(x < 0) x += mod; return x;}
inline int mul(int x, int y){ return (x * 1ll * y) % mod;}
inline int powr(int a, ll b){
  int x = 1 % mod;
  while(b){
    if(b & 1) x = mul(x, a);
    a = mul(a, a);
    b >>= 1;
  }
  return x;
}
inline int inv(int a){ return powr(a, mod - 2);}

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  
  int n;
  cin >> n;
  vector<int> vec;
  int v;
  for (int i = 0; i < n; i++) {
    cin >> v;
    vec.pb(v);
  }  
  ll ans = 0, mx = vec[0];
  for (auto it : vec) {
    if (mx > it)
      ans += mx - it;
    mx = max(mx, (ll)it);
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 4240
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;

namespace ARC103C
{
    public class Program
    {
        struct Result
        {
            public int ReplaceCount;
            public int RemainNumber;
        }

        void Solve(StreamScanner ss, StreamWriter sw)
        {
            //---------------------------------
            var N = ss.Next(int.Parse);
            var V = ss.Next(int.Parse, N);
            var odds = V.Where((_, i) => i % 2 == 0);
            var evens = V.Where((_, i) => i % 2 == 1);

            var oddsRes = GetResult(odds);
            var evensRes = GetResult(evens);
            if (oddsRes.RemainNumber != evensRes.RemainNumber)
            {
                Console.WriteLine(oddsRes.ReplaceCount + evensRes.ReplaceCount);
                return;
            }

            var res1 = GetResult(odds, 0).ReplaceCount + GetResult(evens, 1).ReplaceCount;
            var res2 = GetResult(odds, 1).ReplaceCount + GetResult(evens, 0).ReplaceCount;
            Console.WriteLine(Math.Min(res1, res2));
            //---------------------------------
        }

        Result GetResult(IEnumerable<int> seq, int rank = 0)
        {
            var counts = new Dictionary<int, int> {{0, 0}};

            foreach (var x in seq)
            {
                if (!counts.ContainsKey(x)) counts.Add(x, 0);
                counts[x]++;
            }

            var remain = counts.OrderByDescending(pair => pair.Value).ToArray()[rank];
            return new Result{ReplaceCount = seq.Count() - remain.Value, RemainNumber = remain.Key};
        }

        static void Main()
        {
            var ss = new StreamScanner(new StreamReader(Console.OpenStandardInput()));
            var sw = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false};
            new Program().Solve(ss, sw);
            sw.Flush();
        }

        static readonly Func<string, string> String = s => s;
    }

    public class StreamScanner
    {
        static readonly char[] Sep = {' '};
        readonly Queue<string> buffer = new Queue<string>();
        readonly TextReader textReader;

        public StreamScanner(TextReader textReader)
        {
            this.textReader = textReader;
        }

        public T Next<T>(Func<string, T> parser)
        {
            if (buffer.Count != 0) return parser(buffer.Dequeue());
            var nextStrings = textReader.ReadLine().Split(Sep, StringSplitOptions.RemoveEmptyEntries);
            foreach (var nextString in nextStrings) buffer.Enqueue(nextString);
            return Next(parser);
        }

        public T[] Next<T>(Func<string, T> parser, int x)
        {
            var ret = new T[x];
            for (var i = 0; i < x; ++i) ret[i] = Next(parser);
            return ret;
        }

        public T[][] Next<T>(Func<string, T> parser, int x, int y)
        {
            var ret = new T[y][];
            for (var i = 0; i < y; ++i) ret[i] = Next(parser, x);
            return ret;
        }
    }
}

Measured memory_bytes: 34116
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_A main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LLONG_MAX/2)
const int MGN = 10;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
using psi = pair<string, int>;
// functions
void get_permutation(vector<vs>& perm, vs a){
    sort(a.begin(), a.end());
    do {
        vs t;
        for (string s : a) t.push_back(s);
        perm.push_back(t);
    } while (next_permutation(a.begin(), a.end()));
}
#endif


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

    const int N = 3;
    vi A(N); REP(i, N) cin >> A[i];

    vs a;
    for (int i = 0; i < 3; i++) a.push_back(to_string(i));

    vector<vs> pm;
    get_permutation(pm, a);

    int ans = INF;
    for(auto p : pm) {
        int cost = 0;
        for(int i=0; i<2; i++) {
            cost += abs(A[stoi(p[i+1])] - A[stoi(p[i])]);
        }
        ans = min(ans, cost);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <list>

using namespace std;

const int MAX = 100000;
vector<int> G[MAX];
list<int> out;
vector<bool> visited;

void dfs(int u){
    visited[u] = true;
    for (auto v :G[u]) {
        if (!visited[v])dfs(v);
    }
    out.push_front(u);
}
int main(){
    //freopen("in", "r", stdin);
    int v,e;
    cin >> v >> e;
    for (int i = 0; i < e; ++i) {
        int s,t;
        cin >> s >> t;
        G[s].push_back(t);
    }

    visited.resize(v);
    for (int i = 0; i < v; ++i) {
        if (!visited[i])dfs(i);
    }
    for (auto item :out) cout << item << endl;
    return 0;
}

Measured memory_bytes: 6156
def least_multiplication(mtx):
    N = len(mtx)
    mul = [[None] * N for x in range(N)]

    for i in range(N):
        mul[i][i] = 0
    #pprint.pprint(mul)

    for chain in range(1, N):
        for begin in range(N-chain):
            end = begin + chain
            cand = []
            for j in range(begin, end):
                left = mul[begin][j]
                down = mul[j+1][end]
                this = mtx[begin][0] * mtx[j][1] * mtx[end][1]
                cand.append(left + down + this)
            mul[begin][begin+chain] = min(cand)
        #pprint.pprint(mul)
    return mul[0][N-1]


def main():
    n = int(input())
    matrices = []
    for i in range(n):
        col, row = map(int, input().split())
        matrices .append((col, row))
    ans = least_multiplication(matrices)
    print(ans)


main()


Measured memory_bytes: 5724
#include <bits/stdc++.h>
    #include <ext/pb_ds/assoc_container.hpp>
    #include <ext/pb_ds/tree_policy.hpp>
    #define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>   
    using namespace std;
    using namespace __gnu_pbds;
    typedef long long ll; 
    #define int long long
    typedef unsigned long long lu;
    typedef vector<ll> v;
    typedef vector<vector<ll> > vv;
    typedef vector<string>  vs;
    typedef vector<pair<ll,ll>> vpr;
    typedef long double ld;
    #define f(i,n) for(ll i = 0; i < n; i++)
    #define ff(i,n) for(ll i=1;i<=n;i++)
    #define pb push_back
    #define mp make_pair
    #define endl "\n"
    #define fi first
    #define se second
    #define all(x) x.begin(),x.end()
    #define rall(x) x.rbegin(),x.rend()
    #define amax(x,y) if(y>x) x=y;
    #define amin(x,y) if(y<x)x=y;
    #define bg(x) x.begin()
    #define sz(x) (ll)x.size()
    #define in(x,n) for(ll i=0;i<n;i++)cin>>x[i]
    #define out(x,n) for(ll i=0;i<n;i++)cout<<x[i]<<" " 
    #define mxt(a) *(max_element(a.begin(),a.end()))
    #define mnt(a) *(min_element(a.begin(),a.end())
    #define tc ll t;cin>>t;while(t--)
    typedef pair<ll,ll> pi;
    #define yes cout<<"Yes\n";
    #define no cout<<"No\n";
    #define yesno(f) if(f) yes else no
    const v dx = {1, -1, 0, 0};
    const v dy = {0, 0, 1, -1};
    const ld PI = 2 * acos(0.0);
    ll cel(ll x1,ll y1){if((x1%y1)==0)return x1/y1;else return x1/y1+1;}
    ll power(ll a,ll b,ll m)
    {
        if(b==0)
            return 1;
        ll d=power(a,b/2,m);
        d=(d*d)%m;
        if(b&1)
            d=(d*a)%m;
        return d;
    }
    const ll mod=1e9+7;
    int MOD(int a)
    {
        if(a<0)
            a+=mod;
        if(a>=mod)
            a%=mod;
        return a;
    }
    // set_name.find_by_order(k) It returns to an iterator to the kth element (counting from zero) in the set in O(logn) time
    // set_name.order_of_key(k) It returns to the number of items that are strictly smaller than our item k in O(logn) time.
    /*string operations :
    str.substr (x,y) : returns a substring str[x],str[x+1],...str[x+y-1]
    str.substr (x) : returns a substring str[x],... end of string
    str.find(qtr) : returns the first occurenece of qtr in str */
    int32_t main()
    {
        ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
        int x,y;cin>>x>>y;yesno(((y%2==0) && ((y/2)<=2*x) && ((y/2)>=x)));
        return 0;
    }

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

int main(){
    int A, B, T;
    int i = 0;
    int ans = 0;

    cin >> A >> B >> T;
    while(i <= T+0.5){
        if(i % A == 0 && i != 0){
            ans += B;
        }
        i++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.util.regex.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        // 入力
        int n = sc.nextInt();
        int[] t = new int[n+1];
        int[] x = new int[n+1];
        int[] y = new int[n+1];
        // 初期値
        t[0] = 0;
        x[0] = 0;
        y[0] = 0;
        // 入力値
        for (int i = 1; i <= n; i++) {
            t[i] = sc.nextInt();
            x[i] = sc.nextInt();
            y[i] = sc.nextInt();
        }

        int dt, dist, diff;
        for (int i = 0; i < n; i++) {
            // dt = t[i+1] - t[i];
            // dist = Math.abs(x[i+1] - x[i]) + Math.abs(y[i+1] - y[i]);
            // if (dt < dist || (dist % 2 != dt % 2)) {
            //     // 出力
            //     System.out.println("No");
            //     return;
            // }
            diff = Math.abs(x[i+1] - x[i]) + Math.abs(y[i+1] - y[i]) - t[i+1] + t[i];
            if (diff > 0 || (diff % 2 != 0)) {
                // 出力
                System.out.println("No");
                return;
            }
        }

        // 出力
        System.out.println("Yes");
    }
}


Measured memory_bytes: 88596
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;

const int inf = numeric_limits<int>::max() /4;
const ll linf = numeric_limits<ll>::max() /4;
const ull ulinf = numeric_limits<ull>::max()/4;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.end(), v.begin());
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - a) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

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

struct boll{
    int r = 0;
    int w = 1;
};

int n,m;
boll b[100005] = {};

int main(){

    cin >> n >> m;
    b[1].r = 1;
    b[1].w = 0;
    
    rep(i,0,m){
        int x,y;
        cin >> x >> y;
        
        if(b[x].w > 0){
            if(b[x].r > 0){
                b[x].w --;
                b[y].r ++;
            }else{
                b[x].w --;
                b[y].w ++;
            }
        }else{
            b[x].r --;
            b[y].r ++;
        }
    }
    int ans = 0;
    rep(i,1,n+1){
        if(b[i].r > 0)ans++;
    }
    P(ans);
	
	return  0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  
  int arr[n+1],cnt=0,mi = 10e9;
  
  for(int i=1;i<=n;i++)
    cin>>arr[i];
  
  for(int i=1;i<=n;i++)
  {
     if(arr[i]<mi)
     { mi=arr[i];
       cnt++;
     }
  }
 
  cout<<cnt<<endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int a, b;
int main() {
    cin >> a >> b;
    if (a > 0 && b > 0) {
        cout << "Positive" << endl;
    }
	else if (max(a, b) >= 0 && min(a, b) <= 0 || a == 0 || b == 0)
	{
        cout << "Zero" << endl;
    }
	else 
	{
        if ((abs(min(a, b)) - abs(max(a, b))) % 2 == 0)
		{
            cout << "Negative" << endl;
        }
		else
		{
            cout << "Positive" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){

	unsigned long n, min, xy[4] = {0}, k[1000][2] = {0};
	int i, a1 ,a2, ans[1000] = {0};

	scanf("%d",&n);
	scanf("%d",&i);

	for(a1 = 0; a1 < i; a1++){
		scanf("%d %d",&k[a1][0],&k[a1][1]);
		for(a2 = 0; a2 < 2; a2++){
			xy[a2] = k[a1][a2] - 1;
			xy[a2+2] = n - k[a1][a2];
		}
		min = xy[0];
		for(a2 = 1; a2 <= 3; a2++){
			if(min > xy[a2])
				min = xy[a2];
		}
		ans[a1] = min % 3 + 1;
	}

	for(a1 = 0; a1 < i; a1++)
		printf("%d\n",ans[a1]);

	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
// A - Beginning

using namespace std;

int N[5];

int main() {
    int i;

    for (i = 0;i < 4;i++)
        scanf("%d",&N[i]);

    sort(N,N + 4);

    if (N[0] == 1 && N[1] == 4 && N[2] == 7 && N[3] == 9)
        printf("YES\n");
    else
        printf("NO\n");

    return 0;
}


Measured memory_bytes: 256
N = int(input())

nums = list(map(int, input().split()))

ans = 0

if 1 not in nums:
    print(-1)
    exit()

ci = 1
for i in range(1, N+1):
    if nums[i-1] == ci:
        ci += 1
    else:
        ans += 1
print(ans)


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

int main(){
    int N,K;
    cin >> N >> K;
    long long int count = 0;

    for(int b=1; b<=N; b++){
        int p = N / b;
        int r = N % b;
        count += p * max(0, b - K) + max(0, r - K + 1);
    }

    if(K == 0) count -= N;

    cout << count << endl;
}

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

using namespace std;

using ll = long long;

const ll MOD = 1000000007;

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

ll dp[105][100005];

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, K;
	cin >> n >> K;
	vector<int> a(n);
	for (int i = 0; i < n; i++) cin >> a[i];

	dp[0][0] = 1;
	for (int i = 0; i < n; i++) {
		ll sum = 0;
		for (int j = 0; j <= K; j++) {
			(sum += dp[i][j]) %= MOD;
			if (j > a[i]) {
				sum = (sum + MOD - dp[i][j - a[i] - 1]) % MOD;
			}
			dp[i + 1][j] = sum;
		}
	}
	
	cout << dp[n][K] << endl;
	return 0;
}

Measured memory_bytes: 79360
#### import ####
import sys
import math
from collections import defaultdict

#### 設定 ####
sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

#### 定数 ####
mod = 10**9 + 7

#### 読み込み ####
def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N):
    read_all = [tuple(map(int, input().split())) for _ in range(N)]
    return map(list,zip(*read_all))

#################

N = I()
S = str(input())

nw = [0]*N
for i in range(1,N):
    if S[i-1]=='W':
        nw[i] = nw[i-1]+1
    else:
        nw[i] = nw[i-1]

ne = [0]*N
for i in range(N-1)[::-1]:
    if S[i+1]=='E':
        ne[i] = ne[i+1]+1
    else:
        ne[i] = ne[i+1]

x = [0]*N
for i in range(N):
    x[i] = nw[i] + ne[i]

print(min(x))

Measured memory_bytes: 47716
(defun solve (strings)
  (let ((count-map (make-hash-table :test 'equal)))
    (dolist (str strings)
      (incf (gethash (sort str #'char<) count-map 0)))
    (loop for count being each hash-value of count-map
          sum (/ (* (+ 1 (1- count)) (1+ (- (1- count) 1))) 2))))

#-swank
(let* ((n (read))
       (strings (loop repeat n collect (read-line))))
  (format t "~A~%" (solve strings)))


Measured memory_bytes: 53732
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b!=0?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}

const ll mod=1e9+7;

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

ll modfact(ll na,ll nz){
    if(na==nz) return 1;
    else return na*modfact(na-1,nz)%mod;
}

int main(){
    ll x,y;
    cin>>x>>y;
    ll cntx=0,cnty=0;
    while(x>0&&y>0){
        if(x==2*y){
            cntx+=y;
            x=y=0;
            break;
        }
        cnty++;
        x--;
        y-=2;
    }
    if(x==0&&y==0) cout<<modfact(cntx+cnty,cntx)*modpow(modfact(cnty,0),mod-2)%mod<<endl;
    else cout<<0<<endl;
    return 0;
}

Measured memory_bytes: 6784
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef pair<ll,ll> P;
#define fi first
#define se second
set<string> c;
const ll mod=1000000007;
const ll mod2=998244353;
const ll inf=100000000000000000;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
map<ll,ll> mp;
int n;
int tmp;
int check(int a,int b){
    for(int i=0;i<32;i++){
	if( ( (a>>i)&1 ) != ( (b>>i)&1 ) ) return i; 
    }
    return 0;
}

int main(){
    ll n;
    cin>>n;
    for(int i=0;i<n-1;i++){
	for(int j=i+1;j<n;j++){
	    cout<<1+check(i,j)<<" ";
	}
	cout<<endl;
    }
}


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

int main() {
  int a[4];
  for (int i=0; i<4; ++i) {
    char ch;
    scanf("%c", &ch);
    a[i] = ch-'0';
  }

  for (int i=0; i<8; ++i) {
    int cur=a[0];
    for (int j=0; j<3; ++j) {
      if (i >> j & 1) {
        cur += a[j+1];
      } else {
        cur -= a[j+1];
      }
    }

    if (cur != 7)
      continue;

    printf("%d", a[0]);
    for (int j=0; j<3; ++j) {
      if (i >> j & 1) {
        printf("+%d", a[j+1]);
      } else {
        printf("-%d", a[j+1]);
      }
    }

    printf("=7\n");
    return 0;
  }

  return 1;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define in ({int x=0;int c=getchar(),n=0;for(;!isdigit(c);c=getchar()) n=(c=='-');for(;isdigit(c);c=getchar()) x=x*10+c-'0';n?-x:x;})
#define forinc(i,a,b) for(int i=a;i<=b;i++)
#define fordec(i,a,b) for(int i=a;i>=b;i--)
#define int long long
const int maxn=1e5+1;

int n;
int a[maxn],f[1000001];

main()
{
    cin>>n;
    forinc(i,1,n) cin>>a[i];
    f[1]=0;
    f[2]=abs(a[2]-a[1]);
    forinc(i,3,n)
    {
        f[i]=min(f[i-1]+abs(a[i]-a[i-1]),f[i-2]+abs(a[i]-a[i-2]));
    }
    cout<<f[n];
}



Measured memory_bytes: 3456
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define debug(x) cerr << #x " = " << (x) << endl;
#define P(x) cerr << #x << endl;    
typedef long long ll;
//#define int long long
const int mod = 1000000007;


int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout << fixed << setprecision(9);
    
    
    int a, b;
    cin >> a >> b;
    cout << max({a + b, a - b, a * b}) << endl;
    
    
    return 0;
}






Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=1e5+4;
const int MOD=1e9+7;
int f[N][10][14];//pos, num, remainder
int n;
char ss[N];
ll fp[N];
inline ll fpow(ll a,int b,int m) {
	ll ret=1;
	while (b) {
		if (b&1) ret=1ll*ret*a%m;
		b>>=1,a=1ll*a*a%m;
	}
	return ret;
}
inline void init() {
	if (ss[1]^'?') f[1][ss[1]-'0'][ss[1]-'0']=1;
	else {
		for (int num=0;num<10;++num)
			f[1][num][num]=1;
	}
	fp[0]=1;
	for (register int i=1;i<=n;++i)
		fp[i]=fp[i-1]*10%13;
}
int main() {
	scanf("%s",ss+1);
	n=strlen(ss+1);
	for (int i=1;(i<<1)<=n;++i)
		swap(ss[i],ss[n-i+1]);
	init();
	for (register int i=2;i<=n;++i) {
		if (ss[i]^'?') {
			for (int r=0;r<13;++r)
				for (int num=0;num<10;++num) {
					int t=ss[i]-'0';
					(f[i][t][(fp[i-1]*t+r)%13]+=f[i-1][num][r])%=MOD;
				}
		} else {
			for (int cur=0;cur<10;++cur)
				for (int r=0;r<13;++r)
					for (int num=0;num<10;++num)
						(f[i][cur][(fp[i-1]*cur+r)%13]+=f[i-1][num][r])%=MOD;
		}
	}
	int ans=0;
	for (int num=0;num<10;++num)
		(ans+=f[n][num][5])%=MOD;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 55808
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000000)
INF = 1<<32


def solve(S: str):
    
    cf = 'CODEFESTIVAL2016'
    print([S[i]!=cf[i] for i in range(len(S))].count(True))

    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940