akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <math.h>
using namespace std;

int main() {
	int a, b, result;
	cin >> a >> b;
	for (result = 0; result < 10000; ++result) {
		int ta = result * 0.08, tb = result * 0.1;
		if (ta == a && tb == b) {
			cout << result << endl;
			return 0;
		}
	}
	cout << -1 << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;

int main(){
  vector<string> day{"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
  string s;
  cin >> s;
  int num;
  rep(i, 7){
    if (s == day[i]){
      num = i;
    }
  }
  int ans = 7 - num;
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 3596
#include <iostream>
#include <string>
#include <stack>

using namespace std;



int main() {
	string str;
	
	while (getline(cin, str)) {
		if ((int)str.size() == 1 && str[0] == '.') break;
		int n = (int)str.size();
		
		stack<char> s;
		
		bool isok = true;
		for (int i=0; i<n && isok; i++) {
			if (str[i] == '(') {
				s.push(str[i]);
			} else if (str[i] == ')') {
				if (s.empty()) {
					isok = false;
					break;
				}
				char popc = s.top(); s.pop();
				if (popc != '(') isok = false;
			} else if (str[i] == '[') {
				s.push(str[i]);
			} else if (str[i] == ']') {
				if (s.empty()) {
					isok = false;
					break;
				}
				char popc = s.top(); s.pop();
				if (popc != '[') isok = false;
			}
		}
		
		if (!s.empty()) isok = false;
		
		if (isok) cout << "yes" << endl;
		else cout << "no" << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1172
#include<iostream>
#include<string>
using namespace std;
int main(){
	int a,b,c;
	cin>>a>>b>>c;
	
	if(a<b&&b<c&&a<c){
		cout<<"Yes"<<endl;
		} 
    else{
		cout<<"No"<<endl;
		}		
	return 0 ;
}
	 





Measured memory_bytes: 3092
#pragma GCC optimize("O3")

#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
tree<int,int,greater<int>,rb_tree_tag,tree_order_statistics_node_update> map_t;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for(int i = 0; i < (a); ++i)
#define sz(x) (int)x.size()
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
#define REV(x) reverse(x.begin(),x.end())
int dx[]={-1,0,1,0};
int dy[]={0,-1,0,1};
const ll INF=1e15;

int main() {
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n;
    cin >> n;
    n++;
    vector<ll> leaves(n),child(n);
    F0R(i,n)
        cin >> leaves[i];
    if(leaves[0]>1) {
        cout << -1;
        return 0;
    }
    if(leaves[0]==1) {
        if(n>1) cout << -1;
        else cout << 1;
        return 0;
    }
    child[0]=1;
    FOR(i,1,n) {
        child[i]=2*child[i-1]-leaves[i];
        if(2*child[i-1]>INF)
            child[i]=INF;
    }
    vector<ll> tot(n);
    tot[n-1]=leaves[n-1];
    for(int i=n-2; ~i; i--) {
        child[i]=min(child[i],tot[i+1]);
        if(child[i]<0) {
            cout << -1;
            return 0;
        }
        tot[i]=child[i]+leaves[i];
    }
    if(tot[0]>1) {
        cout << -1;
        return 0;
    }
    if(n-1<60 && tot[n-1]>(1LL<<(n-1))) {
        cout << -1;
        return 0;
    }
    FOR(i,1,n) {
        if(tot[i]<child[i-1] || tot[i]>2*child[i-1]) {
            cout << -1;
            return 0;
        }
    }
    ll res=0;
    F0R(i,n)
        res+=tot[i];
    cout << res;

    return 0;
}


Measured memory_bytes: 5592
#include <bits/stdc++.h>
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ThxDem=b;i<ThxDem;++i)
#define pb push_back
#define ALL(s) s.begin(),s.end()
#define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define SZ(n) ((int)(n).size())
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;

ll MOD=1e9+7, d, dp[10010][100][2];
string s;

ll solve(int pos, int m, bool low){
  if(pos == SZ(s)) return m==0;
  ll &r = dp[pos][m][low];
  if(r >= 0) return r;
  r = 0;
  ll top = low?10:(s[pos]-'0'+1), exp = SZ(s)-pos-1;
  fore(i,0,top) r = (r + solve(pos+1, (m+i)%d, low||i<(s[pos]-'0')))%MOD;
  return r;
}


int main(){FIN;
  memset(dp,-1,sizeof(dp));
  cin >> s >> d;
  cout << (solve(0,0,0)-1+MOD)%MOD << endl;
}

Measured memory_bytes: 16640
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>

using namespace std;

#define int long long
#define w first
#define v second

int N, W;

signed main()
{
	cin >> N >> W;
	vector<pair<int, int>> a;

	for (int i = 0; i < N; ++i) {
		int w, v; cin >> w >> v;
		a.push_back(make_pair(w, v));
	}

	sort(begin(a), end(a));

	vector<int> dp(W+5), tmp;

	for (int i = 0; i < N; ++i) {
		tmp = vector<int>(W+5);
		
		for (int j = 0; j <= W; ++j) {
			tmp[j] = max(tmp[j], dp[j]);
			if (j + a[i].w > W) break; // ←単調性を仮定していましたね…
			tmp[j + a[i].w] = max(dp[j + a[i].w], dp[j] + a[i].v);
		}

		dp = tmp;
	}

	int ans = 0;
	for (int i = 0; i <= W; ++i) ans = max(ans, dp[i]);

	cout << ans << endl;
}


Measured memory_bytes: 2656
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
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 ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main() {
    int n;
    cin >> n;
    int ans = 0;
    FOR(i,1,n){
        if (i % 2 == 0) continue;
        int x = 0;
        FOR(j,1,i){
            if (i % j == 0) x++;
        }
        if (x == 8) ans++;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <string.h>
#include <ctype.h>
#include <algorithm>

using namespace std;

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

  int sum = 0;
  for(int i = 0; i < n.size(); i++) {
    sum += n[i] - '0';
  }

  if(sum % 9 == 0)
    cout << "Yes" << endl;
  else cout << "No" << endl;
}

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

typedef long long ll;
typedef pair<int,int> P;
int dx[] = {-1, 1, 0,  0};
int dy[] = { 0, 0, 1, -1};

 
int main(){
  int ans = 0;
  string s;
  cin >> s;
  int cnt = 0;
  for(int i=0; i<s.length(); i++){
    if(s[i]=='A'||s[i]=='C'||s[i]=='G'||s[i]=='T'){
      cnt++;
      ans = max(ans, cnt);
    }
    else{
      ans = max(ans, cnt);
      cnt = 0;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3556
#include <bits/stdc++.h>
#define int long long
#define ll long long
using ull = unsigned long long;
using namespace std;
#define dump(x)                             \
    if (dbg) {                              \
        cerr << #x << " = " << (x) << endl; \
    }
#define overload4(_1, _2, _3, _4, name, ...) name
#define FOR1(n) for (ll i = 0; i < (n); ++i)
#define FOR2(i, n) for (ll i = 0; i < (n); ++i)
#define FOR3(i, a, b) for (ll i = (a); i < (b); ++i)
#define FOR4(i, a, b, c) for (ll i = (a); i < (b); i += (c))
#define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define FORR(i, a, b) for (int i = (a); i <= (b); ++i)
#define bit(n, k) ((n >> k) & 1) /*nのk bit目*/
namespace mydef {
const int INF = 1ll << 60;
const int MOD = 1e9 + 7;
template <class T>
bool chmin(T& a, const T& b) {
    if (a > b) {
        a = b;
        return 1;
    } else
        return 0;
}
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    } else
        return 0;
}
void Yes(bool flag = true) {
    if (flag)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}
void No(bool flag = true) {
    Yes(!flag);
}
void YES(bool flag = true) {
    if (flag)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}
void NO(bool flag = true) {
    YES(!flag);
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T& val) {
    std::fill((T*)array, (T*)(array + N), val);
}
bool dbg = false;
}  // namespace mydef
using namespace mydef;
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(), (v).end()
#define SZ(x) ((int)(x).size())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vp vector<pair<int, int>>
#define vvp vector<vector<pair<int, int>>>
#define pi pair<int, int>
//#define P pair<int, int>
//#define V vector<int>
//#define S set<int>
#define asn ans

int N, A[101010];
set<int> S[101010];

int f(int x) {
    vi V;
    for (auto& y : S[x])
        V.emplace_back(f(y));
    sort(all(V));
    int ret = 0;
    for (auto& y : V) {
        chmax(ret, y);
        ret++;
    }
    return ret;
}

void solve() {
    cout << f(0) << endl;
}

signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

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

    solve();
    return 0;
}


Measured memory_bytes: 23156
import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;

public class Main {
  public static void main(String[] args ){

    Scanner sc = new Scanner(System.in);

    int A = sc.nextInt();
    int B = sc.nextInt();

    int remainWidth = A - B * 2;
    System.out.println(remainWidth < 0 ? 0 : remainWidth);

  }
}


Measured memory_bytes: 23124
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define REP(i, n) for(i=0; i<n; i++)
#define REPR(i, n) for(i=n; i>=0; i--)
#define FOR(i, m, n) for(i=m; i<n; i++)
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define INF 1000000000
#define MOD 1000000007LL
#define MAX 100005
#define NIL -1
#define WHITE 0
#define GRAY 1
#define BLACK 2
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> doup;

int main(void) {
    ll x;
    cin >> x;
    ll ans;
    ans=x/11*2+(x%11>6 ? 2 : x%11>0 ? 1 : 0);
    cout << ans << endl;
}


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

int main() {
    string s;
    cin >> s;
    int a[4]={0};
    for(int i=0;i<s.size();i++){
        if(s[i]=='N') a[0]=1;
        if(s[i]=='W') a[1]=1;
        if(s[i]=='S') a[2]=1;
        if(s[i]=='E') a[3]=1;
    }

    if(a[0]==a[2] && a[1]==a[3]) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
int main() {
    string c;
    cin >> c;
    if (c[0] == c[1] && c[1] == c[2]) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
int main()
{
  
  int n;
  scanf("%d",&n);
  int flag=0;
  while(n!=0)
  {
      if(n%10==7)
         {
             flag=1;
             break;
         }
       n/=10;
  }
       
      if(flag==1)
          printf("Yes");
          
      else
         printf("No");
         
  
  
}

Measured memory_bytes: 3728
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>

using namespace std;
using ll = long long int;
#define rep(i,n) for(int i = 0; i < n; i++)
#define FOR(i, a, b)  for(int i = (a); i < (b) ; i++)
#define pb push_back
#define SORT(v,n) sort(v, v+n)
#define ALL(x) (x).begin(),(x).end()
#define debug(x) cerr << #x << ": " << x << '\n'
#define elif else if
#define itn ll
#define int ll
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 };
int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 };
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;


int f(int mx) {
	int n = 0;
	while (mx > 0) {
		mx /= 10;
		n++;
	}
	return n;
}

int n;
int ans = INF;

signed main() {
	ios::sync_with_stdio(false);
	cin >> n;
	int ans = f(n);
	for (int a = 1; a * a <= n; a++) {
		if (n % a != 0) continue;
		const int b = n / a;
		int cur = max(f(a), f(b));
		if (ans > cur) {
			ans = cur;
		}
	}
	cout << ans << '\n';
	return 0;
}

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


class Program
{
    public static long Read()
    {
        return long.Parse(Console.ReadLine());
    }

    public static long[] Reads()
    {
        return Console.ReadLine().Split().Select(long.Parse).ToArray();
    }



    public static void Main()
    {
        var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        Console.SetOut(sw);


        var input = Reads();
        var n = input[0];

        var input0 = Reads();
        var a = new long[n];
        var acon = new long[n];
        for (int i = 0; i < n; i++)
        {
            a[i] = input0[i];
            acon[a[i] - 1] = i+1;
        }
        for (int i = 0; i < n; i++)
        {

            Console.Write(acon[i]);
            Console.Write(" ");
        }


        Console.Out.Flush();
    }
}

Measured memory_bytes: 30684
import copy

h, w, x = map(int, input().split())
s = [[0 for j in range(w)] for i in range(h)]
for i in range(h):
    c = input()
    s[i] = list(map(int, c.replace('.','0 ').replace('#', '1 ').split()))

t = 0
for i in range(2**h):
    a = copy.deepcopy(s)
    for j in range(h):
        if ((i >> j) & 1):
            for k in range(w):
                a[j][k] = 0
    for j in range(2**w):
        b = copy.deepcopy(a)
        for k in range(w):
            if ((j >> k) & 1):
                for l in range(h):
                    b[l][k] = 0
        result = sum(map(sum, b))
        if x == result:
            t += 1

print(t)

Measured memory_bytes: 9188
n,m,x = map(int,input().split())
c = []
a = []
for i in range(n):
  ci,*ai = map(int,input().split())
  c.append(ci)
  a.append(ai)

INF = float('inf')
ans = INF
for i in range(1<<n):
  r = [0 for _ in range(m)]
  p = 0
  for j in range(n):
    if (i>>j)&1 == 1:
      p += c[j]
      for k in range(m):
        r[k] += a[j][k]
  f = True
  for ri in r:
    if ri < x:
      f = False
      break
  #print(p,r,f)
  if f:
    ans = min(p,ans)
print(ans if ans != INF else -1)

Measured memory_bytes: 68488
my $N =  <STDIN>;
chomp ($N);
my @A;
foreach (split(/ /o, <STDIN>)) {
  chomp($_);
  push(@A, $_) if ($_ ne '');
}
my $t = 0;
foreach my $a (@A) {
  $t += 1/$a;
}
print 1/$t;

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

int a,b,c;
std::string ans;

int main(){
  cin >> a >> b >> c;
  if(a < b){
    if(b < c){ ans = "Yes";} else{ ans = "No";}
    }
   else{ ans = "No";}
   
   cout << ans << endl;
   return 0;
   }

Measured memory_bytes: 3140
#include<iostream>
typedef long long ll;
using namespace std;
int main(){
  ll x,y,ans,be,af,tmp;
  cin >> x >> y;
  ans=1000000000000;
  for(int i=0;i<2;i++){
    for(int j=0;j<2;j++){
      be=x;
      af=y;
      be*=(i)?-1:1;
      af*=(j)?-1:1;
        tmp = af-be;
        if(tmp>=0){
          ans = min(ans,tmp+i+j);
        }
      }
    }
  cout << ans<<endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		int h, w, x, y;
		Scanner sca = new Scanner(System.in);
		
		h = sca.nextInt();
		w = sca.nextInt();
		x = sca.nextInt();
		y = sca.nextInt();
		
		System.out.println((h-x)*(w-y));
	}
}


Measured memory_bytes: 23636
h, w = map(int, input().split(' '))

dot = [input() for _ in range(h)]

shape = [[j if j == '#' else 0 for j in i] for i in dot]

for i in range(h):
    for j in range(w):
        if shape[i][j] != '#':
            for a in range(-1, 2):
                for b in range(-1, 2):
                    if 0 <= i + a < h and 0 <= j + b < w and shape[i + a][j + b] == '#':
                        shape[i][j] += 1


ans = []
for i in shape:
    ans.append(list(map(str, i)))

for i in ans:
    for j in i:
        print(j, end = '')
    print()

Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
int main() {
	string s;
	cin >> s;
	int x = 0;
	for (char c : s) {
		if (x == 0 && c == 'C') x = 1;
		else if (x == 1 && c == 'F') x = 2;
	}
	cout << (x == 2 ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include <iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include <cstring>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
#include <random>
#define inf  1000000000
#define mod  1073741824
#pragma GCC optimization ("O3")
using namespace std;
const long long int N = 6999999;
#define all(x) begin(x),end(x)
int main()
{
   
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    //ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  	int n,m,a,b,d,ans =0;
  	cin >> n >> m >> a >> b;
  	d = min(n,m);
  	ans = d*a; 
  	n -= m;
  	while(n > 0)
  	{
  		ans += b;
  		n--;
  	}
  	cout << ans;
  	return 0;
}	

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

const int MOD = 1e9 + 7;
const int INF32 = 1<<30;
const ll INF64 = 1LL<<60;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll x,y,a,b,c;
    cin >> x >> y >> a >> b >> c;
    vector<ll>red(a);
    vector<ll>green(b);
    deque<ll>nocolor(c);
    vector<ll>ans;
    for(int i = 0;i<a;i++) cin >> red[i];
    for(int i = 0;i<b;i++) cin >> green[i];
    for(int i = 0;i<c;i++){
        int z;cin >> z;
        nocolor.push_back(z);
    }
    nocolor.push_back(0);
    sort(red.rbegin(),red.rend());
    sort(green.rbegin(),green.rend());
    sort(nocolor.rbegin(),nocolor.rend());
    for(int i = 0;i<min(a,x);i++) ans.push_back(red[i]);
    for(int i = 0;i<min(b,y);i++) ans.push_back(green[i]);
    for(int i = ans.size();i<x+y;i++) {
            ans.push_back(nocolor.front());
            nocolor.pop_front();
    }
    sort(ans.begin(),ans.end());
    for(int i = 0;i<x+y;i++){
        if(nocolor.front()>ans[i]){
        ans[i] = nocolor.front();
        nocolor.pop_front();
    }
}
ll sum = 0;
for(int i = 0;i<x+y;i++) sum += ans[i];
cout << sum;
    return 0;
}

Measured memory_bytes: 8448
#pragma optimize("unroll-loops,no-stack-protector")
#include <bits/stdc++.h>
using namespace std;
// using namespace __gnu_pbds;
// #include <ext/pb_ds/assoc_container.hpp>
// typedef tree<int,null_type,less<int>,rb_tree_tag,
// tree_order_statistics_node_update> indexed_set;
#define f(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(ll i=a;i>=b;i--)
#define Max(a,b,c) max(a,max(b,c))
#define Min(a,b,c) min(a,min(b,c))
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define pc(x)  __builtin_popcount (x)
#define vl vector< ll >
#define sorts(v) sort(v.begin(),v.end())
#define sortg(v) sort(v.begin(),v.end(),greater<ll>())
#define ss second
#define ff first
#define ll long long
#define ld long double
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1e18)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod 1000000007
#define mem(x,y) memset(x,y,sizeof(x))
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >
#define flush fflush(stdout) 
#define gcd __gcd
#define primeDEN 727999983
#define nx_pe next_permutation(s.begin(),s.end())
#define cl cout<<"\n"
#define sp(x) setprecision(x)
const ll N=105,M=100005;
ll n,k;
ll a[N];
ll dp[N][M];
ll pre[N][M];
ll dp1[N][M];

void solve()
{
   cin>>n>>k;
   f(i,1,n+1)cin>>a[i];
   
   rep(i,n+1)dp[i][0]=1;
   rep(i,n+1)
   {
       pre[i][0]=dp[i][0];
   }
   f(j,1,k+1)
   {
       pre[0][j]=dp[0][j]%mod+pre[0][j-1]%mod;
       pre[0][j]%=mod;
   }
   f(i,1,n+1)
   {
       f(j,1,k+1)
       {
           ll x=min(a[i],j);
           ll sum=pre[i-1][j]%mod;
           if(j-x-1>=0)
           sum=sum%mod-pre[i-1][j-x-1]%mod+mod;
           sum%=mod;
           dp[i][j]=dp[i][j]%mod+sum%mod;
           dp[i][j]%=mod;
       }
       f(j,1,k+1)
       {
           pre[i][j]=pre[i][j-1]%mod+dp[i][j]%mod;
           pre[i][j]%=mod;
       }
   }

   cout<<dp[n][k];
   
}


    
int main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin) ;
    freopen("ouput.txt", "w", stdout) ;
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL) ; cout.tie(NULL) ;
    std::ios::sync_with_stdio(false);
    ll te=1;
    // cin>>te;
    while(te--){
        solve();
    }
    
}


Measured memory_bytes: 160620
#include <iostream>
#include <cmath>

int main()
{
	while (true) {
		int n;
		std::cin >> n;
		
		if (n==0) break;
		
		double* scores = new double[n];
		
		for (int i=0; i<n; i++) {
			std::cin >> scores[i];
		}
		
		double mean = 0.0;
		for (int i=0; i<n; i++) mean += scores[i];
		mean /= (double)n;
		
		double sdev = 0.0;
		for (int i=0; i<n; i++) sdev += (scores[i] - mean) * (scores[i] - mean);
		sdev /= (double)n;
		sdev = sqrt(sdev);
		
		std::cout << std::fixed << sdev << std::endl;
	}
	return 0;
}




Measured memory_bytes: 3256
N = int(input())
S = [input() for i in range(N)]
M = int(input())
T = [input() for i in range(M)]

dict = {}

for s in S:
    if s not in dict:
        dict[s] = 1
    else:
        dict[s] += 1

for t in T:
    if t not in dict:
        dict[t] = -1
    else:
        dict[t] -= 1

if max(dict.values()) <= 0:
    print(int(0))
else:
    print(max(dict.values()))

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

int main(){
 
  int F, L, C;
  cin >> F >> L;
  C = 0;
  
  for(int i = F; i <= L; i++){
    int TS = i / 10000;
    int S = (i % 10000) / 1000;
    int T = (i % 100) / 10;
    int I = i % 10;
    if(TS == I && S == T)
      C++;
  }
  
  cout << C << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define rep(i, n) for(int i=0; i<(n); i++)
#define FOR(i, m, n) for(int i=(m);i<(n);i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define RSORT(x) sort((x).rbegin(),(x).rend())
#define REVE(x) reverse((x).begin(),(x).end())
#define mp make_pair
#define pb push_back
#define chmax(x,y) x = max(x,y)

 
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<vector<int> > VVI;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<bool> VB;
typedef vector<LL> VL;
typedef vector<vector<long long>> VVLL;
typedef vector<set<int>> VSI;
const int MOD = 1e9+7;
const int INF = 1e9;
const LL LINF = 1e18;
int gcd(int a, int b)
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}

int lcm(int a, int b)
{
   return a * b / gcd(a, b);
}


int main() {
    char a;
    cin >> a;

    if(a >= 'a' and a <= 'z') {
        cout << 'a' << endl;
    } else {
        cout << 'A' << endl;
    }

}


Measured memory_bytes: 3632
#include <stdio.h>

int main()
{

 int a, b;
 char op;
 while(1)
 {

     scanf("%d %c %d\n", &a, &op, &b);
     if(op == '?') break;
     
     if(op == '+')
     {
         printf("%d\n", a + b);
     }
     else if(op == '-')
     {
         printf("%d\n", a - b);
     }
     else if(op == '*')
     {
         printf("%d\n", a * b);
     }
     else if(op == '/')
     {
         printf("%d\n", a / b);
     }

 }

 return 0; 

}

Measured memory_bytes: 604
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <fstream>
#include <iomanip>

typedef long long ll;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1e9 + 7;

template<class T> std::ostream& operator << (std::ostream& os, std::vector< T > v)
{
  ll i = 0;
  for (auto x : v) {os << " [" << i++ << "]" << x; if (i % 10 == 0) os << std::endl;}
  return os;
}

template<class T, class S> std::ostream& operator << (std::ostream& os, std::vector< std::pair<T, S> > vp)
{
  ll i = 0;
  for (auto p : vp) {os << " [" << i++ << "]" << p.first << " " << p.second; if (i % 10 == 0) os << std::endl;}
  return os;
}

void print(){ std::cout << std::endl; }
template<typename H> void print(H head) { std::cout << head << std::endl; }
template<typename H, typename... T> void print(H head, T... tail){ std::cout << head << " ", print(tail...); }

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

  ll a, b;
  std::cin >> a >> b;

  ll ans = (a > b) ? a - 1 : a;
  print(ans);

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define f(a,b,c) for(int a = b, _ = c; a < _; a++)
using namespace std;
typedef long long int lli;
typedef pair<int, int> pii;
#define mp make_pair
#define pb push_back
#define pp pop_back
#define fs first
#define sc second

int main(){
  #ifdef LOCAL_DEFINE
    freopen("input.txt", "rt", stdin);
    freopen("output.txt", "wt", stdout);
  #endif
  int n;
  cin >> n;
  int k;
  cin >> k;
  int ans = 0;
  for(int i = 0; i < n; i++){
    int a;
    cin >> a;
    ans += 2 * min(a, abs(k - a));
  }
  cout << ans;
  return 0;
}


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

int main(){
    int a,b ;
    cin >> a >> b ;
    if ((a+b) % 2 == 0)
    {
        cout << (a+b) / 2 << endl;
    }
    else
    {
        cout << "IMPOSSIBLE" << endl ;
    }
    
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
int main(){
    int n;
    cin >>n;
    vector<double> v(n);
    rep (i,n) cin>> v[i];
    priority_queue<double,vector<double>,greater<double>> q;
    rep(i,n) q.push(v[i]);
    bool flag=true;
    while(flag){
       double a = q.top();
       q.pop();
       double b = q.top();
       q.pop();
       q.push((a+b)/2);
       if (q.size()==1) flag=false; 
    }
    double ans =q.top();
    cout << ans <<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin >> N;
    vector<int> a(N,0);
    for(int i = 0;i < N;i++){
        cin >> a[i];
    }
    int sum,ans;
    ans = 400000000;
    for(int i = -100;i < 101;i++){
        sum = 0;
        for(int j = 0;j < N;j++){
            sum += (a[j]-i)*(a[j]-i);
        }
        if(sum < ans)ans = sum;
    }
    cout << ans << endl;
    //cin >> N;
}

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

int main() {
    string S; cin >> S;
    for(int i = 0; i < S.size(); ++i) {
        cout << 'x';
    }
    return 0;
}

// overflow
// corner cases


Measured memory_bytes: 256
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        if ((a * b) % 2 == 0)
            System.out.println("Even");
        else
            System.out.println("Odd");
    }
}

Measured memory_bytes: 20948
#include<bits/stdc++.h>
using namespace std;
#define FasterIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
typedef unsigned long long ull;
typedef long long ll;
typedef double db;

#define mem(a,x) memset(a,x,sizeof(a))
#define pb push_back
#define ff first
#define ss second
#define mk make_pair
#define pi pair<int,int>
#define vi vector<int>
#define pL pair<ll,ll>
#define vL vector<ll>
#define vp vector<pi>
#define vpL vector<pL>

const int MX=1000000;
const ll inf=1e9;
const ll mod=998244353;


ll mat[505][505], row[MX];

int main()
{
    FasterIO;

    string s;
    cin>>s;
    if(s[0]=='7' || s[1]=='7' || s[2]=='7') cout<<"Yes"<<endl;
    else  cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 3640
#include<stdio.h>
int main(void)
{
	int n,m,d,i,j,k,flg,x;
	char c[100][101];
	scanf("%d %d %d",&n,&m,&d);
	for(i=0;i<n;i++){
		scanf("%s",c[i]);

	}
	x=0;
	for(i=0;i<n;i++){
		for(j=0;j<m;j++){
			flg=1;
			for(k=0;k<d;k++){
				if(c[i][k+j]!='.'||k+j>=m){
					flg=0;
					break;
				}
			}
			if(flg==1){
				x++;
			}
		}
	}
	
	for(i=0;i<n;i++){
		for(j=0;j<m;j++){
			flg=1;
			for(k=0;k<d;k++){
				if(c[k+i][j]!='.'||k+i>=n){
					flg=0;
					break;
				}
			}
			if(flg==1){
				x++;
			}
		}
	}
	printf("%d\n",x);
	return 0;
}


Measured memory_bytes: 2072
/*input
8
-406 10
512 859
494 362
-955 -475
128 553
-986 -885
763 77
449 310
*/
#include<bits/stdc++.h> 
using namespace std;
long double find(int n){
    long double res = 1;
    for(int i=2;i<=n;i++)
        res = res*i;
    return res;
}

int main(){
    int n;
    cin >> n;
    vector<pair<int,int>> vpp;
    vector<int> points;
    for(int i=0;i<n;i++){
        int x,y;
        cin >> x >> y;
        vpp.push_back({x,y});
        points.push_back(i);
    }
    long double ans = 0;
    do{
        long double sum = 0;
        for(int i=1;i<n;i++){
            long double first = (vpp[points[i]].first-vpp[points[i-1]].first);
            first = first*first;
            long double second = (vpp[points[i]].second-vpp[points[i-1]].second);
            second *= second;
            sum += sqrtl(first+second);
            // ans += 
        }
        ans += sum;
        // for(auto it: points)
        //     cout << it+1 << " ";
        // cout << "\n";
    }while(next_permutation(points.begin(), points.end()));
    cout << fixed;
    cout << setprecision(20);
    long double mm = find(n);
    cout << ans/mm << "\n";

}

Measured memory_bytes: 256
import * as fs from 'fs';

namespace AtCoder.abc163 {

    export class Program {

        constructor(private readonly args: string[]) {
        }

        /**
         * in
         *
         * out
         *
         */
        main(this: Program): void {
            const r :number = parseInt(this.args[0],10);
            console.log((r*2)*Math.PI);
        }
    }
}

const args = fs.readFileSync('/dev/stdin', 'utf8').trim().split('\n');
const prg: AtCoder.abc163.Program = new AtCoder.abc163.Program(args);
prg.main();


Measured memory_bytes: 29660
#include <bits/stdc++.h>
using namespace std;
#define lo long
const int lmax=1999999999;
const long long lmx=1999999999999999999;
int n,t,C=lmax;
int c[100003],tt[100003];
int main(){std::ios::sync_with_stdio(false);
cin>>n>>t;
for(int i=0;i<n;i++)
{
	cin>>c[i]>>tt[i];
	if(t>=tt[i])
	{
		C=min(C,c[i]);
	}
}
if(C!=lmax)
cout<<C<<endl;
else
{
	cout<<"TLE"<<endl;
}
}
/*

                   *         *
                  * *       * *
                 *   *     *   *
                *     *   *     *
               *       * *       *
               *        *        *
                *               *
                 *             *
                  *           *
                   *         *
                    *       *
                     *     *
                      *   *
                       * *
                        *



*/





Measured memory_bytes: 256
#include <stdio.h>

 int main(void){
     int i,len,c,sum=0;

     scanf("%d %d %d",&i,&len,&c);

     for( ; i<=len; i++){
         if(c%i == 0){
             sum += 1;
         }
     }

     printf("%d\n",sum);

     return 0;
 }


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

X=[]
Y=[]
for _ in range(N):
    x, y = map(int, input().split())
    X.append(x)
    Y.append(y)
    
A="No"
for n in range(N-2):
    if X[n]==Y[n]:
        if X[n+1]==Y[n+1]:
            if X[n+2]==Y[n+2]:
                A="Yes"
                break
            else:
                continue
        else:
            continue
    else:
        continue
print(A)

Measured memory_bytes: 9116
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#include<map>
#include<vector>
using namespace std;
const int MaxN = 1e5;

int a[2 * MaxN + 5],ans[2 * MaxN + 5];

int main()
{
	int n,cnt,sum;
	while(~scanf("%d",&n))
	{
		for(int i = 1;i <= n;i++) 
		{
			scanf("%d",&a[i]);
			ans[i] = 0;
		}
		for(int i = 1;i <= n;i++)
		{
			ans[a[i]] = ans[a[i] - 1] + 1;
		}
		sort(ans + 1,ans + 1 + n);
		printf("%d\n",n - ans[n]);
	}
	return 0;
}

Measured memory_bytes: 1664
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
using namespace std;
typedef long long int ll;

int main(){
	int N;
	cin >> N;
	int ans = 1000000000;
	for(int i = 0; i <= N; i++){
		int a = i, b = N - i;
		int num = 0;
		while(a > 0){
			num += a % 6;
			a /= 6;
		}
		while(b > 0){
			num += b % 9;
			b /= 9;
		}
		ans = min(ans, num);
	}
	cout << ans << endl;
	return 0;
}


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

int main() {
	double x1, x2, x3, y1, y2, y3, a, b, c, M, S, r, X;
	cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
	a = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
	a = sqrt(a);
	b = (x2 - x3) * (x2 - x3) + (y2 - y3) * (y2 - y3);
	b= sqrt(b);
	c = (x3 - x1) * (x3 - x1) + (y3 - y1) * (y3 - y1);
	c = sqrt(c);
	S = 0.25 * sqrt((a + b + c) * (-a + b + c) * (a - b + c) * (a + b - c));
	r = 2 * S / (a + b + c);
	M = max(max(a, b), c);
	X = 2 / M + 1 / r;
	X = 1 / X;
	printf("%.12f", X);
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
using ll = int64_t;
#define rep(i, j, n) for (int i = j; i < (int)n; ++i)

constexpr ll MOD = 1000000007;

int main() {
  ll n;
  cin >> n;
  ll a;

  vector<ll> one(60);
  rep(i, 0, n) {
    cin >> a;
    rep(j, 0, 60) if (a >> j & 1) one[j]++;
  }

  ll ans = 0;
  rep(i, 0, 60) ans =
    (ans + (1ll << i) % MOD * one[i] % MOD * (n - one[i]) % MOD) % MOD;

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


Measured memory_bytes: 3644
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<sstream>
#include<string>
#include<string.h>
#include<cmath>
#include<stack>
#include<vector>
#include<map>
#define E (2.71828182)
#define PI (3.1415926535898)
#define	mem(a,b)	memset(a,b,sizeof(a))
#define	_max(a,b,c)	(max(a,b)>c?max(a,b):c)
#define mod	1000000007
#include<set>
#define gc getchar
#define debug(a) cout << "*" << a << "*" << endl
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<float, int> P;
const int N = 200000;
const long long  MAX_V = 5005, INF = 2147483647, MOD = 998244353;
#include <iostream>
using namespace std;
int q, f, op, st = N, se;
char a[500005], c;
int main()
{
	scanf("%s", a + st);
	scanf("%d", &q);
	se = strlen(a + st) + st;
	st--;
	for (int i = 0; i < q; i++)
	{
		scanf("%d", &f);
		if (f == 1)
		{
			swap(st, se);
		}
		else
		{
			scanf("%d %c", &op, &c);
			if (op == 1)
			{
				if (st < se)
				a[st--] = c;
				else
				a[st++] = c;
			}
			else
			{
				if (st < se)
				a[se++] = c;
				else
				a[se--] = c;
			}
		}
	}
	if (st < se)
		for (int i = st + 1; i < se; i++)
		{
			printf("%c", a[i]);
		}
	else
		for (int i = st - 1; i > se; i--)
		{
			printf("%c", a[i]);
		}
}

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

using namespace std;

int n;
long long dp[3100][3100];

int main()
{
  cin >> n;
  for (int l = 0; l < n; l++) {
    cin >> dp[l][l+1];
  }

  for (int l = n-2; l >= 0; l--) {
    for (int r = l+2; r <= n; r++) {
      dp[l][r] = max(dp[l][l+1]-dp[l+1][r], dp[r-1][r]-dp[l][r-1]);
    }
  }

  cout << dp[0][n] << endl;
  return 0;
}

Measured memory_bytes: 73984
class union_find:
    def __init__(self, n):
        self.par = [i for i in range(n)]
        self.rank = [0 for _ in range(n)]
        
    def root(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.root(self.par[x])
            return self.par[x]
            
    def same(self, x, y):
        return self.root(x) == self.root(y)
        
    def unite(self, x, y):
        x, y = self.root(x), self.root(y)
        if x != y:
            if self.rank[x] < self.rank[y]:
                self.par[x] = y
            else:
                self.par[y] = x
                if self.rank[x] == self.rank[y]:
                    self.rank[x] += 1

N, Q = map(int, input().split())
uf = union_find(N)
for i in range(Q):
    t, u, v = map(int, input().split())
    if t:
        print(int(uf.same(u, v)))
    else:
        uf.unite(u, v)

Measured memory_bytes: 18064
#include<map>
#include<set>
#include<bitset>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<chrono>
#include<stack>
#include<fstream>
#include<math.h>
#include<list>
#include<complex>
#define REP(i,x,y) for(ll i=x;i<=y;i++)
#define SIZE(a) ll(a.size())
#define vll vector<ll>
#define vvll vector<vector<ll>>
#define vtype(type) vector<type>
#define vvtype(type) vector<vector<type>>
#define MEMSET(a, n, m) for(ll i=0;i<=n;i++) a[i] = m
#define BIT(n) (ll(1)<<n)
#define UNIQUE(v) v.erase(unique(v.begin(),v.end()),v.end()) 
#define UNIQUE_ARRAY(a,x) unique(a + 1, a + x + 1) - a - 1
#define SORT(a,n) sort(a+1,a+n+1)
#define SORT_O(a,n,order) sort(a+1,a+n+1,order)
#define PER(i,y,x) for(ll i=y;i>=x;i--)
typedef long long ll;
using namespace std;
struct wall
{
	long long r; ll c;
	bool operator<(const wall& rhs) const {
		if (r != rhs.r) {
			return r < rhs.r;
		}
		else {
			return c < rhs.c;
		}
	}
};



ll const MOD = 998244353;
ll mod_p(ll x, ll y) {
	//x %= MOD;
	//y %= MOD;
	return (x + y + MOD) % MOD;
}

ll mod_m(ll x, ll y) {
	x %= MOD;
	y %= MOD;
	return x * y%MOD;
}

ll mod_pow(ll x, ll t) {
	x %= MOD;
	if (t == 0) {
		return 1;
	}
	else {
		ll v = mod_pow(x, t / 2);
		if (t % 2 == 0) {
			return v * v % MOD;
		}
		else {
			return v * v%MOD * x %MOD;
		}
	}
}

ll mod_inv(ll x) {
	return mod_pow(x, MOD - 2);
}

vll fct(1e7 + 5);
vll fct_inv(1e7 + 5);

void fct_init() {
	fct[0] = fct_inv[0] = 1;
	REP(i, 1, 1e6) {
		fct[i] = mod_m(fct[i - 1], i);
		fct_inv[i] = mod_inv(fct[i]);
	}
}

ll c(ll n, ll r) {
	return mod_m(fct[n], mod_m(fct_inv[r], fct_inv[n - r]));
}

ll h(ll n, ll r) {
	return c(n - 1 + r, r - 1);
	
}

ll f(ll n, ll k, ll t, ll x) {
	ll ans = 0;
	ll sign = 1;
	REP(i, 0, x) {
		ll tmp = 0;
		if (n - 2 * i < 0) {
			break;
		}
	//	cout << "h " << h(n - 2 * i, k) << " " << c(x, i) << endl;
		tmp = mod_m(h(n - 2 * i, k), c(x, i));
		ans = mod_p(ans, sign*tmp);
		sign *= -1;
		//cout << ans << "?" << endl;
	}
	return ans;
}


int main() {
	ll n, k;
	cin >> k >> n;
	if (k == 1) {
		cout << 0 << endl;
		return 0;
	}
	fct_init();
	REP(t, 2, 2 * k) {
		ll x = 0;
		REP(i, 1, t) {
			ll j = t - i;
			if (i < j && j <= k) {
				x++;
			}
			if (i >= j) break;
		}
		//cout << x << "!" << endl;
		if (t % 2 == 1) {
			ll ans = f(n, k, t, x);
			cout << ans << endl;
		}
		else {
			ll u = f(n, k - 1, t, x);
			ll v = f(n - 1, k - 1, t, x);
			ll ans = mod_p(u, v);
			cout << ans << endl;
		}
	}
}

Measured memory_bytes: 156672
use proconio::input;

fn main() {
    input! {
        n: usize,
        w: usize,
        v: [(usize, i64); n]
    };
    let mut dp = vec![0; w+1];
    for &p in &v {
        for i in (p.0..=w).rev() {
            dp[i] = dp[i].max(dp[i-p.0] + p.1);
        }
    }
    println!("{}", dp[w]);
}


Measured memory_bytes: 2880
//GODLEON'S CODE
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;

#define ff                first
#define ss                second
#define int        	  long long
#define ll                long long
#define ddouble           long double  
#define pb 		  push_back
#define mp 		  make_pair
#define pii               pair<int , int>
#define vi                vector<int>
#define mii               map<int,int>
#define gsort             greater<int>
#define pqb               priority_queue<int>
#define pqs               priority_queue<int , vi , greater<int>>
#define setbits(x)        _builtin_popcountll(x)
#define zrobits(x)        _builtin_ctzll(x)
#define mod               1000000007
#define mod1              mod
#define mod2              1000000009
#define inf               1e18
#define ps(x,y)           fixed<<setprecision(y)<<x
#define mk(arr,n,type)    type *arr = new type[n] ;
#define test(t)           int t ; cin >> t ; while(t--)
#define ifor(a,b)         for(int i = a ; i < b ; i++)
#define dfor(a,b)         for(int i = b-1 ; i >= a ; i--)
#define fio               ios_base::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0) ;
mt19937                   rng(chrono::steady_clock::now().time_since_epoch().count());


// check odd even : n & 1
// check power of 2 : n & n - 1 == 0
//flip xor
//set or
//unset and
//for -ve no.s mod ( a % mod + mod ) % mod ; 

int32_t main()
{
int n , k ;
cin >> n >> k ;
int dpcost[n] = {0};
vector<int>h(n);
for(int i = 0 ; i < n ; i++)
{
    cin >> h[i];
}
for(int i = 1 ; i < n ; i++)
{
    int minimum = INT_MAX;
    for(int j = i-1 ; j >= 0 && j >= i-k; j--)
    {
        minimum = min(dpcost[j] + abs(h[j] - h[i]) , minimum);
    }
    dpcost[i] = minimum ;
}
cout << dpcost[n-1] << endl;
}


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

int main(){
    int n;
    string s;

    cin >> n;
    cin >> s;

    rep(i, s.size()) {
        int x = s[i] - 'A';
        x = (x+n)%26;
        s[i] = 'A' + x;
    }

    cout << s << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
 
int main(void){
 
  double x1, y1, x2, y2;
  double result;
 
  scanf("%lf %lf %lf %lf", &x1, &y1, &x2, &y2);
  result = sqrt ((x1 - x2)*(x1 - x2) +  (y1 - y2)*(y1 - y2));
  printf ("%lf\n", result);
 
  return 0;
 
}


Measured memory_bytes: 2048
N = int(input())
S = []
for _ in range(N):
    S.append(input()) 
a = S.count('AC')
b = S.count('WA')
c = S.count('TLE')
d = S.count('RE')
print ('AC x' +' ' + str(a))
print('WA x' + ' '+ str(b))
print('TLE x' +' ' + str(c))
print('RE x' + ' '+ str(d))

Measured memory_bytes: 16224
#include<iostream>
#include<map>
#include<vector>
#include<algorithm>

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FUNCTION__ << endl;
#define int long long

using namespace std;

signed main(){
    int r, g, b;
    cin >> r >> g >> b;
    cout << (((r * 100 + g * 10+ b) % 4 == 0)? "YES" : "NO");
    return 0;
}


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

#define rep(i,n)   for(int i=0;i<n;++i)
#define F          first
#define S          second
#define PB         push_back
#define INF        ( 1 << 20 )

using namespace std;

struct state
{
	int x[2], y[2]; // left, right
	int lr; // どっちの足を着いているか
	int cost;

	bool operator< (const state &s) const { return cost > s.cost; }
};

// 右足を動かせる範囲（左足の場合はx符号反転）
int ad[9][2] =
{
	{ 1, 2 }, { 1, 1 }, { 1, 0 }, { 1, -1 }, { 1, -2 },
	{ 2, 1 }, { 2, 0 }, { 2, -1 },
	{ 3, 0 },
};

int sign[2] = { -1, 1 };

int W,H;
vector< pair<int, int> > ss;
vector< pair<int, int> > ts;
int costs[61][31];
bool det[2][61][31];

bool ok(int x, int y)
{
	return 0 <= x && x < W && 0 <= y && y < H;
}

int main()
{
	while(cin>>W>>H,W|H)
	{
		ss.clear();
		ts.clear();

		rep(y,H)rep(x,W)
		{
			char c;
			cin>>c;
			switch (c)
			{
			case 'S':
				costs[y][x] = 0;
				ss.PB(make_pair(x, y));
				break;
			case 'T':
				costs[y][x] = 0;
				ts.PB(make_pair(x, y));
				break;
			case 'X':
				costs[y][x] = INF;
				break;
			default:
				costs[y][x] = c - '0';
				break;
			}
			det[0][y][x] = det[1][y][x] = false;
		}

		priority_queue<state> Q;
		rep(i,ss.size())
		{
			pair<int, int> pt = ss[i];
			state init;
			init.cost = 0;
			rep(d,2)
			{
				init.x[d] = pt.F;
				init.y[d] = pt.S;
				init.lr = d;
				Q.push(init);
			}
		}

		int mincost = INF;
		while (!Q.empty())
		{
			state s = Q.top();
			Q.pop();

			int x0 = s.x[s.lr], y0 = s.y[s.lr];
			if (det[s.lr][y0][x0]) continue;
			det[s.lr][y0][x0] = true;

			rep(i,ts.size())
			{
				pair<int, int> p = ts[i];
				if (x0 == p.F && y0 == p.S)
				{
					mincost = min(mincost, s.cost);
					//break;
				}
			}

			rep(i,9)
			{
				int lr = 1 - s.lr; // 動かす足
				int x1 = x0 + sign[lr] * ad[i][0], y1 = y0 + ad[i][1];
				if (ok(x1, y1) && !det[lr][y1][x1])
				{
					state s1;
					s1.cost = s.cost + costs[y1][x1];
					s1.x[lr] = x1;
					s1.y[lr] = y1;
					s1.lr = lr;
					Q.push(s1);
				}
			}
		}
		cout << (mincost == INF ? -1 : mincost) << endl;
	}
	return 0;
}

Measured memory_bytes: 1264
#include<stdio.h>
#include<string.h>
#define fo(i,a,b) for(int i=a;i<=b;i++)
char S[220000],T[220000],c[500];
bool b[500];
int n;
int main(){
	scanf("%s%s",S+1,T+1);
	n=strlen(S+1);
	fo(i,1,n) if (!c[S[i]]){
		if (b[T[i]]){
			printf("No\n");
			return 0;
		}
		b[T[i]]=1;
		c[S[i]]=T[i];
	}else if (c[S[i]]!=T[i]){
		printf("No\n");
		return 0;
	}
	printf("Yes\n");
	return 0;
}

Measured memory_bytes: 512
/**
 *   @FileName	b.cpp
 *   @Author	kanpurin
 *   @Created	2020.09.19 21:03:02
**/

#include "bits/stdc++.h" 
using namespace std; 
typedef long long ll;

int main() {
    int n;cin >> n;
    int cnt = 0;
    for (int i = 0; i < n; i++) {
        int a,b;cin >> a >> b;
        if (a == b) cnt++;
        else cnt = 0;
        if (cnt == 3) {
            puts("Yes");
            return 0;
        }
    }
    puts("No");
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
    string N;
    while ( cin >> N, N != "0000" ) {
        int cnt = 0;
        set < string > st;
 
        while ( N != "6174" && st.find(N) == st.end() ) {
            string L = N, S = N;
            int val = 0;
            st.insert(N);
            sort(rbegin(L), rend(L));
            sort(begin(S), end(S));
            val = atoi(L.c_str()) - atoi(S.c_str());
            N = to_string(val);
            while ( N.size() < 4 ) {
                N = '0' + N;
            }
            cnt++;
        }
 
        if ( N == "6174" ) {
            cout << cnt << endl;
        } else {
            cout << "NA" << endl;
        }
    }
 
    return ( 0 );
}


Measured memory_bytes: 3224
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
using namespace std;
using ll = long long;

constexpr int P = 1000000007;

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

    int n;
    cin >> n;

    int p[60] = {};

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

        for (int k = 0; k < 60; k++) {
            if (a >> k & 1) p[k]++;
        }
    }

    ll r = 0;
    for (int k = 0; k < 60; k++) {
        r += (1LL << k) % P * p[k] % P * (n - p[k]) % P;
    }
    r %= P;

    cout << r << endl;

    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
B - Maximum Sum
https://abc096.contest.atcoder.jp/tasks/abc096_b

"""
import sys
from sys import stdin
input = stdin.readline


def calc_sum(a, b, c, k):
    m = max(a, b, c)
    ans = sum([a, b, c])
    ans -= m
    for _ in range(k):
        m *= 2
    ans += m
    return ans


def main(args):
    a, b, c = map(int, input().split())
    k = int(input())
    ans = calc_sum(a, b, c, k)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])


Measured memory_bytes: 3064