akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <functional>
#include <string>
#include <cmath>  //sqrt 
#include <iomanip> //setprecision
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define beg begin()
#define end end()

void _main(){
    char pm,before;
    ll p=0,m=0;
    ll sum=0;
    while(cin >> pm){
        if(before=='>'&&pm=='<'){
            ll bigger = max(p,m);
            ll smaller = max(min(p,m) -1,(ll)0);
            sum += bigger*(1+bigger)/2 + smaller*(1+smaller)/2;
            p=0;m=0;
        }
        if(pm=='>') m++;
        if(pm=='<') p++;
        before=pm;
    };
    ll bigger = max(p,m);
    ll smaller = max(min(p,m) -1,(ll)0);
    sum += bigger*(1+bigger)/2 + smaller*(1+smaller)/2;
    cout << sum << endl;
    return;
}
int main() {
    cout << fixed << setprecision(10);
    _main();
    return 0;
}
    

Measured memory_bytes: 3168
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <assert.h>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <unordered_map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,a) for(ll i=ll(a-1);i>=0;--i)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}

const ll INF = 1e15;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
const ll EPS = 1e-10;
int sgn(const double a){
    return (a < -EPS ? -1 : (a > EPS ? +1 : 0));
}
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> tri;
typedef pair<double,double> point;
typedef complex<double> Point;
const ll MAX = 30000;
constexpr ll nx[8] = {1,0,-1,0,1,-1,1,-1};
constexpr ll ny[8] = {0,1,0,-1,1,1,-1,-1};

int main(){
    //cin.tie(0);
    //ios::sync_with_stdio(false);
    string s;
    cin >> s;
    ll cnt = 0,ans = 0;
    rep(i,3){
        if (s[i] == 'R') cnt++;
        else{
            chmax(ans,cnt);
            cnt = 0;
        }
    }
    chmax(ans,cnt);
    PRINT(ans);
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
using pii = pair<int,int>;
using ll = long long;
using pll = pair<ll,ll>;
using pli = pair<ll,int>;
using pil = pair<int,ll>;
using ld = long double;
using ui = unsigned int;
using ull = unsigned long long;
using ui128 = __uint128_t;
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define lc ind<<1
#define rc ind<<1|1
const int MN = 1e6 + 2, LOG = 17, INF = 1e8;
int main () { 
	int n,x;
	scanf ("%d %d",&n,&x);
	vector<ll> a(n+1);
	for (int i = 1; i <= n; i++) scanf ("%lld",&a[i]);
	ll ret = 0;
	for (int i = 2; i <= n; i++) {
		ll take = max(0LL,(ll)a[i-1] + a[i] - x);ret += take;
		ll go = min(take,a[i]);
		a[i] -= go; take -= go; 
		a[i-1] -= take;
	}
	printf ("%lld\n",ret);
    return 0;
}


Measured memory_bytes: 4056
#include<bits/stdc++.h>
using namespace std;
struct point{
    long long int first,second;
};
int main(){
    int n;
    cin>>n;
    long long int arr[n];
    for(int i=0;i<n;i++){
        cin>>arr[i];
    }
    //DP[i][j] gives maximum value chhosen by player A and B if()subarray{i.....j] isconsidered;
    point dp[n][n];
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            dp[i][j].first=0;
            dp[i][j].second=0;
        }
    }
    for(int l=1;l<=n;l++){
        for(int i=0;i<n-l+1;i++){
            int j = i+(l-1);
            if(i==j){
                dp[i][j].first = arr[i];
                dp[i][j].second = 0;
            }
            else{
                if(arr[i]+dp[i+1][j].second>arr[j]+dp[i][j-1].second){
                    dp[i][j].first = arr[i]+dp[i+1][j].second;
                    dp[i][j].second = dp[i+1][j].first;
                }
                else{
                    dp[i][j].first = arr[j]+dp[i][j-1].second;
                    dp[i][j].second = dp[i][j-1].first;
                    
                }
            }
        }
    }
//    for(int i=0;i<n;i++){
//        for(int j=0;j<n;j++){
//            cout<<dp[i][j].first<<" "<<dp[i][j].second<<"   ";
//        }
//        cout<<endl;
//    }
    long long int ans=0;
    ans = dp[0][n-1].first-dp[0][n-1].second;
    cout<<ans;
    return 0;
}


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

lis=[26, 702, 18278, 475254, 12356630, 321272406, 8353082582, 217180147158, 5646683826134, 146813779479510, 1000000000000001]


k=0#答えが何桁になるか調べる
for i in range(len(lis)):
  if lis[i]>=n:
    k=i
    break

s=""
if k==0:
  s+=chr(n+96)
else:
  for i in range(k+1):
    n-=1
    x=int(n%26)
    s+=(chr(x+ord('a')))
    n=int(n//26)

print(s[::-1])

Measured memory_bytes: 9068
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0; i<N; i++)

using namespace std;

int main(){
  int n; cin >> n;
  map<int,int> a;
  
  int key;
  for(int i = 1; i <= n; i++) {
    cin >> key;
    a[key] = i;
  }
  for(int i = 1; i <= n; i++) {
    cout << a[i] << " ";
  }
  cout << endl;
}

Measured memory_bytes: 5504
import numpy as np
N,M = map(int,input().split())
A = np.array([list(input()) for i in range(N)])
B = np.array([list(input()) for i in range(M)])
for i in range(N):
    for j in range(N):
        check = A[i:i+M,j:j+M]
        if check.shape != (M,M):
            continue
        if (check==B).all():
            print("Yes")
            exit()
print("No")


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

int main(){
    int n, y;
    cin >> n >> y;
    int r10000 = -1, r5000 = -1, r1000 = -1;
    for(int a = 0; a <= n; a++){
        for(int b = 0; a + b <= n; b++){
            int c = n - a - b;
            int sum = 10000*a + 5000*b + 1000*c;
            if(sum == y){
                r10000 = a;
                r5000 = b;
                r1000 = c;
            }
        }
    }

    cout << r10000 << " " << r5000 << " " << r1000 << endl;
    return 0;
}

Measured memory_bytes: 3616
N = int(input())
A = [int(i) for i in input().split()]

S = A[0] + A[1]
X = 0
for i in range(2, N) :
  X ^= A[i]

dp = [[[-1] * 2 for _ in range(2)] for _ in range(60)]
dp[0][0][0] = 0

for i in range(59) :
  cs = (S >> i) & 1
  cx = (X >> i) & 1
  ca = (A[0] >> i) & 1
  for j in (0, 1) :
    for k in (0, 1) :
      if dp[i][j][k] < 0 : continue
      for na in (0, 1) :
        for nb in (0, 1) :
          ni = i + 1
          nj = 0
          nk = k
          if na ^ nb != cx : continue
          ns = na + nb + j
          if ns % 2 != cs :continue
          if ns >= 2 :
            nj = 1
          if ca < na :
            nk = 1
          elif ca == na :
            nk = k
          else :
            nk = 0
          dp[ni][nj][nk] = max(dp[ni][nj][nk], dp[i][j][k] | (na << i))
          
if 1 <= dp[-1][0][0] <= A[0] :
  print(A[0] - dp[-1][0][0])
else :
  print(-1)

Measured memory_bytes: 62708
#include <bits/stdc++.h>
#define assem99 ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define ld long double
#define endll '\n'
#define sz(a) (int)(a).size()
#define RWFile freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
int dx[] = { 0, -1, 0, 1, -1, 1, -1, 1 };
int dy[] = { -1, 0, 1, 0, 1, -1, -1, 1 };
const int MOD = 1e9 + 7, N = 2e6 + 5, oo = 1e9;
const double pi = acos(-1);
using namespace std;

int n, arr[50][50], dp[50][1 << 20];
ll solve(int i, int msk)
{
    if(i == n) return 1;
    if(~dp[i][msk]) return dp[i][msk];
    ll ans = 0;
    for(int j = 0; j < n; j++)
    {
        int cur = (1 << j);
        if(arr[i][j] and !(msk & cur)) ans += solve(i + 1, msk + cur), ans %= MOD;
    }
    return dp[i][msk] = ans;
}

int main()
{
    assem99
    memset(dp, -1, sizeof dp);
    cin>>n;
    for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) cin>>arr[i][j];
    cout<<solve(0, 0);

    return 0;
}

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

#define INF 1e9
#define llINF 1e18
#define MOD 1e9+7
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ALL(a) (a).begin(),(a).end()
#define Yes(hoge) cout<<((hoge)?"Yes":"No")<<endl;
#define YES(hoge) cout<<((hoge)?"YES":"NO")<<endl;
using namespace std;
int main(){
  int a,b,c,d,e;string s,ss;
  cin>>a>>b;
  if(a%b==0)cout<<0<<endl;
  else cout<<1<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<int, int>;
using VI = vector<int>;

int main() {
#ifdef LOCAL_EXEC
//	freopen("sample.in", "r", stdin);
//	freopen("sample.out", "w", stdout);
#else
  ios_base::sync_with_stdio(false); cin.tie(NULL);
#endif

  ll h; cin >> h;
  ll ans = 1;
  while (ans <= h) ans <<= 1;
  ans--;
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <bitset>
#include <vector>
#include <queue>
#include <map>
#include <set>

#define i64 int64_t
#define ff(ii,nn,mm) for(int ii=nn;ii<mm;ii++)
#define st(vvv) sort(vvv.begin(),vvv.end())
#define rvs(vvv) reverse(vvv.begin(),vvv.end())
int inf = 1000000007;
i64 giant = 4000000000000000000;

using namespace std;


int main() {
	int a, b;
	cin >> a >> b;
	if (a != 1 && b != 1) {
		cout << 1 << endl;
	}
	else if (a != 2 && b != 2) {
		cout << 2 << endl;
	}
	else if (a != 3 && b != 3) {
		cout << 3 << endl;
	}
	return 0;
}

Measured memory_bytes: 384
// inputに入力データ全体が入る
function Main(input) {
	var args = input.split(" ");
	var N = parseInt(args[0],10);
	var sum = parseInt(args[1],10);
	var output = "";

	double_loop:
	for(var x = 0;x <= N;x++){
		for(var y = 0;y<= N - x;y++){
			z = N-x-y;
			if(10000*x+5000*y+1000*z == sum){
				output = `${x} ${y} ${z}`;
				break double_loop;
			}
		}
	}
	if(!output) output = "-1 -1 -1";
	//出力
	console.log(output);
}

//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

const int MOD = 1e9 + 7;

const string table = "ATGC";
typedef vector<string> Term;

int Na, Nt, Ng, Nc;
int M;

string flabel;
map<string, vector<string>> terms;
vector<int> symbols;
int memo[55][55][55][55];

int dfs(int a, int t, int g, int c){
    if(memo[a][t][g][c] >= 0)
        return memo[a][t][g][c];

    if(a > Na || t > Nt || g > Ng || c > Nc)
        return memo[a][t][g][c] = 0;
    if(a == Na && t == Nt && g == Ng && c == Nc)
        return 1;
    
    int l = a + t + g + c;
    int res = 0;
    if(symbols[l]&1)
        res = (res + dfs(a+1, t, g, c)) % MOD;
    if(symbols[l]&2)
        res = (res + dfs(a, t+1, g, c)) % MOD;
    if(symbols[l]&4)
        res = (res + dfs(a, t, g+1, c)) % MOD;
    if(symbols[l]&8)
        res = (res + dfs(a, t, g, c+1)) % MOD;
    return memo[a][t][g][c] = res;
}

bool dfs(string label){
    auto term = terms[label];

    for(auto t: term){
        if(t[0] == '['){
            int sym = 0;
            for(int i=1; i<t.size()-1; i++){
                sym |= 1<<table.find(t[i]);
            }
            symbols.push_back(sym);
            if(symbols.size() > Na + Nt + Ng + Nc)
                return false;
        }else{
            if(!dfs(t))
                return false;
        }
    }
    return true;
}

int solve(){
    memset(memo, -1, sizeof(memo));
    
    if(!dfs(flabel))
        return 0;
    
    return dfs(0, 0, 0, 0);
}

int main(){
    cin >> Na >> Nt >> Ng >> Nc;
    cin >> M; cin.ignore();
    
    for(int i=0; i<M; i++){
        string s; getline(cin, s);
        stringstream ss(s);
        string label; ss >> label;
        label = label.substr(0, label.size()-1);
        
        if(i == 0) flabel = label;
        
        string t;
        while(ss >> t)
            terms[label].push_back(t);
    }
    cout << solve() << endl;
    
    return 0;
}

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

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define COUT(x) cout<<(x)<<"\n"

int main(){
    int n;cin >>n;
    vector<int> a(n);
    REP(i,n)cin >> a[i];
    sort(a.begin(),a.end(),greater<int>());
    ll ans = a[0];
    int tes = 2,count = 0;
    for(int i=1;i<n;){
        if(tes==n)break;
        count++;
        tes++;
        ans += a[i];
        if(count%2==0){
            count = 0;
            i++;
        }
    }
    COUT(ans);
}

Measured memory_bytes: 4028
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <cctype>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int

template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}

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

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

typedef string::const_iterator State;
class ParseError {};

struct Parser {
    // ??°?????????????????????
    int number(State &begin) {
        int ret = 0;
        while(isdigit(*begin)) {
            ret *= 10;
            ret += (*begin - '0');
            begin++;
        }
        return ret;
    }

    // ??¬??§?????°????????????
    int factor(State &begin) {
        if(*begin == '(') {
            begin++; // '(' ????£???°???
            int ret = expression(begin);
            begin++; // ')' ????£???°???
            return ret;
        }
        else return number(begin);
    }

    // ??????????????????????????????
    int term(State &begin) {
        // ????????????????????¨????????£????????°??????????????§???????????????
        // begin ?????????????????°?????§???????????????
        int ret = factor(begin);

        while(1) {
            if(*begin == '*') {
                begin++;
                ret *= factor(begin);
            }
            else if(*begin == '/') {
                begin++;
                ret /= factor(begin);
            }
            else break;
        }

        return ret;
    }

    // ??????????????????????????????
    int expression(State &begin) {
        int ret = term(begin);
        while(1) {
            if(*begin == '+') {
                begin++;
                ret += term(begin);
            }
            else if(*begin == '-') {
                begin++;
                ret -= term(begin);
            }
            else break;
        }
        return ret;
    }
};

signed main() {
    int N; cin >> N;
    rep(i,0,N) {
        Parser ps;
        string s; cin >> s;
        State begin = s.begin();
        int ans = ps.expression(begin);
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 3208
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
using namespace std;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;

int main()
{
    int n;
    cin >> n;
    string s, t;
    cin >> s >> t;
    for (int i = 0; i < n; i++)
    {
        cout << s[i] << t[i];
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
#define FOR(i,a,b) for(int i=(a);i<=(b);++i) 
#define RFOR(i,a,b) for(int i=(a);i>=(b);--i) 
#define REP(i,n) for(int i=0;i<(n);++i)
#define RREP(i,n) for(int i=(n);i>0;--i)
#define CI cin>> 
#define CO cout<<
#define EN <<endl 
#define all(x) (x).begin(),(x).end() 
#define asn ans
using namespace std;
template <typename T> istream& operator >> (istream& is, vector<T>& vec) { for (T& x : vec) is >> x; 	return is; }
using ll = long long;

long long p[1000] = {1};
long long a[1000] = {1};

long long makeB(long long n,long long x) {
	if (n == 0) {
		if (x <= 0)return 0;
		else return 1;
	}
	else if (x <= 1 + a[n - 1]) {
		return makeB(n - 1, x - 1);
	}
	else {
		return p[n - 1] + 1+makeB(n-1,x-2-a[n-1]);
	}
}

int main() {
	long long n,x; CI n>>x;

	for(int i=1;i<n;i++) {
		a[i] = a[i - 1] * 2 + 3;
		p[i] = p[i - 1] * 2 + 1;
	}

	CO makeB(n, x) EN;

	return 0;
}

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

#define forn(i,n) for(int i=0;i<(int)(n);i++)
#define si(c) ((int)(c).size())
#define forsn(i,s,n) for(int i = (int)(s); i<((int)n); i++)
#define dforsn(i,s,n) for(int i = (int)(n)-1; i>=((int)s); i--)
#define all(c) (c).begin(), (c).end()
#define D(a) cerr << #a << "=" << a << endl;
#define pb push_back
#define eb emplace_back
#define mp make_pair

typedef long long int ll;
typedef vector<int> vi;
typedef pair<int,int> pii;

const int N = 444;

bool in[N];

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

    int n,m; 
    cin >> n >> m;
    vector<pii> e(m);
    forn(i,m) cin >> e[i].first >> e[i].second;
    reverse(all(e));

    int ans = 0;
    forsn(v,1,n+1) forsn(u,1,v) {
        memset(in, 0, sizeof in);
        in[u] = in[v] = 1;
        for (auto xy : e) {
            int x,y; tie(x,y) = xy;
            if (in[x] != in[y]) {
                if (in[x] < in[y]) swap(x,y);
                in[y] = 1;
            }
            else if (in[x]) {
                ans--;
                break;
            }
        }
        ans++;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s, t;
  cin >> s >> t;
  int sum = 0;
  for (int i = 0; i < 3; i++){
    if (s.at(i) == t.at(i)){
      sum++;
    }
  }
  cout << sum << endl;
}

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

int main() {
    int n;cin>>n;
    long a[n];
    long ans=0,cc=1;
    
    for(int i=0;i<n;++i){
        cin>>a[i];
    }
    sort(a,a+n);
    for(int i=0;i<n;++i){
    if(a[i]==a[i+1]){
        cc++;
    }
    else{
        if(a[i]<=cc)ans+=cc-a[i];
        else ans+=cc;
        
        cc=1;
    }
    }
    cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"
#ifndef err
#define err(...)(void)0
#endif
using namespace std;
using ll = long long;
using ull = decltype(1ull);
template<class T>int size(T&&a) { return a.size(); }
#define REP(t,a)for(typename make_signed<decltype(a.second)>::type t=a.first,_l##t=a.second;t<_l##t;t++)
#define RREP(t,a)for(typename make_signed<decltype(a.second)>::type t=a.second-1,_l##t=a.first;t>=_l##t;t--)
template<class B>pair<int, B>make_pair(B b) { return{ 0,b }; }
#define rep(t,...)REP(t,make_pair(__VA_ARGS__))
#define rrep(t,...)RREP(t,make_pair(__VA_ARGS__))
#define all(a)begin(a),end(a)
#define rall(a)a.rbegin(),a.rend()
#define var(t, ...) t __VA_ARGS__;in,__VA_ARGS__;

void Calc();
int main() {
  ios::sync_with_stdio(false); cin.tie(nullptr);
  cin.exceptions(istream::failbit | istream::badbit);
  cout << fixed << setprecision(15); Calc(); cout.flush(); return 0;
}
template<class A>void amax(A&a, A b) { a = max(a, b); }
template<class A>void amin(A&a, A b) { a = min(a, b); }
template<class A>int comp(A a, A b) { return a < b ? 1 : b < a ? -1 : 0; }
struct Scanner {
  template<class A = string>A Next() { A a; cin >> a; return a; }
  template<class A = int>vector<A>Array(int n) { vector<A>a(n); for (A&i : a) cin >> i; return a; }
  string Line() const { string s; getline(cin, s); return s; }
  template<class A>Scanner&operator,(A&a) { a = Next<A>(); return *this; }
  template<class A>operator A() { return Next<A>(); }
}in;

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


void Calc() {

  int k = in;
  struct Data {
    int i, cost;
    void In() {

    }
    bool operator<(const Data&d)const {
      return cost > d.cost;
    }
  };

  vector<vector<Data>> edge(k + 1);
  const int INF = 1e9 - 1;

  vector<int> cost(k, INF);
  rep(i, k + 1) {
    edge[i].push_back({ (i + 1) % k, 1 });
    edge[i].push_back({ (i * 10) % k, 0 });
  }

  priority_queue<Data> q;
  q.push({ 1, 1 });
  while (q.size()) {
    auto p = q.top(); q.pop();
    if (cost[p.i] != INF)continue;
    cost[p.i] = p.cost;
    for (auto& i : edge[p.i]) {
      if (p.cost + i.cost < cost[i.i]) {
        q.push({ i.i, p.cost + i.cost });
      }
    }
  }
  cout << (cost[0]) << endl;
}


Measured memory_bytes: 6780
#include<bits/stdc++.h>
using namespace std;
int main()
{
	double a,b;
	cin>>a>>b;
	if(a<=5)
	{
		cout<<0;
		return 0;
	}
	if(a<=12)
	{
		cout<<b/2;
		return 0;
	}
	cout<<b;
	return 0;
} 

Measured memory_bytes: 256
#include"bits/stdc++.h"
#include<cassert>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
const int mod = 1000000007;
const int inf = 1ll << 61;
typedef pair<int, int> P;
typedef pair<int, P>PP;

signed main() {
	string s; cin >> s;
	vector<char>c; vector<int>v;
	char now = '<';
	int cnt = 0;
	s.push_back('@');
	rep(i, s.size()) {
		if (s[i] == now)cnt++;
		else {
			c.push_back(now);
			v.push_back(cnt);
			cnt = 1;
			now = s[i];
		}
	}
	s.pop_back();
//	rep(i, c.size())cout << c[i] << v[i] << endl;
	int sum = 0;
	for (int i = 0; i < c.size()-1; i += 2) {
		int k = v[i], l = v[i + 1];
		if (k > l)swap(k, l);
		sum += k*(k - 1) / 2 + l*(l + 1) / 2;
	}
	if (s[s.size() - 1] == '<') {
		int k = v[v.size() - 1];
		sum += k*(k + 1) / 2;
	}
	cout << sum << endl;
}


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

int main(){
  int n;string s;
  cin>>n>>s;
  set<int> ss3;
  int ans=0;
  rep(i,n){ss3.insert(s.at(i));}
  rep(i,n){
    set<int> ss1,ss2;
    string s1=s.substr(0,i);
    string s2=s.substr(i,n-i);
    
    rep(j,n-i){
      ss2.insert(s2.at(j));
    }
    
    rep(j,i){
      ss1.insert(s1.at(j));
    }
    
    int a=ss1.size()+ss2.size()-ss3.size();
    ans=max(ans,a);
  }
  cout<<ans;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi acos(-1.0)

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;


ll comb_mem[51][51] = {}; // -1で初期化すること
ll comb(int x, int y){
    if(x < y) return 0;
    if(y == 0 || y == x) return 1;
    if(comb_mem[x][y] != -1) return comb_mem[x][y];
    else return comb_mem[x][y] = comb(x - 1, y - 1) + comb(x - 1, y);
}


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    fill_n((ll*)comb_mem, 51 * 51, -1);
    int n, a, b;
    cin >> n >> a >> b;
    VL vv;
    REP(i, n){
        ll v;
        cin >> v;
        vv.push_back(v);
    }
    sort(vv.begin(), vv.end(), greater<ll>());

    double ans = 1.0;
    int ans_div = a;
    vector<P> comv;
    FOR(i, a, b){
        ll avr = 0;
        ll select_min = vv[i - 1];
        int all_cnt = 0;
        int select_cnt = 0;
        REP(j, vv.size()){
            if(j < i) avr += vv[j];
            if(vv[j] == select_min){
                if(j < i) select_cnt++;
                all_cnt++;
            }
        }
        if(ans * i < avr * ans_div){
            ans = avr;
            ans_div = i;
            comv.clear();
            comv.push_back(make_pair(all_cnt, select_cnt));
        }else if(ans * i == avr * ans_div){
            comv.push_back(make_pair(all_cnt, select_cnt));
        }
    }

    cout << fixed;
    cout << setprecision(6) << (double)ans / ans_div << "\n";
    ll ans2 = 0;
    for(auto c : comv) ans2 += comb(c.first, c.second);
    cout << ans2 << "\n";
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<cctype>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define all(v) (v).begin(),(v).end()
typedef long long int ll;
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4
#define pii pair<int,int>


int main(){
  int sx, sy, tx, ty; cin >> sx >> sy >> tx >> ty;
  int dx = tx - sx, dy = ty - sy;

  cout << string(dy,'U') << string(dx,'R');
  cout << string(dy,'D') << string(dx,'L');
  cout << 'L' << string(dy+1,'U') << string(dx+1,'R') << 'D';
  cout << 'R' << string(dy+1,'D') << string(dx+1,'L') << 'U';
  cout << endl;
  






  // cout << fixed << setprecision(10);
  
  return 0;
}


Measured memory_bytes: 3596
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = 0
for i in range(n):
    ans += min(a[i], b[i])
    # print(i, ans)
    if a[i] < b[i]:
        if a[i+1] <= b[i] - a[i]:
            ans += a[i+1]
            a[i+1] = 0
        else:
        # a[i+1] -= min(a[i+1], b[i] - a[i])
            a[i+1] -= b[i] - a[i]
            ans += b[i] - a[i]
        # print(i, ans)

print(ans)

Measured memory_bytes: 18624
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cassert>
using namespace std;
using ll = long long;
const int INF = 1<<30;
const int MOD = 1e9 + 7;
signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    string s; cin >> s;
    int ans = INF;
    vector<int> B(n + 1, 0), W(n + 1, 0);
    for(int i = 1; i <= s.size(); i++)
    {
        B[i] = B[i - 1] + (s[i - 1] == '#' ? 1 : 0);
        W[i] = W[i - 1] + (s[i - 1] == '.' ? 1 : 0);
    }
    for(int i = 0; i <= s.size(); i++)
    {
        int black = B[i];
        int white = W[n] - W[i];
        ans = min(ans, black + white);
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 2196
import java.util.Scanner;

public class Main{
	static int n;
	static int[]a;
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		n = scan.nextInt();
		a = new int[n  +1];
		for(int i = 0; i < n; i++) {
			a[i] = scan.nextInt();
		}
		scan.close();
		System.out.println(lis());
	}
	static int lis() {
		int len = 1;
		int[]L = new int[n];
		L[0] = a[0];
		for(int i = 1; i < n; i++) {
			if(L[len - 1] < a[i]) {
				L[len++] = a[i];
			}else {
//				int k  = Arrays.binarySearch(a, 0, len - 1, a[i]);
//				if(k < 0) {
//					k = ~k;
//				}
				int idx = bs(L, 0, len - 1, a[i]);
				L[idx] = a[i];
			}
		}
		return len;
	}
	static int bs(int[]L, int from, int to, int key) {
		int l = from - 1;
		int r = to;
		while(r - l > 1) {
			int mid = (l + r) / 2;
			if(L[mid] >= key) {
				r = mid;
			}else {
				l = mid;
			}
		}
		return r;
	}
}


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

int N, R, P[50], C[50];
int a[51][50];

int main(void) {
  while(cin >> N>>R, N || R) {
    REP(i, 0, R)cin >>P[i]>>C[i];
    REP(i, 0, N) a[0][i] = N - i;
    REP(i, 0, R){
      REP(j, 0, C[i]) a[i + 1][j] = a[i][P[i] + j - 1];
      REP(j, 0, P[i] - 1) a[i + 1][C[i] + j] = a[i][j];
      REP(j, C[i] + P[i] - 1, N) a[i + 1][j] = a[i][j];
      // REP(j, 0, N) {
      //     cout << a[i + 1][j] << " ";
      // }
      // cout << endl;
    }
    cout << a[R][0] << endl;
  }

  return 0;
}

Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
constexpr int mod=1000000007;
constexpr int mod1=998244353;
vector<int> dx={0,-1,0,1},dy={1,0,-1,0};
bool inside(int y,int x,int h,int w){
	if(y<h && y>=0 && x<w && x>=0) return true;
	return false;
}





int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;cin >> n;
	vector<string> a(n);
	map<string,int> m;
	rep(i,n){
		cin >> a.at(i);
		sort(a.at(i).begin(),a.at(i).end());
		m[a.at(i)]++;
	}
	ll ans = 0;
	for(auto i : m){
		ll k = i.second;
		ans += k * (k - 1) / 2;
	}
	cout << ans << endl;
}


Measured memory_bytes: 16640
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(long long)(n);++i)
#define all(a) a.begin(), a.end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
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; }
 
const int MOD=1e9+7;
const ll INF=1e18;
const int MAX=510000;
const double pi=acos(-1);
int dx[8] = {1,0,-1,0,1,1,-1,-1};
int dy[8] = {0,1,0,-1,-1,1,1,-1};


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
  
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  int ng = 0,  ok = 1e9;
  while(abs(ng-ok)>1){
    int m = (ng+ok)/2;
    auto f = [&](int m){//&が[]に入るときは外部の数を引数に使える
      ll now = 0;
      rep(i,n) now += (a[i]-1)/m;
      return now <= k;
    };
    if(f(m)) ok = m;
    else ng = m;
  }
  cout << ok << endl;
      
  
  return 0;
}


Measured memory_bytes: 3976
#pragma region include
#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <tuple>
#include <bitset>

#include <queue>
#include <complex>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <fstream>
#include <random>
//#include <time.h>
#include <ctime>
#pragma endregion //#include
/////////
#define REP(i, x, n) for(int i = x; i < n; ++i)
#define rep(i,n) REP(i,0,n)
#define ALL(X) X.begin(), X.end()
/////////
#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
typedef std::pair<LL,LL> PLL;//
typedef std::pair<int,int> PII;//
#pragma endregion //typedef
////定数
const int INF = (int)1e9;
const LL MOD = (LL)1e9+7;
const LL LINF = (LL)4e18+20;
const LD PI = acos(-1.0);
const double EPS = 1e-9;
/////////
using namespace::std;

void solve(){
	int H,W;
	cin >> H >> W;
	vector< vector<int> > C(10,vector<int>(10));
	for(int i=0;i<10;++i){
		for(int j=0;j<10;++j){
			cin >> C[i][j];
		}
	}
	///////////
	vector< vector<int> > cost = C;
	for(int k=0;k<10;++k){
		for(int i=0;i<10;++i){
			for(int j=0;j<10;++j){
				//i->j :i->k->j
				int ter = cost[i][k]+cost[k][j];
				if( cost[i][j] > ter ){
					cost[i][j] = ter;
				}
			}
		}
	}
	///////////
	int ans = 0;
	int N = H*W;
	int num;
	while(N--){
		cin >> num;
		if( num != -1 ){
			ans += cost[num][1];
		}
	}
	cout << ans << endl;
}

#pragma region main
signed main(void){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}
#pragma endregion //main()

Measured memory_bytes: 256
#include<stdio.h>

#define N 100000

int partition(int A[],int p,int r){
  int x,i,j,temp;

  x = A[r];
  i = p-1;
  for(j=p;j<r;j++){
    if(A[j] <= x){
     i = i+1;
     temp=A[i];
     A[i]=A[j];
     A[j]=temp;
    }
  }

  temp=A[i+1];
  A[i+1]=A[r];
  A[r]=temp;

  return i+1;

}

int main(){
  int n,A[N];
  int i,a;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  a=partition(A, 0, n-1);

    for(i=0;i<n;i++){
      if(i==a) printf("[%d]",A[a]);
      else printf("%d",A[i]);
      if(i<n-1) printf(" ");
    }

    printf("\n");

    return 0;
  }





Measured memory_bytes: 2108
#include<bits/stdc++.h>
using namespace std;
int gcd(int a, int b)
{
    int c;

    if (a < b) {
        a+=b; b=a-b; a-=b;
    }

    while (b != 0) {
        c = a % b;
        a = b;
        b = c;
    }

    return a;
}

int main(void){
    int n;
    cin >> n;
    int ans;
    cin >> ans;
    for (int i = 0; i < n - 1; i++){
        int a;
        cin >> a;
        ans = gcd(a, ans);
    }
    cout << ans << endl;
}

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

#define LL long long

int main() {
    ios::sync_with_stdio(0), cin.tie(0);
    
    int n, l, sum = 0; cin >> n >> l;
    int a[n];
    for(int i = 0; i < n; i++) a[i] = l + i;
    int mn = 1e9;
    for(int i : a) {
        sum += i;
        if(abs(i) < abs(mn)) {
            mn = i;
        }
    }    
    cout << sum - mn;
}

Measured memory_bytes: 3656
N,M=map(int,input().split())
A,B=[0]*M,[0]*M
for i in range(M):
  A[i],B[i]=map(int,input().split())
X,Y=[0]*N,[0]*N
for i in range(M):
  if(A[i]==1):
    X[B[i]-1]=1
  elif(B[i]==N):
    Y[A[i]-1]=1
sum=0
for i in range(N):
  sum+=X[i]*Y[i]
if(sum):
  print("POSSIBLE")
else:
  print("IMPOSSIBLE")

Measured memory_bytes: 21876
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
/* this code is generated by shikhar verma . Dont try to copy it. You may be booked under plagiarism. */
//int numberofPaths(int h,int w,int a,int b);
int main()
{
    ll n,i,len1,h,w,t,cnt=0,cnt1=0,x=1,m,flag=0,k=10;
   /* freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);*/
    cin>>n;
    t=n;
    if(n%2==1)
    {
        cout<<0<<endl;
        return 0;
    }else{
    while(k<=n)
    {
        cnt+=n/k;
        k=k*5;
    }
    }

    cout<<cnt+cnt1;

	return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int a=sc.nextInt();
		int b=sc.nextInt();
		int c=b-a;
		int d=0;
		for(int i=1;i<=c;i++) {
			d=d+i;
		}
		System.out.println(d-b);
	}
}

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

#define pb push_back
#define inf 0x3f3f3f3f
int v[100100];
int memo[100100];
int n;

int go(int i) {
	if (i == n-1) return 0;
	if (memo[i] != -1) return memo[i];

	int ans = 1<<30;

	if(i+1 <= n-1) ans = min(ans, go(i+1) + abs(v[i+1] - v[i]));
	if(i+2 <= n-1) ans = min(ans, go(i+2) + abs(v[i+2] - v[i]));

	return memo[i] = ans;
}

int main(){
	cin >> n;
	for(int i = 0; i < n; i++) cin >> v[i];

	memset(memo, -1, sizeof(memo));
	cout << go(0) << endl;
}

Measured memory_bytes: 5760
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define double long double
#define low lower_bound
#define upp upper_bound
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define Rep(i,n) for (int i = (int)(n); i >= 0; i--)
#define all(vec) vec.begin(),vec.end()
#define rever(vec) reverse(all(vec));
#define cend cout << endl;
#define prique(T) priority_queue<T,vector<T>,greater<T>>
struct edge { int to, cost; };
typedef pair<int, int> P;
const int mod = 1e9 + 7, inf = 1e16;

int modpow(int x, int n) {
	if (n == 0) return 1;
	if (n % 2) return (x * modpow(x * x % mod, n / 2) % mod + mod) % mod;
	return (modpow(x * x % mod, n / 2) + mod) % mod;
}

int fact(int n) {
	int ans = 1;
	rep(i, n) {
		ans *= (i + 1);
		ans %= mod;
	}
	return ans;
}

int comb(int n, int r) {
	if (n < r) swap(n, r);
	if (n - r < r) r = n - r;
	return fact(n) * modpow(fact(n - r), mod - 2) % mod * modpow(fact(r), mod - 2) % mod;
}

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

template <typename T>
void greater_sort(vector<T>& vec) {
	sort(all(vec), greater<T>());
	return;
}

int k, a, b;
signed main() {
	cin >> k >> a >> b;
	k -= a - 1;
	cout << max(k + a, k / 2 * (b - a) + a + k % 2) << endl;
}

Measured memory_bytes: 256
A, B, C, K = map(int, input().split())

def mysum(A, B, C, K):
  if K <= A:
    return(K)
  
  if K <= A+B:
    return(A)
  
  return(A + -1 * (K-A-B))
 
print(mysum(A, B, C, K))

Measured memory_bytes: 9176
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
#define PI 3.141592653589
typedef pair<int,int> PP;
typedef long long ll;
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE do { cout << -1 << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl

signed main(void){
    int N;
    int A[1010][1010];
    cin >> N;
    REP(i,N){
        REP(j,N-1){
            cin >> A[i][j];
            A[i][j]--;
        }
    }
    //z=1000*i+j
    vector<int> G[1000000];
    int D[1000000]={};
    int E[1000000]={};
    REP(i,N){
        REP(j,N){
          	if(i>=j)continue;
            int z=1000*min(i,j)+max(i,j);
          	E[z]=-1;
        }
    }
  
  
    REP(i,N){
        REP(j,N-1){
            if(j==0)continue;
            //i vs A[i][j]
            int l = min(i,A[i][j-1]);
            int r = max(i,A[i][j-1]);
            int z1=1000*l+r;
            l = min(i,A[i][j]);
            r = max(i,A[i][j]);
            int z2=1000*l+r;
            D[z2]++;
            G[z1].push_back(z2);
            
            //cout << z1 MM z2 << endl;
        }
    }
    
    queue<int> Q;
    
    REP(i,N){
        REP(j,N){
          	if(i>=j)continue;
            int z=1000*min(i,j)+max(i,j);
            if(D[z]==0){
                Q.push(z);
                E[z]=1;
            }
        }
    }
    
    if(Q.empty()){
        GOODBYE;
    }
    
    while(!Q.empty()){
        int T=Q.front();
        Q.pop();
        REP(i,G[T].size()){
            int k=G[T][i];
            D[k]--;
            if(D[k]==0){
                Q.push(k);
                E[k]=E[T]+1;
            }
        }
    }
    
    int Ans=0;
    REP(i,N){
        REP(j,N){
          	if(i>=j)continue;
            int z=1000*min(i,j)+max(i,j);
          	if(E[z]==-1){
              GOODBYE;
            }
            Ans=max(Ans,E[z]);
        }
    }
    cout << Ans << endl;
  return 0;
}



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

#define ll long long
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

using namespace std;

int main() {
    string s;
    cin >> s;
    int i;
    int  maxS = 0;
    int leng = 0;
    for(i=0;i<s.length();i++) {
        leng = 0;
        while(i<s.length()) {
            if(s[i]=='A'||s[i]=='T'||s[i]=='C'||s[i]=='G') {
                leng++;
                i++;
            } else
                break;
        }
        maxS = (leng>maxS)?leng:maxS;
    }
    cout << maxS;
}


Measured memory_bytes: 256
N,M = map(int, input().split())
inpu = []
K = []
for i in range(N):
    A = input().split()
    for j in range(int(A[0])+1):
        A[j] = int(A[j])
    K.append(A[0])
    del A[0]
    inpu.append(A)
inpu

count = 0
for i in range(K[0]):
    flag = True
    for j in range(N-1):
        if(inpu[0][i] not in inpu[j+1]):
            flag = False
    if (flag == True):
        count = count + 1
print(count)

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

using namespace std;
using ll = long long;

using Field = vector<vector<int>>;
using Graph = vector<vector<int>>;
using VI = vector<int>;
using VC = vector<char>;
using PI = pair<int, int>;

#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(x) x.begin(), x.end()

const long long INF = 1LL<<60;
const int mod = 1000000007;

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; }

int N, K;
vector<int> a;
vector<vector<ll>> S;
vector<vector<ll>> dp;

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

    cin >> N >> K;
    a.resize(N);
    REP(i, N) cin >> a[i];

    dp.assign(N + 10, vector<ll>(K + 10, 0));
    S.assign(N + 10, vector<ll>(K + 10, 0));


    for (int i = 0; i < a[0] + 1; i++) {
        dp[0][i] = 1;
    }

    for(int i = 0; i < K + 1; i++) {
        S[0][i + 1] = S[0][i] + dp[0][i];
    }

    for (int i = 1; i < N; i++) {
        for (int j = 0; j <= K; j++) {
            if (j > a[i]) {
                dp[i][j] = (S[i - 1][j + 1] - S[i - 1][j - a[i]] + mod) % mod;
                dp[i][j] %= mod;
            } else {
                dp[i][j] = S[i - 1][j + 1];
                dp[i][j] %= mod;
            }
        }
        for (int j = 0; j <= K; j++) {
            S[i][j + 1] = S[i][j] + dp[i][j];
            S[i][j + 1] %= mod;
        }
    }

    cout << dp[N - 1][K] << endl;
    
    return 0;
}

Measured memory_bytes: 173296
/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   main.cpp                                           :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: monoue <marvin@student.42.fr>              +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2020/04/22 12:30:15 by monoue            #+#    #+#             */
/*   Updated: 2020/04/24 15:16:03 by monoue           ###   ########.fr       */
/*                                                                            */
/* ************************************************************************** */

#include <bits/stdc++.h>

/* #include <boost/multi_array.hpp> */
/* #include <boost/optional.hpp> */
/* #include <boost/range/irange.hpp> */
/* #include <boost/range/algorithm.hpp> */
/* #include <boost/range/adaptors.hpp> */
/* #include <boost/multiprecision/cpp_int.hpp> */
/* #include <boost/algorithm/string/classification.hpp> // is_any_of */
/* #include <boost/algorithm/string/split.hpp> */
/* #include <boost/algorithm/string/join.hpp> */
/* #include <boost/algorithm/string/replace.hpp> */
/* #include <boost/math/tools/minima.hpp> */
/* namespace adaptor = boost::adaptors; */
/* using boost::math::tools::brent_find_minima; */
/* using boost::irange; */
/* using boost::algorithm::join; */
/* using boost::algorithm::split; */
/* using boost::algorithm::replace_all; */
/* using boost::multiprecision::cpp_int; */

#define MOD 1e9+7;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = (n); i >= 0; --i)

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

// TOP
void	Main()
{
	int	n;
	cin >> n;
	vector<ll>	V(5);
	rep(i, n)
	{
		string	s;
		cin >> s;

		if (s.at(0) == 'M')
			V.at(0)++;
		if (s.at(0) == 'A')
			V.at(1)++;
		if (s.at(0) == 'R')
			V.at(2)++;
		if (s.at(0) == 'C')
			V.at(3)++;
		if (s.at(0) == 'H')
			V.at(4)++;
	}
	ll	sum;
	sum = 0;
	for (ll i = 0; i < 3; i++)
	{
		if (V.at(i) == 0)
			continue;
		for (ll j = i + 1; j < 4; j++)
		{
			if (V.at(j) == 0)
				continue;
			for (ll k = j + 1; k < 5; k++)
			{
				if (V.at(k) == 0)
					continue;
				sum += V.at(i) * V.at(j) * V.at(k);
			}
		}
	}
	cout << sum << endl;
}
// END

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


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <stack>
#include <queue>
#include <functional>
#include <limits.h>
using namespace std;

#define ll long long
#define ull unsigned long long
#define rep(i,N) for (int i=0;i<N;i++)

//変数
int N,D,X;
vector<int> A;

//解法
void solve() {

	int ans = X;
	rep(i, N) {
		ans += (D - 1) / A[i] + 1;
	}
	cout << ans;

	return;
}

int main() {
	//入力
	cin >> N >> D >> X;
	A.resize(N);
	rep(i, N) cin >> A[i];
	solve();
	cout << endl;
	return 0;
}


Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.NoSuchElementException;
import java.util.Collections;

public class Main {
	public static ArrayList<Integer> getLargePrime(int n, int k) {
		ArrayList<Integer> primes = new ArrayList<Integer>();
		ArrayList<Integer> result = new ArrayList<Integer>();
		primes.add(2);
		if(n < 2) result.add(2);
		int i = 3;
		while(true) {
			boolean isValid = true;
			for(int j=0; j<primes.size(); j++) {
				int e = primes.get(j);
				if(i % e == 0) {
					isValid = false;
					break;
				}
				if(i < e * e) break;
			}
			if(isValid) {
				primes.add(i);
				if(n < i) result.add(i);
			}
			if(k < result.size()) break;
			i += 2;
		}
		return result;
	}

	public static void main(String[] args) {
		FS r = new FS();
		while(true) {
			int n = r.nextInt();
			int p = r.nextInt();
			if(n==-1 && p==-1) break;
			ArrayList<Integer> ps = getLargePrime(n, p);
			ArrayList<Integer> re = new ArrayList<Integer>();
			for(int i=0; i<ps.size(); i++) {
				for(int j=i; j<ps.size(); j++) {
					re.add(ps.get(i)+ps.get(j));
				}
			}
			Collections.sort(re);
			System.out.println(re.get(p-1));
		}
	}

	// Read Class
	static class FS {
		private final InputStream in = System.in;
		private final byte[] buffer = new byte[1024];
		private int ptr = 0;
		private int buflen = 0;
		private boolean hasNextByte() {
			if (ptr < buflen) {
				return true;
			} else {
				ptr = 0;
				try {
					buflen = in.read(buffer);
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (buflen <= 0) {
					return false;
				}
			}
			return true;
		}

		private int readByte() { return hasNextByte() ? buffer[ptr++] : -1;}
		private boolean isPrintableChar(int c) {return 33 <= c && c <= 126;}
		private void skipUnprintable() {while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}

		public boolean hasNext() { skipUnprintable(); return hasNextByte();}
		public String next() {
			if (!hasNext()) throw new NoSuchElementException();
			StringBuilder sb = new StringBuilder();
			int b = readByte();
			while(isPrintableChar(b)) {
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}
		public int nextInt() {
			return (int)nextLong();
		}
		public long nextLong() {
			if (!hasNext()) throw new NoSuchElementException();
			long n = 0;
			boolean minus = false;
			int b = readByte();
			if (b == '-') {
				minus = true;
				b = readByte();
			}
			if (b < '0' || '9' < b) {
				throw new NumberFormatException();
			}
			while(true) {
				if ('0' <= b && b <= '9') {
					n *= 10;
					n += b - '0';
				} else if(b == -1 || !isPrintableChar(b)) {
					return minus ? -n : n;
				} else {
					throw new NumberFormatException();
				}
				b = readByte();
			}
		}
	}
}

Measured memory_bytes: 62848
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		long N = sc.nextLong();
		long a = 0;
		if( N%11<=6 && N%11>0 ){
			a = 1;
		}
		if( N%11>6 ){
			a = 2;
		}
		System.out.println(N/11*2+a);
	}
}


Measured memory_bytes: 23764
#include<stdio.h>

int main(){
int n,a,b,c;
  a=0; b=0; c=0;
  scanf("%d",&n);
  int s[n];
  for(int i=0;i<n;++i){
    scanf("%d",&s[i]);
   a+=s[i];
  }
  int A; A = a;
  int k =0;
while(b<A){
  b+=s[k];
  A -=s[k];
  ++k;
}
  int B; B =a;
  int l=1;
  while(c<B){
  c+=s[n-l];
    B -=s[n-l];
   ++l;
  }
int d,e;
 d = b-A;
 e = c-B;
 if(d<e)
   printf("%d",d);
  else
    printf("%d",e);

  
}

Measured memory_bytes: 128