akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define RFOR(i,a,b) for (int i = (b-1); i >= (a); i--)
#define REP(i,n) FOR(i,0,(n))
#define RREP(i,n) RFOR(i,0,(n))
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define DEBUG(x)  cout << #x << " = " << (x) << endl;
#define SORT(x) sort(ALL(x));
#define RSORT(x) sort(RALL(x));
#define SUM(x) accumulate(ALL(x),0);
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const ll mod = 1e9+7;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//cout << fixed << setprecision(10);

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

bool f(vector<vector<char>> &s, int i, int j) {
  REP(k,4) {
    if (s[i+dy[k]][j+dx[k]] == '#') return true;
  }
  return false;
}

int main () {
  int H, W; cin >> H >> W;
  vector<vector<char>> s(H+2,vector<char>(W+2, '.'));
  FOR(i,1,H+1) FOR(j,1,W+1) cin >> s[i][j];

  FOR(i,1,H+1) {
    FOR(j,1,W+1) {
      if (s[i][j] == '#') {
        if (!f(s, i, j)) { 
          cout << "No" << endl;
          return 0;
        }
      }
    }
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 256
N = int(input())
S = []
for _ in range(N):
    S.append(input())

import sys
from collections import Counter

count_dict = Counter(S)
most_freq = count_dict.most_common(1)[0][1]

words = []

for word, freq in sorted(count_dict.items(), key=lambda x: -x[1]):
    if freq == most_freq:
        words.append(word)

for word in sorted(words):
    print(word)


Measured memory_bytes: 148368
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000000)
INF = 1<<32


def solve(H: int):
    from math import ceil
    from functools import lru_cache

    @lru_cache(None)
    def f(n: int):
        if 0 < n <= 1:
            return 1
        
        return 1 + f((n//2)) + f((n//2))

    print(f(H))
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    solve(H)

if __name__ == '__main__':
    main()


Measured memory_bytes: 4184
#include <iostream>
#include <stdio.h>
#include <vector>

using namespace std;

int main() {
	int N;

	cin >> N;
	vector<pair<int, int>> ans;
	if (N % 2 == 0) {
		//偶数
		for (int i = 1; i < N; i++) {
			for (int j = i + 1; j <= N; j++) {
				if (i + j != N + 1) {
					ans.push_back(make_pair(i, j));
				}
			}
		}
	}
	else {
		//奇数
		for (int i = 1; i < N; i++) {
			for (int j = i + 1; j <= N; j++) {
				if (i + j != N) {
					ans.push_back(make_pair(i, j));
				}
			}
		}
	}

	cout << ans.size() << endl;

	for (auto a : ans) {
		printf("%d %d\n", a.first, a.second);
	}

	return 0;
}

Measured memory_bytes: 384
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using System.Runtime.CompilerServices;
using static MyUtil;

class MyUtil
{
    public static int[] ReadIntArray()
    {
	return ReadLine().Split().Select(x => int.Parse(x)).ToArray();
    }
}

class Program
{
    public static void Main()
    {
	var tmp = ReadIntArray();
	int n = tmp[0], k = tmp[1];
	int[] h = ReadIntArray();
	int ans = 0;
	for (int i = 0; i < n; i++)
	    if (h[i] >= k) ans++;
	WriteLine(ans);
    }
}


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

int main() {
  ll n;
  cin>>n;
  vector<ll> a,b;
  for(int i=0; i<n; i++){
    ll x;
    cin>>x;
    a.push_back(x);
    b.push_back(x);
  }
  sort(b.begin(),b.end());
  reverse(b.begin(),b.end());
  for(ll i=0; i<n; i++){
    if(a[i]!=b[0]) cout<<b[0]<<endl;
    else cout<<b[1]<<endl;
  }
}

Measured memory_bytes: 4964
//xtwakioi! xtwddYnoi(双重含义)!
#include <bits/stdc++.h>
#define ri register
#define int long long
#define E (n+1)
#define TP (int)300001
#define mk make_pair
using namespace std; const int N=600010;
inline int read()
{
    int s=0, w=1; ri char ch=getchar();
    while(ch<'0'||ch>'9') { if(ch=='-') w=-1; ch=getchar(); }
    while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch^48), ch=getchar();
    return s*w;
}
int n,K,a[N],sum[N<<2];
#define lc (x<<1)
#define rc (x<<1|1)
void UpDate(int pos,int l,int r,int x,int k)
{
	if(l==r) { sum[x]=max(sum[x],k); return; }
	int mid=(l+r)/2;
	if(pos<=mid) UpDate(pos,l,mid,lc,k);
	else UpDate(pos,mid+1,r,rc,k);
	sum[x]=max(sum[lc],sum[rc]);
}
int Ask(int u,int v,int l,int r,int x)
{
	if(l>=u&&r<=v) return sum[x];
	if(u>v || l>r) return 0;
	int mx=0;
	int mid=(l+r)/2;
	if(u<=mid) mx=max(mx,Ask(u,v,l,mid,lc));
	if(v>mid) mx=max(mx,Ask(u,v,mid+1,r,rc));
	return mx;
}
signed main()
{
	n=read(), K=read();
	for(ri int i=1;i<=n;i++) a[i]=read(), a[i]++;
	for(ri int i=1;i<=n;i++) UpDate(a[i],1,TP,1,Ask(max(1ll,a[i]-K),min(TP,a[i]+K),1,TP,1)+1);
	printf("%lld\n",Ask(1,TP,1,TP,1));
    return 0;
}

Measured memory_bytes: 14304
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <string>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <tuple>
#include <numeric>
#include <functional>
#include <unordered_map>

using namespace std;

/*-----------------------------------------------------------------------------
　定義
 -------------------------------------------------------------------------------*/
#define ALL(a)			(a).begin(),(a).end()
#define REP(i, n)		for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n)	for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define INF				2e9
#define MOD				(1000 * 1000 * 1000 + 7)
#define Ceil(x, n)		(((((x))+((n)-1))/n))		/* Nの倍数に切り上げ割り算 */
#define CeilN(x, n)		(((((x))+((n)-1))/n)*n)		/* Nの倍数に切り上げ */
#define FloorN(x, n)	((x)-(x)%(n))				/* Nの倍数に切り下げ */
#define IsOdd(x)		(((x)&0x01UL) == 0x01UL)			
#define IsEven(x)		(!IsOdd((x)))						
#define M_PI			3.14159265358979323846
typedef long long		ll;
typedef pair<ll, ll>	P;

/*-----------------------------------------------------------------------------
　処理
 -------------------------------------------------------------------------------*/
// ベクターを値とインデックスのマップに圧縮
template <class T> 
map<T, int> compressVectorToMap(vector<T> vect)
{
	int cmpIdx = 0;
	map<T, int> idxTblMap;
	
	// 重複削除
	sort(vect.begin(), vect.end());
	vect.erase(unique(vect.begin(), vect.end()), vect.end());
	
	// 昇順にインデックスを割り当て
	for (auto one : vect) {
		idxTblMap[one] = cmpIdx;
		cmpIdx++;
	}

	return idxTblMap;
}

int main()
{
	int N, K;
	cin >> N >> K;
	map<int, int> mp;
	REP(i, N) {
		int a;
		cin >> a;
		mp[a]++;
	}
	
	vector<P> kind;
	for (auto mpOne : mp) {
		kind.emplace_back(mpOne.second, mpOne.first);
	}
	sort(ALL(kind));

	ll ans = 0;
	int delNum = kind.size() - K;
	REP (i, delNum) {
		ans += kind[i].first;
	}

	cout << ans << endl;
	return 0;

}


Measured memory_bytes: 14580
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));

console.log(main());
function main(){
  var n = o.a();
  var m = o.a();
  var a = Array(n+1).fill(1);
  var b = new Set();
  b.add(1);
  for(var i = 0; i < m; i++){
    var t = o.l(), x = t[0], y = t[1];
    a[x]--; a[y]++;
    if(b.has(x)){
      b.add(y);
      if(a[x] === 0)b.delete(x);
    }
  }
  return b.size;
}

Measured memory_bytes: 34096
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 400000;

struct tri {
	ll s; ll t; ll x;
};

bool cmp(tri a, tri b) {
	return a.x < b.x;
}



int main() {

	int N, Q;
	cin >> N >> Q;

	tri koji[MAX];

	repn(i, N) {
		cin >> koji[i].s >> koji[i].t >> koji[i].x;
	}

	sort(koji + 1, koji + N + 1, cmp);

	
	
	ll D[MAX];

	repn(i, Q) cin >> D[i];

	map<ll,ll> hito;
	repn(i, Q) hito[D[i]] = i;

	ll ans[MAX];
	repn(i, Q) ans[i] = -1;

	
	for (int i = 1; i <= N; i++) {
		auto x = hito.lower_bound(koji[i].s - koji[i].x);
		auto y = hito.lower_bound(koji[i].t - koji[i].x);
		
		for (auto z = x; z != y; ++z) {

			ans[z->second] = koji[i].x;
		}

		hito.erase(x, y);

	}


	repn(i, Q) cout << ans[i] << endl;

	system("PAUSE");

}

Measured memory_bytes: 27124
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdlib>
#include <cmath>

typedef long long ll;

#define reps(i, s, e) for (ll i = s; i < e; ++i)
#define rep(i, n) reps(i, 0, n)
#define rreps(i, s, e) for (ll i = e-1; i >= s; --i)
#define rrep(i, n) rreps(i, 0, n)

const ll LL_INF = 1LL<<60;

template <class T> inline void chmin(T& a, T b) {if (a > b) {a = b;}}
template <class T> inline void chmax(T& a, T b) {if (a < b) {a = b;}}

using namespace std;

int main() {
    // http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DPL_1_E&lang=jp

    string s1, s2;
    cin >> s1 >> s2;

    ll l1 = s1.length();
    ll l2 = s2.length();

    vector< vector<ll> > dp(l1+1);
    rep(i, l1+1) dp[i].resize(l2+1,LL_INF);
    rep(i, l1+1) dp[i][0] = i;
    rep(j, l2+1) dp[0][j] = j;

    rep(i, l1) {
        rep(j, l2) {
            if (s1[i] == s2[j]) {
                chmin(dp[i+1][j+1], dp[i][j]);
            } else {
                chmin(dp[i+1][j+1], dp[i+1][j]+1);
                chmin(dp[i+1][j+1], dp[i][j+1]+1);
                chmin(dp[i+1][j+1], dp[i][j]+1);
            }
        }
    }

    cout << dp[l1][l2] << endl;
}


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

#define FOR(i,a,b) for(int i = a; i < b; i++)
#define pb push_back

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

const int N = 1e5 + 5;
const int mod = 1e9 + 7;
int dp[2][N];
int n;
char str[N];
int L[N];
int R[N];
int fast(int b, int e){
    if(!e)return 1;
    if(e & 1)return b * 1ll * fast(b * 1ll * b % mod, e >> 1) % mod;
    return fast(b * 1ll * b % mod, e >> 1) % mod;
}
int main(){
    scanf("%s",str);
    n = strlen(str);
    int out = 0;
    int cntQ = 0;
    int cntA = 0;
    int cntC = 0;
    FOR(i,0,n){
        if(str[i] == '?' || str[i] == 'B'){

            L[i] = cntA * 1ll * fast(3, cntQ) % mod;
            if(cntQ)
            L[i] += (cntQ * 1ll * fast(3,cntQ-1) % mod);
//            cout << L[i] << endl;
        }


        cntQ += (str[i] == '?');
        cntA += (str[i] == 'A');
    }
    cntQ = cntA = 0;
    for(int i = n-1; i >= 0; i--){

        if(str[i] == '?' || str[i] == 'B'){

            R[i] = cntA * 1ll * fast(3, cntQ) % mod;
            if(cntQ)
            R[i] += (cntQ * 1ll * fast(3,cntQ-1) % mod);
//            cout << R[i] << '\n';
            if(R[i] >= mod)R[i] -= mod;

        }


        cntQ += (str[i] == '?');
        cntA += (str[i] == 'C');
    }

    FOR(i,0,n){

        out += L[i] * 1ll * R[i] % mod;
        if(out >= mod)out -= mod;
    }


    cout << out << endl;
    return 0;
}


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

D = [[0]*10 for i in range(10)]

for i in range(1,N+1):
    sento = int(str(i)[0])
    ushiro = int(str(i)[-1])
    D[sento][ushiro] += 1
    
ans = 0
for i in range(1,10):
    for j in range(1,10):
        ans += D[i][j]*D[j][i]
print(ans)

Measured memory_bytes: 41068
fn getline() -> String {
    let mut __ret = String::new();
    std::io::stdin().read_line(&mut __ret).ok();
    return __ret;
}
 
fn main() {
    let s = getline();
    let vec: Vec<i32> = s.trim().split(' ').map(|s| s.parse().unwrap()).collect();
    let x = vec[0];
    let y = vec[1];
    let ans = (x-1) * (y-1);
 
    println!("{}", ans);
}

Measured memory_bytes: 4352
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# 数 値 読 み 込 み
a,b,c = [int(i) for i in input().split()]

if a*b*c % 2 == 0:
  print(0)
else:
  d = [a,b,c]
  d.sort()
  print(d[0]*d[1])

Measured memory_bytes: 2940
#include <bits/stdc++.h>
#pragma GCC optimize("O3")

#define fi first
#define se second
#define em emplace
#define eb emplace_back
#define mp make_pair
#define pi pair<int,int>
#define vi vector<int>
#define vpi vector<pair<int,int>>
#define vll vector<ll>
#define vpll vector<pair<ll,ll>>
#define endl '\n'

#define si(v) int(v.size())
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep2(i, n, m) for (ll i = n; i <= (m); ++i)
#define rep3(i, n, m) for (ll i = n; i >= (m); --i)

template<class T, class U> bool chmax(T &a, U b) { if (a < b) a = b; return true; }
template<class T, class U> bool chmin(T &a, U b) { if (b < a) a = b; return true; }

using ll = long long;
using ld = long double;
using namespace std;

constexpr ll MOD = 1000000007;

signed main()
{
  cout << fixed << setprecision(20);
  ios::sync_with_stdio(false);
  cin.tie(0);
  
  int n; cin >> n;
  vi a(n);

  rep(i, n) cin >> a[i];
  int ans = MOD;

  rep2(i, 1, 100) {
    int p = i, score = 0;

    rep(j, n) {
      int cost = a[j] - p;
      score += cost * cost;
    }
    chmin(ans, score);
  }

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

Measured memory_bytes: 3656
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <utility>
#include <numeric>
#include <iomanip>

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

using namespace std;

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

    vector<string> s(n);
    vector<int> t(n);

    for (int i = 0; i < n; i++)
    {
        cin >> s[i] >> t[i];
    }

    string x;
    cin >> x;

    bool check = false;
    int ans = 0;

    for (int i = 0; i < n; i++)
    {
        if (check == true)
        {
            ans += t[i];
        }

        if (s[i] == x)
        {
            check = true;
        }
        
    }

    cout << ans << endl;
    
    
}

/*

long int gcd(long int a, long int b)
{
    if (a < b) {
        a ^= b;
        b ^= a;
        a ^= b;
    }
    
    return b ? gcd(b, a % b) : a;
}

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

*/

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

int main() {
    int n, a, b;
    cin >> n >> a >> b;
    int c = b - a;
    if (c % 2 == 1) cout << "Borys" << endl;
    else if (c % 2 == 0) cout << "Alice" << endl;
    return 0;
}

Measured memory_bytes: 256
EPS=10**(-9)

def outercenter(z1,z2,z3):
    w=(z1-z2)*z3.conjugate()+(z2-z3)*z1.conjugate()+(z3-z1)*z2.conjugate()
    if w==0:
        return (False,0,0)
    else:
        W=(z1-z2)*abs(z3)**2+(z2-z3)*abs(z1)**2+(z3-z1)*abs(z2)**2
        return (True,W/w,abs(z1-W/w))

def is_in_circle(c,r,z):
    return r+EPS>abs(z-c)

N=int(input())
z=[0 for i in range(0,N)]
for i in range(0,N):
    x,y=map(int,input().split())
    z[i]=complex(x,y)

ans=float('inf')
for i in range(0,N-1):
    for j in range(i+1,N):
        mid=(z[i]+z[j])/2
        r=abs(z[i]-mid)
        for k in range(0,N):
            if not is_in_circle(mid,r,z[k]):
                break
        else:
            ans=min(ans,r)

for i in range(0,N-2):
    for j in range(i+1,N-1):
        for k in range(j+1,N):
            info=outercenter(z[i],z[j],z[k])
            if info[0]:
                c=info[1]
                r=info[2]
                for l in range(0,N):
                    if not is_in_circle(c,r,z[l]):
                        break
                else:
                    ans=min(ans,r)

print(ans)

Measured memory_bytes: 51180
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long N,A,B;
  long long ans;
  cin >> N >> A >> B;
  ans = (N/(A+B))*A;
  if(N%(A+B)>A){
    ans += A;
  }else{
    ans += N%(A+B);
  }
  cout << ans << "\n";
}

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

long long n, w, item[110][2];


long long mem[110][100010];
long long DP(int idx, int weight){

    if(idx == n)    return 0;
    if(mem[idx][weight] != -1) return mem[idx][weight];
    ///Take
        long long opt1 = (weight + item[idx][0] <= w) ? DP(idx + 1, weight + item[idx][0]) + item[idx][1] : 0;
    ///Leave
        long long opt2 = DP(idx + 1, weight);

    return mem[idx][weight] = max(opt1, opt2);
}

int main() {
    memset(mem, -1, sizeof mem);
	scanf("%lld %lld", &n, &w);
	for(int i = 0 ; i < n ; ++i)	scanf("%lld %lld", &item[i][0], &item[i][1]);
    cout << DP(0, 0) << endl;

	return 0;
}


Measured memory_bytes: 86144
n, m = map(int, input().split())
L = sorted(map(int, input().split()))
d = [0] * (m - 1)
for i in range(1, m):
    d[i - 1] = abs(L[i] - L[i - 1])
d = sorted(d, reverse=True)[(n - 1):]
print(sum(d))


Measured memory_bytes: 13968
#include <bits/stdc++.h>
using namespace std;
#define int long long
using ll=long long;
using vi=vector<int>;
using vl=vector<long long>;
using pii=pair<int,int>;
using pll=pair<long long,long long>;
#define ITR(i,c) for(auto i=begin(c);i!=end(c);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define REPW(i,n) for(i=0;i<(int)(n);++i)
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) (y<0||x<0||y>=h||x>=w)
#define dump(...)
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
#define INF (1001001001)
#define INFLL (1001001001001001001ll)
template<class T> ostream& operator << (ostream &os,const vector<T> &v) {
    ITR(i,v) os << *i << (i==end(v)-1 ? "" : " "); return os; }
template<class T> istream& operator >> (istream &is,vector<T> &v) {
    ITR(i,v) is >> * i; return is; }
template<class T> istream& operator >> (istream &is, pair<T,T> &p) {
        is >> p.first >> p.second; return is; }
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
//------------------------------------------------------------------------------
struct before_main_function {
    before_main_function() {
        #ifdef int
            #undef INF
            #define INF INFLL
            #define stoi stoll
        #endif
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

const int MOD=1e9+7;
int fact[100005];
int fact_inv[100005];
int bin_pow_mod(int a,int b) {
    if(a==0) return 1;
    int p=1;
    while(b>0) {
        if(b&1) p=(p*a)%MOD;
        a=(a*a)%MOD;
        b>>=1;
    }
    return p;
}
void init_fact() {
    fact[0]=fact_inv[0]=1;
    REPF(i,1,100005) {
        fact[i]=(fact[i-1]*i)%MOD;
    }
    REPF(i,1,100005) {
        fact_inv[i]=bin_pow_mod(fact[i],MOD-2);
    }
}
int ncr(int n,int r) {
    return (((fact[n]*fact_inv[n-r])%MOD)*fact_inv[r])%MOD;
}
signed main() {
    init_fact();
    int n;
    cin>>n;
    vector<int> a(n+1);
    cin>>a;
    int dup=0;
    {
        vector<bool> b(n,false);
        REP(i,n+1) {
            if(b[a[i]-1]) {
                dup=a[i]-1;
                break;
            }
            b[a[i]-1]=true;
        }
    }
    int idx[2];
    idx[0]=-1;
    REP(i,n+1) {
        if(a[i]-1==dup) {
            if(idx[0]==-1) idx[0]=i;
            else idx[1]=i;
        }
    }

    int l=idx[0]+n-idx[1];
    REPF(k,1,n+2) {
        int ans=0;
        ans=ncr(n+1,k);
        if(l>=k-1) {
            ans-=ncr(l,k-1);
        }
        ans+=MOD;
        ans%=MOD;
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 3584
#include<stdio.h>
void bubblesort(int*,int);
int c=0;

int main()
{

  int n,i;
  
  scanf("%d",&n);
  int A[n];

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

 bubblesort(A,n);
 
  for(i=0;i<n;i++)
  {
  if(i==0)printf("%d",A[i]);
  else printf(" %d",A[i]);
  }
  printf("\n%d\n",c);

  return 0;
  
}

void bubblesort(int *A,int N)
{
  int flag=1,a,j;
  
  while(flag) 
    {
    
      flag=0;
      for(j=N-1;j>=1;j--)	
      {

	  if (A[j]<A[j-1])
	    {
	      a=A[j];
	      A[j]=A[j-1];
	      A[j-1]=a;
	      flag=1;
	      c++;
	    }
	  
	  }
      
    }

  
}



Measured memory_bytes: 2108
#include <bits/stdc++.h>
#include <unistd.h>
 
using namespace std;
 
typedef long long ll;
typedef pair<ll,ll> P;
 
long long int INF = 3e18;
double Pi = 3.1415926535897932384626;
 
vector<ll> G[550010];
//vector<P> tree[500010];
priority_queue <ll> pql;
priority_queue <P> pqp;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
priority_queue <P,vector<P>,greater<P> > pqps;
//small priority queue
//top pop
 
int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
char dir[] = "DRUL";
//ll bit[500005];
//↓,→,↑,←
 
 
#define p(x) cout<<x<<"\n";
#define el cout<<endl;
#define pe(x) cout<<(x)<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<(x);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define CLEAR(a) a = decltype(a)(); 
 
 
ll mod = 998244353;
 
ll rui(ll number1,ll number2){
 
    if(number2 == 0){
        return 1;
    }else{
        ll number3 = rui(number1,number2 / 2);
        number3 *= number3;
        number3 %= mod;
        if(number2%2==1){
            number3 *= number1;
            number3 %= mod;
        }
        return number3;
    }
}
ll gcd(ll number1,ll number2){
 
    if(number1 > number2){
        swap(number1,number2);
    }
    if(number1 == 0 || number1 == number2){
        return number2;
    }else{
        return gcd(number2 % number1,number1);
    }
}
void YES(bool condition){
 
    if(condition){
        p("YES");
    }else{
        p("NO");
    }
    return;
}
void Yes(bool condition){
 
    if(condition){
        p("Yes");
    }else{
        p("No");
    }
    return;
}
 

ll fact[800005],rfact[800005];
 
void c3_init(){
    fact[0] = rfact[0] = 1;
    for(ll i=1; i<=800000; i++){
        fact[i] = (fact[i-1]*i) % mod;
    }
    rfact[800000] = rui(fact[800000],mod - 2);
    for(ll i=800000; i>=1; i--){
       rfact[i-1] = rfact[i] * i;
       rfact[i-1] %= mod;
    }
    return;}
ll c3(ll n,ll r){
    return (((fact[n] * rfact[r]) % mod ) * rfact[n-r]) % mod;}

 
ll n,m,num,sum,a,b,c,d,e,g,h,w,i,j,q,r,l;
ll k,ans;
ll x[500005],y[500005],z[500005];

char s[500005];

int main(){
    cin >> a >> b;
    if(a <= 9 && b <= 9){
        p(a * b);
    }else{
        p(-1);
    }
    

    return 0;
}











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

#define SAFE_DELETE( x ) { if ( x ){ delete x; x = NULL; } }

struct tCell{
	tCell(){
		x = y = size = 0;
		prev = next = NULL;
	}
	int x, y, size;
	tCell *prev, *next;
};

class MyArray{
public:
	MyArray() : size( 0 ), head( NULL ), tail( NULL ){
		head = new tCell;
		tail = new tCell;
		head->next = tail;
		tail->prev = head;
	}
	~MyArray(){
		for( int i = size; i > 0; --i ){
			tCell* cell = tail->prev;
			cell->prev->next = cell->next;
			cell->next->prev = cell->prev;
			SAFE_DELETE( cell );
		}
		SAFE_DELETE( tail );
		SAFE_DELETE( head );
	}

	void pushBack( int x, int y, int size ){
		++this->size;
		tCell* cell = new tCell;
		cell->x = x;
		cell->y = y;
		cell->size = size;
		cell->prev = tail->prev;
		cell->next = tail;
		cell->prev->next = cell;
		cell->next->prev = cell;
	}
	int getSize(){ return size; }

	tCell operator[]( int d ){
		tCell* cell = head->next;
		if ( d >= size ){ cell = NULL; return *cell; }
		for ( int i = 0; i < d; ++i ){
			cell = cell->next;
		}
		return *cell;
	}

private:
	int size;
	tCell *head, *tail;
};

const unsigned SX = 14;
const unsigned SY = 14;

void putInk( int x, int y, int* board, int* sample ){
	for ( int j = -2; j < 3; ++j ){
		for ( int i = -2; i < 3; ++i ){
			board[ ( y+j ) * SY + ( x+i ) ] += sample[ ( j+2 ) * 5 + ( i+2 ) ];
		}
	}
}

int main(){
	int x, y, size;
	char c;
	MyArray ma;
	int board[ SY * SX ];
	for ( int j = 0; j < SY; ++j ){
		for ( int i = 0; i < SX; ++i ){
			board[ j*SX + i ] = 0;
		}
	}

	int small[ 5 * 5 ];
	int medium[ 5 * 5 ];
	int large[ 5 * 5 ];
	for ( int j = 0; j < 5; ++j ){
		for ( int i = 0; i < 5; ++i ){
			small[ j*5 + i ] = medium[ j*5 + i ] = large[ j*5 + i ] = 0;
			if ( ( i >= 1 && i <=3 ) && ( j >= 1 && j <= 3 ) ) {
				small[ j*5 + i ] = medium[ j*5 + i ] = large[ j*5 + i ] = 1;
			}
			if ( ( i == 1 || i == 3 ) && ( j == 1 || j == 3 ) ) {
				small[ j*5 + i ] = 0;
			}
			if ( i == 2 || j == 2 ) {
				large[ j*5 + i ] = 1;
			}
		}
	}

	while ( cin >> x >> c >> y >> c >> size ){
		ma.pushBack( x+2, y+2, size );
	}

	for ( int i = 0; i < ma.getSize(); ++i ){
		x = ma[ i ].x;
		y = ma[ i ].y;
		size = ma[ i ].size;
		int* sample;
		switch ( size ){
			case 1 : sample = small; break;
			case 2 : sample = medium; break;
			case 3 : sample = large; break;
		}
		putInk( x, y, board, sample );
	}

	int blank = 0, depth = 0;
	for ( int j = 2; j < SY-2; ++j ){
		for ( int i = 2; i < SX-2; ++i ){
			if ( !board[ j * SY + i ] ) ++blank;
			else if ( depth < board[ j * SY + i ] ) depth = board[ j * SY + i ];
		}
	}

	cout << blank << endl << depth << endl;

	return 0;
}

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

int main()
{
  char S[3];
  int count = 0;
  
  cin >> S[0] >> S[1] >> S[2];
  
  for(int i = 0; i < 3; i++)
  {
    if(S[i] == '1')
    {
      count++;
    }
  }
  
  cout << count << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<map>
#include<algorithm>
using namespace std;
typedef long long ll;
const int Max = 1e5 + 7;
int lst[Max];

int main()
{
	string str;
	cin >> str;
	for (int i = 0; i <= str.size() - 1; i++) lst[str[i] - 'a']++;
	int f = 1;
	for (int i = 0; i <= 25; i++)
	{
		if (lst[i] == 0) { cout << char('a' + i); f = 0; break; }
	}
	if (f)cout << "None";
}

Measured memory_bytes: 3160
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
const ll LINF=0x1fffffffffffffff;
const int INF=0x3fffffff;
const int MOD=1000000007;
#define VAR(type,...) type __VA_ARGS__;in(__VA_ARGS__)
#define VEC(type,name,size) vector<type> name(size);each(x, name)in(x)
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,a,b) for(int i=(a-1);i>=(b);--i)
#define each(x,v) for(auto &x:(v))
#define all(x) (x).begin(),(x).end()
#define print(x) cout<<(x)<<endl
void in(){} template<class T,class... U> void in(T &t,U &...u){cin>>t;in(u...);}
void solve();
int main(){cin.tie(0);ios::sync_with_stdio(0);solve();}

void solve() {
  VAR(string, a, b, c);
  cout << "A" << b[0] << "C" << endl;
}


Measured memory_bytes: 256
x,y,a,b,c = map(int,input().split())
p = sorted(list(map(int,input().split())),reverse=True)
q = sorted(list(map(int,input().split())),reverse=True)
r = sorted(list(map(int,input().split())),reverse=True)
apples = p[0:x]+q[0:y]+r
print(sum(sorted(apples,reverse=True)[0:x+y]))

Measured memory_bytes: 22704
#include <bits/stdc++.h>
using namespace std;
int main() {
    int N;cin >> N;
    long long c=0,r=0;
    for (int i=0;i<N;i++){
        int d; cin >> d;
        c += d;r += d*d;
    }
    cout << (c*c-r)/2 << "\n";
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
  int n, x;
  while (1) {
    int count = 0;
    cin >> n >> x;
    if (n == 0 && x == 0) break;
    for (int i = 1; i < n; i++)
      for (int j = i+1; j < n; j++)
        for (int k = j+1; k <= n; k++)
          if (!(i+j+k-x)) count++;
    cout << count << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn=10000;
int a[maxn];
int ans, n;
void solve(int x,int y){
	int mini=0x3f3f3f3f;
	
	for(int i=x;i<y;i++)
		mini=min(mini,a[i]);	
	for(int i=x;i<y;i++)
		a[i]-=mini;
	
	if(mini!=0x3f3f3f3f)
		ans+=mini;
//	cout<<"#m:"<<mini<<endl;
//	cout<<"====="<<endl;
//	for(int i=0;i<n;i++)
//		cout<<a[i]<<" ";
//	cout<<endl;
//	cout<<"====="<<endl;
	return ;
}
int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>a[i];
	int cnt=0;
	ans=0;
	int l,r;
	while(cnt!=n){
		cnt=0;
		l=r=0;
		bool sign=false;
		for(int i=0;i<n;i++){
			if(l==i&&a[i]==0){
				l=i+1;
				continue;
			}	
			else{
				r=i;
				if(a[i]==0)
				{
					sign=true;break;
				}	
			}
		}
		if(!sign)
			r++;
	//	cout<<"#"<<l<<" "<<r<<endl;
			solve(l,r);
		for(int i=0;i<n;i++)
			if(a[i]==0)   
				cnt++;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define mod 1000000007
#define INF2 9999999999
#define INF (1 << 30)
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)

using namespace std;
using ll = __int64_t;

int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
int DX[] = {1, 1, 0, -1, -1, -1, 0, 1};
int DY[] = {0, -1, -1, -1, 0, 1, 1, 1};

void solve(){
    int s;
    cin >> s;
    int sa = s/100;
    int sb = s%100;
    if((sa <= 0 || sa > 12) && (sb <= 0 || sb > 12)){
        cout << "NA" << endl;
    }else if((0 < sa && sa <= 12) && (sb <= 0 || sb > 12)){
        cout << "MMYY" << endl;
    }else if((0 < sb && sb <= 12) && (sa <= 0 || sa > 12)){ 
        cout << "YYMM" << endl;
    }else{
        cout << "AMBIGUOUS" << endl;
    }
}

int main() {
    solve();
    return 0;
}

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

int main(){
    long long R,G,B,N;
    cin >> R >> G >> B >> N;
    long long ans = 0;
    for(int i = 0; i <= N; i++){
        for(int j = 0; j <= N; j++){
        int X = N-R*i-G*j;       
            if(X%B == 0 && X>=0){
            ans++;
            }     
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#define SIZE 300005
#define MOD 998244353LL
#define EPS 1e-10
#define INF 2147483647
#define LLINF 9223372036854775807
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define DOWN(i,b,a) for(int i=b;i>=a;i--)
#define SET(a,c) memset(a,c,sizeof a)
#define BIT(i,j) ((i)>>(j))&1
#define ALL(o) (o).begin(), (o).end()
#define ERASE(o) (o).erase(unique((o).begin(),(o).end()), (o).end())
#define SQ(x) ((x)*(x))
using namespace std;
typedef int_fast64_t ll;
typedef pair<ll,ll> Pll;
typedef pair<int, int> Pii;
typedef pair<double, double> Pdd;
typedef complex<double> dcomplex;
template<typename T> inline void priv(vector<T>a){REP(i,a.size()){cerr<<a[i]<<((i==a.size()-1)?"\n":" ");}}
inline void fastio(){cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15);}
ll gcd(ll a,ll b){ll c=max(a,b);ll d=min(a,b);return c==0||d==0?c:gcd(c%d,d);}
ll lcm(ll a,ll b){return a==0||b==0?0:a*b/gcd(a,b);}

template<int N, typename T, T M>
struct ModFact {
    T fact[N+1];
    T ifact[N+1];
    constexpr ModFact() : fact(), ifact() {
        fact[0] = 1;
        for (int i=0; i<N; ++i)
            fact[i+1] = (fact[i]*(i+1))%M;
        ifact[N] = power(fact[N], M-2);
        for (int i=N-1; i >= 0; --i)
            ifact[i] = (ifact[i+1]*(i+1))%M;
    }
    constexpr T power(T a, T b) {
        T r = 1;
        while (b>0) {
            if((b&1)!=0) r = (r*a)%M;
            a = (a*a)%M;
            b >>= 1;
        }
        return r;
    }
    constexpr T comb(T n, T r) {
        return (((fact[n]*ifact[r])%M)*ifact[n-r])%M;
    }
};
 
ModFact<300000, ll, MOD> fact;

int main() {
    fastio();
    ll N, A, B, K, ans = 0;
	cin >> N >> A >> B >> K;
    ll g = gcd(A, B);
    if(K%g==0) {
        ll s, ca=B/g, cb=A/g;
        ll oa=min(N, K/A), ob=min(N, K/B);
        int i=0, j=ob;
        while(i<=oa) {
            while (i*A+j*B>K) j--;
            if (i*A+j*B==K) break;
            i++;
        }
        while(i<=oa && j>=0) {
            ans += fact.comb(N,i)*fact.comb(N,j);
            if(ans > MOD) ans %= MOD;
            i += ca; j -= cb;
        }
    }
    cout << ans << "\n";
	return 0;
}


Measured memory_bytes: 256
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
A = [0]
B = [0]
for i in range(n):
    A.append(a[i] + A[i])
for i in range(m):
    B.append(b[i] + B[i])
ans = 0
j = m
for i in range(n+1):
    if A[i] > k:
        break
    while B[j] > k - A[i]:
        j -= 1
    ans = max(ans, i + j)
print(ans)

Measured memory_bytes: 47504
{-# LANGUAGE BangPatterns #-}
import Control.Arrow (second)
import Control.Monad
import Control.Monad.Fix
import Data.Foldable (foldl')
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import qualified Data.ByteString.Char8 as B
import Data.ByteString.Internal (accursedUnutterablePerformIO)

uread :: VUM.Unbox a => Int -> VUM.IOVector a -> a
uread i v = accursedUnutterablePerformIO $ VUM.unsafeRead v i

uwrite :: VUM.Unbox a => Int -> a -> VUM.IOVector a -> VUM.IOVector a
uwrite i a v = accursedUnutterablePerformIO $ VUM.unsafeWrite v i a >> return v

uswap :: VUM.Unbox a => Int -> Int -> VUM.IOVector a -> VUM.IOVector a
uswap i j v = accursedUnutterablePerformIO $ VUM.unsafeSwap v i j >> return v

ufreeze :: VUM.Unbox a => VUM.IOVector a -> VU.Vector a
ufreeze v = accursedUnutterablePerformIO $ VU.unsafeFreeze v

uthaw :: VUM.Unbox a => VU.Vector a -> VUM.IOVector a
uthaw v = accursedUnutterablePerformIO $ VU.unsafeThaw v

newtype UnionFind = UnionFind (VUM.IOVector Int, VUM.IOVector Int)

findUF :: UnionFind -> Int -> Int
findUF (UnionFind (elems, _)) k = fix
  ( \f (elems, k, path) -> case uread k elems of
    n | n == k -> foldl' (\acc p -> uwrite p n acc) elems path `seq` n
    n          -> f (elems, n, n : path)
  )
  (elems, k, [k])

sizeUF :: UnionFind -> Int -> Int
sizeUF (UnionFind (_, sizes)) i = uread i sizes

uwriteElem :: Int -> Int -> UnionFind -> UnionFind
uwriteElem i a (UnionFind (elem, sizes)) = UnionFind (uwrite i a elem, sizes)

uwriteSize :: Int -> Int -> UnionFind -> UnionFind
uwriteSize i a (UnionFind (elem, sizes)) = UnionFind (elem, uwrite i a sizes)

unionUF :: UnionFind -> Int -> Int -> (UnionFind, Int)
unionUF uf@(UnionFind (elem, sizes)) i j =
  let pi  = findUF uf i
      pj  = findUF uf j
      si  = uread pi sizes
      sj  = uread pj sizes
      sij = si + sj
  in  if pi == pj
      then
        (uf, 0)
      else
        let (t1, t2) = if si < sj then (pi, pj) else (pj, pi)
        in  ( UnionFind (uwrite t1 t2 elem, uwrite t1 0 $ uwrite t2 sij sizes)
            , si * sj
            )

comb2 k = k * (k - 1) `div` 2

solve :: Int -> Int -> VU.Vector (Int, Int) -> VU.Vector Int
solve n m abs = ufreeze $ (\(_, _, acc) -> acc) $ VU.foldr'
  go
  (group, 0, accursedUnutterablePerformIO $ VUM.replicate m 0)
  abs
 where
  go (a, b) (uf, k, acc) =
    let (uf', d) = unionUF uf a b
        prev     = if k == 0 then 0 else uread (k - 1) acc
    in  (uf', k + 1, uwrite k (prev + d) acc)

  nC2 = comb2 n

  group :: UnionFind
  group = UnionFind
    (uthaw $ VU.enumFromN 0 n, accursedUnutterablePerformIO $ VUM.replicate n 1)

main = do
  let readInt = fmap (second B.tail) . B.readInt

  nm  <- VU.unfoldrN 2 readInt <$> B.getLine
  abs <- VU.replicateM
    (nm VU.! 1)
    (   (\vec -> (vec VU.! 0 - 1, vec VU.! 1 - 1))
    .   VU.unfoldrN 2 readInt
    <$> B.getLine
    )

  let solutions = solve (nm VU.! 0) (nm VU.! 1) abs
  let nC2       = comb2 $ nm VU.! 0

  mapM_ (print . (nC2 -) . (solutions VU.!)) [nm VU.! 1 - 2, nm VU.! 1 - 3 .. 0]
  print nC2


Measured memory_bytes: 34044
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    H,W=MI()
    grid = [ST() for _ in range(H)]
    N = H*W
    edge = [[] for _ in range(N)]
    def enc(h,w):
        return h*W+w

    # DP = [[[inf,inf] for _ in range(W)] for _ in range(H)]
    # DP[0][0][0] = 0
    DP = [[inf]*W for _ in range(H)]
    DP[0][0] = int(grid[0][0] == "#")
    for h in range(H):
        for w in range(W):
            if(h+1<H):
                if(grid[h][w] == grid[h+1][w] or grid[h+1][w] == "."):
                    DP[h+1][w] = min(DP[h+1][w], DP[h][w])
                else:
                    DP[h+1][w] = min(DP[h+1][w], DP[h][w] + 1) 
            if(w+1<W):
                if(grid[h][w] == grid[h][w+1] or grid[h][w+1] == "."):
                    DP[h][w+1] = min(DP[h][w+1], DP[h][w])
                else:
                    DP[h][w+1] = min(DP[h][w+1], DP[h][w] + 1) 
    print(DP[-1][-1])
if __name__ == '__main__':
    main()

Measured memory_bytes: 69996
#include<bits/stdc++.h>
using namespace std;
using LL = long long;
constexpr int maxn = 240000;
char s[maxn];
template<typename T> void no(const T&s){cout << s; exit(0);}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cin >> (s + 1);
	int n = strlen(s + 1);
	LL ans = 0, pre = 0;
	for(int i = 1; i <= n; i += 1){
		if(s[i] == 'A') pre += 1;
		else if(s[i] == 'B' and s[i + 1] == 'C'){
			ans += pre;
			i += 1;
		}
		else pre = 0;
	}
	cout << ans;
	return 0;
}

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

int main() {
    long long a, b[300], i, flag = 0, num = 0;
    cin >> a;
    for(i = 0; i < a; i++)
        cin >> b[i];

    while(1) {
        for(i = 0; i < a; i++) {
            if(b[i] % 2) {
                flag = 1;   break;
            }
            else
                b[i] /= 2;
        }

        if(flag)
            break;
        else
            num++;
    }

    cout << num << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pii> vp;

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


signed main(void) {
    int n;
    cin >> n;
    string s;
    cin >> s;
    reverse(all(s));
    int m;
    cin >> m;
    vi v(m);
    rep(i,m)cin >> v[i];
    vector<vi> dp(n+1,vi(10,0));
    //i桁目まで見て総和%10がjのときの通り数
    dp[0][0] = 1;
    rep(i,n)rep(j,10)if(dp[i][j]){
        //cout << i << " " << j << " " << dp[i][j] << endl;
        if(s[i] == '*'){
            rep(k,m){
                int ne = v[k];
                if(i%2) ne *= 2;
                ne = ne%10 + ne/10;
                //cout << " " << k << " " << j+ne << endl;
                dp[i+1][(j+ne)%10] += dp[i][j];
            }
        }else{
            int ne = s[i] - '0';
            if(i%2) ne *= 2;
            ne = ne%10 + ne/10;
            dp[i+1][(j+ne)%10] += dp[i][j];
        }
    }

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



Measured memory_bytes: 14752
// Problem : B - Trick or Treat
// Contest : AtCoder - AtCoder Beginner Contest 166
// URL : https://atcoder.jp/contests/abc166/tasks/abc166_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

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

#define pb push_back
#define vi vector<int>


int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	
	int n,k,ans=0;
	cin>>n>>k;
	int dp[n+1];
	
	for(int i=1;i<=n;i++)
		dp[i]=0;
		
	while(k--)
	{
		int d;
		cin>>d;
		for(int i=0,x;i<d;i++)
		{
			cin>>x;
			dp[x]++;
		}
	}
	
	for(int i=1;i<=n;i++)
		if(!dp[i])
			ans++;
			
	cout<<ans<<"\n";
	
	
   	return 0;
}



Measured memory_bytes: 3660
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<map>
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<((int)(n));i++)
#define reg(i,a,b) for(int i=((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i=((int)(n))-1;i>=0;i--)
#define ireg(i,a,b) for(int i=((int)(b));i>=((int)(a));i--)
typedef long long int lli;
typedef pair<int,int> mp;
#define fir first
#define sec second
#define IINF INT_MAX
#define LINF LLONG_MAX
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define pque(type) priority_queue<type,vector<type>,greater<type> >
#define memst(a,b) memset(a,b,sizeof(a))

int n;
vector<int> vs[100005];

int ans[100005];

set<int> s[100005];

void dfs(){
	vector<int> stc;
	stc.push_back(0);
	{
		for(int i=0;i!=stc.size();i++){
			int no=stc[i];
			rep(j,vs[no].size()){
				stc.push_back(vs[no][j]);
			}
		}
	}
	
	irep(k,stc.size()){
		int no=stc[k];
	
		rep(i,vs[no].size()){
			int to=vs[no][i];
			if(s[to].size()>s[no].size())swap(s[no],s[to]);
			
			for(set<int>::iterator ite=s[to].begin(); ite!=s[to].end(); ite++){
				int p=*ite;
				if(s[no].count(p)>=1){
					s[no].erase(p);
					ans[p]=no;
				}
				else{
					s[no].insert(p);
				}
			}
			s[to].clear();
		}
	}
}

int main(void){
	scanf("%d",&n);
	rep(i,n){
		int k;
		scanf("%d",&k);
		rep(j,k){
			int a;
			scanf("%d",&a);
			vs[i].push_back(a);
		}
	}
	
	int q;
	scanf("%d",&q);
	rep(i,q){
		int a,b;
		scanf("%d%d",&a,&b);
		if(a==b)ans[i]=a;
		else{
			s[a].insert(i);
			s[b].insert(i);
		}
	}
	
	dfs();
	
	rep(i,q){
		printf("%d\n",ans[i]);
	}
	
	return 0;
}

Measured memory_bytes: 21588
#include <string>
#include <vector>
#include <algorithm>
#include<iostream>
#include <stdio.h>
using namespace std;


int main()
{    
    long long N;
    cin >> N;
    std::string S;
    cin >> S;

    long long ans=0;
    long long J=0;
    for (long long i = 0; i < N; ++i) {
        if (S[i]=='W'){
            for (long long j = J; j < N; ++j) {
                if (i+j>=N){
                    J=j;
                    break;
                }
                if (S[N-1-j]=='R'){
                    ans+=1;
                    J=j+1;
                    break;
                }
            }
            
        if (i+J+1>N){break;}
        }
    }
    cout << ans << endl;
    
    return 0;

}

Measured memory_bytes: 3696
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Range(container) container.begin(), container.end()
#define Cin(T, x) T x; cin >> x;
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i];
#define Cout(val) cout << (val) << "\n";
using namespace std;
using ll = long long;

int main(void){
    Cin(int, a);
    Cin(int, b);
    Cin(int, c);
    Cin(int, d);
    Cout((abs(a-b) < abs(a-c)) ? "A" : "B");
}

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

int main (void) {
    int i;
    int a, b;
    int ans;

    scanf("%d%d", &a, &b);

    ans = 10 * b;
    for ( i=0; i<9; i++ ) {
        if ( ans * 8 / 100 == a )
            break;
        ans++;
    }
    if ( ans * 8 / 100 != a || ans / 10 != b )
        ans = -1;

    printf("%d\n", ans);
    return EXIT_SUCCESS;
}


Measured memory_bytes: 128
#include <vector>
#include <list>
#include <map>
#include <set>
#include "queue"
#include <deque>
#include <stack>
#include <numeric>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <climits>
#include <cassert>
#include <iostream>
#define MOD1 1000000007

inline void inp( long long int  &n ){n=0;int ch=getchar();int sign=1;while( ch < '0' || ch > '9' ){if(ch=='-')sign=-1; ch=getchar();}while( ch >= '0' && ch <= '9' )n = (n<<3)+(n<<1) + ch-'0', ch=getchar();n=n*sign;}
#define pi acos(-1)
#define iil pair<int,int>
#define vii vector<ii>
#define ll  long long int
#define loop(i,n) for(ll i=0;i<n;i++)
#define ll  long long int
#define LL long long int
#define loop2(i,n) for(ll i=1;i<=n;i++)
#define MIN(a,b) (a) < (b) ? (a) : (b)
#define MAX(a,b) (a) > (b) ? (a) : (b)
#define ABS(a) (a) > 0 ? (a) : -(a)
#define rep1(i,a,n) for(i=a;i<(n);i++)
#define pii pair< ll, ll >
#define pb push_back
#define mp make_pair
#define all(x)                  (x).begin(),(x).end()
#define OUT_RT cerr << (float(clock()) / CLOCKS_PER_SEC) << endl
#define EPS 1e-7
using namespace std;
//find the holy grail in an  adventure frought with danger
//The bigger the occasion, the better the response.
// Never giving in, fighting to the end
// Look at  the limits ; Check if it is binary search
//Code till the end of contest


const int MAXN  = (ll)1e6+10;

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll n  ;
    ll len;
    cin>>n>>len;
    ll array[MAXN];
    loop2(i, n)
    {
        cin>>array[i];
    }
    for(ll j =  1;j<=n-1;j+=1)
    {
        if(array[j]+array[j+1]>=len)
        {
            cout<<"Possible"<<endl;
            for(ll  i = n-1;i>=j+1;i--)
            {
                cout<<i<<endl;
            }
            for(ll  i = 1;i<=j-1;i+=1)
            {
                cout<<i<<endl;
            }
            cout<<j<<endl;
            return 0;
        }
    }
  
    cout<<"Impossible"<<endl;
    return 0;
}


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

ll gcd(ll a, ll b){
  if(b == 0){
    return a;
  }
  else{
    return gcd(b,(a%b));
  }
}
ll lcm(ll a,ll b){
  return a/gcd(a,b)*b;
}

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

Measured memory_bytes: 256
use proconio::{fastout, input};

use proconio::marker::Usize1;

#[fastout]
fn main() {
    input! {
        n: usize,
        a: [Usize1; n - 1]
    }
    let mut b = vec![0; n];
    for x in a.iter() {
        b[*x] += 1;
    }
    for i in 0..n {
        println!("{}", b[i]);
    }
}


Measured memory_bytes: 5544
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  int a,b,k;
  cin>>a>>b>>k;
  for(int i=100;i>=1;i--){
    if(a%i==0&&b%i==0) k--;
      if(k==0){
        cout<<i<<endl;
        return 0;
      }
    
  }
  return 0;
}


Measured memory_bytes: 256