akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;

static const int MOD = 998244353;

long long Inv(long long a) {
        long long res = 1;
        long long n = MOD - 2;
        while (n > 0) {
                if (n & 1) res = res * a % MOD;
                a = a * a % MOD;
                n >>= 1;
        }
        return res;
}
const int N = 5000001;
long long fact[N];
long long invfact[N];
void init() {
        fact[0] = 1;
        for (int i = 1; i < N; i ++) fact[i] = fact[i - 1] * i % MOD;
        for (int i = 0; i < N; i ++) invfact[i] = Inv(fact[i]);
}
long long C(long long n, long long r) {
        if (n < 0 || r < 0 || n < r) return 0;
        return fact[n] * invfact[n - r] % MOD * invfact[r] % MOD;
}

int main() {
        init();
        int n, m;
        scanf("%d%d", &n, &m);
        if (n < m) swap(n, m);
        long long ans = 0;
        for (int i = 1; i <= m; i ++) {
                long long mul = C(2 * i, i) % MOD;
                mul = mul * C(n + m - 2 * i, n - i) % MOD;
                ans = (ans + mul) % MOD;
        }
        ans = ans * Inv(2 * C(n + m, n)) % MOD;
        ans = (ans + n) % MOD;
        printf("%lld\n", ans);
        return 0;
}


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

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

	int tp = 0;
	string s;
	cin >> s;
	for (int i = 0; i < s.size(); ++i){
		if (s[i] == 'p'){
			tp++;
		}
	}
	cout << s.size()/2 - tp << "\n";
	return 0;
}

Measured memory_bytes: 512
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}


fn main() {
    let a: u32 = read();
    let b: u32 = read();
    if (a * b) % 2 == 1 {
        println!("Odd");
    } else {
        println!("Even");
    }
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
#define int long long
using namespace std;
template<class T> inline bool chmax(T& a, T b){ if(a<b){ a=b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b){ if(a>b){ a=b; return 1; } return 0; }


signed main()
{   
    int N; cin>>N;
    vector<int> v;
    int ans=0;
    for(int i=0;i<N;i++){
        int a,b; cin>>a>>b;
        v.push_back(a+b);
        ans-=b;
    }
    sort(v.rbegin(),v.rend());
 
    for(int i=0;i<(N+1)/2;i++){
        ans+=v[i*2];
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 1400
#include <stdio.h>
#include <cmath>
#include <bits/stdc++.h>



using namespace std;

typedef vector<int> VI;
typedef vector<string> VS;


//container util
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)



int main(void){

	int N; cin >> N;

	REP(i,26){
		REP(j,15){
			if(i*4+j*7 == N){
				cout << "Yes" << endl;
				return 0;
			}

		}
	}

	cout << "No" << endl;

	return 0;

}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int n, a[200005] = {}, d[200005] = {};
    vector<pii> b;
    cin >> n;
    ll z = n;
    for (int i = 1; i <= n; i++) cin >> a[i];
    for (int i = 1; i <= n; i++) if (a[i]) b.push_back({a[i], i});
    for (int i = 0; i < b.size(); i++) {
        int c = b[i].first;
        for (int j = i + 1; j <= b.size(); j++) {
            if (j == (int)b.size()) {
                z += n - b[i].second;
                d[b[i].second] = n - b[i].second;
                break;
            }
            if (c & b[j].first) {
                z += b[j].second - b[i].second - 1;
                d[b[i].second] = b[j].second - b[i].second - 1;
                break;
            }
            c |= b[j].first;
        }
    }
    d[n + 1] = -1;
    for (int i = n; i; i--) if (!a[i]) d[i] = d[i + 1] + 1, z += d[i];
    cout << z;
}


Measured memory_bytes: 3956
#include <iostream>
#include <vector>

using namespace std;

int solve (vector<int> &v) {
  int n = v.size();

  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (((n - 1) | i) == n - 1) {
      ans ^= v[i];
    }
  }

  return ans;
}

int main () {
  ios::sync_with_stdio(false);

  int n;
  cin >> n;

  int flag = 0;
  
  vector<int> arr (n);
  for (int i = 0; i < n; i++) {
    char c;
    cin >> c;

    arr[i] = c - '1';
    if (arr[i] == 1) flag = 1;
  }

  if (flag) {
    // convert 2 -> 0
    for (int i = 0; i < n; i++) {
      arr[i] %= 2;
    }
    cout << solve(arr) << endl;
  } else {
    // convert 2 -> 1;
    for (int i = 0; i < n; i++) {
      arr[i] /= 2;
    }
    cout << 2 * solve(arr) << endl;
  }
}


Measured memory_bytes: 4224
use std::fs;
use std::io::{stdin, Read};

macro_rules! parse {
    ($it: ident) => {
        $it.next().unwrap().parse().unwrap()
    };
    ($it: ident,2) => {
        (parse!($it), parse!($it))
    };
    ($it: ident,3) => {
        (parse!($it), parse!($it), parse!($it))
    };
    ($it: ident,4) => {
        (parse!($it), parse!($it), parse!($it), parse!($it))
    };
    ($it: ident, $n: expr) => {
        (&mut $it).take($n).map(|e| e.parse().unwrap()).collect();
    };
}

fn solve(s: &str) {
    let mut it = s.split_whitespace();
    let (k, n): (usize, usize) = parse!(it, 2);
    let a: Vec<usize> = parse!(it, n);
    let mut ret = std::usize::MAX;
    for i in 0..n {
        let start = a[i];
        let end = if i == 0 { a[n - 1] } else { a[i - 1] + k };
        ret = std::cmp::min(ret, end - start)
    }
    println!("{}", ret);
}

fn main() {
    let mut s = String::new();
    stdin().read_to_string(&mut s).unwrap();
    solve(&s);
}

#[cfg(test)]
mod tests {
    use super::*;
    #[test]
    fn test_input() {
        let s = "
        ";
        solve(s);
    }
}


Measured memory_bytes: 10492
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val hList = readLine()!!.split(' ').map(String::toLong).reversed().toMutableList()

    for (i in 0 until n - 1) {
        if (hList[i] + 1 < hList[i + 1]) {
            println("No")
            return
        } else if (hList[i] < hList[i + 1]) {
            hList[i + 1] = hList[i + 1] - 1
        }
    }
    println("Yes")
}


Measured memory_bytes: 59616
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <unordered_map>
#include <unordered_set>
#include <fstream>
#include <queue>

using namespace std;

typedef unsigned long long ll;


int main() {

    int a, b;
    cin >> a >> b;

    if(a >= 13)
        cout << b;
    else if(a >= 6 && a <= 12)
        cout << b/2;
    else 
        cout << 0;


    return 0;

}

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

int main() {
  int N;
  cin >> N;
  
  vector<int> A(N - 1);
  rep(i, N - 1) cin >> A.at(i);
  
  vector<vector<int>> table (N, vector<int>(0));
  rep(i, N - 1) {
    table.at(A.at(i) - 1).push_back(1);
  }
  
  int sum = 0;
  vector<int> Ans(N);
  rep(i, N) {
    sum = 0;
    rep(j, table.at(i).size()) {
      sum += table.at(i).at(j);
    }
    Ans.at(i) = sum;
  }
  
 
  rep(i, N) {
    cout << Ans.at(i) << endl;
  }
}

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

#define _GLIBCXX_DEBUG

int main() {
  string s, t;
  bool ans = 1;
  cin >> s >> t;

  if(s.size() == t.size()-1) {
    for(int i = 0; i < s.size(); i++) {
        if(s[i] == t[i]) continue;
        else { ans = 0; break; }
    }
  }
  
  else ans = 0;
  
  if(ans == 1) cout << "Yes" << endl;
  else if(ans == 0) cout << "No" << endl; 
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define all(a) a.begin(), a.end()
#define forn(l, r) for(int i = l; i < (r); ++i)
#define F first
#define S second
#define $ ios::sync_with_stdio(0);
///#define int long long int

using namespace std;
using namespace __gnu_pbds;
using ll = long long int;
using ii = pair<int, int>;
using li = pair<ll, int>;
using vi = vector<int>;
using graph = vector<vi>;
using ordered_set = tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll mod =  1000000007;
const int INF = 0x3f3f3f3f;
const int MAXN = 212345;
// const double pi = 3.14159265359;
const double eps = 0.00000001;


int32_t main() {
    $
    int n;
    stack<char> st;
    string s;
    cin >> s;
    n = s.size();
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        if (st.size() && st.top() != s[i]) {
            ans += 2;
            st.pop();
        } else {
            st.push(s[i]);
        }
    }
    cout << ans << '\n';
}   



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

using namespace std;

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

  int n, t;
  cin >> n >> t;
  vector<pair<int, int>> kek(n);
  for (int i = 0; i < n; ++i) {
    cin >> kek[i].first >> kek[i].second;
  }
  sort(kek.begin(), kek.end());
  vector<int> dp(t + 3228);
  for (int i = 0; i < n; ++i) {
    int a = kek[i].first, b = kek[i].second;
    auto ndp = dp;
    for (int j = 0; j < t; ++j) {
      ndp[j + a] = max(ndp[j + a], dp[j] + b);
    }
    dp = ndp;
  }
  cout << *max_element(dp.begin(), dp.end());

  return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<vector>
#include<numeric>
#include<math.h>
#include<algorithm>
#include<iomanip>
using namespace std;

int main() {
	
	int a;
	string s;
	cin >> a;
	cin >> s;

	if (3200 <= a) {
		cout << s << endl;
	}
	else {
		cout << "red" << endl;
	}

	return 0;
}


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

int main() {
  int N;
  cin >> N;
  int sum=0;
  int ai=1;
  while(sum<N){
    sum+=ai;
    ai++;
  }
  int del=sum-N;
  for(int i=1;i<ai;i++){
    if(i!=del)cout << i << endl;
  }
}



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

long long cnt;
int l;
int A[1000000];
int n;
vector<int> G;

void insertionSort(int A[],int n,int g){
for(int i=g;i<n;i++){
int v=A[i];
int j=i-g;
while(j>=0&&A[j]>v){ 
	A[j+g]=A[j];
	j-=g;
	cnt++;
}
	A[j+g]=v;
}
}

void shellSort(int A[],int n){
	for(int h=1; ; ){
		if(h>n)break;
		G.push_back(h);
		h=3*h+1;
	}
	
	for(int i=G.size()-1;i>=0;i--){
		insertionSort(A,n,G[i]);
	}
}

int main(){
	cin>>n;
	for(int i=0;i<n;i++)scanf("%d",&A[i]);
	cnt=0;
	
	shellSort(A,n);
	
	cout<<G.size()<<endl;
	for(int i=G.size()-1;i>=0;i--){
		printf("%d",G[i]);
		if(i)printf(" ");
	}
	printf("\n");
	printf("%d\n",cnt);
	for(int i=0;i<n;i++)printf("%d\n",A[i]);
	
	return 0;
}


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

typedef long long ll;
const int N = 100054;

int n;
int a[N], o[N];
ll ans[N];

inline void down(int &x, const int y) {x > y ? x = y : 0;}

int main() {
	int i, j, k;
	scanf("%d", &n), o[n] = k = n;
	for (i = 0; i < n; ++i) scanf("%d", a + i), o[i] = i;
	std::stable_sort(o, o + n, [] (const int x, const int y) {return a[x] > a[y];});
	for (j = i = 0; i < n; i = j) {
		for (; j < n && a[o[i]] == a[o[j]]; ++j);
		down(k, o[i]), ans[k] += ll(a[o[i]] - a[o[j]]) * j;
	}
	for (i = 0; i < n; ++i) printf("%lld\n", ans[i]);
	return 0;
}

Measured memory_bytes: 2620
import java.util.*; 
 public class Main{
  public static void main (String args[]){
    Scanner sc = new Scanner(System.in);
    
    int n = sc.nextInt();
    int k = sc.nextInt();
    int[] list = new int[n];
    
    for(int i = 0; i < n; i++){
      list[i] = sc.nextInt();
    }
    
    Arrays.sort(list);
    
    int ans = 0;
    for(int i = 0; i < k; i++){
      ans += list[i];
    }
    
    System.out.println(ans);

  }
}

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

using namespace std;
typedef long long ll;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin >> n;
	ll sol=0;
	for(int i=1; i<=n; i++){
		if(i%5!=0 && i%3!=0){
			sol+=i;
		}
	}
	cout << sol << '\n';
	return 0;
}

Measured memory_bytes: 3652
#include <iostream>

using namespace std;

int x, n, n2, n4;

int main()
{
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> x;
        if (x % 4 == 0) {
            n4++;
        } else if (x % 2 == 0) {
            n2++;
        }
    }
    if (n2 > 0) {
        n = n - n2 + 1;
    }
    if (n < 0) {
        cout << "Yes";
    } else if (n / 2 <= n4) {
        cout << "Yes";
    } else {
        cout << "No";
    }
    return 0;
}


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

using namespace std;

const int maxn = 1e5 + 10;

vector < int > g[maxn];
int p[maxn];

bool used[maxn];
int color[maxn];

void dfs(int v) {
	used[v] = true;
	for (int u : g[v]) {
		if (!used[u]) {
			p[u] = v;
			dfs(u);
		}
	}
}

void paint(int v, int c) {
	used[v] = true;
	color[v] = c;
	for (int u : g[v]) {
		if (!used[u] && color[u] == 0)
			paint(u, c);
	}
}

int main() {
	ios_base :: sync_with_stdio(false);
	int n = 0;
	cin >> n;
	for (int i = 0; i < n - 1; i++) {
		int x, y;
		cin >> x >> y;
		x--;
		y--;
		g[x].push_back(y);
		g[y].push_back(x);
	}
	color[0] = 1;
	color[n - 1] = 2;
	dfs(0);
	for (int i = 0; i < n; i++) {
		used[i] = false;
	}
	vector < int > path;
	int v = n - 1;
	while (v != 0) {
		int pv = p[v];
		if (pv == 0)
			break;
		path.push_back(pv);
		v = pv;
	}
	int l = 0;
	int r = path.size() - 1;
	while (l <= r) {
		color[path[r]] = 1;
		r--;
		if (l <= r) {
			color[path[l]] = 2;
			l++;
		}
	}
	for (int i = 0; i < n; i++) {
		if (color[i] != 0)
			paint(i, color[i]);
	}
	int cnt[3] = {};
	for (int i = 0; i < n; i++) {
		cnt[color[i]]++;
	}
	if (cnt[1] == cnt[2]) {
		cout << "Snuke";
		return 0;
	}
	if (cnt[1] < cnt[2]) {
		cout << "Snuke";
		return 0;
	}
	cout << "Fennec";
	return 0;
}

Measured memory_bytes: 10232
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>

#define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
#define fb(i,a,b) for(int (i) = (a); (i) >= (b); --(i))
#define mod 1000000007
#define xx first
#define yy second
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define ll long long
#define pii pair<int,int>


using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>,rb_tree_tag, tree_order_statistics_node_update> ordered_set;/// find_by_order(x)(x+1th) , order_of_key() (strictly less)
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());




int n,k;

ll niz[200005];
vector<ll> poz;
vector<ll> neg;

ll mul(ll x, ll y){
    return ((x%mod) * (y%mod)) % mod;
}

int main()
{

    ios_base::sync_with_stdio(false); cin.tie(0);

    cin >> n >> k;
    int nule = 0;
    ll stap = 1;
    ff(i,0,n - 1){
        cin >> niz[i];
        if(niz[i] < 0)neg.pb(niz[i]);
        else if(niz[i] > 0)poz.pb(niz[i]);
        else if(niz[i] == 0)nule++;
    }
    if(nule > n-k){
        cout << 0 << "\n";
        return 0;
    }
    n = poz.size();
    int m = neg.size();
    sort(neg.begin(), neg.end());
    sort(poz.begin(), poz.end());
    reverse(poz.begin(), poz.end());
    ll tmp = 1;
    int prvi = k - (k%2);
    int drugi = m - (m%2);
    int kolko = min(prvi, drugi);
    if(k - kolko > n){
        if(nule){
            cout << 0 << "\n";
            return 0;
        }
        reverse(neg.begin(), neg.end());
        if(k == n+m){
            ll resres = 1;
            for(auto c:neg)resres = mul(resres, c);
            for(auto c:poz)resres = mul(resres, c);
            if(resres < 0)resres += mod;
            cout << resres << "\n";
            return 0;
        }
        ff(i,0,k - 1)tmp = mul(tmp, neg[i]);
        if(tmp < 0)tmp = tmp + mod;
        cout << tmp << "\n";
        //cout << "wtf\n";
        return 0;
    }
    vector<ll>svi;
    int br1 = 0;
    int br2 = 0;
    if(k%2 == 1){
        tmp = mul(tmp,poz[0]);
        br2++;
    }
    ff(i,br1,m - 2){
        svi.pb(neg[i] * neg[i + 1]);
        i++;
    }
    ff(i,br2,n - 2){
        svi.pb(poz[i] * poz[i + 1]);
        i++;
    }
    //cout << "nigga\n";
    sort(svi.begin(), svi.end());
    reverse(svi.begin(), svi.end());
    //cout << svi.size() << "\n";
    int target = k/2;
    for(auto c:svi)c = c%mod;
    ff(i,0,target - 1)tmp = mul(tmp, svi[i]);
    cout << tmp << "\n";
    return 0;
}


Measured memory_bytes: 8212
/*
ID: anonymo14
TASK: wormhole
LANG: C++                 
*/
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

#define REP(i,a,b) for(int i=a; i<=b; i++)

#define MOD 1000000007

void solve(int test_case) {
	int a,b;
	cin>>a>>b;
	if(a!=1&&b!=1)cout<<1;
	if(a!=2&&b!=2)cout<<2;
	if(a!=3&&b!=3)cout<<3;
}

int main() {
	
	////// FILE BASED IO////
	//freopen("wormhole.in", "r", stdin);
	//freopen("wormhole.out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
	return 0;
}	


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

using namespace std;

int main(){
    int N,Q;
    cin >> N >> Q;

    string S;
    cin >> S;

    int l[Q],r[Q];
    for(int i = 0; i < Q; i++) cin >> l[i] >> r[i];

    int cnt = 0;
  
    int ans[N] = {0};

    for(int i = 1; i < N; i++){
      if( S.at(i-1) == 'A' && S.at(i) == 'C' ) ++cnt;
      ans[i] = cnt;
    }

  
  for(int i = 0; i < Q; i++){
    cout << ans[r[i]-1] - ans[l[i]-1] << endl;
  }

    return 0;
}

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

using namespace std;

int main()
{
	int Q,i,counter;
	string S;
	cin>>S>>Q;
	deque<char> s(S.size());
	for(i=0 ; i<S.size() ; i++)
	{
		s[i]=S[i];
	}
	counter=0;
	for(i=0 ; i<Q ; i++)
	{
		int T,F;
		char C;
		cin>>T;
		if(T==1)
		{
			counter++;
		}
		else if(T==2)
		{
			cin>>F;
			cin>>C;
			if(F==1)
			{
				if(counter%2==0)
				{
					s.push_front(C); //front push
				}
				else if(counter%2==1)
				{
					s.push_back(C); //back push
				}
			}
			else if(F==2)
			{
				if(counter%2==0)
				{
					s.push_back(C); //back push
				}
				else if(counter%2==1)
				{
					s.push_front(C); //front push
				}
			}	
		}
	}
	if(counter%2==1)
	{
		reverse(s.begin(),s.end());
	}
	for(i=0 ; i<s.size() ; i++)
	{
		cout<<s[i];
	}
	return 0;
}

Measured memory_bytes: 896
# -*- coding: utf-8 -*-
from itertools import permutations, combinations
from fractions import gcd
from collections import Counter
from math import sqrt
import sys
input = sys.stdin.readline
def lcm(x, y):
    return (x*y//gcd(x, y))
def small_letters():
    return [chr(i) for i in range(97, 97+26)]
def capital_letters():
    return [chr(i) for i in range(65, 65+26)]


def main():
    """ここに書いてね"""
    N = int(input())
    A_list = [int(input()) for i in range(N)]
    ans = 0
    counter = Counter(A_list)
    for i in counter.values():
        if i % 2 == 1:
            ans += 1
    print(ans)

if __name__ == '__main__':
    main()



Measured memory_bytes: 80344
MOD = None

class Convolution:

    # ROOT = 3
    def __init__(self, mod):
        global MOD
        MOD = mod
        # self.MOD = mod

    def __butterfly(self, arr):
        n = len(arr)
        h = (n - 1).bit_length()
        # MOD = self.MOD
        sum_e = (911660635, 509520358, 369330050, 332049552, 983190778, 123842337, 238493703, 975955924, 603855026, 856644456, 131300601, 842657263, 730768835, 942482514, 806263778, 151565301, 510815449, 503497456, 743006876, 741047443, 56250497, 0, 0, 0, 0, 0, 0, 0, 0, 0)
        for ph in range(1, h + 1):
            w = 1 << (ph - 1)
            p = 1 << (h - ph)
            now = 1
            for s in range(w):
                offset = s << (h - ph + 1)
                for i in range(p):
                    l = arr[i + offset]
                    r = arr[i + offset + p] * now
                    arr[i + offset] = (l + r) % MOD
                    arr[i + offset + p] = (l - r) % MOD
                now *= sum_e[(~s & -~s).bit_length() - 1]
                now %= MOD

    def __butterfly_inv(self, arr):
        n = len(arr)
        h = (n - 1).bit_length()
        # MOD = self.MOD
        sum_ie = (86583718, 372528824, 373294451, 645684063, 112220581, 692852209, 155456985, 797128860, 90816748, 860285882, 927414960, 354738543,
                  109331171, 293255632, 535113200, 308540755, 121186627, 608385704, 438932459, 359477183, 824071951, 0, 0, 0, 0, 0, 0, 0, 0, 0)
        for ph in range(1, h + 1)[::-1]:
            w = 1 << (ph - 1)
            p = 1 << (h - ph)
            inow = 1
            for s in range(w):
                offset = s << (h - ph + 1)
                for i in range(p):
                    l = arr[i + offset]
                    r = arr[i + offset + p]
                    arr[i + offset] = (l + r) % MOD
                    arr[i + offset + p] = (MOD + l - r) * inow % MOD
                inow *= sum_ie[(~s & -~s).bit_length() - 1]
                inow %= MOD

    def __call__(self, a, b):
        n = len(a)
        m = len(b)
        # MOD = self.MOD
        if not n or not m: return []
        if min(n, m) <= 50:
            if n < m:
                n, m = m, n
                a, b = b, a
            res = [0] * (n + m - 1)
            for i in range(n):
                for j in range(m):
                    res[i + j] += a[i] * b[j]
                    res[i + j] %= MOD
            return res
        z = 1 << (n + m - 2).bit_length()
        a += [0] * (z - n)
        b += [0] * (z - m)
        self.__butterfly(a)
        self.__butterfly(b)
        for i in range(z):
            a[i] *= b[i]
            a[i] %= MOD
        self.__butterfly_inv(a)
        a = a[:n + m - 1]
        iz = pow(z, MOD - 2, MOD)
        for i in range(n + m - 1):
            a[i] *= iz
            a[i] %= MOD
        return a




def atcoder_practice2_f():
    import sys
    input = sys.stdin.buffer.readline

    N, M = map(int, input().split())
    A = [int(x) for x in input().split()]
    B = [int(x) for x in input().split()]

    convolution = Convolution(998244353)
    print(*convolution(A, B))


if __name__ == "__main__":
    atcoder_practice2_f()


Measured memory_bytes: 197176
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;
using namespace std;
typedef tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update> oset;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
using ll = long long;

// g > r
// b > g
// 

void test_case(){
	int a ,b , c; cin >> a >> b >> c;
	int k; cin >> k;
	while(k){
		if(a >= b)
			b*=2;
		else if(b >= c)
			c*=2;
		k--; 
	}
	if(c > b && b > a)
		cout<<"Yes\n";
	else
		cout<<"No\n";
	
}
 
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int T=1;
	//~ cin >> T;
	while(T--){
		test_case();
	}
	return 0;
}


Measured memory_bytes: 3636
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;


int main ()
{
	string str , str2;
	vector<string>data;
	while( getline ( cin , str2 ) )
	{

		bool f = 0;
		for( size_t i = 0; i < 26; i++ )
		{

			for( auto &x : str2 )
			{
				if( x <= 'z'&&'a' <= x )
				{
					x -= 'a';
					x += 1;
					x %= 26;
					x += 'a';
				}
			}

			if( str2.find ( "the" ) != string::npos || str2.find ( "this" ) != string::npos || str2.find ( "that" ) != string::npos )
			{
				cout << str2 << endl;
				break;
			}


		}
	}
}

Measured memory_bytes: 1184
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

ans = 0
for i in range(N):
  ans += B[A[i]-1]
  if i>0:
    if A[i]-A[i-1]==1:
      ans += C[A[i-1]-1]

print(ans)

Measured memory_bytes: 3064
a,b,c,x,y=map(int,input().split())
ret=10**10
for i in range(2*max(x,y)+1):
    aleft=max(x-(i//2),0)
    bleft=max(y-(i//2),0)
    ret=min(ret,c*i+aleft*a+bleft*b)
print(ret)

Measured memory_bytes: 3064
#17:43
n = int(input())
mod = 10**9 + 7
s = input()
t = [1]
for i in range(1,n):
  if s[i-1] == s[i]:
    t[-1] += 1
  else:
    t.append(1)
#print(t)
l = len(t)
if t[0] == 2:
  ans = 6
else:
  ans = 3
for j in range(1,l):
  if t[j-1] == 1:
    ans *= 2
    ans %= mod
  elif t[j] == 2:
    ans *= 3
    ans %= mod
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"

ll n, q;
vector<vector<ll>> g;
vector<ll> dp;

void dfs(ll v, ll p = -1) {
    if (p != -1) dp[v] += dp[p];
    for(auto &u : g[v]) {
        if (u == p) continue;
        dfs(u, v);
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    cin >> n >> q;
    g.resize(n);
    rep(i, n - 1) {
        ll a, b;
        cin >> a >> b;
        a--; b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    dp.resize(n, 0);
    rep(i, q) {
        ll p, x;
        cin >> p >> x;
        p--;
        dp[p] += x;
    }
    dfs(0);
    rep(i, n) printf("%lld%s", dp[i], (i == (n - 1)) ? "\n" : " ");
    return 0;
}


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

int main() {
  int N;
  cin >> N;
  long long   ans=0 ;
       
  for (int i=0 ; i<=N ;i++ ){
    if(i%3==0 ||i%5==0 ||i%15==0){
     }
    else{
      ans+= i;
    }
  }
    cout << ans<< endl;
}





Measured memory_bytes: 3504
using System;
using System.Linq;
using System.Collections.Generic;

namespace ABC
{
    class ProgramC
    {
        static void Main(string[] args)
        {
            var inputs = Console.ReadLine().Split(" ");
            var n = int.Parse(inputs[0]);
            var m = int.Parse(inputs[1]);

            var list = new List<int>[m];

            for (var i = 0; i < m; i++)
            {
                var inputs1 = Console.ReadLine().Split(" ").Select(x => int.Parse(x) - 1).ToList();
                inputs1.RemoveAt(0);
                list[i] = inputs1;
            }

            var p = Console.ReadLine().Split(" ").Select(x => int.Parse(x)).ToList();

            var result = 0;

            for (var i = 0; i < (1 << n); i++)
            {
                var r = true;

                for (var j = 0; j < m; j++)
                {
                    var switchs = list[j];
                    var onCount = 0;

                    for (var k = 0; k < switchs.Count; k++)
                    {
                        if (((i >> switchs[k]) & 1) == 1)
                        {
                            onCount++;
                        }
                    }

                    if (!(onCount % 2 == p[j]))
                    {
                        r = false;
                        break;
                    }
                }

                if (r)
                {
                    result++;
                }
            }

            Console.WriteLine(result);
        }
    }
}


Measured memory_bytes: 28260
#include<iostream>
#include<vector>
#include<algorithm>

using ull = unsigned long long;

auto process() {
	ull n, k;
	std::cin >> n >> k;
	std::vector<ull> vec;
	
	for (ull i{}; i < n; i++) {
		ull tmp;
		std::cin >> tmp;
		vec.emplace_back(tmp);
	}

	std::sort(std::rbegin(vec), std::rend(vec));
	
	ull r{ 0 };
	for (ull i{}; i < k; i++) {
		r += vec[i];
	}

	std::cout << r << "\n";
}

int main() {
//	while (true) {
		process();
	//}
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
using namespace std;

int main() {
    int a,b;
    cin >> a >> b;
    if(a == 1) a = 14;
    if(b == 1) b = 14;
    if(a > b) cout << "Alice" << endl;
    else if(a == b) cout << "Draw" << endl;
    else cout << "Bob" << endl;
}

Measured memory_bytes: 256
<?php
list($a, $b, $c) = explode(' ', trim(fgets(STDIN)));

if ($a > $b && $a > $c) {
	echo ($b < $c ? 'Yes' : 'No'), PHP_EOL;
} else if ($a < $b && $a < $c) {
	echo ($c < $b ? 'Yes' : 'No'), PHP_EOL;
} else {
  	echo 'No', PHP_EOL;
}

Measured memory_bytes: 4856
import java.util.Scanner;
public class Main{
public static void main (String [] args) {
int win =0;
Scanner sc = new Scanner(System.in);
String s = sc.nextLine();
for(int j=0; j<s.length();j++) {
if( s.charAt(j) == 'o')
win++; 
}
if(15-s.length()+win >= 8) 
System.out.print("YES");
else
System.out.print("NO");
}
}

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

using namespace std;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1LL<<60;

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

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

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

struct SegmentTree {
private:
  int n;
  vector<ll> node;

public:
    // 元配列 v をセグメント木で表現する
  SegmentTree(vector<ll> v) {
    // 最下段のノード数は元配列のサイズ以上になる最小の 2 冪 -> これを n とおく
    // セグメント木全体で必要なノード数は 2n-1 個である
    int sz = v.size();
    n = 1; while(n < sz) n *= 2;
    node.resize(2*n-1, 0); // 最小値は-1

    // 最下段に値を入れたあとに、下の段から順番に値を入れる
    // 値を入れるには、自分の子の 2 値を参照すれば良い
    for(int i=0; i<sz; i++) node[i+n-1] = v[i];
    for(int i=n-2; i>=0; i--) node[i] = node[2*i+1] + node[2*i+2];
  }

  void update(int x, ll val) {
    // 最下段のノードにアクセスする
    x += (n - 1);

    // 最下段のノードを更新したら、あとは親に上って更新していく
    node[x] = val;
    while(x > 0) {
      x = (x - 1) / 2;
      node[x] = node[2*x+1] + node[2*x+2];
    }
  }

    // 要求区間 [a, b) 中の要素の最大値を答える
    // k := 自分がいるノードのインデックス
    // 対象区間は [l, r) にあたる
  ll getsum(int a, int b, int k=0, int l=0, int r=-1) {
    // 最初に呼び出されたときの対象区間は [0, n)
    if(r < 0) r = n;

    // 要求区間と対象区間が交わらない -> 適当に返す
    if(r <= a || b <= l) return 0;

    // 要求区間が対象区間を完全に被覆 -> 対象区間を答えの計算に使う
    if(a <= l && r <= b) return node[k];

    // 要求区間が対象区間の一部を被覆 -> 子について探索を行う
    // 左側の子を vl ・ 右側の子を vr としている
    // 新しい対象区間は、現在の対象区間を半分に割ったもの
    ll vl = getsum(a, b, 2*k+1, l, (l+r)/2);
    ll vr = getsum(a, b, 2*k+2, (l+r)/2, r);
    return vl + vr;
  }
};

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

  int n;
  ll k;
  cin >> n >> k;

  vector<ll> a(n);
  rep(i, n){
    cin >> a[i];
    a[i] -= k;
  }

  vector<ll> suma(n+1);
  suma[0] = 0;
  rep(i, n){
    suma[i+1] = suma[i] + a[i];
  }

  set<ll> st;
  rep(i, n+1){
    st.insert(suma[i]);
  }

  map<ll, int> mp;
  int ind = 0;
  for(auto val : st){
    mp[val] = ind;
    ind++;
  }

  SegmentTree sg(vector<ll>(n+1, 0));

  ll ans = 0;
  for(int i = n; i >= 0; i--){

    int ind = mp[suma[i]];
    
    ans += sg.getsum(ind, n+1);

    ll val = sg.getsum(ind, ind+1);
    sg.update(ind, val+1);

  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 30976
#include <iostream>
#include <iomanip>
#include<math.h>
#include<list>
#include <algorithm>
#include<set>
#include<vector>
#include<math.h>
#include<map>
#include<string>
#include <numeric>
#include <queue>
#include <sstream>
#include <bitset>
#include<stack>
#include<functional>
#include<unordered_set>
#include<unordered_map>

using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;
const long long ll_max = 9223372036854775807;
const long long ll_min = -9223372036854775807;
const int int_max = 2147483647;

template<typename T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }

template<typename T>
map<T, T> getPrimeFactor(T n) {
	map<T, T> ret;
	for (T i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			ret[i] ++;
			n /= i;
		}
	}
	if (n != 1) ret[n] = 1;
	return ret;
}

template<typename T>
bool IsPrimeNumber(T num)
{
	if (num <= 2) return true;
	else if (num % 2 == 0) return false;

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			return false;
		}
	}

	return true;
}

template<typename T>
T modinv(T a, T m) {
	T b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}



// 繰り返し二乗法
ll pow2(ll n, ll p, ll mod) {
	if (p == 0 || n == 1) {
		return 1;
	}
	else {
		ll ret = pow2(n * n % mod, p / 2, mod);
		if (p % 2 == 1) {
			ret *= n;
		}
		return ret % mod;
	}
}


#define rep(i,s,e) for(ll i=s;i<e;i++)
#define repeq(i,s,e) for(ll i=s;i<=e;i++)

int main() {
	ll X;
	cin >> X;
	if (X == 3 || X == 5 || X == 7) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}

	return 0;
}


Measured memory_bytes: 3516
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;


int N, A[200000];


int main(){
  cin >> N;
  for(int i = 0; i < N; i++){
    cin >> A[i];
    A[i] -= i+1;
  }
  sort(A, A+N);
  int b = A[N/2];
  long long ans = 0;
  for(int i = 0; i < N; i++){
    ans += abs(A[i] - b);
  }
  cout << ans << endl;

}


Measured memory_bytes: 1024
/*#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("fast-math")*/
#include <stdio.h>
#include <bits/stdc++.h>
using namespace std;

#define amen ;
#define vec vector
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define Str(x) to_string(x)
#define len(s) (int)s.size()

typedef long long ll;
typedef double d;
typedef long double lld;
typedef string str;
typedef unsigned long long ull;
typedef unsigned int ui;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int a, b, c;
    cin >>a >> b >> c;
    cout << max(0, c- (a - b));

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


int main(void) {
    int n;
    cin >> n;
    vector<int>pvec;
    vector<int>qvec;

    for(int i = 0; i < n; i++) {
        int p ; cin >> p;
        pvec.push_back(p);
    }
    for(int i = 0; i < n; i++) {
        int q ; cin >> q;
        qvec.push_back(q);
    }

    int a = 0;
    do {
        a++;
    }while(next_permutation(pvec.begin(),pvec.end()));

    int b = 0;
    do {
        b++;
    }while(next_permutation(qvec.begin(),qvec.end()));

    cout << abs(a-b) << endl;

    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <stack>
#include <vector>

int main() {
  int N;
  std::cin >> N;
  std::vector<float> v(N);
  for (int i = 0; i < N; ++i) std::cin >> v[i];
  std::sort(v.begin(), v.end(), std::greater<float>());
  std::stack<float> V;
  for (auto&& e : v) V.push(e);
  for (int i = 0; i < N - 1; i++) {
    float x{V.top()};
    V.pop();
    float y{V.top()};
    V.pop();
    V.push((x + y) / 2);
  }
  std::cout << V.top() << std::endl;
}

Measured memory_bytes: 256
s = gets.chomp

flag = 1
s.length.times do|i|
  if (i%2)==0 then
    if !(s[i]=='R'||s[i]=='U'||s[i]=='D') then
      flag = 0
      break
    end
  else 
    if !(s[i]=='L'||s[i]=='U'||s[i]=='D') then
      flag = 0
      break
    end
  end 
end
if flag ==1 then
  puts "Yes"
else 
  puts "No"
end

Measured memory_bytes: 1916
#include <bits/stdc++.h>
#define REP(i, a, n) for (long long i = (a); i < (long long)(n); ++i)
#define REPC(i, a, n) for (long long i = (a); i <= (long long)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init) \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T>
using VEC = std::vector<T>;
template <class T>
using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail>
void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec) os << v << ",";
  os << "}";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, set<T> &s) {
  os << "{";
  for (auto p : s) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> &m) {
  os << "{";
  for (auto p : m) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}
int N;
string ans = "";
void dfs(int index, char last, map<char, int> &s) {
  // DUMP(index, last,  s, ans);
  if (index == N) {
    cout << ans << "\n";
    return;
  }
  for (auto p : s) {
    char c = p.first;
    int cnt = p.second;
    if (cnt > 0) {
      if (c == last) {
        for (char a = 'a'; a <= last + 1; a++) {
          s[a]++;
        }
        ans.push_back(c);
        dfs(index + 1, last + 1, s);
        ans.pop_back();
        for (char a = 'a'; a <= last + 1; a++) {
          s[a]--;
        }
      } else {
        for (char a = 'a'; a <= last; a++) {
          s[a]++;
        }
        ans.push_back(c);
        dfs(index + 1, last, s);
        ans.pop_back();
        for (char a = 'a'; a <= last; a++) {
          s[a]--;
        }
      }
    }
  }
}

int main() {
  cin >> N;
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  map<char, int> s;
  s['a']++;
  dfs(0, 'a', s);

  return 0;
}


Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ULL;
typedef long long ll;
const int modn=1e9+7;
ll mulit(ll a,ll b,ll m){
    ll ans=0;
    while(b){
        if(b&1) ans=(ans+a)%m;
        a=(a<<1)%m;
        b>>=1;
    }
    return ans;
}

ll quick_mod(ll a,ll b,ll m){
    ll ans=1;
    while(b){
        if(b&1){
            ans=mulit(ans,a,m);
        }
        a=mulit(a,a,m);
        b>>=1;
    }
    return ans;
}

ll comp(ll a,ll b,ll m){
    if(a<b) return 0;
    if(a==b) return 1;
    if(b>a-b) b=a-b;
    ll ans=1,ca=1,cb=1;
    for(int i=0;i<b;i++){
        ca=ca*(a-i)%m;
        cb=cb*(b-i)%m;
    }
    ans=ca*quick_mod(cb,m-2,m)%m;
    return ans;
}

ll lucas(ll a,ll b,ll m){
    ll ans=1;
    while(a&&b){
        ans=(ans*comp(a%m,b%m,m))%m;
        a/=m;
        b/=m;
    }
    return ans;
}
int main(){
	int n,k;
	scanf("%d%d",&n,&k);
	for(int i=1;i<=k;i++){
		printf("%lld\n",lucas(n-k+1,i,modn)*lucas(k-1,i-1,modn)%modn);
	}
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
    int a,b,h,ar,arf;;
    cin>>a>>b>>h;
    if((a>=1 && a<=100) && (b>=1 && b<=100) && (h>=1 && h<=100) && (h%2==0))
    {
        ar=(a+b)*h;
        arf=ar/2;
        cout<< arf;
    }
    return 0;
}


Measured memory_bytes: 256
from numba import jit
@jit
def main():
    n, k = map(int, input().split())
    p = list(map(int, input().split()))
    c = list(map(int, input().split()))
    ans = -10**10
    
    for i in range(n):
        start, count = i, 1
        val = c[start]
        while p[start]-1 != i:
            start = p[start]-1
            count += 1
            val += c[start]

        start = i
        if val > 0:
            a = (k//count-1)*val
            ans = max(a, ans)
            num = k%count+count
        else:
            a = 0
            num = min(k, count)

        for _ in range(num):
            start = p[start]-1
            a += c[start]
            ans = max(a, ans)
    print(int(ans))

main()


Measured memory_bytes: 120320
N = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
g = 0
for i in range(N):
    c = b[i] - min(a[i],b[i])
    g += min(a[i],b[i])
    a[i] -= min(a[i],b[i])
    if c == 0:pass
    else:
        d = c - min(a[i+1],c)
        g += min(a[i+1],c)
        a[i+1] -= min(a[i+1],c)
print(g)

Measured memory_bytes: 18476
#include<iostream>
using namespace std;
int main()
{
	int a[10];
	cin >> a[0] >> a[1] >> a[2] >> a[3] >> a[4];
	int res = 10;
	int last = 0;
	for (int i = 0; i < 5; i++) {
		int b = a[i] % 10;
		if (b < res && b!=0) {
			last = i;
			res = b;
		}
	}
	int sum = 0;
	for (int i = 0; i < 5; i++) {
		if (i != last) {
			sum += ((a[i] - 1 + 10) / 10)*10;
		}
	}
	sum += a[last];
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 256
s=input()+"R"


p=[0]*(len(s)-1)
key=s[0]
strt=0
for i in range(len(s)):

    if key!=s[i]:
        if key=="R":
            p[i]  += (i-strt)//2
            p[i-1] += (i-strt)//2 + (i-strt)%2
            key="L"
        else:
            p[strt] += (i-strt)//2 + (i-strt)%2
            p[strt-1] += (i-strt)//2
            key="R"
        strt=i

for i in p:
    print(i,end=" ")


Measured memory_bytes: 10064
#include <iostream>
#include <tuple>
#include <vector>

int main()
{
    int h, w; std::cin >> h >> w;
    std::vector<std::vector<int>> a(h, std::vector<int>(w, 0));
    std::vector<std::tuple<int, int, int, int>> t;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            std::cin >> a[i][j];
            a[i][j] %= 2;
        }
    }
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w-1; j++) {
            if (a[i][j] == 1) {
                t.push_back(std::make_tuple(i+1, j+1, i+1, j+2));
                a[i][j+1] = (a[i][j+1] + 1) % 2;
                a[i][j] = 0;
            }
        }
    }

    for (int i = 0; i < h-1; i++) {
        if (a[i][w-1] == 1) {
            t.push_back(std::make_tuple(i+1, w, i+2, w));
            a[i+1][w-1] = (a[i+1][w-1] + 1) % 2;
            a[i][w-1] = 0;
        }
    }

    std::cout << t.size() << std::endl;
    for (const auto& tt: t) {
        std::cout
            << std::get<0>(tt) << " "
            << std::get<1>(tt) << " "
            << std::get<2>(tt) << " "
            << std::get<3>(tt) << std::endl;
    }

    return 0;
}


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

int main(){
	int n, l = 0, r = 0;
	string s[10000],t;
	cin >> n;
	for(int i=0;i<n;i++) cin >> s[i];
	cin >> t;
	for(int i=0;i<n;i++){
		string x,y;
		x = y = s[i];
		for(int j=0;j<x.length();j++) if(x[j]=='?') x[j] = 'a';
		for(int j=0;j<y.length();j++) if(y[j]=='?') y[j] = 'z';
		if(t<x) r++;
		else if(y<t) l++;
	}
	for(int i=l+1;i<=n-r+1;i++){
		if(i==n-r+1) cout << i << endl;
		else cout << i << ' ';
	}
}


Measured memory_bytes: 896
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>

int main(int argc, char const *argv[])
{
	int j = 0;
	char s[100],a[100],cf[] = "CF";
	scanf("%s",s);
	for (int i = 0; i < strlen(s); ++i)
	{
		if(s[i] == 'C' || s[i] == 'F')	a[j++] = s[i];
	}
	if(strstr(a,cf) != NULL)	printf("Yes\n");
	else printf("No\n");
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

int a[120];

int main(){
    int n;
    scanf("%d", &n);
    for(int i = 0; i < n; i++) scanf("%d", &a[i]);
    long long res = 0;
    for(int i = 0; i < n - 1; i++){
        for(int j = i + 1; j < n; j++)
            res += (long long) a[i] * a[j];
    }
    printf("%lld\n", res);
}

Measured memory_bytes: 128
from heapq import heappop, heappush
from collections import defaultdict


class Dijkstra:
    """Graph input:
    {
    node:{node:cost,node:cost...},
    node:{node:cost,node:cost...},
    ...
    }
    """

    def __init__(self, graph: dict, N: int):
        self.graph = graph
        self.costs = [float("inf")] * N

    def calculate(self, start):
        queue = list()

        # step1: push the start point into the priority queue
        self.costs[start] = 0
        heappush(queue, (0, start))  # (cost,node)

        while queue:
            # step2: get the minimum cost node from unfixed node and fix the cost
            cost_from_start, min_node = heappop(queue)

            # step3: update the direct connected nodes
            for link, cost in self.graph[min_node].items():
                if cost_from_start + cost < self.costs[link]:
                    self.costs[link] = cost_from_start + cost
                    heappush(queue, (self.costs[link], link))

        return self.costs


n = int(input())
graph = defaultdict(dict)

for _ in range(n):
    data = [int(i) for i in input().split()]
    u = data[0]
    count = data[1]
    for j in range(1, count + 1):
        v = data[2 * j]
        w = data[2 * j + 1]
        graph[u][v] = w

dijkstra = Dijkstra(graph, n)
costs = dijkstra.calculate(0)

for i in range(n):
    print(i, costs[i])



Measured memory_bytes: 50488