akhauriyash/Code-Regression huggingface dataset:
/*
LANG:C++
PROB:

*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
#include <iostream>
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)


using namespace __gnu_pbds;
using namespace std;


typedef tree<int, null_type, less<int>, rb_tree_tag,
            tree_order_statistics_node_update>
    ordered_set;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;
typedef unsigned long long ui64;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }
const int mod=1000000007;
  i64 poww(i64 a, i64 b)
  {
    a%=mod;
    i64 res=1;
    while(b)
      {
if(b&1)res=res*a%mod;

      a=a*a%mod;
      b/=2;

      }
      return res;
  }
  i64 inv(i64 a)
  {
    return poww(a,mod-2);
  }


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

    // ifstream fin(".in");
    // ofstream fout(".in");

char ch;
cin>>ch;
if(ch>='A'&&ch<='Z')cout<<"A";
else cout<<"a";


    return 0;
  }


Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std ;
#define ll long long
#define ld long double
#define ff first
#define ss second
const ll mod =   1e9 + 7 ;
ll multiply(ll a, ll b ){ return ((a % mod) * (b % mod)) % mod; }
ll add(ll a, ll b) {     return ((a % mod) + (b % mod)) % mod; }
ll sub(ll a, ll b) { return ((a%mod) - (b % mod)+ mod) % mod ; }
////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////
void solve(){
  int n ;
  cin >> n ;
  int ac = 0 , tle = 0 ,  re = 0 ,  wa = 0 ;
  for( int i = 0 ; i < n ; i++){
    string s ;
    cin >> s ;
    if(s=="AC"){
        ac++;
    }
    if(s[0]=='T')
        tle++;
    if(s[0]=='R')
        re++;
    if(s[0]=='W')
        wa++;
  }
  cout << "AC x " << ac << "\n";
  cout << "WA x " << wa << "\n";
  cout << "TLE x " << tle << "\n";
  cout << "RE x " << re << "\n";

}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t = 1 ;
    //cin >> t ;
    while(t--){
        solve( );
    }
}




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

int main(){
    int n, m;
    cin >> n >> m;
    vector<long long> h(n);
    for(int i = 0; i < n; i++){
        cin >> h[i];
    }
    // vector<long long> a(m), b(m);
    // for(long long i = 0; i < m; i++){
    //     cin >> a[i] >> b[i];
    // }
    vector<vector<int>> way(n,vector<int>());
    for(int i = 0; i < m; i++){
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        way[a].push_back(b);
        way[b].push_back(a);
    }
    
    vector<int> isGoodPlace(n, -1);
    for(int i = 0; i < n; i++){
        if(isGoodPlace[i] != -1){
            continue;
        }
        int height = h[i];
        for(auto x:way[i]){
            int height2 = h[x];
            if(height > height2){
                isGoodPlace[x] = 0;
            }
            else{
                isGoodPlace[i] = 0;
            }
        }
    }

    int ans = 0;
    for(auto x:isGoodPlace){
        if(x == -1){
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 9544
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=200003,INF=1<<30;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    string S;cin>>S;
    if(S[0]=='7'||S[1]=='7'||S[2]=='7') cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


Measured memory_bytes: 3648
using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Http.Headers;

namespace AtCoder
{
	public class ABC
	{
		static public void Main(string[] args)
		{
			Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
			Solve(args);
			Console.Out.Flush();
		}

		const int mod = 1000000007;  // 10^9+7
		static int Mod(long x, int m) { return (int)((x % m + m) % m); }
		static long Mod(long x, long m) { return (x % m + m) % m; }

		static public void Solve(string[] args)
		{
			//string s = Console.ReadLine();
			//int n = int.Parse(Console.ReadLine());
			//long x = long.Parse(Console.ReadLine());
			//int[] vs = Console.ReadLine().Split().Select(int.Parse).ToArray();
			//long[] vs = Console.ReadLine().Split().Select(long.Parse).ToArray();

			int[] vs = Console.ReadLine().Split().Select(int.Parse).ToArray();

			int d = vs[0];
			int t = vs[1];
			int s = vs[2];

			if (d <= t * s) {
				Console.WriteLine("Yes");
			} else {
				Console.WriteLine("No");
			}

		}
	}
}


Measured memory_bytes: 28144
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll MOD = 1e9 + 7;
// dp[i][j] = 和がiになるj項の数列ですべての項が3以上になるものの数
ll dp[2001][667] = {};
int main()
{
    int s;
    cin >> s;
    for(int i=3; i<=s; ++i){
        dp[i][1] = 1;
    }
    for(int j=2; j*3<=s; ++j){
        for(int i=3; i<=s; ++i){
            // dp[i][j] = \sum_{k>=3} dp[i-k][j-1]
            // = dp[i-3][j-1] + \sum_{k>=4} dp[i-k][j-1]
            // = dp[i-3][j-1] + \sum_{k>=3} dp[i-1-k][j-1]
            // = dp[i-3][j-1] + dp[i-1][j]
            dp[i][j] = (dp[i-3][j-1] + dp[i-1][j]) % MOD;
        }
    }
    ll ans = 0;
    for(int j=0; 3*j<=s; ++j)ans=(ans + dp[s][j]) % MOD;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 13972
/*  -*- coding: utf-8 -*-
 *
 * b.cc: B - Go to Jail
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

/* typedef */

/* global variables */

/* subroutines */

/* main */

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

  int c = 0;
  for (int i = 0; i < n; i++) {
    int d0, d1;
    scanf("%d%d", &d0, &d1);
    if (d0 == d1) {
      if (++c >= 3) {
	puts("Yes");
	return 0;
      }
    }
    else
      c = 0;
  }

  puts("No");
  return 0;
}


Measured memory_bytes: 3712
#include <stdio.h>
#include <vector>
#include <iostream>
#include <queue>
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<vs> vvs;

typedef vector<pair<int, int>> vpi;
typedef vector<tuple<int, int, int>> vti;


int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    int n, i;
    cin >> n;
    vpi a(n);
    for (i=0;i<n;i++) {
        int j;
        cin >> j;
        a[i] = make_pair(j, i);
    }
    sort(a.begin(), a.end());
    for (auto ans: a) cout << ans.second + 1 << endl;
}


Measured memory_bytes: 1664
#include "bits/stdc++.h"
#define int long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(obj) begin(obj), end(obj)
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define SQR(x) (x) * (x)
#define itn int

using namespace std;
using ll      = long long;
const int MOD = (int)(1e9 + 7);
const int INF = (int)(1e13 + 7);
template <typename A, size_t N, typename T>
void FILL(A (&array)[N], const T &val) {
  std::fill((T *)array, (T *)(array + N), val);
}

class UnionFind {
public:
  vector<int> _par;
  vector<int> _size;
  UnionFind(int sz_) : _par(sz_), _size(sz_, 1LL) {
    for (int i = 0; i < sz_; i++) _par[i] += i;
  }
  void init(int sz_) {
    _par.resize(sz_);
    _size.assign(sz_, 1LL);
    for (int i = 0; i < sz_; i++) _par[i] = i;
  }
  int root(int x) {
    while (_par[x] != x) {
      x = _par[x] = _par[_par[x]];
    }
    return x;
  }
  bool unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) return false;
    if (_size[x] < _size[y]) swap(x, y);
    _size[x] += _size[y];
    _par[y] = x;
    return true;
  }
  bool same(int x, int y) {
    return root(x) == root(y);
  }
  int size(int x) {
    return _size[root(x)];
  }
};

signed main() {
  int n, q;
  cin >> n >> q;
  int query, x, y;
  UnionFind Uf(n);
  REP(_, q) {
    cin >> query >> x >> y;
    if (query == 0) {
      Uf.unite(x, y);
    } else {
      cout << (Uf.same(x, y) ? 1 : 0) << endl;
    }
  }
}



Measured memory_bytes: 3220
#include<cstdio>
#include<iostream>
#include<string>
#include<cstring>
#include<cmath>
#include<algorithm>
#define M 1010
#define N 1000000
#define D double
#define LL long long
using namespace std;
LL a,b,c,d,sum;
LL max(LL x,LL y)
{
	if(x>y) return x;
	else return y; 	
} 
LL maxx(LL x,LL y,LL z,LL k)
{
	LL ss=max(max(max(x,y),z),k);
	return ss;
}
int main()
{
	std::ios::sync_with_stdio(false);
	cin>>a>>b>>c>>d;
	sum=maxx(a*c,a*d,b*c,b*d);
	cout<<sum;
	return 0;
}
/*
*/


Measured memory_bytes: 3580
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define Clear(a) a = decltype(a)()
#define all(a) a.begin(),a.end()
#define vec vector
typedef long long ll;
typedef pair<ll,ll> P;
//const ll big=998244353;
const ll big=1000000007LL;
const ll INF=1e18;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
ll max(ll x,ll y){
if(x>y)return x;
else return y;
}
ll min(ll x,ll y){
if(x<y)return x;
else return y;
}
ll expm(ll x,ll y){
    if(y==0)return 1;//0^0=1
    if(x==1||x==0)return x;
    if(y%2==1)return (expm(x,y-1)*x)%big;
    ll t=expm(x,y/2);
    return (t*t)%big;
}
ll exp(ll x,ll y){
    if(y==0)return 1;//0^0=1
    if(x==1||y==0)return x;
    if(y%2==1)return exp(x,y-1)*x;
    ll t=exp(x,y/2);
    return t*t;
}
ll inv(ll x){
    return expm(x,big-2);
}


int main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cout << fixed << setprecision(10);
    /*--------------------------------*/

    string s;cin >> s;
    ll ans=0;
    rep(i,s.size())ans+=(s[i]-'0');
    cout << (ans%9 ? "No" : "Yes") << endl;
}

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

int a[300];


int main(){
	int n;
	cin>>n;
	for (int i=0;i<n;i++){
		cin>>a[i];
	}
	bool flag=true;
	int tot=0;
	while (flag){
		for (int i=0;i<n;i++){
		if (a[i]%2!=0) {
			cout<<tot;
			return 0;
		}
		else a[i]/=2;	
	}
	tot++;
	}
	cout<<tot;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y);
#define chmin(x,y) x = min(x,y);
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};
const int INF = 1001001001;



int main() {
    int n;
    cin >> n;
    vector<string> a(n);
    set<string> s;
    rep(i,n) {
        string w;
        cin >> w;
        if (s.count(w)) {
            cout << "No" << endl;
            return 0;
        }
        s.insert(w);
        a[i] = w;
    }
    for (int i = 0; i <= n-2; i++) {
        if (a[i].back() != a[i+1][0]) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 3592
#include <stdio.h>
int main(){
    int n,d;
    scanf("%d%d",&n,&d);
    int a,b;
    b=(2*d)+1;
    a=n/b;
    if(n%b==0){printf("%d\n",a);}
    else{printf("%d\n",a+1);}
    return 0;;
}

Measured memory_bytes: 128
import numpy as np
import sys
input = sys.stdin.readline
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N = I()
A = S()
B = S()
C = S()

cnt = 0
for i in range(N):
    if A[i] != B[i]:
        cnt += 1
    if A[i] != C[i]:
        cnt += 1
    if A[i] != B[i] and B[i] == C[i]:
        cnt -= 1

print(cnt)

Measured memory_bytes: 21404
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Mayank
 */



#include "bits/stdc++.h"

#define ll long long
#define rep(i, a, b) for(ll i = (a); i < (b); i++)
using namespace std;
const ll MOD = 1e9+7;

ll modExp(ll a, ll b){
    ll ret = 1;
    ll idx=0;
    while(b>0){
        if(b%2){
            ll temp = a;
            rep(i, 0, idx)temp = (temp*temp)%MOD;
            ret = (ret*temp)%MOD;
        }
        b/=2;
        idx++;
    }
    return ret%MOD;
}

class CUbiquity {
public:
	void solve(std::istream& cin, std::ostream& cout) {
        ll n;
        cin>>n;
        if(n<=1)cout<<0;
        else{
            ll a1 = modExp(10, n);
            ll a2 = modExp(9, n);
            ll a3 = modExp(8, n);
            cout<<(a1 - (2*a2)%MOD + a3 + MOD)%MOD;
        }
	}
};


int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
	CUbiquity solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


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


int main() {
int N,M;
cin >> N >> M;
vector<int> ac(M),pe(N+1),wa(N+1);
int ans = 0,wro = 0;
rep(i,M) {
    string a;
    cin >> ac.at(i) >> a;
    if (pe.at(ac.at(i)) == 0 && a == "AC") {
        ans++;
        pe.at(ac.at(i)) = 1;
    } else if (pe.at(ac.at(i)) == 0 && a == "WA"){
        wa.at(ac.at(i))++;
    }

}
rep(i,N+1) {
    if (pe.at(i) == 1) {
        wro += wa.at(i);
    }
}
cout << ans << " " << wro << endl;



return 0;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
#define ll long long
#define mod 924844033
#define N 200009
#define M 600009
using namespace std;

int n,m,tot,fst[N],pnt[N<<1],nxt[N<<1],fa[N],sz[N];
int fac[N],inv[N],w[2][M],pos[M],a[M],na[M],b[M];
int ksm(int x,int y){
	int z=1; for (; y; y>>=1,x=(ll)x*x%mod) if (y&1) z=(ll)z*x%mod;
	return z;
}
void add(int x,int y){
	pnt[++tot]=y; nxt[tot]=fst[x]; fst[x]=tot;
}
void pwk(int n){
	for (m=1; m<=n; m<<=1);
	int i,x=ksm(5,(mod-1)/m);
	for (i=w[0][0]=w[1][0]=1; i<m; i++)
		w[0][i]=w[1][m-i]=(ll)w[0][i-1]*x%mod;
	for (i=1; i<m; i++) pos[i]=pos[i>>1]>>1|((i&1)?m>>1:0);
}
void dfs(int x){
	int i,y; sz[x]=1;
	for (i=fst[x]; i; i=nxt[i]){
		y=pnt[i];
		if (y!=fa[x]){
			fa[y]=x; dfs(y);
			sz[x]+=sz[y];
			a[sz[y]]++;
		}
	}
	if (x>1) a[n-sz[x]]++;
}
void fft(int *a,int n,int p){
	int i,j,k,l,x,u,v;
	for (i=0; i<n; i++) na[pos[i]]=a[i];
	for (i=0; i<n; i++) a[i]=na[i];
	for (k=1; k<n; k<<=1)
		for (i=0,x=n/k>>1; i<n; i+=(k<<1))
			for (j=i,l=0; j<i+k; j++,l+=x){
				u=a[j]; v=(ll)a[j+k]*w[p][l]%mod;
				a[j]=(u+v)%mod; a[j+k]=(u-v+mod)%mod;
			}
	if (p){
		x=ksm(n,mod-2);
		for (i=0; i<n; i++) a[i]=(ll)a[i]*x%mod;
	}
}
int main(){
	scanf("%d",&n);
	int i,x,y;
	for (i=1; i<n; i++){
		scanf("%d%d",&x,&y);
		add(x,y); add(y,x);
	}
	dfs(1);
	fac[0]=inv[0]=inv[1]=1;
	for (i=1; i<=n; i++) fac[i]=(ll)fac[i-1]*i%mod;
	for (i=2; i<=n; i++) inv[i]=mod-(ll)inv[mod%i]*(mod/i)%mod;
	for (i=2; i<=n; i++) inv[i]=(ll)inv[i-1]*inv[i]%mod;
	for (i=0; i<=n; i++) b[n-i]=inv[i];
	for (i=1; i<=n; i++) a[i]=(ll)a[i]*fac[i]%mod;
	pwk(n<<1);
	fft(a,m,0); fft(b,m,0);
	for (i=0; i<m; i++) a[i]=(ll)a[i]*b[i]%mod;
	fft(a,m,1);
	for (i=1; i<=n; i++)
		printf("%lld\n",((ll)n*fac[n]%mod*inv[i]%mod*inv[n-i]%mod-(ll)a[i+n]*inv[i]%mod+mod)%mod);
	return 0;
}

Measured memory_bytes: 31232
#include<stdio.h>

int main(){
  int a,b,c,d,ans=0;
  scanf("%d%d%d%d",&a,&b,&c,&d);
  if(a>=b)ans+=b;
  else ans+=a;
  if(c>=d) ans+=d;
  else ans+=c;
  printf("%d",ans);
  return 0;
}

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

vector<int> num;
const int N=2000;
int n,k;
string s;
int dp[N][5][2];
long long d(int pos, int c, int f){
    if(c > k) return 0;

    if(pos == num.size()){
        if(c == k) {
                return 1;
        }
        return 0;
    }

    if(dp[pos][c][f] != -1) return dp[pos][c][f];
    long long res = 0;

    int x;

    if(f == 0){
        x = num[pos];
    } else {
        x = 9;
    }
    for(int i = 0; i<=x; i++){
        int nf = f;
        int ncnt = c;
        if(f == 0 && i < x) nf = 1;
        if(i != 0) ncnt++;
        if(ncnt <= k) res += d(pos+1, ncnt, nf);
    }

    return dp[pos][c][f] = res;
}

long long solve(string s){
    num.clear();
    for(int i=0;i<s.size();i++){
        num.push_back(s[i]-'0');
    }
    memset(dp, -1, sizeof(dp));
    long long res = d(0, 0, 0);
    return res;
}

int main () {
    cin>>s;
    scanf("%d",&k);
    long long res = solve(s);
    printf("%lld",res);
}


Measured memory_bytes: 3868
n=int(input())
s=input()

basho=[[],[],[]]

for i in range(n):
    if(s[i]=='R'):
        basho[0].append(i)
    if(s[i]=='G'):
        basho[1].append(i)
    if(s[i]=='B'):
        basho[2].append(i)

ans=1

for i in range(3):
    ans*=len(basho[i])

for i in range(n-1):
    for j in range(i+1,n):
        ken=j*2-i
        if(ken>=n):
            continue
        if(s[i]!=s[j] and s[j]!=s[ken] and s[i]!=s[ken]):
            ans-=1

print(ans)

Measured memory_bytes: 9288
N, K = map(int, input().split())
A = [int(s) for s in input().split()]

ru = [None] * (N+1)
ru[0] = 0
for i in range(len(A)):
    ru[i+1] = ru[i] + A[i]

ans = 0
for m in reversed(range(40)):
    cnt = 0
    for i in range(N):
        for j in range(i+1, N+1):
            sum = ru[j] - ru[i]
            if (sum & ans) < ans:
                continue
            if sum & (1 << m):
                cnt += 1
    if cnt >= K:
        ans |= (1 << m)

print(ans)

Measured memory_bytes: 43628
#include <bits/stdc++.h>
#define ld long double
#define ll long long
#define ull unsigned ll
#define pll pair<ll, ll>
#define itr(a) begin(a), end(a)
#define pb push_back
#define x first
#define y second
#define endl '\n'
#define FAST cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
#define FILES(namein, nameout) freopen(namein, "r", stdin); freopen(nameout, "w", stdout);
#define M 1000000007
#define N 200000
#define INF 101111111111111
using namespace std;
main(){
    FAST;
    ll n;
    cin >> n;
    string s;
    cin >> s;
    char last = '\0';
    ll bc = 0;
    for(ll i =0;i<n;i++){
    	if(s[i] != last){
    		bc++;
    	}
    	last = s[i];
    }
    cout << bc << endl;
}

Measured memory_bytes: 512
#include<iostream>
using namespace std;
int main(){
    int a[100010],n,k;
    while(cin>>n>>k,n||k){
        for(int i=0;i<n;i++)cin>>a[i];
        int mx=-1;
        int sum=0;
        for(int i=0;i<k;i++)sum+=a[i];
        mx=sum;
        for(int i=k;i<n;i++){
            sum-=a[i-k];
            sum+=a[i];
            mx=max(mx,sum);
        }
        cout<<mx<<endl;
    }
}

Measured memory_bytes: 1548
#include <bits/stdc++.h>
      
#define FOR(i,a,b) for( ll i = (a); i < (ll)(b); i++ )
#define REP(i,n) FOR(i,0,n)
#define YYS(x,arr) for(auto& x:arr)
#define ALL(x) (x).begin(),(x).end()
#define SORT(x) sort( (x).begin(),(x).end() )
#define REVERSE(x) reverse( (x).begin(),(x).end() )
#define UNIQUE(x) (x).erase( unique( ALL( (x) ) ) , (x).end() )
#define PW(x) (1LL<<(x))
#define SZ(x) ((ll)(x).size())
#define SHOW(x) cout << #x << " = " << x << endl
#define SHOWA(x,n) for( int yui = 0; yui < n; yui++ ){ cout << x[yui] << " "; } cout << endl

#define pb emplace_back
#define fi first
#define se second

using namespace std;

typedef long double ld;
typedef long long int ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<ld> vd;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<vpl> gr;
typedef vector<vl> ml;
typedef vector<vd> md;
typedef vector<vi> mi;
     
const ll INF = (ll)1e9 + 10;
const ll INFLL = (ll)1e18 + 10;
const ld EPS = 1e-12;
const ll MOD = 1e9+7;
     
template<class T> T &chmin( T &a , const T &b ){ return a = min(a,b); }
template<class T> T &chmax( T &a , const T &b ){ return a = max(a,b); }
template<class T> inline T sq( T a ){ return a * a; }

ll in(){ long long int x; scanf( "%lld" , &x ); return x; }
char yuyushiki[1000010]; string stin(){ scanf( "%s" , yuyushiki ); return yuyushiki; }

// head


struct Mod{
  unsigned n;
  Mod() : n(0){}
  Mod( ll x ){
    if( x < 0 ) n = x%MOD+MOD;
    else n = x%MOD;
  }
};
Mod operator + ( Mod a  , Mod b ){ return Mod( a.n + b.n ); }
Mod operator +=( Mod &a , Mod b ){ return a = a + b; }
Mod operator - ( Mod a ){ return Mod( MOD - a.n ); }
Mod operator - ( Mod a  , Mod b ){ return Mod( a.n + MOD - b.n ); }
Mod operator -=( Mod &a , Mod b ){ return a = a - b; }
Mod operator * ( Mod a  , Mod b ){ return Mod( (ll)a.n * b.n ); }
Mod operator *=( Mod &a , Mod b ){ return a = a * b; }
Mod modpow( Mod x , ll k ){
  Mod res = 1;
  while( k ){
    if( k & 1 ) res *= x;
    k /= 2;
    x *= x;
  }
  return res;
}
ll extgcd( ll a , ll b , ll &x , ll &y ){
  ll d = a;
  if( b != 0 ){
    d = extgcd( b , a % b , y , x );
    y -= a / b * x;
  } else {
    x = 1, y = 0;
  }
  return d;
}
Mod inv( Mod a ){ ll x, y; assert( extgcd( a.n , MOD , x , y ) == 1 ); return Mod( x ); }
Mod operator / ( Mod a  , Mod b ){ return Mod( (ll)a.n * inv(b).n ); }
Mod operator /=( Mod &a , Mod b ){ return a = a / b; }


ll n, m;
ll x[100010];
ll y[100010];

Mod ysum = 0;

int main(){

  n = in();
  m = in();
  REP( i , n ){
    x[i] = in();
  }
  for( int i = n-1; i >= 0; i-- ){
    x[i] -= x[0];
  }
  REP( i , m ){
    y[i] = in();
  }
  for( int i = m-1; i >= 0; i-- ){
    y[i] -= y[0];
  }

  FOR( i , 1 , m ){
    Mod ad = i;
    Mod mi = m - 1 - i;
    ysum += ( ad - mi ) * y[i];
  }


  Mod ans = 0;
  FOR( i , 1 , n ){
    Mod ad = i;
    Mod mi = n - 1 - i;
    ans += ( ad - mi ) * x[i] * ysum;
  }

  printf( "%d\n" , (int)ans.n );
  
  return 0;
}


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

typedef long long ll;
ll L[87];
int main() {
  int N; cin >> N;
  L[0] = 2, L[1] = 1;
  for (int i = 2; i <= N; i++){
    L[i] = L[i-2] + L[i-1];
  }

  cout << L[N] << endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <deque>
#include <math.h>
#include <set>
#include <iomanip>
#include <time.h>
#include <list>
#include <stdio.h>
#include <queue>
#include <map>
#include <algorithm>
#include <assert.h>
#include <memory.h>

#define mk make_pair
#define sc second
#define fr first
#define pb emplace_back
#define all(s) s.begin(), s.end()
#define sz(s) ( (int)s.size() )
#define int long long

using namespace std;

const int N = 2e5 + 5;

int n, k;
long long ar[N], b[N];

long long ans;

void Merge_sort(int l, int r)
{
    if (l == r)
        return;

    int md = (l + r) >> 1;

    int i = l, j = md + 1;

    Merge_sort(l, md);
    Merge_sort(md + 1, r);

    for (int e = l; e <= r; e++)
    {
        if ( i <= md && ( j > r || ar[i] <= ar[j] ) )
        {
            ans += r - j + 1;
            b[e] = ar[i++];
        }
        else
            b[e] = ar[j++];
    }
    for (int e = l; e <= r; e++)
        ar[e] = b[e];
}

main ()
{
    cin >> n >> k;

    for (int i = 1; i <= n; i++)
    {
        scanf("%lld", &ar[i]), ar[i] -= k;
        ar[i] += ar[i - 1];
    }
    Merge_sort(0, n);

    cout << ans;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()

using namespace std;

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

const int MAX_N = (int)3 * 1e5 + 5;
int sumW[MAX_N];
int sumE[MAX_N];

int main()
{
	memset(sumW, 0, sizeof(sumW));
	memset(sumE, 0, sizeof(sumE));
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	int N; cin >> N;
	string S; cin >> S;

	rep (i, N){
		if (i == 0){
			sumW[i] = (int)(S[i] == 'W');
			sumE[i] = (int)(S[i] == 'E');
		}else{
			sumW[i] = sumW[i-1] + (int)(S[i] == 'W');
			sumE[i] = sumE[i-1] + (int)(S[i] == 'E');
		} // end if
	} // end rep

	int res = N;
	rep (i, N){
		int curr = 0;
		if (i == 0){
			curr += sumE[N-1] - sumE[i];
		}else{
			curr += sumW[i-1];
			curr += sumE[N-1] - sumE[i];
		} // end if
		res = min(res, curr);
	} // end rep

	cout << res << endl;

	return 0;
}

Measured memory_bytes: 3152
#include <iostream>
using namespace std;
int main(void){
    int a;
cin>>a;
if(a<2){
    cout<<a<<endl;
}
if(a>=2 && a<4){
    cout<<2<<endl;
}
else if(a>=4 && a<8){
    cout<<4<<endl;
}
else if(a>=8 && a<16){
    cout<<8<<endl;
}
else if(a>=16 && a<32){
    cout<<16<<endl;
}
else if(a>=32 && a<64){
    cout<<32<<endl;
}
else if(a>=64){
    cout<<64<<endl;
}

    
    
}

Measured memory_bytes: 256
N, K = (int(x) for x in input().split(' '))
H    = [int(x) for x in input().split(' ')]
#ソート処理
list.sort(H, reverse=True)
#K回最大値をHから消す
if N >= K:
  del H[0:K]
else:
  H.clear()
#総和を出力
print(sum(H))


Measured memory_bytes: 26764
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

A, B, C, D = mapint()
mod = 998244353

dp = [[0]*D for _ in range(C)]
dp[A-1][B-1] = 1

for i in range(A-1, C):
    for j in range(B-1, D):
        if i==A-1 and j == B-1:
            continue
        val = 0
        if i>A-1:
            val += dp[i-1][j]*(j+1)
        if j>B-1:
            val += dp[i][j-1]*(i+1)
        if i>A-1 and j>B-1:
            val -= dp[i-1][j-1]*i*j
        dp[i][j] = val%mod

print(dp[C-1][D-1])

Measured memory_bytes: 136508
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define repr(e,x) for(auto& e:x)
using namespace std;
typedef long long ll;

ll x,y;

int main(){
    cin>>x>>y;

    ll ans=1001001001001001;
    if(x<=y) ans=min(ans,y-x);
    if(-x<=y) ans=min(ans,1+y+x);
    if(x<=-y) ans=min(ans,1-y-x);
    if(-x<=-y) ans=min(ans,2-y+x);

    cout<<ans<<endl;
}

Measured memory_bytes: 256
import numpy as np

n,m,x = map(int,input().split())
arr = np.array([list(map(int,input().split())) for i in range(n)])
c = arr.T[0]
a = arr.T[1:].T

ans = np.inf
for i in range(2**n):
    ability = np.zeros(m, np.int64)
    cost = 0
    for j in range(n):
        if (i>>j)&1: ability += a[j] ; cost += c[j]
    if np.all(ability>=x): ans = min(ans,cost)

ans = -1 if ans==np.inf else ans
print(ans)


Measured memory_bytes: 27292
#include <bits/stdc++.h>
#define ll long long

using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  priority_queue<int> a;
  for(int i = 0; i < n; i++) {
    int t;
    cin >> t;
    a.push(t);
  }
  for(int i = 0; i < m; i++) {
    int t = a.top();
    a.pop();
    a.push(t >> 1);
  }
  ll o = 0;
  while(!a.empty()) {
    o += a.top();
    a.pop();
  }
  cout << o << endl;
}

Measured memory_bytes: 892
// 嘘解法を手直しして正しく出力できるようにした
// S="?b??",T="ab",ans="abaa"
// C - Dubious Document 2
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(s);i<(e);++i)
string S, T;

bool match(int k){
	rp(i,0,T.size()) if(S[k+i] != '?' && S[k+i] != T[i]) return false;
	return true;
}

string create(int k){
	string s = S;
	s.replace(k, T.size(), T);
	replace(s.begin(), s.end(), '?', 'a');
	return s;
}

int main(){
	cin>>S>>T;
	string ans = "~";
	rp(i,0,S.size()-T.size()+1) if(match(i)) ans = min(ans, create(i));
	cout<< (ans=="~"? "UNRESTORABLE":ans) <<endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
	int n,m;
	cin>>n>>m;
	int t=m-n+1;
	if(n>0)
	{
		cout<<"Positive"<<'\n';
		return 0;
	}
	if(n<=0&&m>=0)
	{
		cout<<"Zero"<<"\n";
		return 0;
	}
	if(n<0&&m<0&&t%2==1)
    {
        cout<<"Negative"<<'\n';
        return 0;
    }
	cout<<"Positive"<<'\n';
	return 0;
}

Measured memory_bytes: 256
/**
 * @brief  : c++ code for AtCoder
 * @author : rk222
 * @created: 2019.06.09 20:55:26
 */

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef pair<int, P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i, x) for (ll i = 0; i < x; i++)
#define rep1(i, x) for (ll i = 1; i <= x; i++)
#define rrep(i, x) for (ll i = x - 1; i >= 0; i--)
#define rrep1(i, x) for (ll i = x; i > 0; i--)
#define sor(v) sort(v.begin(), v.end())
#define rev(s) reverse(s.begin(), s.end())
#define lb(vec, a) lower_bound(vec.begin(), vec.end(), a)
#define ub(vec, a) upper_bound(vec.begin(), vec.end(), a)
#define uniq(vec) vec.erase(unique(vec.begin(), vec.end()), vec.end())
#define mp1(a, b, c) P1(a, P(b, c))

#define disp(x) cout << #x << ": " << x << endl
#define disp_vec(v)                                                                           \
    cout << #v << ":";                                                                        \
    rep(i, v.size()) cout << " " << v[i];                                                     \
    cout << endl

const int INF = 100000000;
const ll M = 1000000007;
const int dir_4[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
const int dir_8[8][2] = {{1, 0}, {1, 1}, {0, 1}, {-1, 1}, {-1, 0}, {-1, -1}, {0, -1}, {1, -1}};

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

ll dp[100010];
ll n, m, a[100010];

int main() {
    scanf("%lld%lld", &n, &m);
    rep(i, m) scanf("%lld", &a[i]);
    a[m] = -1;

    dp[0] = 1;
    ll aid = 0;
    rep1(i, n) {
        if (a[aid] == i) {
            dp[i] = 0;
            aid++;
        } else {
            if (i == 1LL) {
                dp[i] = dp[i - 1];
            } else {
                dp[i] = (dp[i - 1] + dp[i - 2]) % M;
            }
        }
    }

    printf("%lld\n", dp[n]);

    /* --------------------------------- */
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin >> N;
    vector<int> C(N), S(N), F(N), A(N, 0);
    for (int i = 0; i < N - 1; i++){
        cin >> C.at(i) >> S.at(i) >> F.at(i);
    }
    for (int i = 0; i < N - 1; i++){
        int sta = 0;
        for(int j = i; j < N - 1; j++){
            if (sta < S.at(j)) sta = S.at(j);
            else if ((sta - S.at(j)) % F.at(j) != 0) sta = F.at(j) * (sta / F.at(j) + 1) ;
            sta += C.at(j);
            //cout << "i " << i << " j " << j << " sta " << sta << endl;
        }
        cout << sta << endl;
    }
    cout << "0" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
long long a, b;
bool check(long long time, int n, vector<long long>& h)
{
    long long need = 0;
    for(int i = 0; i < n; i++){
        if(h[i] - b * time > 0){
            need += ((h[i] - b * time) / (a - b));
            if((h[i] - b * time) % (a - b) != 0){
                need++;
                //cout << need << endl;
            }
        }
    }
    if(need <= time){
        //cout << "true" << endl;
        return true;
    }
    //cout << "false" << endl;
    return false;
}

int main()
{
    long long ng = 0;
    long long ok = 1000000010;
    int n;
    cin >> n >> a >> b;
    vector<long long> h;
    for(int i = 1; i <= n; i++){
        long long in;
        cin >> in;
        h.push_back(in);

    }
    while(ok - ng != 1){
        long long mid = (ok + ng) / 2;
        if(check(mid, n, h) == true){
            ok = mid;
        } else {
            ng = mid;
        }
    }
    cout << ok << endl;
    return 0;
}

Measured memory_bytes: 1400
from collections import Counter
from itertools import permutations
N,C = map(int, input().split())
cost = [list(map(int, input().split())) for _ in range(C)]
color = [list(map(lambda x:int(x)-1, input().split())) for _ in range(N)]

# 3 groups
mod3 = {0:[], 1:[], 2:[]}
for i in range(N):
    for j in range(N):
        m = (i+j)%3
        mod3[m].append(color[i][j])

cnts = [Counter(mod3[i]) for i in range(3)]
cost_mod = [[-1]*C for _ in range(3)]
for i in range(3):
    for to_ in range(C):
        cond = 0
        for from_ in cnts[i].keys():
            cond += cnts[i][from_]*cost[from_][to_]
        cost_mod[i][to_] = cond

ans = float('inf')
for p in permutations(range(C), 3):
    cond = 0
    for i in range(3):
        cond += cost_mod[i][p[i]]
    ans = min(ans, cond)
    #print(cond, p)
print(ans)
    

Measured memory_bytes: 8012
#include <iostream>
#include <iomanip>
#include <string>
#include <unordered_map>
#include <cmath>
#include <algorithm>

typedef long long ll;
typedef long double ld;

using namespace std;
int main()
{
  int x, y;
  cin >> x >> y;

  for (int i = 0; i <= x; ++i)
  {
    for (int j = 0; j <= x; ++j)
    {
      if ((i * 4 + j * 2 == y) && (j + i == x))
      {
        cout << "Yes";
        return 0;
      }
    }
  }

  cout << "No";
  return 0;
}


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

using namespace std;

int main()
{
    int n,k;
    string s;
    cin >> n >> k;
    cin >> s;
    //cout <<(int)'A' << (int)'a';
    s[k-1] +=32; 
    cout << s << endl;

    return 0;
}

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

int main(void){
  int limit = 200020;
  char str1[limit];
  char str2[limit];
  scanf("%s", str1);
  scanf("%s", str2);

  int i;
  int count = 0;
  int length = strlen(str1);
  int lengthTrue = strlen(str2);

  if(length == lengthTrue){
  for(i = 0; i < length; i++){
    if(str1[i] != str2[i]){
      count++;
    }
  }

  printf("%d\n",count);
}
}

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

int main(){
  int count=0;
  string S, T;
  cin >> S >> T;
  
  for (int i=0;i<S.size();i++){
    if ( S.at(i) != T.at(i) )
      count ++;
  }
  
  cout << count << endl;
}

Measured memory_bytes: 3912
#include <bits/stdc++.h>
using namespace std ;
string s,t ;

int solve(int pos) {
    int ans = 0 ;
    for(int i = 0;i < t.length(); ++ i) {
        if(s[pos + i] != t[i]) {
            ++ ans ;
        }
    }
    return ans ;
}

int main()
{
    int64_t D, T, S ;
    ios::sync_with_stdio(false) ;
    while(cin >> s >> t) {
        int lens = s.length(), lent = t.length() ;
        int ans = 0x3f3f3f3f ;
        for(int i = 0;i + lent - 1 < lens; ++ i) {
            ans = min(ans, solve(i)) ;
        }
        cout << ans << endl ;
    }
}


Measured memory_bytes: 3492
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include <cmath>
#include <limits>
#include <utility>
#include <map>
#include <iomanip>
#include <queue>
#include <cctype>
#include <stack>
#include <random>
#include <list>
#include <numeric>
#include <chrono>
#include <set>


#define rep(i,p,q) for(ll i = p;i < q;i++)
#define ll long long

using namespace std;

vector<vector<ll>> graph;
vector<ll> query;
vector<ll> ans;
vector<ll> visited;


const long long MAX_N = 1 << 17;

long long dat[2 * MAX_N - 1];

ll ecd(ll a, ll b) {
	if (a < b) swap(a, b);
	if (b == 0) return a;
	else {
		return ecd(b, a % b);
	}
}

ll pow(ll a, ll b) {
	vector<ll> d = vector<ll>((ll)(log(b)) + 2);
	d[0] = a;
	rep(i, 1, d.size()) d[i] = d[i - 1] * d[i - 1];
	ll ret = 1;
	rep(i, 0, log(b) + 1) {
		if (b & 1 << i) ret *= d[i];
	}
	return ret;
}

//C
int main(void) {
	ll n;
	cin >> n;
	vector<ll> a = vector<ll>(n), b = vector<ll>(n), c = vector<ll>(n);
	rep(i, 0, n) cin >> a[i] >> b[i] >> c[i];
	vector<ll> aDP = vector<ll>(n), bDP = vector<ll>(n),  cDP = vector<ll>(n);
	aDP[0] = a[0];
	bDP[0] = b[0];
	cDP[0] = c[0];
	rep(i, 1, n) {
		aDP[i] = a[i] + max(bDP[i - 1], cDP[i - 1]);
		bDP[i] = b[i] + max(aDP[i - 1], cDP[i - 1]);
		cDP[i] = c[i] + max(bDP[i - 1], aDP[i - 1]);
	}
	cout << max(aDP[n - 1], max(bDP[n - 1], cDP[n - 1])) << endl;
}


Measured memory_bytes: 4992
#include <stdio.h>
#include <stdlib.h>
int N;
long int ans;
int A[200001];
int main(void) {
	A[0] = 0;
	scanf("%d", &N);
	for(int k = 1; k <= N; k++){
		scanf("%d", &A[k]);
		if(A[k] < A[k-1]){
			ans += (A[k-1] - A[k]);
			A[k] = A[k-1];
		}
	}
	printf("%ld", ans);
	return 0;
}

Measured memory_bytes: 2464
N = int(input())
lst_A = list(map(int, input().split()))
lst_B = list(map(int, input().split()))
lst_C = list(map(int, input().split()))

ret = sum(lst_B)
for idx, n in enumerate(lst_A[:-1]):
    if n == lst_A[idx + 1] - 1:
        ret += lst_C[n - 1]
print(ret)

Measured memory_bytes: 3064
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    n=int(input())
    AI=[(a,i) for i,a in enumerate(map(int,input().split()))]
    AI.append((0,-1))
    AI.sort(reverse=1)

    m=INF
    ans=[0]*n
    for i in range(n):
        d=AI[i][0]-AI[i+1][0]
        m=min(m,AI[i][1])
        ans[m]+=(i+1)*d

    print(*ans,sep='\n')
resolve()

Measured memory_bytes: 64112
import numpy as np
from sys import stdin

'''
Reference: https://codeforces.com/blog/entry/75046#comment-591494 (1-based index)

(0-based index)

For a sequence A[l]..A[k]..A[r] with sum S contributes l * (N - r) to answer.
    0, 1, 2, ..., l....k....r, ..., N - 2, N - 1
    x  x  x   x   x         v   v     v      v
There are l `x` and (N - r) `v`.

Enumerate all possible sequence is impossible. 
Consider all sequeuces with sum S and **ends** at specific r:
    A[l1]...A[r] -> l1 * (N - r)
    A[l2]...A[r] -> l2 * (N - r)
    A[l3]...A[r] -> l3 * (N - r)
    .
    .
    .
which contributes (l1 + l2 + ... + lm) * (N - r) in total.

We can find *sum of left index for all valid sequence* for each r using DP.

    dp[i][s] = the sum of left index for all sequence that
                    1. ends at i
                    2. has sum s
    
    dp[i][:A[i]] = 0  since any sequence ends at i has sum >= A[i]

    dp[i][A[i]] = i + 1
    dp[i][s] = sum(dp[j][s - A[i]] for j in range(i))

    Take A = [2, 3, 4] for example, sequences that end at A[2] are:
    
                   [4] -> dp[2][4] = 3
             [2,    4] ↘
                [3, 4] -> dp[2][s] = dp[2][s - 4] for all s
             [2, 3, 4] ↗
    
    The answer is dp[r][S] * (N - r) for r in range(N)

So the naive implementation is:

    dp = np.zeros((N, max(S, A.max()) + 1), dtype=np.int64)
    for i, a in enumerate(A):
        dp[i, a] = i + 1
        for s in range(a + 1, S + 1):
            dp[i, s] = dp[:i, s - a].sum() % M  # here can be optimized
    
    ans = 0
    for i in range(N):
        ans += (N - i) * dp[i, S]
        ans = ans % M

has time O(N * S * N) which results in TLE.

Using another array to store the cumsum (prefix sum) of dp solves the problem:
'''

N, S = map(int, input().split())
A = np.int32(input().split())
M = 998244353
V = max(A.max(), S)

ans = 0
dp = np.zeros((N, V + 1), dtype=np.int64)
cs = np.zeros(V + 1, dtype=np.int64)
for i, a in enumerate(A):
    dp[i, a] = i + 1
    dp[i, a + 1 : S + 1] = cs[np.arange(a + 1, S + 1) - a]
    cs = (cs + dp[i]) % M
    ans = (ans + (N - i) * dp[i, S]) % M
print(ans)


Measured memory_bytes: 82764
import std;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] lreads(T = long)(long n){return generate(()=>readln.chomp.to!T()).take(n).array();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
// dfmt on

void main()
{
    long S, W;
    scan(S, W);
    writeln((S <= W) ? "unsafe" : "safe");
}


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

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

template <typename InputIterator>
typename InputIterator::value_type summation(InputIterator first,
                                             InputIterator last) {
  return std::accumulate(first, last, typename InputIterator::value_type());
}
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v);
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p);
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v) {
  for (auto &i : v) {
    stream >> i;
  }
  return stream;
}
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p) {
  stream >> p.first >> p.second;
  return stream;
}

int main() {
  int64_t a, b;
  std::cin >> a >> b;

  if (b < a) {
    std::swap(a, b);
  }

  for (int64_t i = 0; i < b; i++) {
    std::cout << a;
  }
  std::cout << std::endl;
  return 0;
}

Measured memory_bytes: 256
using System;

namespace ABCA096
{
    class Program
    {
        static void Main(string[] args)
        {
            int a, b;
            string[] str = Console.ReadLine().Split(' ');
            a = int.Parse(str[0]);
            b = int.Parse(str[1]);
            if (a <= b)
                Console.WriteLine(a);
            else
                Console.WriteLine(a-1);
            Console.ReadKey();


        }
    }
}


Measured memory_bytes: 11092
import sys
from itertools import permutations

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, *A = map(int, read().split())
    A.sort()

    vec1 = [0] * N
    vec2 = [0] * N
    for i in range(N - 1):
        if i % 2 == 0:
            vec1[i] += 1
            vec1[i + 1] -= 1
            vec2[i] -= 1
            vec2[i + 1] += 1
        else:
            vec1[i] -= 1
            vec1[i + 1] += 1
            vec2[i] += 1
            vec2[i + 1] -= 1

    vec1.sort()
    vec2.sort()

    ans1 = ans2 = 0
    for a, v1, v2 in zip(A, vec1, vec2):
        ans1 += a * v1
        ans2 += a * v2

    print(max(ans1, ans2))
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 85632
#include "iostream"
#include "algorithm"
#include "string"
#include "vector"
#include "cmath"
#include "bitset"
#include "queue"
#include "functional"
#include "map"
#include "unordered_map"
#include "set"

#define lp(n) for (int i = 0; i < n; i++)
#define LP(n,i) for (int i = 0; i < n; i++)
#define mod 1000000007
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define nya_n "(=^･ω･^=)"
typedef long long ll;
using namespace std;

int n, m[100000];
pair<int, bool>t[100000], a[100000];
ll ans;
int main() {
	cin >> n;
	cin >> t[0].first;
	t[0].second = true;
	lp(n - 1) {
		cin >> t[i + 1].first;
		if (t[i].first < t[i + 1].first)
			t[i + 1].second = true;
		else if (t[i].first > t[i + 1].first) {
			cout << 0 << endl;
			return 0;
		}
		else t[i + 1].second = false;
	}
	cin >> a[0].first;
	lp(n - 1) {
		cin >> a[i + 1].first;
		if (a[i].first > a[i + 1].first)
			a[i].second = true;
		else if (a[i].first < a[i + 1].first) {
			cout << 0 << endl;
			return 0;
		}
		else a[i].second = false;
	}
	a[n - 1].second = true;

	lp(n) {
		if (t[i].second&&a[i].second) {
			if (t[i].first != a[i].first) {
				cout << 0 << endl;
				return 0;
			}
			else m[i] = 1;
		}
		else if (t[i].second && !a[i].second) {
			if (t[i].first > a[i].first) {
				cout << 0 << endl;
				return 0;
			}
			else m[i] = 1;
		}
		else if (!t[i].second&&a[i].second) {
			if (t[i].first < a[i].first) {
				cout << 0 << endl;
				return 0;
			}
			else m[i] = 1;
		}
		else m[i] = min(t[i].first, a[i].first);
	}
	ans = 1;
	lp(n) {
		ans *= m[i];
		ans %= mod;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 2176
T = int(input())

for _ in range(T):
    N = int(input())
    A = list(map(int,input().split()))
    S = input()

    if S[-1] == '1':
        print(1)
        continue

    list0 = [0] * 64

    for a, s in zip(A[::-1], S[::-1]):
        blen = a.bit_length()
        for i in range(blen, 0, -1):
            if a.bit_length() < i: continue
            if list0[i - 1]:
                a ^= list0[i - 1]
                if a == 0: break

        else:
            if s == '1':
                ans = 1
                break
            else:
                list0[a.bit_length() - 1] = a

    else:
        ans = 0

    print(ans)


Measured memory_bytes: 9192
private fun readLn() = readLine()!!
private fun readInt() = readLn().toInt()
private fun readLong() = readLn().toLong()
private fun readStrings() = readLn().split(" ")
private fun readInts() = readStrings().map(String::toInt)
private fun readLongs() = readStrings().map(String::toLong)

fun main() {
    val n = readInt()
    val s = readLn()
    val popcnt = s.sumBy { if (it == '1') 1 else 0 }
    val mds = ArrayList<Int>()
    val p2s = ArrayList<IntArray>()
    for (m in popcnt-1..popcnt+1) {
        if (m <= 0) {
            mds.add(-1)
            p2s.add(IntArray(n))
            continue
        }
        var cur = 0
        for (c in s) {
            cur *= 2
            if (c == '1')
                cur++
            cur %= m
        }
        mds.add(cur)
        val p2 = IntArray(n)
        p2[0] = 1
        for (i in 1 until n) {
            p2[i] = p2[i - 1] * 2 % m
        }
        p2s.add(p2)
    }
    fun popCount(x : Int) : Int = if (x > 0) x % 2 + popCount(x / 2) else 0
    fun brute(x: Int) : Int = if (x == 0) 0 else 1 + brute(x % popCount(x))
    for (i in 0 until n) {
        val cmd = if (s[i] == '1') popcnt - 1 else popcnt + 1
        if (cmd == 0) {
            println(0)
            continue
        }
        var cans = if (s[i] == '1') mds[0] else mds[2]
        if (s[i] == '1') {
            cans -= p2s[0][n - i - 1]
        } else {
            cans += p2s[2][n - i - 1]
        }
        cans += cmd
        cans %= cmd
        println(brute(cans) + 1)
    }
}

Measured memory_bytes: 60176
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define REPR(i, n) for(int i = (n); i >= 0; i--)
#define FOR(i, m, n) for(int i = (m); i < (n); i++)
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << ": " << x << endl;

using namespace std;
typedef long long ll;

signed main() {
  int N, K, p = 0;
  cin >> N;
  K = N;

  while(N > 1) {
    p++;
    N -= 2;
  }

  if(K % 2 == 1)
    p++;

  cout << p << endl;

  return 0;
}


Measured memory_bytes: 256