akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <map>
#include <vector>
using namespace std;

int main(){
    int n; cin>>n;
    vector<int> a(n); for(int i=0;i<n;i++){cin>>a[i];}
    map<int, int> b; for(int i=0;i<n;i++){cin>>b[i];}
    map<int, int> c; for(int i=0;i<n-1;i++){cin>>c[i];}

    int satisfaction = 0;
    int latest_index = 0;
    for (auto a_i : a){
        satisfaction += b[a_i-1];
        if (latest_index+1 == a_i){
            satisfaction += c[latest_index-1];
        }
        latest_index = a_i;
    }
    cout << satisfaction << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define mod 1000000007 //10^9+7
#define INF 1000000000000 //10^12
#define P pair<int,int>
#define rep(i,n) for(int i=0;i<n;i++)
int x,y,ans=0;
signed main(){
    cin>>x>>y;
    if(x<=3)ans+=100000*(4-x);
    if(y<=3)ans+=100000*(4-y);
    if(x==1&&y==1)ans+=400000;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        while(true){
            int n=sc.nextInt();
            int s=sc.nextInt();
            if(n==0&&s==0) break;
            for(int i=0;i<=9;i++) dfs(0,0,i,n,s);
            System.out.println(ans);
            ans=0;
        }
        
    }
    static int ans;
    public static void dfs(int c,int sum,int now,int n,int s){
        sum+=now;
        c++;
        if(c==n){
            if(sum==s){
                ans++;
            }
            return;
        }
        for(int i=now+1;i<=9;i++) dfs(c,sum,i,n,s);
        return;
    }
}


Measured memory_bytes: 26184
#include <bits/stdc++.h>
#define fast_read ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
using namespace std;
int main()
{
    fast_read
    int x,y,z;
    cin>>x>>y>>z;
    int e = x / (y + z);
    if (x - e * (y + z) >= z)cout<<e<<endl;
    else cout<<e-1<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cassert>
#include <utility>
#include <numeric>
#include <cstring>
using namespace std;
using ll = long long;

int main(){
    int r;
    cin >> r;
    cout << 3*r*r;
}

Measured memory_bytes: 256
class Factorial:
    def __init__(self, n, mod=10**9+7):
        self.fac = [0] * (n+1)
        self.ifac = [0] * (n+1)
        self.fac[0] = 1
        self.ifac[0] = 1
        self.mod = mod
        modmod = self.mod - 2
        for i in range(n):
            self.fac[i+1] = self.fac[i] * (i+1) % self.mod
            self.ifac[i+1] = self.ifac[i] * pow(i+1, modmod, self.mod) % self.mod

    def comb(self, n, r):
        if n == 0 and r == 0:
            return 1
        if n < r or n < 0:
            return 0
        tmp =  self.ifac[n-r] * self.ifac[r] % self.mod
        return tmp * self.fac[n] % self.mod

    def perm(self, n, r):
        if n == 0 and r == 0:
            return 1
        if n < r or n < 0:
            return 0
        return (self.fac[n] * self.ifac[n-r]) % self.mod

n = int(input())
a = list(map(int, input().split()))
mod = 10**9+7

d = {}
for i in range(0,n+1):
    if a[i] not in d:
        d[a[i]] = i
    else:
        l,r = d[a[i]], n-i
        break

fact = Factorial(n+1)

for i in range(1,n+2):
    ans = fact.comb(n+1,i)
    s = fact.comb(l+r,i-1)
    ans -= s
    while ans < 0:
        ans += mod
    print(ans)


Measured memory_bytes: 25796
#include<cstdio>
#include<algorithm>
using namespace std;

int main(){
  int n,s,r[20200];

  while(scanf("%d%d",&n,&s),n){
    for(int i=0;i<n;i++)scanf("%d",r+i);
    sort(r,r+n);

    int ans = 0;
    for(int i=0;i<n;i++){
      ans += n - (upper_bound(r+i+1,r+n,s-r[i]) - r);
    }
    printf("%d\n",ans);
  }
}

Measured memory_bytes: 1092
#include <stdio.h>

int main(void)
{
	float max, min;
	float f;
	
	scanf("%f", &min);
	max = min;
	while (scanf("%f", &f) != EOF){
		if (max < f){
			max = f;
		}
		if (min > f){
			min = f;
		}
	}
	
	printf("%f\n", max - min);
	
	return (0);
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main() {
	string S, T; cin >> S >> T;
	int R1[26], R2[26];
	fill(R1, R1 + 26, -1);
	fill(R2, R2 + 26, -1);
	bool flg = true;
	for (int i = 0; i < S.size(); i++) {
		if (R1[S[i] - 'a'] < 0)  R1[S[i] - 'a'] = T[i] - 'a';
		else {
			if (R1[S[i] - 'a'] != T[i] - 'a') flg = false;
		}
		if (R2[T[i] - 'a'] < 0)  R2[T[i] - 'a'] = S[i] - 'a';
		else {
			if (R2[T[i] - 'a'] != S[i] - 'a') flg = false;
		}
	}
	if (flg) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 776
# Acknowledge: https://atcoder.jp/contests/arc102/submissions/3127544
MOD = 998244353
k, n = map(int, input().split())

facts = [1]
invs = [1]
for i in range(1, n+k):
    f = (i*facts[i-1])%MOD
    facts.append(f)
    invs.append(pow(f, MOD-2, MOD))

def nCk(n, k):
    return (facts[n]*invs[k]*invs[n-k])%MOD

memo = []
for p in range(1, (k+3)//2):
    i = 2*p+1
    tmp = 0
    for t in range(min(p+1, n+1)):
        if k-i+t < 0:
            continue
        res = nCk(p, t)
        res *= nCk(n+k-i, k-i+t)
        res *= pow(2, t, MOD)
        tmp = (tmp+res)%MOD
    memo.append(tmp)

ans = []
for i in range(1, k):
    ans.append(memo[(i-1)//2])
for a in ans+[memo[-1]]+ans[::-1]:
    print(a)


Measured memory_bytes: 3608
//----------------------Shanu Garg here---------------------
//-------------Search on youtube : Shanu Garg---------------
//-Studying at National Institute of Technology Delhi(NITD)-
//---------------------From Delhi, India--------------------

#include<bits/stdc++.h>
#include<algorithm>
using namespace std;

#define f(i,n) for(auto i=0;i<n;i++)
#define fr(i,n) for(auto i=n-1;i>=0;i--)
#define fs(i,a,b,c) for(auto i=a;i!=b;i+=c)
#define fl(i,x) for(auto i : x)
#define nl cout<<"\n";
#define ll long long int
#define vi vector<int>
#define pr pair<ll, ll>
#define vll vector<pr>
#define vl vector<ll>
#define mid(a,b) ((a+b)/2)
#define pb push_back
#define LCM(a,b) ((a*b)/__gcd(a, b))
const int INF = 0x3f3f3f3f, mod = 1e9 + 7;

class triplet{ll f, s, t;};

vl in(ll n){vl v;ll x;
    f(i,n)
    cin>>x, v.pb(x%mod);
    return v;}
void out(vl v){fl(i,v)cout<<i;}
void out(vl v, char ch){
    fl(i,v)
    cout<<i<<ch;}

void solve(){
    ll n, k, x, total = 0;
    cin>>n>>k;
    ll ar[n];
    f(i, n)
    cin>>ar[i];
    if(k >= n)
    cout<<0, exit(0);
    sort(ar, ar+n);
    f(i, n-k)
    total += ar[i];
    cout<<total;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
   return 0;
}

Measured memory_bytes: 5252
fn main(){
    let scan = std::io::stdin();
    let mut line = String::new();
    let _ = scan.read_line(&mut line);
    let vec: Vec<&str> = line.split_whitespace().collect();
    let c: i32 = vec[0].parse().unwrap();

    let mut line = String::new();
    let _ = scan.read_line(&mut line);
    let vec: Vec<&str> = line.split_whitespace().collect();

    let mut data: Vec<i32> = Vec::new();
    for x in 0..c{
        let n: i32 = vec[x as usize].parse().unwrap();
        data.push(n);
    }
    sort(&mut data);
}
pub fn sort(data:&mut Vec<i32>){
    let mut count: i32 = 0;
//    let mut flag: bool = true;

//    while flag {
        for x in 0..data.len(){
//            flag = false;
            for y in 1..data.len()-x{
                if data[y] < data[y-1]{
//                    println!("swap({},{})", y, y-1);
                    data.swap(y,y-1);
//                    flag = true;
                    count += 1;
                }
            }
        }
//    }
//    for x in 0..data.len(){
//        for y in x+1..data.len(){
//            if data[x] > data[y]{
//                data.swap(x,y);
//                count += 1;
//            }
//        }
//    }

    for x in 0..data.len(){
        let n: i32 = data[x];
        print!("{}",n);
        if x != data.len()-1 {
            print!(" ");
        }
    }
    println!("");
    println!("{}",count);
}

Measured memory_bytes: 5052
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define INF 0x7fffffff
#define LL_INF 0x7fffffffffffffff
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

int main(void)
{
	int k, a, b;
	cin >> k >> a >> b;
	if(a % k == 0 || b % k == 0) {
		printf("OK\n");
	}
	else if(a / k != b / k) {
		printf("OK\n");
	}
	else {
		printf("NG\n");
	}

	return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <cmath>
#include <iomanip>
#include <bitset>
#include <string>
#include <stdlib.h>
using namespace std;
//cout <<  << endl;
typedef long long int ll;
typedef long double ld;

int main(){
    ll a,b,c;
    cin >> a >> b >> c;
    if (a<=c && a+b>=c){
        cout << "YES" << endl;
        return 0;
    }
    cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF (1ll << 60)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
using vl = vector<ll>;
using vvl = vector<vl>;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
using ll = long long;
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

void print(const std::vector<int> &v) {
    std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
    std::cout << std::endl;
}

int main() {
    ll N;
    cin >> N;
    if(N % 2 == 0) {
        cout << N / 2 - 1 << endl;
        return 0;
    } else {
        cout << N / 2 << endl;
    }
    return 0;
}

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

int H;
int largest;

int parent(int i){
    return i/2;
}

int left(int i){
    return i*2;
}

int right(int i){
    return i*2+1;
}

void maxHeap(int A[],int i){
    int l = left(i);
    int r= right(i);
    
    if(l<=H && A[l]>A[i])
        largest = l;
    else
        largest = i;
    
    if(r<=H && A[r] > A[largest])
        largest = r;
    
    if(largest!=i){
        int temp = A[i];
        A[i] = A[largest];
        A[largest] = temp;
        maxHeap(A, largest);
    }
    
}

int main(int argc, const char * argv[]) {
    cin >> H;
    int A[H];
    for(int i=1;i<=H;i++){
       cin >> A[i];
    }
    
    for(int i=H/2;i>0;i--)
        maxHeap(A, i);
    
    for(int i=1;i<=H;i++){
        cout << " " << A[i] ;
    }
    cout << endl;
    
    return 0;
}

Measured memory_bytes: 3112
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

using namespace std;
//using namespace __gnu_pbds;
//typedef tree< pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag, tree_order_statistics_node_update>
//ordered_set;
int dx[] = {0, 1, 0, -1};
int dy[] = {-1, 0, 1, 0};
#define X first
#define Y second
#define int long long int 
const int N = (int)1e6 + 10;
const int MOD = 1000000007;


void solve(){
    int x, y, z;
    cin >> x >> y >> z;
    cout << z << " " << x << " " << y << '\n';

}   

int32_t main(){
    ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr); 
    //int t; cin >> t;
    //while(t--)
        solve();
    return 0;
}

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

const int maxn = 100005;
const int maxd = 10;

int n, cnt;
int a[maxn], b[maxn];
long long h, w;
long long ans[maxd];
map < int, map < int, bool > > point;

signed main () {
	scanf("%lld %lld %d", &h, &w, &n);
	for (int i = 1; i <= n; ++i) {
		scanf("%d %d", &a[i], &b[i]);
		point[a[i]][b[i]] = 1;
	}
	for (int i = 1; i <= n; ++i) {
		for (int dx = -2; dx <= 0; ++dx) {
			for (int dy = -2; dy <= 0; ++dy) {
				if (a[i] + dx < 1 || b[i] + dy < 1 || a[i] + dx + 2 > h || b[i] + dy + 2 > w)
					continue;
				else {
					cnt = 0;
					for (int x = a[i] + dx; x <= a[i] + dx + 2; ++x) {
						for (int y = b[i] + dy; y <= b[i] + dy + 2; ++y) 
							cnt += point[x][y];
					}
					++ans[cnt];
				}
			}
		}
	}
	ans[0] = (h - 2) * (w - 2);
	for (long long i = 1; i < maxd; ++i) {
		ans[i] /= i;
		ans[0] -= ans[i];
	}
	for (int i = 0; i < maxd; ++i)
		printf("%lld\n", ans[i]);
}


Measured memory_bytes: 168640
#include<cmath>
#include<cstdio>
#include<iostream>
using namespace std;
const int MAXN=100001;
int n,nowt=0,nowx=0,nowy=0,tot,tox,toy;
bool flag=true;
inline int read()
{
	int x=0,f=1;char c=getchar();
	while(c<'0'||c>'9') {if(c=='-') f=-1;c=getchar();}
	while(c>='0'&&c<='9') {x=x*10+c-'0';c=getchar();}
	return x*f;
}
int main()
{
	n=read();
	while(n--)
	{
		tot=read();tox=read();toy=read();
		int dist=abs(tox-nowx)+abs(toy-nowy);
		int Time=tot-nowt;
		if(Time<dist) {flag=false;break;}
		Time-=dist;
		if(Time&1) {flag=false;break;}
		nowt=tot;nowx=tox;nowy=toy;
	}
	if(flag) printf("Yes");
	else printf("No");
	return 0;
}

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

const int max_n = 1000000;
int prime[max_n + 1];
bool is_prime[max_n + 1];

int sieve(int n) {
    int p = 0;
    for (int i = 0; i <= n; i++) {
        is_prime[i] = true;
    }

    is_prime[0] = is_prime[1] = false;
    for (int i = 2; i <= n; i++) {
        if (is_prime[i]) {
            prime[p++] = i;
            for (int j = 2 * i; j <= n; j += i) {
                is_prime[j] = false;
            }
        }
    }
    return p;
}

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

    sieve(max_n);
    for (int i = n; i <= max_n; i++) {
        if (is_prime[i]) {
            cout << i << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
typedef vector<string> vstr;
typedef pair<ll, ll> pll;
typedef vector<pll> vp;
typedef map<ll, ll> mll;
typedef map<string, ll> mstrll;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fir first
#define sec second
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(ll i = ll(a); i < ll(b); i++)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep,)(__VA_ARGS__)
#define each(i, n) for(auto&& i: n)
#define out(x) cout << (x)
#define indent() cout << '\n'
#define print(x) cout << (x) << '\n'
#define debug(x) cerr << #x << ": " << (x) << '\n'
ll gcd(ll a, ll b){return b != 0 ? gcd(b, a % b) : a;}
ll lcm(ll a, ll b){return a / gcd(a, b) * b;}
const ll INF = 1e16;
const ll MOD = 1e9 + 7;
ll a, b, c, n, m, x, y, z, w, h, ans, cnt, mx, mn;
string s, t;
vll dx = {-1, 0, 1, 0}, dy = {0, -1, 0, 1};
//vll dx = {-1, 0, 1, -1, 1, -1, 0, 1}, dy = {-1, -1, -1, 0, 0, 1, 1, 1};
string alphabet = "abcdefghijklmnopqrstuvwxyz";

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(cin >> n >> m){
        if(n <= m / 2){
            print(n + (m - 2 * n) / 4);
        }else{
            print(m / 2);
        }
    }
}


Measured memory_bytes: 256
/*#include <iostream>
using namespace std;
int main(){
	int N;
	cin >> N;

	int K, P;
	for (int i = 0; i < N; i++){
		cin >> K >> P;
		if (K%P != 0){
			cout << K%P << endl;
		}
		else{
			cout << P << endl;
		}
	}
	return 0;
}*/

/*#include <iostream>
#include <algorithm>
using namespace std;
int main(){
	int NM[200];
	int N;
	cin >> N;
	int Nh[100], Nm[100];
	for (int i = 0; i < N; i++){
		cin >> Nh[i] >> Nm[i];
		NM[i] = Nh[i] * 60 + Nm[i];
	}

	int M;
	cin >> M;
	int Mh[100], Mm[100];
	for (int i = 0; i < M; i++){
		cin >> Mh[i] >> Mm[i];
		NM[N + i] = Mh[i] * 60 + Mm[i];
	}
	sort(NM, NM+N+M);
	for (int i = 0; i < N + M; i++){
		if (NM[i] != NM[i + 1]){
			cout << NM[i] / 60 << ':';
			if (NM[i] % 60 < 10){
				cout << '0' << NM[i] % 60;
			}
			else{
				cout << NM[i] % 60;
			}
			if (N + M - 1 != i){
				cout << ' ';
			}
			else cout << endl;
		}
	}
}*/

/*#include <iostream>
#include <algorithm>
using namespace std;
int main(){
	int N;
	cin >> N;
	int x, y, b, p;
	int moneya;
	int moneyb;
	for (int i = 0; i < N; i++){
		cin >> x >> y >> b >> p;
		moneya = x*b + y * p;
		if (b >= 5 && p >= 2){
			moneya *= 0.8;
		}
		if (b <= 5){
			b = 5;
		}
		if (p <= 2){
			p = 2;
		}
		moneyb = x*b + y*p;
		moneyb *= 0.8;
		cout << min(moneya, moneyb) << endl;
	}
	return 0;
}*/

#include <iostream>
using namespace std;
int main(){
	int N;
	int k[10000];
	while (true){
		cin >> N;
		if (N == 0){
			break;
		}
		int cnt0 = 0;
		bool flg = 0;
		int total = 0;
		for (int i = 0; i < N; i++){
			cin >> k[i];
			if (k[i] == 0) cnt0++;
			if (k[i] >= 2) flg = 1;
			total += k[i];
		}
		if (flg) cout << N + 1 - cnt0 << endl;
		else if (total < N + 1 - cnt0){
			cout << "NA\n";
		}
		else cout << N + 1 - cnt0 << endl;
	}
	return 0;
}

Measured memory_bytes: 1200
A,B,C,X,Y=map(int,input().split(' '))

price=0
if X>Y:    
  N_same=Y
  flag='A'
else:
  N_same=X
  flag='B'
  
if A+B >2*C:
  price+=2*C*N_same
else:
  price+=(A+B)*N_same

if flag=='A':
  if A*(X-Y)>2*C*(X-Y):
    price+=2*C*(X-Y)
  else:
    price+=A*(X-Y)
else:
  if B*(Y-X)>2*C*(Y-X):
    price+=2*C*(Y-X)
  else:
    price+=B*(Y-X)

print(price)


Measured memory_bytes: 9204
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 7;
typedef long long ll;
int n;
char s[maxn];
int num[maxn], p[maxn], tot;
int main() {
    scanf("%d", &n);
    scanf("%s", s + 1);
    int cnt = 0;
    for (int i = 1; i <= n; i++) {
        if(s[i] == 'W') num[i] = num[i - 1] + 1, p[++tot] = i;
        else num[i] = num[i - 1];
    }
    int c = 0;
    for (int i = n; i >= 1; i--) {
        if(s[i] == 'R' && num[i] - c > 0) {
            swap(s[i], s[p[++c]]);
        }
    }
    printf("%d\n", c);
}


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

s = 0
p = 0
for _ in range(n):
  t,x,y = map(int, input().split())
  s = t - s
  p = abs((x+y)-p)
  if s < p:
    print("No")
    exit()
  elif s%2 != p%2:
    print("No")
    exit()
print("Yes")

Measured memory_bytes: 9164
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  string S;
  cin >> S;
  int64_t ans = 0;
  for(int j=0; j<N; j++){
    int bR = 0;
    int bG = 0;
    int bB = 0;
    int aR = 0;
    int aB = 0;
    int aG = 0;
    int minus = 0;
    char x = S.at(j);
    for(int i=0; i<j; i++){
      if(S.at(i) == 'R'){
        bR++;
      }
      else if(S.at(i) == 'G'){
        bG++;
      }
      else{
        bB++;
      }
    }
    for(int i=j+1; i<N; i++){
      if(S.at(i) == 'R'){
        aR++;
      }
      else if(S.at(i) == 'G'){
        aG++;
      }
      else{
        aB++;
      }
    }
    for(int i=1; i<=min(j,N-j-1); i++){
      if(S.at(j-i) != S.at(j) && S.at(j) != S.at(j+i) && S.at(j+i) != S.at(j-i)){
        minus++;
      }
    }
    if(S.at(j) == 'R'){
      ans += aG*bB + aB*bG - minus;
    }
    else if(S.at(j) == 'G'){
      ans += aR*bB + aB*bR- minus;
    }
    else{
      ans += aR*bG + aG*bR - minus;
    }
  }
  cout << ans << endl;
}



Measured memory_bytes: 3628
# coding: utf-8
# Your code here!
import sys
read = sys.stdin.read
readline = sys.stdin.readline

#a,b,c,d = map(int,readline().split())
s,k = readline().split()


a = [len(i) for i in s.split("0")]
while a and a[-1] == 0: a.pop()

if not a:
    print(1)
    exit()

MOD = 998244353

M = sum(a)+1
k = min(int(k),M)


dp = [[0]*M for _ in range(k+1)] # j 使って（上限 k）、l 余ってる
dp[0][0] = 1

#print(a)
for ai in a[::-1]:
    ndp = [[0]*M for _ in range(k+1)] # j 使って（上限 k）、l 余ってる
    for j in range(k+1):
        for l in range(M):
            for ll in range(l):
                ndp[j][ll] += dp[j][l]
                ndp[j][ll] %= MOD
            
            V = min(M-l,k-j+1,ai+1)
            for i in range(V):
                #if j+i > k: break
                ndp[j+i][l+i] += dp[j][l]
                ndp[j+i][l+i] %= MOD
    
    dp = ndp
    #print(dp)

ans = 0
for jj in range(k+1):
    ans += dp[jj][0]

print(ans%MOD)







Measured memory_bytes: 86376
#include <bits/stdc++.h> 
using namespace std; 
int gi() { 
	int res = 0, w = 1; 
	char ch = getchar(); 
	while (ch != '-' && !isdigit(ch)) ch = getchar(); 
	if (ch == '-') w = -1, ch = getchar(); 
	while (isdigit(ch)) res = res * 10 + ch - '0', ch = getchar(); 
	return res * w; 
} 
typedef long long LL; 
const int MAX_N = 2e5 + 5; 
int N, K, B[MAX_N]; 
int L[MAX_N], R[MAX_N]; 
int o[MAX_N << 2], cnt;
LL A[MAX_N]; 
#define lson (o << 1)
#define rson (o << 1 | 1)
int val[MAX_N << 3], tag[MAX_N << 3]; 
void puttag(int o, int v) { tag[o] = val[o] = v; } 
void pushdown(int o) {
	if (!tag[o]) return ; 
	puttag(lson, tag[o]), puttag(rson, tag[o]); 
	tag[o] = 0; 
} 
void modify(int o, int l, int r, int ql, int qr, int v) {
	if (ql > qr) return ; 
	if (ql <= l && r <= qr) return puttag(o, v); 
	pushdown(o); 
	int mid = (l + r) >> 1; 
	if (ql <= mid) modify(lson, l, mid, ql, qr, v); 
	if (qr > mid) modify(rson, mid + 1, r, ql, qr, v); 
} 
int query(int o, int l, int r, int pos) { 
	if (l == r) return val[o]; 
	pushdown(o); 
	int mid = (l + r) >> 1; 
	if (pos <= mid) return query(lson, l, mid, pos); 
	else return query(rson, mid + 1, r, pos); 
} 
LL f[MAX_N << 1]; 
LL trans(int pos) { 
	int x = query(1, 1, cnt, pos); 
	return x ? f[x] + (o[pos] - o[R[x]] + K) % K : 0; 
} 
int main () { 
#ifndef ONLINE_JUDGE 
    freopen("cpp.in", "r", stdin); 
#endif 
	N = gi(), K = gi(); 
	for (int i = 1; i <= N; i++) { 
		int a = gi(); A[i] = A[i - 1] + a, B[i] = gi();
		if (B[i] == 1 && 2 * a > K) return puts("-1") & 0; 
		if (B[i] == 1) L[i] = (-2 * A[i - 1] % K + K) % K, R[i] = (-2 * A[i] % K + K) % K;
		else L[i] = 0, R[i] = K - 1; 
	} 
	for (int i = 1; i <= N; i++) o[++cnt] = L[i], o[++cnt] = R[i], o[++cnt] = L[i] - 1, o[++cnt] = R[i] + 1; 
	sort(&o[1], &o[cnt + 1]); cnt = unique(&o[1], &o[cnt + 1]) - o - 1; 
	for (int i = 1; i <= N; i++) { 
		L[i] = lower_bound(&o[1], &o[cnt + 1], L[i]) - o; 
		R[i] = lower_bound(&o[1], &o[cnt + 1], R[i]) - o; 
		f[i] = trans(R[i]); 
		if (L[i] > R[i]) modify(1, 1, cnt, R[i] + 1, L[i] - 1, i); 
		else modify(1, 1, cnt, 1, L[i] - 1, i), modify(1, 1, cnt, R[i] + 1, cnt, i); 
	} 
	LL ans = 1e18;
	for (int i = 1; i <= cnt; i++) ans = min(ans, trans(i));
	printf("%lld\n", 2 * A[N] + ans); 
    return 0; 
} 

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

int main() {
	int A, B, C, D; cin >> A >> B >> C >> D;
	int i = 0;
	while (A > 0 && C > 0) {
		if (i % 2 == 0)C -= B;
		else A -= D;
		i++;
	}
	if (A <= 0)cout << "No";
	else cout << "Yes";
}


Measured memory_bytes: 3636
import sys

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


class UnionFind:
    # Reference: https://note.nkmk.me/python-union-find/
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())


def main():
    N, M = map(int, readline().split())
    AB = [[int(s) - 1 for s in line.split()] for line in readlines()]

    ans = 0
    for i in range(M):
        uf = UnionFind(N)
        for j, (a, b) in enumerate(AB):
            if i == j:
                continue
            uf.union(a, b)
        if uf.group_count() > 1:
            ans += 1

    print(ans)
    return


if __name__ == '__main__':
    main()


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

def dfs(s):
    if int(s)>N:
        return 0
    
    if all(s.count(c)>0 for c in "753"):
        ret=1
    else:
        ret=0

    for c in "753":
        ret+=dfs(s+c)
    return ret

print(dfs("0"))

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

int main(){
    int W,H,x,y,r;
    bool flag = true;
    cin >> W >> H >> x >> y >> r;
    
    if(x-r < 0 || x + r > W || y-r < 0 || y+r > H) flag = false;
    
    if(flag) cout << "Yes\n";
    else cout << "No\n";
    
    return 0;
}


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

int main() {
  int D ;
  int T ;
  int S ;
  
  cin >> D;
  cin >> T;
  cin >> S;
  
  if (T*S < D ) {
    cout << "No" << endl;
  }
  else if (T*S >= D) {
    cout << "Yes" << endl;
  }
}


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

int main(){
    int n,m;
    cin >> n >> m;
    vector <int> v[n];
    vector <int> l;
    for(int i=0;i<m;i++){
        int a,b;
        scanf("%d %d",&a,&b);
        v[a-1].push_back(b-1);
        v[b-1].push_back(a-1);
    }
    for(int i=1;i<n;i++){
        l.push_back(i);
    }
    
    int ans=0;


    do{
        bool z=true;
        int save=0;
        for(int x : l){
            auto result=find(v[save].begin(), v[save].end(),x);
            if(result == v[save].end()){
                z=false;
                break;
            }
            else{
                save=x;
                continue;
            }
        }
        if(z) ans++;
    }while(next_permutation(l.begin(),l.end()));

    cout << ans << "\n";



}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/priority_queue.hpp>
#define lp(i, l, r) for (int i = l; i <= r; ++i)
#define rp(i, r, l) for (int i = r; i >= l; --i)
#define ls(i, s) for (int i = 0; s[i]; ++i)
#define rs(i, s) for (int i = strlen(s) - 1; i >= 0; --i)
#define lv(i, a) for (int i = 0; i < a.size(); ++i)
#define rv(i, a) for (int i = (int)a.size() - 1; i >= 0; --i)
#define in(a) int a = (cin >> a, a)
#define ou(a) cout << a << endl
#define fast ios::sync_with_stdio(0), cin.tie(0)
#define prec(a) cout << setprecision(a) << fixed
#define appl(f, a) for (auto i = begin(a); i != end(a); f, ++i)
#define many for (int T = -1; T < 0 && cin >> T, T--;)
#define rang(a) begin(a), end(a)
#define gene template <class T>
#define endl '\n'
#define asse assert
using namespace std;
using namespace __gnu_pbds;
gene void sort(T &a) { sort(rang(a)); }
gene void reve(T &a) { reverse(rang(a)); }
gene void uniq(T &a) { sort(a), a.erase(unique(rang(a)), end(a)); }
gene void shuf(T &a) { random_shuffle(rang(a)); }
gene void merg(T l, T m, T r) { inplace_merge(l, m, r); }
gene auto gath(const T &a, const vector<int> &b) {
    vector<typename T::value_type> r;
    for (auto i : b)
        r.push_back(a[i]);
    return r;
}
gene auto min(const T &a) { return *min_element(rang(a)); }
gene auto max(const T &a) { return *max_element(rang(a)); }
gene auto sum(const T &a) { return accumulate(rang(a), 0); }
gene T inf() { return numeric_limits<T>::max(); }
gene int tmin(T &a, T b) { return b < a ? a = b, 1 : 0; }
gene int tmax(T &a, T b) { return b > a ? a = b, 1 : 0; }
gene using bbst =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
gene using heap = __gnu_pbds::priority_queue<T, greater<T>, pairing_heap_tag>;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
template <class F, class S> auto &operator>>(istream &s, pair<F, S> &a) {
    return s >> a.first >> a.second;
}
gene auto &operator>>(istream &s, vector<T> &a) {
    for (int i = -1; i < 0 && (!a.size() && (cin >> i, a.resize(i), 0), i = 0),
             i < a.size();)
        s >> a[i++];
    return s;
}
template <class F, class S> auto &operator<<(ostream &s, const pair<F, S> &a) {
    return s << '(' << a.first << ", " << a.second << ')';
}
gene auto &operator<<(ostream &s, const vector<T> &a) {
    lv(i, a) cout << a[i] << (i + 1 == a.size() ? "" : " ");
    return s;
}
int main() {
    fast, prec(12);
    int n;
    cin >> n;
    vpii a;
    lp(i, 1, n) {
        int x, l;
        cin >> x >> l;
        a.emplace_back(x + l, x - l);
    }
    sort(a);
    int ans = 0;
    int cur = -inf<int>();
    // for (auto [r, l] : a) {
    for (auto seg : a) {
        int l = seg.second, r = seg.first;
        if (l >= cur) {
            ++ans;
            cur = r;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1400
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <utility>
#include <algorithm>
#include <numeric>
#include <typeinfo>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define debug(n) cout<<__FILE__<<","<<__LINE__<<": #"<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();i++)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;

int main()
{
	int tc;cin>>tc;
	while(tc--){
		string s;
		cin>>s;
		deque<char> res;
		int pos=0;
		res.push_back(s[0]);
		for(int i=3;i<s.size();i+=3){
			if(s[i-1]=='>')
				pos++;
			else
				pos--;
			if(pos==-1){
				pos=0;
				res.push_front(s[i]);
			}
			else if(pos==res.size())
				res.push_back(s[i]);
		}
		rep(i,res.size())
			cout<<res[i]<<(i==res.size()-1?"\n":"");
	}
	
	return 0;
}

Measured memory_bytes: 0
#include <stdio.h>
#include <iostream>
int main() {
    int n,k,count;
    scanf("%d", &n);
    scanf("%d", &k);

    int div;
    count = 0;

    while(n != 0) {
        n = n/k;
        count++;
    }

    printf("%d", count);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
#define MAX 200000
bool isP[MAX];
vector<int> primes;
void make_table(){
  for(int i=0;i<MAX;i++)isP[i]=true;
  isP[0]=isP[1]=false;
  for(int i=2;i*i<MAX;i++){
    if(!isP[i])continue;
    for(int j=i*i;j<MAX;j+=i)isP[j]=false;
  }
  for(int i=0;i<MAX;i++)
    if(isP[i])primes.push_back(i);
}

int N,P;
int main(){
  make_table();
  vector<int> :: iterator it;
  while(1){
    cin>>N>>P;
    if(N==-1&&P==-1)break;
    it=upper_bound(primes.begin(),primes.end(),N);
    //cout<<*it<<endl;
    vector<int> t,u;
    for(int i=0;i<100;i++,it++){
      t.push_back(*it);
      for(int j=0;j<=i;j++)u.push_back(t[j]+t[i]);
    }
    sort(u.begin(),u.end());
    cout<<u[P-1]<<endl;
  }
  return 0;
}

Measured memory_bytes: 1544
// luogu-judger-enable-o2
#include<bits/stdc++.h>
#define reg register
#define ll long long
#define inf 0x3f3f3f3f
#define mod 1000000007
using namespace std;
string s;
int main()
{
    cin>>s;
    cout<<s.substr(0,s.length()-8)<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
  int n, l;
  scanf("%d%d", &n, &l);
  if (l<=0 && l+n-1>=0) {
    printf("%d\n", n*(2*l+n-1)/2);
  } else if (l>0) {
    printf("%d\n", (n-1)*(2*l+n)/2);
  } else {
    printf("%d\n", (n-1)*(2*l+n-2)/2);
  }
  return 0;
}


Measured memory_bytes: 128
import           Control.Monad
import           Data.Array.ST
import           Data.Array.Unboxed    (UArray)
import qualified Data.Array.Unboxed    as U
import qualified Data.ByteString.Char8 as BS
import           Data.Char
import           Data.List

getAsInt :: IO [Int]
getAsInt =  unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine

getAsIntLine :: Int -> IO [[Int]]
getAsIntLine n = replicateM n getAsInt

getAsIntArray2D :: Int -> Int -> IO (UArray (Int,Int) Int)
getAsIntArray2D n m = U.listArray ((1,1),(n,m)) . concat <$> getAsIntLine n


main :: IO ()
main = main2

main1 :: IO ()
main1 = do
  [n,w] <- getAsInt
  wvs <- getAsIntArray2D n 2
  let result = solve1 wvs n w
  print $ maximum $ map (\x -> result U.! (n,x)) [0..w]

main2 :: IO ()
main2 = do
  [n,w] <- getAsInt
  wvs <- map (\[x,y] -> (x, y)) <$> getAsIntLine n
  let solve = solve3
      result = solve w wvs
  print $ maximum $ map (\x -> result U.! x) [0..w]

solve1 :: UArray (Int,Int) Int -> Int -> Int -> UArray (Int,Int) Int
solve1 wvs n' w' = runSTUArray $ do
  dp <- newArray ((0,0),(n',w')) 0
  forM_ [(n_,w_) | n_ <- [1..n'], w_ <- [0..w']] $ \(n,w) -> do
    let wtmp = wvs U.! (n,1)
        vtmp = wvs U.! (n,2)
    if w - wtmp < 0
      then readArray dp (n-1,w) >>= writeArray dp (n,w)
      else do
        a <- readArray dp (n-1,w)
        b <- readArray dp (n-1,w-wtmp)
        writeArray dp (n,w) $ max a (b+vtmp)
  return dp

solve2 :: Int -> [(Int,Int)] -> UArray Int Int
solve2 w' [] = U.listArray (0,w') $ repeat 0
solve2 w' ((wtmp,vtmp):xs) = let a = solve2 w' xs
                                 f w = if w - wtmp >= 0
                                       then max (a U.! w) (a U.! (w - wtmp) + vtmp)
                                       else a U.! w
                             in U.array (0,w') [(w, f w) | w <- [0..w']]

solve3 :: Int -> [(Int,Int)] -> UArray Int Int
solve3 w' = foldr f (U.listArray (0,w') $ repeat 0)
  where f (wtmp,vtmp) a = let g w = if w - wtmp >= 0
                                    then max (a U.! w) (a U.! (w - wtmp) + vtmp)
                                    else a U.! w
                          in U.array (0,w') [(w, g w) | w <- [0..w']]


Measured memory_bytes: 90876
# C
K, N = map(int,input().split())
A =list(map(int,input().split()))
l = len(A)
ans = 10**9
for i in range(l):
    if (i == 0):
        ans = min(A[-1] - A[0], A[0] + K - A[1], ans)
    elif (i == l-1):
        ans = min(A[-1] - A[0], A[-2] + K - A[-1], ans)
    else:
        ans = min(K - A[i] + A[i-1], A[i] + K - A[i+1], ans)
print(ans)

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

#define ll long long
#define ar array

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

  ll a, b, c, d;
  cin >> a >> b >> c >> d;
  cout << max({b*c, a*c, a*d, b*d});
}

Measured memory_bytes: 3576
#include<bits/stdc++.h>
#define debug(x) cerr << #x << " = " << x << "\n";
#define debug_v(x) cerr << #x << " ="; for(auto it : x) {cerr << " [" <<  it << "]";} cerr << "\n";
using namespace std;
using ll = long long;
using ld = long double;
const double PI = acos(-1);
const int mod = 1e9 + 7;
const int inf = 1e9 + 100;
const ll inf64 = 2e18;
vector<vector<int>> graph;
vector<int> avel;
void dfs(int a, int parent){
	for(auto x : graph[a]){
		if(x != parent){
			avel[x] += avel[a];
			dfs(x, a);
		}
	}
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cout << fixed << setprecision(20);
	int n, q;
	cin >> n >> q;
	graph.resize(n);
	avel.resize(n);
	for(int i = 0;i < n - 1;++i){
		int u, v;
		cin >> u >> v;
		--u;
		--v;
		graph[u].push_back(v);
		graph[v].push_back(u);
	}
	for(int i = 0;i < q;++i){
		int p, x;
		cin >> p >> x;
		--p;
		avel[p] += x;
	}
	dfs(0, -1);
	for(int i = 0;i < n;++i){
		cout << avel[i] << '\n';
	}
	return 0;
	
}


Measured memory_bytes: 23552
use std::io::prelude::*;

fn input<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

fn main() {
    let n: i32 = input();
    let k: i32 = input();

    let mut ans = k;
    for _ in 1..n {
        ans *= k - 1;
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <array>

#define REP(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;

const int INF = 100000000;

int main() {
  while(1){
    int n,m,p[3];
    cin>>n>>m>>p[0]>>p[1]>>p[2];
    if(!n)break;
    REP(i,3)--p[i];
    int d[100][100];
    REP(i,n)REP(j,n)d[i][j]=INF;
    REP(i,m){
      int b1,b2,c;
      cin>>b1>>b2>>c;
      --b1;--b2;
      d[b1][b2]=c;
    }
    REP(i,n)
      d[i][i]=0;
    REP(k,n)REP(i,n)REP(j,n)
      d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
    int dmin=INF;
    REP(i,n){
      int sum=0;
      sum+=d[p[0]][i];
      sum+=d[i][p[1]];
      sum+=d[i][p[2]];
      dmin=min(dmin,sum);
    }
    cout<<dmin<<endl;
  }
  return 0;
}

Measured memory_bytes: 1200
N, M = map(int, input().split())
H = list(map(int, input().split()))

lst = [0] * N # 隣接する展望台の最大値を格納するリスト

for i in range(M):
    A, B = map(int, input().split())
    lst[A-1] = max(lst[A-1], H[B-1]) # i番目の隣接する展望台の最大値と、Bの展望台の高さを比較
    lst[B-1] = max(lst[B-1], H[A-1])


ans = 0 #良い展望台を数える
for j in range(N):
    if H[j] > lst[j]: #もし隣接する展望台の最大値よりも、i番目の展望台が大きかったら
        ans += 1

print(ans)

Measured memory_bytes: 20124
#include <cstring>
#include <sstream>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>
#include <stack>

using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto i:mp)
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll half_inf = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);
typedef pair<ll, ll> P;
typedef map<pair<ll, ll>, ll> ump;

ump mp;
ll n, k, l;
const ll MAX_V = 2 * half_inf;

vector<ll> G_k[MAX_V];
bool see_k[MAX_V];
ll num_k[MAX_V];
vector<ll> G_l[MAX_V];
bool see_l[MAX_V];
ll num_l[MAX_V];

void dfs_k(ll s, ll num) {
    see_k[s] = true;
    num_k[s] = num;
    rep(i, G_k[s].size()) {
        if (!see_k[G_k[s][i]]) dfs_k(G_k[s][i], num);
    }
}

void dfs_l(ll s, ll num) {
    see_l[s] = true;
    num_l[s] = num;
    rep(i, G_l[s].size()) {
        if (!see_l[G_l[s][i]]) dfs_l(G_l[s][i], num);
    }
}

void solve() {
    ll nk = 1;
    rep(i, n) {
        if (!see_k[i]) {
            dfs_k(i, nk);
            nk++;
        }
    }
    ll nl = 1;
    rep(i, n) {
        if (!see_l[i]) {
            dfs_l(i, nl);
            nl++;
        }
    }

    rep(i, n) mp[make_pair(num_k[i], num_l[i])]++;
    rep(i, n) {
        printf("%d ", mp[make_pair(num_k[i], num_l[i])]);
    }
}

int main() {
#ifdef MY_DEBUG
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmissing-noreturn"
    while (true) {
        mp = ump();
#pragma clang diagnostic pop
#endif
        cin >> n >> k >> l;
        rep(i, k) {
            ll p, q;
            cin >> p >> q;
            p--, q--;
            G_k[p].emplace_back(q);
            G_k[q].emplace_back(p);
        }

        rep(i, l) {
            ll r, s;
            cin >> r >> s;
            r--, s--;
            G_l[r].emplace_back(s);
            G_l[s].emplace_back(r);
        }

        solve();

#ifdef MY_DEBUG
    }
#endif
    return 0;
}

Measured memory_bytes: 30848
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <stack>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <stdio.h>
#include <math.h>


using namespace std;

typedef long long ll;

typedef vector<vector<int>> vvi;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<ll> vll;

typedef pair<int, int> P;
#define mp(x, y) make_pair(x, y)

typedef queue<int> qi;
typedef queue<string> qs;


#define rep(i, n) for(int i=0; i<(n); ++i)
#define repp(i, a, b) for(int i = (a); i <= (b); i++)
#define repm(i, n) for(int i=n; i >= 0; i--)

#define all(v) v.begin(), v.end()
//sort( all(v) )　などと使える

int D;
vector<int> c(26);
vvi s;
vi T;
vvi last;

int manzoku = 0;


int main(void) {
    cin >> D;
    rep(i, 26) cin >> c[i];
    
    s.resize(D, vi(26));
    //i日目にAjCをやるとs_ij 満足度が上がるよ
    rep(i, D) rep(j, 26) {
        int int_s; cin >> int_s;
        s[i][j] = int_s;
    }


    
    last.resize(D+1 , vi(26));
    rep(i, 26) last[0][i] = 0;


    //d日目にAjCをやるよ
    rep(d, D) {
        int i; cin >> i;
        i--;
        last[d+1][i] = d+1;

        manzoku += s[d][i];

        rep(j, 26) {
            if (j == i) continue;
            last[d+1][j] = last[d][j];

            manzoku -= (d+1 - last[d+1][j]) * c[j];
        }

        cout << manzoku << endl;
    }

 }

Measured memory_bytes: 3724
/*************************************************************************
    > File Name: test.cpp
    > Author: Akira 
    > Mail: qaq.febr2.qaq@gmail.com 
 ************************************************************************/

#include<bits/stdc++.h>
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
#define MST(a,b) memset(a,b,sizeof(a))
#define CLR(a) MST(a,0)
#define Sqr(a) ((a)*(a))
using namespace std;

#define MaxN 100001
#define MaxM MaxN*10
#define INF 0x3f3f3f3f
#define PI 3.1415926535897932384626
const int mod = 1E9+7;
const double eps = 1e-6;
#define bug cout<<88888888<<endl;
#define debug(x) cout << #x" = " << x << endl;

int main()
{
    std::ios::sync_with_stdio(false);
    string str;
    cin >> str;
    str[5] = ' ', str[13] = ' ';
    cout << str << endl;
    //system("pause");
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public void main(Scanner sc) {
        int n = sc.nextInt();
        long x = sc.nextInt();
        long a[] = new long[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }

        long b[] = new long[n];
        Arrays.fill(b, Long.MAX_VALUE);

        long ans = n * 1000000000L;
        for (int magic = 0; magic < n; magic++) {
            for (int i = 0; i < n; i++) {
                b[i] = Math.min(b[i], a[(i + n - magic) % n]);
            }
            ans = Math.min(ans, magic * x + Arrays.stream(b).sum());
        }

        System.out.println(ans);
    }

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


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

struct grid {
    ll x;
    ll y;
};
struct maze {
    grid g;
    ll cost;
};
array<grid, 4> dirs = { { { -1, 0 }, { 1, 0 }, { 0, -1 }, { 0, 1 } } };

void main_()
{
    ll H, W;
    cin >> H >> W;
    vector<string> As;
    As.emplace_back(W + 2, '#');
    for (ll i = 0; i < H; i++) {
        string A;
        cin >> A;
        As.push_back('#' + A + '#');
    }
    As.emplace_back(W + 2, '#');

    queue<maze> que;
    for (ll i = 1; i <= H; i++) {
        for (ll j = 1; j <= W; j++) {
            if (As[i][j] == '#') {
                que.push({ { j, i }, 0 });
            }
        }
    }

    ll ans = 0;
    while (!que.empty()) {
        auto q = que.front();
        que.pop();
        ans = max(ans, q.cost);
        for (auto&& d : dirs) {
            auto nx = q.g.x + d.x;
            auto ny = q.g.y + d.y;
            if (As[ny][nx] != '#') {
                que.push({ { nx, ny }, q.cost + 1 });
                As[ny][nx] = '#';
            }
        }
    }
    cout << ans << endl;
}
int main()
{
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios_base::sync_with_stdio(false);
    main_();
    return 0;
}


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

#define INF_LL (ll)1e18
#define INF (int)1e9
#define REP(i, n) for(int i = 0;i < (n);i++)
#define FOR(i, a, b) for(int i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
using ll = long long;
using PII = pair<int, int>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

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

	long double Q, H, S, D;
	ll N;
	cin >> Q >> H >> S >> D;
	cin >> N;
	ll res=  0;
	Q *= 4; H *= 2; D /= 2;
	if(D < min(H, min(S, Q))){
		res += D*(N-N%2);
		N %= 2;
	}
	if(S < min(H, Q)){
		res += S*N;
		N = 0;
	}
	if(H < Q){
		res += H*N;
		N = 0;
	}
	res += N*Q;
	cout << res << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))

//辺の情報を個別に持つタイプ
typedef struct edge{ll s,g;}E;
typedef struct graph{
	int vcnt,ecnt;
	E  e[200010];//適宜変える(ecnt)
	int id[100010];//適宜変える(vcnt)
}G;
G g;

int esort(const void*a,const void*b){
	E*p=(E*)a,*q=(E*)b;
	if((*p).s<(*q).s)return -1;
	if((*p).s>(*q).s)return  1;
	if((*p).g<(*q).g)return -1;
	return 1;
}
void readgraph(){
	//適宜変える
	ll n,m;
	scanf("%lld%lld",&n,&m);
	rep(i,0,m){
		ll x,y,c;
		scanf("%lld%lld",&x,&y);
		x--,y--;
		g.e[i].s=x;
		g.e[i].g=y;
	}
	g.vcnt=n;
	g.ecnt=m;
	qsort(g.e,g.ecnt,sizeof(E),esort);

	int p=0;
	rep(i,0,g.vcnt){
		while(p<g.ecnt&&g.e[p].s<i)p++;
		g.id[i]=p;
	}
	g.id[g.vcnt]=g.ecnt;//番兵
}

double dp[610];
double ans=1e100;
void f(int k){
	//kから出るworstを潰す
	if(k!=g.vcnt-1&&g.id[k]+1==g.id[k+1]){
		//kから出る通路が1本
		return;
	}
	
	for(int v=g.vcnt-2;v>=0;v--){
		double s=0,cnt=0,M=0;
		for(int i=g.id[v];i<g.id[v+1];i++){
			s+=dp[g.e[i].g];
			cnt++;
			M=max(M,dp[g.e[i].g]);
		}
		if(v==k){
			//塞ぐ
			s-=M;
			cnt--;
		}
		if(cnt==0)printf("%d ",v);
		dp[v]=s/cnt+1;
	}
	ans=min(ans,dp[0]);
	
}

int main(){
	readgraph();
	for(int i=g.vcnt-1;i>=0;i--)f(i);
	printf("%.9f",ans);
}

Measured memory_bytes: 5756